summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2010-03-18 10:59:45 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2010-03-18 10:59:45 (GMT)
commit29b735fa6d45d36e552be123a3704a9a84b60d97 (patch)
treeac9b035f57b98126263b1cccf914c68972c06e8b /generic
parent5d7a1c17873ac12e80410c4cf4fef6ace21565f6 (diff)
downloadtcl-29b735fa6d45d36e552be123a3704a9a84b60d97.zip
tcl-29b735fa6d45d36e552be123a3704a9a84b60d97.tar.gz
tcl-29b735fa6d45d36e552be123a3704a9a84b60d97.tar.bz2
[Bug 2971921]: Corrected jump so that it doesn't skip into the middle
of an instruction! Tightened the instruction issuing. Moved endCatch calls closer to their point that they guard.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclCompCmdsSZ.c73
1 files changed, 40 insertions, 33 deletions
diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c
index fb34f66..b55367c 100644
--- a/generic/tclCompCmdsSZ.c
+++ b/generic/tclCompCmdsSZ.c
@@ -14,7 +14,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCompCmdsSZ.c,v 1.2 2010/03/05 14:34:03 dkf Exp $
+ * RCS: @(#) $Id: tclCompCmdsSZ.c,v 1.3 2010/03/18 10:59:48 dkf Exp $
*/
#include "tclInt.h"
@@ -145,6 +145,10 @@ const AuxDataType tclJumptableInfoType = {
(var) = CurrentOffset(envPtr);TclEmitInstInt4(INST_##name,0,envPtr)
#define FIXJUMP(var) \
TclStoreInt4AtPtr(CurrentOffset(envPtr)-(var),envPtr->codeStart+(var)+1)
+#define LOAD(idx) \
+ if ((idx)<256) {OP1(LOAD_SCALAR1,(idx));} else {OP4(LOAD_SCALAR4,(idx));}
+#define STORE(idx) \
+ if ((idx)<256) {OP1(STORE_SCALAR1,(idx));} else {OP4(STORE_SCALAR4,(idx));}
/*
*----------------------------------------------------------------------
@@ -2072,16 +2076,17 @@ IssueTryInstructions(
ExceptionRangeStarts(envPtr, range);
BODY( bodyToken, 1);
ExceptionRangeEnds(envPtr, range);
- OP1( JUMP1, 3);
+ PUSH( "0");
+ OP1( JUMP1, 4);
ExceptionRangeTarget(envPtr, range, catchOffset);
+ OP( PUSH_RETURN_CODE);
OP( PUSH_RESULT);
- OP4( STORE_SCALAR4, resultVar);
- OP( POP);
OP( PUSH_RETURN_OPTIONS);
- OP4( STORE_SCALAR4, optionsVar);
- OP( POP);
- OP( PUSH_RETURN_CODE);
OP( END_CATCH);
+ STORE( optionsVar);
+ OP( POP);
+ STORE( resultVar);
+ OP( POP);
/*
* Now we handle all the registered 'on' and 'trap' handlers in order.
@@ -2106,7 +2111,7 @@ IssueTryInstructions(
* Match the errorcode according to try/trap rules.
*/
- OP4( LOAD_SCALAR4, optionsVar);
+ LOAD( optionsVar);
PUSH( "-errorcode");
OP4( DICT_GET, 1);
OP44( LIST_RANGE_IMM, 0, len-1);
@@ -2125,12 +2130,12 @@ IssueTryInstructions(
*/
if (resultVars[i] >= 0) {
- OP4( LOAD_SCALAR4, resultVar);
- OP4( STORE_SCALAR4, resultVars[i]);
+ LOAD( resultVar);
+ STORE( resultVars[i]);
OP( POP);
if (optionVars[i] >= 0) {
- OP4( LOAD_SCALAR4, optionsVar);
- OP4( STORE_SCALAR4, optionVars[i]);
+ LOAD( optionsVar);
+ STORE( optionVars[i]);
OP( POP);
}
}
@@ -2166,8 +2171,8 @@ IssueTryInstructions(
*/
OP( POP);
- OP4( LOAD_SCALAR4, optionsVar);
- OP4( LOAD_SCALAR4, resultVar);
+ LOAD( optionsVar);
+ LOAD( resultVar);
OP( RETURN_STK);
/*
@@ -2218,16 +2223,17 @@ IssueTryFinallyInstructions(
ExceptionRangeStarts(envPtr, range);
BODY( bodyToken, 1);
ExceptionRangeEnds(envPtr, range);
- OP1( JUMP1, 3);
+ PUSH( "0");
+ OP1( JUMP1, 4);
ExceptionRangeTarget(envPtr, range, catchOffset);
+ OP( PUSH_RETURN_CODE);
OP( PUSH_RESULT);
- OP4( STORE_SCALAR4, resultVar);
- OP( POP);
OP( PUSH_RETURN_OPTIONS);
- OP4( STORE_SCALAR4, optionsVar);
- OP( POP);
- OP( PUSH_RETURN_CODE);
OP( END_CATCH);
+ STORE( optionsVar);
+ OP( POP);
+ STORE( resultVar);
+ OP( POP);
envPtr->currStackDepth = savedStackDepth + 1;
/*
@@ -2255,7 +2261,7 @@ IssueTryFinallyInstructions(
* Match the errorcode according to try/trap rules.
*/
- OP4( LOAD_SCALAR4, optionsVar);
+ LOAD( optionsVar);
PUSH( "-errorcode");
OP4( DICT_GET, 1);
OP44( LIST_RANGE_IMM, 0, len-1);
@@ -2279,12 +2285,12 @@ IssueTryFinallyInstructions(
ExceptionRangeStarts(envPtr, range);
}
if (resultVars[i] >= 0) {
- OP4( LOAD_SCALAR4, resultVar);
- OP4( STORE_SCALAR4, resultVars[i]);
+ LOAD( resultVar);
+ STORE( resultVars[i]);
OP( POP);
if (optionVars[i] >= 0) {
- OP4( LOAD_SCALAR4, optionsVar);
- OP4( STORE_SCALAR4, optionVars[i]);
+ LOAD( optionsVar);
+ STORE( optionVars[i]);
OP( POP);
}
}
@@ -2321,8 +2327,9 @@ IssueTryFinallyInstructions(
}
BODY( handlerTokens[i], 5+i*4);
ExceptionRangeEnds(envPtr, range);
- OP( POP);
- OP1( JUMP1, 6);
+ OP( PUSH_RETURN_OPTIONS);
+ OP4( REVERSE, 2);
+ OP1( JUMP1, 4);
forwardsToFix[i] = -1;
/*
@@ -2334,13 +2341,13 @@ IssueTryFinallyInstructions(
finishTrapCatchHandling:
ExceptionRangeTarget(envPtr, range, catchOffset);
+ OP( PUSH_RETURN_OPTIONS);
OP( PUSH_RESULT);
- OP4( STORE_SCALAR4, resultVar);
+ OP( END_CATCH);
+ STORE( resultVar);
OP( POP);
- OP( PUSH_RETURN_OPTIONS);
- OP4( STORE_SCALAR4, optionsVar);
+ STORE( optionsVar);
OP( POP);
- OP( END_CATCH);
}
if (i+1 < numHandlers) {
JUMP(addrsToFix[i], JUMP4);
@@ -2380,8 +2387,8 @@ IssueTryFinallyInstructions(
BODY( finallyToken, 3 + 4*numHandlers);
OP( POP);
- OP4( LOAD_SCALAR4, optionsVar);
- OP4( LOAD_SCALAR4, resultVar);
+ LOAD( optionsVar);
+ LOAD( resultVar);
OP( RETURN_STK);
return TCL_OK;