1 /* ------------------------------------------------------------------------- */
2 /* Header file for Inform: Z-machine ("Infocom" format) compiler */
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 /* *** To compile this program in one of the existing ports, you must */
22 /* at least change the machine definition (on the next page). */
23 /* In most cases no other work will be needed. *** */
27 /* Machine/host OS definitions (in alphabetical order) */
28 /* Default definitions */
29 /* Standard ANSI inclusions, macro definitions, structures */
30 /* Definitions of internal code numbers */
31 /* Extern declarations for linkage (in alphabetical order of file) */
33 /* ------------------------------------------------------------------------- */
35 #define RELEASE_DATE "1 Oct 2016"
36 #define RELEASE_NUMBER 1634
37 #define GLULX_RELEASE_NUMBER 38
38 #define MODULE_VERSION_NUMBER 1
39 #define VNUMBER RELEASE_NUMBER
41 /* N indicates an intermediate release for Inform 7 */
42 /*#define RELEASE_SUFFIX "N"*/
44 /* ------------------------------------------------------------------------- */
45 /* Our host machine or OS for today is... */
47 /* [ Inform should compile (possibly with warnings) and work safely */
50 /* #define AMIGA - for the Commodore Amiga under SAS/C */
51 /* #define ARCHIMEDES - for Acorn RISC OS machines under Norcroft C */
52 /* #define ATARIST - for the Atari ST */
53 /* #define BEOS - for the BeBox */
54 /* #define LINUX - for Linux under gcc (essentially as Unix) */
55 /* #define MACOS - for the Apple Mac with OS X (another Unix) */
56 /* #define MAC_CLASSIC - for the Apple Mac under Think C or Codewarrior */
57 /* #define MAC_MPW - for MPW under Codewarrior (and maybe Think C) */
58 /* #define OS2 - for OS/2 32-bit mode under IBM's C Set++ */
59 /* #define PC - for 386+ IBM PCs, eg. Microsoft Visual C/C++ */
60 /* #define PC_QUICKC - for small IBM PCs under QuickC */
61 /* #define PC_WIN32 - for Borland C++ or Microsoft Visual C++ */
62 /* #define UNIX - for Unix under gcc (or big IBM PC under djgpp) */
63 /* #define VMS - for VAX or ALPHA under DEC C, but not VAX C */
65 /* In most cases executables are already available at */
66 /* http://www.ifarchive.org/, and these are sometimes enhanced with */
67 /* e.g. windowed interfaces whose source is not archived with the */
68 /* main Inform source.] */
70 /* (If no machine is defined, then cautious #defines will be made. In */
71 /* most cases, porting to a new machine is a matter of carefully filling */
72 /* out a block of definitions like those below.) */
73 /* ------------------------------------------------------------------------- */
77 /* ------------------------------------------------------------------------- */
78 /* The first task is to include the ANSI header files, and typedef */
79 /* suitable 32-bit integer types. */
80 /* ------------------------------------------------------------------------- */
92 #if SCHAR_MAX >= 0x7FFFFFFFL && SCHAR_MIN <= -0x7FFFFFFFL
93 typedef signed char int32;
94 typedef unsigned char uint32;
95 #elif SHRT_MAX >= 0x7FFFFFFFL && SHRT_MIN <= -0x7FFFFFFFL
96 typedef signed short int int32;
97 typedef unsigned short int uint32;
98 #elif INT_MAX >= 0x7FFFFFFFL && INT_MIN <= -0x7FFFFFFFL
99 typedef signed int int32;
100 typedef unsigned int uint32;
101 #elif LONG_MAX >= 0x7FFFFFFFL && LONG_MIN <= -0x7FFFFFFFL
102 typedef signed long int int32;
103 typedef unsigned long int uint32;
105 #error No type large enough to support 32-bit integers.
108 /* VAX C does not provide these limit constants, contrary to ANSI */
110 typedef unsigned int uint32;
113 /* ------------------------------------------------------------------------- */
114 /* The next part of this file contains blocks of definitions, one for */
115 /* each port, of machine or OS-dependent constants needed by Inform. */
117 /* 1. MACHINE_STRING should be set to the name of the machine or OS. */
119 /* 2. Some miscellaneous #define options (set if the constant is */
120 /* defined, otherwise not set): */
122 /* USE_TEMPORARY_FILES - use scratch files for workspace, not memory, */
124 /* PROMPT_INPUT - prompt input (don't use Unix-style command line) */
125 /* TIME_UNAVAILABLE - don't use ANSI time routines to work out today's */
127 /* CHAR_IS_UNSIGNED - if on your compiler the type "char" is unsigned */
128 /* by default, you should define this */
129 /* HAS_REALPATH - the POSIX realpath() function is available to */
130 /* find the absolute path to a file */
132 /* 3. An estimate of the typical amount of memory likely to be free */
133 /* should be given in DEFAULT_MEMORY_SIZE. */
134 /* For most modern machines, HUGE_SIZE is the appropriate setting, but */
135 /* some older micros may benefit from SMALL_SIZE. */
136 /* ------------------------------------------------------------------------- */
142 /* ------------------------------------------------------------------------- */
143 /* 4. Filenaming definitions: */
145 /* It's assumed that the host OS has the concept of subdirectories and */
146 /* has "pathnames", that is, filenames giving a chain of subdirectories */
147 /* divided by the FN_SEP (filename separator) character: e.g. for Unix */
148 /* FN_SEP is defined below as '/' and a typical name is */
149 /* "users/graham/jigsaw.z5". */
150 /* White space is not allowed in filenames, and nor is the special */
151 /* character FN_ALT, which unless defined here will be a comma and will */
152 /* be used to separate alternative locations in a path variable. */
154 /* If NO_FILE_EXTENSIONS is undefined then the OS allows "file extensions" */
155 /* of 1 to 3 alphanumeric characters like ".txt" (for text files), ".z5" */
156 /* (for game files), etc., to indicate the file's type (and, crucially, */
157 /* regards the same filename but with different extensions -- e.g., */
158 /* "frog.amp" and "frog.lil" -- as being different names). */
159 /* (The file extensions defined below are widely accepted, so please use */
160 /* them unless there's a good reason why not.) */
162 /* You should then define STANDARD_DIRECTORIES (you can define it anyway) */
163 /* in which case Inform will expect by default that files are sorted out */
164 /* by being put into suitable directories (e.g., a "games" directory for */
167 /* If it's convenient for your port you can alter the detailed definitions */
168 /* which these broad settings make. Be careful if NO_FILE_EXTENSIONS */
169 /* is set without STANDARD_DIRECTORIES, as then Inform may */
170 /* overwrite its source with object code. */
172 /* 5. Filenames (or code related to filenames) for the three temporary */
173 /* files. These only exist during compilation (and only if -F1 is set). */
174 /* Temporary_Name is the body of a filename to use */
175 /* (if you don't set this, it becomes "Inftemp") and Temporary_Directory */
176 /* is the directory path for the files to go in (which can be altered on */
177 /* the command line). On some multi-tasking OSs these filenames ought to */
178 /* include a number uniquely identifying the process: to indicate this, */
179 /* define INCLUDE_TASK_ID and provide some code... */
181 /* #define INCLUDE_TASK_ID */
182 /* #ifdef INFORM_FILE */
183 /* static int32 unique_task_id(void) */
184 /* { ...some code returning your task ID... */
188 /* 6. Any other definitions specific to the OS or machine. */
189 /* (In particular DEFAULT_ERROR_FORMAT is 0 on most machines and 1 on PCs; */
190 /* it controls the style of error messages, which is important for some */
191 /* error-throwback debugging tools.) */
192 /* ------------------------------------------------------------------------- */
194 /* ========================================================================= */
195 /* The blocks now follow in alphabetical order. */
196 /* ------------------------------------------------------------------------- */
198 /* ------------------------------------------------------------------------- */
201 #define MACHINE_STRING "Amiga"
203 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
207 #define __USE_SYSBASE
208 #include <proto/exec.h>
209 #define INCLUDE_TASK_ID
210 #define Temporary_Directory "T:"
211 #ifdef MAIN_INFORM_FILE
212 static int32 unique_task_id(void)
213 { return (int32)FindTask(NULL);
217 /* ------------------------------------------------------------------------- */
218 /* ARCHIMEDES block: Acorn/RISC OS settings */
219 /* ------------------------------------------------------------------------- */
222 #define MACHINE_STRING "RISC OS"
224 #define CHAR_IS_UNSIGNED
226 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
229 #define STANDARD_DIRECTORIES
230 #define NO_FILE_EXTENSIONS
231 #define Source_Directory "inform"
232 #define ICL_Directory "ICL"
234 #define ENABLE_TEMPORARY_PATH
235 #define Temporary_Directory "ram:"
237 #define ARC_THROWBACK
239 /* ------------------------------------------------------------------------- */
241 /* ------------------------------------------------------------------------- */
244 #define MACHINE_STRING "Atari ST"
246 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
251 #define Temporary_Directory "/tmp"
252 #define INCLUDE_TASK_ID
253 #ifdef MAIN_INFORM_FILE
254 static int32 unique_task_id(void)
255 { return (int32)getpid();
260 /* ------------------------------------------------------------------------- */
262 /* ------------------------------------------------------------------------- */
265 #define MACHINE_STRING "BeOS"
267 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
270 #define FILE_EXTENSIONS
272 #define Temporary_Directory "/tmp"
274 /* ------------------------------------------------------------------------- */
276 /* ------------------------------------------------------------------------- */
279 #define MACHINE_STRING "Linux"
283 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
287 #define Temporary_Directory "/tmp"
291 /* ------------------------------------------------------------------------- */
292 /* Macintosh block */
293 /* ------------------------------------------------------------------------- */
301 #define MACHINE_STRING "Macintosh Programmer's Workshop"
303 #define MACHINE_STRING "Macintosh"
307 #define EXTERNAL_SHELL
315 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
319 #define Include_Extension ".h"
323 #include "TB Inform.h"
326 #include <CursorCtl.h>
327 #define DEFAULT_ERROR_FORMAT 2
330 /* ------------------------------------------------------------------------- */
332 /* ------------------------------------------------------------------------- */
335 #define MACHINE_STRING "OS/2"
337 #define CHAR_IS_UNSIGNED
339 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
343 /* ------------------------------------------------------------------------- */
345 /* ------------------------------------------------------------------------- */
348 #define MACHINE_STRING "MacOS"
352 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
356 #define Temporary_Directory "/tmp"
357 #define INCLUDE_TASK_ID
358 #define _POSIX_C_SOURCE 199506L
359 #define _XOPEN_SOURCE 500
360 #ifdef MAIN_INFORM_FILE
361 #include <sys/types.h>
363 static int32 unique_task_id(void)
364 { return (int32)getpid();
370 /* ------------------------------------------------------------------------- */
371 /* PC and PC_QUICKC block */
372 /* ------------------------------------------------------------------------- */
379 #define MACHINE_STRING "PC"
381 #define USE_TEMPORARY_FILES
384 #define DEFAULT_MEMORY_SIZE SMALL_SIZE
386 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
391 #define DEFAULT_ERROR_FORMAT 1
393 /* ------------------------------------------------------------------------- */
395 /* ------------------------------------------------------------------------- */
398 #define MACHINE_STRING "Win32"
402 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
406 #define DEFAULT_ERROR_FORMAT 1
408 #ifdef _MSC_VER /* Microsoft Visual C++ */
409 #define snprintf _snprintf
411 #define isinf(x) (!_isnan(x) && !_finite(x))
414 /* ------------------------------------------------------------------------- */
416 /* ------------------------------------------------------------------------- */
419 #ifndef MACHINE_STRING
420 #define MACHINE_STRING "Unix"
425 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
430 #define Temporary_Directory "/tmp"
431 #define INCLUDE_TASK_ID
432 #ifdef MAIN_INFORM_FILE
434 static int32 unique_task_id(void)
435 { return (int32)getpid();
439 /* ------------------------------------------------------------------------- */
440 /* VMS (Dec VAX and Alpha) block */
441 /* ------------------------------------------------------------------------- */
449 #define MACHINE_STRING "Alpha/VMS"
451 #define MACHINE_STRING "VAX/VMS"
454 #define CHAR_IS_UNSIGNED
456 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
459 #define Code_Extension ".zip"
460 #define V4Code_Extension ".zip"
461 #define V5Code_Extension ".zip"
462 #define V6Code_Extension ".zip"
463 #define V7Code_Extension ".zip"
464 #define V8Code_Extension ".zip"
466 /* ========================================================================= */
467 /* Default settings: */
468 /* ------------------------------------------------------------------------- */
470 #ifndef NO_FILE_EXTENSIONS
471 #define FILE_EXTENSIONS
474 #ifndef Transcript_File
475 #ifdef FILE_EXTENSIONS
476 #define Transcript_File "gametext.txt"
478 #define Transcript_File "gametext"
481 #ifndef Debugging_File
482 #ifdef FILE_EXTENSIONS
483 #define Debugging_File "gameinfo.dbg"
485 #define Debugging_File "gamedebug"
489 #ifdef FILE_EXTENSIONS
490 #ifndef Source_Extension
491 #define Source_Extension ".inf"
493 #ifndef Include_Extension
494 #define Include_Extension ".h"
496 #ifndef Code_Extension
497 #define Code_Extension ".z3"
499 #ifndef V4Code_Extension
500 #define V4Code_Extension ".z4"
502 #ifndef V5Code_Extension
503 #define V5Code_Extension ".z5"
505 #ifndef V6Code_Extension
506 #define V6Code_Extension ".z6"
508 #ifndef V7Code_Extension
509 #define V7Code_Extension ".z7"
511 #ifndef V8Code_Extension
512 #define V8Code_Extension ".z8"
514 #ifndef GlulxCode_Extension
515 #define GlulxCode_Extension ".ulx"
517 #ifndef Module_Extension
518 #define Module_Extension ".m5"
520 #ifndef ICL_Extension
521 #define ICL_Extension ".icl"
526 #define Source_Extension ""
527 #define Include_Extension ""
528 #define Code_Extension ""
529 #define V4Code_Extension ""
530 #define V5Code_Extension ""
531 #define V6Code_Extension ""
532 #define V7Code_Extension ""
533 #define V8Code_Extension ""
534 #define GlulxCode_Extension ""
535 #define Module_Extension ""
536 #define ICL_Extension ""
539 #ifdef STANDARD_DIRECTORIES
540 #ifndef Source_Directory
541 #define Source_Directory "source"
543 #ifndef Include_Directory
544 #define Include_Directory "library"
546 #ifndef Code_Directory
547 #define Code_Directory "games"
549 #ifndef Module_Directory
550 #define Module_Directory "modules"
552 #ifndef Temporary_Directory
553 #define Temporary_Directory ""
555 #ifndef ICL_Directory
556 #define ICL_Directory ""
561 #ifndef Source_Directory
562 #define Source_Directory ""
564 #ifndef Include_Directory
565 #define Include_Directory ""
567 #ifndef Code_Directory
568 #define Code_Directory ""
570 #ifndef Module_Directory
571 #define Module_Directory ""
573 #ifndef Temporary_Directory
574 #define Temporary_Directory ""
576 #ifndef ICL_Directory
577 #define ICL_Directory ""
593 #ifndef Temporary_File
594 #define Temporary_File "Inftemp"
597 #ifndef DEFAULT_ERROR_FORMAT
598 #define DEFAULT_ERROR_FORMAT 0
601 #ifndef DEFAULT_MEMORY_SIZE
602 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
605 #ifndef CHAR_IS_UNSIGNED
606 typedef unsigned char uchar;
611 #if defined(__GNUC__) || defined(__clang__)
612 #define NORETURN __attribute__((__noreturn__))
613 #endif /* defined(__GNUC__) || defined(__clang__) */
619 /* ------------------------------------------------------------------------- */
620 /* A macro (rather than constant) definition: */
621 /* ------------------------------------------------------------------------- */
624 void _huge * halloc(long, size_t);
626 #define subtract_pointers(p1,p2) (long)((char _huge *)p1-(char _huge *)p2)
628 #define subtract_pointers(p1,p2) (((char *) p1)-((char *) p2))
631 /* ------------------------------------------------------------------------- */
632 /* SEEK_SET is a constant which should be defined in the ANSI header files */
633 /* but which is not present in some implementations: it's used as a */
634 /* parameter for "fseek", defined in "stdio". In pre-ANSI C, the value */
635 /* 0 was used as a parameter instead, hence the definition below. */
636 /* ------------------------------------------------------------------------- */
642 /* ------------------------------------------------------------------------- */
643 /* A large block of #define'd constant values follows. */
644 /* ------------------------------------------------------------------------- */
649 /* These checked the glulx_mode global during development, but are no
651 #define ASSERT_ZCODE() (0)
652 #define ASSERT_GLULX() (0)
655 #define ReadInt32(ptr) \
656 ( (((int32)(((uchar *)(ptr))[0])) << 24) \
657 | (((int32)(((uchar *)(ptr))[1])) << 16) \
658 | (((int32)(((uchar *)(ptr))[2])) << 8) \
659 | (((int32)(((uchar *)(ptr))[3])) ) )
661 #define ReadInt16(ptr) \
662 ( (((int32)(((uchar *)(ptr))[0])) << 8) \
663 | (((int32)(((uchar *)(ptr))[1])) ) )
665 #define WriteInt32(ptr, val) \
666 ((ptr)[0] = (uchar)(((int32)(val)) >> 24), \
667 (ptr)[1] = (uchar)(((int32)(val)) >> 16), \
668 (ptr)[2] = (uchar)(((int32)(val)) >> 8), \
669 (ptr)[3] = (uchar)(((int32)(val)) ) )
671 #define WriteInt16(ptr, val) \
672 ((ptr)[0] = (uchar)(((int32)(val)) >> 8), \
673 (ptr)[1] = (uchar)(((int32)(val)) ) )
675 /* ------------------------------------------------------------------------- */
676 /* If your compiler doesn't recognise \t, and you use ASCII, you could */
677 /* define T_C as (char) 9; failing that, it _must_ be defined as ' ' */
678 /* (space) and is _not_ allowed to be 0 or any recognisable character. */
679 /* ------------------------------------------------------------------------- */
681 #define TAB_CHARACTER '\t'
683 /* ------------------------------------------------------------------------- */
685 /* ------------------------------------------------------------------------- */
687 #define MAX_ERRORS 100
688 #define MAX_IDENTIFIER_LENGTH 32
689 #define MAX_ABBREV_LENGTH 64
690 #define MAX_DICT_WORD_SIZE 40
691 #define MAX_DICT_WORD_BYTES (40*4)
692 #define MAX_NUM_ATTR_BYTES 39
694 #define VENEER_CONSTRAINT_ON_CLASSES_Z 256
695 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_Z 128
696 #define VENEER_CONSTRAINT_ON_CLASSES_G 32768
697 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_G 32768
698 #define VENEER_CONSTRAINT_ON_CLASSES \
699 (glulx_mode ? VENEER_CONSTRAINT_ON_CLASSES_G \
700 : VENEER_CONSTRAINT_ON_CLASSES_Z)
701 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE \
702 (glulx_mode ? VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_G \
703 : VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_Z)
705 #define GLULX_HEADER_SIZE 36
706 /* Number of bytes in the header. */
707 #define GLULX_STATIC_ROM_SIZE 24
708 /* Number of bytes in the Inform-specific block right after the header. */
709 #define GPAGESIZE 256
710 /* All Glulx memory boundaries must be multiples of GPAGESIZE. */
712 /* ------------------------------------------------------------------------- */
713 /* Structure definitions (there are a few others local to files) */
714 /* ------------------------------------------------------------------------- */
716 typedef struct assembly_operand_t
719 int symtype; /* 6.30 */
720 int symflags; /* 6.30 */
724 #define INITAOTV(aop, typ, val) ((aop)->type=(typ), (aop)->value=(val), (aop)->marker=0, (aop)->symtype=0, (aop)->symflags=0)
725 #define INITAOT(aop, typ) INITAOTV(aop, typ, 0)
726 #define INITAO(aop) INITAOTV(aop, 0, 0)
728 #define MAX_LINES_PER_VERB 32
729 typedef struct verbt {
731 int l[MAX_LINES_PER_VERB];
734 typedef struct prop {
736 assembly_operand ao[32];
739 /* Only one of this object. */
740 typedef struct fpropt {
746 typedef struct objecttz {
748 int parent, next, child;
752 typedef struct propg {
760 /* Only one of this object. */
761 typedef struct fproptg {
762 uchar atts[MAX_NUM_ATTR_BYTES];
766 assembly_operand *propdata;
770 typedef struct objecttg {
771 /* attributes are stored in a separate array */
773 int32 parent, next, child;
778 typedef struct maybe_file_position_S
781 } maybe_file_position;
783 typedef struct debug_location_s
785 int32 beginning_byte_index;
786 int32 end_byte_index;
787 int32 beginning_line_number;
788 int32 end_line_number;
789 int32 beginning_character_number;
790 int32 end_character_number;
791 int32 orig_file_index;
792 int32 orig_beg_line_number;
793 int32 orig_beg_char_number;
794 /* We only track the beginning #origsource location, not the end. */
797 typedef struct debug_locations_s
798 { debug_location location;
799 struct debug_locations_s *next;
803 typedef struct brief_location_s
806 int32 orig_file_index;
807 int32 orig_line_number;
810 typedef struct debug_location_beginning_s
811 { debug_locations *head;
812 int32 beginning_byte_index;
813 int32 beginning_line_number;
814 int32 beginning_character_number;
815 int32 orig_file_index;
816 int32 orig_beg_line_number;
817 int32 orig_beg_char_number;
818 } debug_location_beginning;
820 typedef struct keyword_group_s
821 { char *keywords[120];
822 int change_token_type;
827 typedef struct token_data_s
829 int32 value; /* ###-long */
831 int symtype; /* 6.30 */
832 int symflags; /* 6.30 */
834 debug_location location;
837 typedef struct FileId_s /* Source code file identifier: */
838 { char *filename; /* The filename (after translation) */
839 FILE *handle; /* Handle of file (when open), or
841 int is_input; /* Is this a source file that we are
842 parsing? If not, this is an
843 origsource filename (and handle
847 typedef struct ErrorPosition_s
858 /* A memory block can hold at most ALLOC_CHUNK_SIZE * 72: */
860 extern int ALLOC_CHUNK_SIZE;
862 typedef struct memory_block_s
869 /* This serves for both Z-code and Glulx instructions. Glulx doesn't use
870 the text, store_variable_number, branch_label_number, or branch_flag
872 typedef struct assembly_instruction_t
873 { int internal_number;
874 int store_variable_number;
875 int32 branch_label_number;
879 assembly_operand operand[8];
880 } assembly_instruction;
882 typedef struct expression_tree_node_s
884 /* Data used in tree construction */
887 int operator_number; /* Only meaningful for non-leaves */
888 assembly_operand value; /* Only meaningful for leaves */
890 /* Attributes synthesised during code generation */
892 int must_produce_value; /* e.g. FALSE in a void context */
894 int label_after; /* -1, or "put this label after code" */
895 int to_expression; /* TRUE if a condition used as numeric val */
896 int true_label; /* On condition "true", jump to this (or keep
898 int false_label; /* Likewise if the condition is "false". */
900 } expression_tree_node;
902 typedef struct operator_s
903 { int precedence; /* Level 0 to 13 (13 is highest) */
904 int token_type; /* Lexical token type */
905 int token_value; /* Lexical token value */
906 int usage; /* Infix (IN_U), prefix or postfix */
907 int associativity; /* Left (L_A), right (R_A)
908 or 0 for "it is an error to
909 implicitly associate this" */
910 int requires_lvalue; /* TRUE if the first operand must
911 be an "lvalue" (the name of some
912 storage object, such as a variable
913 or an array entry) */
914 int opcode_number_z; /* Translation number (see below) */
915 int opcode_number_g; /* Translation number (see below) */
916 int side_effect; /* TRUE if evaluating the operator
917 has potential side-effects in
918 terms of changing the Z-machine */
919 int negation; /* 0 for an unconditional operator,
920 otherwise the negation operator */
921 char *description; /* Text describing the operator
922 for error messages and tracing */
925 /* The translation number of an operator is as follows:
928 an internal opcode number if the operator can be translated
929 directly to a single Z-machine opcode;
930 400+n if it can be translated to branch opcode n;
931 800+n if to the negated form of branch opcode n;
932 (using n = 200, 201 for two conditions requiring special
936 an internal opcode number if the operator can be translated
937 directly to a single Glulx opcode;
938 FIRST_CC to LAST_CC if it is a condition;
941 /* ------------------------------------------------------------------------- */
942 /* Assembly operand types. */
943 /* ------------------------------------------------------------------------- */
945 /* For Z-machine... */
947 #define LONG_CONSTANT_OT 0 /* General constant */
948 #define SHORT_CONSTANT_OT 1 /* Constant in range 0 to 255 */
949 #define VARIABLE_OT 2 /* Variable (global, local or sp) */
950 #define OMITTED_OT 3 /* Value used in type field to indicate
951 that no operand is supplied */
952 #define EXPRESSION_OT 4 /* Meaning: to determine this value, run code
953 equivalent to the expression tree whose
954 root node-number is the value given */
958 /* #define OMITTED_OT 3 */ /* Same as above */
959 /* #define EXPRESSION_OT 4 */ /* Same as above */
960 #define CONSTANT_OT 5 /* Four-byte constant */
961 #define HALFCONSTANT_OT 6 /* Two-byte constant */
962 #define BYTECONSTANT_OT 7 /* One-byte constant */
963 #define ZEROCONSTANT_OT 8 /* Constant zero (no bytes of data) */
964 #define SYSFUN_OT 9 /* System function value */
965 #define DEREFERENCE_OT 10 /* Value at this address */
966 #define GLOBALVAR_OT 11 /* Global variable */
967 #define LOCALVAR_OT 12 /* Local variable or sp */
969 /* ------------------------------------------------------------------------- */
970 /* Internal numbers representing assemble-able Z-opcodes */
971 /* ------------------------------------------------------------------------- */
982 #define test_attr_zc 9
983 #define set_attr_zc 10
984 #define clear_attr_zc 11
986 #define insert_obj_zc 13
989 #define get_prop_zc 16
990 #define get_prop_addr_zc 17
991 #define get_next_prop_zc 18
1000 #define put_prop_zc 27
1002 #define print_char_zc 29
1003 #define print_num_zc 30
1004 #define random_zc 31
1007 #define split_window_zc 34
1008 #define set_window_zc 35
1009 #define output_stream_zc 36
1010 #define input_stream_zc 37
1011 #define sound_effect_zc 38
1013 #define get_sibling_zc 40
1014 #define get_child_zc 41
1015 #define get_parent_zc 42
1016 #define get_prop_len_zc 43
1019 #define print_addr_zc 46
1020 #define remove_obj_zc 47
1021 #define print_obj_zc 48
1024 #define print_paddr_zc 51
1028 #define rfalse_zc 55
1030 #define print_ret_zc 57
1033 #define restore_zc 60
1034 #define restart_zc 61
1035 #define ret_popped_zc 62
1038 #define new_line_zc 65
1039 #define show_status_zc 66
1040 #define verify_zc 67
1041 #define call_2s_zc 68
1042 #define call_vs_zc 69
1044 #define call_vs2_zc 71
1045 #define erase_window_zc 72
1046 #define erase_line_zc 73
1047 #define set_cursor_zc 74
1048 #define get_cursor_zc 75
1049 #define set_text_style_zc 76
1050 #define buffer_mode_zc 77
1051 #define read_char_zc 78
1052 #define scan_table_zc 79
1053 #define call_1s_zc 80
1054 #define call_2n_zc 81
1055 #define set_colour_zc 82
1057 #define call_vn_zc 84
1058 #define call_vn2_zc 85
1059 #define tokenise_zc 86
1060 #define encode_text_zc 87
1061 #define copy_table_zc 88
1062 #define print_table_zc 89
1063 #define check_arg_count_zc 90
1064 #define call_1n_zc 91
1066 #define piracy_zc 93
1067 #define log_shift_zc 94
1068 #define art_shift_zc 95
1069 #define set_font_zc 96
1070 #define save_undo_zc 97
1071 #define restore_undo_zc 98
1072 #define draw_picture_zc 99
1073 #define picture_data_zc 100
1074 #define erase_picture_zc 101
1075 #define set_margins_zc 102
1076 #define move_window_zc 103
1077 #define window_size_zc 104
1078 #define window_style_zc 105
1079 #define get_wind_prop_zc 106
1080 #define scroll_window_zc 107
1081 #define pop_stack_zc 108
1082 #define read_mouse_zc 109
1083 #define mouse_window_zc 110
1084 #define push_stack_zc 111
1085 #define put_wind_prop_zc 112
1086 #define print_form_zc 113
1087 #define make_menu_zc 114
1088 #define picture_table_zc 115
1089 #define print_unicode_zc 116
1090 #define check_unicode_zc 117
1093 /* ------------------------------------------------------------------------- */
1094 /* Internal numbers representing assemble-able Glulx opcodes */
1095 /* ------------------------------------------------------------------------- */
1107 #define bitnot_gc 10
1108 #define shiftl_gc 11
1109 #define sshiftr_gc 12
1110 #define ushiftr_gc 13
1125 #define return_gc 28
1128 #define tailcall_gc 31
1135 #define aloads_gc 38
1136 #define aloadb_gc 39
1137 #define aloadbit_gc 40
1138 #define astore_gc 41
1139 #define astores_gc 42
1140 #define astoreb_gc 43
1141 #define astorebit_gc 44
1142 #define stkcount_gc 45
1143 #define stkpeek_gc 46
1144 #define stkswap_gc 47
1145 #define stkroll_gc 48
1146 #define stkcopy_gc 49
1147 #define streamchar_gc 50
1148 #define streamnum_gc 51
1149 #define streamstr_gc 52
1150 #define gestalt_gc 53
1151 #define debugtrap_gc 54
1152 #define getmemsize_gc 55
1153 #define setmemsize_gc 56
1154 #define jumpabs_gc 57
1155 #define random_gc 58
1156 #define setrandom_gc 59
1158 #define verify_gc 61
1159 #define restart_gc 62
1161 #define restore_gc 64
1162 #define saveundo_gc 65
1163 #define restoreundo_gc 66
1164 #define protect_gc 67
1166 #define getstringtbl_gc 69
1167 #define setstringtbl_gc 70
1168 #define getiosys_gc 71
1169 #define setiosys_gc 72
1170 #define linearsearch_gc 73
1171 #define binarysearch_gc 74
1172 #define linkedsearch_gc 75
1174 #define callfi_gc 77
1175 #define callfii_gc 78
1176 #define callfiii_gc 79
1177 #define streamunichar_gc 80
1180 #define malloc_gc 83
1182 #define accelfunc_gc 85
1183 #define accelparam_gc 86
1184 #define numtof_gc 87
1185 #define ftonumz_gc 88
1186 #define ftonumn_gc 89
1204 #define atan2_gc 107
1211 #define jisnan_gc 114
1212 #define jisinf_gc 115
1214 /* ------------------------------------------------------------------------- */
1215 /* Index numbers into the keyword group "opcode_macros_g" (see "lexer.c") */
1216 /* ------------------------------------------------------------------------- */
1222 #define SYMBOL_TT 0 /* value = index in symbol table */
1223 #define NUMBER_TT 1 /* value = the number */
1224 #define DQ_TT 2 /* no value */
1225 #define SQ_TT 3 /* no value */
1226 #define SEP_TT 4 /* value = the _SEP code */
1227 #define EOF_TT 5 /* no value */
1229 #define STATEMENT_TT 100 /* a statement keyword */
1230 #define SEGMENT_MARKER_TT 101 /* with/has/class etc. */
1231 #define DIRECTIVE_TT 102 /* a directive keyword */
1232 #define CND_TT 103 /* in/has/etc. */
1233 #define SYSFUN_TT 105 /* built-in function */
1234 #define LOCAL_VARIABLE_TT 106 /* local variable */
1235 #define OPCODE_NAME_TT 107 /* opcode name */
1236 #define MISC_KEYWORD_TT 108 /* keyword like "char" used in
1237 syntax for a statement */
1238 #define DIR_KEYWORD_TT 109 /* keyword like "meta" used in
1239 syntax for a directive */
1240 #define TRACE_KEYWORD_TT 110 /* keyword used in debugging */
1241 #define SYSTEM_CONSTANT_TT 111 /* such as "code_offset" */
1242 #define OPCODE_MACRO_TT 112 /* fake opcode for compatibility */
1244 #define OP_TT 200 /* value = operator no */
1245 #define ENDEXP_TT 201 /* no value */
1246 #define SUBOPEN_TT 202 /* ( used for subexpr */
1247 #define SUBCLOSE_TT 203 /* ) used to close subexp */
1248 #define LARGE_NUMBER_TT 204 /* constant not in range 0-255 */
1249 #define SMALL_NUMBER_TT 205 /* constant in range 0-255 */
1250 /* In Glulx, that's the range -0x8000 to 0x7fff instead. */
1251 #define VARIABLE_TT 206 /* variable name */
1252 #define DICTWORD_TT 207 /* literal 'word' */
1253 #define ACTION_TT 208 /* action name */
1255 #define VOID_CONTEXT 1
1256 #define CONDITION_CONTEXT 2
1257 #define CONSTANT_CONTEXT 3
1258 #define QUANTITY_CONTEXT 4
1259 #define ACTION_Q_CONTEXT 5
1260 #define ASSEMBLY_CONTEXT 6
1261 #define ARRAY_CONTEXT 7
1262 #define FORINIT_CONTEXT 8
1263 #define RETURN_Q_CONTEXT 9
1265 #define LOWEST_SYSTEM_VAR_NUMBER 249 /* globals 249 to 255 are used
1266 in compiled code (Z-code
1267 only; in Glulx, the range can
1270 /* ------------------------------------------------------------------------- */
1271 /* Symbol flag definitions (in no significant order) */
1272 /* ------------------------------------------------------------------------- */
1274 #define UNKNOWN_SFLAG 1
1275 #define REPLACE_SFLAG 2
1276 #define USED_SFLAG 4
1277 #define DEFCON_SFLAG 8
1278 #define STUB_SFLAG 16
1279 #define IMPORT_SFLAG 32
1280 #define EXPORT_SFLAG 64
1281 #define ALIASED_SFLAG 128
1283 #define CHANGE_SFLAG 256
1284 #define SYSTEM_SFLAG 512
1285 #define INSF_SFLAG 1024
1286 #define UERROR_SFLAG 2048
1287 #define ACTION_SFLAG 4096
1288 #define REDEFINABLE_SFLAG 8192
1289 #define STAR_SFLAG 16384
1291 /* ------------------------------------------------------------------------- */
1292 /* Symbol type definitions */
1293 /* ------------------------------------------------------------------------- */
1297 #define GLOBAL_VARIABLE_T 3
1299 #define CONSTANT_T 5
1300 #define ATTRIBUTE_T 6
1301 #define PROPERTY_T 7
1302 #define INDIVIDUAL_PROPERTY_T 8
1305 #define FAKE_ACTION_T 11
1307 /* ------------------------------------------------------------------------- */
1308 /* Statusline_flag values */
1309 /* ------------------------------------------------------------------------- */
1311 #define SCORE_STYLE 0
1312 #define TIME_STYLE 1
1314 /* ------------------------------------------------------------------------- */
1315 /* Inform keyword definitions */
1316 /* ------------------------------------------------------------------------- */
1318 /* Index numbers into the keyword group "directives" (see "lexer.c") */
1320 #define ABBREVIATE_CODE 0
1321 #define ARRAY_CODE 1
1322 #define ATTRIBUTE_CODE 2
1323 #define CLASS_CODE 3
1324 #define CONSTANT_CODE 4
1325 #define DEFAULT_CODE 5
1326 #define DICTIONARY_CODE 6
1328 #define ENDIF_CODE 8
1329 #define EXTEND_CODE 9
1330 #define FAKE_ACTION_CODE 10
1331 #define GLOBAL_CODE 11
1332 #define IFDEF_CODE 12
1333 #define IFNDEF_CODE 13
1334 #define IFNOT_CODE 14
1335 #define IFV3_CODE 15
1336 #define IFV5_CODE 16
1337 #define IFTRUE_CODE 17
1338 #define IFFALSE_CODE 18
1339 #define IMPORT_CODE 19
1340 #define INCLUDE_CODE 20
1341 #define LINK_CODE 21
1342 #define LOWSTRING_CODE 22
1343 #define MESSAGE_CODE 23
1344 #define NEARBY_CODE 24
1345 #define OBJECT_CODE 25
1346 #define ORIGSOURCE_CODE 26
1347 #define PROPERTY_CODE 27
1348 #define RELEASE_CODE 28
1349 #define REPLACE_CODE 29
1350 #define SERIAL_CODE 30
1351 #define SWITCHES_CODE 31
1352 #define STATUSLINE_CODE 32
1353 #define STUB_CODE 33
1354 #define SYSTEM_CODE 34
1355 #define TRACE_CODE 35
1356 #define UNDEF_CODE 36
1357 #define VERB_CODE 37
1358 #define VERSION_CODE 38
1359 #define ZCHARACTER_CODE 39
1361 #define OPENBLOCK_CODE 100
1362 #define CLOSEBLOCK_CODE 101
1364 /* Index numbers into the keyword group "statements" (see "lexer.c") */
1367 #define BREAK_CODE 1
1368 #define CONTINUE_CODE 2
1369 #define SDEFAULT_CODE 3
1376 #define INVERSION_CODE 10
1377 #define JUMP_CODE 11
1378 #define MOVE_CODE 12
1379 #define NEW_LINE_CODE 13
1380 #define OBJECTLOOP_CODE 14
1381 #define PRINT_CODE 15
1382 #define PRINT_RET_CODE 16
1383 #define QUIT_CODE 17
1384 #define READ_CODE 18
1385 #define REMOVE_CODE 19
1386 #define RESTORE_CODE 20
1387 #define RETURN_CODE 21
1388 #define RFALSE_CODE 22
1389 #define RTRUE_CODE 23
1390 #define SAVE_CODE 24
1391 #define SPACES_CODE 25
1392 #define STRING_CODE 26
1393 #define STYLE_CODE 27
1394 #define SWITCH_CODE 28
1395 #define UNTIL_CODE 29
1396 #define WHILE_CODE 30
1398 #define ASSIGNMENT_CODE 100
1399 #define FUNCTION_CODE 101
1401 /* Index numbers into the keyword group "conditions" (see "lexer.c") */
1404 #define HASNT_COND 1
1406 #define NOTIN_COND 3
1407 #define OFCLASS_COND 4
1409 #define PROVIDES_COND 6
1411 /* Index numbers into the keyword group "segment_markers" (see "lexer.c") */
1413 #define CLASS_SEGMENT 0
1414 #define HAS_SEGMENT 1
1415 #define PRIVATE_SEGMENT 2
1416 #define WITH_SEGMENT 3
1418 /* Index numbers into the keyword group "misc_keywords" (see "lexer.c") */
1425 #define CAP_THE_MK 5
1428 #define REVERSE_MK 8
1430 #define UNDERLINE_MK 10
1435 #define ADDRESS_MK 15
1436 #define STRING_MK 16
1437 #define OBJECT_MK 17
1440 #define PROPERTY_MK 20
1443 /* Index numbers into the keyword group "directive_keywords" (see "lexer.c") */
1447 #define ADDITIVE_DK 2
1453 #define MULTIHELD_DK 8
1454 #define MULTIEXCEPT_DK 9
1455 #define MULTIINSIDE_DK 10
1456 #define CREATURE_DK 11
1457 #define SPECIAL_DK 12
1458 #define NUMBER_DK 13
1461 #define REVERSE_DK 16
1464 #define REPLACE_DK 19
1467 #define STRING_DK 22
1469 #define BUFFER_DK 24
1471 #define INITIAL_DK 26
1472 #define INITSTR_DK 27
1474 #define PRIVATE_DK 29
1478 #define FATALERROR_DK 33
1479 #define WARNING_DK 34
1480 #define TERMINATING_DK 35
1482 /* Index numbers into the keyword group "trace_keywords" (see "lexer.c") */
1484 #define DICTIONARY_TK 0
1485 #define SYMBOLS_TK 1
1486 #define OBJECTS_TK 2
1488 #define ASSEMBLY_TK 4
1489 #define EXPRESSIONS_TK 5
1496 /* Index numbers into the keyword group "system_constants" (see "lexer.c") */
1498 #define NO_SYSTEM_CONSTANTS 62
1500 #define adjectives_table_SC 0
1501 #define actions_table_SC 1
1502 #define classes_table_SC 2
1503 #define identifiers_table_SC 3
1504 #define preactions_table_SC 4
1505 #define version_number_SC 5
1506 #define largest_object_SC 6
1507 #define strings_offset_SC 7
1508 #define code_offset_SC 8
1509 #define dict_par1_SC 9
1510 #define dict_par2_SC 10
1511 #define dict_par3_SC 11
1512 #define actual_largest_object_SC 12
1513 #define static_memory_offset_SC 13
1514 #define array_names_offset_SC 14
1515 #define readable_memory_offset_SC 15
1516 #define cpv__start_SC 16
1517 #define cpv__end_SC 17
1518 #define ipv__start_SC 18
1519 #define ipv__end_SC 19
1520 #define array__start_SC 20
1521 #define array__end_SC 21
1523 #define lowest_attribute_number_SC 22
1524 #define highest_attribute_number_SC 23
1525 #define attribute_names_array_SC 24
1527 #define lowest_property_number_SC 25
1528 #define highest_property_number_SC 26
1529 #define property_names_array_SC 27
1531 #define lowest_action_number_SC 28
1532 #define highest_action_number_SC 29
1533 #define action_names_array_SC 30
1535 #define lowest_fake_action_number_SC 31
1536 #define highest_fake_action_number_SC 32
1537 #define fake_action_names_array_SC 33
1539 #define lowest_routine_number_SC 34
1540 #define highest_routine_number_SC 35
1541 #define routines_array_SC 36
1542 #define routine_names_array_SC 37
1543 #define routine_flags_array_SC 38
1545 #define lowest_global_number_SC 39
1546 #define highest_global_number_SC 40
1547 #define globals_array_SC 41
1548 #define global_names_array_SC 42
1549 #define global_flags_array_SC 43
1551 #define lowest_array_number_SC 44
1552 #define highest_array_number_SC 45
1553 #define arrays_array_SC 46
1554 #define array_names_array_SC 47
1555 #define array_flags_array_SC 48
1557 #define lowest_constant_number_SC 49
1558 #define highest_constant_number_SC 50
1559 #define constants_array_SC 51
1560 #define constant_names_array_SC 52
1562 #define lowest_class_number_SC 53
1563 #define highest_class_number_SC 54
1564 #define class_objects_array_SC 55
1566 #define lowest_object_number_SC 56
1567 #define highest_object_number_SC 57
1569 #define oddeven_packing_SC 58
1571 #define grammar_table_SC 59 /* Glulx-only */
1572 #define dictionary_table_SC 60 /* Glulx-only */
1573 #define dynam_string_table_SC 61 /* Glulx-only */
1576 /* Index numbers into the keyword group "system_functions" (see "lexer.c") */
1578 #define NUMBER_SYSTEM_FUNCTIONS 12
1580 #define CHILD_SYSF 0
1581 #define CHILDREN_SYSF 1
1582 #define ELDER_SYSF 2
1583 #define ELDEST_SYSF 3
1584 #define INDIRECT_SYSF 4
1585 #define PARENT_SYSF 5
1586 #define RANDOM_SYSF 6
1587 #define SIBLING_SYSF 7
1588 #define YOUNGER_SYSF 8
1589 #define YOUNGEST_SYSF 9
1590 #define METACLASS_SYSF 10
1591 #define GLK_SYSF 11 /* Glulx-only */
1593 /* Index numbers into the operators group "separators" (see "lexer.c") */
1595 #define NUMBER_SEPARATORS 49
1598 #define DARROW_SEP 1
1604 #define DIVIDE_SEP 7
1605 #define REMAINDER_SEP 8
1607 #define ARTOR_SEP 10
1608 #define LOGAND_SEP 11
1609 #define ARTAND_SEP 12
1610 #define LOGNOT_SEP 13
1611 #define NOTEQUAL_SEP 14
1612 #define ARTNOT_SEP 15
1613 #define CONDEQUALS_SEP 16
1614 #define SETEQUALS_SEP 17
1616 #define GREATER_SEP 19
1619 #define OPENB_SEP 22
1620 #define CLOSEB_SEP 23
1621 #define COMMA_SEP 24
1622 #define PROPADD_SEP 25
1623 #define PROPNUM_SEP 26
1624 #define MPROPADD_SEP 27
1625 #define MPROPNUM_SEP 28
1626 #define MESSAGE_SEP 29
1627 #define PROPERTY_SEP 30
1628 #define SUPERCLASS_SEP 31
1629 #define COLON_SEP 32
1631 #define SEMICOLON_SEP 34
1632 #define OPEN_SQUARE_SEP 35
1633 #define CLOSE_SQUARE_SEP 36
1634 #define OPEN_BRACE_SEP 37
1635 #define CLOSE_BRACE_SEP 38
1636 #define DOLLAR_SEP 39
1637 #define NBRANCH_SEP 40
1638 #define BRANCH_SEP 41
1639 #define HASHADOLLAR_SEP 42
1640 #define HASHGDOLLAR_SEP 43
1641 #define HASHNDOLLAR_SEP 44
1642 #define HASHRDOLLAR_SEP 45
1643 #define HASHWDOLLAR_SEP 46
1644 #define HASHHASH_SEP 47
1647 #define UNARY_MINUS_SEP 100
1648 #define POST_INC_SEP 101
1649 #define POST_DEC_SEP 102
1651 /* ------------------------------------------------------------------------- */
1652 /* Internal numbers used to refer to operators (in expressions) */
1653 /* (must correspond to entries in the operators table in "express.c") */
1654 /* ------------------------------------------------------------------------- */
1656 #define NUM_OPERATORS 68
1666 #define SETEQUALS_OP 1
1672 #define NONZERO_OP 6
1673 #define CONDEQUALS_OP 7
1674 #define NOTEQUAL_OP 8
1676 #define GREATER_OP 10
1683 #define OFCLASS_OP 17
1684 #define PROVIDES_OP 18
1685 #define NOTOFCLASS_OP 19
1686 #define NOTPROVIDES_OP 20
1692 #define DIVIDE_OP 25
1693 #define REMAINDER_OP 26
1694 #define ARTAND_OP 27
1696 #define ARTNOT_OP 29
1698 #define DARROW_OP 31
1699 #define UNARY_MINUS_OP 32
1701 #define POST_INC_OP 34
1703 #define POST_DEC_OP 36
1704 #define PROP_ADD_OP 37
1705 #define PROP_NUM_OP 38
1706 #define MPROP_ADD_OP 39
1707 #define MPROP_NUM_OP 40
1709 #define MESSAGE_OP 42
1710 #define PROPERTY_OP 43
1711 #define SUPERCLASS_OP 44
1713 #define ARROW_SETEQUALS_OP 45
1714 #define DARROW_SETEQUALS_OP 46
1715 #define MESSAGE_SETEQUALS_OP 47
1716 #define PROPERTY_SETEQUALS_OP 48
1718 #define ARROW_INC_OP 49
1719 #define DARROW_INC_OP 50
1720 #define MESSAGE_INC_OP 51
1721 #define PROPERTY_INC_OP 52
1723 #define ARROW_DEC_OP 53
1724 #define DARROW_DEC_OP 54
1725 #define MESSAGE_DEC_OP 55
1726 #define PROPERTY_DEC_OP 56
1728 #define ARROW_POST_INC_OP 57
1729 #define DARROW_POST_INC_OP 58
1730 #define MESSAGE_POST_INC_OP 59
1731 #define PROPERTY_POST_INC_OP 60
1733 #define ARROW_POST_DEC_OP 61
1734 #define DARROW_POST_DEC_OP 62
1735 #define MESSAGE_POST_DEC_OP 63
1736 #define PROPERTY_POST_DEC_OP 64
1738 #define PROP_CALL_OP 65
1739 #define MESSAGE_CALL_OP 66
1741 #define PUSH_OP 67 /* Glulx only */
1743 /* ------------------------------------------------------------------------- */
1744 /* The five types of compiled array */
1745 /* ------------------------------------------------------------------------- */
1747 #define BYTE_ARRAY 0
1748 #define WORD_ARRAY 1
1749 #define STRING_ARRAY 2
1750 #define TABLE_ARRAY 3
1751 #define BUFFER_ARRAY 4
1753 /* ------------------------------------------------------------------------- */
1754 /* Internal numbers used to refer to veneer routines */
1755 /* (must correspond to entries in the table in "veneer.c") */
1756 /* ------------------------------------------------------------------------- */
1758 #define VENEER_ROUTINES 48
1760 #define Box__Routine_VR 0
1762 #define R_Process_VR 1
1764 #define InDefArt_VR 3
1765 #define CDefArt_VR 4
1766 #define CInDefArt_VR 5
1767 #define PrintShortName_VR 6
1768 #define EnglishNumber_VR 7
1769 #define Print__Pname_VR 8
1772 #define RV__Pr_VR 10
1773 #define CA__Pr_VR 11
1774 #define IB__Pr_VR 12
1775 #define IA__Pr_VR 13
1776 #define DB__Pr_VR 14
1777 #define DA__Pr_VR 15
1778 #define RA__Pr_VR 16
1779 #define RL__Pr_VR 17
1780 #define RA__Sc_VR 18
1781 #define OP__Pr_VR 19
1782 #define OC__Cl_VR 20
1784 #define Copy__Primitive_VR 21
1785 #define RT__Err_VR 22
1786 #define Z__Region_VR 23
1787 #define Unsigned__Compare_VR 24
1788 #define Metaclass_VR 25
1789 #define CP__Tab_VR 26
1790 #define Cl__Ms_VR 27
1791 #define RT__ChT_VR 28
1792 #define RT__ChR_VR 29
1793 #define RT__ChG_VR 30
1794 #define RT__ChGt_VR 31
1795 #define RT__ChPS_VR 32
1796 #define RT__ChPR_VR 33
1797 #define RT__TrPS_VR 34
1798 #define RT__ChLDB_VR 35
1799 #define RT__ChLDW_VR 36
1800 #define RT__ChSTB_VR 37
1801 #define RT__ChSTW_VR 38
1802 #define RT__ChPrintC_VR 39
1803 #define RT__ChPrintA_VR 40
1804 #define RT__ChPrintS_VR 41
1805 #define RT__ChPrintO_VR 42
1807 /* Glulx-only veneer routines */
1808 #define OB__Move_VR 43
1809 #define OB__Remove_VR 44
1810 #define Print__Addr_VR 45
1811 #define Glk__Wrap_VR 46
1812 #define Dynam__String_VR 47
1814 /* ------------------------------------------------------------------------- */
1815 /* Run-time-error numbers (must correspond with RT__Err code in veneer) */
1816 /* ------------------------------------------------------------------------- */
1820 #define PARENT_RTE 4
1821 #define ELDEST_RTE 5
1823 #define YOUNGER_RTE 7
1824 #define SIBLING_RTE 8
1825 #define CHILDREN_RTE 9
1826 #define YOUNGEST_RTE 10
1827 #define ELDER_RTE 11
1828 #define OBJECTLOOP_RTE 12
1829 #define OBJECTLOOP2_RTE 13
1831 #define REMOVE_RTE 15
1832 #define MOVE1_RTE 16
1833 #define MOVE2_RTE 17
1834 /* 18 = creating a loop in object tree */
1835 /* 19 = giving a non-existent attribute */
1836 #define DBYZERO_RTE 20
1837 #define PROP_ADD_RTE 21
1838 #define PROP_NUM_RTE 22
1839 #define PROPERTY_RTE 23
1840 /* 24 = reading with -> out of range */
1841 /* 25 = reading with --> out of range */
1842 /* 26 = writing with -> out of range */
1843 /* 27 = writing with --> out of range */
1844 #define ABOUNDS_RTE 28
1845 /* similarly 29, 30, 31 */
1846 #define OBJECTLOOP_BROKEN_RTE 32
1847 /* 33 = print (char) out of range */
1848 /* 34 = print (address) out of range */
1849 /* 35 = print (string) out of range */
1850 /* 36 = print (object) out of range */
1852 /* ------------------------------------------------------------------------- */
1853 /* Z-region areas (used to refer to module positions in markers) */
1854 /* ------------------------------------------------------------------------- */
1856 #define LOW_STRINGS_ZA 1
1857 #define PROP_DEFAULTS_ZA 2
1858 #define OBJECT_TREE_ZA 3
1860 #define CLASS_NUMBERS_ZA 5
1861 #define INDIVIDUAL_PROP_ZA 6
1862 #define DYNAMIC_ARRAY_ZA 7 /* Z-code only */
1863 #define GRAMMAR_ZA 8
1864 #define ACTIONS_ZA 9
1865 #define PREACTIONS_ZA 10
1866 #define ADJECTIVES_ZA 11
1867 #define DICTIONARY_ZA 12
1869 #define STATIC_STRINGS_ZA 14
1870 #define LINK_DATA_ZA 15
1872 #define SYMBOLS_ZA 16
1874 #define ARRAY_ZA 17 /* Glulx only */
1875 #define GLOBALVAR_ZA 18 /* Glulx only */
1877 /* ------------------------------------------------------------------------- */
1878 /* "Marker values", used for backpatching and linkage */
1879 /* ------------------------------------------------------------------------- */
1881 #define NULL_MV 0 /* Null */
1883 /* Marker values used in backpatch areas: */
1885 #define DWORD_MV 1 /* Dictionary word address */
1886 #define STRING_MV 2 /* Static string */
1887 #define INCON_MV 3 /* "Hardware" constant (table address) */
1888 #define IROUTINE_MV 4 /* Call to internal routine */
1889 #define VROUTINE_MV 5 /* Call to veneer routine */
1890 #define ARRAY_MV 6 /* Ref to internal array address */
1891 #define NO_OBJS_MV 7 /* Ref to number of game objects */
1892 #define INHERIT_MV 8 /* Inherited property value */
1893 #define INHERIT_INDIV_MV 9 /* Inherited indiv property value */
1894 #define MAIN_MV 10 /* "Main" routine */
1895 #define SYMBOL_MV 11 /* Forward ref to unassigned symbol */
1897 /* Additional marker values used in module backpatch areas: */
1898 /* (In Glulx, OBJECT_MV and VARIABLE_MV are used in backpatching, even
1899 without modules.) */
1901 #define VARIABLE_MV 12 /* Global variable */
1902 #define IDENT_MV 13 /* Property identifier number */
1903 #define INDIVPT_MV 14 /* Individual prop table address */
1904 #define ACTION_MV 15 /* Action number */
1905 #define OBJECT_MV 16 /* Ref to internal object number */
1907 #define LARGEST_BPATCH_MV 16 /* Larger marker values are never written
1908 to backpatch tables */
1910 /* Value indicating an imported symbol record: */
1912 #define IMPORT_MV 32
1914 /* Values indicating an exported symbol record: */
1916 #define EXPORT_MV 33 /* Defined ordinarily */
1917 #define EXPORTSF_MV 34 /* Defined in a system file */
1918 #define EXPORTAC_MV 35 /* Action name */
1920 /* Values used only in branch backpatching: */
1921 /* ###-I've rearranged these, so that BRANCH_MV can be last; Glulx uses the
1922 whole range from BRANCH_MV to BRANCHMAX_MV. */
1924 #define LABEL_MV 36 /* Ditto: marks "jump" operands */
1925 #define DELETED_MV 37 /* Ditto: marks bytes deleted from code */
1926 #define BRANCH_MV 38 /* Used in "asm.c" for routine coding */
1927 #define BRANCHMAX_MV 58 /* In fact, the range BRANCH_MV to
1928 BRANCHMAX_MV all means the same thing.
1929 The position within the range means
1930 how far back from the label to go
1931 to find the opmode byte to modify. */
1933 /* ========================================================================= */
1934 /* Initialisation extern definitions */
1936 /* Note that each subsystem in Inform provides four routines to keep */
1937 /* track of variables and data structures: */
1939 /* init_*_vars should set variables to initial values (they must */
1940 /* not be initialised directly in their declarations */
1941 /* as Inform may need to compile several times in a */
1944 /* *_begin_pass any variable/array initialisation that needs to */
1945 /* happen at the start of the pass through the source */
1947 /* *_allocate_arrays should use my_malloc/my_calloc (see memory.c) */
1948 /* to allocate any arrays or workspace needed */
1950 /* *_free_arrays should use my_free to free all memory allocated */
1951 /* (with one exception in "text.c") */
1953 /* ========================================================================= */
1955 /* > READ INFORM SOURCE */
1957 /* My Source Book */
1959 extern void init_arrays_vars(void); /* arrays: construct tableaux */
1960 extern void init_asm_vars(void); /* asm: assemble even rare or v6 codes */
1961 extern void init_bpatch_vars(void); /* bpatch: backpatches code */
1962 extern void init_chars_vars(void); /* chars: translate character sets */
1963 extern void init_directs_vars(void); /* directs: ponder directives */
1964 extern void init_errors_vars(void); /* errors: issue diagnostics */
1965 extern void init_expressc_vars(void); /* expressc: compile expressions */
1966 extern void init_expressp_vars(void); /* expressp: parse expressions */
1967 extern void init_files_vars(void); /* files: handle files */
1968 /* void init_vars(void); inform: decide what to do */
1969 extern void init_lexer_vars(void); /* lexer: lexically analyse source */
1970 extern void init_linker_vars(void); /* linker: link in pre-compiled module */
1971 extern void init_memory_vars(void); /* memory: manage memory settings */
1972 extern void init_objects_vars(void); /* objects: cultivate object tree */
1973 extern void init_states_vars(void); /* states: translate statements to code*/
1974 extern void init_symbols_vars(void); /* symbols: construct symbols table */
1975 extern void init_syntax_vars(void); /* syntax: parse the program */
1976 extern void init_tables_vars(void); /* tables: glue tables into the output */
1977 extern void init_text_vars(void); /* text: encode text and dictionary */
1978 extern void init_veneer_vars(void); /* veneer: compile a layer of code */
1979 extern void init_verbs_vars(void); /* verbs: lay out grammar */
1981 extern void files_begin_prepass(void); /* These routines initialise just */
1982 extern void lexer_begin_prepass(void); /* enough to begin loading source */
1984 extern void arrays_begin_pass(void);
1985 extern void asm_begin_pass(void);
1986 extern void bpatch_begin_pass(void);
1987 extern void chars_begin_pass(void);
1988 extern void directs_begin_pass(void);
1989 extern void errors_begin_pass(void);
1990 extern void expressc_begin_pass(void);
1991 extern void expressp_begin_pass(void);
1992 extern void files_begin_pass(void);
1993 /* void begin_pass(void); */
1994 extern void lexer_begin_pass(void);
1995 extern void linker_begin_pass(void);
1996 extern void memory_begin_pass(void);
1997 extern void objects_begin_pass(void);
1998 extern void states_begin_pass(void);
1999 extern void symbols_begin_pass(void);
2000 extern void syntax_begin_pass(void);
2001 extern void tables_begin_pass(void);
2002 extern void text_begin_pass(void);
2003 extern void veneer_begin_pass(void);
2004 extern void verbs_begin_pass(void);
2006 extern void lexer_endpass(void);
2007 extern void linker_endpass(void);
2009 extern void arrays_allocate_arrays(void);
2010 extern void asm_allocate_arrays(void);
2011 extern void bpatch_allocate_arrays(void);
2012 extern void chars_allocate_arrays(void);
2013 extern void directs_allocate_arrays(void);
2014 extern void errors_allocate_arrays(void);
2015 extern void expressc_allocate_arrays(void);
2016 extern void expressp_allocate_arrays(void);
2017 extern void files_allocate_arrays(void);
2018 /* void allocate_arrays(void); */
2019 extern void lexer_allocate_arrays(void);
2020 extern void linker_allocate_arrays(void);
2021 extern void memory_allocate_arrays(void);
2022 extern void objects_allocate_arrays(void);
2023 extern void states_allocate_arrays(void);
2024 extern void symbols_allocate_arrays(void);
2025 extern void syntax_allocate_arrays(void);
2026 extern void tables_allocate_arrays(void);
2027 extern void text_allocate_arrays(void);
2028 extern void veneer_allocate_arrays(void);
2029 extern void verbs_allocate_arrays(void);
2031 extern void arrays_free_arrays(void);
2032 extern void asm_free_arrays(void);
2033 extern void bpatch_free_arrays(void);
2034 extern void chars_free_arrays(void);
2035 extern void directs_free_arrays(void);
2036 extern void errors_free_arrays(void);
2037 extern void expressc_free_arrays(void);
2038 extern void expressp_free_arrays(void);
2039 extern void files_free_arrays(void);
2040 /* void free_arrays(void); */
2041 extern void lexer_free_arrays(void);
2042 extern void linker_free_arrays(void);
2043 extern void memory_free_arrays(void);
2044 extern void objects_free_arrays(void);
2045 extern void states_free_arrays(void);
2046 extern void symbols_free_arrays(void);
2047 extern void syntax_free_arrays(void);
2048 extern void tables_free_arrays(void);
2049 extern void text_free_arrays(void);
2050 extern void veneer_free_arrays(void);
2051 extern void verbs_free_arrays(void);
2053 /* ========================================================================= */
2054 /* Remaining extern definitions are given by file in alphabetical order */
2055 /* ------------------------------------------------------------------------- */
2056 /* Extern definitions for "arrays" */
2057 /* ------------------------------------------------------------------------- */
2059 extern int no_globals, no_arrays;
2060 extern int dynamic_array_area_size;
2061 extern int *dynamic_array_area;
2062 extern int32 *global_initial_value;
2063 extern int32 *array_symbols;
2064 extern int *array_sizes, *array_types;
2066 extern void make_global(int array_flag, int name_only);
2067 extern void set_variable_value(int i, int32 v);
2068 extern void check_globals(void);
2069 extern int32 begin_table_array(void);
2070 extern int32 begin_word_array(void);
2071 extern void array_entry(int32 i, assembly_operand VAL);
2072 extern void finish_array(int32 i);
2074 /* ------------------------------------------------------------------------- */
2075 /* Extern definitions for "asm" */
2076 /* ------------------------------------------------------------------------- */
2078 extern memory_block zcode_area;
2079 extern int32 zmachine_pc;
2081 extern int32 no_instructions;
2082 extern int sequence_point_follows;
2083 extern int uses_unicode_features, uses_memheap_features,
2084 uses_acceleration_features, uses_float_features;
2085 extern debug_location statement_debug_location;
2086 extern int execution_never_reaches_here;
2087 extern int *variable_usage;
2088 extern int next_label, no_sequence_points;
2089 extern int32 *variable_tokens;
2090 extern assembly_instruction AI;
2091 extern int32 *named_routine_symbols;
2093 extern void print_operand(assembly_operand o);
2094 extern char *variable_name(int32 i);
2095 extern void set_constant_ot(assembly_operand *AO);
2096 extern int is_constant_ot(int otval);
2097 extern int is_variable_ot(int otval);
2098 extern void assemblez_instruction(assembly_instruction *a);
2099 extern void assembleg_instruction(assembly_instruction *a);
2100 extern void assemble_label_no(int n);
2101 extern void assemble_jump(int n);
2102 extern void define_symbol_label(int symbol);
2103 extern int32 assemble_routine_header(int no_locals, int debug_flag,
2104 char *name, int embedded_flag, int the_symbol);
2105 extern void assemble_routine_end(int embedded_flag, debug_locations locations);
2107 extern void assemblez_0(int internal_number);
2108 extern void assemblez_0_to(int internal_number, assembly_operand o1);
2109 extern void assemblez_0_branch(int internal_number, int label, int flag);
2110 extern void assemblez_1(int internal_number, assembly_operand o1);
2111 extern void assemblez_1_to(int internal_number,
2112 assembly_operand o1, assembly_operand st);
2113 extern void assemblez_1_branch(int internal_number,
2114 assembly_operand o1, int label, int flag);
2115 extern void assemblez_objcode(int internal_number,
2116 assembly_operand o1, assembly_operand st,
2117 int label, int flag);
2118 extern void assemblez_2(int internal_number,
2119 assembly_operand o1, assembly_operand o2);
2120 extern void assemblez_2_to(int internal_number,
2121 assembly_operand o1, assembly_operand o2,
2122 assembly_operand st);
2123 extern void assemblez_2_branch(int internal_number,
2124 assembly_operand o1, assembly_operand o2,
2125 int label, int flag);
2126 extern void assemblez_3(int internal_number,
2127 assembly_operand o1, assembly_operand o2,
2128 assembly_operand o3);
2129 extern void assemblez_3_branch(int internal_number,
2130 assembly_operand o1, assembly_operand o2,
2131 assembly_operand o3, int label, int flag);
2132 extern void assemblez_3_to(int internal_number,
2133 assembly_operand o1, assembly_operand o2,
2134 assembly_operand o3, assembly_operand st);
2135 extern void assemblez_4(int internal_number,
2136 assembly_operand o1, assembly_operand o2,
2137 assembly_operand o3, assembly_operand o4);
2138 extern void assemblez_5(int internal_number,
2139 assembly_operand o1, assembly_operand o2,
2140 assembly_operand o3, assembly_operand o4,
2141 assembly_operand o5);
2142 extern void assemblez_6(int internal_number,
2143 assembly_operand o1, assembly_operand o2,
2144 assembly_operand o3, assembly_operand o4,
2145 assembly_operand o5, assembly_operand o6);
2146 extern void assemblez_4_branch(int internal_number,
2147 assembly_operand o1, assembly_operand o2,
2148 assembly_operand o3, assembly_operand o4,
2149 int label, int flag);
2150 extern void assemblez_4_to(int internal_number,
2151 assembly_operand o1, assembly_operand o2,
2152 assembly_operand o3, assembly_operand o4,
2153 assembly_operand st);
2154 extern void assemblez_5_to(int internal_number,
2155 assembly_operand o1, assembly_operand o2,
2156 assembly_operand o3, assembly_operand o4,
2157 assembly_operand o5, assembly_operand st);
2159 extern void assemblez_inc(assembly_operand o1);
2160 extern void assemblez_dec(assembly_operand o1);
2161 extern void assemblez_store(assembly_operand o1, assembly_operand o2);
2162 extern void assemblez_jump(int n);
2164 extern void assembleg_0(int internal_number);
2165 extern void assembleg_1(int internal_number, assembly_operand o1);
2166 extern void assembleg_2(int internal_number, assembly_operand o1,
2167 assembly_operand o2);
2168 extern void assembleg_3(int internal_number, assembly_operand o1,
2169 assembly_operand o2, assembly_operand o3);
2170 extern void assembleg_4(int internal_number, assembly_operand o1,
2171 assembly_operand o2, assembly_operand o3, assembly_operand o4);
2172 extern void assembleg_5(int internal_number, assembly_operand o1,
2173 assembly_operand o2, assembly_operand o3, assembly_operand o4,
2174 assembly_operand o5);
2175 extern void assembleg_0_branch(int internal_number,
2177 extern void assembleg_1_branch(int internal_number,
2178 assembly_operand o1, int label);
2179 extern void assembleg_2_branch(int internal_number,
2180 assembly_operand o1, assembly_operand o2, int label);
2181 extern void assembleg_call_1(assembly_operand oaddr, assembly_operand o1,
2182 assembly_operand odest);
2183 extern void assembleg_call_2(assembly_operand oaddr, assembly_operand o1,
2184 assembly_operand o2, assembly_operand odest);
2185 extern void assembleg_call_3(assembly_operand oaddr, assembly_operand o1,
2186 assembly_operand o2, assembly_operand o3, assembly_operand odest);
2187 extern void assembleg_inc(assembly_operand o1);
2188 extern void assembleg_dec(assembly_operand o1);
2189 extern void assembleg_store(assembly_operand o1, assembly_operand o2);
2190 extern void assembleg_jump(int n);
2192 extern void parse_assembly(void);
2194 /* ------------------------------------------------------------------------- */
2195 /* Extern definitions for "bpatch" */
2196 /* ------------------------------------------------------------------------- */
2198 extern memory_block zcode_backpatch_table, zmachine_backpatch_table;
2199 extern int32 zcode_backpatch_size, zmachine_backpatch_size;
2200 extern int backpatch_marker, backpatch_error_flag;
2202 extern int32 backpatch_value(int32 value);
2203 extern void backpatch_zmachine_image_z(void);
2204 extern void backpatch_zmachine_image_g(void);
2205 extern void backpatch_zmachine(int mv, int zmachine_area, int32 offset);
2207 /* ------------------------------------------------------------------------- */
2208 /* Extern definitions for "chars" */
2209 /* ------------------------------------------------------------------------- */
2211 extern uchar source_to_iso_grid[];
2212 extern int32 iso_to_unicode_grid[];
2213 extern int character_digit_value[];
2214 extern uchar alphabet[3][27];
2215 extern int alphabet_modified;
2216 extern int zscii_defn_modified;
2217 extern int zscii_high_water_mark;
2218 extern char alphabet_used[];
2219 extern int iso_to_alphabet_grid[];
2220 extern int zscii_to_alphabet_grid[];
2221 extern int textual_form_length;
2223 extern int iso_to_unicode(int iso);
2224 extern int unicode_to_zscii(int32 u);
2225 extern int32 zscii_to_unicode(int z);
2226 extern int32 text_to_unicode(char *text);
2227 extern void zscii_to_text(char *text, int zscii);
2228 extern char *name_of_iso_set(int s);
2229 extern void change_character_set(void);
2230 extern void new_alphabet(char *text, int alphabet);
2231 extern void new_zscii_character(int32 unicode, int plus_flag);
2232 extern void new_zscii_finished(void);
2233 extern void map_new_zchar(int32 unicode);
2234 extern void make_lower_case(char *str);
2235 extern void make_upper_case(char *str);
2237 /* ------------------------------------------------------------------------- */
2238 /* Extern definitions for "directs" */
2239 /* ------------------------------------------------------------------------- */
2241 extern brief_location routine_starts_line;
2243 extern int no_routines, no_named_routines, no_locals, no_termcs;
2244 extern int terminating_characters[];
2246 extern int parse_given_directive(int internal_flag);
2248 /* ------------------------------------------------------------------------- */
2249 /* Extern definitions for "errors" */
2250 /* ------------------------------------------------------------------------- */
2252 extern char *forerrors_buff;
2253 extern int forerrors_pointer;
2254 extern int no_errors, no_warnings, no_suppressed_warnings,
2255 no_link_errors, no_compiler_errors;
2257 extern ErrorPosition ErrorReport;
2259 extern void fatalerror(char *s) NORETURN;
2260 extern void fatalerror_named(char *s1, char *s2) NORETURN;
2261 extern void memory_out_error(int32 size, int32 howmany, char *name) NORETURN;
2262 extern void memoryerror(char *s, int32 size) NORETURN;
2263 extern void error(char *s);
2264 extern void error_named(char *s1, char *s2);
2265 extern void error_numbered(char *s1, int val);
2266 extern void error_named_at(char *s1, char *s2, brief_location report_line);
2267 extern void ebf_error(char *s1, char *s2);
2268 extern void char_error(char *s, int ch);
2269 extern void unicode_char_error(char *s, int32 uni);
2270 extern void no_such_label(char *lname);
2271 extern void warning(char *s);
2272 extern void warning_numbered(char *s1, int val);
2273 extern void warning_named(char *s1, char *s2);
2274 extern void dbnu_warning(char *type, char *name, brief_location report_line);
2275 extern void uncalled_routine_warning(char *type, char *name, brief_location report_line);
2276 extern void obsolete_warning(char *s1);
2277 extern void link_error(char *s);
2278 extern void link_error_named(char *s1, char *s2);
2279 extern int compiler_error(char *s);
2280 extern int compiler_error_named(char *s1, char *s2);
2281 extern void print_sorry_message(void);
2283 #ifdef ARC_THROWBACK
2284 extern int throwback_switch;
2286 extern void throwback(int severity, char * error);
2287 extern void throwback_start(void);
2288 extern void throwback_end(void);
2291 /* ------------------------------------------------------------------------- */
2292 /* Extern definitions for "expressc" */
2293 /* ------------------------------------------------------------------------- */
2295 extern int vivc_flag;
2296 extern operator operators[];
2298 extern assembly_operand stack_pointer, temp_var1, temp_var2, temp_var3,
2299 temp_var4, zero_operand, one_operand, two_operand, three_operand,
2300 four_operand, valueless_operand;
2302 assembly_operand code_generate(assembly_operand AO, int context, int label);
2303 assembly_operand check_nonzero_at_runtime(assembly_operand AO1, int label,
2306 /* ------------------------------------------------------------------------- */
2307 /* Extern definitions for "expressp" */
2308 /* ------------------------------------------------------------------------- */
2310 extern int system_function_usage[];
2311 extern expression_tree_node *ET;
2313 extern int z_system_constant_list[];
2314 extern int glulx_system_constant_list[];
2316 extern int32 value_of_system_constant(int t);
2317 extern void clear_expression_space(void);
2318 extern void show_tree(assembly_operand AO, int annotate);
2319 extern assembly_operand parse_expression(int context);
2320 extern int test_for_incdec(assembly_operand AO);
2322 /* ------------------------------------------------------------------------- */
2323 /* Extern definitions for "files" */
2324 /* ------------------------------------------------------------------------- */
2326 extern int total_files;
2327 extern int current_input_file;
2328 extern int total_input_files;
2329 extern FileId *InputFiles;
2331 extern FILE *Temp1_fp, *Temp2_fp, *Temp3_fp;
2332 extern char Temp1_Name[], Temp2_Name[], Temp3_Name[];
2333 extern int32 total_chars_read;
2335 extern void open_temporary_files(void);
2336 extern void check_temp_files(void);
2337 extern void remove_temp_files(void);
2339 extern void open_transcript_file(char *what_of);
2340 extern void write_to_transcript_file(char *text);
2341 extern void close_transcript_file(void);
2342 extern void abort_transcript_file(void);
2344 extern void nullify_debug_file_position(maybe_file_position *position);
2346 extern void begin_debug_file(void);
2348 extern void debug_file_printf(const char*format, ...);
2349 extern void debug_file_print_with_entities(const char*string);
2350 extern void debug_file_print_base_64_triple
2351 (uchar first, uchar second, uchar third);
2352 extern void debug_file_print_base_64_pair(uchar first, uchar second);
2353 extern void debug_file_print_base_64_single(uchar first);
2355 extern void write_debug_location(debug_location location);
2356 extern void write_debug_locations(debug_locations locations);
2357 extern void write_debug_optional_identifier(int32 symbol_index);
2358 extern void write_debug_symbol_backpatch(int32 symbol_index);
2359 extern void write_debug_symbol_optional_backpatch(int32 symbol_index);
2360 extern void write_debug_object_backpatch(int32 object_number);
2361 extern void write_debug_packed_code_backpatch(int32 offset);
2362 extern void write_debug_code_backpatch(int32 offset);
2363 extern void write_debug_global_backpatch(int32 offset);
2364 extern void write_debug_array_backpatch(int32 offset);
2365 extern void write_debug_grammar_backpatch(int32 offset);
2367 extern void begin_writing_debug_sections(void);
2368 extern void write_debug_section(const char*name, int32 beginning_address);
2369 extern void end_writing_debug_sections(int32 end_address);
2371 extern void write_debug_undef(int32 symbol_index);
2373 extern void end_debug_file(void);
2375 extern void add_to_checksum(void *address);
2377 extern void load_sourcefile(char *story_name, int style);
2378 extern int file_load_chars(int file_number, char *buffer, int length);
2379 extern void close_all_source(void);
2380 extern int register_orig_sourcefile(char *filename);
2382 extern void output_file(void);
2384 /* ------------------------------------------------------------------------- */
2385 /* Extern definitions for "inform" */
2386 /* ------------------------------------------------------------------------- */
2388 extern char Code_Name[];
2389 extern int endofpass_flag;
2391 extern int version_number, instruction_set_number, extend_memory_map;
2392 extern int32 scale_factor, length_scale_factor;
2394 extern int WORDSIZE, INDIV_PROP_START,
2395 OBJECT_BYTE_LENGTH, DICT_ENTRY_BYTE_LENGTH, DICT_ENTRY_FLAG_POS;
2396 extern int32 MAXINTWORD;
2398 extern int asm_trace_level, line_trace_level, expr_trace_level,
2399 linker_trace_level, tokens_trace_level;
2402 bothpasses_switch, concise_switch,
2403 economy_switch, frequencies_switch,
2404 ignore_switches_switch, listobjects_switch, debugfile_switch,
2405 listing_switch, memout_switch, printprops_switch,
2406 offsets_switch, percentages_switch, obsolete_switch,
2407 transcript_switch, statistics_switch, optimise_switch,
2408 version_set_switch, nowarnings_switch, hash_switch,
2409 memory_map_switch, module_switch, temporary_files_switch,
2410 define_DEBUG_switch, define_USE_MODULES_switch, define_INFIX_switch,
2411 runtime_error_checking_switch;
2413 extern int oddeven_packing_switch;
2415 extern int glulx_mode, compression_switch;
2416 extern int32 requested_glulx_version;
2418 extern int error_format, store_the_text, asm_trace_setting,
2419 double_space_setting, trace_fns_setting, character_set_setting,
2420 character_set_unicode;
2422 extern char Debugging_Name[];
2423 extern char Transcript_Name[];
2424 extern char Language_Name[];
2425 extern char Charset_Map[];
2427 extern char banner_line[];
2429 extern void select_version(int vn);
2430 extern void switches(char *, int);
2431 extern int translate_in_filename(int last_value, char *new_name, char *old_name,
2432 int same_directory_flag, int command_line_flag);
2433 extern void translate_out_filename(char *new_name, char *old_name);
2434 extern int translate_link_filename(int last_value,
2435 char *new_name, char *old_name);
2436 extern void translate_temp_filename(int i);
2439 extern char *riscos_file_type(void);
2442 /* For the benefit of the MAC_FACE port these are declared extern, though
2443 unused outside "inform" in the compiler itself */
2445 extern void allocate_arrays(void);
2446 extern void free_arrays(void);
2448 /* ------------------------------------------------------------------------- */
2449 /* Extern definitions for "lexer" */
2450 /* ------------------------------------------------------------------------- */
2452 extern int hash_printed_since_newline;
2453 extern int total_source_line_count;
2454 extern int dont_enter_into_symbol_table;
2455 extern int return_sp_as_variable;
2456 extern int next_token_begins_syntax_line;
2457 extern char **local_variable_texts;
2459 extern int32 token_value;
2460 extern int token_type;
2461 extern char *token_text;
2463 extern debug_location get_token_location(void);
2464 extern debug_locations get_token_locations(void);
2465 extern debug_location_beginning get_token_location_beginning(void);
2466 extern void discard_token_location(debug_location_beginning beginning);
2467 extern debug_locations get_token_location_end(debug_location_beginning beginning);
2469 extern void describe_token(token_data t);
2471 extern void construct_local_variable_tables(void);
2472 extern void declare_systemfile(void);
2473 extern int is_systemfile(void);
2474 extern void report_errors_at_current_line(void);
2475 extern debug_location get_current_debug_location(void);
2476 extern debug_location get_error_report_debug_location(void);
2477 extern int32 get_current_line_start(void);
2478 extern void set_origsource_location(char *source, int32 line, int32 charnum);
2479 extern brief_location get_brief_location(ErrorPosition *errpos);
2480 extern void export_brief_location(brief_location loc, ErrorPosition *errpos);
2481 extern brief_location blank_brief_location;
2483 extern void put_token_back(void);
2484 extern void get_next_token(void);
2485 extern void restart_lexer(char *lexical_source, char *name);
2487 extern keyword_group directives, statements, segment_markers,
2488 conditions, system_functions, local_variables, opcode_names,
2489 misc_keywords, directive_keywords, trace_keywords, system_constants,
2492 /* ------------------------------------------------------------------------- */
2493 /* Extern definitions for "linker" */
2494 /* ------------------------------------------------------------------------- */
2496 extern memory_block link_data_area;
2497 extern int32 link_data_size;
2498 extern char current_module_filename[];
2500 extern char *describe_mv(int mval);
2501 extern void write_link_marker(int zmachine_area, int32 offset,
2502 assembly_operand op);
2503 extern void flush_link_data(void);
2504 extern void import_symbol(int32 symbol_number);
2505 extern void export_symbol(int32 symbol_number);
2506 extern void export_symbol_name(int32 i);
2507 extern void link_module(char *filename);
2509 /* ------------------------------------------------------------------------- */
2510 /* Extern definitions for "memory" */
2511 /* ------------------------------------------------------------------------- */
2513 extern int32 malloced_bytes;
2515 extern int MAX_QTEXT_SIZE, MAX_SYMBOLS, HASH_TAB_SIZE, MAX_DICT_ENTRIES,
2516 MAX_OBJECTS, MAX_ACTIONS, MAX_ADJECTIVES, MAX_ABBREVS,
2517 MAX_STATIC_DATA, MAX_PROP_TABLE_SIZE, SYMBOLS_CHUNK_SIZE,
2518 MAX_EXPRESSION_NODES, MAX_LABELS, MAX_LINESPACE,
2519 MAX_LOW_STRINGS, MAX_CLASSES, MAX_VERBS,
2520 MAX_VERBSPACE, MAX_ARRAYS, MAX_INCLUSION_DEPTH,
2523 extern int32 MAX_STATIC_STRINGS, MAX_ZCODE_SIZE, MAX_LINK_DATA_SIZE,
2524 MAX_TRANSCRIPT_SIZE, MAX_INDIV_PROP_TABLE_SIZE,
2525 MAX_NUM_STATIC_STRINGS, MAX_UNICODE_CHARS,
2526 MAX_STACK_SIZE, MEMORY_MAP_EXTENSION;
2528 extern int32 MAX_OBJ_PROP_COUNT, MAX_OBJ_PROP_TABLE_SIZE;
2529 extern int MAX_LOCAL_VARIABLES, MAX_GLOBAL_VARIABLES;
2530 extern int DICT_WORD_SIZE, DICT_CHAR_SIZE, DICT_WORD_BYTES;
2531 extern int ZCODE_HEADER_EXT_WORDS, ZCODE_HEADER_FLAGS_3;
2532 extern int NUM_ATTR_BYTES, GLULX_OBJECT_EXT_BYTES;
2533 extern int WARN_UNUSED_ROUTINES, OMIT_UNUSED_ROUTINES;
2535 /* These macros define offsets that depend on the value of NUM_ATTR_BYTES.
2536 (Meaningful only for Glulx.) */
2537 /* GOBJFIELD: word offsets of various elements in the object structure. */
2538 #define GOBJFIELD_CHAIN() (1+((NUM_ATTR_BYTES)/4))
2539 #define GOBJFIELD_NAME() (2+((NUM_ATTR_BYTES)/4))
2540 #define GOBJFIELD_PROPTAB() (3+((NUM_ATTR_BYTES)/4))
2541 #define GOBJFIELD_PARENT() (4+((NUM_ATTR_BYTES)/4))
2542 #define GOBJFIELD_SIBLING() (5+((NUM_ATTR_BYTES)/4))
2543 #define GOBJFIELD_CHILD() (6+((NUM_ATTR_BYTES)/4))
2545 extern void *my_malloc(int32 size, char *whatfor);
2546 extern void my_realloc(void *pointer, int32 oldsize, int32 size,
2548 extern void *my_calloc(int32 size, int32 howmany, char *whatfor);
2549 extern void my_recalloc(void *pointer, int32 size, int32 oldhowmany,
2550 int32 howmany, char *whatfor);
2551 extern void my_free(void *pointer, char *whatitwas);
2553 extern void set_memory_sizes(int size_flag);
2554 extern void adjust_memory_sizes(void);
2555 extern void memory_command(char *command);
2556 extern void print_memory_usage(void);
2558 extern void initialise_memory_block(memory_block *MB);
2559 extern void deallocate_memory_block(memory_block *MB);
2560 extern int read_byte_from_memory_block(memory_block *MB, int32 index);
2561 extern void write_byte_to_memory_block(memory_block *MB,
2562 int32 index, int value);
2564 /* ------------------------------------------------------------------------- */
2565 /* Extern definitions for "objects" */
2566 /* ------------------------------------------------------------------------- */
2568 extern int no_attributes, no_properties;
2569 extern int no_individual_properties;
2570 extern int individuals_length;
2571 extern uchar *individuals_table;
2572 extern int no_classes, no_objects;
2573 extern objecttz *objectsz;
2574 extern objecttg *objectsg;
2575 extern uchar *objectatts;
2576 extern int *class_object_numbers;
2577 extern int32 *class_begins_at;
2579 extern int32 *prop_default_value;
2580 extern int *prop_is_long;
2581 extern int *prop_is_additive;
2582 extern char *properties_table;
2583 extern int properties_table_size;
2585 extern void make_attribute(void);
2586 extern void make_property(void);
2587 extern void make_object(int nearby_flag,
2588 char *textual_name, int specified_parent, int specified_class,
2590 extern void make_class(char *metaclass_name);
2591 extern int object_provides(int obj, int id);
2592 extern void list_object_tree(void);
2593 extern void write_the_identifier_names(void);
2595 /* ------------------------------------------------------------------------- */
2596 /* Extern definitions for "symbols" */
2597 /* ------------------------------------------------------------------------- */
2599 extern int no_named_constants;
2600 extern int no_symbols;
2601 extern int32 **symbs;
2602 extern int32 *svals;
2604 extern brief_location *slines;
2607 extern char *stypes;
2609 extern signed char *stypes;
2611 extern maybe_file_position *symbol_debug_backpatch_positions;
2612 extern maybe_file_position *replacement_debug_backpatch_positions;
2613 extern int32 *individual_name_strings;
2614 extern int32 *attribute_name_strings;
2615 extern int32 *action_name_strings;
2616 extern int32 *array_name_strings;
2617 extern int track_unused_routines;
2618 extern int df_dont_note_global_symbols;
2619 extern uint32 df_total_size_before_stripping;
2620 extern uint32 df_total_size_after_stripping;
2622 extern char *typename(int type);
2623 extern int hash_code_from_string(char *p);
2624 extern int strcmpcis(char *p, char *q);
2625 extern int symbol_index(char *lexeme_text, int hashcode);
2626 extern void end_symbol_scope(int k);
2627 extern void describe_symbol(int k);
2628 extern void list_symbols(int level);
2629 extern void assign_marked_symbol(int index, int marker, int32 value, int type);
2630 extern void assign_symbol(int index, int32 value, int type);
2631 extern void issue_unused_warnings(void);
2632 extern void add_symbol_replacement_mapping(int original, int renamed);
2633 extern int find_symbol_replacement(int *value);
2634 extern void df_note_function_start(char *name, uint32 address,
2635 int embedded_flag, brief_location source_line);
2636 extern void df_note_function_end(uint32 endaddress);
2637 extern void df_note_function_symbol(int symbol);
2638 extern void locate_dead_functions(void);
2639 extern uint32 df_stripped_address_for_address(uint32);
2640 extern uint32 df_stripped_offset_for_code_offset(uint32, int *);
2641 extern void df_prepare_function_iterate(void);
2642 extern uint32 df_next_function_iterate(int *);
2644 /* ------------------------------------------------------------------------- */
2645 /* Extern definitions for "syntax" */
2646 /* ------------------------------------------------------------------------- */
2648 extern int no_syntax_lines;
2650 extern void panic_mode_error_recovery(void);
2651 extern void get_next_token_with_directives(void);
2652 extern int parse_directive(int internal_flag);
2653 extern void parse_program(char *source);
2654 extern int32 parse_routine(char *source, int embedded_flag, char *name,
2655 int veneer_flag, int r_symbol);
2656 extern void parse_code_block(int break_label, int continue_label,
2659 /* ------------------------------------------------------------------------- */
2660 /* Extern definitions for "states" */
2661 /* ------------------------------------------------------------------------- */
2663 extern void match_close_bracket(void);
2664 extern void parse_statement(int break_label, int continue_label);
2665 extern int parse_label(void);
2667 /* ------------------------------------------------------------------------- */
2668 /* Extern definitions for "tables" */
2669 /* ------------------------------------------------------------------------- */
2671 extern uchar *zmachine_paged_memory;
2673 code_offset, actions_offset, preactions_offset,
2674 dictionary_offset, strings_offset, adjectives_offset,
2675 variables_offset, class_numbers_offset, individuals_offset,
2676 identifier_names_offset, prop_defaults_offset, prop_values_offset,
2677 static_memory_offset, array_names_offset, attribute_names_offset,
2678 action_names_offset, fake_action_names_offset,
2679 routine_names_offset, routines_array_offset, routine_flags_array_offset,
2680 global_names_offset, global_flags_array_offset,
2681 array_flags_array_offset, constant_names_offset, constants_array_offset;
2683 arrays_offset, object_tree_offset, grammar_table_offset,
2684 abbreviations_offset; /* For Glulx */
2686 extern int32 Out_Size, Write_Code_At, Write_Strings_At;
2687 extern int32 RAM_Size, Write_RAM_At; /* For Glulx */
2689 extern int release_number, statusline_flag;
2690 extern int flags2_requirements[];
2691 extern int serial_code_given_in_program;
2692 extern char serial_code_buffer[];
2694 extern void construct_storyfile(void);
2695 extern void write_serial_number(char *buffer);
2697 /* ------------------------------------------------------------------------- */
2698 /* Extern definitions for "text" */
2699 /* ------------------------------------------------------------------------- */
2701 extern uchar *low_strings, *low_strings_top;
2702 extern char *all_text, *all_text_top;
2704 extern int no_abbreviations;
2705 extern int abbrevs_lookup_table_made, is_abbreviation;
2706 extern uchar *abbreviations_at;
2707 extern int *abbrev_values;
2708 extern int *abbrev_quality;
2709 extern int *abbrev_freqs;
2711 extern int32 total_chars_trans, total_bytes_trans,
2712 zchars_trans_in_last_string;
2713 extern int put_strings_in_low_memory;
2714 extern int dict_entries;
2715 extern uchar *dictionary, *dictionary_top;
2716 extern int *final_dict_order;
2718 extern memory_block static_strings_area;
2719 extern int32 static_strings_extent;
2721 /* And now, a great many declarations for dealing with Glulx string
2724 extern int32 no_strings, no_dynamic_strings;
2725 extern int no_unicode_chars;
2727 #define MAX_DYNAMIC_STRINGS (64)
2729 typedef struct unicode_usage_s unicode_usage_t;
2730 struct unicode_usage_s {
2732 unicode_usage_t *next;
2735 extern unicode_usage_t *unicode_usage_entries;
2737 /* This is the maximum number of (8-bit) bytes that can encode a single
2738 Huffman entity. Four should be plenty, unless someone starts encoding
2739 an ideographic language. */
2740 #define MAXHUFFBYTES (4)
2742 typedef struct huffbitlist_struct {
2743 uchar b[MAXHUFFBYTES];
2745 typedef struct huffentity_struct {
2758 extern huffentity_t *huff_entities;
2760 extern int32 compression_table_size, compression_string_size;
2761 extern int32 *compressed_offsets;
2762 extern int no_huff_entities;
2763 extern int huff_abbrev_start, huff_dynam_start, huff_unicode_start;
2764 extern int huff_entity_root;
2766 extern void compress_game_text(void);
2768 /* end of the Glulx string compression stuff */
2770 extern void ao_free_arrays(void);
2771 extern int32 compile_string(char *b, int in_low_memory, int is_abbrev);
2772 extern uchar *translate_text(uchar *p, uchar *p_limit, char *s_text);
2773 extern void optimise_abbreviations(void);
2774 extern void make_abbreviation(char *text);
2775 extern void show_dictionary(void);
2776 extern void word_to_ascii(uchar *p, char *result);
2777 extern void write_dictionary_to_transcript(void);
2778 extern void sort_dictionary(void);
2779 extern void dictionary_prepare(char *dword, uchar *optresult);
2780 extern int dictionary_add(char *dword, int x, int y, int z);
2781 extern void dictionary_set_verb_number(char *dword, int to);
2782 extern int compare_sorts(uchar *d1, uchar *d2);
2783 extern void copy_sorts(uchar *d1, uchar *d2);
2785 /* ------------------------------------------------------------------------- */
2786 /* Extern definitions for "veneer" */
2787 /* ------------------------------------------------------------------------- */
2789 extern int veneer_mode;
2790 extern int32 veneer_routine_address[];
2792 extern void compile_initial_routine(void);
2793 extern assembly_operand veneer_routine(int code);
2794 extern void compile_veneer(void);
2796 /* ------------------------------------------------------------------------- */
2797 /* Extern definitions for "verbs" */
2798 /* ------------------------------------------------------------------------- */
2800 extern int no_adjectives, no_Inform_verbs, no_grammar_token_routines,
2801 no_fake_actions, no_actions, no_grammar_lines, no_grammar_tokens,
2802 grammar_version_number;
2803 extern int32 grammar_version_symbol;
2804 extern verbt *Inform_verbs;
2805 extern uchar *grammar_lines;
2806 extern int32 grammar_lines_top;
2807 extern int32 *action_byte_offset,
2808 *grammar_token_routine,
2811 extern void find_the_actions(void);
2812 extern void make_fake_action(void);
2813 extern assembly_operand action_of_name(char *name);
2814 extern void make_verb(void);
2815 extern void extend_verb(void);
2816 extern void list_verb_table(void);
2818 /* ========================================================================= */