1 | # set to 1 to trace object creation/destruction |
---|
2 | CREATE $(TRACE) = 0 |
---|
3 | |
---|
4 | # EMPTY can e.g. be used to insert trailing SPACES |
---|
5 | CREATE $(EMPTY) = |
---|
6 | |
---|
7 | GOTO main |
---|
8 | |
---|
9 | FUNCTION return_ifnot conds,result |
---|
10 | IF $(conds) ~ & |
---|
11 | P if (!($(conds:# && =))) return $(INIT|$(result)); |
---|
12 | ENDIF |
---|
13 | RETURN |
---|
14 | FUNCTION index_or_return index,return |
---|
15 | IF $(index) !~ # |
---|
16 | P int index = aisc_talking_get_index(0, $(index)); /* index_or_return $(return) */ |
---|
17 | SET $(return) return $(return); |
---|
18 | P if (aisc_server_error) $(return: ;=;) |
---|
19 | ENDIF |
---|
20 | RETURN |
---|
21 | |
---|
22 | FUNCTION define_callback a,type,func |
---|
23 | CONST $(a) # releative key |
---|
24 | CONST $(type) # function type (get, set etc.) |
---|
25 | CONST $(func) # function name |
---|
26 | |
---|
27 | CREATE $(num) = $(+ $(a)+$(KEYC)) |
---|
28 | CREATE $(cb) $(type)_list[$(num)] |
---|
29 | # $(cb) contains name of callback variable |
---|
30 | |
---|
31 | IF $($(cb)) |
---|
32 | IF $($(cb)) ~ 0 |
---|
33 | ELSE |
---|
34 | ERROR Number $(KEYC) for '$(func)' already in use by '$($(cb))' |
---|
35 | ENDIF |
---|
36 | ELSE |
---|
37 | ERROR Invalid number $(KEYC) for '$(func)'. Increase MAX_KEY to $(num) in $(argv[2]) |
---|
38 | ENDIF |
---|
39 | SET $($(cb)) = $(func) |
---|
40 | RETURN |
---|
41 | |
---|
42 | FUNCTION accessors struct,a,c |
---|
43 | # struct = struct/member name |
---|
44 | # a = relative key (int) |
---|
45 | # c = conditions |
---|
46 | |
---|
47 | CONST $(struct) |
---|
48 | CONST $(a) |
---|
49 | CONST $(c) |
---|
50 | |
---|
51 | CREATE $(su) $(setup) |
---|
52 | CREATE $(ac) $(access) |
---|
53 | CREATE $(in) $(index) |
---|
54 | |
---|
55 | CONST $(su) |
---|
56 | CONST $(ac) |
---|
57 | CONST $(in) |
---|
58 | |
---|
59 | CREATE $(type) |
---|
60 | CREATE $(member) |
---|
61 | CREATE $(conds) |
---|
62 | CREATE $(fun) |
---|
63 | CREATE $(funtype) |
---|
64 | CREATE $(null) |
---|
65 | |
---|
66 | FOR $({/KEY) |
---|
67 | SET $(member) $(struct)$(KEY) |
---|
68 | SET $(conds) $(c) |
---|
69 | SET $(setup) $(su) |
---|
70 | |
---|
71 | IF $(TYPE) = dllh |
---|
72 | SET $(fun) get_$(member)PRED |
---|
73 | CALL define_callback $(a),get,$(fun) |
---|
74 | IF $(extern_$(fun)) |
---|
75 | ELSE |
---|
76 | P static $(maintype) *$(fun)(const $(maintype) *THIS) { |
---|
77 | INDENT +1 |
---|
78 | CALL return_ifnot $(conds),NULp |
---|
79 | #P return ($(maintype) *)$(ac)previous; |
---|
80 | P return $(ac)previous; |
---|
81 | INDENT -1 |
---|
82 | P } |
---|
83 | ENDIF |
---|
84 | |
---|
85 | SET $(fun) get_$(member)NEXT |
---|
86 | CALL define_callback $(+ $(a)+1),get,$(fun) |
---|
87 | IF $(extern_$(fun)) |
---|
88 | ELSE |
---|
89 | P static $(maintype) *$(fun)(const $(maintype) *THIS) { |
---|
90 | INDENT +1 |
---|
91 | CALL return_ifnot $(conds),NULp |
---|
92 | #P return ($(maintype) *)$(ac)next; |
---|
93 | P return $(ac)next; |
---|
94 | INDENT -1 |
---|
95 | P } |
---|
96 | ENDIF |
---|
97 | |
---|
98 | PUSH |
---|
99 | CREATE $(subadd) $(+ 2+$(+ $(a)+$(KEYC))) |
---|
100 | SET $(access) $(ac)$(IDENT). |
---|
101 | MOVETO $(/AISC/DATA/STRUCT.dll_header) |
---|
102 | GOSUB accessors $(member),$(subadd),$(conds) |
---|
103 | POP |
---|
104 | CONTINUE |
---|
105 | ENDIF |
---|
106 | |
---|
107 | SET $(index) $(in) |
---|
108 | SET $(access) $(ac)$(IDENT) |
---|
109 | |
---|
110 | IF $(REF) ~ * |
---|
111 | SET $(conds) $(conds) && $(access) |
---|
112 | SET $(index) $(SIZE:THIS->=$(ac)) |
---|
113 | IF $(REF) ~ o,d,l,r |
---|
114 | SET $(type) $(TYPE) * |
---|
115 | ELSE |
---|
116 | SET $(type) $(TYPE) |
---|
117 | ENDIF |
---|
118 | SET $(setup) $(setup)if (!$(access)) $(access) = ($(type)*)calloc(sizeof($(type)),$(index));$n |
---|
119 | SET $(access) $(access)[index] |
---|
120 | ELSEIF $(REF) ~ v |
---|
121 | SET $(index) $(SIZE:THIS->=$(ac)) |
---|
122 | SET $(access) $(access)[index] |
---|
123 | ENDIF |
---|
124 | |
---|
125 | IF $(REF) ~ s |
---|
126 | IF $(REF) ~ o,l,r |
---|
127 | SET $(conds) $(conds) && $(access) |
---|
128 | SET $(setup) $(setup)if (!$(access)) $(access) = create_$(TYPE)();$n |
---|
129 | SET $(access) $(access)-> |
---|
130 | ELSEIF $(REF) ~ i |
---|
131 | SET $(access) $(access). |
---|
132 | ENDIF |
---|
133 | |
---|
134 | PUSH |
---|
135 | CREATE $(subadd) = $(+ $(a)+$(KEYC)) |
---|
136 | MOVETO $(/AISC/DATA/STRUCT.$(TYPE)) |
---|
137 | CALL accessors $(member),$(subadd),$(conds) |
---|
138 | POP |
---|
139 | CONTINUE |
---|
140 | ENDIF |
---|
141 | |
---|
142 | IF $(REF) ~ o,d |
---|
143 | IF $(ACC) !~ c |
---|
144 | ELSE |
---|
145 | # CREATE FUNCTIONS |
---|
146 | SET $(fun) create_$(member) |
---|
147 | CALL define_callback $(a),create,$(fun) |
---|
148 | IF $(extern_$(fun)) |
---|
149 | ELSE |
---|
150 | P static $(TYPE) *$(fun)($(maintype) *THIS) { |
---|
151 | INDENT +1 |
---|
152 | CALL return_ifnot $(conds),NULp |
---|
153 | CALL index_or_return $(index),NULp |
---|
154 | P $(TYPE) *obj = create_$(TYPE)(); |
---|
155 | P if (obj) { |
---|
156 | INDENT +1 |
---|
157 | P aisc_make_sets((long *)obj); |
---|
158 | P if (aisc_server_error) { |
---|
159 | INDENT +1 |
---|
160 | P destroy_$(TYPE)(obj); |
---|
161 | P obj = NULp; |
---|
162 | INDENT -1 |
---|
163 | P } |
---|
164 | P else { |
---|
165 | INDENT +1 |
---|
166 | IF $(REF) ~ d |
---|
167 | P aisc_server_error = aisc_link((dllpublic_ext*)&($(ac)p$(IDENT)), (dllheader_ext*)obj); |
---|
168 | ELSE |
---|
169 | P if ($(access)) destroy_$(TYPE)($(access)); |
---|
170 | P $(access) = obj; |
---|
171 | ENDIF |
---|
172 | INDENT -1 |
---|
173 | P } |
---|
174 | INDENT -1 |
---|
175 | P } |
---|
176 | P return obj; |
---|
177 | INDENT -1 |
---|
178 | P } |
---|
179 | ENDIF |
---|
180 | |
---|
181 | # COPY FUNCTIONS |
---|
182 | SET $(fun) copy_$(member) |
---|
183 | CALL define_callback $(a),copy,$(fun) |
---|
184 | IF $(extern_$(fun)) |
---|
185 | ELSE |
---|
186 | P static $(TYPE) *$(fun)($(maintype) *THIS) { |
---|
187 | INDENT +1 |
---|
188 | CALL return_ifnot $(conds),NULp |
---|
189 | CALL index_or_return $(index),NULp |
---|
190 | P trf_begin(); |
---|
191 | P $(TYPE) *obj = copy_$(TYPE)($(access)); |
---|
192 | P trf_commit(0); |
---|
193 | P if (obj) { |
---|
194 | INDENT +1 |
---|
195 | P aisc_make_sets((long *)obj); |
---|
196 | P if (aisc_server_error) { |
---|
197 | INDENT +1 |
---|
198 | P destroy_$(TYPE)(obj); |
---|
199 | P obj = NULp; |
---|
200 | INDENT -1 |
---|
201 | P } |
---|
202 | P else { |
---|
203 | INDENT +1 |
---|
204 | IF $(REF) ~ d |
---|
205 | P aisc_server_error = aisc_link((dllpublic_ext*)&($(ac)p$(IDENT)), (dllheader_ext*)obj); |
---|
206 | ELSE |
---|
207 | P if ($(access)) destroy_$(TYPE)($(access)); |
---|
208 | P $(access) = obj; |
---|
209 | ENDIF |
---|
210 | INDENT -1 |
---|
211 | P } |
---|
212 | INDENT -1 |
---|
213 | P } |
---|
214 | P return obj; |
---|
215 | INDENT -1 |
---|
216 | P } |
---|
217 | ENDIF |
---|
218 | ENDIF |
---|
219 | # FIND FUNCTIONS |
---|
220 | IF $(ACC) !~ f |
---|
221 | ELSEIF $(REF) ~ d |
---|
222 | SET $(fun) find_$(member) |
---|
223 | CALL define_callback $(a),find,$(fun) |
---|
224 | IF $(extern_$(fun)) |
---|
225 | ELSE |
---|
226 | P static $(TYPE) *$(fun)(const $(maintype) *THIS, const char *key) { |
---|
227 | INDENT +1 |
---|
228 | CALL return_ifnot $(conds),NULp |
---|
229 | P $(TYPE) *obj = ($(TYPE)*)aisc_read_hash((aisc_hash_node**)$(ac)p$(IDENT).hash, key); |
---|
230 | P return obj; |
---|
231 | INDENT -1 |
---|
232 | P } |
---|
233 | ENDIF |
---|
234 | ENDIF |
---|
235 | # CNT FUNCTION |
---|
236 | IF $(REF) ~ d |
---|
237 | SET $(fun) get_$(member)_CNT |
---|
238 | CALL define_callback $(+ $(a)+1),get,$(fun) |
---|
239 | IF $(extern_$(fun)) |
---|
240 | ELSE |
---|
241 | P static int $(fun)(const $(maintype) *THIS) { |
---|
242 | INDENT +1 |
---|
243 | CALL return_ifnot $(conds),0 |
---|
244 | P return $(ac)p$(IDENT).cnt; |
---|
245 | INDENT -1 |
---|
246 | P } |
---|
247 | ENDIF |
---|
248 | ENDIF |
---|
249 | ELSE |
---|
250 | # not $(REF) ~ o,d |
---|
251 | |
---|
252 | # SET FUNCTIONS |
---|
253 | IF $(ACC) !~ w |
---|
254 | ELSEIF $(REF) ~ $(v) |
---|
255 | CALL define_callback $(a),set,$(IDENT) |
---|
256 | IF $(extern_$(IDENT)) |
---|
257 | ELSE |
---|
258 | OUT import # Generate Prototypes for import |
---|
259 | P extern int $1$(IDENT)($(maintype)*, $(TYPE:bytestring=bytestring *)); |
---|
260 | OUT save |
---|
261 | ENDIF |
---|
262 | ELSE |
---|
263 | SET $(fun) set_$(member) |
---|
264 | CALL define_callback $(a),set,$(fun) |
---|
265 | IF $(extern_$(fun)) |
---|
266 | ELSE |
---|
267 | IF $(REF) ~ o,l,r |
---|
268 | P static void $(fun)($(maintype) *THIS, const $(TYPE) *x) { |
---|
269 | ELSEIF $(REF) ~ t,e |
---|
270 | P static void $(fun)($(maintype) *THIS, $(TYPE:bytestring=const bytestring *) x) { |
---|
271 | ELSE |
---|
272 | ERROR UNKNOWN REF '$(REF|)' in $(STRUCT).$(TYPE) |
---|
273 | ENDIF |
---|
274 | INDENT +1 |
---|
275 | CALL index_or_return $(index), |
---|
276 | P $(setup)$\ |
---|
277 | IF $(TYPE) = aisc_string |
---|
278 | P freeset($(access), x); |
---|
279 | ELSEIF $(TYPE) = bytestring |
---|
280 | P if (x) { |
---|
281 | P $1freeset($(access).data, x->data); |
---|
282 | P $1$(access).size = x->size; |
---|
283 | P } |
---|
284 | P else { |
---|
285 | P $1freenull($(access).data); |
---|
286 | P $1$(access).size = 0; |
---|
287 | P } |
---|
288 | ELSE |
---|
289 | IF $(REF) ~ o |
---|
290 | P if ($(access)) destroy_$(TYPE)($(access)); |
---|
291 | ENDIF |
---|
292 | P $(access) = x; |
---|
293 | ENDIF |
---|
294 | INDENT -1 |
---|
295 | P } |
---|
296 | ENDIF |
---|
297 | ENDIF |
---|
298 | ENDIF |
---|
299 | |
---|
300 | # GET FUNCTIONS |
---|
301 | IF $(ACC) !~ r |
---|
302 | ELSEIF $(REF) ~ $(v) |
---|
303 | IF $(extern_$(IDENT)) |
---|
304 | CALL define_callback $(a),get,$(IDENT) |
---|
305 | ELSE |
---|
306 | IF $(IDENT) = aisc_get_keystring |
---|
307 | # special cast for aisc_get_keystring |
---|
308 | CALL define_callback $(a),get,(const char*(*)(int*))$(IDENT) |
---|
309 | ELSE |
---|
310 | # explicit cast to overloaded function type before casting to void |
---|
311 | CALL define_callback $(a),get,($(TYPE:bytestring=bytestring *)(*)(const $(maintype)*))$(IDENT) |
---|
312 | ENDIF |
---|
313 | OUT import # Generate Prototypes for import |
---|
314 | P extern $(TYPE:bytestring=bytestring *) $(IDENT)(const $(maintype)*); |
---|
315 | OUT save |
---|
316 | ENDIF |
---|
317 | ELSE |
---|
318 | CALL define_callback $(a),get,get_$(member) |
---|
319 | IF $(extern_get_$(member)) |
---|
320 | ELSE |
---|
321 | P static $\ |
---|
322 | IF $(REF) ~ o,l,r,d |
---|
323 | SET $(funtype) = const $(TYPE) * |
---|
324 | ELSEIF $(REF) ~ e,t |
---|
325 | SET $(funtype) = $(TYPE:bytestring=const bytestring *:aisc_string=aisc_cstring) |
---|
326 | ELSE |
---|
327 | ERROR UNKNOWN REF '$(REF|)' in $(STRUCT).$(TYPE) |
---|
328 | ENDIF |
---|
329 | |
---|
330 | # detect return type for return_ifnot and index_or_return below |
---|
331 | IF $(funtype) ~ * |
---|
332 | SET $(null) = NULp |
---|
333 | ELSE |
---|
334 | # note the trailing space on next line! |
---|
335 | SET $(funtype) = $(funtype) $(EMPTY) |
---|
336 | SET $(null) = 0 |
---|
337 | ENDIF |
---|
338 | P $(funtype)get_$(member)(const $(maintype) *THIS) { |
---|
339 | |
---|
340 | INDENT +1 |
---|
341 | CALL return_ifnot $(conds),$(null) |
---|
342 | CALL index_or_return $(index),$(null) |
---|
343 | IF $(TYPE) = bytestring |
---|
344 | P return &($(access)); |
---|
345 | ELSE |
---|
346 | P return $(access); |
---|
347 | ENDIF |
---|
348 | INDENT -1 |
---|
349 | P } |
---|
350 | ENDIF |
---|
351 | ENDIF |
---|
352 | ENDFOR |
---|
353 | RETURN |
---|
354 | |
---|
355 | FUNCTION accessor_table fun |
---|
356 | P void *aisc_talking_functions_$(fun)_$(STRUCT)[] = { |
---|
357 | INDENT +1 |
---|
358 | CREATE $(i) |
---|
359 | CREATE $(cb) |
---|
360 | CREATE $(zeros) |
---|
361 | FOR $(i) = 0 TO $(MAX_KEY) |
---|
362 | SET $(cb) = $($(fun)_list[$(i)]) |
---|
363 | IF $(cb) = 0 |
---|
364 | # collect multiple '0' to print them in one line |
---|
365 | SET $(zeros) = $(zeros) NULp, |
---|
366 | ELSE |
---|
367 | IF $(zeros)!= |
---|
368 | P $(zeros) |
---|
369 | SET $(zeros) |
---|
370 | ENDIF |
---|
371 | |
---|
372 | IF $(cb) ~ /* |
---|
373 | SET $(cb) = $(cb:/*=,/*: ,/*=,/*:,/*=, /*) |
---|
374 | ELSEIF $(cb) ~ // |
---|
375 | SET $(cb) = $(cb://=,//: ,//=,//:,//=, //) |
---|
376 | ELSE |
---|
377 | SET $(cb) = $(cb), |
---|
378 | ENDIF |
---|
379 | |
---|
380 | P (void *)$(cb) |
---|
381 | ENDIF |
---|
382 | ENDFOR |
---|
383 | IF $(zeros) != |
---|
384 | P $(zeros) NULp |
---|
385 | ELSE |
---|
386 | P NULp |
---|
387 | ENDIF |
---|
388 | INDENT -1 |
---|
389 | P }; |
---|
390 | RETURN |
---|
391 | |
---|
392 | FUNCTION accessor_tables |
---|
393 | CALL accessor_table get |
---|
394 | CALL accessor_table set |
---|
395 | CALL accessor_table create |
---|
396 | CALL accessor_table find |
---|
397 | CALL accessor_table copy |
---|
398 | -- |
---|
399 | RETURN |
---|
400 | |
---|
401 | FUNCTION build_accessors |
---|
402 | # init callback tables |
---|
403 | CREATE $(i) = 0 |
---|
404 | FOR $(i) = 0 TO $(MAX_KEY) |
---|
405 | CREATE $(set_list[$(i)]) 0 |
---|
406 | CREATE $(get_list[$(i)]) 0 |
---|
407 | CREATE $(create_list[$(i)]) 0 |
---|
408 | CREATE $(find_list[$(i)]) 0 |
---|
409 | CREATE $(copy_list[$(i)]) 0 |
---|
410 | ENDFOR |
---|
411 | |
---|
412 | #CREATE $(conds) |
---|
413 | CREATE $(access) |
---|
414 | CREATE $(maintype) |
---|
415 | CREATE $(setup) |
---|
416 | CREATE $(index) # |
---|
417 | |
---|
418 | CREATE $(joined) |
---|
419 | |
---|
420 | FOR $(STRUCT) |
---|
421 | IF $(SKEY) |
---|
422 | P // $(STRUCT) accessors |
---|
423 | -- |
---|
424 | |
---|
425 | IF $(JOINED) |
---|
426 | ELSE |
---|
427 | FOR $(i) = 0 TO $(MAX_KEY) |
---|
428 | SET $(set_list[$(i)]) 0 |
---|
429 | SET $(get_list[$(i)]) 0 |
---|
430 | SET $(create_list[$(i)]) 0 |
---|
431 | SET $(find_list[$(i)]) 0 |
---|
432 | SET $(copy_list[$(i)]) 0 |
---|
433 | ENDFOR |
---|
434 | ENDIF |
---|
435 | #SET $(conds) = # |
---|
436 | SET $(access) THIS-> |
---|
437 | SET $(maintype) $(STRUCT) |
---|
438 | # 'setup' can not be transformed to parameter, cause it is |
---|
439 | # assigned sth containing ,; etc. so we need to use a global here :-( |
---|
440 | SET $(setup) |
---|
441 | SET $(index) # |
---|
442 | GOSUB accessors $(SKEY)_,0,# |
---|
443 | -- |
---|
444 | |
---|
445 | IF $(JOIN_NEXT) |
---|
446 | SET $(joined) = $(joined) $(STRUCT) |
---|
447 | ELSE |
---|
448 | P // $(joined) $(STRUCT) callback tables |
---|
449 | SET $(joined) = |
---|
450 | GOSUB accessor_tables |
---|
451 | ENDIF |
---|
452 | ENDIF |
---|
453 | ENDFOR |
---|
454 | RETURN |
---|
455 | |
---|
456 | # -------------------------------------------------------------------------------- |
---|
457 | |
---|
458 | FUNCTION init_structure,self,deref |
---|
459 | CREATE $(member) |
---|
460 | CREATE $(isloop) |
---|
461 | |
---|
462 | FOR $({/TYPE) |
---|
463 | SET $(member) $(self)$(deref)$(IDENT) |
---|
464 | SET $(isloop) 0 |
---|
465 | IF $(REF) ~ $(v) |
---|
466 | ELSE |
---|
467 | IF $(REF) ~ v |
---|
468 | SET $(isloop) 1 |
---|
469 | PMSTART |
---|
470 | PM for (int index = 0; index < $(SIZE:THIS->=$(self)$(deref)); index++) { |
---|
471 | INDENT +1 |
---|
472 | SET $(member) $(member)[index] |
---|
473 | ENDIF |
---|
474 | IF $(TYPE) = dllh |
---|
475 | P $(member).key $|= KEY_$(OBJECT_KEY)_$(SKEY|COMMON); |
---|
476 | PUSH |
---|
477 | MOVETO $(/AISC/DATA/STRUCT.dll_header) |
---|
478 | GOSUB init_structure,$(member),. |
---|
479 | POP |
---|
480 | ELSEIF $(REF) ~ o |
---|
481 | # just a NULp pointer - no init necessary |
---|
482 | ELSEIF $(REF) ~ d |
---|
483 | PUSH |
---|
484 | SET $(member) = $(self)$(deref)p$(IDENT) |
---|
485 | MOVETO $(/AISC/DATA/STRUCT.$(TYPE)) |
---|
486 | P $(member).parent $|= (dllheader_ext *)$(self); |
---|
487 | P $(member).key $|= KEY_$(OBJECT_KEY)_$(SKEY|SKEY_missing); |
---|
488 | POP |
---|
489 | ELSEIF $(REF) ~ s |
---|
490 | IF $(REF) ~ i |
---|
491 | PUSH |
---|
492 | MOVETO $(/AISC/DATA/STRUCT.$(TYPE)) |
---|
493 | GOSUB init_structure,$(member),. |
---|
494 | POP |
---|
495 | ENDIF |
---|
496 | ELSEIF $(REF) ~ t,e,l |
---|
497 | IF $(IDENT) = key |
---|
498 | IF $(SKEY) !~ COMMON |
---|
499 | P $(member) $|= KEY_$(OBJECT_KEY)_$(SKEY|COMMON); |
---|
500 | ENDIF |
---|
501 | ELSEIF $(INIT) |
---|
502 | IF $(TYPE) = aisc_string |
---|
503 | P $(member) $|= strdup($(INIT:THIS=$(self))); |
---|
504 | ELSE |
---|
505 | P $(member) $|= $(INIT:THIS=$(self)); |
---|
506 | ENDIF |
---|
507 | ENDIF |
---|
508 | ELSE |
---|
509 | ERROR UNKNOWN REF '$(REF|)' in $(STRUCT).$(TYPE) |
---|
510 | ENDIF |
---|
511 | IF $(isloop) = 1 |
---|
512 | INDENT -1 |
---|
513 | PM } |
---|
514 | PMEND |
---|
515 | ENDIF |
---|
516 | ENDIF |
---|
517 | ENDFOR |
---|
518 | RETURN |
---|
519 | |
---|
520 | FUNCTION build_init |
---|
521 | P // ------------ |
---|
522 | P // constructors |
---|
523 | -- |
---|
524 | P inline void alloc_err(const char *objectname) { |
---|
525 | P $1aisc_server_errorf("Could not allocate '%s'", objectname); |
---|
526 | P } |
---|
527 | -- |
---|
528 | |
---|
529 | FOR $(STRUCT) |
---|
530 | IF $(extern_create_$(STRUCT)) |
---|
531 | ELSE |
---|
532 | P $(STRUCT) *create_$(STRUCT)()$\ |
---|
533 | P { |
---|
534 | INDENT +1 |
---|
535 | P $(STRUCT) *o = ($(STRUCT)*)calloc(sizeof(*o), 1); |
---|
536 | P if (!o) alloc_err("$(STRUCT)"); |
---|
537 | PMSTART |
---|
538 | PM else { |
---|
539 | INDENT +1 |
---|
540 | GOSUB init_structure o,-> |
---|
541 | INDENT -1 |
---|
542 | PM } |
---|
543 | PMEND |
---|
544 | GOSUB trace "created $(STRUCT)" |
---|
545 | P return o; |
---|
546 | INDENT -1 |
---|
547 | P } |
---|
548 | ENDIF |
---|
549 | -- |
---|
550 | ENDFOR |
---|
551 | RETURN |
---|
552 | |
---|
553 | FUNCTION delete_structure,self,deref |
---|
554 | CREATE $(member) |
---|
555 | CREATE $(isloop) |
---|
556 | CREATE $(isinif) |
---|
557 | CREATE $(start) |
---|
558 | |
---|
559 | FOR $({/TYPE) |
---|
560 | SET $(member) $(self)$(deref)$(IDENT) |
---|
561 | SET $(isloop) 0 |
---|
562 | SET $(isinif) 0 |
---|
563 | |
---|
564 | IF $(DESTROY) |
---|
565 | P $(DESTROY:THIS=obj); |
---|
566 | ELSEIF $(REF) ~ $(v) |
---|
567 | # virtual function |
---|
568 | ELSE |
---|
569 | IF $(REF) ~ *,v |
---|
570 | PMSTART |
---|
571 | IF $(REF) ~ * |
---|
572 | SET $(isinif) 1 |
---|
573 | PM if ($(member)) { |
---|
574 | INDENT +1 |
---|
575 | ENDIF |
---|
576 | SET $(isloop) 1 |
---|
577 | PM for (int index = 0; index < $(SIZE:THIS->=$(self)$(deref)); index++) { |
---|
578 | INDENT +1 |
---|
579 | SET $(member) $(member)[index] |
---|
580 | ENDIF |
---|
581 | IF $(TYPE) = dllh |
---|
582 | PUSH |
---|
583 | MOVETO $(/AISC/DATA/STRUCT.dll_header) |
---|
584 | GOSUB delete_structure,$(member),. |
---|
585 | POP |
---|
586 | ELSEIF $(REF) ~ s |
---|
587 | IF $(REF) ~ o,d,i |
---|
588 | PUSH |
---|
589 | IF $(REF) ~ i |
---|
590 | CREATE $(subderef) . |
---|
591 | ELSE |
---|
592 | P if ($(member)) { |
---|
593 | INDENT +1 |
---|
594 | CREATE $(subderef) -> |
---|
595 | ENDIF |
---|
596 | MOVETO $(/AISC/DATA/STRUCT.$(TYPE)) |
---|
597 | GOSUB delete_structure,$(member),$(subderef) |
---|
598 | POP |
---|
599 | IF $(REF) !~ i |
---|
600 | P free($(member)); |
---|
601 | INDENT -1 |
---|
602 | P } |
---|
603 | ENDIF |
---|
604 | ENDIF |
---|
605 | ELSEIF $(REF) ~ d,o |
---|
606 | IF $(REF) ~ d |
---|
607 | P while $\ |
---|
608 | ELSE |
---|
609 | P if $\ |
---|
610 | ENDIF |
---|
611 | P ($(member)) { |
---|
612 | INDENT +1 |
---|
613 | P destroy_$(TYPE)($(member)); |
---|
614 | P if (aisc_server_error) return; |
---|
615 | INDENT -1 |
---|
616 | P } |
---|
617 | ELSEIF $(REF) ~ t,e |
---|
618 | IF $(TYPE) = aisc_string |
---|
619 | P free($(member)); |
---|
620 | ELSEIF $(TYPE) = bytestring |
---|
621 | P free($(member).data); |
---|
622 | ENDIF |
---|
623 | ELSEIF $(REF) ~ l |
---|
624 | ELSE |
---|
625 | ERROR UNKNOWN REF '$(REF|)' in $(STRUCT).$(TYPE) |
---|
626 | ENDIF |
---|
627 | |
---|
628 | IF $(isloop) = 1 |
---|
629 | INDENT -1 |
---|
630 | PM } |
---|
631 | IF $(isinif) = 1 |
---|
632 | INDENT -1 |
---|
633 | PM } |
---|
634 | ENDIF |
---|
635 | PMEND |
---|
636 | ENDIF |
---|
637 | ENDIF |
---|
638 | ENDFOR |
---|
639 | RETURN |
---|
640 | |
---|
641 | FUNCTION build_delete |
---|
642 | P // ----------- |
---|
643 | P // destructors |
---|
644 | -- |
---|
645 | |
---|
646 | FOR $(STRUCT) |
---|
647 | IF $(extern_destroy_$(STRUCT)) |
---|
648 | ELSE |
---|
649 | PUSH |
---|
650 | CREATE $(islinked) = 0 |
---|
651 | CREATE $(ident) |
---|
652 | |
---|
653 | PUSH |
---|
654 | MOVETO $({/.) |
---|
655 | IF $(TYPE) = dllh |
---|
656 | SET $(islinked) = 1 |
---|
657 | SET $(ident) = $(IDENT) |
---|
658 | ENDIF |
---|
659 | POP |
---|
660 | |
---|
661 | # pass pointers to not-linked objects by reference and set them to NULp below |
---|
662 | # linked object-pointers are set to NULp by aisc_unlink |
---|
663 | P void destroy_$(STRUCT)($(STRUCT)$\ |
---|
664 | IF $(islinked) = 1 |
---|
665 | P *obj$\ |
---|
666 | ELSE |
---|
667 | P *& obj$\ |
---|
668 | ENDIF |
---|
669 | P ) { |
---|
670 | INDENT +1 |
---|
671 | IF $(islinked) = 1 |
---|
672 | P if (obj->$(ident).parent) { |
---|
673 | INDENT +1 |
---|
674 | P aisc_unlink((dllheader_ext*)obj); |
---|
675 | P if (aisc_server_error) return; |
---|
676 | INDENT -1 |
---|
677 | P } |
---|
678 | ENDIF |
---|
679 | GOSUB delete_structure,obj,-> |
---|
680 | IF $(islinked) = 1 |
---|
681 | P free(obj); |
---|
682 | ELSE |
---|
683 | P freenull(obj); |
---|
684 | ENDIF |
---|
685 | GOSUB trace "destroyed $(STRUCT)" |
---|
686 | INDENT -1 |
---|
687 | P } |
---|
688 | -- |
---|
689 | POP |
---|
690 | ENDIF |
---|
691 | ENDFOR |
---|
692 | RETURN |
---|
693 | |
---|
694 | FUNCTION move_structure |
---|
695 | CREATE $(isloop) |
---|
696 | CREATE $(my_key) |
---|
697 | CREATE $(index) |
---|
698 | CREATE $(access) |
---|
699 | |
---|
700 | FOR $({/TYPE) |
---|
701 | SET $(index) |
---|
702 | SET $(access) $(IDENT) |
---|
703 | SET $(isloop) 0 |
---|
704 | IF $(REF) ~ $(v) |
---|
705 | ELSEIF $(IDENT) = key |
---|
706 | ELSE |
---|
707 | IF $(REF) ~ *,v |
---|
708 | IF $(SIZE) |
---|
709 | SET $(index) $(SIZE:THIS->=sobj->) |
---|
710 | ELSE |
---|
711 | ERROR Missing SIZE in STRUCT $(STRUCT) ident $(IDENT) |
---|
712 | ENDIF |
---|
713 | IF $(REF) ~ * |
---|
714 | P if (dobj->$(access))$\ |
---|
715 | ENDIF |
---|
716 | |
---|
717 | SET $(isloop) 1 |
---|
718 | PMSTART |
---|
719 | PM for (int index = 0; index < $(index); index++) { |
---|
720 | INDENT +1 |
---|
721 | SET $(access) $(access)[index] |
---|
722 | ENDIF |
---|
723 | IF $(TYPE) = dllh |
---|
724 | P move_dll_header(&(sobj->$(access)), &(dobj->$(access))); |
---|
725 | ELSEIF $(REF) ~ l,r |
---|
726 | P dobj->$(access) $|= sobj->$(access); $\ |
---|
727 | P $|trf_link((long)sobj->$(access), (long*)&dobj->$(access)); |
---|
728 | ELSEIF $(REF) ~ o |
---|
729 | P dobj->$(access) $|= copy_$(TYPE)(sobj->$(access)); |
---|
730 | ELSEIF $(REF) ~ d |
---|
731 | P for ($(TYPE) *cobj = sobj->$(access); cobj; cobj = cobj->next) { |
---|
732 | INDENT +1 |
---|
733 | P $(TYPE) *d2obj = copy_$(TYPE)(cobj); |
---|
734 | P if (!d2obj) return 1; |
---|
735 | P aisc_server_error = aisc_link((dllpublic_ext*)&(dobj->p$(access)), (dllheader_ext*)d2obj); |
---|
736 | P if (aisc_server_error) return 1; |
---|
737 | INDENT -1 |
---|
738 | P } |
---|
739 | ELSEIF $(REF) ~ s |
---|
740 | IF $(REF) ~ i |
---|
741 | P if (move_$(TYPE)(&(sobj->$(access)), &(dobj->$(access)))) return 1; |
---|
742 | ENDIF |
---|
743 | ELSEIF $(REF) ~ t,e |
---|
744 | IF $(TYPE) = aisc_string |
---|
745 | P dobj->$(access) $|= nulldup(sobj->$(access)); |
---|
746 | ELSEIF $(TYPE) = bytestring |
---|
747 | P if (sobj->$(access).data) { |
---|
748 | INDENT +1 |
---|
749 | P dobj->$(access).data = (char *)malloc(sobj->$(access).size); |
---|
750 | P memcpy(dobj->$(access).data, sobj->$(access).data, sobj->$(access).size); |
---|
751 | P dobj->$(access).size = sobj->$(access).size; |
---|
752 | INDENT -1 |
---|
753 | P } |
---|
754 | ELSE |
---|
755 | P dobj->$(access) $|= sobj->$(access); |
---|
756 | ENDIF |
---|
757 | ELSE |
---|
758 | PP UNKNOWN REF '$(REF|)' in $(STRUCT).$(TYPE) |
---|
759 | ENDIF |
---|
760 | IF $(isloop) = 1 |
---|
761 | INDENT -1 |
---|
762 | PM } |
---|
763 | PMEND |
---|
764 | ENDIF |
---|
765 | ENDIF |
---|
766 | ENDFOR |
---|
767 | RETURN |
---|
768 | |
---|
769 | FUNCTION build_move |
---|
770 | P // ------------ |
---|
771 | P // move objects |
---|
772 | -- |
---|
773 | FOR $(STRUCT) |
---|
774 | IF $(extern_move_$(STRUCT)) |
---|
775 | ELSE |
---|
776 | P static int move_$(STRUCT)(const $(STRUCT) *sobj, $(STRUCT) *dobj) { |
---|
777 | INDENT +1 |
---|
778 | GOSUB move_structure |
---|
779 | P return 0; |
---|
780 | INDENT -1 |
---|
781 | P } |
---|
782 | -- |
---|
783 | ENDIF |
---|
784 | ENDFOR |
---|
785 | RETURN |
---|
786 | |
---|
787 | FUNCTION build_copy |
---|
788 | P // ------------ |
---|
789 | P // copy objects |
---|
790 | -- |
---|
791 | FOR $(STRUCT) |
---|
792 | IF $(extern_copy_$(STRUCT)) |
---|
793 | ELSE |
---|
794 | P $(STRUCT) *copy_$(STRUCT)(const $(STRUCT) *sobj) { |
---|
795 | INDENT +1 |
---|
796 | P $(STRUCT) *dobj = NULp; |
---|
797 | P if (sobj) { |
---|
798 | INDENT +1 |
---|
799 | P dobj = create_$(STRUCT)(); |
---|
800 | P if (!dobj) alloc_err("$(STRUCT)"); |
---|
801 | P else { |
---|
802 | INDENT +1 |
---|
803 | P trf_create((long)sobj, (long)dobj); |
---|
804 | P if (move_$(STRUCT)(sobj, dobj)) { |
---|
805 | INDENT +1 |
---|
806 | P destroy_$(STRUCT)(dobj); |
---|
807 | P dobj = NULp; |
---|
808 | INDENT -1 |
---|
809 | P } |
---|
810 | INDENT -1 |
---|
811 | P } |
---|
812 | INDENT -1 |
---|
813 | P } |
---|
814 | GOSUB trace "copied $(STRUCT)" |
---|
815 | P return dobj; |
---|
816 | INDENT -1 |
---|
817 | P } |
---|
818 | -- |
---|
819 | ENDIF |
---|
820 | ENDFOR |
---|
821 | RETURN |
---|
822 | |
---|
823 | FUNCTION save_structure self,deref,prekey,fp |
---|
824 | CREATE $(member) |
---|
825 | CREATE $(isloop) |
---|
826 | CREATE $(isinif) |
---|
827 | CREATE $(saved_elems) = 0 |
---|
828 | |
---|
829 | FOR $({/TYPE) |
---|
830 | SET $(member) $(self)$(deref)$(IDENT) |
---|
831 | SET $(isloop) 0 |
---|
832 | SET $(isinif) 0 |
---|
833 | |
---|
834 | IF $(REF) ~ $(v) |
---|
835 | # virtual function |
---|
836 | ELSEIF $(SAVE) |
---|
837 | SET $(saved_elems) = $(+ $(saved_elems)+1) |
---|
838 | IF $(REF) ~ *,v |
---|
839 | PMSTART |
---|
840 | IF $(REF) ~ * |
---|
841 | SET $(isinif) 1 |
---|
842 | PM if ($(access)) { |
---|
843 | INDENT +1 |
---|
844 | ENDIF |
---|
845 | SET $(isloop) 1 |
---|
846 | PM for (int index = 0; index < $(SIZE:THIS->=$(self)$(deref); index++) { |
---|
847 | INDENT +1 |
---|
848 | SET $(member) $(member)[index] |
---|
849 | ENDIF |
---|
850 | IF $(TYPE) = dllh |
---|
851 | PUSH |
---|
852 | CREATE $(pk) $(prekey)$(KEY) |
---|
853 | MOVETO $(/AISC/DATA/STRUCT.dll_header) |
---|
854 | GOSUB save_structure,$(member),.,$(pk),$(fp) |
---|
855 | POP |
---|
856 | ELSEIF $(REF) ~ s |
---|
857 | IF $(REF) ~ o,d,i |
---|
858 | ERROR previously unused - check generated code! |
---|
859 | PUSH |
---|
860 | IF $(REF) ~ i |
---|
861 | CREATE $(subderef) . |
---|
862 | ELSE |
---|
863 | PMSTART |
---|
864 | PM if ($(member)) { |
---|
865 | INDENT +1 |
---|
866 | CREATE $(subderef) -> |
---|
867 | ENDIF |
---|
868 | CREATE $(pk) $(prekey)$(KEY|NOKEYDEFINED) |
---|
869 | MOVETO $(/AISC/DATA/STRUCT.$(TYPE)) |
---|
870 | GOSUB save_structure,$(member),$(subderef),$(pk),$(fp) |
---|
871 | POP |
---|
872 | IF $(REF) !~ i |
---|
873 | INDENT -1 |
---|
874 | PM } |
---|
875 | PMEND |
---|
876 | ENDIF |
---|
877 | ENDIF |
---|
878 | ELSEIF $(REF) ~ d |
---|
879 | IF $(saveable_$(TYPE)) = 0 |
---|
880 | ERROR Can't save $(TYPE) (has no saveable members) |
---|
881 | ENDIF |
---|
882 | P for ($(TYPE) *s = $(member); s; s = s->next) { |
---|
883 | INDENT +1 |
---|
884 | P fputs("$(prekey)$(KEY|NOKEYDEFINED){ ", $(fp)); |
---|
885 | P save_$(TYPE)(s, $(fp)); |
---|
886 | P fputs("}\n", $(fp)); |
---|
887 | INDENT -1 |
---|
888 | P } |
---|
889 | ELSEIF $(REF) ~ o |
---|
890 | ERROR previously unused - check generated code! |
---|
891 | IF $(saveable_$(TYPE)) = 0 |
---|
892 | ERROR Can't save $(TYPE) (has no saveable members) |
---|
893 | ENDIF |
---|
894 | P fputs("$(prekey)$(KEY) {\n", $(fp)); |
---|
895 | P save_$TYPE($(member), $(fp)); |
---|
896 | P fputs("}\n", $(fp)); |
---|
897 | ELSEIF $(REF) ~ t,e |
---|
898 | IF $(TYPE) = aisc_string |
---|
899 | P if ($(member)) $|save_string("$(prekey)$(KEY|NOKEYDEFINED)", $(member), $(fp)); |
---|
900 | ELSEIF $(TYPE) = int,long,char |
---|
901 | P fprintf($(fp), "$(prekey)$(KEY|NOKEYDEFINED) %i\n", $(member)); |
---|
902 | ELSEIF $(TYPE) = float,double |
---|
903 | P fprintf($(fp), "$(prekey)$(KEY|NOKEYDEFINED) %f\n", $(member)); |
---|
904 | ELSE |
---|
905 | ERROR CANNOT SAVE TYPE '$(TYPE)' |
---|
906 | ENDIF |
---|
907 | ELSEIF $(REF) ~ l |
---|
908 | P fprintf($(fp), "$(prekey)$(KEY|NOKEYDEFINED) %i", $(member)); |
---|
909 | ELSE |
---|
910 | ERROR UNKNOWN REF '$(REF|)' in $(STRUCT).$(TYPE) |
---|
911 | ENDIF |
---|
912 | IF $(isloop) = 1 |
---|
913 | INDENT -1 |
---|
914 | PM } |
---|
915 | IF $(isinif) = 1 |
---|
916 | INDENT -1 |
---|
917 | PM } |
---|
918 | ENDIF |
---|
919 | PMEND |
---|
920 | ENDIF |
---|
921 | ENDIF |
---|
922 | ENDFOR |
---|
923 | IF $(saved_elems) = 0 |
---|
924 | ERROR It makes no sense to save $(STRUCT), since it has no saveable data elements |
---|
925 | ENDIF |
---|
926 | RETURN |
---|
927 | |
---|
928 | FUNCTION load_structure self,deref,prekey,fp |
---|
929 | CREATE $(member) |
---|
930 | CREATE $(isloop) |
---|
931 | CREATE $(isinif) |
---|
932 | |
---|
933 | FOR $({/TYPE) |
---|
934 | SET $(member) $(self)$(deref)$(IDENT) |
---|
935 | SET $(isloop) 0 |
---|
936 | SET $(isinif) 0 |
---|
937 | |
---|
938 | IF $(REF) ~ $(v) |
---|
939 | # virtual function |
---|
940 | ELSEIF $(SAVE) |
---|
941 | IF $(REF) ~ *,v |
---|
942 | PMSTART |
---|
943 | IF $(REF) ~ * |
---|
944 | SET $(isinif) 1 |
---|
945 | PM if ($(member)) { |
---|
946 | INDENT +1 |
---|
947 | ENDIF |
---|
948 | SET $(isloop) 1 |
---|
949 | PM for (int index = 0; index < $(SIZE:THIS->=$(self)$(deref); index++) { |
---|
950 | INDENT +1 |
---|
951 | SET $(member) $(member)[index] |
---|
952 | ENDIF |
---|
953 | IF $(TYPE) = dllh |
---|
954 | PUSH |
---|
955 | CREATE $(pk) $(prekey)$(KEY) |
---|
956 | MOVETO $(/AISC/DATA/STRUCT.dll_header) |
---|
957 | GOSUB load_structure,$(member),.,$(pk),$(fp) |
---|
958 | POP |
---|
959 | ELSEIF $(REF) ~ s |
---|
960 | IF $(REF) ~ o,d,i |
---|
961 | ERROR previously unused - check generated code! |
---|
962 | PUSH |
---|
963 | IF $(REF) ~ i |
---|
964 | CREATE $(subderef) . |
---|
965 | ELSE |
---|
966 | PMSTART |
---|
967 | PM if ($(member)) { |
---|
968 | INDENT +1 |
---|
969 | CREATE $(subderef) -> |
---|
970 | ENDIF |
---|
971 | CREATE $(pk) $(prekey)$(KEY|NOKEYDEFINED) |
---|
972 | MOVETO $(/AISC/DATA/STRUCT.$(TYPE)) |
---|
973 | GOSUB load_structure,$(member),$(subderef),$(pk),$(fp) |
---|
974 | POP |
---|
975 | IF $(REF) !~ i |
---|
976 | INDENT -1 |
---|
977 | PM } |
---|
978 | PMEND |
---|
979 | ENDIF |
---|
980 | ENDIF |
---|
981 | ELSEIF $(REF) ~ d |
---|
982 | P if (strcmp("$(prekey)$(KEY|NOKEYDEFINED){", token)==0) { |
---|
983 | INDENT +1 |
---|
984 | P $(TYPE) *cobj = create_$(TYPE)(); |
---|
985 | P if (cobj) { |
---|
986 | INDENT +1 |
---|
987 | P if (load_$(TYPE)(cobj, $(fp))==0) { |
---|
988 | INDENT +1 |
---|
989 | P aisc_link((dllpublic_ext*)&($(self)$(deref)p$(IDENT)), (dllheader_ext*)cobj); |
---|
990 | P continue; |
---|
991 | INDENT -1 |
---|
992 | P } |
---|
993 | P destroy_$(TYPE)(cobj); |
---|
994 | INDENT -1 |
---|
995 | P } |
---|
996 | P return 1; |
---|
997 | INDENT -1 |
---|
998 | P } |
---|
999 | ELSEIF $(REF) ~ o |
---|
1000 | ERROR code generated here is broken (does save instead of load) |
---|
1001 | P fprintf($(fp),"$(prekey)$(KEY) {\n"); |
---|
1002 | P { int error = save_$TYPE($(member),$(fp)); |
---|
1003 | P if (error) return error; } |
---|
1004 | P fprintf($(fp),"}\n"); |
---|
1005 | ELSEIF $(REF) ~ t,e |
---|
1006 | P if (strcmp("$(prekey)$(KEY|NOKEYDEFINED)", token)==0) { |
---|
1007 | INDENT +1 |
---|
1008 | P if (aisc_server_load_token($(fp), token, $(TOKENSIZE))) return 1; |
---|
1009 | IF $(TYPE) = aisc_string |
---|
1010 | P $(member) = strdup(token); |
---|
1011 | ELSEIF $(TYPE) = int,long,char |
---|
1012 | P $(member) = atoi(token); |
---|
1013 | ELSEIF $(TYPE) = float,double |
---|
1014 | P $(member) = atof(token); |
---|
1015 | ELSE |
---|
1016 | ERROR Loading type '$(TYPE)' not implemented (yet) |
---|
1017 | ENDIF |
---|
1018 | P continue; |
---|
1019 | INDENT -1 |
---|
1020 | P } |
---|
1021 | ELSEIF $(REF) ~ l |
---|
1022 | ERROR loading links not implemented (yet) |
---|
1023 | ELSE |
---|
1024 | ERROR UNKNOWN REF '$(REF|)' in $(STRUCT).$(TYPE) |
---|
1025 | ENDIF |
---|
1026 | IF $(isloop) = 1 |
---|
1027 | INDENT -1 |
---|
1028 | PM } |
---|
1029 | IF $(isinif) = 1 |
---|
1030 | INDENT -1 |
---|
1031 | PM } |
---|
1032 | ENDIF |
---|
1033 | PMEND |
---|
1034 | ENDIF |
---|
1035 | ENDIF |
---|
1036 | ENDFOR |
---|
1037 | RETURN |
---|
1038 | |
---|
1039 | FUNCTION build_saveload |
---|
1040 | CREATE $(TOKENSIZE) 1024 |
---|
1041 | |
---|
1042 | P // ------------- |
---|
1043 | P // save and load |
---|
1044 | -- |
---|
1045 | P inline void warn_unknown_token(const char *token, const char *objectname) { |
---|
1046 | P $1fprintf(stderr, "Unknown token '%s' while loading '%s' (ignored)\n", token, objectname); |
---|
1047 | P } |
---|
1048 | -- |
---|
1049 | P inline void save_string(const char *key, const char *value, FILE *out) { |
---|
1050 | INDENT +1 |
---|
1051 | P fputs(key, out); |
---|
1052 | P fputc(' ', out); |
---|
1053 | P aisc_server_save_token(out, value, $(TOKENSIZE)); |
---|
1054 | INDENT -1 |
---|
1055 | P } |
---|
1056 | -- |
---|
1057 | |
---|
1058 | FOR $(STRUCT) |
---|
1059 | CREATE $(saveable_$(STRUCT)) = 0 |
---|
1060 | FOR $({/TYPE) |
---|
1061 | IF $(SAVE) |
---|
1062 | SET $(saveable_$(STRUCT)) = 1 |
---|
1063 | ENDIF |
---|
1064 | ENDFOR |
---|
1065 | #WARNING saveable_$(STRUCT) = $(saveable_$(STRUCT)) |
---|
1066 | ENDFOR |
---|
1067 | |
---|
1068 | FOR $(STRUCT) |
---|
1069 | IF $(saveable_$(STRUCT)) = 1 |
---|
1070 | IF $(extern_save_$(STRUCT)) |
---|
1071 | ELSE |
---|
1072 | P void save_$(STRUCT)(const $(STRUCT) *o, FILE *out) { |
---|
1073 | INDENT +1 |
---|
1074 | GOSUB save_structure,o,->,,out |
---|
1075 | INDENT -1 |
---|
1076 | P } |
---|
1077 | -- |
---|
1078 | ENDIF |
---|
1079 | ENDIF |
---|
1080 | ENDFOR |
---|
1081 | FOR $(STRUCT) |
---|
1082 | IF $(saveable_$(STRUCT)) = 1 |
---|
1083 | IF $(extern_load_$(STRUCT)) |
---|
1084 | ELSE |
---|
1085 | P int load_$(STRUCT)($(STRUCT) *o, FILE *in) { |
---|
1086 | INDENT +1 |
---|
1087 | P char token[$(TOKENSIZE)+1]; |
---|
1088 | P while (aisc_server_load_token(in, token, $(TOKENSIZE))==0) { |
---|
1089 | INDENT +1 |
---|
1090 | P if (*token == '}') break; |
---|
1091 | GOSUB load_structure,o,->,,in |
---|
1092 | P warn_unknown_token(token, "$(STRUCT)"); |
---|
1093 | INDENT -1 |
---|
1094 | P } |
---|
1095 | P return 0; |
---|
1096 | INDENT -1 |
---|
1097 | P } |
---|
1098 | -- |
---|
1099 | ENDIF |
---|
1100 | ENDIF |
---|
1101 | ENDFOR |
---|
1102 | RETURN |
---|
1103 | |
---|
1104 | FUNCTION trace msg |
---|
1105 | IF $(TRACE) = 1 |
---|
1106 | P fputs("AISC_SERVER_TRACE " $(msg) "\n", stderr); fflush(stderr); |
---|
1107 | ENDIF |
---|
1108 | RETURN |
---|
1109 | |
---|
1110 | FUNCTION file_header |
---|
1111 | P // ----------------------------------------------------------------- |
---|
1112 | P // Created automagically from ../$(argv[2]) |
---|
1113 | P // and ../$(argv[4]) |
---|
1114 | P // using aisc-script '../AISC/aisc_server.pa' |
---|
1115 | P // DO NOT EDIT THIS FILE!!! |
---|
1116 | P // ----------------------------------------------------------------- |
---|
1117 | -- |
---|
1118 | RETURN |
---|
1119 | |
---|
1120 | # -------------------------------------------------------------------------------- |
---|
1121 | |
---|
1122 | LABEL main |
---|
1123 | IF $(argc) < 7 |
---|
1124 | ERROR Wrong number of parameters[$(argc)]. Usage: aisc aisc_server.pa xxx.aisc outfile externfile.aisc import_proto globals.aisc |
---|
1125 | ENDIF |
---|
1126 | |
---|
1127 | DATA AISC { $(#FILE $(argv[2])) }, EXTERN { $(#FILE $(argv[4])) }, GLOBALS { $(#FILE $(argv[6])) }; |
---|
1128 | DUMPDATA DUMP/aisc_server.pa__$(argv[2]).dump |
---|
1129 | |
---|
1130 | OPEN save $(argv[3]) |
---|
1131 | OPEN import $(argv[5]) |
---|
1132 | |
---|
1133 | # set extern functions |
---|
1134 | MOVETO $(EXTERN/.) |
---|
1135 | FOR $(FUNCTION) |
---|
1136 | CREATE $(extern_$(FUNCTION)) |
---|
1137 | NEXT |
---|
1138 | ERROR no extern Functions found |
---|
1139 | ENDFOR |
---|
1140 | |
---|
1141 | # set globals passed from Makefile |
---|
1142 | MOVETO $(/GLOBALS/.) |
---|
1143 | CREATE $(create_save_code) = $(AISC_SAVE) |
---|
1144 | |
---|
1145 | OUT import |
---|
1146 | CALL file_header |
---|
1147 | |
---|
1148 | OUT save |
---|
1149 | CALL file_header |
---|
1150 | P $(#FILE C/aisc_server.h) |
---|
1151 | |
---|
1152 | MOVETO $(/AISC/DATA/.) |
---|
1153 | |
---|
1154 | CREATE $(v) = % |
---|
1155 | |
---|
1156 | CALL build_init |
---|
1157 | CALL build_delete |
---|
1158 | CALL build_move |
---|
1159 | CALL build_copy |
---|
1160 | CALL build_accessors |
---|
1161 | |
---|
1162 | IF $(create_save_code) = YES |
---|
1163 | CALL build_saveload |
---|
1164 | ENDIF |
---|
1165 | |
---|
1166 | |
---|
1167 | CLOSE save |
---|
1168 | CLOSE import |
---|
1169 | EXIT |
---|
1170 | |
---|