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