fix: use _STR and _INT variants of member instructions
This commit is contained in:
parent
78d233a6bd
commit
2a5f6aa9aa
@ -6,6 +6,8 @@ import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
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 final Node object;
|
||||
@ -16,21 +18,49 @@ public class IndexAssignNode extends Node {
|
||||
@Override public void compile(CompileResult target, boolean pollute) {
|
||||
if (operation != null) {
|
||||
object.compile(target, true);
|
||||
index.compile(target, true);
|
||||
target.add(Instruction.dup(2));
|
||||
|
||||
target.add(Instruction.loadMember());
|
||||
value.compile(target, true);
|
||||
target.add(Instruction.operation(operation));
|
||||
if (index instanceof NumberNode num && (int)num.value == num.value) {
|
||||
target.add(Instruction.loadMember((int)num.value));
|
||||
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 {
|
||||
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.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.StringNode;
|
||||
|
||||
public class IndexNode extends Node implements AssignableNode {
|
||||
@ -24,8 +25,19 @@ public class IndexNode extends Node implements AssignableNode {
|
||||
object.compile(target, true);
|
||||
if (dupObj) target.add(Instruction.dup());
|
||||
|
||||
index.compile(target, true);
|
||||
target.add(Instruction.loadMember()).setLocationAndDebug(loc(), BreakpointType.STEP_IN);
|
||||
if (index instanceof NumberNode num && (int)num.value == num.value) {
|
||||
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());
|
||||
}
|
||||
@Override public void compile(CompileResult target, boolean pollute) {
|
||||
|
Loading…
Reference in New Issue
Block a user