refactor: remove unneeded old comments
This commit is contained in:
parent
eac4a3af23
commit
55caf1e206
@ -123,18 +123,6 @@ public class Environment {
|
||||
public Environment addAll(Map<Key<?>, ?> 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) {
|
||||
|
@ -59,7 +59,6 @@ public class ParseRes<T> {
|
||||
|
||||
@SafeVarargs
|
||||
@SuppressWarnings("all")
|
||||
// to hell with all of java's bullshit generics that do jack shit nothing
|
||||
public static <T> ParseRes<T> first(Source src, int i, Parser ...parsers) {
|
||||
int n = Parsing.skipEmpty(src, i);
|
||||
ParseRes<T> error = ParseRes.failed();
|
||||
|
@ -27,7 +27,6 @@ public final class CompileResult {
|
||||
}
|
||||
|
||||
public final List<IntFunction<Instruction>> instructions;
|
||||
// public final List<Supplier<CompileResult>> childrenTasks;
|
||||
public final List<CompileResult> 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<CompileResult> supplier) {
|
||||
// this.childrenTasks.add(() -> supplier.get());
|
||||
// return childrenTasks.size() - 1;
|
||||
// }
|
||||
|
||||
public Instruction[] instructions() {
|
||||
var res = new Instruction[instructions.size()];
|
||||
var i = 0;
|
||||
|
@ -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);
|
||||
|
@ -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)));
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -22,7 +22,6 @@ public class BreakNode extends Node {
|
||||
}
|
||||
target.add(res);
|
||||
|
||||
// target.add(Instruction.nop("break", label));
|
||||
if (pollute) target.add(Instruction.pushUndefined());
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ public class ContinueNode extends Node {
|
||||
}
|
||||
target.add(res);
|
||||
|
||||
// () -> Instruction.nop("cont", label));
|
||||
if (pollute) target.add(Instruction.pushUndefined());
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<WhileNode> parse(Source src, int i) {
|
||||
var n = Parsing.skipEmpty(src, i);
|
||||
var loc = src.loc(i + n);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
|
@ -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)));
|
||||
|
Loading…
Reference in New Issue
Block a user