diff --git a/src/main/java/me/topchetoeu/jscript/common/environment/Environment.java b/src/main/java/me/topchetoeu/jscript/common/environment/Environment.java index 6195fa2..7efce20 100644 --- a/src/main/java/me/topchetoeu/jscript/common/environment/Environment.java +++ b/src/main/java/me/topchetoeu/jscript/common/environment/Environment.java @@ -123,18 +123,6 @@ public class Environment { public Environment addAll(Map, ?> map) { return addAll(map, true); } - // public Environment addAll(Environment env) { - // this.map.putAll(env.map); - // this.hidden.removeAll(env.map.keySet()); - - // for (var el : env.multi.entrySet()) { - // for (var val : el.getValue()) { - // add(el.getKey(), val); - // } - // } - - // return this; - // } @SuppressWarnings("unchecked") public Environment remove(Key key) { diff --git a/src/main/java/me/topchetoeu/jscript/common/parsing/ParseRes.java b/src/main/java/me/topchetoeu/jscript/common/parsing/ParseRes.java index 7c1f553..17873e4 100644 --- a/src/main/java/me/topchetoeu/jscript/common/parsing/ParseRes.java +++ b/src/main/java/me/topchetoeu/jscript/common/parsing/ParseRes.java @@ -59,7 +59,6 @@ public class ParseRes { @SafeVarargs @SuppressWarnings("all") - // to hell with all of java's bullshit generics that do jack shit nothing public static ParseRes first(Source src, int i, Parser ...parsers) { int n = Parsing.skipEmpty(src, i); ParseRes error = ParseRes.failed(); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/CompileResult.java b/src/main/java/me/topchetoeu/jscript/compilation/CompileResult.java index b68adc4..4234653 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/CompileResult.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/CompileResult.java @@ -27,7 +27,6 @@ public final class CompileResult { } public final List> instructions; - // public final List> childrenTasks; public final List children; public final FunctionMapBuilder map; public final Environment env; @@ -58,9 +57,6 @@ public final class CompileResult { instructions.set(i, instr); return this; } - // public Instruction get(int i) { - // return instructions.get(i); - // } public int size() { return instructions.size(); } public void setDebug(Location loc, BreakpointType type) { @@ -87,11 +83,6 @@ public final class CompileResult { return this.children.size() - 1; } - // public int addChild(Supplier supplier) { - // this.childrenTasks.add(() -> supplier.get()); - // return childrenTasks.size() - 1; - // } - public Instruction[] instructions() { var res = new Instruction[instructions.size()]; var i = 0; diff --git a/src/main/java/me/topchetoeu/jscript/compilation/FunctionNode.java b/src/main/java/me/topchetoeu/jscript/compilation/FunctionNode.java index 06f6a3f..6433c32 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/FunctionNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/FunctionNode.java @@ -19,27 +19,6 @@ public abstract class FunctionNode extends Node { public abstract String name(); - // @Override public void declare(CompileResult target) { - // if (varName != null && statement) target.scope.define(varName); - // } - - // public static void checkBreakAndCont(CompileResult target, int start) { - // for (int i = start; i < target.size(); i++) { - // if (target.get(i).type == Type.NOP) { - // if (target.get(i).is(0, "break") ) { - // throw new SyntaxException(target.map.toLocation(i), "Break was placed outside a loop."); - // } - // if (target.get(i).is(0, "cont")) { - // throw new SyntaxException(target.map.toLocation(i), "Continue was placed outside a loop."); - // } - // } - // } - // } - - // protected void compileLoadFunc(CompileResult target, int id, int[] captures, String name) { - // target.add(Instruction.loadFunc(id, true, true, false, name, captures)); - // } - protected final int[] captures(int id, CompileResult target) { return ((FunctionScope)target.children.get(id).scope).getCaptureIndices(); } @@ -112,9 +91,6 @@ public abstract class FunctionNode extends Node { scope.finish(); }); - - // if (pollute) compileLoadFunc(target, target.children.size(), subscope.getCaptureIndices(), name); - // return target.addChild(subtarget); } public final CompileResult compileBody(CompileResult parent, boolean hasArgs, String name, String selfName) { return compileBody(parent.env, new FunctionScope(parent.scope), false, hasArgs, name, selfName); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/FunctionValueNode.java b/src/main/java/me/topchetoeu/jscript/compilation/FunctionValueNode.java index 85f97a0..f0bfd5f 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/FunctionValueNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/FunctionValueNode.java @@ -9,10 +9,6 @@ public class FunctionValueNode extends FunctionNode { @Override public String name() { return name; } - // @Override public void compile(CompileResult target, boolean pollute, String name, BreakpointType bp) { - // compileBody(target, pollute, true, name, null, bp); - // } - @Override public void compile(CompileResult target, boolean pollute, String name, BreakpointType bp) { var id = target.addChild(compileBody(target, false, name, null)); target.add(_i -> Instruction.loadFunc(id, true, true, false, name, captures(id, target))); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/JavaScript.java b/src/main/java/me/topchetoeu/jscript/compilation/JavaScript.java index bd9b880..676fdb2 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/JavaScript.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/JavaScript.java @@ -113,11 +113,9 @@ public final class JavaScript { if (id.result.equals("true")) return ParseRes.res(new BoolNode(loc, true), n); if (id.result.equals("false")) return ParseRes.res(new BoolNode(loc, false), n); - // if (id.result.equals("undefined")) return ParseRes.res(new DiscardNode(loc, null), n); if (id.result.equals("null")) return ParseRes.res(new NullNode(loc), n); if (id.result.equals("this")) return ParseRes.res(new ThisNode(loc), n); // if (id.result.equals("arguments")) return ParseRes.res(new ArgumentsNode(loc), n); - // if (id.result.equals("globalThis")) return ParseRes.res(new GlobalThisNode(loc), n); return ParseRes.failed(); } @@ -328,28 +326,6 @@ public final class JavaScript { var res = func.compileBody(env, new FunctionScope(true), true, true, null, null); res.buildTask.run(); return res; - - // var target = new CompileResult(env, new FunctionScope(true)); - // var stm = ; - // var argsI = target.scope.defineStrict(new Variable("arguments", true), null); - // target.add(Instruction.loadArgs()); - // target.add(_i -> Instruction.storeVar(argsI.index())); - - // // try { - // stm.resolve(target); - // stm.compile(target, true, false, BreakpointType.NONE); - // // FunctionNode.checkBreakAndCont(target, 0); - // // } - // // catch (SyntaxException e) { - // // target = new CompileResult(env, new LocalScope(new GlobalScope())); - - // // target.add(Instruction.throwSyntax(e)).setLocation(stm.loc()); - // // } - - // target.scope.end(); - // target.scope.finish(); - - // return target; } public static CompileResult compile(Environment env, Filename filename, String raw) { diff --git a/src/main/java/me/topchetoeu/jscript/compilation/VariableDeclareNode.java b/src/main/java/me/topchetoeu/jscript/compilation/VariableDeclareNode.java index c35dffd..5fc137f 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/VariableDeclareNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/VariableDeclareNode.java @@ -36,7 +36,6 @@ public class VariableDeclareNode extends Node { } } } - // let a = 10, b = "test"; var c = () => a + b @Override public void compile(CompileResult target, boolean pollute) { for (var entry : values) { if (entry.name == null) continue; diff --git a/src/main/java/me/topchetoeu/jscript/compilation/control/BreakNode.java b/src/main/java/me/topchetoeu/jscript/compilation/control/BreakNode.java index b74e2a4..b09b8ca 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/control/BreakNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/control/BreakNode.java @@ -22,7 +22,6 @@ public class BreakNode extends Node { } target.add(res); - // target.add(Instruction.nop("break", label)); if (pollute) target.add(Instruction.pushUndefined()); } diff --git a/src/main/java/me/topchetoeu/jscript/compilation/control/ContinueNode.java b/src/main/java/me/topchetoeu/jscript/compilation/control/ContinueNode.java index afc94a5..da7eebb 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/control/ContinueNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/control/ContinueNode.java @@ -22,7 +22,6 @@ public class ContinueNode extends Node { } target.add(res); - // () -> Instruction.nop("cont", label)); if (pollute) target.add(Instruction.pushUndefined()); } diff --git a/src/main/java/me/topchetoeu/jscript/compilation/control/DoWhileNode.java b/src/main/java/me/topchetoeu/jscript/compilation/control/DoWhileNode.java index c07a004..1f3de82 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/control/DoWhileNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/control/DoWhileNode.java @@ -34,7 +34,6 @@ public class DoWhileNode extends Node { int endI = target.size(); end.set(endI + 1); - // WhileNode.replaceBreaks(target, label, start, mid - 1, mid, end + 1); target.add(Instruction.jmpIf(start - endI)); } diff --git a/src/main/java/me/topchetoeu/jscript/compilation/control/SwitchNode.java b/src/main/java/me/topchetoeu/jscript/compilation/control/SwitchNode.java index a48f432..e3b1496 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/control/SwitchNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/control/SwitchNode.java @@ -75,12 +75,6 @@ public class SwitchNode extends Node { if (defaultI < 0 || defaultI >= body.length) subtarget.set(start, Instruction.jmp(endI - start)); else subtarget.set(start, Instruction.jmp(statementToIndex.get(defaultI) - start)); - // for (int i = start; i < end; i++) { - // var instr = target.get(i); - // if (instr.type == Type.NOP && instr.is(0, "break") && instr.get(1) == null) { - // target.set(i, Instruction.jmp(end - i)); - // } - // } for (var el : caseToStatement.entrySet()) { var i = statementToIndex.get(el.getValue()); if (i == null) i = endI; diff --git a/src/main/java/me/topchetoeu/jscript/compilation/control/WhileNode.java b/src/main/java/me/topchetoeu/jscript/compilation/control/WhileNode.java index 55787df..94330cf 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/control/WhileNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/control/WhileNode.java @@ -34,8 +34,6 @@ public class WhileNode extends Node { var endI = target.size(); end.set(endI + 1); - // replaceBreaks(target, label, mid + 1, end, start, end + 1); - target.add(Instruction.jmp(start - end.getAsInt())); target.set(mid, Instruction.jmpIfNot(end.getAsInt() - mid + 1)); if (pollute) target.add(Instruction.pushUndefined()); @@ -48,18 +46,6 @@ public class WhileNode extends Node { this.body = body; } - // public static void replaceBreaks(CompileResult target, String label, int start, int end, int continuePoint, int breakPoint) { - // for (int i = start; i < end; i++) { - // var instr = target.get(i); - // if (instr.type == Type.NOP && instr.is(0, "cont") && (instr.get(1) == null || instr.is(1, label))) { - // target.set(i, Instruction.jmp(continuePoint - i)); - // } - // if (instr.type == Type.NOP && instr.is(0, "break") && (instr.get(1) == null || instr.is(1, label))) { - // target.set(i, Instruction.jmp(breakPoint - i)); - // } - // } - // } - public static ParseRes parse(Source src, int i) { var n = Parsing.skipEmpty(src, i); var loc = src.loc(i + n); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java b/src/main/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java index ee3444d..550817c 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java @@ -28,8 +28,6 @@ public class FunctionScope extends Scope { @Override public Variable define(Variable var, Location loc) { checkNotEnded(); if (locals.has(var.name)) throw alreadyDefinedErr(loc, var.name); - // if (specials.has(var.name)) throw alreadyDefinedErr(loc, var.name); - // if (blacklistNames.contains(var.name)) throw alreadyDefinedErr(loc, var.name); if (passtrough) { blacklistNames.add(var.name); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/values/VariableNode.java b/src/main/java/me/topchetoeu/jscript/compilation/values/VariableNode.java index 4e2e276..02c4d36 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/values/VariableNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/values/VariableNode.java @@ -19,13 +19,6 @@ import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; public class VariableNode extends Node implements AssignableNode { public final String name; - // @Override public EvalResult evaluate(CompileResult target) { - // var i = target.scope.getKey(name); - - // if (i instanceof String) return EvalResult.NONE; - // else return EvalResult.UNKNOWN; - // } - @Override public Node toAssign(Node val, Operation operation) { return new VariableAssignNode(loc(), name, val, operation); } @@ -57,7 +50,7 @@ public class VariableNode extends Node implements AssignableNode { } public static IntFunction toGet(CompileResult target, Location loc, String name) { return toGet(target, loc, name, () -> Instruction.globGet(name)); - } + } public static IntFunction toSet(CompileResult target, Location loc, String name, boolean keep, boolean define) { diff --git a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/DiscardNode.java b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/DiscardNode.java index a68ebb6..eaf7b89 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/DiscardNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/DiscardNode.java @@ -13,15 +13,6 @@ import me.topchetoeu.jscript.compilation.Node; public class DiscardNode extends Node { public final Node value; - // @Override public EvalResult evaluate(CompileResult target) { - // if (value == null) return EvalResult.FALSY; - // var res = value.evaluate(target); - - // if (res.isPure) return EvalResult.FALSY; - // else if (res.never) return EvalResult.NEVER; - // else return EvalResult.FALSY_IMPURE; - // } - @Override public void compile(CompileResult target, boolean pollute) { if (value != null) value.compile(target, false); if (pollute) target.add(Instruction.pushUndefined()); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/LazyAndNode.java b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/LazyAndNode.java index a63506b..318751e 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/LazyAndNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/LazyAndNode.java @@ -12,14 +12,6 @@ import me.topchetoeu.jscript.compilation.Node; public class LazyAndNode extends Node { public final Node first, second; - // @Override public EvalResult evaluate(CompileResult target) { - // var firstRes = first.evaluate(target); - // if (firstRes.falsy) return firstRes; - // if (!firstRes.isPure) return firstRes; - - // return second.evaluate(target); - // } - @Override public void compile(CompileResult target, boolean pollute) { first.compile(target, true); if (pollute) target.add(Instruction.dup()); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/LazyOrNode.java b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/LazyOrNode.java index ac374ce..9b1e5a9 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/LazyOrNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/LazyOrNode.java @@ -13,14 +13,6 @@ import me.topchetoeu.jscript.compilation.Node; public class LazyOrNode extends Node { public final Node first, second; - // @Override public EvalResult evaluate(CompileResult target) { - // var firstRes = first.evaluate(target); - // if (firstRes.truthy) return firstRes; - // if (!firstRes.isPure) return firstRes; - - // return second.evaluate(target); - // } - @Override public void compile(CompileResult target, boolean pollute) { first.compile(target, true); if (pollute) target.add(Instruction.dup()); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/TypeofNode.java b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/TypeofNode.java index 15f8387..4d3b07d 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/values/operations/TypeofNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/values/operations/TypeofNode.java @@ -14,15 +14,6 @@ import me.topchetoeu.jscript.compilation.values.VariableNode; public class TypeofNode extends Node { public final Node value; - // @Override public EvalResult evaluate(CompileResult target) { - // if (value instanceof VariableNode) { - // var i = target.scope.getKey(((VariableNode)value).name); - // if (i instanceof String) return EvalResult.NONE; - // } - - // return EvalResult.UNKNOWN; - // } - @Override public void compile(CompileResult target, boolean pollute) { if (value instanceof VariableNode varNode) { target.add(VariableNode.toGet(target, varNode.loc(), varNode.name, () -> Instruction.typeof(varNode.name)));