fix: control flow nodes were making scopes instead of compound nodes
This commit is contained in:
parent
87e077d70d
commit
7ab78b9cea
@ -22,9 +22,12 @@ public class CompoundNode extends Node {
|
||||
@Override public void compile(CompileResult target, boolean pollute, BreakpointType type) {
|
||||
List<Node> statements = new ArrayList<Node>();
|
||||
|
||||
var subtarget = target.subtarget();
|
||||
subtarget.add(() -> Instruction.stackAlloc(subtarget.scope.allocCount()));
|
||||
|
||||
for (var stm : this.statements) {
|
||||
if (stm instanceof FunctionStatementNode) {
|
||||
stm.compile(target, false);
|
||||
if (stm instanceof FunctionStatementNode func) {
|
||||
func.compile(subtarget, false);
|
||||
}
|
||||
else statements.add(stm);
|
||||
}
|
||||
@ -34,10 +37,13 @@ public class CompoundNode extends Node {
|
||||
for (var i = 0; i < statements.size(); i++) {
|
||||
var stm = statements.get(i);
|
||||
|
||||
if (i != statements.size() - 1) stm.compile(target, false, BreakpointType.STEP_OVER);
|
||||
else stm.compile(target, polluted = pollute, BreakpointType.STEP_OVER);
|
||||
if (i != statements.size() - 1) stm.compile(subtarget, false, BreakpointType.STEP_OVER);
|
||||
else stm.compile(subtarget, polluted = pollute, BreakpointType.STEP_OVER);
|
||||
}
|
||||
|
||||
subtarget.scope.end();
|
||||
subtarget.add(Instruction.stackFree(subtarget.scope.allocCount()));
|
||||
|
||||
if (!polluted && pollute) {
|
||||
target.add(Instruction.pushUndefined());
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ public abstract class FunctionNode extends Node {
|
||||
subtarget.length = args.length;
|
||||
subtarget.scope.end();
|
||||
funcScope.end();
|
||||
subtarget.add(Instruction.ret()).setLocation(end);
|
||||
|
||||
if (pollute) compileLoadFunc(target, funcScope.getCaptureIndices(), name);
|
||||
|
||||
|
@ -288,8 +288,6 @@ public class JavaScript {
|
||||
target.add(Instruction.throwSyntax(e)).setLocation(stm.loc());
|
||||
}
|
||||
|
||||
target.add(Instruction.ret()).setLocation(stm.loc());
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
@ -44,13 +44,7 @@ public class ForInNode extends Node {
|
||||
var end = new DeferredIntSupplier();
|
||||
|
||||
LabelContext.pushLoop(target.env, loc(), label, end, start);
|
||||
var subtarget = target.subtarget();
|
||||
subtarget.add(() -> Instruction.stackAlloc(subtarget.scope.allocCount()));
|
||||
|
||||
body.compile(target, false, BreakpointType.STEP_OVER);
|
||||
|
||||
subtarget.scope.end();
|
||||
subtarget.add(Instruction.stackFree(subtarget.scope.allocCount()));
|
||||
LabelContext.popLoop(target.env, label);
|
||||
|
||||
int endI = target.size();
|
||||
|
@ -30,16 +30,9 @@ public class ForNode extends Node {
|
||||
int mid = target.temp();
|
||||
|
||||
var end = new DeferredIntSupplier();
|
||||
|
||||
LabelContext.pushLoop(target.env, loc(), label, end, start);
|
||||
|
||||
var subtarget = target.subtarget();
|
||||
subtarget.add(() -> Instruction.stackAlloc(subtarget.scope.allocCount()));
|
||||
|
||||
body.compile(subtarget, false, BreakpointType.STEP_OVER);
|
||||
|
||||
subtarget.scope.end();
|
||||
subtarget.add(Instruction.stackFree(subtarget.scope.allocCount()));
|
||||
|
||||
body.compile(target, false, BreakpointType.STEP_OVER);
|
||||
LabelContext.popLoop(target.env, label);
|
||||
|
||||
// int beforeAssign = target.size();
|
||||
|
@ -51,13 +51,7 @@ public class ForOfNode extends Node {
|
||||
var end = new DeferredIntSupplier();
|
||||
|
||||
LabelContext.pushLoop(target.env, loc(), label, end, start);
|
||||
var subtarget = target.subtarget();
|
||||
subtarget.add(() -> Instruction.stackAlloc(subtarget.scope.allocCount()));
|
||||
|
||||
body.compile(target, false, BreakpointType.STEP_OVER);
|
||||
|
||||
subtarget.scope.end();
|
||||
subtarget.add(Instruction.stackFree(subtarget.scope.allocCount()));
|
||||
LabelContext.popLoop(target.env, label);
|
||||
|
||||
int endI = target.size();
|
||||
|
@ -29,15 +29,7 @@ public class IfNode extends Node {
|
||||
var end = new DeferredIntSupplier();
|
||||
|
||||
LabelContext.getBreak(target.env).push(loc(), label, end);
|
||||
|
||||
var subtarget = target.subtarget();
|
||||
subtarget.add(() -> Instruction.stackAlloc(subtarget.scope.allocCount()));
|
||||
|
||||
body.compile(subtarget, false, BreakpointType.STEP_OVER);
|
||||
|
||||
subtarget.scope.end();
|
||||
subtarget.add(Instruction.stackFree(subtarget.scope.allocCount()));
|
||||
|
||||
body.compile(target, false, BreakpointType.STEP_OVER);
|
||||
LabelContext.getBreak(target.env).pop(label);
|
||||
|
||||
int endI = target.size();
|
||||
@ -50,25 +42,11 @@ public class IfNode extends Node {
|
||||
var end = new DeferredIntSupplier();
|
||||
|
||||
LabelContext.getBreak(target.env).push(loc(), label, end);
|
||||
|
||||
var bodyTarget = target.subtarget();
|
||||
bodyTarget.add(() -> Instruction.stackAlloc(bodyTarget.scope.allocCount()));
|
||||
|
||||
body.compile(bodyTarget, false, BreakpointType.STEP_OVER);
|
||||
|
||||
bodyTarget.scope.end();
|
||||
bodyTarget.add(Instruction.stackFree(bodyTarget.scope.allocCount()));
|
||||
body.compile(target, false, BreakpointType.STEP_OVER);
|
||||
|
||||
int mid = target.temp();
|
||||
|
||||
var elseTarget = target.subtarget();
|
||||
elseTarget.add(() -> Instruction.stackAlloc(elseTarget.scope.allocCount()));
|
||||
|
||||
body.compile(elseTarget, false, BreakpointType.STEP_OVER);
|
||||
|
||||
elseTarget.scope.end();
|
||||
elseTarget.add(Instruction.stackFree(elseTarget.scope.allocCount()));
|
||||
|
||||
body.compile(target, false, BreakpointType.STEP_OVER);
|
||||
LabelContext.getBreak(target.env).pop(label);
|
||||
|
||||
int endI = target.size();
|
||||
|
@ -14,9 +14,9 @@ import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
|
||||
public class TryNode extends Node {
|
||||
public final Node tryBody;
|
||||
public final Node catchBody;
|
||||
public final Node finallyBody;
|
||||
public final CompoundNode tryBody;
|
||||
public final CompoundNode catchBody;
|
||||
public final CompoundNode finallyBody;
|
||||
public final String captureName;
|
||||
public final String label;
|
||||
|
||||
@ -34,43 +34,26 @@ public class TryNode extends Node {
|
||||
|
||||
LabelContext.getBreak(target.env).push(loc(), label, endSuppl);
|
||||
|
||||
{
|
||||
var subtarget = target.subtarget();
|
||||
subtarget.add(() -> Instruction.stackAlloc(subtarget.scope.allocCount()));
|
||||
|
||||
tryBody.compile(subtarget, false);
|
||||
subtarget.add(Instruction.tryEnd());
|
||||
|
||||
subtarget.scope.end();
|
||||
subtarget.add(Instruction.stackFree(subtarget.scope.allocCount()));
|
||||
}
|
||||
tryBody.compile(target, false);
|
||||
target.add(Instruction.tryEnd());
|
||||
|
||||
if (catchBody != null) {
|
||||
catchStart = target.size() - start;
|
||||
|
||||
var subtarget = target.subtarget();
|
||||
var decN = captureName != null ? 1 : 0;
|
||||
if (captureName != null) {
|
||||
var subtarget = target.subtarget();
|
||||
subtarget.scope.defineStrict(captureName, false, catchBody.loc());
|
||||
catchBody.compile(subtarget, false);
|
||||
subtarget.scope.end();
|
||||
}
|
||||
else catchBody.compile(target, false);
|
||||
|
||||
if (captureName != null) subtarget.scope.defineStrict(captureName, false, catchBody.loc());
|
||||
|
||||
var _subtarget = subtarget;
|
||||
|
||||
subtarget.add(() -> Instruction.stackAlloc(_subtarget.scope.allocCount() - decN));
|
||||
|
||||
catchBody.compile(subtarget, false);
|
||||
|
||||
subtarget.add(Instruction.tryEnd());
|
||||
|
||||
subtarget.scope.end();
|
||||
subtarget.add(Instruction.stackFree(subtarget.scope.allocCount() - decN));
|
||||
target.add(Instruction.tryEnd());
|
||||
}
|
||||
|
||||
if (finallyBody != null) {
|
||||
finallyStart = target.size() - start;
|
||||
|
||||
var subtarget = target.subtarget();
|
||||
finallyBody.compile(subtarget, false);
|
||||
subtarget.add(Instruction.tryEnd());
|
||||
finallyBody.compile(target, false);
|
||||
}
|
||||
|
||||
LabelContext.getBreak(target.env).pop(label);
|
||||
@ -83,7 +66,7 @@ public class TryNode extends Node {
|
||||
if (pollute) target.add(Instruction.pushUndefined());
|
||||
}
|
||||
|
||||
public TryNode(Location loc, String label, Node tryBody, Node catchBody, Node finallyBody, String captureName) {
|
||||
public TryNode(Location loc, String label, CompoundNode tryBody, CompoundNode catchBody, CompoundNode finallyBody, String captureName) {
|
||||
super(loc);
|
||||
this.tryBody = tryBody;
|
||||
this.catchBody = catchBody;
|
||||
@ -109,7 +92,7 @@ public class TryNode extends Node {
|
||||
n += Parsing.skipEmpty(src, i + n);
|
||||
|
||||
String capture = null;
|
||||
Node catchBody = null, finallyBody = null;
|
||||
CompoundNode catchBody = null, finallyBody = null;
|
||||
|
||||
if (Parsing.isIdentifier(src, i + n, "catch")) {
|
||||
n += 5;
|
||||
|
@ -28,13 +28,7 @@ public class WhileNode extends Node {
|
||||
|
||||
|
||||
LabelContext.pushLoop(target.env, loc(), label, end, start);
|
||||
var subtarget = target.subtarget();
|
||||
subtarget.add(() -> Instruction.stackAlloc(subtarget.scope.allocCount()));
|
||||
|
||||
body.compile(target, false, BreakpointType.STEP_OVER);
|
||||
|
||||
subtarget.scope.end();
|
||||
subtarget.add(Instruction.stackFree(subtarget.scope.allocCount()));
|
||||
LabelContext.popLoop(target.env, label);
|
||||
|
||||
var endI = target.size();
|
||||
|
Loading…
Reference in New Issue
Block a user