Skip to content

Commit

Permalink
revert pull/45, resume continuation should *NOT* discard handler's stack
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao committed Sep 14, 2024
1 parent c363e1e commit 72ea8e8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 22 deletions.
6 changes: 1 addition & 5 deletions src/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,6 @@ continuationAsClosure(struct Cora *co) {
Obj this = co->args[0];
Obj cont = nativeData(this)[0];

// Discard the stack to the try.
int p = contTryMark(cont);
co->callstack.len = p;

// Replace the current stack with the delimited continuation.
struct callStack* cs = contCallStack(cont);
Obj val = co->args[1];
Expand All @@ -428,7 +424,7 @@ builtinThrow(struct Cora *co) {
assert(try->pos == 1);

// Capture the call stack as continuation.
Obj cont = makeContinuation(p);
Obj cont = makeContinuation();
struct callStack* stack = contCallStack(cont);
for (int i=p; i<co->callstack.len; i++) {
struct returnAddr *addr = &co->callstack.data[i];
Expand Down
7 changes: 0 additions & 7 deletions src/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,6 @@ makeContinuation(int pos) {
return ((Obj)(&cont->head) | TAG_PTR);
}

int
contTryMark(Obj cont) {
struct scmContinuation* v = ptr(cont);
assert(v->head.type == scmHeadContinuation);
return v->pos;
}

struct callStack*
contCallStack(Obj cont) {
struct scmContinuation* v = ptr(cont);
Expand Down
1 change: 0 additions & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ struct callStack {

Obj makeContinuation();
struct callStack* contCallStack(Obj cont);
int contTryMark(Obj cont);

void gcMarkCallStack(struct GC *gc, struct callStack *stack);

Expand Down
2 changes: 1 addition & 1 deletion test/r/discard-handler-stack.result
Original file line number Diff line number Diff line change
@@ -1 +1 @@
708
709
6 changes: 5 additions & 1 deletion test/t/closure-ref.cora
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
667
((lambda (x y)
(try (lambda ()
(+ x (throw 'ignore)))
(lambda (v resume) (resume y))))
666 1)
8 changes: 3 additions & 5 deletions test/t/discard-handler-stack.cora
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
(let fd (throw 'Accept)
(begin
(throw 'Spawn)
(+ fd 42))))
(+ fd 1))))
(lambda (v k)
(match v
'Accept (begin
(k 666)
42)
'Spawn (k ()))))
'Accept (+ (k 666) 42)
'Spawn (k ()))))
2 changes: 1 addition & 1 deletion test/t/recover-multiple-times.cora
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2
(try (lambda () (do (throw 1) (throw 2))) (lambda (v cc) (cc v)))
5 changes: 4 additions & 1 deletion test/t/resume-in-closure-call.cora
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
44
(do (set 'f (lambda (a b) (+ a b)))
(try (lambda ()
(f (throw 42) 1))
(lambda (v resume) (resume (+ v 1)))))

0 comments on commit 72ea8e8

Please sign in to comment.