sl@0
|
1 |
/*
|
sl@0
|
2 |
* tclCompile.h --
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* Copyright (c) 1996-1998 Sun Microsystems, Inc.
|
sl@0
|
5 |
* Copyright (c) 1998-2000 by Scriptics Corporation.
|
sl@0
|
6 |
* Copyright (c) 2001 by Kevin B. Kenny. All rights reserved.
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* See the file "license.terms" for information on usage and redistribution
|
sl@0
|
9 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
10 |
*
|
sl@0
|
11 |
* RCS: @(#) $Id: tclCompile.h,v 1.33.2.1 2006/11/28 22:20:00 andreas_kupries Exp $
|
sl@0
|
12 |
*/
|
sl@0
|
13 |
|
sl@0
|
14 |
#ifndef _TCLCOMPILATION
|
sl@0
|
15 |
#define _TCLCOMPILATION 1
|
sl@0
|
16 |
|
sl@0
|
17 |
#ifndef _TCLINT
|
sl@0
|
18 |
#include "tclInt.h"
|
sl@0
|
19 |
#endif /* _TCLINT */
|
sl@0
|
20 |
|
sl@0
|
21 |
#ifdef BUILD_tcl
|
sl@0
|
22 |
# undef TCL_STORAGE_CLASS
|
sl@0
|
23 |
# define TCL_STORAGE_CLASS DLLEXPORT
|
sl@0
|
24 |
#endif
|
sl@0
|
25 |
|
sl@0
|
26 |
/*
|
sl@0
|
27 |
*------------------------------------------------------------------------
|
sl@0
|
28 |
* Variables related to compilation. These are used in tclCompile.c,
|
sl@0
|
29 |
* tclExecute.c, tclBasic.c, and their clients.
|
sl@0
|
30 |
*------------------------------------------------------------------------
|
sl@0
|
31 |
*/
|
sl@0
|
32 |
|
sl@0
|
33 |
#ifdef TCL_COMPILE_DEBUG
|
sl@0
|
34 |
/*
|
sl@0
|
35 |
* Variable that controls whether compilation tracing is enabled and, if so,
|
sl@0
|
36 |
* what level of tracing is desired:
|
sl@0
|
37 |
* 0: no compilation tracing
|
sl@0
|
38 |
* 1: summarize compilation of top level cmds and proc bodies
|
sl@0
|
39 |
* 2: display all instructions of each ByteCode compiled
|
sl@0
|
40 |
* This variable is linked to the Tcl variable "tcl_traceCompile".
|
sl@0
|
41 |
*/
|
sl@0
|
42 |
|
sl@0
|
43 |
extern int tclTraceCompile;
|
sl@0
|
44 |
#endif
|
sl@0
|
45 |
|
sl@0
|
46 |
#ifdef TCL_COMPILE_DEBUG
|
sl@0
|
47 |
/*
|
sl@0
|
48 |
* Variable that controls whether execution tracing is enabled and, if so,
|
sl@0
|
49 |
* what level of tracing is desired:
|
sl@0
|
50 |
* 0: no execution tracing
|
sl@0
|
51 |
* 1: trace invocations of Tcl procs only
|
sl@0
|
52 |
* 2: trace invocations of all (not compiled away) commands
|
sl@0
|
53 |
* 3: display each instruction executed
|
sl@0
|
54 |
* This variable is linked to the Tcl variable "tcl_traceExec".
|
sl@0
|
55 |
*/
|
sl@0
|
56 |
|
sl@0
|
57 |
extern int tclTraceExec;
|
sl@0
|
58 |
#endif
|
sl@0
|
59 |
|
sl@0
|
60 |
/*
|
sl@0
|
61 |
*------------------------------------------------------------------------
|
sl@0
|
62 |
* Data structures related to compilation.
|
sl@0
|
63 |
*------------------------------------------------------------------------
|
sl@0
|
64 |
*/
|
sl@0
|
65 |
|
sl@0
|
66 |
/*
|
sl@0
|
67 |
* The structure used to implement Tcl "exceptions" (exceptional returns):
|
sl@0
|
68 |
* for example, those generated in loops by the break and continue commands,
|
sl@0
|
69 |
* and those generated by scripts and caught by the catch command. This
|
sl@0
|
70 |
* ExceptionRange structure describes a range of code (e.g., a loop body),
|
sl@0
|
71 |
* the kind of exceptions (e.g., a break or continue) that might occur, and
|
sl@0
|
72 |
* the PC offsets to jump to if a matching exception does occur. Exception
|
sl@0
|
73 |
* ranges can nest so this structure includes a nesting level that is used
|
sl@0
|
74 |
* at runtime to find the closest exception range surrounding a PC. For
|
sl@0
|
75 |
* example, when a break command is executed, the ExceptionRange structure
|
sl@0
|
76 |
* for the most deeply nested loop, if any, is found and used. These
|
sl@0
|
77 |
* structures are also generated for the "next" subcommands of for loops
|
sl@0
|
78 |
* since a break there terminates the for command. This means a for command
|
sl@0
|
79 |
* actually generates two LoopInfo structures.
|
sl@0
|
80 |
*/
|
sl@0
|
81 |
|
sl@0
|
82 |
typedef enum {
|
sl@0
|
83 |
LOOP_EXCEPTION_RANGE, /* Exception's range is part of a loop.
|
sl@0
|
84 |
* Break and continue "exceptions" cause
|
sl@0
|
85 |
* jumps to appropriate PC offsets. */
|
sl@0
|
86 |
CATCH_EXCEPTION_RANGE /* Exception's range is controlled by a
|
sl@0
|
87 |
* catch command. Errors in the range cause
|
sl@0
|
88 |
* a jump to a catch PC offset. */
|
sl@0
|
89 |
} ExceptionRangeType;
|
sl@0
|
90 |
|
sl@0
|
91 |
typedef struct ExceptionRange {
|
sl@0
|
92 |
ExceptionRangeType type; /* The kind of ExceptionRange. */
|
sl@0
|
93 |
int nestingLevel; /* Static depth of the exception range.
|
sl@0
|
94 |
* Used to find the most deeply-nested
|
sl@0
|
95 |
* range surrounding a PC at runtime. */
|
sl@0
|
96 |
int codeOffset; /* Offset of the first instruction byte of
|
sl@0
|
97 |
* the code range. */
|
sl@0
|
98 |
int numCodeBytes; /* Number of bytes in the code range. */
|
sl@0
|
99 |
int breakOffset; /* If LOOP_EXCEPTION_RANGE, the target PC
|
sl@0
|
100 |
* offset for a break command in the range. */
|
sl@0
|
101 |
int continueOffset; /* If LOOP_EXCEPTION_RANGE and not -1, the
|
sl@0
|
102 |
* target PC offset for a continue command in
|
sl@0
|
103 |
* the code range. Otherwise, ignore this range
|
sl@0
|
104 |
* when processing a continue command. */
|
sl@0
|
105 |
int catchOffset; /* If a CATCH_EXCEPTION_RANGE, the target PC
|
sl@0
|
106 |
* offset for any "exception" in range. */
|
sl@0
|
107 |
} ExceptionRange;
|
sl@0
|
108 |
|
sl@0
|
109 |
/*
|
sl@0
|
110 |
* Structure used to map between instruction pc and source locations. It
|
sl@0
|
111 |
* defines for each compiled Tcl command its code's starting offset and
|
sl@0
|
112 |
* its source's starting offset and length. Note that the code offset
|
sl@0
|
113 |
* increases monotonically: that is, the table is sorted in code offset
|
sl@0
|
114 |
* order. The source offset is not monotonic.
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
|
sl@0
|
117 |
typedef struct CmdLocation {
|
sl@0
|
118 |
int codeOffset; /* Offset of first byte of command code. */
|
sl@0
|
119 |
int numCodeBytes; /* Number of bytes for command's code. */
|
sl@0
|
120 |
int srcOffset; /* Offset of first char of the command. */
|
sl@0
|
121 |
int numSrcBytes; /* Number of command source chars. */
|
sl@0
|
122 |
} CmdLocation;
|
sl@0
|
123 |
|
sl@0
|
124 |
#ifdef TCL_TIP280
|
sl@0
|
125 |
/*
|
sl@0
|
126 |
* TIP #280
|
sl@0
|
127 |
* Structure to record additional location information for byte code.
|
sl@0
|
128 |
* This information is internal and not saved. I.e. tbcload'ed code
|
sl@0
|
129 |
* will not have this information. It records the lines for all words
|
sl@0
|
130 |
* of all commands found in the byte code. The association with a
|
sl@0
|
131 |
* ByteCode structure BC is done through the 'lineBCPtr' HashTable in
|
sl@0
|
132 |
* Interp, keyed by the address of BC. Also recorded is information
|
sl@0
|
133 |
* coming from the context, i.e. type of the frame and associated
|
sl@0
|
134 |
* information, like the path of a sourced file.
|
sl@0
|
135 |
*/
|
sl@0
|
136 |
|
sl@0
|
137 |
typedef struct ECL {
|
sl@0
|
138 |
int srcOffset; /* cmd location to find the entry */
|
sl@0
|
139 |
int nline;
|
sl@0
|
140 |
int* line; /* line information for all words in the command */
|
sl@0
|
141 |
} ECL;
|
sl@0
|
142 |
typedef struct ExtCmdLoc {
|
sl@0
|
143 |
int type; /* Context type */
|
sl@0
|
144 |
Tcl_Obj* path; /* Path of the sourced file the command is in */
|
sl@0
|
145 |
ECL* loc; /* Command word locations (lines) */
|
sl@0
|
146 |
int nloc; /* Number of allocated entries in 'loc' */
|
sl@0
|
147 |
int nuloc; /* Number of used entries in 'loc' */
|
sl@0
|
148 |
} ExtCmdLoc;
|
sl@0
|
149 |
#endif
|
sl@0
|
150 |
|
sl@0
|
151 |
/*
|
sl@0
|
152 |
* CompileProcs need the ability to record information during compilation
|
sl@0
|
153 |
* that can be used by bytecode instructions during execution. The AuxData
|
sl@0
|
154 |
* structure provides this "auxiliary data" mechanism. An arbitrary number
|
sl@0
|
155 |
* of these structures can be stored in the ByteCode record (during
|
sl@0
|
156 |
* compilation they are stored in a CompileEnv structure). Each AuxData
|
sl@0
|
157 |
* record holds one word of client-specified data (often a pointer) and is
|
sl@0
|
158 |
* given an index that instructions can later use to look up the structure
|
sl@0
|
159 |
* and its data.
|
sl@0
|
160 |
*
|
sl@0
|
161 |
* The following definitions declare the types of procedures that are called
|
sl@0
|
162 |
* to duplicate or free this auxiliary data when the containing ByteCode
|
sl@0
|
163 |
* objects are duplicated and freed. Pointers to these procedures are kept
|
sl@0
|
164 |
* in the AuxData structure.
|
sl@0
|
165 |
*/
|
sl@0
|
166 |
|
sl@0
|
167 |
typedef ClientData (AuxDataDupProc) _ANSI_ARGS_((ClientData clientData));
|
sl@0
|
168 |
typedef void (AuxDataFreeProc) _ANSI_ARGS_((ClientData clientData));
|
sl@0
|
169 |
|
sl@0
|
170 |
/*
|
sl@0
|
171 |
* We define a separate AuxDataType struct to hold type-related information
|
sl@0
|
172 |
* for the AuxData structure. This separation makes it possible for clients
|
sl@0
|
173 |
* outside of the TCL core to manipulate (in a limited fashion!) AuxData;
|
sl@0
|
174 |
* for example, it makes it possible to pickle and unpickle AuxData structs.
|
sl@0
|
175 |
*/
|
sl@0
|
176 |
|
sl@0
|
177 |
typedef struct AuxDataType {
|
sl@0
|
178 |
char *name; /* the name of the type. Types can be
|
sl@0
|
179 |
* registered and found by name */
|
sl@0
|
180 |
AuxDataDupProc *dupProc; /* Callback procedure to invoke when the
|
sl@0
|
181 |
* aux data is duplicated (e.g., when the
|
sl@0
|
182 |
* ByteCode structure containing the aux
|
sl@0
|
183 |
* data is duplicated). NULL means just
|
sl@0
|
184 |
* copy the source clientData bits; no
|
sl@0
|
185 |
* proc need be called. */
|
sl@0
|
186 |
AuxDataFreeProc *freeProc; /* Callback procedure to invoke when the
|
sl@0
|
187 |
* aux data is freed. NULL means no
|
sl@0
|
188 |
* proc need be called. */
|
sl@0
|
189 |
} AuxDataType;
|
sl@0
|
190 |
|
sl@0
|
191 |
/*
|
sl@0
|
192 |
* The definition of the AuxData structure that holds information created
|
sl@0
|
193 |
* during compilation by CompileProcs and used by instructions during
|
sl@0
|
194 |
* execution.
|
sl@0
|
195 |
*/
|
sl@0
|
196 |
|
sl@0
|
197 |
typedef struct AuxData {
|
sl@0
|
198 |
AuxDataType *type; /* pointer to the AuxData type associated with
|
sl@0
|
199 |
* this ClientData. */
|
sl@0
|
200 |
ClientData clientData; /* The compilation data itself. */
|
sl@0
|
201 |
} AuxData;
|
sl@0
|
202 |
|
sl@0
|
203 |
/*
|
sl@0
|
204 |
* Structure defining the compilation environment. After compilation, fields
|
sl@0
|
205 |
* describing bytecode instructions are copied out into the more compact
|
sl@0
|
206 |
* ByteCode structure defined below.
|
sl@0
|
207 |
*/
|
sl@0
|
208 |
|
sl@0
|
209 |
#define COMPILEENV_INIT_CODE_BYTES 250
|
sl@0
|
210 |
#define COMPILEENV_INIT_NUM_OBJECTS 60
|
sl@0
|
211 |
#define COMPILEENV_INIT_EXCEPT_RANGES 5
|
sl@0
|
212 |
#define COMPILEENV_INIT_CMD_MAP_SIZE 40
|
sl@0
|
213 |
#define COMPILEENV_INIT_AUX_DATA_SIZE 5
|
sl@0
|
214 |
|
sl@0
|
215 |
typedef struct CompileEnv {
|
sl@0
|
216 |
Interp *iPtr; /* Interpreter containing the code being
|
sl@0
|
217 |
* compiled. Commands and their compile
|
sl@0
|
218 |
* procs are specific to an interpreter so
|
sl@0
|
219 |
* the code emitted will depend on the
|
sl@0
|
220 |
* interpreter. */
|
sl@0
|
221 |
char *source; /* The source string being compiled by
|
sl@0
|
222 |
* SetByteCodeFromAny. This pointer is not
|
sl@0
|
223 |
* owned by the CompileEnv and must not be
|
sl@0
|
224 |
* freed or changed by it. */
|
sl@0
|
225 |
int numSrcBytes; /* Number of bytes in source. */
|
sl@0
|
226 |
Proc *procPtr; /* If a procedure is being compiled, a
|
sl@0
|
227 |
* pointer to its Proc structure; otherwise
|
sl@0
|
228 |
* NULL. Used to compile local variables.
|
sl@0
|
229 |
* Set from information provided by
|
sl@0
|
230 |
* ObjInterpProc in tclProc.c. */
|
sl@0
|
231 |
int numCommands; /* Number of commands compiled. */
|
sl@0
|
232 |
int exceptDepth; /* Current exception range nesting level;
|
sl@0
|
233 |
* -1 if not in any range currently. */
|
sl@0
|
234 |
int maxExceptDepth; /* Max nesting level of exception ranges;
|
sl@0
|
235 |
* -1 if no ranges have been compiled. */
|
sl@0
|
236 |
int maxStackDepth; /* Maximum number of stack elements needed
|
sl@0
|
237 |
* to execute the code. Set by compilation
|
sl@0
|
238 |
* procedures before returning. */
|
sl@0
|
239 |
int currStackDepth; /* Current stack depth. */
|
sl@0
|
240 |
LiteralTable localLitTable; /* Contains LiteralEntry's describing
|
sl@0
|
241 |
* all Tcl objects referenced by this
|
sl@0
|
242 |
* compiled code. Indexed by the string
|
sl@0
|
243 |
* representations of the literals. Used to
|
sl@0
|
244 |
* avoid creating duplicate objects. */
|
sl@0
|
245 |
unsigned char *codeStart; /* Points to the first byte of the code. */
|
sl@0
|
246 |
unsigned char *codeNext; /* Points to next code array byte to use. */
|
sl@0
|
247 |
unsigned char *codeEnd; /* Points just after the last allocated
|
sl@0
|
248 |
* code array byte. */
|
sl@0
|
249 |
int mallocedCodeArray; /* Set 1 if code array was expanded
|
sl@0
|
250 |
* and codeStart points into the heap.*/
|
sl@0
|
251 |
LiteralEntry *literalArrayPtr;
|
sl@0
|
252 |
/* Points to start of LiteralEntry array. */
|
sl@0
|
253 |
int literalArrayNext; /* Index of next free object array entry. */
|
sl@0
|
254 |
int literalArrayEnd; /* Index just after last obj array entry. */
|
sl@0
|
255 |
int mallocedLiteralArray; /* 1 if object array was expanded and
|
sl@0
|
256 |
* objArray points into the heap, else 0. */
|
sl@0
|
257 |
ExceptionRange *exceptArrayPtr;
|
sl@0
|
258 |
/* Points to start of the ExceptionRange
|
sl@0
|
259 |
* array. */
|
sl@0
|
260 |
int exceptArrayNext; /* Next free ExceptionRange array index.
|
sl@0
|
261 |
* exceptArrayNext is the number of ranges
|
sl@0
|
262 |
* and (exceptArrayNext-1) is the index of
|
sl@0
|
263 |
* the current range's array entry. */
|
sl@0
|
264 |
int exceptArrayEnd; /* Index after the last ExceptionRange
|
sl@0
|
265 |
* array entry. */
|
sl@0
|
266 |
int mallocedExceptArray; /* 1 if ExceptionRange array was expanded
|
sl@0
|
267 |
* and exceptArrayPtr points in heap,
|
sl@0
|
268 |
* else 0. */
|
sl@0
|
269 |
CmdLocation *cmdMapPtr; /* Points to start of CmdLocation array.
|
sl@0
|
270 |
* numCommands is the index of the next
|
sl@0
|
271 |
* entry to use; (numCommands-1) is the
|
sl@0
|
272 |
* entry index for the last command. */
|
sl@0
|
273 |
int cmdMapEnd; /* Index after last CmdLocation entry. */
|
sl@0
|
274 |
int mallocedCmdMap; /* 1 if command map array was expanded and
|
sl@0
|
275 |
* cmdMapPtr points in the heap, else 0. */
|
sl@0
|
276 |
AuxData *auxDataArrayPtr; /* Points to auxiliary data array start. */
|
sl@0
|
277 |
int auxDataArrayNext; /* Next free compile aux data array index.
|
sl@0
|
278 |
* auxDataArrayNext is the number of aux
|
sl@0
|
279 |
* data items and (auxDataArrayNext-1) is
|
sl@0
|
280 |
* index of current aux data array entry. */
|
sl@0
|
281 |
int auxDataArrayEnd; /* Index after last aux data array entry. */
|
sl@0
|
282 |
int mallocedAuxDataArray; /* 1 if aux data array was expanded and
|
sl@0
|
283 |
* auxDataArrayPtr points in heap else 0. */
|
sl@0
|
284 |
unsigned char staticCodeSpace[COMPILEENV_INIT_CODE_BYTES];
|
sl@0
|
285 |
/* Initial storage for code. */
|
sl@0
|
286 |
LiteralEntry staticLiteralSpace[COMPILEENV_INIT_NUM_OBJECTS];
|
sl@0
|
287 |
/* Initial storage of LiteralEntry array. */
|
sl@0
|
288 |
ExceptionRange staticExceptArraySpace[COMPILEENV_INIT_EXCEPT_RANGES];
|
sl@0
|
289 |
/* Initial ExceptionRange array storage. */
|
sl@0
|
290 |
CmdLocation staticCmdMapSpace[COMPILEENV_INIT_CMD_MAP_SIZE];
|
sl@0
|
291 |
/* Initial storage for cmd location map. */
|
sl@0
|
292 |
AuxData staticAuxDataArraySpace[COMPILEENV_INIT_AUX_DATA_SIZE];
|
sl@0
|
293 |
/* Initial storage for aux data array. */
|
sl@0
|
294 |
#ifdef TCL_TIP280
|
sl@0
|
295 |
/* TIP #280 */
|
sl@0
|
296 |
ExtCmdLoc* extCmdMapPtr; /* Extended command location information
|
sl@0
|
297 |
* for 'info frame'. */
|
sl@0
|
298 |
int line; /* First line of the script, based on the
|
sl@0
|
299 |
* invoking context, then the line of the
|
sl@0
|
300 |
* command currently compiled. */
|
sl@0
|
301 |
#endif
|
sl@0
|
302 |
} CompileEnv;
|
sl@0
|
303 |
|
sl@0
|
304 |
/*
|
sl@0
|
305 |
* The structure defining the bytecode instructions resulting from compiling
|
sl@0
|
306 |
* a Tcl script. Note that this structure is variable length: a single heap
|
sl@0
|
307 |
* object is allocated to hold the ByteCode structure immediately followed
|
sl@0
|
308 |
* by the code bytes, the literal object array, the ExceptionRange array,
|
sl@0
|
309 |
* the CmdLocation map, and the compilation AuxData array.
|
sl@0
|
310 |
*/
|
sl@0
|
311 |
|
sl@0
|
312 |
/*
|
sl@0
|
313 |
* A PRECOMPILED bytecode struct is one that was generated from a compiled
|
sl@0
|
314 |
* image rather than implicitly compiled from source
|
sl@0
|
315 |
*/
|
sl@0
|
316 |
#define TCL_BYTECODE_PRECOMPILED 0x0001
|
sl@0
|
317 |
|
sl@0
|
318 |
typedef struct ByteCode {
|
sl@0
|
319 |
TclHandle interpHandle; /* Handle for interpreter containing the
|
sl@0
|
320 |
* compiled code. Commands and their compile
|
sl@0
|
321 |
* procs are specific to an interpreter so the
|
sl@0
|
322 |
* code emitted will depend on the
|
sl@0
|
323 |
* interpreter. */
|
sl@0
|
324 |
int compileEpoch; /* Value of iPtr->compileEpoch when this
|
sl@0
|
325 |
* ByteCode was compiled. Used to invalidate
|
sl@0
|
326 |
* code when, e.g., commands with compile
|
sl@0
|
327 |
* procs are redefined. */
|
sl@0
|
328 |
Namespace *nsPtr; /* Namespace context in which this code
|
sl@0
|
329 |
* was compiled. If the code is executed
|
sl@0
|
330 |
* if a different namespace, it must be
|
sl@0
|
331 |
* recompiled. */
|
sl@0
|
332 |
int nsEpoch; /* Value of nsPtr->resolverEpoch when this
|
sl@0
|
333 |
* ByteCode was compiled. Used to invalidate
|
sl@0
|
334 |
* code when new namespace resolution rules
|
sl@0
|
335 |
* are put into effect. */
|
sl@0
|
336 |
int refCount; /* Reference count: set 1 when created
|
sl@0
|
337 |
* plus 1 for each execution of the code
|
sl@0
|
338 |
* currently active. This structure can be
|
sl@0
|
339 |
* freed when refCount becomes zero. */
|
sl@0
|
340 |
unsigned int flags; /* flags describing state for the codebyte.
|
sl@0
|
341 |
* this variable holds ORed values from the
|
sl@0
|
342 |
* TCL_BYTECODE_ masks defined above */
|
sl@0
|
343 |
char *source; /* The source string from which this
|
sl@0
|
344 |
* ByteCode was compiled. Note that this
|
sl@0
|
345 |
* pointer is not owned by the ByteCode and
|
sl@0
|
346 |
* must not be freed or modified by it. */
|
sl@0
|
347 |
Proc *procPtr; /* If the ByteCode was compiled from a
|
sl@0
|
348 |
* procedure body, this is a pointer to its
|
sl@0
|
349 |
* Proc structure; otherwise NULL. This
|
sl@0
|
350 |
* pointer is also not owned by the ByteCode
|
sl@0
|
351 |
* and must not be freed by it. */
|
sl@0
|
352 |
size_t structureSize; /* Number of bytes in the ByteCode structure
|
sl@0
|
353 |
* itself. Does not include heap space for
|
sl@0
|
354 |
* literal Tcl objects or storage referenced
|
sl@0
|
355 |
* by AuxData entries. */
|
sl@0
|
356 |
int numCommands; /* Number of commands compiled. */
|
sl@0
|
357 |
int numSrcBytes; /* Number of source bytes compiled. */
|
sl@0
|
358 |
int numCodeBytes; /* Number of code bytes. */
|
sl@0
|
359 |
int numLitObjects; /* Number of objects in literal array. */
|
sl@0
|
360 |
int numExceptRanges; /* Number of ExceptionRange array elems. */
|
sl@0
|
361 |
int numAuxDataItems; /* Number of AuxData items. */
|
sl@0
|
362 |
int numCmdLocBytes; /* Number of bytes needed for encoded
|
sl@0
|
363 |
* command location information. */
|
sl@0
|
364 |
int maxExceptDepth; /* Maximum nesting level of ExceptionRanges;
|
sl@0
|
365 |
* -1 if no ranges were compiled. */
|
sl@0
|
366 |
int maxStackDepth; /* Maximum number of stack elements needed
|
sl@0
|
367 |
* to execute the code. */
|
sl@0
|
368 |
unsigned char *codeStart; /* Points to the first byte of the code.
|
sl@0
|
369 |
* This is just after the final ByteCode
|
sl@0
|
370 |
* member cmdMapPtr. */
|
sl@0
|
371 |
Tcl_Obj **objArrayPtr; /* Points to the start of the literal
|
sl@0
|
372 |
* object array. This is just after the
|
sl@0
|
373 |
* last code byte. */
|
sl@0
|
374 |
ExceptionRange *exceptArrayPtr;
|
sl@0
|
375 |
/* Points to the start of the ExceptionRange
|
sl@0
|
376 |
* array. This is just after the last
|
sl@0
|
377 |
* object in the object array. */
|
sl@0
|
378 |
AuxData *auxDataArrayPtr; /* Points to the start of the auxiliary data
|
sl@0
|
379 |
* array. This is just after the last entry
|
sl@0
|
380 |
* in the ExceptionRange array. */
|
sl@0
|
381 |
unsigned char *codeDeltaStart;
|
sl@0
|
382 |
/* Points to the first of a sequence of
|
sl@0
|
383 |
* bytes that encode the change in the
|
sl@0
|
384 |
* starting offset of each command's code.
|
sl@0
|
385 |
* If -127<=delta<=127, it is encoded as 1
|
sl@0
|
386 |
* byte, otherwise 0xFF (128) appears and
|
sl@0
|
387 |
* the delta is encoded by the next 4 bytes.
|
sl@0
|
388 |
* Code deltas are always positive. This
|
sl@0
|
389 |
* sequence is just after the last entry in
|
sl@0
|
390 |
* the AuxData array. */
|
sl@0
|
391 |
unsigned char *codeLengthStart;
|
sl@0
|
392 |
/* Points to the first of a sequence of
|
sl@0
|
393 |
* bytes that encode the length of each
|
sl@0
|
394 |
* command's code. The encoding is the same
|
sl@0
|
395 |
* as for code deltas. Code lengths are
|
sl@0
|
396 |
* always positive. This sequence is just
|
sl@0
|
397 |
* after the last entry in the code delta
|
sl@0
|
398 |
* sequence. */
|
sl@0
|
399 |
unsigned char *srcDeltaStart;
|
sl@0
|
400 |
/* Points to the first of a sequence of
|
sl@0
|
401 |
* bytes that encode the change in the
|
sl@0
|
402 |
* starting offset of each command's source.
|
sl@0
|
403 |
* The encoding is the same as for code
|
sl@0
|
404 |
* deltas. Source deltas can be negative.
|
sl@0
|
405 |
* This sequence is just after the last byte
|
sl@0
|
406 |
* in the code length sequence. */
|
sl@0
|
407 |
unsigned char *srcLengthStart;
|
sl@0
|
408 |
/* Points to the first of a sequence of
|
sl@0
|
409 |
* bytes that encode the length of each
|
sl@0
|
410 |
* command's source. The encoding is the
|
sl@0
|
411 |
* same as for code deltas. Source lengths
|
sl@0
|
412 |
* are always positive. This sequence is
|
sl@0
|
413 |
* just after the last byte in the source
|
sl@0
|
414 |
* delta sequence. */
|
sl@0
|
415 |
#ifdef TCL_COMPILE_STATS
|
sl@0
|
416 |
Tcl_Time createTime; /* Absolute time when the ByteCode was
|
sl@0
|
417 |
* created. */
|
sl@0
|
418 |
#endif /* TCL_COMPILE_STATS */
|
sl@0
|
419 |
} ByteCode;
|
sl@0
|
420 |
|
sl@0
|
421 |
/*
|
sl@0
|
422 |
* Opcodes for the Tcl bytecode instructions. These must correspond to
|
sl@0
|
423 |
* the entries in the table of instruction descriptions,
|
sl@0
|
424 |
* tclInstructionTable, in tclCompile.c. Also, the order and number of
|
sl@0
|
425 |
* the expression opcodes (e.g., INST_LOR) must match the entries in
|
sl@0
|
426 |
* the array operatorStrings in tclExecute.c.
|
sl@0
|
427 |
*/
|
sl@0
|
428 |
|
sl@0
|
429 |
/* Opcodes 0 to 9 */
|
sl@0
|
430 |
#define INST_DONE 0
|
sl@0
|
431 |
#define INST_PUSH1 1
|
sl@0
|
432 |
#define INST_PUSH4 2
|
sl@0
|
433 |
#define INST_POP 3
|
sl@0
|
434 |
#define INST_DUP 4
|
sl@0
|
435 |
#define INST_CONCAT1 5
|
sl@0
|
436 |
#define INST_INVOKE_STK1 6
|
sl@0
|
437 |
#define INST_INVOKE_STK4 7
|
sl@0
|
438 |
#define INST_EVAL_STK 8
|
sl@0
|
439 |
#define INST_EXPR_STK 9
|
sl@0
|
440 |
|
sl@0
|
441 |
/* Opcodes 10 to 23 */
|
sl@0
|
442 |
#define INST_LOAD_SCALAR1 10
|
sl@0
|
443 |
#define INST_LOAD_SCALAR4 11
|
sl@0
|
444 |
#define INST_LOAD_SCALAR_STK 12
|
sl@0
|
445 |
#define INST_LOAD_ARRAY1 13
|
sl@0
|
446 |
#define INST_LOAD_ARRAY4 14
|
sl@0
|
447 |
#define INST_LOAD_ARRAY_STK 15
|
sl@0
|
448 |
#define INST_LOAD_STK 16
|
sl@0
|
449 |
#define INST_STORE_SCALAR1 17
|
sl@0
|
450 |
#define INST_STORE_SCALAR4 18
|
sl@0
|
451 |
#define INST_STORE_SCALAR_STK 19
|
sl@0
|
452 |
#define INST_STORE_ARRAY1 20
|
sl@0
|
453 |
#define INST_STORE_ARRAY4 21
|
sl@0
|
454 |
#define INST_STORE_ARRAY_STK 22
|
sl@0
|
455 |
#define INST_STORE_STK 23
|
sl@0
|
456 |
|
sl@0
|
457 |
/* Opcodes 24 to 33 */
|
sl@0
|
458 |
#define INST_INCR_SCALAR1 24
|
sl@0
|
459 |
#define INST_INCR_SCALAR_STK 25
|
sl@0
|
460 |
#define INST_INCR_ARRAY1 26
|
sl@0
|
461 |
#define INST_INCR_ARRAY_STK 27
|
sl@0
|
462 |
#define INST_INCR_STK 28
|
sl@0
|
463 |
#define INST_INCR_SCALAR1_IMM 29
|
sl@0
|
464 |
#define INST_INCR_SCALAR_STK_IMM 30
|
sl@0
|
465 |
#define INST_INCR_ARRAY1_IMM 31
|
sl@0
|
466 |
#define INST_INCR_ARRAY_STK_IMM 32
|
sl@0
|
467 |
#define INST_INCR_STK_IMM 33
|
sl@0
|
468 |
|
sl@0
|
469 |
/* Opcodes 34 to 39 */
|
sl@0
|
470 |
#define INST_JUMP1 34
|
sl@0
|
471 |
#define INST_JUMP4 35
|
sl@0
|
472 |
#define INST_JUMP_TRUE1 36
|
sl@0
|
473 |
#define INST_JUMP_TRUE4 37
|
sl@0
|
474 |
#define INST_JUMP_FALSE1 38
|
sl@0
|
475 |
#define INST_JUMP_FALSE4 39
|
sl@0
|
476 |
|
sl@0
|
477 |
/* Opcodes 40 to 64 */
|
sl@0
|
478 |
#define INST_LOR 40
|
sl@0
|
479 |
#define INST_LAND 41
|
sl@0
|
480 |
#define INST_BITOR 42
|
sl@0
|
481 |
#define INST_BITXOR 43
|
sl@0
|
482 |
#define INST_BITAND 44
|
sl@0
|
483 |
#define INST_EQ 45
|
sl@0
|
484 |
#define INST_NEQ 46
|
sl@0
|
485 |
#define INST_LT 47
|
sl@0
|
486 |
#define INST_GT 48
|
sl@0
|
487 |
#define INST_LE 49
|
sl@0
|
488 |
#define INST_GE 50
|
sl@0
|
489 |
#define INST_LSHIFT 51
|
sl@0
|
490 |
#define INST_RSHIFT 52
|
sl@0
|
491 |
#define INST_ADD 53
|
sl@0
|
492 |
#define INST_SUB 54
|
sl@0
|
493 |
#define INST_MULT 55
|
sl@0
|
494 |
#define INST_DIV 56
|
sl@0
|
495 |
#define INST_MOD 57
|
sl@0
|
496 |
#define INST_UPLUS 58
|
sl@0
|
497 |
#define INST_UMINUS 59
|
sl@0
|
498 |
#define INST_BITNOT 60
|
sl@0
|
499 |
#define INST_LNOT 61
|
sl@0
|
500 |
#define INST_CALL_BUILTIN_FUNC1 62
|
sl@0
|
501 |
#define INST_CALL_FUNC1 63
|
sl@0
|
502 |
#define INST_TRY_CVT_TO_NUMERIC 64
|
sl@0
|
503 |
|
sl@0
|
504 |
/* Opcodes 65 to 66 */
|
sl@0
|
505 |
#define INST_BREAK 65
|
sl@0
|
506 |
#define INST_CONTINUE 66
|
sl@0
|
507 |
|
sl@0
|
508 |
/* Opcodes 67 to 68 */
|
sl@0
|
509 |
#define INST_FOREACH_START4 67
|
sl@0
|
510 |
#define INST_FOREACH_STEP4 68
|
sl@0
|
511 |
|
sl@0
|
512 |
/* Opcodes 69 to 72 */
|
sl@0
|
513 |
#define INST_BEGIN_CATCH4 69
|
sl@0
|
514 |
#define INST_END_CATCH 70
|
sl@0
|
515 |
#define INST_PUSH_RESULT 71
|
sl@0
|
516 |
#define INST_PUSH_RETURN_CODE 72
|
sl@0
|
517 |
|
sl@0
|
518 |
/* Opcodes 73 to 78 */
|
sl@0
|
519 |
#define INST_STR_EQ 73
|
sl@0
|
520 |
#define INST_STR_NEQ 74
|
sl@0
|
521 |
#define INST_STR_CMP 75
|
sl@0
|
522 |
#define INST_STR_LEN 76
|
sl@0
|
523 |
#define INST_STR_INDEX 77
|
sl@0
|
524 |
#define INST_STR_MATCH 78
|
sl@0
|
525 |
|
sl@0
|
526 |
/* Opcodes 78 to 81 */
|
sl@0
|
527 |
#define INST_LIST 79
|
sl@0
|
528 |
#define INST_LIST_INDEX 80
|
sl@0
|
529 |
#define INST_LIST_LENGTH 81
|
sl@0
|
530 |
|
sl@0
|
531 |
/* Opcodes 82 to 87 */
|
sl@0
|
532 |
#define INST_APPEND_SCALAR1 82
|
sl@0
|
533 |
#define INST_APPEND_SCALAR4 83
|
sl@0
|
534 |
#define INST_APPEND_ARRAY1 84
|
sl@0
|
535 |
#define INST_APPEND_ARRAY4 85
|
sl@0
|
536 |
#define INST_APPEND_ARRAY_STK 86
|
sl@0
|
537 |
#define INST_APPEND_STK 87
|
sl@0
|
538 |
|
sl@0
|
539 |
/* Opcodes 88 to 93 */
|
sl@0
|
540 |
#define INST_LAPPEND_SCALAR1 88
|
sl@0
|
541 |
#define INST_LAPPEND_SCALAR4 89
|
sl@0
|
542 |
#define INST_LAPPEND_ARRAY1 90
|
sl@0
|
543 |
#define INST_LAPPEND_ARRAY4 91
|
sl@0
|
544 |
#define INST_LAPPEND_ARRAY_STK 92
|
sl@0
|
545 |
#define INST_LAPPEND_STK 93
|
sl@0
|
546 |
|
sl@0
|
547 |
/* TIP #22 - LINDEX operator with flat arg list */
|
sl@0
|
548 |
|
sl@0
|
549 |
#define INST_LIST_INDEX_MULTI 94
|
sl@0
|
550 |
|
sl@0
|
551 |
/*
|
sl@0
|
552 |
* TIP #33 - 'lset' command. Code gen also required a Forth-like
|
sl@0
|
553 |
* OVER operation.
|
sl@0
|
554 |
*/
|
sl@0
|
555 |
|
sl@0
|
556 |
#define INST_OVER 95
|
sl@0
|
557 |
#define INST_LSET_LIST 96
|
sl@0
|
558 |
#define INST_LSET_FLAT 97
|
sl@0
|
559 |
|
sl@0
|
560 |
/* The last opcode */
|
sl@0
|
561 |
#define LAST_INST_OPCODE 97
|
sl@0
|
562 |
|
sl@0
|
563 |
/*
|
sl@0
|
564 |
* Table describing the Tcl bytecode instructions: their name (for
|
sl@0
|
565 |
* displaying code), total number of code bytes required (including
|
sl@0
|
566 |
* operand bytes), and a description of the type of each operand.
|
sl@0
|
567 |
* These operand types include signed and unsigned integers of length
|
sl@0
|
568 |
* one and four bytes. The unsigned integers are used for indexes or
|
sl@0
|
569 |
* for, e.g., the count of objects to push in a "push" instruction.
|
sl@0
|
570 |
*/
|
sl@0
|
571 |
|
sl@0
|
572 |
#define MAX_INSTRUCTION_OPERANDS 2
|
sl@0
|
573 |
|
sl@0
|
574 |
typedef enum InstOperandType {
|
sl@0
|
575 |
OPERAND_NONE,
|
sl@0
|
576 |
OPERAND_INT1, /* One byte signed integer. */
|
sl@0
|
577 |
OPERAND_INT4, /* Four byte signed integer. */
|
sl@0
|
578 |
OPERAND_UINT1, /* One byte unsigned integer. */
|
sl@0
|
579 |
OPERAND_UINT4 /* Four byte unsigned integer. */
|
sl@0
|
580 |
} InstOperandType;
|
sl@0
|
581 |
|
sl@0
|
582 |
typedef struct InstructionDesc {
|
sl@0
|
583 |
char *name; /* Name of instruction. */
|
sl@0
|
584 |
int numBytes; /* Total number of bytes for instruction. */
|
sl@0
|
585 |
int stackEffect; /* The worst-case balance stack effect of the
|
sl@0
|
586 |
* instruction, used for stack requirements
|
sl@0
|
587 |
* computations. The value INT_MIN signals
|
sl@0
|
588 |
* that the instruction's worst case effect
|
sl@0
|
589 |
* is (1-opnd1).
|
sl@0
|
590 |
*/
|
sl@0
|
591 |
int numOperands; /* Number of operands. */
|
sl@0
|
592 |
InstOperandType opTypes[MAX_INSTRUCTION_OPERANDS];
|
sl@0
|
593 |
/* The type of each operand. */
|
sl@0
|
594 |
} InstructionDesc;
|
sl@0
|
595 |
|
sl@0
|
596 |
extern InstructionDesc tclInstructionTable[];
|
sl@0
|
597 |
|
sl@0
|
598 |
/*
|
sl@0
|
599 |
* Definitions of the values of the INST_CALL_BUILTIN_FUNC instruction's
|
sl@0
|
600 |
* operand byte. Each value denotes a builtin Tcl math function. These
|
sl@0
|
601 |
* values must correspond to the entries in the tclBuiltinFuncTable array
|
sl@0
|
602 |
* below and to the values stored in the tclInt.h MathFunc structure's
|
sl@0
|
603 |
* builtinFuncIndex field.
|
sl@0
|
604 |
*/
|
sl@0
|
605 |
|
sl@0
|
606 |
#define BUILTIN_FUNC_ACOS 0
|
sl@0
|
607 |
#define BUILTIN_FUNC_ASIN 1
|
sl@0
|
608 |
#define BUILTIN_FUNC_ATAN 2
|
sl@0
|
609 |
#define BUILTIN_FUNC_ATAN2 3
|
sl@0
|
610 |
#define BUILTIN_FUNC_CEIL 4
|
sl@0
|
611 |
#define BUILTIN_FUNC_COS 5
|
sl@0
|
612 |
#define BUILTIN_FUNC_COSH 6
|
sl@0
|
613 |
#define BUILTIN_FUNC_EXP 7
|
sl@0
|
614 |
#define BUILTIN_FUNC_FLOOR 8
|
sl@0
|
615 |
#define BUILTIN_FUNC_FMOD 9
|
sl@0
|
616 |
#define BUILTIN_FUNC_HYPOT 10
|
sl@0
|
617 |
#define BUILTIN_FUNC_LOG 11
|
sl@0
|
618 |
#define BUILTIN_FUNC_LOG10 12
|
sl@0
|
619 |
#define BUILTIN_FUNC_POW 13
|
sl@0
|
620 |
#define BUILTIN_FUNC_SIN 14
|
sl@0
|
621 |
#define BUILTIN_FUNC_SINH 15
|
sl@0
|
622 |
#define BUILTIN_FUNC_SQRT 16
|
sl@0
|
623 |
#define BUILTIN_FUNC_TAN 17
|
sl@0
|
624 |
#define BUILTIN_FUNC_TANH 18
|
sl@0
|
625 |
#define BUILTIN_FUNC_ABS 19
|
sl@0
|
626 |
#define BUILTIN_FUNC_DOUBLE 20
|
sl@0
|
627 |
#define BUILTIN_FUNC_INT 21
|
sl@0
|
628 |
#define BUILTIN_FUNC_RAND 22
|
sl@0
|
629 |
#define BUILTIN_FUNC_ROUND 23
|
sl@0
|
630 |
#define BUILTIN_FUNC_SRAND 24
|
sl@0
|
631 |
#define BUILTIN_FUNC_WIDE 25
|
sl@0
|
632 |
|
sl@0
|
633 |
#define LAST_BUILTIN_FUNC 25
|
sl@0
|
634 |
|
sl@0
|
635 |
/*
|
sl@0
|
636 |
* Table describing the built-in math functions. Entries in this table are
|
sl@0
|
637 |
* indexed by the values of the INST_CALL_BUILTIN_FUNC instruction's
|
sl@0
|
638 |
* operand byte.
|
sl@0
|
639 |
*/
|
sl@0
|
640 |
|
sl@0
|
641 |
typedef int (CallBuiltinFuncProc) _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
642 |
ExecEnv *eePtr, ClientData clientData));
|
sl@0
|
643 |
|
sl@0
|
644 |
typedef struct {
|
sl@0
|
645 |
char *name; /* Name of function. */
|
sl@0
|
646 |
int numArgs; /* Number of arguments for function. */
|
sl@0
|
647 |
Tcl_ValueType argTypes[MAX_MATH_ARGS];
|
sl@0
|
648 |
/* Acceptable types for each argument. */
|
sl@0
|
649 |
CallBuiltinFuncProc *proc; /* Procedure implementing this function. */
|
sl@0
|
650 |
ClientData clientData; /* Additional argument to pass to the
|
sl@0
|
651 |
* function when invoking it. */
|
sl@0
|
652 |
} BuiltinFunc;
|
sl@0
|
653 |
|
sl@0
|
654 |
extern BuiltinFunc tclBuiltinFuncTable[];
|
sl@0
|
655 |
|
sl@0
|
656 |
/*
|
sl@0
|
657 |
* Compilation of some Tcl constructs such as if commands and the logical or
|
sl@0
|
658 |
* (||) and logical and (&&) operators in expressions requires the
|
sl@0
|
659 |
* generation of forward jumps. Since the PC target of these jumps isn't
|
sl@0
|
660 |
* known when the jumps are emitted, we record the offset of each jump in an
|
sl@0
|
661 |
* array of JumpFixup structures. There is one array for each sequence of
|
sl@0
|
662 |
* jumps to one target PC. When we learn the target PC, we update the jumps
|
sl@0
|
663 |
* with the correct distance. Also, if the distance is too great (> 127
|
sl@0
|
664 |
* bytes), we replace the single-byte jump with a four byte jump
|
sl@0
|
665 |
* instruction, move the instructions after the jump down, and update the
|
sl@0
|
666 |
* code offsets for any commands between the jump and the target.
|
sl@0
|
667 |
*/
|
sl@0
|
668 |
|
sl@0
|
669 |
typedef enum {
|
sl@0
|
670 |
TCL_UNCONDITIONAL_JUMP,
|
sl@0
|
671 |
TCL_TRUE_JUMP,
|
sl@0
|
672 |
TCL_FALSE_JUMP
|
sl@0
|
673 |
} TclJumpType;
|
sl@0
|
674 |
|
sl@0
|
675 |
typedef struct JumpFixup {
|
sl@0
|
676 |
TclJumpType jumpType; /* Indicates the kind of jump. */
|
sl@0
|
677 |
int codeOffset; /* Offset of the first byte of the one-byte
|
sl@0
|
678 |
* forward jump's code. */
|
sl@0
|
679 |
int cmdIndex; /* Index of the first command after the one
|
sl@0
|
680 |
* for which the jump was emitted. Used to
|
sl@0
|
681 |
* update the code offsets for subsequent
|
sl@0
|
682 |
* commands if the two-byte jump at jumpPc
|
sl@0
|
683 |
* must be replaced with a five-byte one. */
|
sl@0
|
684 |
int exceptIndex; /* Index of the first range entry in the
|
sl@0
|
685 |
* ExceptionRange array after the current
|
sl@0
|
686 |
* one. This field is used to adjust the
|
sl@0
|
687 |
* code offsets in subsequent ExceptionRange
|
sl@0
|
688 |
* records when a jump is grown from 2 bytes
|
sl@0
|
689 |
* to 5 bytes. */
|
sl@0
|
690 |
} JumpFixup;
|
sl@0
|
691 |
|
sl@0
|
692 |
#define JUMPFIXUP_INIT_ENTRIES 10
|
sl@0
|
693 |
|
sl@0
|
694 |
typedef struct JumpFixupArray {
|
sl@0
|
695 |
JumpFixup *fixup; /* Points to start of jump fixup array. */
|
sl@0
|
696 |
int next; /* Index of next free array entry. */
|
sl@0
|
697 |
int end; /* Index of last usable entry in array. */
|
sl@0
|
698 |
int mallocedArray; /* 1 if array was expanded and fixups points
|
sl@0
|
699 |
* into the heap, else 0. */
|
sl@0
|
700 |
JumpFixup staticFixupSpace[JUMPFIXUP_INIT_ENTRIES];
|
sl@0
|
701 |
/* Initial storage for jump fixup array. */
|
sl@0
|
702 |
} JumpFixupArray;
|
sl@0
|
703 |
|
sl@0
|
704 |
/*
|
sl@0
|
705 |
* The structure describing one variable list of a foreach command. Note
|
sl@0
|
706 |
* that only foreach commands inside procedure bodies are compiled inline so
|
sl@0
|
707 |
* a ForeachVarList structure always describes local variables. Furthermore,
|
sl@0
|
708 |
* only scalar variables are supported for inline-compiled foreach loops.
|
sl@0
|
709 |
*/
|
sl@0
|
710 |
|
sl@0
|
711 |
typedef struct ForeachVarList {
|
sl@0
|
712 |
int numVars; /* The number of variables in the list. */
|
sl@0
|
713 |
int varIndexes[1]; /* An array of the indexes ("slot numbers")
|
sl@0
|
714 |
* for each variable in the procedure's
|
sl@0
|
715 |
* array of local variables. Only scalar
|
sl@0
|
716 |
* variables are supported. The actual
|
sl@0
|
717 |
* size of this field will be large enough
|
sl@0
|
718 |
* to numVars indexes. THIS MUST BE THE
|
sl@0
|
719 |
* LAST FIELD IN THE STRUCTURE! */
|
sl@0
|
720 |
} ForeachVarList;
|
sl@0
|
721 |
|
sl@0
|
722 |
/*
|
sl@0
|
723 |
* Structure used to hold information about a foreach command that is needed
|
sl@0
|
724 |
* during program execution. These structures are stored in CompileEnv and
|
sl@0
|
725 |
* ByteCode structures as auxiliary data.
|
sl@0
|
726 |
*/
|
sl@0
|
727 |
|
sl@0
|
728 |
typedef struct ForeachInfo {
|
sl@0
|
729 |
int numLists; /* The number of both the variable and value
|
sl@0
|
730 |
* lists of the foreach command. */
|
sl@0
|
731 |
int firstValueTemp; /* Index of the first temp var in a proc
|
sl@0
|
732 |
* frame used to point to a value list. */
|
sl@0
|
733 |
int loopCtTemp; /* Index of temp var in a proc frame
|
sl@0
|
734 |
* holding the loop's iteration count. Used
|
sl@0
|
735 |
* to determine next value list element to
|
sl@0
|
736 |
* assign each loop var. */
|
sl@0
|
737 |
ForeachVarList *varLists[1];/* An array of pointers to ForeachVarList
|
sl@0
|
738 |
* structures describing each var list. The
|
sl@0
|
739 |
* actual size of this field will be large
|
sl@0
|
740 |
* enough to numVars indexes. THIS MUST BE
|
sl@0
|
741 |
* THE LAST FIELD IN THE STRUCTURE! */
|
sl@0
|
742 |
} ForeachInfo;
|
sl@0
|
743 |
|
sl@0
|
744 |
extern AuxDataType tclForeachInfoType;
|
sl@0
|
745 |
|
sl@0
|
746 |
|
sl@0
|
747 |
/*
|
sl@0
|
748 |
*----------------------------------------------------------------
|
sl@0
|
749 |
* Procedures exported by tclBasic.c to be used within the engine.
|
sl@0
|
750 |
*----------------------------------------------------------------
|
sl@0
|
751 |
*/
|
sl@0
|
752 |
|
sl@0
|
753 |
EXTERN int TclEvalObjvInternal _ANSI_ARGS_((Tcl_Interp *interp, int objc,
|
sl@0
|
754 |
Tcl_Obj *CONST objv[], CONST char *command, int length,
|
sl@0
|
755 |
int flags));
|
sl@0
|
756 |
EXTERN int TclInterpReady _ANSI_ARGS_((Tcl_Interp *interp));
|
sl@0
|
757 |
|
sl@0
|
758 |
|
sl@0
|
759 |
/*
|
sl@0
|
760 |
*----------------------------------------------------------------
|
sl@0
|
761 |
* Procedures exported by the engine to be used by tclBasic.c
|
sl@0
|
762 |
*----------------------------------------------------------------
|
sl@0
|
763 |
*/
|
sl@0
|
764 |
|
sl@0
|
765 |
#ifndef TCL_TIP280
|
sl@0
|
766 |
EXTERN int TclCompEvalObj _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
767 |
Tcl_Obj *objPtr));
|
sl@0
|
768 |
#else
|
sl@0
|
769 |
EXTERN int TclCompEvalObj _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
770 |
Tcl_Obj *objPtr, CONST CmdFrame* invoker,
|
sl@0
|
771 |
int word));
|
sl@0
|
772 |
#endif
|
sl@0
|
773 |
|
sl@0
|
774 |
/*
|
sl@0
|
775 |
*----------------------------------------------------------------
|
sl@0
|
776 |
* Procedures shared among Tcl bytecode compilation and execution
|
sl@0
|
777 |
* modules but not used outside:
|
sl@0
|
778 |
*----------------------------------------------------------------
|
sl@0
|
779 |
*/
|
sl@0
|
780 |
|
sl@0
|
781 |
EXTERN void TclCleanupByteCode _ANSI_ARGS_((ByteCode *codePtr));
|
sl@0
|
782 |
EXTERN int TclCompileCmdWord _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
783 |
Tcl_Token *tokenPtr, int count,
|
sl@0
|
784 |
CompileEnv *envPtr));
|
sl@0
|
785 |
EXTERN int TclCompileExpr _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
786 |
CONST char *script, int numBytes,
|
sl@0
|
787 |
CompileEnv *envPtr));
|
sl@0
|
788 |
EXTERN int TclCompileExprWords _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
789 |
Tcl_Token *tokenPtr, int numWords,
|
sl@0
|
790 |
CompileEnv *envPtr));
|
sl@0
|
791 |
EXTERN int TclCompileScript _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
792 |
CONST char *script, int numBytes, int nested,
|
sl@0
|
793 |
CompileEnv *envPtr));
|
sl@0
|
794 |
EXTERN int TclCompileTokens _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
795 |
Tcl_Token *tokenPtr, int count,
|
sl@0
|
796 |
CompileEnv *envPtr));
|
sl@0
|
797 |
EXTERN int TclCreateAuxData _ANSI_ARGS_((ClientData clientData,
|
sl@0
|
798 |
AuxDataType *typePtr, CompileEnv *envPtr));
|
sl@0
|
799 |
EXTERN int TclCreateExceptRange _ANSI_ARGS_((
|
sl@0
|
800 |
ExceptionRangeType type, CompileEnv *envPtr));
|
sl@0
|
801 |
EXTERN ExecEnv * TclCreateExecEnv _ANSI_ARGS_((Tcl_Interp *interp));
|
sl@0
|
802 |
EXTERN void TclDeleteExecEnv _ANSI_ARGS_((ExecEnv *eePtr));
|
sl@0
|
803 |
EXTERN void TclDeleteLiteralTable _ANSI_ARGS_((
|
sl@0
|
804 |
Tcl_Interp *interp, LiteralTable *tablePtr));
|
sl@0
|
805 |
EXTERN void TclEmitForwardJump _ANSI_ARGS_((CompileEnv *envPtr,
|
sl@0
|
806 |
TclJumpType jumpType, JumpFixup *jumpFixupPtr));
|
sl@0
|
807 |
EXTERN ExceptionRange * TclGetExceptionRangeForPc _ANSI_ARGS_((
|
sl@0
|
808 |
unsigned char *pc, int catchOnly,
|
sl@0
|
809 |
ByteCode* codePtr));
|
sl@0
|
810 |
EXTERN void TclExpandJumpFixupArray _ANSI_ARGS_((
|
sl@0
|
811 |
JumpFixupArray *fixupArrayPtr));
|
sl@0
|
812 |
EXTERN void TclFinalizeAuxDataTypeTable _ANSI_ARGS_((void));
|
sl@0
|
813 |
EXTERN int TclFindCompiledLocal _ANSI_ARGS_((CONST char *name,
|
sl@0
|
814 |
int nameChars, int create, int flags,
|
sl@0
|
815 |
Proc *procPtr));
|
sl@0
|
816 |
EXTERN LiteralEntry * TclLookupLiteralEntry _ANSI_ARGS_((
|
sl@0
|
817 |
Tcl_Interp *interp, Tcl_Obj *objPtr));
|
sl@0
|
818 |
EXTERN int TclFixupForwardJump _ANSI_ARGS_((
|
sl@0
|
819 |
CompileEnv *envPtr, JumpFixup *jumpFixupPtr,
|
sl@0
|
820 |
int jumpDist, int distThreshold));
|
sl@0
|
821 |
EXTERN void TclFreeCompileEnv _ANSI_ARGS_((CompileEnv *envPtr));
|
sl@0
|
822 |
EXTERN void TclFreeJumpFixupArray _ANSI_ARGS_((
|
sl@0
|
823 |
JumpFixupArray *fixupArrayPtr));
|
sl@0
|
824 |
EXTERN void TclInitAuxDataTypeTable _ANSI_ARGS_((void));
|
sl@0
|
825 |
EXTERN void TclInitByteCodeObj _ANSI_ARGS_((Tcl_Obj *objPtr,
|
sl@0
|
826 |
CompileEnv *envPtr));
|
sl@0
|
827 |
EXTERN void TclInitCompilation _ANSI_ARGS_((void));
|
sl@0
|
828 |
#ifndef TCL_TIP280
|
sl@0
|
829 |
EXTERN void TclInitCompileEnv _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
830 |
CompileEnv *envPtr, char *string,
|
sl@0
|
831 |
int numBytes));
|
sl@0
|
832 |
#else
|
sl@0
|
833 |
EXTERN void TclInitCompileEnv _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
834 |
CompileEnv *envPtr, char *string,
|
sl@0
|
835 |
int numBytes, CONST CmdFrame* invoker, int word));
|
sl@0
|
836 |
#endif
|
sl@0
|
837 |
EXTERN void TclInitJumpFixupArray _ANSI_ARGS_((
|
sl@0
|
838 |
JumpFixupArray *fixupArrayPtr));
|
sl@0
|
839 |
EXTERN void TclInitLiteralTable _ANSI_ARGS_((
|
sl@0
|
840 |
LiteralTable *tablePtr));
|
sl@0
|
841 |
#ifdef TCL_COMPILE_STATS
|
sl@0
|
842 |
EXTERN char * TclLiteralStats _ANSI_ARGS_((
|
sl@0
|
843 |
LiteralTable *tablePtr));
|
sl@0
|
844 |
EXTERN int TclLog2 _ANSI_ARGS_((int value));
|
sl@0
|
845 |
#endif
|
sl@0
|
846 |
#ifdef TCL_COMPILE_DEBUG
|
sl@0
|
847 |
EXTERN void TclPrintByteCodeObj _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
848 |
Tcl_Obj *objPtr));
|
sl@0
|
849 |
#endif
|
sl@0
|
850 |
EXTERN int TclPrintInstruction _ANSI_ARGS_((ByteCode* codePtr,
|
sl@0
|
851 |
unsigned char *pc));
|
sl@0
|
852 |
EXTERN void TclPrintObject _ANSI_ARGS_((FILE *outFile,
|
sl@0
|
853 |
Tcl_Obj *objPtr, int maxChars));
|
sl@0
|
854 |
EXTERN void TclPrintSource _ANSI_ARGS_((FILE *outFile,
|
sl@0
|
855 |
CONST char *string, int maxChars));
|
sl@0
|
856 |
EXTERN void TclRegisterAuxDataType _ANSI_ARGS_((AuxDataType *typePtr));
|
sl@0
|
857 |
EXTERN int TclRegisterLiteral _ANSI_ARGS_((CompileEnv *envPtr,
|
sl@0
|
858 |
char *bytes, int length, int onHeap));
|
sl@0
|
859 |
EXTERN void TclReleaseLiteral _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
860 |
Tcl_Obj *objPtr));
|
sl@0
|
861 |
EXTERN void TclSetCmdNameObj _ANSI_ARGS_((Tcl_Interp *interp,
|
sl@0
|
862 |
Tcl_Obj *objPtr, Command *cmdPtr));
|
sl@0
|
863 |
#ifdef TCL_COMPILE_DEBUG
|
sl@0
|
864 |
EXTERN void TclVerifyGlobalLiteralTable _ANSI_ARGS_((
|
sl@0
|
865 |
Interp *iPtr));
|
sl@0
|
866 |
EXTERN void TclVerifyLocalLiteralTable _ANSI_ARGS_((
|
sl@0
|
867 |
CompileEnv *envPtr));
|
sl@0
|
868 |
#endif
|
sl@0
|
869 |
EXTERN int TclCompileVariableCmd _ANSI_ARGS_((
|
sl@0
|
870 |
Tcl_Interp *interp, Tcl_Parse *parsePtr, CompileEnv *envPtr));
|
sl@0
|
871 |
|
sl@0
|
872 |
/*
|
sl@0
|
873 |
*----------------------------------------------------------------
|
sl@0
|
874 |
* Macros used by Tcl bytecode compilation and execution modules
|
sl@0
|
875 |
* inside the Tcl core but not used outside.
|
sl@0
|
876 |
*----------------------------------------------------------------
|
sl@0
|
877 |
*/
|
sl@0
|
878 |
|
sl@0
|
879 |
/*
|
sl@0
|
880 |
* Form of TclRegisterLiteral with onHeap == 0.
|
sl@0
|
881 |
* In that case, it is safe to cast away CONSTness, and it
|
sl@0
|
882 |
* is cleanest to do that here, all in one place.
|
sl@0
|
883 |
*/
|
sl@0
|
884 |
|
sl@0
|
885 |
#define TclRegisterNewLiteral(envPtr, bytes, length) \
|
sl@0
|
886 |
TclRegisterLiteral(envPtr, (char *)(bytes), length, /*onHeap*/ 0)
|
sl@0
|
887 |
|
sl@0
|
888 |
/*
|
sl@0
|
889 |
* Macro used to update the stack requirements.
|
sl@0
|
890 |
* It is called by the macros TclEmitOpCode, TclEmitInst1 and
|
sl@0
|
891 |
* TclEmitInst4.
|
sl@0
|
892 |
* Remark that the very last instruction of a bytecode always
|
sl@0
|
893 |
* reduces the stack level: INST_DONE or INST_POP, so that the
|
sl@0
|
894 |
* maxStackdepth is always updated.
|
sl@0
|
895 |
*/
|
sl@0
|
896 |
|
sl@0
|
897 |
#define TclUpdateStackReqs(op, i, envPtr) \
|
sl@0
|
898 |
{\
|
sl@0
|
899 |
int delta = tclInstructionTable[(op)].stackEffect;\
|
sl@0
|
900 |
if (delta) {\
|
sl@0
|
901 |
if (delta < 0) {\
|
sl@0
|
902 |
if((envPtr)->maxStackDepth < (envPtr)->currStackDepth) {\
|
sl@0
|
903 |
(envPtr)->maxStackDepth = (envPtr)->currStackDepth;\
|
sl@0
|
904 |
}\
|
sl@0
|
905 |
if (delta == INT_MIN) {\
|
sl@0
|
906 |
delta = 1 - (i);\
|
sl@0
|
907 |
}\
|
sl@0
|
908 |
}\
|
sl@0
|
909 |
(envPtr)->currStackDepth += delta;\
|
sl@0
|
910 |
}\
|
sl@0
|
911 |
}
|
sl@0
|
912 |
|
sl@0
|
913 |
/*
|
sl@0
|
914 |
* Macro to emit an opcode byte into a CompileEnv's code array.
|
sl@0
|
915 |
* The ANSI C "prototype" for this macro is:
|
sl@0
|
916 |
*
|
sl@0
|
917 |
* EXTERN void TclEmitOpcode _ANSI_ARGS_((unsigned char op,
|
sl@0
|
918 |
* CompileEnv *envPtr));
|
sl@0
|
919 |
*/
|
sl@0
|
920 |
|
sl@0
|
921 |
#define TclEmitOpcode(op, envPtr) \
|
sl@0
|
922 |
if ((envPtr)->codeNext == (envPtr)->codeEnd) \
|
sl@0
|
923 |
TclExpandCodeArray(envPtr); \
|
sl@0
|
924 |
*(envPtr)->codeNext++ = (unsigned char) (op);\
|
sl@0
|
925 |
TclUpdateStackReqs(op, 0, envPtr)
|
sl@0
|
926 |
|
sl@0
|
927 |
/*
|
sl@0
|
928 |
* Macro to emit an integer operand.
|
sl@0
|
929 |
* The ANSI C "prototype" for this macro is:
|
sl@0
|
930 |
*
|
sl@0
|
931 |
* EXTERN void TclEmitInt1 _ANSI_ARGS_((int i, CompileEnv *envPtr));
|
sl@0
|
932 |
*/
|
sl@0
|
933 |
|
sl@0
|
934 |
#define TclEmitInt1(i, envPtr) \
|
sl@0
|
935 |
if ((envPtr)->codeNext == (envPtr)->codeEnd) \
|
sl@0
|
936 |
TclExpandCodeArray(envPtr); \
|
sl@0
|
937 |
*(envPtr)->codeNext++ = (unsigned char) ((unsigned int) (i))
|
sl@0
|
938 |
|
sl@0
|
939 |
/*
|
sl@0
|
940 |
* Macros to emit an instruction with signed or unsigned integer operands.
|
sl@0
|
941 |
* Four byte integers are stored in "big-endian" order with the high order
|
sl@0
|
942 |
* byte stored at the lowest address.
|
sl@0
|
943 |
* The ANSI C "prototypes" for these macros are:
|
sl@0
|
944 |
*
|
sl@0
|
945 |
* EXTERN void TclEmitInstInt1 _ANSI_ARGS_((unsigned char op, int i,
|
sl@0
|
946 |
* CompileEnv *envPtr));
|
sl@0
|
947 |
* EXTERN void TclEmitInstInt4 _ANSI_ARGS_((unsigned char op, int i,
|
sl@0
|
948 |
* CompileEnv *envPtr));
|
sl@0
|
949 |
*/
|
sl@0
|
950 |
|
sl@0
|
951 |
|
sl@0
|
952 |
#define TclEmitInstInt1(op, i, envPtr) \
|
sl@0
|
953 |
if (((envPtr)->codeNext + 2) > (envPtr)->codeEnd) { \
|
sl@0
|
954 |
TclExpandCodeArray(envPtr); \
|
sl@0
|
955 |
} \
|
sl@0
|
956 |
*(envPtr)->codeNext++ = (unsigned char) (op); \
|
sl@0
|
957 |
*(envPtr)->codeNext++ = (unsigned char) ((unsigned int) (i));\
|
sl@0
|
958 |
TclUpdateStackReqs(op, i, envPtr)
|
sl@0
|
959 |
|
sl@0
|
960 |
#define TclEmitInstInt4(op, i, envPtr) \
|
sl@0
|
961 |
if (((envPtr)->codeNext + 5) > (envPtr)->codeEnd) { \
|
sl@0
|
962 |
TclExpandCodeArray(envPtr); \
|
sl@0
|
963 |
} \
|
sl@0
|
964 |
*(envPtr)->codeNext++ = (unsigned char) (op); \
|
sl@0
|
965 |
*(envPtr)->codeNext++ = \
|
sl@0
|
966 |
(unsigned char) ((unsigned int) (i) >> 24); \
|
sl@0
|
967 |
*(envPtr)->codeNext++ = \
|
sl@0
|
968 |
(unsigned char) ((unsigned int) (i) >> 16); \
|
sl@0
|
969 |
*(envPtr)->codeNext++ = \
|
sl@0
|
970 |
(unsigned char) ((unsigned int) (i) >> 8); \
|
sl@0
|
971 |
*(envPtr)->codeNext++ = \
|
sl@0
|
972 |
(unsigned char) ((unsigned int) (i) );\
|
sl@0
|
973 |
TclUpdateStackReqs(op, i, envPtr)
|
sl@0
|
974 |
|
sl@0
|
975 |
/*
|
sl@0
|
976 |
* Macro to push a Tcl object onto the Tcl evaluation stack. It emits the
|
sl@0
|
977 |
* object's one or four byte array index into the CompileEnv's code
|
sl@0
|
978 |
* array. These support, respectively, a maximum of 256 (2**8) and 2**32
|
sl@0
|
979 |
* objects in a CompileEnv. The ANSI C "prototype" for this macro is:
|
sl@0
|
980 |
*
|
sl@0
|
981 |
* EXTERN void TclEmitPush _ANSI_ARGS_((int objIndex, CompileEnv *envPtr));
|
sl@0
|
982 |
*/
|
sl@0
|
983 |
|
sl@0
|
984 |
#define TclEmitPush(objIndex, envPtr) \
|
sl@0
|
985 |
{\
|
sl@0
|
986 |
register int objIndexCopy = (objIndex);\
|
sl@0
|
987 |
if (objIndexCopy <= 255) { \
|
sl@0
|
988 |
TclEmitInstInt1(INST_PUSH1, objIndexCopy, (envPtr)); \
|
sl@0
|
989 |
} else { \
|
sl@0
|
990 |
TclEmitInstInt4(INST_PUSH4, objIndexCopy, (envPtr)); \
|
sl@0
|
991 |
}\
|
sl@0
|
992 |
}
|
sl@0
|
993 |
|
sl@0
|
994 |
/*
|
sl@0
|
995 |
* Macros to update a (signed or unsigned) integer starting at a pointer.
|
sl@0
|
996 |
* The two variants depend on the number of bytes. The ANSI C "prototypes"
|
sl@0
|
997 |
* for these macros are:
|
sl@0
|
998 |
*
|
sl@0
|
999 |
* EXTERN void TclStoreInt1AtPtr _ANSI_ARGS_((int i, unsigned char *p));
|
sl@0
|
1000 |
* EXTERN void TclStoreInt4AtPtr _ANSI_ARGS_((int i, unsigned char *p));
|
sl@0
|
1001 |
*/
|
sl@0
|
1002 |
|
sl@0
|
1003 |
#define TclStoreInt1AtPtr(i, p) \
|
sl@0
|
1004 |
*(p) = (unsigned char) ((unsigned int) (i))
|
sl@0
|
1005 |
|
sl@0
|
1006 |
#define TclStoreInt4AtPtr(i, p) \
|
sl@0
|
1007 |
*(p) = (unsigned char) ((unsigned int) (i) >> 24); \
|
sl@0
|
1008 |
*(p+1) = (unsigned char) ((unsigned int) (i) >> 16); \
|
sl@0
|
1009 |
*(p+2) = (unsigned char) ((unsigned int) (i) >> 8); \
|
sl@0
|
1010 |
*(p+3) = (unsigned char) ((unsigned int) (i) )
|
sl@0
|
1011 |
|
sl@0
|
1012 |
/*
|
sl@0
|
1013 |
* Macros to update instructions at a particular pc with a new op code
|
sl@0
|
1014 |
* and a (signed or unsigned) int operand. The ANSI C "prototypes" for
|
sl@0
|
1015 |
* these macros are:
|
sl@0
|
1016 |
*
|
sl@0
|
1017 |
* EXTERN void TclUpdateInstInt1AtPc _ANSI_ARGS_((unsigned char op, int i,
|
sl@0
|
1018 |
* unsigned char *pc));
|
sl@0
|
1019 |
* EXTERN void TclUpdateInstInt4AtPc _ANSI_ARGS_((unsigned char op, int i,
|
sl@0
|
1020 |
* unsigned char *pc));
|
sl@0
|
1021 |
*/
|
sl@0
|
1022 |
|
sl@0
|
1023 |
#define TclUpdateInstInt1AtPc(op, i, pc) \
|
sl@0
|
1024 |
*(pc) = (unsigned char) (op); \
|
sl@0
|
1025 |
TclStoreInt1AtPtr((i), ((pc)+1))
|
sl@0
|
1026 |
|
sl@0
|
1027 |
#define TclUpdateInstInt4AtPc(op, i, pc) \
|
sl@0
|
1028 |
*(pc) = (unsigned char) (op); \
|
sl@0
|
1029 |
TclStoreInt4AtPtr((i), ((pc)+1))
|
sl@0
|
1030 |
|
sl@0
|
1031 |
/*
|
sl@0
|
1032 |
* Macros to get a signed integer (GET_INT{1,2}) or an unsigned int
|
sl@0
|
1033 |
* (GET_UINT{1,2}) from a pointer. There are two variants for each
|
sl@0
|
1034 |
* return type that depend on the number of bytes fetched.
|
sl@0
|
1035 |
* The ANSI C "prototypes" for these macros are:
|
sl@0
|
1036 |
*
|
sl@0
|
1037 |
* EXTERN int TclGetInt1AtPtr _ANSI_ARGS_((unsigned char *p));
|
sl@0
|
1038 |
* EXTERN int TclGetInt4AtPtr _ANSI_ARGS_((unsigned char *p));
|
sl@0
|
1039 |
* EXTERN unsigned int TclGetUInt1AtPtr _ANSI_ARGS_((unsigned char *p));
|
sl@0
|
1040 |
* EXTERN unsigned int TclGetUInt4AtPtr _ANSI_ARGS_((unsigned char *p));
|
sl@0
|
1041 |
*/
|
sl@0
|
1042 |
|
sl@0
|
1043 |
/*
|
sl@0
|
1044 |
* The TclGetInt1AtPtr macro is tricky because we want to do sign
|
sl@0
|
1045 |
* extension on the 1-byte value. Unfortunately the "char" type isn't
|
sl@0
|
1046 |
* signed on all platforms so sign-extension doesn't always happen
|
sl@0
|
1047 |
* automatically. Sometimes we can explicitly declare the pointer to be
|
sl@0
|
1048 |
* signed, but other times we have to explicitly sign-extend the value
|
sl@0
|
1049 |
* in software.
|
sl@0
|
1050 |
*/
|
sl@0
|
1051 |
|
sl@0
|
1052 |
#ifndef __CHAR_UNSIGNED__
|
sl@0
|
1053 |
# define TclGetInt1AtPtr(p) ((int) *((char *) p))
|
sl@0
|
1054 |
#else
|
sl@0
|
1055 |
# ifdef HAVE_SIGNED_CHAR
|
sl@0
|
1056 |
# define TclGetInt1AtPtr(p) ((int) *((signed char *) p))
|
sl@0
|
1057 |
# else
|
sl@0
|
1058 |
# define TclGetInt1AtPtr(p) (((int) *((char *) p)) \
|
sl@0
|
1059 |
| ((*(p) & 0200) ? (-256) : 0))
|
sl@0
|
1060 |
# endif
|
sl@0
|
1061 |
#endif
|
sl@0
|
1062 |
|
sl@0
|
1063 |
#define TclGetInt4AtPtr(p) (((int) TclGetInt1AtPtr(p) << 24) | \
|
sl@0
|
1064 |
(*((p)+1) << 16) | \
|
sl@0
|
1065 |
(*((p)+2) << 8) | \
|
sl@0
|
1066 |
(*((p)+3)))
|
sl@0
|
1067 |
|
sl@0
|
1068 |
#define TclGetUInt1AtPtr(p) ((unsigned int) *(p))
|
sl@0
|
1069 |
#define TclGetUInt4AtPtr(p) ((unsigned int) (*(p) << 24) | \
|
sl@0
|
1070 |
(*((p)+1) << 16) | \
|
sl@0
|
1071 |
(*((p)+2) << 8) | \
|
sl@0
|
1072 |
(*((p)+3)))
|
sl@0
|
1073 |
|
sl@0
|
1074 |
/*
|
sl@0
|
1075 |
* Macros used to compute the minimum and maximum of two integers.
|
sl@0
|
1076 |
* The ANSI C "prototypes" for these macros are:
|
sl@0
|
1077 |
*
|
sl@0
|
1078 |
* EXTERN int TclMin _ANSI_ARGS_((int i, int j));
|
sl@0
|
1079 |
* EXTERN int TclMax _ANSI_ARGS_((int i, int j));
|
sl@0
|
1080 |
*/
|
sl@0
|
1081 |
|
sl@0
|
1082 |
#define TclMin(i, j) ((((int) i) < ((int) j))? (i) : (j))
|
sl@0
|
1083 |
#define TclMax(i, j) ((((int) i) > ((int) j))? (i) : (j))
|
sl@0
|
1084 |
|
sl@0
|
1085 |
# undef TCL_STORAGE_CLASS
|
sl@0
|
1086 |
# define TCL_STORAGE_CLASS DLLIMPORT
|
sl@0
|
1087 |
|
sl@0
|
1088 |
#endif /* _TCLCOMPILATION */
|