📄 tclcompile.h
字号:
* code when new namespace resolution rules * are put into effect. */ int refCount; /* Reference count: set 1 when created * plus 1 for each execution of the code * currently active. This structure can be * freed when refCount becomes zero. */ unsigned int flags; /* flags describing state for the codebyte. * this variable holds ORed values from the * TCL_BYTECODE_ masks defined above */ char *source; /* The source string from which this * ByteCode was compiled. Note that this * pointer is not owned by the ByteCode and * must not be freed or modified by it. */ Proc *procPtr; /* If the ByteCode was compiled from a * procedure body, this is a pointer to its * Proc structure; otherwise NULL. This * pointer is also not owned by the ByteCode * and must not be freed by it. Used for * debugging. */ size_t totalSize; /* Total number of bytes required for this * ByteCode structure including the storage * for Tcl objects in its object array. */ int numCommands; /* Number of commands compiled. */ int numSrcChars; /* Number of source chars compiled. */ int numCodeBytes; /* Number of code bytes. */ int numObjects; /* Number of Tcl objects in object array. */ int numExcRanges; /* Number of ExceptionRange array elems. */ int numAuxDataItems; /* Number of AuxData items. */ int numCmdLocBytes; /* Number of bytes needed for encoded * command location information. */ int maxExcRangeDepth; /* Maximum nesting level of ExceptionRanges; * -1 if no ranges were compiled. */ int maxStackDepth; /* Maximum number of stack elements needed * to execute the code. */ unsigned char *codeStart; /* Points to the first byte of the code. * This is just after the final ByteCode * member cmdMapPtr. */ Tcl_Obj **objArrayPtr; /* Points to the start of the object array. * This is just after the last code byte. */ ExceptionRange *excRangeArrayPtr; /* Points to the start of the ExceptionRange * array. This is just after the last * object in the object array. */ AuxData *auxDataArrayPtr; /* Points to the start of the auxiliary data * array. This is just after the last entry * in the ExceptionRange array. */ unsigned char *codeDeltaStart; /* Points to the first of a sequence of * bytes that encode the change in the * starting offset of each command's code. * If -127<=delta<=127, it is encoded as 1 * byte, otherwise 0xFF (128) appears and * the delta is encoded by the next 4 bytes. * Code deltas are always positive. This * sequence is just after the last entry in * the AuxData array. */ unsigned char *codeLengthStart; /* Points to the first of a sequence of * bytes that encode the length of each * command's code. The encoding is the same * as for code deltas. Code lengths are * always positive. This sequence is just * after the last entry in the code delta * sequence. */ unsigned char *srcDeltaStart; /* Points to the first of a sequence of * bytes that encode the change in the * starting offset of each command's source. * The encoding is the same as for code * deltas. Source deltas can be negative. * This sequence is just after the last byte * in the code length sequence. */ unsigned char *srcLengthStart; /* Points to the first of a sequence of * bytes that encode the length of each * command's source. The encoding is the * same as for code deltas. Source lengths * are always positive. This sequence is * just after the last byte in the source * delta sequence. */} ByteCode;/* * Opcodes for the Tcl bytecode instructions. These opcodes must correspond * to the entries in the table of instruction descriptions in tclCompile.c. * Also, the order and number of the expression opcodes (e.g., INST_LOR) * must match the entries in the array operatorStrings in tclExecute.c. *//* Opcodes 0 to 9 */#define INST_DONE 0#define INST_PUSH1 (INST_DONE + 1)#define INST_PUSH4 (INST_DONE + 2)#define INST_POP (INST_DONE + 3)#define INST_DUP (INST_DONE + 4)#define INST_CONCAT1 (INST_DONE + 5)#define INST_INVOKE_STK1 (INST_DONE + 6)#define INST_INVOKE_STK4 (INST_DONE + 7)#define INST_EVAL_STK (INST_DONE + 8)#define INST_EXPR_STK (INST_DONE + 9)/* Opcodes 10 to 23 */#define INST_LOAD_SCALAR1 (INST_EXPR_STK + 1)#define INST_LOAD_SCALAR4 (INST_LOAD_SCALAR1 + 1)#define INST_LOAD_SCALAR_STK (INST_LOAD_SCALAR1 + 2)#define INST_LOAD_ARRAY1 (INST_LOAD_SCALAR1 + 3)#define INST_LOAD_ARRAY4 (INST_LOAD_SCALAR1 + 4)#define INST_LOAD_ARRAY_STK (INST_LOAD_SCALAR1 + 5)#define INST_LOAD_STK (INST_LOAD_SCALAR1 + 6)#define INST_STORE_SCALAR1 (INST_LOAD_SCALAR1 + 7)#define INST_STORE_SCALAR4 (INST_LOAD_SCALAR1 + 8)#define INST_STORE_SCALAR_STK (INST_LOAD_SCALAR1 + 9)#define INST_STORE_ARRAY1 (INST_LOAD_SCALAR1 + 10)#define INST_STORE_ARRAY4 (INST_LOAD_SCALAR1 + 11)#define INST_STORE_ARRAY_STK (INST_LOAD_SCALAR1 + 12)#define INST_STORE_STK (INST_LOAD_SCALAR1 + 13)/* Opcodes 24 to 33 */#define INST_INCR_SCALAR1 (INST_STORE_STK + 1)#define INST_INCR_SCALAR_STK (INST_INCR_SCALAR1 + 1)#define INST_INCR_ARRAY1 (INST_INCR_SCALAR1 + 2)#define INST_INCR_ARRAY_STK (INST_INCR_SCALAR1 + 3)#define INST_INCR_STK (INST_INCR_SCALAR1 + 4)#define INST_INCR_SCALAR1_IMM (INST_INCR_SCALAR1 + 5)#define INST_INCR_SCALAR_STK_IMM (INST_INCR_SCALAR1 + 6)#define INST_INCR_ARRAY1_IMM (INST_INCR_SCALAR1 + 7)#define INST_INCR_ARRAY_STK_IMM (INST_INCR_SCALAR1 + 8)#define INST_INCR_STK_IMM (INST_INCR_SCALAR1 + 9)/* Opcodes 34 to 39 */#define INST_JUMP1 (INST_INCR_STK_IMM + 1)#define INST_JUMP4 (INST_JUMP1 + 1)#define INST_JUMP_TRUE1 (INST_JUMP1 + 2)#define INST_JUMP_TRUE4 (INST_JUMP1 + 3)#define INST_JUMP_FALSE1 (INST_JUMP1 + 4)#define INST_JUMP_FALSE4 (INST_JUMP1 + 5)/* Opcodes 40 to 64 */#define INST_LOR (INST_JUMP_FALSE4 + 1)#define INST_LAND (INST_LOR + 1)#define INST_BITOR (INST_LOR + 2)#define INST_BITXOR (INST_LOR + 3)#define INST_BITAND (INST_LOR + 4)#define INST_EQ (INST_LOR + 5)#define INST_NEQ (INST_LOR + 6)#define INST_LT (INST_LOR + 7)#define INST_GT (INST_LOR + 8)#define INST_LE (INST_LOR + 9)#define INST_GE (INST_LOR + 10)#define INST_LSHIFT (INST_LOR + 11)#define INST_RSHIFT (INST_LOR + 12)#define INST_ADD (INST_LOR + 13)#define INST_SUB (INST_LOR + 14)#define INST_MULT (INST_LOR + 15)#define INST_DIV (INST_LOR + 16)#define INST_MOD (INST_LOR + 17)#define INST_UPLUS (INST_LOR + 18)#define INST_UMINUS (INST_LOR + 19)#define INST_BITNOT (INST_LOR + 20)#define INST_LNOT (INST_LOR + 21)#define INST_CALL_BUILTIN_FUNC1 (INST_LOR + 22)#define INST_CALL_FUNC1 (INST_LOR + 23)#define INST_TRY_CVT_TO_NUMERIC (INST_LOR + 24)/* Opcodes 65 to 66 */#define INST_BREAK (INST_TRY_CVT_TO_NUMERIC + 1)#define INST_CONTINUE (INST_BREAK + 1)/* Opcodes 67 to 68 */#define INST_FOREACH_START4 (INST_CONTINUE + 1)#define INST_FOREACH_STEP4 (INST_FOREACH_START4 + 1)/* Opcodes 69 to 72 */#define INST_BEGIN_CATCH4 (INST_FOREACH_STEP4 + 1)#define INST_END_CATCH (INST_BEGIN_CATCH4 + 1)#define INST_PUSH_RESULT (INST_BEGIN_CATCH4 + 2)#define INST_PUSH_RETURN_CODE (INST_BEGIN_CATCH4 + 3)/* The last opcode */#define LAST_INST_OPCODE INST_PUSH_RETURN_CODE/* * Table describing the Tcl bytecode instructions: their name (for * displaying code), total number of code bytes required (including * operand bytes), and a description of the type of each operand. * These operand types include signed and unsigned integers of length * one and four bytes. The unsigned integers are used for indexes or * for, e.g., the count of objects to push in a "push" instruction. */#define MAX_INSTRUCTION_OPERANDS 2typedef enum InstOperandType { OPERAND_NONE, OPERAND_INT1, /* One byte signed integer. */ OPERAND_INT4, /* Four byte signed integer. */ OPERAND_UINT1, /* One byte unsigned integer. */ OPERAND_UINT4 /* Four byte unsigned integer. */} InstOperandType;typedef struct InstructionDesc { char *name; /* Name of instruction. */ int numBytes; /* Total number of bytes for instruction. */ int numOperands; /* Number of operands. */ InstOperandType opTypes[MAX_INSTRUCTION_OPERANDS]; /* The type of each operand. */} InstructionDesc;extern InstructionDesc instructionTable[];/* * Definitions of the values of the INST_CALL_BUILTIN_FUNC instruction's * operand byte. Each value denotes a builtin Tcl math function. These * values must correspond to the entries in the builtinFuncTable array * below and to the values stored in the tclInt.h MathFunc structure's * builtinFuncIndex field. */#define BUILTIN_FUNC_ACOS 0#define BUILTIN_FUNC_ASIN 1#define BUILTIN_FUNC_ATAN 2#define BUILTIN_FUNC_ATAN2 3#define BUILTIN_FUNC_CEIL 4#define BUILTIN_FUNC_COS 5#define BUILTIN_FUNC_COSH 6#define BUILTIN_FUNC_EXP 7#define BUILTIN_FUNC_FLOOR 8#define BUILTIN_FUNC_FMOD 9#define BUILTIN_FUNC_HYPOT 10#define BUILTIN_FUNC_LOG 11#define BUILTIN_FUNC_LOG10 12#define BUILTIN_FUNC_POW 13#define BUILTIN_FUNC_SIN 14#define BUILTIN_FUNC_SINH 15#define BUILTIN_FUNC_SQRT 16#define BUILTIN_FUNC_TAN 17#define BUILTIN_FUNC_TANH 18#define BUILTIN_FUNC_ABS 19#define BUILTIN_FUNC_DOUBLE 20#define BUILTIN_FUNC_INT 21#define BUILTIN_FUNC_RAND 22#define BUILTIN_FUNC_ROUND 23#define BUILTIN_FUNC_SRAND 24#define LAST_BUILTIN_FUNC BUILTIN_FUNC_SRAND/* * Table describing the built-in math functions. Entries in this table are * indexed by the values of the INST_CALL_BUILTIN_FUNC instruction's * operand byte. */typedef int (CallBuiltinFuncProc) _ANSI_ARGS_((Tcl_Interp *interp, ExecEnv *eePtr, ClientData clientData));typedef struct { char *name; /* Name of function. */ int numArgs; /* Number of arguments for function. */ Tcl_ValueType argTypes[MAX_MATH_ARGS]; /* Acceptable types for each argument. */ CallBuiltinFuncProc *proc; /* Procedure implementing this function. */ ClientData clientData; /* Additional argument to pass to the * function when invoking it. */} BuiltinFunc;extern BuiltinFunc builtinFuncTable[];/* * The structure used to hold information about the start and end of each * argument word in a command. */#define ARGINFO_INIT_ENTRIES 5typedef struct ArgInfo { int numArgs; /* Number of argument words in command. */ char **startArray; /* Array of pointers to the first character * of each argument word. */ char **endArray; /* Array of pointers to the last character * of each argument word. */ int allocArgs; /* Number of array entries currently * allocated. */ int mallocedArrays; /* 1 if the arrays were expanded and * wordStartArray/wordEndArray point into * the heap, else 0. */ char *staticStartSpace[ARGINFO_INIT_ENTRIES]; /* Initial storage for word start array. */ char *staticEndSpace[ARGINFO_INIT_ENTRIES]; /* Initial storage for word end array. */} ArgInfo;/* * Compilation of some Tcl constructs such as if commands and the logical or * (||) and logical and (&&) operators in expressions requires the * generation of forward jumps. Since the PC target of these jumps isn't * known when the jumps are emitted, we record the offset of each jump in an * array of JumpFixup structures. There is one array for each sequence of * jumps to one target PC. When we learn the target PC, we update the jumps * with the correct distance. Also, if the distance is too great (> 127 * bytes), we replace the single-byte jump with a four byte jump * instruction, move the instructions after the jump down, and update the * code offsets for any commands between the jump and the target. */typedef enum { TCL_UNCONDITIONAL_JUMP, TCL_TRUE_JUMP, TCL_FALSE_JUMP} TclJumpType;typedef struct JumpFixup { TclJumpType jumpType; /* Indicates the kind of jump. */ int codeOffset; /* Offset of the first byte of the one-byte * forward jump's code. */ int cmdIndex; /* Index of the first command after the one * for which the jump was emitted. Used to * update the code offsets for subsequent * commands if the two-byte jump at jumpPc * must be replaced with a five-byte one. */ int excRangeIndex; /* Index of the first range entry in the * ExceptionRange array after the current * one. This field is used to adjust the * code offsets in subsequent ExceptionRange * records when a jump is grown from 2 bytes * to 5 bytes. */} JumpFixup;#define JUMPFIXUP_INIT_ENTRIES 10typedef struct JumpFixupArray { JumpFixup *fixup; /* Points to start of jump fixup array. */ int next; /* Index of next free array entry. */ int end; /* Index of last usable entry in array. */ int mallocedArray; /* 1 if array was expanded and fixups points * into the heap, else 0. */ JumpFixup staticFixupSpace[JUMPFIXUP_INIT_ENTRIES]; /* Initial storage for jump fixup array. */} JumpFixupArray;/* * The structure describing one variable list of a foreach command. Note * that only foreach commands inside procedure bodies are compiled inline so * a ForeachVarList structure always describes local variables. Furthermore, * only scalar variables are supported for inline-compiled foreach loops. */typedef struct ForeachVarList { int numVars; /* The number of variables in the list. */ int varIndexes[1]; /* An array of the indexes ("slot numbers") * for each variable in the procedure's * array of local variables. Only scalar * variables are supported. The actual
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -