|
|
1.1 ! root 1: /* ! 2: * tclInt.h -- ! 3: * ! 4: * Declarations of things used internally by the Tcl interpreter. ! 5: * ! 6: * Copyright 1987 Regents of the University of California ! 7: * Permission to use, copy, modify, and distribute this ! 8: * software and its documentation for any purpose and without ! 9: * fee is hereby granted, provided that the above copyright ! 10: * notice appear in all copies. The University of California ! 11: * makes no representations about the suitability of this ! 12: * software for any purpose. It is provided "as is" without ! 13: * express or implied warranty. ! 14: * ! 15: * $Header: /sprite/src/lib/tcl/RCS/tclInt.h,v 1.22 90/03/29 10:55:01 ouster Exp $ SPRITE (Berkeley) ! 16: */ ! 17: ! 18: #ifndef _TCLINT ! 19: #define _TCLINT ! 20: ! 21: #ifndef _TCL ! 22: #include "tcl.h" ! 23: #endif ! 24: ! 25: #define bcopy(src,dest,count) memcpy(dest,src,count) ! 26: ! 27: /* ! 28: * The structure below defines one Tcl command, by associating a procedure ! 29: * with a textual string. ! 30: */ ! 31: ! 32: typedef struct Command { ! 33: int (*proc)(); /* Procedure to process command. */ ! 34: ClientData clientData; /* Arbitrary value to pass to proc. */ ! 35: void (*deleteProc)(); /* Procedure to invoke when deleting ! 36: * command. */ ! 37: struct Command *nextPtr; /* Pointer to next command in list, or NULL ! 38: * for end of list. */ ! 39: char name[4]; /* Name of command. The actual size of this ! 40: * portion is as large as is necessary to ! 41: * hold the characters. This must be the ! 42: * last subfield of the record. */ ! 43: } Command; ! 44: ! 45: #define CMD_SIZE(nameLength) ((unsigned) sizeof(Command) + nameLength - 3) ! 46: ! 47: /* ! 48: * The structure below defines a variable, which associates a string name ! 49: * with a string value. To cut down on the number of malloc's and free's ! 50: * (particularly for procedure parameters), space for both the variable's ! 51: * name and initial value is allocated at the end of the structure (in ! 52: * "storage"). If the variable's value changes later, a new dynamic ! 53: * string is allocated, if there is insufficient space in the current ! 54: * storage area. ! 55: */ ! 56: ! 57: typedef struct Var { ! 58: char *value; /* Current value of variable (either points ! 59: * to static space after name, or to dynamic ! 60: * space if VAR_DYNAMIC is set). */ ! 61: int valueLength; /* Number of bytes of storage at the place ! 62: * referred to by value, not including space ! 63: * for NULL terminator. */ ! 64: int flags; /* Miscellaneous flags: see below. */ ! 65: struct Var *globalPtr; /* If VAR_GLOBAL is set, this points to the ! 66: * global variable corresponding to name. */ ! 67: struct Var *nextPtr; /* Next variable in list, or NULL for end ! 68: * of list. */ ! 69: char name[4]; /* Storage space for variable's name (and ! 70: * initial value). The name is at the ! 71: * beginning, and is null-terminated. ! 72: * May contain more than 4 bytes (see ! 73: * VAR_SIZE macro below). */ ! 74: } Var; ! 75: ! 76: #define VAR_SIZE(nameLength, valueLength) \ ! 77: ((unsigned) sizeof(Var) + nameLength + valueLength - 2) ! 78: ! 79: /* ! 80: * Variable flags: ! 81: * ! 82: * VAR_DYNAMIC: 1 means the storage space for the value was ! 83: * dynamically allocated, and must eventually be ! 84: * freed. ! 85: * VAR_GLOBAL: Used only in local variables. Means that this ! 86: * is really a global variable. ! 87: * VAR_DOESNT_EXIST: 1 means this variable has not yet been assigned ! 88: * a value. Used when a "global" command refers ! 89: * to a variable that hasn't been set yet. ! 90: */ ! 91: ! 92: #define VAR_DYNAMIC 1 ! 93: #define VAR_GLOBAL 2 ! 94: #define VAR_DOESNT_EXIST 4 ! 95: ! 96: /* ! 97: * The structure below defines a command procedure, which consists of ! 98: * a collection of Tcl commands plus information about arguments and ! 99: * variables. ! 100: */ ! 101: ! 102: typedef struct Proc { ! 103: struct Interp *iPtr; /* Interpreter for which this command ! 104: * is defined. */ ! 105: char *command; /* Command that constitutes the body of ! 106: * the procedure (dynamically allocated). */ ! 107: Var *argPtr; /* Pointer to first in list of variables ! 108: * giving names to the procedure's arguments. ! 109: * The order of the variables is the same ! 110: * as the order of the arguments. The "value" ! 111: * fields of the variables are the default ! 112: * values. */ ! 113: } Proc; ! 114: ! 115: /* ! 116: * The structure below defines a trace. This is used to allow Tcl ! 117: * clients to find out whenever a command is about to be executed. ! 118: */ ! 119: ! 120: typedef struct Trace { ! 121: int level; /* Only trace commands at nesting level ! 122: * less than or equal to this. */ ! 123: void (*proc)(); /* Procedure to call to trace command. */ ! 124: ClientData clientData; /* Arbitrary value to pass to proc. */ ! 125: struct Trace *nextPtr; /* Next in list of traces for this interp. */ ! 126: } Trace; ! 127: ! 128: /* ! 129: * The stucture below defines an interpreter callback, which is ! 130: * a procedure to invoke just before an interpreter is deleted. ! 131: */ ! 132: ! 133: typedef struct InterpCallback { ! 134: void (*proc)(); /* Procedure to call. */ ! 135: ClientData clientData; /* Value to pass to procedure. */ ! 136: struct InterpCallback *nextPtr; ! 137: /* Next in list of callbacks for this ! 138: * interpreter (or NULL for end of ! 139: * list). */ ! 140: } InterpCallback; ! 141: ! 142: /* ! 143: * The structure below defines a frame, which is a procedure invocation. ! 144: * These structures exist only while procedures are being executed, and ! 145: * provide a sort of call stack. ! 146: */ ! 147: ! 148: typedef struct CallFrame { ! 149: Var *varPtr; /* First in list of all local variables ! 150: * and arguments for this procedure ! 151: * invocation. */ ! 152: int level; /* Level of this procedure, for "uplevel" ! 153: * purposes (i.e. corresponds to nesting of ! 154: * callerVarPtr's, not callerPtr's). 1 means ! 155: * outer-most procedure, 0 means top-level. */ ! 156: int argc; /* This and argv below describe name and ! 157: * arguments for this procedure invocation. */ ! 158: char **argv; /* Array of arguments. */ ! 159: struct CallFrame *callerPtr; ! 160: /* Frame of procedure that invoked this one ! 161: * (NULL if level == 1). */ ! 162: struct CallFrame *callerVarPtr; ! 163: /* Frame used by caller for accessing local ! 164: * variables (same as callerPtr unless an ! 165: * "uplevel" command was active in the ! 166: * caller). This field is used in the ! 167: * implementation of "uplevel". */ ! 168: } CallFrame; ! 169: ! 170: /* ! 171: * The structure below defines one history event (a previously-executed ! 172: * command that can be re-executed in whole or in part). ! 173: */ ! 174: ! 175: typedef struct { ! 176: char *command; /* String containing previously-executed ! 177: * command. */ ! 178: int bytesAvl; /* Total # of bytes available at *event (not ! 179: * all are necessarily in use now). */ ! 180: } HistoryEvent; ! 181: ! 182: /* ! 183: * The structure below defines a pending revision to the most recent ! 184: * history event. Changes are linked together into a list and applied ! 185: * during the next call to Tcl_RecordHistory. See the comments at the ! 186: * beginning of tclHistory.c for information on revisions. ! 187: */ ! 188: ! 189: typedef struct HistoryRev { ! 190: int firstIndex; /* Index of the first byte to replace in ! 191: * current history event. */ ! 192: int lastIndex; /* Index of last byte to replace in ! 193: * current history event. */ ! 194: int newSize; /* Number of bytes in newBytes. */ ! 195: char *newBytes; /* Replacement for the range given by ! 196: * firstIndex and lastIndex. */ ! 197: struct HistoryRev *nextPtr; /* Next in chain of revisions to apply, or ! 198: * NULL for end of list. */ ! 199: } HistoryRev; ! 200: ! 201: /* ! 202: * This structure defines an interpreter, which is a collection of commands ! 203: * plus other state information related to interpreting commands, such as ! 204: * variable storage. The lists of commands and variables are sorted by usage: ! 205: * each time a command or variable is used it is pulled to the front of its ! 206: * list. ! 207: */ ! 208: ! 209: typedef struct Interp { ! 210: ! 211: /* ! 212: * Note: the first three fields must match exactly the fields in ! 213: * a Tcl_Interp struct (see tcl.h). If you change one, be sure to ! 214: * change the other. ! 215: */ ! 216: ! 217: char *result; /* Points to result returned by last ! 218: * command. */ ! 219: int dynamic; /* Non-zero means result is dynamically- ! 220: * allocated and must be freed by Tcl_Eval ! 221: * before executing the next command. */ ! 222: int errorLine; /* When TCL_ERROR is returned, this gives ! 223: * the line number within the command where ! 224: * the error occurred (1 means first line). */ ! 225: Command *commandPtr; /* First command in list containing all ! 226: * commands defined for this table. */ ! 227: ! 228: /* ! 229: * Information related to procedures and variables. See tclProc.c ! 230: * for usage. ! 231: */ ! 232: ! 233: Var *globalPtr; /* First in list of all global variables for ! 234: * this command table. */ ! 235: Var *localPtr; /* First in list of all local variables and ! 236: * arguments for the Tcl procedure that is ! 237: * currently being executed. If no procedure ! 238: * is being executed, or if it has no vars or ! 239: * args, this will be NULL. */ ! 240: int numLevels; /* Keeps track of how many nested calls to ! 241: * Tcl_Eval are in progress for this ! 242: * interpreter. It's used to delay deletion ! 243: * of the table until all Tcl_Eval invocations ! 244: * are completed. */ ! 245: CallFrame *framePtr; /* If a procedure is being executed, this ! 246: * points to the call frame for the current ! 247: * procedure (most recently-called). NULL ! 248: * means no procedure is active. */ ! 249: CallFrame *varFramePtr; /* Points to the call frame whose variables ! 250: * are currently in use (same as framePtr ! 251: * unless an "uplevel" command is being ! 252: * executed). NULL means no procedure is ! 253: * active or "uplevel 0" is being exec'ed. */ ! 254: ! 255: /* ! 256: * Information related to history: ! 257: */ ! 258: ! 259: int numEvents; /* Number of previously-executed commands ! 260: * to retain. */ ! 261: HistoryEvent *events; /* Array containing numEvents entries ! 262: * (dynamically allocated). */ ! 263: int curEvent; /* Index into events of place where current ! 264: * (or most recent) command is recorded. */ ! 265: int curEventNum; /* Event number associated with the slot ! 266: * given by curEvent. */ ! 267: HistoryRev *revPtr; /* First in list of pending revisions. */ ! 268: char *historyFirst; /* First char. of current command executed ! 269: * from history module. NULL means don't ! 270: * do history revision (see tclHistory.c ! 271: * for details on revision). */ ! 272: char *evalFirst; /* If TCL_RECORD_BOUNDS flag set, Tcl_Eval ! 273: * sets this field to point to the first ! 274: * char. of text from which the current ! 275: * command came. Otherwise Tcl_Eval sets ! 276: * this to NULL. */ ! 277: char *evalLast; /* Similar to evalFirst, except points to ! 278: * last character of current command. */ ! 279: ! 280: /* ! 281: * Miscellaneous information: ! 282: */ ! 283: ! 284: int cmdCount; /* Total number of times a command procedure ! 285: * has been called for this interpreter. */ ! 286: int noEval; /* Non-zero means no commands should actually ! 287: * be executed: just parse only. Used in ! 288: * expressions when the result is already ! 289: * determined. */ ! 290: int flags; /* Various flag bits. See below. */ ! 291: Trace *tracePtr; /* List of traces for this interpreter. */ ! 292: InterpCallback *callbackPtr;/* List of callbacks to invoke when ! 293: * interpreter is deleted. */ ! 294: char resultSpace[TCL_RESULT_SIZE]; ! 295: /* Static space for storing small results. */ ! 296: } Interp; ! 297: ! 298: /* ! 299: * Flag bits for Interp structures: ! 300: * ! 301: * DELETED: Non-zero means the interpreter has been deleted: ! 302: * don't process any more commands for it, and destroy ! 303: * the structure as soon as all nested invocations of ! 304: * Tcl_Eval are done. ! 305: * ERR_IN_PROGRESS: Non-zero means an error unwind is already in progress. ! 306: * Zero means a command proc has been invoked since last ! 307: * error occured. ! 308: * ERR_ALREADY_LOGGED: Non-zero means information has already been logged ! 309: * in $errorInfo for the current Tcl_Eval instance, ! 310: * so Tcl_Eval needn't log it (used to implement the ! 311: * "error message log" command). ! 312: */ ! 313: ! 314: #define DELETED 1 ! 315: #define ERR_IN_PROGRESS 2 ! 316: #define ERR_ALREADY_LOGGED 4 ! 317: ! 318: /* ! 319: * Additional flags passed to Tcl_Eval. See tcl.h for other flags to ! 320: * Tcl_Eval; these ones are only used internally by Tcl. ! 321: * ! 322: * TCL_RECORD_BOUNDS Tells Tcl_Eval to record information in the ! 323: * evalFirst and evalLast fields for each command ! 324: * executed directly from the string (top-level ! 325: * commands and those from command substitution). ! 326: */ ! 327: ! 328: #define TCL_RECORD_BOUNDS 0x100 ! 329: ! 330: /* ! 331: * Maximum number of levels of nesting permitted in Tcl commands. ! 332: */ ! 333: ! 334: #define MAX_NESTING_DEPTH 100 ! 335: ! 336: /* ! 337: * Procedures shared among Tcl modules but not used by the outside ! 338: * world: ! 339: */ ! 340: ! 341: extern void TclCopyAndCollapse(); ! 342: extern void TclDeleteVars(); ! 343: extern Command * TclFindCmd(); ! 344: extern int TclFindElement(); ! 345: extern Proc * TclFindProc(); ! 346: extern Proc * TclIsProc(); ! 347: extern char * TclWordEnd(); ! 348: ! 349: #endif _TCLINT
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.