Fork me on GitHub

source: git/external/tcl/tclInt.h@ 282f591

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 282f591 was d7d2da3, checked in by pavel <pavel@…>, 12 years ago

move branches/ModularDelphes to trunk

  • Property mode set to 100644
File size: 76.9 KB
RevLine 
[d7d2da3]1/*
2 * tclInt.h --
3 *
4 * Declarations of things used internally by the Tcl interpreter.
5 *
6 * Copyright (c) 1987-1993 The Regents of the University of California.
7 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
8 * Copyright (c) 1993-1997 Lucent Technologies.
9 * Copyright (c) 1998-1999 by Scriptics Corporation.
10 *
11 * See the file "license.terms" for information on usage and redistribution
12 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 *
14 * RCS: @(#) $Id: tclInt.h,v 1.1 2008-06-04 13:58:07 demin Exp $
15 */
16
17#ifndef _TCLINT
18#define _TCLINT
19
20/*
21 * Common include files needed by most of the Tcl source files are
22 * included here, so that system-dependent personalizations for the
23 * include files only have to be made in once place. This results
24 * in a few extra includes, but greater modularity. The order of
25 * the three groups of #includes is important. For example, stdio.h
26 * is needed by tcl.h, and the _ANSI_ARGS_ declaration in tcl.h is
27 * needed by stdlib.h in some configurations.
28 */
29
30#include <stdio.h>
31
32#ifndef _TCL
33#include "tcl.h"
34#endif
35
36#include <ctype.h>
37#ifdef NO_LIMITS_H
38# include "../compat/limits.h"
39#else
40# include <limits.h>
41#endif
42#ifdef NO_STDLIB_H
43# include "../compat/stdlib.h"
44#else
45# include <stdlib.h>
46#endif
47#ifdef NO_STRING_H
48#include "../compat/string.h"
49#else
50#include <string.h>
51#endif
52#if defined(__STDC__) || defined(HAS_STDARG)
53# include <stdarg.h>
54#else
55# include <varargs.h>
56#endif
57
58#ifdef BUILD_tcl
59# undef TCL_STORAGE_CLASS
60# define TCL_STORAGE_CLASS DLLEXPORT
61#endif
62
63/*
64 * The following procedures allow namespaces to be customized to
65 * support special name resolution rules for commands/variables.
66 *
67 */
68
69struct Tcl_ResolvedVarInfo;
70
71typedef Tcl_Var (Tcl_ResolveRuntimeVarProc) _ANSI_ARGS_((
72 Tcl_Interp* interp, struct Tcl_ResolvedVarInfo *vinfoPtr));
73
74typedef void (Tcl_ResolveVarDeleteProc) _ANSI_ARGS_((
75 struct Tcl_ResolvedVarInfo *vinfoPtr));
76
77/*
78 * The following structure encapsulates the routines needed to resolve a
79 * variable reference at runtime. Any variable specific state will typically
80 * be appended to this structure.
81 */
82
83
84typedef struct Tcl_ResolvedVarInfo {
85 Tcl_ResolveRuntimeVarProc *fetchProc;
86 Tcl_ResolveVarDeleteProc *deleteProc;
87} Tcl_ResolvedVarInfo;
88
89
90
91typedef int (Tcl_ResolveCompiledVarProc) _ANSI_ARGS_((
92 Tcl_Interp* interp, char* name, int length,
93 Tcl_Namespace *context, Tcl_ResolvedVarInfo **rPtr));
94
95typedef int (Tcl_ResolveVarProc) _ANSI_ARGS_((
96 Tcl_Interp* interp, char* name, Tcl_Namespace *context,
97 int flags, Tcl_Var *rPtr));
98
99typedef int (Tcl_ResolveCmdProc) _ANSI_ARGS_((Tcl_Interp* interp,
100 char* name, Tcl_Namespace *context, int flags,
101 Tcl_Command *rPtr));
102
103typedef struct Tcl_ResolverInfo {
104 Tcl_ResolveCmdProc *cmdResProc; /* Procedure handling command name
105 * resolution. */
106 Tcl_ResolveVarProc *varResProc; /* Procedure handling variable name
107 * resolution for variables that
108 * can only be handled at runtime. */
109 Tcl_ResolveCompiledVarProc *compiledVarResProc;
110 /* Procedure handling variable name
111 * resolution at compile time. */
112} Tcl_ResolverInfo;
113
114/*
115 *----------------------------------------------------------------
116 * Data structures related to namespaces.
117 *----------------------------------------------------------------
118 */
119
120/*
121 * The structure below defines a namespace.
122 * Note: the first five fields must match exactly the fields in a
123 * Tcl_Namespace structure (see tcl.h). If you change one, be sure to
124 * change the other.
125 */
126
127typedef struct Namespace {
128 char *name; /* The namespace's simple (unqualified)
129 * name. This contains no ::'s. The name of
130 * the global namespace is "" although "::"
131 * is an synonym. */
132 char *fullName; /* The namespace's fully qualified name.
133 * This starts with ::. */
134 ClientData clientData; /* An arbitrary value associated with this
135 * namespace. */
136 Tcl_NamespaceDeleteProc *deleteProc;
137 /* Procedure invoked when deleting the
138 * namespace to, e.g., free clientData. */
139 struct Namespace *parentPtr; /* Points to the namespace that contains
140 * this one. NULL if this is the global
141 * namespace. */
142 Tcl_HashTable childTable; /* Contains any child namespaces. Indexed
143 * by strings; values have type
144 * (Namespace *). */
145 long nsId; /* Unique id for the namespace. */
146 Tcl_Interp *interp; /* The interpreter containing this
147 * namespace. */
148 int flags; /* OR-ed combination of the namespace
149 * status flags NS_DYING and NS_DEAD
150 * listed below. */
151 int activationCount; /* Number of "activations" or active call
152 * frames for this namespace that are on
153 * the Tcl call stack. The namespace won't
154 * be freed until activationCount becomes
155 * zero. */
156 int refCount; /* Count of references by namespaceName *
157 * objects. The namespace can't be freed
158 * until refCount becomes zero. */
159 Tcl_HashTable cmdTable; /* Contains all the commands currently
160 * registered in the namespace. Indexed by
161 * strings; values have type (Command *).
162 * Commands imported by Tcl_Import have
163 * Command structures that point (via an
164 * ImportedCmdRef structure) to the
165 * Command structure in the source
166 * namespace's command table. */
167 Tcl_HashTable varTable; /* Contains all the (global) variables
168 * currently in this namespace. Indexed
169 * by strings; values have type (Var *). */
170 char **exportArrayPtr; /* Points to an array of string patterns
171 * specifying which commands are exported.
172 * A pattern may include "string match"
173 * style wildcard characters to specify
174 * multiple commands; however, no namespace
175 * qualifiers are allowed. NULL if no
176 * export patterns are registered. */
177 int numExportPatterns; /* Number of export patterns currently
178 * registered using "namespace export". */
179 int maxExportPatterns; /* Mumber of export patterns for which
180 * space is currently allocated. */
181 int cmdRefEpoch; /* Incremented if a newly added command
182 * shadows a command for which this
183 * namespace has already cached a Command *
184 * pointer; this causes all its cached
185 * Command* pointers to be invalidated. */
186 int resolverEpoch; /* Incremented whenever the name resolution
187 * rules change for this namespace; this
188 * invalidates all byte codes compiled in
189 * the namespace, causing the code to be
190 * recompiled under the new rules. */
191 Tcl_ResolveCmdProc *cmdResProc;
192 /* If non-null, this procedure overrides
193 * the usual command resolution mechanism
194 * in Tcl. This procedure is invoked
195 * within Tcl_FindCommand to resolve all
196 * command references within the namespace. */
197 Tcl_ResolveVarProc *varResProc;
198 /* If non-null, this procedure overrides
199 * the usual variable resolution mechanism
200 * in Tcl. This procedure is invoked
201 * within Tcl_FindNamespaceVar to resolve all
202 * variable references within the namespace
203 * at runtime. */
204 Tcl_ResolveCompiledVarProc *compiledVarResProc;
205 /* If non-null, this procedure overrides
206 * the usual variable resolution mechanism
207 * in Tcl. This procedure is invoked
208 * within LookupCompiledLocal to resolve
209 * variable references within the namespace
210 * at compile time. */
211} Namespace;
212
213/*
214 * Flags used to represent the status of a namespace:
215 *
216 * NS_DYING - 1 means Tcl_DeleteNamespace has been called to delete the
217 * namespace but there are still active call frames on the Tcl
218 * stack that refer to the namespace. When the last call frame
219 * referring to it has been popped, it's variables and command
220 * will be destroyed and it will be marked "dead" (NS_DEAD).
221 * The namespace can no longer be looked up by name.
222 * NS_DEAD - 1 means Tcl_DeleteNamespace has been called to delete the
223 * namespace and no call frames still refer to it. Its
224 * variables and command have already been destroyed. This bit
225 * allows the namespace resolution code to recognize that the
226 * namespace is "deleted". When the last namespaceName object
227 * in any byte code code unit that refers to the namespace has
228 * been freed (i.e., when the namespace's refCount is 0), the
229 * namespace's storage will be freed.
230 */
231
232#define NS_DYING 0x01
233#define NS_DEAD 0x02
234
235/*
236 * Flag passed to TclGetNamespaceForQualName to have it create all namespace
237 * components of a namespace-qualified name that cannot be found. The new
238 * namespaces are created within their specified parent. Note that this
239 * flag's value must not conflict with the values of the flags
240 * TCL_GLOBAL_ONLY, TCL_NAMESPACE_ONLY, and FIND_ONLY_NS (defined in
241 * tclNamesp.c).
242 */
243
244#define CREATE_NS_IF_UNKNOWN 0x800
245
246/*
247 *----------------------------------------------------------------
248 * Data structures related to variables. These are used primarily
249 * in tclVar.c
250 *----------------------------------------------------------------
251 */
252
253/*
254 * The following structure defines a variable trace, which is used to
255 * invoke a specific C procedure whenever certain operations are performed
256 * on a variable.
257 */
258
259typedef struct VarTrace {
260 Tcl_VarTraceProc *traceProc;/* Procedure to call when operations given
261 * by flags are performed on variable. */
262 ClientData clientData; /* Argument to pass to proc. */
263 int flags; /* What events the trace procedure is
264 * interested in: OR-ed combination of
265 * TCL_TRACE_READS, TCL_TRACE_WRITES, and
266 * TCL_TRACE_UNSETS. */
267 struct VarTrace *nextPtr; /* Next in list of traces associated with
268 * a particular variable. */
269} VarTrace;
270
271/*
272 * When a variable trace is active (i.e. its associated procedure is
273 * executing), one of the following structures is linked into a list
274 * associated with the variable's interpreter. The information in
275 * the structure is needed in order for Tcl to behave reasonably
276 * if traces are deleted while traces are active.
277 */
278
279typedef struct ActiveVarTrace {
280 struct Var *varPtr; /* Variable that's being traced. */
281 struct ActiveVarTrace *nextPtr;
282 /* Next in list of all active variable
283 * traces for the interpreter, or NULL
284 * if no more. */
285 VarTrace *nextTracePtr; /* Next trace to check after current
286 * trace procedure returns; if this
287 * trace gets deleted, must update pointer
288 * to avoid using free'd memory. */
289} ActiveVarTrace;
290
291/*
292 * The following structure describes an enumerative search in progress on
293 * an array variable; this are invoked with options to the "array"
294 * command.
295 */
296
297typedef struct ArraySearch {
298 int id; /* Integer id used to distinguish among
299 * multiple concurrent searches for the
300 * same array. */
301 struct Var *varPtr; /* Pointer to array variable that's being
302 * searched. */
303 Tcl_HashSearch search; /* Info kept by the hash module about
304 * progress through the array. */
305 Tcl_HashEntry *nextEntry; /* Non-null means this is the next element
306 * to be enumerated (it's leftover from
307 * the Tcl_FirstHashEntry call or from
308 * an "array anymore" command). NULL
309 * means must call Tcl_NextHashEntry
310 * to get value to return. */
311 struct ArraySearch *nextPtr;/* Next in list of all active searches
312 * for this variable, or NULL if this is
313 * the last one. */
314} ArraySearch;
315
316/*
317 * The structure below defines a variable, which associates a string name
318 * with a Tcl_Obj value. These structures are kept in procedure call frames
319 * (for local variables recognized by the compiler) or in the heap (for
320 * global variables and any variable not known to the compiler). For each
321 * Var structure in the heap, a hash table entry holds the variable name and
322 * a pointer to the Var structure.
323 */
324
325typedef struct Var {
326 union {
327 Tcl_Obj *objPtr; /* The variable's object value. Used for
328 * scalar variables and array elements. */
329 Tcl_HashTable *tablePtr;/* For array variables, this points to
330 * information about the hash table used
331 * to implement the associative array.
332 * Points to malloc-ed data. */
333 struct Var *linkPtr; /* If this is a global variable being
334 * referred to in a procedure, or a variable
335 * created by "upvar", this field points to
336 * the referenced variable's Var struct. */
337 } value;
338 char *name; /* NULL if the variable is in a hashtable,
339 * otherwise points to the variable's
340 * name. It is used, e.g., by TclLookupVar
341 * and "info locals". The storage for the
342 * characters of the name is not owned by
343 * the Var and must not be freed when
344 * freeing the Var. */
345 Namespace *nsPtr; /* Points to the namespace that contains
346 * this variable or NULL if the variable is
347 * a local variable in a Tcl procedure. */
348 Tcl_HashEntry *hPtr; /* If variable is in a hashtable, either the
349 * hash table entry that refers to this
350 * variable or NULL if the variable has been
351 * detached from its hash table (e.g. an
352 * array is deleted, but some of its
353 * elements are still referred to in
354 * upvars). NULL if the variable is not in a
355 * hashtable. This is used to delete an
356 * variable from its hashtable if it is no
357 * longer needed. */
358 int refCount; /* Counts number of active uses of this
359 * variable, not including its entry in the
360 * call frame or the hash table: 1 for each
361 * additional variable whose linkPtr points
362 * here, 1 for each nested trace active on
363 * variable, and 1 if the variable is a
364 * namespace variable. This record can't be
365 * deleted until refCount becomes 0. */
366 VarTrace *tracePtr; /* First in list of all traces set for this
367 * variable. */
368 ArraySearch *searchPtr; /* First in list of all searches active
369 * for this variable, or NULL if none. */
370 int flags; /* Miscellaneous bits of information about
371 * variable. See below for definitions. */
372} Var;
373
374/*
375 * Flag bits for variables. The first three (VAR_SCALAR, VAR_ARRAY, and
376 * VAR_LINK) are mutually exclusive and give the "type" of the variable.
377 * VAR_UNDEFINED is independent of the variable's type.
378 *
379 * VAR_SCALAR - 1 means this is a scalar variable and not
380 * an array or link. The "objPtr" field points
381 * to the variable's value, a Tcl object.
382 * VAR_ARRAY - 1 means this is an array variable rather
383 * than a scalar variable or link. The
384 * "tablePtr" field points to the array's
385 * hashtable for its elements.
386 * VAR_LINK - 1 means this Var structure contains a
387 * pointer to another Var structure that
388 * either has the real value or is itself
389 * another VAR_LINK pointer. Variables like
390 * this come about through "upvar" and "global"
391 * commands, or through references to variables
392 * in enclosing namespaces.
393 * VAR_UNDEFINED - 1 means that the variable is in the process
394 * of being deleted. An undefined variable
395 * logically does not exist and survives only
396 * while it has a trace, or if it is a global
397 * variable currently being used by some
398 * procedure.
399 * VAR_IN_HASHTABLE - 1 means this variable is in a hashtable and
400 * the Var structure is malloced. 0 if it is
401 * a local variable that was assigned a slot
402 * in a procedure frame by the compiler so the
403 * Var storage is part of the call frame.
404 * VAR_TRACE_ACTIVE - 1 means that trace processing is currently
405 * underway for a read or write access, so
406 * new read or write accesses should not cause
407 * trace procedures to be called and the
408 * variable can't be deleted.
409 * VAR_ARRAY_ELEMENT - 1 means that this variable is an array
410 * element, so it is not legal for it to be
411 * an array itself (the VAR_ARRAY flag had
412 * better not be set).
413 * VAR_NAMESPACE_VAR - 1 means that this variable was declared
414 * as a namespace variable. This flag ensures
415 * it persists until its namespace is
416 * destroyed or until the variable is unset;
417 * it will persist even if it has not been
418 * initialized and is marked undefined.
419 * The variable's refCount is incremented to
420 * reflect the "reference" from its namespace.
421 *
422 * The following additional flags are used with the CompiledLocal type
423 * defined below:
424 *
425 * VAR_ARGUMENT - 1 means that this variable holds a procedure
426 * argument.
427 * VAR_TEMPORARY - 1 if the local variable is an anonymous
428 * temporary variable. Temporaries have a NULL
429 * name.
430 * VAR_RESOLVED - 1 if name resolution has been done for this
431 * variable.
432 */
433
434#define VAR_SCALAR 0x1
435#define VAR_ARRAY 0x2
436#define VAR_LINK 0x4
437#define VAR_UNDEFINED 0x8
438#define VAR_IN_HASHTABLE 0x10
439#define VAR_TRACE_ACTIVE 0x20
440#define VAR_ARRAY_ELEMENT 0x40
441#define VAR_NAMESPACE_VAR 0x80
442
443#define VAR_ARGUMENT 0x100
444#define VAR_TEMPORARY 0x200
445#define VAR_RESOLVED 0x400
446
447/*
448 * Macros to ensure that various flag bits are set properly for variables.
449 * The ANSI C "prototypes" for these macros are:
450 *
451 * EXTERN void TclSetVarScalar _ANSI_ARGS_((Var *varPtr));
452 * EXTERN void TclSetVarArray _ANSI_ARGS_((Var *varPtr));
453 * EXTERN void TclSetVarLink _ANSI_ARGS_((Var *varPtr));
454 * EXTERN void TclSetVarArrayElement _ANSI_ARGS_((Var *varPtr));
455 * EXTERN void TclSetVarUndefined _ANSI_ARGS_((Var *varPtr));
456 * EXTERN void TclClearVarUndefined _ANSI_ARGS_((Var *varPtr));
457 */
458
459#define TclSetVarScalar(varPtr) \
460 (varPtr)->flags = ((varPtr)->flags & ~(VAR_ARRAY|VAR_LINK)) | VAR_SCALAR
461
462#define TclSetVarArray(varPtr) \
463 (varPtr)->flags = ((varPtr)->flags & ~(VAR_SCALAR|VAR_LINK)) | VAR_ARRAY
464
465#define TclSetVarLink(varPtr) \
466 (varPtr)->flags = ((varPtr)->flags & ~(VAR_SCALAR|VAR_ARRAY)) | VAR_LINK
467
468#define TclSetVarArrayElement(varPtr) \
469 (varPtr)->flags = ((varPtr)->flags & ~VAR_ARRAY) | VAR_ARRAY_ELEMENT
470
471#define TclSetVarUndefined(varPtr) \
472 (varPtr)->flags |= VAR_UNDEFINED
473
474#define TclClearVarUndefined(varPtr) \
475 (varPtr)->flags &= ~VAR_UNDEFINED
476
477/*
478 * Macros to read various flag bits of variables.
479 * The ANSI C "prototypes" for these macros are:
480 *
481 * EXTERN int TclIsVarScalar _ANSI_ARGS_((Var *varPtr));
482 * EXTERN int TclIsVarLink _ANSI_ARGS_((Var *varPtr));
483 * EXTERN int TclIsVarArray _ANSI_ARGS_((Var *varPtr));
484 * EXTERN int TclIsVarUndefined _ANSI_ARGS_((Var *varPtr));
485 * EXTERN int TclIsVarArrayElement _ANSI_ARGS_((Var *varPtr));
486 * EXTERN int TclIsVarTemporary _ANSI_ARGS_((Var *varPtr));
487 * EXTERN int TclIsVarArgument _ANSI_ARGS_((Var *varPtr));
488 * EXTERN int TclIsVarResolved _ANSI_ARGS_((Var *varPtr));
489 */
490
491#define TclIsVarScalar(varPtr) \
492 ((varPtr)->flags & VAR_SCALAR)
493
494#define TclIsVarLink(varPtr) \
495 ((varPtr)->flags & VAR_LINK)
496
497#define TclIsVarArray(varPtr) \
498 ((varPtr)->flags & VAR_ARRAY)
499
500#define TclIsVarUndefined(varPtr) \
501 ((varPtr)->flags & VAR_UNDEFINED)
502
503#define TclIsVarArrayElement(varPtr) \
504 ((varPtr)->flags & VAR_ARRAY_ELEMENT)
505
506#define TclIsVarTemporary(varPtr) \
507 ((varPtr)->flags & VAR_TEMPORARY)
508
509#define TclIsVarArgument(varPtr) \
510 ((varPtr)->flags & VAR_ARGUMENT)
511
512#define TclIsVarResolved(varPtr) \
513 ((varPtr)->flags & VAR_RESOLVED)
514
515/*
516 *----------------------------------------------------------------
517 * Data structures related to procedures. These are used primarily
518 * in tclProc.c, tclCompile.c, and tclExecute.c.
519 *----------------------------------------------------------------
520 */
521
522/*
523 * Forward declaration to prevent an error when the forward reference to
524 * Command is encountered in the Proc and ImportRef types declared below.
525 */
526
527struct Command;
528
529/*
530 * The variable-length structure below describes a local variable of a
531 * procedure that was recognized by the compiler. These variables have a
532 * name, an element in the array of compiler-assigned local variables in the
533 * procedure's call frame, and various other items of information. If the
534 * local variable is a formal argument, it may also have a default value.
535 * The compiler can't recognize local variables whose names are
536 * expressions (these names are only known at runtime when the expressions
537 * are evaluated) or local variables that are created as a result of an
538 * "upvar" or "uplevel" command. These other local variables are kept
539 * separately in a hash table in the call frame.
540 */
541
542typedef struct CompiledLocal {
543 struct CompiledLocal *nextPtr;
544 /* Next compiler-recognized local variable
545 * for this procedure, or NULL if this is
546 * the last local. */
547 int nameLength; /* The number of characters in local
548 * variable's name. Used to speed up
549 * variable lookups. */
550 int frameIndex; /* Index in the array of compiler-assigned
551 * variables in the procedure call frame. */
552 int flags; /* Flag bits for the local variable. Same as
553 * the flags for the Var structure above,
554 * although only VAR_SCALAR, VAR_ARRAY,
555 * VAR_LINK, VAR_ARGUMENT, VAR_TEMPORARY, and
556 * VAR_RESOLVED make sense. */
557 Tcl_Obj *defValuePtr; /* Pointer to the default value of an
558 * argument, if any. NULL if not an argument
559 * or, if an argument, no default value. */
560 Tcl_ResolvedVarInfo *resolveInfo;
561 /* Customized variable resolution info
562 * supplied by the Tcl_ResolveCompiledVarProc
563 * associated with a namespace. Each variable
564 * is marked by a unique ClientData tag
565 * during compilation, and that same tag
566 * is used to find the variable at runtime. */
567 char name[4]; /* Name of the local variable starts here.
568 * If the name is NULL, this will just be
569 * '\0'. The actual size of this field will
570 * be large enough to hold the name. MUST
571 * BE THE LAST FIELD IN THE STRUCTURE! */
572} CompiledLocal;
573
574/*
575 * The structure below defines a command procedure, which consists of a
576 * collection of Tcl commands plus information about arguments and other
577 * local variables recognized at compile time.
578 */
579
580typedef struct Proc {
581 struct Interp *iPtr; /* Interpreter for which this command
582 * is defined. */
583 int refCount; /* Reference count: 1 if still present
584 * in command table plus 1 for each call
585 * to the procedure that is currently
586 * active. This structure can be freed
587 * when refCount becomes zero. */
588 struct Command *cmdPtr; /* Points to the Command structure for
589 * this procedure. This is used to get
590 * the namespace in which to execute
591 * the procedure. */
592 Tcl_Obj *bodyPtr; /* Points to the ByteCode object for
593 * procedure's body command. */
594 int numArgs; /* Number of formal parameters. */
595 int numCompiledLocals; /* Count of local variables recognized by
596 * the compiler including arguments and
597 * temporaries. */
598 CompiledLocal *firstLocalPtr; /* Pointer to first of the procedure's
599 * compiler-allocated local variables, or
600 * NULL if none. The first numArgs entries
601 * in this list describe the procedure's
602 * formal arguments. */
603 CompiledLocal *lastLocalPtr; /* Pointer to the last allocated local
604 * variable or NULL if none. This has
605 * frame index (numCompiledLocals-1). */
606} Proc;
607
608/*
609 * The structure below defines a command trace. This is used to allow Tcl
610 * clients to find out whenever a command is about to be executed.
611 */
612
613typedef struct Trace {
614 int level; /* Only trace commands at nesting level
615 * less than or equal to this. */
616 Tcl_CmdTraceProc *proc; /* Procedure to call to trace command. */
617 ClientData clientData; /* Arbitrary value to pass to proc. */
618 struct Trace *nextPtr; /* Next in list of traces for this interp. */
619} Trace;
620
621/*
622 * The structure below defines an entry in the assocData hash table which
623 * is associated with an interpreter. The entry contains a pointer to a
624 * function to call when the interpreter is deleted, and a pointer to
625 * a user-defined piece of data.
626 */
627
628typedef struct AssocData {
629 Tcl_InterpDeleteProc *proc; /* Proc to call when deleting. */
630 ClientData clientData; /* Value to pass to proc. */
631} AssocData;
632
633/*
634 * The structure below defines a call frame. A call frame defines a naming
635 * context for a procedure call: its local naming scope (for local
636 * variables) and its global naming scope (a namespace, perhaps the global
637 * :: namespace). A call frame can also define the naming context for a
638 * namespace eval or namespace inscope command: the namespace in which the
639 * command's code should execute. The Tcl_CallFrame structures exist only
640 * while procedures or namespace eval/inscope's are being executed, and
641 * provide a kind of Tcl call stack.
642 *
643 * WARNING!! The structure definition must be kept consistent with the
644 * Tcl_CallFrame structure in tcl.h. If you change one, change the other.
645 */
646
647typedef struct CallFrame {
648 Namespace *nsPtr; /* Points to the namespace used to resolve
649 * commands and global variables. */
650 int isProcCallFrame; /* If nonzero, the frame was pushed to
651 * execute a Tcl procedure and may have
652 * local vars. If 0, the frame was pushed
653 * to execute a namespace command and var
654 * references are treated as references to
655 * namespace vars; varTablePtr and
656 * compiledLocals are ignored. */
657 int objc; /* This and objv below describe the
658 * arguments for this procedure call. */
659 Tcl_Obj *CONST *objv; /* Array of argument objects. */
660 struct CallFrame *callerPtr;
661 /* Value of interp->framePtr when this
662 * procedure was invoked (i.e. next higher
663 * in stack of all active procedures). */
664 struct CallFrame *callerVarPtr;
665 /* Value of interp->varFramePtr when this
666 * procedure was invoked (i.e. determines
667 * variable scoping within caller). Same
668 * as callerPtr unless an "uplevel" command
669 * or something equivalent was active in
670 * the caller). */
671 int level; /* Level of this procedure, for "uplevel"
672 * purposes (i.e. corresponds to nesting of
673 * callerVarPtr's, not callerPtr's). 1 for
674 * outermost procedure, 0 for top-level. */
675 Proc *procPtr; /* Points to the structure defining the
676 * called procedure. Used to get information
677 * such as the number of compiled local
678 * variables (local variables assigned
679 * entries ["slots"] in the compiledLocals
680 * array below). */
681 Tcl_HashTable *varTablePtr; /* Hash table containing local variables not
682 * recognized by the compiler, or created at
683 * execution time through, e.g., upvar.
684 * Initially NULL and created if needed. */
685 int numCompiledLocals; /* Count of local variables recognized by
686 * the compiler including arguments. */
687 Var* compiledLocals; /* Points to the array of local variables
688 * recognized by the compiler. The compiler
689 * emits code that refers to these variables
690 * using an index into this array. */
691} CallFrame;
692
693/*
694 *----------------------------------------------------------------
695 * Data structures related to history. These are used primarily
696 * in tclHistory.c
697 *----------------------------------------------------------------
698 */
699
700/*
701 * The structure below defines one history event (a previously-executed
702 * command that can be re-executed in whole or in part).
703 */
704
705typedef struct {
706 char *command; /* String containing previously-executed
707 * command. */
708 int bytesAvl; /* Total # of bytes available at *event (not
709 * all are necessarily in use now). */
710} HistoryEvent;
711
712/*
713 * The structure below defines a pending revision to the most recent
714 * history event. Changes are linked together into a list and applied
715 * during the next call to Tcl_RecordHistory. See the comments at the
716 * beginning of tclHistory.c for information on revisions.
717 */
718
719typedef struct HistoryRev {
720 int firstIndex; /* Index of the first byte to replace in
721 * current history event. */
722 int lastIndex; /* Index of last byte to replace in
723 * current history event. */
724 int newSize; /* Number of bytes in newBytes. */
725 char *newBytes; /* Replacement for the range given by
726 * firstIndex and lastIndex (malloced). */
727 struct HistoryRev *nextPtr; /* Next in chain of revisions to apply, or
728 * NULL for end of list. */
729} HistoryRev;
730
731/*
732 *----------------------------------------------------------------
733 * Data structures related to expressions. These are used only in
734 * tclExpr.c.
735 *----------------------------------------------------------------
736 */
737
738/*
739 * The data structure below defines a math function (e.g. sin or hypot)
740 * for use in Tcl expressions.
741 */
742
743#define MAX_MATH_ARGS 5
744typedef struct MathFunc {
745 int builtinFuncIndex; /* If this is a builtin math function, its
746 * index in the array of builtin functions.
747 * (tclCompilation.h lists these indices.)
748 * The value is -1 if this is a new function
749 * defined by Tcl_CreateMathFunc. The value
750 * is also -1 if a builtin function is
751 * replaced by a Tcl_CreateMathFunc call. */
752 int numArgs; /* Number of arguments for function. */
753 Tcl_ValueType argTypes[MAX_MATH_ARGS];
754 /* Acceptable types for each argument. */
755 Tcl_MathProc *proc; /* Procedure that implements this function.
756 * NULL if isBuiltinFunc is 1. */
757 ClientData clientData; /* Additional argument to pass to the
758 * function when invoking it. NULL if
759 * isBuiltinFunc is 1. */
760} MathFunc;
761
762/*
763 *----------------------------------------------------------------
764 * Data structures related to bytecode compilation and execution.
765 * These are used primarily in tclCompile.c, tclExecute.c, and
766 * tclBasic.c.
767 *----------------------------------------------------------------
768 */
769
770/*
771 * Forward declaration to prevent an error when the forward reference to
772 * CompileEnv is encountered in the procedure type CompileProc declared
773 * below.
774 */
775
776struct CompileEnv;
777
778/*
779 * The type of procedures called by the Tcl bytecode compiler to compile
780 * commands. Pointers to these procedures are kept in the Command structure
781 * describing each command. When a CompileProc returns, the interpreter's
782 * result is set to error information, if any. In addition, the CompileProc
783 * returns an integer value, which is one of the following:
784 *
785 * TCL_OK Compilation completed normally.
786 * TCL_ERROR Compilation failed because of an error;
787 * the interpreter's result describes what went wrong.
788 * TCL_OUT_LINE_COMPILE Compilation failed because, e.g., the command is
789 * too complex for effective inline compilation. The
790 * CompileProc believes the command is legal but
791 * should be compiled "out of line" by emitting code
792 * to invoke its command procedure at runtime.
793 */
794
795#define TCL_OUT_LINE_COMPILE (TCL_CONTINUE + 1)
796
797typedef int (CompileProc) _ANSI_ARGS_((Tcl_Interp *interp, char *string,
798 char *lastChar, int compileFlags, struct CompileEnv *compEnvPtr));
799
800/*
801 * The data structure defining the execution environment for ByteCode's.
802 * There is one ExecEnv structure per Tcl interpreter. It holds the
803 * evaluation stack that holds command operands and results. The stack grows
804 * towards increasing addresses. The "stackTop" member is cached by
805 * TclExecuteByteCode in a local variable: it must be set before calling
806 * TclExecuteByteCode and will be restored by TclExecuteByteCode before it
807 * returns.
808 */
809
810typedef union StackItem {
811 Tcl_Obj *o; /* Stack item as a pointer to a Tcl_Obj. */
812 int i; /* Stack item as an integer. */
813 VOID *p; /* Stack item as an arbitrary pointer. */
814} StackItem;
815
816typedef struct ExecEnv {
817 StackItem *stackPtr; /* Points to the first item in the
818 * evaluation stack on the heap. */
819 int stackTop; /* Index of current top of stack; -1 when
820 * the stack is empty. */
821 int stackEnd; /* Index of last usable item in stack. */
822} ExecEnv;
823
824/*
825 *----------------------------------------------------------------
826 * Data structures related to commands.
827 *----------------------------------------------------------------
828 */
829
830/*
831 * An imported command is created in an namespace when it imports a "real"
832 * command from another namespace. An imported command has a Command
833 * structure that points (via its ClientData value) to the "real" Command
834 * structure in the source namespace's command table. The real command
835 * records all the imported commands that refer to it in a list of ImportRef
836 * structures so that they can be deleted when the real command is deleted. */
837
838typedef struct ImportRef {
839 struct Command *importedCmdPtr;
840 /* Points to the imported command created in
841 * an importing namespace; this command
842 * redirects its invocations to the "real"
843 * command. */
844 struct ImportRef *nextPtr; /* Next element on the linked list of
845 * imported commands that refer to the
846 * "real" command. The real command deletes
847 * these imported commands on this list when
848 * it is deleted. */
849} ImportRef;
850
851/*
852 * Data structure used as the ClientData of imported commands: commands
853 * created in an namespace when it imports a "real" command from another
854 * namespace.
855 */
856
857typedef struct ImportedCmdData {
858 struct Command *realCmdPtr; /* "Real" command that this imported command
859 * refers to. */
860 struct Command *selfPtr; /* Pointer to this imported command. Needed
861 * only when deleting it in order to remove
862 * it from the real command's linked list of
863 * imported commands that refer to it. */
864} ImportedCmdData;
865
866/*
867 * A Command structure exists for each command in a namespace. The
868 * Tcl_Command opaque type actually refers to these structures.
869 */
870
871typedef struct Command {
872 Tcl_HashEntry *hPtr; /* Pointer to the hash table entry that
873 * refers to this command. The hash table is
874 * either a namespace's command table or an
875 * interpreter's hidden command table. This
876 * pointer is used to get a command's name
877 * from its Tcl_Command handle. NULL means
878 * that the hash table entry has been
879 * removed already (this can happen if
880 * deleteProc causes the command to be
881 * deleted or recreated). */
882 Namespace *nsPtr; /* Points to the namespace containing this
883 * command. */
884 int refCount; /* 1 if in command hashtable plus 1 for each
885 * reference from a CmdName Tcl object
886 * representing a command's name in a
887 * ByteCode instruction sequence. This
888 * structure can be freed when refCount
889 * becomes zero. */
890 int cmdEpoch; /* Incremented to invalidate any references
891 * that point to this command when it is
892 * renamed, deleted, hidden, or exposed. */
893 CompileProc *compileProc; /* Procedure called to compile command. NULL
894 * if no compile proc exists for command. */
895 Tcl_ObjCmdProc *objProc; /* Object-based command procedure. */
896 ClientData objClientData; /* Arbitrary value passed to object proc. */
897 Tcl_CmdProc *proc; /* String-based command procedure. */
898 ClientData clientData; /* Arbitrary value passed to string proc. */
899 Tcl_CmdDeleteProc *deleteProc;
900 /* Procedure invoked when deleting command
901 * to, e.g., free all client data. */
902 ClientData deleteData; /* Arbitrary value passed to deleteProc. */
903 int deleted; /* Means that the command is in the process
904 * of being deleted (its deleteProc is
905 * currently executing). Other attempts to
906 * delete the command should be ignored. */
907 ImportRef *importRefPtr; /* List of each imported Command created in
908 * another namespace when this command is
909 * imported. These imported commands
910 * redirect invocations back to this
911 * command. The list is used to remove all
912 * those imported commands when deleting
913 * this "real" command. */
914} Command;
915
916/*
917 *----------------------------------------------------------------
918 * Data structures related to name resolution procedures.
919 *----------------------------------------------------------------
920 */
921
922/*
923 * The interpreter keeps a linked list of name resolution schemes.
924 * The scheme for a namespace is consulted first, followed by the
925 * list of schemes in an interpreter, followed by the default
926 * name resolution in Tcl. Schemes are added/removed from the
927 * interpreter's list by calling Tcl_AddInterpResolver and
928 * Tcl_RemoveInterpResolver.
929 */
930
931typedef struct ResolverScheme {
932 char *name; /* Name identifying this scheme. */
933 Tcl_ResolveCmdProc *cmdResProc;
934 /* Procedure handling command name
935 * resolution. */
936 Tcl_ResolveVarProc *varResProc;
937 /* Procedure handling variable name
938 * resolution for variables that
939 * can only be handled at runtime. */
940 Tcl_ResolveCompiledVarProc *compiledVarResProc;
941 /* Procedure handling variable name
942 * resolution at compile time. */
943
944 struct ResolverScheme *nextPtr;
945 /* Pointer to next record in linked list. */
946} ResolverScheme;
947
948/*
949 *----------------------------------------------------------------
950 * This structure defines an interpreter, which is a collection of
951 * commands plus other state information related to interpreting
952 * commands, such as variable storage. Primary responsibility for
953 * this data structure is in tclBasic.c, but almost every Tcl
954 * source file uses something in here.
955 *----------------------------------------------------------------
956 */
957
958typedef struct Interp {
959
960 /*
961 * Note: the first three fields must match exactly the fields in
962 * a Tcl_Interp struct (see tcl.h). If you change one, be sure to
963 * change the other.
964 *
965 * The interpreter's result is held in both the string and the
966 * objResultPtr fields. These fields hold, respectively, the result's
967 * string or object value. The interpreter's result is always in the
968 * result field if that is non-empty, otherwise it is in objResultPtr.
969 * The two fields are kept consistent unless some C code sets
970 * interp->result directly. Programs should not access result and
971 * objResultPtr directly; instead, they should always get and set the
972 * result using procedures such as Tcl_SetObjResult, Tcl_GetObjResult,
973 * and Tcl_GetStringResult. See the SetResult man page for details.
974 */
975
976 char *result; /* If the last command returned a string
977 * result, this points to it. Should not be
978 * accessed directly; see comment above. */
979 Tcl_FreeProc *freeProc; /* Zero means a string result is statically
980 * allocated. TCL_DYNAMIC means string
981 * result was allocated with ckalloc and
982 * should be freed with ckfree. Other values
983 * give address of procedure to invoke to
984 * free the string result. Tcl_Eval must
985 * free it before executing next command. */
986 int errorLine; /* When TCL_ERROR is returned, this gives
987 * the line number in the command where the
988 * error occurred (1 means first line). */
989 Tcl_Obj *objResultPtr; /* If the last command returned an object
990 * result, this points to it. Should not be
991 * accessed directly; see comment above. */
992 Namespace *globalNsPtr; /* The interpreter's global namespace. */
993 Tcl_HashTable mathFuncTable;/* Contains all the math functions currently
994 * defined for the interpreter. Indexed by
995 * strings (function names); values have
996 * type (MathFunc *). */
997
998 /*
999 * Information related to procedures and variables. See tclProc.c
1000 * and tclvar.c for usage.
1001 */
1002
1003 int numLevels; /* Keeps track of how many nested calls to
1004 * Tcl_Eval are in progress for this
1005 * interpreter. It's used to delay deletion
1006 * of the table until all Tcl_Eval
1007 * invocations are completed. */
1008 int maxNestingDepth; /* If numLevels exceeds this value then Tcl
1009 * assumes that infinite recursion has
1010 * occurred and it generates an error. */
1011 CallFrame *framePtr; /* Points to top-most in stack of all nested
1012 * procedure invocations. NULL means there
1013 * are no active procedures. */
1014 CallFrame *varFramePtr; /* Points to the call frame whose variables
1015 * are currently in use (same as framePtr
1016 * unless an "uplevel" command is
1017 * executing). NULL means no procedure is
1018 * active or "uplevel 0" is executing. */
1019 ActiveVarTrace *activeTracePtr;
1020 /* First in list of active traces for
1021 * interp, or NULL if no active traces. */
1022 int returnCode; /* Completion code to return if current
1023 * procedure exits with TCL_RETURN code. */
1024 char *errorInfo; /* Value to store in errorInfo if returnCode
1025 * is TCL_ERROR. Malloc'ed, may be NULL */
1026 char *errorCode; /* Value to store in errorCode if returnCode
1027 * is TCL_ERROR. Malloc'ed, may be NULL */
1028
1029 /*
1030 * Information used by Tcl_AppendResult to keep track of partial
1031 * results. See Tcl_AppendResult code for details.
1032 */
1033
1034 char *appendResult; /* Storage space for results generated
1035 * by Tcl_AppendResult. Malloc-ed. NULL
1036 * means not yet allocated. */
1037 int appendAvl; /* Total amount of space available at
1038 * partialResult. */
1039 int appendUsed; /* Number of non-null bytes currently
1040 * stored at partialResult. */
1041
1042 /*
1043 * Miscellaneous information:
1044 */
1045
1046 int cmdCount; /* Total number of times a command procedure
1047 * has been called for this interpreter. */
1048 int evalFlags; /* Flags to control next call to Tcl_Eval.
1049 * Normally zero, but may be set before
1050 * calling Tcl_Eval. See below for valid
1051 * values. */
1052 int termOffset; /* Offset of character just after last one
1053 * compiled or executed by Tcl_EvalObj. */
1054 int compileEpoch; /* Holds the current "compilation epoch"
1055 * for this interpreter. This is
1056 * incremented to invalidate existing
1057 * ByteCodes when, e.g., a command with a
1058 * compile procedure is redefined. */
1059 Proc *compiledProcPtr; /* If a procedure is being compiled, a
1060 * pointer to its Proc structure; otherwise,
1061 * this is NULL. Set by ObjInterpProc in
1062 * tclProc.c and used by tclCompile.c to
1063 * process local variables appropriately. */
1064 ResolverScheme *resolverPtr;
1065 /* Linked list of name resolution schemes
1066 * added to this interpreter. Schemes
1067 * are added/removed by calling
1068 * Tcl_AddInterpResolver and
1069 * Tcl_RemoveInterpResolver. */
1070 char *scriptFile; /* NULL means there is no nested source
1071 * command active; otherwise this points to
1072 * the name of the file being sourced (it's
1073 * not malloc-ed: it points to an argument
1074 * to Tcl_EvalFile. */
1075 int flags; /* Various flag bits. See below. */
1076 long randSeed; /* Seed used for rand() function. */
1077 Trace *tracePtr; /* List of traces for this interpreter. */
1078 Tcl_HashTable *assocData; /* Hash table for associating data with
1079 * this interpreter. Cleaned up when
1080 * this interpreter is deleted. */
1081 struct ExecEnv *execEnvPtr; /* Execution environment for Tcl bytecode
1082 * execution. Contains a pointer to the
1083 * Tcl evaluation stack. */
1084 Tcl_Obj *emptyObjPtr; /* Points to an object holding an empty
1085 * string. Returned by Tcl_ObjSetVar2 when
1086 * variable traces change a variable in a
1087 * gross way. */
1088 char resultSpace[TCL_RESULT_SIZE+1];
1089 /* Static space holding small results. */
1090} Interp;
1091
1092/*
1093 * EvalFlag bits for Interp structures:
1094 *
1095 * TCL_BRACKET_TERM 1 means that the current script is terminated by
1096 * a close bracket rather than the end of the string.
1097 * TCL_ALLOW_EXCEPTIONS 1 means it's OK for the script to terminate with
1098 * a code other than TCL_OK or TCL_ERROR; 0 means
1099 * codes other than these should be turned into errors.
1100 */
1101
1102#define TCL_BRACKET_TERM 1
1103#define TCL_ALLOW_EXCEPTIONS 4
1104
1105/*
1106 * Flag bits for Interp structures:
1107 *
1108 * DELETED: Non-zero means the interpreter has been deleted:
1109 * don't process any more commands for it, and destroy
1110 * the structure as soon as all nested invocations of
1111 * Tcl_Eval are done.
1112 * ERR_IN_PROGRESS: Non-zero means an error unwind is already in
1113 * progress. Zero means a command proc has been
1114 * invoked since last error occured.
1115 * ERR_ALREADY_LOGGED: Non-zero means information has already been logged
1116 * in $errorInfo for the current Tcl_Eval instance,
1117 * so Tcl_Eval needn't log it (used to implement the
1118 * "error message log" command).
1119 * ERROR_CODE_SET: Non-zero means that Tcl_SetErrorCode has been
1120 * called to record information for the current
1121 * error. Zero means Tcl_Eval must clear the
1122 * errorCode variable if an error is returned.
1123 * EXPR_INITIALIZED: Non-zero means initialization specific to
1124 * expressions has been carried out.
1125 * DONT_COMPILE_CMDS_INLINE: Non-zero means that the bytecode compiler
1126 * should not compile any commands into an inline
1127 * sequence of instructions. This is set 1, for
1128 * example, when command traces are requested.
1129 * RAND_SEED_INITIALIZED: Non-zero means that the randSeed value of the
1130 * interp has not be initialized. This is set 1
1131 * when we first use the rand() or srand() functions.
1132 * SAFE_INTERP: Non zero means that the current interp is a
1133 * safe interp (ie it has only the safe commands
1134 * installed, less priviledge than a regular interp).
1135 */
1136
1137#define DELETED 1
1138#define ERR_IN_PROGRESS 2
1139#define ERR_ALREADY_LOGGED 4
1140#define ERROR_CODE_SET 8
1141#define EXPR_INITIALIZED 0x10
1142#define DONT_COMPILE_CMDS_INLINE 0x20
1143#define RAND_SEED_INITIALIZED 0x40
1144#define SAFE_INTERP 0x80
1145
1146/*
1147 *----------------------------------------------------------------
1148 * Data structures related to command parsing. These are used in
1149 * tclParse.c and its clients.
1150 *----------------------------------------------------------------
1151 */
1152
1153/*
1154 * The following data structure is used by various parsing procedures
1155 * to hold information about where to store the results of parsing
1156 * (e.g. the substituted contents of a quoted argument, or the result
1157 * of a nested command). At any given time, the space available
1158 * for output is fixed, but a procedure may be called to expand the
1159 * space available if the current space runs out.
1160 */
1161
1162typedef struct ParseValue {
1163 char *buffer; /* Address of first character in
1164 * output buffer. */
1165 char *next; /* Place to store next character in
1166 * output buffer. */
1167 char *end; /* Address of the last usable character
1168 * in the buffer. */
1169 void (*expandProc) _ANSI_ARGS_((struct ParseValue *pvPtr, int needed));
1170 /* Procedure to call when space runs out;
1171 * it will make more space. */
1172 ClientData clientData; /* Arbitrary information for use of
1173 * expandProc. */
1174} ParseValue;
1175
1176/*
1177 * A table used to classify input characters to assist in parsing
1178 * Tcl commands. The table should be indexed with a signed character
1179 * using the CHAR_TYPE macro. The character may have a negative
1180 * value. The CHAR_TYPE macro takes a pointer to a signed character
1181 * and a pointer to the last character in the source string. If the
1182 * src pointer is pointing at the terminating null of the string,
1183 * CHAR_TYPE returns TCL_COMMAND_END.
1184 */
1185
1186extern unsigned char tclTypeTable[];
1187#define CHAR_TYPE(src,last) \
1188 (((src)==(last))?TCL_COMMAND_END:(tclTypeTable)[(int)(*(src) + 128)])
1189
1190/*
1191 * Possible values returned by CHAR_TYPE. Note that except for TCL_DOLLAR,
1192 * these are all one byte values with a single bit set 1. This means these
1193 * values may be bit-or'ed together (except for TCL_DOLLAR) to quickly test
1194 * whether a character is one of several different kinds of characters.
1195 *
1196 * TCL_NORMAL - All characters that don't have special significance
1197 * to the Tcl language.
1198 * TCL_SPACE - Character is space, tab, or return.
1199 * TCL_COMMAND_END - Character is newline or semicolon or close-bracket
1200 * or terminating null.
1201 * TCL_QUOTE - Character is a double-quote.
1202 * TCL_OPEN_BRACKET - Character is a "[".
1203 * TCL_OPEN_BRACE - Character is a "{".
1204 * TCL_CLOSE_BRACE - Character is a "}".
1205 * TCL_BACKSLASH - Character is a "\".
1206 * TCL_DOLLAR - Character is a "$".
1207 */
1208
1209#define TCL_NORMAL 0x01
1210#define TCL_SPACE 0x02
1211#define TCL_COMMAND_END 0x04
1212#define TCL_QUOTE 0x08
1213#define TCL_OPEN_BRACKET 0x10
1214#define TCL_OPEN_BRACE 0x20
1215#define TCL_CLOSE_BRACE 0x40
1216#define TCL_BACKSLASH 0x80
1217#define TCL_DOLLAR 0x00
1218
1219/*
1220 * Maximum number of levels of nesting permitted in Tcl commands (used
1221 * to catch infinite recursion).
1222 */
1223
1224#define MAX_NESTING_DEPTH 1000
1225
1226/*
1227 * The macro below is used to modify a "char" value (e.g. by casting
1228 * it to an unsigned character) so that it can be used safely with
1229 * macros such as isspace.
1230 */
1231
1232#define UCHAR(c) ((unsigned char) (c))
1233
1234/*
1235 * This macro is used to determine the offset needed to safely allocate any
1236 * data structure in memory. Given a starting offset or size, it "rounds up"
1237 * or "aligns" the offset to the next 8-byte boundary so that any data
1238 * structure can be placed at the resulting offset without fear of an
1239 * alignment error.
1240 *
1241 * WARNING!! DO NOT USE THIS MACRO TO ALIGN POINTERS: it will produce
1242 * the wrong result on platforms that allocate addresses that are divisible
1243 * by 4 or 2. Only use it for offsets or sizes.
1244 */
1245
1246#define TCL_ALIGN(x) (((int)(x) + 7) & ~7)
1247
1248/*
1249 * The following macros are used to specify the runtime platform
1250 * setting of the tclPlatform variable.
1251 */
1252
1253typedef enum {
1254 TCL_PLATFORM_UNIX, /* Any Unix-like OS. */
1255 TCL_PLATFORM_MAC, /* MacOS. */
1256 TCL_PLATFORM_WINDOWS /* Any Microsoft Windows OS. */
1257} TclPlatformType;
1258
1259/*
1260 * Flags for TclInvoke:
1261 *
1262 * TCL_INVOKE_HIDDEN Invoke a hidden command; if not set,
1263 * invokes an exposed command.
1264 * TCL_INVOKE_NO_UNKNOWN If set, "unknown" is not invoked if
1265 * the command to be invoked is not found.
1266 * Only has an effect if invoking an exposed
1267 * command, i.e. if TCL_INVOKE_HIDDEN is not
1268 * also set.
1269 */
1270
1271#define TCL_INVOKE_HIDDEN (1<<0)
1272#define TCL_INVOKE_NO_UNKNOWN (1<<1)
1273
1274/*
1275 * The structure used as the internal representation of Tcl list
1276 * objects. This is an array of pointers to the element objects. This array
1277 * is grown (reallocated and copied) as necessary to hold all the list's
1278 * element pointers. The array might contain more slots than currently used
1279 * to hold all element pointers. This is done to make append operations
1280 * faster.
1281 */
1282
1283typedef struct List {
1284 int maxElemCount; /* Total number of element array slots. */
1285 int elemCount; /* Current number of list elements. */
1286 Tcl_Obj **elements; /* Array of pointers to element objects. */
1287} List;
1288
1289/*
1290 *----------------------------------------------------------------
1291 * Data structures related to hooking 'TclStat(...)' and
1292 * 'TclAccess(...)'.
1293 *----------------------------------------------------------------
1294 */
1295
1296typedef int (*TclCmdProcType) _ANSI_ARGS_((ClientData clientData,
1297 Tcl_Interp *interp, int argc, char *argv[]));
1298typedef int (*TclObjCmdProcType) _ANSI_ARGS_((ClientData clientData,
1299 Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST objv[]));
1300
1301/*
1302 *----------------------------------------------------------------
1303 * Variables shared among Tcl modules but not used by the outside world.
1304 *----------------------------------------------------------------
1305 */
1306
1307extern char * tclExecutableName;
1308extern TclPlatformType tclPlatform;
1309
1310/*
1311 * Variables denoting the Tcl object types defined in the core.
1312 */
1313
1314extern Tcl_ObjType tclBooleanType;
1315extern Tcl_ObjType tclByteCodeType;
1316extern Tcl_ObjType tclDoubleType;
1317extern Tcl_ObjType tclIntType;
1318extern Tcl_ObjType tclListType;
1319extern Tcl_ObjType tclProcBodyType;
1320extern Tcl_ObjType tclStringType;
1321
1322/*
1323 * The head of the list of free Tcl objects, and the total number of Tcl
1324 * objects ever allocated and freed.
1325 */
1326
1327extern Tcl_Obj * tclFreeObjList;
1328
1329#ifdef TCL_COMPILE_STATS
1330extern long tclObjsAlloced;
1331extern long tclObjsFreed;
1332#endif /* TCL_COMPILE_STATS */
1333
1334/*
1335 * Pointer to a heap-allocated string of length zero that the Tcl core uses
1336 * as the value of an empty string representation for an object. This value
1337 * is shared by all new objects allocated by Tcl_NewObj.
1338 */
1339
1340extern char * tclEmptyStringRep;
1341
1342/*
1343 *----------------------------------------------------------------
1344 * Procedures shared among Tcl modules but not used by the outside
1345 * world:
1346 *----------------------------------------------------------------
1347 */
1348
1349EXTERN void panic _ANSI_ARGS_(TCL_VARARGS(char *,format));
1350EXTERN void TclAllocateFreeObjects _ANSI_ARGS_((void));
1351EXTERN void TclCleanupCommand _ANSI_ARGS_((Command *cmdPtr));
1352EXTERN int TclCopyAndCollapse _ANSI_ARGS_((int count,
1353 char *src, char *dst));
1354EXTERN int TclCreateProc _ANSI_ARGS_((Tcl_Interp *interp,
1355 Namespace *nsPtr, char *procName,
1356 Tcl_Obj *argsPtr, Tcl_Obj *bodyPtr,
1357 Proc **procPtrPtr));
1358EXTERN void TclDeleteCompiledLocalVars _ANSI_ARGS_((
1359 Interp *iPtr, CallFrame *framePtr));
1360EXTERN void TclDeleteVars _ANSI_ARGS_((Interp *iPtr,
1361 Tcl_HashTable *tablePtr));
1362EXTERN void TclDumpMemoryInfo _ANSI_ARGS_((FILE *outFile));
1363EXTERN void TclExpandParseValue _ANSI_ARGS_((ParseValue *pvPtr,
1364 int needed));
1365EXTERN void TclExprFloatError _ANSI_ARGS_((Tcl_Interp *interp,
1366 double value));
1367EXTERN void TclFinalizeCompExecEnv _ANSI_ARGS_((void));
1368EXTERN void TclFinalizeEnvironment _ANSI_ARGS_((void));
1369EXTERN void TclFinalizeExecEnv _ANSI_ARGS_((void));
1370EXTERN int TclFindElement _ANSI_ARGS_((Tcl_Interp *interp,
1371 char *list, int listLength, char **elementPtr,
1372 char **nextPtr, int *sizePtr, int *bracePtr));
1373EXTERN Proc * TclFindProc _ANSI_ARGS_((Interp *iPtr,
1374 char *procName));
1375EXTERN int TclFormatInt _ANSI_ARGS_((char *buffer, long n));
1376EXTERN int TclGetDate _ANSI_ARGS_((char *p,
1377 unsigned long now, long zone,
1378 unsigned long *timePtr));
1379EXTERN Tcl_Obj * TclGetElementOfIndexedArray _ANSI_ARGS_((
1380 Tcl_Interp *interp, int localIndex,
1381 Tcl_Obj *elemPtr, int leaveErrorMsg));
1382EXTERN char * TclGetEnv _ANSI_ARGS_((CONST char *name));
1383EXTERN int TclGetFrame _ANSI_ARGS_((Tcl_Interp *interp,
1384 char *string, CallFrame **framePtrPtr));
1385EXTERN TclCmdProcType TclGetInterpProc _ANSI_ARGS_((void));
1386EXTERN int TclGetIntForIndex _ANSI_ARGS_((Tcl_Interp *interp,
1387 Tcl_Obj *objPtr, int endValue, int *indexPtr));
1388EXTERN Tcl_Obj * TclGetIndexedScalar _ANSI_ARGS_((Tcl_Interp *interp,
1389 int localIndex, int leaveErrorMsg));
1390EXTERN int TclGetLong _ANSI_ARGS_((Tcl_Interp *interp,
1391 char *string, long *longPtr));
1392EXTERN int TclGetNamespaceForQualName _ANSI_ARGS_((
1393 Tcl_Interp *interp, char *qualName,
1394 Namespace *cxtNsPtr, int flags,
1395 Namespace **nsPtrPtr, Namespace **altNsPtrPtr,
1396 Namespace **actualCxtPtrPtr,
1397 char **simpleNamePtr));
1398EXTERN TclObjCmdProcType TclGetObjInterpProc _ANSI_ARGS_((void));
1399EXTERN int TclGetOpenMode _ANSI_ARGS_((Tcl_Interp *interp,
1400 char *string, int *seekFlagPtr));
1401EXTERN Tcl_Command TclGetOriginalCommand _ANSI_ARGS_((
1402 Tcl_Command command));
1403EXTERN char * TclGetUserHome _ANSI_ARGS_((char *name,
1404 Tcl_DString *bufferPtr));
1405EXTERN int TclGlobalInvoke _ANSI_ARGS_((Tcl_Interp *interp,
1406 int argc, char **argv, int flags));
1407EXTERN int TclInExit _ANSI_ARGS_((void));
1408EXTERN Tcl_Obj * TclIncrElementOfIndexedArray _ANSI_ARGS_((
1409 Tcl_Interp *interp, int localIndex,
1410 Tcl_Obj *elemPtr, long incrAmount));
1411EXTERN Tcl_Obj * TclIncrIndexedScalar _ANSI_ARGS_((
1412 Tcl_Interp *interp, int localIndex,
1413 long incrAmount));
1414EXTERN Tcl_Obj * TclIncrVar2 _ANSI_ARGS_((Tcl_Interp *interp,
1415 Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr,
1416 long incrAmount, int part1NotParsed));
1417EXTERN void TclInitCompiledLocals _ANSI_ARGS_((
1418 Tcl_Interp *interp, CallFrame *framePtr,
1419 Namespace *nsPtr));
1420EXTERN void TclInitNamespaces _ANSI_ARGS_((void));
1421EXTERN int TclInterpInit _ANSI_ARGS_((Tcl_Interp *interp));
1422EXTERN int TclInvoke _ANSI_ARGS_((Tcl_Interp *interp,
1423 int argc, char **argv, int flags));
1424EXTERN int TclInvokeObjectCommand _ANSI_ARGS_((
1425 ClientData clientData, Tcl_Interp *interp,
1426 int argc, char **argv));
1427EXTERN int TclInvokeStringCommand _ANSI_ARGS_((
1428 ClientData clientData, Tcl_Interp *interp,
1429 int objc, Tcl_Obj *CONST objv[]));
1430EXTERN Proc * TclIsProc _ANSI_ARGS_((Command *cmdPtr));
1431EXTERN int TclLooksLikeInt _ANSI_ARGS_((char *p));
1432EXTERN Var * TclLookupVar _ANSI_ARGS_((Tcl_Interp *interp,
1433 char *part1, char *part2, int flags, char *msg,
1434 int createPart1, int createPart2,
1435 Var **arrayPtrPtr));
1436EXTERN int TclNeedSpace _ANSI_ARGS_((char *start, char *end));
1437EXTERN Tcl_Obj * TclNewProcBodyObj _ANSI_ARGS_((Proc *procPtr));
1438EXTERN int TclObjCommandComplete _ANSI_ARGS_((Tcl_Obj *cmdPtr));
1439EXTERN int TclObjInterpProc _ANSI_ARGS_((ClientData clientData,
1440 Tcl_Interp *interp, int objc,
1441 Tcl_Obj *CONST objv[]));
1442EXTERN int TclObjInvoke _ANSI_ARGS_((Tcl_Interp *interp,
1443 int objc, Tcl_Obj *CONST objv[], int flags));
1444EXTERN int TclObjInvokeGlobal _ANSI_ARGS_((Tcl_Interp *interp,
1445 int objc, Tcl_Obj *CONST objv[], int flags));
1446EXTERN char * TclpAlloc _ANSI_ARGS_((unsigned int size));
1447
1448EXTERN char * TclpRealloc _ANSI_ARGS_((char *ptr,
1449 unsigned int size));
1450#ifndef TclpSysAlloc
1451EXTERN VOID * TclpSysAlloc _ANSI_ARGS_((long size, int isBin));
1452#endif
1453#ifndef TclpSysFree
1454EXTERN void TclpSysFree _ANSI_ARGS_((VOID *ptr));
1455#endif
1456#ifndef TclpSysRealloc
1457EXTERN VOID * TclpSysRealloc _ANSI_ARGS_((VOID *cp,
1458 unsigned int size));
1459#endif
1460EXTERN int TclParseBraces _ANSI_ARGS_((Tcl_Interp *interp,
1461 char *string, char **termPtr, ParseValue *pvPtr));
1462EXTERN int TclParseNestedCmd _ANSI_ARGS_((Tcl_Interp *interp,
1463 char *string, int flags, char **termPtr,
1464 ParseValue *pvPtr));
1465EXTERN int TclParseQuotes _ANSI_ARGS_((Tcl_Interp *interp,
1466 char *string, int termChar, int flags,
1467 char **termPtr, ParseValue *pvPtr));
1468EXTERN void TclPlatformExit _ANSI_ARGS_((int status));
1469EXTERN char * TclPrecTraceProc _ANSI_ARGS_((ClientData clientData,
1470 Tcl_Interp *interp, char *name1, char *name2,
1471 int flags));
1472EXTERN int TclPreventAliasLoop _ANSI_ARGS_((Tcl_Interp *interp,
1473 Tcl_Interp *cmdInterp, Tcl_Command cmd));
1474EXTERN void TclPrintByteCodeObj _ANSI_ARGS_((Tcl_Interp *interp,
1475 Tcl_Obj *objPtr));
1476EXTERN void TclProcCleanupProc _ANSI_ARGS_((Proc *procPtr));
1477EXTERN int TclProcCompileProc _ANSI_ARGS_((Tcl_Interp *interp,
1478 Proc *procPtr, Tcl_Obj *bodyPtr, Namespace *nsPtr,
1479 CONST char *description, CONST char *procName));
1480EXTERN void TclProcDeleteProc _ANSI_ARGS_((ClientData clientData));
1481EXTERN int TclProcInterpProc _ANSI_ARGS_((ClientData clientData,
1482 Tcl_Interp *interp, int argc, char **argv));
1483EXTERN int TclRenameCommand _ANSI_ARGS_((Tcl_Interp *interp,
1484 char *oldName, char *newName)) ;
1485EXTERN void TclResetShadowedCmdRefs _ANSI_ARGS_((
1486 Tcl_Interp *interp, Command *newCmdPtr));
1487EXTERN int TclServiceIdle _ANSI_ARGS_((void));
1488EXTERN Tcl_Obj * TclSetElementOfIndexedArray _ANSI_ARGS_((
1489 Tcl_Interp *interp, int localIndex,
1490 Tcl_Obj *elemPtr, Tcl_Obj *objPtr,
1491 int leaveErrorMsg));
1492EXTERN Tcl_Obj * TclSetIndexedScalar _ANSI_ARGS_((Tcl_Interp *interp,
1493 int localIndex, Tcl_Obj *objPtr,
1494 int leaveErrorMsg));
1495EXTERN char * TclSetPreInitScript _ANSI_ARGS_((char *string));
1496EXTERN int TclSockGetPort _ANSI_ARGS_((Tcl_Interp *interp,
1497 char *string, char *proto, int *portPtr));
1498EXTERN int TclSockMinimumBuffers _ANSI_ARGS_((int sock,
1499 int size));
1500EXTERN void TclTeardownNamespace _ANSI_ARGS_((Namespace *nsPtr));
1501EXTERN int TclUpdateReturnInfo _ANSI_ARGS_((Interp *iPtr));
1502EXTERN char * TclWordEnd _ANSI_ARGS_((char *start, char *lastChar,
1503 int nested, int *semiPtr));
1504
1505/*
1506 *----------------------------------------------------------------
1507 * Command procedures in the generic core:
1508 *----------------------------------------------------------------
1509 */
1510
1511EXTERN int Tcl_AfterObjCmd _ANSI_ARGS_((ClientData clientData,
1512 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1513EXTERN int Tcl_AppendObjCmd _ANSI_ARGS_((ClientData clientData,
1514 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1515EXTERN int Tcl_ArrayObjCmd _ANSI_ARGS_((ClientData clientData,
1516 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1517EXTERN int Tcl_BreakCmd _ANSI_ARGS_((ClientData clientData,
1518 Tcl_Interp *interp, int argc, char **argv));
1519EXTERN int Tcl_CaseObjCmd _ANSI_ARGS_((ClientData clientData,
1520 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1521EXTERN int Tcl_CatchObjCmd _ANSI_ARGS_((ClientData clientData,
1522 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1523EXTERN int Tcl_CdObjCmd _ANSI_ARGS_((ClientData clientData,
1524 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1525EXTERN int Tcl_ConcatObjCmd _ANSI_ARGS_((ClientData clientData,
1526 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1527EXTERN int Tcl_ContinueCmd _ANSI_ARGS_((ClientData clientData,
1528 Tcl_Interp *interp, int argc, char **argv));
1529EXTERN int Tcl_ErrorObjCmd _ANSI_ARGS_((ClientData clientData,
1530 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1531EXTERN int Tcl_EvalObjCmd _ANSI_ARGS_((ClientData clientData,
1532 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1533EXTERN int Tcl_ExitObjCmd _ANSI_ARGS_((ClientData clientData,
1534 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1535EXTERN int Tcl_ExprObjCmd _ANSI_ARGS_((ClientData clientData,
1536 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1537EXTERN int Tcl_ForCmd _ANSI_ARGS_((ClientData clientData,
1538 Tcl_Interp *interp, int argc, char **argv));
1539EXTERN int Tcl_ForeachObjCmd _ANSI_ARGS_((ClientData clientData,
1540 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1541EXTERN int Tcl_FormatObjCmd _ANSI_ARGS_((ClientData dummy,
1542 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1543EXTERN int Tcl_GlobalObjCmd _ANSI_ARGS_((ClientData clientData,
1544 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1545EXTERN int Tcl_IfCmd _ANSI_ARGS_((ClientData clientData,
1546 Tcl_Interp *interp, int argc, char **argv));
1547EXTERN int Tcl_IncrCmd _ANSI_ARGS_((ClientData clientData,
1548 Tcl_Interp *interp, int argc, char **argv));
1549EXTERN int Tcl_InfoObjCmd _ANSI_ARGS_((ClientData clientData,
1550 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1551EXTERN int Tcl_InterpObjCmd _ANSI_ARGS_((ClientData clientData,
1552 Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[]));
1553EXTERN int Tcl_JoinObjCmd _ANSI_ARGS_((ClientData clientData,
1554 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1555EXTERN int Tcl_LappendObjCmd _ANSI_ARGS_((ClientData clientData,
1556 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1557EXTERN int Tcl_LindexObjCmd _ANSI_ARGS_((ClientData clientData,
1558 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1559EXTERN int Tcl_LinsertObjCmd _ANSI_ARGS_((ClientData clientData,
1560 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1561EXTERN int Tcl_LlengthObjCmd _ANSI_ARGS_((ClientData clientData,
1562 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1563EXTERN int Tcl_ListObjCmd _ANSI_ARGS_((ClientData clientData,
1564 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1565EXTERN int Tcl_LrangeObjCmd _ANSI_ARGS_((ClientData clientData,
1566 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1567EXTERN int Tcl_LreplaceObjCmd _ANSI_ARGS_((ClientData clientData,
1568 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1569EXTERN int Tcl_LsortObjCmd _ANSI_ARGS_((ClientData clientData,
1570 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1571EXTERN int Tcl_NamespaceObjCmd _ANSI_ARGS_((ClientData clientData,
1572 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1573EXTERN int Tcl_ProcObjCmd _ANSI_ARGS_((ClientData clientData,
1574 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1575EXTERN int Tcl_PutsObjCmd _ANSI_ARGS_((ClientData clientData,
1576 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1577EXTERN int Tcl_PwdCmd _ANSI_ARGS_((ClientData clientData,
1578 Tcl_Interp *interp, int argc, char **argv));
1579EXTERN int Tcl_RegexpCmd _ANSI_ARGS_((ClientData clientData,
1580 Tcl_Interp *interp, int argc, char **argv));
1581EXTERN int Tcl_RegsubCmd _ANSI_ARGS_((ClientData clientData,
1582 Tcl_Interp *interp, int argc, char **argv));
1583EXTERN int Tcl_RenameObjCmd _ANSI_ARGS_((ClientData clientData,
1584 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1585EXTERN int Tcl_ReturnObjCmd _ANSI_ARGS_((ClientData clientData,
1586 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1587EXTERN int Tcl_ScanCmd _ANSI_ARGS_((ClientData clientData,
1588 Tcl_Interp *interp, int argc, char **argv));
1589EXTERN int Tcl_SetCmd _ANSI_ARGS_((ClientData clientData,
1590 Tcl_Interp *interp, int argc, char **argv));
1591EXTERN int Tcl_SplitObjCmd _ANSI_ARGS_((ClientData clientData,
1592 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1593EXTERN int Tcl_SourceObjCmd _ANSI_ARGS_((ClientData clientData,
1594 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1595EXTERN int Tcl_StringObjCmd _ANSI_ARGS_((ClientData clientData,
1596 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1597EXTERN int Tcl_SubstCmd _ANSI_ARGS_((ClientData clientData,
1598 Tcl_Interp *interp, int argc, char **argv));
1599EXTERN int Tcl_SwitchObjCmd _ANSI_ARGS_((ClientData clientData,
1600 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1601EXTERN int Tcl_TimeObjCmd _ANSI_ARGS_((ClientData clientData,
1602 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1603EXTERN int Tcl_TraceCmd _ANSI_ARGS_((ClientData clientData,
1604 Tcl_Interp *interp, int argc, char **argv));
1605EXTERN int Tcl_UnsetObjCmd _ANSI_ARGS_((ClientData clientData,
1606 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1607EXTERN int Tcl_UplevelObjCmd _ANSI_ARGS_((ClientData clientData,
1608 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1609EXTERN int Tcl_UpvarObjCmd _ANSI_ARGS_((ClientData clientData,
1610 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1611EXTERN int Tcl_VariableObjCmd _ANSI_ARGS_((ClientData clientData,
1612 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1613EXTERN int Tcl_WhileCmd _ANSI_ARGS_((ClientData clientData,
1614 Tcl_Interp *interp, int argc, char **argv));
1615
1616/*
1617 *----------------------------------------------------------------
1618 * Command procedures found only in the Mac version of the core:
1619 *----------------------------------------------------------------
1620 */
1621
1622#ifdef MAC_TCL
1623EXTERN int Tcl_EchoCmd _ANSI_ARGS_((ClientData clientData,
1624 Tcl_Interp *interp, int argc, char **argv));
1625EXTERN int Tcl_LsCmd _ANSI_ARGS_((ClientData clientData,
1626 Tcl_Interp *interp, int argc, char **argv));
1627EXTERN int Tcl_BeepObjCmd _ANSI_ARGS_((ClientData clientData,
1628 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1629EXTERN int Tcl_MacSourceObjCmd _ANSI_ARGS_((ClientData clientData,
1630 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1631EXTERN int Tcl_ResourceObjCmd _ANSI_ARGS_((ClientData clientData,
1632 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1633#endif
1634
1635/*
1636 *----------------------------------------------------------------
1637 * Compilation procedures for commands in the generic core:
1638 *----------------------------------------------------------------
1639 */
1640
1641EXTERN int TclCompileBreakCmd _ANSI_ARGS_((Tcl_Interp *interp,
1642 char *string, char *lastChar, int compileFlags,
1643 struct CompileEnv *compileEnvPtr));
1644EXTERN int TclCompileCatchCmd _ANSI_ARGS_((Tcl_Interp *interp,
1645 char *string, char *lastChar, int compileFlags,
1646 struct CompileEnv *compileEnvPtr));
1647EXTERN int TclCompileContinueCmd _ANSI_ARGS_((Tcl_Interp *interp,
1648 char *string, char *lastChar, int compileFlags,
1649 struct CompileEnv *compileEnvPtr));
1650EXTERN int TclCompileExprCmd _ANSI_ARGS_((Tcl_Interp *interp,
1651 char *string, char *lastChar, int compileFlags,
1652 struct CompileEnv *compileEnvPtr));
1653EXTERN int TclCompileForCmd _ANSI_ARGS_((Tcl_Interp *interp,
1654 char *string, char *lastChar, int compileFlags,
1655 struct CompileEnv *compileEnvPtr));
1656EXTERN int TclCompileForeachCmd _ANSI_ARGS_((Tcl_Interp *interp,
1657 char *string, char *lastChar, int compileFlags,
1658 struct CompileEnv *compileEnvPtr));
1659EXTERN int TclCompileIfCmd _ANSI_ARGS_((Tcl_Interp *interp,
1660 char *string, char *lastChar, int compileFlags,
1661 struct CompileEnv *compileEnvPtr));
1662EXTERN int TclCompileIncrCmd _ANSI_ARGS_((Tcl_Interp *interp,
1663 char *string, char *lastChar, int compileFlags,
1664 struct CompileEnv *compileEnvPtr));
1665EXTERN int TclCompileSetCmd _ANSI_ARGS_((Tcl_Interp *interp,
1666 char *string, char *lastChar, int compileFlags,
1667 struct CompileEnv *compileEnvPtr));
1668EXTERN int TclCompileWhileCmd _ANSI_ARGS_((Tcl_Interp *interp,
1669 char *string, char *lastChar, int compileFlags,
1670 struct CompileEnv *compileEnvPtr));
1671
1672/*
1673 *----------------------------------------------------------------
1674 * Macros used by the Tcl core to create and release Tcl objects.
1675 * TclNewObj(objPtr) creates a new object denoting an empty string.
1676 * TclDecrRefCount(objPtr) decrements the object's reference count,
1677 * and frees the object if its reference count is zero.
1678 * These macros are inline versions of Tcl_NewObj() and
1679 * Tcl_DecrRefCount(). Notice that the names differ in not having
1680 * a "_" after the "Tcl". Notice also that these macros reference
1681 * their argument more than once, so you should avoid calling them
1682 * with an expression that is expensive to compute or has
1683 * side effects. The ANSI C "prototypes" for these macros are:
1684 *
1685 * EXTERN void TclNewObj _ANSI_ARGS_((Tcl_Obj *objPtr));
1686 * EXTERN void TclDecrRefCount _ANSI_ARGS_((Tcl_Obj *objPtr));
1687 *----------------------------------------------------------------
1688 */
1689
1690#ifdef TCL_COMPILE_STATS
1691# define TclIncrObjsAllocated() \
1692 tclObjsAlloced++
1693# define TclIncrObjsFreed() \
1694 tclObjsFreed++
1695#else
1696# define TclIncrObjsAllocated()
1697# define TclIncrObjsFreed()
1698#endif /* TCL_COMPILE_STATS */
1699
1700#ifdef TCL_MEM_DEBUG
1701# define TclNewObj(objPtr) \
1702 (objPtr) = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), __FILE__, __LINE__); \
1703 (objPtr)->refCount = 0; \
1704 (objPtr)->bytes = tclEmptyStringRep; \
1705 (objPtr)->length = 0; \
1706 (objPtr)->typePtr = NULL; \
1707 TclIncrObjsAllocated()
1708# define TclDbNewObj(objPtr, file, line) \
1709 (objPtr) = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), (file), (line)); \
1710 (objPtr)->refCount = 0; \
1711 (objPtr)->bytes = tclEmptyStringRep; \
1712 (objPtr)->length = 0; \
1713 (objPtr)->typePtr = NULL; \
1714 TclIncrObjsAllocated()
1715# define TclDecrRefCount(objPtr) \
1716 if (--(objPtr)->refCount <= 0) { \
1717 if ((objPtr)->refCount < -1) \
1718 panic("Reference count for %lx was negative: %s line %d", \
1719 (objPtr), __FILE__, __LINE__); \
1720 if (((objPtr)->bytes != NULL) \
1721 && ((objPtr)->bytes != tclEmptyStringRep)) { \
1722 ckfree((char *) (objPtr)->bytes); \
1723 } \
1724 if (((objPtr)->typePtr != NULL) \
1725 && ((objPtr)->typePtr->freeIntRepProc != NULL)) { \
1726 (objPtr)->typePtr->freeIntRepProc(objPtr); \
1727 } \
1728 ckfree((char *) (objPtr)); \
1729 TclIncrObjsFreed(); \
1730 }
1731#else /* not TCL_MEM_DEBUG */
1732# define TclNewObj(objPtr) \
1733 if (tclFreeObjList == NULL) { \
1734 TclAllocateFreeObjects(); \
1735 } \
1736 (objPtr) = tclFreeObjList; \
1737 tclFreeObjList = (Tcl_Obj *) \
1738 tclFreeObjList->internalRep.otherValuePtr; \
1739 (objPtr)->refCount = 0; \
1740 (objPtr)->bytes = tclEmptyStringRep; \
1741 (objPtr)->length = 0; \
1742 (objPtr)->typePtr = NULL; \
1743 TclIncrObjsAllocated()
1744# define TclDecrRefCount(objPtr) \
1745 if (--(objPtr)->refCount <= 0) { \
1746 if (((objPtr)->bytes != NULL) \
1747 && ((objPtr)->bytes != tclEmptyStringRep)) { \
1748 ckfree((char *) (objPtr)->bytes); \
1749 } \
1750 if (((objPtr)->typePtr != NULL) \
1751 && ((objPtr)->typePtr->freeIntRepProc != NULL)) { \
1752 (objPtr)->typePtr->freeIntRepProc(objPtr); \
1753 } \
1754 (objPtr)->internalRep.otherValuePtr = (VOID *) tclFreeObjList; \
1755 tclFreeObjList = (objPtr); \
1756 TclIncrObjsFreed(); \
1757 }
1758#endif /* TCL_MEM_DEBUG */
1759
1760/*
1761 *----------------------------------------------------------------
1762 * Macro used by the Tcl core to set a Tcl_Obj's string representation
1763 * to a copy of the "len" bytes starting at "bytePtr". This code
1764 * works even if the byte array contains NULLs as long as the length
1765 * is correct. Because "len" is referenced multiple times, it should
1766 * be as simple an expression as possible. The ANSI C "prototype" for
1767 * this macro is:
1768 *
1769 * EXTERN void TclInitStringRep _ANSI_ARGS_((Tcl_Obj *objPtr,
1770 * char *bytePtr, int len));
1771 *----------------------------------------------------------------
1772 */
1773
1774#define TclInitStringRep(objPtr, bytePtr, len) \
1775 if ((len) == 0) { \
1776 (objPtr)->bytes = tclEmptyStringRep; \
1777 (objPtr)->length = 0; \
1778 } else { \
1779 (objPtr)->bytes = (char *) ckalloc((unsigned) ((len) + 1)); \
1780 memcpy((VOID *) (objPtr)->bytes, (VOID *) (bytePtr), \
1781 (unsigned) (len)); \
1782 (objPtr)->bytes[len] = '\0'; \
1783 (objPtr)->length = (len); \
1784 }
1785
1786/*
1787 *----------------------------------------------------------------
1788 * Macro used by the Tcl core to get the string representation's
1789 * byte array pointer and length from a Tcl_Obj. This is an inline
1790 * version of Tcl_GetStringFromObj(). "lengthPtr" must be the
1791 * address of an integer variable or NULL; If non-NULL, that variable
1792 * will be set to the string rep's length. The macro's expression
1793 * result is the string rep's byte pointer which might be NULL.
1794 * Note that the bytes referenced by this pointer must not be modified
1795 * by the caller. The ANSI C "prototype" for this macro is:
1796 *
1797 * EXTERN char * TclGetStringFromObj _ANSI_ARGS_((Tcl_Obj *objPtr,
1798 * int *lengthPtr));
1799 *----------------------------------------------------------------
1800 */
1801
1802#define TclGetStringFromObj(objPtr, lengthPtr) \
1803 ((objPtr)->bytes? \
1804 ((lengthPtr)? \
1805 ((*(lengthPtr) = (objPtr)->length), (objPtr)->bytes) : \
1806 (objPtr)->bytes) : \
1807 Tcl_GetStringFromObj((objPtr), (lengthPtr)))
1808
1809/*
1810 *----------------------------------------------------------------
1811 * Macro used by the Tcl core to reset an interpreter's Tcl object
1812 * result to an unshared empty string object with ref count one.
1813 * This does not clear any error information for the interpreter.
1814 * The ANSI C "prototype" for this macro is:
1815 *
1816 * EXTERN void TclResetObjResult _ANSI_ARGS_((Tcl_Interp *interp));
1817 *---------------------------------------------------------------
1818 */
1819
1820#define TclResetObjResult(interp) \
1821 { \
1822 register Tcl_Obj *objResultPtr = ((Interp *) interp)->objResultPtr; \
1823 if (Tcl_IsShared(objResultPtr)) { \
1824 TclDecrRefCount(objResultPtr); \
1825 TclNewObj(objResultPtr); \
1826 Tcl_IncrRefCount(objResultPtr); \
1827 ((Interp *) interp)->objResultPtr = objResultPtr; \
1828 } else { \
1829 if ((objResultPtr->bytes != NULL) \
1830 && (objResultPtr->bytes != tclEmptyStringRep)) { \
1831 ckfree((char *) objResultPtr->bytes); \
1832 } \
1833 objResultPtr->bytes = tclEmptyStringRep; \
1834 objResultPtr->length = 0; \
1835 if ((objResultPtr->typePtr != NULL) \
1836 && (objResultPtr->typePtr->freeIntRepProc != NULL)) { \
1837 objResultPtr->typePtr->freeIntRepProc(objResultPtr); \
1838 } \
1839 objResultPtr->typePtr = (Tcl_ObjType *) NULL; \
1840 } \
1841 }
1842
1843/*
1844 *----------------------------------------------------------------
1845 * Procedures used in conjunction with Tcl namespaces. They are
1846 * defined here instead of in tcl.h since they are not stable yet.
1847 *----------------------------------------------------------------
1848 */
1849
1850EXTERN void Tcl_AddInterpResolvers _ANSI_ARGS_((Tcl_Interp *interp,
1851 char *name, Tcl_ResolveCmdProc *cmdProc,
1852 Tcl_ResolveVarProc *varProc,
1853 Tcl_ResolveCompiledVarProc *compiledVarProc));
1854EXTERN int Tcl_AppendExportList _ANSI_ARGS_((
1855 Tcl_Interp *interp, Tcl_Namespace *nsPtr,
1856 Tcl_Obj *objPtr));
1857EXTERN Tcl_Namespace * Tcl_CreateNamespace _ANSI_ARGS_((Tcl_Interp *interp,
1858 char *name, ClientData clientData,
1859 Tcl_NamespaceDeleteProc *deleteProc));
1860EXTERN void Tcl_DeleteNamespace _ANSI_ARGS_((
1861 Tcl_Namespace *nsPtr));
1862EXTERN int Tcl_Export _ANSI_ARGS_((Tcl_Interp *interp,
1863 Tcl_Namespace *nsPtr, char *pattern,
1864 int resetListFirst));
1865EXTERN Tcl_Command Tcl_FindCommand _ANSI_ARGS_((Tcl_Interp *interp,
1866 char *name, Tcl_Namespace *contextNsPtr,
1867 int flags));
1868EXTERN Tcl_Namespace * Tcl_FindNamespace _ANSI_ARGS_((Tcl_Interp *interp,
1869 char *name, Tcl_Namespace *contextNsPtr,
1870 int flags));
1871EXTERN int Tcl_GetInterpResolvers _ANSI_ARGS_((Tcl_Interp *interp,
1872 char *name, Tcl_ResolverInfo *resInfo));
1873EXTERN int Tcl_GetNamespaceResolvers _ANSI_ARGS_((
1874 Tcl_Namespace *namespacePtr,
1875 Tcl_ResolverInfo *resInfo));
1876EXTERN void Tcl_GetVariableFullName _ANSI_ARGS_((
1877 Tcl_Interp *interp, Tcl_Var variable,
1878 Tcl_Obj *objPtr));
1879EXTERN Tcl_Var Tcl_FindNamespaceVar _ANSI_ARGS_((
1880 Tcl_Interp *interp, char *name,
1881 Tcl_Namespace *contextNsPtr, int flags));
1882EXTERN int Tcl_ForgetImport _ANSI_ARGS_((Tcl_Interp *interp,
1883 Tcl_Namespace *nsPtr, char *pattern));
1884EXTERN Tcl_Command Tcl_GetCommandFromObj _ANSI_ARGS_((
1885 Tcl_Interp *interp, Tcl_Obj *objPtr));
1886EXTERN void Tcl_GetCommandFullName _ANSI_ARGS_((
1887 Tcl_Interp *interp, Tcl_Command command,
1888 Tcl_Obj *objPtr));
1889EXTERN Tcl_Namespace * Tcl_GetCurrentNamespace _ANSI_ARGS_((
1890 Tcl_Interp *interp));
1891EXTERN Tcl_Namespace * Tcl_GetGlobalNamespace _ANSI_ARGS_((
1892 Tcl_Interp *interp));
1893EXTERN void Tcl_GetVariableFullName _ANSI_ARGS_((
1894 Tcl_Interp *interp, Tcl_Var variable,
1895 Tcl_Obj *objPtr));
1896EXTERN int Tcl_Import _ANSI_ARGS_((Tcl_Interp *interp,
1897 Tcl_Namespace *nsPtr, char *pattern,
1898 int allowOverwrite));
1899EXTERN void Tcl_PopCallFrame _ANSI_ARGS_((Tcl_Interp* interp));
1900EXTERN int Tcl_PushCallFrame _ANSI_ARGS_((Tcl_Interp* interp,
1901 Tcl_CallFrame *framePtr, Tcl_Namespace *nsPtr,
1902 int isProcCallFrame));
1903EXTERN int Tcl_RemoveInterpResolvers _ANSI_ARGS_((
1904 Tcl_Interp *interp, char *name));
1905EXTERN void Tcl_SetNamespaceResolvers _ANSI_ARGS_((
1906 Tcl_Namespace *namespacePtr,
1907 Tcl_ResolveCmdProc *cmdProc,
1908 Tcl_ResolveVarProc *varProc,
1909 Tcl_ResolveCompiledVarProc *compiledVarProc));
1910
1911# undef TCL_STORAGE_CLASS
1912# define TCL_STORAGE_CLASS DLLIMPORT
1913
1914#endif /* _TCLINT */
1915
Note: See TracBrowser for help on using the repository browser.