TopchetoEU/revert-ES5 #31

Merged
TopchetoEU merged 41 commits from TopchetoEU/revert-ES5 into master 2024-12-09 21:39:57 +00:00
3 changed files with 13 additions and 17 deletions
Showing only changes of commit 7f6df49fc5 - Show all commits

View File

@ -5,8 +5,7 @@ import java.util.HashMap;
public final class FunctionScope { public final class FunctionScope {
protected final VariableList locals = new VariableList(VariableIndex.IndexType.LOCALS); protected final VariableList locals = new VariableList(VariableIndex.IndexType.LOCALS);
protected final VariableList catches = new VariableList(VariableIndex.IndexType.LOCALS, this.locals); protected final VariableList capturables = new VariableList(VariableIndex.IndexType.CAPTURABLES, this.locals);
protected final VariableList capturables = new VariableList(VariableIndex.IndexType.CAPTURABLES, this.catches);
private final VariableList captures = new VariableList(VariableIndex.IndexType.CAPTURES); private final VariableList captures = new VariableList(VariableIndex.IndexType.CAPTURES);
private final HashMap<String, Variable> localsMap = new HashMap<>(); private final HashMap<String, Variable> localsMap = new HashMap<>();
@ -38,8 +37,10 @@ public final class FunctionScope {
public Variable define(Variable var) { public Variable define(Variable var) {
if (passthrough) return null; if (passthrough) return null;
else { else {
var old = get(var.name, false); var catchVar = getCatchVar(var.name);
if (old != null) return old; if (catchVar != null) return catchVar;
if (localsMap.containsKey(var.name)) return localsMap.get(var.name);
if (capturesMap.containsKey(var.name)) throw new RuntimeException("HEY!");
localsMap.put(var.name, var); localsMap.put(var.name, var);
return locals.add(var); return locals.add(var);
@ -58,7 +59,7 @@ public final class FunctionScope {
*/ */
public Variable defineCatch(String name) { public Variable defineCatch(String name) {
var var = new Variable(name, false); var var = new Variable(name, false);
this.catches.add(var); this.locals.add(var);
this.catchesMap.add(var); this.catchesMap.add(var);
return var; return var;
} }
@ -87,7 +88,7 @@ public final class FunctionScope {
var parentVar = parent.get(name, true); var parentVar = parent.get(name, true);
if (parentVar == null) return null; if (parentVar == null) return null;
var childVar = captures.add(parentVar.clone()); var childVar = captures.add(parentVar.clone().setIndexSupplier(null));
capturesMap.put(childVar.name, childVar); capturesMap.put(childVar.name, childVar);
childToParent.put(childVar, parentVar); childToParent.put(childVar, parentVar);
parentToChild.put(parentVar, childVar); parentToChild.put(parentVar, childVar);
@ -103,7 +104,6 @@ public final class FunctionScope {
* @param capture Whether or not to execute this capturing logic * @param capture Whether or not to execute this capturing logic
*/ */
public Variable get(Variable var, boolean capture) { public Variable get(Variable var, boolean capture) {
if (catches.has(var)) return addCaptured(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);

View File

@ -45,14 +45,6 @@ public final class VariableIndex {
default: throw new UnsupportedOperationException("Unknown index type " + type); default: throw new UnsupportedOperationException("Unknown index type " + type);
} }
} }
public final Instruction toInit() {
switch (type) {
case CAPTURES: throw new UnsupportedOperationException("Unknown index type " + type);
case CAPTURABLES: return Instruction.storeVar(index, false, true);
case LOCALS: return Instruction.storeVar(index, false, true);
default: throw new UnsupportedOperationException("Unknown index type " + type);
}
}
public VariableIndex(VariableIndex.IndexType type, int index) { public VariableIndex(VariableIndex.IndexType type, int index) {
this.type = type; this.type = type;

View File

@ -13,7 +13,7 @@ public final class VariableList implements Iterable<Variable> {
public VariableNode next; public VariableNode next;
public VariableNode prev; public VariableNode prev;
public int index; public int index;
public int indexIteration; public int indexIteration = -1;
public VariableList list() { return VariableList.this; } public VariableList list() { return VariableList.this; }
@ -120,6 +120,7 @@ public final class VariableList implements Iterable<Variable> {
node.prev = null; node.prev = null;
varMap.remove(node.var); varMap.remove(node.var);
node.var.setIndexSupplier(null);
return node.var; return node.var;
} }
@ -178,7 +179,10 @@ public final class VariableList implements Iterable<Variable> {
*/ */
public VariableList(IndexType type, VariableList prev) { public VariableList(IndexType type, VariableList prev) {
this.indexType = type; this.indexType = type;
this.offset = prev::size; this.offset = () -> {
if (prev.offset != null) return prev.offset.getAsInt() + prev.size();
else return prev.size();
};
} }
public VariableList(IndexType type) { public VariableList(IndexType type) {
this.indexType = type; this.indexType = type;