change indentation to tabs

This commit is contained in:
TopchetoEU 2024-12-09 23:58:19 +02:00
parent caf44a50e5
commit db45eb529d
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
111 changed files with 7123 additions and 7341 deletions

View File

@ -1,58 +0,0 @@
package me.topchetoeu.jscript.common;
public class Buffer {
private byte[] data;
private int length;
public void write(int i, byte[] val) {
if (i + val.length > data.length) {
var newCap = i + val.length + 1;
if (newCap < data.length * 2) newCap = data.length * 2;
var tmp = new byte[newCap];
System.arraycopy(this.data, 0, tmp, 0, length);
this.data = tmp;
}
System.arraycopy(val, 0, data, i, val.length);
if (i + val.length > length) length = i + val.length;
}
public int read(int i, byte[] buff) {
int n = buff.length;
if (i + n > length) n = length - i;
System.arraycopy(data, i, buff, 0, n);
return n;
}
public void clear() {
data = new byte[128];
length = 0;
}
public void append(byte b) {
write(length, new byte[] { b });
}
public byte[] data() {
var res = new byte[length];
System.arraycopy(this.data, 0, res, 0, length);
return res;
}
public int length() {
return length;
}
public Buffer(byte[] data) {
this.data = new byte[data.length];
this.length = data.length;
System.arraycopy(data, 0, this.data, 0, data.length);
}
public Buffer(int capacity) {
this.data = new byte[capacity];
this.length = 0;
}
public Buffer() {
this.data = new byte[128];
this.length = 0;
}
}

View File

@ -112,129 +112,11 @@ public class Instruction {
return (T)params[i];
}
// public void write(DataOutputStream writer) throws IOException {
// var rawType = type.numeric;
// switch (type) {
// case KEYS:
// case PUSH_BOOL:
// case STORE_MEMBER:
// case GLOB_SET:
// rawType |= (boolean)get(0) ? 128 : 0; break;
// case TYPEOF: rawType |= params.length > 0 ? 128 : 0; break;
// default:
// }
// writer.writeByte(rawType);
// switch (type) {
// case CALL:
// case CALL_NEW:
// case CALL_MEMBER:
// writer.writeInt(get(0));
// writer.writeUTF(get(1));
// break;
// case DUP: writer.writeInt(get(0)); break;
// case JMP: writer.writeInt(get(0)); break;
// case JMP_IF: writer.writeInt(get(0)); break;
// case JMP_IFN: writer.writeInt(get(0)); break;
// case LOAD_ARR: writer.writeInt(get(0)); break;
// case LOAD_FUNC: {
// writer.writeInt(params.length - 1);
// for (var i = 0; i < params.length; i++) {
// writer.writeInt(get(i + 1));
// }
// writer.writeInt(get(0));
// writer.writeUTF(get(0));
// break;
// }
// case LOAD_REGEX: writer.writeUTF(get(0)); break;
// case LOAD_VAR: writer.writeInt(get(0)); break;
// case GLOB_DEF: writer.writeUTF(get(0)); break;
// case GLOB_GET: writer.writeUTF(get(0)); break;
// case GLOB_SET:
// writer.writeUTF(get(0));
// break;
// case OPERATION: writer.writeByte(((Operation)get(0)).numeric); break;
// case PUSH_NUMBER: writer.writeDouble(get(0)); break;
// case PUSH_STRING: writer.writeUTF(get(0)); break;
// case STORE_VAR: writer.writeInt(get(0)); break;
// case THROW_SYNTAX: writer.writeUTF(get(0));
// case TRY_START:
// writer.writeInt(get(0));
// writer.writeInt(get(1));
// writer.writeInt(get(2));
// break;
// case TYPEOF:
// if (params.length > 0) writer.writeUTF(get(0));
// break;
// default:
// }
// }
private Instruction(Type type, Object ...params) {
this.type = type;
this.params = params;
}
// public static Instruction read(DataInputStream stream) throws IOException {
// var rawType = stream.readUnsignedByte();
// var type = Type.fromNumeric(rawType & 127);
// var flag = (rawType & 128) != 0;
// switch (type) {
// case CALL: return call(stream.readInt(), stream.readUTF());
// case CALL_NEW: return callNew(stream.readInt(), stream.readUTF());
// case CALL_MEMBER: return callNew(stream.readInt(), stream.readUTF());
// case DEF_PROP: return defProp();
// case DELETE: return delete();
// case DISCARD: return discard();
// case DUP: return dup(stream.readInt());
// case JMP: return jmp(stream.readInt());
// case JMP_IF: return jmpIf(stream.readInt());
// case JMP_IFN: return jmpIfNot(stream.readInt());
// case KEYS: return keys(flag);
// case LOAD_ARR: return loadArr(stream.readInt());
// case LOAD_FUNC: {
// var captures = new int[stream.readInt()];
// for (var i = 0; i < captures.length; i++) {
// captures[i] = stream.readInt();
// }
// return loadFunc(stream.readInt(), stream.readUTF(), captures);
// }
// case LOAD_GLOB: return loadGlob();
// case LOAD_MEMBER: return loadMember();
// case LOAD_OBJ: return loadObj();
// case LOAD_REGEX: return loadRegex(stream.readUTF(), null);
// case LOAD_VAR: return loadVar(stream.readInt());
// case GLOB_DEF: return globDef(stream.readUTF());
// case GLOB_GET: return globGet(stream.readUTF());
// case GLOB_SET: return globSet(stream.readUTF(), flag);
// case OPERATION: return operation(Operation.fromNumeric(stream.readUnsignedByte()));
// case PUSH_NULL: return pushNull();
// case PUSH_UNDEFINED: return pushUndefined();
// case PUSH_BOOL: return pushValue(flag);
// case PUSH_NUMBER: return pushValue(stream.readDouble());
// case PUSH_STRING: return pushValue(stream.readUTF());
// case RETURN: return ret();
// case STORE_MEMBER: return storeMember(flag);
// case STORE_VAR: return storeVar(stream.readInt(), flag);
// case THROW: return throwInstr();
// case THROW_SYNTAX: return throwSyntax(stream.readUTF());
// case TRY_END: return tryEnd();
// case TRY_START: return tryStart(stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt());
// case TYPEOF: return flag ? typeof(stream.readUTF()) : typeof();
// case NOP:
// if (flag) return null;
// else return nop();
// default: return null;
// }
// }
/**
* Signals the start of a protected context
* @param catchStart The point to witch to jump if an error has been caught
@ -431,9 +313,6 @@ public class Instruction {
return new Instruction(Type.DUP, count, offset);
}
// public static Instruction storeVar(int i) {
// return new Instruction(Type.STORE_VAR, i, false);
// }
public static Instruction storeVar(int i, boolean keep, boolean initialize) {
return new Instruction(Type.STORE_VAR, i, keep, initialize);
}

View File

@ -1,7 +1,3 @@
package me.topchetoeu.jscript.common.environment;
public final class Key<T> {
public static <T> Key<T> of() {
return new Key<>();
}
}
public final class Key<T> { }

View File

@ -9,16 +9,14 @@ public class JSONMap implements Map<String, JSONElement> {
private Map<String, JSONElement> elements = new HashMap<>();
public JSONElement get(String path) {
var curr = this;
var segs = path.split("\\.");
var i = 0;
JSONElement curr = JSONElement.map(this);
while (true) {
var tmp = curr.elements.get(segs[i++]);
if (i == segs.length) return tmp;
if (!tmp.isMap()) return null;
curr = tmp.map();
for (var seg : path.split("\\.")) {
if (!curr.isMap()) return null;
curr = curr.map().elements.get(seg);
}
return curr;
}
public boolean isMap(String path) {

View File

@ -1,8 +0,0 @@
package me.topchetoeu.jscript.common.mapping;
public enum ConvertType {
Exact,
Lower,
Upper,
Both,
}

View File

@ -127,28 +127,6 @@ public class FunctionMap {
return pcToLoc.lastEntry().getValue();
}
// public static FunctionMap apply(FunctionMap funcMap, SourceMap map) {
// var res = new FunctionMap(Map.of(), Map.of(), funcMap.localNames, funcMap.captureNames);
// for (var el : funcMap.pcToLoc.entrySet()) {
// res.pcToLoc.put(el.getKey(), map.toCompiled(el.getValue()));
// }
// res.bps.putAll(bps);
// for (var el : bpLocs.entrySet()) {
// for (var loc : el.getValue()) {
// loc = map.toCompiled(loc);
// if (loc == null) continue;
// if (!res.bpLocs.containsKey(loc.filename())) res.bpLocs.put(loc.filename(), new TreeSet<>());
// res.bpLocs.get(loc.filename()).add(loc);
// }
// }
// return res;
// }
public FunctionMap clone() {
var res = new FunctionMap(new HashMap<>(), new HashMap<>(), localNames, captureNames);
res.pcToLoc.putAll(this.pcToLoc);

View File

@ -47,12 +47,6 @@ public class Filename {
if (i >= 0) return new Filename(val.substring(0, i).trim(), val.substring(i + 3).trim());
else return new Filename("file", val.trim());
}
// public static Path normalize(String path) {
// // File file = new File("/" + path.trim().replace("\\", "/"));
// // String normalizedPath = new File("/" + path.trim().replace("\\", "/")).getAbsolutePath().replaceFirst("^/", "").replace("\\", "/");
// // return normalizedPath;
// return Path.of(Path.of("/" + path.trim().replace("\\", "/")).normalize().toString().substring(1));
// }
public static Filename fromFile(File file) {
return new Filename("file", file.getAbsolutePath());
}

View File

@ -39,12 +39,12 @@ public abstract class FunctionNode extends Node {
for (var param : params) scope.define(param.name);
// if (selfName != null && !scope.has(selfName, false)) {
// var i = scope.defineSpecial(new Variable(selfName, true), end);
var hasSelf = false;
// t.add(Instruction.loadCalled());
// t.add(_i -> i.index().toInit());
// }
if (selfName != null && !scope.has(selfName, false)) {
hasSelf = true;
scope.define(selfName);
}
body.compileFunctions(target);
@ -52,6 +52,10 @@ public abstract class FunctionNode extends Node {
target.add(Instruction.loadArg(i++)).setLocation(param.loc());
target.add(scope.define(param.name).index().toSet(false)).setLocation(param.loc());
}
if (hasSelf) {
target.add(Instruction.loadCalled());
target.add(scope.define(selfName).index().toSet(false));
}
body.compile(target, lastReturn, BreakpointType.NONE);

View File

@ -52,7 +52,7 @@ public final class JavaScript {
VAR;
}
public static final Key<Environment> COMPILE_ROOT = Key.of();
public static final Key<Environment> COMPILE_ROOT = new Key<>();
static final Set<String> reserved = new HashSet<>(Arrays.asList(
"true", "false", "void", "null", "this", "if", "else", "try", "catch",

View File

@ -13,8 +13,8 @@ import me.topchetoeu.jscript.common.environment.Key;
import me.topchetoeu.jscript.common.parsing.Location;
public class LabelContext {
public static final Key<LabelContext> BREAK_CTX = Key.of();
public static final Key<LabelContext> CONTINUE_CTX = Key.of();
public static final Key<LabelContext> BREAK_CTX = new Key<>();
public static final Key<LabelContext> CONTINUE_CTX = new Key<>();
private final LinkedList<IntSupplier> list = new LinkedList<>();
private final HashMap<String, IntSupplier> map = new HashMap<>();

View File

@ -131,7 +131,6 @@ public final class FunctionScope {
*/
public boolean has(String name, boolean capture) {
if (localsMap.containsKey(name)) return true;
// if (specialVarMap.containsKey(name)) return true;
if (capture) {
if (capturesMap.containsKey(name)) return true;

View File

@ -28,7 +28,7 @@ public interface Compiler {
}
};
public Key<Compiler> KEY = Key.of();
public Key<Compiler> KEY = new Key<>();
public FunctionBody compile(Environment env, Filename filename, String source);

View File

@ -11,7 +11,7 @@ import me.topchetoeu.jscript.runtime.values.Value;
import me.topchetoeu.jscript.runtime.values.functions.FunctionValue;
public interface EventLoop {
public static final Key<EventLoop> KEY = Key.of();
public static final Key<EventLoop> KEY = new Key<>();
public static EventLoop get(Environment ext) {
if (ext.hasNotNull(KEY)) return ext.get(KEY);

View File

@ -16,7 +16,7 @@ import me.topchetoeu.jscript.runtime.values.objects.ObjectValue;
import me.topchetoeu.jscript.runtime.values.primitives.numbers.IntValue;
public final class Frame {
public static final Key<Frame> KEY = Key.of();
public static final Key<Frame> KEY = new Key<>();
public static final EngineException STACK_OVERFLOW;
static {
STACK_OVERFLOW = EngineException.ofRange("Stack overflow!");

View File

@ -17,8 +17,8 @@ import me.topchetoeu.jscript.runtime.values.functions.CodeFunction;
import me.topchetoeu.jscript.runtime.values.functions.FunctionValue;
public class DebugContext {
public static final Key<DebugContext> KEY = Key.of();
public static final Key<Void> IGNORE = Key.of();
public static final Key<DebugContext> KEY = new Key<>();
public static final Key<Void> IGNORE = new Key<>();
private HashMap<Filename, String> sources;
private WeakHashMap<FunctionBody, FunctionMap> maps;

View File

@ -48,29 +48,29 @@ public abstract class Value {
}
}
public static final Key<FunctionValue> REGEX_CONSTR = Key.of();
public static final Key<FunctionValue> REGEX_CONSTR = new Key<>();
public static final Key<Integer> MAX_STACK_COUNT = Key.of();
public static final Key<Boolean> HIDE_STACK = Key.of();
public static final Key<Integer> MAX_STACK_COUNT = new Key<>();
public static final Key<Boolean> HIDE_STACK = new Key<>();
public static final Key<ObjectValue> BOOL_PROTO = Key.of();
public static final Key<ObjectValue> NUMBER_PROTO = Key.of();
public static final Key<ObjectValue> STRING_PROTO = Key.of();
public static final Key<ObjectValue> SYMBOL_PROTO = Key.of();
public static final Key<ObjectValue> BOOL_PROTO = new Key<>();
public static final Key<ObjectValue> NUMBER_PROTO = new Key<>();
public static final Key<ObjectValue> STRING_PROTO = new Key<>();
public static final Key<ObjectValue> SYMBOL_PROTO = new Key<>();
public static final Key<ObjectValue> OBJECT_PROTO = Key.of();
public static final Key<ObjectValue> FUNCTION_PROTO = Key.of();
public static final Key<ObjectValue> OBJECT_PROTO = new Key<>();
public static final Key<ObjectValue> FUNCTION_PROTO = new Key<>();
public static final Key<ObjectValue> ARRAY_PROTO = Key.of();
public static final Key<ObjectValue> BYTE_BUFF_PROTO = Key.of();
public static final Key<ObjectValue> ARRAY_PROTO = new Key<>();
public static final Key<ObjectValue> BYTE_BUFF_PROTO = new Key<>();
public static final Key<ObjectValue> ERROR_PROTO = Key.of();
public static final Key<ObjectValue> SYNTAX_ERR_PROTO = Key.of();
public static final Key<ObjectValue> TYPE_ERR_PROTO = Key.of();
public static final Key<ObjectValue> RANGE_ERR_PROTO = Key.of();
public static final Key<ObjectValue> ERROR_PROTO = new Key<>();
public static final Key<ObjectValue> SYNTAX_ERR_PROTO = new Key<>();
public static final Key<ObjectValue> TYPE_ERR_PROTO = new Key<>();
public static final Key<ObjectValue> RANGE_ERR_PROTO = new Key<>();
public static final Key<ObjectValue> GLOBAL = Key.of();
public static final Key<Map<String, Value>> INTRINSICS = Key.of();
public static final Key<ObjectValue> GLOBAL = new Key<>();
public static final Key<Map<String, Value>> INTRINSICS = new Key<>();
public static final VoidValue UNDEFINED = new VoidValue("undefined", "undefined");
public static final VoidValue NULL = new VoidValue("null", "object");