1 /* ------------------------------------------------------------------------- */
2 /* "directs" : Directives (# commands) */
4 /* Copyright (c) Graham Nelson 1993 - 2016 */
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 int32 routine_starts_line; /* Source code line on which 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 /* Property [long] [additive] name [alias oldname] */
667 /* --------------------------------------------------------------------- */
669 case PROPERTY_CODE: make_property(); break; /* See "objects.c" */
671 /* --------------------------------------------------------------------- */
672 /* Release <number> */
673 /* --------------------------------------------------------------------- */
676 { assembly_operand AO;
677 AO = parse_expression(CONSTANT_CONTEXT);
678 if (module_switch && (AO.marker != 0))
679 error("A definite value must be given as release number");
681 release_number = AO.value;
685 /* --------------------------------------------------------------------- */
686 /* Replace routine [routinename] */
687 /* --------------------------------------------------------------------- */
690 /* You can also replace system functions normally implemented in */
691 /* the "hardware" of the Z-machine, like "random()": */
693 system_functions.enabled = TRUE;
694 directives.enabled = FALSE;
695 directive_keywords.enabled = FALSE;
697 /* Don't count the upcoming symbol as a top-level reference
698 *to* the function. */
699 df_dont_note_global_symbols = TRUE;
701 df_dont_note_global_symbols = FALSE;
702 if (token_type == SYSFUN_TT)
703 { if (system_function_usage[token_value] == 1)
704 error("You can't 'Replace' a system function already used");
705 else system_function_usage[token_value] = 2;
707 if (!((token_type == SEP_TT) && (token_value == SEMICOLON_SEP)))
709 error("You can't give a 'Replace'd system function a new name");
710 panic_mode_error_recovery(); return FALSE;
715 if (token_type != SYMBOL_TT)
716 return ebf_error_recover("name of routine to replace", token_text);
717 if (!(sflags[token_value] & UNKNOWN_SFLAG))
718 return ebf_error_recover("name of routine not yet defined", token_text);
720 sflags[token_value] |= REPLACE_SFLAG;
722 /* If a second symbol is provided, it will refer to the
723 original (replaced) definition of the routine. */
726 system_functions.enabled = FALSE;
727 df_dont_note_global_symbols = TRUE;
729 df_dont_note_global_symbols = FALSE;
730 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
734 if (token_type != SYMBOL_TT || !(sflags[token_value] & UNKNOWN_SFLAG))
735 return ebf_error_recover("semicolon ';' or new routine name", token_text);
737 /* Define the original-form symbol as a zero constant. Its
738 value will be overwritten later, when we define the
740 assign_symbol(token_value, 0, CONSTANT_T);
741 add_symbol_replacement_mapping(i, token_value);
745 /* --------------------------------------------------------------------- */
746 /* Serial "yymmdd" */
747 /* --------------------------------------------------------------------- */
751 if ((token_type != DQ_TT) || (strlen(token_text)!=6))
752 { error("The serial number must be a 6-digit date in double-quotes");
753 panic_mode_error_recovery(); return FALSE;
755 for (i=0; i<6; i++) if (isdigit(token_text[i])==0)
756 { error("The serial number must be a 6-digit date in double-quotes");
757 panic_mode_error_recovery(); return FALSE;
759 strcpy(serial_code_buffer, token_text);
760 serial_code_given_in_program = TRUE;
763 /* --------------------------------------------------------------------- */
764 /* Statusline score/time */
765 /* --------------------------------------------------------------------- */
767 case STATUSLINE_CODE:
769 warning("This does not set the final game's statusline");
771 directive_keywords.enabled = TRUE;
773 directive_keywords.enabled = FALSE;
774 if ((token_type != DIR_KEYWORD_TT)
775 || ((token_value != SCORE_DK) && (token_value != TIME_DK)))
776 return ebf_error_recover("'score' or 'time' after 'statusline'", token_text);
777 if (token_value == SCORE_DK) statusline_flag = SCORE_STYLE;
778 else statusline_flag = TIME_STYLE;
781 /* --------------------------------------------------------------------- */
782 /* Stub routinename number-of-locals */
783 /* --------------------------------------------------------------------- */
787 { error("Cannot nest #Stub inside a routine or object");
788 panic_mode_error_recovery(); return FALSE;
791 /* The upcoming symbol is a definition; don't count it as a
792 top-level reference *to* the stub function. */
793 df_dont_note_global_symbols = TRUE;
795 df_dont_note_global_symbols = FALSE;
796 if (token_type != SYMBOL_TT)
797 return ebf_error_recover("routine name to stub", token_text);
799 i = token_value; flag = FALSE;
801 if (sflags[i] & UNKNOWN_SFLAG)
802 { sflags[i] |= STUB_SFLAG;
806 get_next_token(); k = token_value;
807 if (token_type != NUMBER_TT)
808 return ebf_error_recover("number of local variables", token_text);
810 { error("Must specify 0 to 4 local variables for 'Stub' routine");
816 /* Give these parameter-receiving local variables names
817 for the benefit of the debugging information file,
818 and for assembly tracing to look sensible. */
820 local_variable_texts[0] = "dummy1";
821 local_variable_texts[1] = "dummy2";
822 local_variable_texts[2] = "dummy3";
823 local_variable_texts[3] = "dummy4";
826 assemble_routine_header(k, FALSE, (char *) symbs[i], FALSE, i),
829 /* Ensure the return value of a stubbed routine is false,
830 since this is necessary to make the library work properly */
833 assemblez_0(rfalse_zc);
835 assembleg_1(return_gc, zero_operand);
837 /* Inhibit "local variable unused" warnings */
839 for (i=1; i<=k; i++) variable_usage[i] = 1;
840 sequence_point_follows = FALSE;
841 assemble_routine_end(FALSE, get_token_locations());
845 /* --------------------------------------------------------------------- */
846 /* Switches switchblock */
847 /* (this directive is ignored if the -i switch was set at command line) */
848 /* --------------------------------------------------------------------- */
851 dont_enter_into_symbol_table = TRUE;
853 dont_enter_into_symbol_table = FALSE;
854 if (token_type != DQ_TT)
855 return ebf_error_recover("string of switches", token_text);
856 if (!ignore_switches_switch)
857 { if (constant_made_yet)
858 error("A 'Switches' directive must must come before \
859 the first constant definition");
860 switches(token_text, 0); /* see "inform.c" */
864 /* --------------------------------------------------------------------- */
867 /* Some files are declared as "system files": this information is used */
868 /* by Inform only to skip the definition of a routine X if the designer */
869 /* has indicated his intention to Replace X. */
870 /* --------------------------------------------------------------------- */
873 declare_systemfile(); break; /* see "files.c" */
875 /* --------------------------------------------------------------------- */
876 /* Trace dictionary */
881 /* assembly [on/off] */
882 /* expressions [on/off] */
884 /* --------------------------------------------------------------------- */
887 directives.enabled = FALSE;
888 trace_keywords.enabled = TRUE;
890 trace_keywords.enabled = FALSE;
891 directives.enabled = TRUE;
892 if ((token_type == SEP_TT) && (token_value == SEMICOLON_SEP))
893 { asm_trace_level = 1; return FALSE; }
895 if (token_type != TRACE_KEYWORD_TT)
896 return ebf_error_recover("debugging keyword", token_text);
898 trace_keywords.enabled = TRUE;
900 i = token_value; j = 0;
902 { case DICTIONARY_TK: break;
903 case OBJECTS_TK: break;
904 case VERBS_TK: break;
908 trace_level = &asm_trace_level; break;
910 trace_level = &expr_trace_level; break;
912 trace_level = &line_trace_level; break;
914 trace_level = &tokens_trace_level; break;
916 trace_level = &linker_trace_level; break;
918 trace_level = NULL; break;
921 trace_level = &asm_trace_level; break;
925 if ((token_type == SEP_TT) &&
926 (token_value == SEMICOLON_SEP))
927 { put_token_back(); break;
929 if (token_type == NUMBER_TT)
930 { j = token_value; break; }
931 if ((token_type == TRACE_KEYWORD_TT) && (token_value == ON_TK))
933 if ((token_type == TRACE_KEYWORD_TT) && (token_value == OFF_TK))
935 put_token_back(); break;
939 { case DICTIONARY_TK: show_dictionary(); break;
940 case OBJECTS_TK: list_object_tree(); break;
941 case SYMBOLS_TK: list_symbols(j); break;
942 case VERBS_TK: list_verb_table(); break;
947 trace_keywords.enabled = FALSE;
950 /* --------------------------------------------------------------------- */
952 /* --------------------------------------------------------------------- */
956 if (token_type != SYMBOL_TT)
957 return ebf_error_recover("symbol name", token_text);
959 if (sflags[token_value] & UNKNOWN_SFLAG)
960 { break; /* undef'ing an undefined constant is okay */
963 if (stypes[token_value] != CONSTANT_T)
964 { error_named("Cannot Undef a symbol which is not a defined constant:", (char *)symbs[token_value]);
968 if (debugfile_switch)
969 { write_debug_undef(token_value);
971 end_symbol_scope(token_value);
972 sflags[token_value] |= USED_SFLAG;
975 /* --------------------------------------------------------------------- */
977 /* --------------------------------------------------------------------- */
979 case VERB_CODE: make_verb(); return FALSE; /* see "tables.c" */
981 /* --------------------------------------------------------------------- */
982 /* Version <number> */
983 /* --------------------------------------------------------------------- */
987 { assembly_operand AO;
988 AO = parse_expression(CONSTANT_CONTEXT);
989 /* If a version has already been set on the command line,
990 that overrides this. */
991 if (version_set_switch)
993 warning("The Version directive was overridden by a command-line argument.");
997 if (module_switch && (AO.marker != 0))
998 error("A definite value must be given as version number");
1002 warning("The Version directive does not work in Glulx. Use \
1003 -vX.Y.Z instead, as either a command-line argument or a header comment.");
1009 { error("The version number must be in the range 3 to 8");
1015 break; /* see "inform.c" */
1017 /* --------------------------------------------------------------------- */
1018 /* Zcharacter table <num> ... */
1019 /* Zcharacter table + <num> ... */
1020 /* Zcharacter <string> <string> <string> */
1021 /* Zcharacter <char> */
1022 /* --------------------------------------------------------------------- */
1024 case ZCHARACTER_CODE:
1027 error("The Zcharacter directive has no meaning in Glulx.");
1028 panic_mode_error_recovery(); return FALSE;
1031 directive_keywords.enabled = TRUE;
1033 directive_keywords.enabled = FALSE;
1037 new_alphabet(token_text, 0);
1039 if (token_type != DQ_TT)
1040 return ebf_error_recover("double-quoted alphabet string", token_text);
1041 new_alphabet(token_text, 1);
1043 if (token_type != DQ_TT)
1044 return ebf_error_recover("double-quoted alphabet string", token_text);
1045 new_alphabet(token_text, 2);
1049 map_new_zchar(text_to_unicode(token_text));
1050 if (token_text[textual_form_length] != 0)
1051 return ebf_error_recover("single character value", token_text);
1054 case DIR_KEYWORD_TT:
1057 { int plus_flag = FALSE;
1059 if ((token_type == SEP_TT) && (token_value == PLUS_SEP))
1063 while ((token_type!=SEP_TT) || (token_value!=SEMICOLON_SEP))
1064 { switch(token_type)
1066 new_zscii_character(token_value, plus_flag);
1067 plus_flag = TRUE; break;
1069 new_zscii_character(text_to_unicode(token_text),
1071 if (token_text[textual_form_length] != 0)
1072 return ebf_error_recover("single character value",
1077 return ebf_error_recover("character or Unicode number",
1082 if (plus_flag) new_zscii_finished();
1086 case TERMINATING_DK:
1088 while ((token_type!=SEP_TT) || (token_value!=SEMICOLON_SEP))
1089 { switch(token_type)
1091 terminating_characters[no_termcs++]
1095 return ebf_error_recover("ZSCII number",
1103 return ebf_error_recover("'table', 'terminating', \
1104 a string or a constant",
1109 return ebf_error_recover("three alphabet strings, \
1110 a 'table' or 'terminating' command or a single character", token_text);
1114 /* ===================================================================== */
1118 /* We are now at the end of a syntactically valid directive. It
1119 should be terminated by a semicolon. */
1122 if ((token_type != SEP_TT) || (token_value != SEMICOLON_SEP))
1123 { ebf_error("';'", token_text);
1124 /* Put the non-semicolon back. We will continue parsing from
1125 that point, in hope that it's the start of a new directive.
1126 (This recovers cleanly from a missing semicolon at the end
1127 of a directive. It's not so clean if the directive *does*
1128 end with a semicolon, but there's extra garbage before it.) */
1134 /* ========================================================================= */
1135 /* Data structure management routines */
1136 /* ------------------------------------------------------------------------- */
1138 extern void init_directs_vars(void)
1142 extern void directs_begin_pass(void)
1144 no_named_routines = 0;
1147 constant_made_yet = FALSE;
1151 extern void directs_allocate_arrays(void)
1155 extern void directs_free_arrays(void)
1159 /* ========================================================================= */