1 /******************************************** 2 code.h 3 copyright 2009-2012,2019, Thomas E. Dickey 4 copyright 1991-1994,1995, Michael D. Brennan 5 6 This is a source file for mawk, an implementation of 7 the AWK programming language. 8 9 Mawk is distributed without warranty under the terms of 10 the GNU General Public License, version 2, 1991. 11 ********************************************/ 12 13 /* 14 * $MawkId: code.h,v 1.11 2019/01/30 00:49:25 tom Exp $ 15 */ 16 17 /* code.h */ 18 19 #ifndef MAWK_CODE_H 20 #define MAWK_CODE_H 21 22 #include "memory.h" 23 24 #define PAGESZ 512 25 /* number of code instructions allocated at one time */ 26 #define CODEWARN 16 27 28 /* coding scope */ 29 #define SCOPE_MAIN 0 30 #define SCOPE_BEGIN 1 31 #define SCOPE_END 2 32 #define SCOPE_FUNCT 3 33 34 typedef struct { 35 INST *base, *limit, *warn, *ptr; 36 } CODEBLOCK; 37 38 extern CODEBLOCK active_code; 39 extern CODEBLOCK *main_code_p, *begin_code_p, *end_code_p; 40 41 extern INST *main_start, *begin_start, *end_start; 42 extern size_t main_size, begin_size; 43 extern INST *execution_start; 44 extern INST *next_label; /* next statements jump to here */ 45 extern int dump_code_flag; 46 47 #define CodeOffset(base) (int)(code_ptr - (base)) 48 49 #define code_ptr active_code.ptr 50 #define code_base active_code.base 51 #define code_warn active_code.warn 52 #define code_limit active_code.limit 53 #define code_offset CodeOffset(code_base) 54 55 #define INST_BYTES(x) (sizeof(INST)*(unsigned)(x)) 56 57 extern CELL eval_stack[]; 58 extern int exit_code; 59 60 #define code1(x) code_ptr++ -> op = (x) 61 /* shutup picky compilers */ 62 #define code2(x,p) xcode2(x,(PTR)(p)) 63 64 void xcode2(int, PTR); 65 void code2op(int, int); 66 INST *code_shrink(CODEBLOCK *, size_t *); 67 void code_grow(void); 68 void set_code(void); 69 void be_setup(int); 70 void dump_code(void); 71 72 /* the machine opcodes */ 73 /* to avoid confusion with a ptr FE_PUSHA must have op code 0 */ 74 75 typedef enum { 76 FE_PUSHA = 0 77 ,FE_PUSHI 78 ,F_PUSHA 79 ,F_PUSHI 80 ,NF_PUSHI 81 ,_HALT 82 ,_STOP 83 ,_PUSHC 84 ,_PUSHD 85 ,_PUSHS 86 ,_PUSHINT 87 ,_PUSHA 88 ,_PUSHI 89 ,L_PUSHA 90 ,L_PUSHI 91 ,AE_PUSHA 92 ,AE_PUSHI 93 ,A_PUSHA 94 ,LAE_PUSHA 95 ,LAE_PUSHI 96 ,LA_PUSHA 97 ,_POP 98 ,_ADD 99 ,_SUB 100 ,_MUL 101 ,_DIV 102 ,_MOD 103 ,_POW 104 ,_NOT 105 ,_TEST 106 ,A_LENGTH 107 ,A_TEST 108 ,A_DEL 109 ,ALOOP 110 ,A_CAT 111 ,_UMINUS 112 ,_UPLUS 113 ,_ASSIGN 114 ,_ADD_ASG 115 ,_SUB_ASG 116 ,_MUL_ASG 117 ,_DIV_ASG 118 ,_MOD_ASG 119 ,_POW_ASG 120 ,F_ASSIGN 121 ,F_ADD_ASG 122 ,F_SUB_ASG 123 ,F_MUL_ASG 124 ,F_DIV_ASG 125 ,F_MOD_ASG 126 ,F_POW_ASG 127 ,_CAT 128 ,_BUILTIN 129 ,_PRINT 130 ,_POST_INC 131 ,_POST_DEC 132 ,_PRE_INC 133 ,_PRE_DEC 134 ,F_POST_INC 135 ,F_POST_DEC 136 ,F_PRE_INC 137 ,F_PRE_DEC 138 ,_JMP 139 ,_JNZ 140 ,_JZ 141 ,_LJZ 142 ,_LJNZ 143 ,_EQ 144 ,_NEQ 145 ,_LT 146 ,_LTE 147 ,_GT 148 ,_GTE 149 ,_MATCH0 150 ,_MATCH1 151 ,_MATCH2 152 ,_EXIT 153 ,_EXIT0 154 ,_NEXT 155 ,_NEXTFILE 156 ,_RANGE 157 ,_CALL 158 ,_RET 159 ,_RET0 160 ,SET_ALOOP 161 ,POP_AL 162 ,OL_GL 163 ,OL_GL_NR 164 ,_OMAIN 165 ,_JMAIN 166 ,DEL_A 167 } MAWK_OPCODES; 168 169 #endif /* MAWK_CODE_H */ 170