From b9b5c6e92774b657e00987bcad839c6be4dd99e1 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sat, 22 Sep 2012 12:57:46 -0700 Subject: [PATCH] coroutines: 4-space style. --- extra/coroutines/coroutines.factor | 53 +++++++++++++++--------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/extra/coroutines/coroutines.factor b/extra/coroutines/coroutines.factor index 135e6c9b46..ea57460f2f 100644 --- a/extra/coroutines/coroutines.factor +++ b/extra/coroutines/coroutines.factor @@ -9,43 +9,44 @@ SYMBOL: current-coro TUPLE: coroutine resumecc exitcc originalcc ; : cocreate ( quot -- co ) - coroutine new - dup current-coro associate - [ swapd , , \ with-variables , - "Coroutine has terminated illegally." , \ throw , - ] [ ] make - [ >>resumecc ] [ >>originalcc ] bi ; + coroutine new + dup current-coro associate + [ + swapd , , \ with-variables , + "Coroutine has terminated illegally." , \ throw , + ] [ ] make + [ >>resumecc ] [ >>originalcc ] bi ; : coresume ( v co -- result ) - [ - >>exitcc - resumecc>> call( -- ) - #! At this point, the coroutine quotation must have terminated - #! normally (without calling coyield, coreset, or coterminate). - #! This shouldn't happen. - f over - ] callcc1 2nip ; + [ + >>exitcc + resumecc>> call( -- ) + #! At this point, the coroutine quotation must have terminated + #! normally (without calling coyield, coreset, or coterminate). + #! This shouldn't happen. + f over + ] callcc1 2nip ; : coresume* ( v co -- ) coresume drop ; inline : *coresume ( co -- result ) f swap coresume ; inline : coyield ( v -- result ) - current-coro get - [ - [ continue-with ] curry - >>resumecc - exitcc>> continue-with - ] callcc1 2nip ; + current-coro get + [ + [ continue-with ] curry + >>resumecc + exitcc>> continue-with + ] callcc1 2nip ; : coyield* ( v -- ) coyield drop ; inline : *coyield ( -- v ) f coyield ; inline : coterminate ( v -- ) - current-coro get - [ ] >>resumecc - exitcc>> continue-with ; + current-coro get + [ ] >>resumecc + exitcc>> continue-with ; : coreset ( v -- ) - current-coro get dup - originalcc>> >>resumecc - exitcc>> continue-with ; + current-coro get dup + originalcc>> >>resumecc + exitcc>> continue-with ;