53a4992ac00fa297b0cdad9392ec4fdcd4d211ce
[framework/uifw/embryo.git] / src / bin / embryo_cc_sc.h
1 /*  Small compiler
2  *
3  *  Drafted after the Small-C compiler Version 2.01, originally created
4  *  by Ron Cain, july 1980, and enhanced by James E. Hendrix.
5  *
6  *  This version comes close to a complete rewrite.
7  *
8  *  Copyright R. Cain, 1980
9  *  Copyright J.E. Hendrix, 1982, 1983
10  *  Copyright T. Riemersma, 1997-2003
11  *
12  *  Version: $Id$
13  *
14  *  This software is provided "as-is", without any express or implied warranty.
15  *  In no event will the authors be held liable for any damages arising from
16  *  the use of this software.
17  *
18  *  Permission is granted to anyone to use this software for any purpose,
19  *  including commercial applications, and to alter it and redistribute it
20  *  freely, subject to the following restrictions:
21  *
22  *  1.  The origin of this software must not be misrepresented; you must not
23  *      claim that you wrote the original software. If you use this software in
24  *      a product, an acknowledgment in the product documentation would be
25  *      appreciated but is not required.
26  *  2.  Altered source versions must be plainly marked as such, and must not be
27  *      misrepresented as being the original software.
28  *  3.  This notice may not be removed or altered from any source distribution.
29  */
30
31 #ifndef EMBRYO_CC_SC_H
32 #define EMBRYO_CC_SC_H
33
34 #include <limits.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <setjmp.h>
38 #include "embryo_cc_osdefs.h"
39 #include "embryo_cc_amx.h"
40
41 #if HAVE___ATTRIBUTE__
42 #define __UNUSED__ __attribute__((unused))
43 #else
44 #define __UNUSED__
45 #endif
46
47 /* Note: the "cell" and "ucell" types are defined in AMX.H */
48
49 #define PUBLIC_CHAR '@'         /* character that defines a function "public" */
50 #define CTRL_CHAR   '\\'        /* default control character */
51
52 #define DIRSEP_CHAR '/'         /* directory separator character */
53
54 #define sDIMEN_MAX     2        /* maximum number of array dimensions */
55 #define sDEF_LITMAX  500        /* initial size of the literal pool, in "cells" */
56 #define sLINEMAX     65535      /* input line length (in characters) */
57 #define sDEF_AMXSTACK 4096      /* default stack size for AMX files */
58 #define sSTKMAX       80        /* stack for nested #includes and other uses */
59 #define PREPROC_TERM  '\x7f'    /* termination character for preprocessor expressions (the "DEL" code) */
60 #define sDEF_PREFIX   "default.inc"     /* default prefix filename */
61
62 typedef void       *stkitem;    /* type of items stored on the stack */
63
64 typedef struct __s_arginfo
65 {                               /* function argument info */
66    char                name[sNAMEMAX + 1];
67    char                ident;   /* iVARIABLE, iREFERENCE, iREFARRAY or iVARARGS */
68    char                usage;   /* uCONST */
69    int                *tags;    /* argument tag id. list */
70    int                 numtags; /* number of tags in the tag list */
71    int                 dim[sDIMEN_MAX];
72    int                 numdim;  /* number of dimensions */
73    unsigned char       hasdefault;      /* bit0: is there a default value? bit6: "tagof"; bit7: "sizeof" */
74    union
75    {
76       cell                val;  /* default value */
77       struct
78       {
79          char               *symname;   /* name of another symbol */
80          short               level;     /* indirection level for that symbol */
81       } size;                   /* used for "sizeof" default value */
82       struct
83       {
84          cell               *data;      /* values of default array */
85          int                 size;      /* complete length of default array */
86          int                 arraysize; /* size to reserve on the heap */
87          cell                addr;      /* address of the default array in the data segment */
88       } array;
89    } defvalue;                  /* default value, or pointer to default array */
90    int                 defvalue_tag;    /* tag of the default value */
91 } arginfo;
92
93 /*  Equate table, tagname table, library table */
94 typedef struct __s_constvalue
95 {
96    struct __s_constvalue *next;
97    char                name[sNAMEMAX + 1];
98    cell                value;
99    short               index;
100 } constvalue;
101
102 /*  Symbol table format
103  *
104  *  The symbol name read from the input file is stored in "name", the
105  *  value of "addr" is written to the output file. The address in "addr"
106  *  depends on the class of the symbol:
107  *      global          offset into the data segment
108  *      local           offset relative to the stack frame
109  *      label           generated hexadecimal number
110  *      function        offset into code segment
111  */
112 typedef struct __s_symbol
113 {
114    struct __s_symbol  *next;
115    struct __s_symbol  *parent;  /* hierarchical types (multi-dimensional arrays) */
116    char                name[sNAMEMAX + 1];
117    unsigned int        hash;    /* value derived from name, for quicker searching */
118    cell                addr;    /* address or offset (or value for constant, index for native function) */
119    char                vclass;  /* sLOCAL if "addr" refers to a local symbol */
120    char                ident;   /* see below for possible values */
121    char                usage;   /* see below for possible values */
122    int                 compound;        /* compound level (braces nesting level) */
123    int                 tag;     /* tagname id */
124    union
125    {
126       int                 declared;     /* label: how many local variables are declared */
127       int                 idxtag;       /* array: tag of array indices */
128       constvalue         *lib;  /* native function: library it is part of *///??? use "stringlist"
129    } x;                         /* 'x' for 'extra' */
130    union
131    {
132       arginfo            *arglist;      /* types of all parameters for functions */
133       struct
134       {
135          cell                length;    /* arrays: length (size) */
136          short               level;     /* number of dimensions below this level */
137       } array;
138    } dim;                       /* for 'dimension', both functions and arrays */
139    int                 fnumber; /* static global variables: file number in which the declaration is visible */
140    struct __s_symbol **refer;   /* referrer list, functions that "use" this symbol */
141    int                 numrefers;       /* number of entries in the referrer list */
142 } symbol;
143
144 /*  Possible entries for "ident". These are used in the "symbol", "value"
145  *  and arginfo structures. Not every constant is valid for every use.
146  *  In an argument list, the list is terminated with a "zero" ident; labels
147  *  cannot be passed as function arguments, so the value 0 is overloaded.
148  */
149 #define iLABEL      0
150 #define iVARIABLE   1           /* cell that has an address and that can be fetched directly (lvalue) */
151 #define iREFERENCE  2           /* iVARIABLE, but must be dereferenced */
152 #define iARRAY      3
153 #define iREFARRAY   4           /* an array passed by reference (i.e. a pointer) */
154 #define iARRAYCELL  5           /* array element, cell that must be fetched indirectly */
155 #define iARRAYCHAR  6           /* array element, character from cell from array */
156 #define iEXPRESSION 7           /* expression result, has no address (rvalue) */
157 #define iCONSTEXPR  8           /* constant expression (or constant symbol) */
158 #define iFUNCTN     9
159 #define iREFFUNC    10          /* function passed as a parameter */
160 #define iVARARGS    11          /* function specified ... as argument(s) */
161
162 /*  Possible entries for "usage"
163  *
164  *  This byte is used as a serie of bits, the syntax is different for
165  *  functions and other symbols:
166  *
167  *  VARIABLE
168  *  bits: 0     (uDEFINE) the variable is defined in the source file
169  *        1     (uREAD) the variable is "read" (accessed) in the source file
170  *        2     (uWRITTEN) the variable is altered (assigned a value)
171  *        3     (uCONST) the variable is constant (may not be assigned to)
172  *        4     (uPUBLIC) the variable is public
173  *        6     (uSTOCK) the variable is discardable (without warning)
174  *
175  *  FUNCTION
176  *  bits: 0     (uDEFINE) the function is defined ("implemented") in the source file
177  *        1     (uREAD) the function is invoked in the source file
178  *        2     (uRETVALUE) the function returns a value (or should return a value)
179  *        3     (uPROTOTYPED) the function was prototyped
180  *        4     (uPUBLIC) the function is public
181  *        5     (uNATIVE) the function is native
182  *        6     (uSTOCK) the function is discardable (without warning)
183  *        7     (uMISSING) the function is not implemented in this source file
184  *
185  *  CONSTANT
186  *  bits: 0     (uDEFINE) the symbol is defined in the source file
187  *        1     (uREAD) the constant is "read" (accessed) in the source file
188  *        3     (uPREDEF) the constant is pre-defined and should be kept between passes
189  */
190 #define uDEFINE   0x01
191 #define uREAD     0x02
192 #define uWRITTEN  0x04
193 #define uRETVALUE 0x04          /* function returns (or should return) a value */
194 #define uCONST    0x08
195 #define uPROTOTYPED 0x08
196 #define uPREDEF   0x08          /* constant is pre-defined */
197 #define uPUBLIC   0x10
198 #define uNATIVE   0x20
199 #define uSTOCK    0x40
200 #define uMISSING  0x80
201 /* uRETNONE is not stored in the "usage" field of a symbol. It is
202  * used during parsing a function, to detect a mix of "return;" and
203  * "return value;" in a few special cases.
204  */
205 #define uRETNONE  0x10
206
207 #define uTAGOF    0x40          /* set in the "hasdefault" field of the arginfo struct */
208 #define uSIZEOF   0x80          /* set in the "hasdefault" field of the arginfo struct */
209
210 #define uMAINFUNC "main"
211
212 #define sGLOBAL   0             /* global/local variable/constant class */
213 #define sLOCAL    1
214 #define sSTATIC   2             /* global life, local scope */
215
216 typedef struct
217 {
218    symbol             *sym;     /* symbol in symbol table, NULL for (constant) expression */
219    cell                constval;        /* value of the constant expression (if ident==iCONSTEXPR)
220                                          * also used for the size of a literal array */
221    int                 tag;     /* tagname id (of the expression) */
222    char                ident;   /* iCONSTEXPR, iVARIABLE, iARRAY, iARRAYCELL,
223                                  * iEXPRESSION or iREFERENCE */
224    char                boolresult;      /* boolean result for relational operators */
225    cell               *arrayidx;        /* last used array indices, for checking self assignment */
226 } value;
227
228 /*  "while" statement queue (also used for "for" and "do - while" loops) */
229 enum
230 {
231    wqBRK,                       /* used to restore stack for "break" */
232    wqCONT,                      /* used to restore stack for "continue" */
233    wqLOOP,                      /* loop start label number */
234    wqEXIT,                      /* loop exit label number (jump if false) */
235    /* --- */
236    wqSIZE                       /* "while queue" size */
237 };
238
239 #define wqTABSZ (24*wqSIZE)     /* 24 nested loop statements */
240
241 enum
242 {
243    statIDLE,                    /* not compiling yet */
244    statFIRST,                   /* first pass */
245    statWRITE,                   /* writing output */
246    statSKIP,                    /* skipping output */
247 };
248
249 typedef struct __s_stringlist
250 {
251    struct __s_stringlist *next;
252    char               *line;
253 } stringlist;
254
255 typedef struct __s_stringpair
256 {
257    struct __s_stringpair *next;
258    char               *first;
259    char               *second;
260    int                 matchlength;
261 } stringpair;
262
263 /* macros for code generation */
264 #define opcodes(n)      ((n)*sizeof(cell))      /* opcode size */
265 #define opargs(n)       ((n)*sizeof(cell))      /* size of typical argument */
266
267 /*  Tokens recognized by lex()
268  *  Some of these constants are assigned as well to the variable "lastst"
269  */
270 #define tFIRST   256            /* value of first multi-character operator */
271 #define tMIDDLE  279            /* value of last multi-character operator */
272 #define tLAST    320            /* value of last multi-character match-able token */
273 /* multi-character operators */
274 #define taMULT   256            /* *= */
275 #define taDIV    257            /* /= */
276 #define taMOD    258            /* %= */
277 #define taADD    259            /* += */
278 #define taSUB    260            /* -= */
279 #define taSHL    261            /* <<= */
280 #define taSHRU   262            /* >>>= */
281 #define taSHR    263            /* >>= */
282 #define taAND    264            /* &= */
283 #define taXOR    265            /* ^= */
284 #define taOR     266            /* |= */
285 #define tlOR     267            /* || */
286 #define tlAND    268            /* && */
287 #define tlEQ     269            /* == */
288 #define tlNE     270            /* != */
289 #define tlLE     271            /* <= */
290 #define tlGE     272            /* >= */
291 #define tSHL     273            /* << */
292 #define tSHRU    274            /* >>> */
293 #define tSHR     275            /* >> */
294 #define tINC     276            /* ++ */
295 #define tDEC     277            /* -- */
296 #define tELLIPS  278            /* ... */
297 #define tDBLDOT  279            /* .. */
298 /* reserved words (statements) */
299 #define tASSERT  280
300 #define tBREAK   281
301 #define tCASE    282
302 #define tCHAR    283
303 #define tCONST   284
304 #define tCONTINUE 285
305 #define tDEFAULT 286
306 #define tDEFINED 287
307 #define tDO      288
308 #define tELSE    289
309 #define tENUM    290
310 #define tEXIT    291
311 #define tFOR     292
312 #define tFORWARD 293
313 #define tGOTO    294
314 #define tIF      295
315 #define tNATIVE  296
316 #define tNEW     297
317 #define tOPERATOR 298
318 #define tPUBLIC  299
319 #define tRETURN  300
320 #define tSIZEOF  301
321 #define tSLEEP   302
322 #define tSTATIC  303
323 #define tSTOCK   304
324 #define tSWITCH  305
325 #define tTAGOF   306
326 #define tWHILE   307
327 /* compiler directives */
328 #define tpASSERT 308            /* #assert */
329 #define tpDEFINE 309
330 #define tpELSE   310            /* #else */
331 #define tpEMIT   311
332 #define tpENDIF  312
333 #define tpENDINPUT 313
334 #define tpENDSCRPT 314
335 #define tpFILE   315
336 #define tpIF     316            /* #if */
337 #define tINCLUDE 317
338 #define tpLINE   318
339 #define tpPRAGMA 319
340 #define tpUNDEF  320
341 /* semicolon is a special case, because it can be optional */
342 #define tTERM    321            /* semicolon or newline */
343 #define tENDEXPR 322            /* forced end of expression */
344 /* other recognized tokens */
345 #define tNUMBER  323            /* integer number */
346 #define tRATIONAL 324           /* rational number */
347 #define tSYMBOL  325
348 #define tLABEL   326
349 #define tSTRING  327
350 #define tEXPR    328            /* for assigment to "lastst" only */
351
352 /* (reversed) evaluation of staging buffer */
353 #define sSTARTREORDER 1
354 #define sENDREORDER   2
355 #define sEXPRSTART    0xc0      /* top 2 bits set, rest is free */
356 #define sMAXARGS      64        /* relates to the bit pattern of sEXPRSTART */
357
358 /* codes for ffabort() */
359 #define xEXIT           1       /* exit code in PRI */
360 #define xASSERTION      2       /* abort caused by failing assertion */
361 #define xSTACKERROR     3       /* stack/heap overflow */
362 #define xBOUNDSERROR    4       /* array index out of bounds */
363 #define xMEMACCESS      5       /* data access error */
364 #define xINVINSTR       6       /* invalid instruction */
365 #define xSTACKUNDERFLOW 7       /* stack underflow */
366 #define xHEAPUNDERFLOW  8       /* heap underflow */
367 #define xCALLBACKERR    9       /* no, or invalid, callback */
368 #define xSLEEP         12       /* sleep, exit code in PRI, tag in ALT */
369
370 /* Miscellaneous  */
371 #if !defined TRUE
372 #define FALSE         0
373 #define TRUE          1
374 #endif
375 #define sIN_CSEG        1       /* if parsing CODE */
376 #define sIN_DSEG        2       /* if parsing DATA */
377 #define sCHKBOUNDS      1       /* bit position in "debug" variable: check bounds */
378 #define sSYMBOLIC       2       /* bit position in "debug" variable: symbolic info */
379 #define sNOOPTIMIZE     4       /* bit position in "debug" variable: no optimization */
380 #define sRESET          0       /* reset error flag */
381 #define sFORCESET       1       /* force error flag on */
382 #define sEXPRMARK       2       /* mark start of expression */
383 #define sEXPRRELEASE    3       /* mark end of expression */
384
385 #if INT_MAX<0x8000u
386 #define PUBLICTAG   0x8000u
387 #define FIXEDTAG    0x4000u
388 #else
389 #define PUBLICTAG   0x80000000Lu
390 #define FIXEDTAG    0x40000000Lu
391 #endif
392 #define TAGMASK       (~PUBLICTAG)
393
394
395 /*
396  * Functions you call from the "driver" program
397  */
398    int                 sc_compile(int argc, char **argv);
399    int                 sc_addconstant(char *name, cell value, int tag);
400    int                 sc_addtag(char *name);
401
402 /*
403  * Functions called from the compiler (to be implemented by you)
404  */
405
406 /* general console output */
407    int                 sc_printf(const char *message, ...);
408
409 /* error report function */
410    int                 sc_error(int number, char *message, char *filename,
411                                 int firstline, int lastline, va_list argptr);
412
413 /* input from source file */
414    void               *sc_opensrc(char *filename);      /* reading only */
415    void                sc_closesrc(void *handle);       /* never delete */
416    void                sc_resetsrc(void *handle, void *position);       /* reset to a position marked earlier */
417    char               *sc_readsrc(void *handle, char *target, int maxchars);
418    void               *sc_getpossrc(void *handle);      /* mark the current position */
419    int                 sc_eofsrc(void *handle);
420
421 /* output to intermediate (.ASM) file */
422    void               *sc_openasm(int fd);      /* read/write */
423    void                sc_closeasm(void *handle);
424    void                sc_resetasm(void *handle);
425    int                 sc_writeasm(void *handle, char *str);
426    char               *sc_readasm(void *handle, char *target, int maxchars);
427
428 /* output to binary (.AMX) file */
429    void               *sc_openbin(char *filename);
430    void                sc_closebin(void *handle, int deletefile);
431    void                sc_resetbin(void *handle);
432    int                 sc_writebin(void *handle, void *buffer, int size);
433    long                sc_lengthbin(void *handle);      /* return the length of the file */
434
435 /* function prototypes in SC1.C */
436 symbol     *fetchfunc(char *name, int tag);
437 char       *operator_symname(char *symname, char *opername, int tag1,
438                                      int tag2, int numtags, int resulttag);
439 char       *funcdisplayname(char *dest, char *funcname);
440 int         constexpr(cell * val, int *tag);
441 constvalue *append_constval(constvalue * table, char *name, cell val,
442                                     short index);
443 constvalue *find_constval(constvalue * table, char *name, short index);
444 void        delete_consttable(constvalue * table);
445 void        add_constant(char *name, cell val, int vclass, int tag);
446 void        exporttag(int tag);
447
448 /* function prototypes in SC2.C */
449 void        pushstk(stkitem val);
450 stkitem     popstk(void);
451 int         plungequalifiedfile(char *name);    /* explicit path included */
452 int         plungefile(char *name, int try_currentpath, int try_includepaths);  /* search through "include" paths */
453 void        preprocess(void);
454 void        lexinit(void);
455 int         lex(cell * lexvalue, char **lexsym);
456 void        lexpush(void);
457 void        lexclr(int clreol);
458 int         matchtoken(int token);
459 int         tokeninfo(cell * val, char **str);
460 int         needtoken(int token);
461 void        stowlit(cell value);
462 int         alphanum(char c);
463 void        delete_symbol(symbol * root, symbol * sym);
464 void        delete_symbols(symbol * root, int level, int del_labels,
465                                    int delete_functions);
466 int         refer_symbol(symbol * entry, symbol * bywhom);
467 void        markusage(symbol * sym, int usage);
468 unsigned int namehash(char *name);
469 symbol     *findglb(char *name);
470 symbol     *findloc(char *name);
471 symbol     *findconst(char *name);
472 symbol     *finddepend(symbol * parent);
473 symbol     *addsym(char *name, cell addr, int ident, int vclass,
474                            int tag, int usage);
475 symbol     *addvariable(char *name, cell addr, int ident, int vclass,
476                                 int tag, int dim[], int numdim, int idxtag[]);
477 int         getlabel(void);
478 char       *itoh(ucell val);
479
480 /* function prototypes in SC3.C */
481 int         check_userop(void (*oper) (void), int tag1, int tag2,
482                                  int numparam, value * lval, int *resulttag);
483 int         matchtag(int formaltag, int actualtag, int allowcoerce);
484 int         expression(int *constant, cell * val, int *tag,
485                                int chkfuncresult);
486 int         hier14(value * lval1);      /* the highest expression level */
487
488 /* function prototypes in SC4.C */
489 void        writeleader(void);
490 void        writetrailer(void);
491 void        begcseg(void);
492 void        begdseg(void);
493 void        setactivefile(int fnumber);
494 cell        nameincells(char *name);
495 void        setfile(char *name, int fileno);
496 void        setline(int line, int fileno);
497 void        setlabel(int index);
498 void        endexpr(int fullexpr);
499 void        startfunc(char *fname);
500 void        endfunc(void);
501 void        alignframe(int numbytes);
502 void        defsymbol(char *name, int ident, int vclass, cell offset,
503                               int tag);
504 void        symbolrange(int level, cell size);
505 void        rvalue(value * lval);
506 void        address(symbol * ptr);
507 void        store(value * lval);
508 void        memcopy(cell size);
509 void        copyarray(symbol * sym, cell size);
510 void        fillarray(symbol * sym, cell size, cell value);
511 void        const1(cell val);
512 void        const2(cell val);
513 void        moveto1(void);
514 void        push1(void);
515 void        push2(void);
516 void        pushval(cell val);
517 void        pop1(void);
518 void        pop2(void);
519 void        swap1(void);
520 void        ffswitch(int label);
521 void        ffcase(cell value, char *labelname, int newtable);
522 void        ffcall(symbol * sym, int numargs);
523 void        ffret(void);
524 void        ffabort(int reason);
525 void        ffbounds(cell size);
526 void        jumplabel(int number);
527 void        defstorage(void);
528 void        modstk(int delta);
529 void        setstk(cell value);
530 void        modheap(int delta);
531 void        setheap_pri(void);
532 void        setheap(cell value);
533 void        cell2addr(void);
534 void        cell2addr_alt(void);
535 void        addr2cell(void);
536 void        char2addr(void);
537 void        charalign(void);
538 void        addconst(cell value);
539
540 /*  Code generation functions for arithmetic operators.
541  *
542  *  Syntax: o[u|s|b]_name
543  *          |   |   | +--- name of operator
544  *          |   |   +----- underscore
545  *          |   +--------- "u"nsigned operator, "s"igned operator or "b"oth
546  *          +------------- "o"perator
547  */
548 void        os_mult(void);      /* multiplication (signed) */
549 void        os_div(void);       /* division (signed) */
550 void        os_mod(void);       /* modulus (signed) */
551 void        ob_add(void);       /* addition */
552 void        ob_sub(void);       /* subtraction */
553 void        ob_sal(void);       /* shift left (arithmetic) */
554 void        os_sar(void);       /* shift right (arithmetic, signed) */
555 void        ou_sar(void);       /* shift right (logical, unsigned) */
556 void        ob_or(void);        /* bitwise or */
557 void        ob_xor(void);       /* bitwise xor */
558 void        ob_and(void);       /* bitwise and */
559 void        ob_eq(void);        /* equality */
560 void        ob_ne(void);        /* inequality */
561 void        relop_prefix(void);
562 void        relop_suffix(void);
563 void        os_le(void);        /* less or equal (signed) */
564 void        os_ge(void);        /* greater or equal (signed) */
565 void        os_lt(void);        /* less (signed) */
566 void        os_gt(void);        /* greater (signed) */
567
568 void        lneg(void);
569 void        neg(void);
570 void        invert(void);
571 void        nooperation(void);
572 void        inc(value * lval);
573 void        dec(value * lval);
574 void        jmp_ne0(int number);
575 void        jmp_eq0(int number);
576 void        outval(cell val, int newline);
577
578 /* function prototypes in SC5.C */
579 int         error(int number, ...);
580 void        errorset(int code);
581
582 /* function prototypes in SC6.C */
583 void        assemble(FILE * fout, FILE * fin);
584
585 /* function prototypes in SC7.C */
586 void        stgbuffer_cleanup(void);
587 void        stgmark(char mark);
588 void        stgwrite(char *st);
589 void        stgout(int index);
590 void        stgdel(int index, cell code_index);
591 int         stgget(int *index, cell * code_index);
592 void        stgset(int onoff);
593 int         phopt_init(void);
594 int         phopt_cleanup(void);
595
596 /* function prototypes in SCLIST.C */
597 stringpair *insert_alias(char *name, char *alias);
598 stringpair *find_alias(char *name);
599 int         lookup_alias(char *target, char *name);
600 void        delete_aliastable(void);
601 stringlist *insert_path(char *path);
602 char       *get_path(int index);
603 void        delete_pathtable(void);
604 stringpair *insert_subst(char *pattern, char *substitution,
605                                  int prefixlen);
606 int         get_subst(int index, char **pattern, char **substitution);
607 stringpair *find_subst(char *name, int length);
608 int         delete_subst(char *name, int length);
609 void        delete_substtable(void);
610
611 /* external variables (defined in scvars.c) */
612 extern symbol     loctab;       /* local symbol table */
613 extern symbol     glbtab;       /* global symbol table */
614 extern cell      *litq; /* the literal queue */
615 extern char       pline[];      /* the line read from the input file */
616 extern char      *lptr; /* points to the current position in "pline" */
617 extern constvalue tagname_tab;  /* tagname table */
618 extern constvalue libname_tab;  /* library table (#pragma library "..." syntax) *///??? use "stringlist" type
619 extern constvalue *curlibrary;  /* current library */
620 extern symbol    *curfunc;      /* pointer to current function */
621 extern char      *inpfname;     /* name of the file currently read from */
622 extern char       outfname[];   /* output file name */
623 extern char       sc_ctrlchar;  /* the control character (or escape character) */
624 extern int        litidx;       /* index to literal table */
625 extern int        litmax;       /* current size of the literal table */
626 extern int        stgidx;       /* index to the staging buffer */
627 extern int        labnum;       /* number of (internal) labels */
628 extern int        staging;      /* true if staging output */
629 extern cell       declared;     /* number of local cells declared */
630 extern cell       glb_declared; /* number of global cells declared */
631 extern cell       code_idx;     /* number of bytes with generated code */
632 extern int        ntv_funcid;   /* incremental number of native function */
633 extern int        errnum;       /* number of errors */
634 extern int        warnnum;      /* number of warnings */
635 extern int        sc_debug;     /* debug/optimization options (bit field) */
636 extern int        charbits;     /* number of bits for a character */
637 extern int        sc_packstr;   /* strings are packed by default? */
638 extern int        sc_asmfile;   /* create .ASM file? */
639 extern int        sc_listing;   /* create .LST file? */
640 extern int        sc_compress;  /* compress bytecode? */
641 extern int        sc_needsemicolon;     /* semicolon required to terminate expressions? */
642 extern int        sc_dataalign; /* data alignment value */
643 extern int        sc_alignnext; /* must frame of the next function be aligned? */
644 extern int        curseg;       /* 1 if currently parsing CODE, 2 if parsing DATA */
645 extern cell       sc_stksize;   /* stack size */
646 extern int        freading;     /* is there an input file ready for reading? */
647 extern int        fline;        /* the line number in the current file */
648 extern int        fnumber;      /* number of files in the file table (debugging) */
649 extern int        fcurrent;     /* current file being processed (debugging) */
650 extern int        intest;       /* true if inside a test */
651 extern int        sideeffect;   /* true if an expression causes a side-effect */
652 extern int        stmtindent;   /* current indent of the statement */
653 extern int        indent_nowarn;        /* skip warning "217 loose indentation" */
654 extern int        sc_tabsize;   /* number of spaces that a TAB represents */
655 extern int        sc_allowtags; /* allow/detect tagnames in lex() */
656 extern int        sc_status;    /* read/write status */
657 extern int        sc_rationaltag;       /* tag for rational numbers */
658 extern int        rational_digits;      /* number of fractional digits */
659
660 extern FILE      *inpf; /* file read from (source or include) */
661 extern FILE      *inpf_org;     /* main source file */
662 extern FILE      *outf; /* file written to */
663
664 extern jmp_buf    errbuf;       /* target of longjmp() on a fatal error */
665
666 #endif