Temporary work on generators.
diff --git a/src/org/mozilla/classfile/ClassFileWriter.java b/src/org/mozilla/classfile/ClassFileWriter.java index 26905b2..55b5bee 100644 --- a/src/org/mozilla/classfile/ClassFileWriter.java +++ b/src/org/mozilla/classfile/ClassFileWriter.java
@@ -1242,7 +1242,12 @@ if (!(label < 0)) throw new IllegalArgumentException("Bad label, no biscuit"); + if (DEBUGLABELS) { + System.out.println("(" + itsCodeBufferTop + ") LABEL " + Integer.toHexString(label)); + } + label &= 0x7FFFFFFF; + if (label > itsLabelTableTop) throw new IllegalArgumentException("Bad label"); @@ -1333,6 +1338,11 @@ itsStackTop = n; } + @Override + public String toString() { + return super.toString(); + } + public void adjustStackTop(int delta) { int newStack = itsStackTop + delta; if (newStack < 0 || Short.MAX_VALUE < newStack) @@ -1860,6 +1870,11 @@ long lType, lType2; String className; + if (DEBUGCODE) { + System.out.println("(" + bci + " stack " + stackTop + + "): " + bytecodeStr(bc) + ')'); + } + switch (bc) { case ByteCode.NOP: case ByteCode.IINC: @@ -2602,7 +2617,7 @@ private boolean wide; - static final boolean DEBUGSTACKMAP = false; + static final boolean DEBUGSTACKMAP = true; } /** @@ -4517,9 +4532,9 @@ private final static int FileHeaderConstant = 0xCAFEBABE; // Set DEBUG flags to true to get better checking and progress info. - private static final boolean DEBUGSTACK = false; - private static final boolean DEBUGLABELS = false; - private static final boolean DEBUGCODE = false; + private static final boolean DEBUGSTACK = true; + private static final boolean DEBUGLABELS = true; + private static final boolean DEBUGCODE = true; private String generatedClassName;
diff --git a/src/org/mozilla/javascript/Token.java b/src/org/mozilla/javascript/Token.java index 4559262..d2a28fb 100644 --- a/src/org/mozilla/javascript/Token.java +++ b/src/org/mozilla/javascript/Token.java
@@ -25,7 +25,7 @@ } // debug flags - public static final boolean printTrees = false; + public static final boolean printTrees = true; static final boolean printICode = false; static final boolean printNames = printTrees || printICode;
diff --git a/src/org/mozilla/javascript/optimizer/Codegen.java b/src/org/mozilla/javascript/optimizer/Codegen.java index 6cb94d3..29a09b2 100644 --- a/src/org/mozilla/javascript/optimizer/Codegen.java +++ b/src/org/mozilla/javascript/optimizer/Codegen.java
@@ -1983,6 +1983,11 @@ if (!hasVarsInRegs) throw Codegen.badTree(); epilogueLabel = cfw.acquireLabel(); } + /*if (isGenerator) { + // This seems to be necessary because where we jump to expects + // nothing on the stack! + cfw.add(ByteCode.POP); + }*/ cfw.add(ByteCode.GOTO, epilogueLabel); break; @@ -2101,7 +2106,7 @@ if (!isGenerator) { break; } - +/* if (compilerEnv.isGenerateObserverCount()) saveCurrentCodeOffset(); // there is exactly one value on the stack when enterring @@ -2132,6 +2137,8 @@ releaseWordLocal((short)finallyRegister); cfw.markLabel(finallyEnd); + // At this point stack is 1. Should it be? + */ } break; @@ -2183,6 +2190,7 @@ private void generateExpression(Node node, Node parent) { + System.out.println("** " + node + " **"); int type = node.getType(); Node child = node.getFirstChild(); switch (type) { @@ -2907,6 +2915,7 @@ cfw.markLabel(label); if (!hasLocals) { // jump here directly if there are no locals + // jump here directly if there are no locals cfw.markTableSwitchCase(generatorSwitch, nextState); } @@ -3037,12 +3046,12 @@ cfw.markLabel(fallThruLabel); } else { if (type == Token.JSR) { - if (isGenerator) { + /*if (isGenerator) { addGotoWithReturn(target); - } else { + } else {*/ // This assumes that JSR is only ever used for finally inlineFinally(target); - } + //} } else { addGoto(target, ByteCode.GOTO); } @@ -3788,6 +3797,7 @@ exceptionManager.setHandlers(handlerLabels, startLabel); // create a table for the equivalent of JSR returns + /* if (isGenerator && finallyTarget != null) { FinallyReturnPoint ret = new FinallyReturnPoint(); if (finallys == null) { @@ -3798,6 +3808,7 @@ // add the finally node as well to the hash table finallys.put(finallyTarget.getNext(), ret); } + */ while (child != null) { if (child == catchTarget) { @@ -3866,9 +3877,9 @@ int finallyHandler = cfw.acquireLabel(); int finallyEnd = cfw.acquireLabel(); cfw.markHandler(finallyHandler); - if (!isGenerator) { + //if (!isGenerator) { cfw.markLabel(handlerLabels[FINALLY_EXCEPTION]); - } + //} cfw.addAStore(exceptionLocal); // reset the variable object local @@ -3877,12 +3888,12 @@ // get the label to JSR to int finallyLabel = finallyTarget.labelId(); - if (isGenerator) + /*if (isGenerator) addGotoWithReturn(finallyTarget); - else { + else {*/ inlineFinally(finallyTarget, handlerLabels[FINALLY_EXCEPTION], finallyEnd); - } + //} // rethrow cfw.addALoad(exceptionLocal); @@ -3890,19 +3901,20 @@ cfw.add(ByteCode.CHECKCAST, "java/lang/Throwable"); cfw.add(ByteCode.ATHROW); - cfw.markLabel(finallyEnd); // mark the handler if (isGenerator) { cfw.addExceptionHandler(startLabel, finallyLabel, finallyHandler, null); // catch any - } + }// else { + cfw.markLabel(finallyEnd); + //} } releaseWordLocal(savedVariableObject); cfw.markLabel(realEnd); - if (!isGenerator) { + //if (!isGenerator) { exceptionManager.popExceptionInfo(); - } + //} } private static final int JAVASCRIPT_EXCEPTION = 0;