home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 0 / 0988 / tclInt.h < prev   
Encoding:
C/C++ Source or Header  |  1990-12-28  |  8.9 KB  |  253 lines

  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.19 90/01/27 14:40:46 ouster Exp $ SPRITE (Berkeley)
  16.  */
  17.  
  18. #ifndef _TCLINT
  19. #define _TCLINT
  20.  
  21. #ifndef _TCL
  22. #include "tcl.h"
  23. #endif
  24.  
  25. /*
  26.  * The structure below defines one Tcl command, by associating a procedure
  27.  * with a textual string.
  28.  */
  29.  
  30. typedef struct Command {
  31.     int (*proc)();        /* Procedure to process command. */
  32.     ClientData clientData;    /* Arbitrary value to pass to proc. */
  33.     void (*deleteProc)();    /* Procedure to invoke when deleting
  34.                  * command. */
  35.     struct Command *nextPtr;    /* Pointer to next command in list, or NULL
  36.                  * for end of list. */
  37.     char name[4];        /* Name of command.  The actual size of this
  38.                  * portion is as large as is necessary to
  39.                  * hold the characters.  This must be the
  40.                  * last subfield of the record. */
  41. } Command;
  42.  
  43. #define CMD_SIZE(nameLength) ((unsigned) sizeof(Command) + nameLength - 3)
  44.  
  45. /*
  46.  * The structure below defines a variable, which associates a string name
  47.  * with a string value.  To cut down on the number of malloc's and free's
  48.  * (particularly for procedure parameters), space for both the variable's
  49.  * name and initial value is allocated at the end of the structure (in
  50.  * "storage").  If the variable's value changes later, a new dynamic
  51.  * string is allocated, if there is insufficient space in the current
  52.  * storage area.
  53.  */
  54.  
  55. typedef struct Var {
  56.     char *value;        /* Current value of variable (either points
  57.                  * to static space after name, or to dynamic
  58.                  * space if VAR_DYNAMIC is set). */
  59.     int valueLength;        /* Number of bytes of storage at the place
  60.                  * referred to by value, not including space
  61.                  * for NULL terminator. */
  62.     int flags;            /* Miscellaneous flags:  see below. */
  63.     struct Var *globalPtr;    /* If VAR_GLOBAL is set, this points to the
  64.                  * global variable corresponding to name. */
  65.     struct Var *nextPtr;    /* Next variable in list, or NULL for end
  66.                  * of list. */
  67.     char name[4];        /* Storage space for variable's name (and
  68.                  * initial value).  The name is at the
  69.                  * beginning, and is null-terminated.
  70.                  * May contain more than 4 bytes (see
  71.                  * VAR_SIZE macro below). */
  72. } Var;
  73.  
  74. #define VAR_SIZE(nameLength, valueLength) \
  75.     ((unsigned) sizeof(Var) + nameLength + valueLength - 2)
  76.  
  77. /*
  78.  * Variable flags:
  79.  *
  80.  * VAR_DYNAMIC:        1 means the storage space for the value was
  81.  *            dynamically allocated, and must eventually be
  82.  *            freed.
  83.  * VAR_GLOBAL:        Used only in local variables.  Means that this
  84.  *            is really a global variable.
  85.  */
  86.  
  87. #define VAR_DYNAMIC    1
  88. #define VAR_GLOBAL    2
  89.  
  90. /*
  91.  * The structure below defines a command procedure, which consists of
  92.  * a collection of Tcl commands plus information about arguments and
  93.  * variables.
  94.  */
  95.  
  96. typedef struct Proc {
  97.     struct Interp *iPtr;    /* Interpreter for which this command
  98.                  * is defined. */
  99.     char *command;        /* Command that constitutes the body of
  100.                  * the procedure (dynamically allocated). */
  101.     Var *argPtr;        /* Pointer to first in list of variables
  102.                  * giving names to the procedure's arguments.
  103.                  * The order of the variables is the same
  104.                  * as the order of the arguments.  The "value"
  105.                  * fields of the variables are the default
  106.                  * values. */
  107. } Proc;
  108.  
  109. /*
  110.  * The structure below defines a trace.  This is used to allow Tcl
  111.  * clients to find out whenever a command is about to be executed.
  112.  */
  113.  
  114. typedef struct Trace {
  115.     int level;            /* Only trace commands at nesting level
  116.                  * less than or equal to this. */
  117.     void (*proc)();        /* Procedure to call to trace command. */
  118.     ClientData clientData;    /* Arbitrary value to pass to proc. */
  119.     struct Trace *nextPtr;    /* Next in list of traces for this interp. */
  120. } Trace;
  121.  
  122. /*
  123.  * The stucture below defines an interpreter callback, which is
  124.  * a procedure to invoke just before an interpreter is deleted.
  125.  */
  126.  
  127. typedef struct InterpCallback {
  128.     void (*proc)();        /* Procedure to call. */
  129.     ClientData clientData;    /* Value to pass to procedure. */
  130.     struct InterpCallback *nextPtr;
  131.                 /* Next in list of callbacks for this
  132.                  * interpreter (or NULL for end of
  133.                  * list). */
  134. } InterpCallback;
  135.  
  136. /*
  137.  * The structure below defines a frame, which is a procedure invocation.
  138.  * These structures exist only while procedures are being executed, and
  139.  * provide a sort of call stack.
  140.  */
  141.  
  142. typedef struct CallFrame {
  143.     Var *varPtr;        /* First in list of all local variables
  144.                  * and arguments for this procedure
  145.                  * invocation. */
  146.     int level;            /* Level of this procedure, for "uplevel"
  147.                  * purposes (i.e. corresponds to nesting of
  148.                  * callerVarPtr's, not callerPtr's).  1 means
  149.                  * outer-most procedure, 0 means top-level. */
  150.     int argc;            /* This and argv below describe name and
  151.                  * arguments for this procedure invocation. */
  152.     char **argv;        /* Array of arguments. */
  153.     struct CallFrame *callerPtr;
  154.                 /* Frame of procedure that invoked this one
  155.                  * (NULL if level == 1). */
  156.     struct CallFrame *callerVarPtr;
  157.                 /* Frame used by caller for accessing local
  158.                  * variables (same as callerPtr unless an
  159.                  * "uplevel" command was active in the
  160.                  * caller).  This field is used in the
  161.                  * implementation of "uplevel". */
  162. } CallFrame;
  163.  
  164. /*
  165.  * This structure defines an interpreter, which is a collection of commands
  166.  * plus other state information related to interpreting commands, such as
  167.  * variable storage.  The lists of commands and variables are sorted by usage:
  168.  * each time a command or variable is used it is pulled to the front of its
  169.  * list.
  170.  */
  171.  
  172. typedef struct Interp {
  173.  
  174.     /*
  175.      * Note:  the first two fields must match exactly the first
  176.      * fields in a Tcl_Interp struct (see tcl.h).  If you change
  177.      * one, be sure to change the other.
  178.      */
  179.  
  180.     char *result;        /* Points to result returned by last
  181.                  * command. */
  182.     int dynamic;        /* Non-zero means result is dynamically-
  183.                  * allocated and must be freed by Tcl_Eval
  184.                  * before executing the next command. */
  185.     int errorLine;        /* When TCL_ERROR is returned, this gives
  186.                  * the line number within the command where
  187.                  * the error occurred (1 means first line). */
  188.     Command *commandPtr;    /* First command in list containing all
  189.                  * commands defined for this table. */
  190.     Var *globalPtr;        /* First in list of all global variables for
  191.                  * this command table. */
  192.     Var *localPtr;        /* First in list of all local variables and
  193.                  * arguments for the Tcl procedure that is
  194.                  * currently being executed.  If no procedure
  195.                  * is being executed, or if it has no vars or
  196.                  * args, this will be NULL. */
  197.     int numLevels;        /* Keeps track of how many nested calls to
  198.                  * Tcl_Eval are in progress for this
  199.                  * interpreter.  It's used to delay deletion
  200.                  * of the table until all Tcl_Eval invocations
  201.                  * are completed. */
  202.     CallFrame *framePtr;    /* If a procedure is being executed, this
  203.                  * points to the call frame for the current
  204.                  * procedure (most recently-called).  NULL
  205.                  * means no procedure is active. */
  206.     CallFrame *varFramePtr;    /* Points to the call frame whose variables
  207.                  * are currently in use (same as framePtr
  208.                  * unless an "uplevel" command is being
  209.                  * executed).  NULL means no procedure is
  210.                  * active or "uplevel 0" is being exec'ed. */
  211.     int cmdCount;        /* Total number of times a command procedure
  212.                  * has been called for this interpreter. */
  213.     int errInProgress;        /* Non-zero means an error unwind is already
  214.                  * in progress.  Zero means Tcl_Eval has
  215.                  * been invoked since the last error
  216.                  * occurred. */
  217.     int noEval;            /* Non-zero means no commands should actually
  218.                  * be executed:  just parse only.  Used in
  219.                  * expressions when the result is already
  220.                  * determined. */
  221.     int flags;            /* Various flag bits.  See below. */
  222.     Trace *tracePtr;        /* List of traces for this interpreter. */
  223.     InterpCallback *callbackPtr;/* List of callbacks to invoke when
  224.                  * interpreter is deleted. */
  225.     char resultSpace[TCL_RESULT_SIZE];
  226.                 /* Static space for storing small results. */
  227. } Interp;
  228.  
  229. /*
  230.  * Flag bits for Interp structures:
  231.  *
  232.  * DELETED:        Non-zero means the interpreter has been deleted:
  233.  *            don't process any more commands for it, and destroy
  234.  *            the structure as soon as all nested invocations of
  235.  *            Tcl_Eval are done.
  236.  */
  237.  
  238. #define DELETED 1
  239.  
  240. /*
  241.  * Procedures shared among Tcl modules but not used by the outside
  242.  * world:
  243.  */
  244.  
  245. extern void        TclCopyAndCollapse();
  246. extern void        TclDeleteVars();
  247. extern Command *    TclFindCmd();
  248. extern int        TclFindElement();
  249. extern Proc *        TclFindProc();
  250. extern Proc *        TclIsProc();
  251.  
  252. #endif /* _TCLINT */
  253.