ES6 Support Groundwork + Fixes (OLD ONE DON'T LOOK AT ME!!!) #22
@ -14,7 +14,7 @@ public class FunctionArrowNode extends FunctionNode {
|
|||||||
@Override public String name() { return null; }
|
@Override public String name() { return null; }
|
||||||
|
|
||||||
@Override public void compile(CompileResult target, boolean pollute, String name, BreakpointType bp) {
|
@Override public void compile(CompileResult target, boolean pollute, String name, BreakpointType bp) {
|
||||||
var id = target.addChild(compileBody(target, false, name, null));
|
var id = target.addChild(compileBody(target, name, null));
|
||||||
target.add(_i -> Instruction.loadFunc(id, true, false, true, null, captures(id, target)));
|
target.add(_i -> Instruction.loadFunc(id, true, false, true, null, captures(id, target)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public abstract class FunctionNode extends Node {
|
|||||||
return ((FunctionScope)target.children.get(id).scope).getCaptureIndices();
|
return ((FunctionScope)target.children.get(id).scope).getCaptureIndices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final CompileResult compileBody(Environment env, FunctionScope scope, boolean lastReturn, boolean hasArgs, String _name, String selfName) {
|
public final CompileResult compileBody(Environment env, FunctionScope scope, boolean lastReturn, String _name, String selfName) {
|
||||||
var name = this.name() != null ? this.name() : _name;
|
var name = this.name() != null ? this.name() : _name;
|
||||||
|
|
||||||
env = env.child()
|
env = env.child()
|
||||||
@ -31,7 +31,7 @@ public abstract class FunctionNode extends Node {
|
|||||||
.remove(LabelContext.CONTINUE_CTX);
|
.remove(LabelContext.CONTINUE_CTX);
|
||||||
|
|
||||||
return new CompileResult(env, scope, params.params.size(), target -> {
|
return new CompileResult(env, scope, params.params.size(), target -> {
|
||||||
if (hasArgs || params.params.size() > 0) target.add(Instruction.loadArgs(true));
|
// if (params.params.size() > 0) target.add(Instruction.loadArgs(true));
|
||||||
|
|
||||||
// if (hasArgs) {
|
// if (hasArgs) {
|
||||||
// var argsVar = scope.defineStrict(new Variable("arguments", true), loc());
|
// var argsVar = scope.defineStrict(new Variable("arguments", true), loc());
|
||||||
@ -39,6 +39,7 @@ public abstract class FunctionNode extends Node {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (params.params.size() > 0) {
|
if (params.params.size() > 0) {
|
||||||
|
target.add(Instruction.loadArgs(true));
|
||||||
if (params.params.size() > 1) target.add(Instruction.dup(params.params.size() - 1));
|
if (params.params.size() > 1) target.add(Instruction.dup(params.params.size() - 1));
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
@ -70,13 +71,13 @@ public abstract class FunctionNode extends Node {
|
|||||||
|
|
||||||
if (params.restName != null) {
|
if (params.restName != null) {
|
||||||
if (scope.has(params.restName, false)) throw new SyntaxException(params.restLocation, "Duplicate parameter name not allowed");
|
if (scope.has(params.restName, false)) throw new SyntaxException(params.restLocation, "Duplicate parameter name not allowed");
|
||||||
var restVar = scope.defineParam(new Variable(params.restName, false), params.restLocation);
|
var restVar = scope.define(new Variable(params.restName, false), params.restLocation);
|
||||||
target.add(Instruction.loadRestArgs(params.params.size()));
|
target.add(Instruction.loadRestArgs(params.params.size()));
|
||||||
target.add(_i -> Instruction.storeVar(restVar.index()));
|
target.add(_i -> Instruction.storeVar(restVar.index()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selfName != null && !scope.has(name, false)) {
|
if (selfName != null && !scope.has(name, false)) {
|
||||||
var i = scope.defineParam(new Variable(selfName, true), end);
|
var i = scope.defineSpecial(new Variable(selfName, true), end);
|
||||||
|
|
||||||
target.add(Instruction.loadCallee());
|
target.add(Instruction.loadCallee());
|
||||||
target.add(_i -> Instruction.storeVar(i.index(), false));
|
target.add(_i -> Instruction.storeVar(i.index(), false));
|
||||||
@ -92,8 +93,8 @@ public abstract class FunctionNode extends Node {
|
|||||||
scope.finish();
|
scope.finish();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public final CompileResult compileBody(CompileResult parent, boolean hasArgs, String name, String selfName) {
|
public final CompileResult compileBody(CompileResult parent, String name, String selfName) {
|
||||||
return compileBody(parent.env, new FunctionScope(parent.scope), false, hasArgs, name, selfName);
|
return compileBody(parent.env, new FunctionScope(parent.scope), false, name, selfName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void compile(CompileResult target, boolean pollute, String name, BreakpointType bp);
|
public abstract void compile(CompileResult target, boolean pollute, String name, BreakpointType bp);
|
||||||
|
@ -16,7 +16,7 @@ public class FunctionStatementNode extends FunctionNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public void compile(CompileResult target, boolean pollute, String name, BreakpointType bp) {
|
@Override public void compile(CompileResult target, boolean pollute, String name, BreakpointType bp) {
|
||||||
var id = target.addChild(compileBody(target, true, name, null));
|
var id = target.addChild(compileBody(target, name, null));
|
||||||
target.add(_i -> Instruction.loadFunc(id, true, true, false, name, captures(id, target)));
|
target.add(_i -> Instruction.loadFunc(id, true, true, false, name, captures(id, target)));
|
||||||
target.add(VariableNode.toSet(target, end, this.name, pollute, true));
|
target.add(VariableNode.toSet(target, end, this.name, pollute, true));
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ public class FunctionValueNode extends FunctionNode {
|
|||||||
@Override public String name() { return name; }
|
@Override public String name() { return name; }
|
||||||
|
|
||||||
@Override public void compile(CompileResult target, boolean pollute, String name, BreakpointType bp) {
|
@Override public void compile(CompileResult target, boolean pollute, String name, BreakpointType bp) {
|
||||||
var id = target.addChild(compileBody(target, true, name, null));
|
var id = target.addChild(compileBody(target, name, null));
|
||||||
target.add(_i -> Instruction.loadFunc(id, true, true, false, name, captures(id, target)));
|
target.add(_i -> Instruction.loadFunc(id, true, true, false, name, captures(id, target)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ public final class JavaScript {
|
|||||||
|
|
||||||
public static CompileResult compile(Environment env, Node ...statements) {
|
public static CompileResult compile(Environment env, Node ...statements) {
|
||||||
var func = new FunctionValueNode(null, null, new Parameters(List.of()), new CompoundNode(null, statements), null);
|
var func = new FunctionValueNode(null, null, new Parameters(List.of()), new CompoundNode(null, statements), null);
|
||||||
var res = func.compileBody(env, new FunctionScope(true), true, true, null, null);
|
var res = func.compileBody(env, new FunctionScope(true), true, null, null);
|
||||||
res.buildTask.run();
|
res.buildTask.run();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user