ES6 Support Groundwork + Fixes (OLD ONE DON'T LOOK AT ME!!!) #22
@ -9,8 +9,6 @@ public class FunctionScope extends Scope {
|
|||||||
private final VariableList specials = new VariableList();
|
private final VariableList specials = new VariableList();
|
||||||
private final VariableList locals = new VariableList(specials);
|
private final VariableList locals = new VariableList(specials);
|
||||||
private HashMap<VariableDescriptor, VariableDescriptor> childToParent = new HashMap<>();
|
private HashMap<VariableDescriptor, VariableDescriptor> childToParent = new HashMap<>();
|
||||||
public final String selfName;
|
|
||||||
public final VariableDescriptor selfVar;
|
|
||||||
|
|
||||||
private void removeCapture(String name) {
|
private void removeCapture(String name) {
|
||||||
var res = captures.remove(name);
|
var res = captures.remove(name);
|
||||||
@ -29,12 +27,19 @@ public class FunctionScope extends Scope {
|
|||||||
else if (parent == null) throw new RuntimeException("Strict variables may be defined only in local scopes");
|
else if (parent == null) throw new RuntimeException("Strict variables may be defined only in local scopes");
|
||||||
else return parent.defineStrict(name, readonly, loc);
|
else return parent.defineStrict(name, readonly, loc);
|
||||||
}
|
}
|
||||||
|
public VariableDescriptor defineArg(String name, Location loc) {
|
||||||
|
return specials.add(name, false);
|
||||||
|
}
|
||||||
|
public boolean hasArg(String name) {
|
||||||
|
return specials.has(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override public VariableDescriptor get(String name, boolean capture) {
|
public VariableDescriptor get(String name, boolean capture, boolean skipSelf) {
|
||||||
if (specials.has(name)) return specials.get(name);
|
if (!skipSelf) {
|
||||||
if (locals.has(name)) return locals.get(name);
|
if (specials.has(name)) return specials.get(name);
|
||||||
if (captures.has(name)) return captures.get(name);
|
if (locals.has(name)) return locals.get(name);
|
||||||
if (selfName != null && selfName.equals(name)) return selfVar;
|
if (captures.has(name)) return captures.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
var parentVar = parent.get(name, true);
|
var parentVar = parent.get(name, true);
|
||||||
if (parentVar == null) return null;
|
if (parentVar == null) return null;
|
||||||
@ -46,6 +51,10 @@ public class FunctionScope extends Scope {
|
|||||||
return childVar;
|
return childVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public VariableDescriptor get(String name, boolean capture) {
|
||||||
|
return get(name, capture, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override public boolean has(String name) {
|
@Override public boolean has(String name) {
|
||||||
if (specials.has(name)) return true;
|
if (specials.has(name)) return true;
|
||||||
if (locals.has(name)) return true;
|
if (locals.has(name)) return true;
|
||||||
@ -89,22 +98,10 @@ public class FunctionScope extends Scope {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FunctionScope(String selfName, String[] args) {
|
public FunctionScope() {
|
||||||
super();
|
super();
|
||||||
this.selfName = selfName;
|
|
||||||
|
|
||||||
if (selfName != null) this.selfVar = VariableDescriptor.of(selfName, true, -1);
|
|
||||||
else this.selfVar = null;
|
|
||||||
|
|
||||||
for (var arg : args) specials.add(arg, false);
|
|
||||||
}
|
}
|
||||||
public FunctionScope(String selfName, String[] args, Scope parent) {
|
public FunctionScope(Scope parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.selfName = selfName;
|
|
||||||
|
|
||||||
if (selfName != null) this.selfVar = VariableDescriptor.of(selfName, true, -1);
|
|
||||||
else this.selfVar = null;
|
|
||||||
|
|
||||||
for (var arg : args) specials.add(arg, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user