diff --git a/src/java/me/topchetoeu/jscript/common/mapping/FunctionMap.java b/src/java/me/topchetoeu/jscript/common/mapping/FunctionMap.java index 768f88f..cfcc875 100644 --- a/src/java/me/topchetoeu/jscript/common/mapping/FunctionMap.java +++ b/src/java/me/topchetoeu/jscript/common/mapping/FunctionMap.java @@ -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 { diff --git a/src/java/me/topchetoeu/jscript/compilation/CompileResult.java b/src/java/me/topchetoeu/jscript/compilation/CompileResult.java index 2fd5098..00f6db7 100644 --- a/src/java/me/topchetoeu/jscript/compilation/CompileResult.java +++ b/src/java/me/topchetoeu/jscript/compilation/CompileResult.java @@ -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 instructions = new Vector<>(); diff --git a/src/java/me/topchetoeu/jscript/compilation/parsing/Parsing.java b/src/java/me/topchetoeu/jscript/compilation/parsing/Parsing.java index 1a4db0f..8f1de9b 100644 --- a/src/java/me/topchetoeu/jscript/compilation/parsing/Parsing.java +++ b/src/java/me/topchetoeu/jscript/compilation/parsing/Parsing.java @@ -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 diff --git a/src/java/me/topchetoeu/jscript/core/scope/LocalScopeRecord.java b/src/java/me/topchetoeu/jscript/compilation/scope/LocalScopeRecord.java similarity index 95% rename from src/java/me/topchetoeu/jscript/core/scope/LocalScopeRecord.java rename to src/java/me/topchetoeu/jscript/compilation/scope/LocalScopeRecord.java index 174686b..070168d 100644 --- a/src/java/me/topchetoeu/jscript/core/scope/LocalScopeRecord.java +++ b/src/java/me/topchetoeu/jscript/compilation/scope/LocalScopeRecord.java @@ -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; diff --git a/src/java/me/topchetoeu/jscript/common/ScopeRecord.java b/src/java/me/topchetoeu/jscript/compilation/scope/ScopeRecord.java similarity index 60% rename from src/java/me/topchetoeu/jscript/common/ScopeRecord.java rename to src/java/me/topchetoeu/jscript/compilation/scope/ScopeRecord.java index e2cfcfc..fe08968 100644 --- a/src/java/me/topchetoeu/jscript/common/ScopeRecord.java +++ b/src/java/me/topchetoeu/jscript/compilation/scope/ScopeRecord.java @@ -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); diff --git a/src/java/me/topchetoeu/jscript/core/InstructionRunner.java b/src/java/me/topchetoeu/jscript/core/InstructionRunner.java index 78f42c1..9017585 100644 --- a/src/java/me/topchetoeu/jscript/core/InstructionRunner.java +++ b/src/java/me/topchetoeu/jscript/core/InstructionRunner.java @@ -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; } diff --git a/src/java/me/topchetoeu/jscript/core/scope/GlobalScope.java b/src/java/me/topchetoeu/jscript/core/scope/GlobalScope.java index 200296a..8667ecc 100644 --- a/src/java/me/topchetoeu/jscript/core/scope/GlobalScope.java +++ b/src/java/me/topchetoeu/jscript/core/scope/GlobalScope.java @@ -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); } diff --git a/src/java/me/topchetoeu/jscript/lib/Internals.java b/src/java/me/topchetoeu/jscript/lib/Internals.java index 2fbe078..b648681 100644 --- a/src/java/me/topchetoeu/jscript/lib/Internals.java +++ b/src/java/me/topchetoeu/jscript/lib/Internals.java @@ -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));