-
Notifications
You must be signed in to change notification settings - Fork 35
/
veneer.c
2397 lines (2273 loc) · 84.7 KB
/
veneer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ------------------------------------------------------------------------- */
/* "veneer" : Compiling the run-time "veneer" of any routines invoked */
/* by the compiler (e.g. DefArt) which the program doesn't */
/* provide */
/* */
/* Part of Inform 6.34 */
/* copyright (c) Graham Nelson 1993 - 2020 */
/* */
/* ------------------------------------------------------------------------- */
#include "header.h"
int veneer_mode; /* Is the code currently being
compiled from the veneer? */
static debug_locations null_debug_locations =
{ { 0, 0, 0, 0, 0, 0, 0 }, NULL, 0 };
extern void compile_initial_routine(void)
{
/* The first routine present in memory in any Inform game, beginning
at the code area start position, always has 0 local variables
(since the interpreter begins execution with an empty stack frame):
and it must "quit" rather than "return".
In order not to impose these restrictions on "Main", we compile a
trivial routine consisting of a call to "Main" followed by "quit". */
int32 j;
assembly_operand AO;
j = symbol_index("Main__", -1);
assign_symbol(j,
assemble_routine_header(0, FALSE, "Main__", FALSE, j),
ROUTINE_T);
sflags[j] |= SYSTEM_SFLAG + USED_SFLAG;
if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
if (!glulx_mode) {
INITAOTV(&AO, LONG_CONSTANT_OT, 0);
AO.marker = MAIN_MV;
sequence_point_follows = FALSE;
if (version_number > 3)
assemblez_1_to(call_vs_zc, AO, temp_var1);
else
assemblez_1_to(call_zc, AO, temp_var1);
assemblez_0(quit_zc);
}
else {
INITAOTV(&AO, CONSTANT_OT, 0);
AO.marker = MAIN_MV;
sequence_point_follows = FALSE;
assembleg_3(call_gc, AO, zero_operand, zero_operand);
assembleg_1(return_gc, zero_operand);
}
assemble_routine_end(FALSE, null_debug_locations);
}
/* ------------------------------------------------------------------------- */
/* The rest of the veneer is applied at the end of the pass, as required. */
/* ------------------------------------------------------------------------- */
static int veneer_routine_needs_compilation[VENEER_ROUTINES];
int32 veneer_routine_address[VENEER_ROUTINES];
static int veneer_symbols_base;
#define VR_UNUSED 0
#define VR_CALLED 1
#define VR_COMPILED 2
typedef struct VeneerRoutine_s
{ char *name;
char *source1;
char *source2;
char *source3;
char *source4;
char *source5;
char *source6;
} VeneerRoutine;
static char *veneer_source_area;
static VeneerRoutine VRs_z[VENEER_ROUTINES] =
{
/* Box__Routine: the only veneer routine used in the implementation of
an actual statement ("box", of course), written in a
hybrid of Inform and assembly language. Note the
transcription of the box text to the transcript
output stream (-1, or $ffff). */
{ "Box__Routine",
"maxw table n w w2 line lc t;\
n = table --> 0;\
@add n 6 -> sp;\
@split_window sp;\
@set_window 1;\
w = 0 -> 33;\
if (w == 0) w=80;\
w2 = (w - maxw)/2;\
style reverse;\
@sub w2 2 -> w;\
line = 5;\
lc = 1;\
@set_cursor 4 w;\
spaces maxw + 4;",
"do\
{ @set_cursor line w;\
spaces maxw + 4;\
@set_cursor line w2;\
t = table --> lc;\
if (t~=0) print (string) t;\
line++; lc++;\
} until (lc > n);\
@set_cursor line w;\
spaces maxw + 4;\
@buffer_mode 1;\
style roman;\
@set_window 0;\
@split_window 1;\
@output_stream $ffff;\
print \"[ \";\
lc = 1;",
"do\
{ w = table --> lc;\
if (w ~= 0) print (string) w;\
lc++;\
if (lc > n)\
{ print \"]^^\";\
break;\
}\
print \"^ \";\
} until (false);\
@output_stream 1;\
]", "", "", ""
},
/* This batch of routines is expected to be defined (rather better) by
the Inform library: these minimal forms here are provided to prevent
tiny non-library-using programs from failing to compile when certain
legal syntaxes (such as <<Action a b>>;) are used. */
{ "R_Process",
"a b c d; print \"Action <\", a, \" \", b, \" \", c;\
if (d) print \", \", d; print \">^\";\
]", "", "", "", "", ""
},
{ "DefArt",
"obj; print \"the \", obj; ]", "", "", "", "", ""
},
{ "InDefArt",
"obj; print \"a \", obj; ]", "", "", "", "", ""
},
{ "CDefArt",
"obj; print \"The \", obj; ]", "", "", "", "", ""
},
{ "CInDefArt",
"obj; print \"A \", obj; ]", "", "", "", "", ""
},
{ "PrintShortName",
"obj; switch(metaclass(obj))\
{ 0: print \"nothing\";\
Object: @print_obj obj;\
Class: print \"class \"; @print_obj obj;\
Routine: print \"(routine at \", obj, \")\";\
String: print \"(string at \", obj, \")\";\
} ]", "", "", "", "", ""
},
{ "EnglishNumber",
"obj; print obj; ]", "", "", "", "", ""
},
{ "Print__PName",
"prop p size cla i;\
if (prop & $c000)\
{ cla = #classes_table-->(prop & $ff);\
print (name) cla, \"::\";\
if ((prop & $8000) == 0) prop = (prop & $3f00)/$100;\
else\
{ prop = (prop & $7f00)/$100;\
i = cla.3;\
while ((i-->0 ~= 0) && (prop>0))\
{ i = i + i->2 + 3;\
prop--;\
}\
prop = (i-->0) & $7fff;\
}\
}",
"p = #identifiers_table;\
size = p-->0;\
if (prop<=0 || prop>=size || p-->prop==0)\
print \"<number \", prop, \">\";\
else print (string) p-->prop;\
]", "", "", "", ""
},
/* The remaining routines make up the run-time half of the object
orientation system, and need never be present for Inform 5 programs. */
{
/* WV__Pr: write a value to the property for the given
object having the given identifier */
"WV__Pr",
"obj identifier value x;\
x = obj..&identifier;\
if (x==0) { RT__Err(\"write to\", obj, identifier); return; }\
#ifdef INFIX;\
if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,value);\
#ifnot; #ifdef DEBUG;\
if (debug_flag & 15) RT__TrPS(obj,identifier,value);\
#endif; #endif;\
x-->0 = value;\
]", "", "", "", "", ""
},
{
/* RV__Pr: read a value from the property for the given
object having the given identifier */
"RV__Pr",
"obj identifier x;\
x = obj..&identifier;\
if (x==0)\
{ if (identifier >= 1 && identifier < 64 && obj.#identifier <= 2)\
return obj.identifier;\
RT__Err(\"read\", obj, identifier); return; }\
#IFV3;\
if (obj..#identifier > 2) RT__Err(\"read\", obj, identifier);\
#IFNOT;\
if (obj..#identifier > 2) RT__Err(\"read\", obj, identifier, 2);\
#ENDIF;\
return x-->0;\
]", "", "", "", "", ""
},
{ /* CA__Pr: call, that is, print-or-run-or-read, a property:
this exactly implements obj..prop(...). Note that
classes (members of Class) have 5 built-in properties
inherited from Class: create, recreate, destroy,
remaining and copy. Implementing these here prevents
the need for a full metaclass inheritance scheme. */
"CA__Pr",
"obj id a b c d e f x y z s s2 n m;\
if (obj < 1 || obj > #largest_object-255)\
{ switch(Z__Region(obj))\
{ 2: if (id == call)\
{ s = sender; sender = self; self = obj;\
#ifdef action;sw__var=action;#endif;\
x = indirect(obj, a, b, c, d, e, f);\
self = sender; sender = s; return x; }\
jump Call__Error;",
"3: if (id == print) { @print_paddr obj; rtrue; }\
if (id == print_to_array)\
{ @output_stream 3 a; @print_paddr obj; @output_stream -3;\
return a-->0; }\
jump Call__Error;\
}\
jump Call__Error;\
}\
@check_arg_count 3 ?~A__x;y++;@check_arg_count 4 ?~A__x;y++;\
@check_arg_count 5 ?~A__x;y++;@check_arg_count 6 ?~A__x;y++;\
@check_arg_count 7 ?~A__x;y++;@check_arg_count 8 ?~A__x;y++;.A__x;",
"#ifdef INFIX;if (obj has infix__watching) n=1;#endif;\
#ifdef DEBUG;if (debug_flag & 1 ~= 0) n=1;#endif;\
if (n==1) {\
#ifdef DEBUG;n=debug_flag & 1; debug_flag=debug_flag-n;#endif;\
print \"[ ~\", (name) obj, \"~.\", (property) id, \"(\";\
switch(y) { 1: print a; 2: print a,\",\",b; 3: print a,\",\",b,\",\",c;\
4: print a,\",\",b,\",\",c,\",\",d;\
5: print a,\",\",b,\",\",c,\",\",d,\",\",e;\
6: print a,\",\",b,\",\",c,\",\",d,\",\",e,\",\",f; }\
print \") ]^\";\
#ifdef DEBUG;debug_flag = debug_flag + n;#endif;\
}",
"if (id > 0 && id < 64)\
{ x = obj.&id; if (x==0) { x=$000a-->0 + 2*(id-1); n=2; }\
else n = obj.#id; }\
else\
{ if (id>=64 && id<69 && obj in Class)\
return Cl__Ms(obj,id,y,a,b,c,d);\
x = obj..&id;\
if (x == 0) { .Call__Error;\
RT__Err(\"send message\", obj, id); return; }\
n = 0->(x-1);\
if (id&$C000==$4000)\
switch (n&$C0) { 0: n=1; $40: n=2; $80: n=n&$3F; }\
}",
"for (:2*m<n:m++)\
{ if (x-->m==$ffff) rfalse;\
switch(Z__Region(x-->m))\
{ 2: s = sender; sender = self; self = obj; s2 = sw__var;\
#ifdef LibSerial;\
if (id==life) sw__var=reason_code; else sw__var=action;\
#endif;\
switch(y) { 0: z = indirect(x-->m); 1: z = indirect(x-->m, a);\
2: z = indirect(x-->m, a, b); 3: z = indirect(x-->m, a, b, c);",
"4: z = indirect(x-->m, a, b, c, d); 5:z = indirect(x-->m, a, b, c, d, e);\
6: z = indirect(x-->m, a, b, c, d, e, f); }\
self = sender; sender = s; sw__var = s2;\
if (z ~= 0) return z;\
3: print_ret (string) x-->m;\
default: return x-->m;\
}\
}\
rfalse;\
]"
},
{
/* IB__Pr: ++(individual property) */
"IB__Pr",
"obj identifier x;\
x = obj..&identifier;\
if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
#ifdef INFIX;\
if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)+1);\
#ifnot; #ifdef DEBUG;\
if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
#endif; #endif;\
return ++(x-->0);\
]", "", "", "", "", ""
},
{
/* IA__Pr: (individual property)++ */
"IA__Pr",
"obj identifier x;\
x = obj..&identifier;\
if (x==0) { RT__Err(\"increment\", obj, identifier); return; }\
#ifdef INFIX;\
if (obj has infix__watching || (debug_flag & 15))\
RT__TrPS(obj,identifier,(x-->0)+1);\
#ifnot; #ifdef DEBUG;\
if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)+1);\
#endif; #endif;\
return (x-->0)++;\
]", "", "", "", "", ""
},
{
/* DB__Pr: --(individual property) */
"DB__Pr",
"obj identifier x;\
x = obj..&identifier;\
if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
#ifdef INFIX;\
if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
#ifnot; #ifdef DEBUG;\
if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
#endif; #endif;\
return --(x-->0);\
]", "", "", "", "", ""
},
{
/* DA__Pr: (individual property)-- */
"DA__Pr",
"obj identifier x;\
x = obj..&identifier;\
if (x==0) { RT__Err(\"decrement\", obj, identifier); return; }\
#ifdef INFIX;\
if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,identifier,(x-->0)-1);\
#ifnot; #ifdef DEBUG;\
if (debug_flag & 15) RT__TrPS(obj,identifier,(x-->0)-1);\
#endif; #endif;\
return (x-->0)--;\
]", "", "", "", "", ""
},
{
/* RA__Pr: read the address of a property value for a given object,
returning 0 if it doesn't provide this individual
property */
"RA__Pr",
"obj identifier i otherid cla;\
if (obj==0) rfalse;\
if (identifier<64 && identifier>0) return obj.&identifier;\
if (identifier & $8000 ~= 0)\
{ cla = #classes_table-->(identifier & $ff);\
if (cla.&3 == 0) rfalse;\
if (~~(obj ofclass cla)) rfalse;\
identifier = (identifier & $7f00) / $100;\
i = cla.3;\
while (identifier>0)\
{ identifier--;\
i = i + i->2 + 3;\
}\
return i+3;\
}",
"if (identifier & $4000 ~= 0)\
{ cla = #classes_table-->(identifier & $ff);\
identifier = (identifier & $3f00) / $100;\
if (~~(obj ofclass cla)) rfalse; i=0-->5;\
if (cla == 2) return i+2*identifier-2;\
i = 0-->((i+124+cla*14)/2);\
i = CP__Tab(i + 2*(0->i) + 1, -1)+6;\
return CP__Tab(i, identifier);\
}\
if (obj.&3 == 0) rfalse;\
if (obj in 1)\
{ if (identifier<64 || identifier>=72) rfalse;\
}",
"if (self == obj)\
otherid = identifier | $8000;\
i = obj.3;\
while (i-->0 ~= 0)\
{ if (i-->0 == identifier or otherid)\
return i+3;\
i = i + i->2 + 3;\
}\
rfalse;\
]", "", "", ""
},
{
/* RL__Pr: read the property length of an individual property value,
returning 0 if it isn't provided by the given object */
"RL__Pr",
"obj identifier x;\
if (identifier<64 && identifier>0) return obj.#identifier;\
x = obj..&identifier;\
if (x==0) rfalse;\
if (identifier&$C000==$4000)\
switch (((x-1)->0)&$C0)\
{ 0: return 1; $40: return 2; $80: return ((x-1)->0)&$3F; }\
return (x-1)->0;\
]", "", "", "", "", ""
},
{
/* RA__Sc: implement the "superclass" (::) operator,
returning an identifier */
"RA__Sc",
"cla identifier otherid i j k;\
if (cla notin 1 && cla > 4)\
{ RT__Err(\"be a '::' superclass\", cla, -1); rfalse; }\
if (self ofclass cla) otherid = identifier | $8000;\
for (j=0: #classes_table-->j ~= 0: j++)\
{ if (cla==#classes_table-->j)\
{ if (identifier < 64) return $4000 + identifier*$100 + j;\
if (cla.&3 == 0) break;\
i = cla.3;",
"while (i-->0 ~= 0)\
{ if (i-->0 == identifier or otherid)\
return $8000 + k*$100 + j;\
i = i + i->2 + 3;\
k++;\
}\
break;\
}\
}\
RT__Err(\"make use of\", cla, identifier);\
rfalse;\
]", "", "", "", ""
},
{
/* OP__Pr: test whether or not given object provides individual
property with the given identifier code */
"OP__Pr",
"obj identifier;\
if (obj<1 || obj > (#largest_object-255))\
{ if (identifier ~= print or print_to_array or call) rfalse;\
switch(Z__Region(obj))\
{ 2: if (identifier == call) rtrue;\
3: if (identifier == print or print_to_array) rtrue;\
}\
rfalse;\
}",
"if (identifier<64)\
{ if (obj.&identifier ~= 0) rtrue;\
rfalse;\
}\
if (obj..&identifier ~= 0) rtrue;\
if (identifier<72 && obj in 1) rtrue;\
rfalse;\
]", "", "", "", ""
},
{
/* OC__Cl: test whether or not given object is of the given class */
"OC__Cl",
"obj cla j a n;\
if (obj<1 || obj > (#largest_object-255))\
{ if (cla ~= 3 or 4) rfalse;\
if (Z__Region(obj) == cla-1) rtrue;\
rfalse;\
}\
if (cla == 1) {\
if (obj<=4) rtrue;\
if (obj in 1) rtrue;\
rfalse;\
} else if (cla == 2) {\
if (obj<=4) rfalse;\
if (obj in 1) rfalse;\
rtrue;\
} else if (cla == 3 or 4) {\
rfalse;\
}",
"if (cla notin 1) { RT__Err(\"apply 'ofclass' for\", cla, -1);rfalse;}\
@get_prop_addr obj 2 -> a;\
if (a==0) rfalse;\
@get_prop_len a -> n;\
for (j=0: j<n/2: j++)\
{ if (a-->j == cla) rtrue;\
}\
rfalse;\
]", "", "", "", ""
},
{ /* Copy__Primitive: routine to "deep copy" objects */
"Copy__Primitive",
"o1 o2 a1 a2 n m l size identifier;\
for (n=0:n<48:n++)\
{ if (o2 has n) give o1 n;\
else give o1 ~n;\
}\
for (n=1:n<64:n++) if (n~=2 or 3)\
{ a1 = o1.&n; a2 = o2.&n; size = o1.#n;\
if (a1~=0 && a2~=0 && size==o2.#n)\
{ for (m=0:m<size:m++) a1->m=a2->m;\
}\
}",
"if (o1.&3 == 0 || o2.&3 == 0) return;\
for (n=o2.3: n-->0 ~= 0: n = n + size + 3)\
{ identifier = n-->0;\
size = n->2;\
for (m=o1.3: m-->0 ~= 0: m = m + m->2 + 3)\
if ((identifier & $7fff == (m-->0) & $7fff) && size==m->2)\
for (l=3: l<size+3: l++) m->l = n->l;\
}\
]", "", "", "", ""
},
{ /* RT__Err: for run-time errors occurring in the above: e.g.,
an attempt to write to a non-existent individual
property */
"RT__Err",
"crime obj id size p q;\
print \"^[** Programming error: \";\
if (crime<0) jump RErr;\
if (crime==1) { print \"class \"; @print_obj obj;\
\": 'create' can have 0 to 3 parameters only **]\";}\
if (crime == 32) \"objectloop broken because the object \",\
(name) obj, \" was moved while the loop passed through it **]\";\
if (crime == 33) \"tried to print (char) \", obj,\
\", which is not a valid ZSCII character code for output **]\";\
if (crime == 34) \"tried to print (address) on something not the \",\
\"byte address of a string **]\";\
if (crime == 35) \"tried to print (string) on something not a \",\
\"string **]\";\
if (crime == 36) \"tried to print (object) on something not an \",\
\"object or class **]\";",
"if (crime < 32) { print \"tried to \";\
if (crime >= 28) { if (crime==28 or 29) print \"read from \";\
else print \"write to \";\
if (crime==29 or 31) print \"-\"; print \"->\", obj,\
\" in the\"; switch(size&7){0,1:q=0; 2:print \" string\";\
q=1; 3:print \" table\";q=1; 4:print \" buffer\";q=WORDSIZE;} \
if(size&16) print\" (->)\"; if(size&8) print\" (-->)\";\
\" array ~\", (string) #array_names_offset-->p,\
\"~, which has entries \", q, \" up to \",id,\" **]\"; }\
if (crime >= 24 && crime <=27) { if (crime<=25) print \"read\";\
else print \"write\"; print \" outside memory using \";\
switch(crime) { 24,26:\"-> **]\"; 25,27:\"--> **]\"; } }\
if (crime < 4) print \"test \"; else\
if (crime < 12 || crime > 20) print \"find the \"; else\
if (crime < 14) print \"use \";\
if (crime==20) \"divide by zero **]\"; print \"~\";\
switch(crime) {\
2: print \"in~ or ~notin\"; 3: print \"has~ or ~hasnt\";\
4: print \"parent\"; 5: print \"eldest\"; 6: print \"child\";\
7: print \"younger\"; 8: print \"sibling\"; 9: print \"children\";\
10: print \"youngest\"; 11: print \"elder\";\
12: print \"objectloop\"; 13: print \"}~ at end of ~objectloop\";\
14: \"give~ an attribute to \", (name) obj, \" **]\";\
15: \"remove~ \", (name) obj, \" **]\";",
"16,17,18: print \"move~ \", (name) obj, \" to \", (name) id;\
if (crime==18) { print \", which would make a loop: \",(name) obj;\
p=id; if (p==obj) p=obj;\
else do { print \" in \", (name) p; p=parent(p);} until (p==obj);\
\" in \", (name) p, \" **]\"; }\
\" **]\"; 19: \"give~ or test ~has~ or ~hasnt~ with a non-attribute"\
" on the object \",(name) obj,\" **]\";\
21: print \".&\"; 22: print \".#\"; 23: print \".\"; }\
\"~ of \", (name) obj, \" **]\"; }",
".RErr; if (obj>=0 && obj<=(#largest_object-255)) {\
if (obj && obj in Class) print \"class \";\
if (obj) @print_obj obj;else print \"nothing\";print\" \";}\
print \"(object number \", obj, \") \";\
if (id<0) print \"is not of class \", (name) -id;",
"else if (size) print \"has a property \", (property) id,\
\", but it is longer than 2 bytes so you cannot use ~.~\";\
else\
{ print \" has no property \", (property) id;\
p = #identifiers_table;\
size = p-->0;\
if (id<0 || id>=size)\
print \" (and nor has any other object)\";\
}\
print \" to \", (string) crime, \" **]^\";\
]", ""
},
{ /* Z__Region: Determines whether a value is:
1 an object number
2 a code address
3 a string address
0 none of the above */
"Z__Region",
"addr top;\
if (addr==0 or -1) rfalse;\
top = addr;\
#IfV5; #iftrue (#version_number == 6) || (#version_number == 7);\
@log_shift addr $FFFF -> top; #Endif; #Endif;\
if (Unsigned__Compare(top, $001A-->0) >= 0) rfalse;\
if (addr>=1 && addr<=(#largest_object-255)) rtrue;\
#iftrue #oddeven_packing;\
@test addr 1 ?~NotString;\
if (Unsigned__Compare(addr, #strings_offset)<0) rfalse;\
return 3;\
.NotString;\
if (Unsigned__Compare(addr, #code_offset)<0) rfalse;\
return 2;\
#ifnot;\
if (Unsigned__Compare(addr, #strings_offset)>=0) return 3;\
if (Unsigned__Compare(addr, #code_offset)>=0) return 2;\
rfalse;\
#endif;\
]", "", "", "", "", ""
},
{ /* Unsigned__Compare: returns 1 if x>y, 0 if x=y, -1 if x<y */
"Unsigned__Compare",
"x y u v;\
if (x==y) return 0;\
if (x<0 && y>=0) return 1;\
if (x>=0 && y<0) return -1;\
u = x&$7fff; v= y&$7fff;\
if (u>v) return 1;\
return -1;\
]", "", "", "", "", ""
},
{ /* Meta__class: returns the metaclass of an object */
"Meta__class",
"obj;\
switch(Z__Region(obj))\
{ 2: return Routine;\
3: return String;\
1: if (obj in 1 || obj <= 4) return Class;\
return Object;\
}\
rfalse;\
]", "", "", "", "", ""
},
{ /* CP__Tab: searches a common property table for the given
identifier, thus imitating the get_prop_addr opcode.
Returns 0 if not provided, except:
if the identifier supplied is -1, then returns
the address of the first byte after the table. */
"CP__Tab",
"x id n l;\
while ((n=0->x) ~= 0)\
{ if (n & $80) { x++; l = (0->x) & $3f; }\
else { if (n & $40) l=2; else l=1; }\
x++;\
if ((n & $3f) == id) return x;\
x = x + l;\
}\
if (id<0) return x+1; rfalse; ]", "", "", "", "", ""
},
{ /* Cl__Ms: the five message-receiving properties of Classes */
"Cl__Ms",
"obj id y a b c d x;\
switch(id)\
{ create:\
if (children(obj)<=1) rfalse; x=child(obj);\
remove x; if (x provides create) { if (y==0) x..create();\
if (y==1) x..create(a); if (y==2) x..create(a,b);\
if (y>3) RT__Err(1,obj); if (y>=3) x..create(a,b,c);}\
return x;\
recreate:\
if (~~(a ofclass obj))\
{ RT__Err(\"recreate\", a, -obj); rfalse; }\
Copy__Primitive(a, child(obj));\
if (a provides create) { if (y==1) a..create();\
if (y==2) a..create(b); if (y==3) a..create(b,c);\
if (y>4) RT__Err(1,obj); if (y>=4) a..create(b,c,d);\
} rfalse;",
"destroy:\
if (~~(a ofclass obj))\
{ RT__Err(\"destroy\", a, -obj); rfalse; }\
if (a provides destroy) a..destroy();\
Copy__Primitive(a, child(obj));\
move a to obj; rfalse;\
remaining:\
return children(obj)-1;",
"copy:\
if (~~(a ofclass obj))\
{ RT__Err(\"copy\", a, -obj); rfalse; }\
if (~~(b ofclass obj))\
{ RT__Err(\"copy\", b, -obj); rfalse; }\
Copy__Primitive(a, b); rfalse;\
}\
]", "", "", ""
},
{ /* RT__ChT: check at run-time that a proposed object move is legal
cause error and do nothing if not; otherwise move */
"RT__ChT",
"obj1 obj2 x;\
if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
return RT__Err(16,obj1,obj2);\
if (obj2<5 || obj2>(#largest_object-255) || obj2 in 1)\
return RT__Err(17,obj1,obj2);",
"x=obj2; while (x~=0) { if (x==obj1) return RT__Err(18,obj1,obj2); \
x=parent(x); }\
#ifdef INFIX;\
if (obj1 has infix__watching\
|| obj2 has infix__watching || (debug_flag & 15))\
print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
#ifnot; #ifdef DEBUG;\
if (debug_flag & 15)\
print \"[Moving \", (name) obj1, \" to \", (name) obj2, \"]^\";\
#endif; #endif;\
@insert_obj obj1 obj2; ]", "", "", "", ""
},
{ /* RT__ChR: check at run-time that a proposed object remove is legal
cause error and do nothing if not; otherwise remove */
"RT__ChR",
"obj1;\
if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
return RT__Err(15,obj1);",
"#ifdef INFIX;\
if (obj1 has infix__watching || (debug_flag & 15))\
print \"[Removing \", (name) obj1, \"]^\";\
#ifnot; #ifdef DEBUG;\
if (debug_flag & 15)\
print \"[Removing \", (name) obj1, \"]^\";\
#endif; #endif;\
@remove_obj obj1; ]", "", "", "", ""
},
{ /* RT__ChG: check at run-time that a proposed attr give is legal
cause error and do nothing if not; otherwise give */
"RT__ChG",
"obj1 a;\
if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
return RT__Err(14,obj1); if (a<0 || a>=48) return RT__Err(19,obj1);\
if (obj1 has a) return;",
"#ifdef INFIX;\
if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
#ifnot; #ifdef DEBUG;\
if (a ~= workflag && debug_flag & 15)\
print \"[Giving \", (name) obj1, \" \", (DebugAttribute) a, \"]^\";\
#endif; #endif;\
@set_attr obj1 a; ]", "", "", "", ""
},
{ /* RT__ChGt: check at run-time that a proposed attr give ~ is legal
cause error and do nothing if not; otherwise give */
"RT__ChGt",
"obj1 a;\
if (obj1<5 || obj1>(#largest_object-255) || obj1 in 1)\
return RT__Err(14,obj1); if (a<0 || a>=48) return RT__Err(19,obj1);\
if (obj1 hasnt a) return;",
"#ifdef INFIX;\
if (a ~= workflag && (obj1 has infix__watching || (debug_flag & 15)))\
print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
#ifnot; #ifdef DEBUG;\
if (a ~= workflag && debug_flag & 15)\
print \"[Giving \",(name) obj1,\" @@126\", (DebugAttribute) a, \"]^\";\
#endif; #endif;\
@clear_attr obj1 a; ]", "", "", "", ""
},
{ /* RT__ChPS: check at run-time that a proposed property set is legal
cause error and do nothing if not; otherwise make it */
"RT__ChPS",
"obj prop val size;\
if (obj<5 || obj>(#largest_object-255) || obj in 1 || obj.&prop==0 || (size=obj.#prop)>2 )\
return RT__Err(\"set\", obj, prop, size);\
@put_prop obj prop val;",
"#ifdef INFIX;\
if (obj has infix__watching || (debug_flag & 15)) RT__TrPS(obj,prop,val);\
#ifnot; #ifdef DEBUG;\
if (debug_flag & 15) RT__TrPS(obj,prop,val);\
#endif; #endif;\
return val; ]", "", "", "", ""
},
{ /* RT__ChPR: check at run-time that a proposed property read is legal
cause error and return 0 if not; otherwise read it */
"RT__ChPR",
"obj prop val size;\
if (obj<5 || obj>(#largest_object-255) || (size=obj.#prop)>2)\
{RT__Err(\"read\", obj, prop, size); obj=2;}\
@get_prop obj prop -> val;",
"return val; ]", "", "", "", ""
},
{ /* RT__TrPS: trace property settings */
"RT__TrPS",
"obj prop val;\
print \"[Setting \",(name) obj,\".\",(property) prop,\
\" to \",val,\"]^\"; ]",
"", "", "", "", ""
},
{ /* RT__ChLDB: check at run-time that it's safe to load a byte
and return the byte */
"RT__ChLDB",
"base offset a val;\
a=base+offset;if (Unsigned__Compare(a,#readable_memory_offset)>=0)\
return RT__Err(24);",
"@loadb base offset -> val;return val; ]", "", "", "", ""
},
{ /* RT__ChLDW: check at run-time that it's safe to load a word
and return the word */
"RT__ChLDW",
"base offset a val;\
a=base+2*offset;if (Unsigned__Compare(a,#readable_memory_offset)>=0)\
return RT__Err(25);",
"@loadw base offset -> val;return val; ]", "", "", "", ""
},
{ /* RT__ChSTB: check at run-time that it's safe to store a byte
and store it */
"RT__ChSTB",
"base offset val a f;\
a=base+offset;\
if (Unsigned__Compare(a,#array__start)>=0\
&& Unsigned__Compare(a,#array__end)<0) f=1; else\
if (Unsigned__Compare(a,#cpv__start)>=0\
&& Unsigned__Compare(a,#cpv__end)<0) f=1; else\
if (Unsigned__Compare(a,#ipv__start)>=0\
&& Unsigned__Compare(a,#ipv__end)<0) f=1; else\
if (a==$0011) f=1;\
if (f==0) return RT__Err(26);",
"@storeb base offset val; ]", "", "", "", ""
},
{ /* RT__ChSTW: check at run-time that it's safe to store a word
and store it */
"RT__ChSTW",
"base offset val a f;\
a=base+2*offset;\
if (Unsigned__Compare(a,#array__start)>=0\
&& Unsigned__Compare(a,#array__end)<0) f=1; else\
if (Unsigned__Compare(a,#cpv__start)>=0\
&& Unsigned__Compare(a,#cpv__end)<0) f=1; else\
if (Unsigned__Compare(a,#ipv__start)>=0\
&& Unsigned__Compare(a,#ipv__end)<0) f=1; else\
if (a==$0010) f=1;\
if (f==0) return RT__Err(27);",
"@storew base offset val; ]", "", "", "", ""
},
{ /* RT__ChPrintC: check at run-time that it's safe to print (char)
and do so */
"RT__ChPrintC",
"c fl;\
if (c==0 or 9 or 11 or 13) fl=1;\
if (c>=32 && c<=126) fl=1; if (c>=155 && c<=251) fl=1;\
if (fl==0) return RT__Err(33,c);",
"@print_char c; ]", "", "", "", ""
},
{ /* RT__ChPrintA: check at run-time that it's safe to print (address)
and do so */
"RT__ChPrintA",
"a;\
if (Unsigned__Compare(a, #readable_memory_offset)>=0)\
return RT__Err(34);",
"@print_addr a; ]", "", "", "", ""
},
{ /* RT__ChPrintS: check at run-time that it's safe to print (string)
and do so */
"RT__ChPrintS",
"a;\
if (Z__Region(a)~=3) return RT__Err(35);",
"@print_paddr a; ]", "", "", "", ""
},
{ /* RT__ChPrintO: check at run-time that it's safe to print (object)
and do so */
"RT__ChPrintO",
"a;\
if (Z__Region(a)~=1) return RT__Err(36);",
"@print_obj a; ]", "", "", "", ""
}
};
static VeneerRoutine VRs_g[VENEER_ROUTINES] =
{
{
/* Box__Routine: Display the given array of text as a box quote.
This is a very simple implementation; the library should provide
a fancier version.
*/
"Box__Routine",
"maxwid arr ix;\
maxwid = 0;\
glk($0086, 7);\
for (ix=0 : ix<arr-->0 : ix++) {\
print (string) arr-->(ix+1);\
new_line;\
}\
glk($0086, 0);\
]", "", "", "", "", ""
},
/* This batch of routines is expected to be defined (rather better) by
the Inform library: these minimal forms here are provided to prevent
tiny non-library-using programs from failing to compile when certain
legal syntaxes (such as <<Action a b>>;) are used. */
{ "R_Process",
"a b c d; print \"Action <\", a, \" \", b, \" \", c;\
if (d) print \", \", d; print \">^\";\
]", "", "", "", "", ""
},
{ "DefArt",
"obj; print \"the \", obj; ]", "", "", "", "", ""
},
{ "InDefArt",
"obj; print \"a \", obj; ]", "", "", "", "", ""
},
{ "CDefArt",
"obj; print \"The \", obj; ]", "", "", "", "", ""
},
{ "CInDefArt",
"obj; print \"A \", obj; ]", "", "", "", "", ""
},
{ "PrintShortName",
"obj q; switch(metaclass(obj))\
{ 0: print \"nothing\";\
Object: q = obj-->GOBJFIELD_NAME; @streamstr q;\
Class: print \"class \"; q = obj-->GOBJFIELD_NAME; @streamstr q;\
Routine: print \"(routine at \", obj, \")\";\
String: print \"(string at \", obj, \")\";\
} ]", "", "", "", "", ""
},
{ "EnglishNumber",
"obj; print obj; ]", "", "", "", "", ""
},
{
/* Print__PName: Print the name of a property.
*/
"Print__PName",
"prop ptab cla maxcom minind maxind str;\
if (prop & $FFFF0000) {\
cla = #classes_table-->(prop & $FFFF);\
print (name) cla, \"::\";\
@ushiftr prop 16 prop;\
}\
ptab = #identifiers_table;\
maxcom = ptab-->1;\
minind = INDIV_PROP_START;\
maxind = minind + ptab-->3;\
str = 0;\
if (prop >= 0 && prop < maxcom) {\
str = (ptab-->0)-->prop;\
}\
else if (prop >= minind && prop < maxind) {\
str = (ptab-->2)-->(prop-minind);\
}\
if (str)\
print (string) str;\
else\
print \"<number \", prop, \">\";\
]", "", "", "", "", ""
},
/* The remaining routines make up the run-time half of the object
orientation system, and need never be present for Inform 5 programs. */
{
/* WV__Pr: Write a value to the property for the given object.
*/
"WV__Pr",
"obj id val addr;\
addr = obj.&id;\
if (addr == 0) {\
RT__Err(\"write\", obj, id);\