diff -r ea9fd59c8b62 -r 6c1fa412c72d rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Mar 12 11:16:15 2015 +0100 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Mar 13 11:41:04 2015 +0100 @@ -466,9 +466,13 @@ didBranches = false; lastStackFrame = 0; } else { - didBranches = true; lastStackFrame = -1; - append("\n var gt = 0;\n"); + if (flow == null) { + didBranches = true; + append("\n var gt = 0;\n"); + } else { + didBranches = false; + } } int openBraces = 0; @@ -486,7 +490,7 @@ } if (lastStackFrame != stackMapIterator.getFrameIndex()) { smapper.flush(this); - if (i != 0) { + if (flow == null && i != 0) { append(" }\n"); } if (openBraces > 64) { @@ -500,8 +504,16 @@ lastStackFrame = stackMapIterator.getFrameIndex(); lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals()); smapper.syncWithFrameStack(stackMapIterator.getFrameStack()); - append(" X_" + i).append(": for (;;) { IF: if (gt <= " + i + ") {\n"); - openBraces++; + if (flow == null) { + append(" X_" + i).append(": for (;;) { IF: if (gt <= " + i + ") {\n"); + openBraces++; + } else { + if (!flow.isFlow(i)) { + if (i != 0) { + throw new IOException("Expecting flow suggestion at " + i); + } + } + } changeInCatch = true; } else { debug(" /* " + i + " */ "); @@ -510,6 +522,20 @@ append("try {"); previousTrap = trap.current(); } + if (flow != null) { + if (flow.isLoop(i)) { + append(" for (;;) {\n"); + } + if (flow.isBreak(i)) { + append("\n break;"); + } + for (int j = 0; j < flow.isEnd(i); j++) { + append("\n }"); + } + if (flow.isElse(i)) { + append(" else {\n"); + } + } final int c = readUByte(byteCodes, i); switch (c) { case opc_aload_0: @@ -1091,8 +1117,10 @@ break; case opc_goto: { smapper.flush(this); - int indx = i + readShortArg(byteCodes, i); - goTo(this, flow, i, indx, topMostLabel); + if (flow == null) { + int indx = i + readShortArg(byteCodes, i); + goTo(this, flow, i, indx, topMostLabel); + } i += 2; break; } @@ -2275,6 +2303,13 @@ } private static void goTo(Appendable out, Flow flow, int current, int to, int canBack) throws IOException { + if (flow != null) { + if (flow.isIf(current)) { + out.append("{"); + return; + } + throw new IllegalStateException("Opn: "); + } if (to < current) { if (canBack < to) { out.append("{ gt = 0; continue X_" + to + "; }");