depth 2- 2/ fixnum-type 2swap cons
;
-: make-continuation
+: make-continuation ( -- continuation true-obj )
+ \ true-obj allows calling code to detect whether
+ \ it is being called immediately following make-continuation
+ \ or by a restore-continuation.
cons-param-stack
cons-return-stack
cons drop continuation-type
+
+ true boolean-type
;
: continuation->pstack-list
2drop
;
+( This word restores the return stack to that contained in the
+continuation object, and thus NEVER RETURNS. )
: restore-return-stack ( continuation -- )
continuation->rstack-list
2drop
;
+( This word restores the parameter and return stacks
+to those in the continuation object. The restoration of the
+return stack means that execution continues at the point
+described in the continuation object, so this word NEVER RETURNS.
+
+Note that both obj and a false-obj are added to the parameter
+stack before the return stack is restored, so that make-continuation
+knows that this execution path is the result of a continuation
+restoration rather than the original call to make-continuation. )
: restore-continuation-with-arg ( continuation obj -- )
>R >R \ Store obj on return stack
2swap
+ false boolean-type \ Add flag signifying continuation restore
+
+ 2swap
+
restore-return-stack
;
2dup cdr
- nil? not if
+ nil? invert if
except-message: ." Continuations expect exactly 1 argument."
recoverable-exception throw
then
symbol-type istype? if true exit then
compound-proc-type istype? if true exit then
port-type istype? if true exit then
+ continuation-type istype? if true exit then
false
;