-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcmpProcBody.c
More file actions
284 lines (252 loc) · 7.48 KB
/
cmpProcBody.c
File metadata and controls
284 lines (252 loc) · 7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
* procbody.c --
*
* Contains the implementation of the Tcl object TclProProcBody, an object
* that encapsulates information about a compiled procedure body.
* This object is used by the compiler to store information about a compiled
* procedure body so that the loader can extract it back and regenerate it
* in its specialized proc command implementation.
* This object is essentially a container that knows how to copy and free its
* internal rep; the UpdateString and SetFromAny procedures don't expect to
* be called, and therefore panic when they are. To create this type of
* object, clients use the ProcBodyNewObj function. Access to the
* components of internal representation is provided via a number of
* procedures.
*
* Copyright (c) 1998-2000 Ajuba Solutions
* Copyright (c) 2000, 2017 ActiveState Software Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: cmpProcBody.c,v 1.2 2000/05/30 22:19:06 wart Exp $
*/
#include "cmpInt.h"
/*
* Prototypes for static functions in this file
*/
static void ProcBodyDup _ANSI_ARGS_((Tcl_Obj *srcPtr, Tcl_Obj *dupPtr));
static void ProcBodyFree _ANSI_ARGS_((Tcl_Obj *objPtr));
static int ProcBodySetFromAny _ANSI_ARGS_((Tcl_Interp *interp,
Tcl_Obj *objPtr));
static void ProcBodyUpdateString _ANSI_ARGS_((Tcl_Obj *objPtr));
/*
* The CompilerProcBodyObjType type
*/
static Tcl_ObjType cmpProcBodyObjType = {
CMP_PROCBODY_OBJ_TYPE_OLD, /* name for this type */
ProcBodyFree, /* FreeInternalRep procedure */
ProcBodyDup, /* DupInternalRep procedure */
ProcBodyUpdateString, /* UpdateString procedure */
ProcBodySetFromAny /* SetFromAny procedure */
};
/*
* controls registration of object types
*/
static int cmpTypesRegistered = 0;
/*
*----------------------------------------------------------------------
*
* ProcBodyRegisterTypes --
*
* Register the object type(s) used for the procedure body support.
* Can be called multiple times, it will register only once.
*
* Results:
* None.
*
* Side effects:
* Registers the "TclProProcBody" Tcl_Obj with TCL.
*
*----------------------------------------------------------------------
*/
void
ProcBodyRegisterTypes()
{
if (cmpTypesRegistered < 1) {
Tcl_RegisterObjType(&cmpProcBodyObjType);
cmpTypesRegistered = 1;
}
}
/*
*----------------------------------------------------------------------
*
* ProcBodyNewObj --
*
* Creates a new object, of type "TclProProcBody", whose internal
* representation is the given Proc struct.
* The newly created object's reference count is 0.
*
* Results:
* Returns a pointer to a newly allocated Tcl_Obj, 0 on error.
*
* Side effects:
* The reference count in the ByteCode attached to the Proc is bumped up
* by one, since the internal rep stores a pointer to it.
*
*----------------------------------------------------------------------
*/
Tcl_Obj *
ProcBodyNewObj(procPtr)
Proc *procPtr; /* the Proc struct to store as the internal
* representation. */
{
Tcl_Obj *objPtr;
if (!procPtr) {
panic("ProcBodyNewObj: NULL Proc pointer");
}
objPtr = Tcl_NewObj();
if (objPtr) {
objPtr->typePtr = &cmpProcBodyObjType;
objPtr->internalRep.otherValuePtr = (VOID *) procPtr;
procPtr->refCount++;
}
return objPtr;
}
/*
*----------------------------------------------------------------------
*
* ProcBodyDup --
*
* Tcl_ObjType's Dup function for the proc body object.
* Bumps the reference count on the Proc stored in the internal
* representation.
*
* Results:
* None.
*
* Side effects:
* Sets up the object in dupPtr to be a duplicate of the one in srcPtr.
*
*----------------------------------------------------------------------
*/
static void ProcBodyDup(srcPtr, dupPtr)
Tcl_Obj *srcPtr; /* object to copy */
Tcl_Obj *dupPtr; /* target object for the duplication */
{
Proc *procPtr = (Proc *) srcPtr->internalRep.otherValuePtr;
dupPtr->typePtr = &cmpProcBodyObjType;
dupPtr->internalRep.otherValuePtr = (VOID *) procPtr;
procPtr->refCount++;
}
/*
*----------------------------------------------------------------------
*
* ProcBodyFree --
*
* Tcl_ObjType's Free function for the proc body object.
* The reference count on its Proc struct is decreased by 1; if the count
* reaches 0, the proc is freed.
*
* Results:
* None.
*
* Side effects:
* If the reference count on the Proc struct reaches 0, the struct is freed.
*
*----------------------------------------------------------------------
*/
static void
ProcBodyFree(objPtr)
Tcl_Obj *objPtr; /* the object to clean up */
{
Proc *procPtr = (Proc *) objPtr->internalRep.otherValuePtr;
procPtr->refCount--;
if (procPtr->refCount <= 0) {
ProcBodyCleanupProc(procPtr);
}
}
/*
*----------------------------------------------------------------------
*
* ProcBodyCleanupProc --
*
* This procedure does all the real work of freeing up a Proc
* structure. It's called only when the structure's reference
* count becomes zero.
*
* Lifted from tclproc.c::CleanupProc.
*
* Results:
* None.
*
* Side effects:
* Memory gets freed.
*
*----------------------------------------------------------------------
*/
void
ProcBodyCleanupProc(procPtr)
Proc *procPtr; /* Procedure to be deleted. */
{
#if 1
TclProcCleanupProc(procPtr);
#else
register CompiledLocal *localPtr;
Tcl_Obj *bodyPtr = procPtr->bodyPtr;
Tcl_Obj *defPtr;
if (bodyPtr != NULL) {
Tcl_DecrRefCount(bodyPtr);
}
for (localPtr = procPtr->firstLocalPtr; localPtr != NULL; ) {
CompiledLocal *nextPtr = localPtr->nextPtr;
if (localPtr->defValuePtr != NULL) {
defPtr = localPtr->defValuePtr;
Tcl_DecrRefCount(defPtr);
}
ckfree((char *) localPtr);
localPtr = nextPtr;
}
ckfree((char *) procPtr);
#endif
}
/*
*----------------------------------------------------------------------
*
* ProcBodySetFromAny --
*
* Tcl_ObjType's SetFromAny function for the proc body object.
* Calls panic.
*
* Results:
* Theoretically returns a TCL result code.
*
* Side effects:
* Calls panic, since we can't set the value of the object from a string
* representation (or any other internal ones).
*
*----------------------------------------------------------------------
*/
static int
ProcBodySetFromAny(interp, objPtr)
Tcl_Interp *interp; /* current interpreter */
Tcl_Obj *objPtr; /* object pointer */
{
panic("called ProcBodySetFromAny");
/*
* this to keep compilers happy.
*/
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* ProcBodyUpdateString --
*
* Tcl_ObjType's UpdateString function for the proc body object.
* Calls panic.
*
* Results:
* None.
*
* Side effects:
* Calls panic, since we this type has no string representation.
*
*----------------------------------------------------------------------
*/
static void
ProcBodyUpdateString(objPtr)
Tcl_Obj *objPtr; /* the object to update */
{
panic("called ProcBodyUpdateString");
}