! Copyright (C) 2005 Chris Double, 2007 Clemens Hofreither.
! See http://factorcode.org/license.txt for BSD license.
+USING: kernel hashtables namespaces continuations quotations
+accessors ;
IN: coroutines
-USING: kernel hashtables namespaces continuations quotations ;
SYMBOL: current-coro
[ swapd , , \ bind ,
"Coroutine has terminated illegally." , \ throw ,
] [ ] make
- over set-coroutine-resumecc ;
+ >>resumecc ;
: coresume ( v co -- result )
[
- over set-coroutine-exitcc
- coroutine-resumecc call
+ >>exitcc
+ resumecc>> call
#! At this point, the coroutine quotation must have terminated
#! normally (without calling coyield or coterminate). This shouldn't happen.
f over
current-coro get
[
[ continue-with ] curry
- over set-coroutine-resumecc
- coroutine-exitcc continue-with
+ >>resumecc
+ exitcc>> continue-with
] callcc1 2nip ;
: coyield* ( v -- ) coyield drop ; inline
: coterminate ( v -- )
current-coro get
- [ ] over set-coroutine-resumecc
- coroutine-exitcc continue-with ;
+ [ ] >>resumecc
+ exitcc>> continue-with ;