remove all records

This commit is contained in:
TopchetoEU 2023-08-26 11:49:00 +03:00
parent 2cf10d93fa
commit 480293734b
No known key found for this signature in database
GPG Key ID: 24E57B2E9C61AD19
10 changed files with 98 additions and 24 deletions

View File

@ -7,7 +7,15 @@ import me.topchetoeu.jscript.compilation.values.FunctionStatement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.engine.scope.ScopeRecord;
public class VariableDeclareStatement extends Statement { public class VariableDeclareStatement extends Statement {
public static record Pair(String name, Statement value) {} public static class Pair {
public final String name;
public final Statement value;
public Pair(String name, Statement value) {
this.name = name;
this.value = value;
}
}
public final List<Pair> values; public final List<Pair> values;
@ -16,22 +24,22 @@ public class VariableDeclareStatement extends Statement {
@Override @Override
public void declare(ScopeRecord varsScope) { public void declare(ScopeRecord varsScope) {
for (var key : values) { for (var key : values) {
varsScope.define(key.name()); varsScope.define(key.name);
} }
} }
@Override @Override
public void compile(List<Instruction> target, ScopeRecord scope) { public void compile(List<Instruction> target, ScopeRecord scope) {
for (var entry : values) { for (var entry : values) {
if (entry.name() == null) continue; if (entry.name == null) continue;
var key = scope.getKey(entry.name()); var key = scope.getKey(entry.name);
if (key instanceof String) target.add(Instruction.makeVar((String)key).locate(loc())); if (key instanceof String) target.add(Instruction.makeVar((String)key).locate(loc()));
if (entry.value() instanceof FunctionStatement) { if (entry.value instanceof FunctionStatement) {
((FunctionStatement)entry.value()).compile(target, scope, entry.name(), false); ((FunctionStatement)entry.value).compile(target, scope, entry.name, false);
target.add(Instruction.storeVar(key).locate(loc())); target.add(Instruction.storeVar(key).locate(loc()));
} }
else if (entry.value() != null) { else if (entry.value != null) {
entry.value().compileWithPollution(target, scope); entry.value.compileWithPollution(target, scope);
target.add(Instruction.storeVar(key).locate(loc())); target.add(Instruction.storeVar(key).locate(loc()));
} }
} }

View File

@ -11,7 +11,15 @@ import me.topchetoeu.jscript.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.engine.scope.ScopeRecord;
public class SwitchStatement extends Statement { public class SwitchStatement extends Statement {
public static record SwitchCase(Statement value, int statementI) {} public static class SwitchCase {
public final Statement value;
public final int statementI;
public SwitchCase(Statement value, int statementI) {
this.value = value;
this.statementI = statementI;
}
}
@Override @Override
public boolean pollutesStack() { return false; } public boolean pollutesStack() { return false; }

View File

@ -2,4 +2,12 @@ package me.topchetoeu.jscript.engine;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.Location;
public record BreakpointData(Location loc, CallContext ctx) { } public class BreakpointData {
public final Location loc;
public final CallContext ctx;
public BreakpointData(Location loc, CallContext ctx) {
this.loc = loc;
this.ctx = ctx;
}
}

View File

@ -18,7 +18,18 @@ import me.topchetoeu.jscript.interop.NativeTypeRegister;
import me.topchetoeu.jscript.parsing.Parsing; import me.topchetoeu.jscript.parsing.Parsing;
public class Engine { public class Engine {
private static record RawFunction(GlobalScope scope, String filename, String raw) { } private static class RawFunction {
public final GlobalScope scope;
public final String filename;
public final String raw;
public RawFunction(GlobalScope scope, String filename, String raw) {
this.scope = scope;
this.filename = filename;
this.raw = raw;
}
}
private static class Task { private static class Task {
public final Object func; public final Object func;
public final Object thisArg; public final Object thisArg;

View File

@ -64,7 +64,7 @@ public class DebugServer {
} }
} }
private void onWsConnect(HttpRequest req, Socket socket) throws IOException { private void onWsConnect(HttpRequest req, Socket socket) throws IOException {
var key = req.headers().get("sec-websocket-key"); var key = req.headers.get("sec-websocket-key");
if (key == null) { if (key == null) {
Http.writeResponse( Http.writeResponse(
@ -112,7 +112,7 @@ public class DebugServer {
var socket = server.accept(); var socket = server.accept();
var req = Http.readRequest(socket.getInputStream()); var req = Http.readRequest(socket.getInputStream());
switch (req.path()) { switch (req.path) {
case "/json/version": case "/json/version":
send(socket, "{\"Browser\":\"" + browserDisplayName + "\",\"Protocol-Version\":\"1.2\"}"); send(socket, "{\"Browser\":\"" + browserDisplayName + "\",\"Protocol-Version\":\"1.2\"}");
break; break;
@ -133,7 +133,7 @@ public class DebugServer {
); );
break; break;
default: default:
if (req.path().equals("/devtools/page/" + targetName)) onWsConnect(req, socket); if (req.path.equals("/devtools/page/" + targetName)) onWsConnect(req, socket);
else { else {
Http.writeResponse( Http.writeResponse(
socket.getOutputStream(), socket.getOutputStream(),

View File

@ -2,5 +2,15 @@ package me.topchetoeu.jscript.engine.debug;
import java.util.Map; import java.util.Map;
public record HttpRequest(String method, String path, Map<String, String> headers) {} public class HttpRequest {
public final String method;
public final String path;
public final Map<String, String> headers;
public HttpRequest(String method, String path, Map<String, String> headers) {
this.method = method;
this.path = path;
this.headers = headers;
}
}

View File

@ -26,7 +26,15 @@ public class ObjectValue {
FROZEN, FROZEN,
} }
public static record Property(FunctionValue getter, FunctionValue setter) {} public static class Property {
public final FunctionValue getter;
public final FunctionValue setter;
public Property(FunctionValue getter, FunctionValue setter) {
this.getter = getter;
this.setter = setter;
}
}
private static final Object OBJ_PROTO = new Object(); private static final Object OBJ_PROTO = new Object();
private static final Object ARR_PROTO = new Object(); private static final Object ARR_PROTO = new Object();

View File

@ -34,9 +34,9 @@ public class NativeTypeRegister {
var name = get.value(); var name = get.value();
var prop = target.properties.get(name); var prop = target.properties.get(name);
OverloadFunction getter = null; OverloadFunction getter = null;
var setter = prop == null ? null : prop.setter(); var setter = prop == null ? null : prop.setter;
if (prop != null && prop.getter() instanceof OverloadFunction) getter = (OverloadFunction)prop.getter(); if (prop != null && prop.getter instanceof OverloadFunction) getter = (OverloadFunction)prop.getter;
else getter = new OverloadFunction("get " + name); else getter = new OverloadFunction("get " + name);
getter.overloads.add(Overload.fromMethod(method)); getter.overloads.add(Overload.fromMethod(method));
@ -45,10 +45,10 @@ public class NativeTypeRegister {
if (set != null) { if (set != null) {
var name = set.value(); var name = set.value();
var prop = target.properties.get(name); var prop = target.properties.get(name);
var getter = prop == null ? null : prop.getter(); var getter = prop == null ? null : prop.getter;
OverloadFunction setter = null; OverloadFunction setter = null;
if (prop != null && prop.setter() instanceof OverloadFunction) setter = (OverloadFunction)prop.setter(); if (prop != null && prop.setter instanceof OverloadFunction) setter = (OverloadFunction)prop.setter;
else setter = new OverloadFunction("set " + name); else setter = new OverloadFunction("set " + name);
setter.overloads.add(Overload.fromMethod(method)); setter.overloads.add(Overload.fromMethod(method));

View File

@ -27,7 +27,18 @@ public class Parsing {
ParseRes<T> parse(String filename, List<Token> tokens, int i); ParseRes<T> parse(String filename, List<Token> tokens, int i);
} }
private static record ObjProp(Object name, String access, FunctionStatement func) {} private static class ObjProp {
public final Object name;
public final String access;
public final FunctionStatement func;
public ObjProp(Object name, String access, FunctionStatement func) {
this.name = name;
this.access = access;
this.func = func;
}
}
private static final HashSet<String> reserved = new HashSet<String>(); private static final HashSet<String> reserved = new HashSet<String>();
static { static {
reserved.add("true"); reserved.add("true");

View File

@ -14,7 +14,17 @@ import me.topchetoeu.jscript.exceptions.EngineException;
import me.topchetoeu.jscript.interop.Native; import me.topchetoeu.jscript.interop.Native;
public class Promise { public class Promise {
private static record Handle(CallContext ctx, FunctionValue fulfilled, FunctionValue rejected) {} private static class Handle {
public final CallContext ctx;
public final FunctionValue fulfilled;
public final FunctionValue rejected;
public Handle(CallContext ctx, FunctionValue fulfilled, FunctionValue rejected) {
this.ctx = ctx;
this.fulfilled = fulfilled;
this.rejected = rejected;
}
}
@Native("resolve") @Native("resolve")
public static Promise ofResolved(CallContext engine, Object val) { public static Promise ofResolved(CallContext engine, Object val) {
@ -194,7 +204,7 @@ public class Promise {
this.state = STATE_FULFILLED; this.state = STATE_FULFILLED;
this.val = val; this.val = val;
for (var el : handles) el.ctx().engine().pushMsg(true, el.fulfilled, el.ctx().data(), null, val); for (var el : handles) el.ctx.engine().pushMsg(true, el.fulfilled, el.ctx.data(), null, val);
handles = null; handles = null;
} }
/** /**
@ -222,7 +232,7 @@ public class Promise {
this.state = STATE_REJECTED; this.state = STATE_REJECTED;
this.val = val; this.val = val;
for (var el : handles) el.ctx().engine().pushMsg(true, el.rejected, el.ctx().data(), null, val); for (var el : handles) el.ctx.engine().pushMsg(true, el.rejected, el.ctx.data(), null, val);
handles = null; handles = null;
} }
/** /**