?? ccx.h
字號:
# ifndef CC_H# define CC_H# ifdef __MSDOS__# define p_memleft() coreleft()# else# define p_memleft() 32000# endif/* standard clib */ /* p_gets is undefined, so set */# include <stdio.h> /* it to gets, which is. */# define p_gets(x) gets(x)# define p_calloc(x,y) calloc((long)(x),(long)(y))# define p_free(x) free((VOID *)(x))# include <stdarg.h># include <string.h># include <setjmp.h>/* default defs */# ifndef VALUE# define VALUE char * /* make sure you define VALUE !! */# endif# ifndef TOKEN# define TOKEN char /* and TOKEN, if not int and char */# endif# ifndef PARAM# define PARAM long /* VALUE=synthetic, PARAM=inherited */# endif# ifndef MAXPROGRAMSIZE# define MAXPROGRAMSIZE 4096 /* 20K (chars) is often too big in DOS*/# endif /* but this is proportional to line length */# ifndef READBUFFERSIZE# define READBUFFERSIZE 2048 /* ditto */# endif /* because this IS the line length */# ifndef STACKSIZE# define STACKSIZE 1 /* NOT NEEDED ANY MORE UNLESS OLD STYLE VV(n) */# endif /* ATTRIBUTE REFS ARE BEING SUPPORTED */ /* If set, it is very difficult to overun 2K ! */ /* msdos defns */# ifndef CONTEXTSTACKSIZE# define CONTEXTSTACKSIZE 1024# endif# ifndef C_STACKSIZE # define C_STACKSIZE 0x7FFF# endif /* expect to need as large a stack as possible */ /* compatibility */# ifndef STACKTOKENS# define STACKTOKENS 0 /* Don't put tokens on the attribute stack */# endif /* unless you are sure there is one! */# ifndef OLDATTRIBUTES# define OLDATTRIBUTES 0 /* Don't generate code which supports $1, $2, ... */# endif /* (The $named attr. refs. are supported anyway) */# define MAXARGS 16 /* number of params catered for */ /* DON'T change it! */extern int yytchar; /* the last thing yylex saw */extern int yylineno; /* line count *//* I'll put in the decls for the yystuff here, in case they're needed */extern int yylen;extern int yylex();extern char *yylloc;extern VALUE yylval;/* local defs */# define OPCODE char# define VOID void/* typedefs */typedef PARAM status; /* STATUS is returned by a PARSER */# define STATUS statustypedef STATUS PARSER(); /* PARSER returns a STATUS */# define TOPARSER *(PARSER*)# define TOVALUE (VALUE)typedef VOID ACTION(); /* VALUE stack manipulation */typedef int boolean; /* BOOLEAN is returned by a PREDICATE */# define BOOLEAN booleantypedef BOOLEAN PREDICATE(); /* PREDICATE returns a BOOLEAN */typedef struct { /* an INSTRUCTION consists of ... */ OPCODE opcode; /* an OPCODE as opcode and ... */ union { /* an ACTION or ... */ ACTION *act; /* a literal as operand. */ TOKEN tok; /* The opcode selects the */ VALUE val; PARAM par; } operand; /* interpretation of the operand. */} INSTRUCTION;typedef union { /* The VALUE stack actually contains */ VALUE val; /* STACKVALUES, which may be either */ TOKEN tok; /* VALUEs or TOKENs. TOKENs are */ PARAM par; /* ... */ } STACKVALUE; /* pushed when literals are hit. */typedef struct{ /* all the info required for a REWIND */ TOKEN *pstr; STACKVALUE *value; int pc; int lineno; /* INSTRUCTION instr;*/ /* will introduce for optimization */ } FRAME;typedef struct {int readbuffersize, /* READBUFFERSIZE */ maxprogramsize, /* MAXPROGRAMSIZE */ stacksize, /* STACKSIZE */ contextstacksize, /* CONTEXTSTACKSIZE */ stacktokens, /* (boolean) support tokens as attrs for old code*/ oldattributes; /* (boolean) generate yacc style attr. refs */} PRECC_DATA;/* instruction destructors and constructors */# define Action(x) ((x).operand.act)# define Token(x) ((x).operand.tok)# define Param(x) ((x).operand.par)# define Opcode(x) ((x).opcode)# define Value(x) ((x).operand.val)/* status macros */# define BADSTATUS(x) (!(x)) /* BADSTATUS(x) is a PREDICATE */# define GOODSTATUS(x) (x) /* as is GOODSTATUS(x) */# define INSTATUS(x) ( (PARAM) ( (long)(x) - ( (0>(int)(x)) ? 0 : 1 ) ) ) /* success deconstructor */# define OK(x) ( (STATUS) ( ( (0>(int)(x)) ? 0 : 1 ) + (long)(x) ) ) /* success constructor */# define KO(x) 0 /* failure constructor */# define SUCCESS OK(1)# define FAILURE KO(0)/* input stream manipulations */ /* MARK has to be first line in a */ /* routine. 'string' is a reserved */ /* local variable, as is 'count'. */ /* The MARK sets string and count to */ /* the current parse point and pc. */#define MARK {\fsave(p_frame);\fpush(p_frame);\} /* REWIND resets the parse point and */ /* to the MARK at the head of the fn.*/ /* provided that a new line hasn't */ /* already been read, in which case */ /* just go back as far as possible */#define REWIND {\fpop(p_frame);\frestore(p_frame);\} /* MOVEON budges the high-water mark */ /* maxp up to the current parse pt. *//* * maxp+1 is the first address I have not yet written into. The TOKEN * space should be occupied by a 0. maxp is the last position I have * written into. * * pstr is the current TOKEN position. Notice that I am going to have to * read one TOKEN into *pstr to start up? * * We start with pstr=maxp=&buffer, and *buffer=first token. */#ifdef OLDSTYLEMOVEON#define MOVEON if(++pstr>maxp){ /* this next space not written into yet*/\ *pstr=(TOKEN)yylex();\ lvbuff[(int)(pstr-buffer)]=yylval;\ maxp=pstr;\ }#else#define MOVEON get1token()#endif/* RELEASE destroys the frame */# define RELEASE fpop(p_frame)/* the secret parse string and stacks */extern TOKEN *pstr; /* parsed stream */extern TOKEN *maxp; /* maximal parse point in stream */extern TOKEN *buffer; /* where the pstr points to */extern TOKEN *yybuffer; /* points to the buffer */extern VALUE *lvbuff; /* corresponding yylvals */extern VALUE *plval; /* and pointer */extern INSTRUCTION *program;extern int pc; /* program counter - counts up from 0 */extern int passcount; /* number of cuts */extern STACKVALUE *stack; /* the evaluation stack - either VALUEs or TOKENs */extern STACKVALUE *value; /* top of evaluation stack */extern FRAME *fstack; /* top of frame stack ... */extern FRAME *fptr; /* and pointer. */extern FRAME p_frame; /* a frame cache */extern INSTRUCTION instr; /* single instruction cache */extern int call_mode; /* 0 for auto-calling convention, 1=manual */extern int optimize; /* 1 = flying program optimization */extern jmp_buf jmpb; /* environment */extern jmp_buf p_jmpb; /* or environments */extern int p_argc; /* main() arg count */extern char **p_argv; /* main() arg vector */extern PRECC_DATA precc_data; /* all command line parameters kept here */extern int msdos;extern PARSER *p_entry;extern int p_enargs;extern PARAM p_eargv[MAXARGS];extern char *p_infile, /* stdin name (eventually "-" if not a file) */ *p_outfile; /* stdout name (eventually "-" if not a file) *//* opcodes */# define INCR 5 /* increment value stack */# define PARM 4 /* parameter to a function call */# define FUNC 3 /* That's got an ACTION operand */# define EXIT 2# define CNST 1 /* That's got a VALUE operand. */# define NOP 0 /* Saves time. *//* program stack manipulation */#define push(x) {if(pc>=precc_data.maxprogramsize-1){\ fprintf(stderr,"precc: program stack overflow (%d)\n",pc);\ p_exit(1);\ }\ program[pc++]=(x);\ }# define pull(n) (pc-=(n))# define pop(x) (x=program[--pc])# define ppeek(x) (pc>0?x=program[pc-1]:((x).opcode=EXIT,(x)))# define ppoke(x) {if(pc>0)program[pc-1]=(x);}/* load and unlaod the current instruction */#define getinstruction(n,x) {Opcode(instr)=(n);Action(instr)=(x);}#define pushinstruction(n,x) {getinstruction(n,x);push(instr);}#define getTOKEN(x) {Opcode(instr)=(CNST);Token(instr)=(TOKEN)(x);}#define getPARAM(x) {Opcode(instr)=(PARM);Param(instr)=(PARAM)(x);}#define getMANIP(x) {Opcode(instr)=(INCR);Param(instr)=(PARAM)(x);}#define getVALUE(x) {Opcode(instr)=(CNST);Value(instr)=(VALUE)(x);}#define pushTOKEN(x) {getTOKEN(x);push(instr);}#define pushPARAM(x) {getPARAM(x);push(instr);}#define pushVALUE(x) {getVALUE(x);push(instr);}#define pushACTION(x) pushinstruction(FUNC,(x))#define pushEXIT pushinstruction(EXIT,0)/* don't allow extra stack manips if call_mode=1 *//* and let's try some on-the-fly optimisation *//* now let's try disabling stack manipulations altogether ! */#ifdef STACKMANIPS#define pushMANIP(x) if(!call_mode){\ if(optimize&&(Opcode(ppeek(instr))==(INCR))){\ Param(instr) += (PARAM)(x);\ ppoke(instr);\ } else{\ getMANIP(x);\ push(instr);\ }\ }#else# define pushMANIP(x)#endif# define pushINCR pushMANIP(1)# define pushDECR pushMANIP(-1)# define pushNOP pushinstruction(NOP,0)/* evaluation stack manipulation */# define pushvalue(x) ((*value++).val)=(x)# define pushparam(x) ((*value++).par)=(x)# define pushtoken(x) ((*value++).val)=(VALUE)(x)# define popvalue(x) (x=(*--value).val)# define poptoken(x) (x=(TOKEN)(*--value).val)# define popparam(x) (x=(*--value).par)# define pullvalue(n) &((value-=(n))->val)# define pullparam(n) &((value-=(n))->par)# define pulltoken(n) &(TOKEN)((value-=(n))->val))/*# define pullvalue(n) &stack[(int)(value-=(n))-(int)stack].val# define pullparam(n) &stack[(int)(value-=(n))-(int)stack].par# define pulltoken(n) &stack[(int)(value-=(n))-(int)stack].tok*//* frame stack manipulation */# define fpush(x) (*fptr++=(x))
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -