1 /* ------------------------------------------------------------------------- */
2 /* Header file for Inform: Z-machine ("Infocom" format) compiler */
4 /* Copyright (c) Graham Nelson 1993 - 2020 */
6 /* This file is part of Inform. */
8 /* Inform is free software: you can redistribute it and/or modify */
9 /* it under the terms of the GNU General Public License as published by */
10 /* the Free Software Foundation, either version 3 of the License, or */
11 /* (at your option) any later version. */
13 /* Inform is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU General Public License for more details. */
18 /* You should have received a copy of the GNU General Public License */
19 /* along with Inform. If not, see https://gnu.org/licenses/ */
21 /* *** 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 /* For releases, set to the release date in the form "1st January 2000" */
36 #define RELEASE_DATE "15 August 2020"
37 #define RELEASE_NUMBER 1635
38 #define GLULX_RELEASE_NUMBER 38
39 #define MODULE_VERSION_NUMBER 1
40 #define VNUMBER RELEASE_NUMBER
42 /* N indicates an intermediate release for Inform 7 */
43 /*#define RELEASE_SUFFIX "N"*/
45 /* ------------------------------------------------------------------------- */
46 /* Our host machine or OS for today is... */
48 /* [ Inform should compile (possibly with warnings) and work safely */
51 /* #define AMIGA - for the Commodore Amiga under SAS/C */
52 /* #define ARCHIMEDES - for Acorn RISC OS machines under Norcroft C */
53 /* #define ATARIST - for the Atari ST */
54 /* #define BEOS - for the BeBox */
55 /* #define LINUX - for Linux under gcc (essentially as Unix) */
56 /* #define MACOS - for the Apple Mac with OS X (another Unix) */
57 /* #define MAC_CLASSIC - for the Apple Mac under Think C or Codewarrior */
58 /* #define MAC_MPW - for MPW under Codewarrior (and maybe Think C) */
59 /* #define OS2 - for OS/2 32-bit mode under IBM's C Set++ */
60 /* #define PC - for 386+ IBM PCs, eg. Microsoft Visual C/C++ */
61 /* #define PC_QUICKC - for small IBM PCs under QuickC */
62 /* #define PC_WIN32 - for Borland C++ or Microsoft Visual C++ */
63 /* #define UNIX - for Unix under gcc (or big IBM PC under djgpp) */
64 /* #define VMS - for VAX or ALPHA under DEC C, but not VAX C */
66 /* In most cases executables are already available at */
67 /* http://www.ifarchive.org/, and these are sometimes enhanced with */
68 /* e.g. windowed interfaces whose source is not archived with the */
69 /* main Inform source.] */
71 /* (If no machine is defined, then cautious #defines will be made. In */
72 /* most cases, porting to a new machine is a matter of carefully filling */
73 /* out a block of definitions like those below.) */
74 /* ------------------------------------------------------------------------- */
78 /* ------------------------------------------------------------------------- */
79 /* The first task is to include the ANSI header files, and typedef */
80 /* suitable 32-bit integer types. */
81 /* ------------------------------------------------------------------------- */
93 #if SCHAR_MAX >= 0x7FFFFFFFL && SCHAR_MIN <= -0x7FFFFFFFL
94 typedef signed char int32;
95 typedef unsigned char uint32;
96 #elif SHRT_MAX >= 0x7FFFFFFFL && SHRT_MIN <= -0x7FFFFFFFL
97 typedef signed short int int32;
98 typedef unsigned short int uint32;
99 #elif INT_MAX >= 0x7FFFFFFFL && INT_MIN <= -0x7FFFFFFFL
100 typedef signed int int32;
101 typedef unsigned int uint32;
102 #elif LONG_MAX >= 0x7FFFFFFFL && LONG_MIN <= -0x7FFFFFFFL
103 typedef signed long int int32;
104 typedef unsigned long int uint32;
106 #error No type large enough to support 32-bit integers.
109 /* VAX C does not provide these limit constants, contrary to ANSI */
111 typedef unsigned int uint32;
114 /* ------------------------------------------------------------------------- */
115 /* The next part of this file contains blocks of definitions, one for */
116 /* each port, of machine or OS-dependent constants needed by Inform. */
118 /* 1. MACHINE_STRING should be set to the name of the machine or OS. */
120 /* 2. Some miscellaneous #define options (set if the constant is */
121 /* defined, otherwise not set): */
123 /* USE_TEMPORARY_FILES - use scratch files for workspace, not memory, */
125 /* PROMPT_INPUT - prompt input (don't use Unix-style command line) */
126 /* TIME_UNAVAILABLE - don't use ANSI time routines to work out today's */
128 /* CHAR_IS_UNSIGNED - if on your compiler the type "char" is unsigned */
129 /* by default, you should define this */
130 /* HAS_REALPATH - the POSIX realpath() function is available to */
131 /* find the absolute path to a file */
133 /* 3. An estimate of the typical amount of memory likely to be free */
134 /* should be given in DEFAULT_MEMORY_SIZE. */
135 /* For most modern machines, HUGE_SIZE is the appropriate setting, but */
136 /* some older micros may benefit from SMALL_SIZE. */
137 /* ------------------------------------------------------------------------- */
143 /* ------------------------------------------------------------------------- */
144 /* 4. Filenaming definitions: */
146 /* It's assumed that the host OS has the concept of subdirectories and */
147 /* has "pathnames", that is, filenames giving a chain of subdirectories */
148 /* divided by the FN_SEP (filename separator) character: e.g. for Unix */
149 /* FN_SEP is defined below as '/' and a typical name is */
150 /* "users/graham/jigsaw.z5". */
151 /* White space is not allowed in filenames, and nor is the special */
152 /* character FN_ALT, which unless defined here will be a comma and will */
153 /* be used to separate alternative locations in a path variable. */
155 /* If NO_FILE_EXTENSIONS is undefined then the OS allows "file extensions" */
156 /* of 1 to 3 alphanumeric characters like ".txt" (for text files), ".z5" */
157 /* (for game files), etc., to indicate the file's type (and, crucially, */
158 /* regards the same filename but with different extensions -- e.g., */
159 /* "frog.amp" and "frog.lil" -- as being different names). */
160 /* (The file extensions defined below are widely accepted, so please use */
161 /* them unless there's a good reason why not.) */
163 /* You should then define STANDARD_DIRECTORIES (you can define it anyway) */
164 /* in which case Inform will expect by default that files are sorted out */
165 /* by being put into suitable directories (e.g., a "games" directory for */
168 /* If it's convenient for your port you can alter the detailed definitions */
169 /* which these broad settings make. Be careful if NO_FILE_EXTENSIONS */
170 /* is set without STANDARD_DIRECTORIES, as then Inform may */
171 /* overwrite its source with object code. */
173 /* 5. Filenames (or code related to filenames) for the three temporary */
174 /* files. These only exist during compilation (and only if -F1 is set). */
175 /* Temporary_Name is the body of a filename to use */
176 /* (if you don't set this, it becomes "Inftemp") and Temporary_Directory */
177 /* is the directory path for the files to go in (which can be altered on */
178 /* the command line). On some multi-tasking OSs these filenames ought to */
179 /* include a number uniquely identifying the process: to indicate this, */
180 /* define INCLUDE_TASK_ID and provide some code... */
182 /* #define INCLUDE_TASK_ID */
183 /* #ifdef INFORM_FILE */
184 /* static int32 unique_task_id(void) */
185 /* { ...some code returning your task ID... */
189 /* 6. Any other definitions specific to the OS or machine. */
190 /* (In particular DEFAULT_ERROR_FORMAT is 0 on most machines and 1 on PCs; */
191 /* it controls the style of error messages, which is important for some */
192 /* error-throwback debugging tools.) */
193 /* ------------------------------------------------------------------------- */
195 /* ========================================================================= */
196 /* The blocks now follow in alphabetical order. */
197 /* ------------------------------------------------------------------------- */
199 /* ------------------------------------------------------------------------- */
202 #define MACHINE_STRING "Amiga"
204 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
208 #define __USE_SYSBASE
209 #include <proto/exec.h>
210 #define INCLUDE_TASK_ID
211 #define Temporary_Directory "T:"
212 #ifdef MAIN_INFORM_FILE
213 static int32 unique_task_id(void)
214 { return (int32)FindTask(NULL);
218 /* ------------------------------------------------------------------------- */
219 /* ARCHIMEDES block: Acorn/RISC OS settings */
220 /* ------------------------------------------------------------------------- */
223 #define MACHINE_STRING "RISC OS"
225 #define CHAR_IS_UNSIGNED
227 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
230 #define STANDARD_DIRECTORIES
231 #define NO_FILE_EXTENSIONS
232 #define Source_Directory "inform"
233 #define ICL_Directory "ICL"
235 #define ENABLE_TEMPORARY_PATH
236 #define Temporary_Directory "ram:"
238 #define ARC_THROWBACK
240 /* ------------------------------------------------------------------------- */
242 /* ------------------------------------------------------------------------- */
245 #define MACHINE_STRING "Atari ST"
247 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
252 #define Temporary_Directory "/tmp"
253 #define INCLUDE_TASK_ID
254 #ifdef MAIN_INFORM_FILE
255 static int32 unique_task_id(void)
256 { return (int32)getpid();
261 /* ------------------------------------------------------------------------- */
263 /* ------------------------------------------------------------------------- */
266 #define MACHINE_STRING "BeOS"
268 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
271 #define FILE_EXTENSIONS
273 #define Temporary_Directory "/tmp"
275 /* ------------------------------------------------------------------------- */
277 /* ------------------------------------------------------------------------- */
280 #define MACHINE_STRING "Linux"
284 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
288 #define Temporary_Directory "/tmp"
292 /* ------------------------------------------------------------------------- */
293 /* Macintosh block */
294 /* ------------------------------------------------------------------------- */
302 #define MACHINE_STRING "Macintosh Programmer's Workshop"
304 #define MACHINE_STRING "Macintosh"
308 #define EXTERNAL_SHELL
316 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
320 #define Include_Extension ".h"
324 #include "TB Inform.h"
327 #include <CursorCtl.h>
328 #define DEFAULT_ERROR_FORMAT 2
331 /* ------------------------------------------------------------------------- */
333 /* ------------------------------------------------------------------------- */
336 #define MACHINE_STRING "OS/2"
338 #define CHAR_IS_UNSIGNED
340 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
344 /* ------------------------------------------------------------------------- */
346 /* ------------------------------------------------------------------------- */
349 #define MACHINE_STRING "MacOS"
353 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
357 #define Temporary_Directory "/tmp"
358 #define INCLUDE_TASK_ID
359 #define _POSIX_C_SOURCE 199506L
360 #define _XOPEN_SOURCE 500
361 #ifdef MAIN_INFORM_FILE
362 #include <sys/types.h>
364 static int32 unique_task_id(void)
365 { return (int32)getpid();
371 /* ------------------------------------------------------------------------- */
372 /* PC and PC_QUICKC block */
373 /* ------------------------------------------------------------------------- */
380 #define MACHINE_STRING "PC"
382 #define USE_TEMPORARY_FILES
385 #define DEFAULT_MEMORY_SIZE SMALL_SIZE
387 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
392 #define DEFAULT_ERROR_FORMAT 1
394 /* ------------------------------------------------------------------------- */
396 /* ------------------------------------------------------------------------- */
399 #define MACHINE_STRING "Win32"
403 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
407 #define DEFAULT_ERROR_FORMAT 1
409 #ifdef _MSC_VER /* Microsoft Visual C++ */
410 #define snprintf _snprintf
412 #define isinf(x) (!_isnan(x) && !_finite(x))
415 /* ------------------------------------------------------------------------- */
417 /* ------------------------------------------------------------------------- */
420 #ifndef MACHINE_STRING
421 #define MACHINE_STRING "Unix"
426 #define DEFAULT_MEMORY_SIZE HUGE_SIZE
431 #define Temporary_Directory "/tmp"
432 #define INCLUDE_TASK_ID
433 #ifdef MAIN_INFORM_FILE
435 static int32 unique_task_id(void)
436 { return (int32)getpid();
440 /* ------------------------------------------------------------------------- */
441 /* VMS (Dec VAX and Alpha) block */
442 /* ------------------------------------------------------------------------- */
450 #define MACHINE_STRING "Alpha/VMS"
452 #define MACHINE_STRING "VAX/VMS"
455 #define CHAR_IS_UNSIGNED
457 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
460 #define Code_Extension ".zip"
461 #define V4Code_Extension ".zip"
462 #define V5Code_Extension ".zip"
463 #define V6Code_Extension ".zip"
464 #define V7Code_Extension ".zip"
465 #define V8Code_Extension ".zip"
467 /* ========================================================================= */
468 /* Default settings: */
469 /* ------------------------------------------------------------------------- */
471 #ifndef NO_FILE_EXTENSIONS
472 #define FILE_EXTENSIONS
475 #ifndef Transcript_File
476 #ifdef FILE_EXTENSIONS
477 #define Transcript_File "gametext.txt"
479 #define Transcript_File "gametext"
483 #ifndef Debugging_File
484 #ifdef FILE_EXTENSIONS
485 #define Debugging_File "gameinfo.dbg"
487 #define Debugging_File "gamedebug"
491 #ifndef Default_Language
492 #define Default_Language "english"
495 #ifdef FILE_EXTENSIONS
496 #ifndef Source_Extension
497 #define Source_Extension ".inf"
499 #ifndef Include_Extension
500 #define Include_Extension ".h"
502 #ifndef Code_Extension
503 #define Code_Extension ".z3"
505 #ifndef V4Code_Extension
506 #define V4Code_Extension ".z4"
508 #ifndef V5Code_Extension
509 #define V5Code_Extension ".z5"
511 #ifndef V6Code_Extension
512 #define V6Code_Extension ".z6"
514 #ifndef V7Code_Extension
515 #define V7Code_Extension ".z7"
517 #ifndef V8Code_Extension
518 #define V8Code_Extension ".z8"
520 #ifndef GlulxCode_Extension
521 #define GlulxCode_Extension ".ulx"
523 #ifndef Module_Extension
524 #define Module_Extension ".m5"
526 #ifndef ICL_Extension
527 #define ICL_Extension ".icl"
532 #define Source_Extension ""
533 #define Include_Extension ""
534 #define Code_Extension ""
535 #define V4Code_Extension ""
536 #define V5Code_Extension ""
537 #define V6Code_Extension ""
538 #define V7Code_Extension ""
539 #define V8Code_Extension ""
540 #define GlulxCode_Extension ""
541 #define Module_Extension ""
542 #define ICL_Extension ""
545 #ifdef STANDARD_DIRECTORIES
546 #ifndef Source_Directory
547 #define Source_Directory "source"
549 #ifndef Include_Directory
550 #define Include_Directory "library"
552 #ifndef Code_Directory
553 #define Code_Directory "games"
555 #ifndef Module_Directory
556 #define Module_Directory "modules"
558 #ifndef Temporary_Directory
559 #define Temporary_Directory ""
561 #ifndef ICL_Directory
562 #define ICL_Directory ""
567 #ifndef Source_Directory
568 #define Source_Directory ""
570 #ifndef Include_Directory
571 #define Include_Directory ""
573 #ifndef Code_Directory
574 #define Code_Directory ""
576 #ifndef Module_Directory
577 #define Module_Directory ""
579 #ifndef Temporary_Directory
580 #define Temporary_Directory ""
582 #ifndef ICL_Directory
583 #define ICL_Directory ""
599 #ifndef Temporary_File
600 #define Temporary_File "Inftemp"
603 #ifndef DEFAULT_ERROR_FORMAT
604 #define DEFAULT_ERROR_FORMAT 0
607 #ifndef DEFAULT_MEMORY_SIZE
608 #define DEFAULT_MEMORY_SIZE LARGE_SIZE
611 #ifndef CHAR_IS_UNSIGNED
612 typedef unsigned char uchar;
617 #if defined(__GNUC__) || defined(__clang__)
618 #define NORETURN __attribute__((__noreturn__))
619 #endif /* defined(__GNUC__) || defined(__clang__) */
625 /* ------------------------------------------------------------------------- */
626 /* A macro (rather than constant) definition: */
627 /* ------------------------------------------------------------------------- */
630 void _huge * halloc(long, size_t);
632 #define subtract_pointers(p1,p2) (long)((char _huge *)p1-(char _huge *)p2)
634 #define subtract_pointers(p1,p2) (((char *) p1)-((char *) p2))
637 /* ------------------------------------------------------------------------- */
638 /* SEEK_SET is a constant which should be defined in the ANSI header files */
639 /* but which is not present in some implementations: it's used as a */
640 /* parameter for "fseek", defined in "stdio". In pre-ANSI C, the value */
641 /* 0 was used as a parameter instead, hence the definition below. */
642 /* ------------------------------------------------------------------------- */
648 /* ------------------------------------------------------------------------- */
649 /* A large block of #define'd constant values follows. */
650 /* ------------------------------------------------------------------------- */
655 /* These checked the glulx_mode global during development, but are no
657 #define ASSERT_ZCODE() (0)
658 #define ASSERT_GLULX() (0)
661 #define ReadInt32(ptr) \
662 ( (((int32)(((uchar *)(ptr))[0])) << 24) \
663 | (((int32)(((uchar *)(ptr))[1])) << 16) \
664 | (((int32)(((uchar *)(ptr))[2])) << 8) \
665 | (((int32)(((uchar *)(ptr))[3])) ) )
667 #define ReadInt16(ptr) \
668 ( (((int32)(((uchar *)(ptr))[0])) << 8) \
669 | (((int32)(((uchar *)(ptr))[1])) ) )
671 #define WriteInt32(ptr, val) \
672 ((ptr)[0] = (uchar)(((int32)(val)) >> 24), \
673 (ptr)[1] = (uchar)(((int32)(val)) >> 16), \
674 (ptr)[2] = (uchar)(((int32)(val)) >> 8), \
675 (ptr)[3] = (uchar)(((int32)(val)) ) )
677 #define WriteInt16(ptr, val) \
678 ((ptr)[0] = (uchar)(((int32)(val)) >> 8), \
679 (ptr)[1] = (uchar)(((int32)(val)) ) )
681 /* ------------------------------------------------------------------------- */
682 /* If your compiler doesn't recognise \t, and you use ASCII, you could */
683 /* define T_C as (char) 9; failing that, it _must_ be defined as ' ' */
684 /* (space) and is _not_ allowed to be 0 or any recognisable character. */
685 /* ------------------------------------------------------------------------- */
687 #define TAB_CHARACTER '\t'
689 /* ------------------------------------------------------------------------- */
691 /* ------------------------------------------------------------------------- */
693 #define MAX_ERRORS 100
694 #define MAX_IDENTIFIER_LENGTH 32
695 #define MAX_ABBREV_LENGTH 64
696 #define MAX_DICT_WORD_SIZE 40
697 #define MAX_DICT_WORD_BYTES (40*4)
698 #define MAX_NUM_ATTR_BYTES 39
699 #define MAX_VERB_WORD_SIZE 120
701 #define VENEER_CONSTRAINT_ON_CLASSES_Z 256
702 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_Z 128
703 #define VENEER_CONSTRAINT_ON_CLASSES_G 32768
704 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_G 32768
705 #define VENEER_CONSTRAINT_ON_CLASSES \
706 (glulx_mode ? VENEER_CONSTRAINT_ON_CLASSES_G \
707 : VENEER_CONSTRAINT_ON_CLASSES_Z)
708 #define VENEER_CONSTRAINT_ON_IP_TABLE_SIZE \
709 (glulx_mode ? VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_G \
710 : VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_Z)
712 #define GLULX_HEADER_SIZE 36
713 /* Number of bytes in the header. */
714 #define GLULX_STATIC_ROM_SIZE 24
715 /* Number of bytes in the Inform-specific block right after the header. */
716 #define GPAGESIZE 256
717 /* All Glulx memory boundaries must be multiples of GPAGESIZE. */
719 /* ------------------------------------------------------------------------- */
720 /* Structure definitions (there are a few others local to files) */
721 /* ------------------------------------------------------------------------- */
723 typedef struct assembly_operand_t
726 int symtype; /* 6.30 */
727 int symflags; /* 6.30 */
731 #define INITAOTV(aop, typ, val) ((aop)->type=(typ), (aop)->value=(val), (aop)->marker=0, (aop)->symtype=0, (aop)->symflags=0)
732 #define INITAOT(aop, typ) INITAOTV(aop, typ, 0)
733 #define INITAO(aop) INITAOTV(aop, 0, 0)
735 #define MAX_LINES_PER_VERB 32
736 typedef struct verbt {
738 int l[MAX_LINES_PER_VERB];
741 typedef struct prop {
743 assembly_operand ao[32];
746 /* Only one of this object. */
747 typedef struct fpropt {
753 typedef struct objecttz {
755 int parent, next, child;
759 typedef struct propg {
767 /* Only one of this object. */
768 typedef struct fproptg {
769 uchar atts[MAX_NUM_ATTR_BYTES];
773 assembly_operand *propdata;
777 typedef struct objecttg {
778 /* attributes are stored in a separate array */
780 int32 parent, next, child;
785 typedef struct maybe_file_position_S
788 } maybe_file_position;
790 typedef struct debug_location_s
792 int32 beginning_byte_index;
793 int32 end_byte_index;
794 int32 beginning_line_number;
795 int32 end_line_number;
796 int32 beginning_character_number;
797 int32 end_character_number;
798 int32 orig_file_index;
799 int32 orig_beg_line_number;
800 int32 orig_beg_char_number;
801 /* We only track the beginning #origsource location, not the end. */
804 typedef struct debug_locations_s
805 { debug_location location;
806 struct debug_locations_s *next;
810 typedef struct brief_location_s
813 int32 orig_file_index;
814 int32 orig_line_number;
817 typedef struct debug_location_beginning_s
818 { debug_locations *head;
819 int32 beginning_byte_index;
820 int32 beginning_line_number;
821 int32 beginning_character_number;
822 int32 orig_file_index;
823 int32 orig_beg_line_number;
824 int32 orig_beg_char_number;
825 } debug_location_beginning;
827 typedef struct keyword_group_s
828 { char *keywords[120];
829 int change_token_type;
834 typedef struct token_data_s
836 int32 value; /* ###-long */
838 int symtype; /* 6.30 */
839 int symflags; /* 6.30 */
841 debug_location location;
844 typedef struct FileId_s /* Source code file identifier: */
845 { char *filename; /* The filename (after translation) */
846 FILE *handle; /* Handle of file (when open), or
848 int is_input; /* Is this a source file that we are
849 parsing? If not, this is an
850 origsource filename (and handle
854 typedef struct ErrorPosition_s
865 /* A memory block can hold at most ALLOC_CHUNK_SIZE * 72: */
867 extern int ALLOC_CHUNK_SIZE;
869 typedef struct memory_block_s
876 /* This serves for both Z-code and Glulx instructions. Glulx doesn't use
877 the text, store_variable_number, branch_label_number, or branch_flag
879 typedef struct assembly_instruction_t
880 { int internal_number;
881 int store_variable_number;
882 int32 branch_label_number;
886 assembly_operand operand[8];
887 } assembly_instruction;
889 typedef struct expression_tree_node_s
891 /* Data used in tree construction */
894 int operator_number; /* Only meaningful for non-leaves */
895 assembly_operand value; /* Only meaningful for leaves */
897 /* Attributes synthesised during code generation */
899 int must_produce_value; /* e.g. FALSE in a void context */
901 int label_after; /* -1, or "put this label after code" */
902 int to_expression; /* TRUE if a condition used as numeric val */
903 int true_label; /* On condition "true", jump to this (or keep
905 int false_label; /* Likewise if the condition is "false". */
907 } expression_tree_node;
909 typedef struct operator_s
910 { int precedence; /* Level 0 to 13 (13 is highest) */
911 int token_type; /* Lexical token type */
912 int token_value; /* Lexical token value */
913 int usage; /* Infix (IN_U), prefix or postfix */
914 int associativity; /* Left (L_A), right (R_A)
915 or 0 for "it is an error to
916 implicitly associate this" */
917 int requires_lvalue; /* TRUE if the first operand must
918 be an "lvalue" (the name of some
919 storage object, such as a variable
920 or an array entry) */
921 int opcode_number_z; /* Translation number (see below) */
922 int opcode_number_g; /* Translation number (see below) */
923 int side_effect; /* TRUE if evaluating the operator
924 has potential side-effects in
925 terms of changing the Z-machine */
926 int negation; /* 0 for an unconditional operator,
927 otherwise the negation operator */
928 char *description; /* Text describing the operator
929 for error messages and tracing */
932 /* The translation number of an operator is as follows:
935 an internal opcode number if the operator can be translated
936 directly to a single Z-machine opcode;
937 400+n if it can be translated to branch opcode n;
938 800+n if to the negated form of branch opcode n;
939 (using n = 200, 201 for two conditions requiring special
943 an internal opcode number if the operator can be translated
944 directly to a single Glulx opcode;
945 FIRST_CC to LAST_CC if it is a condition;
948 /* ------------------------------------------------------------------------- */
949 /* Assembly operand types. */
950 /* ------------------------------------------------------------------------- */
952 /* For Z-machine... */
954 #define LONG_CONSTANT_OT 0 /* General constant */
955 #define SHORT_CONSTANT_OT 1 /* Constant in range 0 to 255 */
956 #define VARIABLE_OT 2 /* Variable (global, local or sp) */
957 #define OMITTED_OT 3 /* Value used in type field to indicate
958 that no operand is supplied */
959 #define EXPRESSION_OT 4 /* Meaning: to determine this value, run code
960 equivalent to the expression tree whose
961 root node-number is the value given */
965 /* #define OMITTED_OT 3 */ /* Same as above */
966 /* #define EXPRESSION_OT 4 */ /* Same as above */
967 #define CONSTANT_OT 5 /* Four-byte constant */
968 #define HALFCONSTANT_OT 6 /* Two-byte constant */
969 #define BYTECONSTANT_OT 7 /* One-byte constant */
970 #define ZEROCONSTANT_OT 8 /* Constant zero (no bytes of data) */
971 #define SYSFUN_OT 9 /* System function value */
972 #define DEREFERENCE_OT 10 /* Value at this address */
973 #define GLOBALVAR_OT 11 /* Global variable */
974 #define LOCALVAR_OT 12 /* Local variable or sp */
976 /* ------------------------------------------------------------------------- */
977 /* Internal numbers representing assemble-able Z-opcodes */
978 /* ------------------------------------------------------------------------- */
989 #define test_attr_zc 9
990 #define set_attr_zc 10
991 #define clear_attr_zc 11
993 #define insert_obj_zc 13
996 #define get_prop_zc 16
997 #define get_prop_addr_zc 17
998 #define get_next_prop_zc 18
1005 #define storew_zc 25
1006 #define storeb_zc 26
1007 #define put_prop_zc 27
1009 #define print_char_zc 29
1010 #define print_num_zc 30
1011 #define random_zc 31
1014 #define split_window_zc 34
1015 #define set_window_zc 35
1016 #define output_stream_zc 36
1017 #define input_stream_zc 37
1018 #define sound_effect_zc 38
1020 #define get_sibling_zc 40
1021 #define get_child_zc 41
1022 #define get_parent_zc 42
1023 #define get_prop_len_zc 43
1026 #define print_addr_zc 46
1027 #define remove_obj_zc 47
1028 #define print_obj_zc 48
1031 #define print_paddr_zc 51
1035 #define rfalse_zc 55
1037 #define print_ret_zc 57
1040 #define restore_zc 60
1041 #define restart_zc 61
1042 #define ret_popped_zc 62
1045 #define new_line_zc 65
1046 #define show_status_zc 66
1047 #define verify_zc 67
1048 #define call_2s_zc 68
1049 #define call_vs_zc 69
1051 #define call_vs2_zc 71
1052 #define erase_window_zc 72
1053 #define erase_line_zc 73
1054 #define set_cursor_zc 74
1055 #define get_cursor_zc 75
1056 #define set_text_style_zc 76
1057 #define buffer_mode_zc 77
1058 #define read_char_zc 78
1059 #define scan_table_zc 79
1060 #define call_1s_zc 80
1061 #define call_2n_zc 81
1062 #define set_colour_zc 82
1064 #define call_vn_zc 84
1065 #define call_vn2_zc 85
1066 #define tokenise_zc 86
1067 #define encode_text_zc 87
1068 #define copy_table_zc 88
1069 #define print_table_zc 89
1070 #define check_arg_count_zc 90
1071 #define call_1n_zc 91
1073 #define piracy_zc 93
1074 #define log_shift_zc 94
1075 #define art_shift_zc 95
1076 #define set_font_zc 96
1077 #define save_undo_zc 97
1078 #define restore_undo_zc 98
1079 #define draw_picture_zc 99
1080 #define picture_data_zc 100
1081 #define erase_picture_zc 101
1082 #define set_margins_zc 102
1083 #define move_window_zc 103
1084 #define window_size_zc 104
1085 #define window_style_zc 105
1086 #define get_wind_prop_zc 106
1087 #define scroll_window_zc 107
1088 #define pop_stack_zc 108
1089 #define read_mouse_zc 109
1090 #define mouse_window_zc 110
1091 #define push_stack_zc 111
1092 #define put_wind_prop_zc 112
1093 #define print_form_zc 113
1094 #define make_menu_zc 114
1095 #define picture_table_zc 115
1096 #define print_unicode_zc 116
1097 #define check_unicode_zc 117
1100 /* ------------------------------------------------------------------------- */
1101 /* Internal numbers representing assemble-able Glulx opcodes */
1102 /* ------------------------------------------------------------------------- */
1114 #define bitnot_gc 10
1115 #define shiftl_gc 11
1116 #define sshiftr_gc 12
1117 #define ushiftr_gc 13
1132 #define return_gc 28
1135 #define tailcall_gc 31
1142 #define aloads_gc 38
1143 #define aloadb_gc 39
1144 #define aloadbit_gc 40
1145 #define astore_gc 41
1146 #define astores_gc 42
1147 #define astoreb_gc 43
1148 #define astorebit_gc 44
1149 #define stkcount_gc 45
1150 #define stkpeek_gc 46
1151 #define stkswap_gc 47
1152 #define stkroll_gc 48
1153 #define stkcopy_gc 49
1154 #define streamchar_gc 50
1155 #define streamnum_gc 51
1156 #define streamstr_gc 52
1157 #define gestalt_gc 53
1158 #define debugtrap_gc 54
1159 #define getmemsize_gc 55
1160 #define setmemsize_gc 56
1161 #define jumpabs_gc 57
1162 #define random_gc 58
1163 #define setrandom_gc 59
1165 #define verify_gc 61
1166 #define restart_gc 62
1168 #define restore_gc 64
1169 #define saveundo_gc 65
1170 #define restoreundo_gc 66
1171 #define protect_gc 67
1173 #define getstringtbl_gc 69
1174 #define setstringtbl_gc 70
1175 #define getiosys_gc 71
1176 #define setiosys_gc 72
1177 #define linearsearch_gc 73
1178 #define binarysearch_gc 74
1179 #define linkedsearch_gc 75
1181 #define callfi_gc 77
1182 #define callfii_gc 78
1183 #define callfiii_gc 79
1184 #define streamunichar_gc 80
1187 #define malloc_gc 83
1189 #define accelfunc_gc 85
1190 #define accelparam_gc 86
1191 #define numtof_gc 87
1192 #define ftonumz_gc 88
1193 #define ftonumn_gc 89
1211 #define atan2_gc 107
1218 #define jisnan_gc 114
1219 #define jisinf_gc 115
1221 /* ------------------------------------------------------------------------- */
1222 /* Index numbers into the keyword group "opcode_macros_g" (see "lexer.c") */
1223 /* ------------------------------------------------------------------------- */
1229 #define SYMBOL_TT 0 /* value = index in symbol table */
1230 #define NUMBER_TT 1 /* value = the number */
1231 #define DQ_TT 2 /* no value */
1232 #define SQ_TT 3 /* no value */
1233 #define SEP_TT 4 /* value = the _SEP code */
1234 #define EOF_TT 5 /* no value */
1236 #define STATEMENT_TT 100 /* a statement keyword */
1237 #define SEGMENT_MARKER_TT 101 /* with/has/class etc. */
1238 #define DIRECTIVE_TT 102 /* a directive keyword */
1239 #define CND_TT 103 /* in/has/etc. */
1240 #define SYSFUN_TT 105 /* built-in function */
1241 #define LOCAL_VARIABLE_TT 106 /* local variable */
1242 #define OPCODE_NAME_TT 107 /* opcode name */
1243 #define MISC_KEYWORD_TT 108 /* keyword like "char" used in
1244 syntax for a statement */
1245 #define DIR_KEYWORD_TT 109 /* keyword like "meta" used in
1246 syntax for a directive */
1247 #define TRACE_KEYWORD_TT 110 /* keyword used in debugging */
1248 #define SYSTEM_CONSTANT_TT 111 /* such as "code_offset" */
1249 #define OPCODE_MACRO_TT 112 /* fake opcode for compatibility */
1251 #define OP_TT 200 /* value = operator no */
1252 #define ENDEXP_TT 201 /* no value */
1253 #define SUBOPEN_TT 202 /* ( used for subexpr */
1254 #define SUBCLOSE_TT 203 /* ) used to close subexp */
1255 #define LARGE_NUMBER_TT 204 /* constant not in range 0-255 */
1256 #define SMALL_NUMBER_TT 205 /* constant in range 0-255 */
1257 /* In Glulx, that's the range -0x8000 to 0x7fff instead. */
1258 #define VARIABLE_TT 206 /* variable name */
1259 #define DICTWORD_TT 207 /* literal 'word' */
1260 #define ACTION_TT 208 /* action name */
1262 #define VOID_CONTEXT 1
1263 #define CONDITION_CONTEXT 2
1264 #define CONSTANT_CONTEXT 3
1265 #define QUANTITY_CONTEXT 4
1266 #define ACTION_Q_CONTEXT 5
1267 #define ASSEMBLY_CONTEXT 6
1268 #define ARRAY_CONTEXT 7
1269 #define FORINIT_CONTEXT 8
1270 #define RETURN_Q_CONTEXT 9
1272 #define LOWEST_SYSTEM_VAR_NUMBER 249 /* globals 249 to 255 are used
1273 in compiled code (Z-code
1274 only; in Glulx, the range can
1277 /* ------------------------------------------------------------------------- */
1278 /* Symbol flag definitions (in no significant order) */
1279 /* ------------------------------------------------------------------------- */
1281 #define UNKNOWN_SFLAG 1
1282 #define REPLACE_SFLAG 2
1283 #define USED_SFLAG 4
1284 #define DEFCON_SFLAG 8
1285 #define STUB_SFLAG 16
1286 #define IMPORT_SFLAG 32
1287 #define EXPORT_SFLAG 64
1288 #define ALIASED_SFLAG 128
1290 #define CHANGE_SFLAG 256
1291 #define SYSTEM_SFLAG 512
1292 #define INSF_SFLAG 1024
1293 #define UERROR_SFLAG 2048
1294 #define ACTION_SFLAG 4096
1295 #define REDEFINABLE_SFLAG 8192
1296 #define STAR_SFLAG 16384
1298 /* ------------------------------------------------------------------------- */
1299 /* Symbol type definitions */
1300 /* ------------------------------------------------------------------------- */
1304 #define GLOBAL_VARIABLE_T 3
1306 #define CONSTANT_T 5
1307 #define ATTRIBUTE_T 6
1308 #define PROPERTY_T 7
1309 #define INDIVIDUAL_PROPERTY_T 8
1312 #define FAKE_ACTION_T 11
1313 #define STATIC_ARRAY_T 12
1315 /* ------------------------------------------------------------------------- */
1316 /* Statusline_flag values */
1317 /* ------------------------------------------------------------------------- */
1319 #define SCORE_STYLE 0
1320 #define TIME_STYLE 1
1322 /* ------------------------------------------------------------------------- */
1323 /* Inform keyword definitions */
1324 /* ------------------------------------------------------------------------- */
1326 /* Index numbers into the keyword group "directives" (see "lexer.c") */
1328 #define ABBREVIATE_CODE 0
1329 #define ARRAY_CODE 1
1330 #define ATTRIBUTE_CODE 2
1331 #define CLASS_CODE 3
1332 #define CONSTANT_CODE 4
1333 #define DEFAULT_CODE 5
1334 #define DICTIONARY_CODE 6
1336 #define ENDIF_CODE 8
1337 #define EXTEND_CODE 9
1338 #define FAKE_ACTION_CODE 10
1339 #define GLOBAL_CODE 11
1340 #define IFDEF_CODE 12
1341 #define IFNDEF_CODE 13
1342 #define IFNOT_CODE 14
1343 #define IFV3_CODE 15
1344 #define IFV5_CODE 16
1345 #define IFTRUE_CODE 17
1346 #define IFFALSE_CODE 18
1347 #define IMPORT_CODE 19
1348 #define INCLUDE_CODE 20
1349 #define LINK_CODE 21
1350 #define LOWSTRING_CODE 22
1351 #define MESSAGE_CODE 23
1352 #define NEARBY_CODE 24
1353 #define OBJECT_CODE 25
1354 #define ORIGSOURCE_CODE 26
1355 #define PROPERTY_CODE 27
1356 #define RELEASE_CODE 28
1357 #define REPLACE_CODE 29
1358 #define SERIAL_CODE 30
1359 #define SWITCHES_CODE 31
1360 #define STATUSLINE_CODE 32
1361 #define STUB_CODE 33
1362 #define SYSTEM_CODE 34
1363 #define TRACE_CODE 35
1364 #define UNDEF_CODE 36
1365 #define VERB_CODE 37
1366 #define VERSION_CODE 38
1367 #define ZCHARACTER_CODE 39
1369 #define OPENBLOCK_CODE 100
1370 #define CLOSEBLOCK_CODE 101
1372 /* Index numbers into the keyword group "statements" (see "lexer.c") */
1375 #define BREAK_CODE 1
1376 #define CONTINUE_CODE 2
1377 #define SDEFAULT_CODE 3
1384 #define INVERSION_CODE 10
1385 #define JUMP_CODE 11
1386 #define MOVE_CODE 12
1387 #define NEW_LINE_CODE 13
1388 #define OBJECTLOOP_CODE 14
1389 #define PRINT_CODE 15
1390 #define PRINT_RET_CODE 16
1391 #define QUIT_CODE 17
1392 #define READ_CODE 18
1393 #define REMOVE_CODE 19
1394 #define RESTORE_CODE 20
1395 #define RETURN_CODE 21
1396 #define RFALSE_CODE 22
1397 #define RTRUE_CODE 23
1398 #define SAVE_CODE 24
1399 #define SPACES_CODE 25
1400 #define STRING_CODE 26
1401 #define STYLE_CODE 27
1402 #define SWITCH_CODE 28
1403 #define UNTIL_CODE 29
1404 #define WHILE_CODE 30
1406 #define ASSIGNMENT_CODE 100
1407 #define FUNCTION_CODE 101
1409 /* Index numbers into the keyword group "conditions" (see "lexer.c") */
1412 #define HASNT_COND 1
1414 #define NOTIN_COND 3
1415 #define OFCLASS_COND 4
1417 #define PROVIDES_COND 6
1419 /* Index numbers into the keyword group "segment_markers" (see "lexer.c") */
1421 #define CLASS_SEGMENT 0
1422 #define HAS_SEGMENT 1
1423 #define PRIVATE_SEGMENT 2
1424 #define WITH_SEGMENT 3
1426 /* Index numbers into the keyword group "misc_keywords" (see "lexer.c") */
1433 #define CAP_THE_MK 5
1436 #define REVERSE_MK 8
1438 #define UNDERLINE_MK 10
1443 #define ADDRESS_MK 15
1444 #define STRING_MK 16
1445 #define OBJECT_MK 17
1448 #define PROPERTY_MK 20
1451 /* Index numbers into the keyword group "directive_keywords" (see "lexer.c") */
1455 #define ADDITIVE_DK 2
1461 #define MULTIHELD_DK 8
1462 #define MULTIEXCEPT_DK 9
1463 #define MULTIINSIDE_DK 10
1464 #define CREATURE_DK 11
1465 #define SPECIAL_DK 12
1466 #define NUMBER_DK 13
1469 #define REVERSE_DK 16
1472 #define REPLACE_DK 19
1475 #define STRING_DK 22
1477 #define BUFFER_DK 24
1479 #define INITIAL_DK 26
1480 #define INITSTR_DK 27
1482 #define PRIVATE_DK 29
1486 #define FATALERROR_DK 33
1487 #define WARNING_DK 34
1488 #define TERMINATING_DK 35
1489 #define STATIC_DK 36
1491 /* Index numbers into the keyword group "trace_keywords" (see "lexer.c") */
1493 #define DICTIONARY_TK 0
1494 #define SYMBOLS_TK 1
1495 #define OBJECTS_TK 2
1497 #define ASSEMBLY_TK 4
1498 #define EXPRESSIONS_TK 5
1505 /* Index numbers into the keyword group "system_constants" (see "lexer.c") */
1507 #define NO_SYSTEM_CONSTANTS 62
1509 #define adjectives_table_SC 0
1510 #define actions_table_SC 1
1511 #define classes_table_SC 2
1512 #define identifiers_table_SC 3
1513 #define preactions_table_SC 4
1514 #define version_number_SC 5
1515 #define largest_object_SC 6
1516 #define strings_offset_SC 7
1517 #define code_offset_SC 8
1518 #define dict_par1_SC 9
1519 #define dict_par2_SC 10
1520 #define dict_par3_SC 11
1521 #define actual_largest_object_SC 12
1522 #define static_memory_offset_SC 13
1523 #define array_names_offset_SC 14
1524 #define readable_memory_offset_SC 15
1525 #define cpv__start_SC 16
1526 #define cpv__end_SC 17
1527 #define ipv__start_SC 18
1528 #define ipv__end_SC 19
1529 #define array__start_SC 20
1530 #define array__end_SC 21
1532 #define lowest_attribute_number_SC 22
1533 #define highest_attribute_number_SC 23
1534 #define attribute_names_array_SC 24
1536 #define lowest_property_number_SC 25
1537 #define highest_property_number_SC 26
1538 #define property_names_array_SC 27
1540 #define lowest_action_number_SC 28
1541 #define highest_action_number_SC 29
1542 #define action_names_array_SC 30
1544 #define lowest_fake_action_number_SC 31
1545 #define highest_fake_action_number_SC 32
1546 #define fake_action_names_array_SC 33
1548 #define lowest_routine_number_SC 34
1549 #define highest_routine_number_SC 35
1550 #define routines_array_SC 36
1551 #define routine_names_array_SC 37
1552 #define routine_flags_array_SC 38
1554 #define lowest_global_number_SC 39
1555 #define highest_global_number_SC 40
1556 #define globals_array_SC 41
1557 #define global_names_array_SC 42
1558 #define global_flags_array_SC 43
1560 #define lowest_array_number_SC 44
1561 #define highest_array_number_SC 45
1562 #define arrays_array_SC 46
1563 #define array_names_array_SC 47
1564 #define array_flags_array_SC 48
1566 #define lowest_constant_number_SC 49
1567 #define highest_constant_number_SC 50
1568 #define constants_array_SC 51
1569 #define constant_names_array_SC 52
1571 #define lowest_class_number_SC 53
1572 #define highest_class_number_SC 54
1573 #define class_objects_array_SC 55
1575 #define lowest_object_number_SC 56
1576 #define highest_object_number_SC 57
1578 #define oddeven_packing_SC 58
1580 #define grammar_table_SC 59 /* Glulx-only */
1581 #define dictionary_table_SC 60 /* Glulx-only */
1582 #define dynam_string_table_SC 61 /* Glulx-only */
1585 /* Index numbers into the keyword group "system_functions" (see "lexer.c") */
1587 #define NUMBER_SYSTEM_FUNCTIONS 12
1589 #define CHILD_SYSF 0
1590 #define CHILDREN_SYSF 1
1591 #define ELDER_SYSF 2
1592 #define ELDEST_SYSF 3
1593 #define INDIRECT_SYSF 4
1594 #define PARENT_SYSF 5
1595 #define RANDOM_SYSF 6
1596 #define SIBLING_SYSF 7
1597 #define YOUNGER_SYSF 8
1598 #define YOUNGEST_SYSF 9
1599 #define METACLASS_SYSF 10
1600 #define GLK_SYSF 11 /* Glulx-only */
1602 /* Index numbers into the operators group "separators" (see "lexer.c") */
1604 #define NUMBER_SEPARATORS 49
1607 #define DARROW_SEP 1
1613 #define DIVIDE_SEP 7
1614 #define REMAINDER_SEP 8
1616 #define ARTOR_SEP 10
1617 #define LOGAND_SEP 11
1618 #define ARTAND_SEP 12
1619 #define LOGNOT_SEP 13
1620 #define NOTEQUAL_SEP 14
1621 #define ARTNOT_SEP 15
1622 #define CONDEQUALS_SEP 16
1623 #define SETEQUALS_SEP 17
1625 #define GREATER_SEP 19
1628 #define OPENB_SEP 22
1629 #define CLOSEB_SEP 23
1630 #define COMMA_SEP 24
1631 #define PROPADD_SEP 25
1632 #define PROPNUM_SEP 26
1633 #define MPROPADD_SEP 27
1634 #define MPROPNUM_SEP 28
1635 #define MESSAGE_SEP 29
1636 #define PROPERTY_SEP 30
1637 #define SUPERCLASS_SEP 31
1638 #define COLON_SEP 32
1640 #define SEMICOLON_SEP 34
1641 #define OPEN_SQUARE_SEP 35
1642 #define CLOSE_SQUARE_SEP 36
1643 #define OPEN_BRACE_SEP 37
1644 #define CLOSE_BRACE_SEP 38
1645 #define DOLLAR_SEP 39
1646 #define NBRANCH_SEP 40
1647 #define BRANCH_SEP 41
1648 #define HASHADOLLAR_SEP 42
1649 #define HASHGDOLLAR_SEP 43
1650 #define HASHNDOLLAR_SEP 44
1651 #define HASHRDOLLAR_SEP 45
1652 #define HASHWDOLLAR_SEP 46
1653 #define HASHHASH_SEP 47
1656 #define UNARY_MINUS_SEP 100
1657 #define POST_INC_SEP 101
1658 #define POST_DEC_SEP 102
1660 /* ------------------------------------------------------------------------- */
1661 /* Internal numbers used to refer to operators (in expressions) */
1662 /* (must correspond to entries in the operators table in "express.c") */
1663 /* ------------------------------------------------------------------------- */
1665 #define NUM_OPERATORS 68
1675 #define SETEQUALS_OP 1
1681 #define NONZERO_OP 6
1682 #define CONDEQUALS_OP 7
1683 #define NOTEQUAL_OP 8
1685 #define GREATER_OP 10
1692 #define OFCLASS_OP 17
1693 #define PROVIDES_OP 18
1694 #define NOTOFCLASS_OP 19
1695 #define NOTPROVIDES_OP 20
1701 #define DIVIDE_OP 25
1702 #define REMAINDER_OP 26
1703 #define ARTAND_OP 27
1705 #define ARTNOT_OP 29
1707 #define DARROW_OP 31
1708 #define UNARY_MINUS_OP 32
1710 #define POST_INC_OP 34
1712 #define POST_DEC_OP 36
1713 #define PROP_ADD_OP 37
1714 #define PROP_NUM_OP 38
1715 #define MPROP_ADD_OP 39
1716 #define MPROP_NUM_OP 40
1718 #define MESSAGE_OP 42
1719 #define PROPERTY_OP 43
1720 #define SUPERCLASS_OP 44
1722 #define ARROW_SETEQUALS_OP 45
1723 #define DARROW_SETEQUALS_OP 46
1724 #define MESSAGE_SETEQUALS_OP 47
1725 #define PROPERTY_SETEQUALS_OP 48
1727 #define ARROW_INC_OP 49
1728 #define DARROW_INC_OP 50
1729 #define MESSAGE_INC_OP 51
1730 #define PROPERTY_INC_OP 52
1732 #define ARROW_DEC_OP 53
1733 #define DARROW_DEC_OP 54
1734 #define MESSAGE_DEC_OP 55
1735 #define PROPERTY_DEC_OP 56
1737 #define ARROW_POST_INC_OP 57
1738 #define DARROW_POST_INC_OP 58
1739 #define MESSAGE_POST_INC_OP 59
1740 #define PROPERTY_POST_INC_OP 60
1742 #define ARROW_POST_DEC_OP 61
1743 #define DARROW_POST_DEC_OP 62
1744 #define MESSAGE_POST_DEC_OP 63
1745 #define PROPERTY_POST_DEC_OP 64
1747 #define PROP_CALL_OP 65
1748 #define MESSAGE_CALL_OP 66
1750 #define PUSH_OP 67 /* Glulx only */
1752 /* ------------------------------------------------------------------------- */
1753 /* The five types of compiled array */
1754 /* ------------------------------------------------------------------------- */
1756 #define BYTE_ARRAY 0
1757 #define WORD_ARRAY 1
1758 #define STRING_ARRAY 2
1759 #define TABLE_ARRAY 3
1760 #define BUFFER_ARRAY 4
1762 /* ------------------------------------------------------------------------- */
1763 /* Internal numbers used to refer to veneer routines */
1764 /* (must correspond to entries in the table in "veneer.c") */
1765 /* ------------------------------------------------------------------------- */
1767 #define VENEER_ROUTINES 48
1769 #define Box__Routine_VR 0
1771 #define R_Process_VR 1
1773 #define InDefArt_VR 3
1774 #define CDefArt_VR 4
1775 #define CInDefArt_VR 5
1776 #define PrintShortName_VR 6
1777 #define EnglishNumber_VR 7
1778 #define Print__Pname_VR 8
1781 #define RV__Pr_VR 10
1782 #define CA__Pr_VR 11
1783 #define IB__Pr_VR 12
1784 #define IA__Pr_VR 13
1785 #define DB__Pr_VR 14
1786 #define DA__Pr_VR 15
1787 #define RA__Pr_VR 16
1788 #define RL__Pr_VR 17
1789 #define RA__Sc_VR 18
1790 #define OP__Pr_VR 19
1791 #define OC__Cl_VR 20
1793 #define Copy__Primitive_VR 21
1794 #define RT__Err_VR 22
1795 #define Z__Region_VR 23
1796 #define Unsigned__Compare_VR 24
1797 #define Metaclass_VR 25
1798 #define CP__Tab_VR 26
1799 #define Cl__Ms_VR 27
1800 #define RT__ChT_VR 28
1801 #define RT__ChR_VR 29
1802 #define RT__ChG_VR 30
1803 #define RT__ChGt_VR 31
1804 #define RT__ChPS_VR 32
1805 #define RT__ChPR_VR 33
1806 #define RT__TrPS_VR 34
1807 #define RT__ChLDB_VR 35
1808 #define RT__ChLDW_VR 36
1809 #define RT__ChSTB_VR 37
1810 #define RT__ChSTW_VR 38
1811 #define RT__ChPrintC_VR 39
1812 #define RT__ChPrintA_VR 40
1813 #define RT__ChPrintS_VR 41
1814 #define RT__ChPrintO_VR 42
1816 /* Glulx-only veneer routines */
1817 #define OB__Move_VR 43
1818 #define OB__Remove_VR 44
1819 #define Print__Addr_VR 45
1820 #define Glk__Wrap_VR 46
1821 #define Dynam__String_VR 47
1823 /* ------------------------------------------------------------------------- */
1824 /* Run-time-error numbers (must correspond with RT__Err code in veneer) */
1825 /* ------------------------------------------------------------------------- */
1829 #define PARENT_RTE 4
1830 #define ELDEST_RTE 5
1832 #define YOUNGER_RTE 7
1833 #define SIBLING_RTE 8
1834 #define CHILDREN_RTE 9
1835 #define YOUNGEST_RTE 10
1836 #define ELDER_RTE 11
1837 #define OBJECTLOOP_RTE 12
1838 #define OBJECTLOOP2_RTE 13
1840 #define REMOVE_RTE 15
1841 #define MOVE1_RTE 16
1842 #define MOVE2_RTE 17
1843 /* 18 = creating a loop in object tree */
1844 /* 19 = giving a non-existent attribute */
1845 #define DBYZERO_RTE 20
1846 #define PROP_ADD_RTE 21
1847 #define PROP_NUM_RTE 22
1848 #define PROPERTY_RTE 23
1849 /* 24 = reading with -> out of range */
1850 /* 25 = reading with --> out of range */
1851 /* 26 = writing with -> out of range */
1852 /* 27 = writing with --> out of range */
1853 #define ABOUNDS_RTE 28
1854 /* similarly 29, 30, 31 */
1855 #define OBJECTLOOP_BROKEN_RTE 32
1856 /* 33 = print (char) out of range */
1857 /* 34 = print (address) out of range */
1858 /* 35 = print (string) out of range */
1859 /* 36 = print (object) out of range */
1861 /* ------------------------------------------------------------------------- */
1862 /* Z-region areas (used to refer to module positions in markers) */
1863 /* ------------------------------------------------------------------------- */
1865 #define LOW_STRINGS_ZA 1
1866 #define PROP_DEFAULTS_ZA 2
1867 #define OBJECT_TREE_ZA 3
1869 #define CLASS_NUMBERS_ZA 5
1870 #define INDIVIDUAL_PROP_ZA 6
1871 #define DYNAMIC_ARRAY_ZA 7
1872 #define GRAMMAR_ZA 8
1873 #define ACTIONS_ZA 9
1874 #define PREACTIONS_ZA 10
1875 #define ADJECTIVES_ZA 11
1876 #define DICTIONARY_ZA 12
1878 #define STATIC_STRINGS_ZA 14
1879 #define LINK_DATA_ZA 15
1881 #define SYMBOLS_ZA 16
1882 #define STATIC_ARRAY_ZA 17 /* Z-code only */
1883 #define GLOBALVAR_ZA 18 /* Glulx only */
1885 /* ------------------------------------------------------------------------- */
1886 /* "Marker values", used for backpatching and linkage */
1887 /* ------------------------------------------------------------------------- */
1889 #define NULL_MV 0 /* Null */
1891 /* Marker values used in backpatch areas: */
1893 #define DWORD_MV 1 /* Dictionary word address */
1894 #define STRING_MV 2 /* Static string */
1895 #define INCON_MV 3 /* "Hardware" constant (table address) */
1896 #define IROUTINE_MV 4 /* Call to internal routine */
1897 #define VROUTINE_MV 5 /* Call to veneer routine */
1898 #define ARRAY_MV 6 /* Ref to internal dynam array address */
1899 #define NO_OBJS_MV 7 /* Ref to number of game objects */
1900 #define INHERIT_MV 8 /* Inherited property value */
1901 #define INHERIT_INDIV_MV 9 /* Inherited indiv property value */
1902 #define MAIN_MV 10 /* "Main" routine */
1903 #define SYMBOL_MV 11 /* Forward ref to unassigned symbol */
1905 /* Additional marker values used in module backpatch areas: */
1906 /* (In Glulx, OBJECT_MV and VARIABLE_MV are used in backpatching, even
1907 without modules.) */
1909 #define VARIABLE_MV 12 /* Global variable */
1910 #define IDENT_MV 13 /* Property identifier number */
1911 #define INDIVPT_MV 14 /* Individual prop table address */
1912 #define ACTION_MV 15 /* Action number */
1913 #define OBJECT_MV 16 /* Ref to internal object number */
1914 #define STATIC_ARRAY_MV 17 /* Ref to internal static array address */
1916 #define LARGEST_BPATCH_MV 17 /* Larger marker values are never written
1917 to backpatch tables */
1919 /* Value indicating an imported symbol record: */
1921 #define IMPORT_MV 32
1923 /* Values indicating an exported symbol record: */
1925 #define EXPORT_MV 33 /* Defined ordinarily */
1926 #define EXPORTSF_MV 34 /* Defined in a system file */
1927 #define EXPORTAC_MV 35 /* Action name */
1929 /* Values used only in branch backpatching: */
1930 /* ###-I've rearranged these, so that BRANCH_MV can be last; Glulx uses the
1931 whole range from BRANCH_MV to BRANCHMAX_MV. */
1933 #define LABEL_MV 36 /* Ditto: marks "jump" operands */
1934 #define DELETED_MV 37 /* Ditto: marks bytes deleted from code */
1935 #define BRANCH_MV 38 /* Used in "asm.c" for routine coding */
1936 #define BRANCHMAX_MV 58 /* In fact, the range BRANCH_MV to
1937 BRANCHMAX_MV all means the same thing.
1938 The position within the range means
1939 how far back from the label to go
1940 to find the opmode byte to modify. */
1942 /* ========================================================================= */
1943 /* Initialisation extern definitions */
1945 /* Note that each subsystem in Inform provides four routines to keep */
1946 /* track of variables and data structures: */
1948 /* init_*_vars should set variables to initial values (they must */
1949 /* not be initialised directly in their declarations */
1950 /* as Inform may need to compile several times in a */
1953 /* *_begin_pass any variable/array initialisation that needs to */
1954 /* happen at the start of the pass through the source */
1956 /* *_allocate_arrays should use my_malloc/my_calloc (see memory.c) */
1957 /* to allocate any arrays or workspace needed */
1959 /* *_free_arrays should use my_free to free all memory allocated */
1960 /* (with one exception in "text.c") */
1962 /* ========================================================================= */
1964 /* > READ INFORM SOURCE */
1966 /* My Source Book */
1968 extern void init_arrays_vars(void); /* arrays: construct tableaux */
1969 extern void init_asm_vars(void); /* asm: assemble even rare or v6 codes */
1970 extern void init_bpatch_vars(void); /* bpatch: backpatches code */
1971 extern void init_chars_vars(void); /* chars: translate character sets */
1972 extern void init_directs_vars(void); /* directs: ponder directives */
1973 extern void init_errors_vars(void); /* errors: issue diagnostics */
1974 extern void init_expressc_vars(void); /* expressc: compile expressions */
1975 extern void init_expressp_vars(void); /* expressp: parse expressions */
1976 extern void init_files_vars(void); /* files: handle files */
1977 /* void init_vars(void); inform: decide what to do */
1978 extern void init_lexer_vars(void); /* lexer: lexically analyse source */
1979 extern void init_linker_vars(void); /* linker: link in pre-compiled module */
1980 extern void init_memory_vars(void); /* memory: manage memory settings */
1981 extern void init_objects_vars(void); /* objects: cultivate object tree */
1982 extern void init_states_vars(void); /* states: translate statements to code*/
1983 extern void init_symbols_vars(void); /* symbols: construct symbols table */
1984 extern void init_syntax_vars(void); /* syntax: parse the program */
1985 extern void init_tables_vars(void); /* tables: glue tables into the output */
1986 extern void init_text_vars(void); /* text: encode text and dictionary */
1987 extern void init_veneer_vars(void); /* veneer: compile a layer of code */
1988 extern void init_verbs_vars(void); /* verbs: lay out grammar */
1990 extern void files_begin_prepass(void); /* These routines initialise just */
1991 extern void lexer_begin_prepass(void); /* enough to begin loading source */
1993 extern void arrays_begin_pass(void);
1994 extern void asm_begin_pass(void);
1995 extern void bpatch_begin_pass(void);
1996 extern void chars_begin_pass(void);
1997 extern void directs_begin_pass(void);
1998 extern void errors_begin_pass(void);
1999 extern void expressc_begin_pass(void);
2000 extern void expressp_begin_pass(void);
2001 extern void files_begin_pass(void);
2002 /* void begin_pass(void); */
2003 extern void lexer_begin_pass(void);
2004 extern void linker_begin_pass(void);
2005 extern void memory_begin_pass(void);
2006 extern void objects_begin_pass(void);
2007 extern void states_begin_pass(void);
2008 extern void symbols_begin_pass(void);
2009 extern void syntax_begin_pass(void);
2010 extern void tables_begin_pass(void);
2011 extern void text_begin_pass(void);
2012 extern void veneer_begin_pass(void);
2013 extern void verbs_begin_pass(void);
2015 extern void lexer_endpass(void);
2016 extern void linker_endpass(void);
2018 extern void arrays_allocate_arrays(void);
2019 extern void asm_allocate_arrays(void);
2020 extern void bpatch_allocate_arrays(void);
2021 extern void chars_allocate_arrays(void);
2022 extern void directs_allocate_arrays(void);
2023 extern void errors_allocate_arrays(void);
2024 extern void expressc_allocate_arrays(void);
2025 extern void expressp_allocate_arrays(void);
2026 extern void files_allocate_arrays(void);
2027 /* void allocate_arrays(void); */
2028 extern void lexer_allocate_arrays(void);
2029 extern void linker_allocate_arrays(void);
2030 extern void memory_allocate_arrays(void);
2031 extern void objects_allocate_arrays(void);
2032 extern void states_allocate_arrays(void);
2033 extern void symbols_allocate_arrays(void);
2034 extern void syntax_allocate_arrays(void);
2035 extern void tables_allocate_arrays(void);
2036 extern void text_allocate_arrays(void);
2037 extern void veneer_allocate_arrays(void);
2038 extern void verbs_allocate_arrays(void);
2040 extern void arrays_free_arrays(void);
2041 extern void asm_free_arrays(void);
2042 extern void bpatch_free_arrays(void);
2043 extern void chars_free_arrays(void);
2044 extern void directs_free_arrays(void);
2045 extern void errors_free_arrays(void);
2046 extern void expressc_free_arrays(void);
2047 extern void expressp_free_arrays(void);
2048 extern void files_free_arrays(void);
2049 /* void free_arrays(void); */
2050 extern void lexer_free_arrays(void);
2051 extern void linker_free_arrays(void);
2052 extern void memory_free_arrays(void);
2053 extern void objects_free_arrays(void);
2054 extern void states_free_arrays(void);
2055 extern void symbols_free_arrays(void);
2056 extern void syntax_free_arrays(void);
2057 extern void tables_free_arrays(void);
2058 extern void text_free_arrays(void);
2059 extern void veneer_free_arrays(void);
2060 extern void verbs_free_arrays(void);
2062 /* ========================================================================= */
2063 /* Remaining extern definitions are given by file in alphabetical order */
2064 /* ------------------------------------------------------------------------- */
2065 /* Extern definitions for "arrays" */
2066 /* ------------------------------------------------------------------------- */
2068 extern int no_globals, no_arrays;
2069 extern int dynamic_array_area_size;
2070 extern int *dynamic_array_area;
2071 extern int static_array_area_size;
2072 extern int *static_array_area;
2073 extern int32 *global_initial_value;
2074 extern int32 *array_symbols;
2075 extern int *array_sizes, *array_types, *array_locs;
2077 extern void make_global(int array_flag, int name_only);
2078 extern void set_variable_value(int i, int32 v);
2079 extern void check_globals(void);
2080 extern int32 begin_table_array(void);
2081 extern int32 begin_word_array(void);
2082 extern void array_entry(int32 i, int is_static, assembly_operand VAL);
2083 extern void finish_array(int32 i, int is_static);
2085 /* ------------------------------------------------------------------------- */
2086 /* Extern definitions for "asm" */
2087 /* ------------------------------------------------------------------------- */
2089 extern memory_block zcode_area;
2090 extern int32 zmachine_pc;
2092 extern int32 no_instructions;
2093 extern int sequence_point_follows;
2094 extern int uses_unicode_features, uses_memheap_features,
2095 uses_acceleration_features, uses_float_features;
2096 extern debug_location statement_debug_location;
2097 extern int execution_never_reaches_here;
2098 extern int *variable_usage;
2099 extern int next_label, no_sequence_points;
2100 extern int32 *variable_tokens;
2101 extern assembly_instruction AI;
2102 extern int32 *named_routine_symbols;
2104 extern void print_operand(assembly_operand o);
2105 extern char *variable_name(int32 i);
2106 extern void set_constant_ot(assembly_operand *AO);
2107 extern int is_constant_ot(int otval);
2108 extern int is_variable_ot(int otval);
2109 extern void assemblez_instruction(assembly_instruction *a);
2110 extern void assembleg_instruction(assembly_instruction *a);
2111 extern void assemble_label_no(int n);
2112 extern void assemble_jump(int n);
2113 extern void define_symbol_label(int symbol);
2114 extern int32 assemble_routine_header(int no_locals, int debug_flag,
2115 char *name, int embedded_flag, int the_symbol);
2116 extern void assemble_routine_end(int embedded_flag, debug_locations locations);
2118 extern void assemblez_0(int internal_number);
2119 extern void assemblez_0_to(int internal_number, assembly_operand o1);
2120 extern void assemblez_0_branch(int internal_number, int label, int flag);
2121 extern void assemblez_1(int internal_number, assembly_operand o1);
2122 extern void assemblez_1_to(int internal_number,
2123 assembly_operand o1, assembly_operand st);
2124 extern void assemblez_1_branch(int internal_number,
2125 assembly_operand o1, int label, int flag);
2126 extern void assemblez_objcode(int internal_number,
2127 assembly_operand o1, assembly_operand st,
2128 int label, int flag);
2129 extern void assemblez_2(int internal_number,
2130 assembly_operand o1, assembly_operand o2);
2131 extern void assemblez_2_to(int internal_number,
2132 assembly_operand o1, assembly_operand o2,
2133 assembly_operand st);
2134 extern void assemblez_2_branch(int internal_number,
2135 assembly_operand o1, assembly_operand o2,
2136 int label, int flag);
2137 extern void assemblez_3(int internal_number,
2138 assembly_operand o1, assembly_operand o2,
2139 assembly_operand o3);
2140 extern void assemblez_3_branch(int internal_number,
2141 assembly_operand o1, assembly_operand o2,
2142 assembly_operand o3, int label, int flag);
2143 extern void assemblez_3_to(int internal_number,
2144 assembly_operand o1, assembly_operand o2,
2145 assembly_operand o3, assembly_operand st);
2146 extern void assemblez_4(int internal_number,
2147 assembly_operand o1, assembly_operand o2,
2148 assembly_operand o3, assembly_operand o4);
2149 extern void assemblez_5(int internal_number,
2150 assembly_operand o1, assembly_operand o2,
2151 assembly_operand o3, assembly_operand o4,
2152 assembly_operand o5);
2153 extern void assemblez_6(int internal_number,
2154 assembly_operand o1, assembly_operand o2,
2155 assembly_operand o3, assembly_operand o4,
2156 assembly_operand o5, assembly_operand o6);
2157 extern void assemblez_4_branch(int internal_number,
2158 assembly_operand o1, assembly_operand o2,
2159 assembly_operand o3, assembly_operand o4,
2160 int label, int flag);
2161 extern void assemblez_4_to(int internal_number,
2162 assembly_operand o1, assembly_operand o2,
2163 assembly_operand o3, assembly_operand o4,
2164 assembly_operand st);
2165 extern void assemblez_5_to(int internal_number,
2166 assembly_operand o1, assembly_operand o2,
2167 assembly_operand o3, assembly_operand o4,
2168 assembly_operand o5, assembly_operand st);
2170 extern void assemblez_inc(assembly_operand o1);
2171 extern void assemblez_dec(assembly_operand o1);
2172 extern void assemblez_store(assembly_operand o1, assembly_operand o2);
2173 extern void assemblez_jump(int n);
2175 extern void assembleg_0(int internal_number);
2176 extern void assembleg_1(int internal_number, assembly_operand o1);
2177 extern void assembleg_2(int internal_number, assembly_operand o1,
2178 assembly_operand o2);
2179 extern void assembleg_3(int internal_number, assembly_operand o1,
2180 assembly_operand o2, assembly_operand o3);
2181 extern void assembleg_4(int internal_number, assembly_operand o1,
2182 assembly_operand o2, assembly_operand o3, assembly_operand o4);
2183 extern void assembleg_5(int internal_number, assembly_operand o1,
2184 assembly_operand o2, assembly_operand o3, assembly_operand o4,
2185 assembly_operand o5);
2186 extern void assembleg_0_branch(int internal_number,
2188 extern void assembleg_1_branch(int internal_number,
2189 assembly_operand o1, int label);
2190 extern void assembleg_2_branch(int internal_number,
2191 assembly_operand o1, assembly_operand o2, int label);
2192 extern void assembleg_call_1(assembly_operand oaddr, assembly_operand o1,
2193 assembly_operand odest);
2194 extern void assembleg_call_2(assembly_operand oaddr, assembly_operand o1,
2195 assembly_operand o2, assembly_operand odest);
2196 extern void assembleg_call_3(assembly_operand oaddr, assembly_operand o1,
2197 assembly_operand o2, assembly_operand o3, assembly_operand odest);
2198 extern void assembleg_inc(assembly_operand o1);
2199 extern void assembleg_dec(assembly_operand o1);
2200 extern void assembleg_store(assembly_operand o1, assembly_operand o2);
2201 extern void assembleg_jump(int n);
2203 extern void parse_assembly(void);
2205 /* ------------------------------------------------------------------------- */
2206 /* Extern definitions for "bpatch" */
2207 /* ------------------------------------------------------------------------- */
2209 extern memory_block zcode_backpatch_table, staticarray_backpatch_table,
2210 zmachine_backpatch_table;
2211 extern int32 zcode_backpatch_size, staticarray_backpatch_size,
2212 zmachine_backpatch_size;
2213 extern int backpatch_marker, backpatch_error_flag;
2215 extern int32 backpatch_value(int32 value);
2216 extern void backpatch_zmachine_image_z(void);
2217 extern void backpatch_zmachine_image_g(void);
2218 extern void backpatch_zmachine(int mv, int zmachine_area, int32 offset);
2220 /* ------------------------------------------------------------------------- */
2221 /* Extern definitions for "chars" */
2222 /* ------------------------------------------------------------------------- */
2224 extern uchar source_to_iso_grid[];
2225 extern int32 iso_to_unicode_grid[];
2226 extern int character_digit_value[];
2227 extern uchar alphabet[3][27];
2228 extern int alphabet_modified;
2229 extern int zscii_defn_modified;
2230 extern int zscii_high_water_mark;
2231 extern char alphabet_used[];
2232 extern int iso_to_alphabet_grid[];
2233 extern int zscii_to_alphabet_grid[];
2234 extern int textual_form_length;
2236 extern int iso_to_unicode(int iso);
2237 extern int unicode_to_zscii(int32 u);
2238 extern int32 zscii_to_unicode(int z);
2239 extern int32 text_to_unicode(char *text);
2240 extern void zscii_to_text(char *text, int zscii);
2241 extern char *name_of_iso_set(int s);
2242 extern void change_character_set(void);
2243 extern void new_alphabet(char *text, int alphabet);
2244 extern void new_zscii_character(int32 unicode, int plus_flag);
2245 extern void new_zscii_finished(void);
2246 extern void map_new_zchar(int32 unicode);
2247 extern void make_lower_case(char *str);
2248 extern void make_upper_case(char *str);
2250 /* ------------------------------------------------------------------------- */
2251 /* Extern definitions for "directs" */
2252 /* ------------------------------------------------------------------------- */
2254 extern brief_location routine_starts_line;
2256 extern int no_routines, no_named_routines, no_locals, no_termcs;
2257 extern int terminating_characters[];
2259 extern int parse_given_directive(int internal_flag);
2261 /* ------------------------------------------------------------------------- */
2262 /* Extern definitions for "errors" */
2263 /* ------------------------------------------------------------------------- */
2265 extern char *forerrors_buff;
2266 extern int forerrors_pointer;
2267 extern int no_errors, no_warnings, no_suppressed_warnings,
2268 no_link_errors, no_compiler_errors;
2270 extern ErrorPosition ErrorReport;
2272 extern void fatalerror(char *s) NORETURN;
2273 extern void fatalerror_named(char *s1, char *s2) NORETURN;
2274 extern void memory_out_error(int32 size, int32 howmany, char *name) NORETURN;
2275 extern void memoryerror(char *s, int32 size) NORETURN;
2276 extern void error(char *s);
2277 extern void error_named(char *s1, char *s2);
2278 extern void error_numbered(char *s1, int val);
2279 extern void error_named_at(char *s1, char *s2, brief_location report_line);
2280 extern void ebf_error(char *s1, char *s2);
2281 extern void char_error(char *s, int ch);
2282 extern void unicode_char_error(char *s, int32 uni);
2283 extern void no_such_label(char *lname);
2284 extern void warning(char *s);
2285 extern void warning_numbered(char *s1, int val);
2286 extern void warning_named(char *s1, char *s2);
2287 extern void dbnu_warning(char *type, char *name, brief_location report_line);
2288 extern void uncalled_routine_warning(char *type, char *name, brief_location report_line);
2289 extern void obsolete_warning(char *s1);
2290 extern void link_error(char *s);
2291 extern void link_error_named(char *s1, char *s2);
2292 extern int compiler_error(char *s);
2293 extern int compiler_error_named(char *s1, char *s2);
2294 extern void print_sorry_message(void);
2296 #ifdef ARC_THROWBACK
2297 extern int throwback_switch;
2299 extern void throwback(int severity, char * error);
2300 extern void throwback_start(void);
2301 extern void throwback_end(void);
2304 /* ------------------------------------------------------------------------- */
2305 /* Extern definitions for "expressc" */
2306 /* ------------------------------------------------------------------------- */
2308 extern int vivc_flag;
2309 extern operator operators[];
2311 extern assembly_operand stack_pointer, temp_var1, temp_var2, temp_var3,
2312 temp_var4, zero_operand, one_operand, two_operand, three_operand,
2313 four_operand, valueless_operand;
2315 assembly_operand code_generate(assembly_operand AO, int context, int label);
2316 assembly_operand check_nonzero_at_runtime(assembly_operand AO1, int label,
2319 /* ------------------------------------------------------------------------- */
2320 /* Extern definitions for "expressp" */
2321 /* ------------------------------------------------------------------------- */
2323 extern int system_function_usage[];
2324 extern expression_tree_node *ET;
2326 extern int z_system_constant_list[];
2327 extern int glulx_system_constant_list[];
2329 extern int32 value_of_system_constant(int t);
2330 extern void clear_expression_space(void);
2331 extern void show_tree(assembly_operand AO, int annotate);
2332 extern assembly_operand parse_expression(int context);
2333 extern int test_for_incdec(assembly_operand AO);
2335 /* ------------------------------------------------------------------------- */
2336 /* Extern definitions for "files" */
2337 /* ------------------------------------------------------------------------- */
2339 extern int total_files;
2340 extern int current_input_file;
2341 extern int total_input_files;
2342 extern FileId *InputFiles;
2344 extern FILE *Temp1_fp, *Temp2_fp, *Temp3_fp;
2345 extern char Temp1_Name[], Temp2_Name[], Temp3_Name[];
2346 extern int32 total_chars_read;
2348 extern void open_temporary_files(void);
2349 extern void check_temp_files(void);
2350 extern void remove_temp_files(void);
2352 extern void open_transcript_file(char *what_of);
2353 extern void write_to_transcript_file(char *text);
2354 extern void close_transcript_file(void);
2355 extern void abort_transcript_file(void);
2357 extern void nullify_debug_file_position(maybe_file_position *position);
2359 extern void begin_debug_file(void);
2361 extern void debug_file_printf(const char*format, ...);
2362 extern void debug_file_print_with_entities(const char*string);
2363 extern void debug_file_print_base_64_triple
2364 (uchar first, uchar second, uchar third);
2365 extern void debug_file_print_base_64_pair(uchar first, uchar second);
2366 extern void debug_file_print_base_64_single(uchar first);
2368 extern void write_debug_location(debug_location location);
2369 extern void write_debug_locations(debug_locations locations);
2370 extern void write_debug_optional_identifier(int32 symbol_index);
2371 extern void write_debug_symbol_backpatch(int32 symbol_index);
2372 extern void write_debug_symbol_optional_backpatch(int32 symbol_index);
2373 extern void write_debug_object_backpatch(int32 object_number);
2374 extern void write_debug_packed_code_backpatch(int32 offset);
2375 extern void write_debug_code_backpatch(int32 offset);
2376 extern void write_debug_global_backpatch(int32 offset);
2377 extern void write_debug_array_backpatch(int32 offset);
2378 extern void write_debug_grammar_backpatch(int32 offset);
2380 extern void begin_writing_debug_sections(void);
2381 extern void write_debug_section(const char*name, int32 beginning_address);
2382 extern void end_writing_debug_sections(int32 end_address);
2384 extern void write_debug_undef(int32 symbol_index);
2386 extern void end_debug_file(void);
2388 extern void add_to_checksum(void *address);
2390 extern void load_sourcefile(char *story_name, int style);
2391 extern int file_load_chars(int file_number, char *buffer, int length);
2392 extern void close_all_source(void);
2393 extern int register_orig_sourcefile(char *filename);
2395 extern void output_file(void);
2397 /* ------------------------------------------------------------------------- */
2398 /* Extern definitions for "inform" */
2399 /* ------------------------------------------------------------------------- */
2401 extern char Code_Name[];
2402 extern int endofpass_flag;
2404 extern int version_number, instruction_set_number, extend_memory_map;
2405 extern int32 scale_factor, length_scale_factor;
2407 extern int WORDSIZE, INDIV_PROP_START,
2408 OBJECT_BYTE_LENGTH, DICT_ENTRY_BYTE_LENGTH, DICT_ENTRY_FLAG_POS;
2409 extern int32 MAXINTWORD;
2411 extern int asm_trace_level, line_trace_level, expr_trace_level,
2412 linker_trace_level, tokens_trace_level;
2415 bothpasses_switch, concise_switch,
2416 economy_switch, frequencies_switch,
2417 ignore_switches_switch, listobjects_switch, debugfile_switch,
2418 listing_switch, memout_switch, printprops_switch,
2419 offsets_switch, percentages_switch, obsolete_switch,
2420 transcript_switch, statistics_switch, optimise_switch,
2421 version_set_switch, nowarnings_switch, hash_switch,
2422 memory_map_switch, module_switch, temporary_files_switch,
2423 define_DEBUG_switch, define_USE_MODULES_switch, define_INFIX_switch,
2424 runtime_error_checking_switch;
2426 extern int oddeven_packing_switch;
2428 extern int glulx_mode, compression_switch;
2429 extern int32 requested_glulx_version;
2431 extern int error_format, store_the_text, asm_trace_setting,
2432 double_space_setting, trace_fns_setting, character_set_setting,
2433 character_set_unicode;
2435 extern char Debugging_Name[];
2436 extern char Transcript_Name[];
2437 extern char Language_Name[];
2438 extern char Charset_Map[];
2440 extern char banner_line[];
2442 extern void select_version(int vn);
2443 extern void switches(char *, int);
2444 extern int translate_in_filename(int last_value, char *new_name, char *old_name,
2445 int same_directory_flag, int command_line_flag);
2446 extern void translate_out_filename(char *new_name, char *old_name);
2447 extern int translate_link_filename(int last_value,
2448 char *new_name, char *old_name);
2449 extern void translate_temp_filename(int i);
2452 extern char *riscos_file_type(void);
2455 /* For the benefit of the MAC_FACE port these are declared extern, though
2456 unused outside "inform" in the compiler itself */
2458 extern void allocate_arrays(void);
2459 extern void free_arrays(void);
2461 /* ------------------------------------------------------------------------- */
2462 /* Extern definitions for "lexer" */
2463 /* ------------------------------------------------------------------------- */
2465 extern int hash_printed_since_newline;
2466 extern int total_source_line_count;
2467 extern int dont_enter_into_symbol_table;
2468 extern int return_sp_as_variable;
2469 extern int next_token_begins_syntax_line;
2470 extern char **local_variable_texts;
2472 extern int32 token_value;
2473 extern int token_type;
2474 extern char *token_text;
2476 extern debug_location get_token_location(void);
2477 extern debug_locations get_token_locations(void);
2478 extern debug_location_beginning get_token_location_beginning(void);
2479 extern void discard_token_location(debug_location_beginning beginning);
2480 extern debug_locations get_token_location_end(debug_location_beginning beginning);
2482 extern void describe_token(token_data t);
2484 extern void construct_local_variable_tables(void);
2485 extern void declare_systemfile(void);
2486 extern int is_systemfile(void);
2487 extern void report_errors_at_current_line(void);
2488 extern debug_location get_current_debug_location(void);
2489 extern debug_location get_error_report_debug_location(void);
2490 extern int32 get_current_line_start(void);
2491 extern void set_origsource_location(char *source, int32 line, int32 charnum);
2492 extern brief_location get_brief_location(ErrorPosition *errpos);
2493 extern void export_brief_location(brief_location loc, ErrorPosition *errpos);
2494 extern brief_location blank_brief_location;
2496 extern void put_token_back(void);
2497 extern void get_next_token(void);
2498 extern void restart_lexer(char *lexical_source, char *name);
2500 extern keyword_group directives, statements, segment_markers,
2501 conditions, system_functions, local_variables, opcode_names,
2502 misc_keywords, directive_keywords, trace_keywords, system_constants,
2505 /* ------------------------------------------------------------------------- */
2506 /* Extern definitions for "linker" */
2507 /* ------------------------------------------------------------------------- */
2509 extern memory_block link_data_area;
2510 extern int32 link_data_size;
2511 extern char current_module_filename[];
2513 extern char *describe_mv(int mval);
2514 extern void write_link_marker(int zmachine_area, int32 offset,
2515 assembly_operand op);
2516 extern void flush_link_data(void);
2517 extern void import_symbol(int32 symbol_number);
2518 extern void export_symbol(int32 symbol_number);
2519 extern void export_symbol_name(int32 i);
2520 extern void link_module(char *filename);
2522 /* ------------------------------------------------------------------------- */
2523 /* Extern definitions for "memory" */
2524 /* ------------------------------------------------------------------------- */
2526 extern int32 malloced_bytes;
2528 extern int MAX_QTEXT_SIZE, MAX_SYMBOLS, HASH_TAB_SIZE, MAX_DICT_ENTRIES,
2529 MAX_OBJECTS, MAX_ACTIONS, MAX_ADJECTIVES, MAX_ABBREVS,
2530 MAX_STATIC_DATA, MAX_PROP_TABLE_SIZE, SYMBOLS_CHUNK_SIZE,
2531 MAX_EXPRESSION_NODES, MAX_LABELS, MAX_LINESPACE,
2532 MAX_LOW_STRINGS, MAX_CLASSES, MAX_VERBS,
2533 MAX_VERBSPACE, MAX_ARRAYS, MAX_INCLUSION_DEPTH,
2536 extern int32 MAX_STATIC_STRINGS, MAX_ZCODE_SIZE, MAX_LINK_DATA_SIZE,
2537 MAX_TRANSCRIPT_SIZE, MAX_INDIV_PROP_TABLE_SIZE,
2538 MAX_NUM_STATIC_STRINGS, MAX_UNICODE_CHARS,
2539 MAX_STACK_SIZE, MEMORY_MAP_EXTENSION;
2541 extern int32 MAX_OBJ_PROP_COUNT, MAX_OBJ_PROP_TABLE_SIZE;
2542 extern int MAX_LOCAL_VARIABLES, MAX_GLOBAL_VARIABLES;
2543 extern int DICT_WORD_SIZE, DICT_CHAR_SIZE, DICT_WORD_BYTES;
2544 extern int ZCODE_HEADER_EXT_WORDS, ZCODE_HEADER_FLAGS_3;
2545 extern int NUM_ATTR_BYTES, GLULX_OBJECT_EXT_BYTES;
2546 extern int WARN_UNUSED_ROUTINES, OMIT_UNUSED_ROUTINES;
2548 /* These macros define offsets that depend on the value of NUM_ATTR_BYTES.
2549 (Meaningful only for Glulx.) */
2550 /* GOBJFIELD: word offsets of various elements in the object structure. */
2551 #define GOBJFIELD_CHAIN() (1+((NUM_ATTR_BYTES)/4))
2552 #define GOBJFIELD_NAME() (2+((NUM_ATTR_BYTES)/4))
2553 #define GOBJFIELD_PROPTAB() (3+((NUM_ATTR_BYTES)/4))
2554 #define GOBJFIELD_PARENT() (4+((NUM_ATTR_BYTES)/4))
2555 #define GOBJFIELD_SIBLING() (5+((NUM_ATTR_BYTES)/4))
2556 #define GOBJFIELD_CHILD() (6+((NUM_ATTR_BYTES)/4))
2558 extern void *my_malloc(int32 size, char *whatfor);
2559 extern void my_realloc(void *pointer, int32 oldsize, int32 size,
2561 extern void *my_calloc(int32 size, int32 howmany, char *whatfor);
2562 extern void my_recalloc(void *pointer, int32 size, int32 oldhowmany,
2563 int32 howmany, char *whatfor);
2564 extern void my_free(void *pointer, char *whatitwas);
2566 extern void set_memory_sizes(int size_flag);
2567 extern void adjust_memory_sizes(void);
2568 extern void memory_command(char *command);
2569 extern void print_memory_usage(void);
2571 extern void initialise_memory_block(memory_block *MB);
2572 extern void deallocate_memory_block(memory_block *MB);
2573 extern int read_byte_from_memory_block(memory_block *MB, int32 index);
2574 extern void write_byte_to_memory_block(memory_block *MB,
2575 int32 index, int value);
2577 /* ------------------------------------------------------------------------- */
2578 /* Extern definitions for "objects" */
2579 /* ------------------------------------------------------------------------- */
2581 extern int no_attributes, no_properties;
2582 extern int no_individual_properties;
2583 extern int individuals_length;
2584 extern uchar *individuals_table;
2585 extern int no_classes, no_objects;
2586 extern objecttz *objectsz;
2587 extern objecttg *objectsg;
2588 extern uchar *objectatts;
2589 extern int *class_object_numbers;
2590 extern int32 *class_begins_at;
2592 extern int32 *prop_default_value;
2593 extern int *prop_is_long;
2594 extern int *prop_is_additive;
2595 extern char *properties_table;
2596 extern int properties_table_size;
2598 extern void make_attribute(void);
2599 extern void make_property(void);
2600 extern void make_object(int nearby_flag,
2601 char *textual_name, int specified_parent, int specified_class,
2603 extern void make_class(char *metaclass_name);
2604 extern int object_provides(int obj, int id);
2605 extern void list_object_tree(void);
2606 extern void write_the_identifier_names(void);
2608 /* ------------------------------------------------------------------------- */
2609 /* Extern definitions for "symbols" */
2610 /* ------------------------------------------------------------------------- */
2612 extern int no_named_constants;
2613 extern int no_symbols;
2614 extern int32 **symbs;
2615 extern int32 *svals;
2617 extern brief_location *slines;
2620 extern char *stypes;
2622 extern signed char *stypes;
2624 extern maybe_file_position *symbol_debug_backpatch_positions;
2625 extern maybe_file_position *replacement_debug_backpatch_positions;
2626 extern int32 *individual_name_strings;
2627 extern int32 *attribute_name_strings;
2628 extern int32 *action_name_strings;
2629 extern int32 *array_name_strings;
2630 extern int track_unused_routines;
2631 extern int df_dont_note_global_symbols;
2632 extern uint32 df_total_size_before_stripping;
2633 extern uint32 df_total_size_after_stripping;
2635 extern char *typename(int type);
2636 extern int hash_code_from_string(char *p);
2637 extern int strcmpcis(char *p, char *q);
2638 extern int symbol_index(char *lexeme_text, int hashcode);
2639 extern void end_symbol_scope(int k);
2640 extern void describe_symbol(int k);
2641 extern void list_symbols(int level);
2642 extern void assign_marked_symbol(int index, int marker, int32 value, int type);
2643 extern void assign_symbol(int index, int32 value, int type);
2644 extern void issue_unused_warnings(void);
2645 extern void add_symbol_replacement_mapping(int original, int renamed);
2646 extern int find_symbol_replacement(int *value);
2647 extern void df_note_function_start(char *name, uint32 address,
2648 int embedded_flag, brief_location source_line);
2649 extern void df_note_function_end(uint32 endaddress);
2650 extern void df_note_function_symbol(int symbol);
2651 extern void locate_dead_functions(void);
2652 extern uint32 df_stripped_address_for_address(uint32);
2653 extern uint32 df_stripped_offset_for_code_offset(uint32, int *);
2654 extern void df_prepare_function_iterate(void);
2655 extern uint32 df_next_function_iterate(int *);
2657 /* ------------------------------------------------------------------------- */
2658 /* Extern definitions for "syntax" */
2659 /* ------------------------------------------------------------------------- */
2661 extern int no_syntax_lines;
2663 extern void panic_mode_error_recovery(void);
2664 extern void get_next_token_with_directives(void);
2665 extern int parse_directive(int internal_flag);
2666 extern void parse_program(char *source);
2667 extern int32 parse_routine(char *source, int embedded_flag, char *name,
2668 int veneer_flag, int r_symbol);
2669 extern void parse_code_block(int break_label, int continue_label,
2672 /* ------------------------------------------------------------------------- */
2673 /* Extern definitions for "states" */
2674 /* ------------------------------------------------------------------------- */
2676 extern void match_close_bracket(void);
2677 extern void parse_statement(int break_label, int continue_label);
2678 extern int parse_label(void);
2680 /* ------------------------------------------------------------------------- */
2681 /* Extern definitions for "tables" */
2682 /* ------------------------------------------------------------------------- */
2684 extern uchar *zmachine_paged_memory;
2686 code_offset, actions_offset, preactions_offset,
2687 dictionary_offset, strings_offset, adjectives_offset,
2688 variables_offset, class_numbers_offset, individuals_offset,
2689 identifier_names_offset, prop_defaults_offset, prop_values_offset,
2690 static_memory_offset, array_names_offset, attribute_names_offset,
2691 action_names_offset, fake_action_names_offset,
2692 routine_names_offset, routines_array_offset, routine_flags_array_offset,
2693 global_names_offset, global_flags_array_offset,
2694 array_flags_array_offset, constant_names_offset, constants_array_offset,
2695 static_arrays_offset;
2697 arrays_offset, object_tree_offset, grammar_table_offset,
2698 abbreviations_offset; /* For Glulx */
2700 extern int32 Out_Size, Write_Code_At, Write_Strings_At;
2701 extern int32 RAM_Size, Write_RAM_At; /* For Glulx */
2703 extern int release_number, statusline_flag;
2704 extern int flags2_requirements[];
2705 extern int serial_code_given_in_program;
2706 extern char serial_code_buffer[];
2708 extern void construct_storyfile(void);
2709 extern void write_serial_number(char *buffer);
2711 /* ------------------------------------------------------------------------- */
2712 /* Extern definitions for "text" */
2713 /* ------------------------------------------------------------------------- */
2715 extern uchar *low_strings, *low_strings_top;
2716 extern char *all_text, *all_text_top;
2718 extern int no_abbreviations;
2719 extern int abbrevs_lookup_table_made, is_abbreviation;
2720 extern uchar *abbreviations_at;
2721 extern int *abbrev_values;
2722 extern int *abbrev_quality;
2723 extern int *abbrev_freqs;
2725 extern int32 total_chars_trans, total_bytes_trans,
2726 zchars_trans_in_last_string;
2727 extern int put_strings_in_low_memory;
2728 extern int dict_entries;
2729 extern uchar *dictionary, *dictionary_top;
2730 extern int *final_dict_order;
2732 extern memory_block static_strings_area;
2733 extern int32 static_strings_extent;
2735 /* And now, a great many declarations for dealing with Glulx string
2738 extern int32 no_strings, no_dynamic_strings;
2739 extern int no_unicode_chars;
2741 #define MAX_DYNAMIC_STRINGS (64)
2743 typedef struct unicode_usage_s unicode_usage_t;
2744 struct unicode_usage_s {
2746 unicode_usage_t *next;
2749 extern unicode_usage_t *unicode_usage_entries;
2751 /* This is the maximum number of (8-bit) bytes that can encode a single
2752 Huffman entity. Four should be plenty, unless someone starts encoding
2753 an ideographic language. */
2754 #define MAXHUFFBYTES (4)
2756 typedef struct huffbitlist_struct {
2757 uchar b[MAXHUFFBYTES];
2759 typedef struct huffentity_struct {
2772 extern huffentity_t *huff_entities;
2774 extern int32 compression_table_size, compression_string_size;
2775 extern int32 *compressed_offsets;
2776 extern int no_huff_entities;
2777 extern int huff_abbrev_start, huff_dynam_start, huff_unicode_start;
2778 extern int huff_entity_root;
2780 extern void compress_game_text(void);
2782 /* end of the Glulx string compression stuff */
2784 extern void ao_free_arrays(void);
2785 extern int32 compile_string(char *b, int in_low_memory, int is_abbrev);
2786 extern uchar *translate_text(uchar *p, uchar *p_limit, char *s_text);
2787 extern void optimise_abbreviations(void);
2788 extern void make_abbreviation(char *text);
2789 extern void show_dictionary(void);
2790 extern void word_to_ascii(uchar *p, char *result);
2791 extern void write_dictionary_to_transcript(void);
2792 extern void sort_dictionary(void);
2793 extern void dictionary_prepare(char *dword, uchar *optresult);
2794 extern int dictionary_add(char *dword, int x, int y, int z);
2795 extern void dictionary_set_verb_number(char *dword, int to);
2796 extern int compare_sorts(uchar *d1, uchar *d2);
2797 extern void copy_sorts(uchar *d1, uchar *d2);
2799 /* ------------------------------------------------------------------------- */
2800 /* Extern definitions for "veneer" */
2801 /* ------------------------------------------------------------------------- */
2803 extern int veneer_mode;
2804 extern int32 veneer_routine_address[];
2806 extern void compile_initial_routine(void);
2807 extern assembly_operand veneer_routine(int code);
2808 extern void compile_veneer(void);
2810 /* ------------------------------------------------------------------------- */
2811 /* Extern definitions for "verbs" */
2812 /* ------------------------------------------------------------------------- */
2814 extern int no_adjectives, no_Inform_verbs, no_grammar_token_routines,
2815 no_fake_actions, no_actions, no_grammar_lines, no_grammar_tokens,
2816 grammar_version_number;
2817 extern int32 grammar_version_symbol;
2818 extern verbt *Inform_verbs;
2819 extern uchar *grammar_lines;
2820 extern int32 grammar_lines_top;
2821 extern int32 *action_byte_offset,
2822 *grammar_token_routine,
2825 extern void find_the_actions(void);
2826 extern void make_fake_action(void);
2827 extern assembly_operand action_of_name(char *name);
2828 extern void make_verb(void);
2829 extern void extend_verb(void);
2830 extern void list_verb_table(void);
2832 /* ========================================================================= */