1.1 --- a/compiler-init/sc.h Sat Jul 15 05:02:38 2006 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,813 +0,0 @@
1.4 -/* Pawn compiler
1.5 - *
1.6 - * Drafted after the Small-C compiler Version 2.01, originally created
1.7 - * by Ron Cain, july 1980, and enhanced by James E. Hendrix.
1.8 - *
1.9 - * This version comes close to a complete rewrite.
1.10 - *
1.11 - * Copyright R. Cain, 1980
1.12 - * Copyright J.E. Hendrix, 1982, 1983
1.13 - * Copyright ITB CompuPhase, 1997-2006
1.14 - *
1.15 - * This software is provided "as-is", without any express or implied warranty.
1.16 - * In no event will the authors be held liable for any damages arising from
1.17 - * the use of this software.
1.18 - *
1.19 - * Permission is granted to anyone to use this software for any purpose,
1.20 - * including commercial applications, and to alter it and redistribute it
1.21 - * freely, subject to the following restrictions:
1.22 - *
1.23 - * 1. The origin of this software must not be misrepresented; you must not
1.24 - * claim that you wrote the original software. If you use this software in
1.25 - * a product, an acknowledgment in the product documentation would be
1.26 - * appreciated but is not required.
1.27 - * 2. Altered source versions must be plainly marked as such, and must not be
1.28 - * misrepresented as being the original software.
1.29 - * 3. This notice may not be removed or altered from any source distribution.
1.30 - *
1.31 - * Version: $Id: sc.h 3590 2006-06-24 14:16:39Z thiadmer $
1.32 - */
1.33 -#ifndef SC_H_INCLUDED
1.34 -#define SC_H_INCLUDED
1.35 -#include <limits.h>
1.36 -#include <stdarg.h>
1.37 -#include <stdio.h>
1.38 -#if defined __BORLANDC__ && defined _Windows && !(defined __32BIT__ || defined __WIN32__)
1.39 - /* setjmp() and longjmp() not well supported in 16-bit windows */
1.40 - #include <windows.h>
1.41 - typedef int jmp_buf[9];
1.42 - #define setjmp(b) Catch(b)
1.43 - #define longjmp(b,e) Throw(b,e)
1.44 -#else
1.45 - #include <setjmp.h>
1.46 -#endif
1.47 -#include "osdefs.h"
1.48 -#include "amx.h"
1.49 -
1.50 -/* Note: the "cell" and "ucell" types are defined in AMX.H */
1.51 -
1.52 -#define PUBLIC_CHAR '@' /* character that defines a function "public" */
1.53 -#define CTRL_CHAR '\\' /* default control character */
1.54 -#define sCHARBITS 8 /* size of a packed character */
1.55 -
1.56 -#define sDIMEN_MAX 4 /* maximum number of array dimensions */
1.57 -#define sLINEMAX 1023 /* input line length (in characters) */
1.58 -#define sCOMP_STACK 32 /* maximum nesting of #if .. #endif sections */
1.59 -#define sDEF_LITMAX 500 /* initial size of the literal pool, in "cells" */
1.60 -#define sDEF_AMXSTACK 4096 /* default stack size for AMX files */
1.61 -#define PREPROC_TERM '\x7f'/* termination character for preprocessor expressions (the "DEL" code) */
1.62 -#define sDEF_PREFIX "sourcemod.inc" /* default prefix filename */
1.63 -
1.64 -typedef union {
1.65 - void *pv; /* e.g. a name */
1.66 - int i;
1.67 -} stkitem; /* type of items stored on the compiler stack */
1.68 -
1.69 -typedef struct s_arginfo { /* function argument info */
1.70 - char name[sNAMEMAX+1];
1.71 - char ident; /* iVARIABLE, iREFERENCE, iREFARRAY or iVARARGS */
1.72 - char usage; /* uCONST */
1.73 - int *tags; /* argument tag id. list */
1.74 - int numtags; /* number of tags in the tag list */
1.75 - int dim[sDIMEN_MAX];
1.76 - int idxtag[sDIMEN_MAX];
1.77 - int numdim; /* number of dimensions */
1.78 - unsigned char hasdefault; /* bit0: is there a default value? bit6: "tagof"; bit7: "sizeof" */
1.79 - union {
1.80 - cell val; /* default value */
1.81 - struct {
1.82 - char *symname; /* name of another symbol */
1.83 - short level; /* indirection level for that symbol */
1.84 - } size; /* used for "sizeof" default value */
1.85 - struct {
1.86 - cell *data; /* values of default array */
1.87 - int size; /* complete length of default array */
1.88 - int arraysize; /* size to reserve on the heap */
1.89 - cell addr; /* address of the default array in the data segment */
1.90 - } array;
1.91 - } defvalue; /* default value, or pointer to default array */
1.92 - int defvalue_tag; /* tag of the default value */
1.93 -} arginfo;
1.94 -
1.95 -/* Equate table, tagname table, library table */
1.96 -typedef struct s_constvalue {
1.97 - struct s_constvalue *next;
1.98 - char name[sNAMEMAX+1];
1.99 - cell value;
1.100 - int index; /* index level, for constants referring to array sizes/tags
1.101 - * automaton id. for states and automatons
1.102 - * tag for enumeration lists */
1.103 -} constvalue;
1.104 -
1.105 -/* Symbol table format
1.106 - *
1.107 - * The symbol name read from the input file is stored in "name", the
1.108 - * value of "addr" is written to the output file. The address in "addr"
1.109 - * depends on the class of the symbol:
1.110 - * global offset into the data segment
1.111 - * local offset relative to the stack frame
1.112 - * label generated hexadecimal number
1.113 - * function offset into code segment
1.114 - */
1.115 -typedef struct s_symbol {
1.116 - struct s_symbol *next;
1.117 - struct s_symbol *parent; /* hierarchical types (multi-dimensional arrays) */
1.118 - char name[sNAMEMAX+1];
1.119 - uint32_t hash; /* value derived from name, for quicker searching */
1.120 - cell addr; /* address or offset (or value for constant, index for native function) */
1.121 - cell codeaddr; /* address (in the code segment) where the symbol declaration starts */
1.122 - char vclass; /* sLOCAL if "addr" refers to a local symbol */
1.123 - char ident; /* see below for possible values */
1.124 - short usage; /* see below for possible values */
1.125 - char flags; /* see below for possible values */
1.126 - int compound; /* compound level (braces nesting level) */
1.127 - int tag; /* tagname id */
1.128 - union {
1.129 - int declared; /* label: how many local variables are declared */
1.130 - struct {
1.131 - int index; /* array & enum: tag of array indices or the enum item */
1.132 - int field; /* enumeration fields, where a size is attached to the field */
1.133 - } tags; /* extra tags */
1.134 - constvalue *lib; /* native function: library it is part of */
1.135 - long stacksize; /* normal/public function: stack requirements */
1.136 - } x; /* 'x' for 'extra' */
1.137 - union {
1.138 - arginfo *arglist; /* types of all parameters for functions */
1.139 - constvalue *enumlist;/* list of names for the "root" of an enumeration */
1.140 - struct {
1.141 - cell length; /* arrays: length (size) */
1.142 - short level; /* number of dimensions below this level */
1.143 - } array;
1.144 - } dim; /* for 'dimension', both functions and arrays */
1.145 - constvalue *states; /* list of state function/state variable ids + addresses */
1.146 - int fnumber; /* static global variables: file number in which the declaration is visible */
1.147 - int lnumber; /* line number (in the current source file) for the declaration */
1.148 - struct s_symbol **refer; /* referrer list, functions that "use" this symbol */
1.149 - int numrefers; /* number of entries in the referrer list */
1.150 - char *documentation; /* optional documentation string */
1.151 -} symbol;
1.152 -
1.153 -
1.154 -/* Possible entries for "ident". These are used in the "symbol", "value"
1.155 - * and arginfo structures. Not every constant is valid for every use.
1.156 - * In an argument list, the list is terminated with a "zero" ident; labels
1.157 - * cannot be passed as function arguments, so the value 0 is overloaded.
1.158 - */
1.159 -#define iLABEL 0
1.160 -#define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */
1.161 -#define iREFERENCE 2 /* iVARIABLE, but must be dereferenced */
1.162 -#define iARRAY 3
1.163 -#define iREFARRAY 4 /* an array passed by reference (i.e. a pointer) */
1.164 -#define iARRAYCELL 5 /* array element, cell that must be fetched indirectly */
1.165 -#define iARRAYCHAR 6 /* array element, character from cell from array */
1.166 -#define iEXPRESSION 7 /* expression result, has no address (rvalue) */
1.167 -#define iCONSTEXPR 8 /* constant expression (or constant symbol) */
1.168 -#define iFUNCTN 9
1.169 -#define iREFFUNC 10
1.170 -#define iVARARGS 11 /* function specified ... as argument(s) */
1.171 -
1.172 -/* Possible entries for "usage"
1.173 - *
1.174 - * This byte is used as a serie of bits, the syntax is different for
1.175 - * functions and other symbols:
1.176 - *
1.177 - * VARIABLE
1.178 - * bits: 0 (uDEFINE) the variable is defined in the source file
1.179 - * 1 (uREAD) the variable is "read" (accessed) in the source file
1.180 - * 2 (uWRITTEN) the variable is altered (assigned a value)
1.181 - * 3 (uCONST) the variable is constant (may not be assigned to)
1.182 - * 4 (uPUBLIC) the variable is public
1.183 - * 6 (uSTOCK) the variable is discardable (without warning)
1.184 - *
1.185 - * FUNCTION
1.186 - * bits: 0 (uDEFINE) the function is defined ("implemented") in the source file
1.187 - * 1 (uREAD) the function is invoked in the source file
1.188 - * 2 (uRETVALUE) the function returns a value (or should return a value)
1.189 - * 3 (uPROTOTYPED) the function was prototyped (implicitly via a definition or explicitly)
1.190 - * 4 (uPUBLIC) the function is public
1.191 - * 5 (uNATIVE) the function is native
1.192 - * 6 (uSTOCK) the function is discardable (without warning)
1.193 - * 7 (uMISSING) the function is not implemented in this source file
1.194 - * 8 (uFORWARD) the function is explicitly forwardly declared
1.195 - *
1.196 - * CONSTANT
1.197 - * bits: 0 (uDEFINE) the symbol is defined in the source file
1.198 - * 1 (uREAD) the constant is "read" (accessed) in the source file
1.199 - * 2 (uWRITTEN) redundant, but may be set for constants passed by reference
1.200 - * 3 (uPREDEF) the constant is pre-defined and should be kept between passes
1.201 - * 5 (uENUMROOT) the constant is the "root" of an enumeration
1.202 - * 6 (uENUMFIELD) the constant is a field in a named enumeration
1.203 - */
1.204 -#define uDEFINE 0x001
1.205 -#define uREAD 0x002
1.206 -#define uWRITTEN 0x004
1.207 -#define uRETVALUE 0x004 /* function returns (or should return) a value */
1.208 -#define uCONST 0x008
1.209 -#define uPROTOTYPED 0x008
1.210 -#define uPREDEF 0x008 /* constant is pre-defined */
1.211 -#define uPUBLIC 0x010
1.212 -#define uNATIVE 0x020
1.213 -#define uENUMROOT 0x020
1.214 -#define uSTOCK 0x040
1.215 -#define uENUMFIELD 0x040
1.216 -#define uMISSING 0x080
1.217 -#define uFORWARD 0x100
1.218 -/* uRETNONE is not stored in the "usage" field of a symbol. It is
1.219 - * used during parsing a function, to detect a mix of "return;" and
1.220 - * "return value;" in a few special cases.
1.221 - */
1.222 -#define uRETNONE 0x10
1.223 -
1.224 -#define flgDEPRICATED 0x01 /* symbol is depricated (avoid use) */
1.225 -
1.226 -#define uTAGOF 0x40 /* set in the "hasdefault" field of the arginfo struct */
1.227 -#define uSIZEOF 0x80 /* set in the "hasdefault" field of the arginfo struct */
1.228 -
1.229 -#define uMAINFUNC "main"
1.230 -#define uENTRYFUNC "entry"
1.231 -
1.232 -#define sGLOBAL 0 /* global variable/constant class (no states) */
1.233 -#define sLOCAL 1 /* local variable/constant */
1.234 -#define sSTATIC 2 /* global life, local scope */
1.235 -
1.236 -#define sSTATEVAR 3 /* criterion to find variables (sSTATEVAR implies a global variable) */
1.237 -
1.238 -typedef struct s_value {
1.239 - symbol *sym; /* symbol in symbol table, NULL for (constant) expression */
1.240 - cell constval; /* value of the constant expression (if ident==iCONSTEXPR)
1.241 - * also used for the size of a literal array */
1.242 - int tag; /* tag (of the expression) */
1.243 - int cmptag; /* for searching symbols: choose the one with the matching tag */
1.244 - char ident; /* iCONSTEXPR, iVARIABLE, iARRAY, iARRAYCELL,
1.245 - * iEXPRESSION or iREFERENCE */
1.246 - char boolresult; /* boolean result for relational operators */
1.247 - cell *arrayidx; /* last used array indices, for checking self assignment */
1.248 -} value;
1.249 -
1.250 -/* "while" statement queue (also used for "for" and "do - while" loops) */
1.251 -enum {
1.252 - wqBRK, /* used to restore stack for "break" */
1.253 - wqCONT, /* used to restore stack for "continue" */
1.254 - wqLOOP, /* loop start label number */
1.255 - wqEXIT, /* loop exit label number (jump if false) */
1.256 - /* --- */
1.257 - wqSIZE /* "while queue" size */
1.258 -};
1.259 -#define wqTABSZ (24*wqSIZE) /* 24 nested loop statements */
1.260 -
1.261 -enum {
1.262 - statIDLE, /* not compiling yet */
1.263 - statFIRST, /* first pass */
1.264 - statWRITE, /* writing output */
1.265 - statSKIP, /* skipping output */
1.266 -};
1.267 -
1.268 -typedef struct s_stringlist {
1.269 - struct s_stringlist *next;
1.270 - char *line;
1.271 -} stringlist;
1.272 -
1.273 -typedef struct s_stringpair {
1.274 - struct s_stringpair *next;
1.275 - char *first;
1.276 - char *second;
1.277 - int matchlength;
1.278 -} stringpair;
1.279 -
1.280 -/* macros for code generation */
1.281 -#define opcodes(n) ((n)*sizeof(cell)) /* opcode size */
1.282 -#define opargs(n) ((n)*sizeof(cell)) /* size of typical argument */
1.283 -
1.284 -/* Tokens recognized by lex()
1.285 - * Some of these constants are assigned as well to the variable "lastst"
1.286 - */
1.287 -#define tFIRST 256 /* value of first multi-character operator */
1.288 -#define tMIDDLE 280 /* value of last multi-character operator */
1.289 -#define tLAST 326 /* value of last multi-character match-able token */
1.290 -/* multi-character operators */
1.291 -#define taMULT 256 /* *= */
1.292 -#define taDIV 257 /* /= */
1.293 -#define taMOD 258 /* %= */
1.294 -#define taADD 259 /* += */
1.295 -#define taSUB 260 /* -= */
1.296 -#define taSHL 261 /* <<= */
1.297 -#define taSHRU 262 /* >>>= */
1.298 -#define taSHR 263 /* >>= */
1.299 -#define taAND 264 /* &= */
1.300 -#define taXOR 265 /* ^= */
1.301 -#define taOR 266 /* |= */
1.302 -#define tlOR 267 /* || */
1.303 -#define tlAND 268 /* && */
1.304 -#define tlEQ 269 /* == */
1.305 -#define tlNE 270 /* != */
1.306 -#define tlLE 271 /* <= */
1.307 -#define tlGE 272 /* >= */
1.308 -#define tSHL 273 /* << */
1.309 -#define tSHRU 274 /* >>> */
1.310 -#define tSHR 275 /* >> */
1.311 -#define tINC 276 /* ++ */
1.312 -#define tDEC 277 /* -- */
1.313 -#define tELLIPS 278 /* ... */
1.314 -#define tDBLDOT 279 /* .. */
1.315 -#define tDBLCOLON 280 /* :: */
1.316 -/* reserved words (statements) */
1.317 -#define tASSERT 281
1.318 -#define tBREAK 282
1.319 -#define tCASE 283
1.320 -#define tCHAR 284
1.321 -#define tCONST 285
1.322 -#define tCONTINUE 286
1.323 -#define tDEFAULT 287
1.324 -#define tDEFINED 288
1.325 -#define tDO 289
1.326 -#define tELSE 290
1.327 -#define tENUM 291
1.328 -#define tEXIT 292
1.329 -#define tFOR 293
1.330 -#define tFORWARD 294
1.331 -#define tGOTO 295
1.332 -#define tIF 296
1.333 -#define tNATIVE 297
1.334 -#define tNEW 298
1.335 -#define tDECL 299
1.336 -#define tOPERATOR 300
1.337 -#define tPUBLIC 301
1.338 -#define tRETURN 302
1.339 -#define tSIZEOF 303
1.340 -#define tSLEEP 304
1.341 -#define tSTATE 305
1.342 -#define tSTATIC 306
1.343 -#define tSTOCK 307
1.344 -#define tSWITCH 308
1.345 -#define tTAGOF 309
1.346 -#define tWHILE 310
1.347 -/* compiler directives */
1.348 -#define tpASSERT 311 /* #assert */
1.349 -#define tpDEFINE 312
1.350 -#define tpELSE 313 /* #else */
1.351 -#define tpELSEIF 314 /* #elseif */
1.352 -#define tpEMIT 315
1.353 -#define tpENDIF 316
1.354 -#define tpENDINPUT 317
1.355 -#define tpENDSCRPT 318
1.356 -#define tpERROR 319
1.357 -#define tpFILE 320
1.358 -#define tpIF 321 /* #if */
1.359 -#define tINCLUDE 322
1.360 -#define tpLINE 323
1.361 -#define tpPRAGMA 324
1.362 -#define tpTRYINCLUDE 325
1.363 -#define tpUNDEF 326
1.364 -/* semicolon is a special case, because it can be optional */
1.365 -#define tTERM 327 /* semicolon or newline */
1.366 -#define tENDEXPR 328 /* forced end of expression */
1.367 -/* other recognized tokens */
1.368 -#define tNUMBER 329 /* integer number */
1.369 -#define tRATIONAL 330 /* rational number */
1.370 -#define tSYMBOL 331
1.371 -#define tLABEL 332
1.372 -#define tSTRING 333
1.373 -#define tEXPR 334 /* for assigment to "lastst" only */
1.374 -
1.375 -/* (reversed) evaluation of staging buffer */
1.376 -#define sSTARTREORDER 0x01
1.377 -#define sENDREORDER 0x02
1.378 -#define sEXPRSTART 0x80 /* top bit set, rest is free */
1.379 -#define sMAXARGS 127 /* relates to the bit pattern of sEXPRSTART */
1.380 -
1.381 -#define sDOCSEP 0x01 /* to separate documentation comments between functions */
1.382 -
1.383 -/* codes for ffabort() */
1.384 -#define xEXIT 1 /* exit code in PRI */
1.385 -#define xASSERTION 2 /* abort caused by failing assertion */
1.386 -#define xSTACKERROR 3 /* stack/heap overflow */
1.387 -#define xBOUNDSERROR 4 /* array index out of bounds */
1.388 -#define xMEMACCESS 5 /* data access error */
1.389 -#define xINVINSTR 6 /* invalid instruction */
1.390 -#define xSTACKUNDERFLOW 7 /* stack underflow */
1.391 -#define xHEAPUNDERFLOW 8 /* heap underflow */
1.392 -#define xCALLBACKERR 9 /* no, or invalid, callback */
1.393 -#define xSLEEP 12 /* sleep, exit code in PRI, tag in ALT */
1.394 -
1.395 -/* Miscellaneous */
1.396 -#if !defined TRUE
1.397 - #define FALSE 0
1.398 - #define TRUE 1
1.399 -#endif
1.400 -#define sIN_CSEG 1 /* if parsing CODE */
1.401 -#define sIN_DSEG 2 /* if parsing DATA */
1.402 -#define sCHKBOUNDS 1 /* bit position in "debug" variable: check bounds */
1.403 -#define sSYMBOLIC 2 /* bit position in "debug" variable: symbolic info */
1.404 -#define sRESET 0 /* reset error flag */
1.405 -#define sFORCESET 1 /* force error flag on */
1.406 -#define sEXPRMARK 2 /* mark start of expression */
1.407 -#define sEXPRRELEASE 3 /* mark end of expression */
1.408 -#define sSETPOS 4 /* set line number for the error */
1.409 -
1.410 -enum {
1.411 - sOPTIMIZE_NONE, /* no optimization */
1.412 - sOPTIMIZE_NOMACRO, /* no macro instructions */
1.413 - sOPTIMIZE_DEFAULT, /* full optimization */
1.414 - /* ----- */
1.415 - sOPTIMIZE_NUMBER
1.416 -};
1.417 -
1.418 -typedef enum s_regid {
1.419 - sPRI, /* indicates the primary register */
1.420 - sALT, /* indicates the secundary register */
1.421 -} regid;
1.422 -
1.423 -typedef enum s_optmark {
1.424 - sEXPR, /* end of expression (for expressions that form a statement) */
1.425 - sPARM, /* end of parameter (in a function parameter list) */
1.426 - sLDECL, /* start of local declaration (variable) */
1.427 -} optmark;
1.428 -
1.429 -#define suSLEEP_INSTR 0x01 /* the "sleep" instruction was used */
1.430 -
1.431 -#if INT_MAX<0x8000u
1.432 - #define PUBLICTAG 0x8000u
1.433 - #define FIXEDTAG 0x4000u
1.434 -#else
1.435 - #define PUBLICTAG 0x80000000Lu
1.436 - #define FIXEDTAG 0x40000000Lu
1.437 -#endif
1.438 -#define TAGMASK (~PUBLICTAG)
1.439 -#define CELL_MAX (((ucell)1 << (sizeof(cell)*8-1)) - 1)
1.440 -
1.441 -
1.442 -/* interface functions */
1.443 -#if defined __cplusplus
1.444 - extern "C" {
1.445 -#endif
1.446 -
1.447 -/*
1.448 - * Functions you call from the "driver" program
1.449 - */
1.450 -int pc_compile(int argc, char **argv);
1.451 -int pc_addconstant(char *name,cell value,int tag);
1.452 -int pc_addtag(char *name);
1.453 -int pc_enablewarning(int number,int enable);
1.454 -
1.455 -/*
1.456 - * Functions called from the compiler (to be implemented by you)
1.457 - */
1.458 -
1.459 -/* general console output */
1.460 -int pc_printf(const char *message,...);
1.461 -
1.462 -/* error report function */
1.463 -int pc_error(int number,char *message,char *filename,int firstline,int lastline,va_list argptr);
1.464 -
1.465 -/* input from source file */
1.466 -void *pc_opensrc(char *filename); /* reading only */
1.467 -void *pc_createsrc(char *filename);
1.468 -void pc_closesrc(void *handle); /* never delete */
1.469 -void pc_resetsrc(void *handle,void *position); /* reset to a position marked earlier */
1.470 -char *pc_readsrc(void *handle,unsigned char *target,int maxchars);
1.471 -int pc_writesrc(void *handle,unsigned char *source);
1.472 -void *pc_getpossrc(void *handle); /* mark the current position */
1.473 -int pc_eofsrc(void *handle);
1.474 -
1.475 -/* output to intermediate (.ASM) file */
1.476 -void *pc_openasm(char *filename); /* read/write */
1.477 -void pc_closeasm(void *handle,int deletefile);
1.478 -void pc_resetasm(void *handle);
1.479 -int pc_writeasm(void *handle,char *str);
1.480 -char *pc_readasm(void *handle,char *target,int maxchars);
1.481 -
1.482 -/* output to binary (.AMX) file */
1.483 -void *pc_openbin(char *filename);
1.484 -void pc_closebin(void *handle,int deletefile);
1.485 -void pc_resetbin(void *handle,long offset);
1.486 -int pc_writebin(void *handle,void *buffer,int size);
1.487 -long pc_lengthbin(void *handle); /* return the length of the file */
1.488 -
1.489 -#if defined __cplusplus
1.490 - }
1.491 -#endif
1.492 -
1.493 -
1.494 -/* by default, functions and variables used in throughout the compiler
1.495 - * files are "external"
1.496 - */
1.497 -#if !defined SC_FUNC
1.498 - #define SC_FUNC
1.499 -#endif
1.500 -#if !defined SC_VDECL
1.501 - #define SC_VDECL extern
1.502 -#endif
1.503 -#if !defined SC_VDEFINE
1.504 - #define SC_VDEFINE
1.505 -#endif
1.506 -
1.507 -/* function prototypes in SC1.C */
1.508 -SC_FUNC void set_extension(char *filename,char *extension,int force);
1.509 -SC_FUNC symbol *fetchfunc(char *name,int tag);
1.510 -SC_FUNC char *operator_symname(char *symname,char *opername,int tag1,int tag2,int numtags,int resulttag);
1.511 -SC_FUNC char *funcdisplayname(char *dest,char *funcname);
1.512 -SC_FUNC int constexpr(cell *val,int *tag,symbol **symptr);
1.513 -SC_FUNC constvalue *append_constval(constvalue *table,const char *name,cell val,int index);
1.514 -SC_FUNC constvalue *find_constval(constvalue *table,char *name,int index);
1.515 -SC_FUNC void delete_consttable(constvalue *table);
1.516 -SC_FUNC symbol *add_constant(char *name,cell val,int vclass,int tag);
1.517 -SC_FUNC void exporttag(int tag);
1.518 -SC_FUNC void sc_attachdocumentation(symbol *sym);
1.519 -
1.520 -/* function prototypes in SC2.C */
1.521 -#define PUSHSTK_P(v) { stkitem s_; s_.pv=(v); pushstk(s_); }
1.522 -#define PUSHSTK_I(v) { stkitem s_; s_.i=(v); pushstk(s_); }
1.523 -#define POPSTK_P() (popstk().pv)
1.524 -#define POPSTK_I() (popstk().i)
1.525 -SC_FUNC void pushstk(stkitem val);
1.526 -SC_FUNC stkitem popstk(void);
1.527 -SC_FUNC void clearstk(void);
1.528 -SC_FUNC int plungequalifiedfile(char *name); /* explicit path included */
1.529 -SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths); /* search through "include" paths */
1.530 -SC_FUNC void preprocess(void);
1.531 -SC_FUNC void lexinit(void);
1.532 -SC_FUNC int lex(cell *lexvalue,char **lexsym);
1.533 -SC_FUNC void lexpush(void);
1.534 -SC_FUNC void lexclr(int clreol);
1.535 -SC_FUNC int matchtoken(int token);
1.536 -SC_FUNC int tokeninfo(cell *val,char **str);
1.537 -SC_FUNC int needtoken(int token);
1.538 -SC_FUNC void litadd(cell value);
1.539 -SC_FUNC void litinsert(cell value,int pos);
1.540 -SC_FUNC int alphanum(char c);
1.541 -SC_FUNC int ishex(char c);
1.542 -SC_FUNC void delete_symbol(symbol *root,symbol *sym);
1.543 -SC_FUNC void delete_symbols(symbol *root,int level,int del_labels,int delete_functions);
1.544 -SC_FUNC int refer_symbol(symbol *entry,symbol *bywhom);
1.545 -SC_FUNC void markusage(symbol *sym,int usage);
1.546 -SC_FUNC uint32_t namehash(const char *name);
1.547 -SC_FUNC symbol *findglb(const char *name,int filter);
1.548 -SC_FUNC symbol *findloc(const char *name);
1.549 -SC_FUNC symbol *findconst(const char *name,int *matchtag);
1.550 -SC_FUNC symbol *finddepend(const symbol *parent);
1.551 -SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,
1.552 - int usage);
1.553 -SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
1.554 - int dim[],int numdim,int idxtag[]);
1.555 -SC_FUNC int getlabel(void);
1.556 -SC_FUNC char *itoh(ucell val);
1.557 -
1.558 -/* function prototypes in SC3.C */
1.559 -SC_FUNC int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
1.560 - value *lval,int *resulttag);
1.561 -SC_FUNC int matchtag(int formaltag,int actualtag,int allowcoerce);
1.562 -SC_FUNC int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult);
1.563 -SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state);
1.564 -SC_FUNC cell array_totalsize(symbol *sym);
1.565 -
1.566 -/* function prototypes in SC4.C */
1.567 -SC_FUNC void writeleader(symbol *root);
1.568 -SC_FUNC void writetrailer(void);
1.569 -SC_FUNC void begcseg(void);
1.570 -SC_FUNC void begdseg(void);
1.571 -SC_FUNC void setline(int chkbounds);
1.572 -SC_FUNC void setfiledirect(char *name);
1.573 -SC_FUNC void setlinedirect(int line);
1.574 -SC_FUNC void setlabel(int index);
1.575 -SC_FUNC void markexpr(optmark type,const char *name,cell offset);
1.576 -SC_FUNC void startfunc(char *fname);
1.577 -SC_FUNC void endfunc(void);
1.578 -SC_FUNC void alignframe(int numbytes);
1.579 -SC_FUNC void rvalue(value *lval);
1.580 -SC_FUNC void address(symbol *ptr,regid reg);
1.581 -SC_FUNC void store(value *lval);
1.582 -SC_FUNC void loadreg(cell address,regid reg);
1.583 -SC_FUNC void storereg(cell address,regid reg);
1.584 -SC_FUNC void memcopy(cell size);
1.585 -SC_FUNC void copyarray(symbol *sym,cell size);
1.586 -SC_FUNC void fillarray(symbol *sym,cell size,cell value);
1.587 -SC_FUNC void ldconst(cell val,regid reg);
1.588 -SC_FUNC void moveto1(void);
1.589 -SC_FUNC void pushreg(regid reg);
1.590 -SC_FUNC void pushval(cell val);
1.591 -SC_FUNC void popreg(regid reg);
1.592 -SC_FUNC void swap1(void);
1.593 -SC_FUNC void ffswitch(int label);
1.594 -SC_FUNC void ffcase(cell value,char *labelname,int newtable);
1.595 -SC_FUNC void ffcall(symbol *sym,const char *label,int numargs);
1.596 -SC_FUNC void ffret(int remparams);
1.597 -SC_FUNC void ffabort(int reason);
1.598 -SC_FUNC void ffbounds(cell size);
1.599 -SC_FUNC void jumplabel(int number);
1.600 -SC_FUNC void defstorage(void);
1.601 -SC_FUNC void modstk(int delta);
1.602 -SC_FUNC void setstk(cell value);
1.603 -SC_FUNC void modheap(int delta);
1.604 -SC_FUNC void setheap_pri(void);
1.605 -SC_FUNC void setheap(cell value);
1.606 -SC_FUNC void cell2addr(void);
1.607 -SC_FUNC void cell2addr_alt(void);
1.608 -SC_FUNC void addr2cell(void);
1.609 -SC_FUNC void char2addr(void);
1.610 -SC_FUNC void charalign(void);
1.611 -SC_FUNC void addconst(cell value);
1.612 -
1.613 -/* Code generation functions for arithmetic operators.
1.614 - *
1.615 - * Syntax: o[u|s|b]_name
1.616 - * | | | +--- name of operator
1.617 - * | | +----- underscore
1.618 - * | +--------- "u"nsigned operator, "s"igned operator or "b"oth
1.619 - * +------------- "o"perator
1.620 - */
1.621 -SC_FUNC void os_mult(void); /* multiplication (signed) */
1.622 -SC_FUNC void os_div(void); /* division (signed) */
1.623 -SC_FUNC void os_mod(void); /* modulus (signed) */
1.624 -SC_FUNC void ob_add(void); /* addition */
1.625 -SC_FUNC void ob_sub(void); /* subtraction */
1.626 -SC_FUNC void ob_sal(void); /* shift left (arithmetic) */
1.627 -SC_FUNC void os_sar(void); /* shift right (arithmetic, signed) */
1.628 -SC_FUNC void ou_sar(void); /* shift right (logical, unsigned) */
1.629 -SC_FUNC void ob_or(void); /* bitwise or */
1.630 -SC_FUNC void ob_xor(void); /* bitwise xor */
1.631 -SC_FUNC void ob_and(void); /* bitwise and */
1.632 -SC_FUNC void ob_eq(void); /* equality */
1.633 -SC_FUNC void ob_ne(void); /* inequality */
1.634 -SC_FUNC void relop_prefix(void);
1.635 -SC_FUNC void relop_suffix(void);
1.636 -SC_FUNC void os_le(void); /* less or equal (signed) */
1.637 -SC_FUNC void os_ge(void); /* greater or equal (signed) */
1.638 -SC_FUNC void os_lt(void); /* less (signed) */
1.639 -SC_FUNC void os_gt(void); /* greater (signed) */
1.640 -
1.641 -SC_FUNC void lneg(void);
1.642 -SC_FUNC void neg(void);
1.643 -SC_FUNC void invert(void);
1.644 -SC_FUNC void nooperation(void);
1.645 -SC_FUNC void inc(value *lval);
1.646 -SC_FUNC void dec(value *lval);
1.647 -SC_FUNC void jmp_ne0(int number);
1.648 -SC_FUNC void jmp_eq0(int number);
1.649 -SC_FUNC void outval(cell val,int newline);
1.650 -
1.651 -/* function prototypes in SC5.C */
1.652 -SC_FUNC int error(int number,...);
1.653 -SC_FUNC void errorset(int code,int line);
1.654 -
1.655 -/* function prototypes in SC6.C */
1.656 -SC_FUNC int assemble(FILE *fout,FILE *fin);
1.657 -
1.658 -/* function prototypes in SC7.C */
1.659 -SC_FUNC void stgbuffer_cleanup(void);
1.660 -SC_FUNC void stgmark(char mark);
1.661 -SC_FUNC void stgwrite(const char *st);
1.662 -SC_FUNC void stgout(int index);
1.663 -SC_FUNC void stgdel(int index,cell code_index);
1.664 -SC_FUNC int stgget(int *index,cell *code_index);
1.665 -SC_FUNC void stgset(int onoff);
1.666 -SC_FUNC int phopt_init(void);
1.667 -SC_FUNC int phopt_cleanup(void);
1.668 -
1.669 -/* function prototypes in SCLIST.C */
1.670 -SC_FUNC char* duplicatestring(const char* sourcestring);
1.671 -SC_FUNC stringpair *insert_alias(char *name,char *alias);
1.672 -SC_FUNC stringpair *find_alias(char *name);
1.673 -SC_FUNC int lookup_alias(char *target,char *name);
1.674 -SC_FUNC void delete_aliastable(void);
1.675 -SC_FUNC stringlist *insert_path(char *path);
1.676 -SC_FUNC char *get_path(int index);
1.677 -SC_FUNC void delete_pathtable(void);
1.678 -SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen);
1.679 -SC_FUNC int get_subst(int index,char **pattern,char **substitution);
1.680 -SC_FUNC stringpair *find_subst(char *name,int length);
1.681 -SC_FUNC int delete_subst(char *name,int length);
1.682 -SC_FUNC void delete_substtable(void);
1.683 -SC_FUNC stringlist *insert_sourcefile(char *string);
1.684 -SC_FUNC char *get_sourcefile(int index);
1.685 -SC_FUNC void delete_sourcefiletable(void);
1.686 -SC_FUNC stringlist *insert_docstring(char *string);
1.687 -SC_FUNC char *get_docstring(int index);
1.688 -SC_FUNC void delete_docstring(int index);
1.689 -SC_FUNC void delete_docstringtable(void);
1.690 -SC_FUNC stringlist *insert_autolist(char *string);
1.691 -SC_FUNC char *get_autolist(int index);
1.692 -SC_FUNC void delete_autolisttable(void);
1.693 -SC_FUNC stringlist *insert_dbgfile(const char *filename);
1.694 -SC_FUNC stringlist *insert_dbgline(int linenr);
1.695 -SC_FUNC stringlist *insert_dbgsymbol(symbol *sym);
1.696 -SC_FUNC char *get_dbgstring(int index);
1.697 -SC_FUNC void delete_dbgstringtable(void);
1.698 -
1.699 -/* function prototypes in SCMEMFILE.C */
1.700 -#if !defined tMEMFILE
1.701 - typedef unsigned char MEMFILE;
1.702 - #define tMEMFILE 1
1.703 -#endif
1.704 -MEMFILE *mfcreate(char *filename);
1.705 -void mfclose(MEMFILE *mf);
1.706 -int mfdump(MEMFILE *mf);
1.707 -long mflength(MEMFILE *mf);
1.708 -long mfseek(MEMFILE *mf,long offset,int whence);
1.709 -unsigned int mfwrite(MEMFILE *mf,unsigned char *buffer,unsigned int size);
1.710 -unsigned int mfread(MEMFILE *mf,unsigned char *buffer,unsigned int size);
1.711 -char *mfgets(MEMFILE *mf,char *string,unsigned int size);
1.712 -int mfputs(MEMFILE *mf,char *string);
1.713 -
1.714 -/* function prototypes in SCI18N.C */
1.715 -#define MAXCODEPAGE 12
1.716 -SC_FUNC int cp_path(const char *root,const char *directory);
1.717 -SC_FUNC int cp_set(const char *name);
1.718 -SC_FUNC cell cp_translate(const unsigned char *string,const unsigned char **endptr);
1.719 -SC_FUNC cell get_utf8_char(const unsigned char *string,const unsigned char **endptr);
1.720 -SC_FUNC int scan_utf8(FILE *fp,const char *filename);
1.721 -
1.722 -/* function prototypes in SCSTATE.C */
1.723 -SC_FUNC constvalue *automaton_add(const char *name);
1.724 -SC_FUNC constvalue *automaton_find(const char *name);
1.725 -SC_FUNC constvalue *automaton_findid(int id);
1.726 -SC_FUNC constvalue *state_add(const char *name,int fsa_id);
1.727 -SC_FUNC constvalue *state_find(const char *name,int fsa_id);
1.728 -SC_FUNC constvalue *state_findid(int id);
1.729 -SC_FUNC void state_buildlist(int **list,int *listsize,int *count,int stateid);
1.730 -SC_FUNC int state_addlist(int *list,int count,int fsa_id);
1.731 -SC_FUNC void state_deletetable(void);
1.732 -SC_FUNC int state_getfsa(int listid);
1.733 -SC_FUNC int state_count(int listid);
1.734 -SC_FUNC int state_inlist(int listid,int state);
1.735 -SC_FUNC int state_listitem(int listid,int index);
1.736 -SC_FUNC void state_conflict(symbol *root);
1.737 -SC_FUNC int state_conflict_id(int listid1,int listid2);
1.738 -
1.739 -/* external variables (defined in scvars.c) */
1.740 -#if !defined SC_SKIP_VDECL
1.741 -SC_VDECL symbol loctab; /* local symbol table */
1.742 -SC_VDECL symbol glbtab; /* global symbol table */
1.743 -SC_VDECL cell *litq; /* the literal queue */
1.744 -SC_VDECL unsigned char pline[]; /* the line read from the input file */
1.745 -SC_VDECL const unsigned char *lptr;/* points to the current position in "pline" */
1.746 -SC_VDECL constvalue tagname_tab;/* tagname table */
1.747 -SC_VDECL constvalue libname_tab;/* library table (#pragma library "..." syntax) */
1.748 -SC_VDECL constvalue *curlibrary;/* current library */
1.749 -SC_VDECL int pc_addlibtable; /* is the library table added to the AMX file? */
1.750 -SC_VDECL symbol *curfunc; /* pointer to current function */
1.751 -SC_VDECL char *inpfname; /* name of the file currently read from */
1.752 -SC_VDECL char outfname[]; /* intermediate (assembler) file name */
1.753 -SC_VDECL char binfname[]; /* binary file name */
1.754 -SC_VDECL char errfname[]; /* error file name */
1.755 -SC_VDECL char sc_ctrlchar; /* the control character (or escape character) */
1.756 -SC_VDECL char sc_ctrlchar_org;/* the default control character */
1.757 -SC_VDECL int litidx; /* index to literal table */
1.758 -SC_VDECL int litmax; /* current size of the literal table */
1.759 -SC_VDECL int stgidx; /* index to the staging buffer */
1.760 -SC_VDECL int sc_labnum; /* number of (internal) labels */
1.761 -SC_VDECL int staging; /* true if staging output */
1.762 -SC_VDECL cell declared; /* number of local cells declared */
1.763 -SC_VDECL cell glb_declared; /* number of global cells declared */
1.764 -SC_VDECL cell code_idx; /* number of bytes with generated code */
1.765 -SC_VDECL int ntv_funcid; /* incremental number of native function */
1.766 -SC_VDECL int errnum; /* number of errors */
1.767 -SC_VDECL int warnnum; /* number of warnings */
1.768 -SC_VDECL int sc_debug; /* debug/optimization options (bit field) */
1.769 -SC_VDECL int sc_packstr; /* strings are packed by default? */
1.770 -SC_VDECL int sc_asmfile; /* create .ASM file? */
1.771 -SC_VDECL int sc_listing; /* create .LST file? */
1.772 -SC_VDECL int sc_compress; /* compress bytecode? */
1.773 -SC_VDECL int sc_needsemicolon;/* semicolon required to terminate expressions? */
1.774 -SC_VDECL int sc_dataalign; /* data alignment value */
1.775 -SC_VDECL int sc_alignnext; /* must frame of the next function be aligned? */
1.776 -SC_VDECL int pc_docexpr; /* must expression be attached to documentation comment? */
1.777 -SC_VDECL int curseg; /* 1 if currently parsing CODE, 2 if parsing DATA */
1.778 -SC_VDECL cell pc_stksize; /* stack size */
1.779 -SC_VDECL cell pc_amxlimit; /* abstract machine size limit (code + data, or only code) */
1.780 -SC_VDECL cell pc_amxram; /* abstract machine data size limit */
1.781 -SC_VDECL int freading; /* is there an input file ready for reading? */
1.782 -SC_VDECL int fline; /* the line number in the current file */
1.783 -SC_VDECL short fnumber; /* number of files in the file table (debugging) */
1.784 -SC_VDECL short fcurrent; /* current file being processed (debugging) */
1.785 -SC_VDECL short sc_intest; /* true if inside a test */
1.786 -SC_VDECL int sideeffect; /* true if an expression causes a side-effect */
1.787 -SC_VDECL int stmtindent; /* current indent of the statement */
1.788 -SC_VDECL int indent_nowarn; /* skip warning "217 loose indentation" */
1.789 -SC_VDECL int sc_tabsize; /* number of spaces that a TAB represents */
1.790 -SC_VDECL short sc_allowtags; /* allow/detect tagnames in lex() */
1.791 -SC_VDECL int sc_status; /* read/write status */
1.792 -SC_VDECL int sc_rationaltag; /* tag for rational numbers */
1.793 -SC_VDECL int rational_digits; /* number of fractional digits */
1.794 -SC_VDECL int sc_allowproccall;/* allow/detect tagnames in lex() */
1.795 -SC_VDECL short sc_is_utf8; /* is this source file in UTF-8 encoding */
1.796 -SC_VDECL char *pc_depricate; /* if non-NULL, mark next declaration as depricated */
1.797 -SC_VDECL int sc_curstates; /* ID of the current state list */
1.798 -SC_VDECL int pc_optimize; /* (peephole) optimization level */
1.799 -SC_VDECL int pc_memflags; /* special flags for the stack/heap usage */
1.800 -
1.801 -SC_VDECL constvalue sc_automaton_tab; /* automaton table */
1.802 -SC_VDECL constvalue sc_state_tab; /* state table */
1.803 -
1.804 -SC_VDECL FILE *inpf; /* file read from (source or include) */
1.805 -SC_VDECL FILE *inpf_org; /* main source file */
1.806 -SC_VDECL FILE *outf; /* file written to */
1.807 -
1.808 -SC_VDECL jmp_buf errbuf; /* target of longjmp() on a fatal error */
1.809 -
1.810 -#if !defined SC_LIGHT
1.811 - SC_VDECL int sc_makereport; /* generate a cross-reference report */
1.812 -#endif
1.813 -
1.814 -#endif /* SC_SKIP_VDECL */
1.815 -
1.816 -#endif /* SC_H_INCLUDED */