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) { Cell<Callback> shift = reset.shifts;
reset.continuation.handleResult(result); if (shift != null) {
reset.shifts = shift.next;
shift.value.handleResult(result);
} }
return result; return result;
@ -212,42 +214,41 @@ public class Continuations {
return (T) callWithCurrentContinuation(new CallbackReceiver() { return (T) callWithCurrentContinuation(new CallbackReceiver() {
public Object receive(final Callback continuation) { public Object receive(final Callback continuation) {
final Reset reset = latestReset.get(); final Reset reset = latestReset.get();
final Callback resetContinuation = reset.continuation; reset.shifts = new Cell(new Callback() {
reset.continuation = new Callback() {
public void handleResult(Object ignored) { public void handleResult(Object ignored) {
try { try {
resetContinuation.handleResult reset.continuation.handleResult
(receiver.receive (receiver.receive
(new Function() { (new Function() {
public Object call(final Object argument) public Object call(final Object argument)
throws Exception { throws Exception
Object result = callWithCurrentContinuation {
return callWithCurrentContinuation
(new CallbackReceiver() { (new CallbackReceiver() {
public Object receive public Object receive
(Callback shiftContinuation) (Callback shiftContinuation)
throws Exception throws Exception
{ {
reset.continuation = shiftContinuation; reset.shifts = new Cell
(shiftContinuation, reset.shifts);
continuation.handleResult(argument); continuation.handleResult(argument);
throw new AssertionError(); throw new AssertionError();
} }
}); });
reset.continuation = null;
return result;
} }
})); }));
} catch (Exception e) { } catch (Exception e) {
resetContinuation.handleException(e); reset.continuation.handleException(e);
} }
} }
public void handleException(Throwable exception) { public void handleException(Throwable exception) {
throw new AssertionError(); throw new AssertionError();
} }
}; }, reset.shifts);
resetContinuation.handleResult(null); reset.continuation.handleResult(null);
throw new AssertionError(); throw new AssertionError();
} }
}); });
@ -311,9 +312,20 @@ public class Continuations {
private static class Reset { private static class Reset {
public Callback continuation; public Callback continuation;
public final Reset next; public final Reset next;
public Cell<Callback> shifts;
public Reset(Reset next) { public Reset(Reset next) {
this.next = 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"); const char* port = findProperty(t, "avian.trace.port");
if (port) { if (port) {
object host = makeString(t, "0.0.0.0"); object host = makeString(t, "localhost");
PROTECT(t, host); PROTECT(t, host);
object method = resolveMethod object method = resolveMethod

View File

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