1 /* ------------------------------------------------------------------------- */
2 /* "directs" : Directives (# commands) */
4 /* Copyright (c) Graham Nelson 1993 - 2020 */
6 /* This file is part of Inform. */
8 /* Inform is free software: you can redistribute it and/or modify */
9 /* it under the terms of the GNU General Public License as published by */
10 /* the Free Software Foundation, either version 3 of the License, or */
11 /* (at your option) any later version. */
13 /* Inform is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU General Public License for more details. */
18 /* You should have received a copy of the GNU General Public License */
19 /* along with Inform. If not, see https://gnu.org/licenses/ */
21 /* ------------------------------------------------------------------------- */
25 int no_routines, /* Number of routines compiled so far */
26 no_named_routines, /* Number not embedded in objects */
27 no_locals, /* Number of locals in current routine */
28 no_termcs; /* Number of terminating characters */
29 int terminating_characters[32];
31 brief_location routine_starts_line; /* Source code location where the current
32 routine starts. (Useful for reporting
33 "unused variable" warnings on the start
34 line rather than the end line.) */
36 static int constant_made_yet; /* Have any constants been defined yet? */
38 static int ifdef_stack[32], ifdef_sp;
40 /* ------------------------------------------------------------------------- */
42 static int ebf_error_recover(char *s1, char *s2)
44 /* Display an "expected... but found..." error, then skim forward
45 to the next semicolon and return FALSE. This is such a common
46 case in parse_given_directive() that it's worth a utility
47 function. You will see many error paths that look like:
48 return ebf_error_recover(...);
51 panic_mode_error_recovery();
55 /* ------------------------------------------------------------------------- */
57 extern int parse_given_directive(int internal_flag)
58 { /* Internal_flag is FALSE if the directive is encountered normally,
59 TRUE if encountered with a # prefix inside a routine or object
62 Returns: FALSE if program continues, TRUE if end of file reached. */
64 int *trace_level = NULL; int32 i, j, k, n, flag;
65 const char *constant_name;
66 debug_location_beginning beginning_debug_location;
71 /* --------------------------------------------------------------------- */
72 /* Abbreviate "string1" ["string2" ...] */
73 /* --------------------------------------------------------------------- */
79 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
82 /* Z-code has a 64-abbrev limit; Glulx doesn't. */
83 if (!glulx_mode && no_abbreviations==64)
84 { error("All 64 abbreviations already declared");
85 panic_mode_error_recovery(); return FALSE;
87 if (no_abbreviations==MAX_ABBREVS)
88 memoryerror("MAX_ABBREVS", MAX_ABBREVS);
90 if (abbrevs_lookup_table_made)
91 { error("All abbreviations must be declared together");
92 panic_mode_error_recovery(); return FALSE;
94 if (token_type != DQ_TT)
95 return ebf_error_recover("abbreviation string", token_text);
96 if (strlen(token_text)<2)
97 { error_named("It's not worth abbreviating", token_text);
100 /* Abbreviation string with null must fit in a MAX_ABBREV_LENGTH
102 if (strlen(token_text)>=MAX_ABBREV_LENGTH)
103 { error_named("Abbreviation too long", token_text);
106 make_abbreviation(token_text);
109 /* --------------------------------------------------------------------- */
110 /* Array arrayname array... */
111 /* --------------------------------------------------------------------- */
113 case ARRAY_CODE: make_global(TRUE, FALSE); break; /* See "tables.c" */
115 /* --------------------------------------------------------------------- */
116 /* Attribute newname [alias oldname] */
117 /* --------------------------------------------------------------------- */
120 make_attribute(); break; /* See "objects.c" */
122 /* --------------------------------------------------------------------- */
123 /* Class classname ... */
124 /* --------------------------------------------------------------------- */
128 { error("Cannot nest #Class inside a routine or object");
129 panic_mode_error_recovery(); return FALSE;
131 make_class(NULL); /* See "objects.c" */
134 /* --------------------------------------------------------------------- */
135 /* Constant newname [[=] value] [, ...] */
136 /* --------------------------------------------------------------------- */
139 constant_made_yet=TRUE;
142 get_next_token(); i = token_value;
143 beginning_debug_location = get_token_location_beginning();
145 if ((token_type != SYMBOL_TT)
146 || (!(sflags[i] & (UNKNOWN_SFLAG + REDEFINABLE_SFLAG))))
147 { discard_token_location(beginning_debug_location);
148 return ebf_error_recover("new constant name", token_text);
151 assign_symbol(i, 0, CONSTANT_T);
152 constant_name = token_text;
156 if ((token_type == SEP_TT) && (token_value == COMMA_SEP))
157 { if (debugfile_switch && !(sflags[i] & REDEFINABLE_SFLAG))
158 { debug_file_printf("<constant>");
159 debug_file_printf("<identifier>%s</identifier>", constant_name);
160 write_debug_symbol_optional_backpatch(i);
161 write_debug_locations(get_token_location_end(beginning_debug_location));
162 debug_file_printf("</constant>");
164 goto ParseConstantSpec;
167 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
168 { if (debugfile_switch && !(sflags[i] & REDEFINABLE_SFLAG))
169 { debug_file_printf("<constant>");
170 debug_file_printf("<identifier>%s</identifier>", constant_name);
171 write_debug_symbol_optional_backpatch(i);
172 write_debug_locations(get_token_location_end(beginning_debug_location));
173 debug_file_printf("</constant>");
178 if (!((token_type == SEP_TT) && (token_value == SETEQUALS_SEP)))
181 { assembly_operand AO = parse_expression(CONSTANT_CONTEXT);
183 { assign_marked_symbol(i, AO.marker, AO.value,
185 sflags[i] |= CHANGE_SFLAG;
186 if (i == grammar_version_symbol)
188 "Grammar__Version must be given an explicit constant value");
191 { assign_symbol(i, AO.value, CONSTANT_T);
192 if (i == grammar_version_symbol)
193 { if ((grammar_version_number != AO.value)
194 && (no_fake_actions > 0))
196 "Once a fake action has been defined it is too late to \
197 change the grammar version. (If you are using the library, move any \
198 Fake_Action directives to a point after the inclusion of \"Parser\".)");
199 grammar_version_number = AO.value;
204 if (debugfile_switch && !(sflags[i] & REDEFINABLE_SFLAG))
205 { debug_file_printf("<constant>");
206 debug_file_printf("<identifier>%s</identifier>", constant_name);
207 write_debug_symbol_optional_backpatch(i);
208 write_debug_locations
209 (get_token_location_end(beginning_debug_location));
210 debug_file_printf("</constant>");
214 if ((token_type == SEP_TT) && (token_value == COMMA_SEP))
215 goto ParseConstantSpec;
219 /* --------------------------------------------------------------------- */
220 /* Default constantname integer */
221 /* --------------------------------------------------------------------- */
225 { error("'Default' cannot be used in -M (Module) mode");
226 panic_mode_error_recovery(); return FALSE;
230 if (token_type != SYMBOL_TT)
231 return ebf_error_recover("name", token_text);
234 if (sflags[token_value] & UNKNOWN_SFLAG)
236 sflags[i] |= DEFCON_SFLAG;
240 if (!((token_type == SEP_TT) && (token_value == SETEQUALS_SEP)))
243 { assembly_operand AO;
244 AO = parse_expression(CONSTANT_CONTEXT);
246 { if (AO.marker != 0)
247 { assign_marked_symbol(i, AO.marker, AO.value,
249 sflags[i] |= CHANGE_SFLAG;
251 else assign_symbol(i, AO.value, CONSTANT_T);
257 /* --------------------------------------------------------------------- */
258 /* Dictionary 'word' */
259 /* Dictionary 'word' val1 */
260 /* Dictionary 'word' val1 val3 */
261 /* --------------------------------------------------------------------- */
263 case DICTIONARY_CODE:
264 /* In Inform 5, this directive had the form
265 Dictionary SYMBOL "word";
266 This was deprecated as of I6 (if not earlier), and is no longer
267 supported at all. The current form just creates a dictionary word,
268 with the given values for dict_par1 and dict_par3. If the word
269 already exists, the values are bit-or'd in with the existing
271 (We don't offer a way to set dict_par2, because that is entirely
272 reserved for the verb number. Or'ing values into it would create
276 if (token_type != SQ_TT && token_type != DQ_TT)
277 return ebf_error_recover("dictionary word", token_text);
280 char *wd = token_text;
285 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) {
291 AO = parse_expression(CONSTANT_CONTEXT);
292 if (module_switch && (AO.marker != 0))
293 error("A definite value must be given as a Dictionary flag");
298 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) {
304 AO = parse_expression(CONSTANT_CONTEXT);
305 if (module_switch && (AO.marker != 0))
306 error("A definite value must be given as a Dictionary flag");
313 if ((val1 & ~0xFF) || (val3 & ~0xFF)) {
314 warning("Dictionary flag values cannot exceed $FF in Z-code");
318 if ((val1 & ~0xFFFF) || (val3 & ~0xFFFF)) {
319 warning("Dictionary flag values cannot exceed $FFFF in Glulx");
323 dictionary_add(wd, val1, 0, val3);
327 /* --------------------------------------------------------------------- */
329 /* --------------------------------------------------------------------- */
331 case END_CODE: return(TRUE);
334 if (ifdef_sp == 0) error("'Endif' without matching 'If...'");
338 /* --------------------------------------------------------------------- */
340 /* --------------------------------------------------------------------- */
342 case EXTEND_CODE: extend_verb(); return FALSE; /* see "tables.c" */
344 /* --------------------------------------------------------------------- */
345 /* Fake_Action name */
346 /* --------------------------------------------------------------------- */
348 case FAKE_ACTION_CODE:
349 make_fake_action(); break; /* see "verbs.c" */
351 /* --------------------------------------------------------------------- */
352 /* Global variable [= value / array...] */
353 /* --------------------------------------------------------------------- */
355 case GLOBAL_CODE: make_global(FALSE, FALSE); break; /* See "tables.c" */
357 /* --------------------------------------------------------------------- */
360 /* Note that each time Inform tests an If... condition, it stacks the */
361 /* result (TRUE or FALSE) on ifdef_stack: thus, the top of this stack */
362 /* reveals what clause of the current If... is being compiled: */
364 /* If...; ... Ifnot; ... Endif; */
365 /* top of stack: TRUE FALSE */
367 /* This is used to detect "two Ifnots in same If" errors. */
368 /* --------------------------------------------------------------------- */
378 if (token_type != SYMBOL_TT)
379 return ebf_error_recover("symbol name", token_text);
381 if ((token_text[0] == 'V')
382 && (token_text[1] == 'N')
383 && (token_text[2] == '_')
384 && (strlen(token_text)==7))
385 { i = atoi(token_text+3);
386 if (VNUMBER < i) flag = (flag)?FALSE:TRUE;
387 goto HashIfCondition;
390 if (sflags[token_value] & UNKNOWN_SFLAG) flag = (flag)?FALSE:TRUE;
391 else sflags[token_value] |= USED_SFLAG;
392 goto HashIfCondition;
396 error("'Ifnot' without matching 'If...'");
398 if (!(ifdef_stack[ifdef_sp-1]))
399 error("Second 'Ifnot' for the same 'If...' condition");
401 { dont_enter_into_symbol_table = -2; n = 1;
402 directives.enabled = TRUE;
405 if (token_type == EOF_TT)
406 { error("End of file reached in code 'If...'d out");
407 directives.enabled = FALSE;
410 if (token_type == DIRECTIVE_TT)
411 { switch(token_value)
424 "Second 'Ifnot' for the same 'If...' condition");
431 dont_enter_into_symbol_table = FALSE;
432 directives.enabled = FALSE;
437 flag = FALSE; if (version_number == 3) flag = TRUE;
438 goto HashIfCondition;
441 flag = TRUE; if (version_number == 3) flag = FALSE;
442 goto HashIfCondition;
445 { assembly_operand AO;
446 AO = parse_expression(CONSTANT_CONTEXT);
447 if (module_switch && (AO.marker != 0))
448 { error("This condition can't be determined");
451 else flag = (AO.value != 0);
453 goto HashIfCondition;
456 { assembly_operand AO;
457 AO = parse_expression(CONSTANT_CONTEXT);
458 if (module_switch && (AO.marker != 0))
459 { error("This condition can't be determined");
462 else flag = (AO.value == 0);
464 goto HashIfCondition;
468 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)))
469 return ebf_error_recover("semicolon after 'If...' condition", token_text);
472 { ifdef_stack[ifdef_sp++] = TRUE; return FALSE; }
474 { dont_enter_into_symbol_table = -2; n = 1;
475 directives.enabled = TRUE;
478 if (token_type == EOF_TT)
479 { error("End of file reached in code 'If...'d out");
480 directives.enabled = FALSE;
483 if (token_type == DIRECTIVE_TT)
497 { ifdef_stack[ifdef_sp++] = FALSE;
503 directives.enabled = FALSE;
504 dont_enter_into_symbol_table = FALSE;
508 /* --------------------------------------------------------------------- */
509 /* Import global <varname> [, ...] */
511 /* (Further imported goods may be allowed later.) */
512 /* --------------------------------------------------------------------- */
516 { error("'Import' can only be used in -M (Module) mode");
517 panic_mode_error_recovery(); return FALSE;
519 directives.enabled = TRUE;
522 if ((token_type == DIRECTIVE_TT) && (token_value == GLOBAL_CODE))
523 make_global(FALSE, TRUE);
524 else error_named("'Import' cannot import things of this type:",
527 } while ((token_type == SEP_TT) && (token_value == COMMA_SEP));
529 directives.enabled = FALSE;
532 /* --------------------------------------------------------------------- */
533 /* Include "[>]filename" */
535 /* The ">" character means to load the file from the same directory as */
536 /* the current file, instead of relying on the include path. */
537 /* --------------------------------------------------------------------- */
541 if (token_type != DQ_TT)
542 return ebf_error_recover("filename in double-quotes", token_text);
544 { char *name = token_text;
547 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)))
548 ebf_error("semicolon ';' after Include filename", token_text);
550 if (strcmp(name, "language__") == 0)
551 load_sourcefile(Language_Name, 0);
552 else if (name[0] == '>')
553 load_sourcefile(name+1, 1);
554 else load_sourcefile(name, 0);
558 /* --------------------------------------------------------------------- */
559 /* Link "filename" */
560 /* --------------------------------------------------------------------- */
564 if (token_type != DQ_TT)
565 return ebf_error_recover("filename in double-quotes", token_text);
566 link_module(token_text); /* See "linker.c" */
569 /* --------------------------------------------------------------------- */
570 /* Lowstring constantname "text of string" */
571 /* --------------------------------------------------------------------- */
572 /* Unlike most constant creations, these do not require backpatching: */
573 /* the low strings always occupy a table at a fixed offset in the */
574 /* Z-machine (after the abbreviations table has finished, at 0x100). */
575 /* --------------------------------------------------------------------- */
579 { error("'LowString' cannot be used in -M (Module) mode");
580 panic_mode_error_recovery(); return FALSE;
582 get_next_token(); i = token_value;
583 if ((token_type != SYMBOL_TT) || (!(sflags[i] & UNKNOWN_SFLAG)))
584 return ebf_error_recover("new low string name", token_text);
587 if (token_type != DQ_TT)
588 return ebf_error_recover("literal string in double-quotes", token_text);
590 assign_symbol(i, compile_string(token_text, TRUE, TRUE), CONSTANT_T);
593 /* --------------------------------------------------------------------- */
594 /* Message | "information" */
595 /* | error "error message" */
596 /* | fatalerror "fatal error message" */
597 /* | warning "warning message" */
598 /* --------------------------------------------------------------------- */
601 directive_keywords.enabled = TRUE;
603 directive_keywords.enabled = FALSE;
604 if (token_type == DQ_TT)
606 if (hash_printed_since_newline) printf("\n");
607 for (i=0; token_text[i]!=0; i++)
608 { if (token_text[i] == '^') printf("\n");
610 if (token_text[i] == '~') printf("\"");
611 else printf("%c", token_text[i]);
616 if ((token_type == DIR_KEYWORD_TT) && (token_value == ERROR_DK))
618 if (token_type != DQ_TT)
619 { return ebf_error_recover("error message in double-quotes", token_text);
621 error(token_text); break;
623 if ((token_type == DIR_KEYWORD_TT) && (token_value == FATALERROR_DK))
625 if (token_type != DQ_TT)
626 { return ebf_error_recover("fatal error message in double-quotes", token_text);
628 fatalerror(token_text); break;
630 if ((token_type == DIR_KEYWORD_TT) && (token_value == WARNING_DK))
632 if (token_type != DQ_TT)
633 { return ebf_error_recover("warning message in double-quotes", token_text);
635 warning(token_text); break;
637 return ebf_error_recover("a message in double-quotes, 'error', 'fatalerror' or 'warning'",
641 /* --------------------------------------------------------------------- */
642 /* Nearby objname "short name" ... */
643 /* --------------------------------------------------------------------- */
647 { error("Cannot nest #Nearby inside a routine or object");
648 panic_mode_error_recovery(); return FALSE;
650 make_object(TRUE, NULL, -1, -1, -1);
651 return FALSE; /* See "objects.c" */
653 /* --------------------------------------------------------------------- */
654 /* Object objname "short name" ... */
655 /* --------------------------------------------------------------------- */
659 { error("Cannot nest #Object inside a routine or object");
660 panic_mode_error_recovery(); return FALSE;
662 make_object(FALSE, NULL, -1, -1, -1);
663 return FALSE; /* See "objects.c" */
665 /* --------------------------------------------------------------------- */
666 /* Origsource <file> */
667 /* Origsource <file> <line> */
668 /* Origsource <file> <line> <char> */
671 /* The first three forms declare that all following lines are derived */
672 /* from the named Inform 7 source file (with an optional line number */
673 /* and character number). This will be reported in error messages and */
674 /* in debug output. The declaration holds through the next Origsource */
675 /* directive (but does not apply to included files). */
677 /* The fourth form, with no arguments, clears the declaration. */
679 /* Unlike the Include directive, Origsource does not open the named */
680 /* file or even verify that it exists. The filename is treated as an */
682 /* --------------------------------------------------------------------- */
684 case ORIGSOURCE_CODE:
686 char *origsource_file = NULL;
687 int32 origsource_line = 0;
688 int32 origsource_char = 0;
690 /* Parse some optional tokens followed by a mandatory semicolon. */
693 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))) {
694 if (token_type != DQ_TT) {
695 return ebf_error_recover("a file name in double-quotes",
698 origsource_file = token_text;
701 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))) {
702 if (token_type != NUMBER_TT) {
703 return ebf_error_recover("a file line number",
706 origsource_line = token_value;
707 if (origsource_line < 0)
711 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))) {
712 if (token_type != NUMBER_TT) {
713 return ebf_error_recover("a file line number",
716 origsource_char = token_value;
717 if (origsource_char < 0)
727 set_origsource_location(origsource_file, origsource_line, origsource_char);
731 /* --------------------------------------------------------------------- */
732 /* Property [long] [additive] name [alias oldname] */
733 /* --------------------------------------------------------------------- */
735 case PROPERTY_CODE: make_property(); break; /* See "objects.c" */
737 /* --------------------------------------------------------------------- */
738 /* Release <number> */
739 /* --------------------------------------------------------------------- */
742 { assembly_operand AO;
743 AO = parse_expression(CONSTANT_CONTEXT);
744 if (module_switch && (AO.marker != 0))
745 error("A definite value must be given as release number");
747 release_number = AO.value;
751 /* --------------------------------------------------------------------- */
752 /* Replace routine [routinename] */
753 /* --------------------------------------------------------------------- */
756 /* You can also replace system functions normally implemented in */
757 /* the "hardware" of the Z-machine, like "random()": */
759 system_functions.enabled = TRUE;
760 directives.enabled = FALSE;
761 directive_keywords.enabled = FALSE;
763 /* Don't count the upcoming symbol as a top-level reference
764 *to* the function. */
765 df_dont_note_global_symbols = TRUE;
767 df_dont_note_global_symbols = FALSE;
768 if (token_type == SYSFUN_TT)
769 { if (system_function_usage[token_value] == 1)
770 error("You can't 'Replace' a system function already used");
771 else system_function_usage[token_value] = 2;
773 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)))
775 error("You can't give a 'Replace'd system function a new name");
776 panic_mode_error_recovery(); return FALSE;
781 if (token_type != SYMBOL_TT)
782 return ebf_error_recover("name of routine to replace", token_text);
783 if (!(sflags[token_value] & UNKNOWN_SFLAG))
784 return ebf_error_recover("name of routine not yet defined", token_text);
786 sflags[token_value] |= REPLACE_SFLAG;
788 /* If a second symbol is provided, it will refer to the
789 original (replaced) definition of the routine. */
792 system_functions.enabled = FALSE;
793 df_dont_note_global_symbols = TRUE;
795 df_dont_note_global_symbols = FALSE;
796 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
800 if (token_type != SYMBOL_TT || !(sflags[token_value] & UNKNOWN_SFLAG))
801 return ebf_error_recover("semicolon ';' or new routine name", token_text);
803 /* Define the original-form symbol as a zero constant. Its
804 value will be overwritten later, when we define the
806 assign_symbol(token_value, 0, CONSTANT_T);
807 add_symbol_replacement_mapping(i, token_value);
811 /* --------------------------------------------------------------------- */
812 /* Serial "yymmdd" */
813 /* --------------------------------------------------------------------- */
817 if ((token_type != DQ_TT) || (strlen(token_text)!=6))
818 { error("The serial number must be a 6-digit date in double-quotes");
819 panic_mode_error_recovery(); return FALSE;
821 for (i=0; i<6; i++) if (isdigit(token_text[i])==0)
822 { error("The serial number must be a 6-digit date in double-quotes");
823 panic_mode_error_recovery(); return FALSE;
825 strcpy(serial_code_buffer, token_text);
826 serial_code_given_in_program = TRUE;
829 /* --------------------------------------------------------------------- */
830 /* Statusline score/time */
831 /* --------------------------------------------------------------------- */
833 case STATUSLINE_CODE:
835 warning("This does not set the final game's statusline");
837 directive_keywords.enabled = TRUE;
839 directive_keywords.enabled = FALSE;
840 if ((token_type != DIR_KEYWORD_TT)
841 || ((token_value != SCORE_DK) && (token_value != TIME_DK)))
842 return ebf_error_recover("'score' or 'time' after 'statusline'", token_text);
843 if (token_value == SCORE_DK) statusline_flag = SCORE_STYLE;
844 else statusline_flag = TIME_STYLE;
847 /* --------------------------------------------------------------------- */
848 /* Stub routinename number-of-locals */
849 /* --------------------------------------------------------------------- */
853 { error("Cannot nest #Stub inside a routine or object");
854 panic_mode_error_recovery(); return FALSE;
857 /* The upcoming symbol is a definition; don't count it as a
858 top-level reference *to* the stub function. */
859 df_dont_note_global_symbols = TRUE;
861 df_dont_note_global_symbols = FALSE;
862 if (token_type != SYMBOL_TT)
863 return ebf_error_recover("routine name to stub", token_text);
865 i = token_value; flag = FALSE;
867 if (sflags[i] & UNKNOWN_SFLAG)
868 { sflags[i] |= STUB_SFLAG;
872 get_next_token(); k = token_value;
873 if (token_type != NUMBER_TT)
874 return ebf_error_recover("number of local variables", token_text);
876 { error("Must specify 0 to 4 local variables for 'Stub' routine");
882 /* Give these parameter-receiving local variables names
883 for the benefit of the debugging information file,
884 and for assembly tracing to look sensible. */
886 local_variable_texts[0] = "dummy1";
887 local_variable_texts[1] = "dummy2";
888 local_variable_texts[2] = "dummy3";
889 local_variable_texts[3] = "dummy4";
892 assemble_routine_header(k, FALSE, (char *) symbs[i], FALSE, i),
895 /* Ensure the return value of a stubbed routine is false,
896 since this is necessary to make the library work properly */
899 assemblez_0(rfalse_zc);
901 assembleg_1(return_gc, zero_operand);
903 /* Inhibit "local variable unused" warnings */
905 for (i=1; i<=k; i++) variable_usage[i] = 1;
906 sequence_point_follows = FALSE;
907 assemble_routine_end(FALSE, get_token_locations());
911 /* --------------------------------------------------------------------- */
912 /* Switches switchblock */
913 /* (this directive is ignored if the -i switch was set at command line) */
914 /* --------------------------------------------------------------------- */
917 dont_enter_into_symbol_table = TRUE;
919 dont_enter_into_symbol_table = FALSE;
920 if (token_type != DQ_TT)
921 return ebf_error_recover("string of switches", token_text);
922 if (!ignore_switches_switch)
923 { if (constant_made_yet)
924 error("A 'Switches' directive must must come before \
925 the first constant definition");
926 switches(token_text, 0); /* see "inform.c" */
930 /* --------------------------------------------------------------------- */
933 /* Some files are declared as "system files": this information is used */
934 /* by Inform only to skip the definition of a routine X if the designer */
935 /* has indicated his intention to Replace X. */
936 /* --------------------------------------------------------------------- */
939 declare_systemfile(); break; /* see "files.c" */
941 /* --------------------------------------------------------------------- */
942 /* Trace dictionary */
947 /* assembly [on/off] */
948 /* expressions [on/off] */
950 /* --------------------------------------------------------------------- */
953 directives.enabled = FALSE;
954 trace_keywords.enabled = TRUE;
956 trace_keywords.enabled = FALSE;
957 directives.enabled = TRUE;
958 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
959 { asm_trace_level = 1; return FALSE; }
961 if (token_type != TRACE_KEYWORD_TT)
962 return ebf_error_recover("debugging keyword", token_text);
964 trace_keywords.enabled = TRUE;
966 i = token_value; j = 0;
968 { case DICTIONARY_TK: break;
969 case OBJECTS_TK: break;
970 case VERBS_TK: break;
974 trace_level = &asm_trace_level; break;
976 trace_level = &expr_trace_level; break;
978 trace_level = &line_trace_level; break;
980 trace_level = &tokens_trace_level; break;
982 trace_level = &linker_trace_level; break;
984 trace_level = NULL; break;
987 trace_level = &asm_trace_level; break;
991 if ((token_type == SEP_TT) &&
992 (token_value == SEMICOLON_SEP))
993 { put_token_back(); break;
995 if (token_type == NUMBER_TT)
996 { j = token_value; break; }
997 if ((token_type == TRACE_KEYWORD_TT) && (token_value == ON_TK))
999 if ((token_type == TRACE_KEYWORD_TT) && (token_value == OFF_TK))
1001 put_token_back(); break;
1005 { case DICTIONARY_TK: show_dictionary(); break;
1006 case OBJECTS_TK: list_object_tree(); break;
1007 case SYMBOLS_TK: list_symbols(j); break;
1008 case VERBS_TK: list_verb_table(); break;
1013 trace_keywords.enabled = FALSE;
1016 /* --------------------------------------------------------------------- */
1018 /* --------------------------------------------------------------------- */
1022 if (token_type != SYMBOL_TT)
1023 return ebf_error_recover("symbol name", token_text);
1025 if (sflags[token_value] & UNKNOWN_SFLAG)
1026 { break; /* undef'ing an undefined constant is okay */
1029 if (stypes[token_value] != CONSTANT_T)
1030 { error_named("Cannot Undef a symbol which is not a defined constant:", (char *)symbs[token_value]);
1034 if (debugfile_switch)
1035 { write_debug_undef(token_value);
1037 end_symbol_scope(token_value);
1038 sflags[token_value] |= USED_SFLAG;
1041 /* --------------------------------------------------------------------- */
1043 /* --------------------------------------------------------------------- */
1045 case VERB_CODE: make_verb(); return FALSE; /* see "tables.c" */
1047 /* --------------------------------------------------------------------- */
1048 /* Version <number> */
1049 /* --------------------------------------------------------------------- */
1053 { assembly_operand AO;
1054 AO = parse_expression(CONSTANT_CONTEXT);
1055 /* If a version has already been set on the command line,
1056 that overrides this. */
1057 if (version_set_switch)
1059 warning("The Version directive was overridden by a command-line argument.");
1063 if (module_switch && (AO.marker != 0))
1064 error("A definite value must be given as version number");
1068 warning("The Version directive does not work in Glulx. Use \
1069 -vX.Y.Z instead, as either a command-line argument or a header comment.");
1075 { error("The version number must be in the range 3 to 8");
1081 break; /* see "inform.c" */
1083 /* --------------------------------------------------------------------- */
1084 /* Zcharacter table <num> ... */
1085 /* Zcharacter table + <num> ... */
1086 /* Zcharacter <string> <string> <string> */
1087 /* Zcharacter <char> */
1088 /* --------------------------------------------------------------------- */
1090 case ZCHARACTER_CODE:
1093 error("The Zcharacter directive has no meaning in Glulx.");
1094 panic_mode_error_recovery(); return FALSE;
1097 directive_keywords.enabled = TRUE;
1099 directive_keywords.enabled = FALSE;
1103 new_alphabet(token_text, 0);
1105 if (token_type != DQ_TT)
1106 return ebf_error_recover("double-quoted alphabet string", token_text);
1107 new_alphabet(token_text, 1);
1109 if (token_type != DQ_TT)
1110 return ebf_error_recover("double-quoted alphabet string", token_text);
1111 new_alphabet(token_text, 2);
1115 map_new_zchar(text_to_unicode(token_text));
1116 if (token_text[textual_form_length] != 0)
1117 return ebf_error_recover("single character value", token_text);
1120 case DIR_KEYWORD_TT:
1123 { int plus_flag = FALSE;
1125 if ((token_type == SEP_TT) && (token_value == PLUS_SEP))
1129 while ((token_type!=SEP_TT) || (token_value!=SEMICOLON_SEP))
1130 { switch(token_type)
1132 new_zscii_character(token_value, plus_flag);
1133 plus_flag = TRUE; break;
1135 new_zscii_character(text_to_unicode(token_text),
1137 if (token_text[textual_form_length] != 0)
1138 return ebf_error_recover("single character value",
1143 return ebf_error_recover("character or Unicode number",
1148 if (plus_flag) new_zscii_finished();
1152 case TERMINATING_DK:
1154 while ((token_type!=SEP_TT) || (token_value!=SEMICOLON_SEP))
1155 { switch(token_type)
1157 terminating_characters[no_termcs++]
1161 return ebf_error_recover("ZSCII number",
1169 return ebf_error_recover("'table', 'terminating', \
1170 a string or a constant",
1175 return ebf_error_recover("three alphabet strings, \
1176 a 'table' or 'terminating' command or a single character", token_text);
1180 /* ===================================================================== */
1184 /* We are now at the end of a syntactically valid directive. It
1185 should be terminated by a semicolon. */
1188 if ((token_type != SEP_TT) || (token_value != SEMICOLON_SEP))
1189 { ebf_error("';'", token_text);
1190 /* Put the non-semicolon back. We will continue parsing from
1191 that point, in hope that it's the start of a new directive.
1192 (This recovers cleanly from a missing semicolon at the end
1193 of a directive. It's not so clean if the directive *does*
1194 end with a semicolon, but there's extra garbage before it.) */
1200 /* ========================================================================= */
1201 /* Data structure management routines */
1202 /* ------------------------------------------------------------------------- */
1204 extern void init_directs_vars(void)
1208 extern void directs_begin_pass(void)
1210 no_named_routines = 0;
1213 constant_made_yet = FALSE;
1217 extern void directs_allocate_arrays(void)
1221 extern void directs_free_arrays(void)
1225 /* ========================================================================= */