2005-01-29 14:18:28 -05:00
|
|
|
! Copyright (C) 2003, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-04-06 21:41:49 -04:00
|
|
|
IN: kernel USING: errors lists namespaces sequences ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-08-23 01:13:09 -04:00
|
|
|
: reify ( quot -- )
|
|
|
|
>r datastack >pop> callstack >pop> namestack catchstack
|
|
|
|
r> call ;
|
|
|
|
|
2004-07-18 18:12:32 -04:00
|
|
|
: (callcc) cons cons cons cons swap call ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-07-18 18:12:32 -04:00
|
|
|
: continue0 ( ds rs ns cs -- )
|
|
|
|
set-catchstack set-namestack
|
|
|
|
>r set-datastack r> set-callstack ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-07-18 18:12:32 -04:00
|
|
|
: callcc0 ( code -- )
|
2004-07-16 02:26:21 -04:00
|
|
|
#! Calls the code with a special quotation at the top of the
|
|
|
|
#! stack. The quotation has stack effect:
|
|
|
|
#!
|
|
|
|
#! ( -- ... )
|
|
|
|
#!
|
|
|
|
#! When called, the quotation restores execution state to
|
|
|
|
#! the point after the callcc0 call.
|
2004-08-23 01:13:09 -04:00
|
|
|
[ [ continue0 ] (callcc) ] reify ;
|
2004-07-18 18:12:32 -04:00
|
|
|
|
|
|
|
: continue1 ( obj ds rs ns cs -- obj )
|
|
|
|
set-catchstack set-namestack
|
|
|
|
rot >r >r set-datastack r> r> swap set-callstack ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-07-18 18:12:32 -04:00
|
|
|
: callcc1 ( code -- )
|
2004-07-16 02:26:21 -04:00
|
|
|
#! Calls the code with a special quotation at the top of the
|
|
|
|
#! stack. The quotation has stack effect:
|
|
|
|
#!
|
|
|
|
#! ( X -- ... )
|
|
|
|
#!
|
|
|
|
#! When called, the quotation restores execution state to
|
|
|
|
#! the point after the callcc1 call, and places X at the top
|
|
|
|
#! of the original datastack.
|
2004-08-23 01:13:09 -04:00
|
|
|
[ [ continue1 ] (callcc) ] reify ;
|