diff --git a/src/me/topchetoeu/jscript/compilation/CompileTarget.java b/src/me/topchetoeu/jscript/compilation/CompileTarget.java index de44511..06edb94 100644 --- a/src/me/topchetoeu/jscript/compilation/CompileTarget.java +++ b/src/me/topchetoeu/jscript/compilation/CompileTarget.java @@ -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); diff --git a/src/me/topchetoeu/jscript/compilation/CompoundStatement.java b/src/me/topchetoeu/jscript/compilation/CompoundStatement.java index 6045812..38f9dfe 100644 --- a/src/me/topchetoeu/jscript/compilation/CompoundStatement.java +++ b/src/me/topchetoeu/jscript/compilation/CompoundStatement.java @@ -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; diff --git a/src/me/topchetoeu/jscript/compilation/Statement.java b/src/me/topchetoeu/jscript/compilation/Statement.java index 4d684df..3a6de82 100644 --- a/src/me/topchetoeu/jscript/compilation/Statement.java +++ b/src/me/topchetoeu/jscript/compilation/Statement.java @@ -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; } diff --git a/src/me/topchetoeu/jscript/compilation/control/DoWhileStatement.java b/src/me/topchetoeu/jscript/compilation/control/DoWhileStatement.java index ceab5d8..b3e7a68 100644 --- a/src/me/topchetoeu/jscript/compilation/control/DoWhileStatement.java +++ b/src/me/topchetoeu/jscript/compilation/control/DoWhileStatement.java @@ -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); diff --git a/src/me/topchetoeu/jscript/compilation/control/ForInStatement.java b/src/me/topchetoeu/jscript/compilation/control/ForInStatement.java index 64301d1..e6e9825 100644 --- a/src/me/topchetoeu/jscript/compilation/control/ForInStatement.java +++ b/src/me/topchetoeu/jscript/compilation/control/ForInStatement.java @@ -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(); diff --git a/src/me/topchetoeu/jscript/compilation/control/ForStatement.java b/src/me/topchetoeu/jscript/compilation/control/ForStatement.java index 264af2f..1385fb1 100644 --- a/src/me/topchetoeu/jscript/compilation/control/ForStatement.java +++ b/src/me/topchetoeu/jscript/compilation/control/ForStatement.java @@ -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); diff --git a/src/me/topchetoeu/jscript/compilation/control/IfStatement.java b/src/me/topchetoeu/jscript/compilation/control/IfStatement.java index 10e5c94..bba4a58 100644 --- a/src/me/topchetoeu/jscript/compilation/control/IfStatement.java +++ b/src/me/topchetoeu/jscript/compilation/control/IfStatement.java @@ -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) { diff --git a/src/me/topchetoeu/jscript/compilation/control/SwitchStatement.java b/src/me/topchetoeu/jscript/compilation/control/SwitchStatement.java index 2119dc0..dc5d5a9 100644 --- a/src/me/topchetoeu/jscript/compilation/control/SwitchStatement.java +++ b/src/me/topchetoeu/jscript/compilation/control/SwitchStatement.java @@ -37,7 +37,7 @@ public class SwitchStatement extends Statement { var caseToStatement = new HashMap(); var statementToIndex = new HashMap(); - 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(); diff --git a/src/me/topchetoeu/jscript/compilation/control/TryStatement.java b/src/me/topchetoeu/jscript/compilation/control/TryStatement.java index 0cbf1e8..30b6c29 100644 --- a/src/me/topchetoeu/jscript/compilation/control/TryStatement.java +++ b/src/me/topchetoeu/jscript/compilation/control/TryStatement.java @@ -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)); } diff --git a/src/me/topchetoeu/jscript/compilation/control/WhileStatement.java b/src/me/topchetoeu/jscript/compilation/control/WhileStatement.java index 428248c..fb474ce 100644 --- a/src/me/topchetoeu/jscript/compilation/control/WhileStatement.java +++ b/src/me/topchetoeu/jscript/compilation/control/WhileStatement.java @@ -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(); diff --git a/src/me/topchetoeu/jscript/compilation/values/CallStatement.java b/src/me/topchetoeu/jscript/compilation/values/CallStatement.java index feff596..e10e1c2 100644 --- a/src/me/topchetoeu/jscript/compilation/values/CallStatement.java +++ b/src/me/topchetoeu/jscript/compilation/values/CallStatement.java @@ -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) { diff --git a/src/me/topchetoeu/jscript/compilation/values/FunctionStatement.java b/src/me/topchetoeu/jscript/compilation/values/FunctionStatement.java index b6acb0a..b315423 100644 --- a/src/me/topchetoeu/jscript/compilation/values/FunctionStatement.java +++ b/src/me/topchetoeu/jscript/compilation/values/FunctionStatement.java @@ -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) {