fix handling of multiple shifts delimited by a single reset

This commit is contained in:
Joel Dice 2013-12-15 16:32:02 -07:00
parent aa3fa1aff4
commit ff57447507
3 changed files with 27 additions and 17 deletions

View File

@ -195,8 +195,10 @@ public class Continuations {
}
});
if (reset.continuation != null) {
reset.continuation.handleResult(result);
Cell<Callback> shift = reset.shifts;
if (shift != null) {
reset.shifts = shift.next;
shift.value.handleResult(result);
}
return result;
@ -212,42 +214,41 @@ public class Continuations {
return (T) callWithCurrentContinuation(new CallbackReceiver() {
public Object receive(final Callback continuation) {
final Reset reset = latestReset.get();
final Callback resetContinuation = reset.continuation;
reset.continuation = new Callback() {
reset.shifts = new Cell(new Callback() {
public void handleResult(Object ignored) {
try {
resetContinuation.handleResult
reset.continuation.handleResult
(receiver.receive
(new Function() {
public Object call(final Object argument)
throws Exception {
Object result = callWithCurrentContinuation
throws Exception
{
return callWithCurrentContinuation
(new CallbackReceiver() {
public Object receive
(Callback shiftContinuation)
throws Exception
{
reset.continuation = shiftContinuation;
reset.shifts = new Cell
(shiftContinuation, reset.shifts);
continuation.handleResult(argument);
throw new AssertionError();
}
});
reset.continuation = null;
return result;
}
}));
} catch (Exception e) {
resetContinuation.handleException(e);
reset.continuation.handleException(e);
}
}
public void handleException(Throwable exception) {
throw new AssertionError();
}
};
}, reset.shifts);
resetContinuation.handleResult(null);
reset.continuation.handleResult(null);
throw new AssertionError();
}
});
@ -311,9 +312,20 @@ public class Continuations {
private static class Reset {
public Callback continuation;
public final Reset next;
public Cell<Callback> shifts;
public Reset(Reset next) {
this.next = next;
}
}
private static class Cell<T> {
public final T value;
public final Cell<T> next;
public Cell(T value, Cell<T> next) {
this.value = value;
this.next = next;
}
}
}

View File

@ -3550,7 +3550,7 @@ boot(Thread* t, uintptr_t*)
const char* port = findProperty(t, "avian.trace.port");
if (port) {
object host = makeString(t, "0.0.0.0");
object host = makeString(t, "localhost");
PROTECT(t, host);
object method = resolveMethod

View File

@ -68,8 +68,6 @@ public class ComposableContinuations {
}
private static <Car> boolean equal(Cell<Car> a, Cell<Car> b) {
System.out.println(a + " vs " + b);
while (a != null) {
if (b == null || (! equal(a.car, b.car))) {
return false;