ES6 Support Groundwork + Fixes #26
@ -6,6 +6,8 @@ import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
|||||||
import me.topchetoeu.jscript.common.parsing.Location;
|
import me.topchetoeu.jscript.common.parsing.Location;
|
||||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||||
import me.topchetoeu.jscript.compilation.Node;
|
import me.topchetoeu.jscript.compilation.Node;
|
||||||
|
import me.topchetoeu.jscript.compilation.values.constants.NumberNode;
|
||||||
|
import me.topchetoeu.jscript.compilation.values.constants.StringNode;
|
||||||
|
|
||||||
public class IndexAssignNode extends Node {
|
public class IndexAssignNode extends Node {
|
||||||
public final Node object;
|
public final Node object;
|
||||||
@ -16,21 +18,49 @@ public class IndexAssignNode extends Node {
|
|||||||
@Override public void compile(CompileResult target, boolean pollute) {
|
@Override public void compile(CompileResult target, boolean pollute) {
|
||||||
if (operation != null) {
|
if (operation != null) {
|
||||||
object.compile(target, true);
|
object.compile(target, true);
|
||||||
index.compile(target, true);
|
|
||||||
target.add(Instruction.dup(2));
|
|
||||||
|
|
||||||
target.add(Instruction.loadMember());
|
if (index instanceof NumberNode num && (int)num.value == num.value) {
|
||||||
value.compile(target, true);
|
target.add(Instruction.loadMember((int)num.value));
|
||||||
target.add(Instruction.operation(operation));
|
value.compile(target, true);
|
||||||
|
target.add(Instruction.operation(operation));
|
||||||
|
target.add(Instruction.storeMember((int)num.value, pollute));
|
||||||
|
}
|
||||||
|
else if (index instanceof StringNode str) {
|
||||||
|
target.add(Instruction.loadMember(str.value));
|
||||||
|
value.compile(target, true);
|
||||||
|
target.add(Instruction.operation(operation));
|
||||||
|
target.add(Instruction.storeMember(str.value, pollute));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
index.compile(target, true);
|
||||||
|
target.add(Instruction.dup(2));
|
||||||
|
|
||||||
target.add(Instruction.storeMember(pollute)).setLocationAndDebug(loc(), BreakpointType.STEP_IN);
|
target.add(Instruction.loadMember());
|
||||||
|
value.compile(target, true);
|
||||||
|
target.add(Instruction.operation(operation));
|
||||||
|
|
||||||
|
target.add(Instruction.storeMember(pollute));
|
||||||
|
}
|
||||||
|
target.setLocationAndDebug(loc(), BreakpointType.STEP_IN);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
object.compile(target, true);
|
object.compile(target, true);
|
||||||
index.compile(target, true);
|
|
||||||
value.compile(target, true);
|
|
||||||
|
|
||||||
target.add(Instruction.storeMember(pollute)).setLocationAndDebug(loc(), BreakpointType.STEP_IN);;
|
if (index instanceof NumberNode num && (int)num.value == num.value) {
|
||||||
|
value.compile(target, true);
|
||||||
|
target.add(Instruction.storeMember((int)num.value, pollute));
|
||||||
|
}
|
||||||
|
else if (index instanceof StringNode str) {
|
||||||
|
value.compile(target, true);
|
||||||
|
target.add(Instruction.storeMember(str.value, pollute));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
index.compile(target, true);
|
||||||
|
value.compile(target, true);
|
||||||
|
target.add(Instruction.storeMember(pollute));
|
||||||
|
}
|
||||||
|
|
||||||
|
target.setLocationAndDebug(loc(), BreakpointType.STEP_IN);;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import me.topchetoeu.jscript.compilation.AssignableNode;
|
|||||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||||
import me.topchetoeu.jscript.compilation.Node;
|
import me.topchetoeu.jscript.compilation.Node;
|
||||||
|
import me.topchetoeu.jscript.compilation.values.constants.NumberNode;
|
||||||
import me.topchetoeu.jscript.compilation.values.constants.StringNode;
|
import me.topchetoeu.jscript.compilation.values.constants.StringNode;
|
||||||
|
|
||||||
public class IndexNode extends Node implements AssignableNode {
|
public class IndexNode extends Node implements AssignableNode {
|
||||||
@ -24,8 +25,19 @@ public class IndexNode extends Node implements AssignableNode {
|
|||||||
object.compile(target, true);
|
object.compile(target, true);
|
||||||
if (dupObj) target.add(Instruction.dup());
|
if (dupObj) target.add(Instruction.dup());
|
||||||
|
|
||||||
index.compile(target, true);
|
if (index instanceof NumberNode num && (int)num.value == num.value) {
|
||||||
target.add(Instruction.loadMember()).setLocationAndDebug(loc(), BreakpointType.STEP_IN);
|
target.add(Instruction.loadMember((int)num.value));
|
||||||
|
}
|
||||||
|
else if (index instanceof StringNode str) {
|
||||||
|
target.add(Instruction.loadMember(str.value));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
index.compile(target, true);
|
||||||
|
target.add(Instruction.loadMember());
|
||||||
|
}
|
||||||
|
|
||||||
|
target.setLocationAndDebug(loc(), BreakpointType.STEP_IN);
|
||||||
|
|
||||||
if (!pollute) target.add(Instruction.discard());
|
if (!pollute) target.add(Instruction.discard());
|
||||||
}
|
}
|
||||||
@Override public void compile(CompileResult target, boolean pollute) {
|
@Override public void compile(CompileResult target, boolean pollute) {
|
||||||
|
Loading…
Reference in New Issue
Block a user