📄 tclcompile.h
字号:
* 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 firstListTmp; /* The slot number of the first temporary * variable holding the lists themselves. */ int loopIterNumTmp; /* The slot number of the temp var holding * the count of times the loop body has been * executed. This is used to determine which * list element to assign each loop var. */ ForeachVarList *varLists[1];/* An array of pointers to ForeachVarList * structures describing each var list. The * actual size of this field will be large * enough to numVars indexes. THIS MUST BE * THE LAST FIELD IN THE STRUCTURE! */} ForeachInfo;/* * Structure containing a cached pointer to a command that is the result * of resolving the command's name in some namespace. It is the internal * representation for a cmdName object. It contains the pointer along * with some information that is used to check the pointer's validity. */typedef struct ResolvedCmdName { Command *cmdPtr; /* A cached Command pointer. */ Namespace *refNsPtr; /* Points to the namespace containing the * reference (not the namespace that * contains the referenced command). */ long refNsId; /* refNsPtr's unique namespace id. Used to * verify that refNsPtr is still valid * (e.g., it's possible that the cmd's * containing namespace was deleted and a * new one created at the same address). */ int refNsCmdEpoch; /* Value of the referencing namespace's * cmdRefEpoch when the pointer was cached. * Before using the cached pointer, we check * if the namespace's epoch was incremented; * if so, this cached pointer is invalid. */ int cmdEpoch; /* Value of the command's cmdEpoch when this * pointer was cached. Before using the * cached pointer, we check if the cmd's * epoch was incremented; if so, the cmd was * renamed, deleted, hidden, or exposed, and * so the pointer is invalid. */ int refCount; /* Reference count: 1 for each cmdName * object that has a pointer to this * ResolvedCmdName structure as its internal * rep. This structure can be freed when * refCount becomes zero. */} ResolvedCmdName;/* *---------------------------------------------------------------- * Procedures shared among Tcl bytecode compilation and execution * modules but not used outside: *---------------------------------------------------------------- */EXTERN void TclCleanupByteCode _ANSI_ARGS_((ByteCode *codePtr));EXTERN int TclCompileExpr _ANSI_ARGS_((Tcl_Interp *interp, char *string, char *lastChar, int flags, CompileEnv *envPtr));EXTERN int TclCompileQuotes _ANSI_ARGS_((Tcl_Interp *interp, char *string, char *lastChar, int termChar, int flags, CompileEnv *envPtr));EXTERN int TclCompileString _ANSI_ARGS_((Tcl_Interp *interp, char *string, char *lastChar, int flags, CompileEnv *envPtr));EXTERN int TclCompileDollarVar _ANSI_ARGS_((Tcl_Interp *interp, char *string, char *lastChar, int flags, CompileEnv *envPtr));EXTERN int TclCreateAuxData _ANSI_ARGS_((ClientData clientData, AuxDataType *typePtr, CompileEnv *envPtr));EXTERN ExecEnv * TclCreateExecEnv _ANSI_ARGS_((Tcl_Interp *interp));EXTERN void TclDeleteExecEnv _ANSI_ARGS_((ExecEnv *eePtr));EXTERN void TclEmitForwardJump _ANSI_ARGS_((CompileEnv *envPtr, TclJumpType jumpType, JumpFixup *jumpFixupPtr));EXTERN AuxDataType *TclGetAuxDataType _ANSI_ARGS_((char *typeName));EXTERN ExceptionRange * TclGetExceptionRangeForPc _ANSI_ARGS_(( unsigned char *pc, int catchOnly, ByteCode* codePtr));EXTERN InstructionDesc * TclGetInstructionTable _ANSI_ARGS_(());EXTERN int TclExecuteByteCode _ANSI_ARGS_((Tcl_Interp *interp, ByteCode *codePtr));EXTERN void TclExpandCodeArray _ANSI_ARGS_(( CompileEnv *envPtr));EXTERN void TclExpandJumpFixupArray _ANSI_ARGS_(( JumpFixupArray *fixupArrayPtr));EXTERN void TclFinalizeAuxDataTypeTable _ANSI_ARGS_((void));EXTERN int TclFixupForwardJump _ANSI_ARGS_(( CompileEnv *envPtr, JumpFixup *jumpFixupPtr, int jumpDist, int distThreshold));EXTERN void TclFreeCompileEnv _ANSI_ARGS_((CompileEnv *envPtr));EXTERN void TclFreeJumpFixupArray _ANSI_ARGS_(( JumpFixupArray *fixupArrayPtr));EXTERN void TclInitAuxDataTypeTable _ANSI_ARGS_((void));EXTERN void TclInitByteCodeObj _ANSI_ARGS_((Tcl_Obj *objPtr, CompileEnv *envPtr));EXTERN void TclInitCompileEnv _ANSI_ARGS_((Tcl_Interp *interp, CompileEnv *envPtr, char *string));EXTERN void TclInitJumpFixupArray _ANSI_ARGS_(( JumpFixupArray *fixupArrayPtr));#ifdef TCL_COMPILE_STATSEXTERN int TclLog2 _ANSI_ARGS_((int value));#endif /*TCL_COMPILE_STATS*/EXTERN int TclObjIndexForString _ANSI_ARGS_((char *start, int length, int allocStrRep, int inHeap, CompileEnv *envPtr));EXTERN int TclPrintInstruction _ANSI_ARGS_((ByteCode* codePtr, unsigned char *pc));EXTERN void TclPrintSource _ANSI_ARGS_((FILE *outFile, char *string, int maxChars));EXTERN void TclRegisterAuxDataType _ANSI_ARGS_((AuxDataType *typePtr));/* *---------------------------------------------------------------- * Macros used by Tcl bytecode compilation and execution modules * inside the Tcl core but not used outside. *---------------------------------------------------------------- *//* * Macros to ensure there is enough room in a CompileEnv's code array. * The ANSI C "prototypes" for these macros are: * * EXTERN void TclEnsureCodeSpace1 _ANSI_ARGS_((CompileEnv *envPtr)); * EXTERN void TclEnsureCodeSpace _ANSI_ARGS_((int nBytes, * CompileEnv *envPtr)); */#define TclEnsureCodeSpace1(envPtr) \ if ((envPtr)->codeNext == (envPtr)->codeEnd) \ TclExpandCodeArray(envPtr)#define TclEnsureCodeSpace(nBytes, envPtr) \ if (((envPtr)->codeNext + nBytes) > (envPtr)->codeEnd) \ TclExpandCodeArray(envPtr)/* * Macro to emit an opcode byte into a CompileEnv's code array. * The ANSI C "prototype" for this macro is: * * EXTERN void TclEmitOpcode _ANSI_ARGS_((unsigned char op, * CompileEnv *envPtr)); */#define TclEmitOpcode(op, envPtr) \ TclEnsureCodeSpace1(envPtr); \ *(envPtr)->codeNext++ = (unsigned char) (op)/* * Macros to emit a (signed or unsigned) int operand. The two variants * depend on the number of bytes needed for the int. Four byte integers * are stored in "big-endian" order with the high order byte stored at * the lowest address. The ANSI C "prototypes" for these macros are: * * EXTERN void TclEmitInt1 _ANSI_ARGS_((int i, CompileEnv *envPtr)); * EXTERN void TclEmitInt4 _ANSI_ARGS_((int i, CompileEnv *envPtr)); */#define TclEmitInt1(i, envPtr) \ TclEnsureCodeSpace(1, (envPtr)); \ *(envPtr)->codeNext++ = (unsigned char) ((unsigned int) (i))#define TclEmitInt4(i, envPtr) \ TclEnsureCodeSpace(4, (envPtr)); \ *(envPtr)->codeNext++ = \ (unsigned char) ((unsigned int) (i) >> 24); \ *(envPtr)->codeNext++ = \ (unsigned char) ((unsigned int) (i) >> 16); \ *(envPtr)->codeNext++ = \ (unsigned char) ((unsigned int) (i) >> 8); \ *(envPtr)->codeNext++ = \ (unsigned char) ((unsigned int) (i) )/* * Macros to emit an instruction with signed or unsigned int operands. * The ANSI C "prototypes" for these macros are: * * EXTERN void TclEmitInstInt1 _ANSI_ARGS_((unsigned char op, int i, * CompileEnv *envPtr)); * EXTERN void TclEmitInstInt4 _ANSI_ARGS_((unsigned char op, int i, * CompileEnv *envPtr)); * EXTERN void TclEmitInstUInt1 _ANSI_ARGS_((unsigned char op, * unsigned int i, CompileEnv *envPtr)); * EXTERN void TclEmitInstUInt4 _ANSI_ARGS_((unsigned char op, * unsigned int i, CompileEnv *envPtr)); */#define TclEmitInstInt1(op, i, envPtr) \ TclEnsureCodeSpace(2, (envPtr)); \ *(envPtr)->codeNext++ = (unsigned char) (op); \ *(envPtr)->codeNext++ = (unsigned char) ((unsigned int) (i))#define TclEmitInstInt4(op, i, envPtr) \ TclEnsureCodeSpace(5, (envPtr)); \ *(envPtr)->codeNext++ = (unsigned char) (op); \ *(envPtr)->codeNext++ = \ (unsigned char) ((unsigned int) (i) >> 24); \ *(envPtr)->codeNext++ = \ (unsigned char) ((unsigned int) (i) >> 16); \ *(envPtr)->codeNext++ = \ (unsigned char) ((unsigned int) (i) >> 8); \ *(envPtr)->codeNext++ = \ (unsigned char) ((unsigned int) (i) ) #define TclEmitInstUInt1(op, i, envPtr) \ TclEmitInstInt1((op), (i), (envPtr))#define TclEmitInstUInt4(op, i, envPtr) \ TclEmitInstInt4((op), (i), (envPtr)) /* * Macro to push a Tcl object onto the Tcl evaluation stack. It emits the * object's one or four byte array index into the CompileEnv's code * array. These support, respectively, a maximum of 256 (2**8) and 2**32 * objects in a CompileEnv. The ANSI C "prototype" for this macro is: * * EXTERN void TclEmitPush _ANSI_ARGS_((int objIndex, CompileEnv *envPtr)); */#define TclEmitPush(objIndex, envPtr) \ if ((objIndex) <= 255) { \ TclEmitInstUInt1(INST_PUSH1, (objIndex), (envPtr)); \ } else { \ TclEmitInstUInt4(INST_PUSH4, (objIndex), (envPtr)); \ }/* * Macros to update a (signed or unsigned) integer starting at a pointer. * The two variants depend on the number of bytes. The ANSI C "prototypes" * for these macros are: * * EXTERN void TclStoreInt1AtPtr _ANSI_ARGS_((int i, unsigned char *p)); * EXTERN void TclStoreInt4AtPtr _ANSI_ARGS_((int i, unsigned char *p)); */ #define TclStoreInt1AtPtr(i, p) \ *(p) = (unsigned char) ((unsigned int) (i)) #define TclStoreInt4AtPtr(i, p) \ *(p) = (unsigned char) ((unsigned int) (i) >> 24); \ *(p+1) = (unsigned char) ((unsigned int) (i) >> 16); \ *(p+2) = (unsigned char) ((unsigned int) (i) >> 8); \ *(p+3) = (unsigned char) ((unsigned int) (i) )/* * Macros to update instructions at a particular pc with a new op code * and a (signed or unsigned) int operand. The ANSI C "prototypes" for * these macros are: * * EXTERN void TclUpdateInstInt1AtPc _ANSI_ARGS_((unsigned char op, int i, * unsigned char *pc)); * EXTERN void TclUpdateInstInt4AtPc _ANSI_ARGS_((unsigned char op, int i, * unsigned char *pc)); */#define TclUpdateInstInt1AtPc(op, i, pc) \ *(pc) = (unsigned char) (op); \ TclStoreInt1AtPtr((i), ((pc)+1))#define TclUpdateInstInt4AtPc(op, i, pc) \ *(pc) = (unsigned char) (op); \ TclStoreInt4AtPtr((i), ((pc)+1)) /* * Macros to get a signed integer (GET_INT{1,2}) or an unsigned int * (GET_UINT{1,2}) from a pointer. There are two variants for each * return type that depend on the number of bytes fetched. * The ANSI C "prototypes" for these macros are: * * EXTERN int TclGetInt1AtPtr _ANSI_ARGS_((unsigned char *p)); * EXTERN int TclGetInt4AtPtr _ANSI_ARGS_((unsigned char *p)); * EXTERN unsigned int TclGetUInt1AtPtr _ANSI_ARGS_((unsigned char *p)); * EXTERN unsigned int TclGetUInt4AtPtr _ANSI_ARGS_((unsigned char *p)); *//* * The TclGetInt1AtPtr macro is tricky because we want to do sign * extension on the 1-byte value. Unfortunately the "char" type isn't * signed on all platforms so sign-extension doesn't always happen * automatically. Sometimes we can explicitly declare the pointer to be * signed, but other times we have to explicitly sign-extend the value * in software. */#ifndef __CHAR_UNSIGNED__# define TclGetInt1AtPtr(p) ((int) *((char *) p))#else# ifdef HAVE_SIGNED_CHAR# define TclGetInt1AtPtr(p) ((int) *((signed char *) p))# else# define TclGetInt1AtPtr(p) (((int) *((char *) p)) \ | ((*(p) & 0200) ? (-256) : 0))# endif#endif#define TclGetInt4AtPtr(p) (((int) TclGetInt1AtPtr(p) << 24) | \ (*((p)+1) << 16) | \ (*((p)+2) << 8) | \ (*((p)+3)))#define TclGetUInt1AtPtr(p) ((unsigned int) *(p))#define TclGetUInt4AtPtr(p) ((unsigned int) (*(p) << 24) | \ (*((p)+1) << 16) | \ (*((p)+2) << 8) | \ (*((p)+3)))/* * Macros used to compute the minimum and maximum of two integers. * The ANSI C "prototypes" for these macros are: * * EXTERN int TclMin _ANSI_ARGS_((int i, int j)); * EXTERN int TclMax _ANSI_ARGS_((int i, int j)); */#define TclMin(i, j) ((((int) i) < ((int) j))? (i) : (j))#define TclMax(i, j) ((((int) i) > ((int) j))? (i) : (j))/* * Macro used to compute the offset of the current instruction in the * bytecode instruction stream. The ANSI C "prototypes" for this macro is: * * EXTERN int TclCurrCodeOffset _ANSI_ARGS_((void)); */#define TclCurrCodeOffset() ((envPtr)->codeNext - (envPtr)->codeStart)/* * Upper bound for legal jump distances. Checked during compilation if * debugging. */#define MAX_JUMP_DIST 5000# undef TCL_STORAGE_CLASS# define TCL_STORAGE_CLASS DLLIMPORT#endif /* _TCLCOMPILATION */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -