summaryrefslogtreecommitdiffstats
path: root/generic/tclCompExpr.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2013-09-12 19:21:20 (GMT)
committerdgp <dgp@users.sourceforge.net>2013-09-12 19:21:20 (GMT)
commit27c4d781f4bfb6ea056b4b93a9787bc49fe8d582 (patch)
treeb61566ea132ab29819017cb80c577c4272aa22bc /generic/tclCompExpr.c
parent8fd5bbdc7c92308b942426286b37adef8afb5a6a (diff)
downloadtcl-27c4d781f4bfb6ea056b4b93a9787bc49fe8d582.zip
tcl-27c4d781f4bfb6ea056b4b93a9787bc49fe8d582.tar.gz
tcl-27c4d781f4bfb6ea056b4b93a9787bc49fe8d582.tar.bz2
Swap the two fixups used when compiling the ternary operator.
Push them on the stack only when needed, and pop as soon as possible.
Diffstat (limited to 'generic/tclCompExpr.c')
-rw-r--r--generic/tclCompExpr.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c
index 7684c70..106855a 100644
--- a/generic/tclCompExpr.c
+++ b/generic/tclCompExpr.c
@@ -2256,12 +2256,6 @@ CompileExprTree(
switch (nodePtr->lexeme) {
case QUESTION:
- newJump = TclStackAlloc(interp, sizeof(JumpList));
- newJump->next = jumpPtr;
- jumpPtr = newJump;
- newJump = TclStackAlloc(interp, sizeof(JumpList));
- newJump->next = jumpPtr;
- jumpPtr = newJump;
convert = 1;
break;
case AND:
@@ -2302,12 +2296,17 @@ CompileExprTree(
break;
}
case QUESTION:
+ newJump = TclStackAlloc(interp, sizeof(JumpList));
+ newJump->next = jumpPtr;
+ jumpPtr = newJump;
TclEmitForwardJump(envPtr, TCL_FALSE_JUMP, &jumpPtr->jump);
break;
case COLON:
- CLANG_ASSERT(jumpPtr);
+ newJump = TclStackAlloc(interp, sizeof(JumpList));
+ newJump->next = jumpPtr;
+ jumpPtr = newJump;
TclEmitForwardJump(envPtr, TCL_UNCONDITIONAL_JUMP,
- &jumpPtr->next->jump);
+ &jumpPtr->jump);
TclAdjustStackDepth(-1, envPtr);
if (convert) {
jumpPtr->jump.jumpType = TCL_TRUE_JUMP;
@@ -2322,7 +2321,7 @@ CompileExprTree(
break;
}
} else {
- int pc1, pc2;
+ int pc1, pc2, target;
switch (nodePtr->lexeme) {
case START:
@@ -2364,21 +2363,21 @@ CompileExprTree(
case COLON:
CLANG_ASSERT(jumpPtr);
if (jumpPtr->jump.jumpType == TCL_TRUE_JUMP) {
- jumpPtr->jump.jumpType = TCL_FALSE_JUMP;
+ jumpPtr->jump.jumpType = TCL_UNCONDITIONAL_JUMP;
convert = 1;
}
- if (TclFixupForwardJump(envPtr, &jumpPtr->next->jump,
+ target = jumpPtr->jump.codeOffset + 2;
+ if (TclFixupForwardJump(envPtr, &jumpPtr->jump,
(envPtr->codeNext - envPtr->codeStart)
- - jumpPtr->next->jump.codeOffset, 127)) {
- jumpPtr->next->jump.codeOffset += 3;
+ - jumpPtr->jump.codeOffset, 127)) {
+ target += 3;
}
- TclFixupForwardJump(envPtr, &jumpPtr->jump,
- jumpPtr->next->jump.codeOffset + 2
- - jumpPtr->jump.codeOffset, 127);
-
freePtr = jumpPtr;
jumpPtr = jumpPtr->next;
TclStackFree(interp, freePtr);
+ TclFixupForwardJump(envPtr, &jumpPtr->jump,
+ target - jumpPtr->jump.codeOffset, 127);
+
freePtr = jumpPtr;
jumpPtr = jumpPtr->next;
TclStackFree(interp, freePtr);