sl@0: /* sl@0: * tclCompile.h -- sl@0: * sl@0: * Copyright (c) 1996-1998 Sun Microsystems, Inc. sl@0: * Copyright (c) 1998-2000 by Scriptics Corporation. sl@0: * Copyright (c) 2001 by Kevin B. Kenny. All rights reserved. sl@0: * sl@0: * See the file "license.terms" for information on usage and redistribution sl@0: * of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: * sl@0: * RCS: @(#) $Id: tclCompile.h,v 1.33.2.1 2006/11/28 22:20:00 andreas_kupries Exp $ sl@0: */ sl@0: sl@0: #ifndef _TCLCOMPILATION sl@0: #define _TCLCOMPILATION 1 sl@0: sl@0: #ifndef _TCLINT sl@0: #include "tclInt.h" sl@0: #endif /* _TCLINT */ sl@0: sl@0: #ifdef BUILD_tcl sl@0: # undef TCL_STORAGE_CLASS sl@0: # define TCL_STORAGE_CLASS DLLEXPORT sl@0: #endif sl@0: sl@0: /* sl@0: *------------------------------------------------------------------------ sl@0: * Variables related to compilation. These are used in tclCompile.c, sl@0: * tclExecute.c, tclBasic.c, and their clients. sl@0: *------------------------------------------------------------------------ sl@0: */ sl@0: sl@0: #ifdef TCL_COMPILE_DEBUG sl@0: /* sl@0: * Variable that controls whether compilation tracing is enabled and, if so, sl@0: * what level of tracing is desired: sl@0: * 0: no compilation tracing sl@0: * 1: summarize compilation of top level cmds and proc bodies sl@0: * 2: display all instructions of each ByteCode compiled sl@0: * This variable is linked to the Tcl variable "tcl_traceCompile". sl@0: */ sl@0: sl@0: extern int tclTraceCompile; sl@0: #endif sl@0: sl@0: #ifdef TCL_COMPILE_DEBUG sl@0: /* sl@0: * Variable that controls whether execution tracing is enabled and, if so, sl@0: * what level of tracing is desired: sl@0: * 0: no execution tracing sl@0: * 1: trace invocations of Tcl procs only sl@0: * 2: trace invocations of all (not compiled away) commands sl@0: * 3: display each instruction executed sl@0: * This variable is linked to the Tcl variable "tcl_traceExec". sl@0: */ sl@0: sl@0: extern int tclTraceExec; sl@0: #endif sl@0: sl@0: /* sl@0: *------------------------------------------------------------------------ sl@0: * Data structures related to compilation. sl@0: *------------------------------------------------------------------------ sl@0: */ sl@0: sl@0: /* sl@0: * The structure used to implement Tcl "exceptions" (exceptional returns): sl@0: * for example, those generated in loops by the break and continue commands, sl@0: * and those generated by scripts and caught by the catch command. This sl@0: * ExceptionRange structure describes a range of code (e.g., a loop body), sl@0: * the kind of exceptions (e.g., a break or continue) that might occur, and sl@0: * the PC offsets to jump to if a matching exception does occur. Exception sl@0: * ranges can nest so this structure includes a nesting level that is used sl@0: * at runtime to find the closest exception range surrounding a PC. For sl@0: * example, when a break command is executed, the ExceptionRange structure sl@0: * for the most deeply nested loop, if any, is found and used. These sl@0: * structures are also generated for the "next" subcommands of for loops sl@0: * since a break there terminates the for command. This means a for command sl@0: * actually generates two LoopInfo structures. sl@0: */ sl@0: sl@0: typedef enum { sl@0: LOOP_EXCEPTION_RANGE, /* Exception's range is part of a loop. sl@0: * Break and continue "exceptions" cause sl@0: * jumps to appropriate PC offsets. */ sl@0: CATCH_EXCEPTION_RANGE /* Exception's range is controlled by a sl@0: * catch command. Errors in the range cause sl@0: * a jump to a catch PC offset. */ sl@0: } ExceptionRangeType; sl@0: sl@0: typedef struct ExceptionRange { sl@0: ExceptionRangeType type; /* The kind of ExceptionRange. */ sl@0: int nestingLevel; /* Static depth of the exception range. sl@0: * Used to find the most deeply-nested sl@0: * range surrounding a PC at runtime. */ sl@0: int codeOffset; /* Offset of the first instruction byte of sl@0: * the code range. */ sl@0: int numCodeBytes; /* Number of bytes in the code range. */ sl@0: int breakOffset; /* If LOOP_EXCEPTION_RANGE, the target PC sl@0: * offset for a break command in the range. */ sl@0: int continueOffset; /* If LOOP_EXCEPTION_RANGE and not -1, the sl@0: * target PC offset for a continue command in sl@0: * the code range. Otherwise, ignore this range sl@0: * when processing a continue command. */ sl@0: int catchOffset; /* If a CATCH_EXCEPTION_RANGE, the target PC sl@0: * offset for any "exception" in range. */ sl@0: } ExceptionRange; sl@0: sl@0: /* sl@0: * Structure used to map between instruction pc and source locations. It sl@0: * defines for each compiled Tcl command its code's starting offset and sl@0: * its source's starting offset and length. Note that the code offset sl@0: * increases monotonically: that is, the table is sorted in code offset sl@0: * order. The source offset is not monotonic. sl@0: */ sl@0: sl@0: typedef struct CmdLocation { sl@0: int codeOffset; /* Offset of first byte of command code. */ sl@0: int numCodeBytes; /* Number of bytes for command's code. */ sl@0: int srcOffset; /* Offset of first char of the command. */ sl@0: int numSrcBytes; /* Number of command source chars. */ sl@0: } CmdLocation; sl@0: sl@0: #ifdef TCL_TIP280 sl@0: /* sl@0: * TIP #280 sl@0: * Structure to record additional location information for byte code. sl@0: * This information is internal and not saved. I.e. tbcload'ed code sl@0: * will not have this information. It records the lines for all words sl@0: * of all commands found in the byte code. The association with a sl@0: * ByteCode structure BC is done through the 'lineBCPtr' HashTable in sl@0: * Interp, keyed by the address of BC. Also recorded is information sl@0: * coming from the context, i.e. type of the frame and associated sl@0: * information, like the path of a sourced file. sl@0: */ sl@0: sl@0: typedef struct ECL { sl@0: int srcOffset; /* cmd location to find the entry */ sl@0: int nline; sl@0: int* line; /* line information for all words in the command */ sl@0: } ECL; sl@0: typedef struct ExtCmdLoc { sl@0: int type; /* Context type */ sl@0: Tcl_Obj* path; /* Path of the sourced file the command is in */ sl@0: ECL* loc; /* Command word locations (lines) */ sl@0: int nloc; /* Number of allocated entries in 'loc' */ sl@0: int nuloc; /* Number of used entries in 'loc' */ sl@0: } ExtCmdLoc; sl@0: #endif sl@0: sl@0: /* sl@0: * CompileProcs need the ability to record information during compilation sl@0: * that can be used by bytecode instructions during execution. The AuxData sl@0: * structure provides this "auxiliary data" mechanism. An arbitrary number sl@0: * of these structures can be stored in the ByteCode record (during sl@0: * compilation they are stored in a CompileEnv structure). Each AuxData sl@0: * record holds one word of client-specified data (often a pointer) and is sl@0: * given an index that instructions can later use to look up the structure sl@0: * and its data. sl@0: * sl@0: * The following definitions declare the types of procedures that are called sl@0: * to duplicate or free this auxiliary data when the containing ByteCode sl@0: * objects are duplicated and freed. Pointers to these procedures are kept sl@0: * in the AuxData structure. sl@0: */ sl@0: sl@0: typedef ClientData (AuxDataDupProc) _ANSI_ARGS_((ClientData clientData)); sl@0: typedef void (AuxDataFreeProc) _ANSI_ARGS_((ClientData clientData)); sl@0: sl@0: /* sl@0: * We define a separate AuxDataType struct to hold type-related information sl@0: * for the AuxData structure. This separation makes it possible for clients sl@0: * outside of the TCL core to manipulate (in a limited fashion!) AuxData; sl@0: * for example, it makes it possible to pickle and unpickle AuxData structs. sl@0: */ sl@0: sl@0: typedef struct AuxDataType { sl@0: char *name; /* the name of the type. Types can be sl@0: * registered and found by name */ sl@0: AuxDataDupProc *dupProc; /* Callback procedure to invoke when the sl@0: * aux data is duplicated (e.g., when the sl@0: * ByteCode structure containing the aux sl@0: * data is duplicated). NULL means just sl@0: * copy the source clientData bits; no sl@0: * proc need be called. */ sl@0: AuxDataFreeProc *freeProc; /* Callback procedure to invoke when the sl@0: * aux data is freed. NULL means no sl@0: * proc need be called. */ sl@0: } AuxDataType; sl@0: sl@0: /* sl@0: * The definition of the AuxData structure that holds information created sl@0: * during compilation by CompileProcs and used by instructions during sl@0: * execution. sl@0: */ sl@0: sl@0: typedef struct AuxData { sl@0: AuxDataType *type; /* pointer to the AuxData type associated with sl@0: * this ClientData. */ sl@0: ClientData clientData; /* The compilation data itself. */ sl@0: } AuxData; sl@0: sl@0: /* sl@0: * Structure defining the compilation environment. After compilation, fields sl@0: * describing bytecode instructions are copied out into the more compact sl@0: * ByteCode structure defined below. sl@0: */ sl@0: sl@0: #define COMPILEENV_INIT_CODE_BYTES 250 sl@0: #define COMPILEENV_INIT_NUM_OBJECTS 60 sl@0: #define COMPILEENV_INIT_EXCEPT_RANGES 5 sl@0: #define COMPILEENV_INIT_CMD_MAP_SIZE 40 sl@0: #define COMPILEENV_INIT_AUX_DATA_SIZE 5 sl@0: sl@0: typedef struct CompileEnv { sl@0: Interp *iPtr; /* Interpreter containing the code being sl@0: * compiled. Commands and their compile sl@0: * procs are specific to an interpreter so sl@0: * the code emitted will depend on the sl@0: * interpreter. */ sl@0: char *source; /* The source string being compiled by sl@0: * SetByteCodeFromAny. This pointer is not sl@0: * owned by the CompileEnv and must not be sl@0: * freed or changed by it. */ sl@0: int numSrcBytes; /* Number of bytes in source. */ sl@0: Proc *procPtr; /* If a procedure is being compiled, a sl@0: * pointer to its Proc structure; otherwise sl@0: * NULL. Used to compile local variables. sl@0: * Set from information provided by sl@0: * ObjInterpProc in tclProc.c. */ sl@0: int numCommands; /* Number of commands compiled. */ sl@0: int exceptDepth; /* Current exception range nesting level; sl@0: * -1 if not in any range currently. */ sl@0: int maxExceptDepth; /* Max nesting level of exception ranges; sl@0: * -1 if no ranges have been compiled. */ sl@0: int maxStackDepth; /* Maximum number of stack elements needed sl@0: * to execute the code. Set by compilation sl@0: * procedures before returning. */ sl@0: int currStackDepth; /* Current stack depth. */ sl@0: LiteralTable localLitTable; /* Contains LiteralEntry's describing sl@0: * all Tcl objects referenced by this sl@0: * compiled code. Indexed by the string sl@0: * representations of the literals. Used to sl@0: * avoid creating duplicate objects. */ sl@0: unsigned char *codeStart; /* Points to the first byte of the code. */ sl@0: unsigned char *codeNext; /* Points to next code array byte to use. */ sl@0: unsigned char *codeEnd; /* Points just after the last allocated sl@0: * code array byte. */ sl@0: int mallocedCodeArray; /* Set 1 if code array was expanded sl@0: * and codeStart points into the heap.*/ sl@0: LiteralEntry *literalArrayPtr; sl@0: /* Points to start of LiteralEntry array. */ sl@0: int literalArrayNext; /* Index of next free object array entry. */ sl@0: int literalArrayEnd; /* Index just after last obj array entry. */ sl@0: int mallocedLiteralArray; /* 1 if object array was expanded and sl@0: * objArray points into the heap, else 0. */ sl@0: ExceptionRange *exceptArrayPtr; sl@0: /* Points to start of the ExceptionRange sl@0: * array. */ sl@0: int exceptArrayNext; /* Next free ExceptionRange array index. sl@0: * exceptArrayNext is the number of ranges sl@0: * and (exceptArrayNext-1) is the index of sl@0: * the current range's array entry. */ sl@0: int exceptArrayEnd; /* Index after the last ExceptionRange sl@0: * array entry. */ sl@0: int mallocedExceptArray; /* 1 if ExceptionRange array was expanded sl@0: * and exceptArrayPtr points in heap, sl@0: * else 0. */ sl@0: CmdLocation *cmdMapPtr; /* Points to start of CmdLocation array. sl@0: * numCommands is the index of the next sl@0: * entry to use; (numCommands-1) is the sl@0: * entry index for the last command. */ sl@0: int cmdMapEnd; /* Index after last CmdLocation entry. */ sl@0: int mallocedCmdMap; /* 1 if command map array was expanded and sl@0: * cmdMapPtr points in the heap, else 0. */ sl@0: AuxData *auxDataArrayPtr; /* Points to auxiliary data array start. */ sl@0: int auxDataArrayNext; /* Next free compile aux data array index. sl@0: * auxDataArrayNext is the number of aux sl@0: * data items and (auxDataArrayNext-1) is sl@0: * index of current aux data array entry. */ sl@0: int auxDataArrayEnd; /* Index after last aux data array entry. */ sl@0: int mallocedAuxDataArray; /* 1 if aux data array was expanded and sl@0: * auxDataArrayPtr points in heap else 0. */ sl@0: unsigned char staticCodeSpace[COMPILEENV_INIT_CODE_BYTES]; sl@0: /* Initial storage for code. */ sl@0: LiteralEntry staticLiteralSpace[COMPILEENV_INIT_NUM_OBJECTS]; sl@0: /* Initial storage of LiteralEntry array. */ sl@0: ExceptionRange staticExceptArraySpace[COMPILEENV_INIT_EXCEPT_RANGES]; sl@0: /* Initial ExceptionRange array storage. */ sl@0: CmdLocation staticCmdMapSpace[COMPILEENV_INIT_CMD_MAP_SIZE]; sl@0: /* Initial storage for cmd location map. */ sl@0: AuxData staticAuxDataArraySpace[COMPILEENV_INIT_AUX_DATA_SIZE]; sl@0: /* Initial storage for aux data array. */ sl@0: #ifdef TCL_TIP280 sl@0: /* TIP #280 */ sl@0: ExtCmdLoc* extCmdMapPtr; /* Extended command location information sl@0: * for 'info frame'. */ sl@0: int line; /* First line of the script, based on the sl@0: * invoking context, then the line of the sl@0: * command currently compiled. */ sl@0: #endif sl@0: } CompileEnv; sl@0: sl@0: /* sl@0: * The structure defining the bytecode instructions resulting from compiling sl@0: * a Tcl script. Note that this structure is variable length: a single heap sl@0: * object is allocated to hold the ByteCode structure immediately followed sl@0: * by the code bytes, the literal object array, the ExceptionRange array, sl@0: * the CmdLocation map, and the compilation AuxData array. sl@0: */ sl@0: sl@0: /* sl@0: * A PRECOMPILED bytecode struct is one that was generated from a compiled sl@0: * image rather than implicitly compiled from source sl@0: */ sl@0: #define TCL_BYTECODE_PRECOMPILED 0x0001 sl@0: sl@0: typedef struct ByteCode { sl@0: TclHandle interpHandle; /* Handle for interpreter containing the sl@0: * compiled code. Commands and their compile sl@0: * procs are specific to an interpreter so the sl@0: * code emitted will depend on the sl@0: * interpreter. */ sl@0: int compileEpoch; /* Value of iPtr->compileEpoch when this sl@0: * ByteCode was compiled. Used to invalidate sl@0: * code when, e.g., commands with compile sl@0: * procs are redefined. */ sl@0: Namespace *nsPtr; /* Namespace context in which this code sl@0: * was compiled. If the code is executed sl@0: * if a different namespace, it must be sl@0: * recompiled. */ sl@0: int nsEpoch; /* Value of nsPtr->resolverEpoch when this sl@0: * ByteCode was compiled. Used to invalidate sl@0: * code when new namespace resolution rules sl@0: * are put into effect. */ sl@0: int refCount; /* Reference count: set 1 when created sl@0: * plus 1 for each execution of the code sl@0: * currently active. This structure can be sl@0: * freed when refCount becomes zero. */ sl@0: unsigned int flags; /* flags describing state for the codebyte. sl@0: * this variable holds ORed values from the sl@0: * TCL_BYTECODE_ masks defined above */ sl@0: char *source; /* The source string from which this sl@0: * ByteCode was compiled. Note that this sl@0: * pointer is not owned by the ByteCode and sl@0: * must not be freed or modified by it. */ sl@0: Proc *procPtr; /* If the ByteCode was compiled from a sl@0: * procedure body, this is a pointer to its sl@0: * Proc structure; otherwise NULL. This sl@0: * pointer is also not owned by the ByteCode sl@0: * and must not be freed by it. */ sl@0: size_t structureSize; /* Number of bytes in the ByteCode structure sl@0: * itself. Does not include heap space for sl@0: * literal Tcl objects or storage referenced sl@0: * by AuxData entries. */ sl@0: int numCommands; /* Number of commands compiled. */ sl@0: int numSrcBytes; /* Number of source bytes compiled. */ sl@0: int numCodeBytes; /* Number of code bytes. */ sl@0: int numLitObjects; /* Number of objects in literal array. */ sl@0: int numExceptRanges; /* Number of ExceptionRange array elems. */ sl@0: int numAuxDataItems; /* Number of AuxData items. */ sl@0: int numCmdLocBytes; /* Number of bytes needed for encoded sl@0: * command location information. */ sl@0: int maxExceptDepth; /* Maximum nesting level of ExceptionRanges; sl@0: * -1 if no ranges were compiled. */ sl@0: int maxStackDepth; /* Maximum number of stack elements needed sl@0: * to execute the code. */ sl@0: unsigned char *codeStart; /* Points to the first byte of the code. sl@0: * This is just after the final ByteCode sl@0: * member cmdMapPtr. */ sl@0: Tcl_Obj **objArrayPtr; /* Points to the start of the literal sl@0: * object array. This is just after the sl@0: * last code byte. */ sl@0: ExceptionRange *exceptArrayPtr; sl@0: /* Points to the start of the ExceptionRange sl@0: * array. This is just after the last sl@0: * object in the object array. */ sl@0: AuxData *auxDataArrayPtr; /* Points to the start of the auxiliary data sl@0: * array. This is just after the last entry sl@0: * in the ExceptionRange array. */ sl@0: unsigned char *codeDeltaStart; sl@0: /* Points to the first of a sequence of sl@0: * bytes that encode the change in the sl@0: * starting offset of each command's code. sl@0: * If -127<=delta<=127, it is encoded as 1 sl@0: * byte, otherwise 0xFF (128) appears and sl@0: * the delta is encoded by the next 4 bytes. sl@0: * Code deltas are always positive. This sl@0: * sequence is just after the last entry in sl@0: * the AuxData array. */ sl@0: unsigned char *codeLengthStart; sl@0: /* Points to the first of a sequence of sl@0: * bytes that encode the length of each sl@0: * command's code. The encoding is the same sl@0: * as for code deltas. Code lengths are sl@0: * always positive. This sequence is just sl@0: * after the last entry in the code delta sl@0: * sequence. */ sl@0: unsigned char *srcDeltaStart; sl@0: /* Points to the first of a sequence of sl@0: * bytes that encode the change in the sl@0: * starting offset of each command's source. sl@0: * The encoding is the same as for code sl@0: * deltas. Source deltas can be negative. sl@0: * This sequence is just after the last byte sl@0: * in the code length sequence. */ sl@0: unsigned char *srcLengthStart; sl@0: /* Points to the first of a sequence of sl@0: * bytes that encode the length of each sl@0: * command's source. The encoding is the sl@0: * same as for code deltas. Source lengths sl@0: * are always positive. This sequence is sl@0: * just after the last byte in the source sl@0: * delta sequence. */ sl@0: #ifdef TCL_COMPILE_STATS sl@0: Tcl_Time createTime; /* Absolute time when the ByteCode was sl@0: * created. */ sl@0: #endif /* TCL_COMPILE_STATS */ sl@0: } ByteCode; sl@0: sl@0: /* sl@0: * Opcodes for the Tcl bytecode instructions. These must correspond to sl@0: * the entries in the table of instruction descriptions, sl@0: * tclInstructionTable, in tclCompile.c. Also, the order and number of sl@0: * the expression opcodes (e.g., INST_LOR) must match the entries in sl@0: * the array operatorStrings in tclExecute.c. sl@0: */ sl@0: sl@0: /* Opcodes 0 to 9 */ sl@0: #define INST_DONE 0 sl@0: #define INST_PUSH1 1 sl@0: #define INST_PUSH4 2 sl@0: #define INST_POP 3 sl@0: #define INST_DUP 4 sl@0: #define INST_CONCAT1 5 sl@0: #define INST_INVOKE_STK1 6 sl@0: #define INST_INVOKE_STK4 7 sl@0: #define INST_EVAL_STK 8 sl@0: #define INST_EXPR_STK 9 sl@0: sl@0: /* Opcodes 10 to 23 */ sl@0: #define INST_LOAD_SCALAR1 10 sl@0: #define INST_LOAD_SCALAR4 11 sl@0: #define INST_LOAD_SCALAR_STK 12 sl@0: #define INST_LOAD_ARRAY1 13 sl@0: #define INST_LOAD_ARRAY4 14 sl@0: #define INST_LOAD_ARRAY_STK 15 sl@0: #define INST_LOAD_STK 16 sl@0: #define INST_STORE_SCALAR1 17 sl@0: #define INST_STORE_SCALAR4 18 sl@0: #define INST_STORE_SCALAR_STK 19 sl@0: #define INST_STORE_ARRAY1 20 sl@0: #define INST_STORE_ARRAY4 21 sl@0: #define INST_STORE_ARRAY_STK 22 sl@0: #define INST_STORE_STK 23 sl@0: sl@0: /* Opcodes 24 to 33 */ sl@0: #define INST_INCR_SCALAR1 24 sl@0: #define INST_INCR_SCALAR_STK 25 sl@0: #define INST_INCR_ARRAY1 26 sl@0: #define INST_INCR_ARRAY_STK 27 sl@0: #define INST_INCR_STK 28 sl@0: #define INST_INCR_SCALAR1_IMM 29 sl@0: #define INST_INCR_SCALAR_STK_IMM 30 sl@0: #define INST_INCR_ARRAY1_IMM 31 sl@0: #define INST_INCR_ARRAY_STK_IMM 32 sl@0: #define INST_INCR_STK_IMM 33 sl@0: sl@0: /* Opcodes 34 to 39 */ sl@0: #define INST_JUMP1 34 sl@0: #define INST_JUMP4 35 sl@0: #define INST_JUMP_TRUE1 36 sl@0: #define INST_JUMP_TRUE4 37 sl@0: #define INST_JUMP_FALSE1 38 sl@0: #define INST_JUMP_FALSE4 39 sl@0: sl@0: /* Opcodes 40 to 64 */ sl@0: #define INST_LOR 40 sl@0: #define INST_LAND 41 sl@0: #define INST_BITOR 42 sl@0: #define INST_BITXOR 43 sl@0: #define INST_BITAND 44 sl@0: #define INST_EQ 45 sl@0: #define INST_NEQ 46 sl@0: #define INST_LT 47 sl@0: #define INST_GT 48 sl@0: #define INST_LE 49 sl@0: #define INST_GE 50 sl@0: #define INST_LSHIFT 51 sl@0: #define INST_RSHIFT 52 sl@0: #define INST_ADD 53 sl@0: #define INST_SUB 54 sl@0: #define INST_MULT 55 sl@0: #define INST_DIV 56 sl@0: #define INST_MOD 57 sl@0: #define INST_UPLUS 58 sl@0: #define INST_UMINUS 59 sl@0: #define INST_BITNOT 60 sl@0: #define INST_LNOT 61 sl@0: #define INST_CALL_BUILTIN_FUNC1 62 sl@0: #define INST_CALL_FUNC1 63 sl@0: #define INST_TRY_CVT_TO_NUMERIC 64 sl@0: sl@0: /* Opcodes 65 to 66 */ sl@0: #define INST_BREAK 65 sl@0: #define INST_CONTINUE 66 sl@0: sl@0: /* Opcodes 67 to 68 */ sl@0: #define INST_FOREACH_START4 67 sl@0: #define INST_FOREACH_STEP4 68 sl@0: sl@0: /* Opcodes 69 to 72 */ sl@0: #define INST_BEGIN_CATCH4 69 sl@0: #define INST_END_CATCH 70 sl@0: #define INST_PUSH_RESULT 71 sl@0: #define INST_PUSH_RETURN_CODE 72 sl@0: sl@0: /* Opcodes 73 to 78 */ sl@0: #define INST_STR_EQ 73 sl@0: #define INST_STR_NEQ 74 sl@0: #define INST_STR_CMP 75 sl@0: #define INST_STR_LEN 76 sl@0: #define INST_STR_INDEX 77 sl@0: #define INST_STR_MATCH 78 sl@0: sl@0: /* Opcodes 78 to 81 */ sl@0: #define INST_LIST 79 sl@0: #define INST_LIST_INDEX 80 sl@0: #define INST_LIST_LENGTH 81 sl@0: sl@0: /* Opcodes 82 to 87 */ sl@0: #define INST_APPEND_SCALAR1 82 sl@0: #define INST_APPEND_SCALAR4 83 sl@0: #define INST_APPEND_ARRAY1 84 sl@0: #define INST_APPEND_ARRAY4 85 sl@0: #define INST_APPEND_ARRAY_STK 86 sl@0: #define INST_APPEND_STK 87 sl@0: sl@0: /* Opcodes 88 to 93 */ sl@0: #define INST_LAPPEND_SCALAR1 88 sl@0: #define INST_LAPPEND_SCALAR4 89 sl@0: #define INST_LAPPEND_ARRAY1 90 sl@0: #define INST_LAPPEND_ARRAY4 91 sl@0: #define INST_LAPPEND_ARRAY_STK 92 sl@0: #define INST_LAPPEND_STK 93 sl@0: sl@0: /* TIP #22 - LINDEX operator with flat arg list */ sl@0: sl@0: #define INST_LIST_INDEX_MULTI 94 sl@0: sl@0: /* sl@0: * TIP #33 - 'lset' command. Code gen also required a Forth-like sl@0: * OVER operation. sl@0: */ sl@0: sl@0: #define INST_OVER 95 sl@0: #define INST_LSET_LIST 96 sl@0: #define INST_LSET_FLAT 97 sl@0: sl@0: /* The last opcode */ sl@0: #define LAST_INST_OPCODE 97 sl@0: sl@0: /* sl@0: * Table describing the Tcl bytecode instructions: their name (for sl@0: * displaying code), total number of code bytes required (including sl@0: * operand bytes), and a description of the type of each operand. sl@0: * These operand types include signed and unsigned integers of length sl@0: * one and four bytes. The unsigned integers are used for indexes or sl@0: * for, e.g., the count of objects to push in a "push" instruction. sl@0: */ sl@0: sl@0: #define MAX_INSTRUCTION_OPERANDS 2 sl@0: sl@0: typedef enum InstOperandType { sl@0: OPERAND_NONE, sl@0: OPERAND_INT1, /* One byte signed integer. */ sl@0: OPERAND_INT4, /* Four byte signed integer. */ sl@0: OPERAND_UINT1, /* One byte unsigned integer. */ sl@0: OPERAND_UINT4 /* Four byte unsigned integer. */ sl@0: } InstOperandType; sl@0: sl@0: typedef struct InstructionDesc { sl@0: char *name; /* Name of instruction. */ sl@0: int numBytes; /* Total number of bytes for instruction. */ sl@0: int stackEffect; /* The worst-case balance stack effect of the sl@0: * instruction, used for stack requirements sl@0: * computations. The value INT_MIN signals sl@0: * that the instruction's worst case effect sl@0: * is (1-opnd1). sl@0: */ sl@0: int numOperands; /* Number of operands. */ sl@0: InstOperandType opTypes[MAX_INSTRUCTION_OPERANDS]; sl@0: /* The type of each operand. */ sl@0: } InstructionDesc; sl@0: sl@0: extern InstructionDesc tclInstructionTable[]; sl@0: sl@0: /* sl@0: * Definitions of the values of the INST_CALL_BUILTIN_FUNC instruction's sl@0: * operand byte. Each value denotes a builtin Tcl math function. These sl@0: * values must correspond to the entries in the tclBuiltinFuncTable array sl@0: * below and to the values stored in the tclInt.h MathFunc structure's sl@0: * builtinFuncIndex field. sl@0: */ sl@0: sl@0: #define BUILTIN_FUNC_ACOS 0 sl@0: #define BUILTIN_FUNC_ASIN 1 sl@0: #define BUILTIN_FUNC_ATAN 2 sl@0: #define BUILTIN_FUNC_ATAN2 3 sl@0: #define BUILTIN_FUNC_CEIL 4 sl@0: #define BUILTIN_FUNC_COS 5 sl@0: #define BUILTIN_FUNC_COSH 6 sl@0: #define BUILTIN_FUNC_EXP 7 sl@0: #define BUILTIN_FUNC_FLOOR 8 sl@0: #define BUILTIN_FUNC_FMOD 9 sl@0: #define BUILTIN_FUNC_HYPOT 10 sl@0: #define BUILTIN_FUNC_LOG 11 sl@0: #define BUILTIN_FUNC_LOG10 12 sl@0: #define BUILTIN_FUNC_POW 13 sl@0: #define BUILTIN_FUNC_SIN 14 sl@0: #define BUILTIN_FUNC_SINH 15 sl@0: #define BUILTIN_FUNC_SQRT 16 sl@0: #define BUILTIN_FUNC_TAN 17 sl@0: #define BUILTIN_FUNC_TANH 18 sl@0: #define BUILTIN_FUNC_ABS 19 sl@0: #define BUILTIN_FUNC_DOUBLE 20 sl@0: #define BUILTIN_FUNC_INT 21 sl@0: #define BUILTIN_FUNC_RAND 22 sl@0: #define BUILTIN_FUNC_ROUND 23 sl@0: #define BUILTIN_FUNC_SRAND 24 sl@0: #define BUILTIN_FUNC_WIDE 25 sl@0: sl@0: #define LAST_BUILTIN_FUNC 25 sl@0: sl@0: /* sl@0: * Table describing the built-in math functions. Entries in this table are sl@0: * indexed by the values of the INST_CALL_BUILTIN_FUNC instruction's sl@0: * operand byte. sl@0: */ sl@0: sl@0: typedef int (CallBuiltinFuncProc) _ANSI_ARGS_((Tcl_Interp *interp, sl@0: ExecEnv *eePtr, ClientData clientData)); sl@0: sl@0: typedef struct { sl@0: char *name; /* Name of function. */ sl@0: int numArgs; /* Number of arguments for function. */ sl@0: Tcl_ValueType argTypes[MAX_MATH_ARGS]; sl@0: /* Acceptable types for each argument. */ sl@0: CallBuiltinFuncProc *proc; /* Procedure implementing this function. */ sl@0: ClientData clientData; /* Additional argument to pass to the sl@0: * function when invoking it. */ sl@0: } BuiltinFunc; sl@0: sl@0: extern BuiltinFunc tclBuiltinFuncTable[]; sl@0: sl@0: /* sl@0: * Compilation of some Tcl constructs such as if commands and the logical or sl@0: * (||) and logical and (&&) operators in expressions requires the sl@0: * generation of forward jumps. Since the PC target of these jumps isn't sl@0: * known when the jumps are emitted, we record the offset of each jump in an sl@0: * array of JumpFixup structures. There is one array for each sequence of sl@0: * jumps to one target PC. When we learn the target PC, we update the jumps sl@0: * with the correct distance. Also, if the distance is too great (> 127 sl@0: * bytes), we replace the single-byte jump with a four byte jump sl@0: * instruction, move the instructions after the jump down, and update the sl@0: * code offsets for any commands between the jump and the target. sl@0: */ sl@0: sl@0: typedef enum { sl@0: TCL_UNCONDITIONAL_JUMP, sl@0: TCL_TRUE_JUMP, sl@0: TCL_FALSE_JUMP sl@0: } TclJumpType; sl@0: sl@0: typedef struct JumpFixup { sl@0: TclJumpType jumpType; /* Indicates the kind of jump. */ sl@0: int codeOffset; /* Offset of the first byte of the one-byte sl@0: * forward jump's code. */ sl@0: int cmdIndex; /* Index of the first command after the one sl@0: * for which the jump was emitted. Used to sl@0: * update the code offsets for subsequent sl@0: * commands if the two-byte jump at jumpPc sl@0: * must be replaced with a five-byte one. */ sl@0: int exceptIndex; /* Index of the first range entry in the sl@0: * ExceptionRange array after the current sl@0: * one. This field is used to adjust the sl@0: * code offsets in subsequent ExceptionRange sl@0: * records when a jump is grown from 2 bytes sl@0: * to 5 bytes. */ sl@0: } JumpFixup; sl@0: sl@0: #define JUMPFIXUP_INIT_ENTRIES 10 sl@0: sl@0: typedef struct JumpFixupArray { sl@0: JumpFixup *fixup; /* Points to start of jump fixup array. */ sl@0: int next; /* Index of next free array entry. */ sl@0: int end; /* Index of last usable entry in array. */ sl@0: int mallocedArray; /* 1 if array was expanded and fixups points sl@0: * into the heap, else 0. */ sl@0: JumpFixup staticFixupSpace[JUMPFIXUP_INIT_ENTRIES]; sl@0: /* Initial storage for jump fixup array. */ sl@0: } JumpFixupArray; sl@0: sl@0: /* sl@0: * The structure describing one variable list of a foreach command. Note sl@0: * that only foreach commands inside procedure bodies are compiled inline so sl@0: * a ForeachVarList structure always describes local variables. Furthermore, sl@0: * only scalar variables are supported for inline-compiled foreach loops. sl@0: */ sl@0: sl@0: typedef struct ForeachVarList { sl@0: int numVars; /* The number of variables in the list. */ sl@0: int varIndexes[1]; /* An array of the indexes ("slot numbers") sl@0: * for each variable in the procedure's sl@0: * array of local variables. Only scalar sl@0: * variables are supported. The actual sl@0: * size of this field will be large enough sl@0: * to numVars indexes. THIS MUST BE THE sl@0: * LAST FIELD IN THE STRUCTURE! */ sl@0: } ForeachVarList; sl@0: sl@0: /* sl@0: * Structure used to hold information about a foreach command that is needed sl@0: * during program execution. These structures are stored in CompileEnv and sl@0: * ByteCode structures as auxiliary data. sl@0: */ sl@0: sl@0: typedef struct ForeachInfo { sl@0: int numLists; /* The number of both the variable and value sl@0: * lists of the foreach command. */ sl@0: int firstValueTemp; /* Index of the first temp var in a proc sl@0: * frame used to point to a value list. */ sl@0: int loopCtTemp; /* Index of temp var in a proc frame sl@0: * holding the loop's iteration count. Used sl@0: * to determine next value list element to sl@0: * assign each loop var. */ sl@0: ForeachVarList *varLists[1];/* An array of pointers to ForeachVarList sl@0: * structures describing each var list. The sl@0: * actual size of this field will be large sl@0: * enough to numVars indexes. THIS MUST BE sl@0: * THE LAST FIELD IN THE STRUCTURE! */ sl@0: } ForeachInfo; sl@0: sl@0: extern AuxDataType tclForeachInfoType; sl@0: sl@0: sl@0: /* sl@0: *---------------------------------------------------------------- sl@0: * Procedures exported by tclBasic.c to be used within the engine. sl@0: *---------------------------------------------------------------- sl@0: */ sl@0: sl@0: EXTERN int TclEvalObjvInternal _ANSI_ARGS_((Tcl_Interp *interp, int objc, sl@0: Tcl_Obj *CONST objv[], CONST char *command, int length, sl@0: int flags)); sl@0: EXTERN int TclInterpReady _ANSI_ARGS_((Tcl_Interp *interp)); sl@0: sl@0: sl@0: /* sl@0: *---------------------------------------------------------------- sl@0: * Procedures exported by the engine to be used by tclBasic.c sl@0: *---------------------------------------------------------------- sl@0: */ sl@0: sl@0: #ifndef TCL_TIP280 sl@0: EXTERN int TclCompEvalObj _ANSI_ARGS_((Tcl_Interp *interp, sl@0: Tcl_Obj *objPtr)); sl@0: #else sl@0: EXTERN int TclCompEvalObj _ANSI_ARGS_((Tcl_Interp *interp, sl@0: Tcl_Obj *objPtr, CONST CmdFrame* invoker, sl@0: int word)); sl@0: #endif sl@0: sl@0: /* sl@0: *---------------------------------------------------------------- sl@0: * Procedures shared among Tcl bytecode compilation and execution sl@0: * modules but not used outside: sl@0: *---------------------------------------------------------------- sl@0: */ sl@0: sl@0: EXTERN void TclCleanupByteCode _ANSI_ARGS_((ByteCode *codePtr)); sl@0: EXTERN int TclCompileCmdWord _ANSI_ARGS_((Tcl_Interp *interp, sl@0: Tcl_Token *tokenPtr, int count, sl@0: CompileEnv *envPtr)); sl@0: EXTERN int TclCompileExpr _ANSI_ARGS_((Tcl_Interp *interp, sl@0: CONST char *script, int numBytes, sl@0: CompileEnv *envPtr)); sl@0: EXTERN int TclCompileExprWords _ANSI_ARGS_((Tcl_Interp *interp, sl@0: Tcl_Token *tokenPtr, int numWords, sl@0: CompileEnv *envPtr)); sl@0: EXTERN int TclCompileScript _ANSI_ARGS_((Tcl_Interp *interp, sl@0: CONST char *script, int numBytes, int nested, sl@0: CompileEnv *envPtr)); sl@0: EXTERN int TclCompileTokens _ANSI_ARGS_((Tcl_Interp *interp, sl@0: Tcl_Token *tokenPtr, int count, sl@0: CompileEnv *envPtr)); sl@0: EXTERN int TclCreateAuxData _ANSI_ARGS_((ClientData clientData, sl@0: AuxDataType *typePtr, CompileEnv *envPtr)); sl@0: EXTERN int TclCreateExceptRange _ANSI_ARGS_(( sl@0: ExceptionRangeType type, CompileEnv *envPtr)); sl@0: EXTERN ExecEnv * TclCreateExecEnv _ANSI_ARGS_((Tcl_Interp *interp)); sl@0: EXTERN void TclDeleteExecEnv _ANSI_ARGS_((ExecEnv *eePtr)); sl@0: EXTERN void TclDeleteLiteralTable _ANSI_ARGS_(( sl@0: Tcl_Interp *interp, LiteralTable *tablePtr)); sl@0: EXTERN void TclEmitForwardJump _ANSI_ARGS_((CompileEnv *envPtr, sl@0: TclJumpType jumpType, JumpFixup *jumpFixupPtr)); sl@0: EXTERN ExceptionRange * TclGetExceptionRangeForPc _ANSI_ARGS_(( sl@0: unsigned char *pc, int catchOnly, sl@0: ByteCode* codePtr)); sl@0: EXTERN void TclExpandJumpFixupArray _ANSI_ARGS_(( sl@0: JumpFixupArray *fixupArrayPtr)); sl@0: EXTERN void TclFinalizeAuxDataTypeTable _ANSI_ARGS_((void)); sl@0: EXTERN int TclFindCompiledLocal _ANSI_ARGS_((CONST char *name, sl@0: int nameChars, int create, int flags, sl@0: Proc *procPtr)); sl@0: EXTERN LiteralEntry * TclLookupLiteralEntry _ANSI_ARGS_(( sl@0: Tcl_Interp *interp, Tcl_Obj *objPtr)); sl@0: EXTERN int TclFixupForwardJump _ANSI_ARGS_(( sl@0: CompileEnv *envPtr, JumpFixup *jumpFixupPtr, sl@0: int jumpDist, int distThreshold)); sl@0: EXTERN void TclFreeCompileEnv _ANSI_ARGS_((CompileEnv *envPtr)); sl@0: EXTERN void TclFreeJumpFixupArray _ANSI_ARGS_(( sl@0: JumpFixupArray *fixupArrayPtr)); sl@0: EXTERN void TclInitAuxDataTypeTable _ANSI_ARGS_((void)); sl@0: EXTERN void TclInitByteCodeObj _ANSI_ARGS_((Tcl_Obj *objPtr, sl@0: CompileEnv *envPtr)); sl@0: EXTERN void TclInitCompilation _ANSI_ARGS_((void)); sl@0: #ifndef TCL_TIP280 sl@0: EXTERN void TclInitCompileEnv _ANSI_ARGS_((Tcl_Interp *interp, sl@0: CompileEnv *envPtr, char *string, sl@0: int numBytes)); sl@0: #else sl@0: EXTERN void TclInitCompileEnv _ANSI_ARGS_((Tcl_Interp *interp, sl@0: CompileEnv *envPtr, char *string, sl@0: int numBytes, CONST CmdFrame* invoker, int word)); sl@0: #endif sl@0: EXTERN void TclInitJumpFixupArray _ANSI_ARGS_(( sl@0: JumpFixupArray *fixupArrayPtr)); sl@0: EXTERN void TclInitLiteralTable _ANSI_ARGS_(( sl@0: LiteralTable *tablePtr)); sl@0: #ifdef TCL_COMPILE_STATS sl@0: EXTERN char * TclLiteralStats _ANSI_ARGS_(( sl@0: LiteralTable *tablePtr)); sl@0: EXTERN int TclLog2 _ANSI_ARGS_((int value)); sl@0: #endif sl@0: #ifdef TCL_COMPILE_DEBUG sl@0: EXTERN void TclPrintByteCodeObj _ANSI_ARGS_((Tcl_Interp *interp, sl@0: Tcl_Obj *objPtr)); sl@0: #endif sl@0: EXTERN int TclPrintInstruction _ANSI_ARGS_((ByteCode* codePtr, sl@0: unsigned char *pc)); sl@0: EXTERN void TclPrintObject _ANSI_ARGS_((FILE *outFile, sl@0: Tcl_Obj *objPtr, int maxChars)); sl@0: EXTERN void TclPrintSource _ANSI_ARGS_((FILE *outFile, sl@0: CONST char *string, int maxChars)); sl@0: EXTERN void TclRegisterAuxDataType _ANSI_ARGS_((AuxDataType *typePtr)); sl@0: EXTERN int TclRegisterLiteral _ANSI_ARGS_((CompileEnv *envPtr, sl@0: char *bytes, int length, int onHeap)); sl@0: EXTERN void TclReleaseLiteral _ANSI_ARGS_((Tcl_Interp *interp, sl@0: Tcl_Obj *objPtr)); sl@0: EXTERN void TclSetCmdNameObj _ANSI_ARGS_((Tcl_Interp *interp, sl@0: Tcl_Obj *objPtr, Command *cmdPtr)); sl@0: #ifdef TCL_COMPILE_DEBUG sl@0: EXTERN void TclVerifyGlobalLiteralTable _ANSI_ARGS_(( sl@0: Interp *iPtr)); sl@0: EXTERN void TclVerifyLocalLiteralTable _ANSI_ARGS_(( sl@0: CompileEnv *envPtr)); sl@0: #endif sl@0: EXTERN int TclCompileVariableCmd _ANSI_ARGS_(( sl@0: Tcl_Interp *interp, Tcl_Parse *parsePtr, CompileEnv *envPtr)); sl@0: sl@0: /* sl@0: *---------------------------------------------------------------- sl@0: * Macros used by Tcl bytecode compilation and execution modules sl@0: * inside the Tcl core but not used outside. sl@0: *---------------------------------------------------------------- sl@0: */ sl@0: sl@0: /* sl@0: * Form of TclRegisterLiteral with onHeap == 0. sl@0: * In that case, it is safe to cast away CONSTness, and it sl@0: * is cleanest to do that here, all in one place. sl@0: */ sl@0: sl@0: #define TclRegisterNewLiteral(envPtr, bytes, length) \ sl@0: TclRegisterLiteral(envPtr, (char *)(bytes), length, /*onHeap*/ 0) sl@0: sl@0: /* sl@0: * Macro used to update the stack requirements. sl@0: * It is called by the macros TclEmitOpCode, TclEmitInst1 and sl@0: * TclEmitInst4. sl@0: * Remark that the very last instruction of a bytecode always sl@0: * reduces the stack level: INST_DONE or INST_POP, so that the sl@0: * maxStackdepth is always updated. sl@0: */ sl@0: sl@0: #define TclUpdateStackReqs(op, i, envPtr) \ sl@0: {\ sl@0: int delta = tclInstructionTable[(op)].stackEffect;\ sl@0: if (delta) {\ sl@0: if (delta < 0) {\ sl@0: if((envPtr)->maxStackDepth < (envPtr)->currStackDepth) {\ sl@0: (envPtr)->maxStackDepth = (envPtr)->currStackDepth;\ sl@0: }\ sl@0: if (delta == INT_MIN) {\ sl@0: delta = 1 - (i);\ sl@0: }\ sl@0: }\ sl@0: (envPtr)->currStackDepth += delta;\ sl@0: }\ sl@0: } sl@0: sl@0: /* sl@0: * Macro to emit an opcode byte into a CompileEnv's code array. sl@0: * The ANSI C "prototype" for this macro is: sl@0: * sl@0: * EXTERN void TclEmitOpcode _ANSI_ARGS_((unsigned char op, sl@0: * CompileEnv *envPtr)); sl@0: */ sl@0: sl@0: #define TclEmitOpcode(op, envPtr) \ sl@0: if ((envPtr)->codeNext == (envPtr)->codeEnd) \ sl@0: TclExpandCodeArray(envPtr); \ sl@0: *(envPtr)->codeNext++ = (unsigned char) (op);\ sl@0: TclUpdateStackReqs(op, 0, envPtr) sl@0: sl@0: /* sl@0: * Macro to emit an integer operand. sl@0: * The ANSI C "prototype" for this macro is: sl@0: * sl@0: * EXTERN void TclEmitInt1 _ANSI_ARGS_((int i, CompileEnv *envPtr)); sl@0: */ sl@0: sl@0: #define TclEmitInt1(i, envPtr) \ sl@0: if ((envPtr)->codeNext == (envPtr)->codeEnd) \ sl@0: TclExpandCodeArray(envPtr); \ sl@0: *(envPtr)->codeNext++ = (unsigned char) ((unsigned int) (i)) sl@0: sl@0: /* sl@0: * Macros to emit an instruction with signed or unsigned integer operands. sl@0: * Four byte integers are stored in "big-endian" order with the high order sl@0: * byte stored at the lowest address. sl@0: * The ANSI C "prototypes" for these macros are: sl@0: * sl@0: * EXTERN void TclEmitInstInt1 _ANSI_ARGS_((unsigned char op, int i, sl@0: * CompileEnv *envPtr)); sl@0: * EXTERN void TclEmitInstInt4 _ANSI_ARGS_((unsigned char op, int i, sl@0: * CompileEnv *envPtr)); sl@0: */ sl@0: sl@0: sl@0: #define TclEmitInstInt1(op, i, envPtr) \ sl@0: if (((envPtr)->codeNext + 2) > (envPtr)->codeEnd) { \ sl@0: TclExpandCodeArray(envPtr); \ sl@0: } \ sl@0: *(envPtr)->codeNext++ = (unsigned char) (op); \ sl@0: *(envPtr)->codeNext++ = (unsigned char) ((unsigned int) (i));\ sl@0: TclUpdateStackReqs(op, i, envPtr) sl@0: sl@0: #define TclEmitInstInt4(op, i, envPtr) \ sl@0: if (((envPtr)->codeNext + 5) > (envPtr)->codeEnd) { \ sl@0: TclExpandCodeArray(envPtr); \ sl@0: } \ sl@0: *(envPtr)->codeNext++ = (unsigned char) (op); \ sl@0: *(envPtr)->codeNext++ = \ sl@0: (unsigned char) ((unsigned int) (i) >> 24); \ sl@0: *(envPtr)->codeNext++ = \ sl@0: (unsigned char) ((unsigned int) (i) >> 16); \ sl@0: *(envPtr)->codeNext++ = \ sl@0: (unsigned char) ((unsigned int) (i) >> 8); \ sl@0: *(envPtr)->codeNext++ = \ sl@0: (unsigned char) ((unsigned int) (i) );\ sl@0: TclUpdateStackReqs(op, i, envPtr) sl@0: sl@0: /* sl@0: * Macro to push a Tcl object onto the Tcl evaluation stack. It emits the sl@0: * object's one or four byte array index into the CompileEnv's code sl@0: * array. These support, respectively, a maximum of 256 (2**8) and 2**32 sl@0: * objects in a CompileEnv. The ANSI C "prototype" for this macro is: sl@0: * sl@0: * EXTERN void TclEmitPush _ANSI_ARGS_((int objIndex, CompileEnv *envPtr)); sl@0: */ sl@0: sl@0: #define TclEmitPush(objIndex, envPtr) \ sl@0: {\ sl@0: register int objIndexCopy = (objIndex);\ sl@0: if (objIndexCopy <= 255) { \ sl@0: TclEmitInstInt1(INST_PUSH1, objIndexCopy, (envPtr)); \ sl@0: } else { \ sl@0: TclEmitInstInt4(INST_PUSH4, objIndexCopy, (envPtr)); \ sl@0: }\ sl@0: } sl@0: sl@0: /* sl@0: * Macros to update a (signed or unsigned) integer starting at a pointer. sl@0: * The two variants depend on the number of bytes. The ANSI C "prototypes" sl@0: * for these macros are: sl@0: * sl@0: * EXTERN void TclStoreInt1AtPtr _ANSI_ARGS_((int i, unsigned char *p)); sl@0: * EXTERN void TclStoreInt4AtPtr _ANSI_ARGS_((int i, unsigned char *p)); sl@0: */ sl@0: sl@0: #define TclStoreInt1AtPtr(i, p) \ sl@0: *(p) = (unsigned char) ((unsigned int) (i)) sl@0: sl@0: #define TclStoreInt4AtPtr(i, p) \ sl@0: *(p) = (unsigned char) ((unsigned int) (i) >> 24); \ sl@0: *(p+1) = (unsigned char) ((unsigned int) (i) >> 16); \ sl@0: *(p+2) = (unsigned char) ((unsigned int) (i) >> 8); \ sl@0: *(p+3) = (unsigned char) ((unsigned int) (i) ) sl@0: sl@0: /* sl@0: * Macros to update instructions at a particular pc with a new op code sl@0: * and a (signed or unsigned) int operand. The ANSI C "prototypes" for sl@0: * these macros are: sl@0: * sl@0: * EXTERN void TclUpdateInstInt1AtPc _ANSI_ARGS_((unsigned char op, int i, sl@0: * unsigned char *pc)); sl@0: * EXTERN void TclUpdateInstInt4AtPc _ANSI_ARGS_((unsigned char op, int i, sl@0: * unsigned char *pc)); sl@0: */ sl@0: sl@0: #define TclUpdateInstInt1AtPc(op, i, pc) \ sl@0: *(pc) = (unsigned char) (op); \ sl@0: TclStoreInt1AtPtr((i), ((pc)+1)) sl@0: sl@0: #define TclUpdateInstInt4AtPc(op, i, pc) \ sl@0: *(pc) = (unsigned char) (op); \ sl@0: TclStoreInt4AtPtr((i), ((pc)+1)) sl@0: sl@0: /* sl@0: * Macros to get a signed integer (GET_INT{1,2}) or an unsigned int sl@0: * (GET_UINT{1,2}) from a pointer. There are two variants for each sl@0: * return type that depend on the number of bytes fetched. sl@0: * The ANSI C "prototypes" for these macros are: sl@0: * sl@0: * EXTERN int TclGetInt1AtPtr _ANSI_ARGS_((unsigned char *p)); sl@0: * EXTERN int TclGetInt4AtPtr _ANSI_ARGS_((unsigned char *p)); sl@0: * EXTERN unsigned int TclGetUInt1AtPtr _ANSI_ARGS_((unsigned char *p)); sl@0: * EXTERN unsigned int TclGetUInt4AtPtr _ANSI_ARGS_((unsigned char *p)); sl@0: */ sl@0: sl@0: /* sl@0: * The TclGetInt1AtPtr macro is tricky because we want to do sign sl@0: * extension on the 1-byte value. Unfortunately the "char" type isn't sl@0: * signed on all platforms so sign-extension doesn't always happen sl@0: * automatically. Sometimes we can explicitly declare the pointer to be sl@0: * signed, but other times we have to explicitly sign-extend the value sl@0: * in software. sl@0: */ sl@0: sl@0: #ifndef __CHAR_UNSIGNED__ sl@0: # define TclGetInt1AtPtr(p) ((int) *((char *) p)) sl@0: #else sl@0: # ifdef HAVE_SIGNED_CHAR sl@0: # define TclGetInt1AtPtr(p) ((int) *((signed char *) p)) sl@0: # else sl@0: # define TclGetInt1AtPtr(p) (((int) *((char *) p)) \ sl@0: | ((*(p) & 0200) ? (-256) : 0)) sl@0: # endif sl@0: #endif sl@0: sl@0: #define TclGetInt4AtPtr(p) (((int) TclGetInt1AtPtr(p) << 24) | \ sl@0: (*((p)+1) << 16) | \ sl@0: (*((p)+2) << 8) | \ sl@0: (*((p)+3))) sl@0: sl@0: #define TclGetUInt1AtPtr(p) ((unsigned int) *(p)) sl@0: #define TclGetUInt4AtPtr(p) ((unsigned int) (*(p) << 24) | \ sl@0: (*((p)+1) << 16) | \ sl@0: (*((p)+2) << 8) | \ sl@0: (*((p)+3))) sl@0: sl@0: /* sl@0: * Macros used to compute the minimum and maximum of two integers. sl@0: * The ANSI C "prototypes" for these macros are: sl@0: * sl@0: * EXTERN int TclMin _ANSI_ARGS_((int i, int j)); sl@0: * EXTERN int TclMax _ANSI_ARGS_((int i, int j)); sl@0: */ sl@0: sl@0: #define TclMin(i, j) ((((int) i) < ((int) j))? (i) : (j)) sl@0: #define TclMax(i, j) ((((int) i) > ((int) j))? (i) : (j)) sl@0: sl@0: # undef TCL_STORAGE_CLASS sl@0: # define TCL_STORAGE_CLASS DLLIMPORT sl@0: sl@0: #endif /* _TCLCOMPILATION */