sourcepawn/compiler/sc.h
author Scott Ehlert <ds@alliedmods.net>
Sun Mar 30 07:00:22 2008 +0000 (2008-03-30)
changeset 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Spring Cleaning, Part Ichi (1)
Various minor things done to project files
Updated sample extension project file and updated makefile to the new unified version (more changes likely on the way)
Updated regex project file and makefile
ds@1952
     1
/*  Pawn compiler
ds@1952
     2
 *
ds@1952
     3
 *  Drafted after the Small-C compiler Version 2.01, originally created
ds@1952
     4
 *  by Ron Cain, july 1980, and enhanced by James E. Hendrix.
ds@1952
     5
 *
ds@1952
     6
 *  This version comes close to a complete rewrite.
ds@1952
     7
 *
ds@1952
     8
 *  Copyright R. Cain, 1980
ds@1952
     9
 *  Copyright J.E. Hendrix, 1982, 1983
ds@1952
    10
 *  Copyright ITB CompuPhase, 1997-2006
ds@1952
    11
 *
ds@1952
    12
 *  This software is provided "as-is", without any express or implied warranty.
ds@1952
    13
 *  In no event will the authors be held liable for any damages arising from
ds@1952
    14
 *  the use of this software.
ds@1952
    15
 *
ds@1952
    16
 *  Permission is granted to anyone to use this software for any purpose,
ds@1952
    17
 *  including commercial applications, and to alter it and redistribute it
ds@1952
    18
 *  freely, subject to the following restrictions:
ds@1952
    19
 *
ds@1952
    20
 *  1.  The origin of this software must not be misrepresented; you must not
ds@1952
    21
 *      claim that you wrote the original software. If you use this software in
ds@1952
    22
 *      a product, an acknowledgment in the product documentation would be
ds@1952
    23
 *      appreciated but is not required.
ds@1952
    24
 *  2.  Altered source versions must be plainly marked as such, and must not be
ds@1952
    25
 *      misrepresented as being the original software.
ds@1952
    26
 *  3.  This notice may not be removed or altered from any source distribution.
ds@1952
    27
 *
ds@1952
    28
 *  Version: $Id$
ds@1952
    29
 */
ds@1952
    30
#ifndef SC_H_INCLUDED
ds@1952
    31
#define SC_H_INCLUDED
ds@1952
    32
#include <limits.h>
ds@1952
    33
#include <stdarg.h>
ds@1952
    34
#include <stdio.h>
ds@1952
    35
#if defined __BORLANDC__ && defined _Windows && !(defined __32BIT__ || defined __WIN32__)
ds@1952
    36
  /* setjmp() and longjmp() not well supported in 16-bit windows */
ds@1952
    37
  #include <windows.h>
ds@1952
    38
  typedef int jmp_buf[9];
ds@1952
    39
  #define setjmp(b)     Catch(b)
ds@1952
    40
  #define longjmp(b,e)  Throw(b,e)
ds@1952
    41
#else
ds@1952
    42
  #include <setjmp.h>
ds@1952
    43
#endif
ds@1952
    44
#include "osdefs.h"
ds@1952
    45
#include "amx.h"
ds@1952
    46
ds@1952
    47
/* Note: the "cell" and "ucell" types are defined in AMX.H */
ds@1952
    48
ds@1952
    49
#define PUBLIC_CHAR '@'     /* character that defines a function "public" */
ds@1952
    50
#define CTRL_CHAR   '\\'    /* default control character */
ds@1952
    51
#define sCHARBITS   8       /* size of a packed character */
ds@1952
    52
ds@1952
    53
#define sDIMEN_MAX     4    /* maximum number of array dimensions */
ds@1952
    54
#define sLINEMAX     1023   /* input line length (in characters) */
ds@1952
    55
#define sCOMP_STACK   32    /* maximum nesting of #if .. #endif sections */
ds@1952
    56
#define sDEF_LITMAX  500    /* initial size of the literal pool, in "cells" */
ds@1952
    57
#define sDEF_AMXSTACK 4096  /* default stack size for AMX files */
ds@1952
    58
#define PREPROC_TERM  '\x7f'/* termination character for preprocessor expressions (the "DEL" code) */
ds@1952
    59
#define sDEF_PREFIX   "sourcemod.inc" /* default prefix filename */
ds@1952
    60
#define sARGS_MAX		32	/* number of arguments a function can have, max */
ds@1952
    61
#define sTAGS_MAX		16  /* maximum number of tags on an argument */
ds@1952
    62
ds@1952
    63
typedef union {
ds@1952
    64
  void *pv;                 /* e.g. a name */
ds@1952
    65
  int i;
ds@1952
    66
} stkitem;                  /* type of items stored on the compiler stack */
ds@1952
    67
ds@1952
    68
typedef struct s_arginfo {  /* function argument info */
ds@1952
    69
  char name[sNAMEMAX+1];
ds@1952
    70
  char ident;           /* iVARIABLE, iREFERENCE, iREFARRAY or iVARARGS */
ds@1952
    71
  char usage;           /* uCONST */
ds@1952
    72
  int *tags;            /* argument tag id. list */
ds@1952
    73
  int numtags;          /* number of tags in the tag list */
ds@1952
    74
  int dim[sDIMEN_MAX];
ds@1952
    75
  int idxtag[sDIMEN_MAX];
ds@1952
    76
  int numdim;           /* number of dimensions */
ds@1952
    77
  unsigned char hasdefault; /* bit0: is there a default value? bit6: "tagof"; bit7: "sizeof" */
ds@1952
    78
  union {
ds@1952
    79
    cell val;           /* default value */
ds@1952
    80
    struct {
ds@1952
    81
      char *symname;    /* name of another symbol */
ds@1952
    82
      short level;      /* indirection level for that symbol */
ds@1952
    83
    } size;             /* used for "sizeof" default value */
ds@1952
    84
    struct {
ds@1952
    85
      cell *data;       /* values of default array */
ds@1952
    86
      int size;         /* complete length of default array */
ds@1952
    87
      int arraysize;    /* size to reserve on the heap */
ds@1952
    88
      cell addr;        /* address of the default array in the data segment */
ds@1952
    89
    } array;
ds@1952
    90
  } defvalue;           /* default value, or pointer to default array */
ds@1952
    91
  int defvalue_tag;     /* tag of the default value */
ds@1952
    92
} arginfo;
ds@1952
    93
ds@1952
    94
/*  Equate table, tagname table, library table */
ds@1952
    95
typedef struct s_constvalue {
ds@1952
    96
  struct s_constvalue *next;
ds@1952
    97
  char name[sNAMEMAX+1];
ds@1952
    98
  cell value;
ds@1952
    99
  int index;            /* index level, for constants referring to array sizes/tags
ds@1952
   100
                         * automaton id. for states and automatons
ds@1952
   101
                         * tag for enumeration lists */
ds@1952
   102
} constvalue;
ds@1952
   103
ds@1952
   104
/*  Symbol table format
ds@1952
   105
 *
ds@1952
   106
 *  The symbol name read from the input file is stored in "name", the
ds@1952
   107
 *  value of "addr" is written to the output file. The address in "addr"
ds@1952
   108
 *  depends on the class of the symbol:
ds@1952
   109
 *      global          offset into the data segment
ds@1952
   110
 *      local           offset relative to the stack frame
ds@1952
   111
 *      label           generated hexadecimal number
ds@1952
   112
 *      function        offset into code segment
ds@1952
   113
 */
ds@1952
   114
typedef struct s_symbol {
ds@1952
   115
  struct s_symbol *next;
ds@1952
   116
  struct s_symbol *parent;  /* hierarchical types (multi-dimensional arrays) */
ds@1952
   117
  char name[sNAMEMAX+1];
ds@1952
   118
  uint32_t hash;        /* value derived from name, for quicker searching */
ds@1952
   119
  cell addr;            /* address or offset (or value for constant, index for native function) */
ds@1952
   120
  cell codeaddr;        /* address (in the code segment) where the symbol declaration starts */
ds@1952
   121
  char vclass;          /* sLOCAL if "addr" refers to a local symbol */
ds@1952
   122
  char ident;           /* see below for possible values */
ds@1952
   123
  short usage;          /* see below for possible values */
ds@1952
   124
  char flags;           /* see below for possible values */
ds@1952
   125
  int compound;         /* compound level (braces nesting level) */
ds@1952
   126
  int tag;              /* tagname id */
ds@1952
   127
  union {
ds@1952
   128
    int declared;       /* label: how many local variables are declared */
ds@1952
   129
    struct {
ds@1952
   130
      int index;        /* array & enum: tag of array indices or the enum item */
ds@1952
   131
      int field;        /* enumeration fields, where a size is attached to the field */
ds@1952
   132
    } tags;             /* extra tags */
ds@1952
   133
    constvalue *lib;    /* native function: library it is part of */
ds@1952
   134
    long stacksize;     /* normal/public function: stack requirements */
ds@1952
   135
  } x;                  /* 'x' for 'extra' */
ds@1952
   136
  union {
ds@1952
   137
    arginfo *arglist;   /* types of all parameters for functions */
ds@1952
   138
    constvalue *enumlist;/* list of names for the "root" of an enumeration */
ds@1952
   139
    struct {
ds@1952
   140
      cell length;      /* arrays: length (size) */
ds@1952
   141
      cell slength;		/* if a string index, this will be set to the original size */
ds@1952
   142
      short level;      /* number of dimensions below this level */
ds@1952
   143
    } array;
ds@1952
   144
  } dim;                /* for 'dimension', both functions and arrays */
ds@1952
   145
  constvalue *states;   /* list of state function/state variable ids + addresses */
ds@1952
   146
  int fnumber;          /* static global variables: file number in which the declaration is visible */
ds@1952
   147
  int lnumber;          /* line number (in the current source file) for the declaration */
ds@1952
   148
  struct s_symbol **refer;  /* referrer list, functions that "use" this symbol */
ds@1952
   149
  int numrefers;        /* number of entries in the referrer list */
ds@1952
   150
  char *documentation;  /* optional documentation string */
ds@1952
   151
} symbol;
ds@1952
   152
ds@1952
   153
ds@1952
   154
/*  Possible entries for "ident". These are used in the "symbol", "value"
ds@1952
   155
 *  and arginfo structures. Not every constant is valid for every use.
ds@1952
   156
 *  In an argument list, the list is terminated with a "zero" ident; labels
ds@1952
   157
 *  cannot be passed as function arguments, so the value 0 is overloaded.
ds@1952
   158
 */
ds@1952
   159
#define iLABEL      0
ds@1952
   160
#define iVARIABLE   1   /* cell that has an address and that can be fetched directly (lvalue) */
ds@1952
   161
#define iREFERENCE  2   /* iVARIABLE, but must be dereferenced */
ds@1952
   162
#define iARRAY      3
ds@1952
   163
#define iREFARRAY   4   /* an array passed by reference (i.e. a pointer) */
ds@1952
   164
#define iARRAYCELL  5   /* array element, cell that must be fetched indirectly */
ds@1952
   165
#define iARRAYCHAR  6   /* array element, character from cell from array */
ds@1952
   166
#define iEXPRESSION 7   /* expression result, has no address (rvalue) */
ds@1952
   167
#define iCONSTEXPR  8   /* constant expression (or constant symbol) */
ds@1952
   168
#define iFUNCTN     9
ds@1952
   169
#define iREFFUNC    10
ds@1952
   170
#define iVARARGS    11  /* function specified ... as argument(s) */
ds@1952
   171
ds@1952
   172
/*  Possible entries for "usage"
ds@1952
   173
 *
ds@1952
   174
 *  This byte is used as a serie of bits, the syntax is different for
ds@1952
   175
 *  functions and other symbols:
ds@1952
   176
 *
ds@1952
   177
 *  VARIABLE
ds@1952
   178
 *  bits: 0     (uDEFINE) the variable is defined in the source file
ds@1952
   179
 *        1     (uREAD) the variable is "read" (accessed) in the source file
ds@1952
   180
 *        2     (uWRITTEN) the variable is altered (assigned a value)
ds@1952
   181
 *        3     (uCONST) the variable is constant (may not be assigned to)
ds@1952
   182
 *        4     (uPUBLIC) the variable is public
ds@1952
   183
 *        6     (uSTOCK) the variable is discardable (without warning)
ds@1952
   184
 *
ds@1952
   185
 *  FUNCTION
ds@1952
   186
 *  bits: 0     (uDEFINE) the function is defined ("implemented") in the source file
ds@1952
   187
 *        1     (uREAD) the function is invoked in the source file
ds@1952
   188
 *        2     (uRETVALUE) the function returns a value (or should return a value)
ds@1952
   189
 *        3     (uPROTOTYPED) the function was prototyped (implicitly via a definition or explicitly)
ds@1952
   190
 *        4     (uPUBLIC) the function is public
ds@1952
   191
 *        5     (uNATIVE) the function is native
ds@1952
   192
 *        6     (uSTOCK) the function is discardable (without warning)
ds@1952
   193
 *        7     (uMISSING) the function is not implemented in this source file
ds@1952
   194
 *        8     (uFORWARD) the function is explicitly forwardly declared
ds@1952
   195
 *
ds@1952
   196
 *  CONSTANT
ds@1952
   197
 *  bits: 0     (uDEFINE) the symbol is defined in the source file
ds@1952
   198
 *        1     (uREAD) the constant is "read" (accessed) in the source file
ds@1952
   199
 *        2     (uWRITTEN) redundant, but may be set for constants passed by reference
ds@1952
   200
 *        3     (uPREDEF) the constant is pre-defined and should be kept between passes
ds@1952
   201
 *        5     (uENUMROOT) the constant is the "root" of an enumeration
ds@1952
   202
 *        6     (uENUMFIELD) the constant is a field in a named enumeration
ds@1952
   203
 */
ds@1952
   204
#define uDEFINE   0x001
ds@1952
   205
#define uREAD     0x002
ds@1952
   206
#define uWRITTEN  0x004
ds@1952
   207
#define uRETVALUE 0x004 /* function returns (or should return) a value */
ds@1952
   208
#define uCONST    0x008
ds@1952
   209
#define uPROTOTYPED 0x008
ds@1952
   210
#define uPREDEF   0x008 /* constant is pre-defined */
ds@1952
   211
#define uPUBLIC   0x010
ds@1952
   212
#define uNATIVE   0x020
ds@1952
   213
#define uENUMROOT 0x020
ds@1952
   214
#define uSTOCK    0x040
ds@1952
   215
#define uENUMFIELD 0x040
ds@1952
   216
#define uMISSING  0x080
ds@1952
   217
#define uFORWARD  0x100
ds@1952
   218
#define uSTRUCT	  0x200 /* :TODO: make this an ident */
ds@1952
   219
/* uRETNONE is not stored in the "usage" field of a symbol. It is
ds@1952
   220
 * used during parsing a function, to detect a mix of "return;" and
ds@1952
   221
 * "return value;" in a few special cases.
ds@1952
   222
 */
ds@1952
   223
#define uRETNONE  0x10
ds@1952
   224
ds@1952
   225
#define flgDEPRECATED 0x01  /* symbol is deprecated (avoid use) */
ds@1952
   226
ds@1952
   227
#define uCOUNTOF  0x20  /* set in the "hasdefault" field of the arginfo struct */
ds@1952
   228
#define uTAGOF    0x40  /* set in the "hasdefault" field of the arginfo struct */
ds@1952
   229
#define uSIZEOF   0x80  /* set in the "hasdefault" field of the arginfo struct */
ds@1952
   230
ds@1952
   231
#define uMAINFUNC "main"
ds@1952
   232
#define uENTRYFUNC "entry"
ds@1952
   233
ds@1952
   234
#define sGLOBAL   0     /* global variable/constant class (no states) */
ds@1952
   235
#define sLOCAL    1     /* local variable/constant */
ds@1952
   236
#define sSTATIC   2     /* global life, local scope */
ds@1952
   237
ds@1952
   238
#define sSTATEVAR  3    /* criterion to find variables (sSTATEVAR implies a global variable) */
ds@1952
   239
ds@1952
   240
typedef struct s_value {
ds@1952
   241
  symbol *sym;          /* symbol in symbol table, NULL for (constant) expression */
ds@1952
   242
  cell constval;        /* value of the constant expression (if ident==iCONSTEXPR)
ds@1952
   243
                         * also used for the size of a literal array */
ds@1952
   244
  int tag;              /* tag (of the expression) */
ds@1952
   245
  int cmptag;           /* for searching symbols: choose the one with the matching tag */
ds@1952
   246
  char ident;           /* iCONSTEXPR, iVARIABLE, iARRAY, iARRAYCELL,
ds@1952
   247
                         * iEXPRESSION or iREFERENCE */
ds@1952
   248
  char boolresult;      /* boolean result for relational operators */
ds@1952
   249
  cell *arrayidx;       /* last used array indices, for checking self assignment */
ds@1952
   250
} value;
ds@1952
   251
ds@1952
   252
/*  "while" statement queue (also used for "for" and "do - while" loops) */
ds@1952
   253
enum {
ds@1952
   254
  wqBRK,        /* used to restore stack for "break" */
ds@1952
   255
  wqCONT,       /* used to restore stack for "continue" */
ds@1952
   256
  wqLOOP,       /* loop start label number */
ds@1952
   257
  wqEXIT,       /* loop exit label number (jump if false) */
ds@1952
   258
  /* --- */
ds@1952
   259
  wqSIZE        /* "while queue" size */
ds@1952
   260
};
ds@1952
   261
#define wqTABSZ (24*wqSIZE)    /* 24 nested loop statements */
ds@1952
   262
ds@1952
   263
enum {
ds@1952
   264
  statIDLE,     /* not compiling yet */
ds@1952
   265
  statFIRST,    /* first pass */
ds@1952
   266
  statWRITE,    /* writing output */
ds@1952
   267
  statSKIP,     /* skipping output */
ds@1952
   268
};
ds@1952
   269
ds@1952
   270
typedef struct s_stringlist {
ds@1952
   271
  struct s_stringlist *next;
ds@1952
   272
  char *line;
ds@1952
   273
} stringlist;
ds@1952
   274
ds@1952
   275
typedef struct s_stringpair {
ds@1952
   276
  struct s_stringpair *next;
ds@1952
   277
  char *first;
ds@1952
   278
  char *second;
ds@1952
   279
  int matchlength;
ds@1952
   280
  char flags;
ds@1952
   281
  char *documentation;
ds@1952
   282
} stringpair;
ds@1952
   283
ds@1952
   284
/* macros for code generation */
ds@1952
   285
#define opcodes(n)      ((n)*sizeof(cell))      /* opcode size */
ds@1952
   286
#define opargs(n)       ((n)*sizeof(cell))      /* size of typical argument */
ds@1952
   287
ds@1952
   288
/*  Tokens recognized by lex()
ds@1952
   289
 *  Some of these constants are assigned as well to the variable "lastst" (see SC1.C)
ds@1952
   290
 */
ds@1952
   291
#define tFIRST   256    /* value of first multi-character operator */
ds@1952
   292
#define tMIDDLE  280    /* value of last multi-character operator */
ds@1952
   293
#define tLAST    333    /* value of last multi-character match-able token */
ds@1952
   294
/* multi-character operators */
ds@1952
   295
#define taMULT   256    /* *= */
ds@1952
   296
#define taDIV    257    /* /= */
ds@1952
   297
#define taMOD    258    /* %= */
ds@1952
   298
#define taADD    259    /* += */
ds@1952
   299
#define taSUB    260    /* -= */
ds@1952
   300
#define taSHL    261    /* <<= */
ds@1952
   301
#define taSHRU   262    /* >>>= */
ds@1952
   302
#define taSHR    263    /* >>= */
ds@1952
   303
#define taAND    264    /* &= */
ds@1952
   304
#define taXOR    265    /* ^= */
ds@1952
   305
#define taOR     266    /* |= */
ds@1952
   306
#define tlOR     267    /* || */
ds@1952
   307
#define tlAND    268    /* && */
ds@1952
   308
#define tlEQ     269    /* == */
ds@1952
   309
#define tlNE     270    /* != */
ds@1952
   310
#define tlLE     271    /* <= */
ds@1952
   311
#define tlGE     272    /* >= */
ds@1952
   312
#define tSHL     273    /* << */
ds@1952
   313
#define tSHRU    274    /* >>> */
ds@1952
   314
#define tSHR     275    /* >> */
ds@1952
   315
#define tINC     276    /* ++ */
ds@1952
   316
#define tDEC     277    /* -- */
ds@1952
   317
#define tELLIPS  278    /* ... */
ds@1952
   318
#define tDBLDOT  279    /* .. */
ds@1952
   319
#define tDBLCOLON 280   /* :: */
ds@1952
   320
/* reserved words (statements) */
ds@1952
   321
#define tASSERT  281
ds@1952
   322
#define tBEGIN   282
ds@1952
   323
#define tBREAK   283
ds@1952
   324
#define tCASE    284
ds@1952
   325
#define tCELLSOF 285
ds@1952
   326
#define tCHAR    286
ds@1952
   327
#define tCONST   287
ds@1952
   328
#define tCONTINUE 288
ds@1952
   329
#define tDEFAULT 289
ds@1952
   330
#define tDEFINED 290
ds@1952
   331
#define tDO      291
ds@1952
   332
#define tELSE    292
ds@1952
   333
#define tEND     293
ds@1952
   334
#define tENUM    294
ds@1952
   335
#define tEXIT    295
ds@1952
   336
#define tFOR     296
ds@1952
   337
#define tFORWARD 297
ds@1952
   338
#define tFUNCENUM 298
ds@1952
   339
#define tFUNCTAG 299
ds@1952
   340
#define tGOTO    300
ds@1952
   341
#define tIF      301
ds@1952
   342
#define tNATIVE  302
ds@1952
   343
#define tNEW     303
ds@1952
   344
#define tDECL    304
ds@1952
   345
#define tOPERATOR 305
ds@1952
   346
#define tPUBLIC  306
ds@1952
   347
#define tRETURN  307
ds@1952
   348
#define tSIZEOF  308
ds@1952
   349
#define tSLEEP   309
ds@1952
   350
#define tSTATE   310
ds@1952
   351
#define tSTATIC  311
ds@1952
   352
#define tSTOCK   312
ds@1952
   353
#define tSTRUCT  313
ds@1952
   354
#define tSWITCH  314
ds@1952
   355
#define tTAGOF   315
ds@1952
   356
#define tTHEN    316
ds@1952
   357
#define tWHILE   317
ds@1952
   358
/* compiler directives */
ds@1952
   359
#define tpASSERT 318    /* #assert */
ds@1952
   360
#define tpDEFINE 319
ds@1952
   361
#define tpELSE   320    /* #else */
ds@1952
   362
#define tpELSEIF 321    /* #elseif */
ds@1952
   363
#define tpEMIT   322
ds@1952
   364
#define tpENDIF  323
ds@1952
   365
#define tpENDINPUT 324
ds@1952
   366
#define tpENDSCRPT 325
ds@1952
   367
#define tpERROR  326
ds@1952
   368
#define tpFILE   327
ds@1952
   369
#define tpIF     328    /* #if */
ds@1952
   370
#define tINCLUDE 329
ds@1952
   371
#define tpLINE   330
ds@1952
   372
#define tpPRAGMA 331
ds@1952
   373
#define tpTRYINCLUDE 332
ds@1952
   374
#define tpUNDEF  333
ds@1952
   375
/* semicolon is a special case, because it can be optional */
ds@1952
   376
#define tTERM    334    /* semicolon or newline */
ds@1952
   377
#define tENDEXPR 335    /* forced end of expression */
ds@1952
   378
/* other recognized tokens */
ds@1952
   379
#define tNUMBER  336    /* integer number */
ds@1952
   380
#define tRATIONAL 337   /* rational number */
ds@1952
   381
#define tSYMBOL  338
ds@1952
   382
#define tLABEL   339
ds@1952
   383
#define tSTRING  340
ds@1952
   384
#define tEXPR    341 /* for assigment to "lastst" only (see SC1.C) */
ds@1952
   385
#define tENDLESS 342 /* endless loop, for assigment to "lastst" only */
ds@1952
   386
ds@1952
   387
/* (reversed) evaluation of staging buffer */
ds@1952
   388
#define sSTARTREORDER 0x01
ds@1952
   389
#define sENDREORDER   0x02
ds@1952
   390
#define sEXPRSTART    0x80      /* top bit set, rest is free */
ds@1952
   391
#define sMAXARGS      127       /* relates to the bit pattern of sEXPRSTART */
ds@1952
   392
ds@1952
   393
#define sDOCSEP       0x01      /* to separate documentation comments between functions */
ds@1952
   394
ds@1952
   395
/* codes for ffabort() */
ds@1952
   396
#define xEXIT           1       /* exit code in PRI */
ds@1952
   397
#define xASSERTION      2       /* abort caused by failing assertion */
ds@1952
   398
#define xSTACKERROR     3       /* stack/heap overflow */
ds@1952
   399
#define xBOUNDSERROR    4       /* array index out of bounds */
ds@1952
   400
#define xMEMACCESS      5       /* data access error */
ds@1952
   401
#define xINVINSTR       6       /* invalid instruction */
ds@1952
   402
#define xSTACKUNDERFLOW 7       /* stack underflow */
ds@1952
   403
#define xHEAPUNDERFLOW  8       /* heap underflow */
ds@1952
   404
#define xCALLBACKERR    9       /* no, or invalid, callback */
ds@1952
   405
#define xSLEEP         12       /* sleep, exit code in PRI, tag in ALT */
ds@1952
   406
ds@1952
   407
/* Miscellaneous  */
ds@1952
   408
#if !defined TRUE
ds@1952
   409
  #define FALSE         0
ds@1952
   410
  #define TRUE          1
ds@1952
   411
#endif
ds@1952
   412
#define sIN_CSEG        1       /* if parsing CODE */
ds@1952
   413
#define sIN_DSEG        2       /* if parsing DATA */
ds@1952
   414
#define sCHKBOUNDS      1       /* bit position in "debug" variable: check bounds */
ds@1952
   415
#define sSYMBOLIC       2       /* bit position in "debug" variable: symbolic info */
ds@1952
   416
#define sRESET          0       /* reset error flag */
ds@1952
   417
#define sFORCESET       1       /* force error flag on */
ds@1952
   418
#define sEXPRMARK       2       /* mark start of expression */
ds@1952
   419
#define sEXPRRELEASE    3       /* mark end of expression */
ds@1952
   420
#define sSETPOS         4       /* set line number for the error */
ds@1952
   421
ds@1952
   422
enum {
ds@1952
   423
  sOPTIMIZE_NONE,               /* no optimization */
ds@1952
   424
  sOPTIMIZE_NOMACRO,            /* no macro instructions */
ds@1952
   425
  sOPTIMIZE_DEFAULT,            /* full optimization */
ds@1952
   426
  /* ----- */
ds@1952
   427
  sOPTIMIZE_NUMBER
ds@1952
   428
};
ds@1952
   429
ds@1952
   430
typedef enum s_regid {
ds@1952
   431
  sPRI,                         /* indicates the primary register */
ds@1952
   432
  sALT,                         /* indicates the secundary register */
ds@1952
   433
} regid;
ds@1952
   434
ds@1952
   435
typedef enum s_optmark {
ds@1952
   436
  sEXPR,                        /* end of expression (for expressions that form a statement) */
ds@1952
   437
  sPARM,                        /* end of parameter (in a function parameter list) */
ds@1952
   438
  sLDECL,                       /* start of local declaration (variable) */
ds@1952
   439
} optmark;
ds@1952
   440
ds@1952
   441
#define suSLEEP_INSTR 0x01      /* the "sleep" instruction was used */
ds@1952
   442
ds@1952
   443
#if INT_MAX<0x8000u
ds@1952
   444
  #define PUBLICTAG   0x8000u
ds@1952
   445
  #define FIXEDTAG    0x4000u
ds@1952
   446
  #define FUNCTAG     0x2000u
ds@1952
   447
#else
ds@1952
   448
  #define PUBLICTAG   0x80000000Lu
ds@1952
   449
  #define FIXEDTAG    0x40000000Lu
ds@1952
   450
  #define FUNCTAG     0x20000000Lu
ds@1952
   451
#endif
ds@1952
   452
#define TAGMASK       (~PUBLICTAG)
ds@1952
   453
#define CELL_MAX      (((ucell)1 << (sizeof(cell)*8-1)) - 1)
ds@1952
   454
ds@1952
   455
ds@1952
   456
/* interface functions */
ds@1952
   457
#if defined __cplusplus
ds@1952
   458
  extern "C" {
ds@1952
   459
#endif
ds@1952
   460
ds@1952
   461
/*
ds@1952
   462
 * Functions you call from the "driver" program
ds@1952
   463
 */
ds@1952
   464
int pc_compile(int argc, char **argv);
ds@1952
   465
int pc_addconstant(char *name,cell value,int tag);
ds@1952
   466
int pc_addtag(char *name);
ds@1952
   467
int pc_addfunctag(char *name);
ds@1952
   468
int pc_enablewarning(int number,int enable);
ds@1952
   469
ds@1952
   470
/*
ds@1952
   471
 * Functions called from the compiler (to be implemented by you)
ds@1952
   472
 */
ds@1952
   473
ds@1952
   474
/* general console output */
ds@1952
   475
int pc_printf(const char *message,...);
ds@1952
   476
ds@1952
   477
/* error report function */
ds@1952
   478
int pc_error(int number,char *message,char *filename,int firstline,int lastline,va_list argptr);
ds@1952
   479
ds@1952
   480
/* input from source file */
ds@1952
   481
void *pc_opensrc(char *filename); /* reading only */
ds@1952
   482
void *pc_createsrc(char *filename);
ds@1952
   483
void pc_closesrc(void *handle);   /* never delete */
ds@1952
   484
void pc_resetsrc(void *handle,void *position);  /* reset to a position marked earlier */
ds@1952
   485
char *pc_readsrc(void *handle,unsigned char *target,int maxchars);
ds@1952
   486
int pc_writesrc(void *handle,unsigned char *source);
ds@1952
   487
void *pc_getpossrc(void *handle); /* mark the current position */
ds@1952
   488
int  pc_eofsrc(void *handle);
ds@1952
   489
ds@1952
   490
/* output to intermediate (.ASM) file */
ds@1952
   491
void *pc_openasm(char *filename); /* read/write */
ds@1952
   492
void pc_closeasm(void *handle,int deletefile);
ds@1952
   493
void pc_resetasm(void *handle);
ds@1952
   494
int  pc_writeasm(void *handle,char *str);
ds@1952
   495
char *pc_readasm(void *handle,char *target,int maxchars);
ds@1952
   496
ds@1952
   497
/* output to binary (.AMX) file */
ds@1952
   498
void *pc_openbin(char *filename);
ds@1952
   499
void pc_closebin(void *handle,int deletefile);
ds@1952
   500
void pc_resetbin(void *handle,long offset);
ds@1952
   501
int  pc_writebin(void *handle,void *buffer,int size);
ds@1952
   502
long pc_lengthbin(void *handle); /* return the length of the file */
ds@1952
   503
ds@1952
   504
#if defined __cplusplus
ds@1952
   505
  }
ds@1952
   506
#endif
ds@1952
   507
ds@1952
   508
ds@1952
   509
/* by default, functions and variables used in throughout the compiler
ds@1952
   510
 * files are "external"
ds@1952
   511
 */
ds@1952
   512
#if !defined SC_FUNC
ds@1952
   513
  #define SC_FUNC
ds@1952
   514
#endif
ds@1952
   515
#if !defined SC_VDECL
ds@1952
   516
  #define SC_VDECL  extern
ds@1952
   517
#endif
ds@1952
   518
#if !defined SC_VDEFINE
ds@1952
   519
  #define SC_VDEFINE
ds@1952
   520
#endif
ds@1952
   521
ds@1952
   522
/* function prototypes in SC1.C */
ds@1952
   523
SC_FUNC void set_extension(char *filename,char *extension,int force);
ds@1952
   524
SC_FUNC symbol *fetchfunc(char *name,int tag);
ds@1952
   525
SC_FUNC char *operator_symname(char *symname,char *opername,int tag1,int tag2,int numtags,int resulttag);
ds@1952
   526
SC_FUNC char *funcdisplayname(char *dest,char *funcname);
ds@1952
   527
SC_FUNC int constexpr(cell *val,int *tag,symbol **symptr);
ds@1952
   528
SC_FUNC constvalue *append_constval(constvalue *table,const char *name,cell val,int index);
ds@1952
   529
SC_FUNC constvalue *find_constval(constvalue *table,char *name,int index);
ds@1952
   530
SC_FUNC void delete_consttable(constvalue *table);
ds@1952
   531
SC_FUNC symbol *add_constant(char *name,cell val,int vclass,int tag);
ds@1952
   532
SC_FUNC void exporttag(int tag);
ds@1952
   533
SC_FUNC void sc_attachdocumentation(symbol *sym);
ds@1952
   534
SC_FUNC constvalue *find_tag_byval(int tag);
ds@1952
   535
ds@1952
   536
/* function prototypes in SC2.C */
ds@1952
   537
#define PUSHSTK_P(v)  { stkitem s_; s_.pv=(v); pushstk(s_); }
ds@1952
   538
#define PUSHSTK_I(v)  { stkitem s_; s_.i=(v); pushstk(s_); }
ds@1952
   539
#define POPSTK_P()    (popstk().pv)
ds@1952
   540
#define POPSTK_I()    (popstk().i)
ds@1952
   541
SC_FUNC void pushstk(stkitem val);
ds@1952
   542
SC_FUNC stkitem popstk(void);
ds@1952
   543
SC_FUNC void clearstk(void);
ds@1952
   544
SC_FUNC int plungequalifiedfile(char *name);  /* explicit path included */
ds@1952
   545
SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths);   /* search through "include" paths */
ds@1952
   546
SC_FUNC void preprocess(void);
ds@1952
   547
SC_FUNC void lexinit(void);
ds@1952
   548
SC_FUNC int lex(cell *lexvalue,char **lexsym);
ds@1952
   549
SC_FUNC void lexpush(void);
ds@1952
   550
SC_FUNC void lexclr(int clreol);
ds@1952
   551
SC_FUNC int matchtoken(int token);
ds@1952
   552
SC_FUNC int tokeninfo(cell *val,char **str);
ds@1952
   553
SC_FUNC int needtoken(int token);
ds@1952
   554
SC_FUNC void litadd(cell value);
ds@1952
   555
SC_FUNC void litinsert(cell value,int pos);
ds@1952
   556
SC_FUNC int alphanum(char c);
ds@1952
   557
SC_FUNC int ishex(char c);
ds@1952
   558
SC_FUNC void delete_symbol(symbol *root,symbol *sym);
ds@1952
   559
SC_FUNC void delete_symbols(symbol *root,int level,int del_labels,int delete_functions);
ds@1952
   560
SC_FUNC int refer_symbol(symbol *entry,symbol *bywhom);
ds@1952
   561
SC_FUNC void markusage(symbol *sym,int usage);
ds@1952
   562
SC_FUNC uint32_t namehash(const char *name);
ds@1952
   563
SC_FUNC symbol *findglb(const char *name,int filter);
ds@1952
   564
SC_FUNC symbol *findloc(const char *name);
ds@1952
   565
SC_FUNC symbol *findconst(const char *name,int *matchtag);
ds@1952
   566
SC_FUNC symbol *finddepend(const symbol *parent);
ds@1952
   567
SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,
ds@1952
   568
                       int usage);
ds@1952
   569
SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
ds@1952
   570
                            int dim[],int numdim,int idxtag[]);
ds@1952
   571
SC_FUNC symbol *addvariable2(const char *name,cell addr,int ident,int vclass,int tag,
ds@1952
   572
							 int dim[],int numdim,int idxtag[],int slength);
ds@1952
   573
SC_FUNC int getlabel(void);
ds@1952
   574
SC_FUNC char *itoh(ucell val);
ds@1952
   575
ds@1952
   576
/* function prototypes in SC3.C */
ds@1952
   577
SC_FUNC int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
ds@1952
   578
                         value *lval,int *resulttag);
ds@1952
   579
SC_FUNC int matchtag(int formaltag,int actualtag,int allowcoerce);
ds@1952
   580
SC_FUNC int checktag(int tags[],int numtags,int exprtag);
ds@1952
   581
SC_FUNC int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult,value *_lval);
ds@1952
   582
SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state);
ds@1952
   583
SC_FUNC cell array_totalsize(symbol *sym);
ds@1952
   584
SC_FUNC int matchtag_string(int ident, int tag);
ds@1952
   585
SC_FUNC int checktag_string(value *sym1, value *sym2);
ds@1952
   586
SC_FUNC int checktags_string(int tags[], int numtags, value *sym1);
ds@1952
   587
ds@1952
   588
/* function prototypes in SC4.C */
ds@1952
   589
SC_FUNC void writeleader(symbol *root);
ds@1952
   590
SC_FUNC void writetrailer(void);
ds@1952
   591
SC_FUNC void begcseg(void);
ds@1952
   592
SC_FUNC void begdseg(void);
ds@1952
   593
SC_FUNC void setline(int chkbounds);
ds@1952
   594
SC_FUNC void setfiledirect(char *name);
ds@1952
   595
SC_FUNC void setlinedirect(int line);
ds@1952
   596
SC_FUNC void setlabel(int index);
ds@1952
   597
SC_FUNC void markexpr(optmark type,const char *name,cell offset);
ds@1952
   598
SC_FUNC void startfunc(char *fname);
ds@1952
   599
SC_FUNC void endfunc(void);
ds@1952
   600
SC_FUNC void alignframe(int numbytes);
ds@1952
   601
SC_FUNC void rvalue(value *lval);
ds@1952
   602
SC_FUNC void address(symbol *ptr,regid reg);
ds@1952
   603
SC_FUNC void store(value *lval);
ds@1952
   604
SC_FUNC void loadreg(cell address,regid reg);
ds@1952
   605
SC_FUNC void storereg(cell address,regid reg);
ds@1952
   606
SC_FUNC void memcopy(cell size);
ds@1952
   607
SC_FUNC void copyarray(symbol *sym,cell size);
ds@1952
   608
SC_FUNC void fillarray(symbol *sym,cell size,cell value);
ds@1952
   609
SC_FUNC void ldconst(cell val,regid reg);
ds@1952
   610
SC_FUNC void moveto1(void);
ds@1952
   611
SC_FUNC void pushreg(regid reg);
ds@1952
   612
SC_FUNC void pushval(cell val);
ds@1952
   613
SC_FUNC void popreg(regid reg);
ds@1952
   614
SC_FUNC void genarray(int dims, int _autozero);
ds@1952
   615
SC_FUNC void swap1(void);
ds@1952
   616
SC_FUNC void ffswitch(int label);
ds@1952
   617
SC_FUNC void ffcase(cell value,char *labelname,int newtable);
ds@1952
   618
SC_FUNC void ffcall(symbol *sym,const char *label,int numargs);
ds@1952
   619
SC_FUNC void ffret(int remparams);
ds@1952
   620
SC_FUNC void ffabort(int reason);
ds@1952
   621
SC_FUNC void ffbounds(cell size);
ds@1952
   622
SC_FUNC void jumplabel(int number);
ds@1952
   623
SC_FUNC void defstorage(void);
ds@1952
   624
SC_FUNC void modstk(int delta);
ds@1952
   625
SC_FUNC void setstk(cell value);
ds@1952
   626
SC_FUNC void modheap(int delta);
ds@1952
   627
SC_FUNC void modheap_i();
ds@1952
   628
SC_FUNC void setheap_pri(void);
ds@1952
   629
SC_FUNC void setheap(cell value);
ds@1952
   630
SC_FUNC void cell2addr(void);
ds@1952
   631
SC_FUNC void cell2addr_alt(void);
ds@1952
   632
SC_FUNC void addr2cell(void);
ds@1952
   633
SC_FUNC void char2addr(void);
ds@1952
   634
SC_FUNC void charalign(void);
ds@1952
   635
SC_FUNC void addconst(cell value);
ds@1952
   636
SC_FUNC void setheap_save(cell value);
ds@1952
   637
SC_FUNC void stradjust(regid reg);
ds@1952
   638
ds@1952
   639
/*  Code generation functions for arithmetic operators.
ds@1952
   640
 *
ds@1952
   641
 *  Syntax: o[u|s|b]_name
ds@1952
   642
 *          |   |   | +--- name of operator
ds@1952
   643
 *          |   |   +----- underscore
ds@1952
   644
 *          |   +--------- "u"nsigned operator, "s"igned operator or "b"oth
ds@1952
   645
 *          +------------- "o"perator
ds@1952
   646
 */
ds@1952
   647
SC_FUNC void os_mult(void); /* multiplication (signed) */
ds@1952
   648
SC_FUNC void os_div(void);  /* division (signed) */
ds@1952
   649
SC_FUNC void os_mod(void);  /* modulus (signed) */
ds@1952
   650
SC_FUNC void ob_add(void);  /* addition */
ds@1952
   651
SC_FUNC void ob_sub(void);  /* subtraction */
ds@1952
   652
SC_FUNC void ob_sal(void);  /* shift left (arithmetic) */
ds@1952
   653
SC_FUNC void os_sar(void);  /* shift right (arithmetic, signed) */
ds@1952
   654
SC_FUNC void ou_sar(void);  /* shift right (logical, unsigned) */
ds@1952
   655
SC_FUNC void ob_or(void);   /* bitwise or */
ds@1952
   656
SC_FUNC void ob_xor(void);  /* bitwise xor */
ds@1952
   657
SC_FUNC void ob_and(void);  /* bitwise and */
ds@1952
   658
SC_FUNC void ob_eq(void);   /* equality */
ds@1952
   659
SC_FUNC void ob_ne(void);   /* inequality */
ds@1952
   660
SC_FUNC void relop_prefix(void);
ds@1952
   661
SC_FUNC void relop_suffix(void);
ds@1952
   662
SC_FUNC void os_le(void);   /* less or equal (signed) */
ds@1952
   663
SC_FUNC void os_ge(void);   /* greater or equal (signed) */
ds@1952
   664
SC_FUNC void os_lt(void);   /* less (signed) */
ds@1952
   665
SC_FUNC void os_gt(void);   /* greater (signed) */
ds@1952
   666
ds@1952
   667
SC_FUNC void lneg(void);
ds@1952
   668
SC_FUNC void neg(void);
ds@1952
   669
SC_FUNC void invert(void);
ds@1952
   670
SC_FUNC void nooperation(void);
ds@1952
   671
SC_FUNC void inc(value *lval);
ds@1952
   672
SC_FUNC void dec(value *lval);
ds@1952
   673
SC_FUNC void jmp_ne0(int number);
ds@1952
   674
SC_FUNC void jmp_eq0(int number);
ds@1952
   675
SC_FUNC void outval(cell val,int newline);
ds@1952
   676
ds@1952
   677
/* function prototypes in SC5.C */
ds@1952
   678
SC_FUNC int error(int number,...);
ds@1952
   679
SC_FUNC void errorset(int code,int line);
ds@1952
   680
ds@1952
   681
/* function prototypes in SC6.C */
ds@1952
   682
SC_FUNC int assemble(FILE *fout,FILE *fin);
ds@1952
   683
ds@1952
   684
/* function prototypes in SC7.C */
ds@1952
   685
SC_FUNC void stgbuffer_cleanup(void);
ds@1952
   686
SC_FUNC void stgmark(char mark);
ds@1952
   687
SC_FUNC void stgwrite(const char *st);
ds@1952
   688
SC_FUNC void stgout(int index);
ds@1952
   689
SC_FUNC void stgdel(int index,cell code_index);
ds@1952
   690
SC_FUNC int stgget(int *index,cell *code_index);
ds@1952
   691
SC_FUNC void stgset(int onoff);
ds@1952
   692
SC_FUNC int phopt_init(void);
ds@1952
   693
SC_FUNC int phopt_cleanup(void);
ds@1952
   694
ds@1952
   695
/* function prototypes in SCLIST.C */
ds@1952
   696
SC_FUNC char* duplicatestring(const char* sourcestring);
ds@1952
   697
SC_FUNC stringpair *insert_alias(char *name,char *alias);
ds@1952
   698
SC_FUNC stringpair *find_alias(char *name);
ds@1952
   699
SC_FUNC int lookup_alias(char *target,char *name);
ds@1952
   700
SC_FUNC void delete_aliastable(void);
ds@1952
   701
SC_FUNC stringlist *insert_path(char *path);
ds@1952
   702
SC_FUNC char *get_path(int index);
ds@1952
   703
SC_FUNC void delete_pathtable(void);
ds@1952
   704
SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen);
ds@1952
   705
SC_FUNC int get_subst(int index,char **pattern,char **substitution);
ds@1952
   706
SC_FUNC stringpair *find_subst(char *name,int length);
ds@1952
   707
SC_FUNC int delete_subst(char *name,int length);
ds@1952
   708
SC_FUNC void delete_substtable(void);
ds@1952
   709
SC_FUNC stringlist *insert_sourcefile(char *string);
ds@1952
   710
SC_FUNC char *get_sourcefile(int index);
ds@1952
   711
SC_FUNC void delete_sourcefiletable(void);
ds@1952
   712
SC_FUNC stringlist *insert_docstring(char *string);
ds@1952
   713
SC_FUNC char *get_docstring(int index);
ds@1952
   714
SC_FUNC void delete_docstring(int index);
ds@1952
   715
SC_FUNC void delete_docstringtable(void);
ds@1952
   716
SC_FUNC stringlist *insert_autolist(char *string);
ds@1952
   717
SC_FUNC char *get_autolist(int index);
ds@1952
   718
SC_FUNC void delete_autolisttable(void);
ds@1952
   719
SC_FUNC stringlist *insert_dbgfile(const char *filename);
ds@1952
   720
SC_FUNC stringlist *insert_dbgline(int linenr);
ds@1952
   721
SC_FUNC stringlist *insert_dbgsymbol(symbol *sym);
ds@1952
   722
SC_FUNC char *get_dbgstring(int index);
ds@1952
   723
SC_FUNC void delete_dbgstringtable(void);
ds@1952
   724
ds@1952
   725
/* function prototypes in SCMEMFILE.C */
ds@1952
   726
#if !defined tMEMFILE
ds@1952
   727
  typedef unsigned char MEMFILE;
ds@1952
   728
  #define tMEMFILE  1
ds@1952
   729
#endif
ds@1952
   730
MEMFILE *mfcreate(const char *filename);
ds@1952
   731
void mfclose(MEMFILE *mf);
ds@1952
   732
int mfdump(MEMFILE *mf);
ds@1952
   733
long mflength(const MEMFILE *mf);
ds@1952
   734
long mfseek(MEMFILE *mf,long offset,int whence);
ds@1952
   735
unsigned int mfwrite(MEMFILE *mf,const unsigned char *buffer,unsigned int size);
ds@1952
   736
unsigned int mfread(MEMFILE *mf,unsigned char *buffer,unsigned int size);
ds@1952
   737
char *mfgets(MEMFILE *mf,char *string,unsigned int size);
ds@1952
   738
int mfputs(MEMFILE *mf,const char *string);
ds@1952
   739
ds@1952
   740
/* function prototypes in SCI18N.C */
ds@1952
   741
#define MAXCODEPAGE 12
ds@1952
   742
SC_FUNC int cp_path(const char *root,const char *directory);
ds@1952
   743
SC_FUNC int cp_set(const char *name);
ds@1952
   744
SC_FUNC cell cp_translate(const unsigned char *string,const unsigned char **endptr);
ds@1952
   745
SC_FUNC cell get_utf8_char(const unsigned char *string,const unsigned char **endptr);
ds@1952
   746
SC_FUNC int scan_utf8(FILE *fp,const char *filename);
ds@1952
   747
ds@1952
   748
/* function prototypes in SCSTATE.C */
ds@1952
   749
SC_FUNC constvalue *automaton_add(const char *name);
ds@1952
   750
SC_FUNC constvalue *automaton_find(const char *name);
ds@1952
   751
SC_FUNC constvalue *automaton_findid(int id);
ds@1952
   752
SC_FUNC constvalue *state_add(const char *name,int fsa_id);
ds@1952
   753
SC_FUNC constvalue *state_find(const char *name,int fsa_id);
ds@1952
   754
SC_FUNC constvalue *state_findid(int id);
ds@1952
   755
SC_FUNC void state_buildlist(int **list,int *listsize,int *count,int stateid);
ds@1952
   756
SC_FUNC int state_addlist(int *list,int count,int fsa_id);
ds@1952
   757
SC_FUNC void state_deletetable(void);
ds@1952
   758
SC_FUNC int state_getfsa(int listid);
ds@1952
   759
SC_FUNC int state_count(int listid);
ds@1952
   760
SC_FUNC int state_inlist(int listid,int state);
ds@1952
   761
SC_FUNC int state_listitem(int listid,int index);
ds@1952
   762
SC_FUNC void state_conflict(symbol *root);
ds@1952
   763
SC_FUNC int state_conflict_id(int listid1,int listid2);
ds@1952
   764
ds@1952
   765
/* external variables (defined in scvars.c) */
ds@1952
   766
#if !defined SC_SKIP_VDECL
ds@1952
   767
SC_VDECL symbol loctab;       /* local symbol table */
ds@1952
   768
SC_VDECL symbol glbtab;       /* global symbol table */
ds@1952
   769
SC_VDECL cell *litq;          /* the literal queue */
ds@1952
   770
SC_VDECL unsigned char pline[]; /* the line read from the input file */
ds@1952
   771
SC_VDECL const unsigned char *lptr;/* points to the current position in "pline" */
ds@1952
   772
SC_VDECL constvalue tagname_tab;/* tagname table */
ds@1952
   773
SC_VDECL constvalue libname_tab;/* library table (#pragma library "..." syntax) */
ds@1952
   774
SC_VDECL constvalue *curlibrary;/* current library */
ds@1952
   775
SC_VDECL int pc_addlibtable;  /* is the library table added to the AMX file? */
ds@1952
   776
SC_VDECL symbol *curfunc;     /* pointer to current function */
ds@1952
   777
SC_VDECL char *inpfname;      /* name of the file currently read from */
ds@1952
   778
SC_VDECL char outfname[];     /* intermediate (assembler) file name */
ds@1952
   779
SC_VDECL char binfname[];     /* binary file name */
ds@1952
   780
SC_VDECL char errfname[];     /* error file name */
ds@1952
   781
SC_VDECL char sc_ctrlchar;    /* the control character (or escape character) */
ds@1952
   782
SC_VDECL char sc_ctrlchar_org;/* the default control character */
ds@1952
   783
SC_VDECL int litidx;          /* index to literal table */
ds@1952
   784
SC_VDECL int litmax;          /* current size of the literal table */
ds@1952
   785
SC_VDECL int stgidx;          /* index to the staging buffer */
ds@1952
   786
SC_VDECL int sc_labnum;       /* number of (internal) labels */
ds@1952
   787
SC_VDECL int staging;         /* true if staging output */
ds@1952
   788
SC_VDECL cell declared;       /* number of local cells declared */
ds@1952
   789
SC_VDECL cell glb_declared;   /* number of global cells declared */
ds@1952
   790
SC_VDECL cell code_idx;       /* number of bytes with generated code */
ds@1952
   791
SC_VDECL int ntv_funcid;      /* incremental number of native function */
ds@1952
   792
SC_VDECL int errnum;          /* number of errors */
ds@1952
   793
SC_VDECL int warnnum;         /* number of warnings */
ds@1952
   794
SC_VDECL int sc_debug;        /* debug/optimization options (bit field) */
ds@1952
   795
SC_VDECL int sc_packstr;      /* strings are packed by default? */
ds@1952
   796
SC_VDECL int sc_asmfile;      /* create .ASM file? */
ds@1952
   797
SC_VDECL int sc_listing;      /* create .LST file? */
ds@1952
   798
SC_VDECL int sc_compress;     /* compress bytecode? */
ds@1952
   799
SC_VDECL int sc_needsemicolon;/* semicolon required to terminate expressions? */
ds@1952
   800
SC_VDECL int sc_dataalign;    /* data alignment value */
ds@1952
   801
SC_VDECL int sc_alignnext;    /* must frame of the next function be aligned? */
ds@1952
   802
SC_VDECL int pc_docexpr;      /* must expression be attached to documentation comment? */
ds@1952
   803
SC_VDECL int curseg;          /* 1 if currently parsing CODE, 2 if parsing DATA */
ds@1952
   804
SC_VDECL cell pc_stksize;     /* stack size */
ds@1952
   805
SC_VDECL cell pc_amxlimit;    /* abstract machine size limit (code + data, or only code) */
ds@1952
   806
SC_VDECL cell pc_amxram;      /* abstract machine data size limit */
ds@1952
   807
SC_VDECL int freading;        /* is there an input file ready for reading? */
ds@1952
   808
SC_VDECL int fline;           /* the line number in the current file */
ds@1952
   809
SC_VDECL short fnumber;       /* number of files in the file table (debugging) */
ds@1952
   810
SC_VDECL short fcurrent;      /* current file being processed (debugging) */
ds@1952
   811
SC_VDECL short sc_intest;     /* true if inside a test */
ds@1952
   812
SC_VDECL int sideeffect;      /* true if an expression causes a side-effect */
ds@1952
   813
SC_VDECL int stmtindent;      /* current indent of the statement */
ds@1952
   814
SC_VDECL int indent_nowarn;   /* skip warning "217 loose indentation" */
ds@1952
   815
SC_VDECL int sc_tabsize;      /* number of spaces that a TAB represents */
ds@1952
   816
SC_VDECL short sc_allowtags;  /* allow/detect tagnames in lex() */
ds@1952
   817
SC_VDECL int sc_status;       /* read/write status */
ds@1952
   818
SC_VDECL int sc_rationaltag;  /* tag for rational numbers */
ds@1952
   819
SC_VDECL int rational_digits; /* number of fractional digits */
ds@1952
   820
SC_VDECL int sc_allowproccall;/* allow/detect tagnames in lex() */
ds@1952
   821
SC_VDECL short sc_is_utf8;    /* is this source file in UTF-8 encoding */
ds@1952
   822
SC_VDECL char *pc_deprecate;  /* if non-NULL, mark next declaration as deprecated */
ds@1952
   823
SC_VDECL int sc_curstates;    /* ID of the current state list */
ds@1952
   824
SC_VDECL int pc_optimize;     /* (peephole) optimization level */
ds@1952
   825
SC_VDECL int pc_memflags;     /* special flags for the stack/heap usage */
ds@1952
   826
SC_VDECL int pc_functag;      /* global function tag */
ds@1952
   827
SC_VDECL int pc_tag_string;   /* global string tag */
ds@1952
   828
SC_VDECL int pc_anytag;       /* global any tag */
ds@1952
   829
SC_VDECL int glbstringread;	  /* last global string read */
ds@1952
   830
ds@1952
   831
SC_VDECL constvalue sc_automaton_tab; /* automaton table */
ds@1952
   832
SC_VDECL constvalue sc_state_tab;     /* state table */
ds@1952
   833
ds@1952
   834
SC_VDECL FILE *inpf;          /* file read from (source or include) */
ds@1952
   835
SC_VDECL FILE *inpf_org;      /* main source file */
ds@1952
   836
SC_VDECL FILE *outf;          /* file written to */
ds@1952
   837
ds@1952
   838
SC_VDECL jmp_buf errbuf;      /* target of longjmp() on a fatal error */
ds@1952
   839
ds@1952
   840
#if !defined SC_LIGHT
ds@1952
   841
  SC_VDECL int sc_makereport; /* generate a cross-reference report */
ds@1952
   842
#endif
ds@1952
   843
ds@1952
   844
#if defined WIN32
ds@1952
   845
#if !defined snprintf
ds@1952
   846
#define snprintf _snprintf
ds@1952
   847
#endif
ds@1952
   848
#endif
ds@1952
   849
ds@1952
   850
#endif /* SC_SKIP_VDECL */
ds@1952
   851
ds@1952
   852
typedef struct array_info_s
ds@1952
   853
{
ds@1952
   854
  const int *dim_list;				/* Dimension sizes */
ds@1952
   855
  int dim_count;					/* Number of dimensions */
ds@1952
   856
  const int *lastdim_list;			/* Sizes of last dimensions, if variable */
ds@1952
   857
  const cell *dim_offs_precalc;		/* Cached calculations into the lastdim_list array */
ds@1952
   858
  cell *data_offs;					/* Current offset AFTER the indirection vectors (data) */
ds@1952
   859
  int *cur_dims;					/* Current dimensions the recursion is at */
ds@1952
   860
  cell *base;						/* &litq[startlit] */
ds@1952
   861
} array_info_t;
ds@1952
   862
ds@1952
   863
#endif /* SC_H_INCLUDED */