Skip to content

Commit

Permalink
fix compile
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZZank committed Oct 11, 2024
1 parent a359b6c commit d2c3042
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
7 changes: 7 additions & 0 deletions common/src/main/java/dev/latvian/mods/rhino/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,11 @@ public static RuntimeException codeBug(String msg) throws RuntimeException {
ex.printStackTrace(System.err);
throw ex;
}

/**
* useful for lambda -> iterable
*/
public static <T> Iterable<T> iterable(Iterable<T> itrProvider) {
return itrProvider;
}
}
17 changes: 8 additions & 9 deletions common/src/main/java/dev/latvian/mods/rhino/NodeTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ private void transformCompilationUnit_r(final ScriptNode tree, final Node parent
break; // skip the whole mess.
}
Node unwindBlock = null;
for (val n : loops.reversed()) {
for (val n : Kit.iterable(loops::descendingIterator)) {
val elemtype = n.getType();
if (elemtype == Token.TRY || elemtype == Token.WITH) {
Node unwind;
if (elemtype == Token.TRY) {
val jsrNode = new Jump(Token.JSR);
val jsrTarget = ((Jump) n).getFinally();
jsrNode.target = jsrTarget;
jsrNode.target = ((Jump) n).getFinally();
unwind = jsrNode;
} else {
unwind = new Node(Token.LEAVEWITH);
Expand All @@ -178,12 +177,12 @@ private void transformCompilationUnit_r(final ScriptNode tree, final Node parent
}
if (unwindBlock != null) {
Node returnNode = node;
Node returnExpr = returnNode.getFirstChild();
val returnExpr = returnNode.getFirstChild();
node = replaceCurrent(parent, previous, node, unwindBlock);
if (returnExpr == null || isGenerator) {
unwindBlock.addChildToBack(returnNode);
} else {
Node store = new Node(Token.EXPR_RESULT, returnExpr);
val store = new Node(Token.EXPR_RESULT, returnExpr);
unwindBlock.addChildToFront(store);
returnNode = new Node(Token.RETURN_RESULT);
unwindBlock.addChildToBack(returnNode);
Expand All @@ -198,8 +197,8 @@ private void transformCompilationUnit_r(final ScriptNode tree, final Node parent

case Token.BREAK:
case Token.CONTINUE: {
Jump jump = (Jump) node;
Jump jumpStatement = jump.getJumpStatement();
val jump = (Jump) node;
val jumpStatement = jump.getJumpStatement();
if (jumpStatement == null) {
Kit.codeBug();
}
Expand All @@ -210,12 +209,12 @@ private void transformCompilationUnit_r(final ScriptNode tree, final Node parent
// which should be found
throw Kit.codeBug();
}
for (Node n : loops.reversed()) {
for (val n : Kit.iterable(loops::descendingIterator)) {
if (n == jumpStatement) {
break;
}

int elemtype = n.getType();
val elemtype = n.getType();
if (elemtype == Token.WITH) {
Node leave = new Node(Token.LEAVEWITH);
previous = addBeforeCurrent(parent, previous, node, leave);
Expand Down

0 comments on commit d2c3042

Please sign in to comment.