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 /* Copyright (c) Graham Nelson 1993 - 2018 */
8 /* This file is part of Inform. */
10 /* Inform is free software: you can redistribute it and/or modify */
11 /* it under the terms of the GNU General Public License as published by */
12 /* the Free Software Foundation, either version 3 of the License, or */
13 /* (at your option) any later version. */
15 /* Inform is distributed in the hope that it will be useful, */
16 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
17 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
18 /* GNU General Public License for more details. */
20 /* You should have received a copy of the GNU General Public License */
21 /* along with Inform. If not, see https://gnu.org/licenses/ */
23 /* ------------------------------------------------------------------------- */
27 int veneer_mode; /* Is the code currently being
28 compiled from the veneer? */
30 static debug_locations null_debug_locations =
31 { { 0, 0, 0, 0, 0, 0, 0 }, NULL, 0 };
33 extern void compile_initial_routine(void)
35 /* The first routine present in memory in any Inform game, beginning
36 at the code area start position, always has 0 local variables
37 (since the interpreter begins execution with an empty stack frame):
38 and it must "quit" rather than "return".
40 In order not to impose these restrictions on "Main", we compile a
41 trivial routine consisting of a call to "Main" followed by "quit". */
46 j = symbol_index("Main__", -1);
48 assemble_routine_header(0, FALSE, "Main__", FALSE, j),
50 sflags[j] |= SYSTEM_SFLAG + USED_SFLAG;
51 if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
55 INITAOTV(&AO, LONG_CONSTANT_OT, 0);
58 sequence_point_follows = FALSE;
60 if (version_number > 3)
61 assemblez_1_to(call_vs_zc, AO, temp_var1);
63 assemblez_1_to(call_zc, AO, temp_var1);
70 INITAOTV(&AO, CONSTANT_OT, 0);
73 sequence_point_follows = FALSE;
75 assembleg_3(call_gc, AO, zero_operand, zero_operand);
76 assembleg_1(return_gc, zero_operand);
80 assemble_routine_end(FALSE, null_debug_locations);
83 /* ------------------------------------------------------------------------- */
84 /* The rest of the veneer is applied at the end of the pass, as required. */
85 /* ------------------------------------------------------------------------- */
87 static int veneer_routine_needs_compilation[VENEER_ROUTINES];
88 int32 veneer_routine_address[VENEER_ROUTINES];
89 static int veneer_symbols_base;
95 typedef struct VeneerRoutine_s
105 static char *veneer_source_area;
107 static VeneerRoutine VRs_z[VENEER_ROUTINES] =
109 /* Box__Routine: the only veneer routine used in the implementation of
110 an actual statement ("box", of course), written in a
111 hybrid of Inform and assembly language. Note the
112 transcription of the box text to the transcript
113 output stream (-1, or $ffff). */
116 "maxw table n w w2 line lc t;\
131 { @set_cursor line w;\
133 @set_cursor line w2;\
135 if (t~=0) print (string) t;\
144 @output_stream $ffff;\
149 if (w ~= 0) print (string) w;\
161 /* This batch of routines is expected to be defined (rather better) by
162 the Inform library: these minimal forms here are provided to prevent
163 tiny non-library-using programs from failing to compile when certain
164 legal syntaxes (such as <<Action a b>>;) are used. */
167 "a b c d; print \"Action <\", a, \" \", b, \" \", c;\
168 if (d) print \", \", d; print \">^\";\
169 ]", "", "", "", "", ""
172 "obj; print \"the \", obj; ]", "", "", "", "", ""
175 "obj; print \"a \", obj; ]", "", "", "", "", ""
178 "obj; print \"The \", obj; ]", "", "", "", "", ""
181 "obj; print \"A \", obj; ]", "", "", "", "", ""
184 "obj; switch(metaclass(obj))\
185 { 0: print \"nothing\";\
186 Object: @print_obj obj;\
187 Class: print \"class \"; @print_obj obj;\
188 Routine: print \"(routine at \", obj, \")\";\
189 String: print \"(string at \", obj, \")\";\
190 } ]", "", "", "", "", ""
193 "obj; print obj; ]", "", "", "", "", ""
198 { cla = #classes_table-->(prop & $ff);\
199 print (name) cla, \"::\";\
200 if ((prop & $8000) == 0) prop = (prop & $3f00)/$100;\
202 { prop = (prop & $7f00)/$100;\
204 while ((i-->0 ~= 0) && (prop>0))\
208 prop = (i-->0) & $7fff;\
211 "p = #identifiers_table;\
213 if (prop<=0 || prop>=size || p-->prop==0)\
214 print \"<number \", prop, \">\";\
215 else print (string) p-->prop;\
219 /* The remaining routines make up the run-time half of the object
220 orientation system, and need never be present for Inform 5 programs. */
223 /* WV__Pr: write a value to the property for the given
224 object having the given identifier */
227 "obj identifier value x;\
228 x = obj..&identifier;\
229 if (x==0) { RT__Err(\"write to\", obj, identifier); return; }\
231 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,value);\
232 #ifnot; #ifdef DEBUG;\
233 if (debug_flag & 15) RT__TrPS(obj,identifier,value);\
236 ]", "", "", "", "", ""
239 /* RV__Pr: read a value from the property for the given
240 object having the given identifier */
244 x = obj..&identifier;\
246 { if (identifier >= 1 && identifier < 64 && obj.#identifier <= 2)\
247 return obj.identifier;\
248 RT__Err(\"read\", obj, identifier); return; }\
249 if (obj..#identifier > 2) RT__Err(\"read\", obj, identifier, 2);\
251 ]", "", "", "", "", ""
253 { /* CA__Pr: call, that is, print-or-run-or-read, a property:
254 this exactly implements obj..prop(...). Note that
255 classes (members of Class) have 5 built-in properties
256 inherited from Class: create, recreate, destroy,
257 remaining and copy. Implementing these here prevents
258 the need for a full metaclass inheritance scheme. */
261 "obj id a b c d e f x y z s s2 n m;\
262 if (obj < 1 || obj > #largest_object-255)\
263 { switch(Z__Region(obj))\
264 { 2: if (id == call)\
265 { s = sender; sender = self; self = obj;\
266 #ifdef action;sw__var=action;#endif;\
267 x = indirect(obj, a, b, c, d, e, f);\
268 self = sender; sender = s; return x; }\
270 "3: if (id == print) { @print_paddr obj; rtrue; }\
271 if (id == print_to_array)\
272 { @output_stream 3 a; @print_paddr obj; @output_stream -3;\
278 @check_arg_count 3 ?~A__x;y++;@check_arg_count 4 ?~A__x;y++;\
279 @check_arg_count 5 ?~A__x;y++;@check_arg_count 6 ?~A__x;y++;\
280 @check_arg_count 7 ?~A__x;y++;@check_arg_count 8 ?~A__x;y++;.A__x;",
281 "#ifdef INFIX;if (obj has infix__watching) n=1;#endif;\
282 #ifdef DEBUG;if (debug_flag & 1 ~= 0) n=1;#endif;\
284 #ifdef DEBUG;n=debug_flag & 1; debug_flag=debug_flag-n;#endif;\
285 print \"[ ~\", (name) obj, \"~.\", (property) id, \"(\";\
286 switch(y) { 1: print a; 2: print a,\",\",b; 3: print a,\",\",b,\",\",c;\
287 4: print a,\",\",b,\",\",c,\",\",d;\
288 5: print a,\",\",b,\",\",c,\",\",d,\",\",e;\
289 6: print a,\",\",b,\",\",c,\",\",d,\",\",e,\",\",f; }\
291 #ifdef DEBUG;debug_flag = debug_flag + n;#endif;\
293 "if (id > 0 && id < 64)\
294 { x = obj.&id; if (x==0) { x=$000a-->0 + 2*(id-1); n=2; }\
297 { if (id>=64 && id<69 && obj in Class)\
298 return Cl__Ms(obj,id,y,a,b,c,d);\
300 if (x == 0) { .Call__Error;\
301 RT__Err(\"send message\", obj, id); return; }\
303 if (id&$C000==$4000)\
304 switch (n&$C0) { 0: n=1; $40: n=2; $80: n=n&$3F; }\
307 { if (x-->m==$ffff) rfalse;\
308 switch(Z__Region(x-->m))\
309 { 2: s = sender; sender = self; self = obj; s2 = sw__var;\
311 if (id==life) sw__var=reason_code; else sw__var=action;\
313 switch(y) { 0: z = indirect(x-->m); 1: z = indirect(x-->m, a);\
314 2: z = indirect(x-->m, a, b); 3: z = indirect(x-->m, a, b, c);",
315 "4: z = indirect(x-->m, a, b, c, d); 5:z = indirect(x-->m, a, b, c, d, e);\
316 6: z = indirect(x-->m, a, b, c, d, e, f); }\
317 self = sender; sender = s; sw__var = s2;\
318 if (z ~= 0) return z;\
319 3: print_ret (string) x-->m;\
320 default: return x-->m;\
327 /* IB__Pr: ++(individual property) */
331 x = obj..&identifier;\
332 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
334 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)+1);\
335 #ifnot; #ifdef DEBUG;\
336 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
339 ]", "", "", "", "", ""
342 /* IA__Pr: (individual property)++ */
346 x = obj..&identifier;\
347 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
349 if (obj has infix__watching || (debug_flag & 15))\
350 RT__TrPS(obj,identifier,(x-->0)+1);\
351 #ifnot; #ifdef DEBUG;\
352 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
355 ]", "", "", "", "", ""
358 /* DB__Pr: --(individual property) */
362 x = obj..&identifier;\
363 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
365 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
366 #ifnot; #ifdef DEBUG;\
367 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
370 ]", "", "", "", "", ""
373 /* DA__Pr: (individual property)-- */
377 x = obj..&identifier;\
378 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
380 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
381 #ifnot; #ifdef DEBUG;\
382 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
385 ]", "", "", "", "", ""
388 /* RA__Pr: read the address of a property value for a given object,
389 returning 0 if it doesn't provide this individual
393 "obj identifier i otherid cla;\
395 if (identifier<64 && identifier>0) return obj.&identifier;\
396 if (identifier & $8000 ~= 0)\
397 { cla = #classes_table-->(identifier & $ff);\
398 if (cla.&3 == 0) rfalse;\
399 if (~~(obj ofclass cla)) rfalse;\
400 identifier = (identifier & $7f00) / $100;\
402 while (identifier>0)\
408 "if (identifier & $4000 ~= 0)\
409 { cla = #classes_table-->(identifier & $ff);\
410 identifier = (identifier & $3f00) / $100;\
411 if (~~(obj ofclass cla)) rfalse; i=0-->5;\
412 if (cla == 2) return i+2*identifier-2;\
413 i = 0-->((i+124+cla*14)/2);\
414 i = CP__Tab(i + 2*(0->i) + 1, -1)+6;\
415 return CP__Tab(i, identifier);\
417 if (obj.&3 == 0) rfalse;\
419 { if (identifier<64 || identifier>=72) rfalse;\
422 otherid = identifier | $8000;\
425 { if (i-->0 == identifier or otherid)\
433 /* RL__Pr: read the property length of an individual property value,
434 returning 0 if it isn't provided by the given object */
438 if (identifier<64 && identifier>0) return obj.#identifier;\
439 x = obj..&identifier;\
441 if (identifier&$C000==$4000)\
442 switch (((x-1)->0)&$C0)\
443 { 0: return 1; $40: return 2; $80: return ((x-1)->0)&$3F; }\
445 ]", "", "", "", "", ""
448 /* RA__Sc: implement the "superclass" (::) operator,
449 returning an identifier */
452 "cla identifier otherid i j k;\
453 if (cla notin 1 && cla > 4)\
454 { RT__Err(\"be a '::' superclass\", cla, -1); rfalse; }\
455 if (self ofclass cla) otherid = identifier | $8000;\
456 for (j=0: #classes_table-->j ~= 0: j++)\
457 { if (cla==#classes_table-->j)\
458 { if (identifier < 64) return $4000 + identifier*$100 + j;\
459 if (cla.&3 == 0) break;\
462 { if (i-->0 == identifier or otherid)\
463 return $8000 + k*$100 + j;\
470 RT__Err(\"make use of\", cla, identifier);\
475 /* OP__Pr: test whether or not given object provides individual
476 property with the given identifier code */
480 if (obj<1 || obj > (#largest_object-255))\
481 { if (identifier ~= print or print_to_array or call) rfalse;\
482 switch(Z__Region(obj))\
483 { 2: if (identifier == call) rtrue;\
484 3: if (identifier == print or print_to_array) rtrue;\
489 { if (obj.&identifier ~= 0) rtrue;\
492 if (obj..&identifier ~= 0) rtrue;\
493 if (identifier<72 && obj in 1) rtrue;\
498 /* OC__Cl: test whether or not given object is of the given class */
502 if (obj<1 || obj > (#largest_object-255))\
503 { if (cla ~= 3 or 4) rfalse;\
504 if (Z__Region(obj) == cla-1) rtrue;\
509 if (obj in 1) rtrue;\
511 } else if (cla == 2) {\
513 if (obj in 1) rfalse;\
515 } else if (cla == 3 or 4) {\
518 "if (cla notin 1) { RT__Err(\"apply 'ofclass' for\", cla, -1);rfalse;}\
519 @get_prop_addr obj 2 -> a;\
521 @get_prop_len a -> n;\
522 for (j=0: j<n/2: j++)\
523 { if (a-->j == cla) rtrue;\
528 { /* Copy__Primitive: routine to "deep copy" objects */
531 "o1 o2 a1 a2 n m l size identifier;\
533 { if (o2 has n) give o1 n;\
536 for (n=1:n<64:n++) if (n~=2 or 3)\
537 { a1 = o1.&n; a2 = o2.&n; size = o1.#n;\
538 if (a1~=0 && a2~=0 && size==o2.#n)\
539 { for (m=0:m<size:m++) a1->m=a2->m;\
542 "if (o1.&3 == 0 || o2.&3 == 0) return;\
543 for (n=o2.3: n-->0 ~= 0: n = n + size + 3)\
544 { identifier = n-->0;\
546 for (m=o1.3: m-->0 ~= 0: m = m + m->2 + 3)\
547 if ((identifier & $7fff == (m-->0) & $7fff) && size==m->2)\
548 for (l=3: l<size+3: l++) m->l = n->l;\
552 { /* RT__Err: for run-time errors occurring in the above: e.g.,
553 an attempt to write to a non-existent individual
557 "crime obj id size p q;\
558 print \"^[** Programming error: \";\
559 if (crime<0) jump RErr;\
560 if (crime==1) { print \"class \"; @print_obj obj;\
561 \": 'create' can have 0 to 3 parameters only **]\";}\
562 if (crime == 32) \"objectloop broken because the object \",\
563 (name) obj, \" was moved while the loop passed through it **]\";\
564 if (crime == 33) \"tried to print (char) \", obj,\
565 \", which is not a valid ZSCII character code for output **]\";\
566 if (crime == 34) \"tried to print (address) on something not the \",\
567 \"byte address of a string **]\";\
568 if (crime == 35) \"tried to print (string) on something not a \",\
570 if (crime == 36) \"tried to print (object) on something not an \",\
571 \"object or class **]\";",
572 "if (crime < 32) { print \"tried to \";\
573 if (crime >= 28) { if (crime==28 or 29) print \"read from \";\
574 else print \"write to \";\
575 if (crime==29 or 31) print \"-\"; print \"->\", obj,\
576 \" in the\"; switch(size&7){0,1:q=0; 2:print \" string\";\
577 q=1; 3:print \" table\";q=1; 4:print \" buffer\";q=WORDSIZE;} \
578 if(size&16) print\" (->)\"; if(size&8) print\" (-->)\";\
579 \" array ~\", (string) #array_names_offset-->p,\
580 \"~, which has entries \", q, \" up to \",id,\" **]\"; }\
581 if (crime >= 24 && crime <=27) { if (crime<=25) print \"read\";\
582 else print \"write\"; print \" outside memory using \";\
583 switch(crime) { 24,26:\"-> **]\"; 25,27:\"--> **]\"; } }\
584 if (crime < 4) print \"test \"; else\
585 if (crime < 12 || crime > 20) print \"find the \"; else\
586 if (crime < 14) print \"use \";\
587 if (crime==20) \"divide by zero **]\"; print \"~\";\
589 2: print \"in~ or ~notin\"; 3: print \"has~ or ~hasnt\";\
590 4: print \"parent\"; 5: print \"eldest\"; 6: print \"child\";\
591 7: print \"younger\"; 8: print \"sibling\"; 9: print \"children\";\
592 10: print \"youngest\"; 11: print \"elder\";\
593 12: print \"objectloop\"; 13: print \"}~ at end of ~objectloop\";\
594 14: \"give~ an attribute to \", (name) obj, \" **]\";\
595 15: \"remove~ \", (name) obj, \" **]\";",
596 "16,17,18: print \"move~ \", (name) obj, \" to \", (name) id;\
597 if (crime==18) { print \", which would make a loop: \",(name) obj;\
598 p=id; if (p==obj) p=obj;\
599 else do { print \" in \", (name) p; p=parent(p);} until (p==obj);\
600 \" in \", (name) p, \" **]\"; }\
601 \" **]\"; 19: \"give~ or test ~has~ or ~hasnt~ with a non-attribute"\
602 " on the object \",(name) obj,\" **]\";\
603 21: print \".&\"; 22: print \".#\"; 23: print \".\"; }\
604 \"~ of \", (name) obj, \" **]\"; }",
605 ".RErr; if (obj>=0 && obj<=(#largest_object-255)) {\
606 if (obj && obj in Class) print \"class \";\
607 if (obj) @print_obj obj;else print \"nothing\";print\" \";}\
608 print \"(object number \", obj, \") \";\
609 if (id<0) print \"is not of class \", (name) -id;",
610 "else if (size) print \"has a property \", (property) id,\
611 \", but it is longer than 2 bytes so you cannot use ~.~\";\
613 { print \" has no property \", (property) id;\
614 p = #identifiers_table;\
616 if (id<0 || id>=size)\
617 print \" (and nor has any other object)\";\
619 print \" to \", (string) crime, \" **]^\";\
622 { /* Z__Region: Determines whether a value is:
626 0 none of the above */
630 if (addr==0 or -1) rfalse;\
632 #IfV5; #iftrue (#version_number == 6) || (#version_number == 7);\
633 @log_shift addr $FFFF -> top; #Endif; #Endif;\
634 if (Unsigned__Compare(top, $001A-->0) >= 0) rfalse;\
635 if (addr>=1 && addr<=(#largest_object-255)) rtrue;\
636 #iftrue #oddeven_packing;\
637 @test addr 1 ?~NotString;\
638 if (Unsigned__Compare(addr, #strings_offset)<0) rfalse;\
641 if (Unsigned__Compare(addr, #code_offset)<0) rfalse;\
644 if (Unsigned__Compare(addr, #strings_offset)>=0) return 3;\
645 if (Unsigned__Compare(addr, #code_offset)>=0) return 2;\
648 ]", "", "", "", "", ""
650 { /* Unsigned__Compare: returns 1 if x>y, 0 if x=y, -1 if x<y */
655 if (x<0 && y>=0) return 1;\
656 if (x>=0 && y<0) return -1;\
657 u = x&$7fff; v= y&$7fff;\
660 ]", "", "", "", "", ""
662 { /* Meta__class: returns the metaclass of an object */
666 switch(Z__Region(obj))\
667 { 2: return Routine;\
669 1: if (obj in 1 || obj <= 4) return Class;\
673 ]", "", "", "", "", ""
675 { /* CP__Tab: searches a common property table for the given
676 identifier, thus imitating the get_prop_addr opcode.
677 Returns 0 if not provided, except:
678 if the identifier supplied is -1, then returns
679 the address of the first byte after the table. */
683 while ((n=0->x) ~= 0)\
684 { if (n & $80) { x++; l = (0->x) & $3f; }\
685 else { if (n & $40) l=2; else l=1; }\
687 if ((n & $3f) == id) return x;\
690 if (id<0) return x+1; rfalse; ]", "", "", "", "", ""
692 { /* Cl__Ms: the five message-receiving properties of Classes */
695 "obj id y a b c d x;\
698 if (children(obj)<=1) rfalse; x=child(obj);\
699 remove x; if (x provides create) { if (y==0) x..create();\
700 if (y==1) x..create(a); if (y==2) x..create(a,b);\
701 if (y>3) RT__Err(1,obj); if (y>=3) x..create(a,b,c);}\
704 if (~~(a ofclass obj))\
705 { RT__Err(\"recreate\", a, -obj); rfalse; }\
706 Copy__Primitive(a, child(obj));\
707 if (a provides create) { if (y==1) a..create();\
708 if (y==2) a..create(b); if (y==3) a..create(b,c);\
709 if (y>4) RT__Err(1,obj); if (y>=4) a..create(b,c,d);\
712 if (~~(a ofclass obj))\
713 { RT__Err(\"destroy\", a, -obj); rfalse; }\
714 if (a provides destroy) a..destroy();\
715 Copy__Primitive(a, child(obj));\
716 move a to obj; rfalse;\
718 return children(obj)-1;",
720 if (~~(a ofclass obj))\
721 { RT__Err(\"copy\", a, -obj); rfalse; }\
722 if (~~(b ofclass obj))\
723 { RT__Err(\"copy\", b, -obj); rfalse; }\
724 Copy__Primitive(a, b); rfalse;\
728 { /* RT__ChT: check at run-time that a proposed object move is legal
729 cause error and do nothing if not; otherwise move */
733 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
734 return RT__Err(16,obj1,obj2);\
735 if (obj2<5 || obj2>(#largest_object-255) || obj2 in 1)\
736 return RT__Err(17,obj1,obj2);",
737 "x=obj2; while (x~=0) { if (x==obj1) return RT__Err(18,obj1,obj2); \
740 if (obj1 has infix__watching\
741 || obj2 has infix__watching || (debug_flag & 15))\
742 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
743 #ifnot; #ifdef DEBUG;\
744 if (debug_flag & 15)\
745 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
747 @insert_obj obj1 obj2; ]", "", "", "", ""
749 { /* RT__ChR: check at run-time that a proposed object remove is legal
750 cause error and do nothing if not; otherwise remove */
754 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
755 return RT__Err(15,obj1);",
757 if (obj1 has infix__watching || (debug_flag & 15))\
758 print \"[Removing \", (name) obj1, \"]^\";\
759 #ifnot; #ifdef DEBUG;\
760 if (debug_flag & 15)\
761 print \"[Removing \", (name) obj1, \"]^\";\
763 @remove_obj obj1; ]", "", "", "", ""
765 { /* RT__ChG: check at run-time that a proposed attr give is legal
766 cause error and do nothing if not; otherwise give */
770 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
771 return RT__Err(14,obj1); if (a<0 || a>=48) return RT__Err(19,obj1);\
772 if (obj1 has a) return;",
774 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
775 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
776 #ifnot; #ifdef DEBUG;\
777 if (a ~= workflag && debug_flag & 15)\
778 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
780 @set_attr obj1 a; ]", "", "", "", ""
782 { /* RT__ChGt: check at run-time that a proposed attr give ~ is legal
783 cause error and do nothing if not; otherwise give */
787 if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
788 return RT__Err(14,obj1); if (a<0 || a>=48) return RT__Err(19,obj1);\
789 if (obj1 hasnt a) return;",
791 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
792 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
793 #ifnot; #ifdef DEBUG;\
794 if (a ~= workflag && debug_flag & 15)\
795 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
797 @clear_attr obj1 a; ]", "", "", "", ""
799 { /* RT__ChPS: check at run-time that a proposed property set is legal
800 cause error and do nothing if not; otherwise make it */
804 if (obj<5 || obj>(#largest_object-255) || obj in 1 || obj.&prop==0 || (size=obj.#prop)>2 )\
805 return RT__Err(\"set\", obj, prop, size);\
806 @put_prop obj prop val;",
808 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,prop,val);\
809 #ifnot; #ifdef DEBUG;\
810 if (debug_flag & 15) RT__TrPS(obj,prop,val);\
812 return val; ]", "", "", "", ""
814 { /* RT__ChPR: check at run-time that a proposed property read is legal
815 cause error and return 0 if not; otherwise read it */
819 if (obj<5 || obj>(#largest_object-255) || (size=obj.#prop)>2)\
820 {RT__Err(\"read\", obj, prop, size); obj=2;}\
821 @get_prop obj prop -> val;",
822 "return val; ]", "", "", "", ""
824 { /* RT__TrPS: trace property settings */
828 print \"[Setting \",(name) obj,\".\",(property) prop,\
829 \" to \",val,\"]^\"; ]",
832 { /* RT__ChLDB: check at run-time that it's safe to load a byte
833 and return the byte */
837 a=base+offset;if (Unsigned__Compare(a,#readable_memory_offset)>=0)\
838 return RT__Err(24);",
839 "@loadb base offset -> val;return val; ]", "", "", "", ""
841 { /* RT__ChLDW: check at run-time that it's safe to load a word
842 and return the word */
846 a=base+2*offset;if (Unsigned__Compare(a,#readable_memory_offset)>=0)\
847 return RT__Err(25);",
848 "@loadw base offset -> val;return val; ]", "", "", "", ""
850 { /* RT__ChSTB: check at run-time that it's safe to store a byte
854 "base offset val a f;\
856 if (Unsigned__Compare(a,#array__start)>=0\
857 && Unsigned__Compare(a,#array__end)<0) f=1; else\
858 if (Unsigned__Compare(a,#cpv__start)>=0\
859 && Unsigned__Compare(a,#cpv__end)<0) f=1; else\
860 if (Unsigned__Compare(a,#ipv__start)>=0\
861 && Unsigned__Compare(a,#ipv__end)<0) f=1; else\
863 if (f==0) return RT__Err(26);",
864 "@storeb base offset val; ]", "", "", "", ""
866 { /* RT__ChSTW: check at run-time that it's safe to store a word
870 "base offset val a f;\
872 if (Unsigned__Compare(a,#array__start)>=0\
873 && Unsigned__Compare(a,#array__end)<0) f=1; else\
874 if (Unsigned__Compare(a,#cpv__start)>=0\
875 && Unsigned__Compare(a,#cpv__end)<0) f=1; else\
876 if (Unsigned__Compare(a,#ipv__start)>=0\
877 && Unsigned__Compare(a,#ipv__end)<0) f=1; else\
879 if (f==0) return RT__Err(27);",
880 "@storew base offset val; ]", "", "", "", ""
882 { /* RT__ChPrintC: check at run-time that it's safe to print (char)
887 if (c==0 or 9 or 11 or 13) fl=1;\
888 if (c>=32 && c<=126) fl=1; if (c>=155 && c<=251) fl=1;\
889 if (fl==0) return RT__Err(33,c);",
890 "@print_char c; ]", "", "", "", ""
892 { /* RT__ChPrintA: check at run-time that it's safe to print (address)
897 if (Unsigned__Compare(a, #readable_memory_offset)>=0)\
898 return RT__Err(34);",
899 "@print_addr a; ]", "", "", "", ""
901 { /* RT__ChPrintS: check at run-time that it's safe to print (string)
906 if (Z__Region(a)~=3) return RT__Err(35);",
907 "@print_paddr a; ]", "", "", "", ""
909 { /* RT__ChPrintO: check at run-time that it's safe to print (object)
914 if (Z__Region(a)~=1) return RT__Err(36);",
915 "@print_obj a; ]", "", "", "", ""
919 static VeneerRoutine VRs_g[VENEER_ROUTINES] =
922 /* Box__Routine: Display the given array of text as a box quote.
923 This is a very simple implementation; the library should provide
930 for (ix=0 : ix<arr-->0 : ix++) {\
931 print (string) arr-->(ix+1);\
935 ]", "", "", "", "", ""
938 /* This batch of routines is expected to be defined (rather better) by
939 the Inform library: these minimal forms here are provided to prevent
940 tiny non-library-using programs from failing to compile when certain
941 legal syntaxes (such as <<Action a b>>;) are used. */
944 "a b c d; print \"Action <\", a, \" \", b, \" \", c;\
945 if (d) print \", \", d; print \">^\";\
946 ]", "", "", "", "", ""
949 "obj; print \"the \", obj; ]", "", "", "", "", ""
952 "obj; print \"a \", obj; ]", "", "", "", "", ""
955 "obj; print \"The \", obj; ]", "", "", "", "", ""
958 "obj; print \"A \", obj; ]", "", "", "", "", ""
961 "obj q; switch(metaclass(obj))\
962 { 0: print \"nothing\";\
963 Object: q = obj-->GOBJFIELD_NAME; @streamstr q;\
964 Class: print \"class \"; q = obj-->GOBJFIELD_NAME; @streamstr q;\
965 Routine: print \"(routine at \", obj, \")\";\
966 String: print \"(string at \", obj, \")\";\
967 } ]", "", "", "", "", ""
970 "obj; print obj; ]", "", "", "", "", ""
973 /* Print__PName: Print the name of a property.
976 "prop ptab cla maxcom minind maxind str;\
977 if (prop & $FFFF0000) {\
978 cla = #classes_table-->(prop & $FFFF);\
979 print (name) cla, \"::\";\
980 @ushiftr prop 16 prop;\
982 ptab = #identifiers_table;\
984 minind = INDIV_PROP_START;\
985 maxind = minind + ptab-->3;\
987 if (prop >= 0 && prop < maxcom) {\
988 str = (ptab-->0)-->prop;\
990 else if (prop >= minind && prop < maxind) {\
991 str = (ptab-->2)-->(prop-minind);\
996 print \"<number \", prop, \">\";\
997 ]", "", "", "", "", ""
1000 /* The remaining routines make up the run-time half of the object
1001 orientation system, and need never be present for Inform 5 programs. */
1004 /* WV__Pr: Write a value to the property for the given object.
1010 RT__Err(\"write\", obj, id);\
1015 ]", "", "", "", "", ""
1019 /* RV__Pr: Read a value to the property for the given object.
1025 if (id > 0 && id < INDIV_PROP_START) {\
1026 return #cpv__start-->id;\
1028 RT__Err(\"read\", obj, id);\
1032 ]", "", "", "", "", ""
1035 /* CA__Pr: Call, that is, print-or-run-or-read, a property:
1036 this exactly implements obj..prop(...). Note that
1037 classes (members of Class) have 5 built-in properties
1038 inherited from Class: create, recreate, destroy,
1039 remaining and copy. Implementing these here prevents
1040 the need for a full metaclass inheritance scheme.
1043 "_vararg_count obj id zr s s2 z addr len m val;\
1046 _vararg_count = _vararg_count - 2;\
1047 zr = Z__Region(obj);\
1050 s = sender; sender = self; self = obj;\
1051 #ifdef action; sw__var=action; #endif;\
1052 @call obj _vararg_count z;\
1053 self = sender; sender = s;\
1060 @streamstr obj; rtrue;\
1062 if (id == print_to_array) {\
1063 if (_vararg_count >= 2) {\
1068 RT__Err(37); rfalse;\
1071 s = glk($0043, m+4, len-4, 1, 0);",
1076 @copy $ffffffff sp;\
1090 #ifdef DEBUG;#ifdef InformLibrary;\
1091 if (debug_flag & 1 ~= 0) {\
1093 print \"[ ~\", (name) obj, \"~.\", (property) id, \"(\";\
1094 @stkcopy _vararg_count;\
1095 for (val=0 : val < _vararg_count : val++) {\
1096 if (val) print \", \";\
1103 if (obj in Class) {\
1106 return Cl__Ms(obj, id);\
1110 return Cl__Ms(obj, id, m, val);\
1111 create, destroy, recreate:\
1112 m = _vararg_count+2;\
1115 @call Cl__Ms m val;\
1121 if (id > 0 && id < INDIV_PROP_START) {\
1122 addr = #cpv__start + 4*id;\
1132 for (m=0 : 4*m<len : m++) {\
1134 if (val == -1) rfalse;\
1135 switch (Z__Region(val)) {\
1137 s = sender; sender = self; self = obj; s2 = sw__var;\
1139 if (id==life) sw__var=reason_code; else sw__var=action;\
1141 " @stkcopy _vararg_count;\
1142 @call val _vararg_count z;\
1143 self = sender; sender = s; sw__var = s2;\
1144 if (z ~= 0) return z;\
1155 RT__Err(\"send message\", obj, id);\
1160 /* IB__Pr: ++(individual property) */
1164 x = obj.&identifier;\
1165 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
1167 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)+1);\
1168 #ifnot; #ifdef DEBUG;\
1169 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
1172 ]", "", "", "", "", ""
1175 /* IA__Pr: (individual property)++ */
1179 x = obj.&identifier;\
1180 if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
1182 if (obj has infix__watching || (debug_flag & 15))\
1183 RT__TrPS(obj,identifier,(x-->0)+1);\
1184 #ifnot; #ifdef DEBUG;\
1185 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
1188 ]", "", "", "", "", ""
1191 /* DB__Pr: --(individual property) */
1195 x = obj.&identifier;\
1196 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
1198 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
1199 #ifnot; #ifdef DEBUG;\
1200 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
1203 ]", "", "", "", "", ""
1206 /* DA__Pr: (individual property)-- */
1210 x = obj.&identifier;\
1211 if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
1213 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
1214 #ifnot; #ifdef DEBUG;\
1215 if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
1218 ]", "", "", "", "", ""
1221 /* RA__Pr: Read the property address of a given property value.
1222 Returns zero if it isn't provided by the object. This
1223 understands all the same concerns as RL__Pr().
1226 "obj id cla prop ix;\
1227 if (id & $FFFF0000) {\
1228 cla = #classes_table-->(id & $FFFF);\
1229 if (~~(obj ofclass cla)) return 0;\
1233 prop = CP__Tab(obj, id);\
1234 if (prop==0) return 0;\
1235 if (obj in Class && cla == 0) {\
1236 if (id < INDIV_PROP_START || id >= INDIV_PROP_START+8)\
1240 @aloadbit prop 72 ix;\
1244 ]", "", "", "", "", ""
1248 /* RL__Pr: Read the property length of a given property value.
1249 Returns zero if it isn't provided by the object. This understands
1250 inherited values (of the form class::prop) as well as simple
1251 property ids and the special metaclass methods. It also knows
1252 that private properties can only be read if (self == obj).
1255 "obj id cla prop ix;\
1256 if (id & $FFFF0000) {\
1257 cla = #classes_table-->(id & $FFFF);\
1258 if (~~(obj ofclass cla)) return 0;\
1262 prop = CP__Tab(obj, id);\
1263 if (prop==0) return 0;\
1264 if (obj in Class && cla == 0) {\
1265 if (id < INDIV_PROP_START || id >= INDIV_PROP_START+8)\
1269 @aloadbit prop 72 ix;\
1273 return WORDSIZE * ix;\
1274 ]", "", "", "", "", ""
1277 /* RA__Sc: Implement the \"superclass\" (::) operator. This
1278 returns an compound property identifier, which is a
1283 if ((cla notin Class) && (cla ~= Class or String or Routine or Object)) {\
1284 RT__Err(\"be a '::' superclass\", cla, -1);\
1287 for (j=0 : #classes_table-->j ~= 0 : j++) {\
1288 if (cla == #classes_table-->j) {\
1289 return (id * $10000 + j);\
1292 RT__Err(\"make use of\", cla, id);\
1294 ]", "", "", "", "", ""
1298 /* OP__Pr: Test whether the given object provides the given property.
1299 This winds up calling RA__Pr().
1303 zr = Z__Region(obj);\
1305 if (id == print or print_to_array) rtrue;\
1309 if (id == call) rtrue;\
1312 if (zr ~= 1) rfalse;\
1313 if (id >= INDIV_PROP_START && id < INDIV_PROP_START+8) {\
1314 if (obj in Class) rtrue;\
1319 ]", "", "", "", "", ""
1322 /* OC__Cl: Test whether the given object is of the given class.
1323 (implements the OfClass operator.)
1326 "obj cla zr jx inlist inlistlen;\
1327 zr = Z__Region(obj);\
1329 if (cla == String) rtrue;\
1333 if (cla == Routine) rtrue;\
1336 if (zr ~= 1) rfalse;\
1337 if (cla == Class) {\
1339 || obj == Class or String or Routine or Object)\
1343 if (cla == Object) {\
1345 || obj == Class or String or Routine or Object)\
1349 if (cla == String or Routine) rfalse;\
1350 if (cla notin Class) {\
1351 RT__Err(\"apply 'ofclass' for\", cla, -1);\
1355 if (inlist == 0) rfalse;\
1356 inlistlen = (obj.#2) / WORDSIZE;\
1357 for (jx=0 : jx<inlistlen : jx++) {\
1358 if (inlist-->jx == cla) rtrue;\
1361 ]", "", "", "", "", ""
1365 /* Copy__Primitive: Routine to \"deep copy\" objects.
1368 "o1 o2 p1 p2 pcount i j propid proplen val pa1 pa2;\
1369 for (i=1 : i<=NUM_ATTR_BYTES : i++) {\
1372 p2 = o2-->GOBJFIELD_PROPTAB;\
1375 for (i=0 : i<pcount : i++) {\
1376 @aloads p2 0 propid;\
1377 @aloads p2 1 proplen;\
1378 p1 = CP__Tab(o1, propid);\
1381 if (proplen == val) {\
1386 for (j=0 : j<proplen : j++)\
1392 ]", "", "", "", "", ""
1394 { /* RT__Err: for run-time errors occurring in the above: e.g.,
1395 an attempt to write to a non-existent individual
1399 "crime obj id size p q;\
1400 print \"^[** Programming error: \";\
1401 if (crime<0) jump RErr;\
1402 if (crime==1) { print \"class \"; q = obj-->GOBJFIELD_NAME; @streamstr q;\
1403 \": 'create' can have 0 to 3 parameters only **]\";}\
1404 if (crime == 40) \"tried to change printing variable \",\
1405 obj, \"; must be 0 to \", #dynam_string_table-->0-1, \" **]\";\
1406 if (crime == 32) \"objectloop broken because the object \",\
1407 (name) obj, \" was moved while the loop passed through it **]\";\
1408 if (crime == 33) \"tried to print (char) \", obj,\
1409 \", which is not a valid Glk character code for output **]\";\
1410 if (crime == 34) \"tried to print (address) on something not the \",\
1411 \"address of a dict word **]\";\
1412 if (crime == 35) \"tried to print (string) on something not a \",\
1414 if (crime == 36) \"tried to print (object) on something not an \",\
1415 \"object or class **]\";\
1416 if (crime == 37) \"tried to call Glulx print_to_array with only \",\
1417 \"one argument **]\";",
1418 "if (crime < 32) { print \"tried to \";\
1419 if (crime >= 28) { if (crime==28 or 29) print \"read from \";\
1420 else print \"write to \";\
1421 if (crime==29 or 31) print \"-\"; print \"->\", obj,\
1422 \" in the\"; switch(size&7){0,1:q=0; 2:print \" string\";\
1423 q=1; 3:print \" table\";q=1; 4:print \" buffer\";q=WORDSIZE;} \
1424 if(size&16) print\" (->)\"; if(size&8) print\" (-->)\";\
1425 \" array ~\", (string) #array_names_offset-->(p+1),\
1426 \"~, which has entries \", q, \" up to \",id,\" **]\"; }\
1427 if (crime >= 24 && crime <=27) { if (crime<=25) print \"read\";\
1428 else print \"write\"; print \" outside memory using \";\
1429 switch(crime) { 24,26:\"-> **]\"; 25,27:\"--> **]\"; } }\
1430 if (crime < 4) print \"test \"; else\
1431 if (crime < 12 || crime > 20) print \"find the \"; else\
1432 if (crime < 14) print \"use \";\
1433 if (crime==20) \"divide by zero **]\"; print \"~\";\
1435 2: print \"in~ or ~notin\"; 3: print \"has~ or ~hasnt\";\
1436 4: print \"parent\"; 5: print \"eldest\"; 6: print \"child\";\
1437 7: print \"younger\"; 8: print \"sibling\"; 9: print \"children\";\
1438 10: print \"youngest\"; 11: print \"elder\";\
1439 12: print \"objectloop\"; 13: print \"}~ at end of ~objectloop\";\
1440 14: \"give~ an attribute to \", (name) obj, \" **]\";\
1441 15: \"remove~ \", (name) obj, \" **]\";",
1442 "16,17,18: print \"move~ \", (name) obj, \" to \", (name) id;\
1443 if (crime==18) { print \", which would make a loop: \",(name) obj;\
1444 p=id; if (p==obj) p=obj;\
1445 else do { print \" in \", (name) p; p=parent(p);} until (p==obj);\
1446 \" in \", (name) p, \" **]\"; }\
1447 \" **]\"; 19: \"give~ or test ~has~ or ~hasnt~ with a non-attribute"\
1448 " on the object \",(name) obj,\" **]\";\
1449 21: print \".&\"; 22: print \".#\"; 23: print \".\"; }\
1450 \"~ of \", (name) obj, \" **]\"; }",
1451 ".RErr; if (obj==0 || obj->0>=$70 && obj->0<=$7F) {\
1452 if (obj && obj in Class) print \"class \";\
1453 if (obj) print (object) obj;else print \"nothing\";print\" \";}\
1454 print \"(object number \", obj, \") \";\
1455 if (id<0) print \"is not of class \", (name) -id;",
1457 { print \" has no property \", (property) id;\
1458 p = #identifiers_table;\
1459 size = INDIV_PROP_START + p-->3;\
1460 if (id<0 || id>=size)\
1461 print \" (and nor has any other object)\";\
1463 print \" to \", (string) crime, \" **]^\";\
1467 /* Z__Region: Determines whether a value is:
1475 if (addr<36) rfalse;\
1476 @getmemsize endmem;\
1477 @jgeu addr endmem?outrange;\
1479 if (tb >= $E0) return 3;\
1480 if (tb >= $C0) return 2;\
1481 if (tb >= $70 && tb <= $7F && addr >= (0-->2)) return 1;\
1484 ]", "", "", "", "", ""
1486 { /* Unsigned__Compare: returns 1 if x>y, 0 if x=y, -1 if x<y */
1488 "Unsigned__Compare",
1497 ]", "", "", "", "", ""
1499 { /* Meta__class: returns the metaclass of an object */
1503 switch(Z__Region(obj))\
1504 { 2: return Routine;\
1506 1: if (obj in Class\
1507 || obj == Class or String or Routine or Object)\
1512 ]", "", "", "", "", ""
1516 /* CP__Tab: Search a property table for the given identifier.
1517 The definition here is a bit different from the Z-code veneer.
1518 This just searches the property table of obj for an entry with
1519 the given identifier. It return the address of the property
1520 entry, or 0 if nothing found. (Remember that the value returned
1521 is not the address of the property *data*; it's the structure
1522 which contains the address/length/flags.)
1525 "obj id otab max res;\
1526 if (Z__Region(obj)~=1) {RT__Err(23, obj); rfalse;}\
1527 otab = obj-->GOBJFIELD_PROPTAB;\
1528 if (otab == 0) return 0;\
1531 @binarysearch id 2 otab 10 max 0 0 res;\
1533 ]", "", "", "", "", ""
1537 /* Cl__Ms: Implements the five message-receiving properties of
1541 "_vararg_count obj id a b x y;\
1544 _vararg_count = _vararg_count - 2;\
1547 if (children(obj) <= 1) rfalse;\
1550 if (x provides create) {\
1553 y = _vararg_count + 2;\
1560 if (~~(a ofclass obj)) {\
1561 RT__Err(\"recreate\", a, -obj);\
1564 if (a provides destroy)\
1566 Copy__Primitive(a, child(obj));\
1567 if (a provides create) {\
1570 y = _vararg_count + 2;\
1577 if (~~(a ofclass obj)) {\
1578 RT__Err(\"destroy\", a, -obj);\
1581 if (a provides destroy)\
1583 Copy__Primitive(a, child(obj));\
1587 return children(obj)-1;\
1591 _vararg_count = _vararg_count - 2;\
1592 if (~~(a ofclass obj)) {\
1593 RT__Err(\"copy\", a, -obj);\
1596 if (~~(b ofclass obj)) {\
1597 RT__Err(\"copy\", b, -obj);\
1600 Copy__Primitive(a, b);\
1603 ]", "", "", "", "", ""
1606 /* RT__ChT: Check at run-time that a proposed object move is legal.
1607 Cause error and do nothing if not; otherwise move
1611 if (obj1==0 || Z__Region(obj1)~=1\
1612 || (obj1 == Class or String or Routine or Object) || obj1 in Class)\
1613 return RT__Err(16, obj1, obj2);\
1614 if (obj2==0 || Z__Region(obj2)~=1\
1615 || (obj2 == Class or String or Routine or Object) || obj2 in Class)\
1616 return RT__Err(17, obj1, obj2);\
1619 if (ix==obj1) return RT__Err(18, obj1, obj2);\
1623 if (obj1 has infix__watching\
1624 || obj2 has infix__watching || (debug_flag & 15))\
1625 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
1626 #ifnot; #ifdef DEBUG;\
1627 if (debug_flag & 15)\
1628 print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
1630 OB__Move(obj1, obj2);\
1631 ]", "", "", "", "", ""
1634 /* RT__ChR: Check at run-time that a proposed object remove is legal.
1635 Cause error and do nothing if not; otherwise remove
1639 if (obj1==0 || Z__Region(obj1)~=1\
1640 || (obj1 == Class or String or Routine or Object) || obj1 in Class)\
1641 return RT__Err(15, obj1);\
1643 if (obj1 has infix__watching || (debug_flag & 15))\
1644 print \"[Removing \", (name) obj1, \"]^\";\
1645 #ifnot; #ifdef DEBUG;\
1646 if (debug_flag & 15)\
1647 print \"[Removing \", (name) obj1, \"]^\";\
1650 ]", "", "", "", "", ""
1652 { /* RT__ChG: check at run-time that a proposed attr give is legal
1653 cause error and do nothing if not; otherwise give */
1657 if (Z__Region(obj1) ~= 1) return RT__Err(14,obj1);\
1658 if (obj1 in Class || obj1 == Class or String or Routine or Object)\
1659 return RT__Err(14,obj1);\
1660 if (a<0 || a>=NUM_ATTR_BYTES*8) return RT__Err(19,obj1);\
1661 if (obj1 has a) return;",
1663 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
1664 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
1665 #ifnot; #ifdef DEBUG;\
1666 if (a ~= workflag && debug_flag & 15)\
1667 print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
1669 give obj1 a; ]", "", "", "", ""
1671 { /* RT__ChGt: check at run-time that a proposed attr give ~ is legal
1672 cause error and do nothing if not; otherwise give */
1676 if (Z__Region(obj1) ~= 1) return RT__Err(14,obj1);\
1677 if (obj1 in Class || obj1 == Class or String or Routine or Object)\
1678 return RT__Err(14,obj1);\
1679 if (a<0 || a>=NUM_ATTR_BYTES*8) return RT__Err(19,obj1);\
1680 if (obj1 hasnt a) return;",
1682 if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
1683 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
1684 #ifnot; #ifdef DEBUG;\
1685 if (a ~= workflag && debug_flag & 15)\
1686 print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
1688 give obj1 ~a; ]", "", "", "", ""
1691 /* RT__ChPS: Check at run-time that a proposed property set is legal.
1692 Cause error and do nothing if not; otherwise make it.
1696 if (obj==0 || Z__Region(obj)~=1\
1697 || (obj == Class or String or Routine or Object) || obj in Class)\
1698 return RT__Err(\"set\", obj, prop);\
1699 res = WV__Pr(obj, prop, val);\
1701 if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,prop,val);\
1702 #ifnot; #ifdef DEBUG;\
1703 if (debug_flag & 15) RT__TrPS(obj,prop,val);\
1706 ]", "", "", "", "", ""
1708 { /* RT__ChPR: check at run-time that a proposed property read is legal.
1709 cause error and return 0 if not; otherwise read it */
1712 if (obj==0 or Class or String or Routine or Object || Z_Region(obj)~=1 )\
1713 {RT__Err(\"read\", obj, prop); obj=2;}\
1714 val = RV__Pr(obj, prop);",
1715 "return val; ]", "", "", "", ""
1717 { /* RT__TrPS: trace property settings */
1721 print \"[Setting \",(name) obj,\".\",(property) prop,\
1722 \" to \",val,\"]^\"; ]",
1726 /* RT__ChLDB: Check at run-time that it's safe to load a byte
1727 and return the byte.
1730 "base offset a b val;\
1733 if (Unsigned__Compare(a, b) >= 0)\
1734 return RT__Err(24);\
1735 @aloadb base offset val;\
1737 ]", "", "", "", "", ""
1741 /* RT__ChLDW: Check at run-time that it's safe to load a word
1745 "base offset a b val;\
1746 a=base+WORDSIZE*offset;\
1748 if (Unsigned__Compare(a, b) >= 0)\
1749 return RT__Err(25);\
1750 @aload base offset val;\
1752 ]", "", "", "", "", ""
1756 /* RT__ChSTB: Check at run-time that it's safe to store a byte
1760 "base offset val a b;\
1763 if (Unsigned__Compare(a, b) >= 0) jump ChSTB_Fail;\
1765 if (Unsigned__Compare(a, b) < 0) jump ChSTB_Fail;\
1766 @astoreb base offset val;\
1769 return RT__Err(26);\
1770 ]", "", "", "", "", ""
1774 /* RT__ChSTW: Check at run-time that it's safe to store a word
1778 "base offset val a b;\
1779 a=base+WORDSIZE*offset;\
1781 if (Unsigned__Compare(a, b) >= 0) jump ChSTW_Fail;\
1783 if (Unsigned__Compare(a, b) < 0) jump ChSTW_Fail;\
1784 @astore base offset val;\
1787 return RT__Err(27);\
1788 ]", "", "", "", "", ""
1792 /* RT__ChPrintC: Check at run-time that it's safe to print (char)
1797 if (c<10 || (c>10 && c<32) || (c>126 && c<160))\
1798 return RT__Err(33,c);\
1803 ]", "", "", "", "", ""
1806 /* RT__ChPrintA: Check at run-time that it's safe to print (address)
1812 return RT__Err(34);\
1813 @getmemsize endmem;\
1814 if (Unsigned__Compare(addr, endmem) >= 0)\
1815 return RT__Err(34);\
1816 if (addr->0 ~= $60)\
1817 return RT__Err(34);\
1819 ]", "", "", "", "", ""
1822 /* Check at run-time that it's safe to print (string) and do so.
1826 if (Z__Region(str) ~= 3)\
1827 return RT__Err(35);\
1829 ]", "", "", "", "", ""
1832 /* Check at run-time that it's safe to print (object) and do so.
1836 if (Z__Region(obj) ~= 1)\
1837 return RT__Err(36);\
1838 @aload obj GOBJFIELD_NAME sp; @streamstr sp;\
1839 ]", "", "", "", "", ""
1842 /* OB__Move: Move an object within the object tree. This does no
1843 more error checking than the Z-code \"move\" opcode.
1846 "obj dest par chi sib;\
1847 par = obj-->GOBJFIELD_PARENT;\
1849 chi = par-->GOBJFIELD_CHILD;\
1851 par-->GOBJFIELD_CHILD = obj-->GOBJFIELD_SIBLING;\
1855 sib = chi-->GOBJFIELD_SIBLING;\
1860 chi-->GOBJFIELD_SIBLING = obj-->GOBJFIELD_SIBLING;\
1863 obj-->GOBJFIELD_SIBLING = dest-->GOBJFIELD_CHILD;\
1864 obj-->GOBJFIELD_PARENT = dest;\
1865 dest-->GOBJFIELD_CHILD = obj;\
1867 ]", "", "", "", "", ""
1871 /* OB__Remove: Remove an object from the tree. This does no
1872 more error checking than the Z-code \"remove\" opcode.
1876 par = obj-->GOBJFIELD_PARENT;\
1879 chi = par-->GOBJFIELD_CHILD;\
1881 par-->GOBJFIELD_CHILD = obj-->GOBJFIELD_SIBLING;\
1885 sib = chi-->GOBJFIELD_SIBLING;\
1890 chi-->GOBJFIELD_SIBLING = obj-->GOBJFIELD_SIBLING;\
1892 obj-->GOBJFIELD_SIBLING = 0;\
1893 obj-->GOBJFIELD_PARENT = 0;\
1895 ]", "", "", "", "", ""
1899 /* Print__Addr: Handle the print (address) statement. In Glulx,
1900 this behaves differently than on the Z-machine; it can *only*
1901 print dictionary words.
1905 if (addr->0 ~= $60) {\
1906 print \"(\", addr, \": not dict word)\";\
1909 for (ix=1 : ix <= DICT_WORD_SIZE : ix++) {\
1910 #ifndef DICT_IS_UNICODE;\
1915 if (ch == 0) return;\
1918 ]", "", "", "", "", ""
1922 /* Glk__Wrap: This is a wrapper for the @glk opcode. It just passes
1923 all its arguments into the Glk dispatcher, and returns the Glk
1927 "_vararg_count callid retval;\
1929 _vararg_count = _vararg_count - 1;\
1930 @glk callid _vararg_count retval;\
1932 ]", "", "", "", "", ""
1936 /* Dynam__String: Set dynamic string (printing variable) num to the
1937 given val, which can be any string or function.
1941 if (num < 0 || num >= #dynam_string_table-->0)\
1942 return RT__Err(40, num);\
1943 (#dynam_string_table)-->(num+1) = val;\
1944 ]", "", "", "", "", ""
1950 static void mark_as_needed_z(int code)
1953 if (veneer_routine_needs_compilation[code] == VR_UNUSED)
1954 { veneer_routine_needs_compilation[code] = VR_CALLED;
1955 /* Here each routine must mark every veneer routine it explicitly
1959 mark_as_needed_z(RT__TrPS_VR);
1960 mark_as_needed_z(RT__Err_VR);
1963 mark_as_needed_z(RT__Err_VR);
1966 mark_as_needed_z(Z__Region_VR);
1967 mark_as_needed_z(Cl__Ms_VR);
1968 mark_as_needed_z(RT__Err_VR);
1974 mark_as_needed_z(RT__Err_VR);
1975 mark_as_needed_z(RT__TrPS_VR);
1978 mark_as_needed_z(CP__Tab_VR);
1981 mark_as_needed_z(RT__Err_VR);
1984 mark_as_needed_z(Z__Region_VR);
1987 mark_as_needed_z(Z__Region_VR);
1988 mark_as_needed_z(RT__Err_VR);
1991 mark_as_needed_z(Unsigned__Compare_VR);
1994 mark_as_needed_z(Z__Region_VR);
1997 mark_as_needed_z(RT__Err_VR);
1998 mark_as_needed_z(Copy__Primitive_VR);
2005 mark_as_needed_z(RT__Err_VR);
2008 mark_as_needed_z(RT__Err_VR);
2009 mark_as_needed_z(RT__TrPS_VR);
2015 mark_as_needed_z(Unsigned__Compare_VR);
2016 mark_as_needed_z(RT__Err_VR);
2018 case RT__ChPrintC_VR:
2019 mark_as_needed_z(RT__Err_VR);
2021 case RT__ChPrintA_VR:
2022 mark_as_needed_z(Unsigned__Compare_VR);
2023 mark_as_needed_z(RT__Err_VR);
2025 case RT__ChPrintS_VR:
2026 case RT__ChPrintO_VR:
2027 mark_as_needed_z(RT__Err_VR);
2028 mark_as_needed_z(Z__Region_VR);
2034 static void mark_as_needed_g(int code)
2037 if (veneer_routine_needs_compilation[code] == VR_UNUSED)
2038 { veneer_routine_needs_compilation[code] = VR_CALLED;
2039 /* Here each routine must mark every veneer routine it explicitly
2043 case PrintShortName_VR:
2044 mark_as_needed_g(Metaclass_VR);
2046 case Print__Pname_VR:
2047 mark_as_needed_g(PrintShortName_VR);
2050 mark_as_needed_g(RA__Pr_VR);
2051 mark_as_needed_g(RT__TrPS_VR);
2052 mark_as_needed_g(RT__Err_VR);
2055 mark_as_needed_g(RA__Pr_VR);
2056 mark_as_needed_g(RT__Err_VR);
2059 mark_as_needed_g(RA__Pr_VR);
2060 mark_as_needed_g(RL__Pr_VR);
2061 mark_as_needed_g(PrintShortName_VR);
2062 mark_as_needed_g(Print__Pname_VR);
2063 mark_as_needed_g(Z__Region_VR);
2064 mark_as_needed_g(Cl__Ms_VR);
2065 mark_as_needed_g(Glk__Wrap_VR);
2066 mark_as_needed_g(RT__Err_VR);
2072 mark_as_needed_g(RT__Err_VR);
2073 mark_as_needed_g(RT__TrPS_VR);
2076 mark_as_needed_g(OC__Cl_VR);
2077 mark_as_needed_g(CP__Tab_VR);
2080 mark_as_needed_g(OC__Cl_VR);
2081 mark_as_needed_g(CP__Tab_VR);
2084 mark_as_needed_g(OC__Cl_VR);
2085 mark_as_needed_g(RT__Err_VR);
2088 mark_as_needed_g(RA__Pr_VR);
2089 mark_as_needed_g(Z__Region_VR);
2092 mark_as_needed_g(RA__Pr_VR);
2093 mark_as_needed_g(RL__Pr_VR);
2094 mark_as_needed_g(Z__Region_VR);
2095 mark_as_needed_g(RT__Err_VR);
2097 case Copy__Primitive_VR:
2098 mark_as_needed_g(CP__Tab_VR);
2101 mark_as_needed_g(Unsigned__Compare_VR);
2105 mark_as_needed_g(Z__Region_VR);
2108 mark_as_needed_g(OC__Cl_VR);
2109 mark_as_needed_g(OP__Pr_VR);
2110 mark_as_needed_g(RT__Err_VR);
2111 mark_as_needed_g(Copy__Primitive_VR);
2112 mark_as_needed_g(OB__Remove_VR);
2113 mark_as_needed_g(OB__Move_VR);
2117 mark_as_needed_g(RT__Err_VR);
2120 mark_as_needed_g(RT__Err_VR);
2121 mark_as_needed_g(Z__Region_VR);
2122 mark_as_needed_g(OB__Remove_VR);
2125 mark_as_needed_g(RT__Err_VR);
2126 mark_as_needed_g(Z__Region_VR);
2127 mark_as_needed_g(OB__Move_VR);
2130 mark_as_needed_g(RT__Err_VR);
2131 mark_as_needed_g(RT__TrPS_VR);
2132 mark_as_needed_g(WV__Pr_VR);
2135 mark_as_needed_g(RT__Err_VR);
2136 mark_as_needed_g(RV__Pr_VR); return;
2141 mark_as_needed_g(Unsigned__Compare_VR);
2142 mark_as_needed_g(RT__Err_VR);
2144 case RT__ChPrintC_VR:
2145 mark_as_needed_g(RT__Err_VR);
2147 case RT__ChPrintA_VR:
2148 mark_as_needed_g(Unsigned__Compare_VR);
2149 mark_as_needed_g(RT__Err_VR);
2150 mark_as_needed_g(Print__Addr_VR);
2152 case RT__ChPrintS_VR:
2153 case RT__ChPrintO_VR:
2154 mark_as_needed_g(RT__Err_VR);
2155 mark_as_needed_g(Z__Region_VR);
2157 case Print__Addr_VR:
2158 mark_as_needed_g(RT__Err_VR);
2160 case Dynam__String_VR:
2161 mark_as_needed_g(RT__Err_VR);
2167 extern assembly_operand veneer_routine(int code)
2168 { assembly_operand AO;
2170 INITAOTV(&AO, LONG_CONSTANT_OT, code);
2171 AO.marker = VROUTINE_MV;
2172 mark_as_needed_z(code);
2175 INITAOTV(&AO, CONSTANT_OT, code);
2176 AO.marker = VROUTINE_MV;
2177 mark_as_needed_g(code);
2182 static void compile_symbol_table_routine(void)
2183 { int32 j, nl, arrays_l, routines_l, constants_l;
2184 assembly_operand AO, AO2, AO3;
2186 /* Assign local var names for the benefit of the debugging information
2188 local_variable_texts[0] = "dummy1";
2189 local_variable_texts[1] = "dummy2";
2191 veneer_mode = TRUE; j = symbol_index("Symb__Tab", -1);
2193 assemble_routine_header(2, FALSE, "Symb__Tab", FALSE, j),
2195 sflags[j] |= SYSTEM_SFLAG + USED_SFLAG;
2196 if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
2200 if (define_INFIX_switch == FALSE)
2201 { assemblez_0(rfalse_zc);
2202 variable_usage[1] = TRUE;
2203 variable_usage[2] = TRUE;
2204 assemble_routine_end(FALSE, null_debug_locations);
2205 veneer_mode = FALSE;
2209 INITAOTV(&AO, VARIABLE_OT, 1);
2210 INITAOT(&AO2, SHORT_CONSTANT_OT);
2211 INITAOT(&AO3, LONG_CONSTANT_OT);
2213 arrays_l = next_label++;
2214 routines_l = next_label++;
2215 constants_l = next_label++;
2217 sequence_point_follows = FALSE;
2219 assemblez_2_branch(je_zc, AO, AO2, arrays_l, TRUE);
2220 sequence_point_follows = FALSE;
2222 assemblez_2_branch(je_zc, AO, AO2, routines_l, TRUE);
2223 sequence_point_follows = FALSE;
2225 assemblez_2_branch(je_zc, AO, AO2, constants_l, TRUE);
2226 sequence_point_follows = FALSE;
2227 assemblez_0(rtrue_zc);
2229 assemble_label_no(arrays_l);
2231 for (j=0; j<no_arrays; j++)
2233 if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
2234 else AO2.type = LONG_CONSTANT_OT;
2236 sequence_point_follows = FALSE;
2237 assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
2238 AO3.value = array_sizes[j];
2240 assemblez_store(temp_var2, AO3);
2241 AO3.value = array_types[j];
2242 if (sflags[array_symbols[j]] & (INSF_SFLAG+SYSTEM_SFLAG))
2243 AO3.value = AO3.value + 16;
2245 assemblez_store(temp_var3, AO3);
2246 AO3.value = svals[array_symbols[j]];
2247 AO3.marker = ARRAY_MV;
2248 assemblez_1(ret_zc, AO3);
2249 assemble_label_no(nl);
2252 sequence_point_follows = FALSE;
2253 assemblez_0(rtrue_zc);
2254 assemble_label_no(routines_l);
2255 for (j=0; j<no_named_routines; j++)
2257 if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
2258 else AO2.type = LONG_CONSTANT_OT;
2260 sequence_point_follows = FALSE;
2261 assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
2263 if (sflags[named_routine_symbols[j]]
2264 & (INSF_SFLAG+SYSTEM_SFLAG)) AO3.value = 16;
2266 assemblez_store(temp_var3, AO3);
2267 AO3.value = svals[named_routine_symbols[j]];
2268 AO3.marker = IROUTINE_MV;
2269 assemblez_1(ret_zc, AO3);
2270 assemble_label_no(nl);
2272 sequence_point_follows = FALSE;
2273 assemblez_0(rtrue_zc);
2275 assemble_label_no(constants_l);
2276 for (j=0, no_named_constants=0; j<no_symbols; j++)
2277 { if (((stypes[j] == OBJECT_T) || (stypes[j] == CLASS_T)
2278 || (stypes[j] == CONSTANT_T))
2279 && ((sflags[j] & (UNKNOWN_SFLAG+ACTION_SFLAG))==0))
2280 { AO2.value = no_named_constants++;
2281 if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
2282 else AO2.type = LONG_CONSTANT_OT;
2284 sequence_point_follows = FALSE;
2285 assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
2287 if (stypes[j] == OBJECT_T) AO3.value = 2;
2288 if (stypes[j] == CLASS_T) AO3.value = 1;
2289 if (sflags[j] & (INSF_SFLAG+SYSTEM_SFLAG))
2290 AO3.value = AO3.value + 16;
2292 assemblez_store(temp_var3, AO3);
2294 AO3.marker = SYMBOL_MV;
2295 assemblez_1(ret_zc, AO3);
2296 assemble_label_no(nl);
2299 no_named_constants = 0; AO3.marker = 0;
2301 sequence_point_follows = FALSE;
2302 assemblez_0(rfalse_zc);
2303 variable_usage[1] = TRUE;
2304 variable_usage[2] = TRUE;
2305 assemble_routine_end(FALSE, null_debug_locations);
2306 veneer_mode = FALSE;
2310 if (define_INFIX_switch == FALSE)
2311 { assembleg_1(return_gc, zero_operand);
2312 variable_usage[1] = TRUE;
2313 variable_usage[2] = TRUE;
2314 assemble_routine_end(FALSE, null_debug_locations);
2315 veneer_mode = FALSE;
2319 error("*** Infix symbol-table routine is not yet implemented. ***");
2323 extern void compile_veneer(void)
2324 { int i, j, try_veneer_again;
2327 if (module_switch) return;
2329 VRs = (!glulx_mode) ? VRs_z : VRs_g;
2331 /* Called at the end of the pass to insert as much of the veneer as is
2332 needed and not elsewhere compiled. */
2334 veneer_symbols_base = no_symbols;
2336 /* for (i=0; i<VENEER_ROUTINES; i++)
2337 printf("%s %d %d %d %d %d %d\n", VRs[i].name,
2338 strlen(VRs[i].source1), strlen(VRs[i].source2),
2339 strlen(VRs[i].source3), strlen(VRs[i].source4),
2340 strlen(VRs[i].source5), strlen(VRs[i].source6)); */
2342 try_veneer_again = TRUE;
2343 while (try_veneer_again)
2344 { try_veneer_again = FALSE;
2345 for (i=0; i<VENEER_ROUTINES; i++)
2346 { if (veneer_routine_needs_compilation[i] == VR_CALLED)
2347 { j = symbol_index(VRs[i].name, -1);
2348 if (sflags[j] & UNKNOWN_SFLAG)
2349 { veneer_mode = TRUE;
2350 strcpy(veneer_source_area, VRs[i].source1);
2351 strcat(veneer_source_area, VRs[i].source2);
2352 strcat(veneer_source_area, VRs[i].source3);
2353 strcat(veneer_source_area, VRs[i].source4);
2354 strcat(veneer_source_area, VRs[i].source5);
2355 strcat(veneer_source_area, VRs[i].source6);
2357 parse_routine(veneer_source_area, FALSE,
2358 VRs[i].name, TRUE, j),
2360 veneer_mode = FALSE;
2361 if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
2364 { if (stypes[j] != ROUTINE_T)
2365 error_named("The following name is reserved by Inform for its \
2366 own use as a routine name; you can use it as a routine name yourself (to \
2367 override the standard definition) but cannot use it for anything else:",
2370 sflags[j] |= USED_SFLAG;
2372 veneer_routine_address[i] = svals[j];
2373 veneer_routine_needs_compilation[i] = VR_COMPILED;
2374 try_veneer_again = TRUE;
2379 compile_symbol_table_routine();
2382 /* ========================================================================= */
2383 /* Data structure management routines */
2384 /* ------------------------------------------------------------------------- */
2386 extern void init_veneer_vars(void)
2390 extern void veneer_begin_pass(void)
2392 veneer_mode = FALSE;
2393 for (i=0; i<VENEER_ROUTINES; i++)
2394 { veneer_routine_needs_compilation[i] = VR_UNUSED;
2395 veneer_routine_address[i] = 0;
2399 extern void veneer_allocate_arrays(void)
2400 { veneer_source_area = my_malloc(16384, "veneer source code area");
2403 extern void veneer_free_arrays(void)
2404 { my_free(&veneer_source_area, "veneer source code area");
2407 /* ========================================================================= */