tclcompile.h

来自「tcl是工具命令语言」· C头文件 代码 · 共 1,047 行 · 第 1/3 页

H
1,047
字号
				 * 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. */#ifdef TCL_COMPILE_STATS    Tcl_Time createTime;	/* Absolute time when the ByteCode was				 * created. */#endif /* TCL_COMPILE_STATS */} ByteCode;/* * Opcodes for the Tcl bytecode instructions. These must correspond to * the entries in the table of instruction descriptions, * tclInstructionTable, 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			1#define INST_PUSH4			2#define INST_POP			3#define INST_DUP			4#define INST_CONCAT1			5#define INST_INVOKE_STK1		6#define INST_INVOKE_STK4		7#define INST_EVAL_STK			8#define INST_EXPR_STK			9/* Opcodes 10 to 23 */#define INST_LOAD_SCALAR1		10#define INST_LOAD_SCALAR4		11#define INST_LOAD_SCALAR_STK		12#define INST_LOAD_ARRAY1		13#define INST_LOAD_ARRAY4		14#define INST_LOAD_ARRAY_STK		15#define INST_LOAD_STK			16#define INST_STORE_SCALAR1		17#define INST_STORE_SCALAR4		18#define INST_STORE_SCALAR_STK		19#define INST_STORE_ARRAY1		20#define INST_STORE_ARRAY4		21#define INST_STORE_ARRAY_STK		22#define INST_STORE_STK			23/* Opcodes 24 to 33 */#define INST_INCR_SCALAR1		24#define INST_INCR_SCALAR_STK		25#define INST_INCR_ARRAY1		26#define INST_INCR_ARRAY_STK		27#define INST_INCR_STK			28#define INST_INCR_SCALAR1_IMM		29#define INST_INCR_SCALAR_STK_IMM	30#define INST_INCR_ARRAY1_IMM		31#define INST_INCR_ARRAY_STK_IMM		32#define INST_INCR_STK_IMM		33/* Opcodes 34 to 39 */#define INST_JUMP1			34#define INST_JUMP4			35#define INST_JUMP_TRUE1			36#define INST_JUMP_TRUE4			37#define INST_JUMP_FALSE1		38#define INST_JUMP_FALSE4	        39/* Opcodes 40 to 64 */#define INST_LOR			40#define INST_LAND			41#define INST_BITOR			42#define INST_BITXOR			43#define INST_BITAND			44#define INST_EQ				45#define INST_NEQ			46#define INST_LT				47#define INST_GT				48#define INST_LE				49#define INST_GE				50#define INST_LSHIFT			51#define INST_RSHIFT			52#define INST_ADD			53#define INST_SUB			54#define INST_MULT			55#define INST_DIV			56#define INST_MOD			57#define INST_UPLUS			58#define INST_UMINUS			59#define INST_BITNOT			60#define INST_LNOT			61#define INST_CALL_BUILTIN_FUNC1		62#define INST_CALL_FUNC1			63#define INST_TRY_CVT_TO_NUMERIC		64/* Opcodes 65 to 66 */#define INST_BREAK			65#define INST_CONTINUE			66/* Opcodes 67 to 68 */#define INST_FOREACH_START4		67#define INST_FOREACH_STEP4		68/* 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/* 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/* 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/* 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/* TIP #22 - LINDEX operator with flat arg list */#define INST_LIST_INDEX_MULTI		94/* * 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/* The last opcode */#define LAST_INST_OPCODE        	97/* * 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 stackEffect;            /* The worst-case balance stack effect of the 				 * instruction, used for stack requirements 				 * computations. The value INT_MIN signals				 * that the instruction's worst case effect				 * is (1-opnd1).				 */    int numOperands;		/* Number of operands. */    InstOperandType opTypes[MAX_INSTRUCTION_OPERANDS];				/* The type of each operand. */} InstructionDesc;extern InstructionDesc tclInstructionTable[];/* * 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 tclBuiltinFuncTable 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 BUILTIN_FUNC_WIDE		25#define LAST_BUILTIN_FUNC        	25/* * 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 tclBuiltinFuncTable[];/* * 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 exceptIndex;		/* 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				 * size of this field will be large enough				 * to numVars indexes. THIS MUST BE THE				 * LAST FIELD IN THE STRUCTURE! */} ForeachVarList;/* * Structure used to hold information about a foreach command that is needed * during program execution. These structures are stored in CompileEnv and * ByteCode structures as auxiliary data. */typedef struct ForeachInfo {    int numLists;		/* The number of both the variable and value				 * lists of the foreach command. */    int firstValueTemp;		/* Index of the first temp var in a proc				 * frame used to point to a value list. */    int loopCtTemp;		/* Index of temp var in a proc frame

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?