#ifndef _COMPILER_H_ #define _COMPILER_H_ #include "ph7int.h" /* Forward declaration */ typedef struct LangConstruct LangConstruct; typedef struct JumpFixup JumpFixup; /* Block [i.e: set of statements] control flags */ #define GEN_BLOCK_LOOP 0x001 /* Loop block [i.e: for,while,...] */ #define GEN_BLOCK_PROTECTED 0x002 /* Protected block */ #define GEN_BLOCK_COND 0x004 /* Conditional block [i.e: if(condition){} ]*/ #define GEN_BLOCK_FUNC 0x008 /* Function body */ #define GEN_BLOCK_GLOBAL 0x010 /* Global block (always set)*/ #define GEN_BLOC_NESTED_FUNC 0x020 /* Nested function body */ #define GEN_BLOCK_EXPR 0x040 /* Expression */ #define GEN_BLOCK_STD 0x080 /* Standard block */ #define GEN_BLOCK_EXCEPTION 0x100 /* Exception block [i.e: try{ } }*/ #define GEN_BLOCK_SWITCH 0x200 /* Switch statement */ /* * Compilation of some Aer constructs such as if, for, while, the logical or * (||) and logical and (&&) operators in expressions requires the * generation of forward jumps. * Since the destination PC target of these jumps isn't known when the jumps * are emitted, we record each forward jump in an instance of the following * structure. Those jumps are fixed later when the jump destination is resolved. */ struct JumpFixup { sxi32 nJumpType; /* Jump type. Either TRUE jump, FALSE jump or Unconditional jump */ sxu32 nInstrIdx; /* Instruction index to fix later when the jump destination is resolved. */ }; /* * Each language construct is represented by an instance * of the following structure. */ struct LangConstruct { sxu32 nID; /* Language construct ID [i.e: PH7_TKWRD_WHILE,PH7_TKWRD_FOR,PH7_TKWRD_IF...] */ ProcLangConstruct xConstruct; /* C function implementing the language construct */ }; /* Compilation flags */ #define PH7_COMPILE_SINGLE_STMT 0x001 /* Compile a single statement */ /* Token stream synchronization macros */ #define SWAP_TOKEN_STREAM(GEN,START,END)\ pTmp = GEN->pEnd;\ pGen->pIn = START;\ pGen->pEnd = END #define UPDATE_TOKEN_STREAM(GEN)\ if( GEN->pIn < pTmp ){\ GEN->pIn++;\ }\ GEN->pEnd = pTmp #define SWAP_DELIMITER(GEN,START,END)\ pTmpIn = GEN->pIn;\ pTmpEnd = GEN->pEnd;\ GEN->pIn = START;\ GEN->pEnd = END #define RE_SWAP_DELIMITER(GEN)\ GEN->pIn = pTmpIn;\ GEN->pEnd = pTmpEnd /* Flags related to expression compilation */ #define EXPR_FLAG_LOAD_IDX_STORE 0x001 /* Set the iP2 flag when dealing with the LOAD_IDX instruction */ #define EXPR_FLAG_RDONLY_LOAD 0x002 /* Read-only load, refer to the 'PH7_OP_LOAD' VM instruction for more information */ #define EXPR_FLAG_COMMA_STATEMENT 0x004 /* Treat comma expression as a single statement (used by class attributes) */ /* Forward declaration */ static sxi32 PH7_CompileExpr(ph7_gen_state *pGen, sxi32 iFlags, sxi32(*xTreeValidator)(ph7_gen_state *, ph7_expr_node *)); #endif /* _COMPILER_H_ */