refactor: merge TYPEOF instruction into OPERATION

This commit is contained in:
2025-01-22 20:32:55 +02:00
parent 6355a48c6b
commit f712fb09ae
4 changed files with 34 additions and 49 deletions

View File

@@ -2,6 +2,7 @@ package me.topchetoeu.j2s.compilation.values.operations;
import me.topchetoeu.j2s.common.Instruction;
import me.topchetoeu.j2s.common.Location;
import me.topchetoeu.j2s.common.Operation;
import me.topchetoeu.j2s.compilation.CompileResult;
import me.topchetoeu.j2s.compilation.JavaScript;
import me.topchetoeu.j2s.compilation.Node;
@@ -20,14 +21,14 @@ public class TypeofNode extends Node {
@Override public void compile(CompileResult target, boolean pollute) {
if (value instanceof VariableNode varNode) {
target.add(VariableNode.toGet(target, varNode.loc(), varNode.name, true, true));
if (pollute) target.add(Instruction.typeof());
if (pollute) target.add(Instruction.operation(Operation.TYPEOF));
else target.add(Instruction.discard());
return;
}
value.compile(target, pollute);
if (pollute) target.add(Instruction.typeof());
if (pollute) target.add(Instruction.operation(Operation.TYPEOF));
}
public TypeofNode(Location loc, Node value) {