From 54654ae7e480be0e9a929d0fe9c3c5ba6d46535c Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 6 Mar 2018 05:27:21 +0000 Subject: Convert macros to enums - constrained by need for matching table. --- generic/tclCompile.c | 16 +-- generic/tclCompile.h | 282 ++++++++++++++++++++++------------------------- generic/tclDisassemble.c | 2 +- generic/tclExecute.c | 4 +- 4 files changed, 143 insertions(+), 161 deletions(-) diff --git a/generic/tclCompile.c b/generic/tclCompile.c index 52c1f11..cc65d12 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.c @@ -129,9 +129,9 @@ InstructionDesc const tclInstructionTable[] = { {"jumpFalse4", 5, -1, 1, {OPERAND_OFFSET4}}, /* Jump relative to (pc + op4) if stktop expr object is false */ - {"lor", 1, -1, 0, {OPERAND_NONE}}, +// {"lor", 1, -1, 0, {OPERAND_NONE}}, /* Logical or: push (stknext || stktop) */ - {"land", 1, -1, 0, {OPERAND_NONE}}, +// {"land", 1, -1, 0, {OPERAND_NONE}}, /* Logical and: push (stknext && stktop) */ {"bitor", 1, -1, 0, {OPERAND_NONE}}, /* Bitwise or: push (stknext | stktop) */ @@ -173,9 +173,9 @@ InstructionDesc const tclInstructionTable[] = { /* Bitwise not: push ~stktop */ {"not", 1, 0, 0, {OPERAND_NONE}}, /* Logical not: push !stktop */ - {"callBuiltinFunc1", 2, 1, 1, {OPERAND_UINT1}}, +// {"callBuiltinFunc1", 2, 1, 1, {OPERAND_UINT1}}, /* Call builtin math function with index op1; any args are on stk */ - {"callFunc1", 2, INT_MIN, 1, {OPERAND_UINT1}}, +// {"callFunc1", 2, INT_MIN, 1, {OPERAND_UINT1}}, /* Call non-builtin func objv[0]; = */ {"tryCvtToNumeric", 1, 0, 0, {OPERAND_NONE}}, /* Try converting stktop to first int then double if possible. */ @@ -186,10 +186,10 @@ InstructionDesc const tclInstructionTable[] = { /* Skip to next iteration of closest enclosing loop; if none, return * TCL_CONTINUE code. */ - {"foreach_start4", 5, 0, 1, {OPERAND_AUX4}}, +// {"foreach_start4", 5, 0, 1, {OPERAND_AUX4}}, /* Initialize execution of a foreach loop. Operand is aux data index * of the ForeachInfo structure for the foreach command. */ - {"foreach_step4", 5, +1, 1, {OPERAND_AUX4}}, +// {"foreach_step4", 5, +1, 1, {OPERAND_AUX4}}, /* "Step" or begin next iteration of foreach loop. Push 0 if to * terminate loop, else push 1. */ @@ -340,7 +340,7 @@ InstructionDesc const tclInstructionTable[] = { {"dictNext", 5, +3, 1, {OPERAND_LVT4}}, /* Get the next iteration from the iterator in op4's local scalar. * Stack: ... => ... value key doneBool */ - {"dictDone", 5, 0, 1, {OPERAND_LVT4}}, +// {"dictDone", 5, 0, 1, {OPERAND_LVT4}}, /* Terminate the iterator in op4's local scalar. Use unsetScalar * instead (with 0 for flags). */ {"dictUpdateStart", 9, 0, 2, {OPERAND_LVT4, OPERAND_AUX4}}, @@ -1428,7 +1428,7 @@ TclInitCompileEnv( { Interp *iPtr = (Interp *) interp; - assert(tclInstructionTable[LAST_INST_OPCODE+1].name == NULL); + assert(tclInstructionTable[LAST_INST_OPCODE].name == NULL); envPtr->iPtr = iPtr; envPtr->source = stringPtr; diff --git a/generic/tclCompile.h b/generic/tclCompile.h index 8c4d544..b84cd48 100644 --- a/generic/tclCompile.h +++ b/generic/tclCompile.h @@ -575,7 +575,7 @@ INST_JUMP_FALSE1, INST_JUMP_FALSE4, /* Opcodes 42 to 64 */ -INST_BITOR=42, +INST_BITOR, INST_BITXOR, INST_BITAND, INST_EQ, @@ -595,234 +595,216 @@ INST_UPLUS, INST_UMINUS, INST_BITNOT, INST_LNOT, -INST_TRY_CVT_TO_NUMERIC=64 - - - -}; - - - +INST_TRY_CVT_TO_NUMERIC, /* Opcodes 65 to 66 */ -#define INST_BREAK 65 -#define INST_CONTINUE 66 +INST_BREAK, +INST_CONTINUE, /* Opcodes 69 to 72 */ -#define INST_BEGIN_CATCH4 69 -#define INST_END_CATCH 70 -#define INST_PUSH_RESULT 71 -#define INST_PUSH_RETURN_CODE 72 +INST_BEGIN_CATCH4, +INST_END_CATCH, +INST_PUSH_RESULT, +INST_PUSH_RETURN_CODE, /* Opcodes 73 to 78 */ -#define INST_STR_EQ 73 -#define INST_STR_NEQ 74 -#define INST_STR_CMP 75 -#define INST_STR_LEN 76 -#define INST_STR_INDEX 77 -#define INST_STR_MATCH 78 - -/* Opcodes 78 to 81 */ -#define INST_LIST 79 -#define INST_LIST_INDEX 80 -#define INST_LIST_LENGTH 81 +INST_STR_EQ, +INST_STR_NEQ, +INST_STR_CMP, +INST_STR_LEN, +INST_STR_INDEX, +INST_STR_MATCH, + +/* Opcodes 79 to 81 */ +INST_LIST, +INST_LIST_INDEX, +INST_LIST_LENGTH, /* Opcodes 82 to 87 */ -#define INST_APPEND_SCALAR1 82 -#define INST_APPEND_SCALAR4 83 -#define INST_APPEND_ARRAY1 84 -#define INST_APPEND_ARRAY4 85 -#define INST_APPEND_ARRAY_STK 86 -#define INST_APPEND_STK 87 +INST_APPEND_SCALAR1, +INST_APPEND_SCALAR4, +INST_APPEND_ARRAY1, +INST_APPEND_ARRAY4, +INST_APPEND_ARRAY_STK, +INST_APPEND_STK, /* Opcodes 88 to 93 */ -#define INST_LAPPEND_SCALAR1 88 -#define INST_LAPPEND_SCALAR4 89 -#define INST_LAPPEND_ARRAY1 90 -#define INST_LAPPEND_ARRAY4 91 -#define INST_LAPPEND_ARRAY_STK 92 -#define INST_LAPPEND_STK 93 +INST_LAPPEND_SCALAR1, +INST_LAPPEND_SCALAR4, +INST_LAPPEND_ARRAY1, +INST_LAPPEND_ARRAY4, +INST_LAPPEND_ARRAY_STK, +INST_LAPPEND_STK, /* TIP #22 - LINDEX operator with flat arg list */ - -#define INST_LIST_INDEX_MULTI 94 +INST_LIST_INDEX_MULTI, /* * TIP #33 - 'lset' command. Code gen also required a Forth-like * OVER operation. */ - -#define INST_OVER 95 -#define INST_LSET_LIST 96 -#define INST_LSET_FLAT 97 +INST_OVER, +INST_LSET_LIST, +INST_LSET_FLAT, /* TIP#90 - 'return' command. */ - -#define INST_RETURN_IMM 98 +INST_RETURN_IMM, /* TIP#123 - exponentiation operator. */ - -#define INST_EXPON 99 +INST_EXPON, /* TIP #157 - {*}... (word expansion) language syntax support. */ - -#define INST_EXPAND_START 100 -#define INST_EXPAND_STKTOP 101 -#define INST_INVOKE_EXPANDED 102 +INST_EXPAND_START, +INST_EXPAND_STKTOP, +INST_INVOKE_EXPANDED, /* * TIP #57 - 'lassign' command. Code generation requires immediate * LINDEX and LRANGE operators. */ - -#define INST_LIST_INDEX_IMM 103 -#define INST_LIST_RANGE_IMM 104 - -#define INST_START_CMD 105 - -#define INST_LIST_IN 106 -#define INST_LIST_NOT_IN 107 - -#define INST_PUSH_RETURN_OPTIONS 108 -#define INST_RETURN_STK 109 +INST_LIST_INDEX_IMM, +INST_LIST_RANGE_IMM, +INST_START_CMD, +INST_LIST_IN, +INST_LIST_NOT_IN, +INST_PUSH_RETURN_OPTIONS, +INST_RETURN_STK, /* * Dictionary (TIP#111) related commands. */ - -#define INST_DICT_GET 110 -#define INST_DICT_SET 111 -#define INST_DICT_UNSET 112 -#define INST_DICT_INCR_IMM 113 -#define INST_DICT_APPEND 114 -#define INST_DICT_LAPPEND 115 -#define INST_DICT_FIRST 116 -#define INST_DICT_NEXT 117 -#define INST_DICT_UPDATE_START 119 -#define INST_DICT_UPDATE_END 120 +INST_DICT_GET, +INST_DICT_SET, +INST_DICT_UNSET, +INST_DICT_INCR_IMM, +INST_DICT_APPEND, +INST_DICT_LAPPEND, +INST_DICT_FIRST, +INST_DICT_NEXT, +INST_DICT_UPDATE_START, +INST_DICT_UPDATE_END, /* * Instruction to support jumps defined by tables (instead of the classic * [switch] technique of chained comparisons). */ - -#define INST_JUMP_TABLE 121 +INST_JUMP_TABLE, /* * Instructions to support compilation of global, variable, upvar and * [namespace upvar]. */ - -#define INST_UPVAR 122 -#define INST_NSUPVAR 123 -#define INST_VARIABLE 124 +INST_UPVAR, +INST_NSUPVAR, +INST_VARIABLE, /* Instruction to support compiling syntax error to bytecode */ - -#define INST_SYNTAX 125 +INST_SYNTAX, /* Instruction to reverse N items on top of stack */ - -#define INST_REVERSE 126 +INST_REVERSE, /* regexp instruction */ - -#define INST_REGEXP 127 +INST_REGEXP, /* For [info exists] compilation */ -#define INST_EXIST_SCALAR 128 -#define INST_EXIST_ARRAY 129 -#define INST_EXIST_ARRAY_STK 130 -#define INST_EXIST_STK 131 +INST_EXIST_SCALAR, +INST_EXIST_ARRAY, +INST_EXIST_ARRAY_STK, +INST_EXIST_STK, /* For [subst] compilation */ -#define INST_NOP 132 -#define INST_RETURN_CODE_BRANCH 133 +INST_NOP, +INST_RETURN_CODE_BRANCH, /* For [unset] compilation */ -#define INST_UNSET_SCALAR 134 -#define INST_UNSET_ARRAY 135 -#define INST_UNSET_ARRAY_STK 136 -#define INST_UNSET_STK 137 +INST_UNSET_SCALAR, +INST_UNSET_ARRAY, +INST_UNSET_ARRAY_STK, +INST_UNSET_STK, /* For [dict with], [dict exists], [dict create] and [dict merge] */ -#define INST_DICT_EXPAND 138 -#define INST_DICT_RECOMBINE_STK 139 -#define INST_DICT_RECOMBINE_IMM 140 -#define INST_DICT_EXISTS 141 -#define INST_DICT_VERIFY 142 +INST_DICT_EXPAND, +INST_DICT_RECOMBINE_STK, +INST_DICT_RECOMBINE_IMM, +INST_DICT_EXISTS, +INST_DICT_VERIFY, /* For [string map] and [regsub] compilation */ -#define INST_STR_MAP 143 -#define INST_STR_FIND 144 -#define INST_STR_FIND_LAST 145 -#define INST_STR_RANGE_IMM 146 -#define INST_STR_RANGE 147 +INST_STR_MAP, +INST_STR_FIND, +INST_STR_FIND_LAST, +INST_STR_RANGE_IMM, +INST_STR_RANGE, /* For operations to do with coroutines and other NRE-manipulators */ -#define INST_YIELD 148 -#define INST_COROUTINE_NAME 149 -#define INST_TAILCALL 150 +INST_YIELD, +INST_COROUTINE_NAME, +INST_TAILCALL, /* For compilation of basic information operations */ -#define INST_NS_CURRENT 151 -#define INST_INFO_LEVEL_NUM 152 -#define INST_INFO_LEVEL_ARGS 153 -#define INST_RESOLVE_COMMAND 154 +INST_NS_CURRENT, +INST_INFO_LEVEL_NUM, +INST_INFO_LEVEL_ARGS, +INST_RESOLVE_COMMAND, /* For compilation relating to TclOO */ -#define INST_TCLOO_SELF 155 -#define INST_TCLOO_CLASS 156 -#define INST_TCLOO_NS 157 -#define INST_TCLOO_IS_OBJECT 158 +INST_TCLOO_SELF, +INST_TCLOO_CLASS, +INST_TCLOO_NS, +INST_TCLOO_IS_OBJECT, /* For compilation of [array] subcommands */ -#define INST_ARRAY_EXISTS_STK 159 -#define INST_ARRAY_EXISTS_IMM 160 -#define INST_ARRAY_MAKE_STK 161 -#define INST_ARRAY_MAKE_IMM 162 +INST_ARRAY_EXISTS_STK, +INST_ARRAY_EXISTS_IMM, +INST_ARRAY_MAKE_STK, +INST_ARRAY_MAKE_IMM, -#define INST_INVOKE_REPLACE 163 +INST_INVOKE_REPLACE, -#define INST_LIST_CONCAT 164 +INST_LIST_CONCAT, -#define INST_EXPAND_DROP 165 +INST_EXPAND_DROP, /* New foreach implementation */ -#define INST_FOREACH_START 166 -#define INST_FOREACH_STEP 167 -#define INST_FOREACH_END 168 -#define INST_LMAP_COLLECT 169 +INST_FOREACH_START, +INST_FOREACH_STEP, +INST_FOREACH_END, +INST_LMAP_COLLECT, /* For compilation of [string trim] and related */ -#define INST_STR_TRIM 170 -#define INST_STR_TRIM_LEFT 171 -#define INST_STR_TRIM_RIGHT 172 +INST_STR_TRIM, +INST_STR_TRIM_LEFT, +INST_STR_TRIM_RIGHT, -#define INST_CONCAT_STK 173 +INST_CONCAT_STK, -#define INST_STR_UPPER 174 -#define INST_STR_LOWER 175 -#define INST_STR_TITLE 176 -#define INST_STR_REPLACE 177 +INST_STR_UPPER, +INST_STR_LOWER, +INST_STR_TITLE, +INST_STR_REPLACE, -#define INST_ORIGIN_COMMAND 178 +INST_ORIGIN_COMMAND, -#define INST_TCLOO_NEXT 179 -#define INST_TCLOO_NEXT_CLASS 180 +INST_TCLOO_NEXT, +INST_TCLOO_NEXT_CLASS, -#define INST_YIELD_TO_INVOKE 181 +INST_YIELD_TO_INVOKE, -#define INST_NUM_TYPE 182 -#define INST_TRY_CVT_TO_BOOLEAN 183 -#define INST_STR_CLASS 184 +INST_NUM_TYPE, +INST_TRY_CVT_TO_BOOLEAN, +INST_STR_CLASS, -#define INST_LAPPEND_LIST 185 -#define INST_LAPPEND_LIST_ARRAY 186 -#define INST_LAPPEND_LIST_ARRAY_STK 187 -#define INST_LAPPEND_LIST_STK 188 +INST_LAPPEND_LIST, +INST_LAPPEND_LIST_ARRAY, +INST_LAPPEND_LIST_ARRAY_STK, +INST_LAPPEND_LIST_STK, -#define INST_CLOCK_READ 189 +INST_CLOCK_READ, + +/* The last opcode */ +LAST_INST_OPCODE +}; #else @@ -1117,10 +1099,10 @@ INST_TRY_CVT_TO_NUMERIC=64 #define INST_CLOCK_READ 189 -#endif - /* The last opcode */ #define LAST_INST_OPCODE 189 +#endif + /* * Table describing the Tcl bytecode instructions: their name (for displaying diff --git a/generic/tclDisassemble.c b/generic/tclDisassemble.c index 874d0d7..77b18df 100644 --- a/generic/tclDisassemble.c +++ b/generic/tclDisassemble.c @@ -820,7 +820,7 @@ UpdateStringOfInstName( size_t len, inst = (size_t)objPtr->internalRep.wideValue; char *s, buf[TCL_INTEGER_SPACE + 5]; - if (inst > LAST_INST_OPCODE) { + if (inst >= LAST_INST_OPCODE) { sprintf(buf, "inst_%" TCL_Z_MODIFIER "d", inst); s = buf; } else { diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 40ee298..56045dd 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -8824,7 +8824,7 @@ ValidatePcAndStackTop( pc); Tcl_Panic("TclNRExecuteByteCode execution failure: bad pc"); } - if ((unsigned) opCode > LAST_INST_OPCODE) { + if ((unsigned) opCode >= LAST_INST_OPCODE) { fprintf(stderr, "\nBad opcode %d at pc %u in TclNRExecuteByteCode\n", (unsigned) opCode, relativePc); Tcl_Panic("TclNRExecuteByteCode execution failure: bad opcode"); @@ -9714,7 +9714,7 @@ EvalStatsCmd( */ Tcl_AppendPrintfToObj(objPtr, "\nInstruction counts:\n"); - for (i = 0; i <= LAST_INST_OPCODE; i++) { + for (i = 0; i < LAST_INST_OPCODE; i++) { Tcl_AppendPrintfToObj(objPtr, "%20s %8ld ", tclInstructionTable[i].name, statsPtr->instructionCount[i]); if (statsPtr->instructionCount[i]) { -- cgit v0.12