fix: remove unneeded comments

This commit is contained in:
TopchetoEU 2024-09-14 22:08:33 +03:00
parent e2a8a382cc
commit fbbd26bf7d
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
13 changed files with 11 additions and 181 deletions

View File

@ -65,8 +65,7 @@ public class Instruction {
GLOB_DEF(0x62), GLOB_DEF(0x62),
STACK_ALLOC(0x70), STACK_ALLOC(0x70),
STACK_REALLOC(0x71), STACK_REALLOC(0x71);
STACK_FREE(0x72);
private static final HashMap<Integer, Type> types = new HashMap<>(); private static final HashMap<Integer, Type> types = new HashMap<>();
public final int numeric; public final int numeric;
@ -470,10 +469,6 @@ public class Instruction {
public static Instruction stackRealloc(int start, int n) { public static Instruction stackRealloc(int start, int n) {
return new Instruction(Type.STACK_REALLOC, start, start + n); return new Instruction(Type.STACK_REALLOC, start, start + n);
} }
@Deprecated
public static Instruction stackFree(int n) {
return new Instruction(Type.STACK_FREE, n);
}
@Override public String toString() { @Override public String toString() {
var res = type.toString(); var res = type.toString();

View File

@ -38,35 +38,12 @@ public abstract class FunctionNode extends Node {
for (var param : params.params) { for (var param : params.params) {
target.add(Instruction.loadMember(i++)); target.add(Instruction.loadMember(i++));
param.destruct(target, DeclarationType.VAR, true); param.destruct(target, DeclarationType.VAR, true);
// if (scope.has(param.name, false)) throw new SyntaxException(param.loc, "Duplicate parameter name not allowed");
// if (!JavaScript.checkVarName(param.name)) {
// throw new SyntaxException(param.loc, String.format("Unexpected identifier '%s'", param.name));
// }
// var varI = scope.define(new Variable(param.name, false), param.loc);
// if (param.node != null) {
// var end = new DeferredIntSupplier();
// target.add(Instruction.dup());
// target.add(Instruction.pushUndefined());
// target.add(Instruction.operation(Operation.EQUALS));
// target.add(Instruction.jmpIfNot(end));
// target.add(Instruction.discard());
// param.node.compile(target, true);
// end.set(target.size());
// }
// target.add(_i -> varI.index().toSet(false));
} }
} }
if (params.rest != null) { if (params.rest != null) {
target.add(Instruction.loadRestArgs(params.params.size())); target.add(Instruction.loadRestArgs(params.params.size()));
params.rest.destruct(target, DeclarationType.VAR, true); params.rest.destruct(target, DeclarationType.VAR, true);
// if (scope.has(params.restName, false)) throw new SyntaxException(params.restLocation, "Duplicate parameter name not allowed");
// var restVar = scope.define(new Variable(params.restName, false), params.restLocation);
// target.add(_i -> restVar.index().toSet(false));
} }
if (selfName != null && !scope.has(name, false)) { if (selfName != null && !scope.has(name, false)) {

View File

@ -167,8 +167,6 @@ public class SwitchNode extends Node {
SwitchNode::parseSwitchCase SwitchNode::parseSwitchCase
); );
// Parsing::parseStatement
if (caseRes.isSuccess()) { if (caseRes.isSuccess()) {
n += caseRes.n; n += caseRes.n;

View File

@ -27,8 +27,6 @@ public class AssignPattern implements Pattern {
throw new SyntaxException(loc(), "Expected an assignment value for destructor declaration"); throw new SyntaxException(loc(), "Expected an assignment value for destructor declaration");
} }
@Override public void destruct(CompileResult target, DeclarationType decl, boolean shouldDeclare) { @Override public void destruct(CompileResult target, DeclarationType decl, boolean shouldDeclare) {
// if (assignable instanceof AssignPattern other) throw new SyntaxException(other.loc(), "Unexpected destruction target");
target.add(Instruction.dup()); target.add(Instruction.dup());
target.add(Instruction.pushUndefined()); target.add(Instruction.pushUndefined());
target.add(Instruction.operation(Operation.EQUALS)); target.add(Instruction.operation(Operation.EQUALS));

View File

@ -286,11 +286,6 @@ public class ObjectNode extends Node implements AssignTargetLike {
// target.scope.end(); // target.scope.end();
// } // }
// @Override public void destruct(CompileResult target, DeclarationType decl) {
// if (getters.size() > 0) throw new SyntaxException(getters.values().iterator().next().loc(), "Unexpected getter in destructor");
// if (setters.size() > 0) throw new SyntaxException(setters.values().iterator().next().loc(), "Unexpected setter in destructor");
// }
@Override public void compile(CompileResult target, boolean pollute) { @Override public void compile(CompileResult target, boolean pollute) {
target.add(Instruction.loadObj()); target.add(Instruction.loadObj());

View File

@ -21,22 +21,10 @@ public class VariableNode extends Node implements Pattern, ChangeTarget {
public String assignName() { return name; } public String assignName() { return name; }
// @Override public void compileBeforeAssign(CompileResult target, boolean operator) {
// if (operator) {
// target.add(VariableNode.toGet(target, loc(), name));
// }
// }
// @Override public void compileAfterAssign(CompileResult target, boolean operator, boolean pollute) {
// target.add(VariableNode.toSet(target, loc(), name, pollute, false));
// }
@Override public void beforeChange(CompileResult target) { @Override public void beforeChange(CompileResult target) {
target.add(VariableNode.toGet(target, loc(), name)); target.add(VariableNode.toGet(target, loc(), name));
} }
// @Override public void destructArg(CompileResult target) {
// target.add(_i -> target.scope.define(new Variable(name, false), loc()).index().toSet(false));
// }
@Override public void destructDeclResolve(CompileResult target) { @Override public void destructDeclResolve(CompileResult target) {
target.scope.define(new Variable(name, false), loc()); target.scope.define(new Variable(name, false), loc());
} }

View File

@ -53,9 +53,6 @@ public class IndexNode extends Node implements ChangeTarget {
indexStore(target, index, pollute); indexStore(target, index, pollute);
} }
// @Override public Node toAssign(Node val, Operation operation) {
// return new IndexAssignNode(loc(), object, index, val, operation);
// }
public void compile(CompileResult target, boolean dupObj, boolean pollute) { public void compile(CompileResult target, boolean dupObj, boolean pollute) {
object.compile(target, true); object.compile(target, true);
if (dupObj) target.add(Instruction.dup()); if (dupObj) target.add(Instruction.dup());

View File

@ -226,11 +226,6 @@ public class OperationNode extends Node {
var res = factory.construct(src, i + n, prev); var res = factory.construct(src, i + n, prev);
return res.addN(n); return res.addN(n);
// var res = Parsing.parseValue(src, i + n, prec + 1);
// if (!res.isSuccess()) return res.chainError(src.loc(i + n), String.format("Expected a value after the '%s' operator.", token));
// n += res.n;
// return ParseRes.res(new OperationStatement(loc, factories.get(token), prev, res.result), n);
} }
return ParseRes.failed(); return ParseRes.failed();

View File

@ -222,13 +222,10 @@ public final class Frame {
if (newCtx != tryCtx) { if (newCtx != tryCtx) {
switch (newCtx.state) { switch (newCtx.state) {
case CATCH: case CATCH:
// TODO: may cause problems
// if (tryCtx.state != TryState.CATCH) locals.add(new Value[] { error.value });
codePtr = tryCtx.catchStart; codePtr = tryCtx.catchStart;
stackPtr = tryCtx.restoreStackPtr; stackPtr = tryCtx.restoreStackPtr;
break; break;
case FINALLY: case FINALLY:
// if (tryCtx.state == TryState.CATCH) locals.remove(locals.size() - 1);
codePtr = tryCtx.finallyStart; codePtr = tryCtx.finallyStart;
stackPtr = tryCtx.restoreStackPtr; stackPtr = tryCtx.restoreStackPtr;
default: default:
@ -244,7 +241,6 @@ public final class Frame {
} }
else { else {
popTryFlag = false; popTryFlag = false;
// if (tryCtx.state == TryState.CATCH) locals.remove(locals.size() - 1);
if (tryCtx.state != TryState.FINALLY && tryCtx.hasFinally()) { if (tryCtx.state != TryState.FINALLY && tryCtx.hasFinally()) {
codePtr = tryCtx.finallyStart; codePtr = tryCtx.finallyStart;
@ -339,44 +335,6 @@ public final class Frame {
DebugContext.get(env).onFramePop(env, this); DebugContext.get(env).onFramePop(env, this);
} }
/**
* Gets an object proxy of the local locals
*/
public ObjectValue getLocalScope() {
throw new RuntimeException("Not supported");
// var names = new String[locals.locals.length];
// var map = DebugContext.get(env).getMapOrEmpty(function);
// for (int i = 0; i < locals.locals.length; i++) {
// var name = "local_" + (i - 2);
// if (i == 0) name = "this";
// else if (i == 1) name = "arguments";
// else if (i < map.localNames.length) name = map.localNames[i];
// names[i] = name;
// }
// return new ScopeValue(locals, names);
}
/**
* Gets an object proxy of the capture locals
*/
public ObjectValue getCaptureScope() {
throw new RuntimeException("Not supported");
// var names = new String[captures.length];
// var map = DebugContext.get(env).getMapOrEmpty(function);
// for (int i = 0; i < captures.length; i++) {
// var name = "capture_" + (i - 2);
// if (i < map.captureNames.length) name = map.captureNames[i];
// names[i] = name;
// }
// return new ScopeValue(captures, names);
}
/** /**
* Gets an array proxy of the local locals * Gets an array proxy of the local locals
*/ */
@ -389,31 +347,6 @@ public final class Frame {
@Override public int size() { return stackPtr; } @Override public int size() { return stackPtr; }
@Override public boolean setSize(int val) { return false; } @Override public boolean setSize(int val) { return false; }
// @Override public Member getOwnMember(Environment env, KeyCache key) {
// var res = super.getOwnMember(env, key);
// if (res != null) return res;
// var num = key.toNumber(env);
// var i = key.toInt(env);
// if (num != i || i < 0 || i >= stackPtr) return null;
// else return new FieldMember(this, false, true, true) {
// @Override public Value get(Environment env, Value self) { return stack[i]; }
// @Override public boolean set(Environment env, Value val, Value self) {
// stack[i] = val;
// return true;
// }
// };
// }
// @Override public Set<String> getOwnMembers(Environment env, boolean onlyEnumerable) {
// var res = new LinkedHashSet<String>();
// res.addAll(super.getOwnMembers(env, onlyEnumerable));
// for (var i = 0; i < stackPtr; i++) res.add(i + "");
// return res;
// }
}; };
} }

View File

@ -534,14 +534,6 @@ public class InstructionRunner {
frame.codePtr++; frame.codePtr++;
return null; return null;
} }
private static Value execStackFree(Environment env, Instruction instr, Frame frame) {
// int n = instr.get(0);
// TODO: Remove if safe to do so
frame.codePtr++;
return null;
}
public static Value exec(Environment env, Instruction instr, Frame frame) { public static Value exec(Environment env, Instruction instr, Frame frame) {
switch (instr.type) { switch (instr.type) {
@ -602,7 +594,6 @@ public class InstructionRunner {
case STACK_ALLOC: return execStackAlloc(env, instr, frame); case STACK_ALLOC: return execStackAlloc(env, instr, frame);
case STACK_REALLOC: return execStackRealloc(env, instr, frame); case STACK_REALLOC: return execStackRealloc(env, instr, frame);
case STACK_FREE: return execStackFree(env, instr, frame);
default: throw EngineException.ofSyntax("Invalid instruction " + instr.type.name() + "."); default: throw EngineException.ofSyntax("Invalid instruction " + instr.type.name() + ".");
} }

View File

@ -345,29 +345,8 @@ public class SimpleRepl {
} }
private static void initEnv() { private static void initEnv() {
// glob.define(null, false, new NativeFunction("go", args -> {
// try {
// var f = Path.of("do.js");
// var func = Compiler.compile(args.env, new Filename("do", "do/" + j++ + ".js"), new String(Files.readAllBytes(f)));
// return func.call(args.env);
// }
// catch (IOException e) {
// throw new EngineException("Couldn't open do.js");
// }
// }));
// var fs = new RootFilesystem(PermissionsProvider.get(environment));
// fs.protocols.put("temp", new MemoryFilesystem(Mode.READ_WRITE));
// fs.protocols.put("file", new PhysicalFilesystem("."));
// fs.protocols.put("std", new STDFilesystem(System.in, System.out, System.err));
// environment.add(PermissionsProvider.KEY, PermissionsManager.ALL_PERMS);
// environment.add(Filesystem.KEY, fs);
// environment.add(ModuleRepo.KEY, ModuleRepo.ofFilesystem(fs));
// environment.add(Compiler.KEY, new JSCompiler(environment));
environment.add(EventLoop.KEY, engine); environment.add(EventLoop.KEY, engine);
environment.add(DebugContext.KEY, new DebugContext()); environment.add(DebugContext.KEY, new DebugContext());
// environment.add(EventLoop.KEY, engine);
environment.add(Compiler.KEY, Compiler.DEFAULT); environment.add(Compiler.KEY, Compiler.DEFAULT);
var glob = Value.global(environment); var glob = Value.global(environment);

View File

@ -9,7 +9,6 @@ import me.topchetoeu.jscript.common.environment.Environment;
import me.topchetoeu.jscript.runtime.values.Value; import me.topchetoeu.jscript.runtime.values.Value;
import me.topchetoeu.jscript.runtime.values.primitives.VoidValue; import me.topchetoeu.jscript.runtime.values.primitives.VoidValue;
// TODO: Make methods generic
public class ArrayValue extends ArrayLikeValue implements Iterable<Value> { public class ArrayValue extends ArrayLikeValue implements Iterable<Value> {
private Value[] values; private Value[] values;
private int size; private int size;

View File

@ -1,26 +1,15 @@
package me.topchetoeu.jscript.runtime.values.objects; package me.topchetoeu.jscript.runtime.values.objects;
import java.util.Comparator; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import me.topchetoeu.jscript.common.environment.Environment; import me.topchetoeu.jscript.common.environment.Environment;
import me.topchetoeu.jscript.runtime.values.Value; import me.topchetoeu.jscript.runtime.values.Value;
import me.topchetoeu.jscript.runtime.values.primitives.numbers.NumberValue; import me.topchetoeu.jscript.runtime.values.primitives.numbers.NumberValue;
// TODO: Make methods generic
public class ByteBufferValue extends ArrayLikeValue implements Iterable<Value> { public class ByteBufferValue extends ArrayLikeValue implements Iterable<Value> {
public final byte[] values; public final byte[] values;
// private Value[] alloc(int index) {
// index++;
// if (index < values.length) return values;
// if (index < values.length * 2) index = values.length * 2;
// var arr = new Value[index];
// System.arraycopy(values, 0, arr, 0, values.length);
// return values = arr;
// }
public int size() { return values.length; } public int size() { return values.length; }
public boolean setSize(int val) { return false; } public boolean setSize(int val) { return false; }
@ -54,22 +43,18 @@ public class ByteBufferValue extends ArrayLikeValue implements Iterable<Value> {
System.arraycopy(values, srcI, values, dstI, n); System.arraycopy(values, srcI, values, dstI, n);
} }
public void sort(Comparator<Value> comparator) { public void sort() {
throw new RuntimeException("not supported"); var buckets = new int[256];
// Arrays.sort(values, 0, values.length, (a, b) -> {
// var _a = 0;
// var _b = 0;
// if (a == null) _a = 2; for (var i = 0; i < values.length; i++) {
// if (a instanceof VoidValue) _a = 1; buckets[values[i] + 128]++;
}
// if (b == null) _b = 2; var offset = 0;
// if (b instanceof VoidValue) _b = 1;
// if (_a != 0 || _b != 0) return Integer.compare(_a, _b); for (var i = 0; i < values.length; i++) {
Arrays.fill(values, offset, offset += buckets[i], (byte)(i - 128));
// return comparator.compare(a, b); }
// });
} }
@Override public Iterator<Value> iterator() { @Override public Iterator<Value> iterator() {