TopchetoEU/revert-ES5 #31

Merged
TopchetoEU merged 41 commits from TopchetoEU/revert-ES5 into master 2024-12-09 21:39:57 +00:00
2 changed files with 5 additions and 1 deletions
Showing only changes of commit 797452c28f - Show all commits

View File

@ -14,6 +14,7 @@ public class FunctionScope extends Scope {
private final HashSet<String> blacklistNames = new HashSet<>(); private final HashSet<String> blacklistNames = new HashSet<>();
private final HashMap<Variable, Variable> childToParent = new HashMap<>(); private final HashMap<Variable, Variable> childToParent = new HashMap<>();
private final HashMap<Variable, Variable> parentToChild = new HashMap<>();
private final Scope captureParent; private final Scope captureParent;
@ -63,11 +64,13 @@ public class FunctionScope extends Scope {
var childVar = captures.add(parentVar.clone()); var childVar = captures.add(parentVar.clone());
capturesMap.put(childVar.name, childVar); capturesMap.put(childVar.name, childVar);
childToParent.put(childVar, parentVar); childToParent.put(childVar, parentVar);
parentToChild.put(parentVar, childVar);
return childVar; return childVar;
} }
@Override public Variable get(Variable var, boolean capture) { @Override public Variable get(Variable var, boolean capture) {
if (parentToChild.containsKey(var)) return addCaptured(parentToChild.get(var), capture);
if (captures.has(var)) return addCaptured(var, capture); if (captures.has(var)) return addCaptured(var, capture);
if (locals.has(var)) return addCaptured(var, capture); if (locals.has(var)) return addCaptured(var, capture);
@ -78,6 +81,7 @@ public class FunctionScope extends Scope {
var childVar = captures.add(parentVar.clone()); var childVar = captures.add(parentVar.clone());
childToParent.put(childVar, parentVar); childToParent.put(childVar, parentVar);
parentToChild.put(parentVar, childVar);
return childVar; return childVar;
} }

View File

@ -29,7 +29,7 @@ public class Scope {
protected void transferCaptured(Variable var) { protected void transferCaptured(Variable var) {
if (!singleEntry) { if (!singleEntry) {
this.capturables.add(var); if (!this.capturables.has(var)) this.capturables.add(var);
} }
else if (parent != null) { else if (parent != null) {
parent.transferCaptured(var); parent.transferCaptured(var);