summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdIL.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2013-12-16 21:01:35 (GMT)
committerdgp <dgp@users.sourceforge.net>2013-12-16 21:01:35 (GMT)
commitf3e8b534b38e07387ab2c0c94653917863c57411 (patch)
treef7edca5af1085c9c5fdd399d2a1f9b8d082cd19f /generic/tclCmdIL.c
parent9c336539e4efc2577c7977a99679a133bf4569c5 (diff)
downloadtcl-f3e8b534b38e07387ab2c0c94653917863c57411.zip
tcl-f3e8b534b38e07387ab2c0c94653917863c57411.tar.gz
tcl-f3e8b534b38e07387ab2c0c94653917863c57411.tar.bz2
Refactoring work on the "chain" operation.
Diffstat (limited to 'generic/tclCmdIL.c')
-rw-r--r--generic/tclCmdIL.c101
1 files changed, 48 insertions, 53 deletions
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index fc2c367..28fb3ce 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -104,7 +104,7 @@ typedef struct SortInfo {
* Forward declarations for procedures defined in this file:
*/
-static CmdFrame * CmdFrameChain(CoroutineData *corPtr);
+static void CmdFrameChain(CoroutineData *corPtr);
static int DictionaryCompare(const char *left, const char *right);
static int IfConditionCallback(ClientData data[],
Tcl_Interp *interp, int result);
@@ -1140,6 +1140,47 @@ TclInfoExistsCmd(
*----------------------------------------------------------------------
*/
+static void
+Chain(
+ CmdFrame **cmdFramePtrPtr,
+ CoroutineData *corPtr)
+{
+ CmdFrame *tailPtr = corPtr->caller.cmdFramePtr;
+ CmdFrame *runPtr = *cmdFramePtrPtr;
+ int offset;
+
+ if (tailPtr == NULL) {
+ return;
+ }
+
+ if (runPtr == NULL) {
+ *cmdFramePtrPtr = tailPtr;
+ return;
+ }
+
+ offset = tailPtr->level;
+
+ while (runPtr->nextPtr) {
+ runPtr->level += offset;
+ runPtr = runPtr->nextPtr;
+ }
+ runPtr->level += offset;
+ runPtr->nextPtr = tailPtr;
+}
+
+static void
+CmdFrameChain(
+ CoroutineData *corPtr)
+{
+ CmdFrame **cmdFramePtrPtr = &corPtr->caller.cmdFramePtr;
+
+ corPtr = corPtr->callerEEPtr->corPtr;
+ if (corPtr) {
+ CmdFrameChain(corPtr);
+ Chain(cmdFramePtrPtr, corPtr);
+ }
+}
+
static int
InfoFrameCmd(
ClientData dummy, /* Not used. */
@@ -1149,7 +1190,7 @@ InfoFrameCmd(
{
Interp *iPtr = (Interp *) interp;
int level, topLevel, code = TCL_OK;
- CmdFrame *runPtr, *framePtr, **cmdFramePtrPtr = &iPtr->cmdFramePtr;
+ CmdFrame *framePtr, **cmdFramePtrPtr = &iPtr->cmdFramePtr;
CoroutineData *corPtr = iPtr->execEnvPtr->corPtr;
if (objc > 2) {
@@ -1157,36 +1198,13 @@ InfoFrameCmd(
return TCL_ERROR;
}
- topLevel = ((iPtr->cmdFramePtr == NULL)
- ? 0
- : iPtr->cmdFramePtr->level);
-
if (corPtr) {
- /*
- * A coroutine: must fix the level computations AND the cmdFrame chain,
- * which is interrupted at the base.
- */
-
- CmdFrame *lastPtr = NULL;
- CmdFrame *tailPtr = CmdFrameChain(corPtr);
- int offset = tailPtr ? tailPtr->level : 0;
-
- runPtr = iPtr->cmdFramePtr;
-
- /* TODO - deal with overflow */
- topLevel += offset;
- while (runPtr) {
- runPtr->level += offset;
- lastPtr = runPtr;
- runPtr = runPtr->nextPtr;
- }
- if (lastPtr) {
- lastPtr->nextPtr = tailPtr;
- } else {
- iPtr->cmdFramePtr = tailPtr;
- }
+ CmdFrameChain(corPtr);
+ Chain(cmdFramePtrPtr, corPtr);
}
+ topLevel = iPtr->cmdFramePtr ? iPtr->cmdFramePtr->level : 0;
+
if (objc == 1) {
/*
* Just "info frame".
@@ -1234,6 +1252,7 @@ InfoFrameCmd(
Tcl_SetObjResult(interp, TclInfoFrame(interp, framePtr));
done:
+ cmdFramePtrPtr = &iPtr->cmdFramePtr;
while (corPtr) {
CmdFrame *endPtr = corPtr->caller.cmdFramePtr;
@@ -1254,30 +1273,6 @@ InfoFrameCmd(
}
return code;
}
-
-static CmdFrame *
-CmdFrameChain(
- CoroutineData *corPtr)
-{
- if (corPtr->callerEEPtr->corPtr) {
- CmdFrame *tailPtr = CmdFrameChain(corPtr->callerEEPtr->corPtr);
- CmdFrame *lastPtr = NULL;
- CmdFrame *runPtr = corPtr->caller.cmdFramePtr;
- int offset = tailPtr ? tailPtr->level : 0;
-
- while (runPtr) {
- runPtr->level += offset;
- lastPtr = runPtr;
- runPtr = runPtr->nextPtr;
- }
- if (lastPtr) {
- lastPtr->nextPtr = tailPtr;
- } else {
- corPtr->caller.cmdFramePtr = tailPtr;
- }
- }
- return corPtr->caller.cmdFramePtr;
-}
/*
*----------------------------------------------------------------------