fix: how the hell did i fix this (it was the cache all along)
This commit is contained in:
parent
773bc72f3e
commit
42f443572a
1
src/assets/js/bootstrap.js
vendored
1
src/assets/js/bootstrap.js
vendored
@ -64,7 +64,6 @@
|
|||||||
|
|
||||||
if (!environments[env.id]) environments[env.id] = []
|
if (!environments[env.id]) environments[env.id] = []
|
||||||
declSnapshots = environments[env.id];
|
declSnapshots = environments[env.id];
|
||||||
debugger;
|
|
||||||
var emit = service.getEmitOutput("/src.ts");
|
var emit = service.getEmitOutput("/src.ts");
|
||||||
|
|
||||||
var diagnostics = []
|
var diagnostics = []
|
||||||
|
7
src/assets/js/lib.d.ts
vendored
7
src/assets/js/lib.d.ts
vendored
@ -458,11 +458,16 @@ interface SymbolConstructor {
|
|||||||
readonly asyncIterator: unique symbol;
|
readonly asyncIterator: unique symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface Promise<T> extends Thenable<T> {
|
interface Promise<T> extends Thenable<T> {
|
||||||
catch<ResT = void>(func: (err: unknown) => ResT): Promise<ResT>;
|
catch<ResT = void>(func: (err: unknown) => ResT): Promise<ResT>;
|
||||||
finally(func: () => void): Promise<T>;
|
finally(func: () => void): Promise<T>;
|
||||||
|
constructor: PromiseConstructor;
|
||||||
}
|
}
|
||||||
interface PromiseConstructor {
|
interface PromiseConstructorLike {
|
||||||
|
new <T>(func: (res: (val: T) => void, rej: (err: unknown) => void) => void): Thenable<Awaited<T>>;
|
||||||
|
}
|
||||||
|
interface PromiseConstructor extends PromiseConstructorLike {
|
||||||
prototype: Promise<any>;
|
prototype: Promise<any>;
|
||||||
|
|
||||||
new <T>(func: (res: (val: T) => void, rej: (err: unknown) => void) => void): Promise<Awaited<T>>;
|
new <T>(func: (res: (val: T) => void, rej: (err: unknown) => void) => void): Promise<Awaited<T>>;
|
||||||
|
@ -15,15 +15,9 @@ public class CompileTarget {
|
|||||||
public final Map<Long, FunctionBody> functions;
|
public final Map<Long, FunctionBody> functions;
|
||||||
public final TreeSet<Location> breakpoints;
|
public final TreeSet<Location> breakpoints;
|
||||||
private final HashMap<Location, Instruction> bpToInstr = new HashMap<>();
|
private final HashMap<Location, Instruction> bpToInstr = new HashMap<>();
|
||||||
private BreakpointType queueType = BreakpointType.NONE;
|
|
||||||
private Location queueLoc = null;
|
|
||||||
|
|
||||||
public Instruction add(Instruction instr) {
|
public Instruction add(Instruction instr) {
|
||||||
target.add(instr);
|
target.add(instr);
|
||||||
if (queueType != BreakpointType.NONE) setDebug(queueType);
|
|
||||||
if (queueLoc != null) instr.locate(queueLoc);
|
|
||||||
queueType = BreakpointType.NONE;
|
|
||||||
queueLoc = null;
|
|
||||||
return instr;
|
return instr;
|
||||||
}
|
}
|
||||||
public Instruction set(int i, Instruction instr) {
|
public Instruction set(int i, Instruction instr) {
|
||||||
@ -56,13 +50,6 @@ public class CompileTarget {
|
|||||||
else return target.get(target.size() - 1).location;
|
else return target.get(target.size() - 1).location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queueDebug(BreakpointType type) {
|
|
||||||
queueType = type;
|
|
||||||
}
|
|
||||||
public void queueDebug(BreakpointType type, Location loc) {
|
|
||||||
queueType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Instruction[] array() { return target.toArray(Instruction[]::new); }
|
public Instruction[] array() { return target.toArray(Instruction[]::new); }
|
||||||
|
|
||||||
public FunctionBody body() {
|
public FunctionBody body() {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package me.topchetoeu.jscript.compilation;
|
package me.topchetoeu.jscript.compilation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.Location;
|
import me.topchetoeu.jscript.Location;
|
||||||
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType;
|
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType;
|
||||||
import me.topchetoeu.jscript.compilation.values.FunctionStatement;
|
import me.topchetoeu.jscript.compilation.values.FunctionStatement;
|
||||||
@ -25,19 +28,21 @@ public class CompoundStatement extends Statement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType type) {
|
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType type) {
|
||||||
if (separateFuncs) for (var stm : statements) {
|
List<Statement> statements = new Vector<Statement>();
|
||||||
|
if (separateFuncs) for (var stm : this.statements) {
|
||||||
if (stm instanceof FunctionStatement && ((FunctionStatement)stm).statement) {
|
if (stm instanceof FunctionStatement && ((FunctionStatement)stm).statement) {
|
||||||
stm.compile(target, scope, false);
|
stm.compile(target, scope, false);
|
||||||
}
|
}
|
||||||
|
else statements.add(stm);
|
||||||
}
|
}
|
||||||
|
else statements = List.of(this.statements);
|
||||||
|
|
||||||
var polluted = false;
|
var polluted = false;
|
||||||
|
|
||||||
for (var i = 0; i < statements.length; i++) {
|
for (var i = 0; i < statements.size(); i++) {
|
||||||
var stm = statements[i];
|
var stm = statements.get(i);
|
||||||
|
|
||||||
if (separateFuncs && stm instanceof FunctionStatement) continue;
|
if (i != statements.size() - 1) stm.compile(target, scope, false, BreakpointType.STEP_OVER);
|
||||||
if (i != statements.length - 1) stm.compile(target, scope, false, BreakpointType.STEP_OVER);
|
|
||||||
else stm.compile(target, scope, polluted = pollute, BreakpointType.STEP_OVER);
|
else stm.compile(target, scope, polluted = pollute, BreakpointType.STEP_OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +36,10 @@ public class VariableDeclareStatement extends Statement {
|
|||||||
|
|
||||||
if (key instanceof String) target.add(Instruction.makeVar(entry.location, (String)key));
|
if (key instanceof String) target.add(Instruction.makeVar(entry.location, (String)key));
|
||||||
|
|
||||||
target.queueDebug(BreakpointType.STEP_OVER, entry.location);
|
if (entry.value != null) {
|
||||||
if (entry.value != null) FunctionStatement.compileWithName(entry.value, target, scope, true, entry.name);
|
FunctionStatement.compileWithName(entry.value, target, scope, true, entry.name, BreakpointType.STEP_OVER);
|
||||||
else target.add(Instruction.loadValue(entry.location, null));
|
target.add(Instruction.storeVar(entry.location, key));
|
||||||
target.add(Instruction.storeVar(entry.location, key));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pollute) target.add(Instruction.loadValue(loc(), null));
|
if (pollute) target.add(Instruction.loadValue(loc(), null));
|
||||||
|
@ -44,11 +44,10 @@ public class ForInStatement extends Statement {
|
|||||||
target.add(Instruction.nop(loc()));
|
target.add(Instruction.nop(loc()));
|
||||||
|
|
||||||
target.add(Instruction.loadMember(varLocation, "value"));
|
target.add(Instruction.loadMember(varLocation, "value"));
|
||||||
target.queueDebug(BreakpointType.STEP_OVER, object.loc());
|
target.add(Instruction.storeVar(object.loc(), key));
|
||||||
target.add(Instruction.storeVar(varLocation, key));
|
target.setDebug(BreakpointType.STEP_OVER);
|
||||||
|
|
||||||
target.queueDebug(BreakpointType.STEP_OVER, body.loc());
|
body.compile(target, scope, false, BreakpointType.STEP_OVER);
|
||||||
body.compile(target, scope, false);
|
|
||||||
|
|
||||||
int end = target.size();
|
int end = target.size();
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ public class TryStatement extends Statement {
|
|||||||
target.add(Instruction.tryEnd(loc()));
|
target.add(Instruction.tryEnd(loc()));
|
||||||
}
|
}
|
||||||
|
|
||||||
target.queueDebug(BreakpointType.STEP_OVER);
|
|
||||||
target.set(start - 1, Instruction.tryStart(loc(), catchStart, finallyStart, target.size() - start));
|
target.set(start - 1, Instruction.tryStart(loc(), catchStart, finallyStart, target.size() - start));
|
||||||
|
target.setDebug(start - 1, BreakpointType.STEP_OVER);
|
||||||
if (pollute) target.add(Instruction.loadValue(loc(), null));
|
if (pollute) target.add(Instruction.loadValue(loc(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ public class CallStatement extends Statement {
|
|||||||
|
|
||||||
for (var arg : args) arg.compile(target, scope, true);
|
for (var arg : args) arg.compile(target, scope, true);
|
||||||
|
|
||||||
target.queueDebug(type);
|
|
||||||
if (isNew) target.add(Instruction.callNew(loc(), args.length));
|
if (isNew) target.add(Instruction.callNew(loc(), args.length));
|
||||||
else target.add(Instruction.call(loc(), args.length));
|
else target.add(Instruction.call(loc(), args.length));
|
||||||
|
target.setDebug(type);
|
||||||
|
|
||||||
if (!pollute) target.add(Instruction.discard(loc()));
|
if (!pollute) target.add(Instruction.discard(loc()));
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class FunctionStatement extends Statement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long compileBody(CompileTarget target, ScopeRecord scope, boolean polute) {
|
private long compileBody(CompileTarget target, ScopeRecord scope, boolean polute, BreakpointType bp) {
|
||||||
for (var i = 0; i < args.length; i++) {
|
for (var i = 0; i < args.length; i++) {
|
||||||
for (var j = 0; j < i; j++) {
|
for (var j = 0; j < i; j++) {
|
||||||
if (args[i].equals(args[j])) {
|
if (args[i].equals(args[j])) {
|
||||||
@ -68,6 +68,7 @@ public class FunctionStatement extends Statement {
|
|||||||
|
|
||||||
if (!statement && this.varName != null) {
|
if (!statement && this.varName != null) {
|
||||||
subtarget.add(Instruction.storeSelfFunc(loc(), (int)subscope.define(this.varName)));
|
subtarget.add(Instruction.storeSelfFunc(loc(), (int)subscope.define(this.varName)));
|
||||||
|
subtarget.setDebug(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
body.declare(subscope);
|
body.declare(subscope);
|
||||||
@ -84,13 +85,13 @@ public class FunctionStatement extends Statement {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, String name) {
|
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, String name, BreakpointType bp) {
|
||||||
if (this.varName != null) name = this.varName;
|
if (this.varName != null) name = this.varName;
|
||||||
|
|
||||||
var hasVar = this.varName != null && statement;
|
var hasVar = this.varName != null && statement;
|
||||||
var hasName = name != null;
|
var hasName = name != null;
|
||||||
|
|
||||||
compileBody(target, scope, pollute || hasVar || hasName);
|
compileBody(target, scope, pollute || hasVar || hasName, bp);
|
||||||
|
|
||||||
if (hasName) {
|
if (hasName) {
|
||||||
if (pollute || hasVar) target.add(Instruction.dup(loc()));
|
if (pollute || hasVar) target.add(Instruction.dup(loc()));
|
||||||
@ -106,8 +107,14 @@ public class FunctionStatement extends Statement {
|
|||||||
target.add(Instruction.storeVar(loc(), scope.getKey(this.varName), false));
|
target.add(Instruction.storeVar(loc(), scope.getKey(this.varName), false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, String name) {
|
||||||
|
compile(target, scope, pollute, name, BreakpointType.NONE);
|
||||||
|
}
|
||||||
|
@Override public void compile(CompileTarget target, ScopeRecord scope, boolean pollute, BreakpointType bp) {
|
||||||
|
compile(target, scope, pollute, (String)null, bp);
|
||||||
|
}
|
||||||
@Override public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
@Override public void compile(CompileTarget target, ScopeRecord scope, boolean pollute) {
|
||||||
compile(target, scope, pollute, BreakpointType.NONE);
|
compile(target, scope, pollute, (String)null, BreakpointType.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FunctionStatement(Location loc, Location end, String varName, String[] args, boolean statement, CompoundStatement body) {
|
public FunctionStatement(Location loc, Location end, String varName, String[] args, boolean statement, CompoundStatement body) {
|
||||||
@ -125,4 +132,8 @@ public class FunctionStatement extends Statement {
|
|||||||
if (stm instanceof FunctionStatement) ((FunctionStatement)stm).compile(target, scope, pollute, name);
|
if (stm instanceof FunctionStatement) ((FunctionStatement)stm).compile(target, scope, pollute, name);
|
||||||
else stm.compile(target, scope, pollute);
|
else stm.compile(target, scope, pollute);
|
||||||
}
|
}
|
||||||
|
public static void compileWithName(Statement stm, CompileTarget target, ScopeRecord scope, boolean pollute, String name, BreakpointType bp) {
|
||||||
|
if (stm instanceof FunctionStatement) ((FunctionStatement)stm).compile(target, scope, pollute, name, bp);
|
||||||
|
else stm.compile(target, scope, pollute, bp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,6 +198,7 @@ public class CodeFrame {
|
|||||||
|
|
||||||
if (instr == null) returnValue = null;
|
if (instr == null) returnValue = null;
|
||||||
else {
|
else {
|
||||||
|
// System.out.println(instr + "@" + instr.location);
|
||||||
ctx.engine.onInstruction(ctx, this, instr, Runners.NO_RETURN, null, false);
|
ctx.engine.onInstruction(ctx, this, instr, Runners.NO_RETURN, null, false);
|
||||||
|
|
||||||
if (instr.location != null) prevLoc = instr.location;
|
if (instr.location != null) prevLoc = instr.location;
|
||||||
|
@ -880,7 +880,7 @@ public class Parsing {
|
|||||||
var callRes = parseCall(filename, tokens, i + n, valRes.result, 0);
|
var callRes = parseCall(filename, tokens, i + n, valRes.result, 0);
|
||||||
n += callRes.n;
|
n += callRes.n;
|
||||||
if (callRes.isError()) return callRes.transform();
|
if (callRes.isError()) return callRes.transform();
|
||||||
else if (callRes.isFailed()) return ParseRes.res(new CallStatement(loc, false, valRes.result), n);
|
else if (callRes.isFailed()) return ParseRes.res(new CallStatement(loc, true, valRes.result), n);
|
||||||
var call = (CallStatement)callRes.result;
|
var call = (CallStatement)callRes.result;
|
||||||
|
|
||||||
return ParseRes.res(new CallStatement(loc, true, call.func, call.args), n);
|
return ParseRes.res(new CallStatement(loc, true, call.func, call.args), n);
|
||||||
|
80
test.txt
80
test.txt
@ -1,80 +0,0 @@
|
|||||||
const { spawn } = require('child_process');
|
|
||||||
const fs = require('fs/promises');
|
|
||||||
const pt = require('path');
|
|
||||||
const { argv, exit } = require('process');
|
|
||||||
|
|
||||||
const conf = {
|
|
||||||
name: "java-jscript",
|
|
||||||
author: "TopchetoEU",
|
|
||||||
javahome: "",
|
|
||||||
version: argv[3]
|
|
||||||
};
|
|
||||||
|
|
||||||
if (conf.version.startsWith('refs/tags/')) conf.version = conf.version.substring(10);
|
|
||||||
if (conf.version.startsWith('v')) conf.version = conf.version.substring(1);
|
|
||||||
|
|
||||||
async function* find(src, dst, wildcard) {
|
|
||||||
const stat = await fs.stat(src);
|
|
||||||
|
|
||||||
if (stat.isDirectory()) {
|
|
||||||
for (const el of await fs.readdir(src)) {
|
|
||||||
for await (const res of find(pt.join(src, el), dst ? pt.join(dst, el) : undefined, wildcard)) yield res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (stat.isFile() && wildcard(src)) yield dst ? { src, dst } : src;
|
|
||||||
}
|
|
||||||
async function copy(src, dst, wildcard) {
|
|
||||||
const promises = [];
|
|
||||||
|
|
||||||
for await (const el of find(src, dst, wildcard)) {
|
|
||||||
promises.push((async () => {
|
|
||||||
await fs.mkdir(pt.dirname(el.dst), { recursive: true });
|
|
||||||
await fs.copyFile(el.src, el.dst);
|
|
||||||
})());
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
function run(cmd, ...args) {
|
|
||||||
return new Promise((res, rej) => {
|
|
||||||
const proc = spawn(cmd, args, { stdio: 'inherit' });
|
|
||||||
proc.once('exit', code => {
|
|
||||||
if (code === 0) res(code);
|
|
||||||
else rej(new Error(`Process ${cmd} exited with code ${code}.`));
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function compileJava() {
|
|
||||||
try {
|
|
||||||
await fs.writeFile('Metadata.java', (await fs.readFile('src/me/topchetoeu/jscript/Metadata.java')).toString()
|
|
||||||
.replace('${VERSION}', conf.version)
|
|
||||||
.replace('${NAME}', conf.name)
|
|
||||||
.replace('${AUTHOR}', conf.author)
|
|
||||||
);
|
|
||||||
const args = ['--release', '11', ];
|
|
||||||
if (argv[2] === 'debug') args.push('-g');
|
|
||||||
args.push('-d', 'dst/classes', 'Metadata.java');
|
|
||||||
|
|
||||||
for await (const path of find('src', undefined, v => v.endsWith('.java') && !v.endsWith('Metadata.java'))) args.push(path);
|
|
||||||
await run(conf.javahome + 'javac', ...args);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
await fs.rm('Metadata.java');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
try { await fs.rm('dst', { recursive: true }); } catch {}
|
|
||||||
await copy('src', 'dst/classes', v => !v.endsWith('.java'));
|
|
||||||
await compileJava();
|
|
||||||
await run('jar', '-c', '-f', 'dst/jscript.jar', '-e', 'me.topchetoeu.jscript.Main', '-C', 'dst/classes', '.');
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
if (argv[2] === 'debug') throw e;
|
|
||||||
console.log(e.toString());
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
})();
|
|
Loading…
Reference in New Issue
Block a user