diff --git a/src/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java b/src/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java index 3e70aa5..d20a277 100644 --- a/src/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java +++ b/src/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java @@ -27,19 +27,17 @@ public class FunctionScope extends Scope { else if (parent == null) throw new RuntimeException("Strict variables may be defined only in local scopes"); else return parent.defineStrict(name, readonly, loc); } - public VariableDescriptor defineParam(String name, Location loc) { - return specials.add(name, false); + public VariableDescriptor defineParam(String name, boolean readonly, Location loc) { + return specials.add(name, readonly); } public boolean hasArg(String name) { return specials.has(name); } - public VariableDescriptor get(String name, boolean capture, boolean skipSelf) { - if (!skipSelf) { - if (specials.has(name)) return specials.get(name); - if (locals.has(name)) return locals.get(name); - if (captures.has(name)) return captures.get(name); - } + @Override public VariableDescriptor get(String name, boolean capture) { + if (specials.has(name)) return specials.get(name); + if (locals.has(name)) return locals.get(name); + if (captures.has(name)) return captures.get(name); var parentVar = parent.get(name, true); if (parentVar == null) return null; @@ -51,10 +49,6 @@ public class FunctionScope extends Scope { return childVar; } - @Override public VariableDescriptor get(String name, boolean capture) { - return get(name, capture, false); - } - @Override public boolean has(String name) { if (specials.has(name)) return true; if (locals.has(name)) return true; @@ -83,7 +77,7 @@ public class FunctionScope extends Scope { } public int offset() { - return captures.size() + locals.size(); + return specials.size() + locals.size(); } public int[] getCaptureIndices() { @@ -93,6 +87,7 @@ public class FunctionScope extends Scope { for (var el : captures) { assert childToParent.containsKey(el); res[i] = childToParent.get(el).index(); + i++; } return res; diff --git a/src/java/me/topchetoeu/jscript/compilation/scope/LocalScope.java b/src/java/me/topchetoeu/jscript/compilation/scope/LocalScope.java index c348168..71599f7 100644 --- a/src/java/me/topchetoeu/jscript/compilation/scope/LocalScope.java +++ b/src/java/me/topchetoeu/jscript/compilation/scope/LocalScope.java @@ -3,7 +3,10 @@ package me.topchetoeu.jscript.compilation.scope; import me.topchetoeu.jscript.common.parsing.Location; public final class LocalScope extends Scope { - private final VariableList locals = new VariableList(); + private final VariableList locals = new VariableList(() -> { + if (parent != null) return parent.offset(); + else return 0; + }); @Override public int offset() { if (parent != null) return parent.offset() + locals.size(); diff --git a/src/java/me/topchetoeu/jscript/compilation/scope/VariableList.java b/src/java/me/topchetoeu/jscript/compilation/scope/VariableList.java index dc583af..036c313 100644 --- a/src/java/me/topchetoeu/jscript/compilation/scope/VariableList.java +++ b/src/java/me/topchetoeu/jscript/compilation/scope/VariableList.java @@ -38,13 +38,11 @@ public final class VariableList implements Iterable { public ListVar freeze() { if (frozen) return this; this.frozen = true; - + this.next = null; if (prev == null) return this; - assert prev.frozen; this.index = prev.index + 1; this.next = null; - this.prev = null; return this; }