1 /* ------------------------------------------------------------------------- */
2 /* "veneer" : Compiling the run-time "veneer" of any routines invoked */
3 /* by the compiler (e.g. DefArt) which the program doesn't */
6 /* Part of Inform 6.41 */
7 /* copyright (c) Graham Nelson 1993 - 2022 */
9 /* Inform is free software: you can redistribute it and/or modify */
10 /* it under the terms of the GNU General Public License as published by */
11 /* the Free Software Foundation, either version 3 of the License, or */
12 /* (at your option) any later version. */
14 /* Inform is distributed in the hope that it will be useful, */
15 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17 /* GNU General Public License for more details. */
19 /* You should have received a copy of the GNU General Public License */
20 /* along with Inform. If not, see https://gnu.org/licenses/ */
22 /* ------------------------------------------------------------------------- */
26 int veneer_mode; /* Is the code currently being
27 compiled from the veneer? */
29 static debug_locations null_debug_locations =
30 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, NULL, 0 };
32 extern void compile_initial_routine(void)
34 /* The first routine present in memory in any Inform game, beginning
35 at the code area start position, always has 0 local variables
36 (since the interpreter begins execution with an empty stack frame):
37 and it must "quit" rather than "return".
39 (Pedantically, in Z-code 1-5, this is not a routine at all. It's
40 a sequence of opcodes which ends with "quit". The one-byte
41 header generated by assemble_routine_header() is a dummy.)
43 In order not to impose these restrictions on "Main", we compile a
44 trivial routine consisting of a call to "Main" followed by "quit". */
49 j = symbol_index("Main__", -1);
51 assemble_routine_header(0, FALSE, "Main__", FALSE, j),
53 symbols[j].flags |= SYSTEM_SFLAG + USED_SFLAG;
54 if (trace_fns_setting==3) symbols[j].flags |= STAR_SFLAG;
58 INITAOTV(&AO, LONG_CONSTANT_OT, 0);
61 sequence_point_follows = FALSE;
63 if (version_number > 3)
64 assemblez_1_to(call_vs_zc, AO, temp_var1);
66 assemblez_1_to(call_zc, AO, temp_var1);
73 INITAOTV(&AO, CONSTANT_OT, 0);
76 sequence_point_follows = FALSE;
78 assembleg_3(call_gc, AO, zero_operand, zero_operand);
79 assembleg_1(return_gc, zero_operand);
83 assemble_routine_end(FALSE, null_debug_locations);
86 /* ------------------------------------------------------------------------- */
87 /* The rest of the veneer is applied at the end of the pass, as required. */
88 /* ------------------------------------------------------------------------- */
90 static int veneer_routine_needs_compilation[VENEER_ROUTINES];
91 int32 veneer_routine_address[VENEER_ROUTINES];
92 static int veneer_symbols_base;
98 typedef struct VeneerRoutine_s
108 static char *veneer_source_area;
110 static VeneerRoutine VRs_z[VENEER_ROUTINES] =
112 /* Box__Routine: the only veneer routine used in the implementation of
113 an actual statement ("box", of course), written in a
114 hybrid of Inform and assembly language. Note the
115 transcription of the box text to the transcript
116 output stream (-1, or $ffff). */
119 "maxw table n w w2 line lc t;\
134 { @set_cursor line w;\
136 @set_cursor line w2;\
138 if (t~=0) print (string) t;\
147 @output_stream $ffff;\
152 if (w ~= 0) print (string) w;\
164 /* This batch of routines is expected to be defined (rather better) by
165 the Inform library: these minimal forms here are provided to prevent
166 tiny non-library-using programs from failing to compile when certain
167 legal syntaxes (such as <<Action a b>>;) are used. */
170 "a b c d; print \"Action <\", a, \" \", b, \" \", c;\
171 if (d) print \", \", d; print \">^\";\
172 ]", "", "", "", "", ""
175 "obj; print \"the \", obj; ]", "", "", "", "", ""
178 "obj; print \"a \", obj; ]", "", "", "", "", ""
181 "obj; print \"The \", obj; ]", "", "", "", "", ""
184 "obj; print \"A \", obj; ]", "", "", "", "", ""
187 "obj; switch(metaclass(obj))\
188 { 0: print \"nothing\";\
189 Object: @print_obj obj;\
190 Class: print \"class \"; @print_obj obj;\
191 Routine: print \"(routine at \", obj, \")\";\
192 String: print \"(string at \", obj, \")\";\
193 } ]", "", "", "", "", ""
196 "obj; print obj; ]", "", "", "", "", ""
201 { cla = #classes_table-->(prop & $ff);\
202 print (name) cla, \"::\";\
203 if ((prop & $8000) == 0) prop = (prop & $3f00)/$100;\
205 { prop = (prop & $7f00)/$100;\
207 while ((i-->0 ~= 0) && (prop>0))\
211 prop = (i-->0) & $7fff;\
214 "p = #identifiers_table;\
216 if (prop<=0 || prop>=size || p-->prop==0)\
217 print \"<number \", prop, \">\";\
218 else print (string) p-->prop;\
222 /* The remaining routines make up the run-time half of the object
223 orientation system, and need never be present for Inform 5 programs. */
226 /* WV__Pr: write a value to the property for the given
227 object having the given identifier */
230 "obj identifier value x;\
231 x = obj..&identifier;\
232 if (x==0) { RT__Err(\"write to\", obj, identifier); return; }\
234 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,value);\
235 #ifnot; #ifdef DEBUG;\
236 if (debug_flag & 15) RT__TrPS(obj,identifier,value);\
239 ]", "", "", "", "", ""
242 /* RV__Pr: read a value from the property for the given
243 object having the given identifier */
247 x = obj..&identifier;\
249 { if (identifier >= 1 && identifier < 64 && obj.#identifier <= 2)\
250 return obj.identifier;\
251 RT__Err(\"read\", obj, identifier); return; }\
253 if (obj..#identifier > 2) RT__Err(\"read\", obj, identifier);\
255 if (obj..#identifier > 2) RT__Err(\"read\", obj, identifier, 2);\
258 ]", "", "", "", "", ""
260 { /* CA__Pr: call, that is, print-or-run-or-read, a property:
261 this exactly implements obj..prop(...). Note that
262 classes (members of Class) have 5 built-in properties
263 inherited from Class: create, recreate, destroy,
264 remaining and copy. Implementing these here prevents
265 the need for a full metaclass inheritance scheme. */
268 "obj id a b c d e f x y z s s2 n m;\
269 if (obj < 1 || obj > #largest_object-255)\
270 { switch(Z__Region(obj))\
271 { 2: if (id == call)\
272 { s = sender; sender = self; self = obj;\
273 #ifdef action;sw__var=action;#endif;\
274 x = indirect(obj, a, b, c, d, e, f);\
275 self = sender; sender = s; return x; }\
277 "3: if (id == print) { @print_paddr obj; rtrue; }\
278 if (id == print_to_array)\
279 { @output_stream 3 a; @print_paddr obj; @output_stream -3;\
285 @check_arg_count 3 ?~A__x;y++;@check_arg_count 4 ?~A__x;y++;\
286 @check_arg_count 5 ?~A__x;y++;@check_arg_count 6 ?~A__x;y++;\
287 @check_arg_count 7 ?~A__x;y++;@check_arg_count 8 ?~A__x;y++;.A__x;",
288 "#ifdef INFIX;if (obj has infix__watching) n=1;#endif;\
289 #ifdef DEBUG;if (debug_flag & 1 ~= 0) n=1;#endif;\
291 #ifdef DEBUG;n=debug_flag & 1; debug_flag=debug_flag-n;#endif;\
292 print \"[ ~\", (name) obj, \"~.\", (property) id, \"(\";\
293 switch(y) { 1: print a; 2: print a,\",\",b; 3: print a,\",\",b,\",\",c;\
294 4: print a,\",\",b,\",\",c,\",\",d;\
295 5: print a,\",\",b,\",\",c,\",\",d,\",\",e;\
296 6: print a,\",\",b,\",\",c,\",\",d,\",\",e,\",\",f; }\
298 #ifdef DEBUG;debug_flag = debug_flag + n;#endif;\
300 "if (id > 0 && id < 64)\
301 { x = obj.&id; if (x==0) { x=$000a-->0 + 2*(id-1); n=2; }\
304 { if (id>=64 && id<69 && obj in Class)\
305 return Cl__Ms(obj,id,y,a,b,c,d);\
307 if (x == 0) { .Call__Error;\
308 RT__Err(\"send message\", obj, id); return; }\
310 if (id&$C000==$4000)\
311 switch (n&$C0) { 0: n=1; $40: n=2; $80: n=n&$3F; }\
314 { if (x-->m==$ffff) rfalse;\
315 switch(Z__Region(x-->m))\
316 { 2: s = sender; sender = self; self = obj; s2 = sw__var;\
318 if (id==life) sw__var=reason_code; else sw__var=action;\
320 switch(y) { 0: z = indirect(x-->m); 1: z = indirect(x-->m, a);\
321 2: z = indirect(x-->m, a, b); 3: z = indirect(x-->m, a, b, c);",
322 "4: z = indirect(x-->m, a, b, c, d); 5:z = indirect(x-->m, a, b, c, d, e);\
323 6: z = indirect(x-->m, a, b, c, d, e, f); }\
324 self = sender; sender = s; sw__var = s2;\
325 if (z ~= 0) return z;\
326 3: print_ret (string) x-->m;\
327 default: return x-->m;\
334 /* IB__Pr: ++(individual property) */
338 x = obj..&identifier;\
339 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
341 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)+1);\
342 #ifnot; #ifdef DEBUG;\
343 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
346 ]", "", "", "", "", ""
349 /* IA__Pr: (individual property)++ */
353 x = obj..&identifier;\
354 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
356 if (obj has infix__watching || (debug_flag & 15))\
357 RT__TrPS(obj,identifier,(x-->0)+1);\
358 #ifnot; #ifdef DEBUG;\
359 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
362 ]", "", "", "", "", ""
365 /* DB__Pr: --(individual property) */
369 x = obj..&identifier;\
370 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
372 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
373 #ifnot; #ifdef DEBUG;\
374 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
377 ]", "", "", "", "", ""
380 /* DA__Pr: (individual property)-- */
384 x = obj..&identifier;\
385 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
387 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
388 #ifnot; #ifdef DEBUG;\
389 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
392 ]", "", "", "", "", ""
395 /* RA__Pr: read the address of a property value for a given object,
396 returning 0 if it doesn't provide this individual
400 "obj identifier i otherid cla;\
402 if (identifier<64 && identifier>0) return obj.&identifier;\
403 if (identifier & $8000 ~= 0)\
404 { cla = #classes_table-->(identifier & $ff);\
405 if (cla.&3 == 0) rfalse;\
406 if (~~(obj ofclass cla)) rfalse;\
407 identifier = (identifier & $7f00) / $100;\
409 while (identifier>0)\
415 "if (identifier & $4000 ~= 0)\
416 { cla = #classes_table-->(identifier & $ff);\
417 identifier = (identifier & $3f00) / $100;\
418 if (~~(obj ofclass cla)) rfalse; i=0-->5;\
419 if (cla == 2) return i+2*identifier-2;\
420 i = 0-->((i+124+cla*14)/2);\
421 i = CP__Tab(i + 2*(0->i) + 1, -1)+6;\
422 return CP__Tab(i, identifier);\
424 if (obj.&3 == 0) rfalse;\
426 { if (identifier<64 || identifier>=72) rfalse;\
429 otherid = identifier | $8000;\
432 { if (i-->0 == identifier or otherid)\
440 /* RL__Pr: read the property length of an individual property value,
441 returning 0 if it isn't provided by the given object */
445 if (identifier<64 && identifier>0) return obj.#identifier;\
446 x = obj..&identifier;\
448 if (identifier&$C000==$4000)\
449 switch (((x-1)->0)&$C0)\
450 { 0: return 1; $40: return 2; $80: return ((x-1)->0)&$3F; }\
452 ]", "", "", "", "", ""
455 /* RA__Sc: implement the "superclass" (::) operator,
456 returning an identifier */
459 "cla identifier otherid i j k;\
460 if (cla notin 1 && cla > 4)\
461 { RT__Err(\"be a '::' superclass\", cla, -1); rfalse; }\
462 if (self ofclass cla) otherid = identifier | $8000;\
463 for (j=0: #classes_table-->j ~= 0: j++)\
464 { if (cla==#classes_table-->j)\
465 { if (identifier < 64) return $4000 + identifier*$100 + j;\
466 if (cla.&3 == 0) break;\
469 { if (i-->0 == identifier or otherid)\
470 return $8000 + k*$100 + j;\
477 RT__Err(\"make use of\", cla, identifier);\
482 /* OP__Pr: test whether or not given object provides individual
483 property with the given identifier code */
487 if (obj<1 || obj > (#largest_object-255))\
488 { if (identifier ~= print or print_to_array or call) rfalse;\
489 switch(Z__Region(obj))\
490 { 2: if (identifier == call) rtrue;\
491 3: if (identifier == print or print_to_array) rtrue;\
496 { if (obj.&identifier ~= 0) rtrue;\
499 if (obj..&identifier ~= 0) rtrue;\
500 if (identifier<72 && obj in 1) rtrue;\
505 /* OC__Cl: test whether or not given object is of the given class */
509 if (obj<1 || obj > (#largest_object-255))\
510 { if (cla ~= 3 or 4) rfalse;\
511 if (Z__Region(obj) == cla-1) rtrue;\
516 if (obj in 1) rtrue;\
518 } else if (cla == 2) {\
520 if (obj in 1) rfalse;\
522 } else if (cla == 3 or 4) {\
525 "if (cla notin 1) { RT__Err(\"apply 'ofclass' for\", cla, -1);rfalse;}\
526 @get_prop_addr obj 2 -> a;\
528 @get_prop_len a -> n;\
529 for (j=0: j<n/2: j++)\
530 { if (a-->j == cla) rtrue;\
535 { /* Copy__Primitive: routine to "deep copy" objects */
538 "o1 o2 a1 a2 n m l size identifier;\
540 { if (o2 has n) give o1 n;\
543 for (n=1:n<64:n++) if (n~=2 or 3)\
544 { a1 = o1.&n; a2 = o2.&n; size = o1.#n;\
545 if (a1~=0 && a2~=0 && size==o2.#n)\
546 { for (m=0:m<size:m++) a1->m=a2->m;\
549 "if (o1.&3 == 0 || o2.&3 == 0) return;\
550 for (n=o2.3: n-->0 ~= 0: n = n + size + 3)\
551 { identifier = n-->0;\
553 for (m=o1.3: m-->0 ~= 0: m = m + m->2 + 3)\
554 if ((identifier & $7fff == (m-->0) & $7fff) && size==m->2)\
555 for (l=3: l<size+3: l++) m->l = n->l;\
559 { /* RT__Err: for run-time errors occurring in the above: e.g.,
560 an attempt to write to a non-existent individual
564 "crime obj id size p q;\
565 print \"^[** Programming error: \";\
566 if (crime<0) jump RErr;\
567 if (crime==1) { print \"class \"; @print_obj obj;\
568 \": 'create' can have 0 to 3 parameters only **]\";}\
569 if (crime == 32) \"objectloop broken because the object \",\
570 (name) obj, \" was moved while the loop passed through it **]\";\
571 if (crime == 33) \"tried to print (char) \", obj,\
572 \", which is not a valid ZSCII character code for output **]\";\
573 if (crime == 34) \"tried to print (address) on something not the \",\
574 \"byte address of a string **]\";\
575 if (crime == 35) \"tried to print (string) on something not a \",\
577 if (crime == 36) \"tried to print (object) on something not an \",\
578 \"object or class **]\";",
579 "if (crime < 32) { print \"tried to \";\
580 if (crime >= 28) { if (crime==28 or 29) print \"read from \";\
581 else print \"write to \";\
582 if (crime==29 or 31) print \"-\"; print \"->\", obj,\
583 \" in the\"; switch(size&7){0,1:q=0; 2:print \" string\";\
584 q=1; 3:print \" table\";q=1; 4:print \" buffer\";q=WORDSIZE;} \
585 if(size&16) print\" (->)\"; if(size&8) print\" (-->)\";\
586 \" array ~\", (string) #array_names_offset-->p,\
587 \"~, which has entries \", q, \" up to \",id,\" **]\"; }\
588 if (crime >= 24 && crime <=27) { if (crime<=25) print \"read\";\
589 else print \"write\"; print \" outside memory using \";\
590 switch(crime) { 24,26:\"-> **]\"; 25,27:\"--> **]\"; } }\
591 if (crime < 4) print \"test \"; else\
592 if (crime < 12 || crime > 20) print \"find the \"; else\
593 if (crime < 14) print \"use \";\
594 if (crime==20) \"divide by zero **]\"; print \"~\";\
596 2: print \"in~ or ~notin\"; 3: print \"has~ or ~hasnt\";\
597 4: print \"parent\"; 5: print \"eldest\"; 6: print \"child\";\
598 7: print \"younger\"; 8: print \"sibling\"; 9: print \"children\";\
599 10: print \"youngest\"; 11: print \"elder\";\
600 12: print \"objectloop\"; 13: print \"}~ at end of ~objectloop\";\
601 14: \"give~ an attribute to \", (name) obj, \" **]\";\
602 15: \"remove~ \", (name) obj, \" **]\";",
603 "16,17,18: print \"move~ \", (name) obj, \" to \", (name) id;\
604 if (crime==18) { print \", which would make a loop: \",(name) obj;\
605 p=id; if (p==obj) p=obj;\
606 else do { print \" in \", (name) p; p=parent(p);} until (p==obj);\
607 \" in \", (name) p, \" **]\"; }\
608 \" **]\"; 19: \"give~ or test ~has~ or ~hasnt~ with a non-attribute"\
609 " on the object \",(name) obj,\" **]\";\
610 21: print \".&\"; 22: print \".#\"; 23: print \".\"; }\
611 \"~ of \", (name) obj, \" **]\"; }",
612 ".RErr; if (obj>=0 && obj<=(#largest_object-255)) {\
613 if (obj && obj in Class) print \"class \";\
614 if (obj) @print_obj obj;else print \"nothing\";print\" \";}\
615 print \"(object number \", obj, \") \";\
616 if (id<0) print \"is not of class \", (name) -id;",
617 "else if (size) print \"has a property \", (property) id,\
618 \", but it is longer than 2 bytes so you cannot use ~.~\";\
620 { print \" has no property \", (property) id;\
621 p = #identifiers_table;\
623 if (id<0 || id>=size)\
624 print \" (and nor has any other object)\";\
626 print \" to \", (string) crime, \" **]^\";\
629 { /* Z__Region: Determines whether a value is:
633 0 none of the above */
637 if (addr==0 or -1) rfalse;\
639 #IfV5; #iftrue (#version_number == 6) || (#version_number == 7);\
640 @log_shift addr $FFFF -> top; #Endif; #Endif;\
641 if (Unsigned__Compare(top, $001A-->0) >= 0) rfalse;\
642 if (addr>=1 && addr<=(#largest_object-255)) rtrue;\
643 #iftrue #oddeven_packing;\
644 @test addr 1 ?~NotString;\
645 if (Unsigned__Compare(addr, #strings_offset)<0) rfalse;\
648 if (Unsigned__Compare(addr, #code_offset)<0) rfalse;\
651 if (Unsigned__Compare(addr, #strings_offset)>=0) return 3;\
652 if (Unsigned__Compare(addr, #code_offset)>=0) return 2;\
655 ]", "", "", "", "", ""
657 { /* Unsigned__Compare: returns 1 if x>y, 0 if x=y, -1 if x<y */
662 if (x<0 && y>=0) return 1;\
663 if (x>=0 && y<0) return -1;\
664 u = x&$7fff; v= y&$7fff;\
667 ]", "", "", "", "", ""
669 { /* Meta__class: returns the metaclass of an object */
673 switch(Z__Region(obj))\
674 { 2: return Routine;\
676 1: if (obj in 1 || obj <= 4) return Class;\
680 ]", "", "", "", "", ""
682 { /* CP__Tab: searches a common property table for the given
683 identifier, thus imitating the get_prop_addr opcode.
684 Returns 0 if not provided, except:
685 if the identifier supplied is -1, then returns
686 the address of the first byte after the table. */
690 while ((n=0->x) ~= 0)\
691 { if (n & $80) { x++; l = (0->x) & $3f; }\
692 else { if (n & $40) l=2; else l=1; }\
694 if ((n & $3f) == id) return x;\
697 if (id<0) return x+1; rfalse; ]", "", "", "", "", ""
699 { /* Cl__Ms: the five message-receiving properties of Classes */
702 "obj id y a b c d x;\
705 if (children(obj)<=1) rfalse; x=child(obj);\
706 remove x; if (x provides create) { if (y==0) x..create();\
707 if (y==1) x..create(a); if (y==2) x..create(a,b);\
708 if (y>3) RT__Err(1,obj); if (y>=3) x..create(a,b,c);}\
711 if (~~(a ofclass obj))\
712 { RT__Err(\"recreate\", a, -obj); rfalse; }\
713 Copy__Primitive(a, child(obj));\
714 if (a provides create) { if (y==1) a..create();\
715 if (y==2) a..create(b); if (y==3) a..create(b,c);\
716 if (y>4) RT__Err(1,obj); if (y>=4) a..create(b,c,d);\
719 if (~~(a ofclass obj))\
720 { RT__Err(\"destroy\", a, -obj); rfalse; }\
721 if (a provides destroy) a..destroy();\
722 Copy__Primitive(a, child(obj));\
723 move a to obj; rfalse;\
725 return children(obj)-1;",
727 if (~~(a ofclass obj))\
728 { RT__Err(\"copy\", a, -obj); rfalse; }\
729 if (~~(b ofclass obj))\
730 { RT__Err(\"copy\", b, -obj); rfalse; }\
731 Copy__Primitive(a, b); rfalse;\
735 { /* RT__ChT: check at run-time that a proposed object move is legal
736 cause error and do nothing if not; otherwise move */
740 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
741 return RT__Err(16,obj1,obj2);\
742 if (obj2<5 || obj2>(#largest_object-255) || obj2 in 1)\
743 return RT__Err(17,obj1,obj2);",
744 "x=obj2; while (x~=0) { if (x==obj1) return RT__Err(18,obj1,obj2); \
747 if (obj1 has infix__watching\
748 || obj2 has infix__watching || (debug_flag & 15))\
749 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
750 #ifnot; #ifdef DEBUG;\
751 if (debug_flag & 15)\
752 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
754 @insert_obj obj1 obj2; ]", "", "", "", ""
756 { /* RT__ChR: check at run-time that a proposed object remove is legal
757 cause error and do nothing if not; otherwise remove */
761 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
762 return RT__Err(15,obj1);",
764 if (obj1 has infix__watching || (debug_flag & 15))\
765 print \"[Removing \", (name) obj1, \"]^\";\
766 #ifnot; #ifdef DEBUG;\
767 if (debug_flag & 15)\
768 print \"[Removing \", (name) obj1, \"]^\";\
770 @remove_obj obj1; ]", "", "", "", ""
772 { /* RT__ChG: check at run-time that a proposed attr give is legal
773 cause error and do nothing if not; otherwise give */
777 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
778 return RT__Err(14,obj1); if (a<0 || a>=48) return RT__Err(19,obj1);\
779 if (obj1 has a) return;",
781 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
782 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
783 #ifnot; #ifdef DEBUG;\
784 if (a ~= workflag && debug_flag & 15)\
785 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
787 @set_attr obj1 a; ]", "", "", "", ""
789 { /* RT__ChGt: check at run-time that a proposed attr give ~ is legal
790 cause error and do nothing if not; otherwise give */
794 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
795 return RT__Err(14,obj1); if (a<0 || a>=48) return RT__Err(19,obj1);\
796 if (obj1 hasnt a) return;",
798 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
799 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
800 #ifnot; #ifdef DEBUG;\
801 if (a ~= workflag && debug_flag & 15)\
802 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
804 @clear_attr obj1 a; ]", "", "", "", ""
806 { /* RT__ChPS: check at run-time that a proposed property set is legal
807 cause error and do nothing if not; otherwise make it */
811 if (obj<5 || obj>(#largest_object-255) || obj in 1 || obj.&prop==0 || (size=obj.#prop)>2 )\
812 return RT__Err(\"set\", obj, prop, size);\
813 @put_prop obj prop val;",
815 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,prop,val);\
816 #ifnot; #ifdef DEBUG;\
817 if (debug_flag & 15) RT__TrPS(obj,prop,val);\
819 return val; ]", "", "", "", ""
821 { /* RT__ChPR: check at run-time that a proposed property read is legal
822 cause error and return 0 if not; otherwise read it */
826 if (obj<5 || obj>(#largest_object-255) || (size=obj.#prop)>2)\
827 {RT__Err(\"read\", obj, prop, size); obj=2;}\
828 @get_prop obj prop -> val;",
829 "return val; ]", "", "", "", ""
831 { /* RT__TrPS: trace property settings */
835 print \"[Setting \",(name) obj,\".\",(property) prop,\
836 \" to \",val,\"]^\"; ]",
839 { /* RT__ChLDB: check at run-time that it's safe to load a byte
840 and return the byte */
844 a=base+offset;if (Unsigned__Compare(a,#readable_memory_offset)>=0)\
845 return RT__Err(24);",
846 "@loadb base offset -> val;return val; ]", "", "", "", ""
848 { /* RT__ChLDW: check at run-time that it's safe to load a word
849 and return the word */
853 a=base+2*offset;if (Unsigned__Compare(a,#readable_memory_offset)>=0)\
854 return RT__Err(25);",
855 "@loadw base offset -> val;return val; ]", "", "", "", ""
857 { /* RT__ChSTB: check at run-time that it's safe to store a byte
861 "base offset val a f;\
863 if (Unsigned__Compare(a,#array__start)>=0\
864 && Unsigned__Compare(a,#array__end)<0) f=1; else\
865 if (Unsigned__Compare(a,#cpv__start)>=0\
866 && Unsigned__Compare(a,#cpv__end)<0) f=1; else\
867 if (Unsigned__Compare(a,#ipv__start)>=0\
868 && Unsigned__Compare(a,#ipv__end)<0) f=1; else\
870 if (f==0) return RT__Err(26);",
871 "@storeb base offset val; ]", "", "", "", ""
873 { /* RT__ChSTW: check at run-time that it's safe to store a word
877 "base offset val a f;\
879 if (Unsigned__Compare(a,#array__start)>=0\
880 && Unsigned__Compare(a,#array__end)<0) f=1; else\
881 if (Unsigned__Compare(a,#cpv__start)>=0\
882 && Unsigned__Compare(a,#cpv__end)<0) f=1; else\
883 if (Unsigned__Compare(a,#ipv__start)>=0\
884 && Unsigned__Compare(a,#ipv__end)<0) f=1; else\
886 if (f==0) return RT__Err(27);",
887 "@storew base offset val; ]", "", "", "", ""
889 { /* RT__ChPrintC: check at run-time that it's safe to print (char)
894 if (c==0 or 9 or 11 or 13) fl=1;\
895 if (c>=32 && c<=126) fl=1; if (c>=155 && c<=251) fl=1;\
896 if (fl==0) return RT__Err(33,c);",
897 "@print_char c; ]", "", "", "", ""
899 { /* RT__ChPrintA: check at run-time that it's safe to print (address)
904 if (Unsigned__Compare(a, #readable_memory_offset)>=0)\
905 return RT__Err(34);",
906 "@print_addr a; ]", "", "", "", ""
908 { /* RT__ChPrintS: check at run-time that it's safe to print (string)
913 if (Z__Region(a)~=3) return RT__Err(35);",
914 "@print_paddr a; ]", "", "", "", ""
916 { /* RT__ChPrintO: check at run-time that it's safe to print (object)
921 if (Z__Region(a)~=1) return RT__Err(36);",
922 "@print_obj a; ]", "", "", "", ""
926 static VeneerRoutine VRs_g[VENEER_ROUTINES] =
929 /* Box__Routine: Display the given array of text as a box quote.
930 This is a very simple implementation; the library should provide
937 for (ix=0 : ix<arr-->0 : ix++) {\
938 print (string) arr-->(ix+1);\
942 ]", "", "", "", "", ""
945 /* This batch of routines is expected to be defined (rather better) by
946 the Inform library: these minimal forms here are provided to prevent
947 tiny non-library-using programs from failing to compile when certain
948 legal syntaxes (such as <<Action a b>>;) are used. */
951 "a b c d; print \"Action <\", a, \" \", b, \" \", c;\
952 if (d) print \", \", d; print \">^\";\
953 ]", "", "", "", "", ""
956 "obj; print \"the \", obj; ]", "", "", "", "", ""
959 "obj; print \"a \", obj; ]", "", "", "", "", ""
962 "obj; print \"The \", obj; ]", "", "", "", "", ""
965 "obj; print \"A \", obj; ]", "", "", "", "", ""
968 "obj q; switch(metaclass(obj))\
969 { 0: print \"nothing\";\
970 Object: q = obj-->GOBJFIELD_NAME; @streamstr q;\
971 Class: print \"class \"; q = obj-->GOBJFIELD_NAME; @streamstr q;\
972 Routine: print \"(routine at \", obj, \")\";\
973 String: print \"(string at \", obj, \")\";\
974 } ]", "", "", "", "", ""
977 "obj; print obj; ]", "", "", "", "", ""
980 /* Print__PName: Print the name of a property.
983 "prop ptab cla maxcom minind maxind str;\
984 if (prop & $FFFF0000) {\
985 cla = #classes_table-->(prop & $FFFF);\
986 print (name) cla, \"::\";\
987 @ushiftr prop 16 prop;\
989 ptab = #identifiers_table;\
991 minind = INDIV_PROP_START;\
992 maxind = minind + ptab-->3;\
994 if (prop >= 0 && prop < maxcom) {\
995 str = (ptab-->0)-->prop;\
997 else if (prop >= minind && prop < maxind) {\
998 str = (ptab-->2)-->(prop-minind);\
1001 print (string) str;\
1003 print \"<number \", prop, \">\";\
1004 ]", "", "", "", "", ""
1007 /* The remaining routines make up the run-time half of the object
1008 orientation system, and need never be present for Inform 5 programs. */
1011 /* WV__Pr: Write a value to the property for the given object.
1017 RT__Err(\"write\", obj, id);\
1022 ]", "", "", "", "", ""
1026 /* RV__Pr: Read a value to the property for the given object.
1032 if (id > 0 && id < INDIV_PROP_START) {\
1033 return #cpv__start-->id;\
1035 RT__Err(\"read\", obj, id);\
1039 ]", "", "", "", "", ""
1042 /* CA__Pr: Call, that is, print-or-run-or-read, a property:
1043 this exactly implements obj..prop(...). Note that
1044 classes (members of Class) have 5 built-in properties
1045 inherited from Class: create, recreate, destroy,
1046 remaining and copy. Implementing these here prevents
1047 the need for a full metaclass inheritance scheme.
1050 "_vararg_count obj id zr s s2 z addr len m val;\
1053 _vararg_count = _vararg_count - 2;\
1054 zr = Z__Region(obj);\
1057 s = sender; sender = self; self = obj;\
1058 #ifdef action; sw__var=action; #endif;\
1059 @call obj _vararg_count z;\
1060 self = sender; sender = s;\
1067 @streamstr obj; rtrue;\
1069 if (id == print_to_array) {\
1070 if (_vararg_count >= 2) {\
1075 RT__Err(37); rfalse;\
1078 s = glk($0043, m+4, len-4, 1, 0);",
1083 @copy $ffffffff sp;\
1097 #ifdef DEBUG;#ifdef InformLibrary;\
1098 if (debug_flag & 1 ~= 0) {\
1100 print \"[ ~\", (name) obj, \"~.\", (property) id, \"(\";\
1101 @stkcopy _vararg_count;\
1102 for (val=0 : val < _vararg_count : val++) {\
1103 if (val) print \", \";\
1110 if (obj in Class) {\
1113 return Cl__Ms(obj, id);\
1117 return Cl__Ms(obj, id, m, val);\
1118 create, destroy, recreate:\
1119 m = _vararg_count+2;\
1122 @call Cl__Ms m val;\
1128 if (id > 0 && id < INDIV_PROP_START) {\
1129 addr = #cpv__start + 4*id;\
1139 for (m=0 : 4*m<len : m++) {\
1141 if (val == -1) rfalse;\
1142 switch (Z__Region(val)) {\
1144 s = sender; sender = self; self = obj; s2 = sw__var;\
1146 if (id==life) sw__var=reason_code; else sw__var=action;\
1148 " @stkcopy _vararg_count;\
1149 @call val _vararg_count z;\
1150 self = sender; sender = s; sw__var = s2;\
1151 if (z ~= 0) return z;\
1162 RT__Err(\"send message\", obj, id);\
1167 /* IB__Pr: ++(individual property) */
1171 x = obj.&identifier;\
1172 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
1174 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)+1);\
1175 #ifnot; #ifdef DEBUG;\
1176 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
1179 ]", "", "", "", "", ""
1182 /* IA__Pr: (individual property)++ */
1186 x = obj.&identifier;\
1187 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
1189 if (obj has infix__watching || (debug_flag & 15))\
1190 RT__TrPS(obj,identifier,(x-->0)+1);\
1191 #ifnot; #ifdef DEBUG;\
1192 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
1195 ]", "", "", "", "", ""
1198 /* DB__Pr: --(individual property) */
1202 x = obj.&identifier;\
1203 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
1205 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
1206 #ifnot; #ifdef DEBUG;\
1207 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
1210 ]", "", "", "", "", ""
1213 /* DA__Pr: (individual property)-- */
1217 x = obj.&identifier;\
1218 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
1220 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
1221 #ifnot; #ifdef DEBUG;\
1222 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
1225 ]", "", "", "", "", ""
1228 /* RA__Pr: Read the property address of a given property value.
1229 Returns zero if it isn't provided by the object. This
1230 understands all the same concerns as RL__Pr().
1233 "obj id cla prop ix;\
1234 if (id & $FFFF0000) {\
1235 cla = #classes_table-->(id & $FFFF);\
1236 if (~~(obj ofclass cla)) return 0;\
1240 prop = CP__Tab(obj, id);\
1241 if (prop==0) return 0;\
1242 if (obj in Class && cla == 0) {\
1243 if (id < INDIV_PROP_START || id >= INDIV_PROP_START+8)\
1247 @aloadbit prop 72 ix;\
1251 ]", "", "", "", "", ""
1255 /* RL__Pr: Read the property length of a given property value.
1256 Returns zero if it isn't provided by the object. This understands
1257 inherited values (of the form class::prop) as well as simple
1258 property ids and the special metaclass methods. It also knows
1259 that private properties can only be read if (self == obj).
1262 "obj id cla prop ix;\
1263 if (id & $FFFF0000) {\
1264 cla = #classes_table-->(id & $FFFF);\
1265 if (~~(obj ofclass cla)) return 0;\
1269 prop = CP__Tab(obj, id);\
1270 if (prop==0) return 0;\
1271 if (obj in Class && cla == 0) {\
1272 if (id < INDIV_PROP_START || id >= INDIV_PROP_START+8)\
1276 @aloadbit prop 72 ix;\
1280 return WORDSIZE * ix;\
1281 ]", "", "", "", "", ""
1284 /* RA__Sc: Implement the \"superclass\" (::) operator. This
1285 returns an compound property identifier, which is a
1290 if ((cla notin Class) && (cla ~= Class or String or Routine or Object)) {\
1291 RT__Err(\"be a '::' superclass\", cla, -1);\
1294 for (j=0 : #classes_table-->j ~= 0 : j++) {\
1295 if (cla == #classes_table-->j) {\
1296 return (id * $10000 + j);\
1299 RT__Err(\"make use of\", cla, id);\
1301 ]", "", "", "", "", ""
1305 /* OP__Pr: Test whether the given object provides the given property.
1306 This winds up calling RA__Pr().
1310 zr = Z__Region(obj);\
1312 if (id == print or print_to_array) rtrue;\
1316 if (id == call) rtrue;\
1319 if (zr ~= 1) rfalse;\
1320 if (id >= INDIV_PROP_START && id < INDIV_PROP_START+8) {\
1321 if (obj in Class) rtrue;\
1326 ]", "", "", "", "", ""
1329 /* OC__Cl: Test whether the given object is of the given class.
1330 (implements the OfClass operator.)
1333 "obj cla zr jx inlist inlistlen;\
1334 zr = Z__Region(obj);\
1336 if (cla == String) rtrue;\
1340 if (cla == Routine) rtrue;\
1343 if (zr ~= 1) rfalse;\
1344 if (cla == Class) {\
1346 || obj == Class or String or Routine or Object)\
1350 if (cla == Object) {\
1352 || obj == Class or String or Routine or Object)\
1356 if (cla == String or Routine) rfalse;\
1357 if (cla notin Class) {\
1358 RT__Err(\"apply 'ofclass' for\", cla, -1);\
1362 if (inlist == 0) rfalse;\
1363 inlistlen = (obj.#2) / WORDSIZE;\
1364 for (jx=0 : jx<inlistlen : jx++) {\
1365 if (inlist-->jx == cla) rtrue;\
1368 ]", "", "", "", "", ""
1372 /* Copy__Primitive: Routine to \"deep copy\" objects.
1375 "o1 o2 p1 p2 pcount i j propid proplen val pa1 pa2;\
1376 for (i=1 : i<=NUM_ATTR_BYTES : i++) {\
1379 p2 = o2-->GOBJFIELD_PROPTAB;\
1382 for (i=0 : i<pcount : i++) {\
1383 @aloads p2 0 propid;\
1384 @aloads p2 1 proplen;\
1385 p1 = CP__Tab(o1, propid);\
1388 if (proplen == val) {\
1393 for (j=0 : j<proplen : j++)\
1399 ]", "", "", "", "", ""
1401 { /* RT__Err: for run-time errors occurring in the above: e.g.,
1402 an attempt to write to a non-existent individual
1406 "crime obj id size p q;\
1407 print \"^[** Programming error: \";\
1408 if (crime<0) jump RErr;\
1409 if (crime==1) { print \"class \"; q = obj-->GOBJFIELD_NAME; @streamstr q;\
1410 \": 'create' can have 0 to 3 parameters only **]\";}\
1411 if (crime == 40) \"tried to change printing variable \",\
1412 obj, \"; must be 0 to \", #dynam_string_table-->0-1, \" **]\";\
1413 if (crime == 32) \"objectloop broken because the object \",\
1414 (name) obj, \" was moved while the loop passed through it **]\";\
1415 if (crime == 33) \"tried to print (char) \", obj,\
1416 \", which is not a valid Glk character code for output **]\";\
1417 if (crime == 34) \"tried to print (address) on something not the \",\
1418 \"address of a dict word **]\";\
1419 if (crime == 35) \"tried to print (string) on something not a \",\
1421 if (crime == 36) \"tried to print (object) on something not an \",\
1422 \"object or class **]\";\
1423 if (crime == 37) \"tried to call Glulx print_to_array with only \",\
1424 \"one argument **]\";",
1425 "if (crime < 32) { print \"tried to \";\
1426 if (crime >= 28) { if (crime==28 or 29) print \"read from \";\
1427 else print \"write to \";\
1428 if (crime==29 or 31) print \"-\"; print \"->\", obj,\
1429 \" in the\"; switch(size&7){0,1:q=0; 2:print \" string\";\
1430 q=1; 3:print \" table\";q=1; 4:print \" buffer\";q=WORDSIZE;} \
1431 if(size&16) print\" (->)\"; if(size&8) print\" (-->)\";\
1432 \" array ~\", (string) #array_names_offset-->(p+1),\
1433 \"~, which has entries \", q, \" up to \",id,\" **]\"; }\
1434 if (crime >= 24 && crime <=27) { if (crime<=25) print \"read\";\
1435 else print \"write\"; print \" outside memory using \";\
1436 switch(crime) { 24,26:\"-> **]\"; 25,27:\"--> **]\"; } }\
1437 if (crime < 4) print \"test \"; else\
1438 if (crime < 12 || crime > 20) print \"find the \"; else\
1439 if (crime < 14) print \"use \";\
1440 if (crime==20) \"divide by zero **]\"; print \"~\";\
1442 2: print \"in~ or ~notin\"; 3: print \"has~ or ~hasnt\";\
1443 4: print \"parent\"; 5: print \"eldest\"; 6: print \"child\";\
1444 7: print \"younger\"; 8: print \"sibling\"; 9: print \"children\";\
1445 10: print \"youngest\"; 11: print \"elder\";\
1446 12: print \"objectloop\"; 13: print \"}~ at end of ~objectloop\";\
1447 14: \"give~ an attribute to \", (name) obj, \" **]\";\
1448 15: \"remove~ \", (name) obj, \" **]\";",
1449 "16,17,18: print \"move~ \", (name) obj, \" to \", (name) id;\
1450 if (crime==18) { print \", which would make a loop: \",(name) obj;\
1451 p=id; if (p==obj) p=obj;\
1452 else do { print \" in \", (name) p; p=parent(p);} until (p==obj);\
1453 \" in \", (name) p, \" **]\"; }\
1454 \" **]\"; 19: \"give~ or test ~has~ or ~hasnt~ with a non-attribute"\
1455 " on the object \",(name) obj,\" **]\";\
1456 21: print \".&\"; 22: print \".#\"; 23: print \".\"; }\
1457 \"~ of \", (name) obj, \" **]\"; }",
1458 ".RErr; if (obj==0 || obj->0>=$70 && obj->0<=$7F) {\
1459 if (obj && obj in Class) print \"class \";\
1460 if (obj) print (object) obj;else print \"nothing\";print\" \";}\
1461 print \"(object number \", obj, \") \";\
1462 if (id<0) print \"is not of class \", (name) -id;",
1464 { print \" has no property \", (property) id;\
1465 p = #identifiers_table;\
1466 size = INDIV_PROP_START + p-->3;\
1467 if (id<0 || id>=size)\
1468 print \" (and nor has any other object)\";\
1470 print \" to \", (string) crime, \" **]^\";\
1474 /* Z__Region: Determines whether a value is:
1482 if (addr<36) rfalse;\
1483 @getmemsize endmem;\
1484 @jgeu addr endmem?outrange;\
1486 if (tb >= $E0) return 3;\
1487 if (tb >= $C0) return 2;\
1488 if (tb >= $70 && tb <= $7F && addr >= (0-->2)) return 1;\
1491 ]", "", "", "", "", ""
1493 { /* Unsigned__Compare: returns 1 if x>y, 0 if x=y, -1 if x<y */
1495 "Unsigned__Compare",
1504 ]", "", "", "", "", ""
1506 { /* Meta__class: returns the metaclass of an object */
1510 switch(Z__Region(obj))\
1511 { 2: return Routine;\
1513 1: if (obj in Class\
1514 || obj == Class or String or Routine or Object)\
1519 ]", "", "", "", "", ""
1523 /* CP__Tab: Search a property table for the given identifier.
1524 The definition here is a bit different from the Z-code veneer.
1525 This just searches the property table of obj for an entry with
1526 the given identifier. It return the address of the property
1527 entry, or 0 if nothing found. (Remember that the value returned
1528 is not the address of the property *data*; it's the structure
1529 which contains the address/length/flags.)
1532 "obj id otab max res;\
1533 if (Z__Region(obj)~=1) {RT__Err(23, obj); rfalse;}\
1534 otab = obj-->GOBJFIELD_PROPTAB;\
1535 if (otab == 0) return 0;\
1538 @binarysearch id 2 otab 10 max 0 0 res;\
1540 ]", "", "", "", "", ""
1544 /* Cl__Ms: Implements the five message-receiving properties of
1548 "_vararg_count obj id a b x y;\
1551 _vararg_count = _vararg_count - 2;\
1554 if (children(obj) <= 1) rfalse;\
1557 if (x provides create) {\
1560 y = _vararg_count + 2;\
1567 if (~~(a ofclass obj)) {\
1568 RT__Err(\"recreate\", a, -obj);\
1571 if (a provides destroy)\
1573 Copy__Primitive(a, child(obj));\
1574 if (a provides create) {\
1577 y = _vararg_count + 2;\
1584 if (~~(a ofclass obj)) {\
1585 RT__Err(\"destroy\", a, -obj);\
1588 if (a provides destroy)\
1590 Copy__Primitive(a, child(obj));\
1594 return children(obj)-1;\
1598 _vararg_count = _vararg_count - 2;\
1599 if (~~(a ofclass obj)) {\
1600 RT__Err(\"copy\", a, -obj);\
1603 if (~~(b ofclass obj)) {\
1604 RT__Err(\"copy\", b, -obj);\
1607 Copy__Primitive(a, b);\
1610 ]", "", "", "", "", ""
1613 /* RT__ChT: Check at run-time that a proposed object move is legal.
1614 Cause error and do nothing if not; otherwise move
1618 if (obj1==0 || Z__Region(obj1)~=1\
1619 || (obj1 == Class or String or Routine or Object) || obj1 in Class)\
1620 return RT__Err(16, obj1, obj2);\
1621 if (obj2==0 || Z__Region(obj2)~=1\
1622 || (obj2 == Class or String or Routine or Object) || obj2 in Class)\
1623 return RT__Err(17, obj1, obj2);\
1626 if (ix==obj1) return RT__Err(18, obj1, obj2);\
1630 if (obj1 has infix__watching\
1631 || obj2 has infix__watching || (debug_flag & 15))\
1632 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
1633 #ifnot; #ifdef DEBUG;\
1634 if (debug_flag & 15)\
1635 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
1637 OB__Move(obj1, obj2);\
1638 ]", "", "", "", "", ""
1641 /* RT__ChR: Check at run-time that a proposed object remove is legal.
1642 Cause error and do nothing if not; otherwise remove
1646 if (obj1==0 || Z__Region(obj1)~=1\
1647 || (obj1 == Class or String or Routine or Object) || obj1 in Class)\
1648 return RT__Err(15, obj1);\
1650 if (obj1 has infix__watching || (debug_flag & 15))\
1651 print \"[Removing \", (name) obj1, \"]^\";\
1652 #ifnot; #ifdef DEBUG;\
1653 if (debug_flag & 15)\
1654 print \"[Removing \", (name) obj1, \"]^\";\
1657 ]", "", "", "", "", ""
1659 { /* RT__ChG: check at run-time that a proposed attr give is legal
1660 cause error and do nothing if not; otherwise give */
1664 if (Z__Region(obj1) ~= 1) return RT__Err(14,obj1);\
1665 if (obj1 in Class || obj1 == Class or String or Routine or Object)\
1666 return RT__Err(14,obj1);\
1667 if (a<0 || a>=NUM_ATTR_BYTES*8) return RT__Err(19,obj1);\
1668 if (obj1 has a) return;",
1670 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
1671 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
1672 #ifnot; #ifdef DEBUG;\
1673 if (a ~= workflag && debug_flag & 15)\
1674 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
1676 give obj1 a; ]", "", "", "", ""
1678 { /* RT__ChGt: check at run-time that a proposed attr give ~ is legal
1679 cause error and do nothing if not; otherwise give */
1683 if (Z__Region(obj1) ~= 1) return RT__Err(14,obj1);\
1684 if (obj1 in Class || obj1 == Class or String or Routine or Object)\
1685 return RT__Err(14,obj1);\
1686 if (a<0 || a>=NUM_ATTR_BYTES*8) return RT__Err(19,obj1);\
1687 if (obj1 hasnt a) return;",
1689 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
1690 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
1691 #ifnot; #ifdef DEBUG;\
1692 if (a ~= workflag && debug_flag & 15)\
1693 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
1695 give obj1 ~a; ]", "", "", "", ""
1698 /* RT__ChPS: Check at run-time that a proposed property set is legal.
1699 Cause error and do nothing if not; otherwise make it.
1703 if (obj==0 || Z__Region(obj)~=1\
1704 || (obj == Class or String or Routine or Object) || obj in Class)\
1705 return RT__Err(\"set\", obj, prop);\
1706 res = WV__Pr(obj, prop, val);\
1708 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,prop,val);\
1709 #ifnot; #ifdef DEBUG;\
1710 if (debug_flag & 15) RT__TrPS(obj,prop,val);\
1713 ]", "", "", "", "", ""
1715 { /* RT__ChPR: check at run-time that a proposed property read is legal.
1716 cause error and return 0 if not; otherwise read it */
1719 if (obj==0 or Class or String or Routine or Object || Z_Region(obj)~=1 )\
1720 {RT__Err(\"read\", obj, prop); obj=2;}\
1721 val = RV__Pr(obj, prop);",
1722 "return val; ]", "", "", "", ""
1724 { /* RT__TrPS: trace property settings */
1728 print \"[Setting \",(name) obj,\".\",(property) prop,\
1729 \" to \",val,\"]^\"; ]",
1733 /* RT__ChLDB: Check at run-time that it's safe to load a byte
1734 and return the byte.
1737 "base offset a b val;\
1740 if (Unsigned__Compare(a, b) >= 0)\
1741 return RT__Err(24);\
1742 @aloadb base offset val;\
1744 ]", "", "", "", "", ""
1748 /* RT__ChLDW: Check at run-time that it's safe to load a word
1752 "base offset a b val;\
1753 a=base+WORDSIZE*offset;\
1755 if (Unsigned__Compare(a, b) >= 0)\
1756 return RT__Err(25);\
1757 @aload base offset val;\
1759 ]", "", "", "", "", ""
1763 /* RT__ChSTB: Check at run-time that it's safe to store a byte
1767 "base offset val a b;\
1770 if (Unsigned__Compare(a, b) >= 0) jump ChSTB_Fail;\
1772 if (Unsigned__Compare(a, b) < 0) jump ChSTB_Fail;\
1773 @astoreb base offset val;\
1776 return RT__Err(26);\
1777 ]", "", "", "", "", ""
1781 /* RT__ChSTW: Check at run-time that it's safe to store a word
1785 "base offset val a b;\
1786 a=base+WORDSIZE*offset;\
1788 if (Unsigned__Compare(a, b) >= 0) jump ChSTW_Fail;\
1790 if (Unsigned__Compare(a, b) < 0) jump ChSTW_Fail;\
1791 @astore base offset val;\
1794 return RT__Err(27);\
1795 ]", "", "", "", "", ""
1799 /* RT__ChPrintC: Check at run-time that it's safe to print (char)
1804 if (c<10 || (c>10 && c<32) || (c>126 && c<160))\
1805 return RT__Err(33,c);\
1810 ]", "", "", "", "", ""
1813 /* RT__ChPrintA: Check at run-time that it's safe to print (address)
1819 return RT__Err(34);\
1820 @getmemsize endmem;\
1821 if (Unsigned__Compare(addr, endmem) >= 0)\
1822 return RT__Err(34);\
1823 if (addr->0 ~= $60)\
1824 return RT__Err(34);\
1826 ]", "", "", "", "", ""
1829 /* Check at run-time that it's safe to print (string) and do so.
1833 if (Z__Region(str) ~= 3)\
1834 return RT__Err(35);\
1836 ]", "", "", "", "", ""
1839 /* Check at run-time that it's safe to print (object) and do so.
1843 if (Z__Region(obj) ~= 1)\
1844 return RT__Err(36);\
1845 @aload obj GOBJFIELD_NAME sp; @streamstr sp;\
1846 ]", "", "", "", "", ""
1849 /* OB__Move: Move an object within the object tree. This does no
1850 more error checking than the Z-code \"move\" opcode.
1853 "obj dest par chi sib;\
1854 par = obj-->GOBJFIELD_PARENT;\
1856 chi = par-->GOBJFIELD_CHILD;\
1858 par-->GOBJFIELD_CHILD = obj-->GOBJFIELD_SIBLING;\
1862 sib = chi-->GOBJFIELD_SIBLING;\
1867 chi-->GOBJFIELD_SIBLING = obj-->GOBJFIELD_SIBLING;\
1870 obj-->GOBJFIELD_SIBLING = dest-->GOBJFIELD_CHILD;\
1871 obj-->GOBJFIELD_PARENT = dest;\
1872 dest-->GOBJFIELD_CHILD = obj;\
1874 ]", "", "", "", "", ""
1878 /* OB__Remove: Remove an object from the tree. This does no
1879 more error checking than the Z-code \"remove\" opcode.
1883 par = obj-->GOBJFIELD_PARENT;\
1886 chi = par-->GOBJFIELD_CHILD;\
1888 par-->GOBJFIELD_CHILD = obj-->GOBJFIELD_SIBLING;\
1892 sib = chi-->GOBJFIELD_SIBLING;\
1897 chi-->GOBJFIELD_SIBLING = obj-->GOBJFIELD_SIBLING;\
1899 obj-->GOBJFIELD_SIBLING = 0;\
1900 obj-->GOBJFIELD_PARENT = 0;\
1902 ]", "", "", "", "", ""
1906 /* Print__Addr: Handle the print (address) statement. In Glulx,
1907 this behaves differently than on the Z-machine; it can *only*
1908 print dictionary words.
1912 if (addr->0 ~= $60) {\
1913 print \"(\", addr, \": not dict word)\";\
1916 for (ix=1 : ix <= DICT_WORD_SIZE : ix++) {\
1917 #ifndef DICT_IS_UNICODE;\
1922 if (ch == 0) return;\
1925 ]", "", "", "", "", ""
1929 /* Glk__Wrap: This is a wrapper for the @glk opcode. It just passes
1930 all its arguments into the Glk dispatcher, and returns the Glk
1934 "_vararg_count callid retval;\
1936 _vararg_count = _vararg_count - 1;\
1937 @glk callid _vararg_count retval;\
1939 ]", "", "", "", "", ""
1943 /* Dynam__String: Set dynamic string (printing variable) num to the
1944 given val, which can be any string or function.
1948 if (num < 0 || num >= #dynam_string_table-->0)\
1949 return RT__Err(40, num);\
1950 (#dynam_string_table)-->(num+1) = val;\
1951 ]", "", "", "", "", ""
1957 static void mark_as_needed_z(int code)
1960 if (veneer_routine_needs_compilation[code] == VR_UNUSED)
1961 { veneer_routine_needs_compilation[code] = VR_CALLED;
1962 /* Here each routine must mark every veneer routine it explicitly
1966 mark_as_needed_z(RT__TrPS_VR);
1967 mark_as_needed_z(RT__Err_VR);
1970 mark_as_needed_z(RT__Err_VR);
1973 mark_as_needed_z(Z__Region_VR);
1974 mark_as_needed_z(Cl__Ms_VR);
1975 mark_as_needed_z(RT__Err_VR);
1981 mark_as_needed_z(RT__Err_VR);
1982 mark_as_needed_z(RT__TrPS_VR);
1985 mark_as_needed_z(CP__Tab_VR);
1988 mark_as_needed_z(RT__Err_VR);
1991 mark_as_needed_z(Z__Region_VR);
1994 mark_as_needed_z(Z__Region_VR);
1995 mark_as_needed_z(RT__Err_VR);
1998 mark_as_needed_z(Unsigned__Compare_VR);
2001 mark_as_needed_z(Z__Region_VR);
2004 mark_as_needed_z(RT__Err_VR);
2005 mark_as_needed_z(Copy__Primitive_VR);
2012 mark_as_needed_z(RT__Err_VR);
2015 mark_as_needed_z(RT__Err_VR);
2016 mark_as_needed_z(RT__TrPS_VR);
2022 mark_as_needed_z(Unsigned__Compare_VR);
2023 mark_as_needed_z(RT__Err_VR);
2025 case RT__ChPrintC_VR:
2026 mark_as_needed_z(RT__Err_VR);
2028 case RT__ChPrintA_VR:
2029 mark_as_needed_z(Unsigned__Compare_VR);
2030 mark_as_needed_z(RT__Err_VR);
2032 case RT__ChPrintS_VR:
2033 case RT__ChPrintO_VR:
2034 mark_as_needed_z(RT__Err_VR);
2035 mark_as_needed_z(Z__Region_VR);
2041 static void mark_as_needed_g(int code)
2044 if (veneer_routine_needs_compilation[code] == VR_UNUSED)
2045 { veneer_routine_needs_compilation[code] = VR_CALLED;
2046 /* Here each routine must mark every veneer routine it explicitly
2050 case PrintShortName_VR:
2051 mark_as_needed_g(Metaclass_VR);
2053 case Print__Pname_VR:
2054 mark_as_needed_g(PrintShortName_VR);
2057 mark_as_needed_g(RA__Pr_VR);
2058 mark_as_needed_g(RT__TrPS_VR);
2059 mark_as_needed_g(RT__Err_VR);
2062 mark_as_needed_g(RA__Pr_VR);
2063 mark_as_needed_g(RT__Err_VR);
2066 mark_as_needed_g(RA__Pr_VR);
2067 mark_as_needed_g(RL__Pr_VR);
2068 mark_as_needed_g(PrintShortName_VR);
2069 mark_as_needed_g(Print__Pname_VR);
2070 mark_as_needed_g(Z__Region_VR);
2071 mark_as_needed_g(Cl__Ms_VR);
2072 mark_as_needed_g(Glk__Wrap_VR);
2073 mark_as_needed_g(RT__Err_VR);
2079 mark_as_needed_g(RT__Err_VR);
2080 mark_as_needed_g(RT__TrPS_VR);
2083 mark_as_needed_g(OC__Cl_VR);
2084 mark_as_needed_g(CP__Tab_VR);
2087 mark_as_needed_g(OC__Cl_VR);
2088 mark_as_needed_g(CP__Tab_VR);
2091 mark_as_needed_g(OC__Cl_VR);
2092 mark_as_needed_g(RT__Err_VR);
2095 mark_as_needed_g(RA__Pr_VR);
2096 mark_as_needed_g(Z__Region_VR);
2099 mark_as_needed_g(RA__Pr_VR);
2100 mark_as_needed_g(RL__Pr_VR);
2101 mark_as_needed_g(Z__Region_VR);
2102 mark_as_needed_g(RT__Err_VR);
2104 case Copy__Primitive_VR:
2105 mark_as_needed_g(CP__Tab_VR);
2108 mark_as_needed_g(Unsigned__Compare_VR);
2112 mark_as_needed_g(Z__Region_VR);
2115 mark_as_needed_g(OC__Cl_VR);
2116 mark_as_needed_g(OP__Pr_VR);
2117 mark_as_needed_g(RT__Err_VR);
2118 mark_as_needed_g(Copy__Primitive_VR);
2119 mark_as_needed_g(OB__Remove_VR);
2120 mark_as_needed_g(OB__Move_VR);
2124 mark_as_needed_g(RT__Err_VR);
2127 mark_as_needed_g(RT__Err_VR);
2128 mark_as_needed_g(Z__Region_VR);
2129 mark_as_needed_g(OB__Remove_VR);
2132 mark_as_needed_g(RT__Err_VR);
2133 mark_as_needed_g(Z__Region_VR);
2134 mark_as_needed_g(OB__Move_VR);
2137 mark_as_needed_g(RT__Err_VR);
2138 mark_as_needed_g(RT__TrPS_VR);
2139 mark_as_needed_g(WV__Pr_VR);
2142 mark_as_needed_g(RT__Err_VR);
2143 mark_as_needed_g(RV__Pr_VR); return;
2148 mark_as_needed_g(Unsigned__Compare_VR);
2149 mark_as_needed_g(RT__Err_VR);
2151 case RT__ChPrintC_VR:
2152 mark_as_needed_g(RT__Err_VR);
2154 case RT__ChPrintA_VR:
2155 mark_as_needed_g(Unsigned__Compare_VR);
2156 mark_as_needed_g(RT__Err_VR);
2157 mark_as_needed_g(Print__Addr_VR);
2159 case RT__ChPrintS_VR:
2160 case RT__ChPrintO_VR:
2161 mark_as_needed_g(RT__Err_VR);
2162 mark_as_needed_g(Z__Region_VR);
2164 case Print__Addr_VR:
2165 mark_as_needed_g(RT__Err_VR);
2167 case Dynam__String_VR:
2168 mark_as_needed_g(RT__Err_VR);
2174 extern assembly_operand veneer_routine(int code)
2175 { assembly_operand AO;
2177 INITAOTV(&AO, LONG_CONSTANT_OT, code);
2178 AO.marker = VROUTINE_MV;
2179 mark_as_needed_z(code);
2182 INITAOTV(&AO, CONSTANT_OT, code);
2183 AO.marker = VROUTINE_MV;
2184 mark_as_needed_g(code);
2189 extern char *veneer_routine_name(int code)
2191 if (code < 0 || code >= VENEER_ROUTINES) {
2195 return VRs_z[code].name;
2198 return VRs_g[code].name;
2202 static void compile_symbol_table_routine(void)
2203 { int32 j, nl, arrays_l, routines_l, constants_l;
2204 assembly_operand AO, AO2, AO3;
2206 /* Assign local var names for the benefit of the debugging information
2207 file. (We don't set local_variable.keywords because we're not
2208 going to be parsing any code.) */
2209 strcpy(local_variable_names[0].text, "dummy1");
2210 strcpy(local_variable_names[1].text, "dummy2");
2212 veneer_mode = TRUE; j = symbol_index("Symb__Tab", -1);
2214 assemble_routine_header(2, FALSE, "Symb__Tab", FALSE, j),
2216 symbols[j].flags |= SYSTEM_SFLAG + USED_SFLAG;
2217 if (trace_fns_setting==3) symbols[j].flags |= STAR_SFLAG;
2221 if (define_INFIX_switch == FALSE)
2222 { assemblez_0(rfalse_zc);
2223 variables[1].usage = TRUE;
2224 variables[2].usage = TRUE;
2225 assemble_routine_end(FALSE, null_debug_locations);
2226 veneer_mode = FALSE;
2230 INITAOTV(&AO, VARIABLE_OT, 1);
2231 INITAOT(&AO2, SHORT_CONSTANT_OT);
2232 INITAOT(&AO3, LONG_CONSTANT_OT);
2234 arrays_l = next_label++;
2235 routines_l = next_label++;
2236 constants_l = next_label++;
2238 sequence_point_follows = FALSE;
2240 assemblez_2_branch(je_zc, AO, AO2, arrays_l, TRUE);
2241 sequence_point_follows = FALSE;
2243 assemblez_2_branch(je_zc, AO, AO2, routines_l, TRUE);
2244 sequence_point_follows = FALSE;
2246 assemblez_2_branch(je_zc, AO, AO2, constants_l, TRUE);
2247 sequence_point_follows = FALSE;
2248 assemblez_0(rtrue_zc);
2250 assemble_label_no(arrays_l);
2252 for (j=0; j<no_arrays; j++)
2254 if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
2255 else AO2.type = LONG_CONSTANT_OT;
2257 sequence_point_follows = FALSE;
2258 assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
2259 AO3.value = arrays[j].size;
2261 assemblez_store(temp_var2, AO3);
2262 AO3.value = arrays[j].type;
2263 if (symbols[arrays[j].symbol].flags & (INSF_SFLAG+SYSTEM_SFLAG))
2264 AO3.value = AO3.value + 16;
2266 assemblez_store(temp_var3, AO3);
2267 AO3.value = symbols[arrays[j].symbol].value;
2268 AO3.marker = (!arrays[j].loc ? ARRAY_MV : STATIC_ARRAY_MV);
2269 assemblez_1(ret_zc, AO3);
2270 assemble_label_no(nl);
2273 sequence_point_follows = FALSE;
2274 assemblez_0(rtrue_zc);
2275 assemble_label_no(routines_l);
2276 for (j=0; j<no_named_routines; j++)
2278 if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
2279 else AO2.type = LONG_CONSTANT_OT;
2281 sequence_point_follows = FALSE;
2282 assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
2284 if (symbols[named_routine_symbols[j]].flags
2285 & (INSF_SFLAG+SYSTEM_SFLAG)) AO3.value = 16;
2287 assemblez_store(temp_var3, AO3);
2288 AO3.value = symbols[named_routine_symbols[j]].value;
2289 AO3.marker = IROUTINE_MV;
2290 assemblez_1(ret_zc, AO3);
2291 assemble_label_no(nl);
2293 sequence_point_follows = FALSE;
2294 assemblez_0(rtrue_zc);
2296 assemble_label_no(constants_l);
2297 for (j=0, no_named_constants=0; j<no_symbols; j++)
2298 { if (((symbols[j].type == OBJECT_T) || (symbols[j].type == CLASS_T)
2299 || (symbols[j].type == CONSTANT_T))
2300 && ((symbols[j].flags & (UNKNOWN_SFLAG+ACTION_SFLAG))==0))
2301 { AO2.value = no_named_constants++;
2302 if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
2303 else AO2.type = LONG_CONSTANT_OT;
2305 sequence_point_follows = FALSE;
2306 assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
2308 if (symbols[j].type == OBJECT_T) AO3.value = 2;
2309 if (symbols[j].type == CLASS_T) AO3.value = 1;
2310 if (symbols[j].flags & (INSF_SFLAG+SYSTEM_SFLAG))
2311 AO3.value = AO3.value + 16;
2313 assemblez_store(temp_var3, AO3);
2315 AO3.marker = SYMBOL_MV;
2316 assemblez_1(ret_zc, AO3);
2317 assemble_label_no(nl);
2320 no_named_constants = 0; AO3.marker = 0;
2322 sequence_point_follows = FALSE;
2323 assemblez_0(rfalse_zc);
2324 variables[1].usage = TRUE;
2325 variables[2].usage = TRUE;
2326 assemble_routine_end(FALSE, null_debug_locations);
2327 veneer_mode = FALSE;
2331 if (define_INFIX_switch == FALSE)
2332 { assembleg_1(return_gc, zero_operand);
2333 variables[1].usage = TRUE;
2334 variables[2].usage = TRUE;
2335 assemble_routine_end(FALSE, null_debug_locations);
2336 veneer_mode = FALSE;
2340 error("*** Infix symbol-table routine is not yet implemented. ***");
2344 extern void compile_veneer(void)
2345 { int i, j, try_veneer_again;
2348 VRs = (!glulx_mode) ? VRs_z : VRs_g;
2350 /* Called at the end of the pass to insert as much of the veneer as is
2351 needed and not elsewhere compiled. */
2353 veneer_symbols_base = no_symbols;
2355 /* for (i=0; i<VENEER_ROUTINES; i++)
2356 printf("%s %d %d %d %d %d %d\n", VRs[i].name,
2357 strlen(VRs[i].source1), strlen(VRs[i].source2),
2358 strlen(VRs[i].source3), strlen(VRs[i].source4),
2359 strlen(VRs[i].source5), strlen(VRs[i].source6)); */
2361 try_veneer_again = TRUE;
2362 while (try_veneer_again)
2363 { try_veneer_again = FALSE;
2364 for (i=0; i<VENEER_ROUTINES; i++)
2365 { if (veneer_routine_needs_compilation[i] == VR_CALLED)
2366 { j = symbol_index(VRs[i].name, -1);
2367 if (symbols[j].flags & UNKNOWN_SFLAG)
2368 { veneer_mode = TRUE;
2369 strcpy(veneer_source_area, VRs[i].source1);
2370 strcat(veneer_source_area, VRs[i].source2);
2371 strcat(veneer_source_area, VRs[i].source3);
2372 strcat(veneer_source_area, VRs[i].source4);
2373 strcat(veneer_source_area, VRs[i].source5);
2374 strcat(veneer_source_area, VRs[i].source6);
2376 parse_routine(veneer_source_area, FALSE,
2377 VRs[i].name, TRUE, j),
2379 veneer_mode = FALSE;
2380 if (trace_fns_setting==3) symbols[j].flags |= STAR_SFLAG;
2383 { if (symbols[j].type != ROUTINE_T)
2384 error_named("The following name is reserved by Inform for its \
2385 own use as a routine name; you can use it as a routine name yourself (to \
2386 override the standard definition) but cannot use it for anything else:",
2389 symbols[j].flags |= USED_SFLAG;
2391 veneer_routine_address[i] = symbols[j].value;
2392 veneer_routine_needs_compilation[i] = VR_COMPILED;
2393 try_veneer_again = TRUE;
2398 compile_symbol_table_routine();
2401 /* ========================================================================= */
2402 /* Data structure management routines */
2403 /* ------------------------------------------------------------------------- */
2405 extern void init_veneer_vars(void)
2409 extern void veneer_begin_pass(void)
2411 veneer_mode = FALSE;
2412 for (i=0; i<VENEER_ROUTINES; i++)
2413 { veneer_routine_needs_compilation[i] = VR_UNUSED;
2414 veneer_routine_address[i] = 0;
2418 extern void veneer_allocate_arrays(void)
2419 { veneer_source_area = my_malloc(16384, "veneer source code area");
2422 extern void veneer_free_arrays(void)
2423 { my_free(&veneer_source_area, "veneer source code area");
2426 /* ========================================================================= */