-
Notifications
You must be signed in to change notification settings - Fork 35
/
states.c
2826 lines (2477 loc) · 118 KB
/
states.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
/* ------------------------------------------------------------------------- */
/* "states" : Statement translator */
/* */
/* Part of Inform 6.43 */
/* copyright (c) Graham Nelson 1993 - 2024 */
/* */
/* ------------------------------------------------------------------------- */
#include "header.h"
static int match_colon(void)
{ get_next_token();
if (token_type == SEP_TT)
{ if (token_value == SEMICOLON_SEP)
warning("Unlike C, Inform uses ':' to divide parts \
of a 'for' loop specification: replacing ';' with ':'");
else
if (token_value != COLON_SEP)
{ ebf_curtoken_error("':'");
panic_mode_error_recovery();
return(FALSE);
}
}
else
{ ebf_curtoken_error("':'");
panic_mode_error_recovery();
return(FALSE);
}
return(TRUE);
}
static void match_open_bracket(void)
{ get_next_token();
if ((token_type == SEP_TT) && (token_value == OPENB_SEP)) return;
put_token_back();
ebf_curtoken_error("'('");
}
extern void match_close_bracket(void)
{ get_next_token();
if ((token_type == SEP_TT) && (token_value == CLOSEB_SEP)) return;
put_token_back();
ebf_curtoken_error("')'");
}
static void parse_action(void)
{ int level = 1, args = 0, codegen_action;
assembly_operand AO, AO2, AO3, AO4, AO5;
/* An action statement has the form <ACTION NOUN SECOND, ACTOR>
or <<ACTION NOUN SECOND, ACTOR>>. It simply compiles into a call
to R_Process() with those four arguments. (The latter form,
with double brackets, means "return true afterwards".)
The R_Process() function should be supplied by the library,
although a stub is defined in the veneer.
The NOUN, SECOND, and ACTOR arguments are optional. If not
supplied, R_Process() will be called with fewer arguments.
(But if you supply ACTOR, it must be preceded by a comma.
<ACTION, ACTOR> is equivalent to <ACTION 0 0, ACTOR>.)
To complicate life, the ACTION argument may be a bare action
name or a parenthesized expression. (So <Take> is equivalent
to <(##Take)>.) We have to peek at the first token, checking
whether it's an open-paren, to distinguish these cases.
You may ask why the ACTOR argument is last; the "natural"
Inform ordering would be "<floyd, take ball>". True! Sadly,
Inform's lexer isn't smart enough to parse this consistently,
so we can't do it.
*/
dont_enter_into_symbol_table = TRUE;
get_next_token();
if ((token_type == SEP_TT) && (token_value == LESS_SEP))
{ level = 2; get_next_token();
}
dont_enter_into_symbol_table = FALSE;
/* Peek at the next token; see if it's an open-paren. */
if ((token_type==SEP_TT) && (token_value==OPENB_SEP))
{ put_token_back();
AO2 = parse_expression(ACTION_Q_CONTEXT);
codegen_action = TRUE;
}
else
{
if (token_type != UQ_TT) {
ebf_curtoken_error("name of action");
}
codegen_action = FALSE;
AO2 = action_of_name(token_text);
}
get_next_token();
AO3 = zero_operand;
AO4 = zero_operand;
AO5 = zero_operand;
if (!((token_type == SEP_TT) && (token_value == GREATER_SEP || token_value == COMMA_SEP)))
{ put_token_back();
args = 1;
AO3 = parse_expression(ACTION_Q_CONTEXT);
get_next_token();
}
if (!((token_type == SEP_TT) && (token_value == GREATER_SEP || token_value == COMMA_SEP)))
{ put_token_back();
args = 2;
AO4 = parse_expression(QUANTITY_CONTEXT);
get_next_token();
}
if (!((token_type == SEP_TT) && (token_value == GREATER_SEP || token_value == COMMA_SEP)))
{
ebf_curtoken_error("',' or '>'");
}
if ((token_type == SEP_TT) && (token_value == COMMA_SEP))
{
if (!glulx_mode && (version_number < 4))
{
error("<x, y> syntax is not available in Z-code V3 or earlier");
}
args = 3;
AO5 = parse_expression(QUANTITY_CONTEXT);
get_next_token();
if (!((token_type == SEP_TT) && (token_value == GREATER_SEP)))
{
ebf_curtoken_error("'>'");
}
}
if (level == 2)
{ get_next_token();
if (!((token_type == SEP_TT) && (token_value == GREATER_SEP)))
{ put_token_back();
ebf_curtoken_error("'>>'");
}
}
if (!glulx_mode) {
AO = veneer_routine(R_Process_VR);
switch(args)
{ case 0:
if (codegen_action) AO2 = code_generate(AO2, QUANTITY_CONTEXT, -1);
if (version_number>=5)
assemblez_2(call_2n_zc, AO, AO2);
else
if (version_number==4)
assemblez_2_to(call_vs_zc, AO, AO2, temp_var1);
else
assemblez_2_to(call_zc, AO, AO2, temp_var1);
break;
case 1:
AO3 = code_generate(AO3, QUANTITY_CONTEXT, -1);
if (codegen_action) AO2 = code_generate(AO2, QUANTITY_CONTEXT, -1);
if (version_number>=5)
assemblez_3(call_vn_zc, AO, AO2, AO3);
else
if (version_number==4)
assemblez_3_to(call_vs_zc, AO, AO2, AO3, temp_var1);
else
assemblez_3_to(call_zc, AO, AO2, AO3, temp_var1);
break;
case 2:
AO4 = code_generate(AO4, QUANTITY_CONTEXT, -1);
AO3 = code_generate(AO3, QUANTITY_CONTEXT, -1);
if (codegen_action) AO2 = code_generate(AO2, QUANTITY_CONTEXT, -1);
if (version_number>=5)
assemblez_4(call_vn_zc, AO, AO2, AO3, AO4);
else
if (version_number==4)
assemblez_4_to(call_vs_zc, AO, AO2, AO3, AO4, temp_var1);
else
assemblez_4_to(call_zc, AO, AO2, AO3, AO4, temp_var1);
break;
case 3:
AO5 = code_generate(AO5, QUANTITY_CONTEXT, -1);
AO4 = code_generate(AO4, QUANTITY_CONTEXT, -1);
AO3 = code_generate(AO3, QUANTITY_CONTEXT, -1);
if (codegen_action) AO2 = code_generate(AO2, QUANTITY_CONTEXT, -1);
if (version_number>=5)
assemblez_5(call_vn2_zc, AO, AO2, AO3, AO4, AO5);
else
if (version_number==4)
assemblez_5_to(call_vs2_zc, AO, AO2, AO3, AO4, AO5, temp_var1);
/* if V3 or earlier, we've already displayed an error */
break;
break;
}
if (level == 2) assemblez_0(rtrue_zc);
}
else {
AO = veneer_routine(R_Process_VR);
switch (args) {
case 0:
if (codegen_action)
AO2 = code_generate(AO2, QUANTITY_CONTEXT, -1);
assembleg_call_1(AO, AO2, zero_operand);
break;
case 1:
AO3 = code_generate(AO3, QUANTITY_CONTEXT, -1);
if (codegen_action)
AO2 = code_generate(AO2, QUANTITY_CONTEXT, -1);
assembleg_call_2(AO, AO2, AO3, zero_operand);
break;
case 2:
AO4 = code_generate(AO4, QUANTITY_CONTEXT, -1);
AO3 = code_generate(AO3, QUANTITY_CONTEXT, -1);
if (codegen_action)
AO2 = code_generate(AO2, QUANTITY_CONTEXT, -1);
assembleg_call_3(AO, AO2, AO3, AO4, zero_operand);
break;
case 3:
AO5 = code_generate(AO5, QUANTITY_CONTEXT, -1);
if (!((AO5.type == LOCALVAR_OT) && (AO5.value == 0)))
assembleg_store(stack_pointer, AO5);
AO4 = code_generate(AO4, QUANTITY_CONTEXT, -1);
if (!((AO4.type == LOCALVAR_OT) && (AO4.value == 0)))
assembleg_store(stack_pointer, AO4);
AO3 = code_generate(AO3, QUANTITY_CONTEXT, -1);
if (!((AO3.type == LOCALVAR_OT) && (AO3.value == 0)))
assembleg_store(stack_pointer, AO3);
if (codegen_action)
AO2 = code_generate(AO2, QUANTITY_CONTEXT, -1);
if (!((AO2.type == LOCALVAR_OT) && (AO2.value == 0)))
assembleg_store(stack_pointer, AO2);
assembleg_3(call_gc, AO, four_operand, zero_operand);
break;
}
if (level == 2)
assembleg_1(return_gc, one_operand);
}
}
extern int parse_label(void)
{
get_next_token();
if ((token_type == SYMBOL_TT) &&
(symbols[token_value].type == LABEL_T))
{ symbols[token_value].flags |= USED_SFLAG;
return(symbols[token_value].value);
}
if ((token_type == SYMBOL_TT) && (symbols[token_value].flags & UNKNOWN_SFLAG))
{ assign_symbol(token_value, next_label, LABEL_T);
define_symbol_label(token_value);
next_label++;
symbols[token_value].flags |= CHANGE_SFLAG + USED_SFLAG;
return(symbols[token_value].value);
}
ebf_curtoken_error("label name");
return 0;
}
static void parse_print_z(int finally_return)
{ int count = 0; assembly_operand AO;
/* print <printlist> -------------------------------------------------- */
/* print_ret <printlist> ---------------------------------------------- */
/* <literal-string> --------------------------------------------------- */
/* */
/* <printlist> is a comma-separated list of items: */
/* */
/* <literal-string> */
/* <other-expression> */
/* (char) <expression> */
/* (address) <expression> */
/* (string) <expression> */
/* (a) <expression> */
/* (the) <expression> */
/* (The) <expression> */
/* (name) <expression> */
/* (number) <expression> */
/* (property) <expression> */
/* (<routine>) <expression> */
/* (object) <expression> (for use in low-level code only) */
/* --------------------------------------------------------------------- */
do
{ AI.text = token_text;
if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) break;
switch(token_type)
{ case DQ_TT:
if (token_text[0] == '^' && token_text[1] == '\0') {
/* The string "^" is always a simple newline. */
assemblez_0(new_line_zc);
break;
}
if ((int)strlen(token_text) > ZCODE_MAX_INLINE_STRING)
{ INITAOT(&AO, LONG_CONSTANT_OT);
AO.marker = STRING_MV;
AO.value = compile_string(token_text, STRCTX_GAME);
assemblez_1(print_paddr_zc, AO);
if (finally_return)
{ get_next_token();
if ((token_type == SEP_TT)
&& (token_value == SEMICOLON_SEP))
{ assemblez_0(new_line_zc);
assemblez_0(rtrue_zc);
return;
}
put_token_back();
}
break;
}
if (finally_return)
{ get_next_token();
if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
{ assemblez_0(print_ret_zc); return;
}
put_token_back();
}
assemblez_0(print_zc);
break;
case SEP_TT:
if (token_value == OPENB_SEP)
{ misc_keywords.enabled = TRUE;
get_next_token();
get_next_token();
if ((token_type == SEP_TT) && (token_value == CLOSEB_SEP))
{ assembly_operand AO1;
put_token_back(); put_token_back();
local_variables.enabled = FALSE;
get_next_token();
misc_keywords.enabled = FALSE;
local_variables.enabled = TRUE;
if ((token_type == STATEMENT_TT)
&&(token_value == STRING_CODE))
{ token_type = MISC_KEYWORD_TT;
token_value = STRING_MK;
}
switch(token_type)
{
case MISC_KEYWORD_TT:
switch(token_value)
{ case CHAR_MK:
if (runtime_error_checking_switch)
{ AO = veneer_routine(RT__ChPrintC_VR);
goto PrintByRoutine;
}
get_next_token();
AO1 = code_generate(
parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1);
assemblez_1(print_char_zc, AO1);
goto PrintTermDone;
case ADDRESS_MK:
if (runtime_error_checking_switch)
{ AO = veneer_routine(RT__ChPrintA_VR);
goto PrintByRoutine;
}
get_next_token();
AO1 = code_generate(
parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1);
assemblez_1(print_addr_zc, AO1);
goto PrintTermDone;
case STRING_MK:
if (runtime_error_checking_switch)
{ AO = veneer_routine(RT__ChPrintS_VR);
goto PrintByRoutine;
}
get_next_token();
AO1 = code_generate(
parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1);
assemblez_1(print_paddr_zc, AO1);
goto PrintTermDone;
case OBJECT_MK:
if (runtime_error_checking_switch)
{ AO = veneer_routine(RT__ChPrintO_VR);
goto PrintByRoutine;
}
get_next_token();
AO1 = code_generate(
parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1);
assemblez_1(print_obj_zc, AO1);
goto PrintTermDone;
case THE_MK:
AO = veneer_routine(DefArt_VR);
goto PrintByRoutine;
case AN_MK:
case A_MK:
AO = veneer_routine(InDefArt_VR);
goto PrintByRoutine;
case CAP_THE_MK:
AO = veneer_routine(CDefArt_VR);
goto PrintByRoutine;
case CAP_A_MK:
AO = veneer_routine(CInDefArt_VR);
goto PrintByRoutine;
case NAME_MK:
AO = veneer_routine(PrintShortName_VR);
goto PrintByRoutine;
case NUMBER_MK:
AO = veneer_routine(EnglishNumber_VR);
goto PrintByRoutine;
case PROPERTY_MK:
AO = veneer_routine(Print__Pname_VR);
goto PrintByRoutine;
default:
error_named("A reserved word was used as a print specification:",
token_text);
}
break;
case SYMBOL_TT:
if (symbols[token_value].flags & UNKNOWN_SFLAG)
{ INITAOT(&AO, LONG_CONSTANT_OT);
AO.value = token_value;
AO.marker = SYMBOL_MV;
AO.symindex = token_value;
}
else
{ INITAOT(&AO, LONG_CONSTANT_OT);
AO.value = symbols[token_value].value;
AO.marker = IROUTINE_MV;
AO.symindex = token_value;
if (symbols[token_value].type != ROUTINE_T)
ebf_curtoken_error("printing routine name");
}
symbols[token_value].flags |= USED_SFLAG;
PrintByRoutine:
get_next_token();
if (version_number >= 5)
assemblez_2(call_2n_zc, AO,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1));
else if (version_number == 4)
assemblez_2_to(call_vs_zc, AO,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1), temp_var1);
else
assemblez_2_to(call_zc, AO,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1), temp_var1);
goto PrintTermDone;
default: ebf_curtoken_error("print specification");
get_next_token();
assemblez_1(print_num_zc,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1));
goto PrintTermDone;
}
}
put_token_back(); put_token_back(); put_token_back();
misc_keywords.enabled = FALSE;
assemblez_1(print_num_zc,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1));
break;
}
/* Fall through */
default:
put_token_back(); misc_keywords.enabled = FALSE;
assemblez_1(print_num_zc,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1));
break;
}
PrintTermDone: misc_keywords.enabled = FALSE;
count++;
get_next_token();
if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) break;
if ((token_type != SEP_TT) || (token_value != COMMA_SEP))
{ ebf_curtoken_error("comma");
panic_mode_error_recovery(); return;
}
else get_next_token();
} while(TRUE);
if (count == 0) ebf_curtoken_error("something to print");
if (finally_return)
{ assemblez_0(new_line_zc);
assemblez_0(rtrue_zc);
}
}
static void parse_print_g(int finally_return)
{ int count = 0; assembly_operand AO, AO2;
/* print <printlist> -------------------------------------------------- */
/* print_ret <printlist> ---------------------------------------------- */
/* <literal-string> --------------------------------------------------- */
/* */
/* <printlist> is a comma-separated list of items: */
/* */
/* <literal-string> */
/* <other-expression> */
/* (char) <expression> */
/* (address) <expression> */
/* (string) <expression> */
/* (a) <expression> */
/* (A) <expression> */
/* (the) <expression> */
/* (The) <expression> */
/* (name) <expression> */
/* (number) <expression> */
/* (property) <expression> */
/* (<routine>) <expression> */
/* (object) <expression> (for use in low-level code only) */
/* --------------------------------------------------------------------- */
do
{
if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) break;
switch(token_type)
{ case DQ_TT:
if (token_text[0] == '^' && token_text[1] == '\0') {
/* The string "^" is always a simple newline. */
INITAOTV(&AO, BYTECONSTANT_OT, 0x0A);
assembleg_1(streamchar_gc, AO);
break;
}
/* We can't compile a string into the instruction,
so this always goes into the string area. */
{ INITAOT(&AO, CONSTANT_OT);
AO.marker = STRING_MV;
AO.value = compile_string(token_text, STRCTX_GAME);
assembleg_1(streamstr_gc, AO);
if (finally_return)
{ get_next_token();
if ((token_type == SEP_TT)
&& (token_value == SEMICOLON_SEP))
{ INITAOTV(&AO, BYTECONSTANT_OT, 0x0A);
assembleg_1(streamchar_gc, AO);
INITAOTV(&AO, BYTECONSTANT_OT, 1);
assembleg_1(return_gc, AO);
return;
}
put_token_back();
}
break;
}
break;
case SEP_TT:
if (token_value == OPENB_SEP)
{ misc_keywords.enabled = TRUE;
get_next_token();
get_next_token();
if ((token_type == SEP_TT) && (token_value == CLOSEB_SEP))
{ assembly_operand AO1;
put_token_back(); put_token_back();
local_variables.enabled = FALSE;
get_next_token();
misc_keywords.enabled = FALSE;
local_variables.enabled = TRUE;
if ((token_type == STATEMENT_TT)
&&(token_value == STRING_CODE))
{ token_type = MISC_KEYWORD_TT;
token_value = STRING_MK;
}
switch(token_type)
{
case MISC_KEYWORD_TT:
switch(token_value)
{ case CHAR_MK:
if (runtime_error_checking_switch)
{ AO = veneer_routine(RT__ChPrintC_VR);
goto PrintByRoutine;
}
get_next_token();
AO1 = code_generate(
parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1);
if (is_constant_ot(AO1.type) && AO1.marker == 0) {
if (AO1.value >= 0 && AO1.value < 0x100)
assembleg_1(streamchar_gc, AO1);
else
assembleg_1(streamunichar_gc, AO1);
}
else {
assembleg_1(streamunichar_gc, AO1);
}
goto PrintTermDone;
case ADDRESS_MK:
if (runtime_error_checking_switch)
AO = veneer_routine(RT__ChPrintA_VR);
else
AO = veneer_routine(Print__Addr_VR);
goto PrintByRoutine;
case STRING_MK:
if (runtime_error_checking_switch)
{ AO = veneer_routine(RT__ChPrintS_VR);
goto PrintByRoutine;
}
get_next_token();
AO1 = code_generate(
parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1);
assembleg_1(streamstr_gc, AO1);
goto PrintTermDone;
case OBJECT_MK:
if (runtime_error_checking_switch)
{ AO = veneer_routine(RT__ChPrintO_VR);
goto PrintByRoutine;
}
get_next_token();
AO1 = code_generate(
parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1);
INITAOT(&AO2, BYTECONSTANT_OT);
AO2.value = GOBJFIELD_NAME();
assembleg_3(aload_gc, AO1, AO2,
stack_pointer);
assembleg_1(streamstr_gc, stack_pointer);
goto PrintTermDone;
case THE_MK:
AO = veneer_routine(DefArt_VR);
goto PrintByRoutine;
case AN_MK:
case A_MK:
AO = veneer_routine(InDefArt_VR);
goto PrintByRoutine;
case CAP_THE_MK:
AO = veneer_routine(CDefArt_VR);
goto PrintByRoutine;
case CAP_A_MK:
AO = veneer_routine(CInDefArt_VR);
goto PrintByRoutine;
case NAME_MK:
AO = veneer_routine(PrintShortName_VR);
goto PrintByRoutine;
case NUMBER_MK:
AO = veneer_routine(EnglishNumber_VR);
goto PrintByRoutine;
case PROPERTY_MK:
AO = veneer_routine(Print__Pname_VR);
goto PrintByRoutine;
default:
error_named("A reserved word was used as a print specification:",
token_text);
}
break;
case SYMBOL_TT:
if (symbols[token_value].flags & UNKNOWN_SFLAG)
{ INITAOT(&AO, CONSTANT_OT);
AO.value = token_value;
AO.marker = SYMBOL_MV;
AO.symindex = token_value;
}
else
{ INITAOT(&AO, CONSTANT_OT);
AO.value = symbols[token_value].value;
AO.marker = IROUTINE_MV;
AO.symindex = token_value;
if (symbols[token_value].type != ROUTINE_T)
ebf_curtoken_error("printing routine name");
}
symbols[token_value].flags |= USED_SFLAG;
PrintByRoutine:
get_next_token();
INITAOT(&AO2, ZEROCONSTANT_OT);
assembleg_call_1(AO,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1),
AO2);
goto PrintTermDone;
default: ebf_curtoken_error("print specification");
get_next_token();
assembleg_1(streamnum_gc,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1));
goto PrintTermDone;
}
}
put_token_back(); put_token_back(); put_token_back();
misc_keywords.enabled = FALSE;
assembleg_1(streamnum_gc,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1));
break;
}
/* Fall through */
default:
put_token_back(); misc_keywords.enabled = FALSE;
assembleg_1(streamnum_gc,
code_generate(parse_expression(QUANTITY_CONTEXT),
QUANTITY_CONTEXT, -1));
break;
}
PrintTermDone: misc_keywords.enabled = FALSE;
count++;
get_next_token();
if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) break;
if ((token_type != SEP_TT) || (token_value != COMMA_SEP))
{ ebf_curtoken_error("comma");
panic_mode_error_recovery(); return;
}
else get_next_token();
} while(TRUE);
if (count == 0) ebf_curtoken_error("something to print");
if (finally_return)
{
INITAOTV(&AO, BYTECONSTANT_OT, 0x0A);
assembleg_1(streamchar_gc, AO);
INITAOTV(&AO, BYTECONSTANT_OT, 1);
assembleg_1(return_gc, AO);
}
}
/* Parse any number of ".Label;" lines before a statement.
Returns whether a statement can in fact follow. */
static int parse_named_label_statements()
{
while ((token_type == SEP_TT) && (token_value == PROPERTY_SEP))
{ /* That is, a full stop, signifying a label */
get_next_token();
if (token_type != SYMBOL_TT)
{
ebf_curtoken_error("label name");
return TRUE;
}
if (symbols[token_value].flags & UNKNOWN_SFLAG)
{ assign_symbol(token_value, next_label, LABEL_T);
symbols[token_value].flags |= USED_SFLAG;
assemble_label_no(next_label);
define_symbol_label(token_value);
next_label++;
}
else
{ if (symbols[token_value].type != LABEL_T) {
ebf_curtoken_error("label name");
return TRUE;
}
if (symbols[token_value].flags & CHANGE_SFLAG)
{ symbols[token_value].flags &= (~(CHANGE_SFLAG));
assemble_label_no(symbols[token_value].value);
define_symbol_label(token_value);
}
else error_named("Duplicate definition of label:", token_text);
}
get_next_token();
if ((token_type != SEP_TT) || (token_value != SEMICOLON_SEP))
{ ebf_curtoken_error("';'");
put_token_back(); return FALSE;
}
/* Interesting point of Inform grammar: a statement can only
consist solely of a label when it is immediately followed
by a "}". */
get_next_token();
if ((token_type == SEP_TT) && (token_value == CLOSE_BRACE_SEP))
{ put_token_back(); return FALSE;
}
/* The following line prevents labels from influencing the positions
of sequence points. */
statement_debug_location = get_token_location();
/* Another label might follow */
}
/* On with the statement */
return TRUE;
}
static void parse_statement_z(int break_label, int continue_label)
{ int ln, ln2, ln3, ln4, flag;
int pre_unreach, labelexists;
assembly_operand AO, AO2, AO3, AO4;
debug_location spare_debug_location1, spare_debug_location2;
ASSERT_ZCODE();
if ((token_type == SEP_TT) && (token_value == HASH_SEP))
{ parse_directive(TRUE);
parse_statement(break_label, continue_label); return;
}
if ((token_type == SEP_TT) && (token_value == AT_SEP))
{ parse_assembly(); return;
}
if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) return;
if (token_type == DQ_TT)
{ parse_print_z(TRUE); return;
}
if ((token_type == SEP_TT) && (token_value == LESS_SEP))
{ parse_action(); goto StatementTerminator; }
if (token_type == EOF_TT)
{ ebf_curtoken_error("statement"); return; }
/* If we don't see a keyword, this must be a function call or
other expression-with-side-effects. */
if (token_type != STATEMENT_TT)
{ put_token_back();
AO = parse_expression(VOID_CONTEXT);
code_generate(AO, VOID_CONTEXT, -1);
if (vivc_flag) { panic_mode_error_recovery(); return; }
goto StatementTerminator;
}
statements.enabled = FALSE;
switch(token_value)
{
/* -------------------------------------------------------------------- */
/* box <string-1> ... <string-n> -------------------------------------- */
/* -------------------------------------------------------------------- */
case BOX_CODE:
if (version_number == 3)
warning("The 'box' statement has no effect in a version 3 game");
INITAOT(&AO3, LONG_CONSTANT_OT);
AO3.value = begin_table_array();
AO3.marker = ARRAY_MV;
ln = 0; ln2 = 0;
do
{ get_next_token();
if ((token_type==SEP_TT)&&(token_value==SEMICOLON_SEP))
break;
if (token_type != DQ_TT)
ebf_curtoken_error("text of box line in double-quotes");
{ int i, j;
for (i=0, j=0; token_text[i] != 0; j++)
if (token_text[i] == '@')
{ if (token_text[i+1] == '@')
{ i = i + 2;
while (isdigit((uchar)token_text[i])) i++;
}
else
{ i++;
if (token_text[i] != 0) i++;
if (token_text[i] != 0) i++;
}
}
else i++;
if (j > ln2) ln2 = j;
}
put_token_back();
array_entry(ln++, FALSE, parse_expression(CONSTANT_CONTEXT));
} while (TRUE);
finish_array(ln, FALSE);
if (ln == 0)
error("No lines of text given for 'box' display");
if (version_number == 3) return;
INITAOTV(&AO2, SHORT_CONSTANT_OT, ln2);
INITAOTV(&AO4, VARIABLE_OT, 255);
assemblez_3_to(call_vs_zc, veneer_routine(Box__Routine_VR),
AO2, AO3, AO4);
return;
/* -------------------------------------------------------------------- */
/* break -------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
case BREAK_CODE:
if (break_label == -1)
error("'break' can only be used in a loop or 'switch' block");
else
assemblez_jump(break_label);
break;
/* -------------------------------------------------------------------- */
/* continue ----------------------------------------------------------- */
/* -------------------------------------------------------------------- */
case CONTINUE_CODE:
if (continue_label == -1)
error("'continue' can only be used in a loop block");
else
assemblez_jump(continue_label);
break;
/* -------------------------------------------------------------------- */
/* do <codeblock> until (<condition>) --------------------------------- */
/* -------------------------------------------------------------------- */
case DO_CODE:
assemble_label_no(ln = next_label++);
ln2 = next_label++; ln3 = next_label++;
parse_code_block(ln3, ln2, 0);
statements.enabled = TRUE;
get_next_token();
if ((token_type == STATEMENT_TT)
&& (token_value == UNTIL_CODE))
{ assemble_forward_label_no(ln2);
match_open_bracket();
AO = parse_expression(CONDITION_CONTEXT);
match_close_bracket();
code_generate(AO, CONDITION_CONTEXT, ln);
}
else error("'do' without matching 'until'");
assemble_forward_label_no(ln3);
break;
/* -------------------------------------------------------------------- */
/* font on/off -------------------------------------------------------- */
/* -------------------------------------------------------------------- */
case FONT_CODE:
misc_keywords.enabled = TRUE;
get_next_token();
misc_keywords.enabled = FALSE;
if ((token_type != MISC_KEYWORD_TT)
|| ((token_value != ON_MK)
&& (token_value != OFF_MK)))
{ ebf_curtoken_error("'on' or 'off'");
panic_mode_error_recovery();
break;
}
if (version_number >= 5)
{ /* Use the V5 @set_font opcode, setting font 4
(for font off) or 1 (for font on). */
INITAOT(&AO, SHORT_CONSTANT_OT);
if (token_value == ON_MK)
AO.value = 1;
else
AO.value = 4;
assemblez_1_to(set_font_zc, AO, temp_var1);
break;
}
/* Set the fixed-pitch header bit. */
INITAOTV(&AO, SHORT_CONSTANT_OT, 0);
INITAOTV(&AO2, SHORT_CONSTANT_OT, 8);
INITAOTV(&AO3, VARIABLE_OT, 255);
assemblez_2_to(loadw_zc, AO, AO2, AO3);
if (token_value == ON_MK)
{ INITAOTV(&AO4, LONG_CONSTANT_OT, 0xfffd);
assemblez_2_to(and_zc, AO4, AO3, AO3);
}
else
{ INITAOTV(&AO4, SHORT_CONSTANT_OT, 2);
assemblez_2_to(or_zc, AO4, AO3, AO3);
}
assemblez_3(storew_zc, AO, AO2, AO3);
break;
/* -------------------------------------------------------------------- */
/* for (<initialisation> : <continue-condition> : <updating>) --------- */
/* -------------------------------------------------------------------- */
/* Note that it's legal for any or all of the three sections of a
'for' specification to be empty. This 'for' implementation
often wastes 3 bytes with a redundant branch rather than keep
expression parse trees for long periods (as previous versions
of Inform did, somewhat crudely by simply storing the textual
form of a 'for' loop). It is adequate for now. */
case FOR_CODE:
match_open_bracket();
get_next_token();
/* Initialisation code */
AO.type = OMITTED_OT;
spare_debug_location1 = statement_debug_location;
AO2.type = OMITTED_OT; flag = 0;
spare_debug_location2 = statement_debug_location;