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.35 */
7 /* copyright (c) Graham Nelson 1993 - 2021 */
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 }, 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 In order not to impose these restrictions on "Main", we compile a
40 trivial routine consisting of a call to "Main" followed by "quit". */
45 j = symbol_index("Main__", -1);
47 assemble_routine_header(0, FALSE, "Main__", FALSE, j),
49 sflags[j] |= SYSTEM_SFLAG + USED_SFLAG;
50 if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
54 INITAOTV(&AO, LONG_CONSTANT_OT, 0);
57 sequence_point_follows = FALSE;
59 if (version_number > 3)
60 assemblez_1_to(call_vs_zc, AO, temp_var1);
62 assemblez_1_to(call_zc, AO, temp_var1);
69 INITAOTV(&AO, CONSTANT_OT, 0);
72 sequence_point_follows = FALSE;
74 assembleg_3(call_gc, AO, zero_operand, zero_operand);
75 assembleg_1(return_gc, zero_operand);
79 assemble_routine_end(FALSE, null_debug_locations);
82 /* ------------------------------------------------------------------------- */
83 /* The rest of the veneer is applied at the end of the pass, as required. */
84 /* ------------------------------------------------------------------------- */
86 static int veneer_routine_needs_compilation[VENEER_ROUTINES];
87 int32 veneer_routine_address[VENEER_ROUTINES];
88 static int veneer_symbols_base;
94 typedef struct VeneerRoutine_s
104 static char *veneer_source_area;
106 static VeneerRoutine VRs_z[VENEER_ROUTINES] =
108 /* Box__Routine: the only veneer routine used in the implementation of
109 an actual statement ("box", of course), written in a
110 hybrid of Inform and assembly language. Note the
111 transcription of the box text to the transcript
112 output stream (-1, or $ffff). */
115 "maxw table n w w2 line lc t;\
130 { @set_cursor line w;\
132 @set_cursor line w2;\
134 if (t~=0) print (string) t;\
143 @output_stream $ffff;\
148 if (w ~= 0) print (string) w;\
160 /* This batch of routines is expected to be defined (rather better) by
161 the Inform library: these minimal forms here are provided to prevent
162 tiny non-library-using programs from failing to compile when certain
163 legal syntaxes (such as <<Action a b>>;) are used. */
166 "a b c d; print \"Action <\", a, \" \", b, \" \", c;\
167 if (d) print \", \", d; print \">^\";\
168 ]", "", "", "", "", ""
171 "obj; print \"the \", obj; ]", "", "", "", "", ""
174 "obj; print \"a \", obj; ]", "", "", "", "", ""
177 "obj; print \"The \", obj; ]", "", "", "", "", ""
180 "obj; print \"A \", obj; ]", "", "", "", "", ""
183 "obj; switch(metaclass(obj))\
184 { 0: print \"nothing\";\
185 Object: @print_obj obj;\
186 Class: print \"class \"; @print_obj obj;\
187 Routine: print \"(routine at \", obj, \")\";\
188 String: print \"(string at \", obj, \")\";\
189 } ]", "", "", "", "", ""
192 "obj; print obj; ]", "", "", "", "", ""
197 { cla = #classes_table-->(prop & $ff);\
198 print (name) cla, \"::\";\
199 if ((prop & $8000) == 0) prop = (prop & $3f00)/$100;\
201 { prop = (prop & $7f00)/$100;\
203 while ((i-->0 ~= 0) && (prop>0))\
207 prop = (i-->0) & $7fff;\
210 "p = #identifiers_table;\
212 if (prop<=0 || prop>=size || p-->prop==0)\
213 print \"<number \", prop, \">\";\
214 else print (string) p-->prop;\
218 /* The remaining routines make up the run-time half of the object
219 orientation system, and need never be present for Inform 5 programs. */
222 /* WV__Pr: write a value to the property for the given
223 object having the given identifier */
226 "obj identifier value x;\
227 x = obj..&identifier;\
228 if (x==0) { RT__Err(\"write to\", obj, identifier); return; }\
230 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,value);\
231 #ifnot; #ifdef DEBUG;\
232 if (debug_flag & 15) RT__TrPS(obj,identifier,value);\
235 ]", "", "", "", "", ""
238 /* RV__Pr: read a value from the property for the given
239 object having the given identifier */
243 x = obj..&identifier;\
245 { if (identifier >= 1 && identifier < 64 && obj.#identifier <= 2)\
246 return obj.identifier;\
247 RT__Err(\"read\", obj, identifier); return; }\
249 if (obj..#identifier > 2) RT__Err(\"read\", obj, identifier);\
251 if (obj..#identifier > 2) RT__Err(\"read\", obj, identifier, 2);\
254 ]", "", "", "", "", ""
256 { /* CA__Pr: call, that is, print-or-run-or-read, a property:
257 this exactly implements obj..prop(...). Note that
258 classes (members of Class) have 5 built-in properties
259 inherited from Class: create, recreate, destroy,
260 remaining and copy. Implementing these here prevents
261 the need for a full metaclass inheritance scheme. */
264 "obj id a b c d e f x y z s s2 n m;\
265 if (obj < 1 || obj > #largest_object-255)\
266 { switch(Z__Region(obj))\
267 { 2: if (id == call)\
268 { s = sender; sender = self; self = obj;\
269 #ifdef action;sw__var=action;#endif;\
270 x = indirect(obj, a, b, c, d, e, f);\
271 self = sender; sender = s; return x; }\
273 "3: if (id == print) { @print_paddr obj; rtrue; }\
274 if (id == print_to_array)\
275 { @output_stream 3 a; @print_paddr obj; @output_stream -3;\
281 @check_arg_count 3 ?~A__x;y++;@check_arg_count 4 ?~A__x;y++;\
282 @check_arg_count 5 ?~A__x;y++;@check_arg_count 6 ?~A__x;y++;\
283 @check_arg_count 7 ?~A__x;y++;@check_arg_count 8 ?~A__x;y++;.A__x;",
284 "#ifdef INFIX;if (obj has infix__watching) n=1;#endif;\
285 #ifdef DEBUG;if (debug_flag & 1 ~= 0) n=1;#endif;\
287 #ifdef DEBUG;n=debug_flag & 1; debug_flag=debug_flag-n;#endif;\
288 print \"[ ~\", (name) obj, \"~.\", (property) id, \"(\";\
289 switch(y) { 1: print a; 2: print a,\",\",b; 3: print a,\",\",b,\",\",c;\
290 4: print a,\",\",b,\",\",c,\",\",d;\
291 5: print a,\",\",b,\",\",c,\",\",d,\",\",e;\
292 6: print a,\",\",b,\",\",c,\",\",d,\",\",e,\",\",f; }\
294 #ifdef DEBUG;debug_flag = debug_flag + n;#endif;\
296 "if (id > 0 && id < 64)\
297 { x = obj.&id; if (x==0) { x=$000a-->0 + 2*(id-1); n=2; }\
300 { if (id>=64 && id<69 && obj in Class)\
301 return Cl__Ms(obj,id,y,a,b,c,d);\
303 if (x == 0) { .Call__Error;\
304 RT__Err(\"send message\", obj, id); return; }\
306 if (id&$C000==$4000)\
307 switch (n&$C0) { 0: n=1; $40: n=2; $80: n=n&$3F; }\
310 { if (x-->m==$ffff) rfalse;\
311 switch(Z__Region(x-->m))\
312 { 2: s = sender; sender = self; self = obj; s2 = sw__var;\
314 if (id==life) sw__var=reason_code; else sw__var=action;\
316 switch(y) { 0: z = indirect(x-->m); 1: z = indirect(x-->m, a);\
317 2: z = indirect(x-->m, a, b); 3: z = indirect(x-->m, a, b, c);",
318 "4: z = indirect(x-->m, a, b, c, d); 5:z = indirect(x-->m, a, b, c, d, e);\
319 6: z = indirect(x-->m, a, b, c, d, e, f); }\
320 self = sender; sender = s; sw__var = s2;\
321 if (z ~= 0) return z;\
322 3: print_ret (string) x-->m;\
323 default: return x-->m;\
330 /* IB__Pr: ++(individual property) */
334 x = obj..&identifier;\
335 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
337 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)+1);\
338 #ifnot; #ifdef DEBUG;\
339 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
342 ]", "", "", "", "", ""
345 /* IA__Pr: (individual property)++ */
349 x = obj..&identifier;\
350 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
352 if (obj has infix__watching || (debug_flag & 15))\
353 RT__TrPS(obj,identifier,(x-->0)+1);\
354 #ifnot; #ifdef DEBUG;\
355 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
358 ]", "", "", "", "", ""
361 /* DB__Pr: --(individual property) */
365 x = obj..&identifier;\
366 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
368 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
369 #ifnot; #ifdef DEBUG;\
370 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
373 ]", "", "", "", "", ""
376 /* DA__Pr: (individual property)-- */
380 x = obj..&identifier;\
381 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
383 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
384 #ifnot; #ifdef DEBUG;\
385 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
388 ]", "", "", "", "", ""
391 /* RA__Pr: read the address of a property value for a given object,
392 returning 0 if it doesn't provide this individual
396 "obj identifier i otherid cla;\
398 if (identifier<64 && identifier>0) return obj.&identifier;\
399 if (identifier & $8000 ~= 0)\
400 { cla = #classes_table-->(identifier & $ff);\
401 if (cla.&3 == 0) rfalse;\
402 if (~~(obj ofclass cla)) rfalse;\
403 identifier = (identifier & $7f00) / $100;\
405 while (identifier>0)\
411 "if (identifier & $4000 ~= 0)\
412 { cla = #classes_table-->(identifier & $ff);\
413 identifier = (identifier & $3f00) / $100;\
414 if (~~(obj ofclass cla)) rfalse; i=0-->5;\
415 if (cla == 2) return i+2*identifier-2;\
416 i = 0-->((i+124+cla*14)/2);\
417 i = CP__Tab(i + 2*(0->i) + 1, -1)+6;\
418 return CP__Tab(i, identifier);\
420 if (obj.&3 == 0) rfalse;\
422 { if (identifier<64 || identifier>=72) rfalse;\
425 otherid = identifier | $8000;\
428 { if (i-->0 == identifier or otherid)\
436 /* RL__Pr: read the property length of an individual property value,
437 returning 0 if it isn't provided by the given object */
441 if (identifier<64 && identifier>0) return obj.#identifier;\
442 x = obj..&identifier;\
444 if (identifier&$C000==$4000)\
445 switch (((x-1)->0)&$C0)\
446 { 0: return 1; $40: return 2; $80: return ((x-1)->0)&$3F; }\
448 ]", "", "", "", "", ""
451 /* RA__Sc: implement the "superclass" (::) operator,
452 returning an identifier */
455 "cla identifier otherid i j k;\
456 if (cla notin 1 && cla > 4)\
457 { RT__Err(\"be a '::' superclass\", cla, -1); rfalse; }\
458 if (self ofclass cla) otherid = identifier | $8000;\
459 for (j=0: #classes_table-->j ~= 0: j++)\
460 { if (cla==#classes_table-->j)\
461 { if (identifier < 64) return $4000 + identifier*$100 + j;\
462 if (cla.&3 == 0) break;\
465 { if (i-->0 == identifier or otherid)\
466 return $8000 + k*$100 + j;\
473 RT__Err(\"make use of\", cla, identifier);\
478 /* OP__Pr: test whether or not given object provides individual
479 property with the given identifier code */
483 if (obj<1 || obj > (#largest_object-255))\
484 { if (identifier ~= print or print_to_array or call) rfalse;\
485 switch(Z__Region(obj))\
486 { 2: if (identifier == call) rtrue;\
487 3: if (identifier == print or print_to_array) rtrue;\
492 { if (obj.&identifier ~= 0) rtrue;\
495 if (obj..&identifier ~= 0) rtrue;\
496 if (identifier<72 && obj in 1) rtrue;\
501 /* OC__Cl: test whether or not given object is of the given class */
505 if (obj<1 || obj > (#largest_object-255))\
506 { if (cla ~= 3 or 4) rfalse;\
507 if (Z__Region(obj) == cla-1) rtrue;\
512 if (obj in 1) rtrue;\
514 } else if (cla == 2) {\
516 if (obj in 1) rfalse;\
518 } else if (cla == 3 or 4) {\
521 "if (cla notin 1) { RT__Err(\"apply 'ofclass' for\", cla, -1);rfalse;}\
522 @get_prop_addr obj 2 -> a;\
524 @get_prop_len a -> n;\
525 for (j=0: j<n/2: j++)\
526 { if (a-->j == cla) rtrue;\
531 { /* Copy__Primitive: routine to "deep copy" objects */
534 "o1 o2 a1 a2 n m l size identifier;\
536 { if (o2 has n) give o1 n;\
539 for (n=1:n<64:n++) if (n~=2 or 3)\
540 { a1 = o1.&n; a2 = o2.&n; size = o1.#n;\
541 if (a1~=0 && a2~=0 && size==o2.#n)\
542 { for (m=0:m<size:m++) a1->m=a2->m;\
545 "if (o1.&3 == 0 || o2.&3 == 0) return;\
546 for (n=o2.3: n-->0 ~= 0: n = n + size + 3)\
547 { identifier = n-->0;\
549 for (m=o1.3: m-->0 ~= 0: m = m + m->2 + 3)\
550 if ((identifier & $7fff == (m-->0) & $7fff) && size==m->2)\
551 for (l=3: l<size+3: l++) m->l = n->l;\
555 { /* RT__Err: for run-time errors occurring in the above: e.g.,
556 an attempt to write to a non-existent individual
560 "crime obj id size p q;\
561 print \"^[** Programming error: \";\
562 if (crime<0) jump RErr;\
563 if (crime==1) { print \"class \"; @print_obj obj;\
564 \": 'create' can have 0 to 3 parameters only **]\";}\
565 if (crime == 32) \"objectloop broken because the object \",\
566 (name) obj, \" was moved while the loop passed through it **]\";\
567 if (crime == 33) \"tried to print (char) \", obj,\
568 \", which is not a valid ZSCII character code for output **]\";\
569 if (crime == 34) \"tried to print (address) on something not the \",\
570 \"byte address of a string **]\";\
571 if (crime == 35) \"tried to print (string) on something not a \",\
573 if (crime == 36) \"tried to print (object) on something not an \",\
574 \"object or class **]\";",
575 "if (crime < 32) { print \"tried to \";\
576 if (crime >= 28) { if (crime==28 or 29) print \"read from \";\
577 else print \"write to \";\
578 if (crime==29 or 31) print \"-\"; print \"->\", obj,\
579 \" in the\"; switch(size&7){0,1:q=0; 2:print \" string\";\
580 q=1; 3:print \" table\";q=1; 4:print \" buffer\";q=WORDSIZE;} \
581 if(size&16) print\" (->)\"; if(size&8) print\" (-->)\";\
582 \" array ~\", (string) #array_names_offset-->p,\
583 \"~, which has entries \", q, \" up to \",id,\" **]\"; }\
584 if (crime >= 24 && crime <=27) { if (crime<=25) print \"read\";\
585 else print \"write\"; print \" outside memory using \";\
586 switch(crime) { 24,26:\"-> **]\"; 25,27:\"--> **]\"; } }\
587 if (crime < 4) print \"test \"; else\
588 if (crime < 12 || crime > 20) print \"find the \"; else\
589 if (crime < 14) print \"use \";\
590 if (crime==20) \"divide by zero **]\"; print \"~\";\
592 2: print \"in~ or ~notin\"; 3: print \"has~ or ~hasnt\";\
593 4: print \"parent\"; 5: print \"eldest\"; 6: print \"child\";\
594 7: print \"younger\"; 8: print \"sibling\"; 9: print \"children\";\
595 10: print \"youngest\"; 11: print \"elder\";\
596 12: print \"objectloop\"; 13: print \"}~ at end of ~objectloop\";\
597 14: \"give~ an attribute to \", (name) obj, \" **]\";\
598 15: \"remove~ \", (name) obj, \" **]\";",
599 "16,17,18: print \"move~ \", (name) obj, \" to \", (name) id;\
600 if (crime==18) { print \", which would make a loop: \",(name) obj;\
601 p=id; if (p==obj) p=obj;\
602 else do { print \" in \", (name) p; p=parent(p);} until (p==obj);\
603 \" in \", (name) p, \" **]\"; }\
604 \" **]\"; 19: \"give~ or test ~has~ or ~hasnt~ with a non-attribute"\
605 " on the object \",(name) obj,\" **]\";\
606 21: print \".&\"; 22: print \".#\"; 23: print \".\"; }\
607 \"~ of \", (name) obj, \" **]\"; }",
608 ".RErr; if (obj>=0 && obj<=(#largest_object-255)) {\
609 if (obj && obj in Class) print \"class \";\
610 if (obj) @print_obj obj;else print \"nothing\";print\" \";}\
611 print \"(object number \", obj, \") \";\
612 if (id<0) print \"is not of class \", (name) -id;",
613 "else if (size) print \"has a property \", (property) id,\
614 \", but it is longer than 2 bytes so you cannot use ~.~\";\
616 { print \" has no property \", (property) id;\
617 p = #identifiers_table;\
619 if (id<0 || id>=size)\
620 print \" (and nor has any other object)\";\
622 print \" to \", (string) crime, \" **]^\";\
625 { /* Z__Region: Determines whether a value is:
629 0 none of the above */
633 if (addr==0 or -1) rfalse;\
635 #IfV5; #iftrue (#version_number == 6) || (#version_number == 7);\
636 @log_shift addr $FFFF -> top; #Endif; #Endif;\
637 if (Unsigned__Compare(top, $001A-->0) >= 0) rfalse;\
638 if (addr>=1 && addr<=(#largest_object-255)) rtrue;\
639 #iftrue #oddeven_packing;\
640 @test addr 1 ?~NotString;\
641 if (Unsigned__Compare(addr, #strings_offset)<0) rfalse;\
644 if (Unsigned__Compare(addr, #code_offset)<0) rfalse;\
647 if (Unsigned__Compare(addr, #strings_offset)>=0) return 3;\
648 if (Unsigned__Compare(addr, #code_offset)>=0) return 2;\
651 ]", "", "", "", "", ""
653 { /* Unsigned__Compare: returns 1 if x>y, 0 if x=y, -1 if x<y */
658 if (x<0 && y>=0) return 1;\
659 if (x>=0 && y<0) return -1;\
660 u = x&$7fff; v= y&$7fff;\
663 ]", "", "", "", "", ""
665 { /* Meta__class: returns the metaclass of an object */
669 switch(Z__Region(obj))\
670 { 2: return Routine;\
672 1: if (obj in 1 || obj <= 4) return Class;\
676 ]", "", "", "", "", ""
678 { /* CP__Tab: searches a common property table for the given
679 identifier, thus imitating the get_prop_addr opcode.
680 Returns 0 if not provided, except:
681 if the identifier supplied is -1, then returns
682 the address of the first byte after the table. */
686 while ((n=0->x) ~= 0)\
687 { if (n & $80) { x++; l = (0->x) & $3f; }\
688 else { if (n & $40) l=2; else l=1; }\
690 if ((n & $3f) == id) return x;\
693 if (id<0) return x+1; rfalse; ]", "", "", "", "", ""
695 { /* Cl__Ms: the five message-receiving properties of Classes */
698 "obj id y a b c d x;\
701 if (children(obj)<=1) rfalse; x=child(obj);\
702 remove x; if (x provides create) { if (y==0) x..create();\
703 if (y==1) x..create(a); if (y==2) x..create(a,b);\
704 if (y>3) RT__Err(1,obj); if (y>=3) x..create(a,b,c);}\
707 if (~~(a ofclass obj))\
708 { RT__Err(\"recreate\", a, -obj); rfalse; }\
709 Copy__Primitive(a, child(obj));\
710 if (a provides create) { if (y==1) a..create();\
711 if (y==2) a..create(b); if (y==3) a..create(b,c);\
712 if (y>4) RT__Err(1,obj); if (y>=4) a..create(b,c,d);\
715 if (~~(a ofclass obj))\
716 { RT__Err(\"destroy\", a, -obj); rfalse; }\
717 if (a provides destroy) a..destroy();\
718 Copy__Primitive(a, child(obj));\
719 move a to obj; rfalse;\
721 return children(obj)-1;",
723 if (~~(a ofclass obj))\
724 { RT__Err(\"copy\", a, -obj); rfalse; }\
725 if (~~(b ofclass obj))\
726 { RT__Err(\"copy\", b, -obj); rfalse; }\
727 Copy__Primitive(a, b); rfalse;\
731 { /* RT__ChT: check at run-time that a proposed object move is legal
732 cause error and do nothing if not; otherwise move */
736 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
737 return RT__Err(16,obj1,obj2);\
738 if (obj2<5 || obj2>(#largest_object-255) || obj2 in 1)\
739 return RT__Err(17,obj1,obj2);",
740 "x=obj2; while (x~=0) { if (x==obj1) return RT__Err(18,obj1,obj2); \
743 if (obj1 has infix__watching\
744 || obj2 has infix__watching || (debug_flag & 15))\
745 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
746 #ifnot; #ifdef DEBUG;\
747 if (debug_flag & 15)\
748 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
750 @insert_obj obj1 obj2; ]", "", "", "", ""
752 { /* RT__ChR: check at run-time that a proposed object remove is legal
753 cause error and do nothing if not; otherwise remove */
757 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
758 return RT__Err(15,obj1);",
760 if (obj1 has infix__watching || (debug_flag & 15))\
761 print \"[Removing \", (name) obj1, \"]^\";\
762 #ifnot; #ifdef DEBUG;\
763 if (debug_flag & 15)\
764 print \"[Removing \", (name) obj1, \"]^\";\
766 @remove_obj obj1; ]", "", "", "", ""
768 { /* RT__ChG: check at run-time that a proposed attr give is legal
769 cause error and do nothing if not; otherwise give */
773 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
774 return RT__Err(14,obj1); if (a<0 || a>=48) return RT__Err(19,obj1);\
775 if (obj1 has a) return;",
777 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
778 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
779 #ifnot; #ifdef DEBUG;\
780 if (a ~= workflag && debug_flag & 15)\
781 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
783 @set_attr obj1 a; ]", "", "", "", ""
785 { /* RT__ChGt: check at run-time that a proposed attr give ~ is legal
786 cause error and do nothing if not; otherwise give */
790 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
791 return RT__Err(14,obj1); if (a<0 || a>=48) return RT__Err(19,obj1);\
792 if (obj1 hasnt a) return;",
794 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
795 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
796 #ifnot; #ifdef DEBUG;\
797 if (a ~= workflag && debug_flag & 15)\
798 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
800 @clear_attr obj1 a; ]", "", "", "", ""
802 { /* RT__ChPS: check at run-time that a proposed property set is legal
803 cause error and do nothing if not; otherwise make it */
807 if (obj<5 || obj>(#largest_object-255) || obj in 1 || obj.&prop==0 || (size=obj.#prop)>2 )\
808 return RT__Err(\"set\", obj, prop, size);\
809 @put_prop obj prop val;",
811 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,prop,val);\
812 #ifnot; #ifdef DEBUG;\
813 if (debug_flag & 15) RT__TrPS(obj,prop,val);\
815 return val; ]", "", "", "", ""
817 { /* RT__ChPR: check at run-time that a proposed property read is legal
818 cause error and return 0 if not; otherwise read it */
822 if (obj<5 || obj>(#largest_object-255) || (size=obj.#prop)>2)\
823 {RT__Err(\"read\", obj, prop, size); obj=2;}\
824 @get_prop obj prop -> val;",
825 "return val; ]", "", "", "", ""
827 { /* RT__TrPS: trace property settings */
831 print \"[Setting \",(name) obj,\".\",(property) prop,\
832 \" to \",val,\"]^\"; ]",
835 { /* RT__ChLDB: check at run-time that it's safe to load a byte
836 and return the byte */
840 a=base+offset;if (Unsigned__Compare(a,#readable_memory_offset)>=0)\
841 return RT__Err(24);",
842 "@loadb base offset -> val;return val; ]", "", "", "", ""
844 { /* RT__ChLDW: check at run-time that it's safe to load a word
845 and return the word */
849 a=base+2*offset;if (Unsigned__Compare(a,#readable_memory_offset)>=0)\
850 return RT__Err(25);",
851 "@loadw base offset -> val;return val; ]", "", "", "", ""
853 { /* RT__ChSTB: check at run-time that it's safe to store a byte
857 "base offset val a f;\
859 if (Unsigned__Compare(a,#array__start)>=0\
860 && Unsigned__Compare(a,#array__end)<0) f=1; else\
861 if (Unsigned__Compare(a,#cpv__start)>=0\
862 && Unsigned__Compare(a,#cpv__end)<0) f=1; else\
863 if (Unsigned__Compare(a,#ipv__start)>=0\
864 && Unsigned__Compare(a,#ipv__end)<0) f=1; else\
866 if (f==0) return RT__Err(26);",
867 "@storeb base offset val; ]", "", "", "", ""
869 { /* RT__ChSTW: check at run-time that it's safe to store a word
873 "base offset val a f;\
875 if (Unsigned__Compare(a,#array__start)>=0\
876 && Unsigned__Compare(a,#array__end)<0) f=1; else\
877 if (Unsigned__Compare(a,#cpv__start)>=0\
878 && Unsigned__Compare(a,#cpv__end)<0) f=1; else\
879 if (Unsigned__Compare(a,#ipv__start)>=0\
880 && Unsigned__Compare(a,#ipv__end)<0) f=1; else\
882 if (f==0) return RT__Err(27);",
883 "@storew base offset val; ]", "", "", "", ""
885 { /* RT__ChPrintC: check at run-time that it's safe to print (char)
890 if (c==0 or 9 or 11 or 13) fl=1;\
891 if (c>=32 && c<=126) fl=1; if (c>=155 && c<=251) fl=1;\
892 if (fl==0) return RT__Err(33,c);",
893 "@print_char c; ]", "", "", "", ""
895 { /* RT__ChPrintA: check at run-time that it's safe to print (address)
900 if (Unsigned__Compare(a, #readable_memory_offset)>=0)\
901 return RT__Err(34);",
902 "@print_addr a; ]", "", "", "", ""
904 { /* RT__ChPrintS: check at run-time that it's safe to print (string)
909 if (Z__Region(a)~=3) return RT__Err(35);",
910 "@print_paddr a; ]", "", "", "", ""
912 { /* RT__ChPrintO: check at run-time that it's safe to print (object)
917 if (Z__Region(a)~=1) return RT__Err(36);",
918 "@print_obj a; ]", "", "", "", ""
922 static VeneerRoutine VRs_g[VENEER_ROUTINES] =
925 /* Box__Routine: Display the given array of text as a box quote.
926 This is a very simple implementation; the library should provide
933 for (ix=0 : ix<arr-->0 : ix++) {\
934 print (string) arr-->(ix+1);\
938 ]", "", "", "", "", ""
941 /* This batch of routines is expected to be defined (rather better) by
942 the Inform library: these minimal forms here are provided to prevent
943 tiny non-library-using programs from failing to compile when certain
944 legal syntaxes (such as <<Action a b>>;) are used. */
947 "a b c d; print \"Action <\", a, \" \", b, \" \", c;\
948 if (d) print \", \", d; print \">^\";\
949 ]", "", "", "", "", ""
952 "obj; print \"the \", obj; ]", "", "", "", "", ""
955 "obj; print \"a \", obj; ]", "", "", "", "", ""
958 "obj; print \"The \", obj; ]", "", "", "", "", ""
961 "obj; print \"A \", obj; ]", "", "", "", "", ""
964 "obj q; switch(metaclass(obj))\
965 { 0: print \"nothing\";\
966 Object: q = obj-->GOBJFIELD_NAME; @streamstr q;\
967 Class: print \"class \"; q = obj-->GOBJFIELD_NAME; @streamstr q;\
968 Routine: print \"(routine at \", obj, \")\";\
969 String: print \"(string at \", obj, \")\";\
970 } ]", "", "", "", "", ""
973 "obj; print obj; ]", "", "", "", "", ""
976 /* Print__PName: Print the name of a property.
979 "prop ptab cla maxcom minind maxind str;\
980 if (prop & $FFFF0000) {\
981 cla = #classes_table-->(prop & $FFFF);\
982 print (name) cla, \"::\";\
983 @ushiftr prop 16 prop;\
985 ptab = #identifiers_table;\
987 minind = INDIV_PROP_START;\
988 maxind = minind + ptab-->3;\
990 if (prop >= 0 && prop < maxcom) {\
991 str = (ptab-->0)-->prop;\
993 else if (prop >= minind && prop < maxind) {\
994 str = (ptab-->2)-->(prop-minind);\
999 print \"<number \", prop, \">\";\
1000 ]", "", "", "", "", ""
1003 /* The remaining routines make up the run-time half of the object
1004 orientation system, and need never be present for Inform 5 programs. */
1007 /* WV__Pr: Write a value to the property for the given object.
1013 RT__Err(\"write\", obj, id);\
1018 ]", "", "", "", "", ""
1022 /* RV__Pr: Read a value to the property for the given object.
1028 if (id > 0 && id < INDIV_PROP_START) {\
1029 return #cpv__start-->id;\
1031 RT__Err(\"read\", obj, id);\
1035 ]", "", "", "", "", ""
1038 /* CA__Pr: Call, that is, print-or-run-or-read, a property:
1039 this exactly implements obj..prop(...). Note that
1040 classes (members of Class) have 5 built-in properties
1041 inherited from Class: create, recreate, destroy,
1042 remaining and copy. Implementing these here prevents
1043 the need for a full metaclass inheritance scheme.
1046 "_vararg_count obj id zr s s2 z addr len m val;\
1049 _vararg_count = _vararg_count - 2;\
1050 zr = Z__Region(obj);\
1053 s = sender; sender = self; self = obj;\
1054 #ifdef action; sw__var=action; #endif;\
1055 @call obj _vararg_count z;\
1056 self = sender; sender = s;\
1063 @streamstr obj; rtrue;\
1065 if (id == print_to_array) {\
1066 if (_vararg_count >= 2) {\
1071 RT__Err(37); rfalse;\
1074 s = glk($0043, m+4, len-4, 1, 0);",
1079 @copy $ffffffff sp;\
1093 #ifdef DEBUG;#ifdef InformLibrary;\
1094 if (debug_flag & 1 ~= 0) {\
1096 print \"[ ~\", (name) obj, \"~.\", (property) id, \"(\";\
1097 @stkcopy _vararg_count;\
1098 for (val=0 : val < _vararg_count : val++) {\
1099 if (val) print \", \";\
1106 if (obj in Class) {\
1109 return Cl__Ms(obj, id);\
1113 return Cl__Ms(obj, id, m, val);\
1114 create, destroy, recreate:\
1115 m = _vararg_count+2;\
1118 @call Cl__Ms m val;\
1124 if (id > 0 && id < INDIV_PROP_START) {\
1125 addr = #cpv__start + 4*id;\
1135 for (m=0 : 4*m<len : m++) {\
1137 if (val == -1) rfalse;\
1138 switch (Z__Region(val)) {\
1140 s = sender; sender = self; self = obj; s2 = sw__var;\
1142 if (id==life) sw__var=reason_code; else sw__var=action;\
1144 " @stkcopy _vararg_count;\
1145 @call val _vararg_count z;\
1146 self = sender; sender = s; sw__var = s2;\
1147 if (z ~= 0) return z;\
1158 RT__Err(\"send message\", obj, id);\
1163 /* IB__Pr: ++(individual property) */
1167 x = obj.&identifier;\
1168 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
1170 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)+1);\
1171 #ifnot; #ifdef DEBUG;\
1172 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
1175 ]", "", "", "", "", ""
1178 /* IA__Pr: (individual property)++ */
1182 x = obj.&identifier;\
1183 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
1185 if (obj has infix__watching || (debug_flag & 15))\
1186 RT__TrPS(obj,identifier,(x-->0)+1);\
1187 #ifnot; #ifdef DEBUG;\
1188 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
1191 ]", "", "", "", "", ""
1194 /* DB__Pr: --(individual property) */
1198 x = obj.&identifier;\
1199 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
1201 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
1202 #ifnot; #ifdef DEBUG;\
1203 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
1206 ]", "", "", "", "", ""
1209 /* DA__Pr: (individual property)-- */
1213 x = obj.&identifier;\
1214 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
1216 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
1217 #ifnot; #ifdef DEBUG;\
1218 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
1221 ]", "", "", "", "", ""
1224 /* RA__Pr: Read the property address of a given property value.
1225 Returns zero if it isn't provided by the object. This
1226 understands all the same concerns as RL__Pr().
1229 "obj id cla prop ix;\
1230 if (id & $FFFF0000) {\
1231 cla = #classes_table-->(id & $FFFF);\
1232 if (~~(obj ofclass cla)) return 0;\
1236 prop = CP__Tab(obj, id);\
1237 if (prop==0) return 0;\
1238 if (obj in Class && cla == 0) {\
1239 if (id < INDIV_PROP_START || id >= INDIV_PROP_START+8)\
1243 @aloadbit prop 72 ix;\
1247 ]", "", "", "", "", ""
1251 /* RL__Pr: Read the property length of a given property value.
1252 Returns zero if it isn't provided by the object. This understands
1253 inherited values (of the form class::prop) as well as simple
1254 property ids and the special metaclass methods. It also knows
1255 that private properties can only be read if (self == obj).
1258 "obj id cla prop ix;\
1259 if (id & $FFFF0000) {\
1260 cla = #classes_table-->(id & $FFFF);\
1261 if (~~(obj ofclass cla)) return 0;\
1265 prop = CP__Tab(obj, id);\
1266 if (prop==0) return 0;\
1267 if (obj in Class && cla == 0) {\
1268 if (id < INDIV_PROP_START || id >= INDIV_PROP_START+8)\
1272 @aloadbit prop 72 ix;\
1276 return WORDSIZE * ix;\
1277 ]", "", "", "", "", ""
1280 /* RA__Sc: Implement the \"superclass\" (::) operator. This
1281 returns an compound property identifier, which is a
1286 if ((cla notin Class) && (cla ~= Class or String or Routine or Object)) {\
1287 RT__Err(\"be a '::' superclass\", cla, -1);\
1290 for (j=0 : #classes_table-->j ~= 0 : j++) {\
1291 if (cla == #classes_table-->j) {\
1292 return (id * $10000 + j);\
1295 RT__Err(\"make use of\", cla, id);\
1297 ]", "", "", "", "", ""
1301 /* OP__Pr: Test whether the given object provides the given property.
1302 This winds up calling RA__Pr().
1306 zr = Z__Region(obj);\
1308 if (id == print or print_to_array) rtrue;\
1312 if (id == call) rtrue;\
1315 if (zr ~= 1) rfalse;\
1316 if (id >= INDIV_PROP_START && id < INDIV_PROP_START+8) {\
1317 if (obj in Class) rtrue;\
1322 ]", "", "", "", "", ""
1325 /* OC__Cl: Test whether the given object is of the given class.
1326 (implements the OfClass operator.)
1329 "obj cla zr jx inlist inlistlen;\
1330 zr = Z__Region(obj);\
1332 if (cla == String) rtrue;\
1336 if (cla == Routine) rtrue;\
1339 if (zr ~= 1) rfalse;\
1340 if (cla == Class) {\
1342 || obj == Class or String or Routine or Object)\
1346 if (cla == Object) {\
1348 || obj == Class or String or Routine or Object)\
1352 if (cla == String or Routine) rfalse;\
1353 if (cla notin Class) {\
1354 RT__Err(\"apply 'ofclass' for\", cla, -1);\
1358 if (inlist == 0) rfalse;\
1359 inlistlen = (obj.#2) / WORDSIZE;\
1360 for (jx=0 : jx<inlistlen : jx++) {\
1361 if (inlist-->jx == cla) rtrue;\
1364 ]", "", "", "", "", ""
1368 /* Copy__Primitive: Routine to \"deep copy\" objects.
1371 "o1 o2 p1 p2 pcount i j propid proplen val pa1 pa2;\
1372 for (i=1 : i<=NUM_ATTR_BYTES : i++) {\
1375 p2 = o2-->GOBJFIELD_PROPTAB;\
1378 for (i=0 : i<pcount : i++) {\
1379 @aloads p2 0 propid;\
1380 @aloads p2 1 proplen;\
1381 p1 = CP__Tab(o1, propid);\
1384 if (proplen == val) {\
1389 for (j=0 : j<proplen : j++)\
1395 ]", "", "", "", "", ""
1397 { /* RT__Err: for run-time errors occurring in the above: e.g.,
1398 an attempt to write to a non-existent individual
1402 "crime obj id size p q;\
1403 print \"^[** Programming error: \";\
1404 if (crime<0) jump RErr;\
1405 if (crime==1) { print \"class \"; q = obj-->GOBJFIELD_NAME; @streamstr q;\
1406 \": 'create' can have 0 to 3 parameters only **]\";}\
1407 if (crime == 40) \"tried to change printing variable \",\
1408 obj, \"; must be 0 to \", #dynam_string_table-->0-1, \" **]\";\
1409 if (crime == 32) \"objectloop broken because the object \",\
1410 (name) obj, \" was moved while the loop passed through it **]\";\
1411 if (crime == 33) \"tried to print (char) \", obj,\
1412 \", which is not a valid Glk character code for output **]\";\
1413 if (crime == 34) \"tried to print (address) on something not the \",\
1414 \"address of a dict word **]\";\
1415 if (crime == 35) \"tried to print (string) on something not a \",\
1417 if (crime == 36) \"tried to print (object) on something not an \",\
1418 \"object or class **]\";\
1419 if (crime == 37) \"tried to call Glulx print_to_array with only \",\
1420 \"one argument **]\";",
1421 "if (crime < 32) { print \"tried to \";\
1422 if (crime >= 28) { if (crime==28 or 29) print \"read from \";\
1423 else print \"write to \";\
1424 if (crime==29 or 31) print \"-\"; print \"->\", obj,\
1425 \" in the\"; switch(size&7){0,1:q=0; 2:print \" string\";\
1426 q=1; 3:print \" table\";q=1; 4:print \" buffer\";q=WORDSIZE;} \
1427 if(size&16) print\" (->)\"; if(size&8) print\" (-->)\";\
1428 \" array ~\", (string) #array_names_offset-->(p+1),\
1429 \"~, which has entries \", q, \" up to \",id,\" **]\"; }\
1430 if (crime >= 24 && crime <=27) { if (crime<=25) print \"read\";\
1431 else print \"write\"; print \" outside memory using \";\
1432 switch(crime) { 24,26:\"-> **]\"; 25,27:\"--> **]\"; } }\
1433 if (crime < 4) print \"test \"; else\
1434 if (crime < 12 || crime > 20) print \"find the \"; else\
1435 if (crime < 14) print \"use \";\
1436 if (crime==20) \"divide by zero **]\"; print \"~\";\
1438 2: print \"in~ or ~notin\"; 3: print \"has~ or ~hasnt\";\
1439 4: print \"parent\"; 5: print \"eldest\"; 6: print \"child\";\
1440 7: print \"younger\"; 8: print \"sibling\"; 9: print \"children\";\
1441 10: print \"youngest\"; 11: print \"elder\";\
1442 12: print \"objectloop\"; 13: print \"}~ at end of ~objectloop\";\
1443 14: \"give~ an attribute to \", (name) obj, \" **]\";\
1444 15: \"remove~ \", (name) obj, \" **]\";",
1445 "16,17,18: print \"move~ \", (name) obj, \" to \", (name) id;\
1446 if (crime==18) { print \", which would make a loop: \",(name) obj;\
1447 p=id; if (p==obj) p=obj;\
1448 else do { print \" in \", (name) p; p=parent(p);} until (p==obj);\
1449 \" in \", (name) p, \" **]\"; }\
1450 \" **]\"; 19: \"give~ or test ~has~ or ~hasnt~ with a non-attribute"\
1451 " on the object \",(name) obj,\" **]\";\
1452 21: print \".&\"; 22: print \".#\"; 23: print \".\"; }\
1453 \"~ of \", (name) obj, \" **]\"; }",
1454 ".RErr; if (obj==0 || obj->0>=$70 && obj->0<=$7F) {\
1455 if (obj && obj in Class) print \"class \";\
1456 if (obj) print (object) obj;else print \"nothing\";print\" \";}\
1457 print \"(object number \", obj, \") \";\
1458 if (id<0) print \"is not of class \", (name) -id;",
1460 { print \" has no property \", (property) id;\
1461 p = #identifiers_table;\
1462 size = INDIV_PROP_START + p-->3;\
1463 if (id<0 || id>=size)\
1464 print \" (and nor has any other object)\";\
1466 print \" to \", (string) crime, \" **]^\";\
1470 /* Z__Region: Determines whether a value is:
1478 if (addr<36) rfalse;\
1479 @getmemsize endmem;\
1480 @jgeu addr endmem?outrange;\
1482 if (tb >= $E0) return 3;\
1483 if (tb >= $C0) return 2;\
1484 if (tb >= $70 && tb <= $7F && addr >= (0-->2)) return 1;\
1487 ]", "", "", "", "", ""
1489 { /* Unsigned__Compare: returns 1 if x>y, 0 if x=y, -1 if x<y */
1491 "Unsigned__Compare",
1500 ]", "", "", "", "", ""
1502 { /* Meta__class: returns the metaclass of an object */
1506 switch(Z__Region(obj))\
1507 { 2: return Routine;\
1509 1: if (obj in Class\
1510 || obj == Class or String or Routine or Object)\
1515 ]", "", "", "", "", ""
1519 /* CP__Tab: Search a property table for the given identifier.
1520 The definition here is a bit different from the Z-code veneer.
1521 This just searches the property table of obj for an entry with
1522 the given identifier. It return the address of the property
1523 entry, or 0 if nothing found. (Remember that the value returned
1524 is not the address of the property *data*; it's the structure
1525 which contains the address/length/flags.)
1528 "obj id otab max res;\
1529 if (Z__Region(obj)~=1) {RT__Err(23, obj); rfalse;}\
1530 otab = obj-->GOBJFIELD_PROPTAB;\
1531 if (otab == 0) return 0;\
1534 @binarysearch id 2 otab 10 max 0 0 res;\
1536 ]", "", "", "", "", ""
1540 /* Cl__Ms: Implements the five message-receiving properties of
1544 "_vararg_count obj id a b x y;\
1547 _vararg_count = _vararg_count - 2;\
1550 if (children(obj) <= 1) rfalse;\
1553 if (x provides create) {\
1556 y = _vararg_count + 2;\
1563 if (~~(a ofclass obj)) {\
1564 RT__Err(\"recreate\", a, -obj);\
1567 if (a provides destroy)\
1569 Copy__Primitive(a, child(obj));\
1570 if (a provides create) {\
1573 y = _vararg_count + 2;\
1580 if (~~(a ofclass obj)) {\
1581 RT__Err(\"destroy\", a, -obj);\
1584 if (a provides destroy)\
1586 Copy__Primitive(a, child(obj));\
1590 return children(obj)-1;\
1594 _vararg_count = _vararg_count - 2;\
1595 if (~~(a ofclass obj)) {\
1596 RT__Err(\"copy\", a, -obj);\
1599 if (~~(b ofclass obj)) {\
1600 RT__Err(\"copy\", b, -obj);\
1603 Copy__Primitive(a, b);\
1606 ]", "", "", "", "", ""
1609 /* RT__ChT: Check at run-time that a proposed object move is legal.
1610 Cause error and do nothing if not; otherwise move
1614 if (obj1==0 || Z__Region(obj1)~=1\
1615 || (obj1 == Class or String or Routine or Object) || obj1 in Class)\
1616 return RT__Err(16, obj1, obj2);\
1617 if (obj2==0 || Z__Region(obj2)~=1\
1618 || (obj2 == Class or String or Routine or Object) || obj2 in Class)\
1619 return RT__Err(17, obj1, obj2);\
1622 if (ix==obj1) return RT__Err(18, obj1, obj2);\
1626 if (obj1 has infix__watching\
1627 || obj2 has infix__watching || (debug_flag & 15))\
1628 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
1629 #ifnot; #ifdef DEBUG;\
1630 if (debug_flag & 15)\
1631 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
1633 OB__Move(obj1, obj2);\
1634 ]", "", "", "", "", ""
1637 /* RT__ChR: Check at run-time that a proposed object remove is legal.
1638 Cause error and do nothing if not; otherwise remove
1642 if (obj1==0 || Z__Region(obj1)~=1\
1643 || (obj1 == Class or String or Routine or Object) || obj1 in Class)\
1644 return RT__Err(15, obj1);\
1646 if (obj1 has infix__watching || (debug_flag & 15))\
1647 print \"[Removing \", (name) obj1, \"]^\";\
1648 #ifnot; #ifdef DEBUG;\
1649 if (debug_flag & 15)\
1650 print \"[Removing \", (name) obj1, \"]^\";\
1653 ]", "", "", "", "", ""
1655 { /* RT__ChG: check at run-time that a proposed attr give is legal
1656 cause error and do nothing if not; otherwise give */
1660 if (Z__Region(obj1) ~= 1) return RT__Err(14,obj1);\
1661 if (obj1 in Class || obj1 == Class or String or Routine or Object)\
1662 return RT__Err(14,obj1);\
1663 if (a<0 || a>=NUM_ATTR_BYTES*8) return RT__Err(19,obj1);\
1664 if (obj1 has a) return;",
1666 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
1667 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
1668 #ifnot; #ifdef DEBUG;\
1669 if (a ~= workflag && debug_flag & 15)\
1670 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
1672 give obj1 a; ]", "", "", "", ""
1674 { /* RT__ChGt: check at run-time that a proposed attr give ~ is legal
1675 cause error and do nothing if not; otherwise give */
1679 if (Z__Region(obj1) ~= 1) return RT__Err(14,obj1);\
1680 if (obj1 in Class || obj1 == Class or String or Routine or Object)\
1681 return RT__Err(14,obj1);\
1682 if (a<0 || a>=NUM_ATTR_BYTES*8) return RT__Err(19,obj1);\
1683 if (obj1 hasnt a) return;",
1685 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
1686 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
1687 #ifnot; #ifdef DEBUG;\
1688 if (a ~= workflag && debug_flag & 15)\
1689 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
1691 give obj1 ~a; ]", "", "", "", ""
1694 /* RT__ChPS: Check at run-time that a proposed property set is legal.
1695 Cause error and do nothing if not; otherwise make it.
1699 if (obj==0 || Z__Region(obj)~=1\
1700 || (obj == Class or String or Routine or Object) || obj in Class)\
1701 return RT__Err(\"set\", obj, prop);\
1702 res = WV__Pr(obj, prop, val);\
1704 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,prop,val);\
1705 #ifnot; #ifdef DEBUG;\
1706 if (debug_flag & 15) RT__TrPS(obj,prop,val);\
1709 ]", "", "", "", "", ""
1711 { /* RT__ChPR: check at run-time that a proposed property read is legal.
1712 cause error and return 0 if not; otherwise read it */
1715 if (obj==0 or Class or String or Routine or Object || Z_Region(obj)~=1 )\
1716 {RT__Err(\"read\", obj, prop); obj=2;}\
1717 val = RV__Pr(obj, prop);",
1718 "return val; ]", "", "", "", ""
1720 { /* RT__TrPS: trace property settings */
1724 print \"[Setting \",(name) obj,\".\",(property) prop,\
1725 \" to \",val,\"]^\"; ]",
1729 /* RT__ChLDB: Check at run-time that it's safe to load a byte
1730 and return the byte.
1733 "base offset a b val;\
1736 if (Unsigned__Compare(a, b) >= 0)\
1737 return RT__Err(24);\
1738 @aloadb base offset val;\
1740 ]", "", "", "", "", ""
1744 /* RT__ChLDW: Check at run-time that it's safe to load a word
1748 "base offset a b val;\
1749 a=base+WORDSIZE*offset;\
1751 if (Unsigned__Compare(a, b) >= 0)\
1752 return RT__Err(25);\
1753 @aload base offset val;\
1755 ]", "", "", "", "", ""
1759 /* RT__ChSTB: Check at run-time that it's safe to store a byte
1763 "base offset val a b;\
1766 if (Unsigned__Compare(a, b) >= 0) jump ChSTB_Fail;\
1768 if (Unsigned__Compare(a, b) < 0) jump ChSTB_Fail;\
1769 @astoreb base offset val;\
1772 return RT__Err(26);\
1773 ]", "", "", "", "", ""
1777 /* RT__ChSTW: Check at run-time that it's safe to store a word
1781 "base offset val a b;\
1782 a=base+WORDSIZE*offset;\
1784 if (Unsigned__Compare(a, b) >= 0) jump ChSTW_Fail;\
1786 if (Unsigned__Compare(a, b) < 0) jump ChSTW_Fail;\
1787 @astore base offset val;\
1790 return RT__Err(27);\
1791 ]", "", "", "", "", ""
1795 /* RT__ChPrintC: Check at run-time that it's safe to print (char)
1800 if (c<10 || (c>10 && c<32) || (c>126 && c<160))\
1801 return RT__Err(33,c);\
1806 ]", "", "", "", "", ""
1809 /* RT__ChPrintA: Check at run-time that it's safe to print (address)
1815 return RT__Err(34);\
1816 @getmemsize endmem;\
1817 if (Unsigned__Compare(addr, endmem) >= 0)\
1818 return RT__Err(34);\
1819 if (addr->0 ~= $60)\
1820 return RT__Err(34);\
1822 ]", "", "", "", "", ""
1825 /* Check at run-time that it's safe to print (string) and do so.
1829 if (Z__Region(str) ~= 3)\
1830 return RT__Err(35);\
1832 ]", "", "", "", "", ""
1835 /* Check at run-time that it's safe to print (object) and do so.
1839 if (Z__Region(obj) ~= 1)\
1840 return RT__Err(36);\
1841 @aload obj GOBJFIELD_NAME sp; @streamstr sp;\
1842 ]", "", "", "", "", ""
1845 /* OB__Move: Move an object within the object tree. This does no
1846 more error checking than the Z-code \"move\" opcode.
1849 "obj dest par chi sib;\
1850 par = obj-->GOBJFIELD_PARENT;\
1852 chi = par-->GOBJFIELD_CHILD;\
1854 par-->GOBJFIELD_CHILD = obj-->GOBJFIELD_SIBLING;\
1858 sib = chi-->GOBJFIELD_SIBLING;\
1863 chi-->GOBJFIELD_SIBLING = obj-->GOBJFIELD_SIBLING;\
1866 obj-->GOBJFIELD_SIBLING = dest-->GOBJFIELD_CHILD;\
1867 obj-->GOBJFIELD_PARENT = dest;\
1868 dest-->GOBJFIELD_CHILD = obj;\
1870 ]", "", "", "", "", ""
1874 /* OB__Remove: Remove an object from the tree. This does no
1875 more error checking than the Z-code \"remove\" opcode.
1879 par = obj-->GOBJFIELD_PARENT;\
1882 chi = par-->GOBJFIELD_CHILD;\
1884 par-->GOBJFIELD_CHILD = obj-->GOBJFIELD_SIBLING;\
1888 sib = chi-->GOBJFIELD_SIBLING;\
1893 chi-->GOBJFIELD_SIBLING = obj-->GOBJFIELD_SIBLING;\
1895 obj-->GOBJFIELD_SIBLING = 0;\
1896 obj-->GOBJFIELD_PARENT = 0;\
1898 ]", "", "", "", "", ""
1902 /* Print__Addr: Handle the print (address) statement. In Glulx,
1903 this behaves differently than on the Z-machine; it can *only*
1904 print dictionary words.
1908 if (addr->0 ~= $60) {\
1909 print \"(\", addr, \": not dict word)\";\
1912 for (ix=1 : ix <= DICT_WORD_SIZE : ix++) {\
1913 #ifndef DICT_IS_UNICODE;\
1918 if (ch == 0) return;\
1921 ]", "", "", "", "", ""
1925 /* Glk__Wrap: This is a wrapper for the @glk opcode. It just passes
1926 all its arguments into the Glk dispatcher, and returns the Glk
1930 "_vararg_count callid retval;\
1932 _vararg_count = _vararg_count - 1;\
1933 @glk callid _vararg_count retval;\
1935 ]", "", "", "", "", ""
1939 /* Dynam__String: Set dynamic string (printing variable) num to the
1940 given val, which can be any string or function.
1944 if (num < 0 || num >= #dynam_string_table-->0)\
1945 return RT__Err(40, num);\
1946 (#dynam_string_table)-->(num+1) = val;\
1947 ]", "", "", "", "", ""
1953 static void mark_as_needed_z(int code)
1956 if (veneer_routine_needs_compilation[code] == VR_UNUSED)
1957 { veneer_routine_needs_compilation[code] = VR_CALLED;
1958 /* Here each routine must mark every veneer routine it explicitly
1962 mark_as_needed_z(RT__TrPS_VR);
1963 mark_as_needed_z(RT__Err_VR);
1966 mark_as_needed_z(RT__Err_VR);
1969 mark_as_needed_z(Z__Region_VR);
1970 mark_as_needed_z(Cl__Ms_VR);
1971 mark_as_needed_z(RT__Err_VR);
1977 mark_as_needed_z(RT__Err_VR);
1978 mark_as_needed_z(RT__TrPS_VR);
1981 mark_as_needed_z(CP__Tab_VR);
1984 mark_as_needed_z(RT__Err_VR);
1987 mark_as_needed_z(Z__Region_VR);
1990 mark_as_needed_z(Z__Region_VR);
1991 mark_as_needed_z(RT__Err_VR);
1994 mark_as_needed_z(Unsigned__Compare_VR);
1997 mark_as_needed_z(Z__Region_VR);
2000 mark_as_needed_z(RT__Err_VR);
2001 mark_as_needed_z(Copy__Primitive_VR);
2008 mark_as_needed_z(RT__Err_VR);
2011 mark_as_needed_z(RT__Err_VR);
2012 mark_as_needed_z(RT__TrPS_VR);
2018 mark_as_needed_z(Unsigned__Compare_VR);
2019 mark_as_needed_z(RT__Err_VR);
2021 case RT__ChPrintC_VR:
2022 mark_as_needed_z(RT__Err_VR);
2024 case RT__ChPrintA_VR:
2025 mark_as_needed_z(Unsigned__Compare_VR);
2026 mark_as_needed_z(RT__Err_VR);
2028 case RT__ChPrintS_VR:
2029 case RT__ChPrintO_VR:
2030 mark_as_needed_z(RT__Err_VR);
2031 mark_as_needed_z(Z__Region_VR);
2037 static void mark_as_needed_g(int code)
2040 if (veneer_routine_needs_compilation[code] == VR_UNUSED)
2041 { veneer_routine_needs_compilation[code] = VR_CALLED;
2042 /* Here each routine must mark every veneer routine it explicitly
2046 case PrintShortName_VR:
2047 mark_as_needed_g(Metaclass_VR);
2049 case Print__Pname_VR:
2050 mark_as_needed_g(PrintShortName_VR);
2053 mark_as_needed_g(RA__Pr_VR);
2054 mark_as_needed_g(RT__TrPS_VR);
2055 mark_as_needed_g(RT__Err_VR);
2058 mark_as_needed_g(RA__Pr_VR);
2059 mark_as_needed_g(RT__Err_VR);
2062 mark_as_needed_g(RA__Pr_VR);
2063 mark_as_needed_g(RL__Pr_VR);
2064 mark_as_needed_g(PrintShortName_VR);
2065 mark_as_needed_g(Print__Pname_VR);
2066 mark_as_needed_g(Z__Region_VR);
2067 mark_as_needed_g(Cl__Ms_VR);
2068 mark_as_needed_g(Glk__Wrap_VR);
2069 mark_as_needed_g(RT__Err_VR);
2075 mark_as_needed_g(RT__Err_VR);
2076 mark_as_needed_g(RT__TrPS_VR);
2079 mark_as_needed_g(OC__Cl_VR);
2080 mark_as_needed_g(CP__Tab_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(RT__Err_VR);
2091 mark_as_needed_g(RA__Pr_VR);
2092 mark_as_needed_g(Z__Region_VR);
2095 mark_as_needed_g(RA__Pr_VR);
2096 mark_as_needed_g(RL__Pr_VR);
2097 mark_as_needed_g(Z__Region_VR);
2098 mark_as_needed_g(RT__Err_VR);
2100 case Copy__Primitive_VR:
2101 mark_as_needed_g(CP__Tab_VR);
2104 mark_as_needed_g(Unsigned__Compare_VR);
2108 mark_as_needed_g(Z__Region_VR);
2111 mark_as_needed_g(OC__Cl_VR);
2112 mark_as_needed_g(OP__Pr_VR);
2113 mark_as_needed_g(RT__Err_VR);
2114 mark_as_needed_g(Copy__Primitive_VR);
2115 mark_as_needed_g(OB__Remove_VR);
2116 mark_as_needed_g(OB__Move_VR);
2120 mark_as_needed_g(RT__Err_VR);
2123 mark_as_needed_g(RT__Err_VR);
2124 mark_as_needed_g(Z__Region_VR);
2125 mark_as_needed_g(OB__Remove_VR);
2128 mark_as_needed_g(RT__Err_VR);
2129 mark_as_needed_g(Z__Region_VR);
2130 mark_as_needed_g(OB__Move_VR);
2133 mark_as_needed_g(RT__Err_VR);
2134 mark_as_needed_g(RT__TrPS_VR);
2135 mark_as_needed_g(WV__Pr_VR);
2138 mark_as_needed_g(RT__Err_VR);
2139 mark_as_needed_g(RV__Pr_VR); return;
2144 mark_as_needed_g(Unsigned__Compare_VR);
2145 mark_as_needed_g(RT__Err_VR);
2147 case RT__ChPrintC_VR:
2148 mark_as_needed_g(RT__Err_VR);
2150 case RT__ChPrintA_VR:
2151 mark_as_needed_g(Unsigned__Compare_VR);
2152 mark_as_needed_g(RT__Err_VR);
2153 mark_as_needed_g(Print__Addr_VR);
2155 case RT__ChPrintS_VR:
2156 case RT__ChPrintO_VR:
2157 mark_as_needed_g(RT__Err_VR);
2158 mark_as_needed_g(Z__Region_VR);
2160 case Print__Addr_VR:
2161 mark_as_needed_g(RT__Err_VR);
2163 case Dynam__String_VR:
2164 mark_as_needed_g(RT__Err_VR);
2170 extern assembly_operand veneer_routine(int code)
2171 { assembly_operand AO;
2173 INITAOTV(&AO, LONG_CONSTANT_OT, code);
2174 AO.marker = VROUTINE_MV;
2175 mark_as_needed_z(code);
2178 INITAOTV(&AO, CONSTANT_OT, code);
2179 AO.marker = VROUTINE_MV;
2180 mark_as_needed_g(code);
2185 static void compile_symbol_table_routine(void)
2186 { int32 j, nl, arrays_l, routines_l, constants_l;
2187 assembly_operand AO, AO2, AO3;
2189 /* Assign local var names for the benefit of the debugging information
2191 local_variable_texts[0] = "dummy1";
2192 local_variable_texts[1] = "dummy2";
2194 veneer_mode = TRUE; j = symbol_index("Symb__Tab", -1);
2196 assemble_routine_header(2, FALSE, "Symb__Tab", FALSE, j),
2198 sflags[j] |= SYSTEM_SFLAG + USED_SFLAG;
2199 if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
2203 if (define_INFIX_switch == FALSE)
2204 { assemblez_0(rfalse_zc);
2205 variable_usage[1] = TRUE;
2206 variable_usage[2] = TRUE;
2207 assemble_routine_end(FALSE, null_debug_locations);
2208 veneer_mode = FALSE;
2212 INITAOTV(&AO, VARIABLE_OT, 1);
2213 INITAOT(&AO2, SHORT_CONSTANT_OT);
2214 INITAOT(&AO3, LONG_CONSTANT_OT);
2216 arrays_l = next_label++;
2217 routines_l = next_label++;
2218 constants_l = next_label++;
2220 sequence_point_follows = FALSE;
2222 assemblez_2_branch(je_zc, AO, AO2, arrays_l, TRUE);
2223 sequence_point_follows = FALSE;
2225 assemblez_2_branch(je_zc, AO, AO2, routines_l, TRUE);
2226 sequence_point_follows = FALSE;
2228 assemblez_2_branch(je_zc, AO, AO2, constants_l, TRUE);
2229 sequence_point_follows = FALSE;
2230 assemblez_0(rtrue_zc);
2232 assemble_label_no(arrays_l);
2234 for (j=0; j<no_arrays; j++)
2236 if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
2237 else AO2.type = LONG_CONSTANT_OT;
2239 sequence_point_follows = FALSE;
2240 assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
2241 AO3.value = array_sizes[j];
2243 assemblez_store(temp_var2, AO3);
2244 AO3.value = array_types[j];
2245 if (sflags[array_symbols[j]] & (INSF_SFLAG+SYSTEM_SFLAG))
2246 AO3.value = AO3.value + 16;
2248 assemblez_store(temp_var3, AO3);
2249 AO3.value = svals[array_symbols[j]];
2250 AO3.marker = (!array_locs[j] ? ARRAY_MV : STATIC_ARRAY_MV);
2251 assemblez_1(ret_zc, AO3);
2252 assemble_label_no(nl);
2255 sequence_point_follows = FALSE;
2256 assemblez_0(rtrue_zc);
2257 assemble_label_no(routines_l);
2258 for (j=0; j<no_named_routines; j++)
2260 if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
2261 else AO2.type = LONG_CONSTANT_OT;
2263 sequence_point_follows = FALSE;
2264 assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
2266 if (sflags[named_routine_symbols[j]]
2267 & (INSF_SFLAG+SYSTEM_SFLAG)) AO3.value = 16;
2269 assemblez_store(temp_var3, AO3);
2270 AO3.value = svals[named_routine_symbols[j]];
2271 AO3.marker = IROUTINE_MV;
2272 assemblez_1(ret_zc, AO3);
2273 assemble_label_no(nl);
2275 sequence_point_follows = FALSE;
2276 assemblez_0(rtrue_zc);
2278 assemble_label_no(constants_l);
2279 for (j=0, no_named_constants=0; j<no_symbols; j++)
2280 { if (((stypes[j] == OBJECT_T) || (stypes[j] == CLASS_T)
2281 || (stypes[j] == CONSTANT_T))
2282 && ((sflags[j] & (UNKNOWN_SFLAG+ACTION_SFLAG))==0))
2283 { AO2.value = no_named_constants++;
2284 if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
2285 else AO2.type = LONG_CONSTANT_OT;
2287 sequence_point_follows = FALSE;
2288 assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
2290 if (stypes[j] == OBJECT_T) AO3.value = 2;
2291 if (stypes[j] == CLASS_T) AO3.value = 1;
2292 if (sflags[j] & (INSF_SFLAG+SYSTEM_SFLAG))
2293 AO3.value = AO3.value + 16;
2295 assemblez_store(temp_var3, AO3);
2297 AO3.marker = SYMBOL_MV;
2298 assemblez_1(ret_zc, AO3);
2299 assemble_label_no(nl);
2302 no_named_constants = 0; AO3.marker = 0;
2304 sequence_point_follows = FALSE;
2305 assemblez_0(rfalse_zc);
2306 variable_usage[1] = TRUE;
2307 variable_usage[2] = TRUE;
2308 assemble_routine_end(FALSE, null_debug_locations);
2309 veneer_mode = FALSE;
2313 if (define_INFIX_switch == FALSE)
2314 { assembleg_1(return_gc, zero_operand);
2315 variable_usage[1] = TRUE;
2316 variable_usage[2] = TRUE;
2317 assemble_routine_end(FALSE, null_debug_locations);
2318 veneer_mode = FALSE;
2322 error("*** Infix symbol-table routine is not yet implemented. ***");
2326 extern void compile_veneer(void)
2327 { int i, j, try_veneer_again;
2330 if (module_switch) return;
2332 VRs = (!glulx_mode) ? VRs_z : VRs_g;
2334 /* Called at the end of the pass to insert as much of the veneer as is
2335 needed and not elsewhere compiled. */
2337 veneer_symbols_base = no_symbols;
2339 /* for (i=0; i<VENEER_ROUTINES; i++)
2340 printf("%s %d %d %d %d %d %d\n", VRs[i].name,
2341 strlen(VRs[i].source1), strlen(VRs[i].source2),
2342 strlen(VRs[i].source3), strlen(VRs[i].source4),
2343 strlen(VRs[i].source5), strlen(VRs[i].source6)); */
2345 try_veneer_again = TRUE;
2346 while (try_veneer_again)
2347 { try_veneer_again = FALSE;
2348 for (i=0; i<VENEER_ROUTINES; i++)
2349 { if (veneer_routine_needs_compilation[i] == VR_CALLED)
2350 { j = symbol_index(VRs[i].name, -1);
2351 if (sflags[j] & UNKNOWN_SFLAG)
2352 { veneer_mode = TRUE;
2353 strcpy(veneer_source_area, VRs[i].source1);
2354 strcat(veneer_source_area, VRs[i].source2);
2355 strcat(veneer_source_area, VRs[i].source3);
2356 strcat(veneer_source_area, VRs[i].source4);
2357 strcat(veneer_source_area, VRs[i].source5);
2358 strcat(veneer_source_area, VRs[i].source6);
2360 parse_routine(veneer_source_area, FALSE,
2361 VRs[i].name, TRUE, j),
2363 veneer_mode = FALSE;
2364 if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
2367 { if (stypes[j] != ROUTINE_T)
2368 error_named("The following name is reserved by Inform for its \
2369 own use as a routine name; you can use it as a routine name yourself (to \
2370 override the standard definition) but cannot use it for anything else:",
2373 sflags[j] |= USED_SFLAG;
2375 veneer_routine_address[i] = svals[j];
2376 veneer_routine_needs_compilation[i] = VR_COMPILED;
2377 try_veneer_again = TRUE;
2382 compile_symbol_table_routine();
2385 /* ========================================================================= */
2386 /* Data structure management routines */
2387 /* ------------------------------------------------------------------------- */
2389 extern void init_veneer_vars(void)
2393 extern void veneer_begin_pass(void)
2395 veneer_mode = FALSE;
2396 for (i=0; i<VENEER_ROUTINES; i++)
2397 { veneer_routine_needs_compilation[i] = VR_UNUSED;
2398 veneer_routine_address[i] = 0;
2402 extern void veneer_allocate_arrays(void)
2403 { veneer_source_area = my_malloc(16384, "veneer source code area");
2406 extern void veneer_free_arrays(void)
2407 { my_free(&veneer_source_area, "veneer source code area");
2410 /* ========================================================================= */