os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/generic/tclCompile.h
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/generic/tclCompile.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1088 @@
1.4 +/*
1.5 + * tclCompile.h --
1.6 + *
1.7 + * Copyright (c) 1996-1998 Sun Microsystems, Inc.
1.8 + * Copyright (c) 1998-2000 by Scriptics Corporation.
1.9 + * Copyright (c) 2001 by Kevin B. Kenny. All rights reserved.
1.10 + *
1.11 + * See the file "license.terms" for information on usage and redistribution
1.12 + * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.13 + *
1.14 + * RCS: @(#) $Id: tclCompile.h,v 1.33.2.1 2006/11/28 22:20:00 andreas_kupries Exp $
1.15 + */
1.16 +
1.17 +#ifndef _TCLCOMPILATION
1.18 +#define _TCLCOMPILATION 1
1.19 +
1.20 +#ifndef _TCLINT
1.21 +#include "tclInt.h"
1.22 +#endif /* _TCLINT */
1.23 +
1.24 +#ifdef BUILD_tcl
1.25 +# undef TCL_STORAGE_CLASS
1.26 +# define TCL_STORAGE_CLASS DLLEXPORT
1.27 +#endif
1.28 +
1.29 +/*
1.30 + *------------------------------------------------------------------------
1.31 + * Variables related to compilation. These are used in tclCompile.c,
1.32 + * tclExecute.c, tclBasic.c, and their clients.
1.33 + *------------------------------------------------------------------------
1.34 + */
1.35 +
1.36 +#ifdef TCL_COMPILE_DEBUG
1.37 +/*
1.38 + * Variable that controls whether compilation tracing is enabled and, if so,
1.39 + * what level of tracing is desired:
1.40 + * 0: no compilation tracing
1.41 + * 1: summarize compilation of top level cmds and proc bodies
1.42 + * 2: display all instructions of each ByteCode compiled
1.43 + * This variable is linked to the Tcl variable "tcl_traceCompile".
1.44 + */
1.45 +
1.46 +extern int tclTraceCompile;
1.47 +#endif
1.48 +
1.49 +#ifdef TCL_COMPILE_DEBUG
1.50 +/*
1.51 + * Variable that controls whether execution tracing is enabled and, if so,
1.52 + * what level of tracing is desired:
1.53 + * 0: no execution tracing
1.54 + * 1: trace invocations of Tcl procs only
1.55 + * 2: trace invocations of all (not compiled away) commands
1.56 + * 3: display each instruction executed
1.57 + * This variable is linked to the Tcl variable "tcl_traceExec".
1.58 + */
1.59 +
1.60 +extern int tclTraceExec;
1.61 +#endif
1.62 +
1.63 +/*
1.64 + *------------------------------------------------------------------------
1.65 + * Data structures related to compilation.
1.66 + *------------------------------------------------------------------------
1.67 + */
1.68 +
1.69 +/*
1.70 + * The structure used to implement Tcl "exceptions" (exceptional returns):
1.71 + * for example, those generated in loops by the break and continue commands,
1.72 + * and those generated by scripts and caught by the catch command. This
1.73 + * ExceptionRange structure describes a range of code (e.g., a loop body),
1.74 + * the kind of exceptions (e.g., a break or continue) that might occur, and
1.75 + * the PC offsets to jump to if a matching exception does occur. Exception
1.76 + * ranges can nest so this structure includes a nesting level that is used
1.77 + * at runtime to find the closest exception range surrounding a PC. For
1.78 + * example, when a break command is executed, the ExceptionRange structure
1.79 + * for the most deeply nested loop, if any, is found and used. These
1.80 + * structures are also generated for the "next" subcommands of for loops
1.81 + * since a break there terminates the for command. This means a for command
1.82 + * actually generates two LoopInfo structures.
1.83 + */
1.84 +
1.85 +typedef enum {
1.86 + LOOP_EXCEPTION_RANGE, /* Exception's range is part of a loop.
1.87 + * Break and continue "exceptions" cause
1.88 + * jumps to appropriate PC offsets. */
1.89 + CATCH_EXCEPTION_RANGE /* Exception's range is controlled by a
1.90 + * catch command. Errors in the range cause
1.91 + * a jump to a catch PC offset. */
1.92 +} ExceptionRangeType;
1.93 +
1.94 +typedef struct ExceptionRange {
1.95 + ExceptionRangeType type; /* The kind of ExceptionRange. */
1.96 + int nestingLevel; /* Static depth of the exception range.
1.97 + * Used to find the most deeply-nested
1.98 + * range surrounding a PC at runtime. */
1.99 + int codeOffset; /* Offset of the first instruction byte of
1.100 + * the code range. */
1.101 + int numCodeBytes; /* Number of bytes in the code range. */
1.102 + int breakOffset; /* If LOOP_EXCEPTION_RANGE, the target PC
1.103 + * offset for a break command in the range. */
1.104 + int continueOffset; /* If LOOP_EXCEPTION_RANGE and not -1, the
1.105 + * target PC offset for a continue command in
1.106 + * the code range. Otherwise, ignore this range
1.107 + * when processing a continue command. */
1.108 + int catchOffset; /* If a CATCH_EXCEPTION_RANGE, the target PC
1.109 + * offset for any "exception" in range. */
1.110 +} ExceptionRange;
1.111 +
1.112 +/*
1.113 + * Structure used to map between instruction pc and source locations. It
1.114 + * defines for each compiled Tcl command its code's starting offset and
1.115 + * its source's starting offset and length. Note that the code offset
1.116 + * increases monotonically: that is, the table is sorted in code offset
1.117 + * order. The source offset is not monotonic.
1.118 + */
1.119 +
1.120 +typedef struct CmdLocation {
1.121 + int codeOffset; /* Offset of first byte of command code. */
1.122 + int numCodeBytes; /* Number of bytes for command's code. */
1.123 + int srcOffset; /* Offset of first char of the command. */
1.124 + int numSrcBytes; /* Number of command source chars. */
1.125 +} CmdLocation;
1.126 +
1.127 +#ifdef TCL_TIP280
1.128 +/*
1.129 + * TIP #280
1.130 + * Structure to record additional location information for byte code.
1.131 + * This information is internal and not saved. I.e. tbcload'ed code
1.132 + * will not have this information. It records the lines for all words
1.133 + * of all commands found in the byte code. The association with a
1.134 + * ByteCode structure BC is done through the 'lineBCPtr' HashTable in
1.135 + * Interp, keyed by the address of BC. Also recorded is information
1.136 + * coming from the context, i.e. type of the frame and associated
1.137 + * information, like the path of a sourced file.
1.138 + */
1.139 +
1.140 +typedef struct ECL {
1.141 + int srcOffset; /* cmd location to find the entry */
1.142 + int nline;
1.143 + int* line; /* line information for all words in the command */
1.144 +} ECL;
1.145 +typedef struct ExtCmdLoc {
1.146 + int type; /* Context type */
1.147 + Tcl_Obj* path; /* Path of the sourced file the command is in */
1.148 + ECL* loc; /* Command word locations (lines) */
1.149 + int nloc; /* Number of allocated entries in 'loc' */
1.150 + int nuloc; /* Number of used entries in 'loc' */
1.151 +} ExtCmdLoc;
1.152 +#endif
1.153 +
1.154 +/*
1.155 + * CompileProcs need the ability to record information during compilation
1.156 + * that can be used by bytecode instructions during execution. The AuxData
1.157 + * structure provides this "auxiliary data" mechanism. An arbitrary number
1.158 + * of these structures can be stored in the ByteCode record (during
1.159 + * compilation they are stored in a CompileEnv structure). Each AuxData
1.160 + * record holds one word of client-specified data (often a pointer) and is
1.161 + * given an index that instructions can later use to look up the structure
1.162 + * and its data.
1.163 + *
1.164 + * The following definitions declare the types of procedures that are called
1.165 + * to duplicate or free this auxiliary data when the containing ByteCode
1.166 + * objects are duplicated and freed. Pointers to these procedures are kept
1.167 + * in the AuxData structure.
1.168 + */
1.169 +
1.170 +typedef ClientData (AuxDataDupProc) _ANSI_ARGS_((ClientData clientData));
1.171 +typedef void (AuxDataFreeProc) _ANSI_ARGS_((ClientData clientData));
1.172 +
1.173 +/*
1.174 + * We define a separate AuxDataType struct to hold type-related information
1.175 + * for the AuxData structure. This separation makes it possible for clients
1.176 + * outside of the TCL core to manipulate (in a limited fashion!) AuxData;
1.177 + * for example, it makes it possible to pickle and unpickle AuxData structs.
1.178 + */
1.179 +
1.180 +typedef struct AuxDataType {
1.181 + char *name; /* the name of the type. Types can be
1.182 + * registered and found by name */
1.183 + AuxDataDupProc *dupProc; /* Callback procedure to invoke when the
1.184 + * aux data is duplicated (e.g., when the
1.185 + * ByteCode structure containing the aux
1.186 + * data is duplicated). NULL means just
1.187 + * copy the source clientData bits; no
1.188 + * proc need be called. */
1.189 + AuxDataFreeProc *freeProc; /* Callback procedure to invoke when the
1.190 + * aux data is freed. NULL means no
1.191 + * proc need be called. */
1.192 +} AuxDataType;
1.193 +
1.194 +/*
1.195 + * The definition of the AuxData structure that holds information created
1.196 + * during compilation by CompileProcs and used by instructions during
1.197 + * execution.
1.198 + */
1.199 +
1.200 +typedef struct AuxData {
1.201 + AuxDataType *type; /* pointer to the AuxData type associated with
1.202 + * this ClientData. */
1.203 + ClientData clientData; /* The compilation data itself. */
1.204 +} AuxData;
1.205 +
1.206 +/*
1.207 + * Structure defining the compilation environment. After compilation, fields
1.208 + * describing bytecode instructions are copied out into the more compact
1.209 + * ByteCode structure defined below.
1.210 + */
1.211 +
1.212 +#define COMPILEENV_INIT_CODE_BYTES 250
1.213 +#define COMPILEENV_INIT_NUM_OBJECTS 60
1.214 +#define COMPILEENV_INIT_EXCEPT_RANGES 5
1.215 +#define COMPILEENV_INIT_CMD_MAP_SIZE 40
1.216 +#define COMPILEENV_INIT_AUX_DATA_SIZE 5
1.217 +
1.218 +typedef struct CompileEnv {
1.219 + Interp *iPtr; /* Interpreter containing the code being
1.220 + * compiled. Commands and their compile
1.221 + * procs are specific to an interpreter so
1.222 + * the code emitted will depend on the
1.223 + * interpreter. */
1.224 + char *source; /* The source string being compiled by
1.225 + * SetByteCodeFromAny. This pointer is not
1.226 + * owned by the CompileEnv and must not be
1.227 + * freed or changed by it. */
1.228 + int numSrcBytes; /* Number of bytes in source. */
1.229 + Proc *procPtr; /* If a procedure is being compiled, a
1.230 + * pointer to its Proc structure; otherwise
1.231 + * NULL. Used to compile local variables.
1.232 + * Set from information provided by
1.233 + * ObjInterpProc in tclProc.c. */
1.234 + int numCommands; /* Number of commands compiled. */
1.235 + int exceptDepth; /* Current exception range nesting level;
1.236 + * -1 if not in any range currently. */
1.237 + int maxExceptDepth; /* Max nesting level of exception ranges;
1.238 + * -1 if no ranges have been compiled. */
1.239 + int maxStackDepth; /* Maximum number of stack elements needed
1.240 + * to execute the code. Set by compilation
1.241 + * procedures before returning. */
1.242 + int currStackDepth; /* Current stack depth. */
1.243 + LiteralTable localLitTable; /* Contains LiteralEntry's describing
1.244 + * all Tcl objects referenced by this
1.245 + * compiled code. Indexed by the string
1.246 + * representations of the literals. Used to
1.247 + * avoid creating duplicate objects. */
1.248 + unsigned char *codeStart; /* Points to the first byte of the code. */
1.249 + unsigned char *codeNext; /* Points to next code array byte to use. */
1.250 + unsigned char *codeEnd; /* Points just after the last allocated
1.251 + * code array byte. */
1.252 + int mallocedCodeArray; /* Set 1 if code array was expanded
1.253 + * and codeStart points into the heap.*/
1.254 + LiteralEntry *literalArrayPtr;
1.255 + /* Points to start of LiteralEntry array. */
1.256 + int literalArrayNext; /* Index of next free object array entry. */
1.257 + int literalArrayEnd; /* Index just after last obj array entry. */
1.258 + int mallocedLiteralArray; /* 1 if object array was expanded and
1.259 + * objArray points into the heap, else 0. */
1.260 + ExceptionRange *exceptArrayPtr;
1.261 + /* Points to start of the ExceptionRange
1.262 + * array. */
1.263 + int exceptArrayNext; /* Next free ExceptionRange array index.
1.264 + * exceptArrayNext is the number of ranges
1.265 + * and (exceptArrayNext-1) is the index of
1.266 + * the current range's array entry. */
1.267 + int exceptArrayEnd; /* Index after the last ExceptionRange
1.268 + * array entry. */
1.269 + int mallocedExceptArray; /* 1 if ExceptionRange array was expanded
1.270 + * and exceptArrayPtr points in heap,
1.271 + * else 0. */
1.272 + CmdLocation *cmdMapPtr; /* Points to start of CmdLocation array.
1.273 + * numCommands is the index of the next
1.274 + * entry to use; (numCommands-1) is the
1.275 + * entry index for the last command. */
1.276 + int cmdMapEnd; /* Index after last CmdLocation entry. */
1.277 + int mallocedCmdMap; /* 1 if command map array was expanded and
1.278 + * cmdMapPtr points in the heap, else 0. */
1.279 + AuxData *auxDataArrayPtr; /* Points to auxiliary data array start. */
1.280 + int auxDataArrayNext; /* Next free compile aux data array index.
1.281 + * auxDataArrayNext is the number of aux
1.282 + * data items and (auxDataArrayNext-1) is
1.283 + * index of current aux data array entry. */
1.284 + int auxDataArrayEnd; /* Index after last aux data array entry. */
1.285 + int mallocedAuxDataArray; /* 1 if aux data array was expanded and
1.286 + * auxDataArrayPtr points in heap else 0. */
1.287 + unsigned char staticCodeSpace[COMPILEENV_INIT_CODE_BYTES];
1.288 + /* Initial storage for code. */
1.289 + LiteralEntry staticLiteralSpace[COMPILEENV_INIT_NUM_OBJECTS];
1.290 + /* Initial storage of LiteralEntry array. */
1.291 + ExceptionRange staticExceptArraySpace[COMPILEENV_INIT_EXCEPT_RANGES];
1.292 + /* Initial ExceptionRange array storage. */
1.293 + CmdLocation staticCmdMapSpace[COMPILEENV_INIT_CMD_MAP_SIZE];
1.294 + /* Initial storage for cmd location map. */
1.295 + AuxData staticAuxDataArraySpace[COMPILEENV_INIT_AUX_DATA_SIZE];
1.296 + /* Initial storage for aux data array. */
1.297 +#ifdef TCL_TIP280
1.298 + /* TIP #280 */
1.299 + ExtCmdLoc* extCmdMapPtr; /* Extended command location information
1.300 + * for 'info frame'. */
1.301 + int line; /* First line of the script, based on the
1.302 + * invoking context, then the line of the
1.303 + * command currently compiled. */
1.304 +#endif
1.305 +} CompileEnv;
1.306 +
1.307 +/*
1.308 + * The structure defining the bytecode instructions resulting from compiling
1.309 + * a Tcl script. Note that this structure is variable length: a single heap
1.310 + * object is allocated to hold the ByteCode structure immediately followed
1.311 + * by the code bytes, the literal object array, the ExceptionRange array,
1.312 + * the CmdLocation map, and the compilation AuxData array.
1.313 + */
1.314 +
1.315 +/*
1.316 + * A PRECOMPILED bytecode struct is one that was generated from a compiled
1.317 + * image rather than implicitly compiled from source
1.318 + */
1.319 +#define TCL_BYTECODE_PRECOMPILED 0x0001
1.320 +
1.321 +typedef struct ByteCode {
1.322 + TclHandle interpHandle; /* Handle for interpreter containing the
1.323 + * compiled code. Commands and their compile
1.324 + * procs are specific to an interpreter so the
1.325 + * code emitted will depend on the
1.326 + * interpreter. */
1.327 + int compileEpoch; /* Value of iPtr->compileEpoch when this
1.328 + * ByteCode was compiled. Used to invalidate
1.329 + * code when, e.g., commands with compile
1.330 + * procs are redefined. */
1.331 + Namespace *nsPtr; /* Namespace context in which this code
1.332 + * was compiled. If the code is executed
1.333 + * if a different namespace, it must be
1.334 + * recompiled. */
1.335 + int nsEpoch; /* Value of nsPtr->resolverEpoch when this
1.336 + * ByteCode was compiled. Used to invalidate
1.337 + * code when new namespace resolution rules
1.338 + * are put into effect. */
1.339 + int refCount; /* Reference count: set 1 when created
1.340 + * plus 1 for each execution of the code
1.341 + * currently active. This structure can be
1.342 + * freed when refCount becomes zero. */
1.343 + unsigned int flags; /* flags describing state for the codebyte.
1.344 + * this variable holds ORed values from the
1.345 + * TCL_BYTECODE_ masks defined above */
1.346 + char *source; /* The source string from which this
1.347 + * ByteCode was compiled. Note that this
1.348 + * pointer is not owned by the ByteCode and
1.349 + * must not be freed or modified by it. */
1.350 + Proc *procPtr; /* If the ByteCode was compiled from a
1.351 + * procedure body, this is a pointer to its
1.352 + * Proc structure; otherwise NULL. This
1.353 + * pointer is also not owned by the ByteCode
1.354 + * and must not be freed by it. */
1.355 + size_t structureSize; /* Number of bytes in the ByteCode structure
1.356 + * itself. Does not include heap space for
1.357 + * literal Tcl objects or storage referenced
1.358 + * by AuxData entries. */
1.359 + int numCommands; /* Number of commands compiled. */
1.360 + int numSrcBytes; /* Number of source bytes compiled. */
1.361 + int numCodeBytes; /* Number of code bytes. */
1.362 + int numLitObjects; /* Number of objects in literal array. */
1.363 + int numExceptRanges; /* Number of ExceptionRange array elems. */
1.364 + int numAuxDataItems; /* Number of AuxData items. */
1.365 + int numCmdLocBytes; /* Number of bytes needed for encoded
1.366 + * command location information. */
1.367 + int maxExceptDepth; /* Maximum nesting level of ExceptionRanges;
1.368 + * -1 if no ranges were compiled. */
1.369 + int maxStackDepth; /* Maximum number of stack elements needed
1.370 + * to execute the code. */
1.371 + unsigned char *codeStart; /* Points to the first byte of the code.
1.372 + * This is just after the final ByteCode
1.373 + * member cmdMapPtr. */
1.374 + Tcl_Obj **objArrayPtr; /* Points to the start of the literal
1.375 + * object array. This is just after the
1.376 + * last code byte. */
1.377 + ExceptionRange *exceptArrayPtr;
1.378 + /* Points to the start of the ExceptionRange
1.379 + * array. This is just after the last
1.380 + * object in the object array. */
1.381 + AuxData *auxDataArrayPtr; /* Points to the start of the auxiliary data
1.382 + * array. This is just after the last entry
1.383 + * in the ExceptionRange array. */
1.384 + unsigned char *codeDeltaStart;
1.385 + /* Points to the first of a sequence of
1.386 + * bytes that encode the change in the
1.387 + * starting offset of each command's code.
1.388 + * If -127<=delta<=127, it is encoded as 1
1.389 + * byte, otherwise 0xFF (128) appears and
1.390 + * the delta is encoded by the next 4 bytes.
1.391 + * Code deltas are always positive. This
1.392 + * sequence is just after the last entry in
1.393 + * the AuxData array. */
1.394 + unsigned char *codeLengthStart;
1.395 + /* Points to the first of a sequence of
1.396 + * bytes that encode the length of each
1.397 + * command's code. The encoding is the same
1.398 + * as for code deltas. Code lengths are
1.399 + * always positive. This sequence is just
1.400 + * after the last entry in the code delta
1.401 + * sequence. */
1.402 + unsigned char *srcDeltaStart;
1.403 + /* Points to the first of a sequence of
1.404 + * bytes that encode the change in the
1.405 + * starting offset of each command's source.
1.406 + * The encoding is the same as for code
1.407 + * deltas. Source deltas can be negative.
1.408 + * This sequence is just after the last byte
1.409 + * in the code length sequence. */
1.410 + unsigned char *srcLengthStart;
1.411 + /* Points to the first of a sequence of
1.412 + * bytes that encode the length of each
1.413 + * command's source. The encoding is the
1.414 + * same as for code deltas. Source lengths
1.415 + * are always positive. This sequence is
1.416 + * just after the last byte in the source
1.417 + * delta sequence. */
1.418 +#ifdef TCL_COMPILE_STATS
1.419 + Tcl_Time createTime; /* Absolute time when the ByteCode was
1.420 + * created. */
1.421 +#endif /* TCL_COMPILE_STATS */
1.422 +} ByteCode;
1.423 +
1.424 +/*
1.425 + * Opcodes for the Tcl bytecode instructions. These must correspond to
1.426 + * the entries in the table of instruction descriptions,
1.427 + * tclInstructionTable, in tclCompile.c. Also, the order and number of
1.428 + * the expression opcodes (e.g., INST_LOR) must match the entries in
1.429 + * the array operatorStrings in tclExecute.c.
1.430 + */
1.431 +
1.432 +/* Opcodes 0 to 9 */
1.433 +#define INST_DONE 0
1.434 +#define INST_PUSH1 1
1.435 +#define INST_PUSH4 2
1.436 +#define INST_POP 3
1.437 +#define INST_DUP 4
1.438 +#define INST_CONCAT1 5
1.439 +#define INST_INVOKE_STK1 6
1.440 +#define INST_INVOKE_STK4 7
1.441 +#define INST_EVAL_STK 8
1.442 +#define INST_EXPR_STK 9
1.443 +
1.444 +/* Opcodes 10 to 23 */
1.445 +#define INST_LOAD_SCALAR1 10
1.446 +#define INST_LOAD_SCALAR4 11
1.447 +#define INST_LOAD_SCALAR_STK 12
1.448 +#define INST_LOAD_ARRAY1 13
1.449 +#define INST_LOAD_ARRAY4 14
1.450 +#define INST_LOAD_ARRAY_STK 15
1.451 +#define INST_LOAD_STK 16
1.452 +#define INST_STORE_SCALAR1 17
1.453 +#define INST_STORE_SCALAR4 18
1.454 +#define INST_STORE_SCALAR_STK 19
1.455 +#define INST_STORE_ARRAY1 20
1.456 +#define INST_STORE_ARRAY4 21
1.457 +#define INST_STORE_ARRAY_STK 22
1.458 +#define INST_STORE_STK 23
1.459 +
1.460 +/* Opcodes 24 to 33 */
1.461 +#define INST_INCR_SCALAR1 24
1.462 +#define INST_INCR_SCALAR_STK 25
1.463 +#define INST_INCR_ARRAY1 26
1.464 +#define INST_INCR_ARRAY_STK 27
1.465 +#define INST_INCR_STK 28
1.466 +#define INST_INCR_SCALAR1_IMM 29
1.467 +#define INST_INCR_SCALAR_STK_IMM 30
1.468 +#define INST_INCR_ARRAY1_IMM 31
1.469 +#define INST_INCR_ARRAY_STK_IMM 32
1.470 +#define INST_INCR_STK_IMM 33
1.471 +
1.472 +/* Opcodes 34 to 39 */
1.473 +#define INST_JUMP1 34
1.474 +#define INST_JUMP4 35
1.475 +#define INST_JUMP_TRUE1 36
1.476 +#define INST_JUMP_TRUE4 37
1.477 +#define INST_JUMP_FALSE1 38
1.478 +#define INST_JUMP_FALSE4 39
1.479 +
1.480 +/* Opcodes 40 to 64 */
1.481 +#define INST_LOR 40
1.482 +#define INST_LAND 41
1.483 +#define INST_BITOR 42
1.484 +#define INST_BITXOR 43
1.485 +#define INST_BITAND 44
1.486 +#define INST_EQ 45
1.487 +#define INST_NEQ 46
1.488 +#define INST_LT 47
1.489 +#define INST_GT 48
1.490 +#define INST_LE 49
1.491 +#define INST_GE 50
1.492 +#define INST_LSHIFT 51
1.493 +#define INST_RSHIFT 52
1.494 +#define INST_ADD 53
1.495 +#define INST_SUB 54
1.496 +#define INST_MULT 55
1.497 +#define INST_DIV 56
1.498 +#define INST_MOD 57
1.499 +#define INST_UPLUS 58
1.500 +#define INST_UMINUS 59
1.501 +#define INST_BITNOT 60
1.502 +#define INST_LNOT 61
1.503 +#define INST_CALL_BUILTIN_FUNC1 62
1.504 +#define INST_CALL_FUNC1 63
1.505 +#define INST_TRY_CVT_TO_NUMERIC 64
1.506 +
1.507 +/* Opcodes 65 to 66 */
1.508 +#define INST_BREAK 65
1.509 +#define INST_CONTINUE 66
1.510 +
1.511 +/* Opcodes 67 to 68 */
1.512 +#define INST_FOREACH_START4 67
1.513 +#define INST_FOREACH_STEP4 68
1.514 +
1.515 +/* Opcodes 69 to 72 */
1.516 +#define INST_BEGIN_CATCH4 69
1.517 +#define INST_END_CATCH 70
1.518 +#define INST_PUSH_RESULT 71
1.519 +#define INST_PUSH_RETURN_CODE 72
1.520 +
1.521 +/* Opcodes 73 to 78 */
1.522 +#define INST_STR_EQ 73
1.523 +#define INST_STR_NEQ 74
1.524 +#define INST_STR_CMP 75
1.525 +#define INST_STR_LEN 76
1.526 +#define INST_STR_INDEX 77
1.527 +#define INST_STR_MATCH 78
1.528 +
1.529 +/* Opcodes 78 to 81 */
1.530 +#define INST_LIST 79
1.531 +#define INST_LIST_INDEX 80
1.532 +#define INST_LIST_LENGTH 81
1.533 +
1.534 +/* Opcodes 82 to 87 */
1.535 +#define INST_APPEND_SCALAR1 82
1.536 +#define INST_APPEND_SCALAR4 83
1.537 +#define INST_APPEND_ARRAY1 84
1.538 +#define INST_APPEND_ARRAY4 85
1.539 +#define INST_APPEND_ARRAY_STK 86
1.540 +#define INST_APPEND_STK 87
1.541 +
1.542 +/* Opcodes 88 to 93 */
1.543 +#define INST_LAPPEND_SCALAR1 88
1.544 +#define INST_LAPPEND_SCALAR4 89
1.545 +#define INST_LAPPEND_ARRAY1 90
1.546 +#define INST_LAPPEND_ARRAY4 91
1.547 +#define INST_LAPPEND_ARRAY_STK 92
1.548 +#define INST_LAPPEND_STK 93
1.549 +
1.550 +/* TIP #22 - LINDEX operator with flat arg list */
1.551 +
1.552 +#define INST_LIST_INDEX_MULTI 94
1.553 +
1.554 +/*
1.555 + * TIP #33 - 'lset' command. Code gen also required a Forth-like
1.556 + * OVER operation.
1.557 + */
1.558 +
1.559 +#define INST_OVER 95
1.560 +#define INST_LSET_LIST 96
1.561 +#define INST_LSET_FLAT 97
1.562 +
1.563 +/* The last opcode */
1.564 +#define LAST_INST_OPCODE 97
1.565 +
1.566 +/*
1.567 + * Table describing the Tcl bytecode instructions: their name (for
1.568 + * displaying code), total number of code bytes required (including
1.569 + * operand bytes), and a description of the type of each operand.
1.570 + * These operand types include signed and unsigned integers of length
1.571 + * one and four bytes. The unsigned integers are used for indexes or
1.572 + * for, e.g., the count of objects to push in a "push" instruction.
1.573 + */
1.574 +
1.575 +#define MAX_INSTRUCTION_OPERANDS 2
1.576 +
1.577 +typedef enum InstOperandType {
1.578 + OPERAND_NONE,
1.579 + OPERAND_INT1, /* One byte signed integer. */
1.580 + OPERAND_INT4, /* Four byte signed integer. */
1.581 + OPERAND_UINT1, /* One byte unsigned integer. */
1.582 + OPERAND_UINT4 /* Four byte unsigned integer. */
1.583 +} InstOperandType;
1.584 +
1.585 +typedef struct InstructionDesc {
1.586 + char *name; /* Name of instruction. */
1.587 + int numBytes; /* Total number of bytes for instruction. */
1.588 + int stackEffect; /* The worst-case balance stack effect of the
1.589 + * instruction, used for stack requirements
1.590 + * computations. The value INT_MIN signals
1.591 + * that the instruction's worst case effect
1.592 + * is (1-opnd1).
1.593 + */
1.594 + int numOperands; /* Number of operands. */
1.595 + InstOperandType opTypes[MAX_INSTRUCTION_OPERANDS];
1.596 + /* The type of each operand. */
1.597 +} InstructionDesc;
1.598 +
1.599 +extern InstructionDesc tclInstructionTable[];
1.600 +
1.601 +/*
1.602 + * Definitions of the values of the INST_CALL_BUILTIN_FUNC instruction's
1.603 + * operand byte. Each value denotes a builtin Tcl math function. These
1.604 + * values must correspond to the entries in the tclBuiltinFuncTable array
1.605 + * below and to the values stored in the tclInt.h MathFunc structure's
1.606 + * builtinFuncIndex field.
1.607 + */
1.608 +
1.609 +#define BUILTIN_FUNC_ACOS 0
1.610 +#define BUILTIN_FUNC_ASIN 1
1.611 +#define BUILTIN_FUNC_ATAN 2
1.612 +#define BUILTIN_FUNC_ATAN2 3
1.613 +#define BUILTIN_FUNC_CEIL 4
1.614 +#define BUILTIN_FUNC_COS 5
1.615 +#define BUILTIN_FUNC_COSH 6
1.616 +#define BUILTIN_FUNC_EXP 7
1.617 +#define BUILTIN_FUNC_FLOOR 8
1.618 +#define BUILTIN_FUNC_FMOD 9
1.619 +#define BUILTIN_FUNC_HYPOT 10
1.620 +#define BUILTIN_FUNC_LOG 11
1.621 +#define BUILTIN_FUNC_LOG10 12
1.622 +#define BUILTIN_FUNC_POW 13
1.623 +#define BUILTIN_FUNC_SIN 14
1.624 +#define BUILTIN_FUNC_SINH 15
1.625 +#define BUILTIN_FUNC_SQRT 16
1.626 +#define BUILTIN_FUNC_TAN 17
1.627 +#define BUILTIN_FUNC_TANH 18
1.628 +#define BUILTIN_FUNC_ABS 19
1.629 +#define BUILTIN_FUNC_DOUBLE 20
1.630 +#define BUILTIN_FUNC_INT 21
1.631 +#define BUILTIN_FUNC_RAND 22
1.632 +#define BUILTIN_FUNC_ROUND 23
1.633 +#define BUILTIN_FUNC_SRAND 24
1.634 +#define BUILTIN_FUNC_WIDE 25
1.635 +
1.636 +#define LAST_BUILTIN_FUNC 25
1.637 +
1.638 +/*
1.639 + * Table describing the built-in math functions. Entries in this table are
1.640 + * indexed by the values of the INST_CALL_BUILTIN_FUNC instruction's
1.641 + * operand byte.
1.642 + */
1.643 +
1.644 +typedef int (CallBuiltinFuncProc) _ANSI_ARGS_((Tcl_Interp *interp,
1.645 + ExecEnv *eePtr, ClientData clientData));
1.646 +
1.647 +typedef struct {
1.648 + char *name; /* Name of function. */
1.649 + int numArgs; /* Number of arguments for function. */
1.650 + Tcl_ValueType argTypes[MAX_MATH_ARGS];
1.651 + /* Acceptable types for each argument. */
1.652 + CallBuiltinFuncProc *proc; /* Procedure implementing this function. */
1.653 + ClientData clientData; /* Additional argument to pass to the
1.654 + * function when invoking it. */
1.655 +} BuiltinFunc;
1.656 +
1.657 +extern BuiltinFunc tclBuiltinFuncTable[];
1.658 +
1.659 +/*
1.660 + * Compilation of some Tcl constructs such as if commands and the logical or
1.661 + * (||) and logical and (&&) operators in expressions requires the
1.662 + * generation of forward jumps. Since the PC target of these jumps isn't
1.663 + * known when the jumps are emitted, we record the offset of each jump in an
1.664 + * array of JumpFixup structures. There is one array for each sequence of
1.665 + * jumps to one target PC. When we learn the target PC, we update the jumps
1.666 + * with the correct distance. Also, if the distance is too great (> 127
1.667 + * bytes), we replace the single-byte jump with a four byte jump
1.668 + * instruction, move the instructions after the jump down, and update the
1.669 + * code offsets for any commands between the jump and the target.
1.670 + */
1.671 +
1.672 +typedef enum {
1.673 + TCL_UNCONDITIONAL_JUMP,
1.674 + TCL_TRUE_JUMP,
1.675 + TCL_FALSE_JUMP
1.676 +} TclJumpType;
1.677 +
1.678 +typedef struct JumpFixup {
1.679 + TclJumpType jumpType; /* Indicates the kind of jump. */
1.680 + int codeOffset; /* Offset of the first byte of the one-byte
1.681 + * forward jump's code. */
1.682 + int cmdIndex; /* Index of the first command after the one
1.683 + * for which the jump was emitted. Used to
1.684 + * update the code offsets for subsequent
1.685 + * commands if the two-byte jump at jumpPc
1.686 + * must be replaced with a five-byte one. */
1.687 + int exceptIndex; /* Index of the first range entry in the
1.688 + * ExceptionRange array after the current
1.689 + * one. This field is used to adjust the
1.690 + * code offsets in subsequent ExceptionRange
1.691 + * records when a jump is grown from 2 bytes
1.692 + * to 5 bytes. */
1.693 +} JumpFixup;
1.694 +
1.695 +#define JUMPFIXUP_INIT_ENTRIES 10
1.696 +
1.697 +typedef struct JumpFixupArray {
1.698 + JumpFixup *fixup; /* Points to start of jump fixup array. */
1.699 + int next; /* Index of next free array entry. */
1.700 + int end; /* Index of last usable entry in array. */
1.701 + int mallocedArray; /* 1 if array was expanded and fixups points
1.702 + * into the heap, else 0. */
1.703 + JumpFixup staticFixupSpace[JUMPFIXUP_INIT_ENTRIES];
1.704 + /* Initial storage for jump fixup array. */
1.705 +} JumpFixupArray;
1.706 +
1.707 +/*
1.708 + * The structure describing one variable list of a foreach command. Note
1.709 + * that only foreach commands inside procedure bodies are compiled inline so
1.710 + * a ForeachVarList structure always describes local variables. Furthermore,
1.711 + * only scalar variables are supported for inline-compiled foreach loops.
1.712 + */
1.713 +
1.714 +typedef struct ForeachVarList {
1.715 + int numVars; /* The number of variables in the list. */
1.716 + int varIndexes[1]; /* An array of the indexes ("slot numbers")
1.717 + * for each variable in the procedure's
1.718 + * array of local variables. Only scalar
1.719 + * variables are supported. The actual
1.720 + * size of this field will be large enough
1.721 + * to numVars indexes. THIS MUST BE THE
1.722 + * LAST FIELD IN THE STRUCTURE! */
1.723 +} ForeachVarList;
1.724 +
1.725 +/*
1.726 + * Structure used to hold information about a foreach command that is needed
1.727 + * during program execution. These structures are stored in CompileEnv and
1.728 + * ByteCode structures as auxiliary data.
1.729 + */
1.730 +
1.731 +typedef struct ForeachInfo {
1.732 + int numLists; /* The number of both the variable and value
1.733 + * lists of the foreach command. */
1.734 + int firstValueTemp; /* Index of the first temp var in a proc
1.735 + * frame used to point to a value list. */
1.736 + int loopCtTemp; /* Index of temp var in a proc frame
1.737 + * holding the loop's iteration count. Used
1.738 + * to determine next value list element to
1.739 + * assign each loop var. */
1.740 + ForeachVarList *varLists[1];/* An array of pointers to ForeachVarList
1.741 + * structures describing each var list. The
1.742 + * actual size of this field will be large
1.743 + * enough to numVars indexes. THIS MUST BE
1.744 + * THE LAST FIELD IN THE STRUCTURE! */
1.745 +} ForeachInfo;
1.746 +
1.747 +extern AuxDataType tclForeachInfoType;
1.748 +
1.749 +
1.750 +/*
1.751 + *----------------------------------------------------------------
1.752 + * Procedures exported by tclBasic.c to be used within the engine.
1.753 + *----------------------------------------------------------------
1.754 + */
1.755 +
1.756 +EXTERN int TclEvalObjvInternal _ANSI_ARGS_((Tcl_Interp *interp, int objc,
1.757 + Tcl_Obj *CONST objv[], CONST char *command, int length,
1.758 + int flags));
1.759 +EXTERN int TclInterpReady _ANSI_ARGS_((Tcl_Interp *interp));
1.760 +
1.761 +
1.762 +/*
1.763 + *----------------------------------------------------------------
1.764 + * Procedures exported by the engine to be used by tclBasic.c
1.765 + *----------------------------------------------------------------
1.766 + */
1.767 +
1.768 +#ifndef TCL_TIP280
1.769 +EXTERN int TclCompEvalObj _ANSI_ARGS_((Tcl_Interp *interp,
1.770 + Tcl_Obj *objPtr));
1.771 +#else
1.772 +EXTERN int TclCompEvalObj _ANSI_ARGS_((Tcl_Interp *interp,
1.773 + Tcl_Obj *objPtr, CONST CmdFrame* invoker,
1.774 + int word));
1.775 +#endif
1.776 +
1.777 +/*
1.778 + *----------------------------------------------------------------
1.779 + * Procedures shared among Tcl bytecode compilation and execution
1.780 + * modules but not used outside:
1.781 + *----------------------------------------------------------------
1.782 + */
1.783 +
1.784 +EXTERN void TclCleanupByteCode _ANSI_ARGS_((ByteCode *codePtr));
1.785 +EXTERN int TclCompileCmdWord _ANSI_ARGS_((Tcl_Interp *interp,
1.786 + Tcl_Token *tokenPtr, int count,
1.787 + CompileEnv *envPtr));
1.788 +EXTERN int TclCompileExpr _ANSI_ARGS_((Tcl_Interp *interp,
1.789 + CONST char *script, int numBytes,
1.790 + CompileEnv *envPtr));
1.791 +EXTERN int TclCompileExprWords _ANSI_ARGS_((Tcl_Interp *interp,
1.792 + Tcl_Token *tokenPtr, int numWords,
1.793 + CompileEnv *envPtr));
1.794 +EXTERN int TclCompileScript _ANSI_ARGS_((Tcl_Interp *interp,
1.795 + CONST char *script, int numBytes, int nested,
1.796 + CompileEnv *envPtr));
1.797 +EXTERN int TclCompileTokens _ANSI_ARGS_((Tcl_Interp *interp,
1.798 + Tcl_Token *tokenPtr, int count,
1.799 + CompileEnv *envPtr));
1.800 +EXTERN int TclCreateAuxData _ANSI_ARGS_((ClientData clientData,
1.801 + AuxDataType *typePtr, CompileEnv *envPtr));
1.802 +EXTERN int TclCreateExceptRange _ANSI_ARGS_((
1.803 + ExceptionRangeType type, CompileEnv *envPtr));
1.804 +EXTERN ExecEnv * TclCreateExecEnv _ANSI_ARGS_((Tcl_Interp *interp));
1.805 +EXTERN void TclDeleteExecEnv _ANSI_ARGS_((ExecEnv *eePtr));
1.806 +EXTERN void TclDeleteLiteralTable _ANSI_ARGS_((
1.807 + Tcl_Interp *interp, LiteralTable *tablePtr));
1.808 +EXTERN void TclEmitForwardJump _ANSI_ARGS_((CompileEnv *envPtr,
1.809 + TclJumpType jumpType, JumpFixup *jumpFixupPtr));
1.810 +EXTERN ExceptionRange * TclGetExceptionRangeForPc _ANSI_ARGS_((
1.811 + unsigned char *pc, int catchOnly,
1.812 + ByteCode* codePtr));
1.813 +EXTERN void TclExpandJumpFixupArray _ANSI_ARGS_((
1.814 + JumpFixupArray *fixupArrayPtr));
1.815 +EXTERN void TclFinalizeAuxDataTypeTable _ANSI_ARGS_((void));
1.816 +EXTERN int TclFindCompiledLocal _ANSI_ARGS_((CONST char *name,
1.817 + int nameChars, int create, int flags,
1.818 + Proc *procPtr));
1.819 +EXTERN LiteralEntry * TclLookupLiteralEntry _ANSI_ARGS_((
1.820 + Tcl_Interp *interp, Tcl_Obj *objPtr));
1.821 +EXTERN int TclFixupForwardJump _ANSI_ARGS_((
1.822 + CompileEnv *envPtr, JumpFixup *jumpFixupPtr,
1.823 + int jumpDist, int distThreshold));
1.824 +EXTERN void TclFreeCompileEnv _ANSI_ARGS_((CompileEnv *envPtr));
1.825 +EXTERN void TclFreeJumpFixupArray _ANSI_ARGS_((
1.826 + JumpFixupArray *fixupArrayPtr));
1.827 +EXTERN void TclInitAuxDataTypeTable _ANSI_ARGS_((void));
1.828 +EXTERN void TclInitByteCodeObj _ANSI_ARGS_((Tcl_Obj *objPtr,
1.829 + CompileEnv *envPtr));
1.830 +EXTERN void TclInitCompilation _ANSI_ARGS_((void));
1.831 +#ifndef TCL_TIP280
1.832 +EXTERN void TclInitCompileEnv _ANSI_ARGS_((Tcl_Interp *interp,
1.833 + CompileEnv *envPtr, char *string,
1.834 + int numBytes));
1.835 +#else
1.836 +EXTERN void TclInitCompileEnv _ANSI_ARGS_((Tcl_Interp *interp,
1.837 + CompileEnv *envPtr, char *string,
1.838 + int numBytes, CONST CmdFrame* invoker, int word));
1.839 +#endif
1.840 +EXTERN void TclInitJumpFixupArray _ANSI_ARGS_((
1.841 + JumpFixupArray *fixupArrayPtr));
1.842 +EXTERN void TclInitLiteralTable _ANSI_ARGS_((
1.843 + LiteralTable *tablePtr));
1.844 +#ifdef TCL_COMPILE_STATS
1.845 +EXTERN char * TclLiteralStats _ANSI_ARGS_((
1.846 + LiteralTable *tablePtr));
1.847 +EXTERN int TclLog2 _ANSI_ARGS_((int value));
1.848 +#endif
1.849 +#ifdef TCL_COMPILE_DEBUG
1.850 +EXTERN void TclPrintByteCodeObj _ANSI_ARGS_((Tcl_Interp *interp,
1.851 + Tcl_Obj *objPtr));
1.852 +#endif
1.853 +EXTERN int TclPrintInstruction _ANSI_ARGS_((ByteCode* codePtr,
1.854 + unsigned char *pc));
1.855 +EXTERN void TclPrintObject _ANSI_ARGS_((FILE *outFile,
1.856 + Tcl_Obj *objPtr, int maxChars));
1.857 +EXTERN void TclPrintSource _ANSI_ARGS_((FILE *outFile,
1.858 + CONST char *string, int maxChars));
1.859 +EXTERN void TclRegisterAuxDataType _ANSI_ARGS_((AuxDataType *typePtr));
1.860 +EXTERN int TclRegisterLiteral _ANSI_ARGS_((CompileEnv *envPtr,
1.861 + char *bytes, int length, int onHeap));
1.862 +EXTERN void TclReleaseLiteral _ANSI_ARGS_((Tcl_Interp *interp,
1.863 + Tcl_Obj *objPtr));
1.864 +EXTERN void TclSetCmdNameObj _ANSI_ARGS_((Tcl_Interp *interp,
1.865 + Tcl_Obj *objPtr, Command *cmdPtr));
1.866 +#ifdef TCL_COMPILE_DEBUG
1.867 +EXTERN void TclVerifyGlobalLiteralTable _ANSI_ARGS_((
1.868 + Interp *iPtr));
1.869 +EXTERN void TclVerifyLocalLiteralTable _ANSI_ARGS_((
1.870 + CompileEnv *envPtr));
1.871 +#endif
1.872 +EXTERN int TclCompileVariableCmd _ANSI_ARGS_((
1.873 + Tcl_Interp *interp, Tcl_Parse *parsePtr, CompileEnv *envPtr));
1.874 +
1.875 +/*
1.876 + *----------------------------------------------------------------
1.877 + * Macros used by Tcl bytecode compilation and execution modules
1.878 + * inside the Tcl core but not used outside.
1.879 + *----------------------------------------------------------------
1.880 + */
1.881 +
1.882 +/*
1.883 + * Form of TclRegisterLiteral with onHeap == 0.
1.884 + * In that case, it is safe to cast away CONSTness, and it
1.885 + * is cleanest to do that here, all in one place.
1.886 + */
1.887 +
1.888 +#define TclRegisterNewLiteral(envPtr, bytes, length) \
1.889 + TclRegisterLiteral(envPtr, (char *)(bytes), length, /*onHeap*/ 0)
1.890 +
1.891 +/*
1.892 + * Macro used to update the stack requirements.
1.893 + * It is called by the macros TclEmitOpCode, TclEmitInst1 and
1.894 + * TclEmitInst4.
1.895 + * Remark that the very last instruction of a bytecode always
1.896 + * reduces the stack level: INST_DONE or INST_POP, so that the
1.897 + * maxStackdepth is always updated.
1.898 + */
1.899 +
1.900 +#define TclUpdateStackReqs(op, i, envPtr) \
1.901 + {\
1.902 + int delta = tclInstructionTable[(op)].stackEffect;\
1.903 + if (delta) {\
1.904 + if (delta < 0) {\
1.905 + if((envPtr)->maxStackDepth < (envPtr)->currStackDepth) {\
1.906 + (envPtr)->maxStackDepth = (envPtr)->currStackDepth;\
1.907 + }\
1.908 + if (delta == INT_MIN) {\
1.909 + delta = 1 - (i);\
1.910 + }\
1.911 + }\
1.912 + (envPtr)->currStackDepth += delta;\
1.913 + }\
1.914 + }
1.915 +
1.916 +/*
1.917 + * Macro to emit an opcode byte into a CompileEnv's code array.
1.918 + * The ANSI C "prototype" for this macro is:
1.919 + *
1.920 + * EXTERN void TclEmitOpcode _ANSI_ARGS_((unsigned char op,
1.921 + * CompileEnv *envPtr));
1.922 + */
1.923 +
1.924 +#define TclEmitOpcode(op, envPtr) \
1.925 + if ((envPtr)->codeNext == (envPtr)->codeEnd) \
1.926 + TclExpandCodeArray(envPtr); \
1.927 + *(envPtr)->codeNext++ = (unsigned char) (op);\
1.928 + TclUpdateStackReqs(op, 0, envPtr)
1.929 +
1.930 +/*
1.931 + * Macro to emit an integer operand.
1.932 + * The ANSI C "prototype" for this macro is:
1.933 + *
1.934 + * EXTERN void TclEmitInt1 _ANSI_ARGS_((int i, CompileEnv *envPtr));
1.935 + */
1.936 +
1.937 +#define TclEmitInt1(i, envPtr) \
1.938 + if ((envPtr)->codeNext == (envPtr)->codeEnd) \
1.939 + TclExpandCodeArray(envPtr); \
1.940 + *(envPtr)->codeNext++ = (unsigned char) ((unsigned int) (i))
1.941 +
1.942 +/*
1.943 + * Macros to emit an instruction with signed or unsigned integer operands.
1.944 + * Four byte integers are stored in "big-endian" order with the high order
1.945 + * byte stored at the lowest address.
1.946 + * The ANSI C "prototypes" for these macros are:
1.947 + *
1.948 + * EXTERN void TclEmitInstInt1 _ANSI_ARGS_((unsigned char op, int i,
1.949 + * CompileEnv *envPtr));
1.950 + * EXTERN void TclEmitInstInt4 _ANSI_ARGS_((unsigned char op, int i,
1.951 + * CompileEnv *envPtr));
1.952 + */
1.953 +
1.954 +
1.955 +#define TclEmitInstInt1(op, i, envPtr) \
1.956 + if (((envPtr)->codeNext + 2) > (envPtr)->codeEnd) { \
1.957 + TclExpandCodeArray(envPtr); \
1.958 + } \
1.959 + *(envPtr)->codeNext++ = (unsigned char) (op); \
1.960 + *(envPtr)->codeNext++ = (unsigned char) ((unsigned int) (i));\
1.961 + TclUpdateStackReqs(op, i, envPtr)
1.962 +
1.963 +#define TclEmitInstInt4(op, i, envPtr) \
1.964 + if (((envPtr)->codeNext + 5) > (envPtr)->codeEnd) { \
1.965 + TclExpandCodeArray(envPtr); \
1.966 + } \
1.967 + *(envPtr)->codeNext++ = (unsigned char) (op); \
1.968 + *(envPtr)->codeNext++ = \
1.969 + (unsigned char) ((unsigned int) (i) >> 24); \
1.970 + *(envPtr)->codeNext++ = \
1.971 + (unsigned char) ((unsigned int) (i) >> 16); \
1.972 + *(envPtr)->codeNext++ = \
1.973 + (unsigned char) ((unsigned int) (i) >> 8); \
1.974 + *(envPtr)->codeNext++ = \
1.975 + (unsigned char) ((unsigned int) (i) );\
1.976 + TclUpdateStackReqs(op, i, envPtr)
1.977 +
1.978 +/*
1.979 + * Macro to push a Tcl object onto the Tcl evaluation stack. It emits the
1.980 + * object's one or four byte array index into the CompileEnv's code
1.981 + * array. These support, respectively, a maximum of 256 (2**8) and 2**32
1.982 + * objects in a CompileEnv. The ANSI C "prototype" for this macro is:
1.983 + *
1.984 + * EXTERN void TclEmitPush _ANSI_ARGS_((int objIndex, CompileEnv *envPtr));
1.985 + */
1.986 +
1.987 +#define TclEmitPush(objIndex, envPtr) \
1.988 + {\
1.989 + register int objIndexCopy = (objIndex);\
1.990 + if (objIndexCopy <= 255) { \
1.991 + TclEmitInstInt1(INST_PUSH1, objIndexCopy, (envPtr)); \
1.992 + } else { \
1.993 + TclEmitInstInt4(INST_PUSH4, objIndexCopy, (envPtr)); \
1.994 + }\
1.995 + }
1.996 +
1.997 +/*
1.998 + * Macros to update a (signed or unsigned) integer starting at a pointer.
1.999 + * The two variants depend on the number of bytes. The ANSI C "prototypes"
1.1000 + * for these macros are:
1.1001 + *
1.1002 + * EXTERN void TclStoreInt1AtPtr _ANSI_ARGS_((int i, unsigned char *p));
1.1003 + * EXTERN void TclStoreInt4AtPtr _ANSI_ARGS_((int i, unsigned char *p));
1.1004 + */
1.1005 +
1.1006 +#define TclStoreInt1AtPtr(i, p) \
1.1007 + *(p) = (unsigned char) ((unsigned int) (i))
1.1008 +
1.1009 +#define TclStoreInt4AtPtr(i, p) \
1.1010 + *(p) = (unsigned char) ((unsigned int) (i) >> 24); \
1.1011 + *(p+1) = (unsigned char) ((unsigned int) (i) >> 16); \
1.1012 + *(p+2) = (unsigned char) ((unsigned int) (i) >> 8); \
1.1013 + *(p+3) = (unsigned char) ((unsigned int) (i) )
1.1014 +
1.1015 +/*
1.1016 + * Macros to update instructions at a particular pc with a new op code
1.1017 + * and a (signed or unsigned) int operand. The ANSI C "prototypes" for
1.1018 + * these macros are:
1.1019 + *
1.1020 + * EXTERN void TclUpdateInstInt1AtPc _ANSI_ARGS_((unsigned char op, int i,
1.1021 + * unsigned char *pc));
1.1022 + * EXTERN void TclUpdateInstInt4AtPc _ANSI_ARGS_((unsigned char op, int i,
1.1023 + * unsigned char *pc));
1.1024 + */
1.1025 +
1.1026 +#define TclUpdateInstInt1AtPc(op, i, pc) \
1.1027 + *(pc) = (unsigned char) (op); \
1.1028 + TclStoreInt1AtPtr((i), ((pc)+1))
1.1029 +
1.1030 +#define TclUpdateInstInt4AtPc(op, i, pc) \
1.1031 + *(pc) = (unsigned char) (op); \
1.1032 + TclStoreInt4AtPtr((i), ((pc)+1))
1.1033 +
1.1034 +/*
1.1035 + * Macros to get a signed integer (GET_INT{1,2}) or an unsigned int
1.1036 + * (GET_UINT{1,2}) from a pointer. There are two variants for each
1.1037 + * return type that depend on the number of bytes fetched.
1.1038 + * The ANSI C "prototypes" for these macros are:
1.1039 + *
1.1040 + * EXTERN int TclGetInt1AtPtr _ANSI_ARGS_((unsigned char *p));
1.1041 + * EXTERN int TclGetInt4AtPtr _ANSI_ARGS_((unsigned char *p));
1.1042 + * EXTERN unsigned int TclGetUInt1AtPtr _ANSI_ARGS_((unsigned char *p));
1.1043 + * EXTERN unsigned int TclGetUInt4AtPtr _ANSI_ARGS_((unsigned char *p));
1.1044 + */
1.1045 +
1.1046 +/*
1.1047 + * The TclGetInt1AtPtr macro is tricky because we want to do sign
1.1048 + * extension on the 1-byte value. Unfortunately the "char" type isn't
1.1049 + * signed on all platforms so sign-extension doesn't always happen
1.1050 + * automatically. Sometimes we can explicitly declare the pointer to be
1.1051 + * signed, but other times we have to explicitly sign-extend the value
1.1052 + * in software.
1.1053 + */
1.1054 +
1.1055 +#ifndef __CHAR_UNSIGNED__
1.1056 +# define TclGetInt1AtPtr(p) ((int) *((char *) p))
1.1057 +#else
1.1058 +# ifdef HAVE_SIGNED_CHAR
1.1059 +# define TclGetInt1AtPtr(p) ((int) *((signed char *) p))
1.1060 +# else
1.1061 +# define TclGetInt1AtPtr(p) (((int) *((char *) p)) \
1.1062 + | ((*(p) & 0200) ? (-256) : 0))
1.1063 +# endif
1.1064 +#endif
1.1065 +
1.1066 +#define TclGetInt4AtPtr(p) (((int) TclGetInt1AtPtr(p) << 24) | \
1.1067 + (*((p)+1) << 16) | \
1.1068 + (*((p)+2) << 8) | \
1.1069 + (*((p)+3)))
1.1070 +
1.1071 +#define TclGetUInt1AtPtr(p) ((unsigned int) *(p))
1.1072 +#define TclGetUInt4AtPtr(p) ((unsigned int) (*(p) << 24) | \
1.1073 + (*((p)+1) << 16) | \
1.1074 + (*((p)+2) << 8) | \
1.1075 + (*((p)+3)))
1.1076 +
1.1077 +/*
1.1078 + * Macros used to compute the minimum and maximum of two integers.
1.1079 + * The ANSI C "prototypes" for these macros are:
1.1080 + *
1.1081 + * EXTERN int TclMin _ANSI_ARGS_((int i, int j));
1.1082 + * EXTERN int TclMax _ANSI_ARGS_((int i, int j));
1.1083 + */
1.1084 +
1.1085 +#define TclMin(i, j) ((((int) i) < ((int) j))? (i) : (j))
1.1086 +#define TclMax(i, j) ((((int) i) > ((int) j))? (i) : (j))
1.1087 +
1.1088 +# undef TCL_STORAGE_CLASS
1.1089 +# define TCL_STORAGE_CLASS DLLIMPORT
1.1090 +
1.1091 +#endif /* _TCLCOMPILATION */