summaryrefslogtreecommitdiffstats
path: root/generic/tclCompCmds.c
diff options
context:
space:
mode:
authormig <mig>2013-12-23 11:28:12 (GMT)
committermig <mig>2013-12-23 11:28:12 (GMT)
commit3b06f70775be10c7547c05c27e55d4ef0a65ee0c (patch)
tree24228faa92eef9ebab05dc24c7c6a8bd63aeb9ae /generic/tclCompCmds.c
parent4c7d267ddb333ab1d5b6caddfdd8803def611dd0 (diff)
downloadtcl-3b06f70775be10c7547c05c27e55d4ef0a65ee0c.zip
tcl-3b06f70775be10c7547c05c27e55d4ef0a65ee0c.tar.gz
tcl-3b06f70775be10c7547c05c27e55d4ef0a65ee0c.tar.bz2
Added new tools for managing and verifying the stack depth during compilation. Used it in some spots in the compiler and in TclCompileCatchCommand.
Diffstat (limited to 'generic/tclCompCmds.c')
-rw-r--r--generic/tclCompCmds.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c
index c774a5e..323aa87 100644
--- a/generic/tclCompCmds.c
+++ b/generic/tclCompCmds.c
@@ -532,7 +532,8 @@ TclCompileCatchCmd(
Tcl_Token *cmdTokenPtr, *resultNameTokenPtr, *optsNameTokenPtr;
int resultIndex, optsIndex, range, dropScript = 0;
DefineLineInformation; /* TIP #280 */
-
+ int depth = TclGetStackDepth(envPtr);
+
/*
* If syntax does not match what we expect for [catch], do not compile.
* Let runtime checks determine if syntax has changed.
@@ -611,11 +612,13 @@ TclCompileCatchCmd(
}
ExceptionRangeEnds(envPtr, range);
+
/*
* Emit the "no errors" epilogue: push "0" (TCL_OK) as the catch result,
* and jump around the "error case" code.
*/
+ TclCheckStackDepth(depth+1, envPtr);
PushStringLiteral(envPtr, "0");
TclEmitForwardJump(envPtr, TCL_UNCONDITIONAL_JUMP, &jumpFixup);
@@ -624,12 +627,14 @@ TclCompileCatchCmd(
* return code.
*/
- TclAdjustStackDepth(-2 + dropScript, envPtr);
ExceptionRangeTarget(envPtr, range, catchOffset);
+ TclSetStackDepth(depth + dropScript, envPtr);
+
if (dropScript) {
TclEmitOpcode( INST_POP, envPtr);
}
+
/* Stack at this point is empty */
TclEmitOpcode( INST_PUSH_RESULT, envPtr);
TclEmitOpcode( INST_PUSH_RETURN_CODE, envPtr);
@@ -678,6 +683,7 @@ TclCompileCatchCmd(
}
TclEmitOpcode( INST_POP, envPtr);
+ TclCheckStackDepth(depth+1, envPtr);
return TCL_OK;
}