summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Sofer <miguel.sofer@gmail.com>2007-04-11 17:35:31 (GMT)
committerMiguel Sofer <miguel.sofer@gmail.com>2007-04-11 17:35:31 (GMT)
commitdf9a5d0effa8f6496703bbc7d67100e9a1d0890b (patch)
tree19e86b9281471e4e268a958026e1e7f96818cd7f
parent3d1c14d0802d7f68e7d18e10853524da03279c88 (diff)
downloadtcl-df9a5d0effa8f6496703bbc7d67100e9a1d0890b.zip
tcl-df9a5d0effa8f6496703bbc7d67100e9a1d0890b.tar.gz
tcl-df9a5d0effa8f6496703bbc7d67100e9a1d0890b.tar.bz2
* generic/tclExecute.c: new macros OBJ_AT_TOS, OBJ_UNDER_TOS,
OBJ_AT_DEPTH(n) and CURR_DEPTH that remove all direct references to tosPtr from TEBC (after initialisation and the code at the label cleanupV_pushObjResultPtr).
-rw-r--r--ChangeLog7
-rw-r--r--generic/tclExecute.c286
2 files changed, 152 insertions, 141 deletions
diff --git a/ChangeLog b/ChangeLog
index 0f95ffd..14f6408 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-12 Miguel Sofer <msofer@users.sf.net>
+
+ * generic/tclExecute.c: new macros OBJ_AT_TOS, OBJ_UNDER_TOS,
+ OBJ_AT_DEPTH(n) and CURR_DEPTH that remove all direct references
+ to tosPtr from TEBC (after initialisation and the code at the
+ label cleanupV_pushObjResultPtr).
+
2007-04-11 Miguel Sofer <msofer@users.sf.net>
* generic/tclCompCmds.c: moved all exceptDepth management to the
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index da4a5fd..639f80f 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -12,7 +12,7 @@
* 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.273 2007/04/10 22:06:35 dkf Exp $
+ * RCS: @(#) $Id: tclExecute.c,v 1.274 2007/04/11 17:35:32 msofer Exp $
*/
#include "tclInt.h"
@@ -207,8 +207,15 @@ long tclObjsShared[TCL_MAX_SHARED_OBJ_STATS] = { 0, 0, 0, 0, 0 };
#define PUSH_OBJECT(objPtr) \
Tcl_IncrRefCount(*(++tosPtr) = (objPtr))
-#define POP_OBJECT() \
- *(tosPtr--)
+#define POP_OBJECT() *(tosPtr--)
+
+#define OBJ_AT_TOS *tosPtr
+
+#define OBJ_UNDER_TOS *(tosPtr-1)
+
+#define OBJ_AT_DEPTH(n) *(tosPtr-(n))
+
+#define CURR_DEPTH (tosPtr-eePtr->stackPtr)
/*
* Macros used to trace instruction execution. The macros TRACE,
@@ -220,7 +227,7 @@ long tclObjsShared[TCL_MAX_SHARED_OBJ_STATS] = { 0, 0, 0, 0, 0 };
# define TRACE(a) \
if (traceInstructions) { \
fprintf(stdout, "%2d: %2d (%u) %s ", iPtr->numLevels, \
- (tosPtr - eePtr->stackPtr), \
+ CURR_DEPTH, \
(unsigned int)(pc - codePtr->codeStart), \
GetOpcodeName(pc)); \
printf a; \
@@ -232,7 +239,7 @@ long tclObjsShared[TCL_MAX_SHARED_OBJ_STATS] = { 0, 0, 0, 0, 0 };
# define TRACE_WITH_OBJ(a, objPtr) \
if (traceInstructions) { \
fprintf(stdout, "%2d: %2d (%u) %s ", iPtr->numLevels, \
- (tosPtr - eePtr->stackPtr), \
+ CURR_DEPTH, \
(unsigned int)(pc - codePtr->codeStart), \
GetOpcodeName(pc)); \
printf a; \
@@ -646,7 +653,7 @@ TclStackAlloc(
* Reserve the space in the exec stack, and store the data for freeing.
*/
- eePtr->tosPtr += numWords;
+ eePtr->tosPtr += numWords;//
*(eePtr->tosPtr-1) = (Tcl_Obj *) stackRefCountPtr;
*(eePtr->tosPtr) = (Tcl_Obj *) INT2PTR(numWords);
@@ -1164,7 +1171,7 @@ TclExecuteByteCode(
*/
ExecEnv *eePtr; /* Points to the execution environment. */
- int initStackTop; /* Stack top at start of execution. */
+ int initStackDepth; /* Stack top at start of execution. */
int initCatchTop; /* Catch stack top at start of execution. */
Var *compiledLocals;
Namespace *namespacePtr;
@@ -1229,7 +1236,7 @@ TclExecuteByteCode(
codePtr->maxExceptDepth + codePtr->maxStackDepth);
tosPtr = eePtr->tosPtr + codePtr->maxExceptDepth;
- initStackTop = tosPtr - eePtr->stackPtr;
+ initStackDepth = CURR_DEPTH;
/*
* TIP #280: Initialize the frame. Do not push it yet.
@@ -1251,7 +1258,7 @@ TclExecuteByteCode(
#ifdef TCL_COMPILE_DEBUG
if (tclTraceExec >= 2) {
PrintByteCodeInfo(codePtr);
- fprintf(stdout, " Starting stack top=%d\n", initStackTop);
+ fprintf(stdout, " Starting stack top=%d\n", initStackDepth);
fflush(stdout);
}
#endif
@@ -1304,10 +1311,10 @@ TclExecuteByteCode(
TclDecrRefCount(valuePtr);
case 1:
cleanup1_pushObjResultPtr:
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
TclDecrRefCount(valuePtr);
}
- *tosPtr = objResultPtr;
+ OBJ_AT_TOS = objResultPtr;
goto cleanup0;
cleanupV:
@@ -1341,10 +1348,10 @@ TclExecuteByteCode(
* Skip the stack depth check if an expansion is in progress
*/
- ValidatePcAndStackTop(codePtr, pc, (tosPtr - eePtr->stackPtr),
- initStackTop, /*checkStack*/ (expandNestList == NULL));
+ ValidatePcAndStackTop(codePtr, pc, CURR_DEPTH,
+ initStackDepth, /*checkStack*/ (expandNestList == NULL));
if (traceInstructions) {
- fprintf(stdout, "%2d: %2d ", iPtr->numLevels, (tosPtr - eePtr->stackPtr));
+ fprintf(stdout, "%2d: %2d ", iPtr->numLevels, CURR_DEPTH);
TclPrintInstruction(codePtr, pc);
fflush(stdout);
}
@@ -1400,7 +1407,7 @@ TclExecuteByteCode(
result = TclProcessReturn(interp, code, level, returnOpts);
Tcl_DecrRefCount(returnOpts);
if (result != TCL_OK) {
- Tcl_SetObjResult(interp, *tosPtr);
+ Tcl_SetObjResult(interp, OBJ_AT_TOS);
cleanup = 1;
goto processExceptionReturn;
}
@@ -1425,7 +1432,7 @@ TclExecuteByteCode(
}
case INST_DONE:
- if (tosPtr > eePtr->stackPtr + initStackTop) {
+ if (CURR_DEPTH > initStackDepth) {
/*
* Set the interpreter's object result to point to the topmost object
* from the stack, and check for a possible [catch]. The stackTop's
@@ -1433,7 +1440,7 @@ TclExecuteByteCode(
* "abnormalReturn".
*/
- Tcl_SetObjResult(interp, *tosPtr);
+ Tcl_SetObjResult(interp, OBJ_AT_TOS);
#ifdef TCL_COMPILE_DEBUG
TRACE_WITH_OBJ(("=> return code=%d, result=", result),
iPtr->objResultPtr);
@@ -1443,7 +1450,7 @@ TclExecuteByteCode(
#endif
goto checkForCatch;
} else {
- tosPtr--;
+ POP_OBJECT();
goto abnormalReturn;
}
@@ -1453,7 +1460,7 @@ TclExecuteByteCode(
instPush1Peephole:
#endif
PUSH_OBJECT(codePtr->objArrayPtr[TclGetUInt1AtPtr(pc+1)]);
- TRACE_WITH_OBJ(("%u => ", TclGetInt1AtPtr(pc+1)), *tosPtr);
+ TRACE_WITH_OBJ(("%u => ", TclGetInt1AtPtr(pc+1)), OBJ_AT_TOS);
pc += 2;
#if !TCL_COMPILE_DEBUG
/*
@@ -1474,7 +1481,7 @@ TclExecuteByteCode(
case INST_POP: {
Tcl_Obj *valuePtr;
- TRACE_WITH_OBJ(("=> discarding "), *tosPtr);
+ TRACE_WITH_OBJ(("=> discarding "), OBJ_AT_TOS);
valuePtr = POP_OBJECT();
TclDecrRefCount(valuePtr);
@@ -1551,7 +1558,7 @@ TclExecuteByteCode(
}
case INST_DUP:
- objResultPtr = *tosPtr;
+ objResultPtr = OBJ_AT_TOS;
TRACE_WITH_OBJ(("=> "), objResultPtr);
NEXT_INST_F(1, 0, 1);
@@ -1559,7 +1566,7 @@ TclExecuteByteCode(
int opnd;
opnd = TclGetUInt4AtPtr(pc+1);
- objResultPtr = *(tosPtr - opnd);
+ objResultPtr = OBJ_AT_DEPTH(opnd);
TRACE_WITH_OBJ(("=> "), objResultPtr);
NEXT_INST_F(5, 0, 1);
}
@@ -1575,7 +1582,7 @@ TclExecuteByteCode(
* Compute the length to be appended.
*/
- for (currPtr = tosPtr - (opnd-2); currPtr <= tosPtr; currPtr++) {
+ for (currPtr = &OBJ_AT_DEPTH(opnd-2); currPtr <= &OBJ_AT_TOS; currPtr++) {
bytes = Tcl_GetStringFromObj(*currPtr, &length);
if (bytes != NULL) {
appendLen += length;
@@ -1604,20 +1611,20 @@ TclExecuteByteCode(
* bytes, currPtr to the second object.
*/
- objResultPtr = *(tosPtr-(opnd-1));
+ objResultPtr = OBJ_AT_DEPTH(opnd-1);
bytes = Tcl_GetStringFromObj(objResultPtr, &length);
#if !TCL_COMPILE_DEBUG
if (!Tcl_IsShared(objResultPtr)) {
Tcl_SetObjLength(objResultPtr, (length + appendLen));
p = TclGetString(objResultPtr) + length;
- currPtr = tosPtr - (opnd - 2);
+ currPtr = &OBJ_AT_DEPTH(opnd - 2);
} else {
#endif
p = (char *) ckalloc((unsigned) (length + appendLen + 1));
TclNewObj(objResultPtr);
objResultPtr->bytes = p;
objResultPtr->length = length + appendLen;
- currPtr = tosPtr - (opnd - 1);
+ currPtr = &OBJ_AT_DEPTH(opnd - 1);
#if !TCL_COMPILE_DEBUG
}
#endif
@@ -1626,7 +1633,7 @@ TclExecuteByteCode(
* Append the remaining characters.
*/
- for (; currPtr <= tosPtr; currPtr++) {
+ for (; currPtr <= &OBJ_AT_TOS; currPtr++) {
bytes = Tcl_GetStringFromObj(*currPtr, &length);
if (bytes != NULL) {
memcpy(p, bytes, (size_t) length);
@@ -1642,8 +1649,8 @@ TclExecuteByteCode(
case INST_EXPAND_START: {
/*
* Push an element to the expandNestList. This records the current
- * tosPtr - i.e., the point in the stack where the expanded command
- * starts.
+ * stack depth - i.e., the point in the stack where the expanded
+ * command starts.
*
* Use a Tcl_Obj as linked list element; slight mem waste, but faster
* allocation than ckalloc. This also abuses the Tcl_Obj structure, as
@@ -1656,8 +1663,7 @@ TclExecuteByteCode(
Tcl_Obj *objPtr;
TclNewObj(objPtr);
- objPtr->internalRep.twoPtrValue.ptr1 = (VOID *)
- (tosPtr - eePtr->stackPtr);
+ objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) CURR_DEPTH;
objPtr->internalRep.twoPtrValue.ptr2 = (VOID *) expandNestList;
expandNestList = objPtr;
NEXT_INST_F(1, 0, 0);
@@ -1672,7 +1678,7 @@ TclExecuteByteCode(
* the element from the expand link list and leave.
*/
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
if (Tcl_ListObjGetElements(interp, valuePtr, &objc, &objv) != TCL_OK) {
result = TCL_ERROR;
TRACE_WITH_OBJ(("%.30s => ERROR: ", O2S(valuePtr)),
@@ -1682,7 +1688,7 @@ TclExecuteByteCode(
TclDecrRefCount(objPtr);
goto checkForCatch;
}
- tosPtr--;
+ POP_OBJECT();
/*
* Make sure there is enough room in the stack to expand this list
@@ -1719,7 +1725,7 @@ TclExecuteByteCode(
Tcl_Obj *objPtr = expandNestList;
expandNestList = (Tcl_Obj *) objPtr->internalRep.twoPtrValue.ptr2;
- objc = tosPtr - eePtr->stackPtr
+ objc = CURR_DEPTH
- (ptrdiff_t) objPtr->internalRep.twoPtrValue.ptr1;
TclDecrRefCount(objPtr);
}
@@ -1747,7 +1753,7 @@ TclExecuteByteCode(
doInvocation:
{
- Tcl_Obj **objv = (tosPtr - (objc-1));
+ Tcl_Obj **objv = &OBJ_AT_DEPTH(objc-1);
int length;
const char *bytes;
Command *cmdPtr;
@@ -1898,7 +1904,7 @@ TclExecuteByteCode(
* OPTIMISE!
*/
- Tcl_Obj *objPtr = *tosPtr;
+ Tcl_Obj *objPtr = OBJ_AT_TOS;
DECACHE_STACK_INFO();
@@ -1943,7 +1949,7 @@ TclExecuteByteCode(
case INST_EXPR_STK: {
Tcl_Obj *objPtr, *valuePtr;
- objPtr = *tosPtr;
+ objPtr = OBJ_AT_TOS;
DECACHE_STACK_INFO();
/*Tcl_ResetResult(interp);*/
result = Tcl_ExprObj(interp, objPtr, &valuePtr);
@@ -2021,8 +2027,8 @@ TclExecuteByteCode(
case INST_LOAD_ARRAY_STK:
cleanup = 2;
- part2 = Tcl_GetString(*tosPtr); /* element name */
- objPtr = *(tosPtr - 1); /* array name */
+ part2 = Tcl_GetString(OBJ_AT_TOS); /* element name */
+ objPtr = OBJ_UNDER_TOS; /* array name */
TRACE(("\"%.30s(%.30s)\" => ", O2S(objPtr), part2));
goto doLoadStk;
@@ -2030,7 +2036,7 @@ TclExecuteByteCode(
case INST_LOAD_SCALAR_STK:
cleanup = 1;
part2 = NULL;
- objPtr = *tosPtr; /* variable name */
+ objPtr = OBJ_AT_TOS; /* variable name */
TRACE(("\"%.30s\" => ", O2S(objPtr)));
doLoadStk:
@@ -2065,7 +2071,7 @@ TclExecuteByteCode(
pcAdjustment = 2;
doLoadArray:
- part2 = TclGetString(*tosPtr);
+ part2 = TclGetString(OBJ_AT_TOS);
arrayPtr = &(compiledLocals[opnd]);
part1 = arrayPtr->name;
while (TclIsVarLink(arrayPtr)) {
@@ -2145,45 +2151,45 @@ TclExecuteByteCode(
Tcl_Obj *objPtr, *valuePtr;
case INST_LAPPEND_STK:
- valuePtr = *tosPtr; /* value to append */
+ valuePtr = OBJ_AT_TOS; /* value to append */
part2 = NULL;
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE
| TCL_LIST_ELEMENT | TCL_TRACE_READS);
goto doStoreStk;
case INST_LAPPEND_ARRAY_STK:
- valuePtr = *tosPtr; /* value to append */
- part2 = TclGetString(*(tosPtr - 1));
+ valuePtr = OBJ_AT_TOS; /* value to append */
+ part2 = TclGetString(OBJ_UNDER_TOS);
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE
| TCL_LIST_ELEMENT | TCL_TRACE_READS);
goto doStoreStk;
case INST_APPEND_STK:
- valuePtr = *tosPtr; /* value to append */
+ valuePtr = OBJ_AT_TOS; /* value to append */
part2 = NULL;
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE);
goto doStoreStk;
case INST_APPEND_ARRAY_STK:
- valuePtr = *tosPtr; /* value to append */
- part2 = TclGetString(*(tosPtr - 1));
+ valuePtr = OBJ_AT_TOS; /* value to append */
+ part2 = TclGetString(OBJ_UNDER_TOS);
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE);
goto doStoreStk;
case INST_STORE_ARRAY_STK:
- valuePtr = *tosPtr;
- part2 = TclGetString(*(tosPtr - 1));
+ valuePtr = OBJ_AT_TOS;
+ part2 = TclGetString(OBJ_UNDER_TOS);
storeFlags = TCL_LEAVE_ERR_MSG;
goto doStoreStk;
case INST_STORE_STK:
case INST_STORE_SCALAR_STK:
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
part2 = NULL;
storeFlags = TCL_LEAVE_ERR_MSG;
doStoreStk:
- objPtr = *(tosPtr - 1 - (part2 != NULL)); /* variable name */
+ objPtr = OBJ_AT_DEPTH(1 + (part2 != NULL)); /* variable name */
part1 = TclGetString(objPtr);
#ifdef TCL_COMPILE_DEBUG
if (part2 == NULL) {
@@ -2243,8 +2249,8 @@ TclExecuteByteCode(
storeFlags = TCL_LEAVE_ERR_MSG;
doStoreArray:
- valuePtr = *tosPtr;
- part2 = TclGetString(*(tosPtr - 1));
+ valuePtr = OBJ_AT_TOS;
+ part2 = TclGetString(OBJ_UNDER_TOS);
arrayPtr = &(compiledLocals[opnd]);
part1 = arrayPtr->name;
cleanup = 2;
@@ -2309,7 +2315,7 @@ TclExecuteByteCode(
storeFlags = TCL_LEAVE_ERR_MSG;
doStoreScalar:
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
varPtr = &(compiledLocals[opnd]);
part1 = varPtr->name;
TRACE(("%u <- \"%.30s\" => ", opnd, O2S(valuePtr)));
@@ -2331,7 +2337,7 @@ TclExecuteByteCode(
*/
valuePtr = varPtr->value.objPtr;
- objResultPtr = *tosPtr;
+ objResultPtr = OBJ_AT_TOS;
if (valuePtr != objResultPtr) {
if (valuePtr != NULL) {
TclDecrRefCount(valuePtr);
@@ -2403,8 +2409,7 @@ TclExecuteByteCode(
case INST_INCR_SCALAR_STK:
case INST_INCR_STK:
opnd = TclGetUInt1AtPtr(pc+1);
- incrPtr = *tosPtr;
- tosPtr--;
+ incrPtr = POP_OBJECT();
switch (*pc) {
case INST_INCR_SCALAR1:
pcAdjustment = 2;
@@ -2428,13 +2433,13 @@ TclExecuteByteCode(
doIncrStk:
if ((*pc == INST_INCR_ARRAY_STK_IMM)
|| (*pc == INST_INCR_ARRAY_STK)) {
- part2 = TclGetString(*tosPtr);
- objPtr = *(tosPtr - 1);
+ part2 = TclGetString(OBJ_AT_TOS);
+ objPtr = OBJ_UNDER_TOS;
TRACE(("\"%.30s(%.30s)\" (by %ld) => ",
O2S(objPtr), part2, i));
} else {
part2 = NULL;
- objPtr = *tosPtr;
+ objPtr = OBJ_AT_TOS;
TRACE(("\"%.30s\" (by %ld) => ", O2S(objPtr), i));
}
part1 = TclGetString(objPtr);
@@ -2461,7 +2466,7 @@ TclExecuteByteCode(
pcAdjustment = 3;
doIncrArray:
- part2 = TclGetString(*tosPtr);
+ part2 = TclGetString(OBJ_AT_TOS);
arrayPtr = &(compiledLocals[opnd]);
part1 = arrayPtr->name;
cleanup = 1;
@@ -2668,12 +2673,12 @@ TclExecuteByteCode(
int opnd;
Var *varPtr, *otherPtr;
- TRACE_WITH_OBJ(("upvar "), *(tosPtr-1));
+ TRACE_WITH_OBJ(("upvar "), OBJ_UNDER_TOS);
{
CallFrame *framePtr, *savedFramePtr;
- result = TclObjGetFrame(interp, *(tosPtr-1), &framePtr);
+ result = TclObjGetFrame(interp, OBJ_UNDER_TOS, &framePtr);
if (result != -1) {
/*
* Locate the other variable
@@ -2681,7 +2686,7 @@ TclExecuteByteCode(
savedFramePtr = iPtr->varFramePtr;
iPtr->varFramePtr = framePtr;
- otherPtr = TclObjLookupVar(interp, *tosPtr, NULL,
+ otherPtr = TclObjLookupVar(interp, OBJ_AT_TOS, NULL,
(TCL_LEAVE_ERR_MSG), "access",
/*createPart1*/ 1, /*createPart2*/ 1, &varPtr);
iPtr->varFramePtr = savedFramePtr;
@@ -2696,12 +2701,12 @@ TclExecuteByteCode(
case INST_VARIABLE:
case INST_NSUPVAR:
- TRACE_WITH_OBJ(("nsupvar "), *(tosPtr-1));
+ TRACE_WITH_OBJ(("nsupvar "), OBJ_UNDER_TOS);
{
Tcl_Namespace *nsPtr, *savedNsPtr;
- result = TclGetNamespaceFromObj(interp, *(tosPtr-1), &nsPtr);
+ result = TclGetNamespaceFromObj(interp, OBJ_UNDER_TOS, &nsPtr);
if ((result == TCL_OK) && nsPtr) {
/*
* Locate the other variable
@@ -2709,7 +2714,7 @@ TclExecuteByteCode(
savedNsPtr = (Tcl_Namespace *) iPtr->varFramePtr->nsPtr;
iPtr->varFramePtr->nsPtr = (Namespace *) nsPtr;
- otherPtr = TclObjLookupVar(interp, *tosPtr, NULL,
+ otherPtr = TclObjLookupVar(interp, OBJ_AT_TOS, NULL,
(TCL_NAMESPACE_ONLY | TCL_LEAVE_ERR_MSG), "access",
/*createPart1*/ 1, /*createPart2*/ 1, &varPtr);
iPtr->varFramePtr->nsPtr = (Namespace *) savedNsPtr;
@@ -2733,7 +2738,7 @@ TclExecuteByteCode(
*/
Tcl_SetObjResult(interp, Tcl_Format(NULL,
"namespace \"%s\" does not exist", 1,
- (tosPtr-1)));
+ &OBJ_UNDER_TOS));
result = TCL_ERROR;
}
goto checkForCatch;
@@ -2829,7 +2834,7 @@ TclExecuteByteCode(
jmpOffset[1] = TclGetInt1AtPtr(pc+1);
doCondJump:
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
/* TODO - check claim that taking address of b harms performance */
/* TODO - consider optimization search for eePtr->constants */
@@ -2873,8 +2878,8 @@ TclExecuteByteCode(
opnd = TclGetInt4AtPtr(pc+1);
jtPtr = (JumptableInfo *) codePtr->auxDataArrayPtr[opnd].clientData;
- TRACE(("%d => %.20s ", opnd, O2S(*tosPtr)));
- hPtr = Tcl_FindHashEntry(&jtPtr->hashTable, Tcl_GetString(*tosPtr));
+ TRACE(("%d => %.20s ", opnd, O2S(OBJ_AT_TOS)));
+ hPtr = Tcl_FindHashEntry(&jtPtr->hashTable, Tcl_GetString(OBJ_AT_TOS));
if (hPtr != NULL) {
int jumpOffset = PTR2INT(Tcl_GetHashValue(hPtr));
@@ -2900,8 +2905,8 @@ TclExecuteByteCode(
*/
int i1, i2, iResult;
- Tcl_Obj *value2Ptr = *tosPtr;
- Tcl_Obj *valuePtr = *(tosPtr - 1);
+ Tcl_Obj *value2Ptr = OBJ_AT_TOS;
+ Tcl_Obj *valuePtr = OBJ_UNDER_TOS;
result = TclGetBooleanFromObj(NULL, valuePtr, &i1);
if (result != TCL_OK) {
@@ -2943,7 +2948,7 @@ TclExecuteByteCode(
int opnd;
opnd = TclGetUInt4AtPtr(pc+1);
- objResultPtr = Tcl_NewListObj(opnd, (tosPtr - (opnd-1)));
+ objResultPtr = Tcl_NewListObj(opnd, &OBJ_AT_DEPTH(opnd-1));
TRACE_WITH_OBJ(("%u => ", opnd), objResultPtr);
NEXT_INST_V(5, opnd, 1);
}
@@ -2952,7 +2957,7 @@ TclExecuteByteCode(
Tcl_Obj *valuePtr;
int length;
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
result = Tcl_ListObjLength(interp, valuePtr, &length);
if (result == TCL_OK) {
@@ -2975,8 +2980,8 @@ TclExecuteByteCode(
* Pop the two operands
*/
- value2Ptr = *tosPtr;
- valuePtr = *(tosPtr - 1);
+ value2Ptr = OBJ_AT_TOS;
+ valuePtr = OBJ_UNDER_TOS;
/*
* Extract the desired list element
@@ -3010,7 +3015,7 @@ TclExecuteByteCode(
* Pop the list and get the index
*/
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
opnd = TclGetInt4AtPtr(pc+1);
/*
@@ -3062,8 +3067,8 @@ TclExecuteByteCode(
* Do the 'lindex' operation.
*/
- objResultPtr = TclLindexFlat(interp, *(tosPtr - numIdx),
- numIdx, tosPtr - numIdx + 1);
+ objResultPtr = TclLindexFlat(interp, OBJ_AT_DEPTH(numIdx),
+ numIdx, &OBJ_AT_DEPTH(numIdx - 1));
/*
* Check for errors
@@ -3106,14 +3111,14 @@ TclExecuteByteCode(
* Get the new element value.
*/
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
/*
* Compute the new variable value
*/
objResultPtr = TclLsetFlat(interp, value2Ptr, numIdx,
- tosPtr - numIdx, valuePtr);
+ &OBJ_AT_DEPTH(numIdx), valuePtr);
/*
* Check for errors
@@ -3153,8 +3158,8 @@ TclExecuteByteCode(
* Get the new element value, and the index list
*/
- valuePtr = *tosPtr;
- value2Ptr = *(tosPtr - 1);
+ valuePtr = OBJ_AT_TOS;
+ value2Ptr = OBJ_UNDER_TOS;
/*
* Compute the new variable value
@@ -3191,7 +3196,7 @@ TclExecuteByteCode(
* Pop the list and get the indices
*/
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
fromIdx = TclGetInt4AtPtr(pc+1);
toIdx = TclGetInt4AtPtr(pc+5);
@@ -3273,8 +3278,8 @@ TclExecuteByteCode(
char *s1;
const char *s2;
- value2Ptr = *tosPtr;
- valuePtr = *(tosPtr - 1);
+ value2Ptr = OBJ_AT_TOS;
+ valuePtr = OBJ_UNDER_TOS;
/* TODO: Consider more efficient tests than strcmp() */
s1 = Tcl_GetStringFromObj(valuePtr, &s1len);
@@ -3349,8 +3354,8 @@ TclExecuteByteCode(
int iResult;
Tcl_Obj *valuePtr, *value2Ptr;
- value2Ptr = *tosPtr;
- valuePtr = *(tosPtr - 1);
+ value2Ptr = OBJ_AT_TOS;
+ valuePtr = OBJ_UNDER_TOS;
if (valuePtr == value2Ptr) {
/*
@@ -3415,8 +3420,8 @@ TclExecuteByteCode(
Tcl_Obj *valuePtr, *value2Ptr;
stringCompare:
- value2Ptr = *tosPtr;
- valuePtr = *(tosPtr - 1);
+ value2Ptr = OBJ_AT_TOS;
+ valuePtr = OBJ_UNDER_TOS;
/*
* The comparison function should compare up to the minimum byte
@@ -3518,7 +3523,7 @@ TclExecuteByteCode(
int length;
Tcl_Obj *valuePtr;
- valuePtr = *tosPtr;
+ valuePtr = OBJ_AT_TOS;
if (valuePtr->typePtr == &tclByteArrayType) {
(void) Tcl_GetByteArrayFromObj(valuePtr, &length);
@@ -3539,8 +3544,8 @@ TclExecuteByteCode(
Tcl_Obj *valuePtr, *value2Ptr;
bytes = NULL; /* lint */
- value2Ptr = *tosPtr;
- valuePtr = *(tosPtr - 1);
+ value2Ptr = OBJ_AT_TOS;
+ valuePtr = OBJ_UNDER_TOS;
/*
* If we have a ByteArray object, avoid indexing in the Utf string
@@ -3599,8 +3604,8 @@ TclExecuteByteCode(
Tcl_Obj *valuePtr, *value2Ptr;
nocase = TclGetInt1AtPtr(pc+1);
- valuePtr = *tosPtr; /* String */
- value2Ptr = *(tosPtr - 1); /* Pattern */
+ valuePtr = OBJ_AT_TOS; /* String */
+ value2Ptr = OBJ_UNDER_TOS; /* Pattern */
/*
* Check that at least one of the objects is Unicode before promoting
@@ -3638,8 +3643,8 @@ TclExecuteByteCode(
case INST_GT:
case INST_LE:
case INST_GE: {
- Tcl_Obj *valuePtr = *(tosPtr - 1);
- Tcl_Obj *value2Ptr = *tosPtr;
+ Tcl_Obj *valuePtr = OBJ_UNDER_TOS;
+ Tcl_Obj *value2Ptr = OBJ_AT_TOS;
ClientData ptr1, ptr2;
int iResult = 0, compare = 0, type1, type2;
double d1, d2, tmp;
@@ -3952,8 +3957,8 @@ TclExecuteByteCode(
case INST_MOD:
case INST_LSHIFT:
case INST_RSHIFT: {
- Tcl_Obj *value2Ptr = *tosPtr;
- Tcl_Obj *valuePtr = *(tosPtr - 1);
+ Tcl_Obj *value2Ptr = OBJ_AT_TOS;
+ Tcl_Obj *valuePtr = OBJ_UNDER_TOS;
ClientData ptr1, ptr2;
int invalid, shift, type1, type2;
long l1;
@@ -4404,8 +4409,8 @@ TclExecuteByteCode(
case INST_BITAND: {
ClientData ptr1, ptr2;
int type1, type2;
- Tcl_Obj *value2Ptr = *tosPtr;
- Tcl_Obj *valuePtr = *(tosPtr - 1);
+ Tcl_Obj *value2Ptr = OBJ_AT_TOS;
+ Tcl_Obj *valuePtr = OBJ_UNDER_TOS;
result = GetNumberFromObj(NULL, valuePtr, &ptr1, &type1);
if ((result != TCL_OK)
@@ -4676,8 +4681,8 @@ TclExecuteByteCode(
int doWide = 0;
Tcl_Obj *valuePtr, *value2Ptr;
- value2Ptr = *tosPtr;
- valuePtr = *(tosPtr - 1);
+ value2Ptr = OBJ_AT_TOS;
+ valuePtr = OBJ_UNDER_TOS;
if (valuePtr->typePtr == &tclIntType) {
i = valuePtr->internalRep.longValue;
} else if (valuePtr->typePtr == &tclWideIntType) {
@@ -4885,8 +4890,8 @@ TclExecuteByteCode(
case INST_MULT: {
ClientData ptr1, ptr2;
int type1, type2;
- Tcl_Obj *value2Ptr = *tosPtr;
- Tcl_Obj *valuePtr = *(tosPtr - 1);
+ Tcl_Obj *value2Ptr = OBJ_AT_TOS;
+ Tcl_Obj *valuePtr = OBJ_UNDER_TOS;
result = GetNumberFromObj(NULL, valuePtr, &ptr1, &type1);
if ((result != TCL_OK)
@@ -5320,7 +5325,7 @@ TclExecuteByteCode(
case INST_LNOT: {
int b;
- Tcl_Obj *valuePtr = *tosPtr;
+ Tcl_Obj *valuePtr = OBJ_AT_TOS;
/* TODO - check claim that taking address of b harms performance */
/* TODO - consider optimization search for eePtr->constants */
@@ -5340,7 +5345,7 @@ TclExecuteByteCode(
mp_int big;
ClientData ptr;
int type;
- Tcl_Obj *valuePtr = *tosPtr;
+ Tcl_Obj *valuePtr = OBJ_AT_TOS;
result = GetNumberFromObj(NULL, valuePtr, &ptr, &type);
if ((result != TCL_OK)
@@ -5391,7 +5396,7 @@ TclExecuteByteCode(
case INST_UMINUS: {
ClientData ptr;
int type;
- Tcl_Obj *valuePtr = *tosPtr;
+ Tcl_Obj *valuePtr = OBJ_AT_TOS;
result = GetNumberFromObj(NULL, valuePtr, &ptr, &type);
if ((result != TCL_OK)
@@ -5497,7 +5502,7 @@ TclExecuteByteCode(
ClientData ptr;
int type;
- Tcl_Obj *valuePtr = *tosPtr;
+ Tcl_Obj *valuePtr = OBJ_AT_TOS;
if (GetNumberFromObj(NULL, valuePtr, &ptr, &type) != TCL_OK) {
if (*pc == INST_UPLUS) {
@@ -5766,10 +5771,10 @@ TclExecuteByteCode(
* to the operand. Push the current stack depth onto the special catch
* stack.
*/
- eePtr->stackPtr[++catchTop] = (Tcl_Obj *) (tosPtr - eePtr->stackPtr);
+ eePtr->stackPtr[++catchTop] = (Tcl_Obj *) CURR_DEPTH;
TRACE(("%u => catchTop=%d, stackTop=%d\n",
TclGetUInt4AtPtr(pc+1), (catchTop - initCatchTop - 1),
- tosPtr - eePtr->stackPtr));
+ CURR_DEPTH));
NEXT_INST_F(5, 0, 0);
case INST_END_CATCH:
@@ -5816,21 +5821,21 @@ TclExecuteByteCode(
case INST_DICT_GET:
opnd = TclGetUInt4AtPtr(pc+1);
TRACE(("%u => ", opnd));
- dictPtr = *(tosPtr - opnd);
+ dictPtr = OBJ_AT_DEPTH(opnd);
if (opnd > 1) {
dictPtr = TclTraceDictPath(interp, dictPtr, opnd-1,
- tosPtr - (opnd-1), DICT_PATH_READ);
+ &OBJ_AT_DEPTH(opnd-1), DICT_PATH_READ);
if (dictPtr == NULL) {
TRACE_WITH_OBJ((
"%u => ERROR tracing dictionary path into \"%s\": ",
- opnd, O2S(*(tosPtr - opnd))),
+ opnd, O2S(OBJ_AT_DEPTH(opnd))),
Tcl_GetObjResult(interp));
result = TCL_ERROR;
cleanup = opnd + 1;
goto checkForCatch;
}
}
- result = Tcl_DictObjGet(interp, dictPtr, *tosPtr, &objResultPtr);
+ result = Tcl_DictObjGet(interp, dictPtr, OBJ_AT_TOS, &objResultPtr);
if ((result == TCL_OK) && objResultPtr) {
TRACE_APPEND(("%.30s\n", O2S(objResultPtr)));
NEXT_INST_V(5, opnd+1, 1);
@@ -5841,7 +5846,7 @@ TclExecuteByteCode(
opnd, O2S(dictPtr)), Tcl_GetObjResult(interp));
} else {
/*Tcl_ResetResult(interp);*/
- Tcl_AppendResult(interp, "key \"", TclGetString(*tosPtr),
+ Tcl_AppendResult(interp, "key \"", TclGetString(OBJ_AT_TOS),
"\" not known in dictionary", NULL);
TRACE_WITH_OBJ(("%u => ERROR ", opnd), Tcl_GetObjResult(interp));
result = TCL_ERROR;
@@ -5881,24 +5886,24 @@ TclExecuteByteCode(
switch (*pc) {
case INST_DICT_SET:
cleanup = opnd + 1;
- result = Tcl_DictObjPutKeyList(interp, dictPtr, opnd, tosPtr-opnd,
- *tosPtr);
+ result = Tcl_DictObjPutKeyList(interp, dictPtr, opnd,
+ &OBJ_AT_DEPTH(opnd), OBJ_AT_TOS);
break;
case INST_DICT_INCR_IMM:
cleanup = 1;
opnd = TclGetInt4AtPtr(pc+1);
- result = Tcl_DictObjGet(interp, dictPtr, *tosPtr, &valPtr);
+ result = Tcl_DictObjGet(interp, dictPtr, OBJ_AT_TOS, &valPtr);
if (result != TCL_OK) {
break;
}
if (valPtr == NULL) {
- Tcl_DictObjPut(NULL, dictPtr, *tosPtr, Tcl_NewIntObj(opnd));
+ Tcl_DictObjPut(NULL, dictPtr, OBJ_AT_TOS, Tcl_NewIntObj(opnd));
} else {
Tcl_Obj *incrPtr = Tcl_NewIntObj(opnd);
Tcl_IncrRefCount(incrPtr);
if (Tcl_IsShared(valPtr)) {
valPtr = Tcl_DuplicateObj(valPtr);
- Tcl_DictObjPut(NULL, dictPtr, *tosPtr, valPtr);
+ Tcl_DictObjPut(NULL, dictPtr, OBJ_AT_TOS, valPtr);
}
result = TclIncrObj(interp, valPtr, incrPtr);
if (result == TCL_OK) {
@@ -5910,7 +5915,7 @@ TclExecuteByteCode(
case INST_DICT_UNSET:
cleanup = opnd;
result = Tcl_DictObjRemoveKeyList(interp, dictPtr, opnd,
- tosPtr - (opnd-1));
+ &OBJ_AT_DEPTH(opnd-1));
break;
default:
cleanup = 0; /* stop compiler warning */
@@ -5989,7 +5994,7 @@ TclExecuteByteCode(
}
}
- result = Tcl_DictObjGet(interp, dictPtr, *(tosPtr - 1), &valPtr);
+ result = Tcl_DictObjGet(interp, dictPtr, OBJ_UNDER_TOS, &valPtr);
if (result != TCL_OK) {
if (allocateDict) {
Tcl_DecrRefCount(dictPtr);
@@ -6006,12 +6011,12 @@ TclExecuteByteCode(
switch (*pc) {
case INST_DICT_APPEND:
if (valPtr == NULL) {
- valPtr = *tosPtr;
+ valPtr = OBJ_AT_TOS;
} else {
if (Tcl_IsShared(valPtr)) {
valPtr = Tcl_DuplicateObj(valPtr);
}
- Tcl_AppendObjToObj(valPtr, *tosPtr);
+ Tcl_AppendObjToObj(valPtr, OBJ_AT_TOS);
}
break;
case INST_DICT_LAPPEND:
@@ -6020,10 +6025,10 @@ TclExecuteByteCode(
*/
if (valPtr == NULL) {
- valPtr = Tcl_NewListObj(1, tosPtr);
+ valPtr = Tcl_NewListObj(1, &OBJ_AT_TOS);
} else if (Tcl_IsShared(valPtr)) {
valPtr = Tcl_DuplicateObj(valPtr);
- result = Tcl_ListObjAppendElement(interp, valPtr, *tosPtr);
+ result = Tcl_ListObjAppendElement(interp, valPtr, OBJ_AT_TOS);
if (result != TCL_OK) {
Tcl_DecrRefCount(valPtr);
if (allocateDict) {
@@ -6032,7 +6037,7 @@ TclExecuteByteCode(
goto checkForCatch;
}
} else {
- result = Tcl_ListObjAppendElement(interp, valPtr, *tosPtr);
+ result = Tcl_ListObjAppendElement(interp, valPtr, OBJ_AT_TOS);
if (result != TCL_OK) {
if (allocateDict) {
Tcl_DecrRefCount(dictPtr);
@@ -6045,7 +6050,7 @@ TclExecuteByteCode(
Tcl_Panic("Should not happen!");
}
- Tcl_DictObjPut(NULL, dictPtr, *(tosPtr - 1), valPtr);
+ Tcl_DictObjPut(NULL, dictPtr, OBJ_UNDER_TOS, valPtr);
if (TclIsVarDirectWritable(varPtr)) {
if (allocateDict) {
@@ -6137,7 +6142,7 @@ TclExecuteByteCode(
PUSH_OBJECT(keyPtr);
}
TRACE_APPEND(("\"%.30s\" \"%.30s\" %d",
- O2S(*(tosPtr-1)), O2S(*tosPtr), done));
+ O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS), done));
objResultPtr = eePtr->constants[done];
/* TODO: consider opt like INST_FOREACH_STEP4 */
NEXT_INST_F(5, 0, 1);
@@ -6205,7 +6210,7 @@ TclExecuteByteCode(
goto dictUpdateStartFailed;
}
}
- if (Tcl_ListObjGetElements(interp, *tosPtr, &length,
+ if (Tcl_ListObjGetElements(interp, OBJ_AT_TOS, &length,
&keyPtrPtr) != TCL_OK) {
goto dictUpdateStartFailed;
}
@@ -6260,7 +6265,7 @@ TclExecuteByteCode(
NEXT_INST_F(9, 1, 0);
}
if (Tcl_DictObjSize(interp, dictPtr, &length) != TCL_OK
- || Tcl_ListObjGetElements(interp, *tosPtr, &length,
+ || Tcl_ListObjGetElements(interp, OBJ_AT_TOS, &length,
&keyPtrPtr) != TCL_OK) {
cleanup = 1;
result = TCL_ERROR;
@@ -6384,7 +6389,7 @@ TclExecuteByteCode(
* the cleanup.
*/
- TRACE(("\"%.30s\" => ", O2S(*tosPtr)));
+ TRACE(("\"%.30s\" => ", O2S(OBJ_AT_TOS)));
break;
default:
TRACE(("=> "));
@@ -6518,7 +6523,7 @@ TclExecuteByteCode(
*/
processCatch:
- while (tosPtr > ((ptrdiff_t) (eePtr->stackPtr[catchTop])) + eePtr->stackPtr) {
+ while (CURR_DEPTH > ((ptrdiff_t) (eePtr->stackPtr[catchTop]))) {
valuePtr = POP_OBJECT();
TclDecrRefCount(valuePtr);
}
@@ -6545,8 +6550,7 @@ TclExecuteByteCode(
abnormalReturn:
{
- Tcl_Obj **initTosPtr = eePtr->stackPtr + initStackTop;
- while (tosPtr > initTosPtr) {
+ while (CURR_DEPTH > initStackDepth) {
Tcl_Obj *objPtr = POP_OBJECT();
TclDecrRefCount(objPtr);
}
@@ -6560,14 +6564,14 @@ TclExecuteByteCode(
TclDecrRefCount(expandNestList);
expandNestList = objPtr;
}
- if (tosPtr < initTosPtr) {
+ if (CURR_DEPTH < initStackDepth) {
fprintf(stderr, "\nTclExecuteByteCode: abnormal return at pc %u: stack top %d < entry stack top %d\n",
(unsigned int)(pc - codePtr->codeStart),
- (unsigned int) (tosPtr - eePtr->stackPtr),
- (unsigned int) initStackTop);
+ (unsigned int) CURR_DEPTH,
+ (unsigned int) initStackDepth);
Tcl_Panic("TclExecuteByteCode execution failure: end stack top < start stack top");
}
- eePtr->tosPtr = initTosPtr - codePtr->maxExceptDepth;
+ eePtr->tosPtr = eePtr->stackPtr + initStackDepth - codePtr->maxExceptDepth;
}
}
return result;