Mark parse subtree for finally statement with Token.FINALLY instead of using special property to mark USETEMP node.

git-svn-id: svn://10.0.0.236/trunk@146987 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
igor%mir2.org
2003-09-17 13:43:12 +00:00
parent fdc85e5866
commit f560586f15
3 changed files with 50 additions and 28 deletions

View File

@@ -530,15 +530,7 @@ public class IRFactory {
if (hasFinally) {
pn.addChildToBack(finallyTarget);
Node returnTemp = createNewLocal(new Node(Token.EMPTY));
Node popAndMake = new Node(Token.POP, returnTemp);
pn.addChildToBack(popAndMake);
pn.addChildToBack(finallyNode);
Node ret = createUseLocal(returnTemp);
// add the magic prop that makes it output a RET
ret.putProp(Node.TARGET_PROP, Boolean.TRUE);
pn.addChildToBack(ret);
pn.addChildToBack(new Node(Token.FINALLY, finallyNode));
}
pn.addChildToBack(endTarget);
return pn;

View File

@@ -368,7 +368,7 @@ public class Interpreter
case Token.SWITCH : {
iCodeTop = updateLineNumber(node, iCodeTop);
iCodeTop = generateICode(child, iCodeTop);
int theLocalSlot = itsData.itsMaxLocals++;
int theLocalSlot = allocateLocal();
iCodeTop = addToken(Token.NEWTEMP, iCodeTop);
iCodeTop = addByte(theLocalSlot, iCodeTop);
iCodeTop = addToken(Token.POP, iCodeTop);
@@ -466,14 +466,10 @@ public class Interpreter
}
case Token.USELOCAL : {
if (node.getProp(Node.TARGET_PROP) != null) {
iCodeTop = addIcode(Icode_RETSUB, iCodeTop);
} else {
iCodeTop = addToken(Token.USETEMP, iCodeTop);
itsStackDepth++;
if (itsStackDepth > itsData.itsMaxStack)
itsData.itsMaxStack = itsStackDepth;
}
iCodeTop = addToken(Token.USETEMP, iCodeTop);
itsStackDepth++;
if (itsStackDepth > itsData.itsMaxStack)
itsData.itsMaxStack = itsStackDepth;
Node temp = (Node) node.getProp(Node.LOCAL_PROP);
iCodeTop = addLocalRef(temp, iCodeTop);
break;
@@ -506,6 +502,22 @@ public class Interpreter
break;
}
case Token.FINALLY : {
int finallyRegister = allocateLocal();
iCodeTop = addToken(Token.NEWTEMP, iCodeTop);
iCodeTop = addByte(finallyRegister, iCodeTop);
iCodeTop = addToken(Token.POP, iCodeTop);
itsStackDepth--;
while (child != null) {
iCodeTop = generateICode(child, iCodeTop);
child = child.getNext();
}
iCodeTop = addIcode(Icode_RETSUB, iCodeTop);
iCodeTop = addByte(finallyRegister, iCodeTop);
releaseLocal(finallyRegister);
break;
}
case Token.AND : {
iCodeTop = generateICode(child, iCodeTop);
iCodeTop = addIcode(Icode_DUP, iCodeTop);
@@ -986,15 +998,22 @@ public class Interpreter
{
int theLocalSlot = node.getIntProp(Node.LOCAL_PROP, -1);
if (theLocalSlot == -1) {
theLocalSlot = itsData.itsMaxLocals++;
theLocalSlot = allocateLocal();
node.putIntProp(Node.LOCAL_PROP, theLocalSlot);
}
iCodeTop = addByte(theLocalSlot, iCodeTop);
if (theLocalSlot >= itsData.itsMaxLocals)
itsData.itsMaxLocals = theLocalSlot + 1;
return iCodeTop;
}
private int allocateLocal()
{
return itsData.itsMaxLocals++;
}
private void releaseLocal(int local)
{
}
private int getTargetLabel(Node target) {
int targetLabel = target.getIntProp(Node.LABEL_PROP, -1);
if (targetLabel == -1) {

View File

@@ -1575,6 +1575,10 @@ class BodyCodegen
visitGOTO(node, type, child);
break;
case Token.FINALLY:
visitFinally(node, child);
break;
case Token.NOT: {
int trueTarget = cfw.acquireLabel();
int falseTarget = cfw.acquireLabel();
@@ -2046,6 +2050,19 @@ class BodyCodegen
cfw.markLabel(fallThruLabel);
}
private void visitFinally(Node node, Node child)
{
//Save return address in a new local where
int finallyRegister = getNewWordLocal();
cfw.addAStore(finallyRegister);
while (child != null) {
generateCodeFromNode(child, node);
child = child.getNext();
}
cfw.add(ByteCode.RET, finallyRegister);
releaseWordLocal((short)finallyRegister);
}
private void visitEnumInit(Node node, Node child)
{
while (child != null) {
@@ -3766,13 +3783,7 @@ class BodyCodegen
}
Node temp = (Node) node.getProp(Node.LOCAL_PROP);
short local = getLocalFromNode(temp);
// if the temp node has a magic TARGET property,
// treat it as a RET to that temp.
if (node.getProp(Node.TARGET_PROP) != null)
cfw.add(ByteCode.RET, local);
else
cfw.addALoad(local);
cfw.addALoad(local);
}
private void addScriptRuntimeInvoke(String methodName,