Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

/home/groups/n/no/noxwizard/cvs/src/compiler/sc.h

Go to the documentation of this file.
00001 /*  Small compiler
00002  *
00003  *  Drafted after the Small-C compiler Version 2.01, originally created
00004  *  by Ron Cain, july 1980, and enhanced by James E. Hendrix.
00005  *
00006  *  This version comes close to a complete rewrite.
00007  *
00008  *  Copyright R. Cain, 1980
00009  *  Copyright J.E. Hendrix, 1982, 1983
00010  *  Copyright T. Riemersma, 1997-2002
00011  */
00012 #ifndef __SC_H
00013 #define __SC_H
00014 #include <limits.h>
00015 #include <stdarg.h>
00016 #include <stdio.h>
00017 #if defined __BORLANDC__ && defined _Windows && !(defined __32BIT__ || defined __WIN32__)
00018   /* setjmp() and longjmp() not well supported in 16-bit windows */
00019   #include <windows.h>
00020   typedef int jmp_buf[9];
00021   #define setjmp(b)     Catch(b)
00022   #define longjmp(b,e)  Throw(b,e)
00023 #else
00024   #include <setjmp.h>
00025 #endif
00026 #include "osdefs.h"
00027 #include "amx/amx.h"
00028 
00029 /* Note: the "cell" and "ucell" types are defined in AMX.H */
00030 
00031 #define PUBLIC_CHAR '@'     /* character that defines a function "public" */
00032 #define CTRL_CHAR   '^'     /* default control character */
00033 
00034 #if defined __MSDOS__ || defined __WIN32__ || defined _Windows
00035   #define DIRSEP_CHAR '\\'
00036 #elif defined macintosh
00037   #define DIRSEP_CHAR ':'
00038 #else
00039   #define DIRSEP_CHAR '/'   /* directory separator character */
00040 #endif
00041 
00042 #define sDIMEN_MAX     2    /* maximum number of array dimensions */
00043 #define sDEF_LITMAX  500    /* initial size of the literal pool, in "cells" */
00044 #define sLINEMAX     511    /* input line length (in characters) */
00045 #define sNAMEMAX      31    /* significant length of symbol name */
00046 #define sDEF_AMXSTACK 4096  /* default stack size for AMX files */
00047 #define sSTKMAX       80    /* stack for nested #includes and other uses */
00048 #define PREPROC_TERM  '\x7f'/* termination character for preprocessor expressions (the "DEL" code) */
00049 
00050 typedef void *stkitem;      /* type of items stored on the stack */
00051 
00052 typedef struct __s_arginfo {  /* function argument info */
00053   char name[sNAMEMAX+1];
00054   char ident;           /* iVARIABLE, iREFERENCE, iREFARRAY or iVARARGS */
00055   char usage;           /* uCONST */
00056   int *tags;            /* argument tag id. list */
00057   int numtags;          /* number of tags in the tag list */
00058   int dim[sDIMEN_MAX];
00059   int numdim;           /* number of dimensions */
00060   char hasdefault;      /* bit0: is there a default value? bit7: "sizeof" */
00061   union {
00062     cell val;           /* default value */
00063     char *symname;      /* name of another symbol */
00064     struct {
00065       cell *data;       /* values of default array */
00066       int size;         /* complete length of default array */
00067       int arraysize;    /* size to reserve on the heap */
00068       cell addr;        /* address of the default array in the data segment */
00069     } array;
00070   } defvalue;           /* default value, or pointer to default array */
00071 } arginfo;
00072 
00073 /*  Equate table, tagname table, library table */
00074 typedef struct __s_constval {
00075   struct __s_constval *next;
00076   char name[sNAMEMAX+1];
00077   cell value;
00078 } constval;
00079 
00080 /*  Symbol table format
00081  *
00082  *  The symbol name read from the input file is stored in "name", the
00083  *  value of "addr" is written to the output file. The address in "addr"
00084  *  depends on the class of the symbol:
00085  *      global          offset into the data segment
00086  *      local           offset relative to the stack frame
00087  *      label           generated hexadecimal number
00088  *      function        offset into code segment
00089  */
00090 typedef struct __s_symbol {
00091   struct __s_symbol *next;
00092   struct __s_symbol *parent;  /* hierarchical types (multi-dimensional arrays) */
00093   char name[sNAMEMAX+1];
00094   uint32_t hash;        /* value derived from name, for quicker searching */
00095   cell addr;            /* address or offset (or value for constant, index for native function) */
00096   char vclass;          /* sLOCAL if "addr" refers to a local symbol */
00097   char ident;           /* see below for possible values */
00098   char usage;           /* see below for possible values */
00099   int compound;         /* compound level (braces nesting level) */
00100   int tag;              /* tagname id */
00101   union {
00102     int declared;       /* label: how many local variables are declared */
00103     int idxtag;         /* array: tag of array indices */
00104     constval *lib;      /* native function: library it is part of */
00105   } x;                  /* 'x' for 'extra' */
00106   union {
00107     arginfo *arglist;   /* types of all parameters for functions */
00108     struct {
00109       cell length;      /* arrays: length (size) */
00110       short level;      /* number of dimensions below this level */
00111     } array;
00112   } dim;                /* for 'dimension', both functions and arrays */
00113   int fnumber;          /* static global variables: file number in which the declaration is visible */
00114   struct __s_symbol **refer;  /* referrer list, functions that "use" this symbol */
00115   int numrefers;              /* number of entries in the referrer list */
00116 } symbol;
00117 
00118 
00119 /*  Possible entries for "ident". These are used in the "symbol", "value"
00120  *  and arginfo structures. Not every constant is valid for every use.
00121  *  In an argument list, the list is terminated with a "zero" ident; labels
00122  *  cannot be passed as function arguments, so the value 0 is overloaded.
00123  */
00124 #define iLABEL      0
00125 #define iVARIABLE   1   /* cell that has an address and that can be fetched directly (lvalue) */
00126 #define iREFERENCE  2   /* iVARIABLE, but must be dereferenced */
00127 #define iARRAY      3
00128 #define iREFARRAY   4   /* an array passed by reference (i.e. a pointer) */
00129 #define iARRAYCELL  5   /* array element, cell that must be fetched indirectly */
00130 #define iARRAYCHAR  6   /* array element, character from cell from array */
00131 #define iEXPRESSION 7   /* expression result, has no address (rvalue) */
00132 #define iCONSTEXPR  8   /* constant expression (or constant symbol) */
00133 #define iFUNCTN     9
00134 #define iREFFUNC    10  /* function passed as a parameter */
00135 #define iVARARGS    11  /* function specified ... as argument(s) */
00136 
00137 /*  Possible entries for "usage"
00138  *
00139  *  This byte is used as a serie of bits, the syntax is different for
00140  *  functions and other symbols:
00141  *
00142  *  VARIABLE
00143  *  bits: 0     (uDEFINE) the variable is defined in the source file
00144  *        1     (uREAD) the variable is "read" (accessed) in the source file
00145  *        2     (uWRITTEN) the variable is altered (assigned a value)
00146  *        3     (uCONST) the variable is constant (may not be assigned to)
00147  *        4     (uPUBLIC) the variable is public
00148  *        6     (uSTOCK) the variable is discardable (without warning)
00149  *
00150  *  FUNCTION
00151  *  bits: 0     (uDEFINE) the function is defined ("implemented") in the source file
00152  *        1     (uREAD) the function is invoked in the source file
00153  *        2     (uRETVALUE) the function returns a value (or should return a value)
00154  *        3     (uPROTOTYPED) the function was prototyped
00155  *        4     (uPUBLIC) the function is public
00156  *        5     (uNATIVE) the function is native
00157  *        6     (uSTOCK) the function is discardable (without warning)
00158  *        7     (uMISSING) the function is not implemented in this source file
00159  *
00160  *  CONSTANT
00161  *  bits: 0     (uDEFINE) the symbol is defined in the source file
00162  *        1     (uREAD) the constant is "read" (accessed) in the source file
00163  *        3     (uPREDEF) the constant is pre-defined and should be kept between passes
00164  */
00165 #define uDEFINE   0x01
00166 #define uREAD     0x02
00167 #define uWRITTEN  0x04
00168 #define uRETVALUE 0x04  /* function returns (or should return) a value */
00169 #define uCONST    0x08
00170 #define uPROTOTYPED 0x08
00171 #define uPREDEF   0x08  /* constant is pre-defined */
00172 #define uPUBLIC   0x10
00173 #define uNATIVE   0x20
00174 #define uSTOCK    0x40
00175 #define uMISSING  0x80
00176 /* uRETNONE is not stored in the "usage" field of a symbol. It is
00177  * used during parsing a function, to detect a mix of "return;" and
00178  * "return value;" in a few special cases.
00179  */
00180 #define uRETNONE  0x10
00181 #define uSIZEOF   0x80  /* set in the "hasdefault" field of the arginfo struct */
00182 
00183 #define uMAINFUNC "main"
00184 
00185 #define sGLOBAL   0     /* global/local variable/constant class */
00186 #define sLOCAL    1
00187 #define sSTATIC   2     /* global life, local scope */
00188 
00189 typedef struct {
00190   symbol *sym;          /* symbol in symbol table, NULL for (constant) expression */
00191   cell constval;        /* value of the constant expression (if ident==iCONSTEXPR)
00192                          * also used for the size of a literal array */
00193   int tag;              /* tagname id (of the expression) */
00194   char ident;           /* iCONSTEXPR, iVARIABLE, iARRAY, iARRAYCELL,
00195                          * iEXPRESSION or iREFERENCE */
00196   char boolresult;      /* boolean result for relational operators */
00197 } value;
00198 
00199 /*  alias table (native functions) */
00200 typedef struct __s_alias {
00201   struct __s_alias *next;
00202   char name[sNAMEMAX+1];
00203   char alias[sEXPMAX+1];
00204 } namealias;
00205 
00206 /*  "while" statement queue (also used for "for" and "do - while" loops) */
00207 enum {
00208   wqBRK,        /* used to restore stack for "break" */
00209   wqCONT,       /* used to restore stack for "continue" */
00210   wqLOOP,       /* loop start label number */
00211   wqEXIT,       /* loop exit label number (jump if false) */
00212   /* --- */
00213   wqSIZE        /* "while queue" size */
00214 };
00215 #define wqTABSZ (24*wqSIZE)    /* 24 nested loop statements */
00216 
00217 enum {
00218   statIDLE,     /* not compiling (yet) */
00219   statFIRST,    /* first pass */
00220   statWRITE,    /* writing output */
00221   statSKIP,     /* skipping output */
00222 };
00223 
00224 typedef struct __s_stringlist {
00225   struct __s_stringlist *next;
00226   char *line;
00227 } stringlist;
00228 
00229 /* macros for code generation */
00230 #define opcodes(n)      ((n)*sizeof(cell))      /* opcode size */
00231 #define opargs(n)       ((n)*sizeof(cell))      /* size of typical argument */
00232 
00233 /*  Tokens recognized by lex()
00234  *  Some of these constants are assigned as well to the variable "lastst"
00235  */
00236 #define tFIRST   256    /* value of first multi-character operator */
00237 #define tMIDDLE  279    /* value of last multi-character operator */
00238 #define tLAST    316    /* value of last multi-character match-able token */
00239 /* multi-character operators */
00240 #define taMULT   256    /* *= */
00241 #define taDIV    257    /* /= */
00242 #define taMOD    258    /* %= */
00243 #define taADD    259    /* += */
00244 #define taSUB    260    /* -= */
00245 #define taSHL    261    /* <<= */
00246 #define taSHRU   262    /* >>>= */
00247 #define taSHR    263    /* >>= */
00248 #define taAND    264    /* &= */
00249 #define taXOR    265    /* ^= */
00250 #define taOR     266    /* |= */
00251 #define tlOR     267    /* || */
00252 #define tlAND    268    /* && */
00253 #define tlEQ     269    /* == */
00254 #define tlNE     270    /* != */
00255 #define tlLE     271    /* <= */
00256 #define tlGE     272    /* >= */
00257 #define tSHL     273    /* << */
00258 #define tSHRU    274    /* >>> */
00259 #define tSHR     275    /* >> */
00260 #define tINC     276    /* ++ */
00261 #define tDEC     277    /* -- */
00262 #define tELLIPS  278    /* ... */
00263 #define tDBLDOT  279    /* .. */
00264 /* reserved words (statements) */
00265 #define tASSERT  280
00266 #define tBREAK   281
00267 #define tCASE    282
00268 #define tCHAR    283
00269 #define tCONST   284
00270 #define tCONTINUE 285
00271 #define tDEFAULT 286
00272 #define tDEFINED 287
00273 #define tDO      288
00274 #define tELSE    289
00275 #define tENUM    290
00276 #define tEXIT    291
00277 #define tFOR     292
00278 #define tFORWARD 293
00279 #define tGOTO    294
00280 #define tIF      295
00281 #define tNATIVE  296
00282 #define tNEW     297
00283 #define tOPERATOR 298
00284 #define tPUBLIC  299
00285 #define tRETURN  300
00286 #define tSIZEOF  301
00287 #define tSLEEP   302
00288 #define tSTATIC  303
00289 #define tSTOCK   304
00290 #define tSWITCH  305
00291 #define tWHILE   306
00292 /* compiler directives */
00293 #define tpASSERT 307    /* #assert */
00294 #define tpDEFINE 308
00295 #define tpELSE   309    /* #else */
00296 #define tpEMIT   310
00297 #define tpENDIF  311
00298 #define tpENDINPUT 312
00299 #define tpENDSCRPT 313
00300 #define tpIF     314    /* #if */
00301 #define tINCLUDE 315
00302 #define tpPRAGMA 316
00303 /* semicolon is a special case, because it can be optional */
00304 #define tTERM    317    /* semicolon or newline */
00305 #define tENDEXPR 318    /* forced end of expression */
00306 /* other recognized tokens */
00307 #define tNUMBER  319    /* integer number */
00308 #define tRATIONAL 320   /* rational number */
00309 #define tSYMBOL  321
00310 #define tLABEL   322
00311 #define tSTRING  323
00312 #define tEXPR    324    /* for assigment to "lastst" only */
00313 
00314 /* (reversed) evaluation of staging buffer */
00315 #define sSTARTREORDER 1
00316 #define sENDREORDER   2
00317 #define sEXPRSTART    0xc0      /* top 2 bits set, rest is free */
00318 #define sMAXARGS      64        /* relates to the bit pattern of sEXPRSTART */
00319 
00320 /* codes for ffabort() */
00321 #define xEXIT           1       /* exit code in PRI */
00322 #define xASSERTION      2       /* abort caused by failing assertion */
00323 #define xSTACKERROR     3       /* stack/heap overflow */
00324 #define xBOUNDSERROR    4       /* array index out of bounds */
00325 #define xMEMACCESS      5       /* data access error */
00326 #define xINVINSTR       6       /* invalid instruction */
00327 #define xSTACKUNDERFLOW 7       /* stack underflow */
00328 #define xHEAPUNDERFLOW  8       /* heap underflow */
00329 #define xCALLBACKERR    9       /* no, or invalid, callback */
00330 #define xSLEEP         12       /* sleep, exit code in PRI, tag in ALT */
00331 
00332 /* Miscellaneous  */
00333 #if !defined TRUE
00334   #define FALSE         0
00335   #define TRUE          1
00336 #endif
00337 #define sIN_CSEG        1       /* if parsing CODE */
00338 #define sIN_DSEG        2       /* if parsing DATA */
00339 #define sCHKBOUNDS      1       /* bit position in "debug" variable: check bounds */
00340 #define sSYMBOLIC       2       /* bit position in "debug" variable: symbolic info */
00341 #define sNOOPTIMIZE     4       /* bit position in "debug" variable: no optimization */
00342 #define sRESET          0       /* reset error flag */
00343 #define sFORCESET       1       /* force error flag on */
00344 #define sEXPRMARK       2       /* mark start of expression */
00345 #define sEXPRRELEASE    3       /* mark end of expression */
00346 
00347 #if !defined _MAX_PATH
00348   #define _MAX_PATH     255
00349 #endif
00350 #if INT_MAX<0x8000u
00351   #define PUBLICTAG   0x8000u
00352   #define FIXEDTAG    0x4000u
00353 #else
00354   #define PUBLICTAG   0x80000000Lu
00355   #define FIXEDTAG    0x40000000Lu
00356 #endif
00357 #define TAGMASK       (~PUBLICTAG)
00358 
00359 
00360 /* interface functions */
00361 #if defined __cplusplus
00362   extern "C" {
00363 #endif
00364 
00365 /*
00366  * Functions you call from the "driver" program
00367  */
00368 int sc_compile(int argc, char **argv);
00369 int sc_addconstant(char *name,cell value,int tag);
00370 int sc_addtag(char *name);
00371 
00372 /*
00373  * Functions called from the compiler (to be implemented by you)
00374  */
00375 
00376 /* general console output */
00377 int sc_printf(const char *message,...);
00378 
00379 /* error report function */
00380 int sc_error(int number,char *message,char *filename,int firstline,int lastline,va_list argptr);
00381 
00382 /* input from source file */
00383 void *sc_opensrc(char *filename); /* reading only */
00384 void sc_closesrc(void *handle);   /* never delete */
00385 void sc_resetsrc(void *handle,void *position);  /* reset to a position marked earlier */
00386 char *sc_readsrc(void *handle,char *target,int maxchars);
00387 void *sc_getpossrc(void *handle); /* mark the current position */
00388 int  sc_eofsrc(void *handle);
00389 
00390 /* output to intermediate (.ASM) file */
00391 void *sc_openasm(char *filename); /* read/write */
00392 void sc_closeasm(void *handle,int deletefile);
00393 void sc_resetasm(void *handle);
00394 int  sc_writeasm(void *handle,char *str);
00395 char *sc_readasm(void *handle,char *target,int maxchars);
00396 
00397 /* output to binary (.AMX) file */
00398 void *sc_openbin(char *filename);
00399 void sc_closebin(void *handle,int deletefile);
00400 void sc_resetbin(void *handle);
00401 int  sc_writebin(void *handle,void *buffer,int size);
00402 long sc_lengthbin(void *handle); /* return the length of the file */
00403 
00404 #if defined __cplusplus
00405   }
00406 #endif
00407 
00408 
00409 /* by default, functions and variables used in throughout the compiler
00410  * files are "external"
00411  */
00412 #if !defined SC_FUNC
00413   #define SC_FUNC
00414 #endif
00415 #if !defined SC_VDECL
00416   #define SC_VDECL  extern
00417 #endif
00418 #if !defined SC_VDEFINE
00419   #define SC_VDEFINE
00420 #endif
00421 
00422 /* function prototypes in SC1.C */
00423 SC_FUNC symbol *fetchfunc(char *name,int tag);
00424 SC_FUNC char *funcdisplayname(char *dest,char *funcname);
00425 SC_FUNC int constexpr(cell *val,int *tag);
00426 SC_FUNC constval *append_constval(constval *table,char *name,cell val);
00427 SC_FUNC constval *find_constval(constval *table,char *name);
00428 SC_FUNC void delete_consttable(constval *table);
00429 SC_FUNC void add_constant(char *name,cell val,int vclass,int tag);
00430 
00431 /* function prototypes in SC2.C */
00432 SC_FUNC void pushstk(stkitem val);
00433 SC_FUNC stkitem popstk(void);
00434 SC_FUNC int plungefile(char *name);
00435 SC_FUNC void preprocess(void);
00436 SC_FUNC void lexinit(void);
00437 SC_FUNC int lex(cell *lexvalue,char **lexsym);
00438 SC_FUNC void lexpush(void);
00439 SC_FUNC void lexclr(void);
00440 SC_FUNC int matchtoken(int token);
00441 SC_FUNC int tokeninfo(cell *val,char **str);
00442 SC_FUNC int needtoken(int token);
00443 SC_FUNC void stowlit(cell value);
00444 SC_FUNC int alphanum(char c);
00445 SC_FUNC int ishex(char c);
00446 SC_FUNC void delete_symbol(symbol *root,symbol *sym);
00447 SC_FUNC void delete_symbols(symbol *root,int level,int del_labels,int delete_functions);
00448 SC_FUNC int refer_symbol(symbol *entry,symbol *bywhom);
00449 SC_FUNC void markusage(symbol *sym,int usage);
00450 SC_FUNC uint32_t namehash(char *name);
00451 SC_FUNC symbol *findglb(char *name);
00452 SC_FUNC symbol *findloc(char *name);
00453 SC_FUNC symbol *findconst(char *name);
00454 SC_FUNC symbol *finddepend(symbol *parent);
00455 SC_FUNC symbol *addsym(char *name,cell addr,int ident,int vclass,int tag,
00456                        int usage);
00457 SC_FUNC symbol *addvariable(char *name,cell addr,int ident,int vclass,int tag,
00458                             int dim[],int numdim,int idxtag[]);
00459 SC_FUNC int getlabel(void);
00460 SC_FUNC char *itoh(ucell val);
00461 
00462 /* function prototypes in SC3.C */
00463 SC_FUNC int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
00464                          value *lval,int *resulttag);
00465 SC_FUNC int matchtag(int formaltag,int actualtag,int allowcoerce);
00466 SC_FUNC int expression(int *constant,cell *val,int *tag,int chkfuncresult);
00467 SC_FUNC int hier14(value *lval1);       /* the highest expression level */
00468 
00469 /* function prototypes in SC4.C */
00470 SC_FUNC void writeleader(void);
00471 SC_FUNC void writetrailer(void);
00472 SC_FUNC void begcseg(void);
00473 SC_FUNC void begdseg(void);
00474 SC_FUNC void setactivefile(int fnumber);
00475 SC_FUNC cell nameincells(char *name);
00476 SC_FUNC void setfile(char *name,int fileno);
00477 SC_FUNC void setline(int line,int fileno);
00478 SC_FUNC void setlabel(int index);
00479 SC_FUNC void endexpr(void);
00480 SC_FUNC void startfunc(char *fname);
00481 SC_FUNC void endfunc(void);
00482 SC_FUNC void alignframe(int numbytes);
00483 SC_FUNC void defsymbol(char *name,int ident,int vclass,cell offset);
00484 SC_FUNC void symbolrange(int level,cell size);
00485 SC_FUNC void rvalue(value *lval);
00486 SC_FUNC void address(symbol *ptr);
00487 SC_FUNC void store(value *lval);
00488 SC_FUNC void memcopy(cell size);
00489 SC_FUNC void copyarray(symbol *sym,cell size);
00490 SC_FUNC void fillarray(symbol *sym,cell size,cell value);
00491 SC_FUNC void const1(cell val);
00492 SC_FUNC void const2(cell val);
00493 SC_FUNC void moveto1(void);
00494 SC_FUNC void push1(void);
00495 SC_FUNC void push2(void);
00496 SC_FUNC void pushval(cell val);
00497 SC_FUNC void pop1(void);
00498 SC_FUNC void pop2(void);
00499 SC_FUNC void swap1(void);
00500 SC_FUNC void ffswitch(int label);
00501 SC_FUNC void ffcase(cell value,char *labelname,int newtable);
00502 SC_FUNC void ffcall(symbol *sym,int numargs);
00503 SC_FUNC void ffret(void);
00504 SC_FUNC void ffabort(int reason);
00505 SC_FUNC void ffbounds(cell size);
00506 SC_FUNC void jumplabel(int number);
00507 SC_FUNC void defstorage(void);
00508 SC_FUNC void modstk(int delta);
00509 SC_FUNC void setstk(cell value);
00510 SC_FUNC void modheap(int delta);
00511 SC_FUNC void setheap_pri(void);
00512 SC_FUNC void setheap(cell value);
00513 SC_FUNC void cell2addr(void);
00514 SC_FUNC void cell2addr_alt(void);
00515 SC_FUNC void addr2cell(void);
00516 SC_FUNC void char2addr(void);
00517 SC_FUNC void charalign(void);
00518 SC_FUNC void addconst(cell value);
00519 
00520 /*  Code generation functions for arithmetic operators.
00521  *
00522  *  Syntax: o[u|s|b]_name
00523  *          |   |   | +--- name of operator
00524  *          |   |   +----- underscore
00525  *          |   +--------- "u"nsigned operator, "s"igned operator or "b"oth
00526  *          +------------- "o"perator
00527  */
00528 SC_FUNC void os_mult(void); /* multiplication (signed) */
00529 SC_FUNC void os_div(void);  /* division (signed) */
00530 SC_FUNC void os_mod(void);  /* modulus (signed) */
00531 SC_FUNC void ob_add(void);  /* addition */
00532 SC_FUNC void ob_sub(void);  /* subtraction */
00533 SC_FUNC void ob_sal(void);  /* shift left (arithmetic) */
00534 SC_FUNC void os_sar(void);  /* shift right (arithmetic, signed) */
00535 SC_FUNC void ou_sar(void);  /* shift right (logical, unsigned) */
00536 SC_FUNC void ob_or(void);   /* bitwise or */
00537 SC_FUNC void ob_xor(void);  /* bitwise xor */
00538 SC_FUNC void ob_and(void);  /* bitwise and */
00539 SC_FUNC void ob_eq(void);   /* equality */
00540 SC_FUNC void ob_ne(void);   /* inequality */
00541 SC_FUNC void relop_prefix(void);
00542 SC_FUNC void relop_suffix(void);
00543 SC_FUNC void os_le(void);   /* less or equal (signed) */
00544 SC_FUNC void os_ge(void);   /* greater or equal (signed) */
00545 SC_FUNC void os_lt(void);   /* less (signed) */
00546 SC_FUNC void os_gt(void);   /* greater (signed) */
00547 
00548 SC_FUNC void lneg(void);
00549 SC_FUNC void neg(void);
00550 SC_FUNC void invert(void);
00551 SC_FUNC void nooperation(void);
00552 SC_FUNC void inc(value *lval);
00553 SC_FUNC void dec(value *lval);
00554 SC_FUNC void jmp_ne0(int number);
00555 SC_FUNC void jmp_eq0(int number);
00556 SC_FUNC void outval(cell val,int newline);
00557 
00558 /* function prototypes in SC5.C */
00559 SC_FUNC int error(int number,...);
00560 SC_FUNC void errorset(int code);
00561 
00562 /* function prototypes in SC6.C */
00563 SC_FUNC void assemble(FILE *fout,FILE *fin);
00564 
00565 /* function prototypes in SC7.C */
00566 SC_FUNC void stgbuffer_cleanup(void);
00567 SC_FUNC void stgmark(char mark);
00568 SC_FUNC void stgwrite(char *st);
00569 SC_FUNC void stgout(int index);
00570 SC_FUNC void stgdel(int index,cell code_index);
00571 SC_FUNC int stgget(int *index,cell *code_index);
00572 SC_FUNC void stgset(int onoff);
00573 SC_FUNC int phopt_init(void);
00574 SC_FUNC int phopt_cleanup(void);
00575 
00576 /* function prototypes in SCLIST.C */
00577 SC_FUNC namealias *insert_alias(char *name,char *alias);
00578 SC_FUNC namealias *find_alias(char *name);
00579 SC_FUNC int lookup_alias(char *target,char *name);
00580 SC_FUNC void delete_aliastable(void);
00581 SC_FUNC stringlist *insert_path(char *path);
00582 SC_FUNC char *get_path(int index);
00583 SC_FUNC void delete_pathtable(void);
00584 
00585 /* external variables (defined in scvars.c) */
00586 #if !defined SC_SKIP_VDECL
00587 SC_VDECL symbol loctab;       /* local symbol table */
00588 SC_VDECL symbol glbtab;       /* global symbol table */
00589 SC_VDECL cell *litq;          /* the literal queue */
00590 SC_VDECL char pline[];        /* the line read from the input file */
00591 SC_VDECL char *lptr;          /* points to the current position in "pline" */
00592 SC_VDECL constval tagname_tab;/* tagname table */
00593 SC_VDECL constval libname_tab;/* library table (#pragma library "..." syntax) */
00594 SC_VDECL constval *curlibrary;/* current library */
00595 SC_VDECL symbol *curfunc;     /* pointer to current function */
00596 SC_VDECL char *inpfname;      /* name of the file currently read from */
00597 SC_VDECL char outfname[];     /* output file name */
00598 SC_VDECL char errfname[];     /* error file name */
00599 SC_VDECL char sc_ctrlchar;    /* the control character (or escape character) */
00600 SC_VDECL int litidx;          /* index to literal table */
00601 SC_VDECL int litmax;          /* current size of the literal table */
00602 SC_VDECL int stgidx;          /* index to the staging buffer */
00603 SC_VDECL int labnum;          /* number of (internal) labels */
00604 SC_VDECL int staging;         /* true if staging output */
00605 SC_VDECL cell declared;       /* number of local cells declared */
00606 SC_VDECL cell glb_declared;   /* number of global cells declared */
00607 SC_VDECL cell code_idx;       /* number of bytes with generated code */
00608 SC_VDECL int ntv_funcid;      /* incremental number of native function */
00609 SC_VDECL int errnum;          /* number of errors */
00610 SC_VDECL int warnnum;         /* number of warnings */
00611 SC_VDECL int sc_debug;        /* debug/optimization options (bit field) */
00612 SC_VDECL int charbits;        /* number of bits for a character */
00613 SC_VDECL int sc_packstr;      /* strings are packed by default? */
00614 SC_VDECL int sc_listing;      /* create .ASM file? */
00615 SC_VDECL int sc_compress;     /* compress bytecode? */
00616 SC_VDECL int sc_needsemicolon;/* semicolon required to terminate expressions? */
00617 SC_VDECL int sc_dataalign;    /* data alignment value */
00618 SC_VDECL int sc_alignnext;    /* must frame of the next function be aligned? */
00619 SC_VDECL int makereport;      /* do not generate a cross-reference report */
00620 SC_VDECL int curseg;          /* 1 if currently parsing CODE, 2 if parsing DATA */
00621 SC_VDECL cell sc_stksize;     /* stack size */
00622 SC_VDECL int freading;        /* is there an input file ready for reading? */
00623 SC_VDECL int fline;           /* the line number in the current file */
00624 SC_VDECL int fnumber;         /* number of files in the file table (debugging) */
00625 SC_VDECL int fcurrent;        /* current file being processed (debugging) */
00626 SC_VDECL int intest;          /* true if inside a test */
00627 SC_VDECL int sideeffect;      /* true if an expression causes a side-effect */
00628 SC_VDECL int stmtindent;      /* current indent of the statement */
00629 SC_VDECL int indent_nowarn;   /* skip warning "217 loose indentation" */
00630 SC_VDECL int sc_tabsize;      /* number of spaces that a TAB represents */
00631 SC_VDECL int sc_allowtags;    /* allow/detect tagnames in lex() */
00632 SC_VDECL int sc_status;       /* read/write status */
00633 SC_VDECL int sc_rationaltag;  /* tag for rational numbers */
00634 SC_VDECL int rational_digits; /* number of fractional digits */
00635 
00636 SC_VDECL FILE *inpf;          /* file read from (source or include) */
00637 SC_VDECL FILE *inpf_org;      /* main source file */
00638 SC_VDECL FILE *outf;          /* file written to */
00639 
00640 SC_VDECL jmp_buf errbuf;      /* target of longjmp() on a fatal error */
00641 #endif /* SC_SKIP_VDECL */
00642 
00643 #endif /* __SC_H */
SourceForge.net Logo