summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tcl.h4
-rw-r--r--generic/tclCompCmds.c42
-rw-r--r--generic/tclCompile.h1
-rw-r--r--generic/tclExecute.c27
4 files changed, 55 insertions, 19 deletions
diff --git a/generic/tcl.h b/generic/tcl.h
index aab299e..4bf81cc 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -848,10 +848,6 @@ typedef struct Tcl_Obj {
void *ptr;
unsigned long value;
} ptrAndLongRep;
- struct {
- long int1;
- long int2;
- } twoIntValue;
} internalRep;
} Tcl_Obj;
diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c
index b8b2605..bdab2ff 100644
--- a/generic/tclCompCmds.c
+++ b/generic/tclCompCmds.c
@@ -31,6 +31,9 @@ static void FreeForeachInfo(ClientData clientData);
static void PrintForeachInfo(ClientData clientData,
Tcl_Obj *appendObj, ByteCode *codePtr,
unsigned int pcOffset);
+static void PrintNewForeachInfo(ClientData clientData,
+ Tcl_Obj *appendObj, ByteCode *codePtr,
+ unsigned int pcOffset);
static int CompileEachloopCmd(Tcl_Interp *interp,
Tcl_Parse *parsePtr, Command *cmdPtr,
CompileEnv *envPtr, int collect);
@@ -49,6 +52,13 @@ const AuxDataType tclForeachInfoType = {
PrintForeachInfo /* printProc */
};
+const AuxDataType tclNewForeachInfoType = {
+ "NewForeachInfo", /* name */
+ DupForeachInfo, /* dupProc */
+ FreeForeachInfo, /* freeProc */
+ PrintNewForeachInfo /* printProc */
+};
+
const AuxDataType tclDictUpdateInfoType = {
"DictUpdateInfo", /* name */
DupDictUpdateInfo, /* dupProc */
@@ -2599,7 +2609,7 @@ CompileEachloopCmd(
}
infoPtr->varLists[loopIndex] = varListPtr;
}
- infoIndex = TclCreateAuxData(infoPtr, &tclForeachInfoType, envPtr);
+ infoIndex = TclCreateAuxData(infoPtr, &tclNewForeachInfoType, envPtr);
/*
* Evaluate each value list and leave it on stack.
@@ -2828,6 +2838,36 @@ PrintForeachInfo(
Tcl_AppendToObj(appendObj, "]", -1);
}
}
+
+static void
+PrintNewForeachInfo(
+ ClientData clientData,
+ Tcl_Obj *appendObj,
+ ByteCode *codePtr,
+ unsigned int pcOffset)
+{
+ register ForeachInfo *infoPtr = clientData;
+ register ForeachVarList *varsPtr;
+ int i, j;
+
+ Tcl_AppendPrintfToObj(appendObj, "jumpOffset=%+d, vars=",
+ infoPtr->loopCtTemp);
+ for (i=0 ; i<infoPtr->numLists ; i++) {
+ if (i) {
+ Tcl_AppendToObj(appendObj, ",", -1);
+ }
+ Tcl_AppendToObj(appendObj, "[", -1);
+ varsPtr = infoPtr->varLists[i];
+ for (j=0 ; j<varsPtr->numVars ; j++) {
+ if (j) {
+ Tcl_AppendToObj(appendObj, ",", -1);
+ }
+ Tcl_AppendPrintfToObj(appendObj, "%%v%u",
+ (unsigned) varsPtr->varIndexes[j]);
+ }
+ Tcl_AppendToObj(appendObj, "]", -1);
+ }
+}
/*
*----------------------------------------------------------------------
diff --git a/generic/tclCompile.h b/generic/tclCompile.h
index c4e6222..8b1724b 100644
--- a/generic/tclCompile.h
+++ b/generic/tclCompile.h
@@ -908,6 +908,7 @@ typedef struct ForeachInfo {
} ForeachInfo;
MODULE_SCOPE const AuxDataType tclForeachInfoType;
+MODULE_SCOPE const AuxDataType tclNewForeachInfoType;
#define FOREACHINFO(envPtr, index) \
((ForeachInfo*)((envPtr)->auxDataArrayPtr[TclGetUInt4AtPtr(index)].clientData))
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index a831cd6..b6d8841 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -6197,7 +6197,6 @@ TEBCresume(
* corresponding Tcl_Objs to the stack.
*/
-
opnd = TclGetUInt4AtPtr(pc+1);
infoPtr = codePtr->auxDataArrayPtr[opnd].clientData;
numLists = infoPtr->numLists;
@@ -6229,7 +6228,7 @@ TEBCresume(
}
listTmpDepth--;
}
-
+
/*
* Store the iterNum and iterMax in a single Tcl_Obj; we keep a
* nul-string obj with the pointer stored in the ptrValue so that the
@@ -6238,15 +6237,15 @@ TEBCresume(
*/
TclNewObj(tmpPtr);
- tmpPtr->internalRep.twoIntValue.int1 = 0;
- tmpPtr->internalRep.twoIntValue.int2 = iterMax;
+ tmpPtr->internalRep.twoPtrValue.ptr1 = NULL;
+ tmpPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(iterMax);
PUSH_OBJECT(tmpPtr); /* iterCounts object */
-
+
/*
* Store a pointer to the ForeachInfo struct; same dirty trick
- * as above
+ * as above
*/
-
+
TclNewObj(tmpPtr);
tmpPtr->internalRep.otherValuePtr = infoPtr;
PUSH_OBJECT(tmpPtr); /* infoPtr object */
@@ -6254,10 +6253,10 @@ TEBCresume(
/*
* Jump directly to the INST_FOREACH_STEP instruction; the C code just
* falls through.
- */
+ */
pc += 5 - infoPtr->loopCtTemp;
-
+
case INST_FOREACH_STEP:
/*
* "Step" a foreach loop (i.e., begin its next iteration) by assigning
@@ -6269,21 +6268,21 @@ TEBCresume(
numLists = infoPtr->numLists;
tmpPtr = OBJ_AT_DEPTH(1);
- iterNum = tmpPtr->internalRep.twoIntValue.int1;
- iterMax = tmpPtr->internalRep.twoIntValue.int2;
+ iterNum = PTR2INT(tmpPtr->internalRep.twoPtrValue.ptr1);
+ iterMax = PTR2INT(tmpPtr->internalRep.twoPtrValue.ptr2);
/*
* If some list still has a remaining list element iterate one more
* time. Assign to var the next element from its value list.
*/
-
+
if (iterNum < iterMax) {
/*
* Set the variables and jump back to run the body
*/
- tmpPtr->internalRep.twoIntValue.int1 = iterNum + 1;
-
+ tmpPtr->internalRep.twoPtrValue.ptr1 = INT2PTR(iterNum + 1);
+
listTmpDepth = numLists + 1;
for (i = 0; i < numLists; i++) {