Compare commits
2 Commits
v0.9.2-bet
...
v0.9.3-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
3e6214659b
|
|||
|
7c6622c53d
|
@@ -14,7 +14,7 @@ import java.util.stream.Collectors;
|
||||
import me.topchetoeu.jscript.common.Filename;
|
||||
import me.topchetoeu.jscript.common.Location;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.core.scope.LocalScopeRecord;
|
||||
import me.topchetoeu.jscript.compilation.scope.LocalScopeRecord;
|
||||
import me.topchetoeu.jscript.utils.mapping.SourceMap;
|
||||
|
||||
public class FunctionMap {
|
||||
|
||||
@@ -10,7 +10,7 @@ import me.topchetoeu.jscript.common.Location;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.mapping.FunctionMap;
|
||||
import me.topchetoeu.jscript.common.mapping.FunctionMap.FunctionMapBuilder;
|
||||
import me.topchetoeu.jscript.core.scope.LocalScopeRecord;
|
||||
import me.topchetoeu.jscript.compilation.scope.LocalScopeRecord;
|
||||
|
||||
public class CompileResult {
|
||||
public final Vector<Instruction> instructions = new Vector<>();
|
||||
|
||||
@@ -16,8 +16,8 @@ import me.topchetoeu.jscript.compilation.VariableDeclareStatement.Pair;
|
||||
import me.topchetoeu.jscript.compilation.control.*;
|
||||
import me.topchetoeu.jscript.compilation.control.SwitchStatement.SwitchCase;
|
||||
import me.topchetoeu.jscript.compilation.parsing.ParseRes.State;
|
||||
import me.topchetoeu.jscript.compilation.scope.LocalScopeRecord;
|
||||
import me.topchetoeu.jscript.compilation.values.*;
|
||||
import me.topchetoeu.jscript.core.scope.LocalScopeRecord;
|
||||
import me.topchetoeu.jscript.core.exceptions.SyntaxException;
|
||||
|
||||
// TODO: this has to be rewritten
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package me.topchetoeu.jscript.core.scope;
|
||||
package me.topchetoeu.jscript.compilation.scope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import me.topchetoeu.jscript.common.ScopeRecord;
|
||||
|
||||
public class LocalScopeRecord implements ScopeRecord {
|
||||
public final LocalScopeRecord parent;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package me.topchetoeu.jscript.common;
|
||||
|
||||
import me.topchetoeu.jscript.core.scope.LocalScopeRecord;
|
||||
package me.topchetoeu.jscript.compilation.scope;
|
||||
|
||||
public interface ScopeRecord {
|
||||
public Object getKey(String name);
|
||||
@@ -46,7 +46,7 @@ public class InstructionRunner {
|
||||
|
||||
private static Object execMakeVar(Context ctx, Instruction instr, Frame frame) {
|
||||
var name = (String)instr.get(0);
|
||||
ctx.environment.global.define(name);
|
||||
ctx.environment.global.define(ctx, name);
|
||||
frame.codePtr++;
|
||||
return Values.NO_RETURN;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package me.topchetoeu.jscript.core.scope;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import me.topchetoeu.jscript.common.ScopeRecord;
|
||||
import me.topchetoeu.jscript.core.Context;
|
||||
import me.topchetoeu.jscript.core.values.FunctionValue;
|
||||
import me.topchetoeu.jscript.core.values.NativeFunction;
|
||||
@@ -11,31 +10,25 @@ import me.topchetoeu.jscript.core.values.ObjectValue;
|
||||
import me.topchetoeu.jscript.core.values.Values;
|
||||
import me.topchetoeu.jscript.core.exceptions.EngineException;
|
||||
|
||||
public class GlobalScope implements ScopeRecord {
|
||||
public class GlobalScope {
|
||||
public final ObjectValue obj;
|
||||
|
||||
public boolean has(Context ctx, String name) {
|
||||
return Values.hasMember(null, obj, name, false);
|
||||
}
|
||||
public Object getKey(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
public GlobalScope globalChild() {
|
||||
var obj = new ObjectValue();
|
||||
Values.setPrototype(null, obj, this.obj);
|
||||
return new GlobalScope(obj);
|
||||
}
|
||||
public LocalScopeRecord child() {
|
||||
return new LocalScopeRecord();
|
||||
}
|
||||
|
||||
public Object define(String name) {
|
||||
public Object define(Context ctx, String name) {
|
||||
if (Values.hasMember(Context.NULL, obj, name, false)) return name;
|
||||
obj.defineProperty(Context.NULL, name, null);
|
||||
return name;
|
||||
}
|
||||
public void define(String name, Variable val) {
|
||||
public void define(Context ctx, String name, Variable val) {
|
||||
obj.defineProperty(Context.NULL, name,
|
||||
new NativeFunction("get " + name, args -> val.get(args.ctx)),
|
||||
new NativeFunction("set " + name, args -> { val.set(args.ctx, args.get(0)); return null; }),
|
||||
@@ -45,10 +38,10 @@ public class GlobalScope implements ScopeRecord {
|
||||
public void define(Context ctx, String name, boolean readonly, Object val) {
|
||||
obj.defineProperty(ctx, name, val, readonly, true, true);
|
||||
}
|
||||
public void define(String ...names) {
|
||||
for (var n : names) define(n);
|
||||
public void define(Context ctx, String ...names) {
|
||||
for (var n : names) define(ctx, n);
|
||||
}
|
||||
public void define(boolean readonly, FunctionValue val) {
|
||||
public void define(Context ctx, boolean readonly, FunctionValue val) {
|
||||
define(null, val.name, readonly, val);
|
||||
}
|
||||
|
||||
|
||||
@@ -173,27 +173,27 @@ public class Internals {
|
||||
glob.define(null, "Encoding", false, wp.getNamespace(EncodingLib.class));
|
||||
glob.define(null, "Filesystem", false, wp.getNamespace(FilesystemLib.class));
|
||||
|
||||
glob.define(false, wp.getConstr(FileLib.class));
|
||||
glob.define(null, false, wp.getConstr(FileLib.class));
|
||||
|
||||
glob.define(false, wp.getConstr(DateLib.class));
|
||||
glob.define(false, wp.getConstr(ObjectLib.class));
|
||||
glob.define(false, wp.getConstr(FunctionLib.class));
|
||||
glob.define(false, wp.getConstr(ArrayLib.class));
|
||||
glob.define(null, false, wp.getConstr(DateLib.class));
|
||||
glob.define(null, false, wp.getConstr(ObjectLib.class));
|
||||
glob.define(null, false, wp.getConstr(FunctionLib.class));
|
||||
glob.define(null, false, wp.getConstr(ArrayLib.class));
|
||||
|
||||
glob.define(false, wp.getConstr(BooleanLib.class));
|
||||
glob.define(false, wp.getConstr(NumberLib.class));
|
||||
glob.define(false, wp.getConstr(StringLib.class));
|
||||
glob.define(false, wp.getConstr(SymbolLib.class));
|
||||
glob.define(null, false, wp.getConstr(BooleanLib.class));
|
||||
glob.define(null, false, wp.getConstr(NumberLib.class));
|
||||
glob.define(null, false, wp.getConstr(StringLib.class));
|
||||
glob.define(null, false, wp.getConstr(SymbolLib.class));
|
||||
|
||||
glob.define(false, wp.getConstr(PromiseLib.class));
|
||||
glob.define(false, wp.getConstr(RegExpLib.class));
|
||||
glob.define(false, wp.getConstr(MapLib.class));
|
||||
glob.define(false, wp.getConstr(SetLib.class));
|
||||
glob.define(null, false, wp.getConstr(PromiseLib.class));
|
||||
glob.define(null, false, wp.getConstr(RegExpLib.class));
|
||||
glob.define(null, false, wp.getConstr(MapLib.class));
|
||||
glob.define(null, false, wp.getConstr(SetLib.class));
|
||||
|
||||
glob.define(false, wp.getConstr(ErrorLib.class));
|
||||
glob.define(false, wp.getConstr(SyntaxErrorLib.class));
|
||||
glob.define(false, wp.getConstr(TypeErrorLib.class));
|
||||
glob.define(false, wp.getConstr(RangeErrorLib.class));
|
||||
glob.define(null, false, wp.getConstr(ErrorLib.class));
|
||||
glob.define(null, false, wp.getConstr(SyntaxErrorLib.class));
|
||||
glob.define(null, false, wp.getConstr(TypeErrorLib.class));
|
||||
glob.define(null, false, wp.getConstr(RangeErrorLib.class));
|
||||
|
||||
env.add(Environment.OBJECT_PROTO, wp.getProto(ObjectLib.class));
|
||||
env.add(Environment.FUNCTION_PROTO, wp.getProto(FunctionLib.class));
|
||||
|
||||
@@ -87,10 +87,10 @@ public class JScriptRepl {
|
||||
private static void initEnv() {
|
||||
environment = Internals.apply(environment);
|
||||
|
||||
environment.global.define(false, new NativeFunction("exit", args -> {
|
||||
environment.global.define(null, false, new NativeFunction("exit", args -> {
|
||||
throw new InterruptException();
|
||||
}));
|
||||
environment.global.define(false, new NativeFunction("go", args -> {
|
||||
environment.global.define(null, false, new NativeFunction("go", args -> {
|
||||
try {
|
||||
var f = Path.of("do.js");
|
||||
var func = args.ctx.compile(new Filename("do", "do/" + j++ + ".js"), new String(Files.readAllBytes(f)));
|
||||
@@ -100,7 +100,7 @@ public class JScriptRepl {
|
||||
throw new EngineException("Couldn't open do.js");
|
||||
}
|
||||
}));
|
||||
environment.global.define(false, new NativeFunction("log", args -> {
|
||||
environment.global.define(null, false, new NativeFunction("log", args -> {
|
||||
for (var el : args.args) {
|
||||
Values.printValue(args.ctx, el);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user