1 |
578 |
markom |
/*
|
2 |
|
|
* ------------------------------------------------------------------------
|
3 |
|
|
* PACKAGE: [incr Tcl]
|
4 |
|
|
* DESCRIPTION: Object-Oriented Extensions to Tcl
|
5 |
|
|
*
|
6 |
|
|
* This file contains procedures that belong in the Tcl/Tk core.
|
7 |
|
|
* Hopefully, they'll migrate there soon.
|
8 |
|
|
*
|
9 |
|
|
* ========================================================================
|
10 |
|
|
* AUTHOR: Michael J. McLennan
|
11 |
|
|
* Bell Labs Innovations for Lucent Technologies
|
12 |
|
|
* mmclennan@lucent.com
|
13 |
|
|
* http://www.tcltk.com/itcl
|
14 |
|
|
*
|
15 |
|
|
* RCS: $Id: itcl_migrate.c,v 1.1.1.1 2002-01-16 10:24:46 markom Exp $
|
16 |
|
|
* ========================================================================
|
17 |
|
|
* Copyright (c) 1993-1998 Lucent Technologies, Inc.
|
18 |
|
|
* ------------------------------------------------------------------------
|
19 |
|
|
* See the file "license.terms" for information on usage and redistribution
|
20 |
|
|
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
21 |
|
|
*/
|
22 |
|
|
#include "itclInt.h"
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/*
|
26 |
|
|
*----------------------------------------------------------------------
|
27 |
|
|
*
|
28 |
|
|
* _Tcl_GetCallFrame --
|
29 |
|
|
*
|
30 |
|
|
* Checks the call stack and returns the call frame some number
|
31 |
|
|
* of levels up. It is often useful to know the invocation
|
32 |
|
|
* context for a command.
|
33 |
|
|
*
|
34 |
|
|
* Results:
|
35 |
|
|
* Returns a token for the call frame 0 or more levels up in
|
36 |
|
|
* the call stack.
|
37 |
|
|
*
|
38 |
|
|
* Side effects:
|
39 |
|
|
* None.
|
40 |
|
|
*
|
41 |
|
|
*----------------------------------------------------------------------
|
42 |
|
|
*/
|
43 |
|
|
Tcl_CallFrame*
|
44 |
|
|
_Tcl_GetCallFrame(interp, level)
|
45 |
|
|
Tcl_Interp *interp; /* interpreter being queried */
|
46 |
|
|
int level; /* number of levels up in the call stack (>= 0) */
|
47 |
|
|
{
|
48 |
|
|
Interp *iPtr = (Interp*)interp;
|
49 |
|
|
CallFrame *framePtr;
|
50 |
|
|
|
51 |
|
|
if (level < 0) {
|
52 |
|
|
panic("itcl: _Tcl_GetCallFrame called with bad number of levels");
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
framePtr = iPtr->varFramePtr;
|
56 |
|
|
while (framePtr && level > 0) {
|
57 |
|
|
framePtr = framePtr->callerVarPtr;
|
58 |
|
|
level--;
|
59 |
|
|
}
|
60 |
|
|
return (Tcl_CallFrame*)framePtr;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
/*
|
65 |
|
|
*----------------------------------------------------------------------
|
66 |
|
|
*
|
67 |
|
|
* _Tcl_ActivateCallFrame --
|
68 |
|
|
*
|
69 |
|
|
* Makes an existing call frame the current frame on the
|
70 |
|
|
* call stack. Usually called in conjunction with
|
71 |
|
|
* _Tcl_GetCallFrame to simulate the effect of an "uplevel"
|
72 |
|
|
* command.
|
73 |
|
|
*
|
74 |
|
|
* Note that this procedure is different from Tcl_PushCallFrame,
|
75 |
|
|
* which adds a new call frame to the call stack. This procedure
|
76 |
|
|
* assumes that the call frame is already initialized, and it
|
77 |
|
|
* merely activates it on the call stack.
|
78 |
|
|
*
|
79 |
|
|
* Results:
|
80 |
|
|
* Returns a token for the call frame that was in effect before
|
81 |
|
|
* activating the new context. That call frame can be restored
|
82 |
|
|
* by calling _Tcl_ActivateCallFrame again.
|
83 |
|
|
*
|
84 |
|
|
* Side effects:
|
85 |
|
|
* None.
|
86 |
|
|
*
|
87 |
|
|
*----------------------------------------------------------------------
|
88 |
|
|
*/
|
89 |
|
|
Tcl_CallFrame*
|
90 |
|
|
_Tcl_ActivateCallFrame(interp, framePtr)
|
91 |
|
|
Tcl_Interp *interp; /* interpreter being queried */
|
92 |
|
|
Tcl_CallFrame *framePtr; /* call frame to be activated */
|
93 |
|
|
{
|
94 |
|
|
Interp *iPtr = (Interp*)interp;
|
95 |
|
|
CallFrame *oldFramePtr;
|
96 |
|
|
|
97 |
|
|
oldFramePtr = iPtr->varFramePtr;
|
98 |
|
|
iPtr->varFramePtr = (CallFrame *) framePtr;
|
99 |
|
|
|
100 |
|
|
return (Tcl_CallFrame *) oldFramePtr;
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/*
|
104 |
|
|
*----------------------------------------------------------------------
|
105 |
|
|
*
|
106 |
|
|
* _TclNewVar --
|
107 |
|
|
*
|
108 |
|
|
* Create a new heap-allocated variable that will eventually be
|
109 |
|
|
* entered into a hashtable.
|
110 |
|
|
*
|
111 |
|
|
* Results:
|
112 |
|
|
* The return value is a pointer to the new variable structure. It is
|
113 |
|
|
* marked as a scalar variable (and not a link or array variable). Its
|
114 |
|
|
* value initially is NULL. The variable is not part of any hash table
|
115 |
|
|
* yet. Since it will be in a hashtable and not in a call frame, its
|
116 |
|
|
* name field is set NULL. It is initially marked as undefined.
|
117 |
|
|
*
|
118 |
|
|
* Side effects:
|
119 |
|
|
* Storage gets allocated.
|
120 |
|
|
*
|
121 |
|
|
*----------------------------------------------------------------------
|
122 |
|
|
*/
|
123 |
|
|
|
124 |
|
|
Var *
|
125 |
|
|
_TclNewVar()
|
126 |
|
|
{
|
127 |
|
|
register Var *varPtr;
|
128 |
|
|
|
129 |
|
|
varPtr = (Var *) ckalloc(sizeof(Var));
|
130 |
|
|
varPtr->value.objPtr = NULL;
|
131 |
|
|
varPtr->name = NULL;
|
132 |
|
|
varPtr->nsPtr = NULL;
|
133 |
|
|
varPtr->hPtr = NULL;
|
134 |
|
|
varPtr->refCount = 0;
|
135 |
|
|
varPtr->tracePtr = NULL;
|
136 |
|
|
varPtr->searchPtr = NULL;
|
137 |
|
|
varPtr->flags = (VAR_SCALAR | VAR_UNDEFINED | VAR_IN_HASHTABLE);
|
138 |
|
|
return varPtr;
|
139 |
|
|
}
|