summaryrefslogtreecommitdiffstats
path: root/generic/tclExecute.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclExecute.c')
-rw-r--r--generic/tclExecute.c111
1 files changed, 53 insertions, 58 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index d34b364..5cffc90 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -13,8 +13,6 @@
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: tclExecute.c,v 1.511 2010/12/30 23:10:07 msofer Exp $
*/
#include "tclInt.h"
@@ -170,28 +168,32 @@ static BuiltinFunc const tclBuiltinFuncTable[] = {
* Minimal data required to fully reconstruct the execution state.
*/
-typedef struct BottomData {
+typedef struct TEBCdata {
ByteCode *codePtr; /* Constant until the BC returns */
/* -----------------------------------------*/
- struct BottomData *expanded;/* NULL if unchanged, pointer to the succesor
+ struct TEBCdata *expanded;/* NULL if unchanged, pointer to the succesor
* if it was expanded */
const unsigned char *pc; /* These fields are used on return TO this */
ptrdiff_t *catchTop; /* this level: they record the state when a */
int cleanup; /* new codePtr was received for NR */
Tcl_Obj *auxObjList; /* execution. */
int checkInterp;
-} BottomData;
+ CmdFrame cmdFrame;
+ void * stack[1]; /* Start of the actual combined catch and obj
+ * stacks; the struct will be expanded as
+ * necessary */
+} TEBCdata;
-#define NR_YIELD(invoke) \
+#define TEBC_YIELD() \
esPtr->tosPtr = tosPtr; \
- BP->pc = pc; \
- BP->cleanup = cleanup; \
- TclNRAddCallback(interp, TEBCresume, BP, \
- INT2PTR(invoke), NULL, NULL)
+ TD->pc = pc; \
+ TD->cleanup = cleanup; \
+ TclNRAddCallback(interp, TEBCresume, TD, \
+ INT2PTR(1), NULL, NULL)
-#define NR_DATA_DIG() \
- pc = BP->pc; \
- cleanup = BP->cleanup; \
+#define TEBC_DATA_DIG() \
+ pc = TD->pc; \
+ cleanup = TD->cleanup; \
tosPtr = esPtr->tosPtr
@@ -932,7 +934,7 @@ TclDeleteExecEnv(
TclDecrRefCount(eePtr->constants[0]);
TclDecrRefCount(eePtr->constants[1]);
if (eePtr->callbackPtr) {
- Tcl_Panic("Deleting execEnv with pending TEOV callbacks!");
+ Tcl_Panic("Deleting execEnv with pending NRE callbacks!");
}
if (eePtr->corPtr) {
Tcl_Panic("Deleting execEnv with existing coroutine");
@@ -1323,7 +1325,7 @@ Tcl_ExprObj(
Tcl_Obj **resultPtrPtr) /* Where the Tcl_Obj* that is the expression
* result is stored if no errors occur. */
{
- TEOV_callback *rootPtr = TOP_CB(interp);
+ NRE_callback *rootPtr = TOP_CB(interp);
Tcl_Obj *resultPtr;
TclNewObj(resultPtr);
@@ -1912,8 +1914,8 @@ TclIncrObj(
*
*----------------------------------------------------------------------
*/
-#define bcFramePtr ((CmdFrame *) (BP + 1))
-#define initCatchTop (((ptrdiff_t *) (bcFramePtr + 1)) - 1)
+#define bcFramePtr (&TD->cmdFrame)
+#define initCatchTop ((ptrdiff_t *) (&TD->stack[-1]))
#define initTosPtr ((Tcl_Obj **) (initCatchTop+codePtr->maxExceptDepth))
#define esPtr (iPtr->execEnvPtr->execStackPtr)
@@ -1923,10 +1925,10 @@ TclNRExecuteByteCode(
ByteCode *codePtr) /* The bytecode sequence to interpret. */
{
Interp *iPtr = (Interp *) interp;
- BottomData *BP;
- int size = sizeof(BottomData) + sizeof(CmdFrame) +
+ TEBCdata *TD;
+ int size = sizeof(TEBCdata) -1 +
+ (codePtr->maxStackDepth + codePtr->maxExceptDepth)
- *(sizeof(Tcl_Obj *));
+ *(sizeof(void *));
int numWords = (size + sizeof(Tcl_Obj *) - 1)/sizeof(Tcl_Obj *);
if (iPtr->execEnvPtr->rewind) {
@@ -1936,9 +1938,9 @@ TclNRExecuteByteCode(
codePtr->refCount++;
/*
- * Reserve the stack, setup the BottomPtr and CallFrame
+ * Reserve the stack, setup the TEBCdataPtr (TD) and CallFrame
*
- * The execution uses a unified stack: first a BottomData, immediately
+ * The execution uses a unified stack: first a TEBCdata, immediately
* above it a CmdFrame, then the catch stack, then the execution stack.
*
* Make sure the catch stack is large enough to hold the maximum number of
@@ -1947,20 +1949,20 @@ TclNRExecuteByteCode(
* execution stack is large enough to execute this ByteCode.
*/
- BP = (BottomData *) GrowEvaluationStack(iPtr->execEnvPtr, numWords, 0);
+ TD = (TEBCdata *) GrowEvaluationStack(iPtr->execEnvPtr, numWords, 0);
esPtr->tosPtr = initTosPtr;
- BP->codePtr = codePtr;
- BP->expanded = NULL;
- BP->pc = codePtr->codeStart;
- BP->catchTop = initCatchTop;
- BP->cleanup = 0;
- BP->auxObjList = NULL;
- BP->checkInterp = 0;
+ TD->codePtr = codePtr;
+ TD->expanded = NULL;
+ TD->pc = codePtr->codeStart;
+ TD->catchTop = initCatchTop;
+ TD->cleanup = 0;
+ TD->auxObjList = NULL;
+ TD->checkInterp = 0;
/*
* TIP #280: Initialize the frame. Do not push it yet: it will be pushed
- * every time that we call out from this BP, popped when we return to it.
+ * every time that we call out from this TD, popped when we return to it.
*/
bcFramePtr->type = ((codePtr->flags & TCL_BYTECODE_PRECOMPILED)
@@ -1987,9 +1989,9 @@ TclNRExecuteByteCode(
* - bytecode execution
*/
- TclNRAddCallback(interp, TEBCreturn, BP, NULL,
+ TclNRAddCallback(interp, TEBCreturn, TD, NULL,
NULL, NULL);
- TclNRAddCallback(interp, TEBCresume, BP,
+ TclNRAddCallback(interp, TEBCresume, TD,
/*resume*/ INT2PTR(0), NULL, NULL);
return TCL_OK;
@@ -2001,16 +2003,16 @@ TEBCreturn(
Tcl_Interp *interp,
int result)
{
- BottomData *BP = data[0];
- ByteCode *codePtr = BP->codePtr;
+ TEBCdata *TD = data[0];
+ ByteCode *codePtr = TD->codePtr;
if (--codePtr->refCount <= 0) {
TclCleanupByteCode(codePtr);
}
- while (BP->expanded) {
- BP = BP->expanded;
+ while (TD->expanded) {
+ TD = TD->expanded;
}
- TclStackFree(interp, BP); /* free my stack */
+ TclStackFree(interp, TD); /* free my stack */
return result;
}
@@ -2038,7 +2040,6 @@ TEBCresume(
/*
* Bottom of allocated stack holds the NR data
*/
- /* NR_TEBC */
/*
* Constants: variables that do not change during the execution, used
@@ -2064,11 +2065,11 @@ TEBCresume(
* used too frequently
*/
- BottomData *BP = data[0];
-#define auxObjList (BP->auxObjList)
-#define catchTop (BP->catchTop)
-#define codePtr (BP->codePtr)
-#define checkInterp (BP->checkInterp)
+ TEBCdata *TD = data[0];
+#define auxObjList (TD->auxObjList)
+#define catchTop (TD->catchTop)
+#define codePtr (TD->codePtr)
+#define checkInterp (TD->checkInterp)
/* Indicates when a check of interp readyness
* is necessary. Set by CACHE_STACK_INFO() */
@@ -2107,7 +2108,7 @@ TEBCresume(
traceInstructions = (tclTraceExec == 3);
#endif
- NR_DATA_DIG();
+ TEBC_DATA_DIG();
#ifdef TCL_COMPILE_DEBUG
if (!data[1] && (tclTraceExec >= 2)) {
@@ -2688,17 +2689,17 @@ TEBCresume(
length = objc + (codePtr->maxStackDepth - TclGetInt4AtPtr(pc+1));
DECACHE_STACK_INFO();
moved = GrowEvaluationStack(iPtr->execEnvPtr, length, 1)
- - (Tcl_Obj **) BP;
+ - (Tcl_Obj **) TD;
if (moved) {
/*
* Change the global data to point to the new stack: move the
- * bottomPtr, recompute the position of every other
+ * TEBCdataPtr TD, recompute the position of every other
* stack-allocated parameter, update the stack pointers.
*/
esPtr = iPtr->execEnvPtr->execStackPtr;
- BP->expanded = (BottomData *) (((Tcl_Obj **)BP) + moved);
- BP = BP->expanded;
+ TD->expanded = (TEBCdata *) (((Tcl_Obj **)TD) + moved);
+ TD = TD->expanded;
catchTop += moved;
tosPtr += moved;
@@ -2727,7 +2728,7 @@ TEBCresume(
CACHE_STACK_INFO();
cleanup = 1;
pc++;
- NR_YIELD(1);
+ TEBC_YIELD();
return TclNRExecuteByteCode(interp, newCodePtr);
}
@@ -2742,7 +2743,7 @@ TEBCresume(
cleanup = 1;
pc += 1;
- NR_YIELD(1);
+ TEBC_YIELD();
return TclNREvalObjEx(interp, OBJ_AT_TOS, 0, NULL, 0);
case INST_INVOKE_EXPANDED:
@@ -2813,7 +2814,7 @@ TEBCresume(
DECACHE_STACK_INFO();
pc += pcAdjustment;
- NR_YIELD(1);
+ TEBC_YIELD();
return TclNREvalObjv(interp, objc, objv,
TCL_EVAL_NOERR, NULL);
@@ -6420,12 +6421,6 @@ TEBCresume(
CLANG_ASSERT(bcFramePtr);
}
- /*
- * Store the previous bottomPtr for returning to it, then free all
- * resources used by this bytecode and process callbacks until you return
- * to the previous bytecode (if any).
- */
-
iPtr->cmdFramePtr = bcFramePtr->nextPtr;
return result;
}