Update to commit a469d404a7dc4e87e18f367eb4d8e05fc32d20a7
[inform.git] / src / header.h
1 /* ------------------------------------------------------------------------- */
2 /*   Header file for Inform:  Z-machine ("Infocom" format) compiler          */
3 /*                                                                           */
4 /*                              Inform 6.40                                  */
5 /*                                                                           */
6 /*   This header file and the others making up the Inform source code are    */
7 /*   copyright (c) Graham Nelson 1993 - 2022                                 */
8 /*                                                                           */
9 /* Inform is free software: you can redistribute it and/or modify            */
10 /* it under the terms of the GNU General Public License as published by      */
11 /* the Free Software Foundation, either version 3 of the License, or         */
12 /* (at your option) any later version.                                       */
13 /*                                                                           */
14 /* Inform is distributed in the hope that it will be useful,                 */
15 /* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
16 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the              */
17 /* GNU General Public License for more details.                              */
18 /*                                                                           */
19 /* You should have received a copy of the GNU General Public License         */
20 /* along with Inform. If not, see https://gnu.org/licenses/                  */
21 /*                                                                           */
22 /*   *** To compile this program in one of the existing ports, you must      */
23 /*       at least change the machine definition (on the next page).          */
24 /*       In most cases no other work will be needed. ***                     */
25 /*                                                                           */
26 /*   Contents:                                                               */
27 /*                                                                           */
28 /*       Machine/host OS definitions (in alphabetical order)                 */
29 /*       Default definitions                                                 */
30 /*       Standard ANSI inclusions, macro definitions, structures             */
31 /*       Definitions of internal code numbers                                */
32 /*       Extern declarations for linkage (in alphabetical order of file)     */
33 /*                                                                           */
34 /* ------------------------------------------------------------------------- */
35
36 /* For releases, set to the release date in the form "1st January 2000" */
37 #define RELEASE_DATE "in development"
38 #define RELEASE_NUMBER 1640
39 #define GLULX_RELEASE_NUMBER 38
40 #define MODULE_VERSION_NUMBER 1
41 #define VNUMBER RELEASE_NUMBER
42
43 /* N indicates an intermediate release for Inform 7 */
44 /*#define RELEASE_SUFFIX "N"*/
45
46 /* ------------------------------------------------------------------------- */
47 /*   Our host machine or OS for today is...                                  */
48 /*                                                                           */
49 /*   [ Inform should compile (possibly with warnings) and work safely        */
50 /*     if you just:                                                          */
51 /*                                                                           */
52 /*     #define AMIGA       -  for the Commodore Amiga under SAS/C            */
53 /*     #define ARCHIMEDES  -  for Acorn RISC OS machines under Norcroft C    */
54 /*     #define ATARIST     -  for the Atari ST                               */
55 /*     #define BEOS        -  for the BeBox                                  */
56 /*     #define LINUX       -  for Linux under gcc (essentially as Unix)      */
57 /*     #define MACOS       -  for the Apple Mac with OS X (another Unix)     */
58 /*     #define MAC_CLASSIC -  for the Apple Mac under Think C or Codewarrior */
59 /*     #define MAC_MPW     -  for MPW under Codewarrior (and maybe Think C)  */
60 /*     #define OS2         -  for OS/2 32-bit mode under IBM's C Set++       */
61 /*     #define PC          -  for 386+ IBM PCs, eg. Microsoft Visual C/C++   */
62 /*     #define PC_QUICKC   -  for small IBM PCs under QuickC                 */
63 /*     #define PC_WIN32    -  for Borland C++ or Microsoft Visual C++        */
64 /*     #define UNIX        -  for Unix under gcc (or big IBM PC under djgpp) */
65 /*     #define VMS         -  for VAX or ALPHA under DEC C, but not VAX C    */
66 /*                                                                           */
67 /*     In most cases executables are already available at                    */
68 /*     https://www.ifarchive.org/, and these are sometimes enhanced with     */
69 /*     e.g. windowed interfaces whose source is not archived with the        */
70 /*     main Inform source.]                                                  */
71 /*                                                                           */
72 /*   (If no machine is defined, then cautious #defines will be made.  In     */
73 /*   most cases, porting to a new machine is a matter of carefully filling   */
74 /*   out a block of definitions like those below.)                           */
75 /* ------------------------------------------------------------------------- */
76
77 /* ------------------------------------------------------------------------- */
78 /*   The first task is to include the ANSI header files, and typedef         */
79 /*   suitable 32-bit integer types.                                          */
80 /* ------------------------------------------------------------------------- */
81
82 #include <stdio.h>
83 #include <stdlib.h>
84 #include <stdarg.h>
85 #include <ctype.h>
86 #include <string.h>
87 #include <time.h>
88 #include <limits.h>
89 #include <math.h>
90
91 #ifndef VAX
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;
104 #else
105 #error No type large enough to support 32-bit integers.
106 #endif
107 #else
108       /*  VAX C does not provide these limit constants, contrary to ANSI  */
109       typedef int int32;
110       typedef unsigned int uint32;
111 #endif
112
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.       */
116 /*                                                                           */
117 /*   1. MACHINE_STRING should be set to the name of the machine or OS.       */
118 /*                                                                           */
119 /*   2. Some miscellaneous #define options (set if the constant is           */
120 /*   defined, otherwise not set):                                            */
121 /*                                                                           */
122 /*   PROMPT_INPUT        - prompt input (don't use Unix-style command line)  */
123 /*   TIME_UNAVAILABLE    - don't use ANSI time routines to work out today's  */
124 /*                         date                                              */
125 /*   CHAR_IS_UNSIGNED    - if on your compiler the type "char" is unsigned   */
126 /*                         by default, you should define this                */
127 /*   HAS_REALPATH        - the POSIX realpath() function is available to     */
128 /*                         find the absolute path to a file                  */
129 /*                                                                           */
130 /*   3. This was DEFAULT_MEMORY_SIZE, now withdrawn.                         */
131 /* ------------------------------------------------------------------------- */
132
133 /* ------------------------------------------------------------------------- */
134 /*   4. Filenaming definitions:                                              */
135 /*                                                                           */
136 /*   It's assumed that the host OS has the concept of subdirectories and     */
137 /*   has "pathnames", that is, filenames giving a chain of subdirectories    */
138 /*   divided by the FN_SEP (filename separator) character: e.g. for Unix     */
139 /*   FN_SEP is defined below as '/' and a typical name is                    */
140 /*                         "users/graham/jigsaw.z5".                         */
141 /*   White space is not allowed in filenames, and nor is the special         */
142 /*   character FN_ALT, which unless defined here will be a comma and will    */
143 /*   be used to separate alternative locations in a path variable.           */
144 /*                                                                           */
145 /*   If NO_FILE_EXTENSIONS is undefined then the OS allows "file extensions" */
146 /*   of 1 to 3 alphanumeric characters like ".txt" (for text files), ".z5"   */
147 /*   (for game files), etc., to indicate the file's type (and, crucially,    */
148 /*   regards the same filename but with different extensions -- e.g.,        */
149 /*   "frog.amp" and "frog.lil" -- as being different names).                 */
150 /*   (The file extensions defined below are widely accepted, so please use   */
151 /*   them unless there's a good reason why not.)                             */
152 /*                                                                           */
153 /*   You should then define STANDARD_DIRECTORIES (you can define it anyway)  */
154 /*   in which case Inform will expect by default that files are sorted out   */
155 /*   by being put into suitable directories (e.g., a "games" directory for   */
156 /*   story files).                                                           */
157 /*                                                                           */
158 /*   If it's convenient for your port you can alter the detailed definitions */
159 /*   which these broad settings make.  Be careful if NO_FILE_EXTENSIONS      */
160 /*   is set without STANDARD_DIRECTORIES, as then Inform may                 */
161 /*   overwrite its source with object code.                                  */
162 /*                                                                           */
163 /*   5. Filenames (or code related to filenames) for temporary files.        */
164 /*   These included Temporary_Name, Temporary_Directory, and                 */
165 /*   INCLUDE_TASK_ID. These options have been removed, and are listed here   */
166 /*   only for people who might ask "what happened to 5?"                     */
167 /*                                                                           */
168 /*   6. Any other definitions specific to the OS or machine.                 */
169 /*   (In particular DEFAULT_ERROR_FORMAT is 0 on most machines and 1 on PCs; */
170 /*   it controls the style of error messages, which is important for some    */
171 /*   error-throwback debugging tools.)                                       */
172 /* ------------------------------------------------------------------------- */
173
174 /* ========================================================================= */
175 /*   The blocks now follow in alphabetical order.                            */
176 /* ------------------------------------------------------------------------- */
177 /*   AMIGA block                                                             */
178 /* ------------------------------------------------------------------------- */
179 #ifdef AMIGA
180 /* 1 */
181 #define MACHINE_STRING   "Amiga"
182 /* 4 */
183 #define FN_SEP '/'
184 #endif
185 /* ------------------------------------------------------------------------- */
186 /*   ARCHIMEDES block: Acorn/RISC OS settings                                */
187 /* ------------------------------------------------------------------------- */
188 #ifdef ARCHIMEDES
189 /* 1 */
190 #define MACHINE_STRING   "RISC OS"
191 /* 2 */
192 #define CHAR_IS_UNSIGNED
193 /* 4 */
194 #define FN_SEP '.'
195 #define STANDARD_DIRECTORIES
196 #define NO_FILE_EXTENSIONS
197 #define Source_Directory "inform"
198 #define ICL_Directory "ICL"
199 /* 6 */
200 #define ARC_THROWBACK
201 #endif
202 /* ------------------------------------------------------------------------- */
203 /*   Atari ST block                                                          */
204 /* ------------------------------------------------------------------------- */
205 #ifdef ATARIST
206 /* 1 */
207 #define MACHINE_STRING   "Atari ST"
208 /* 4 */
209 #define FN_SEP '/'
210 #endif
211 /* ------------------------------------------------------------------------- */
212 /*   BEOS block                                                              */
213 /* ------------------------------------------------------------------------- */
214 #ifdef BEOS
215 /* 1 */
216 #define MACHINE_STRING   "BeOS"
217 /* 4 */
218 #define FN_SEP '/'
219 #define FILE_EXTENSIONS
220 #endif
221 /* ------------------------------------------------------------------------- */
222 /*   LINUX block                                                             */
223 /* ------------------------------------------------------------------------- */
224 #ifdef LINUX
225 /* 1 */
226 #define MACHINE_STRING   "Linux"
227 /* 2 */
228 #define HAS_REALPATH
229 /* 4 */
230 #define FN_SEP '/'
231 /* 6 */
232 #define PATHLEN 8192
233 #if defined(__STDC__) && (__STDC_VERSION__ >= 201112L)
234 #define USE_C11_TIME_API
235 #endif
236 #endif
237 /* ------------------------------------------------------------------------- */
238 /*   Macintosh block                                                         */
239 /* ------------------------------------------------------------------------- */
240 #ifdef MAC_MPW
241 #define MAC_CLASSIC
242 #endif
243
244 #ifdef MAC_CLASSIC
245 /* 1 */
246 #ifdef MAC_MPW
247 #define MACHINE_STRING   "Macintosh Programmer's Workshop"
248 #else
249 #define MACHINE_STRING   "Macintosh"
250 #endif
251 /* 2 */
252 #ifdef MAC_FACE
253 #define EXTERNAL_SHELL
254 #endif
255 #ifndef MAC_FACE
256 #ifndef MAC_MPW
257 #define PROMPT_INPUT
258 #endif
259 #endif
260 /* 4 */
261 #define FN_SEP           ':'
262 #ifdef MAC_MPW
263 #define Include_Extension ".h"
264 #endif
265 /* 6 */
266 #ifdef MAC_FACE
267 #include "TB Inform.h"
268 #endif
269 #ifdef MAC_MPW
270 #include <CursorCtl.h>
271 #define DEFAULT_ERROR_FORMAT 2
272 #endif
273 #endif
274 /* ------------------------------------------------------------------------- */
275 /*   OS/2 block                                                              */
276 /* ------------------------------------------------------------------------- */
277 #ifdef OS2
278 /* 1 */
279 #define MACHINE_STRING   "OS/2"
280 /* 2 */
281 #define CHAR_IS_UNSIGNED
282 /* 4 */
283 #define FN_SEP '/'
284 #endif
285 /* ------------------------------------------------------------------------- */
286 /*   MACOS block                                                              */
287 /* ------------------------------------------------------------------------- */
288 #ifdef MACOS
289 /* 1 */
290 #define MACHINE_STRING   "MacOS"
291 /* 2 */
292 #define HAS_REALPATH
293 /* 4 */
294 #define FN_SEP '/'
295 /* 6 */
296 #define PATHLEN 8192
297 #if defined(__STDC__) && (__STDC_VERSION__ >= 201112L)
298 #define USE_C11_TIME_API
299 #endif
300 #endif
301 /* ------------------------------------------------------------------------- */
302 /*   PC and PC_QUICKC block                                                  */
303 /* ------------------------------------------------------------------------- */
304 #ifdef PC_QUICKC
305 #define PC
306 #endif
307
308 #ifdef PC
309 /* 1 */
310 #define MACHINE_STRING   "PC"
311 /* 4 */
312 #define FN_SEP '\\'
313 /* 6 */
314 #define DEFAULT_ERROR_FORMAT 1
315 #endif
316 /* ------------------------------------------------------------------------- */
317 /*   PC_WIN32 block                                                          */
318 /* ------------------------------------------------------------------------- */
319 #ifdef PC_WIN32
320 /* 1 */
321 #define MACHINE_STRING   "Win32"
322 /* 2 */
323 #define HAS_REALPATH
324 /* 4 */
325 #define FN_SEP '\\'
326 /* 6 */
327 #define DEFAULT_ERROR_FORMAT 1
328 #define PATHLEN 512
329 #if _MSC_VER >= 1920 /* Visual C++ 2019 */
330 #define USE_C11_TIME_API
331 #endif
332 #endif
333 /* ------------------------------------------------------------------------- */
334 /*   UNIX block                                                              */
335 /* ------------------------------------------------------------------------- */
336 #ifdef UNIX
337 /* 1 */
338 #ifndef MACHINE_STRING
339 #define MACHINE_STRING   "Unix"
340 #endif
341 /* 2 */
342 #define HAS_REALPATH
343 /* 4 */
344 #define FN_SEP '/'
345 #endif
346 /* ------------------------------------------------------------------------- */
347 /*   VMS (Dec VAX and Alpha) block                                           */
348 /* ------------------------------------------------------------------------- */
349 #ifdef __VMS
350 #define VMS
351 #endif
352
353 #ifdef VMS
354 /* 1 */
355 #ifdef __ALPHA
356 #define MACHINE_STRING   "Alpha/VMS"
357 #else
358 #define MACHINE_STRING   "VAX/VMS"
359 #endif
360 /* 2 */
361 #define CHAR_IS_UNSIGNED
362 /* 4 */
363 #define FN_SEP '/'
364 #define Code_Extension   ".zip"
365 #define V4Code_Extension ".zip"
366 #define V5Code_Extension ".zip"
367 #define V6Code_Extension ".zip"
368 #define V7Code_Extension ".zip"
369 #define V8Code_Extension ".zip"
370 #endif
371 /* ========================================================================= */
372 /* Default settings:                                                         */
373 /* ------------------------------------------------------------------------- */
374
375 #ifndef NO_FILE_EXTENSIONS
376 #define FILE_EXTENSIONS
377 #endif
378
379 #ifndef Transcript_File
380 #ifdef FILE_EXTENSIONS
381 #define Transcript_File "gametext.txt"
382 #else
383 #define Transcript_File "gametext"
384 #endif
385 #endif
386
387 #ifndef Debugging_File
388 #ifdef FILE_EXTENSIONS
389 #define Debugging_File "gameinfo.dbg"
390 #else
391 #define Debugging_File "gamedebug"
392 #endif
393 #endif
394
395 #ifndef Default_Language
396 #define Default_Language "english"
397 #endif
398
399 #ifdef FILE_EXTENSIONS
400 #ifndef Source_Extension
401 #define Source_Extension  ".inf"
402 #endif
403 #ifndef Include_Extension
404 #define Include_Extension ".h"
405 #endif
406 #ifndef Code_Extension
407 #define Code_Extension    ".z3"
408 #endif
409 #ifndef V4Code_Extension
410 #define V4Code_Extension  ".z4"
411 #endif
412 #ifndef V5Code_Extension
413 #define V5Code_Extension  ".z5"
414 #endif
415 #ifndef V6Code_Extension
416 #define V6Code_Extension  ".z6"
417 #endif
418 #ifndef V7Code_Extension
419 #define V7Code_Extension  ".z7"
420 #endif
421 #ifndef V8Code_Extension
422 #define V8Code_Extension  ".z8"
423 #endif
424 #ifndef GlulxCode_Extension
425 #define GlulxCode_Extension  ".ulx"
426 #endif
427 #ifndef Module_Extension
428 #define Module_Extension  ".m5"
429 #endif
430 #ifndef ICL_Extension
431 #define ICL_Extension     ".icl"
432 #endif
433
434 #else
435
436 #define Source_Extension  ""
437 #define Include_Extension ""
438 #define Code_Extension    ""
439 #define V4Code_Extension  ""
440 #define V5Code_Extension  ""
441 #define V6Code_Extension  ""
442 #define V7Code_Extension  ""
443 #define V8Code_Extension  ""
444 #define GlulxCode_Extension  ""
445 #define Module_Extension  ""
446 #define ICL_Extension     ""
447 #endif
448
449 #ifdef STANDARD_DIRECTORIES
450 #ifndef Source_Directory
451 #define Source_Directory  "source"
452 #endif
453 #ifndef Include_Directory
454 #define Include_Directory "library"
455 #endif
456 #ifndef Code_Directory
457 #define Code_Directory    "games"
458 #endif
459 #ifndef Module_Directory
460 #define Module_Directory  "modules"
461 #endif
462 #ifndef ICL_Directory
463 #define ICL_Directory     ""
464 #endif
465
466 #else
467
468 #ifndef Source_Directory
469 #define Source_Directory  ""
470 #endif
471 #ifndef Include_Directory
472 #define Include_Directory ""
473 #endif
474 #ifndef Code_Directory
475 #define Code_Directory    ""
476 #endif
477 #ifndef Module_Directory
478 #define Module_Directory  ""
479 #endif
480 #ifndef ICL_Directory
481 #define ICL_Directory     ""
482 #endif
483 #endif
484
485 #ifndef FN_SEP
486 #define FN_SEP '/'
487 #endif
488
489 #ifndef FN_ALT
490 #define FN_ALT ','
491 #endif
492
493 #ifndef PATHLEN
494 #define PATHLEN 128
495 #endif
496
497 #ifndef DEFAULT_ERROR_FORMAT
498 #define DEFAULT_ERROR_FORMAT 0
499 #endif
500
501 #ifndef CHAR_IS_UNSIGNED
502     typedef unsigned char uchar;
503 #else
504     typedef char uchar;
505 #endif
506
507 #if defined(__GNUC__) || defined(__clang__)
508 #define NORETURN __attribute__((__noreturn__))
509 #endif /* defined(__GNUC__) || defined(__clang__) */
510
511 #ifndef NORETURN
512 #define NORETURN
513 #endif
514
515 /* ------------------------------------------------------------------------- */
516 /*   subtract_pointers() measures an address difference in bytes. This is    */
517 /*   a macro.                                                                */
518 /*   We also declare some memory functions for PC_QUICKC.                    */
519 /* ------------------------------------------------------------------------- */
520
521 #ifdef PC_QUICKC
522     void _huge * halloc(long, size_t);
523     void hfree(void *);
524 #define subtract_pointers(p1,p2) (long)((char _huge *)p1-(char _huge *)p2)
525 #else
526 #define subtract_pointers(p1,p2) (((char *) p1)-((char *) p2))
527 #endif
528
529
530 /* ------------------------------------------------------------------------- */
531 /*   Definitions for time measurement. TIMEVALUE is a type; TIMEVALUE_NOW()  */
532 /*   sets it; TIMEVALUE_DIFFERENCE() determines a difference in seconds,     */
533 /*   as a float.                                                             */
534 /*   Modern platforms should support timespec_get() or clock_gettime(). To   */
535 /*   use timespec_get(), #define USE_C11_TIME_API. To use clock_gettime(),   */
536 /*   #define USE_POSIX_TIME_API. To use the old implementation using         */
537 /*   time(), #define USE_OLD_TIME_API. This can only measure in integer      */
538 /*   second counts, but it's better than waiting for gnomon.                 */
539 /* ------------------------------------------------------------------------- */
540
541 #if !defined(USE_C11_TIME_API) && !defined(USE_POSIX_TIME_API) && !defined(USE_OLD_TIME_API)
542 #define USE_OLD_TIME_API
543 #endif
544
545 #if defined(USE_OLD_TIME_API)
546   #define TIMEVALUE time_t
547   #define TIMEVALUE_NOW(t) (*t) = time(0)
548   #define TIMEVALUE_DIFFERENCE(begt, endt) (float)(*(endt) - *(begt))
549 #elif defined(USE_C11_TIME_API)
550   #define TIMEVALUE struct timespec
551   #define TIMEVALUE_NOW(t) timespec_get((t), TIME_UTC)
552   #define TIMEVALUE_DIFFERENCE(begt, endt) ((float)((endt)->tv_sec - (begt)->tv_sec) + (float)((endt)->tv_nsec - (begt)->tv_nsec) / 1000000000.0F)
553 #elif defined(USE_POSIX_TIME_API)
554   #define TIMEVALUE struct timespec
555   #define TIMEVALUE_NOW(t) clock_gettime(CLOCK_REALTIME, (t))
556   #define TIMEVALUE_DIFFERENCE(begt, endt) ((float)((endt)->tv_sec - (begt)->tv_sec) + (float)((endt)->tv_nsec - (begt)->tv_nsec) / 1000000000.0F)
557 #endif
558
559 /* ------------------------------------------------------------------------- */
560 /*   SEEK_SET is a constant which should be defined in the ANSI header files */
561 /*   but which is not present in some implementations: it's used as a        */
562 /*   parameter for "fseek", defined in "stdio".  In pre-ANSI C, the value    */
563 /*   0 was used as a parameter instead, hence the definition below.          */
564 /* ------------------------------------------------------------------------- */
565
566 #ifndef SEEK_SET
567 #define SEEK_SET 0
568 #endif
569
570 /* ------------------------------------------------------------------------- */
571 /*   A large block of #define'd constant values follows.                     */
572 /* ------------------------------------------------------------------------- */
573
574 #define TRUE -1
575 #define FALSE 0
576
577 /* These checked the glulx_mode global during development, but are no
578    longer needed. */
579 #define ASSERT_ZCODE() (0)
580 #define ASSERT_GLULX() (0)
581
582
583 #define ReadInt32(ptr)                               \
584   (   (((int32)(((uchar *)(ptr))[0])) << 24)         \
585     | (((int32)(((uchar *)(ptr))[1])) << 16)         \
586     | (((int32)(((uchar *)(ptr))[2])) <<  8)         \
587     | (((int32)(((uchar *)(ptr))[3]))      ) )
588
589 #define ReadInt16(ptr)                               \
590   (   (((int32)(((uchar *)(ptr))[0])) << 8)          \
591     | (((int32)(((uchar *)(ptr))[1]))     ) )
592
593 #define WriteInt32(ptr, val)                         \
594   ((ptr)[0] = (uchar)(((int32)(val)) >> 24),         \
595    (ptr)[1] = (uchar)(((int32)(val)) >> 16),         \
596    (ptr)[2] = (uchar)(((int32)(val)) >>  8),         \
597    (ptr)[3] = (uchar)(((int32)(val))      ) )
598
599 #define WriteInt16(ptr, val)                         \
600   ((ptr)[0] = (uchar)(((int32)(val)) >> 8),          \
601    (ptr)[1] = (uchar)(((int32)(val))     ) )
602
603 /* ------------------------------------------------------------------------- */
604 /*   If your compiler doesn't recognise \t, and you use ASCII, you could     */
605 /*   define T_C as (char) 9; failing that, it _must_ be defined as ' '       */
606 /*   (space) and is _not_ allowed to be 0 or any recognisable character.     */
607 /* ------------------------------------------------------------------------- */
608
609 #define TAB_CHARACTER '\t'
610
611 /* ------------------------------------------------------------------------- */
612 /*   Maxima.                                                                 */
613 /* ------------------------------------------------------------------------- */
614
615 #define  MAX_ERRORS            100
616 #define  MAX_IDENTIFIER_LENGTH  32
617 #define  MAX_ABBREV_LENGTH      64
618 #define  MAX_DICT_WORD_SIZE     40
619 #define  MAX_DICT_WORD_BYTES    (40*4)
620 #define  MAX_NUM_ATTR_BYTES     39
621 #define  MAX_VERB_WORD_SIZE    120
622
623 #define  VENEER_CONSTRAINT_ON_CLASSES_Z       256
624 #define  VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_Z 128
625 #define  VENEER_CONSTRAINT_ON_CLASSES_G       32768
626 #define  VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_G 32768
627 #define  VENEER_CONSTRAINT_ON_CLASSES  \
628   (glulx_mode ? VENEER_CONSTRAINT_ON_CLASSES_G  \
629               : VENEER_CONSTRAINT_ON_CLASSES_Z)
630 #define  VENEER_CONSTRAINT_ON_IP_TABLE_SIZE  \
631   (glulx_mode ? VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_G  \
632               : VENEER_CONSTRAINT_ON_IP_TABLE_SIZE_Z)
633
634 #define  GLULX_HEADER_SIZE 36
635 /* Number of bytes in the header. */
636 #define  GLULX_STATIC_ROM_SIZE 24
637 /* Number of bytes in the Inform-specific block right after the header. */
638 #define  GPAGESIZE 256
639 /* All Glulx memory boundaries must be multiples of GPAGESIZE. */
640
641 /* ------------------------------------------------------------------------- */
642 /*   Structure definitions (there are a few others local to files)           */
643 /* ------------------------------------------------------------------------- */
644
645 /*  A memory list is a sequential array of items. The list grows as
646     necessary, but it is *not* sparse.
647     This can optionally maintain an external pointer (of any type) which 
648     also refers to the allocated array. The external pointer will always
649     have the same value as data.
650     (Note: the external pointer must itself have a stable location, because
651     we keep a pointer *to* it. It cannot live in another memory list or
652     realloced array. Most of our memory lists refer to global or static
653     variables, so that's fine.)
654 */
655 typedef struct memory_list_s
656 {
657     char *whatfor;   /* must be a static string */
658     void *data;      /* allocated array of count*itemsize bytes */
659     void **extpointer;  /* pointer to keep in sync */
660     size_t itemsize;    /* item size in bytes */
661     size_t count;       /* number of items allocated */
662 } memory_list;
663
664 typedef struct identstruct_s
665 {
666     char text[MAX_IDENTIFIER_LENGTH+1];
667 } identstruct;
668
669 typedef struct assembly_operand_t
670 {   int   type;     /* ?_OT value */
671     int32 value;
672     int   symindex; /* index in symbols array, if derived from a symbol */
673     int   marker;   /* ?_MV value */
674 } assembly_operand;
675
676 #define INITAOTV(aop, typ, val) ((aop)->type=(typ), (aop)->value=(val), (aop)->marker=0, (aop)->symindex=-1)
677 #define INITAOT(aop, typ) INITAOTV(aop, typ, 0)
678 #define INITAO(aop) INITAOTV(aop, 0, 0)
679
680 typedef struct variableinfo_s {
681     int32 token;   /* Symbol table index for variable name */
682     int usage;     /* TRUE if referred to */
683 } variableinfo;
684
685 typedef struct verbt {
686     int lines;
687     int *l; /* alloced array */
688     int size; /* allocated size of l */
689 } verbt;
690
691 typedef struct actioninfo_s {
692     int32 symbol;      /* The symbol table index of the action name */
693     int32 byte_offset; /* The (byte) offset in the Z-machine code area of 
694                           the ...Sub routine */
695 } actioninfo;
696
697 /* Information about an object class. */
698 typedef struct classinfo_s {
699     /* The number of the prototype-object for this class */
700     int object_number;
701     /* The offset of properties block for this class (always an offset inside the properties table) */
702     int32 begins_at;
703     /* Class name symbol number */
704     int32 symbol;
705 } classinfo;
706
707 /* Common property information. */
708 typedef struct commonpropinfo_s {
709     int32 default_value;   /* Common property default value */
710     int is_long;           /* "Long" means "never write a 1-byte value to
711                               this property", and is an obsolete feature:
712                               since Inform 5 all properties have been "long" */
713     int is_additive;       /* "Additive" means that values accumulate rather
714                               than erase each other during class inheritance */
715 } commonpropinfo;
716
717 /* Property entry record (Z). */
718 typedef struct prop {
719     uchar l, num;
720     assembly_operand ao[32];
721 } prop;
722
723 /* Properties and attributes of the object currently being constructed (Z). */
724 /* Only one of this object. */
725 typedef struct fpropt {
726     uchar atts[6];
727     int l;
728     prop pp[64];
729     int32 symbol; /* name symbol or 0 */
730 } fpropt;
731
732 /* Constructed object (Z). */
733 typedef struct objecttz {
734     uchar atts[6];
735     int parent, next, child;
736     int propsize;
737     int32 symbol; /* name symbol or 0 */
738 } objecttz;
739
740 /* Property entry record (G). */
741 typedef struct propg {
742     int num;
743     int continuation; 
744     int flags;
745     int32 datastart;
746     int32 datalen;
747 } propg;
748
749 /* Properties and attributes of the object currently being constructed (G). */
750 /* Only one of this object. */
751 typedef struct fproptg {
752     uchar atts[MAX_NUM_ATTR_BYTES]; 
753     int numprops;
754     propg *props;               /* allocated to numprops */
755     memory_list props_memlist;
756     int propdatasize;
757     assembly_operand *propdata; /* allocated to propdatasize */
758     memory_list propdata_memlist;
759     int32 finalpropaddr;
760     /* It's safe to use memory_lists in this object because there's just
761        one and it's static. */
762     int32 symbol; /* name symbol or 0 */
763 } fproptg;
764
765 /* Constructed object (G). */
766 typedef struct objecttg {
767     /* attributes are stored in a separate array */
768     int32 shortname;
769     int32 parent, next, child;
770     int32 propaddr;
771     int32 propsize;
772     int32 symbol; /* name symbol or 0 */
773 } objecttg;
774
775 typedef struct abbreviation_s {
776     int value;
777     int quality;
778     int freq;
779 } abbreviation;
780
781 typedef struct maybe_file_position_S
782 {   int valid;
783     fpos_t position;
784 } maybe_file_position;
785
786 typedef struct debug_location_s
787 {   int32 file_index;
788     int32 beginning_byte_index;
789     int32 end_byte_index;
790     int32 beginning_line_number;
791     int32 end_line_number;
792     int32 beginning_character_number;
793     int32 end_character_number;
794     int32 orig_file_index;
795     int32 orig_beg_line_number;
796     int32 orig_beg_char_number;
797     /* We only track the beginning #origsource location, not the end. */
798 } debug_location;
799
800 typedef struct debug_locations_s
801 {   debug_location location;
802     struct debug_locations_s *next;
803     int reference_count;
804 } debug_locations;
805
806 typedef struct brief_location_s
807 {   int32 file_index;
808     int32 line_number;
809     int32 orig_file_index;
810     int32 orig_line_number;
811 } brief_location;
812
813 typedef struct debug_location_beginning_s
814 {   debug_locations *head;
815     int32 beginning_byte_index;
816     int32 beginning_line_number;
817     int32 beginning_character_number;
818     int32 orig_file_index;
819     int32 orig_beg_line_number;
820     int32 orig_beg_char_number;
821 } debug_location_beginning;
822
823 #define MAX_KEYWORD_GROUP_SIZE (119)
824
825 typedef struct keyword_group_s
826 {   char *keywords[MAX_KEYWORD_GROUP_SIZE+1]; /* empty-string-terminated */
827     int change_token_type;
828     int enabled;
829     int case_sensitive;
830 } keyword_group;
831
832 typedef struct lexeme_data_s {
833     char *text;  /* points at lextexts array */
834     int32 value;
835     int type;    /* a *_TT value */
836     debug_location location;
837     int lextext; /* index of text string in lextexts */
838     int context; /* lexical context used to interpret this token */
839 } lexeme_data;
840
841 typedef struct token_data_s {
842     char *text;
843     int32 value;
844     int type;      /* a *_TT value */
845     int symindex;
846     int symtype;
847     int symflags;
848     int marker;
849 } token_data;
850
851 typedef struct symbolinfo_s {
852     char *name; /* Points into a symbol_name_space_chunk */
853     int32 value;
854     int marker; /* ?_MV value */
855     brief_location line;
856     unsigned int flags;  /* ?_SFLAGS bitmask */
857     uchar type; /* ?_T value */
858     int next_entry; /* Linked list for symbol hash table */
859 } symbolinfo;
860
861 typedef struct symboldebuginfo_s {
862     maybe_file_position backpatch_pos;
863     maybe_file_position replacement_backpatch_pos;
864 } symboldebuginfo;
865
866 typedef struct arrayinfo_s {
867     int32 symbol; /* index in symbols[] */
868     int size;     /* length of array */
869     int type;     /* BYTE_ARRAY, WORD_ARRAY, etc */
870     int loc;      /* true for static, false for dynamic (regular) arrays */
871 } arrayinfo;
872
873 typedef struct labelinfo_s {
874     int32 offset; /* Offset (zmachine_pc) value */
875     int32 symbol; /* Symbol numbers if defined in source */
876     int next;     /* For linked list */
877     int prev;     /* For linked list */
878 } labelinfo;
879
880 typedef struct sequencepointinfo_s {
881     int label;               /* Label number */
882     debug_location location; /* Source code reference (used for making
883                                 debugging file)                              */
884 } sequencepointinfo;
885
886 typedef struct FileId_s                 /*  Source code file identifier:     */
887 {   char *filename;                     /*  The filename (after translation) */
888     FILE *handle;                       /*  Handle of file (when open), or
889                                             NULL when closed                 */
890     int is_input;                       /*  Is this a source file that we are
891                                             parsing? If not, this is an
892                                             origsource filename (and handle
893                                             is NULL).                        */
894     int initial_buffering;              /* Are we still in the initial
895                                            begin_buffering_file() call?      */
896 } FileId;
897
898 typedef struct ErrorPosition_s
899 {   int  file_number;
900     char *source;
901     int  line_number;
902     int  main_flag;
903     int  orig_file;
904     char *orig_source;
905     int32 orig_line;
906     int32 orig_char;
907 } ErrorPosition;
908
909 /* This serves for both Z-code and Glulx instructions. Glulx doesn't use
910    the text, store_variable_number, branch_label_number, or branch_flag
911    fields. */
912 typedef struct assembly_instruction_t
913 {   int internal_number;
914     int store_variable_number;
915     int32 branch_label_number;
916     int branch_flag;
917     char *text;                    /* if set, generally points to token_text */
918     int operand_count;
919     assembly_operand operand[8];
920 } assembly_instruction;
921
922 typedef struct expression_tree_node_s
923 {
924     /*  Data used in tree construction                                       */
925
926     int up, down, right;
927     int operator_number;         /* Only meaningful for non-leaves           */
928     assembly_operand value;      /* Only meaningful for leaves               */
929
930     /*  Attributes synthesised during code generation                        */
931
932     int must_produce_value;      /* e.g. FALSE in a void context             */
933
934     int label_after;             /* -1, or "put this label after code"       */
935     int to_expression;           /* TRUE if a condition used as numeric val  */
936     int true_label;              /* On condition "true", jump to this (or keep
937                                     going if -1)                             */
938     int false_label;             /* Likewise if the condition is "false".    */
939
940 } expression_tree_node;
941
942 typedef struct operator_s
943 {   int precedence;                     /*  Level 0 to 13 (13 is highest)  */
944     int token_type;                     /*  Lexical token type  */
945     int token_value;                    /*  Lexical token value  */
946     int usage;                          /*  Infix (IN_U), prefix or postfix */
947     int associativity;                  /*  Left (L_A), right (R_A)
948                                             or 0 for "it is an error to
949                                             implicitly associate this"  */
950     int requires_lvalue;                /*  TRUE if the first operand must
951                                             be an "lvalue" (the name of some
952                                             storage object, such as a variable
953                                             or an array entry)  */
954     int opcode_number_z;                /*  Translation number (see below)  */
955     int opcode_number_g;                /*  Translation number (see below)  */
956     int side_effect;                    /*  TRUE if evaluating the operator
957                                             has potential side-effects in
958                                             terms of changing the Z-machine  */
959     int negation;                       /*  0 for an unconditional operator,
960                                             otherwise the negation operator  */
961     char *description;                  /*  Text describing the operator
962                                             for error messages and tracing  */
963 } operator;
964
965 /*  The translation number of an operator is as follows:
966
967     Z-code:
968         an internal opcode number if the operator can be translated
969             directly to a single Z-machine opcode;
970         400+n if it can be translated to branch opcode n;
971         800+n if to the negated form of branch opcode n;
972             (using n = 200, 201 for two conditions requiring special
973             translation)
974         -1 otherwise
975     Glulx:
976         an internal opcode number if the operator can be translated
977             directly to a single Glulx opcode;
978         FIRST_CC to LAST_CC if it is a condition;
979         -1 otherwise                                                         */
980
981 /* ------------------------------------------------------------------------- */
982 /*   Assembly operand types.                                                 */
983 /* ------------------------------------------------------------------------- */
984
985 /* For Z-machine... */
986
987 #define LONG_CONSTANT_OT   0    /* General constant */
988 #define SHORT_CONSTANT_OT  1    /* Constant in range 0 to 255 */
989 #define VARIABLE_OT        2    /* Variable (global, local or sp) */
990 #define OMITTED_OT         3    /* Value used in type field to indicate
991                                    that no operand is supplied */
992 #define EXPRESSION_OT      4    /* Meaning: to determine this value, run code
993                                    equivalent to the expression tree whose
994                                    root node-number is the value given       */
995
996 /* For Glulx... */
997
998 /* #define OMITTED_OT      3 */ /* Same as above */
999 /* #define EXPRESSION_OT   4 */ /* Same as above */
1000 #define CONSTANT_OT        5    /* Four-byte constant */
1001 #define HALFCONSTANT_OT    6    /* Two-byte constant */
1002 #define BYTECONSTANT_OT    7    /* One-byte constant */
1003 #define ZEROCONSTANT_OT    8    /* Constant zero (no bytes of data) */
1004 #define SYSFUN_OT          9    /* System function value */
1005 #define DEREFERENCE_OT     10   /* Value at this address */
1006 #define GLOBALVAR_OT       11   /* Global variable */
1007 #define LOCALVAR_OT        12   /* Local variable or sp */
1008
1009 /* ------------------------------------------------------------------------- */
1010 /*   Internal numbers representing assemble-able Z-opcodes                   */
1011 /* ------------------------------------------------------------------------- */
1012
1013 #define je_zc 0
1014 #define jl_zc 1
1015 #define jg_zc 2
1016 #define dec_chk_zc 3
1017 #define inc_chk_zc 4
1018 #define jin_zc 5
1019 #define test_zc 6
1020 #define or_zc 7
1021 #define and_zc 8
1022 #define test_attr_zc 9
1023 #define set_attr_zc 10
1024 #define clear_attr_zc 11
1025 #define store_zc 12
1026 #define insert_obj_zc 13
1027 #define loadw_zc 14
1028 #define loadb_zc 15
1029 #define get_prop_zc 16
1030 #define get_prop_addr_zc 17
1031 #define get_next_prop_zc 18
1032 #define add_zc 19
1033 #define sub_zc 20
1034 #define mul_zc 21
1035 #define div_zc 22
1036 #define mod_zc 23
1037 #define call_zc 24
1038 #define storew_zc 25
1039 #define storeb_zc 26
1040 #define put_prop_zc 27
1041 #define sread_zc 28
1042 #define print_char_zc 29
1043 #define print_num_zc 30
1044 #define random_zc 31
1045 #define push_zc 32
1046 #define pull_zc 33
1047 #define split_window_zc 34
1048 #define set_window_zc 35
1049 #define output_stream_zc 36
1050 #define input_stream_zc 37
1051 #define sound_effect_zc 38
1052 #define jz_zc 39
1053 #define get_sibling_zc 40
1054 #define get_child_zc 41
1055 #define get_parent_zc 42
1056 #define get_prop_len_zc 43
1057 #define inc_zc 44
1058 #define dec_zc 45
1059 #define print_addr_zc 46
1060 #define remove_obj_zc 47
1061 #define print_obj_zc 48
1062 #define ret_zc 49
1063 #define jump_zc 50
1064 #define print_paddr_zc 51
1065 #define load_zc 52
1066 #define not_zc 53
1067 #define rtrue_zc 54
1068 #define rfalse_zc 55
1069 #define print_zc 56
1070 #define print_ret_zc 57
1071 #define nop_zc 58
1072 #define save_zc 59
1073 #define restore_zc 60
1074 #define restart_zc 61
1075 #define ret_popped_zc 62
1076 #define pop_zc 63
1077 #define quit_zc 64
1078 #define new_line_zc 65
1079 #define show_status_zc 66
1080 #define verify_zc 67
1081 #define call_2s_zc 68
1082 #define call_vs_zc 69
1083 #define aread_zc 70
1084 #define call_vs2_zc 71
1085 #define erase_window_zc 72
1086 #define erase_line_zc 73
1087 #define set_cursor_zc 74
1088 #define get_cursor_zc 75
1089 #define set_text_style_zc 76
1090 #define buffer_mode_zc 77
1091 #define read_char_zc 78
1092 #define scan_table_zc 79
1093 #define call_1s_zc 80
1094 #define call_2n_zc 81
1095 #define set_colour_zc 82
1096 #define throw_zc 83
1097 #define call_vn_zc 84
1098 #define call_vn2_zc 85
1099 #define tokenise_zc 86
1100 #define encode_text_zc 87
1101 #define copy_table_zc 88
1102 #define print_table_zc 89
1103 #define check_arg_count_zc 90
1104 #define call_1n_zc 91
1105 #define catch_zc 92
1106 #define piracy_zc 93
1107 #define log_shift_zc 94
1108 #define art_shift_zc 95
1109 #define set_font_zc 96
1110 #define save_undo_zc 97
1111 #define restore_undo_zc 98
1112 #define draw_picture_zc 99
1113 #define picture_data_zc 100
1114 #define erase_picture_zc 101
1115 #define set_margins_zc 102
1116 #define move_window_zc 103
1117 #define window_size_zc 104
1118 #define window_style_zc 105
1119 #define get_wind_prop_zc 106
1120 #define scroll_window_zc 107
1121 #define pop_stack_zc 108
1122 #define read_mouse_zc 109
1123 #define mouse_window_zc 110
1124 #define push_stack_zc 111
1125 #define put_wind_prop_zc 112
1126 #define print_form_zc 113
1127 #define make_menu_zc 114
1128 #define picture_table_zc 115
1129 #define print_unicode_zc 116
1130 #define check_unicode_zc 117
1131
1132
1133 /* ------------------------------------------------------------------------- */
1134 /*   Internal numbers representing assemble-able Glulx opcodes               */
1135 /* ------------------------------------------------------------------------- */
1136
1137 #define nop_gc 0
1138 #define add_gc 1
1139 #define sub_gc 2
1140 #define mul_gc 3
1141 #define div_gc 4
1142 #define mod_gc 5
1143 #define neg_gc 6
1144 #define bitand_gc 7
1145 #define bitor_gc 8
1146 #define bitxor_gc 9
1147 #define bitnot_gc 10
1148 #define shiftl_gc 11
1149 #define sshiftr_gc 12
1150 #define ushiftr_gc 13
1151 #define jump_gc 14
1152 #define jz_gc 15
1153 #define jnz_gc 16
1154 #define jeq_gc 17
1155 #define jne_gc 18
1156 #define jlt_gc 19
1157 #define jge_gc 20
1158 #define jgt_gc 21
1159 #define jle_gc 22
1160 #define jltu_gc 23
1161 #define jgeu_gc 24
1162 #define jgtu_gc 25
1163 #define jleu_gc 26
1164 #define call_gc 27
1165 #define return_gc 28
1166 #define catch_gc 29
1167 #define throw_gc 30
1168 #define tailcall_gc 31
1169 #define copy_gc 32
1170 #define copys_gc 33
1171 #define copyb_gc 34
1172 #define sexs_gc 35
1173 #define sexb_gc 36
1174 #define aload_gc 37
1175 #define aloads_gc 38
1176 #define aloadb_gc 39
1177 #define aloadbit_gc 40
1178 #define astore_gc 41
1179 #define astores_gc 42
1180 #define astoreb_gc 43
1181 #define astorebit_gc 44
1182 #define stkcount_gc 45
1183 #define stkpeek_gc 46
1184 #define stkswap_gc 47
1185 #define stkroll_gc 48
1186 #define stkcopy_gc 49
1187 #define streamchar_gc 50
1188 #define streamnum_gc 51
1189 #define streamstr_gc 52
1190 #define gestalt_gc 53
1191 #define debugtrap_gc 54
1192 #define getmemsize_gc 55
1193 #define setmemsize_gc 56
1194 #define jumpabs_gc 57
1195 #define random_gc 58
1196 #define setrandom_gc 59
1197 #define quit_gc 60
1198 #define verify_gc 61
1199 #define restart_gc 62
1200 #define save_gc 63
1201 #define restore_gc 64
1202 #define saveundo_gc 65
1203 #define restoreundo_gc 66
1204 #define protect_gc 67
1205 #define glk_gc 68
1206 #define getstringtbl_gc 69
1207 #define setstringtbl_gc 70
1208 #define getiosys_gc 71
1209 #define setiosys_gc 72
1210 #define linearsearch_gc 73
1211 #define binarysearch_gc 74
1212 #define linkedsearch_gc 75
1213 #define callf_gc 76
1214 #define callfi_gc 77
1215 #define callfii_gc 78
1216 #define callfiii_gc 79
1217 #define streamunichar_gc 80
1218 #define mzero_gc 81
1219 #define mcopy_gc 82
1220 #define malloc_gc 83
1221 #define mfree_gc 84
1222 #define accelfunc_gc 85
1223 #define accelparam_gc 86
1224 #define numtof_gc 87
1225 #define ftonumz_gc 88
1226 #define ftonumn_gc 89
1227 #define ceil_gc 90
1228 #define floor_gc 91
1229 #define fadd_gc 92
1230 #define fsub_gc 93
1231 #define fmul_gc 94
1232 #define fdiv_gc 95
1233 #define fmod_gc 96
1234 #define sqrt_gc 97
1235 #define exp_gc 98
1236 #define log_gc 99
1237 #define pow_gc 100
1238 #define sin_gc 101
1239 #define cos_gc 102
1240 #define tan_gc 103
1241 #define asin_gc 104
1242 #define acos_gc 105
1243 #define atan_gc 106
1244 #define atan2_gc 107
1245 #define jfeq_gc 108
1246 #define jfne_gc 109
1247 #define jflt_gc 110
1248 #define jfle_gc 111
1249 #define jfgt_gc 112
1250 #define jfge_gc 113
1251 #define jisnan_gc 114
1252 #define jisinf_gc 115
1253
1254 /* ------------------------------------------------------------------------- */
1255 /*   Index numbers into the keyword group "opcode_macros_g" (see "lexer.c")  */
1256 /* ------------------------------------------------------------------------- */
1257
1258 #define pull_gm   0
1259 #define push_gm   1
1260
1261
1262 #define SYMBOL_TT    0                      /* value = index in symbol table */
1263 #define NUMBER_TT    1                      /* value = the number            */
1264 #define DQ_TT        2                      /* no value                      */
1265 #define SQ_TT        3                      /* no value                      */
1266 #define SEP_TT       4                      /* value = the _SEP code         */
1267 #define EOF_TT       5                      /* no value                      */
1268
1269 #define STATEMENT_TT      100               /* a statement keyword           */
1270 #define SEGMENT_MARKER_TT 101               /* with/has/class etc.           */
1271 #define DIRECTIVE_TT      102               /* a directive keyword           */
1272 #define CND_TT            103               /* in/has/etc.                   */
1273 #define SYSFUN_TT         105               /* built-in function             */
1274 #define LOCAL_VARIABLE_TT 106               /* local variable                */
1275 #define OPCODE_NAME_TT    107               /* opcode name                   */
1276 #define MISC_KEYWORD_TT   108               /* keyword like "char" used in
1277                                                syntax for a statement        */
1278 #define DIR_KEYWORD_TT    109               /* keyword like "meta" used in
1279                                                syntax for a directive        */
1280 #define TRACE_KEYWORD_TT  110               /* keyword used in debugging     */
1281 #define SYSTEM_CONSTANT_TT 111              /* such as "code_offset"         */
1282 #define OPCODE_MACRO_TT   112               /* fake opcode for compatibility */
1283
1284 #define OP_TT        200                    /* value = operator no           */
1285 #define ENDEXP_TT    201                    /* no value                      */
1286 #define SUBOPEN_TT   202                    /* ( used for subexpr            */
1287 #define SUBCLOSE_TT  203                    /* ) used to close subexp        */
1288 #define LARGE_NUMBER_TT 204                 /* constant not in range 0-255   */
1289 #define SMALL_NUMBER_TT 205                 /* constant in range 0-255       */
1290 /* In Glulx, that's the range -0x8000 to 0x7fff instead. */
1291 #define VARIABLE_TT  206                    /* variable name                 */
1292 #define DICTWORD_TT  207                    /* literal 'word'                */
1293 #define ACTION_TT    208                    /* action name                   */
1294
1295 #define VOID_CONTEXT       1
1296 #define CONDITION_CONTEXT  2
1297 #define CONSTANT_CONTEXT   3
1298 #define QUANTITY_CONTEXT   4
1299 #define ACTION_Q_CONTEXT   5
1300 #define ASSEMBLY_CONTEXT   6
1301 #define ARRAY_CONTEXT      7
1302 #define FORINIT_CONTEXT    8
1303 #define RETURN_Q_CONTEXT   9
1304
1305 #define LOWEST_SYSTEM_VAR_NUMBER 249        /* globals 249 to 255 are used
1306                                                in compiled code (Z-code 
1307                                                only; in Glulx, the range can
1308                                                change) */
1309
1310 /* ------------------------------------------------------------------------- */
1311 /*   Symbol flag definitions (in no significant order)                       */
1312 /* ------------------------------------------------------------------------- */
1313
1314 #define UNKNOWN_SFLAG  1
1315 #define REPLACE_SFLAG  2
1316 #define USED_SFLAG     4
1317 #define DEFCON_SFLAG   8
1318 #define STUB_SFLAG     16
1319 #define IMPORT_SFLAG   32
1320 #define EXPORT_SFLAG   64
1321 #define ALIASED_SFLAG  128
1322
1323 #define CHANGE_SFLAG   256
1324 #define SYSTEM_SFLAG   512
1325 #define INSF_SFLAG     1024
1326 #define UERROR_SFLAG   2048
1327 #define ACTION_SFLAG   4096
1328 #define REDEFINABLE_SFLAG  8192
1329 #define STAR_SFLAG    16384
1330
1331 /* ------------------------------------------------------------------------- */
1332 /*   Symbol type definitions                                                 */
1333 /* ------------------------------------------------------------------------- */
1334
1335 #define ROUTINE_T             1
1336 #define LABEL_T               2
1337 #define GLOBAL_VARIABLE_T     3
1338 #define ARRAY_T               4
1339 #define CONSTANT_T            5
1340 #define ATTRIBUTE_T           6
1341 #define PROPERTY_T            7
1342 #define INDIVIDUAL_PROPERTY_T 8
1343 #define OBJECT_T              9
1344 #define CLASS_T               10
1345 #define FAKE_ACTION_T         11
1346 #define STATIC_ARRAY_T        12
1347
1348 /* These types never occur in the symbol table; they exist only as
1349    type-checking requirements. */
1350 #define STRING_REQ_T          13
1351 #define DICT_WORD_REQ_T       14
1352
1353 /* ------------------------------------------------------------------------- */
1354 /*   Statusline_flag values                                                  */
1355 /* ------------------------------------------------------------------------- */
1356
1357 #define SCORE_STYLE          0
1358 #define TIME_STYLE           1
1359
1360 /* ------------------------------------------------------------------------- */
1361 /*   Inform keyword definitions                                              */
1362 /* ------------------------------------------------------------------------- */
1363
1364 /*  Index numbers into the keyword group "directives" (see "lexer.c")  */
1365
1366 #define ABBREVIATE_CODE  0
1367 #define ARRAY_CODE       1
1368 #define ATTRIBUTE_CODE   2
1369 #define CLASS_CODE       3
1370 #define CONSTANT_CODE    4
1371 #define DEFAULT_CODE     5
1372 #define DICTIONARY_CODE  6
1373 #define END_CODE         7
1374 #define ENDIF_CODE       8
1375 #define EXTEND_CODE      9
1376 #define FAKE_ACTION_CODE 10
1377 #define GLOBAL_CODE      11
1378 #define IFDEF_CODE       12
1379 #define IFNDEF_CODE      13
1380 #define IFNOT_CODE       14
1381 #define IFV3_CODE        15
1382 #define IFV5_CODE        16
1383 #define IFTRUE_CODE      17
1384 #define IFFALSE_CODE     18
1385 #define IMPORT_CODE      19
1386 #define INCLUDE_CODE     20
1387 #define LINK_CODE        21
1388 #define LOWSTRING_CODE   22
1389 #define MESSAGE_CODE     23
1390 #define NEARBY_CODE      24
1391 #define OBJECT_CODE      25
1392 #define ORIGSOURCE_CODE  26
1393 #define PROPERTY_CODE    27
1394 #define RELEASE_CODE     28
1395 #define REPLACE_CODE     29
1396 #define SERIAL_CODE      30
1397 #define SWITCHES_CODE    31
1398 #define STATUSLINE_CODE  32
1399 #define STUB_CODE        33
1400 #define SYSTEM_CODE      34
1401 #define TRACE_CODE       35
1402 #define UNDEF_CODE       36
1403 #define VERB_CODE        37
1404 #define VERSION_CODE     38
1405 #define ZCHARACTER_CODE  39
1406
1407 #define OPENBLOCK_CODE   100
1408 #define CLOSEBLOCK_CODE  101
1409
1410 /*  Index numbers into the keyword group "statements" (see "lexer.c")  */
1411
1412 #define BOX_CODE         0
1413 #define BREAK_CODE       1
1414 #define CONTINUE_CODE    2
1415 #define SDEFAULT_CODE    3
1416 #define DO_CODE          4
1417 #define ELSE_CODE        5
1418 #define FONT_CODE        6
1419 #define FOR_CODE         7
1420 #define GIVE_CODE        8
1421 #define IF_CODE          9
1422 #define INVERSION_CODE   10
1423 #define JUMP_CODE        11
1424 #define MOVE_CODE        12
1425 #define NEW_LINE_CODE    13
1426 #define OBJECTLOOP_CODE  14
1427 #define PRINT_CODE       15
1428 #define PRINT_RET_CODE   16
1429 #define QUIT_CODE        17
1430 #define READ_CODE        18
1431 #define REMOVE_CODE      19
1432 #define RESTORE_CODE     20
1433 #define RETURN_CODE      21
1434 #define RFALSE_CODE      22
1435 #define RTRUE_CODE       23
1436 #define SAVE_CODE        24
1437 #define SPACES_CODE      25
1438 #define STRING_CODE      26
1439 #define STYLE_CODE       27
1440 #define SWITCH_CODE      28
1441 #define UNTIL_CODE       29
1442 #define WHILE_CODE       30
1443
1444 #define ASSIGNMENT_CODE  100
1445 #define FUNCTION_CODE    101
1446
1447 /*  Index numbers into the keyword group "conditions" (see "lexer.c")  */
1448
1449 #define HAS_COND         0
1450 #define HASNT_COND       1
1451 #define IN_COND          2
1452 #define NOTIN_COND       3
1453 #define OFCLASS_COND     4
1454 #define OR_COND          5
1455 #define PROVIDES_COND    6
1456
1457 /*  Index numbers into the keyword group "segment_markers" (see "lexer.c")  */
1458
1459 #define CLASS_SEGMENT    0
1460 #define HAS_SEGMENT      1
1461 #define PRIVATE_SEGMENT  2
1462 #define WITH_SEGMENT     3
1463
1464 /*  Index numbers into the keyword group "misc_keywords" (see "lexer.c")  */
1465
1466 #define CHAR_MK          0
1467 #define NAME_MK          1
1468 #define THE_MK           2
1469 #define A_MK             3
1470 #define AN_MK            4
1471 #define CAP_THE_MK       5
1472 #define NUMBER_MK        6
1473 #define ROMAN_MK         7
1474 #define REVERSE_MK       8
1475 #define BOLD_MK          9
1476 #define UNDERLINE_MK    10
1477 #define FIXED_MK        11
1478 #define ON_MK           12
1479 #define OFF_MK          13
1480 #define TO_MK           14
1481 #define ADDRESS_MK      15
1482 #define STRING_MK       16
1483 #define OBJECT_MK       17
1484 #define NEAR_MK         18
1485 #define FROM_MK         19
1486 #define PROPERTY_MK     20
1487 #define CAP_A_MK        21
1488
1489 /*  Index numbers into the keyword group "directive_keywords" (see "lexer.c")  */
1490
1491 #define ALIAS_DK         0
1492 #define LONG_DK          1
1493 #define ADDITIVE_DK      2
1494 #define SCORE_DK         3
1495 #define TIME_DK          4
1496 #define NOUN_DK          5
1497 #define HELD_DK          6
1498 #define MULTI_DK         7
1499 #define MULTIHELD_DK     8
1500 #define MULTIEXCEPT_DK   9
1501 #define MULTIINSIDE_DK  10
1502 #define CREATURE_DK     11
1503 #define SPECIAL_DK      12
1504 #define NUMBER_DK       13
1505 #define SCOPE_DK        14
1506 #define TOPIC_DK        15
1507 #define REVERSE_DK      16
1508 #define META_DK         17
1509 #define ONLY_DK         18
1510 #define REPLACE_DK      19
1511 #define FIRST_DK        20
1512 #define LAST_DK         21
1513 #define STRING_DK       22
1514 #define TABLE_DK        23
1515 #define BUFFER_DK       24
1516 #define DATA_DK         25
1517 #define INITIAL_DK      26
1518 #define INITSTR_DK      27
1519 #define WITH_DK         28
1520 #define PRIVATE_DK      29
1521 #define HAS_DK          30
1522 #define CLASS_DK        31
1523 #define ERROR_DK        32
1524 #define FATALERROR_DK   33
1525 #define WARNING_DK      34
1526 #define TERMINATING_DK  35
1527 #define STATIC_DK       36
1528 #define INDIVIDUAL_DK   37
1529
1530 /*  Index numbers into the keyword group "trace_keywords" (see "lexer.c")  */
1531
1532 #define DICTIONARY_TK    0
1533 #define SYMBOLS_TK       1
1534 #define OBJECTS_TK       2
1535 #define VERBS_TK         3
1536 #define ASSEMBLY_TK      4
1537 #define EXPRESSIONS_TK   5
1538 #define LINES_TK         6
1539 #define TOKENS_TK        7
1540 #define LINKER_TK        8
1541 #define ON_TK            9
1542 #define OFF_TK          10
1543
1544 /*  Index numbers into the keyword group "system_constants" (see "lexer.c")  */
1545
1546 #define NO_SYSTEM_CONSTANTS   62
1547
1548 #define adjectives_table_SC   0
1549 #define actions_table_SC      1
1550 #define classes_table_SC      2
1551 #define identifiers_table_SC  3
1552 #define preactions_table_SC   4
1553 #define version_number_SC     5
1554 #define largest_object_SC     6
1555 #define strings_offset_SC     7
1556 #define code_offset_SC        8
1557 #define dict_par1_SC          9
1558 #define dict_par2_SC         10
1559 #define dict_par3_SC         11
1560 #define actual_largest_object_SC 12
1561 #define static_memory_offset_SC 13
1562 #define array_names_offset_SC 14
1563 #define readable_memory_offset_SC 15
1564 #define cpv__start_SC        16
1565 #define cpv__end_SC          17
1566 #define ipv__start_SC        18
1567 #define ipv__end_SC          19
1568 #define array__start_SC      20
1569 #define array__end_SC        21
1570
1571 #define lowest_attribute_number_SC    22
1572 #define highest_attribute_number_SC   23
1573 #define attribute_names_array_SC      24
1574
1575 #define lowest_property_number_SC     25
1576 #define highest_property_number_SC    26
1577 #define property_names_array_SC       27
1578
1579 #define lowest_action_number_SC       28
1580 #define highest_action_number_SC      29
1581 #define action_names_array_SC         30
1582
1583 #define lowest_fake_action_number_SC  31
1584 #define highest_fake_action_number_SC 32
1585 #define fake_action_names_array_SC    33
1586
1587 #define lowest_routine_number_SC      34
1588 #define highest_routine_number_SC     35
1589 #define routines_array_SC             36
1590 #define routine_names_array_SC        37
1591 #define routine_flags_array_SC        38
1592
1593 #define lowest_global_number_SC       39
1594 #define highest_global_number_SC      40
1595 #define globals_array_SC              41
1596 #define global_names_array_SC         42
1597 #define global_flags_array_SC         43
1598
1599 #define lowest_array_number_SC        44
1600 #define highest_array_number_SC       45
1601 #define arrays_array_SC               46
1602 #define array_names_array_SC          47
1603 #define array_flags_array_SC          48
1604
1605 #define lowest_constant_number_SC     49
1606 #define highest_constant_number_SC    50
1607 #define constants_array_SC            51
1608 #define constant_names_array_SC       52
1609
1610 #define lowest_class_number_SC        53
1611 #define highest_class_number_SC       54
1612 #define class_objects_array_SC        55
1613
1614 #define lowest_object_number_SC       56
1615 #define highest_object_number_SC      57
1616
1617 #define oddeven_packing_SC            58
1618
1619 #define grammar_table_SC              59
1620 #define dictionary_table_SC           60
1621 #define dynam_string_table_SC         61     /* Glulx-only */
1622
1623
1624 /*  Index numbers into the keyword group "system_functions" (see "lexer.c")  */
1625
1626 #define NUMBER_SYSTEM_FUNCTIONS 12
1627
1628 #define CHILD_SYSF       0
1629 #define CHILDREN_SYSF    1
1630 #define ELDER_SYSF       2
1631 #define ELDEST_SYSF      3
1632 #define INDIRECT_SYSF    4
1633 #define PARENT_SYSF      5
1634 #define RANDOM_SYSF      6
1635 #define SIBLING_SYSF     7
1636 #define YOUNGER_SYSF     8
1637 #define YOUNGEST_SYSF    9
1638 #define METACLASS_SYSF  10
1639 #define GLK_SYSF        11     /* Glulx-only */
1640
1641 /*  Index numbers into the operators group "separators" (see "lexer.c")  */
1642
1643 #define NUMBER_SEPARATORS 49
1644
1645 #define ARROW_SEP        0
1646 #define DARROW_SEP       1
1647 #define DEC_SEP          2
1648 #define MINUS_SEP        3
1649 #define INC_SEP          4
1650 #define PLUS_SEP         5
1651 #define TIMES_SEP        6
1652 #define DIVIDE_SEP       7
1653 #define REMAINDER_SEP    8
1654 #define LOGOR_SEP        9
1655 #define ARTOR_SEP       10
1656 #define LOGAND_SEP      11
1657 #define ARTAND_SEP      12
1658 #define LOGNOT_SEP      13
1659 #define NOTEQUAL_SEP    14
1660 #define ARTNOT_SEP      15
1661 #define CONDEQUALS_SEP  16
1662 #define SETEQUALS_SEP   17
1663 #define GE_SEP          18
1664 #define GREATER_SEP     19
1665 #define LE_SEP          20
1666 #define LESS_SEP        21
1667 #define OPENB_SEP       22
1668 #define CLOSEB_SEP      23
1669 #define COMMA_SEP       24
1670 #define PROPADD_SEP     25
1671 #define PROPNUM_SEP     26
1672 #define MPROPADD_SEP    27
1673 #define MPROPNUM_SEP    28
1674 #define MESSAGE_SEP     29
1675 #define PROPERTY_SEP    30
1676 #define SUPERCLASS_SEP  31
1677 #define COLON_SEP       32
1678 #define AT_SEP          33
1679 #define SEMICOLON_SEP   34
1680 #define OPEN_SQUARE_SEP 35
1681 #define CLOSE_SQUARE_SEP 36
1682 #define OPEN_BRACE_SEP  37
1683 #define CLOSE_BRACE_SEP 38
1684 #define DOLLAR_SEP      39
1685 #define NBRANCH_SEP     40
1686 #define BRANCH_SEP      41
1687 #define HASHADOLLAR_SEP 42
1688 #define HASHGDOLLAR_SEP 43
1689 #define HASHNDOLLAR_SEP 44
1690 #define HASHRDOLLAR_SEP 45
1691 #define HASHWDOLLAR_SEP 46
1692 #define HASHHASH_SEP    47
1693 #define HASH_SEP        48
1694
1695 #define UNARY_MINUS_SEP 100
1696 #define POST_INC_SEP    101
1697 #define POST_DEC_SEP    102
1698
1699 /* ------------------------------------------------------------------------- */
1700 /*   Internal numbers used to refer to operators (in expressions)            */
1701 /*   (must correspond to entries in the operators table in "express.c")      */
1702 /* ------------------------------------------------------------------------- */
1703
1704 #define NUM_OPERATORS 68
1705
1706 #define PRE_U          1
1707 #define IN_U           2
1708 #define POST_U         3
1709
1710 #define R_A            1
1711 #define L_A            2
1712
1713 #define COMMA_OP       0
1714 #define SETEQUALS_OP   1
1715 #define LOGAND_OP      2
1716 #define LOGOR_OP       3
1717 #define LOGNOT_OP      4
1718
1719 #define ZERO_OP        5
1720 #define NONZERO_OP     6
1721 #define CONDEQUALS_OP  7
1722 #define NOTEQUAL_OP    8
1723 #define GE_OP          9
1724 #define GREATER_OP    10
1725 #define LE_OP         11
1726 #define LESS_OP       12
1727 #define HAS_OP        13
1728 #define HASNT_OP      14
1729 #define IN_OP         15
1730 #define NOTIN_OP      16
1731 #define OFCLASS_OP    17
1732 #define PROVIDES_OP   18
1733 #define NOTOFCLASS_OP  19
1734 #define NOTPROVIDES_OP 20
1735 #define OR_OP         21
1736
1737 #define PLUS_OP       22
1738 #define MINUS_OP      23
1739 #define TIMES_OP      24
1740 #define DIVIDE_OP     25
1741 #define REMAINDER_OP  26
1742 #define ARTAND_OP     27
1743 #define ARTOR_OP      28
1744 #define ARTNOT_OP     29
1745 #define ARROW_OP      30
1746 #define DARROW_OP     31
1747 #define UNARY_MINUS_OP 32
1748 #define INC_OP        33
1749 #define POST_INC_OP   34
1750 #define DEC_OP        35
1751 #define POST_DEC_OP   36
1752 #define PROP_ADD_OP   37
1753 #define PROP_NUM_OP   38
1754 #define MPROP_ADD_OP  39
1755 #define MPROP_NUM_OP  40
1756 #define FCALL_OP      41
1757 #define MESSAGE_OP    42
1758 #define PROPERTY_OP   43
1759 #define SUPERCLASS_OP 44
1760
1761 #define ARROW_SETEQUALS_OP   45
1762 #define DARROW_SETEQUALS_OP  46
1763 #define MESSAGE_SETEQUALS_OP 47
1764 #define PROPERTY_SETEQUALS_OP 48
1765
1766 #define ARROW_INC_OP   49
1767 #define DARROW_INC_OP  50
1768 #define MESSAGE_INC_OP 51
1769 #define PROPERTY_INC_OP 52
1770
1771 #define ARROW_DEC_OP   53
1772 #define DARROW_DEC_OP  54
1773 #define MESSAGE_DEC_OP 55
1774 #define PROPERTY_DEC_OP 56
1775
1776 #define ARROW_POST_INC_OP   57
1777 #define DARROW_POST_INC_OP  58
1778 #define MESSAGE_POST_INC_OP 59
1779 #define PROPERTY_POST_INC_OP 60
1780
1781 #define ARROW_POST_DEC_OP   61
1782 #define DARROW_POST_DEC_OP  62
1783 #define MESSAGE_POST_DEC_OP 63
1784 #define PROPERTY_POST_DEC_OP 64
1785
1786 #define PROP_CALL_OP 65
1787 #define MESSAGE_CALL_OP 66
1788
1789 #define PUSH_OP 67 /* Glulx only */
1790
1791 /* ------------------------------------------------------------------------- */
1792 /*   The five types of compiled array                                        */
1793 /* ------------------------------------------------------------------------- */
1794
1795 #define BYTE_ARRAY      0
1796 #define WORD_ARRAY      1
1797 #define STRING_ARRAY    2
1798 #define TABLE_ARRAY     3
1799 #define BUFFER_ARRAY    4
1800
1801 /* ------------------------------------------------------------------------- */
1802 /*   Internal numbers used to refer to veneer routines                       */
1803 /*   (must correspond to entries in the table in "veneer.c")                 */
1804 /* ------------------------------------------------------------------------- */
1805
1806 #define VENEER_ROUTINES 48
1807
1808 #define Box__Routine_VR    0
1809
1810 #define R_Process_VR       1
1811 #define DefArt_VR          2
1812 #define InDefArt_VR        3
1813 #define CDefArt_VR         4
1814 #define CInDefArt_VR       5
1815 #define PrintShortName_VR  6
1816 #define EnglishNumber_VR   7
1817 #define Print__Pname_VR    8
1818
1819 #define WV__Pr_VR          9
1820 #define RV__Pr_VR         10
1821 #define CA__Pr_VR         11
1822 #define IB__Pr_VR         12
1823 #define IA__Pr_VR         13
1824 #define DB__Pr_VR         14
1825 #define DA__Pr_VR         15
1826 #define RA__Pr_VR         16
1827 #define RL__Pr_VR         17
1828 #define RA__Sc_VR         18
1829 #define OP__Pr_VR         19
1830 #define OC__Cl_VR         20
1831
1832 #define Copy__Primitive_VR 21
1833 #define RT__Err_VR         22
1834 #define Z__Region_VR       23
1835 #define Unsigned__Compare_VR 24
1836 #define Metaclass_VR      25
1837 #define CP__Tab_VR        26
1838 #define Cl__Ms_VR         27
1839 #define RT__ChT_VR        28
1840 #define RT__ChR_VR        29
1841 #define RT__ChG_VR        30
1842 #define RT__ChGt_VR       31
1843 #define RT__ChPS_VR       32
1844 #define RT__ChPR_VR       33 
1845 #define RT__TrPS_VR       34
1846 #define RT__ChLDB_VR      35
1847 #define RT__ChLDW_VR      36
1848 #define RT__ChSTB_VR      37
1849 #define RT__ChSTW_VR      38
1850 #define RT__ChPrintC_VR   39
1851 #define RT__ChPrintA_VR   40
1852 #define RT__ChPrintS_VR   41
1853 #define RT__ChPrintO_VR   42
1854
1855 /* Glulx-only veneer routines */
1856 #define OB__Move_VR       43
1857 #define OB__Remove_VR     44
1858 #define Print__Addr_VR    45
1859 #define Glk__Wrap_VR      46
1860 #define Dynam__String_VR  47
1861
1862 /* ------------------------------------------------------------------------- */
1863 /*   Run-time-error numbers (must correspond with RT__Err code in veneer)    */
1864 /* ------------------------------------------------------------------------- */
1865
1866 #define IN_RTE             2
1867 #define HAS_RTE            3
1868 #define PARENT_RTE         4
1869 #define ELDEST_RTE         5
1870 #define CHILD_RTE          6
1871 #define YOUNGER_RTE        7
1872 #define SIBLING_RTE        8
1873 #define CHILDREN_RTE       9
1874 #define YOUNGEST_RTE      10
1875 #define ELDER_RTE         11
1876 #define OBJECTLOOP_RTE    12
1877 #define OBJECTLOOP2_RTE   13
1878 #define GIVE_RTE          14
1879 #define REMOVE_RTE        15
1880 #define MOVE1_RTE         16
1881 #define MOVE2_RTE         17
1882 /* 18 = creating a loop in object tree */
1883 /* 19 = giving a non-existent attribute */
1884 #define DBYZERO_RTE       20
1885 #define PROP_ADD_RTE      21
1886 #define PROP_NUM_RTE      22
1887 #define PROPERTY_RTE      23
1888 /* 24 = reading with -> out of range */
1889 /* 25 = reading with --> out of range */
1890 /* 26 = writing with -> out of range */
1891 /* 27 = writing with --> out of range */
1892 #define ABOUNDS_RTE       28
1893 /* similarly 29, 30, 31 */
1894 #define OBJECTLOOP_BROKEN_RTE 32
1895 /* 33 = print (char) out of range */
1896 /* 34 = print (address) out of range */
1897 /* 35 = print (string) out of range */
1898 /* 36 = print (object) out of range */
1899
1900 /* ------------------------------------------------------------------------- */
1901 /*   Z-region areas (used to refer to module positions in markers)           */
1902 /* ------------------------------------------------------------------------- */
1903
1904 #define LOW_STRINGS_ZA         1
1905 #define PROP_DEFAULTS_ZA       2
1906 #define OBJECT_TREE_ZA         3
1907 #define PROP_ZA                4
1908 #define CLASS_NUMBERS_ZA       5
1909 #define INDIVIDUAL_PROP_ZA     6
1910 #define DYNAMIC_ARRAY_ZA       7
1911 #define GRAMMAR_ZA             8
1912 #define ACTIONS_ZA             9
1913 #define PREACTIONS_ZA         10
1914 #define ADJECTIVES_ZA         11
1915 #define DICTIONARY_ZA         12
1916 #define ZCODE_ZA              13
1917 #define STATIC_STRINGS_ZA     14
1918 #define LINK_DATA_ZA          15
1919
1920 #define SYMBOLS_ZA            16
1921 #define STATIC_ARRAY_ZA       17 /* Z-code only */
1922 #define GLOBALVAR_ZA          18 /* Glulx only */
1923
1924 /* ------------------------------------------------------------------------- */
1925 /*   "Marker values", used for backpatching and linkage                      */
1926 /* ------------------------------------------------------------------------- */
1927
1928 #define NULL_MV                0     /* Null */
1929
1930 /* Marker values used in backpatch areas: */
1931
1932 #define DWORD_MV               1     /* Dictionary word address */
1933 #define STRING_MV              2     /* Static string */
1934 #define INCON_MV               3     /* "Hardware" constant (table address) */
1935 #define IROUTINE_MV            4     /* Call to internal routine */
1936 #define VROUTINE_MV            5     /* Call to veneer routine */
1937 #define ARRAY_MV               6     /* Ref to internal dynam array address */
1938 #define NO_OBJS_MV             7     /* Ref to number of game objects */
1939 #define INHERIT_MV             8     /* Inherited property value */
1940 #define INHERIT_INDIV_MV       9     /* Inherited indiv property value */
1941 #define MAIN_MV               10     /* "Main" routine */
1942 #define SYMBOL_MV             11     /* Forward ref to unassigned symbol */
1943
1944 /* Additional marker values used in module backpatch areas: */
1945 /* (In Glulx, OBJECT_MV and VARIABLE_MV are used in backpatching, even
1946    without modules.) */
1947
1948 #define VARIABLE_MV           12     /* Global variable */
1949 #define IDENT_MV              13     /* Property identifier number */
1950 #define INDIVPT_MV            14     /* Individual prop table address */
1951 #define ACTION_MV             15     /* Action number */
1952 #define OBJECT_MV             16     /* Ref to internal object number */
1953 #define STATIC_ARRAY_MV       17     /* Ref to internal static array address */
1954
1955 #define LARGEST_BPATCH_MV     17     /* Larger marker values are never written
1956                                         to backpatch tables */
1957
1958 /* Value indicating an imported symbol record: */
1959
1960 #define IMPORT_MV             32
1961
1962 /* Values indicating an exported symbol record: */
1963
1964 #define EXPORT_MV             33     /* Defined ordinarily */
1965 #define EXPORTSF_MV           34     /* Defined in a system file */
1966 #define EXPORTAC_MV           35     /* Action name */
1967
1968 /* Values used only in branch backpatching: */
1969 /* ###-I've rearranged these, so that BRANCH_MV can be last; Glulx uses the
1970    whole range from BRANCH_MV to BRANCHMAX_MV. */
1971
1972 #define LABEL_MV              36     /* Ditto: marks "jump" operands */
1973 #define DELETED_MV            37     /* Ditto: marks bytes deleted from code */
1974 #define BRANCH_MV             38     /* Used in "asm.c" for routine coding */
1975 #define BRANCHMAX_MV          58     /* In fact, the range BRANCH_MV to 
1976                                         BRANCHMAX_MV all means the same thing.
1977                                         The position within the range means
1978                                         how far back from the label to go
1979                                         to find the opmode byte to modify. */
1980
1981 /* ------------------------------------------------------------------------- */
1982 /*   "String contexts"; the purpose for a given string. This info gets       */
1983 /*   written to the transcript file (gametext.txt).                          */
1984 /* ------------------------------------------------------------------------- */
1985
1986 #define STRCTX_INFO      0  /* comment; not stored in game file */
1987 #define STRCTX_GAME      1  /* strings area */
1988 #define STRCTX_GAMEOPC   2  /* inline text in opcode (Z-code only) */
1989 #define STRCTX_VENEER    3  /* strings area, from veneer code */
1990 #define STRCTX_VENEEROPC 4  /* inline text, veneer code (Z-code only) */
1991 #define STRCTX_LOWSTRING 5  /* lowmem (Z-code); also dynamic-str literals */
1992 #define STRCTX_ABBREV    6  /* abbreviation */
1993 #define STRCTX_DICT      7  /* dictionary word */
1994 #define STRCTX_OBJNAME   8  /* object "hardware name" */
1995 #define STRCTX_SYMBOL    9  /* prop/attr/etc names */
1996 #define STRCTX_INFIX    10  /* text printed in asterisk traces */
1997
1998 /* ------------------------------------------------------------------------- */
1999 /*   Bit-flags applying to the execution_never_reaches_here variable.        */
2000 /*   Note that if any flags are set, UNREACHABLE is set, so we can easily    */
2001 /*   test "if (execution_never_reaches_here)..."                             */
2002 /* ------------------------------------------------------------------------- */
2003
2004 #define EXECSTATE_REACHABLE   0  /* compile normally */
2005 #define EXECSTATE_UNREACHABLE 1  /* execution cannot reach this line */
2006 #define EXECSTATE_ENTIRE      2  /* execution cannot reach this entire
2007                                     statement or code block */
2008 #define EXECSTATE_NOWARN      4  /* do not print a warning about unreachable
2009                                     code */
2010
2011 /* ========================================================================= */
2012 /*   Initialisation extern definitions                                       */
2013 /*                                                                           */
2014 /*   Note that each subsystem in Inform provides four routines to keep       */
2015 /*   track of variables and data structures:                                 */
2016 /*                                                                           */
2017 /*       init_*_vars      should set variables to initial values (they must  */
2018 /*                        not be initialised directly in their declarations  */
2019 /*                        as Inform may need to compile several times in a   */
2020 /*                        row)                                               */
2021 /*                                                                           */
2022 /*       *_begin_pass     any variable/array initialisation that needs to    */
2023 /*                        happen at the start of the pass through the source */
2024 /*                                                                           */
2025 /*       *_allocate_arrays   should use my_malloc/my_calloc (see memory.c)   */
2026 /*                        to allocate any arrays or workspace needed         */
2027 /*                                                                           */
2028 /*       *_free_arrays    should use my_free to free all memory allocated    */
2029 /*                        (with one exception in "text.c")                   */
2030 /*                                                                           */
2031 /* ========================================================================= */
2032
2033                                       /* > READ INFORM SOURCE                */
2034
2035                                       /* My Source Book                      */
2036
2037 extern void init_arrays_vars(void);   /* arrays: construct tableaux          */
2038 extern void init_asm_vars(void);      /* asm: assemble even rare or v6 codes */
2039 extern void init_bpatch_vars(void);   /* bpatch: backpatches code            */
2040 extern void init_chars_vars(void);    /* chars: translate character sets     */
2041 extern void init_directs_vars(void);  /* directs: ponder directives          */
2042 extern void init_errors_vars(void);   /* errors: issue diagnostics           */
2043 extern void init_expressc_vars(void); /* expressc: compile expressions       */
2044 extern void init_expressp_vars(void); /* expressp: parse expressions         */
2045 extern void init_files_vars(void);    /* files: handle files                 */
2046     /* void init_vars(void);             inform: decide what to do           */
2047 extern void init_lexer_vars(void);    /* lexer: lexically analyse source     */
2048 extern void init_linker_vars(void);   /* linker: link in pre-compiled module */
2049 extern void init_memory_vars(void);   /* memory: manage memory settings      */
2050 extern void init_objects_vars(void);  /* objects: cultivate object tree      */
2051 extern void init_states_vars(void);   /* states: translate statements to code*/
2052 extern void init_symbols_vars(void);  /* symbols: construct symbols table    */
2053 extern void init_syntax_vars(void);   /* syntax: parse the program           */
2054 extern void init_tables_vars(void);   /* tables: glue tables into the output */
2055 extern void init_text_vars(void);     /* text: encode text and dictionary    */
2056 extern void init_veneer_vars(void);   /* veneer: compile a layer of code     */
2057 extern void init_verbs_vars(void);    /* verbs: lay out grammar              */
2058
2059 extern void files_begin_prepass(void);  /*  These routines initialise just   */
2060 extern void lexer_begin_prepass(void);  /*  enough to begin loading source   */
2061
2062 extern void arrays_begin_pass(void);
2063 extern void asm_begin_pass(void);
2064 extern void bpatch_begin_pass(void);
2065 extern void chars_begin_pass(void);
2066 extern void directs_begin_pass(void);
2067 extern void errors_begin_pass(void);
2068 extern void expressc_begin_pass(void);
2069 extern void expressp_begin_pass(void);
2070 extern void files_begin_pass(void);
2071     /* void begin_pass(void); */
2072 extern void lexer_begin_pass(void);
2073 extern void linker_begin_pass(void);
2074 extern void memory_begin_pass(void);
2075 extern void objects_begin_pass(void);
2076 extern void states_begin_pass(void);
2077 extern void symbols_begin_pass(void);
2078 extern void syntax_begin_pass(void);
2079 extern void tables_begin_pass(void);
2080 extern void text_begin_pass(void);
2081 extern void veneer_begin_pass(void);
2082 extern void verbs_begin_pass(void);
2083
2084 extern void lexer_endpass(void);
2085 extern void linker_endpass(void);
2086
2087 extern void arrays_allocate_arrays(void);
2088 extern void asm_allocate_arrays(void);
2089 extern void bpatch_allocate_arrays(void);
2090 extern void chars_allocate_arrays(void);
2091 extern void directs_allocate_arrays(void);
2092 extern void errors_allocate_arrays(void);
2093 extern void expressc_allocate_arrays(void);
2094 extern void expressp_allocate_arrays(void);
2095 extern void files_allocate_arrays(void);
2096     /* void allocate_arrays(void); */
2097 extern void lexer_allocate_arrays(void);
2098 extern void linker_allocate_arrays(void);
2099 extern void memory_allocate_arrays(void);
2100 extern void objects_allocate_arrays(void);
2101 extern void states_allocate_arrays(void);
2102 extern void symbols_allocate_arrays(void);
2103 extern void syntax_allocate_arrays(void);
2104 extern void tables_allocate_arrays(void);
2105 extern void text_allocate_arrays(void);
2106 extern void veneer_allocate_arrays(void);
2107 extern void verbs_allocate_arrays(void);
2108
2109 extern void arrays_free_arrays(void);
2110 extern void asm_free_arrays(void);
2111 extern void bpatch_free_arrays(void);
2112 extern void chars_free_arrays(void);
2113 extern void directs_free_arrays(void);
2114 extern void errors_free_arrays(void);
2115 extern void expressc_free_arrays(void);
2116 extern void expressp_free_arrays(void);
2117 extern void files_free_arrays(void);
2118     /* void free_arrays(void); */
2119 extern void lexer_free_arrays(void);
2120 extern void linker_free_arrays(void);
2121 extern void memory_free_arrays(void);
2122 extern void objects_free_arrays(void);
2123 extern void states_free_arrays(void);
2124 extern void symbols_free_arrays(void);
2125 extern void syntax_free_arrays(void);
2126 extern void tables_free_arrays(void);
2127 extern void text_free_arrays(void);
2128 extern void veneer_free_arrays(void);
2129 extern void verbs_free_arrays(void);
2130
2131 /* ========================================================================= */
2132 /*   Remaining extern definitions are given by file in alphabetical order    */
2133 /* ------------------------------------------------------------------------- */
2134 /*   Extern definitions for "arrays"                                         */
2135 /* ------------------------------------------------------------------------- */
2136
2137 #define MAX_ZCODE_GLOBAL_VARS (240)
2138
2139 extern int no_globals, no_arrays;
2140 extern int dynamic_array_area_size;
2141 extern uchar *dynamic_array_area;
2142 extern memory_list dynamic_array_area_memlist;
2143 extern int static_array_area_size;
2144 extern uchar *static_array_area;
2145 extern memory_list static_array_area_memlist;
2146 extern int32 *global_initial_value;
2147 extern arrayinfo *arrays;
2148
2149 extern void make_global(int array_flag, int name_only);
2150 extern void set_variable_value(int i, int32 v);
2151 extern void check_globals(void);
2152 extern int32 begin_table_array(void);
2153 extern int32 begin_word_array(void);
2154 extern void array_entry(int32 i, int is_static, assembly_operand VAL);
2155 extern void finish_array(int32 i, int is_static);
2156
2157 /* ------------------------------------------------------------------------- */
2158 /*   Extern definitions for "asm"                                            */
2159 /* ------------------------------------------------------------------------- */
2160
2161 extern uchar *zcode_area;
2162 extern memory_list zcode_area_memlist;
2163 extern int32 zmachine_pc;
2164
2165 extern int32 no_instructions;
2166 extern int   sequence_point_follows;
2167 extern int   uses_unicode_features, uses_memheap_features, 
2168     uses_acceleration_features, uses_float_features,
2169     uses_extundo_features;
2170 extern debug_location statement_debug_location;
2171 extern int   execution_never_reaches_here;
2172 extern variableinfo *variables;
2173 extern memory_list variables_memlist;
2174 extern int   next_label, no_sequence_points;
2175 extern assembly_instruction AI;
2176 extern int32 *named_routine_symbols;
2177
2178 extern void print_operand(const assembly_operand *o, int annotate);
2179 extern char *variable_name(int32 i);
2180 extern void set_constant_ot(assembly_operand *AO);
2181 extern int  is_constant_ot(int otval);
2182 extern int  is_variable_ot(int otval);
2183 extern void assemblez_instruction(const assembly_instruction *a);
2184 extern void assembleg_instruction(const assembly_instruction *a);
2185 extern void assemble_label_no(int n);
2186 extern int assemble_forward_label_no(int n);
2187 extern void assemble_jump(int n);
2188 extern void define_symbol_label(int symbol);
2189 extern int32 assemble_routine_header(int no_locals, int debug_flag,
2190     char *name, int embedded_flag, int the_symbol);
2191 extern void assemble_routine_end(int embedded_flag, debug_locations locations);
2192
2193 extern void assemblez_0(int internal_number);
2194 extern void assemblez_0_to(int internal_number, assembly_operand o1);
2195 extern void assemblez_0_branch(int internal_number, int label, int flag);
2196 extern void assemblez_1(int internal_number, assembly_operand o1);
2197 extern void assemblez_1_to(int internal_number,
2198                        assembly_operand o1, assembly_operand st);
2199 extern void assemblez_1_branch(int internal_number,
2200                        assembly_operand o1, int label, int flag);
2201 extern void assemblez_objcode(int internal_number,
2202                        assembly_operand o1, assembly_operand st,
2203                        int label, int flag);
2204 extern void assemblez_2(int internal_number,
2205                        assembly_operand o1, assembly_operand o2);
2206 extern void assemblez_2_to(int internal_number,
2207                        assembly_operand o1, assembly_operand o2,
2208                        assembly_operand st);
2209 extern void assemblez_2_branch(int internal_number,
2210                        assembly_operand o1, assembly_operand o2,
2211                        int label, int flag);
2212 extern void assemblez_3(int internal_number,
2213                        assembly_operand o1, assembly_operand o2,
2214                        assembly_operand o3);
2215 extern void assemblez_3_branch(int internal_number,
2216                        assembly_operand o1, assembly_operand o2,
2217                        assembly_operand o3, int label, int flag);
2218 extern void assemblez_3_to(int internal_number,
2219                        assembly_operand o1, assembly_operand o2,
2220                        assembly_operand o3, assembly_operand st);
2221 extern void assemblez_4(int internal_number,
2222                        assembly_operand o1, assembly_operand o2,
2223                        assembly_operand o3, assembly_operand o4);
2224 extern void assemblez_5(int internal_number,
2225                        assembly_operand o1, assembly_operand o2,
2226                        assembly_operand o3, assembly_operand o4,
2227                        assembly_operand o5);
2228 extern void assemblez_6(int internal_number,
2229                        assembly_operand o1, assembly_operand o2,
2230                        assembly_operand o3, assembly_operand o4,
2231                        assembly_operand o5, assembly_operand o6);
2232 extern void assemblez_4_branch(int internal_number,
2233                        assembly_operand o1, assembly_operand o2,
2234                        assembly_operand o3, assembly_operand o4,
2235                        int label, int flag);
2236 extern void assemblez_4_to(int internal_number,
2237                        assembly_operand o1, assembly_operand o2,
2238                        assembly_operand o3, assembly_operand o4,
2239                        assembly_operand st);
2240 extern void assemblez_5_to(int internal_number,
2241                        assembly_operand o1, assembly_operand o2,
2242                        assembly_operand o3, assembly_operand o4,
2243                        assembly_operand o5, assembly_operand st);
2244
2245 extern void assemblez_inc(assembly_operand o1);
2246 extern void assemblez_dec(assembly_operand o1);
2247 extern void assemblez_store(assembly_operand o1, assembly_operand o2);
2248 extern void assemblez_jump(int n);
2249
2250 extern void assembleg_0(int internal_number);
2251 extern void assembleg_1(int internal_number, assembly_operand o1);
2252 extern void assembleg_2(int internal_number, assembly_operand o1,
2253   assembly_operand o2);
2254 extern void assembleg_3(int internal_number, assembly_operand o1,
2255   assembly_operand o2, assembly_operand o3);
2256 extern void assembleg_4(int internal_number, assembly_operand o1,
2257   assembly_operand o2, assembly_operand o3, assembly_operand o4);
2258 extern void assembleg_5(int internal_number, assembly_operand o1,
2259   assembly_operand o2, assembly_operand o3, assembly_operand o4,
2260   assembly_operand o5);
2261 extern void assembleg_0_branch(int internal_number,
2262   int label);
2263 extern void assembleg_1_branch(int internal_number,
2264   assembly_operand o1, int label);
2265 extern void assembleg_2_branch(int internal_number,
2266   assembly_operand o1, assembly_operand o2, int label);
2267 extern void assembleg_call_1(assembly_operand oaddr, assembly_operand o1, 
2268   assembly_operand odest);
2269 extern void assembleg_call_2(assembly_operand oaddr, assembly_operand o1, 
2270   assembly_operand o2, assembly_operand odest);
2271 extern void assembleg_call_3(assembly_operand oaddr, assembly_operand o1, 
2272   assembly_operand o2, assembly_operand o3, assembly_operand odest);
2273 extern void assembleg_inc(assembly_operand o1);
2274 extern void assembleg_dec(assembly_operand o1);
2275 extern void assembleg_store(assembly_operand o1, assembly_operand o2);
2276 extern void assembleg_jump(int n);
2277
2278 extern void parse_assembly(void);
2279
2280 /* ------------------------------------------------------------------------- */
2281 /*   Extern definitions for "bpatch"                                         */
2282 /* ------------------------------------------------------------------------- */
2283
2284 extern uchar *staticarray_backpatch_table;
2285 extern memory_list staticarray_backpatch_table_memlist;
2286 extern uchar *zmachine_backpatch_table;
2287 extern memory_list zmachine_backpatch_table_memlist;
2288 extern uchar *zcode_backpatch_table;
2289 extern memory_list zcode_backpatch_table_memlist;
2290 extern int32 zcode_backpatch_size, staticarray_backpatch_size,
2291     zmachine_backpatch_size;
2292 extern int   backpatch_marker, backpatch_error_flag;
2293
2294 extern int32 backpatch_value(int32 value);
2295 extern void  backpatch_zmachine_image_z(void);
2296 extern void  backpatch_zmachine_image_g(void);
2297 extern void  backpatch_zmachine(int mv, int zmachine_area, int32 offset);
2298
2299 /* ------------------------------------------------------------------------- */
2300 /*   Extern definitions for "chars"                                          */
2301 /* ------------------------------------------------------------------------- */
2302
2303 extern uchar source_to_iso_grid[];
2304 extern int32 iso_to_unicode_grid[];
2305 extern int   character_digit_value[];
2306 extern uchar alphabet[3][27];
2307 extern int   alphabet_modified;
2308 extern int   zscii_defn_modified;
2309 extern int   zscii_high_water_mark;
2310 extern char  alphabet_used[];
2311 extern int   iso_to_alphabet_grid[];
2312 extern int   zscii_to_alphabet_grid[];
2313 extern int   textual_form_length;
2314
2315 extern int   iso_to_unicode(int iso);
2316 extern int   unicode_to_zscii(int32 u);
2317 extern int32 zscii_to_unicode(int z);
2318 extern int32 text_to_unicode(char *text);
2319 extern void  zscii_to_text(char *text, int zscii);
2320 extern char *name_of_iso_set(int s);
2321 extern void  change_character_set(void);
2322 extern void  new_alphabet(char *text, int alphabet);
2323 extern void  new_zscii_character(int32 unicode, int plus_flag);
2324 extern void  new_zscii_finished(void);
2325 extern void  map_new_zchar(int32 unicode);
2326 extern void  make_lower_case(char *str);
2327 extern void  make_upper_case(char *str);
2328
2329 /* ------------------------------------------------------------------------- */
2330 /*   Extern definitions for "directs"                                        */
2331 /* ------------------------------------------------------------------------- */
2332
2333 extern brief_location routine_starts_line;
2334
2335 extern int  no_routines, no_named_routines, no_locals, no_termcs;
2336 extern int  terminating_characters[];
2337
2338 extern int  parse_given_directive(int internal_flag);
2339
2340 /* ------------------------------------------------------------------------- */
2341 /*   Extern definitions for "errors"                                         */
2342 /* ------------------------------------------------------------------------- */
2343
2344 #define FORERRORS_SIZE (512)
2345 extern char *forerrors_buff;
2346 extern int  forerrors_pointer;
2347 extern int  no_errors, no_warnings, no_suppressed_warnings,
2348             no_link_errors, no_compiler_errors;
2349
2350 extern ErrorPosition ErrorReport;
2351
2352 extern void fatalerror(char *s) NORETURN;
2353 extern void fatalerror_named(char *s1, char *s2) NORETURN;
2354 extern void memory_out_error(int32 size, int32 howmany, char *name) NORETURN;
2355 extern void error_max_dynamic_strings(int index);
2356 extern void error_max_abbreviations(int index);
2357 extern void error(char *s);
2358 extern void error_named(char *s1, char *s2);
2359 extern void error_numbered(char *s1, int val);
2360 extern void error_named_at(char *s1, char *s2, brief_location report_line);
2361 extern void ebf_error(char *s1, char *s2);
2362 extern void ebf_symbol_error(char *s1, char *name, char *type, brief_location report_line);
2363 extern void char_error(char *s, int ch);
2364 extern void unicode_char_error(char *s, int32 uni);
2365 extern void no_such_label(char *lname);
2366 extern void warning(char *s);
2367 extern void warning_numbered(char *s1, int val);
2368 extern void warning_named(char *s1, char *s2);
2369 extern void symtype_warning(char *context, char *name, char *type, char *wanttype);
2370 extern void dbnu_warning(char *type, char *name, brief_location report_line);
2371 extern void uncalled_routine_warning(char *type, char *name, brief_location report_line);
2372 extern void obsolete_warning(char *s1);
2373 extern void link_error(char *s);
2374 extern void link_error_named(char *s1, char *s2);
2375 extern int  compiler_error(char *s);
2376 extern int  compiler_error_named(char *s1, char *s2);
2377 extern void print_sorry_message(void);
2378
2379 #ifdef ARC_THROWBACK
2380 extern int  throwback_switch;
2381
2382 extern void throwback(int severity, char * error);
2383 extern void throwback_start(void);
2384 extern void throwback_end(void);
2385 #endif
2386
2387 /* ------------------------------------------------------------------------- */
2388 /*   Extern definitions for "expressc"                                       */
2389 /* ------------------------------------------------------------------------- */
2390
2391 extern int vivc_flag;
2392 extern operator operators[];
2393
2394 extern assembly_operand stack_pointer, temp_var1, temp_var2, temp_var3, 
2395     temp_var4, zero_operand, one_operand, two_operand, three_operand,
2396     four_operand, valueless_operand;
2397
2398 assembly_operand code_generate(assembly_operand AO, int context, int label);
2399 assembly_operand check_nonzero_at_runtime(assembly_operand AO1, int label,
2400        int rte_number);
2401
2402 /* ------------------------------------------------------------------------- */
2403 /*   Extern definitions for "expressp"                                       */
2404 /* ------------------------------------------------------------------------- */
2405
2406 extern int system_function_usage[];
2407 extern expression_tree_node *ET;
2408
2409 extern int z_system_constant_list[];
2410 extern int glulx_system_constant_list[];
2411
2412 extern int32 value_of_system_constant(int t);
2413 extern char *name_of_system_constant(int t);
2414 extern void clear_expression_space(void);
2415 extern void show_tree(assembly_operand AO, int annotate);
2416 extern assembly_operand parse_expression(int context);
2417 extern int test_for_incdec(assembly_operand AO);
2418
2419 /* ------------------------------------------------------------------------- */
2420 /*   Extern definitions for "files"                                          */
2421 /* ------------------------------------------------------------------------- */
2422
2423 extern int  total_files;
2424 extern int  current_input_file;
2425 extern int  total_input_files;
2426 extern FileId *InputFiles;
2427
2428 extern int32 total_chars_read;
2429
2430 extern void open_transcript_file(char *what_of);
2431 extern void write_to_transcript_file(char *text, int linetype);
2432 extern void close_transcript_file(void);
2433 extern void abort_transcript_file(void);
2434
2435 extern void nullify_debug_file_position(maybe_file_position *position);
2436
2437 extern void begin_debug_file(void);
2438
2439 extern void debug_file_printf(const char*format, ...);
2440 extern void debug_file_print_with_entities(const char*string);
2441 extern void debug_file_print_base_64_triple
2442     (uchar first, uchar second, uchar third);
2443 extern void debug_file_print_base_64_pair(uchar first, uchar second);
2444 extern void debug_file_print_base_64_single(uchar first);
2445
2446 extern void write_debug_location(debug_location location);
2447 extern void write_debug_locations(debug_locations locations);
2448 extern void write_debug_optional_identifier(int32 symbol_index);
2449 extern void write_debug_symbol_backpatch(int32 symbol_index);
2450 extern void write_debug_symbol_optional_backpatch(int32 symbol_index);
2451 extern void write_debug_object_backpatch(int32 object_number);
2452 extern void write_debug_packed_code_backpatch(int32 offset);
2453 extern void write_debug_code_backpatch(int32 offset);
2454 extern void write_debug_global_backpatch(int32 offset);
2455 extern void write_debug_array_backpatch(int32 offset);
2456 extern void write_debug_grammar_backpatch(int32 offset);
2457
2458 extern void begin_writing_debug_sections(void);
2459 extern void write_debug_section(const char*name, int32 beginning_address);
2460 extern void end_writing_debug_sections(int32 end_address);
2461
2462 extern void write_debug_undef(int32 symbol_index);
2463
2464 extern void end_debug_file(void);
2465
2466 extern void add_to_checksum(void *address);
2467
2468 extern void load_sourcefile(char *story_name, int style);
2469 extern int file_load_chars(int file_number, char *buffer, int length);
2470 extern void close_all_source(void);
2471 extern int register_orig_sourcefile(char *filename);
2472
2473 extern void output_file(void);
2474
2475 /* ------------------------------------------------------------------------- */
2476 /*   Extern definitions for "inform"                                         */
2477 /* ------------------------------------------------------------------------- */
2478
2479 extern char Code_Name[];
2480 extern int endofpass_flag;
2481
2482 extern int version_number,  instruction_set_number, extend_memory_map;
2483 extern int32 scale_factor,  length_scale_factor;
2484
2485 extern int WORDSIZE, INDIV_PROP_START, 
2486     OBJECT_BYTE_LENGTH, DICT_ENTRY_BYTE_LENGTH, DICT_ENTRY_FLAG_POS;
2487 extern int32 MAXINTWORD;
2488
2489 extern int asm_trace_level, expr_trace_level,
2490     linker_trace_level,     tokens_trace_level;
2491
2492 extern int
2493     concise_switch,
2494     economy_switch,         frequencies_setting,
2495     ignore_switches_switch, debugfile_switch,
2496     files_trace_setting,    memout_switch,        printprops_switch,
2497     printactions_switch,
2498     obsolete_switch,        optabbrevs_trace_setting,
2499     transcript_switch,      statistics_switch,    optimise_switch,
2500     version_set_switch,     nowarnings_switch,    hash_switch,
2501     memory_map_setting,     module_switch,
2502     define_DEBUG_switch,    define_USE_MODULES_switch, define_INFIX_switch,
2503     runtime_error_checking_switch,
2504     list_verbs_setting,     list_dict_setting,    list_objects_setting,
2505     list_symbols_setting;
2506
2507 extern int oddeven_packing_switch;
2508
2509 extern int glulx_mode, compression_switch;
2510 extern int32 requested_glulx_version;
2511
2512 extern int error_format,    store_the_text,       asm_trace_setting,
2513     expr_trace_setting,     linker_trace_setting, tokens_trace_setting,
2514     bpatch_trace_setting,   symdef_trace_setting,
2515     double_space_setting,   trace_fns_setting,    character_set_setting,
2516     character_set_unicode;
2517
2518 extern char Debugging_Name[];
2519 extern char Transcript_Name[];
2520 extern char Language_Name[];
2521 extern char Charset_Map[];
2522
2523 extern char banner_line[];
2524
2525 extern void select_version(int vn);
2526 extern void switches(char *, int);
2527 extern int translate_in_filename(int last_value, char *new_name, char *old_name,
2528     int same_directory_flag, int command_line_flag);
2529 extern void translate_out_filename(char *new_name, char *old_name);
2530 extern int translate_link_filename(int last_value,
2531     char *new_name, char *old_name);
2532
2533 #ifdef ARCHIMEDES
2534 extern char *riscos_file_type(void);
2535 #endif
2536
2537 /* For the benefit of the MAC_FACE port these are declared extern, though
2538    unused outside "inform" in the compiler itself */
2539
2540 extern void allocate_arrays(void);
2541 extern void free_arrays(void);
2542
2543 /* ------------------------------------------------------------------------- */
2544 /*   Extern definitions for "lexer"                                          */
2545 /* ------------------------------------------------------------------------- */
2546
2547 extern int  hash_printed_since_newline;
2548 extern int  total_source_line_count;
2549 extern int  dont_enter_into_symbol_table;
2550 extern int  return_sp_as_variable;
2551 extern int  next_token_begins_syntax_line;
2552 extern identstruct *local_variable_names;
2553
2554 extern int32 token_value;
2555 extern int   token_type;
2556 extern char *token_text;
2557
2558 extern debug_location get_token_location(void);
2559 extern debug_locations get_token_locations(void);
2560 extern debug_location_beginning get_token_location_beginning(void);
2561 extern void discard_token_location(debug_location_beginning beginning);
2562 extern debug_locations get_token_location_end(debug_location_beginning beginning);
2563
2564 extern void describe_token_triple(const char *text, int32 value, int type);
2565 /* The describe_token() macro works on both token_data and lexeme_data structs. */
2566 #define describe_token(t) describe_token_triple((t)->text, (t)->value, (t)->type)
2567
2568 extern void construct_local_variable_tables(void);
2569 extern void declare_systemfile(void);
2570 extern int  is_systemfile(void);
2571 extern void report_errors_at_current_line(void);
2572 extern debug_location get_current_debug_location(void);
2573 extern debug_location get_error_report_debug_location(void);
2574 extern int32 get_current_line_start(void);
2575 extern void set_origsource_location(char *source, int32 line, int32 charnum);
2576 extern brief_location get_brief_location(ErrorPosition *errpos);
2577 extern void export_brief_location(brief_location loc, ErrorPosition *errpos);
2578 extern brief_location blank_brief_location;
2579
2580 extern void put_token_back(void);
2581 extern void get_next_token(void);
2582 extern void release_token_texts(void);
2583 extern void restart_lexer(char *lexical_source, char *name);
2584
2585 extern keyword_group directives, statements, segment_markers,
2586        conditions, system_functions, local_variables, opcode_names,
2587        misc_keywords, directive_keywords, trace_keywords, system_constants,
2588        opcode_macros;
2589
2590 /* ------------------------------------------------------------------------- */
2591 /*   Extern definitions for "linker"                                         */
2592 /* ------------------------------------------------------------------------- */
2593
2594 extern uchar *link_data_area;
2595 extern int32 link_data_size;
2596 extern char  current_module_filename[];
2597
2598 extern char *describe_mv(int mval);
2599 extern void  write_link_marker(int zmachine_area, int32 offset,
2600                  assembly_operand op);
2601 extern void  flush_link_data(void);
2602 extern void  import_symbol(int32 symbol_number);
2603 extern void  export_symbol(int32 symbol_number);
2604 extern void  export_symbol_name(int32 i);
2605 extern void  link_module(char *filename);
2606
2607 /* ------------------------------------------------------------------------- */
2608 /*   Extern definitions for "memory"                                         */
2609 /* ------------------------------------------------------------------------- */
2610
2611 extern size_t malloced_bytes;
2612
2613 extern int HASH_TAB_SIZE,
2614            MAX_ABBREVS,
2615            MAX_DYNAMIC_STRINGS;
2616
2617 extern int32 MAX_STACK_SIZE, MEMORY_MAP_EXTENSION;
2618
2619 extern int MAX_LOCAL_VARIABLES;
2620 extern int DICT_WORD_SIZE, DICT_CHAR_SIZE, DICT_WORD_BYTES;
2621 extern int ZCODE_HEADER_EXT_WORDS, ZCODE_HEADER_FLAGS_3;
2622 extern int ZCODE_LESS_DICT_DATA;
2623 extern int NUM_ATTR_BYTES, GLULX_OBJECT_EXT_BYTES;
2624 extern int WARN_UNUSED_ROUTINES, OMIT_UNUSED_ROUTINES;
2625 extern int STRIP_UNREACHABLE_LABELS;
2626 extern int TRANSCRIPT_FORMAT;
2627
2628 /* These macros define offsets that depend on the value of NUM_ATTR_BYTES.
2629    (Meaningful only for Glulx.) */
2630 /* GOBJFIELD: word offsets of various elements in the object structure. */
2631 #define GOBJFIELD_CHAIN()    (1+((NUM_ATTR_BYTES)/4))
2632 #define GOBJFIELD_NAME()     (2+((NUM_ATTR_BYTES)/4))
2633 #define GOBJFIELD_PROPTAB()  (3+((NUM_ATTR_BYTES)/4))
2634 #define GOBJFIELD_PARENT()   (4+((NUM_ATTR_BYTES)/4))
2635 #define GOBJFIELD_SIBLING()  (5+((NUM_ATTR_BYTES)/4))
2636 #define GOBJFIELD_CHILD()    (6+((NUM_ATTR_BYTES)/4))
2637
2638 extern void *my_malloc(size_t size, char *whatfor);
2639 extern void my_realloc(void *pointer, size_t oldsize, size_t size, 
2640     char *whatfor);
2641 extern void *my_calloc(size_t size, size_t howmany, char *whatfor);
2642 extern void my_recalloc(void *pointer, size_t size, size_t oldhowmany, 
2643     size_t howmany, char *whatfor);
2644 extern void my_free(void *pointer, char *whatitwas);
2645
2646 extern void set_memory_sizes(void);
2647 extern void adjust_memory_sizes(void);
2648 extern void memory_command(char *command);
2649 extern void print_memory_usage(void);
2650
2651 extern void initialise_memory_list(memory_list *ML, size_t itemsize, size_t initalloc, void **extpointer, char *whatfor);
2652 extern void deallocate_memory_list(memory_list *ML);
2653 extern void ensure_memory_list_available(memory_list *ML, size_t count);
2654
2655 /* ------------------------------------------------------------------------- */
2656 /*   Extern definitions for "objects"                                        */
2657 /* ------------------------------------------------------------------------- */
2658
2659 extern int no_attributes, no_properties;
2660 extern int no_individual_properties;
2661 extern int individuals_length;
2662 extern uchar *individuals_table;
2663 extern memory_list individuals_table_memlist;
2664 extern int no_classes, no_objects;
2665 extern objecttz *objectsz;
2666 extern memory_list objectsz_memlist;
2667 extern objecttg *objectsg;
2668 extern uchar *objectatts;
2669 extern classinfo *class_info;
2670 extern memory_list class_info_memlist;
2671
2672 extern commonpropinfo *commonprops;
2673 extern uchar *properties_table;
2674 extern memory_list properties_table_memlist;
2675 extern int properties_table_size;
2676
2677 extern void make_attribute(void);
2678 extern void make_property(void);
2679 extern void make_object(int nearby_flag,
2680     char *textual_name, int specified_parent, int specified_class,
2681     int instance_of);
2682 extern void make_class(char *metaclass_name);
2683 extern int  object_provides(int obj, int id);
2684 extern void list_object_tree(void);
2685 extern void write_the_identifier_names(void);
2686
2687 /* ------------------------------------------------------------------------- */
2688 /*   Extern definitions for "symbols"                                        */
2689 /* ------------------------------------------------------------------------- */
2690
2691 extern int no_named_constants;
2692 extern int no_symbols;
2693 extern symbolinfo *symbols;
2694 extern symboldebuginfo *symbol_debug_info;
2695 extern int32 *individual_name_strings;
2696 extern int32 *attribute_name_strings;
2697 extern int32 *action_name_strings;
2698 extern int32 *array_name_strings;
2699 extern int track_unused_routines;
2700 extern int df_dont_note_global_symbols;
2701 extern uint32 df_total_size_before_stripping;
2702 extern uint32 df_total_size_after_stripping;
2703
2704 extern char *typename(int type);
2705 extern int hash_code_from_string(char *p);
2706 extern int strcmpcis(char *p, char *q);
2707 extern int get_symbol_index(char *p);
2708 extern int symbol_index(char *lexeme_text, int hashcode);
2709 extern void end_symbol_scope(int k);
2710 extern void describe_symbol(int k);
2711 extern void list_symbols(int level);
2712 extern void assign_marked_symbol(int index, int marker, int32 value, int type);
2713 extern void assign_symbol(int index, int32 value, int type);
2714 extern void check_warn_symbol_type(const assembly_operand *AO, int wanttype, int wanttype2, char *label);
2715 extern void check_warn_symbol_has_metaclass(const assembly_operand *AO, char *context);
2716 extern void issue_unused_warnings(void);
2717 extern void issue_debug_symbol_warnings(void);
2718 extern void add_config_symbol_definition(char *symbol, int32 value);
2719 extern void add_symbol_replacement_mapping(int original, int renamed);
2720 extern int find_symbol_replacement(int *value);
2721 extern void df_note_function_start(char *name, uint32 address, 
2722     int embedded_flag, brief_location source_line);
2723 extern void df_note_function_end(uint32 endaddress);
2724 extern void df_note_function_symbol(int symbol);
2725 extern void locate_dead_functions(void);
2726 extern uint32 df_stripped_address_for_address(uint32);
2727 extern uint32 df_stripped_offset_for_code_offset(uint32, int *);
2728 extern void df_prepare_function_iterate(void);
2729 extern uint32 df_next_function_iterate(int *);
2730
2731 /* ------------------------------------------------------------------------- */
2732 /*   Extern definitions for "syntax"                                         */
2733 /* ------------------------------------------------------------------------- */
2734
2735 extern int   no_syntax_lines;
2736
2737 extern void  panic_mode_error_recovery(void);
2738 extern void  get_next_token_with_directives(void);
2739 extern int   parse_directive(int internal_flag);
2740 extern void  parse_program(char *source);
2741 extern int32 parse_routine(char *source, int embedded_flag, char *name,
2742                  int veneer_flag, int r_symbol);
2743 extern void  parse_code_block(int break_label, int continue_label,
2744                  int switch_rule);
2745
2746 /* ------------------------------------------------------------------------- */
2747 /*   Extern definitions for "states"                                         */
2748 /* ------------------------------------------------------------------------- */
2749
2750 extern void  match_close_bracket(void);
2751 extern void  parse_statement(int break_label, int continue_label);
2752 extern int   parse_label(void);
2753
2754 /* ------------------------------------------------------------------------- */
2755 /*   Extern definitions for "tables"                                         */
2756 /* ------------------------------------------------------------------------- */
2757
2758 extern uchar *zmachine_paged_memory;
2759 extern int32
2760     code_offset,            actions_offset,       preactions_offset,
2761     dictionary_offset,      strings_offset,       adjectives_offset,
2762     variables_offset,       class_numbers_offset, individuals_offset,
2763    identifier_names_offset, prop_defaults_offset, prop_values_offset,
2764     static_memory_offset,   array_names_offset,   attribute_names_offset,
2765     action_names_offset,    fake_action_names_offset,
2766     routine_names_offset,   routines_array_offset, routine_flags_array_offset,
2767     global_names_offset,    global_flags_array_offset,
2768     array_flags_array_offset, constant_names_offset, constants_array_offset,
2769     static_arrays_offset;
2770 extern int32
2771     arrays_offset, object_tree_offset, grammar_table_offset,
2772     abbreviations_offset;    /* For Glulx */
2773
2774 extern int32 Out_Size,      Write_Code_At,        Write_Strings_At;
2775 extern int32 RAM_Size,      Write_RAM_At;    /* For Glulx */
2776
2777 extern int release_number, statusline_flag;
2778 extern int flags2_requirements[];
2779 extern int serial_code_given_in_program;
2780 extern char serial_code_buffer[];
2781
2782 extern void construct_storyfile(void);
2783 extern void write_serial_number(char *buffer);
2784
2785 /* ------------------------------------------------------------------------- */
2786 /*   Extern definitions for "text"                                           */
2787 /* ------------------------------------------------------------------------- */
2788
2789 extern uchar *translated_text;
2790
2791 extern uchar *low_strings;
2792 extern int32 low_strings_top;
2793
2794 extern int   no_abbreviations;
2795 extern int   abbrevs_lookup_table_made, is_abbreviation;
2796 extern uchar *abbreviations_at;
2797 extern abbreviation *abbreviations;
2798
2799 extern int32 total_chars_trans, total_bytes_trans,
2800              zchars_trans_in_last_string;
2801 extern int   put_strings_in_low_memory;
2802 extern int   dict_entries;
2803 extern uchar *dictionary;
2804 extern int32 dictionary_top;
2805 extern int   *final_dict_order;
2806
2807 extern uchar *static_strings_area;
2808 extern memory_list static_strings_area_memlist;
2809 extern int32 static_strings_extent;
2810
2811 /* And now, a great many declarations for dealing with Glulx string
2812    compression. */
2813
2814 extern int32 no_strings, no_dynamic_strings;
2815 extern int no_unicode_chars;
2816
2817 typedef struct unicode_usage_s unicode_usage_t;
2818 struct unicode_usage_s {
2819   int32 ch;
2820   int next; /* index in unicode_usage_entries of next */
2821 };
2822
2823 extern unicode_usage_t *unicode_usage_entries;
2824
2825 /* This is the maximum number of (8-bit) bytes that can encode a single
2826    Huffman entity. Four should be plenty, unless someone starts encoding
2827    an ideographic language. */
2828 #define MAXHUFFBYTES (4)
2829
2830 typedef struct huffbitlist_struct {
2831   uchar b[MAXHUFFBYTES];
2832 } huffbitlist_t;
2833 typedef struct huffentity_struct {
2834   int count;
2835   int type;
2836   union {
2837     int branch[2];
2838     uchar ch;
2839     int val;
2840   } u;
2841   int depth;
2842   int32 addr;
2843   huffbitlist_t bits;
2844 } huffentity_t;
2845
2846 extern huffentity_t *huff_entities;
2847
2848 extern int32 compression_table_size, compression_string_size;
2849 extern int32 *compressed_offsets;
2850 extern int no_huff_entities;
2851 extern int huff_abbrev_start, huff_dynam_start, huff_unicode_start;
2852 extern int huff_entity_root;
2853
2854 extern void  compress_game_text(void);
2855
2856 /* end of the Glulx string compression stuff */
2857
2858 extern void  ao_free_arrays(void);
2859 extern void  extract_all_text(void);
2860 extern int32 compile_string(char *b, int strctx);
2861 extern int32 translate_text(int32 p_limit, char *s_text, int strctx);
2862 extern void  optimise_abbreviations(void);
2863 extern void  make_abbreviation(char *text);
2864 extern void  show_dictionary(int level);
2865 extern void  word_to_ascii(uchar *p, char *result);
2866 extern void  print_dict_word(int node);
2867 extern void  write_dictionary_to_transcript(void);
2868 extern void  sort_dictionary(void);
2869 extern void  dictionary_prepare(char *dword, uchar *optresult);
2870 extern int   dictionary_add(char *dword, int x, int y, int z);
2871 extern void  dictionary_set_verb_number(char *dword, int to);
2872 extern int   compare_sorts(uchar *d1, uchar *d2);
2873 extern void  copy_sorts(uchar *d1, uchar *d2);
2874
2875 /* ------------------------------------------------------------------------- */
2876 /*   Extern definitions for "veneer"                                         */
2877 /* ------------------------------------------------------------------------- */
2878
2879 extern int  veneer_mode;
2880 extern int32 veneer_routine_address[];
2881
2882 extern void compile_initial_routine(void);
2883 extern assembly_operand veneer_routine(int code);
2884 extern char *veneer_routine_name(int code);
2885 extern void compile_veneer(void);
2886
2887 /* ------------------------------------------------------------------------- */
2888 /*   Extern definitions for "verbs"                                          */
2889 /* ------------------------------------------------------------------------- */
2890
2891 extern int no_adjectives, no_Inform_verbs, no_grammar_token_routines,
2892            no_fake_actions, no_actions, no_grammar_lines, no_grammar_tokens,
2893            grammar_version_number;
2894 extern int32 grammar_version_symbol;
2895 extern verbt *Inform_verbs;
2896 extern uchar *grammar_lines;
2897 extern int32 grammar_lines_top;
2898 extern actioninfo *actions;
2899 extern memory_list actions_memlist;
2900 extern int32 *grammar_token_routine,
2901              *adjectives;
2902
2903 extern void find_the_actions(void);
2904 extern void make_fake_action(void);
2905 extern assembly_operand action_of_name(char *name);
2906 extern void make_verb(void);
2907 extern void extend_verb(void);
2908 extern void list_verb_table(void);
2909
2910 /* ========================================================================= */