refactor: rename compileWithDebug to compile
This commit is contained in:
parent
0b5178e9fd
commit
773bc72f3e
@ -32,10 +32,17 @@ public class CompileTarget {
|
||||
public void setDebug(int i, BreakpointType type) {
|
||||
var instr = target.get(i);
|
||||
instr.breakpoint = type;
|
||||
breakpoints.add(target.get(i).location);
|
||||
|
||||
var old = bpToInstr.put(instr.location, instr);
|
||||
if (old != null) old.breakpoint = BreakpointType.NONE;
|
||||
if (type == BreakpointType.NONE) {
|
||||
breakpoints.remove(target.get(i).location);
|
||||
bpToInstr.remove(instr.location, instr);
|
||||
}
|
||||
else {
|
||||
breakpoints.add(target.get(i).location);
|
||||
|
||||
var old = bpToInstr.put(instr.location, instr);
|
||||
if (old != null) old.breakpoint = BreakpointType.NONE;
|
||||
}
|
||||
}
|
||||
public void setDebug(BreakpointType type) {
|
||||
setDebug(target.size() - 1, type);
|
||||
|
@ -24,7 +24,7 @@ public class CompoundStatement extends Statement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compileWithDebug(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType type) {
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType type) {
|
||||
if (separateFuncs) for (var stm : statements) {
|
||||
if (stm instanceof FunctionStatement && ((FunctionStatement)stm).statement) {
|
||||
stm.compile(target, scope, false);
|
||||
@ -37,18 +37,14 @@ public class CompoundStatement extends Statement {
|
||||
var stm = statements[i];
|
||||
|
||||
if (separateFuncs && stm instanceof FunctionStatement) continue;
|
||||
if (i != statements.length - 1) stm.compileWithDebug(target, scope, false, BreakpointType.STEP_OVER);
|
||||
else stm.compileWithDebug(target, scope, polluted = pollute, BreakpointType.STEP_OVER);
|
||||
if (i != statements.length - 1) stm.compile(target, scope, false, BreakpointType.STEP_OVER);
|
||||
else stm.compile(target, scope, polluted = pollute, BreakpointType.STEP_OVER);
|
||||
}
|
||||
|
||||
if (!polluted && pollute) {
|
||||
target.add(Instruction.loadValue(loc(), null));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||
compileWithDebug(target, scope, pollute, BreakpointType.STEP_IN);
|
||||
}
|
||||
|
||||
public CompoundStatement setEnd(Location loc) {
|
||||
this.end = loc;
|
||||
|
@ -8,10 +8,9 @@ public abstract class Statement {
|
||||
private Location _loc;
|
||||
|
||||
public boolean pure() { return false; }
|
||||
public abstract void compile(CompileTarget target, ScopeRecord scope, boolean pollute);
|
||||
public void declare(ScopeRecord varsScope) { }
|
||||
|
||||
public void compileWithDebug(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType type) {
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType type) {
|
||||
int start = target.size();
|
||||
compile(target, scope, pollute);
|
||||
|
||||
@ -20,6 +19,9 @@ public abstract class Statement {
|
||||
target.setDebug(start, type);
|
||||
}
|
||||
}
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||
compile(target, scope, pollute, BreakpointType.NONE);
|
||||
}
|
||||
|
||||
public Location loc() { return _loc; }
|
||||
public void setLoc(Location loc) { _loc = loc; }
|
||||
|
@ -19,9 +19,9 @@ public class DoWhileStatement extends Statement {
|
||||
@Override
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||
int start = target.size();
|
||||
body.compileWithDebug(target, scope, false, BreakpointType.STEP_OVER);
|
||||
body.compile(target, scope, false, BreakpointType.STEP_OVER);
|
||||
int mid = target.size();
|
||||
condition.compileWithDebug(target, scope, true, BreakpointType.STEP_OVER);
|
||||
condition.compile(target, scope, true, BreakpointType.STEP_OVER);
|
||||
int end = target.size();
|
||||
|
||||
WhileStatement.replaceBreaks(target, label, start, mid - 1, mid, end + 1);
|
||||
|
@ -33,7 +33,7 @@ public class ForInStatement extends Statement {
|
||||
target.add(Instruction.storeVar(loc(), scope.getKey(varName)));
|
||||
}
|
||||
|
||||
object.compileWithDebug(target, scope, true, BreakpointType.STEP_OVER);
|
||||
object.compile(target, scope, true, BreakpointType.STEP_OVER);
|
||||
target.add(Instruction.keys(loc(), true));
|
||||
|
||||
int start = target.size();
|
||||
|
@ -18,15 +18,15 @@ public class ForStatement extends Statement {
|
||||
}
|
||||
@Override
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||
declaration.compileWithDebug(target, scope, false, BreakpointType.STEP_OVER);
|
||||
declaration.compile(target, scope, false, BreakpointType.STEP_OVER);
|
||||
|
||||
int start = target.size();
|
||||
condition.compileWithDebug(target, scope, true, BreakpointType.STEP_OVER);
|
||||
condition.compile(target, scope, true, BreakpointType.STEP_OVER);
|
||||
int mid = target.size();
|
||||
target.add(Instruction.nop(null));
|
||||
body.compileWithDebug(target, scope, false, BreakpointType.STEP_OVER);
|
||||
body.compile(target, scope, false, BreakpointType.STEP_OVER);
|
||||
int beforeAssign = target.size();
|
||||
assignment.compileWithDebug(target, scope, false, BreakpointType.STEP_OVER);
|
||||
assignment.compile(target, scope, false, BreakpointType.STEP_OVER);
|
||||
int end = target.size();
|
||||
|
||||
WhileStatement.replaceBreaks(target, label, mid + 1, end, beforeAssign, end + 1);
|
||||
|
@ -16,33 +16,31 @@ public class IfStatement extends Statement {
|
||||
if (elseBody != null) elseBody.declare(globScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compileWithDebug(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType breakpoint) {
|
||||
condition.compileWithDebug(target, scope, true, breakpoint);
|
||||
@Override public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType breakpoint) {
|
||||
condition.compile(target, scope, true, breakpoint);
|
||||
|
||||
if (elseBody == null) {
|
||||
int i = target.size();
|
||||
target.add(Instruction.nop(null));
|
||||
body.compileWithDebug(target, scope, pollute, breakpoint);
|
||||
body.compile(target, scope, pollute, breakpoint);
|
||||
int endI = target.size();
|
||||
target.set(i, Instruction.jmpIfNot(loc(), endI - i));
|
||||
}
|
||||
else {
|
||||
int start = target.size();
|
||||
target.add(Instruction.nop(null));
|
||||
body.compileWithDebug(target, scope, pollute, breakpoint);
|
||||
body.compile(target, scope, pollute, breakpoint);
|
||||
target.add(Instruction.nop(null));
|
||||
int mid = target.size();
|
||||
elseBody.compileWithDebug(target, scope, pollute, breakpoint);
|
||||
elseBody.compile(target, scope, pollute, breakpoint);
|
||||
int end = target.size();
|
||||
|
||||
target.set(start, Instruction.jmpIfNot(loc(), mid - start));
|
||||
target.set(mid - 1, Instruction.jmp(loc(), end - mid + 1));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||
compileWithDebug(target, scope, pollute, BreakpointType.STEP_IN);
|
||||
@Override public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||
compile(target, scope, pollute, BreakpointType.STEP_IN);
|
||||
}
|
||||
|
||||
public IfStatement(Location loc, Statement condition, Statement body, Statement elseBody) {
|
||||
|
@ -37,7 +37,7 @@ public class SwitchStatement extends Statement {
|
||||
var caseToStatement = new HashMap<Integer, Integer>();
|
||||
var statementToIndex = new HashMap<Integer, Integer>();
|
||||
|
||||
value.compileWithDebug(target, scope, true, BreakpointType.STEP_OVER);
|
||||
value.compile(target, scope, true, BreakpointType.STEP_OVER);
|
||||
|
||||
for (var ccase : cases) {
|
||||
target.add(Instruction.dup(loc()));
|
||||
@ -53,7 +53,7 @@ public class SwitchStatement extends Statement {
|
||||
|
||||
for (var stm : body) {
|
||||
statementToIndex.put(statementToIndex.size(), target.size());
|
||||
stm.compileWithDebug(target, scope, false, BreakpointType.STEP_OVER);
|
||||
stm.compile(target, scope, false, BreakpointType.STEP_OVER);
|
||||
}
|
||||
|
||||
int end = target.size();
|
||||
|
@ -4,6 +4,7 @@ import me.topchetoeu.jscript.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileTarget;
|
||||
import me.topchetoeu.jscript.compilation.Instruction;
|
||||
import me.topchetoeu.jscript.compilation.Statement;
|
||||
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.engine.scope.GlobalScope;
|
||||
import me.topchetoeu.jscript.engine.scope.LocalScopeRecord;
|
||||
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
|
||||
@ -22,7 +23,7 @@ public class TryStatement extends Statement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType bpt) {
|
||||
target.add(Instruction.nop(null));
|
||||
|
||||
int start = target.size(), catchStart = -1, finallyStart = -1;
|
||||
@ -45,7 +46,7 @@ public class TryStatement extends Statement {
|
||||
target.add(Instruction.tryEnd(loc()));
|
||||
}
|
||||
|
||||
|
||||
target.queueDebug(BreakpointType.STEP_OVER);
|
||||
target.set(start - 1, Instruction.tryStart(loc(), catchStart, finallyStart, target.size() - start));
|
||||
if (pollute) target.add(Instruction.loadValue(loc(), null));
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class WhileStatement extends Statement {
|
||||
condition.compile(target, scope, true);
|
||||
int mid = target.size();
|
||||
target.add(Instruction.nop(null));
|
||||
body.compileWithDebug(target, scope, false, BreakpointType.STEP_OVER);
|
||||
body.compile(target, scope, false, BreakpointType.STEP_OVER);
|
||||
|
||||
int end = target.size();
|
||||
|
||||
|
@ -13,7 +13,7 @@ public class CallStatement extends Statement {
|
||||
public final boolean isNew;
|
||||
|
||||
@Override
|
||||
public void compileWithDebug(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType type) {
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType type) {
|
||||
if (isNew) func.compile(target, scope, true);
|
||||
else if (func instanceof IndexStatement) {
|
||||
((IndexStatement)func).compile(target, scope, true, true);
|
||||
@ -33,7 +33,7 @@ public class CallStatement extends Statement {
|
||||
}
|
||||
@Override
|
||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||
compileWithDebug(target, scope, pollute, BreakpointType.STEP_IN);
|
||||
compile(target, scope, pollute, BreakpointType.STEP_IN);
|
||||
}
|
||||
|
||||
public CallStatement(Location loc, boolean isNew, Statement func, Statement ...args) {
|
||||
|
@ -8,6 +8,7 @@ import me.topchetoeu.jscript.compilation.CompoundStatement;
|
||||
import me.topchetoeu.jscript.compilation.FunctionBody;
|
||||
import me.topchetoeu.jscript.compilation.Instruction;
|
||||
import me.topchetoeu.jscript.compilation.Statement;
|
||||
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.compilation.Instruction.Type;
|
||||
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
|
||||
import me.topchetoeu.jscript.exceptions.SyntaxException;
|
||||
@ -106,7 +107,7 @@ public class FunctionStatement extends Statement {
|
||||
}
|
||||
}
|
||||
@Override public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||
compile(target, scope, pollute, null);
|
||||
compile(target, scope, pollute, BreakpointType.NONE);
|
||||
}
|
||||
|
||||
public FunctionStatement(Location loc, Location end, String varName, String[] args, boolean statement, CompoundStatement body) {
|
||||
|
Loading…
Reference in New Issue
Block a user