1 /* ------------------------------------------------------------------------- */
2 /* Header file for Inform: Z-machine ("Infocom" format) compiler */
6 /* This header file and the others making up the Inform source code are */
7 /* copyright (c) Graham Nelson 1993 - 2021 */
9 /* This file is part of Inform. */
11 /* Inform is free software: you can redistribute it and/or modify */
12 /* it under the terms of the GNU General Public License as published by */
13 /* the Free Software Foundation, either version 3 of the License, or */
14 /* (at your option) any later version. */
16 /* Inform is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU General Public License for more details. */
21 /* You should have received a copy of the GNU General Public License */
22 /* along with Inform. If not, see https://gnu.org/licenses/ */
24 /* For detailed documentation on how this program internally works, and */
25 /* how to port it to a new environment, see the Technical Manual. */
27 /* *** To compile this program in one of the existing ports, you must */
28 /* at least change the machine definition (on the next page). */
29 /* In most cases no other work will be needed. *** */
33 /* Machine/host OS definitions (in alphabetical order) */
34 /* Default definitions */
35 /* Standard ANSI inclusions, macro definitions, structures */
36 /* Definitions of internal code numbers */
37 /* Extern declarations for linkage (in alphabetical order of file) */
39 /* ------------------------------------------------------------------------- */
41 /* For releases, set to the release date in the form "1st January 2000" */
42 #define RELEASE_DATE "22nd May 2021"
43 #define RELEASE_NUMBER 1635
44 #define GLULX_RELEASE_NUMBER 38
45 #define MODULE_VERSION_NUMBER 1
46 #define VNUMBER RELEASE_NUMBER
48 /* N indicates an intermediate release for Inform 7 */
49 /*#define RELEASE_SUFFIX "N"*/
51 /* ------------------------------------------------------------------------- */
52 /* Our host machine or OS for today is... */
54 /* [ Inform should compile (possibly with warnings) and work safely */
57 /* #define AMIGA - for the Commodore Amiga under SAS/C */
58 /* #define ARCHIMEDES - for Acorn RISC OS machines under Norcroft C */
59 /* #define ATARIST - for the Atari ST */
60 /* #define BEOS - for the BeBox */
61 /* #define LINUX - for Linux under gcc (essentially as Unix) */
62 /* #define MACOS - for the Apple Mac with OS X (another Unix) */
63 /* #define MAC_CLASSIC - for the Apple Mac under Think C or Codewarrior */
64 /* #define MAC_MPW - for MPW under Codewarrior (and maybe Think C) */
65 /* #define OS2 - for OS/2 32-bit mode under IBM's C Set++ */
66 /* #define PC - for 386+ IBM PCs, eg. Microsoft Visual C/C++ */
67 /* #define PC_QUICKC - for small IBM PCs under QuickC */
68 /* #define PC_WIN32 - for Borland C++ or Microsoft Visual C++ */
69 /* #define UNIX - for Unix under gcc (or big IBM PC under djgpp) */
70 /* #define VMS - for VAX or ALPHA under DEC C, but not VAX C */
72 /* In most cases executables are already available at */
73 /* http://www.ifarchive.org/, and these are sometimes enhanced with */
74 /* e.g. windowed interfaces whose source is not archived with the */
75 /* main Inform source.] */
77 /* (If no machine is defined, then cautious #defines will be made. In */
78 /* most cases, porting to a new machine is a matter of carefully filling */
79 /* out a block of definitions like those below.) */
80 /* ------------------------------------------------------------------------- */
84 /* ------------------------------------------------------------------------- */
85 /* The first task is to include the ANSI header files, and typedef */
86 /* suitable 32-bit integer types. */
87 /* ------------------------------------------------------------------------- */
99 #if SCHAR_MAX >= 0x7FFFFFFFL && SCHAR_MIN <= -0x7FFFFFFFL
100 typedef signed char int32;
101 typedef unsigned char uint32;
102 #elif SHRT_MAX >= 0x7FFFFFFFL && SHRT_MIN <= -0x7FFFFFFFL
103 typedef signed short int int32;
104 typedef unsigned short int uint32;
105 #elif INT_MAX >= 0x7FFFFFFFL && INT_MIN <= -0x7FFFFFFFL
106 typedef signed int int32;
107 typedef unsigned int uint32;
108 #elif LONG_MAX >= 0x7FFFFFFFL && LONG_MIN <= -0x7FFFFFFFL
109 typedef signed long int int32;
110 typedef unsigned long int uint32;
112 #error No type large enough to support 32-bit integers.
115 /* VAX C does not provide these limit constants, contrary to ANSI */
117 typedef unsigned int uint32;
120 /* ------------------------------------------------------------------------- */
121 /* The next part of this file contains blocks of definitions, one for */
122 /* each port, of machine or OS-dependent constants needed by Inform. */
124 /* 1. MACHINE_STRING should be set to the name of the machine or OS. */
126 /* 2. Some miscellaneous #define options (set if the constant is */
127 /* defined, otherwise not set): */
129 /* USE_TEMPORARY_FILES - use scratch files for workspace, not memory, */
131 /* PROMPT_INPUT - prompt input (don't use Unix-style command line) */
132 /* TIME_UNAVAILABLE - don't use ANSI time routines to work out today's */
134 /* CHAR_IS_UNSIGNED - if on your compiler the type "char" is unsigned */
135 /* by default, you should define this */
136 /* HAS_REALPATH - the POSIX realpath() function is available to */
137 /* find the absolute path to a file */
139 /* 3. An estimate of the typical amount of memory likely to be free */
140 /* should be given in DEFAULT_MEMORY_SIZE. */
141 /* For most modern machines, HUGE_SIZE is the appropriate setting, but */
142 /* some older micros may benefit from SMALL_SIZE. */
143 /* ------------------------------------------------------------------------- */
149 /* ------------------------------------------------------------------------- */
150 /* 4. Filenaming definitions: */
152 /* It's assumed that the host OS has the concept of subdirectories and */
153 /* has "pathnames", that is, filenames giving a chain of subdirectories */
154 /* divided by the FN_SEP (filename separator) character: e.g. for Unix */
155 /* FN_SEP is defined below as '/' and a typical name is */
156 /* "users/graham/jigsaw.z5". */
157 /* White space is not allowed in filenames, and nor is the special */
158 /* character FN_ALT, which unless defined here will be a comma and will */
159 /* be used to separate alternative locations in a path variable. */
161 /* If NO_FILE_EXTENSIONS is undefined then the OS allows "file extensions" */
162 /* of 1 to 3 alphanumeric characters like ".txt" (for text files), ".z5" */
163 /* (for game files), etc., to indicate the file's type (and, crucially, */
164 /* regards the same filename but with different extensions -- e.g., */
165 /* "frog.amp" and "frog.lil" -- as being different names). */
166 /* (The file extensions defined below are widely accepted, so please use */
167 /* them unless there's a good reason why not.) */
169 /* You should then define STANDARD_DIRECTORIES (you can define it anyway) */
170 /* in which case Inform will expect by default that files are sorted out */
171 /* by being put into suitable directories (e.g., a "games" directory for */
174 /* If it's convenient for your port you can alter the detailed definitions */
175 /* which these broad settings make. Be careful if NO_FILE_EXTENSIONS */
176 /* is set without STANDARD_DIRECTORIES, as then Inform may */
177 /* overwrite its source with object code. */
179 /* 5. Filenames (or code related to filenames) for the three temporary */
180 /* files. These only exist during compilation (and only if -F1 is set). */
181 /* Temporary_Name is the body of a filename to use */
182 /* (if you don't set this, it becomes "Inftemp") and Temporary_Directory */
183 /* is the directory path for the files to go in (which can be altered on */
184 /* the command line). On some multi-tasking OSs these filenames ought to */
185 /* include a number uniquely identifying the process: to indicate this, */
186 /* define INCLUDE_TASK_ID and provide some code... */
188 /* #define INCLUDE_TASK_ID */
189 /* #ifdef INFORM_FILE */
190 /* static int32 unique_task_id(void) */
191 /* { ...some code returning your task ID... */
195 /* 6. Any other definitions specific to the OS or machine. */
196 /* (In particular DEFAULT_ERROR_FORMAT is 0 on most machines and 1 on PCs; */
197 /* it controls the style of error messages, which is important for some */
198 /* error-throwback debugging tools.) */
199 /* ------------------------------------------------------------------------- */
201 /* ========================================================================= */
202 /* The blocks now follow in alphabetical order. */
203 /* ------------------------------------------------------------------------- */
205 /* ------------------------------------------------------------------------- */
208 #define MACHINE_STRING "Amiga"
210 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
214 #define __USE_SYSBASE
215 #include <proto/exec.h>
216 #define INCLUDE_TASK_ID
217 #define Temporary_Directory "T:"
218 #ifdef MAIN_INFORM_FILE
219 static int32 unique_task_id(void)
220 { return (int32)FindTask(NULL);
224 /* ------------------------------------------------------------------------- */
225 /* ARCHIMEDES block: Acorn/RISC OS settings */
226 /* ------------------------------------------------------------------------- */
229 #define MACHINE_STRING "RISC OS"
231 #define CHAR_IS_UNSIGNED
233 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
236 #define STANDARD_DIRECTORIES
237 #define NO_FILE_EXTENSIONS
238 #define Source_Directory "inform"
239 #define ICL_Directory "ICL"
241 #define ENABLE_TEMPORARY_PATH
242 #define Temporary_Directory "ram:"
244 #define ARC_THROWBACK
246 /* ------------------------------------------------------------------------- */
248 /* ------------------------------------------------------------------------- */
251 #define MACHINE_STRING "Atari ST"
253 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
258 #define Temporary_Directory "/tmp"
259 #define INCLUDE_TASK_ID
260 #ifdef MAIN_INFORM_FILE
261 static int32 unique_task_id(void)
262 { return (int32)getpid();
267 /* ------------------------------------------------------------------------- */
269 /* ------------------------------------------------------------------------- */
272 #define MACHINE_STRING "BeOS"
274 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
277 #define FILE_EXTENSIONS
279 #define Temporary_Directory "/tmp"
281 /* ------------------------------------------------------------------------- */
283 /* ------------------------------------------------------------------------- */
286 #define MACHINE_STRING "Linux"
290 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
294 #define Temporary_Directory "/tmp"
298 /* ------------------------------------------------------------------------- */
299 /* Macintosh block */
300 /* ------------------------------------------------------------------------- */
308 #define MACHINE_STRING "Macintosh Programmer's Workshop"
310 #define MACHINE_STRING "Macintosh"
314 #define EXTERNAL_SHELL
322 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
326 #define Include_Extension ".h"
330 #include "TB Inform.h"
333 #include <CursorCtl.h>
334 #define DEFAULT_ERROR_FORMAT 2
337 /* ------------------------------------------------------------------------- */
339 /* ------------------------------------------------------------------------- */
342 #define MACHINE_STRING "OS/2"
344 #define CHAR_IS_UNSIGNED
346 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
350 /* ------------------------------------------------------------------------- */
352 /* ------------------------------------------------------------------------- */
355 #define MACHINE_STRING "MacOS"
359 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
363 #define Temporary_Directory "/tmp"
364 #define INCLUDE_TASK_ID
365 #define _POSIX_C_SOURCE 199506L
366 #define _XOPEN_SOURCE 500
367 #ifdef MAIN_INFORM_FILE
368 #include <sys/types.h>
370 static int32 unique_task_id(void)
371 { return (int32)getpid();
377 /* ------------------------------------------------------------------------- */
378 /* PC and PC_QUICKC block */
379 /* ------------------------------------------------------------------------- */
386 #define MACHINE_STRING "PC"
388 #define USE_TEMPORARY_FILES
391 #define DEFAULT_MEMORY_SIZE SMALL_SIZE
393 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
398 #define DEFAULT_ERROR_FORMAT 1
400 /* ------------------------------------------------------------------------- */
402 /* ------------------------------------------------------------------------- */
405 #define MACHINE_STRING "Win32"
409 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
413 #define DEFAULT_ERROR_FORMAT 1
415 #ifdef _MSC_VER /* Microsoft Visual C++ */
416 #define snprintf _snprintf
418 #define isinf(x) (!_isnan(x) && !_finite(x))
421 /* ------------------------------------------------------------------------- */
423 /* ------------------------------------------------------------------------- */
426 #ifndef MACHINE_STRING
427 #define MACHINE_STRING "Unix"
432 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
437 #define Temporary_Directory "/tmp"
438 #define INCLUDE_TASK_ID
439 #ifdef MAIN_INFORM_FILE
441 static int32 unique_task_id(void)
442 { return (int32)getpid();
446 /* ------------------------------------------------------------------------- */
447 /* VMS (Dec VAX and Alpha) block */
448 /* ------------------------------------------------------------------------- */
456 #define MACHINE_STRING "Alpha/VMS"
458 #define MACHINE_STRING "VAX/VMS"
461 #define CHAR_IS_UNSIGNED
463 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
466 #define Code_Extension ".zip"
467 #define V4Code_Extension ".zip"
468 #define V5Code_Extension ".zip"
469 #define V6Code_Extension ".zip"
470 #define V7Code_Extension ".zip"
471 #define V8Code_Extension ".zip"
473 /* ========================================================================= */
474 /* Default settings: */
475 /* ------------------------------------------------------------------------- */
477 #ifndef NO_FILE_EXTENSIONS
478 #define FILE_EXTENSIONS
481 #ifndef Transcript_File
482 #ifdef FILE_EXTENSIONS
483 #define Transcript_File "gametext.txt"
485 #define Transcript_File "gametext"
489 #ifndef Debugging_File
490 #ifdef FILE_EXTENSIONS
491 #define Debugging_File "gameinfo.dbg"
493 #define Debugging_File "gamedebug"
497 #ifndef Default_Language
498 #define Default_Language "english"
501 #ifdef FILE_EXTENSIONS
502 #ifndef Source_Extension
503 #define Source_Extension ".inf"
505 #ifndef Include_Extension
506 #define Include_Extension ".h"
508 #ifndef Code_Extension
509 #define Code_Extension ".z3"
511 #ifndef V4Code_Extension
512 #define V4Code_Extension ".z4"
514 #ifndef V5Code_Extension
515 #define V5Code_Extension ".z5"
517 #ifndef V6Code_Extension
518 #define V6Code_Extension ".z6"
520 #ifndef V7Code_Extension
521 #define V7Code_Extension ".z7"
523 #ifndef V8Code_Extension
524 #define V8Code_Extension ".z8"
526 #ifndef GlulxCode_Extension
527 #define GlulxCode_Extension ".ulx"
529 #ifndef Module_Extension
530 #define Module_Extension ".m5"
532 #ifndef ICL_Extension
533 #define ICL_Extension ".icl"
538 #define Source_Extension ""
539 #define Include_Extension ""
540 #define Code_Extension ""
541 #define V4Code_Extension ""
542 #define V5Code_Extension ""
543 #define V6Code_Extension ""
544 #define V7Code_Extension ""
545 #define V8Code_Extension ""
546 #define GlulxCode_Extension ""
547 #define Module_Extension ""
548 #define ICL_Extension ""
551 #ifdef STANDARD_DIRECTORIES
552 #ifndef Source_Directory
553 #define Source_Directory "source"
555 #ifndef Include_Directory
556 #define Include_Directory "library"
558 #ifndef Code_Directory
559 #define Code_Directory "games"
561 #ifndef Module_Directory
562 #define Module_Directory "modules"
564 #ifndef Temporary_Directory
565 #define Temporary_Directory ""
567 #ifndef ICL_Directory
568 #define ICL_Directory ""
573 #ifndef Source_Directory
574 #define Source_Directory ""
576 #ifndef Include_Directory
577 #define Include_Directory ""
579 #ifndef Code_Directory
580 #define Code_Directory ""
582 #ifndef Module_Directory
583 #define Module_Directory ""
585 #ifndef Temporary_Directory
586 #define Temporary_Directory ""
588 #ifndef ICL_Directory
589 #define ICL_Directory ""
605 #ifndef Temporary_File
606 #define Temporary_File "Inftemp"
609 #ifndef DEFAULT_ERROR_FORMAT
610 #define DEFAULT_ERROR_FORMAT 0
613 #ifndef DEFAULT_MEMORY_SIZE
614 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
617 #ifndef CHAR_IS_UNSIGNED
618 typedef unsigned char uchar;
623 #if defined(__GNUC__) || defined(__clang__)
624 #define NORETURN __attribute__((__noreturn__))
625 #endif /* defined(__GNUC__) || defined(__clang__) */
631 /* ------------------------------------------------------------------------- */
632 /* A macro (rather than constant) definition: */
633 /* ------------------------------------------------------------------------- */
636 void _huge * halloc(long, size_t);
638 #define subtract_pointers(p1,p2) (long)((char _huge *)p1-(char _huge *)p2)
640 #define subtract_pointers(p1,p2) (((char *) p1)-((char *) p2))
643 /* ------------------------------------------------------------------------- */
644 /* SEEK_SET is a constant which should be defined in the ANSI header files */
645 /* but which is not present in some implementations: it's used as a */
646 /* parameter for "fseek", defined in "stdio". In pre-ANSI C, the value */
647 /* 0 was used as a parameter instead, hence the definition below. */
648 /* ------------------------------------------------------------------------- */
654 /* ------------------------------------------------------------------------- */
655 /* A large block of #define'd constant values follows. */
656 /* ------------------------------------------------------------------------- */
661 /* These checked the glulx_mode global during development, but are no
663 #define ASSERT_ZCODE() (0)
664 #define ASSERT_GLULX() (0)
667 #define ReadInt32(ptr) \
668 ( (((int32)(((uchar *)(ptr))[0])) << 24) \
669 | (((int32)(((uchar *)(ptr))[1])) << 16) \
670 | (((int32)(((uchar *)(ptr))[2])) << 8) \
671 | (((int32)(((uchar *)(ptr))[3])) ) )
673 #define ReadInt16(ptr) \
674 ( (((int32)(((uchar *)(ptr))[0])) << 8) \
675 | (((int32)(((uchar *)(ptr))[1])) ) )
677 #define WriteInt32(ptr, val) \
678 ((ptr)[0] = (uchar)(((int32)(val)) >> 24), \
679 (ptr)[1] = (uchar)(((int32)(val)) >> 16), \
680 (ptr)[2] = (uchar)(((int32)(val)) >> 8), \
681 (ptr)[3] = (uchar)(((int32)(val)) ) )
683 #define WriteInt16(ptr, val) \
684 ((ptr)[0] = (uchar)(((int32)(val)) >> 8), \
685 (ptr)[1] = (uchar)(((int32)(val)) ) )
687 /* ------------------------------------------------------------------------- */
688 /* If your compiler doesn't recognise \t, and you use ASCII, you could */
689 /* define T_C as (char) 9; failing that, it _must_ be defined as ' ' */
690 /* (space) and is _not_ allowed to be 0 or any recognisable character. */
691 /* ------------------------------------------------------------------------- */
693 #define TAB_CHARACTER '\t'
695 /* ------------------------------------------------------------------------- */
697 /* ------------------------------------------------------------------------- */
699 #define MAX_ERRORS 100
700 #define MAX_IDENTIFIER_LENGTH 32
701 #define MAX_ABBREV_LENGTH 64
702 #define MAX_DICT_WORD_SIZE 40
703 #define MAX_DICT_WORD_BYTES (40*4)
704 #define MAX_NUM_ATTR_BYTES 39
705 #define MAX_VERB_WORD_SIZE 120
707 #define VENEER_CONSTRAINT_ON_CLASSES_Z 256
708 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_Z 128
709 #define VENEER_CONSTRAINT_ON_CLASSES_G 32768
710 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_G 32768
711 #define VENEER_CONSTRAINT_ON_CLASSES \
712 (glulx_mode ? VENEER_CONSTRAINT_ON_CLASSES_G \
713 : VENEER_CONSTRAINT_ON_CLASSES_Z)
714 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE \
715 (glulx_mode ? VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_G \
716 : VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_Z)
718 #define GLULX_HEADER_SIZE 36
719 /* Number of bytes in the header. */
720 #define GLULX_STATIC_ROM_SIZE 24
721 /* Number of bytes in the Inform-specific block right after the header. */
722 #define GPAGESIZE 256
723 /* All Glulx memory boundaries must be multiples of GPAGESIZE. */
725 /* ------------------------------------------------------------------------- */
726 /* Structure definitions (there are a few others local to files) */
727 /* ------------------------------------------------------------------------- */
729 typedef struct assembly_operand_t
732 int symtype; /* 6.30 */
733 int symflags; /* 6.30 */
737 #define INITAOTV(aop, typ, val) ((aop)->type=(typ), (aop)->value=(val), (aop)->marker=0, (aop)->symtype=0, (aop)->symflags=0)
738 #define INITAOT(aop, typ) INITAOTV(aop, typ, 0)
739 #define INITAO(aop) INITAOTV(aop, 0, 0)
741 #define MAX_LINES_PER_VERB 32
742 typedef struct verbt {
744 int l[MAX_LINES_PER_VERB];
747 typedef struct prop {
749 assembly_operand ao[32];
752 /* Only one of this object. */
753 typedef struct fpropt {
759 typedef struct objecttz {
761 int parent, next, child;
765 typedef struct propg {
773 /* Only one of this object. */
774 typedef struct fproptg {
775 uchar atts[MAX_NUM_ATTR_BYTES];
779 assembly_operand *propdata;
783 typedef struct objecttg {
784 /* attributes are stored in a separate array */
786 int32 parent, next, child;
791 typedef struct maybe_file_position_S
794 } maybe_file_position;
796 typedef struct debug_location_s
798 int32 beginning_byte_index;
799 int32 end_byte_index;
800 int32 beginning_line_number;
801 int32 end_line_number;
802 int32 beginning_character_number;
803 int32 end_character_number;
804 int32 orig_file_index;
805 int32 orig_beg_line_number;
806 int32 orig_beg_char_number;
807 /* We only track the beginning #origsource location, not the end. */
810 typedef struct debug_locations_s
811 { debug_location location;
812 struct debug_locations_s *next;
816 typedef struct brief_location_s
819 int32 orig_file_index;
820 int32 orig_line_number;
823 typedef struct debug_location_beginning_s
824 { debug_locations *head;
825 int32 beginning_byte_index;
826 int32 beginning_line_number;
827 int32 beginning_character_number;
828 int32 orig_file_index;
829 int32 orig_beg_line_number;
830 int32 orig_beg_char_number;
831 } debug_location_beginning;
833 typedef struct keyword_group_s
834 { char *keywords[120];
835 int change_token_type;
840 typedef struct token_data_s
842 int32 value; /* ###-long */
844 int symtype; /* 6.30 */
845 int symflags; /* 6.30 */
847 debug_location location;
850 typedef struct FileId_s /* Source code file identifier: */
851 { char *filename; /* The filename (after translation) */
852 FILE *handle; /* Handle of file (when open), or
854 int is_input; /* Is this a source file that we are
855 parsing? If not, this is an
856 origsource filename (and handle
860 typedef struct ErrorPosition_s
871 /* A memory block can hold at most ALLOC_CHUNK_SIZE * 72: */
873 extern int ALLOC_CHUNK_SIZE;
875 typedef struct memory_block_s
882 /* This serves for both Z-code and Glulx instructions. Glulx doesn't use
883 the text, store_variable_number, branch_label_number, or branch_flag
885 typedef struct assembly_instruction_t
886 { int internal_number;
887 int store_variable_number;
888 int32 branch_label_number;
892 assembly_operand operand[8];
893 } assembly_instruction;
895 typedef struct expression_tree_node_s
897 /* Data used in tree construction */
900 int operator_number; /* Only meaningful for non-leaves */
901 assembly_operand value; /* Only meaningful for leaves */
903 /* Attributes synthesised during code generation */
905 int must_produce_value; /* e.g. FALSE in a void context */
907 int label_after; /* -1, or "put this label after code" */
908 int to_expression; /* TRUE if a condition used as numeric val */
909 int true_label; /* On condition "true", jump to this (or keep
911 int false_label; /* Likewise if the condition is "false". */
913 } expression_tree_node;
915 typedef struct operator_s
916 { int precedence; /* Level 0 to 13 (13 is highest) */
917 int token_type; /* Lexical token type */
918 int token_value; /* Lexical token value */
919 int usage; /* Infix (IN_U), prefix or postfix */
920 int associativity; /* Left (L_A), right (R_A)
921 or 0 for "it is an error to
922 implicitly associate this" */
923 int requires_lvalue; /* TRUE if the first operand must
924 be an "lvalue" (the name of some
925 storage object, such as a variable
926 or an array entry) */
927 int opcode_number_z; /* Translation number (see below) */
928 int opcode_number_g; /* Translation number (see below) */
929 int side_effect; /* TRUE if evaluating the operator
930 has potential side-effects in
931 terms of changing the Z-machine */
932 int negation; /* 0 for an unconditional operator,
933 otherwise the negation operator */
934 char *description; /* Text describing the operator
935 for error messages and tracing */
938 /* The translation number of an operator is as follows:
941 an internal opcode number if the operator can be translated
942 directly to a single Z-machine opcode;
943 400+n if it can be translated to branch opcode n;
944 800+n if to the negated form of branch opcode n;
945 (using n = 200, 201 for two conditions requiring special
949 an internal opcode number if the operator can be translated
950 directly to a single Glulx opcode;
951 FIRST_CC to LAST_CC if it is a condition;
954 /* ------------------------------------------------------------------------- */
955 /* Assembly operand types. */
956 /* ------------------------------------------------------------------------- */
958 /* For Z-machine... */
960 #define LONG_CONSTANT_OT 0 /* General constant */
961 #define SHORT_CONSTANT_OT 1 /* Constant in range 0 to 255 */
962 #define VARIABLE_OT 2 /* Variable (global, local or sp) */
963 #define OMITTED_OT 3 /* Value used in type field to indicate
964 that no operand is supplied */
965 #define EXPRESSION_OT 4 /* Meaning: to determine this value, run code
966 equivalent to the expression tree whose
967 root node-number is the value given */
971 /* #define OMITTED_OT 3 */ /* Same as above */
972 /* #define EXPRESSION_OT 4 */ /* Same as above */
973 #define CONSTANT_OT 5 /* Four-byte constant */
974 #define HALFCONSTANT_OT 6 /* Two-byte constant */
975 #define BYTECONSTANT_OT 7 /* One-byte constant */
976 #define ZEROCONSTANT_OT 8 /* Constant zero (no bytes of data) */
977 #define SYSFUN_OT 9 /* System function value */
978 #define DEREFERENCE_OT 10 /* Value at this address */
979 #define GLOBALVAR_OT 11 /* Global variable */
980 #define LOCALVAR_OT 12 /* Local variable or sp */
982 /* ------------------------------------------------------------------------- */
983 /* Internal numbers representing assemble-able Z-opcodes */
984 /* ------------------------------------------------------------------------- */
995 #define test_attr_zc 9
996 #define set_attr_zc 10
997 #define clear_attr_zc 11
999 #define insert_obj_zc 13
1002 #define get_prop_zc 16
1003 #define get_prop_addr_zc 17
1004 #define get_next_prop_zc 18
1011 #define storew_zc 25
1012 #define storeb_zc 26
1013 #define put_prop_zc 27
1015 #define print_char_zc 29
1016 #define print_num_zc 30
1017 #define random_zc 31
1020 #define split_window_zc 34
1021 #define set_window_zc 35
1022 #define output_stream_zc 36
1023 #define input_stream_zc 37
1024 #define sound_effect_zc 38
1026 #define get_sibling_zc 40
1027 #define get_child_zc 41
1028 #define get_parent_zc 42
1029 #define get_prop_len_zc 43
1032 #define print_addr_zc 46
1033 #define remove_obj_zc 47
1034 #define print_obj_zc 48
1037 #define print_paddr_zc 51
1041 #define rfalse_zc 55
1043 #define print_ret_zc 57
1046 #define restore_zc 60
1047 #define restart_zc 61
1048 #define ret_popped_zc 62
1051 #define new_line_zc 65
1052 #define show_status_zc 66
1053 #define verify_zc 67
1054 #define call_2s_zc 68
1055 #define call_vs_zc 69
1057 #define call_vs2_zc 71
1058 #define erase_window_zc 72
1059 #define erase_line_zc 73
1060 #define set_cursor_zc 74
1061 #define get_cursor_zc 75
1062 #define set_text_style_zc 76
1063 #define buffer_mode_zc 77
1064 #define read_char_zc 78
1065 #define scan_table_zc 79
1066 #define call_1s_zc 80
1067 #define call_2n_zc 81
1068 #define set_colour_zc 82
1070 #define call_vn_zc 84
1071 #define call_vn2_zc 85
1072 #define tokenise_zc 86
1073 #define encode_text_zc 87
1074 #define copy_table_zc 88
1075 #define print_table_zc 89
1076 #define check_arg_count_zc 90
1077 #define call_1n_zc 91
1079 #define piracy_zc 93
1080 #define log_shift_zc 94
1081 #define art_shift_zc 95
1082 #define set_font_zc 96
1083 #define save_undo_zc 97
1084 #define restore_undo_zc 98
1085 #define draw_picture_zc 99
1086 #define picture_data_zc 100
1087 #define erase_picture_zc 101
1088 #define set_margins_zc 102
1089 #define move_window_zc 103
1090 #define window_size_zc 104
1091 #define window_style_zc 105
1092 #define get_wind_prop_zc 106
1093 #define scroll_window_zc 107
1094 #define pop_stack_zc 108
1095 #define read_mouse_zc 109
1096 #define mouse_window_zc 110
1097 #define push_stack_zc 111
1098 #define put_wind_prop_zc 112
1099 #define print_form_zc 113
1100 #define make_menu_zc 114
1101 #define picture_table_zc 115
1102 #define print_unicode_zc 116
1103 #define check_unicode_zc 117
1106 /* ------------------------------------------------------------------------- */
1107 /* Internal numbers representing assemble-able Glulx opcodes */
1108 /* ------------------------------------------------------------------------- */
1120 #define bitnot_gc 10
1121 #define shiftl_gc 11
1122 #define sshiftr_gc 12
1123 #define ushiftr_gc 13
1138 #define return_gc 28
1141 #define tailcall_gc 31
1148 #define aloads_gc 38
1149 #define aloadb_gc 39
1150 #define aloadbit_gc 40
1151 #define astore_gc 41
1152 #define astores_gc 42
1153 #define astoreb_gc 43
1154 #define astorebit_gc 44
1155 #define stkcount_gc 45
1156 #define stkpeek_gc 46
1157 #define stkswap_gc 47
1158 #define stkroll_gc 48
1159 #define stkcopy_gc 49
1160 #define streamchar_gc 50
1161 #define streamnum_gc 51
1162 #define streamstr_gc 52
1163 #define gestalt_gc 53
1164 #define debugtrap_gc 54
1165 #define getmemsize_gc 55
1166 #define setmemsize_gc 56
1167 #define jumpabs_gc 57
1168 #define random_gc 58
1169 #define setrandom_gc 59
1171 #define verify_gc 61
1172 #define restart_gc 62
1174 #define restore_gc 64
1175 #define saveundo_gc 65
1176 #define restoreundo_gc 66
1177 #define protect_gc 67
1179 #define getstringtbl_gc 69
1180 #define setstringtbl_gc 70
1181 #define getiosys_gc 71
1182 #define setiosys_gc 72
1183 #define linearsearch_gc 73
1184 #define binarysearch_gc 74
1185 #define linkedsearch_gc 75
1187 #define callfi_gc 77
1188 #define callfii_gc 78
1189 #define callfiii_gc 79
1190 #define streamunichar_gc 80
1193 #define malloc_gc 83
1195 #define accelfunc_gc 85
1196 #define accelparam_gc 86
1197 #define numtof_gc 87
1198 #define ftonumz_gc 88
1199 #define ftonumn_gc 89
1217 #define atan2_gc 107
1224 #define jisnan_gc 114
1225 #define jisinf_gc 115
1227 /* ------------------------------------------------------------------------- */
1228 /* Index numbers into the keyword group "opcode_macros_g" (see "lexer.c") */
1229 /* ------------------------------------------------------------------------- */
1235 #define SYMBOL_TT 0 /* value = index in symbol table */
1236 #define NUMBER_TT 1 /* value = the number */
1237 #define DQ_TT 2 /* no value */
1238 #define SQ_TT 3 /* no value */
1239 #define SEP_TT 4 /* value = the _SEP code */
1240 #define EOF_TT 5 /* no value */
1242 #define STATEMENT_TT 100 /* a statement keyword */
1243 #define SEGMENT_MARKER_TT 101 /* with/has/class etc. */
1244 #define DIRECTIVE_TT 102 /* a directive keyword */
1245 #define CND_TT 103 /* in/has/etc. */
1246 #define SYSFUN_TT 105 /* built-in function */
1247 #define LOCAL_VARIABLE_TT 106 /* local variable */
1248 #define OPCODE_NAME_TT 107 /* opcode name */
1249 #define MISC_KEYWORD_TT 108 /* keyword like "char" used in
1250 syntax for a statement */
1251 #define DIR_KEYWORD_TT 109 /* keyword like "meta" used in
1252 syntax for a directive */
1253 #define TRACE_KEYWORD_TT 110 /* keyword used in debugging */
1254 #define SYSTEM_CONSTANT_TT 111 /* such as "code_offset" */
1255 #define OPCODE_MACRO_TT 112 /* fake opcode for compatibility */
1257 #define OP_TT 200 /* value = operator no */
1258 #define ENDEXP_TT 201 /* no value */
1259 #define SUBOPEN_TT 202 /* ( used for subexpr */
1260 #define SUBCLOSE_TT 203 /* ) used to close subexp */
1261 #define LARGE_NUMBER_TT 204 /* constant not in range 0-255 */
1262 #define SMALL_NUMBER_TT 205 /* constant in range 0-255 */
1263 /* In Glulx, that's the range -0x8000 to 0x7fff instead. */
1264 #define VARIABLE_TT 206 /* variable name */
1265 #define DICTWORD_TT 207 /* literal 'word' */
1266 #define ACTION_TT 208 /* action name */
1268 #define VOID_CONTEXT 1
1269 #define CONDITION_CONTEXT 2
1270 #define CONSTANT_CONTEXT 3
1271 #define QUANTITY_CONTEXT 4
1272 #define ACTION_Q_CONTEXT 5
1273 #define ASSEMBLY_CONTEXT 6
1274 #define ARRAY_CONTEXT 7
1275 #define FORINIT_CONTEXT 8
1276 #define RETURN_Q_CONTEXT 9
1278 #define LOWEST_SYSTEM_VAR_NUMBER 249 /* globals 249 to 255 are used
1279 in compiled code (Z-code
1280 only; in Glulx, the range can
1283 /* ------------------------------------------------------------------------- */
1284 /* Symbol flag definitions (in no significant order) */
1285 /* ------------------------------------------------------------------------- */
1287 #define UNKNOWN_SFLAG 1
1288 #define REPLACE_SFLAG 2
1289 #define USED_SFLAG 4
1290 #define DEFCON_SFLAG 8
1291 #define STUB_SFLAG 16
1292 #define IMPORT_SFLAG 32
1293 #define EXPORT_SFLAG 64
1294 #define ALIASED_SFLAG 128
1296 #define CHANGE_SFLAG 256
1297 #define SYSTEM_SFLAG 512
1298 #define INSF_SFLAG 1024
1299 #define UERROR_SFLAG 2048
1300 #define ACTION_SFLAG 4096
1301 #define REDEFINABLE_SFLAG 8192
1302 #define STAR_SFLAG 16384
1304 /* ------------------------------------------------------------------------- */
1305 /* Symbol type definitions */
1306 /* ------------------------------------------------------------------------- */
1310 #define GLOBAL_VARIABLE_T 3
1312 #define CONSTANT_T 5
1313 #define ATTRIBUTE_T 6
1314 #define PROPERTY_T 7
1315 #define INDIVIDUAL_PROPERTY_T 8
1318 #define FAKE_ACTION_T 11
1319 #define STATIC_ARRAY_T 12
1321 /* ------------------------------------------------------------------------- */
1322 /* Statusline_flag values */
1323 /* ------------------------------------------------------------------------- */
1325 #define SCORE_STYLE 0
1326 #define TIME_STYLE 1
1328 /* ------------------------------------------------------------------------- */
1329 /* Inform keyword definitions */
1330 /* ------------------------------------------------------------------------- */
1332 /* Index numbers into the keyword group "directives" (see "lexer.c") */
1334 #define ABBREVIATE_CODE 0
1335 #define ARRAY_CODE 1
1336 #define ATTRIBUTE_CODE 2
1337 #define CLASS_CODE 3
1338 #define CONSTANT_CODE 4
1339 #define DEFAULT_CODE 5
1340 #define DICTIONARY_CODE 6
1342 #define ENDIF_CODE 8
1343 #define EXTEND_CODE 9
1344 #define FAKE_ACTION_CODE 10
1345 #define GLOBAL_CODE 11
1346 #define IFDEF_CODE 12
1347 #define IFNDEF_CODE 13
1348 #define IFNOT_CODE 14
1349 #define IFV3_CODE 15
1350 #define IFV5_CODE 16
1351 #define IFTRUE_CODE 17
1352 #define IFFALSE_CODE 18
1353 #define IMPORT_CODE 19
1354 #define INCLUDE_CODE 20
1355 #define LINK_CODE 21
1356 #define LOWSTRING_CODE 22
1357 #define MESSAGE_CODE 23
1358 #define NEARBY_CODE 24
1359 #define OBJECT_CODE 25
1360 #define ORIGSOURCE_CODE 26
1361 #define PROPERTY_CODE 27
1362 #define RELEASE_CODE 28
1363 #define REPLACE_CODE 29
1364 #define SERIAL_CODE 30
1365 #define SWITCHES_CODE 31
1366 #define STATUSLINE_CODE 32
1367 #define STUB_CODE 33
1368 #define SYSTEM_CODE 34
1369 #define TRACE_CODE 35
1370 #define UNDEF_CODE 36
1371 #define VERB_CODE 37
1372 #define VERSION_CODE 38
1373 #define ZCHARACTER_CODE 39
1375 #define OPENBLOCK_CODE 100
1376 #define CLOSEBLOCK_CODE 101
1378 /* Index numbers into the keyword group "statements" (see "lexer.c") */
1381 #define BREAK_CODE 1
1382 #define CONTINUE_CODE 2
1383 #define SDEFAULT_CODE 3
1390 #define INVERSION_CODE 10
1391 #define JUMP_CODE 11
1392 #define MOVE_CODE 12
1393 #define NEW_LINE_CODE 13
1394 #define OBJECTLOOP_CODE 14
1395 #define PRINT_CODE 15
1396 #define PRINT_RET_CODE 16
1397 #define QUIT_CODE 17
1398 #define READ_CODE 18
1399 #define REMOVE_CODE 19
1400 #define RESTORE_CODE 20
1401 #define RETURN_CODE 21
1402 #define RFALSE_CODE 22
1403 #define RTRUE_CODE 23
1404 #define SAVE_CODE 24
1405 #define SPACES_CODE 25
1406 #define STRING_CODE 26
1407 #define STYLE_CODE 27
1408 #define SWITCH_CODE 28
1409 #define UNTIL_CODE 29
1410 #define WHILE_CODE 30
1412 #define ASSIGNMENT_CODE 100
1413 #define FUNCTION_CODE 101
1415 /* Index numbers into the keyword group "conditions" (see "lexer.c") */
1418 #define HASNT_COND 1
1420 #define NOTIN_COND 3
1421 #define OFCLASS_COND 4
1423 #define PROVIDES_COND 6
1425 /* Index numbers into the keyword group "segment_markers" (see "lexer.c") */
1427 #define CLASS_SEGMENT 0
1428 #define HAS_SEGMENT 1
1429 #define PRIVATE_SEGMENT 2
1430 #define WITH_SEGMENT 3
1432 /* Index numbers into the keyword group "misc_keywords" (see "lexer.c") */
1439 #define CAP_THE_MK 5
1442 #define REVERSE_MK 8
1444 #define UNDERLINE_MK 10
1449 #define ADDRESS_MK 15
1450 #define STRING_MK 16
1451 #define OBJECT_MK 17
1454 #define PROPERTY_MK 20
1457 /* Index numbers into the keyword group "directive_keywords" (see "lexer.c") */
1461 #define ADDITIVE_DK 2
1467 #define MULTIHELD_DK 8
1468 #define MULTIEXCEPT_DK 9
1469 #define MULTIINSIDE_DK 10
1470 #define CREATURE_DK 11
1471 #define SPECIAL_DK 12
1472 #define NUMBER_DK 13
1475 #define REVERSE_DK 16
1478 #define REPLACE_DK 19
1481 #define STRING_DK 22
1483 #define BUFFER_DK 24
1485 #define INITIAL_DK 26
1486 #define INITSTR_DK 27
1488 #define PRIVATE_DK 29
1492 #define FATALERROR_DK 33
1493 #define WARNING_DK 34
1494 #define TERMINATING_DK 35
1495 #define STATIC_DK 36
1497 /* Index numbers into the keyword group "trace_keywords" (see "lexer.c") */
1499 #define DICTIONARY_TK 0
1500 #define SYMBOLS_TK 1
1501 #define OBJECTS_TK 2
1503 #define ASSEMBLY_TK 4
1504 #define EXPRESSIONS_TK 5
1511 /* Index numbers into the keyword group "system_constants" (see "lexer.c") */
1513 #define NO_SYSTEM_CONSTANTS 62
1515 #define adjectives_table_SC 0
1516 #define actions_table_SC 1
1517 #define classes_table_SC 2
1518 #define identifiers_table_SC 3
1519 #define preactions_table_SC 4
1520 #define version_number_SC 5
1521 #define largest_object_SC 6
1522 #define strings_offset_SC 7
1523 #define code_offset_SC 8
1524 #define dict_par1_SC 9
1525 #define dict_par2_SC 10
1526 #define dict_par3_SC 11
1527 #define actual_largest_object_SC 12
1528 #define static_memory_offset_SC 13
1529 #define array_names_offset_SC 14
1530 #define readable_memory_offset_SC 15
1531 #define cpv__start_SC 16
1532 #define cpv__end_SC 17
1533 #define ipv__start_SC 18
1534 #define ipv__end_SC 19
1535 #define array__start_SC 20
1536 #define array__end_SC 21
1538 #define lowest_attribute_number_SC 22
1539 #define highest_attribute_number_SC 23
1540 #define attribute_names_array_SC 24
1542 #define lowest_property_number_SC 25
1543 #define highest_property_number_SC 26
1544 #define property_names_array_SC 27
1546 #define lowest_action_number_SC 28
1547 #define highest_action_number_SC 29
1548 #define action_names_array_SC 30
1550 #define lowest_fake_action_number_SC 31
1551 #define highest_fake_action_number_SC 32
1552 #define fake_action_names_array_SC 33
1554 #define lowest_routine_number_SC 34
1555 #define highest_routine_number_SC 35
1556 #define routines_array_SC 36
1557 #define routine_names_array_SC 37
1558 #define routine_flags_array_SC 38
1560 #define lowest_global_number_SC 39
1561 #define highest_global_number_SC 40
1562 #define globals_array_SC 41
1563 #define global_names_array_SC 42
1564 #define global_flags_array_SC 43
1566 #define lowest_array_number_SC 44
1567 #define highest_array_number_SC 45
1568 #define arrays_array_SC 46
1569 #define array_names_array_SC 47
1570 #define array_flags_array_SC 48
1572 #define lowest_constant_number_SC 49
1573 #define highest_constant_number_SC 50
1574 #define constants_array_SC 51
1575 #define constant_names_array_SC 52
1577 #define lowest_class_number_SC 53
1578 #define highest_class_number_SC 54
1579 #define class_objects_array_SC 55
1581 #define lowest_object_number_SC 56
1582 #define highest_object_number_SC 57
1584 #define oddeven_packing_SC 58
1586 #define grammar_table_SC 59 /* Glulx-only */
1587 #define dictionary_table_SC 60 /* Glulx-only */
1588 #define dynam_string_table_SC 61 /* Glulx-only */
1591 /* Index numbers into the keyword group "system_functions" (see "lexer.c") */
1593 #define NUMBER_SYSTEM_FUNCTIONS 12
1595 #define CHILD_SYSF 0
1596 #define CHILDREN_SYSF 1
1597 #define ELDER_SYSF 2
1598 #define ELDEST_SYSF 3
1599 #define INDIRECT_SYSF 4
1600 #define PARENT_SYSF 5
1601 #define RANDOM_SYSF 6
1602 #define SIBLING_SYSF 7
1603 #define YOUNGER_SYSF 8
1604 #define YOUNGEST_SYSF 9
1605 #define METACLASS_SYSF 10
1606 #define GLK_SYSF 11 /* Glulx-only */
1608 /* Index numbers into the operators group "separators" (see "lexer.c") */
1610 #define NUMBER_SEPARATORS 49
1613 #define DARROW_SEP 1
1619 #define DIVIDE_SEP 7
1620 #define REMAINDER_SEP 8
1622 #define ARTOR_SEP 10
1623 #define LOGAND_SEP 11
1624 #define ARTAND_SEP 12
1625 #define LOGNOT_SEP 13
1626 #define NOTEQUAL_SEP 14
1627 #define ARTNOT_SEP 15
1628 #define CONDEQUALS_SEP 16
1629 #define SETEQUALS_SEP 17
1631 #define GREATER_SEP 19
1634 #define OPENB_SEP 22
1635 #define CLOSEB_SEP 23
1636 #define COMMA_SEP 24
1637 #define PROPADD_SEP 25
1638 #define PROPNUM_SEP 26
1639 #define MPROPADD_SEP 27
1640 #define MPROPNUM_SEP 28
1641 #define MESSAGE_SEP 29
1642 #define PROPERTY_SEP 30
1643 #define SUPERCLASS_SEP 31
1644 #define COLON_SEP 32
1646 #define SEMICOLON_SEP 34
1647 #define OPEN_SQUARE_SEP 35
1648 #define CLOSE_SQUARE_SEP 36
1649 #define OPEN_BRACE_SEP 37
1650 #define CLOSE_BRACE_SEP 38
1651 #define DOLLAR_SEP 39
1652 #define NBRANCH_SEP 40
1653 #define BRANCH_SEP 41
1654 #define HASHADOLLAR_SEP 42
1655 #define HASHGDOLLAR_SEP 43
1656 #define HASHNDOLLAR_SEP 44
1657 #define HASHRDOLLAR_SEP 45
1658 #define HASHWDOLLAR_SEP 46
1659 #define HASHHASH_SEP 47
1662 #define UNARY_MINUS_SEP 100
1663 #define POST_INC_SEP 101
1664 #define POST_DEC_SEP 102
1666 /* ------------------------------------------------------------------------- */
1667 /* Internal numbers used to refer to operators (in expressions) */
1668 /* (must correspond to entries in the operators table in "express.c") */
1669 /* ------------------------------------------------------------------------- */
1671 #define NUM_OPERATORS 68
1681 #define SETEQUALS_OP 1
1687 #define NONZERO_OP 6
1688 #define CONDEQUALS_OP 7
1689 #define NOTEQUAL_OP 8
1691 #define GREATER_OP 10
1698 #define OFCLASS_OP 17
1699 #define PROVIDES_OP 18
1700 #define NOTOFCLASS_OP 19
1701 #define NOTPROVIDES_OP 20
1707 #define DIVIDE_OP 25
1708 #define REMAINDER_OP 26
1709 #define ARTAND_OP 27
1711 #define ARTNOT_OP 29
1713 #define DARROW_OP 31
1714 #define UNARY_MINUS_OP 32
1716 #define POST_INC_OP 34
1718 #define POST_DEC_OP 36
1719 #define PROP_ADD_OP 37
1720 #define PROP_NUM_OP 38
1721 #define MPROP_ADD_OP 39
1722 #define MPROP_NUM_OP 40
1724 #define MESSAGE_OP 42
1725 #define PROPERTY_OP 43
1726 #define SUPERCLASS_OP 44
1728 #define ARROW_SETEQUALS_OP 45
1729 #define DARROW_SETEQUALS_OP 46
1730 #define MESSAGE_SETEQUALS_OP 47
1731 #define PROPERTY_SETEQUALS_OP 48
1733 #define ARROW_INC_OP 49
1734 #define DARROW_INC_OP 50
1735 #define MESSAGE_INC_OP 51
1736 #define PROPERTY_INC_OP 52
1738 #define ARROW_DEC_OP 53
1739 #define DARROW_DEC_OP 54
1740 #define MESSAGE_DEC_OP 55
1741 #define PROPERTY_DEC_OP 56
1743 #define ARROW_POST_INC_OP 57
1744 #define DARROW_POST_INC_OP 58
1745 #define MESSAGE_POST_INC_OP 59
1746 #define PROPERTY_POST_INC_OP 60
1748 #define ARROW_POST_DEC_OP 61
1749 #define DARROW_POST_DEC_OP 62
1750 #define MESSAGE_POST_DEC_OP 63
1751 #define PROPERTY_POST_DEC_OP 64
1753 #define PROP_CALL_OP 65
1754 #define MESSAGE_CALL_OP 66
1756 #define PUSH_OP 67 /* Glulx only */
1758 /* ------------------------------------------------------------------------- */
1759 /* The five types of compiled array */
1760 /* ------------------------------------------------------------------------- */
1762 #define BYTE_ARRAY 0
1763 #define WORD_ARRAY 1
1764 #define STRING_ARRAY 2
1765 #define TABLE_ARRAY 3
1766 #define BUFFER_ARRAY 4
1768 /* ------------------------------------------------------------------------- */
1769 /* Internal numbers used to refer to veneer routines */
1770 /* (must correspond to entries in the table in "veneer.c") */
1771 /* ------------------------------------------------------------------------- */
1773 #define VENEER_ROUTINES 48
1775 #define Box__Routine_VR 0
1777 #define R_Process_VR 1
1779 #define InDefArt_VR 3
1780 #define CDefArt_VR 4
1781 #define CInDefArt_VR 5
1782 #define PrintShortName_VR 6
1783 #define EnglishNumber_VR 7
1784 #define Print__Pname_VR 8
1787 #define RV__Pr_VR 10
1788 #define CA__Pr_VR 11
1789 #define IB__Pr_VR 12
1790 #define IA__Pr_VR 13
1791 #define DB__Pr_VR 14
1792 #define DA__Pr_VR 15
1793 #define RA__Pr_VR 16
1794 #define RL__Pr_VR 17
1795 #define RA__Sc_VR 18
1796 #define OP__Pr_VR 19
1797 #define OC__Cl_VR 20
1799 #define Copy__Primitive_VR 21
1800 #define RT__Err_VR 22
1801 #define Z__Region_VR 23
1802 #define Unsigned__Compare_VR 24
1803 #define Metaclass_VR 25
1804 #define CP__Tab_VR 26
1805 #define Cl__Ms_VR 27
1806 #define RT__ChT_VR 28
1807 #define RT__ChR_VR 29
1808 #define RT__ChG_VR 30
1809 #define RT__ChGt_VR 31
1810 #define RT__ChPS_VR 32
1811 #define RT__ChPR_VR 33
1812 #define RT__TrPS_VR 34
1813 #define RT__ChLDB_VR 35
1814 #define RT__ChLDW_VR 36
1815 #define RT__ChSTB_VR 37
1816 #define RT__ChSTW_VR 38
1817 #define RT__ChPrintC_VR 39
1818 #define RT__ChPrintA_VR 40
1819 #define RT__ChPrintS_VR 41
1820 #define RT__ChPrintO_VR 42
1822 /* Glulx-only veneer routines */
1823 #define OB__Move_VR 43
1824 #define OB__Remove_VR 44
1825 #define Print__Addr_VR 45
1826 #define Glk__Wrap_VR 46
1827 #define Dynam__String_VR 47
1829 /* ------------------------------------------------------------------------- */
1830 /* Run-time-error numbers (must correspond with RT__Err code in veneer) */
1831 /* ------------------------------------------------------------------------- */
1835 #define PARENT_RTE 4
1836 #define ELDEST_RTE 5
1838 #define YOUNGER_RTE 7
1839 #define SIBLING_RTE 8
1840 #define CHILDREN_RTE 9
1841 #define YOUNGEST_RTE 10
1842 #define ELDER_RTE 11
1843 #define OBJECTLOOP_RTE 12
1844 #define OBJECTLOOP2_RTE 13
1846 #define REMOVE_RTE 15
1847 #define MOVE1_RTE 16
1848 #define MOVE2_RTE 17
1849 /* 18 = creating a loop in object tree */
1850 /* 19 = giving a non-existent attribute */
1851 #define DBYZERO_RTE 20
1852 #define PROP_ADD_RTE 21
1853 #define PROP_NUM_RTE 22
1854 #define PROPERTY_RTE 23
1855 /* 24 = reading with -> out of range */
1856 /* 25 = reading with --> out of range */
1857 /* 26 = writing with -> out of range */
1858 /* 27 = writing with --> out of range */
1859 #define ABOUNDS_RTE 28
1860 /* similarly 29, 30, 31 */
1861 #define OBJECTLOOP_BROKEN_RTE 32
1862 /* 33 = print (char) out of range */
1863 /* 34 = print (address) out of range */
1864 /* 35 = print (string) out of range */
1865 /* 36 = print (object) out of range */
1867 /* ------------------------------------------------------------------------- */
1868 /* Z-region areas (used to refer to module positions in markers) */
1869 /* ------------------------------------------------------------------------- */
1871 #define LOW_STRINGS_ZA 1
1872 #define PROP_DEFAULTS_ZA 2
1873 #define OBJECT_TREE_ZA 3
1875 #define CLASS_NUMBERS_ZA 5
1876 #define INDIVIDUAL_PROP_ZA 6
1877 #define DYNAMIC_ARRAY_ZA 7
1878 #define GRAMMAR_ZA 8
1879 #define ACTIONS_ZA 9
1880 #define PREACTIONS_ZA 10
1881 #define ADJECTIVES_ZA 11
1882 #define DICTIONARY_ZA 12
1884 #define STATIC_STRINGS_ZA 14
1885 #define LINK_DATA_ZA 15
1887 #define SYMBOLS_ZA 16
1888 #define STATIC_ARRAY_ZA 17 /* Z-code only */
1889 #define GLOBALVAR_ZA 18 /* Glulx only */
1891 /* ------------------------------------------------------------------------- */
1892 /* "Marker values", used for backpatching and linkage */
1893 /* ------------------------------------------------------------------------- */
1895 #define NULL_MV 0 /* Null */
1897 /* Marker values used in backpatch areas: */
1899 #define DWORD_MV 1 /* Dictionary word address */
1900 #define STRING_MV 2 /* Static string */
1901 #define INCON_MV 3 /* "Hardware" constant (table address) */
1902 #define IROUTINE_MV 4 /* Call to internal routine */
1903 #define VROUTINE_MV 5 /* Call to veneer routine */
1904 #define ARRAY_MV 6 /* Ref to internal dynam array address */
1905 #define NO_OBJS_MV 7 /* Ref to number of game objects */
1906 #define INHERIT_MV 8 /* Inherited property value */
1907 #define INHERIT_INDIV_MV 9 /* Inherited indiv property value */
1908 #define MAIN_MV 10 /* "Main" routine */
1909 #define SYMBOL_MV 11 /* Forward ref to unassigned symbol */
1911 /* Additional marker values used in module backpatch areas: */
1912 /* (In Glulx, OBJECT_MV and VARIABLE_MV are used in backpatching, even
1913 without modules.) */
1915 #define VARIABLE_MV 12 /* Global variable */
1916 #define IDENT_MV 13 /* Property identifier number */
1917 #define INDIVPT_MV 14 /* Individual prop table address */
1918 #define ACTION_MV 15 /* Action number */
1919 #define OBJECT_MV 16 /* Ref to internal object number */
1920 #define STATIC_ARRAY_MV 17 /* Ref to internal static array address */
1922 #define LARGEST_BPATCH_MV 17 /* Larger marker values are never written
1923 to backpatch tables */
1925 /* Value indicating an imported symbol record: */
1927 #define IMPORT_MV 32
1929 /* Values indicating an exported symbol record: */
1931 #define EXPORT_MV 33 /* Defined ordinarily */
1932 #define EXPORTSF_MV 34 /* Defined in a system file */
1933 #define EXPORTAC_MV 35 /* Action name */
1935 /* Values used only in branch backpatching: */
1936 /* ###-I've rearranged these, so that BRANCH_MV can be last; Glulx uses the
1937 whole range from BRANCH_MV to BRANCHMAX_MV. */
1939 #define LABEL_MV 36 /* Ditto: marks "jump" operands */
1940 #define DELETED_MV 37 /* Ditto: marks bytes deleted from code */
1941 #define BRANCH_MV 38 /* Used in "asm.c" for routine coding */
1942 #define BRANCHMAX_MV 58 /* In fact, the range BRANCH_MV to
1943 BRANCHMAX_MV all means the same thing.
1944 The position within the range means
1945 how far back from the label to go
1946 to find the opmode byte to modify. */
1948 /* ------------------------------------------------------------------------- */
1949 /* "String contexts"; the purpose for a given string. This info gets */
1950 /* written to the transcript file (gametext.txt). */
1951 /* ------------------------------------------------------------------------- */
1953 #define STRCTX_INFO 0 /* comment; not stored in game file */
1954 #define STRCTX_GAME 1 /* strings area */
1955 #define STRCTX_GAMEOPC 2 /* inline text in opcode (Z-code only) */
1956 #define STRCTX_VENEER 3 /* strings area, from veneer code */
1957 #define STRCTX_VENEEROPC 4 /* inline text, veneer code (Z-code only) */
1958 #define STRCTX_LOWSTRING 5 /* lowmem (Z-code); also dynamic-str literals */
1959 #define STRCTX_ABBREV 6 /* abbreviation */
1960 #define STRCTX_DICT 7 /* dictionary word */
1961 #define STRCTX_OBJNAME 8 /* object "hardware name" */
1962 #define STRCTX_SYMBOL 9 /* prop/attr/etc names */
1963 #define STRCTX_INFIX 10 /* text printed in asterisk traces */
1965 /* ========================================================================= */
1966 /* Initialisation extern definitions */
1968 /* Note that each subsystem in Inform provides four routines to keep */
1969 /* track of variables and data structures: */
1971 /* init_*_vars should set variables to initial values (they must */
1972 /* not be initialised directly in their declarations */
1973 /* as Inform may need to compile several times in a */
1976 /* *_begin_pass any variable/array initialisation that needs to */
1977 /* happen at the start of the pass through the source */
1979 /* *_allocate_arrays should use my_malloc/my_calloc (see memory.c) */
1980 /* to allocate any arrays or workspace needed */
1982 /* *_free_arrays should use my_free to free all memory allocated */
1983 /* (with one exception in "text.c") */
1985 /* ========================================================================= */
1987 /* > READ INFORM SOURCE */
1989 /* My Source Book */
1991 extern void init_arrays_vars(void); /* arrays: construct tableaux */
1992 extern void init_asm_vars(void); /* asm: assemble even rare or v6 codes */
1993 extern void init_bpatch_vars(void); /* bpatch: backpatches code */
1994 extern void init_chars_vars(void); /* chars: translate character sets */
1995 extern void init_directs_vars(void); /* directs: ponder directives */
1996 extern void init_errors_vars(void); /* errors: issue diagnostics */
1997 extern void init_expressc_vars(void); /* expressc: compile expressions */
1998 extern void init_expressp_vars(void); /* expressp: parse expressions */
1999 extern void init_files_vars(void); /* files: handle files */
2000 /* void init_vars(void); inform: decide what to do */
2001 extern void init_lexer_vars(void); /* lexer: lexically analyse source */
2002 extern void init_linker_vars(void); /* linker: link in pre-compiled module */
2003 extern void init_memory_vars(void); /* memory: manage memory settings */
2004 extern void init_objects_vars(void); /* objects: cultivate object tree */
2005 extern void init_states_vars(void); /* states: translate statements to code*/
2006 extern void init_symbols_vars(void); /* symbols: construct symbols table */
2007 extern void init_syntax_vars(void); /* syntax: parse the program */
2008 extern void init_tables_vars(void); /* tables: glue tables into the output */
2009 extern void init_text_vars(void); /* text: encode text and dictionary */
2010 extern void init_veneer_vars(void); /* veneer: compile a layer of code */
2011 extern void init_verbs_vars(void); /* verbs: lay out grammar */
2013 extern void files_begin_prepass(void); /* These routines initialise just */
2014 extern void lexer_begin_prepass(void); /* enough to begin loading source */
2016 extern void arrays_begin_pass(void);
2017 extern void asm_begin_pass(void);
2018 extern void bpatch_begin_pass(void);
2019 extern void chars_begin_pass(void);
2020 extern void directs_begin_pass(void);
2021 extern void errors_begin_pass(void);
2022 extern void expressc_begin_pass(void);
2023 extern void expressp_begin_pass(void);
2024 extern void files_begin_pass(void);
2025 /* void begin_pass(void); */
2026 extern void lexer_begin_pass(void);
2027 extern void linker_begin_pass(void);
2028 extern void memory_begin_pass(void);
2029 extern void objects_begin_pass(void);
2030 extern void states_begin_pass(void);
2031 extern void symbols_begin_pass(void);
2032 extern void syntax_begin_pass(void);
2033 extern void tables_begin_pass(void);
2034 extern void text_begin_pass(void);
2035 extern void veneer_begin_pass(void);
2036 extern void verbs_begin_pass(void);
2038 extern void lexer_endpass(void);
2039 extern void linker_endpass(void);
2041 extern void arrays_allocate_arrays(void);
2042 extern void asm_allocate_arrays(void);
2043 extern void bpatch_allocate_arrays(void);
2044 extern void chars_allocate_arrays(void);
2045 extern void directs_allocate_arrays(void);
2046 extern void errors_allocate_arrays(void);
2047 extern void expressc_allocate_arrays(void);
2048 extern void expressp_allocate_arrays(void);
2049 extern void files_allocate_arrays(void);
2050 /* void allocate_arrays(void); */
2051 extern void lexer_allocate_arrays(void);
2052 extern void linker_allocate_arrays(void);
2053 extern void memory_allocate_arrays(void);
2054 extern void objects_allocate_arrays(void);
2055 extern void states_allocate_arrays(void);
2056 extern void symbols_allocate_arrays(void);
2057 extern void syntax_allocate_arrays(void);
2058 extern void tables_allocate_arrays(void);
2059 extern void text_allocate_arrays(void);
2060 extern void veneer_allocate_arrays(void);
2061 extern void verbs_allocate_arrays(void);
2063 extern void arrays_free_arrays(void);
2064 extern void asm_free_arrays(void);
2065 extern void bpatch_free_arrays(void);
2066 extern void chars_free_arrays(void);
2067 extern void directs_free_arrays(void);
2068 extern void errors_free_arrays(void);
2069 extern void expressc_free_arrays(void);
2070 extern void expressp_free_arrays(void);
2071 extern void files_free_arrays(void);
2072 /* void free_arrays(void); */
2073 extern void lexer_free_arrays(void);
2074 extern void linker_free_arrays(void);
2075 extern void memory_free_arrays(void);
2076 extern void objects_free_arrays(void);
2077 extern void states_free_arrays(void);
2078 extern void symbols_free_arrays(void);
2079 extern void syntax_free_arrays(void);
2080 extern void tables_free_arrays(void);
2081 extern void text_free_arrays(void);
2082 extern void veneer_free_arrays(void);
2083 extern void verbs_free_arrays(void);
2085 /* ========================================================================= */
2086 /* Remaining extern definitions are given by file in alphabetical order */
2087 /* ------------------------------------------------------------------------- */
2088 /* Extern definitions for "arrays" */
2089 /* ------------------------------------------------------------------------- */
2091 extern int no_globals, no_arrays;
2092 extern int dynamic_array_area_size;
2093 extern int *dynamic_array_area;
2094 extern int static_array_area_size;
2095 extern int *static_array_area;
2096 extern int32 *global_initial_value;
2097 extern int32 *array_symbols;
2098 extern int *array_sizes, *array_types, *array_locs;
2100 extern void make_global(int array_flag, int name_only);
2101 extern void set_variable_value(int i, int32 v);
2102 extern void check_globals(void);
2103 extern int32 begin_table_array(void);
2104 extern int32 begin_word_array(void);
2105 extern void array_entry(int32 i, int is_static, assembly_operand VAL);
2106 extern void finish_array(int32 i, int is_static);
2108 /* ------------------------------------------------------------------------- */
2109 /* Extern definitions for "asm" */
2110 /* ------------------------------------------------------------------------- */
2112 extern memory_block zcode_area;
2113 extern int32 zmachine_pc;
2115 extern int32 no_instructions;
2116 extern int sequence_point_follows;
2117 extern int uses_unicode_features, uses_memheap_features,
2118 uses_acceleration_features, uses_float_features;
2119 extern debug_location statement_debug_location;
2120 extern int execution_never_reaches_here;
2121 extern int *variable_usage;
2122 extern int next_label, no_sequence_points;
2123 extern int32 *variable_tokens;
2124 extern assembly_instruction AI;
2125 extern int32 *named_routine_symbols;
2127 extern void print_operand(assembly_operand o);
2128 extern char *variable_name(int32 i);
2129 extern void set_constant_ot(assembly_operand *AO);
2130 extern int is_constant_ot(int otval);
2131 extern int is_variable_ot(int otval);
2132 extern void assemblez_instruction(assembly_instruction *a);
2133 extern void assembleg_instruction(assembly_instruction *a);
2134 extern void assemble_label_no(int n);
2135 extern void assemble_jump(int n);
2136 extern void define_symbol_label(int symbol);
2137 extern int32 assemble_routine_header(int no_locals, int debug_flag,
2138 char *name, int embedded_flag, int the_symbol);
2139 extern void assemble_routine_end(int embedded_flag, debug_locations locations);
2141 extern void assemblez_0(int internal_number);
2142 extern void assemblez_0_to(int internal_number, assembly_operand o1);
2143 extern void assemblez_0_branch(int internal_number, int label, int flag);
2144 extern void assemblez_1(int internal_number, assembly_operand o1);
2145 extern void assemblez_1_to(int internal_number,
2146 assembly_operand o1, assembly_operand st);
2147 extern void assemblez_1_branch(int internal_number,
2148 assembly_operand o1, int label, int flag);
2149 extern void assemblez_objcode(int internal_number,
2150 assembly_operand o1, assembly_operand st,
2151 int label, int flag);
2152 extern void assemblez_2(int internal_number,
2153 assembly_operand o1, assembly_operand o2);
2154 extern void assemblez_2_to(int internal_number,
2155 assembly_operand o1, assembly_operand o2,
2156 assembly_operand st);
2157 extern void assemblez_2_branch(int internal_number,
2158 assembly_operand o1, assembly_operand o2,
2159 int label, int flag);
2160 extern void assemblez_3(int internal_number,
2161 assembly_operand o1, assembly_operand o2,
2162 assembly_operand o3);
2163 extern void assemblez_3_branch(int internal_number,
2164 assembly_operand o1, assembly_operand o2,
2165 assembly_operand o3, int label, int flag);
2166 extern void assemblez_3_to(int internal_number,
2167 assembly_operand o1, assembly_operand o2,
2168 assembly_operand o3, assembly_operand st);
2169 extern void assemblez_4(int internal_number,
2170 assembly_operand o1, assembly_operand o2,
2171 assembly_operand o3, assembly_operand o4);
2172 extern void assemblez_5(int internal_number,
2173 assembly_operand o1, assembly_operand o2,
2174 assembly_operand o3, assembly_operand o4,
2175 assembly_operand o5);
2176 extern void assemblez_6(int internal_number,
2177 assembly_operand o1, assembly_operand o2,
2178 assembly_operand o3, assembly_operand o4,
2179 assembly_operand o5, assembly_operand o6);
2180 extern void assemblez_4_branch(int internal_number,
2181 assembly_operand o1, assembly_operand o2,
2182 assembly_operand o3, assembly_operand o4,
2183 int label, int flag);
2184 extern void assemblez_4_to(int internal_number,
2185 assembly_operand o1, assembly_operand o2,
2186 assembly_operand o3, assembly_operand o4,
2187 assembly_operand st);
2188 extern void assemblez_5_to(int internal_number,
2189 assembly_operand o1, assembly_operand o2,
2190 assembly_operand o3, assembly_operand o4,
2191 assembly_operand o5, assembly_operand st);
2193 extern void assemblez_inc(assembly_operand o1);
2194 extern void assemblez_dec(assembly_operand o1);
2195 extern void assemblez_store(assembly_operand o1, assembly_operand o2);
2196 extern void assemblez_jump(int n);
2198 extern void assembleg_0(int internal_number);
2199 extern void assembleg_1(int internal_number, assembly_operand o1);
2200 extern void assembleg_2(int internal_number, assembly_operand o1,
2201 assembly_operand o2);
2202 extern void assembleg_3(int internal_number, assembly_operand o1,
2203 assembly_operand o2, assembly_operand o3);
2204 extern void assembleg_4(int internal_number, assembly_operand o1,
2205 assembly_operand o2, assembly_operand o3, assembly_operand o4);
2206 extern void assembleg_5(int internal_number, assembly_operand o1,
2207 assembly_operand o2, assembly_operand o3, assembly_operand o4,
2208 assembly_operand o5);
2209 extern void assembleg_0_branch(int internal_number,
2211 extern void assembleg_1_branch(int internal_number,
2212 assembly_operand o1, int label);
2213 extern void assembleg_2_branch(int internal_number,
2214 assembly_operand o1, assembly_operand o2, int label);
2215 extern void assembleg_call_1(assembly_operand oaddr, assembly_operand o1,
2216 assembly_operand odest);
2217 extern void assembleg_call_2(assembly_operand oaddr, assembly_operand o1,
2218 assembly_operand o2, assembly_operand odest);
2219 extern void assembleg_call_3(assembly_operand oaddr, assembly_operand o1,
2220 assembly_operand o2, assembly_operand o3, assembly_operand odest);
2221 extern void assembleg_inc(assembly_operand o1);
2222 extern void assembleg_dec(assembly_operand o1);
2223 extern void assembleg_store(assembly_operand o1, assembly_operand o2);
2224 extern void assembleg_jump(int n);
2226 extern void parse_assembly(void);
2228 /* ------------------------------------------------------------------------- */
2229 /* Extern definitions for "bpatch" */
2230 /* ------------------------------------------------------------------------- */
2232 extern memory_block zcode_backpatch_table, staticarray_backpatch_table,
2233 zmachine_backpatch_table;
2234 extern int32 zcode_backpatch_size, staticarray_backpatch_size,
2235 zmachine_backpatch_size;
2236 extern int backpatch_marker, backpatch_error_flag;
2238 extern int32 backpatch_value(int32 value);
2239 extern void backpatch_zmachine_image_z(void);
2240 extern void backpatch_zmachine_image_g(void);
2241 extern void backpatch_zmachine(int mv, int zmachine_area, int32 offset);
2243 /* ------------------------------------------------------------------------- */
2244 /* Extern definitions for "chars" */
2245 /* ------------------------------------------------------------------------- */
2247 extern uchar source_to_iso_grid[];
2248 extern int32 iso_to_unicode_grid[];
2249 extern int character_digit_value[];
2250 extern uchar alphabet[3][27];
2251 extern int alphabet_modified;
2252 extern int zscii_defn_modified;
2253 extern int zscii_high_water_mark;
2254 extern char alphabet_used[];
2255 extern int iso_to_alphabet_grid[];
2256 extern int zscii_to_alphabet_grid[];
2257 extern int textual_form_length;
2259 extern int iso_to_unicode(int iso);
2260 extern int unicode_to_zscii(int32 u);
2261 extern int32 zscii_to_unicode(int z);
2262 extern int32 text_to_unicode(char *text);
2263 extern void zscii_to_text(char *text, int zscii);
2264 extern char *name_of_iso_set(int s);
2265 extern void change_character_set(void);
2266 extern void new_alphabet(char *text, int alphabet);
2267 extern void new_zscii_character(int32 unicode, int plus_flag);
2268 extern void new_zscii_finished(void);
2269 extern void map_new_zchar(int32 unicode);
2270 extern void make_lower_case(char *str);
2271 extern void make_upper_case(char *str);
2273 /* ------------------------------------------------------------------------- */
2274 /* Extern definitions for "directs" */
2275 /* ------------------------------------------------------------------------- */
2277 extern brief_location routine_starts_line;
2279 extern int no_routines, no_named_routines, no_locals, no_termcs;
2280 extern int terminating_characters[];
2282 extern int parse_given_directive(int internal_flag);
2284 /* ------------------------------------------------------------------------- */
2285 /* Extern definitions for "errors" */
2286 /* ------------------------------------------------------------------------- */
2288 extern char *forerrors_buff;
2289 extern int forerrors_pointer;
2290 extern int no_errors, no_warnings, no_suppressed_warnings,
2291 no_link_errors, no_compiler_errors;
2293 extern ErrorPosition ErrorReport;
2295 extern void fatalerror(char *s) NORETURN;
2296 extern void fatalerror_named(char *s1, char *s2) NORETURN;
2297 extern void memory_out_error(int32 size, int32 howmany, char *name) NORETURN;
2298 extern void memoryerror(char *s, int32 size) NORETURN;
2299 extern void error(char *s);
2300 extern void error_named(char *s1, char *s2);
2301 extern void error_numbered(char *s1, int val);
2302 extern void error_named_at(char *s1, char *s2, brief_location report_line);
2303 extern void ebf_error(char *s1, char *s2);
2304 extern void ebf_symbol_error(char *s1, char *name, char *type, brief_location report_line);
2305 extern void char_error(char *s, int ch);
2306 extern void unicode_char_error(char *s, int32 uni);
2307 extern void no_such_label(char *lname);
2308 extern void warning(char *s);
2309 extern void warning_numbered(char *s1, int val);
2310 extern void warning_named(char *s1, char *s2);
2311 extern void dbnu_warning(char *type, char *name, brief_location report_line);
2312 extern void uncalled_routine_warning(char *type, char *name, brief_location report_line);
2313 extern void obsolete_warning(char *s1);
2314 extern void link_error(char *s);
2315 extern void link_error_named(char *s1, char *s2);
2316 extern int compiler_error(char *s);
2317 extern int compiler_error_named(char *s1, char *s2);
2318 extern void print_sorry_message(void);
2320 #ifdef ARC_THROWBACK
2321 extern int throwback_switch;
2323 extern void throwback(int severity, char * error);
2324 extern void throwback_start(void);
2325 extern void throwback_end(void);
2328 /* ------------------------------------------------------------------------- */
2329 /* Extern definitions for "expressc" */
2330 /* ------------------------------------------------------------------------- */
2332 extern int vivc_flag;
2333 extern operator operators[];
2335 extern assembly_operand stack_pointer, temp_var1, temp_var2, temp_var3,
2336 temp_var4, zero_operand, one_operand, two_operand, three_operand,
2337 four_operand, valueless_operand;
2339 assembly_operand code_generate(assembly_operand AO, int context, int label);
2340 assembly_operand check_nonzero_at_runtime(assembly_operand AO1, int label,
2343 /* ------------------------------------------------------------------------- */
2344 /* Extern definitions for "expressp" */
2345 /* ------------------------------------------------------------------------- */
2347 extern int system_function_usage[];
2348 extern expression_tree_node *ET;
2350 extern int z_system_constant_list[];
2351 extern int glulx_system_constant_list[];
2353 extern int32 value_of_system_constant(int t);
2354 extern void clear_expression_space(void);
2355 extern void show_tree(assembly_operand AO, int annotate);
2356 extern assembly_operand parse_expression(int context);
2357 extern int test_for_incdec(assembly_operand AO);
2359 /* ------------------------------------------------------------------------- */
2360 /* Extern definitions for "files" */
2361 /* ------------------------------------------------------------------------- */
2363 extern int total_files;
2364 extern int current_input_file;
2365 extern int total_input_files;
2366 extern FileId *InputFiles;
2368 extern FILE *Temp1_fp, *Temp2_fp, *Temp3_fp;
2369 extern char Temp1_Name[], Temp2_Name[], Temp3_Name[];
2370 extern int32 total_chars_read;
2372 extern void open_temporary_files(void);
2373 extern void check_temp_files(void);
2374 extern void remove_temp_files(void);
2376 extern void open_transcript_file(char *what_of);
2377 extern void write_to_transcript_file(char *text, int linetype);
2378 extern void close_transcript_file(void);
2379 extern void abort_transcript_file(void);
2381 extern void nullify_debug_file_position(maybe_file_position *position);
2383 extern void begin_debug_file(void);
2385 extern void debug_file_printf(const char*format, ...);
2386 extern void debug_file_print_with_entities(const char*string);
2387 extern void debug_file_print_base_64_triple
2388 (uchar first, uchar second, uchar third);
2389 extern void debug_file_print_base_64_pair(uchar first, uchar second);
2390 extern void debug_file_print_base_64_single(uchar first);
2392 extern void write_debug_location(debug_location location);
2393 extern void write_debug_locations(debug_locations locations);
2394 extern void write_debug_optional_identifier(int32 symbol_index);
2395 extern void write_debug_symbol_backpatch(int32 symbol_index);
2396 extern void write_debug_symbol_optional_backpatch(int32 symbol_index);
2397 extern void write_debug_object_backpatch(int32 object_number);
2398 extern void write_debug_packed_code_backpatch(int32 offset);
2399 extern void write_debug_code_backpatch(int32 offset);
2400 extern void write_debug_global_backpatch(int32 offset);
2401 extern void write_debug_array_backpatch(int32 offset);
2402 extern void write_debug_grammar_backpatch(int32 offset);
2404 extern void begin_writing_debug_sections(void);
2405 extern void write_debug_section(const char*name, int32 beginning_address);
2406 extern void end_writing_debug_sections(int32 end_address);
2408 extern void write_debug_undef(int32 symbol_index);
2410 extern void end_debug_file(void);
2412 extern void add_to_checksum(void *address);
2414 extern void load_sourcefile(char *story_name, int style);
2415 extern int file_load_chars(int file_number, char *buffer, int length);
2416 extern void close_all_source(void);
2417 extern int register_orig_sourcefile(char *filename);
2419 extern void output_file(void);
2421 /* ------------------------------------------------------------------------- */
2422 /* Extern definitions for "inform" */
2423 /* ------------------------------------------------------------------------- */
2425 extern char Code_Name[];
2426 extern int endofpass_flag;
2428 extern int version_number, instruction_set_number, extend_memory_map;
2429 extern int32 scale_factor, length_scale_factor;
2431 extern int WORDSIZE, INDIV_PROP_START,
2432 OBJECT_BYTE_LENGTH, DICT_ENTRY_BYTE_LENGTH, DICT_ENTRY_FLAG_POS;
2433 extern int32 MAXINTWORD;
2435 extern int asm_trace_level, line_trace_level, expr_trace_level,
2436 linker_trace_level, tokens_trace_level;
2439 bothpasses_switch, concise_switch,
2440 economy_switch, frequencies_switch,
2441 ignore_switches_switch, listobjects_switch, debugfile_switch,
2442 listing_switch, memout_switch, printprops_switch,
2443 offsets_switch, percentages_switch, obsolete_switch,
2444 transcript_switch, statistics_switch, optimise_switch,
2445 version_set_switch, nowarnings_switch, hash_switch,
2446 memory_map_switch, module_switch, temporary_files_switch,
2447 define_DEBUG_switch, define_USE_MODULES_switch, define_INFIX_switch,
2448 runtime_error_checking_switch;
2450 extern int oddeven_packing_switch;
2452 extern int glulx_mode, compression_switch;
2453 extern int32 requested_glulx_version;
2455 extern int error_format, store_the_text, asm_trace_setting,
2456 double_space_setting, trace_fns_setting, character_set_setting,
2457 character_set_unicode;
2459 extern char Debugging_Name[];
2460 extern char Transcript_Name[];
2461 extern char Language_Name[];
2462 extern char Charset_Map[];
2464 extern char banner_line[];
2466 extern void select_version(int vn);
2467 extern void switches(char *, int);
2468 extern int translate_in_filename(int last_value, char *new_name, char *old_name,
2469 int same_directory_flag, int command_line_flag);
2470 extern void translate_out_filename(char *new_name, char *old_name);
2471 extern int translate_link_filename(int last_value,
2472 char *new_name, char *old_name);
2473 extern void translate_temp_filename(int i);
2476 extern char *riscos_file_type(void);
2479 /* For the benefit of the MAC_FACE port these are declared extern, though
2480 unused outside "inform" in the compiler itself */
2482 extern void allocate_arrays(void);
2483 extern void free_arrays(void);
2485 /* ------------------------------------------------------------------------- */
2486 /* Extern definitions for "lexer" */
2487 /* ------------------------------------------------------------------------- */
2489 extern int hash_printed_since_newline;
2490 extern int total_source_line_count;
2491 extern int dont_enter_into_symbol_table;
2492 extern int return_sp_as_variable;
2493 extern int next_token_begins_syntax_line;
2494 extern char **local_variable_texts;
2496 extern int32 token_value;
2497 extern int token_type;
2498 extern char *token_text;
2500 extern debug_location get_token_location(void);
2501 extern debug_locations get_token_locations(void);
2502 extern debug_location_beginning get_token_location_beginning(void);
2503 extern void discard_token_location(debug_location_beginning beginning);
2504 extern debug_locations get_token_location_end(debug_location_beginning beginning);
2506 extern void describe_token(token_data t);
2508 extern void construct_local_variable_tables(void);
2509 extern void declare_systemfile(void);
2510 extern int is_systemfile(void);
2511 extern void report_errors_at_current_line(void);
2512 extern debug_location get_current_debug_location(void);
2513 extern debug_location get_error_report_debug_location(void);
2514 extern int32 get_current_line_start(void);
2515 extern void set_origsource_location(char *source, int32 line, int32 charnum);
2516 extern brief_location get_brief_location(ErrorPosition *errpos);
2517 extern void export_brief_location(brief_location loc, ErrorPosition *errpos);
2518 extern brief_location blank_brief_location;
2520 extern void put_token_back(void);
2521 extern void get_next_token(void);
2522 extern void restart_lexer(char *lexical_source, char *name);
2524 extern keyword_group directives, statements, segment_markers,
2525 conditions, system_functions, local_variables, opcode_names,
2526 misc_keywords, directive_keywords, trace_keywords, system_constants,
2529 /* ------------------------------------------------------------------------- */
2530 /* Extern definitions for "linker" */
2531 /* ------------------------------------------------------------------------- */
2533 extern memory_block link_data_area;
2534 extern int32 link_data_size;
2535 extern char current_module_filename[];
2537 extern char *describe_mv(int mval);
2538 extern void write_link_marker(int zmachine_area, int32 offset,
2539 assembly_operand op);
2540 extern void flush_link_data(void);
2541 extern void import_symbol(int32 symbol_number);
2542 extern void export_symbol(int32 symbol_number);
2543 extern void export_symbol_name(int32 i);
2544 extern void link_module(char *filename);
2546 /* ------------------------------------------------------------------------- */
2547 /* Extern definitions for "memory" */
2548 /* ------------------------------------------------------------------------- */
2550 extern int32 malloced_bytes;
2552 extern int MAX_QTEXT_SIZE, MAX_SYMBOLS, HASH_TAB_SIZE, MAX_DICT_ENTRIES,
2553 MAX_OBJECTS, MAX_ACTIONS, MAX_ADJECTIVES, MAX_ABBREVS,
2554 MAX_STATIC_DATA, MAX_PROP_TABLE_SIZE, SYMBOLS_CHUNK_SIZE,
2555 MAX_EXPRESSION_NODES, MAX_LABELS, MAX_LINESPACE,
2556 MAX_LOW_STRINGS, MAX_CLASSES, MAX_VERBS,
2557 MAX_VERBSPACE, MAX_ARRAYS, MAX_INCLUSION_DEPTH,
2558 MAX_SOURCE_FILES, MAX_DYNAMIC_STRINGS;
2560 extern int32 MAX_STATIC_STRINGS, MAX_ZCODE_SIZE, MAX_LINK_DATA_SIZE,
2561 MAX_TRANSCRIPT_SIZE, MAX_INDIV_PROP_TABLE_SIZE,
2562 MAX_NUM_STATIC_STRINGS, MAX_UNICODE_CHARS,
2563 MAX_STACK_SIZE, MEMORY_MAP_EXTENSION;
2565 extern int32 MAX_OBJ_PROP_COUNT, MAX_OBJ_PROP_TABLE_SIZE;
2566 extern int MAX_LOCAL_VARIABLES, MAX_GLOBAL_VARIABLES;
2567 extern int DICT_WORD_SIZE, DICT_CHAR_SIZE, DICT_WORD_BYTES;
2568 extern int ZCODE_HEADER_EXT_WORDS, ZCODE_HEADER_FLAGS_3;
2569 extern int NUM_ATTR_BYTES, GLULX_OBJECT_EXT_BYTES;
2570 extern int WARN_UNUSED_ROUTINES, OMIT_UNUSED_ROUTINES;
2571 extern int TRANSCRIPT_FORMAT;
2573 /* These macros define offsets that depend on the value of NUM_ATTR_BYTES.
2574 (Meaningful only for Glulx.) */
2575 /* GOBJFIELD: word offsets of various elements in the object structure. */
2576 #define GOBJFIELD_CHAIN() (1+((NUM_ATTR_BYTES)/4))
2577 #define GOBJFIELD_NAME() (2+((NUM_ATTR_BYTES)/4))
2578 #define GOBJFIELD_PROPTAB() (3+((NUM_ATTR_BYTES)/4))
2579 #define GOBJFIELD_PARENT() (4+((NUM_ATTR_BYTES)/4))
2580 #define GOBJFIELD_SIBLING() (5+((NUM_ATTR_BYTES)/4))
2581 #define GOBJFIELD_CHILD() (6+((NUM_ATTR_BYTES)/4))
2583 extern void *my_malloc(int32 size, char *whatfor);
2584 extern void my_realloc(void *pointer, int32 oldsize, int32 size,
2586 extern void *my_calloc(int32 size, int32 howmany, char *whatfor);
2587 extern void my_recalloc(void *pointer, int32 size, int32 oldhowmany,
2588 int32 howmany, char *whatfor);
2589 extern void my_free(void *pointer, char *whatitwas);
2591 extern void set_memory_sizes(int size_flag);
2592 extern void adjust_memory_sizes(void);
2593 extern void memory_command(char *command);
2594 extern void print_memory_usage(void);
2596 extern void initialise_memory_block(memory_block *MB);
2597 extern void deallocate_memory_block(memory_block *MB);
2598 extern int read_byte_from_memory_block(memory_block *MB, int32 index);
2599 extern void write_byte_to_memory_block(memory_block *MB,
2600 int32 index, int value);
2602 /* ------------------------------------------------------------------------- */
2603 /* Extern definitions for "objects" */
2604 /* ------------------------------------------------------------------------- */
2606 extern int no_attributes, no_properties;
2607 extern int no_individual_properties;
2608 extern int individuals_length;
2609 extern uchar *individuals_table;
2610 extern int no_classes, no_objects;
2611 extern objecttz *objectsz;
2612 extern objecttg *objectsg;
2613 extern uchar *objectatts;
2614 extern int *class_object_numbers;
2615 extern int32 *class_begins_at;
2617 extern int32 *prop_default_value;
2618 extern int *prop_is_long;
2619 extern int *prop_is_additive;
2620 extern char *properties_table;
2621 extern int properties_table_size;
2623 extern void make_attribute(void);
2624 extern void make_property(void);
2625 extern void make_object(int nearby_flag,
2626 char *textual_name, int specified_parent, int specified_class,
2628 extern void make_class(char *metaclass_name);
2629 extern int object_provides(int obj, int id);
2630 extern void list_object_tree(void);
2631 extern void write_the_identifier_names(void);
2633 /* ------------------------------------------------------------------------- */
2634 /* Extern definitions for "symbols" */
2635 /* ------------------------------------------------------------------------- */
2637 extern int no_named_constants;
2638 extern int no_symbols;
2639 extern int32 **symbs;
2640 extern int32 *svals;
2642 extern brief_location *slines;
2645 extern char *stypes;
2647 extern signed char *stypes;
2649 extern maybe_file_position *symbol_debug_backpatch_positions;
2650 extern maybe_file_position *replacement_debug_backpatch_positions;
2651 extern int32 *individual_name_strings;
2652 extern int32 *attribute_name_strings;
2653 extern int32 *action_name_strings;
2654 extern int32 *array_name_strings;
2655 extern int track_unused_routines;
2656 extern int df_dont_note_global_symbols;
2657 extern uint32 df_total_size_before_stripping;
2658 extern uint32 df_total_size_after_stripping;
2660 extern char *typename(int type);
2661 extern int hash_code_from_string(char *p);
2662 extern int strcmpcis(char *p, char *q);
2663 extern int symbol_index(char *lexeme_text, int hashcode);
2664 extern void end_symbol_scope(int k);
2665 extern void describe_symbol(int k);
2666 extern void list_symbols(int level);
2667 extern void assign_marked_symbol(int index, int marker, int32 value, int type);
2668 extern void assign_symbol(int index, int32 value, int type);
2669 extern void issue_unused_warnings(void);
2670 extern void add_config_symbol_definition(char *symbol, int32 value);
2671 extern void add_symbol_replacement_mapping(int original, int renamed);
2672 extern int find_symbol_replacement(int *value);
2673 extern void df_note_function_start(char *name, uint32 address,
2674 int embedded_flag, brief_location source_line);
2675 extern void df_note_function_end(uint32 endaddress);
2676 extern void df_note_function_symbol(int symbol);
2677 extern void locate_dead_functions(void);
2678 extern uint32 df_stripped_address_for_address(uint32);
2679 extern uint32 df_stripped_offset_for_code_offset(uint32, int *);
2680 extern void df_prepare_function_iterate(void);
2681 extern uint32 df_next_function_iterate(int *);
2683 /* ------------------------------------------------------------------------- */
2684 /* Extern definitions for "syntax" */
2685 /* ------------------------------------------------------------------------- */
2687 extern int no_syntax_lines;
2689 extern void panic_mode_error_recovery(void);
2690 extern void get_next_token_with_directives(void);
2691 extern int parse_directive(int internal_flag);
2692 extern void parse_program(char *source);
2693 extern int32 parse_routine(char *source, int embedded_flag, char *name,
2694 int veneer_flag, int r_symbol);
2695 extern void parse_code_block(int break_label, int continue_label,
2698 /* ------------------------------------------------------------------------- */
2699 /* Extern definitions for "states" */
2700 /* ------------------------------------------------------------------------- */
2702 extern void match_close_bracket(void);
2703 extern void parse_statement(int break_label, int continue_label);
2704 extern int parse_label(void);
2706 /* ------------------------------------------------------------------------- */
2707 /* Extern definitions for "tables" */
2708 /* ------------------------------------------------------------------------- */
2710 extern uchar *zmachine_paged_memory;
2712 code_offset, actions_offset, preactions_offset,
2713 dictionary_offset, strings_offset, adjectives_offset,
2714 variables_offset, class_numbers_offset, individuals_offset,
2715 identifier_names_offset, prop_defaults_offset, prop_values_offset,
2716 static_memory_offset, array_names_offset, attribute_names_offset,
2717 action_names_offset, fake_action_names_offset,
2718 routine_names_offset, routines_array_offset, routine_flags_array_offset,
2719 global_names_offset, global_flags_array_offset,
2720 array_flags_array_offset, constant_names_offset, constants_array_offset,
2721 static_arrays_offset;
2723 arrays_offset, object_tree_offset, grammar_table_offset,
2724 abbreviations_offset; /* For Glulx */
2726 extern int32 Out_Size, Write_Code_At, Write_Strings_At;
2727 extern int32 RAM_Size, Write_RAM_At; /* For Glulx */
2729 extern int release_number, statusline_flag;
2730 extern int flags2_requirements[];
2731 extern int serial_code_given_in_program;
2732 extern char serial_code_buffer[];
2734 extern void construct_storyfile(void);
2735 extern void write_serial_number(char *buffer);
2737 /* ------------------------------------------------------------------------- */
2738 /* Extern definitions for "text" */
2739 /* ------------------------------------------------------------------------- */
2741 extern uchar *low_strings, *low_strings_top;
2742 extern char *all_text, *all_text_top;
2744 extern int no_abbreviations;
2745 extern int abbrevs_lookup_table_made, is_abbreviation;
2746 extern uchar *abbreviations_at;
2747 extern int *abbrev_values;
2748 extern int *abbrev_quality;
2749 extern int *abbrev_freqs;
2751 extern int32 total_chars_trans, total_bytes_trans,
2752 zchars_trans_in_last_string;
2753 extern int put_strings_in_low_memory;
2754 extern int dict_entries;
2755 extern uchar *dictionary, *dictionary_top;
2756 extern int *final_dict_order;
2758 extern memory_block static_strings_area;
2759 extern int32 static_strings_extent;
2761 /* And now, a great many declarations for dealing with Glulx string
2764 extern int32 no_strings, no_dynamic_strings;
2765 extern int no_unicode_chars;
2767 typedef struct unicode_usage_s unicode_usage_t;
2768 struct unicode_usage_s {
2770 unicode_usage_t *next;
2773 extern unicode_usage_t *unicode_usage_entries;
2775 /* This is the maximum number of (8-bit) bytes that can encode a single
2776 Huffman entity. Four should be plenty, unless someone starts encoding
2777 an ideographic language. */
2778 #define MAXHUFFBYTES (4)
2780 typedef struct huffbitlist_struct {
2781 uchar b[MAXHUFFBYTES];
2783 typedef struct huffentity_struct {
2796 extern huffentity_t *huff_entities;
2798 extern int32 compression_table_size, compression_string_size;
2799 extern int32 *compressed_offsets;
2800 extern int no_huff_entities;
2801 extern int huff_abbrev_start, huff_dynam_start, huff_unicode_start;
2802 extern int huff_entity_root;
2804 extern void compress_game_text(void);
2806 /* end of the Glulx string compression stuff */
2808 extern void ao_free_arrays(void);
2809 extern int32 compile_string(char *b, int strctx);
2810 extern uchar *translate_text(uchar *p, uchar *p_limit, char *s_text, int strctx);
2811 extern void optimise_abbreviations(void);
2812 extern void make_abbreviation(char *text);
2813 extern void show_dictionary(void);
2814 extern void word_to_ascii(uchar *p, char *result);
2815 extern void write_dictionary_to_transcript(void);
2816 extern void sort_dictionary(void);
2817 extern void dictionary_prepare(char *dword, uchar *optresult);
2818 extern int dictionary_add(char *dword, int x, int y, int z);
2819 extern void dictionary_set_verb_number(char *dword, int to);
2820 extern int compare_sorts(uchar *d1, uchar *d2);
2821 extern void copy_sorts(uchar *d1, uchar *d2);
2823 /* ------------------------------------------------------------------------- */
2824 /* Extern definitions for "veneer" */
2825 /* ------------------------------------------------------------------------- */
2827 extern int veneer_mode;
2828 extern int32 veneer_routine_address[];
2830 extern void compile_initial_routine(void);
2831 extern assembly_operand veneer_routine(int code);
2832 extern void compile_veneer(void);
2834 /* ------------------------------------------------------------------------- */
2835 /* Extern definitions for "verbs" */
2836 /* ------------------------------------------------------------------------- */
2838 extern int no_adjectives, no_Inform_verbs, no_grammar_token_routines,
2839 no_fake_actions, no_actions, no_grammar_lines, no_grammar_tokens,
2840 grammar_version_number;
2841 extern int32 grammar_version_symbol;
2842 extern verbt *Inform_verbs;
2843 extern uchar *grammar_lines;
2844 extern int32 grammar_lines_top;
2845 extern int32 *action_byte_offset,
2846 *grammar_token_routine,
2849 extern void find_the_actions(void);
2850 extern void make_fake_action(void);
2851 extern assembly_operand action_of_name(char *name);
2852 extern void make_verb(void);
2853 extern void extend_verb(void);
2854 extern void list_verb_table(void);
2856 /* ========================================================================= */