WIP: improvements to GC
This commit is contained in:
parent
51eb61091d
commit
223c4d7bd1
1 changed files with 18 additions and 1 deletions
19
ISBPL.java
19
ISBPL.java
|
@ -89,9 +89,11 @@ public class ISBPL {
|
||||||
idx++;
|
idx++;
|
||||||
AtomicInteger i = new AtomicInteger(idx);
|
AtomicInteger i = new AtomicInteger(idx);
|
||||||
ISBPLCallable callable = readCallable("if", i, words, file);
|
ISBPLCallable callable = readCallable("if", i, words, file);
|
||||||
|
callable.addUse();
|
||||||
if(stack.pop().isTruthy()) {
|
if(stack.pop().isTruthy()) {
|
||||||
callable.call(stack);
|
callable.call(stack);
|
||||||
}
|
}
|
||||||
|
callable.removeUse();
|
||||||
return i.get();
|
return i.get();
|
||||||
};
|
};
|
||||||
case "while":
|
case "while":
|
||||||
|
@ -101,11 +103,15 @@ public class ISBPL {
|
||||||
ISBPLCallable cond = readCallable("while-condition", i, words, file);
|
ISBPLCallable cond = readCallable("while-condition", i, words, file);
|
||||||
i.getAndIncrement();
|
i.getAndIncrement();
|
||||||
ISBPLCallable block = readCallable("while", i, words, file);
|
ISBPLCallable block = readCallable("while", i, words, file);
|
||||||
|
cond.addUse();
|
||||||
|
block.addUse();
|
||||||
cond.call(stack);
|
cond.call(stack);
|
||||||
while (stack.pop().isTruthy()) {
|
while (stack.pop().isTruthy()) {
|
||||||
block.call(stack);
|
block.call(stack);
|
||||||
cond.call(stack);
|
cond.call(stack);
|
||||||
}
|
}
|
||||||
|
cond.removeUse();
|
||||||
|
block.removeUse();
|
||||||
return i.get();
|
return i.get();
|
||||||
};
|
};
|
||||||
case "stop":
|
case "stop":
|
||||||
|
@ -136,6 +142,8 @@ public class ISBPL {
|
||||||
ISBPLCallable block = readCallable("try", i, words, file);
|
ISBPLCallable block = readCallable("try", i, words, file);
|
||||||
i.getAndIncrement();
|
i.getAndIncrement();
|
||||||
ISBPLCallable catcher = readCallable("catch", i, words, file);
|
ISBPLCallable catcher = readCallable("catch", i, words, file);
|
||||||
|
block.addUse();
|
||||||
|
catcher.addUse();
|
||||||
int stackHeight = stack.size();
|
int stackHeight = stack.size();
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
|
@ -170,6 +178,8 @@ public class ISBPL {
|
||||||
while(stack.size() < stackHeight) {
|
while(stack.size() < stackHeight) {
|
||||||
stack.push(getNullObject());
|
stack.push(getNullObject());
|
||||||
}
|
}
|
||||||
|
block.removeUse();
|
||||||
|
catcher.removeUse();
|
||||||
}
|
}
|
||||||
return i.get();
|
return i.get();
|
||||||
};
|
};
|
||||||
|
@ -180,10 +190,14 @@ public class ISBPL {
|
||||||
ISBPLCallable block = readCallable("do-main", i, words, file);
|
ISBPLCallable block = readCallable("do-main", i, words, file);
|
||||||
i.getAndIncrement();
|
i.getAndIncrement();
|
||||||
ISBPLCallable catcher = readCallable("do-finally", i, words, file);
|
ISBPLCallable catcher = readCallable("do-finally", i, words, file);
|
||||||
|
block.addUse();
|
||||||
|
catcher.addUse();
|
||||||
try {
|
try {
|
||||||
block.call(stack);
|
block.call(stack);
|
||||||
} finally {
|
} finally {
|
||||||
catcher.call(stack);
|
catcher.call(stack);
|
||||||
|
block.removeUse();
|
||||||
|
catcher.removeUse();
|
||||||
}
|
}
|
||||||
return i.get();
|
return i.get();
|
||||||
};
|
};
|
||||||
|
@ -2756,8 +2770,11 @@ class ISBPLFrame implements ISBPLUsable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(String name, ISBPLCallable callable) {
|
public void add(String name, ISBPLCallable callable) {
|
||||||
map.put(name, callable);
|
|
||||||
callable.usedBy(this);
|
callable.usedBy(this);
|
||||||
|
callable = map.put(name, callable);
|
||||||
|
if(callable != null) {
|
||||||
|
callable.unusedBy(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void define(String name, ISBPLObject value) {
|
public void define(String name, ISBPLObject value) {
|
||||||
|
|
Loading…
Reference in a new issue