1 /* ------------------------------------------------------------------------- */
2 /* "directs" : Directives (# commands) */
4 /* Part of Inform 6.35 */
5 /* copyright (c) Graham Nelson 1993 - 2020 */
7 /* Inform is free software: you can redistribute it and/or modify */
8 /* it under the terms of the GNU General Public License as published by */
9 /* the Free Software Foundation, either version 3 of the License, or */
10 /* (at your option) any later version. */
12 /* Inform is distributed in the hope that it will be useful, */
13 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
14 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
15 /* GNU General Public License for more details. */
17 /* You should have received a copy of the GNU General Public License */
18 /* along with Inform. If not, see https://gnu.org/licenses/ */
20 /* ------------------------------------------------------------------------- */
24 int no_routines, /* Number of routines compiled so far */
25 no_named_routines, /* Number not embedded in objects */
26 no_locals, /* Number of locals in current routine */
27 no_termcs; /* Number of terminating characters */
28 int terminating_characters[32];
30 brief_location routine_starts_line; /* Source code location where the current
31 routine starts. (Useful for reporting
32 "unused variable" warnings on the start
33 line rather than the end line.) */
35 static int constant_made_yet; /* Have any constants been defined yet? */
37 static int ifdef_stack[32], ifdef_sp;
39 /* ------------------------------------------------------------------------- */
41 static int ebf_error_recover(char *s1, char *s2)
43 /* Display an "expected... but found..." error, then skim forward
44 to the next semicolon and return FALSE. This is such a common
45 case in parse_given_directive() that it's worth a utility
46 function. You will see many error paths that look like:
47 return ebf_error_recover(...);
50 panic_mode_error_recovery();
54 static int ebf_symbol_error_recover(char *s1, char *name, char *type, brief_location report_line)
56 /* Same for ebf_symbol_error(). */
57 ebf_symbol_error(s1, name, type, report_line);
58 panic_mode_error_recovery();
62 /* ------------------------------------------------------------------------- */
64 extern int parse_given_directive(int internal_flag)
65 { /* Internal_flag is FALSE if the directive is encountered normally,
66 TRUE if encountered with a # prefix inside a routine or object
69 Returns: FALSE if program continues, TRUE if end of file reached. */
71 int *trace_level = NULL; int32 i, j, k, n, flag;
72 const char *constant_name;
73 debug_location_beginning beginning_debug_location;
77 /* Only certain directives, such as #ifdef, are permitted within
78 a routine or object definition. In older versions of Inform,
79 nearly any directive was accepted, but this was -- to quote
80 an old code comment -- "about as well-supported as Wile E.
81 Coyote one beat before the plummet-lines kick in." */
83 if (token_value != IFV3_CODE && token_value != IFV5_CODE
84 && token_value != IFDEF_CODE && token_value != IFNDEF_CODE
85 && token_value != IFTRUE_CODE && token_value != IFFALSE_CODE
86 && token_value != IFNOT_CODE && token_value != ENDIF_CODE
87 && token_value != MESSAGE_CODE && token_value != ORIGSOURCE_CODE
88 && token_value != TRACE_CODE) {
89 char *dirname = directives.keywords[token_value];
90 error_named("Cannot nest this directive inside a routine or object:", dirname);
91 panic_mode_error_recovery(); return FALSE;
98 /* --------------------------------------------------------------------- */
99 /* Abbreviate "string1" ["string2" ...] */
100 /* --------------------------------------------------------------------- */
102 case ABBREVIATE_CODE:
106 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
109 /* Z-code has a 64-abbrev limit; Glulx doesn't. */
110 if (!glulx_mode && no_abbreviations==64)
111 { error("All 64 abbreviations already declared");
112 panic_mode_error_recovery(); return FALSE;
114 if (no_abbreviations==MAX_ABBREVS)
115 memoryerror("MAX_ABBREVS", MAX_ABBREVS);
117 if (abbrevs_lookup_table_made)
118 { error("All abbreviations must be declared together");
119 panic_mode_error_recovery(); return FALSE;
121 if (token_type != DQ_TT)
122 return ebf_error_recover("abbreviation string", token_text);
123 if (strlen(token_text)<2)
124 { error_named("It's not worth abbreviating", token_text);
127 /* Abbreviation string with null must fit in a MAX_ABBREV_LENGTH
129 if (strlen(token_text)>=MAX_ABBREV_LENGTH)
130 { error_named("Abbreviation too long", token_text);
133 make_abbreviation(token_text);
136 /* --------------------------------------------------------------------- */
137 /* Array arrayname array... */
138 /* --------------------------------------------------------------------- */
140 case ARRAY_CODE: make_global(TRUE, FALSE); break; /* See "tables.c" */
142 /* --------------------------------------------------------------------- */
143 /* Attribute newname [alias oldname] */
144 /* --------------------------------------------------------------------- */
147 make_attribute(); break; /* See "objects.c" */
149 /* --------------------------------------------------------------------- */
150 /* Class classname ... */
151 /* --------------------------------------------------------------------- */
154 make_class(NULL); /* See "objects.c" */
157 /* --------------------------------------------------------------------- */
158 /* Constant newname [[=] value] [, ...] */
159 /* --------------------------------------------------------------------- */
162 constant_made_yet=TRUE;
165 get_next_token(); i = token_value;
166 beginning_debug_location = get_token_location_beginning();
168 if (token_type != SYMBOL_TT)
169 { discard_token_location(beginning_debug_location);
170 return ebf_error_recover("new constant name", token_text);
173 if (!(sflags[i] & (UNKNOWN_SFLAG + REDEFINABLE_SFLAG)))
174 { discard_token_location(beginning_debug_location);
175 return ebf_symbol_error_recover("new constant name", token_text, typename(stypes[i]), slines[i]);
178 assign_symbol(i, 0, CONSTANT_T);
179 constant_name = token_text;
183 if ((token_type == SEP_TT) && (token_value == COMMA_SEP))
184 { if (debugfile_switch && !(sflags[i] & REDEFINABLE_SFLAG))
185 { debug_file_printf("<constant>");
186 debug_file_printf("<identifier>%s</identifier>", constant_name);
187 write_debug_symbol_optional_backpatch(i);
188 write_debug_locations(get_token_location_end(beginning_debug_location));
189 debug_file_printf("</constant>");
191 goto ParseConstantSpec;
194 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
195 { if (debugfile_switch && !(sflags[i] & REDEFINABLE_SFLAG))
196 { debug_file_printf("<constant>");
197 debug_file_printf("<identifier>%s</identifier>", constant_name);
198 write_debug_symbol_optional_backpatch(i);
199 write_debug_locations(get_token_location_end(beginning_debug_location));
200 debug_file_printf("</constant>");
205 if (!((token_type == SEP_TT) && (token_value == SETEQUALS_SEP)))
208 { assembly_operand AO = parse_expression(CONSTANT_CONTEXT);
210 { assign_marked_symbol(i, AO.marker, AO.value,
212 sflags[i] |= CHANGE_SFLAG;
213 if (i == grammar_version_symbol)
215 "Grammar__Version must be given an explicit constant value");
218 { assign_symbol(i, AO.value, CONSTANT_T);
219 if (i == grammar_version_symbol)
220 { if ((grammar_version_number != AO.value)
221 && (no_fake_actions > 0))
223 "Once a fake action has been defined it is too late to \
224 change the grammar version. (If you are using the library, move any \
225 Fake_Action directives to a point after the inclusion of \"Parser\".)");
226 grammar_version_number = AO.value;
231 if (debugfile_switch && !(sflags[i] & REDEFINABLE_SFLAG))
232 { debug_file_printf("<constant>");
233 debug_file_printf("<identifier>%s</identifier>", constant_name);
234 write_debug_symbol_optional_backpatch(i);
235 write_debug_locations
236 (get_token_location_end(beginning_debug_location));
237 debug_file_printf("</constant>");
241 if ((token_type == SEP_TT) && (token_value == COMMA_SEP))
242 goto ParseConstantSpec;
246 /* --------------------------------------------------------------------- */
247 /* Default constantname integer */
248 /* --------------------------------------------------------------------- */
252 { error("'Default' cannot be used in -M (Module) mode");
253 panic_mode_error_recovery(); return FALSE;
257 if (token_type != SYMBOL_TT)
258 return ebf_error_recover("name", token_text);
261 if (sflags[token_value] & UNKNOWN_SFLAG)
263 sflags[i] |= DEFCON_SFLAG;
267 if (!((token_type == SEP_TT) && (token_value == SETEQUALS_SEP)))
270 { assembly_operand AO;
271 AO = parse_expression(CONSTANT_CONTEXT);
273 { if (AO.marker != 0)
274 { assign_marked_symbol(i, AO.marker, AO.value,
276 sflags[i] |= CHANGE_SFLAG;
278 else assign_symbol(i, AO.value, CONSTANT_T);
284 /* --------------------------------------------------------------------- */
285 /* Dictionary 'word' */
286 /* Dictionary 'word' val1 */
287 /* Dictionary 'word' val1 val3 */
288 /* --------------------------------------------------------------------- */
290 case DICTIONARY_CODE:
291 /* In Inform 5, this directive had the form
292 Dictionary SYMBOL "word";
293 This was deprecated as of I6 (if not earlier), and is no longer
294 supported at all. The current form just creates a dictionary word,
295 with the given values for dict_par1 and dict_par3. If the word
296 already exists, the values are bit-or'd in with the existing
298 (We don't offer a way to set dict_par2, because that is entirely
299 reserved for the verb number. Or'ing values into it would create
303 if (token_type != SQ_TT && token_type != DQ_TT)
304 return ebf_error_recover("dictionary word", token_text);
307 char *wd = token_text;
312 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) {
318 AO = parse_expression(CONSTANT_CONTEXT);
319 if (module_switch && (AO.marker != 0))
320 error("A definite value must be given as a Dictionary flag");
325 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)) {
331 AO = parse_expression(CONSTANT_CONTEXT);
332 if (module_switch && (AO.marker != 0))
333 error("A definite value must be given as a Dictionary flag");
340 if ((val1 & ~0xFF) || (val3 & ~0xFF)) {
341 warning("Dictionary flag values cannot exceed $FF in Z-code");
345 if ((val1 & ~0xFFFF) || (val3 & ~0xFFFF)) {
346 warning("Dictionary flag values cannot exceed $FFFF in Glulx");
350 dictionary_add(wd, val1, 0, val3);
354 /* --------------------------------------------------------------------- */
356 /* --------------------------------------------------------------------- */
358 case END_CODE: return(TRUE);
361 if (ifdef_sp == 0) error("'Endif' without matching 'If...'");
365 /* --------------------------------------------------------------------- */
367 /* --------------------------------------------------------------------- */
369 case EXTEND_CODE: extend_verb(); return FALSE; /* see "tables.c" */
371 /* --------------------------------------------------------------------- */
372 /* Fake_Action name */
373 /* --------------------------------------------------------------------- */
375 case FAKE_ACTION_CODE:
376 make_fake_action(); break; /* see "verbs.c" */
378 /* --------------------------------------------------------------------- */
379 /* Global variable [= value / array...] */
380 /* --------------------------------------------------------------------- */
382 case GLOBAL_CODE: make_global(FALSE, FALSE); break; /* See "tables.c" */
384 /* --------------------------------------------------------------------- */
387 /* Note that each time Inform tests an If... condition, it stacks the */
388 /* result (TRUE or FALSE) on ifdef_stack: thus, the top of this stack */
389 /* reveals what clause of the current If... is being compiled: */
391 /* If...; ... Ifnot; ... Endif; */
392 /* top of stack: TRUE FALSE */
394 /* This is used to detect "two Ifnots in same If" errors. */
395 /* --------------------------------------------------------------------- */
405 if (token_type != SYMBOL_TT)
406 return ebf_error_recover("symbol name", token_text);
408 if ((token_text[0] == 'V')
409 && (token_text[1] == 'N')
410 && (token_text[2] == '_')
411 && (strlen(token_text)==7))
412 { i = atoi(token_text+3);
413 if (VNUMBER < i) flag = (flag)?FALSE:TRUE;
414 goto HashIfCondition;
417 if (sflags[token_value] & UNKNOWN_SFLAG) flag = (flag)?FALSE:TRUE;
418 else sflags[token_value] |= USED_SFLAG;
419 goto HashIfCondition;
423 error("'Ifnot' without matching 'If...'");
425 if (!(ifdef_stack[ifdef_sp-1]))
426 error("Second 'Ifnot' for the same 'If...' condition");
428 { dont_enter_into_symbol_table = -2; n = 1;
429 directives.enabled = TRUE;
432 if (token_type == EOF_TT)
433 { error("End of file reached in code 'If...'d out");
434 directives.enabled = FALSE;
437 if (token_type == DIRECTIVE_TT)
438 { switch(token_value)
451 "Second 'Ifnot' for the same 'If...' condition");
458 dont_enter_into_symbol_table = FALSE;
459 directives.enabled = FALSE;
465 if (!glulx_mode && version_number <= 3) flag = TRUE;
466 goto HashIfCondition;
470 if (!glulx_mode && version_number <= 3) flag = FALSE;
471 goto HashIfCondition;
474 { assembly_operand AO;
475 AO = parse_expression(CONSTANT_CONTEXT);
476 if (module_switch && (AO.marker != 0))
477 { error("This condition can't be determined");
480 else flag = (AO.value != 0);
482 goto HashIfCondition;
485 { assembly_operand AO;
486 AO = parse_expression(CONSTANT_CONTEXT);
487 if (module_switch && (AO.marker != 0))
488 { error("This condition can't be determined");
491 else flag = (AO.value == 0);
493 goto HashIfCondition;
497 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)))
498 return ebf_error_recover("semicolon after 'If...' condition", token_text);
501 { ifdef_stack[ifdef_sp++] = TRUE; return FALSE; }
503 { dont_enter_into_symbol_table = -2; n = 1;
504 directives.enabled = TRUE;
507 if (token_type == EOF_TT)
508 { error("End of file reached in code 'If...'d out");
509 directives.enabled = FALSE;
512 if (token_type == DIRECTIVE_TT)
526 { ifdef_stack[ifdef_sp++] = FALSE;
532 directives.enabled = FALSE;
533 dont_enter_into_symbol_table = FALSE;
537 /* --------------------------------------------------------------------- */
538 /* Import global <varname> [, ...] */
540 /* (Further imported goods may be allowed later.) */
541 /* --------------------------------------------------------------------- */
545 { error("'Import' can only be used in -M (Module) mode");
546 panic_mode_error_recovery(); return FALSE;
548 directives.enabled = TRUE;
551 if ((token_type == DIRECTIVE_TT) && (token_value == GLOBAL_CODE))
552 make_global(FALSE, TRUE);
553 else error_named("'Import' cannot import things of this type:",
556 } while ((token_type == SEP_TT) && (token_value == COMMA_SEP));
558 directives.enabled = FALSE;
561 /* --------------------------------------------------------------------- */
562 /* Include "[>]filename" */
564 /* The ">" character means to load the file from the same directory as */
565 /* the current file, instead of relying on the include path. */
566 /* --------------------------------------------------------------------- */
570 if (token_type != DQ_TT)
571 return ebf_error_recover("filename in double-quotes", token_text);
573 { char *name = token_text;
576 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)))
577 ebf_error("semicolon ';' after Include filename", token_text);
579 if (strcmp(name, "language__") == 0)
580 load_sourcefile(Language_Name, 0);
581 else if (name[0] == '>')
582 load_sourcefile(name+1, 1);
583 else load_sourcefile(name, 0);
587 /* --------------------------------------------------------------------- */
588 /* Link "filename" */
589 /* --------------------------------------------------------------------- */
593 if (token_type != DQ_TT)
594 return ebf_error_recover("filename in double-quotes", token_text);
595 link_module(token_text); /* See "linker.c" */
598 /* --------------------------------------------------------------------- */
599 /* Lowstring constantname "text of string" */
600 /* --------------------------------------------------------------------- */
601 /* Unlike most constant creations, these do not require backpatching: */
602 /* the low strings always occupy a table at a fixed offset in the */
603 /* Z-machine (after the abbreviations table has finished, at 0x100). */
604 /* --------------------------------------------------------------------- */
608 { error("'LowString' cannot be used in -M (Module) mode");
609 panic_mode_error_recovery(); return FALSE;
611 get_next_token(); i = token_value;
612 if (token_type != SYMBOL_TT)
613 return ebf_error_recover("new low string name", token_text);
614 if (!(sflags[i] & UNKNOWN_SFLAG))
615 return ebf_symbol_error_recover("new low string name", token_text, typename(stypes[i]), slines[i]);
618 if (token_type != DQ_TT)
619 return ebf_error_recover("literal string in double-quotes", token_text);
621 assign_symbol(i, compile_string(token_text, TRUE, TRUE), CONSTANT_T);
624 /* --------------------------------------------------------------------- */
625 /* Message | "information" */
626 /* | error "error message" */
627 /* | fatalerror "fatal error message" */
628 /* | warning "warning message" */
629 /* --------------------------------------------------------------------- */
632 directive_keywords.enabled = TRUE;
634 directive_keywords.enabled = FALSE;
635 if (token_type == DQ_TT)
637 if (hash_printed_since_newline) printf("\n");
638 for (i=0; token_text[i]!=0; i++)
639 { if (token_text[i] == '^') printf("\n");
641 if (token_text[i] == '~') printf("\"");
642 else printf("%c", token_text[i]);
647 if ((token_type == DIR_KEYWORD_TT) && (token_value == ERROR_DK))
649 if (token_type != DQ_TT)
650 { return ebf_error_recover("error message in double-quotes", token_text);
652 error(token_text); break;
654 if ((token_type == DIR_KEYWORD_TT) && (token_value == FATALERROR_DK))
656 if (token_type != DQ_TT)
657 { return ebf_error_recover("fatal error message in double-quotes", token_text);
659 fatalerror(token_text); break;
661 if ((token_type == DIR_KEYWORD_TT) && (token_value == WARNING_DK))
663 if (token_type != DQ_TT)
664 { return ebf_error_recover("warning message in double-quotes", token_text);
666 warning(token_text); break;
668 return ebf_error_recover("a message in double-quotes, 'error', 'fatalerror' or 'warning'",
672 /* --------------------------------------------------------------------- */
673 /* Nearby objname "short name" ... */
674 /* --------------------------------------------------------------------- */
677 make_object(TRUE, NULL, -1, -1, -1);
678 return FALSE; /* See "objects.c" */
680 /* --------------------------------------------------------------------- */
681 /* Object objname "short name" ... */
682 /* --------------------------------------------------------------------- */
685 make_object(FALSE, NULL, -1, -1, -1);
686 return FALSE; /* See "objects.c" */
688 /* --------------------------------------------------------------------- */
689 /* Origsource <file> */
690 /* Origsource <file> <line> */
691 /* Origsource <file> <line> <char> */
694 /* The first three forms declare that all following lines are derived */
695 /* from the named Inform 7 source file (with an optional line number */
696 /* and character number). This will be reported in error messages and */
697 /* in debug output. The declaration holds through the next Origsource */
698 /* directive (but does not apply to included files). */
700 /* The fourth form, with no arguments, clears the declaration. */
702 /* Unlike the Include directive, Origsource does not open the named */
703 /* file or even verify that it exists. The filename is treated as an */
705 /* --------------------------------------------------------------------- */
707 case ORIGSOURCE_CODE:
709 char *origsource_file = NULL;
710 int32 origsource_line = 0;
711 int32 origsource_char = 0;
713 /* Parse some optional tokens followed by a mandatory semicolon. */
716 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))) {
717 if (token_type != DQ_TT) {
718 return ebf_error_recover("a file name in double-quotes",
721 origsource_file = token_text;
724 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))) {
725 if (token_type != NUMBER_TT) {
726 return ebf_error_recover("a file line number",
729 origsource_line = token_value;
730 if (origsource_line < 0)
734 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))) {
735 if (token_type != NUMBER_TT) {
736 return ebf_error_recover("a file line number",
739 origsource_char = token_value;
740 if (origsource_char < 0)
750 set_origsource_location(origsource_file, origsource_line, origsource_char);
754 /* --------------------------------------------------------------------- */
755 /* Property [long] [additive] name [alias oldname] */
756 /* --------------------------------------------------------------------- */
758 case PROPERTY_CODE: make_property(); break; /* See "objects.c" */
760 /* --------------------------------------------------------------------- */
761 /* Release <number> */
762 /* --------------------------------------------------------------------- */
765 { assembly_operand AO;
766 AO = parse_expression(CONSTANT_CONTEXT);
767 if (module_switch && (AO.marker != 0))
768 error("A definite value must be given as release number");
770 release_number = AO.value;
774 /* --------------------------------------------------------------------- */
775 /* Replace routine [routinename] */
776 /* --------------------------------------------------------------------- */
779 /* You can also replace system functions normally implemented in */
780 /* the "hardware" of the Z-machine, like "random()": */
782 system_functions.enabled = TRUE;
783 directives.enabled = FALSE;
784 directive_keywords.enabled = FALSE;
786 /* Don't count the upcoming symbol as a top-level reference
787 *to* the function. */
788 df_dont_note_global_symbols = TRUE;
790 df_dont_note_global_symbols = FALSE;
791 if (token_type == SYSFUN_TT)
792 { if (system_function_usage[token_value] == 1)
793 error("You can't 'Replace' a system function already used");
794 else system_function_usage[token_value] = 2;
796 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)))
798 error("You can't give a 'Replace'd system function a new name");
799 panic_mode_error_recovery(); return FALSE;
804 if (token_type != SYMBOL_TT)
805 return ebf_error_recover("name of routine to replace", token_text);
806 if (!(sflags[token_value] & UNKNOWN_SFLAG))
807 return ebf_error_recover("name of routine not yet defined", token_text);
809 sflags[token_value] |= REPLACE_SFLAG;
811 /* If a second symbol is provided, it will refer to the
812 original (replaced) definition of the routine. */
815 system_functions.enabled = FALSE;
816 df_dont_note_global_symbols = TRUE;
818 df_dont_note_global_symbols = FALSE;
819 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
823 if (token_type != SYMBOL_TT || !(sflags[token_value] & UNKNOWN_SFLAG))
824 return ebf_error_recover("semicolon ';' or new routine name", token_text);
826 /* Define the original-form symbol as a zero constant. Its
827 value will be overwritten later, when we define the
829 assign_symbol(token_value, 0, CONSTANT_T);
830 add_symbol_replacement_mapping(i, token_value);
834 /* --------------------------------------------------------------------- */
835 /* Serial "yymmdd" */
836 /* --------------------------------------------------------------------- */
840 if ((token_type != DQ_TT) || (strlen(token_text)!=6))
841 { error("The serial number must be a 6-digit date in double-quotes");
842 panic_mode_error_recovery(); return FALSE;
844 for (i=0; i<6; i++) if (isdigit(token_text[i])==0)
845 { error("The serial number must be a 6-digit date in double-quotes");
846 panic_mode_error_recovery(); return FALSE;
848 strcpy(serial_code_buffer, token_text);
849 serial_code_given_in_program = TRUE;
852 /* --------------------------------------------------------------------- */
853 /* Statusline score/time */
854 /* --------------------------------------------------------------------- */
856 case STATUSLINE_CODE:
858 warning("This does not set the final game's statusline");
860 directive_keywords.enabled = TRUE;
862 directive_keywords.enabled = FALSE;
863 if ((token_type != DIR_KEYWORD_TT)
864 || ((token_value != SCORE_DK) && (token_value != TIME_DK)))
865 return ebf_error_recover("'score' or 'time' after 'statusline'", token_text);
866 if (token_value == SCORE_DK) statusline_flag = SCORE_STYLE;
867 else statusline_flag = TIME_STYLE;
870 /* --------------------------------------------------------------------- */
871 /* Stub routinename number-of-locals */
872 /* --------------------------------------------------------------------- */
875 /* The upcoming symbol is a definition; don't count it as a
876 top-level reference *to* the stub function. */
877 df_dont_note_global_symbols = TRUE;
879 df_dont_note_global_symbols = FALSE;
880 if (token_type != SYMBOL_TT)
881 return ebf_error_recover("routine name to stub", token_text);
883 i = token_value; flag = FALSE;
885 if (sflags[i] & UNKNOWN_SFLAG)
886 { sflags[i] |= STUB_SFLAG;
890 get_next_token(); k = token_value;
891 if (token_type != NUMBER_TT)
892 return ebf_error_recover("number of local variables", token_text);
894 { error("Must specify 0 to 4 local variables for 'Stub' routine");
900 /* Give these parameter-receiving local variables names
901 for the benefit of the debugging information file,
902 and for assembly tracing to look sensible. */
904 local_variable_texts[0] = "dummy1";
905 local_variable_texts[1] = "dummy2";
906 local_variable_texts[2] = "dummy3";
907 local_variable_texts[3] = "dummy4";
910 assemble_routine_header(k, FALSE, (char *) symbs[i], FALSE, i),
913 /* Ensure the return value of a stubbed routine is false,
914 since this is necessary to make the library work properly */
917 assemblez_0(rfalse_zc);
919 assembleg_1(return_gc, zero_operand);
921 /* Inhibit "local variable unused" warnings */
923 for (i=1; i<=k; i++) variable_usage[i] = 1;
924 sequence_point_follows = FALSE;
925 assemble_routine_end(FALSE, get_token_locations());
929 /* --------------------------------------------------------------------- */
930 /* Switches switchblock */
931 /* (this directive is ignored if the -i switch was set at command line) */
932 /* --------------------------------------------------------------------- */
935 dont_enter_into_symbol_table = TRUE;
937 dont_enter_into_symbol_table = FALSE;
938 if (token_type != DQ_TT)
939 return ebf_error_recover("string of switches", token_text);
940 if (!ignore_switches_switch)
941 { if (constant_made_yet)
942 error("A 'Switches' directive must must come before \
943 the first constant definition");
944 switches(token_text, 0); /* see "inform.c" */
948 /* --------------------------------------------------------------------- */
951 /* Some files are declared as "system files": this information is used */
952 /* by Inform only to skip the definition of a routine X if the designer */
953 /* has indicated his intention to Replace X. */
954 /* --------------------------------------------------------------------- */
957 declare_systemfile(); break; /* see "files.c" */
959 /* --------------------------------------------------------------------- */
960 /* Trace dictionary */
965 /* assembly [on/off] */
966 /* expressions [on/off] */
968 /* --------------------------------------------------------------------- */
971 directives.enabled = FALSE;
972 trace_keywords.enabled = TRUE;
974 trace_keywords.enabled = FALSE;
975 directives.enabled = TRUE;
976 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
977 { asm_trace_level = 1; return FALSE; }
979 if (token_type != TRACE_KEYWORD_TT)
980 return ebf_error_recover("debugging keyword", token_text);
982 trace_keywords.enabled = TRUE;
984 i = token_value; j = 0;
986 { case DICTIONARY_TK: break;
987 case OBJECTS_TK: break;
988 case VERBS_TK: break;
992 trace_level = &asm_trace_level; break;
994 trace_level = &expr_trace_level; break;
996 trace_level = &line_trace_level; break;
998 trace_level = &tokens_trace_level; break;
1000 trace_level = &linker_trace_level; break;
1002 trace_level = NULL; break;
1005 trace_level = &asm_trace_level; break;
1009 if ((token_type == SEP_TT) &&
1010 (token_value == SEMICOLON_SEP))
1011 { put_token_back(); break;
1013 if (token_type == NUMBER_TT)
1014 { j = token_value; break; }
1015 if ((token_type == TRACE_KEYWORD_TT) && (token_value == ON_TK))
1017 if ((token_type == TRACE_KEYWORD_TT) && (token_value == OFF_TK))
1019 put_token_back(); break;
1023 { case DICTIONARY_TK: show_dictionary(); break;
1024 case OBJECTS_TK: list_object_tree(); break;
1025 case SYMBOLS_TK: list_symbols(j); break;
1026 case VERBS_TK: list_verb_table(); break;
1031 trace_keywords.enabled = FALSE;
1034 /* --------------------------------------------------------------------- */
1036 /* --------------------------------------------------------------------- */
1040 if (token_type != SYMBOL_TT)
1041 return ebf_error_recover("symbol name", token_text);
1043 if (sflags[token_value] & UNKNOWN_SFLAG)
1044 { break; /* undef'ing an undefined constant is okay */
1047 if (stypes[token_value] != CONSTANT_T)
1048 { error_named("Cannot Undef a symbol which is not a defined constant:", (char *)symbs[token_value]);
1052 if (debugfile_switch)
1053 { write_debug_undef(token_value);
1055 end_symbol_scope(token_value);
1056 sflags[token_value] |= USED_SFLAG;
1059 /* --------------------------------------------------------------------- */
1061 /* --------------------------------------------------------------------- */
1063 case VERB_CODE: make_verb(); return FALSE; /* see "tables.c" */
1065 /* --------------------------------------------------------------------- */
1066 /* Version <number> */
1067 /* --------------------------------------------------------------------- */
1071 { assembly_operand AO;
1072 AO = parse_expression(CONSTANT_CONTEXT);
1073 /* If a version has already been set on the command line,
1074 that overrides this. */
1075 if (version_set_switch)
1077 warning("The Version directive was overridden by a command-line argument.");
1081 if (module_switch && (AO.marker != 0))
1082 error("A definite value must be given as version number");
1086 warning("The Version directive does not work in Glulx. Use \
1087 -vX.Y.Z instead, as either a command-line argument or a header comment.");
1093 { error("The version number must be in the range 3 to 8");
1099 break; /* see "inform.c" */
1101 /* --------------------------------------------------------------------- */
1102 /* Zcharacter table <num> ... */
1103 /* Zcharacter table + <num> ... */
1104 /* Zcharacter <string> <string> <string> */
1105 /* Zcharacter <char> */
1106 /* --------------------------------------------------------------------- */
1108 case ZCHARACTER_CODE:
1111 error("The Zcharacter directive has no meaning in Glulx.");
1112 panic_mode_error_recovery(); return FALSE;
1115 directive_keywords.enabled = TRUE;
1117 directive_keywords.enabled = FALSE;
1121 new_alphabet(token_text, 0);
1123 if (token_type != DQ_TT)
1124 return ebf_error_recover("double-quoted alphabet string", token_text);
1125 new_alphabet(token_text, 1);
1127 if (token_type != DQ_TT)
1128 return ebf_error_recover("double-quoted alphabet string", token_text);
1129 new_alphabet(token_text, 2);
1133 map_new_zchar(text_to_unicode(token_text));
1134 if (token_text[textual_form_length] != 0)
1135 return ebf_error_recover("single character value", token_text);
1138 case DIR_KEYWORD_TT:
1141 { int plus_flag = FALSE;
1143 if ((token_type == SEP_TT) && (token_value == PLUS_SEP))
1147 while ((token_type!=SEP_TT) || (token_value!=SEMICOLON_SEP))
1148 { switch(token_type)
1150 new_zscii_character(token_value, plus_flag);
1151 plus_flag = TRUE; break;
1153 new_zscii_character(text_to_unicode(token_text),
1155 if (token_text[textual_form_length] != 0)
1156 return ebf_error_recover("single character value",
1161 return ebf_error_recover("character or Unicode number",
1166 if (plus_flag) new_zscii_finished();
1170 case TERMINATING_DK:
1172 while ((token_type!=SEP_TT) || (token_value!=SEMICOLON_SEP))
1173 { switch(token_type)
1175 terminating_characters[no_termcs++]
1179 return ebf_error_recover("ZSCII number",
1187 return ebf_error_recover("'table', 'terminating', \
1188 a string or a constant",
1193 return ebf_error_recover("three alphabet strings, \
1194 a 'table' or 'terminating' command or a single character", token_text);
1198 /* ===================================================================== */
1202 /* We are now at the end of a syntactically valid directive. It
1203 should be terminated by a semicolon. */
1206 if ((token_type != SEP_TT) || (token_value != SEMICOLON_SEP))
1207 { ebf_error("';'", token_text);
1208 /* Put the non-semicolon back. We will continue parsing from
1209 that point, in hope that it's the start of a new directive.
1210 (This recovers cleanly from a missing semicolon at the end
1211 of a directive. It's not so clean if the directive *does*
1212 end with a semicolon, but there's extra garbage before it.) */
1218 /* ========================================================================= */
1219 /* Data structure management routines */
1220 /* ------------------------------------------------------------------------- */
1222 extern void init_directs_vars(void)
1226 extern void directs_begin_pass(void)
1228 no_named_routines = 0;
1231 constant_made_yet = FALSE;
1235 extern void directs_allocate_arrays(void)
1239 extern void directs_free_arrays(void)
1243 /* ========================================================================= */