factor/library/continuations.factor

52 lines
1.3 KiB
Factor
Raw Normal View History

2006-05-02 06:05:58 -04:00
! Copyright (C) 2003, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: kernel-internals
USING: vectors ;
: catchstack* ( -- cs ) 6 getenv { vector } declare ; inline
IN: errors
USING: kernel kernel-internals ;
: catchstack ( -- cs ) catchstack* clone ; inline
2006-05-18 01:08:09 -04:00
: set-catchstack ( cs -- ) >vector 6 setenv ; inline
2005-09-14 00:37:50 -04:00
IN: kernel
USING: namespaces sequences ;
2004-07-16 02:26:21 -04:00
2006-05-14 23:09:47 -04:00
TUPLE: continuation data retain call name catch ;
2005-09-24 23:21:09 -04:00
2005-09-14 00:37:50 -04:00
: continuation ( -- interp )
datastack retainstack callstack dup pop* dup pop* dup pop*
2005-09-18 23:22:58 -04:00
namestack catchstack <continuation> ; inline
2004-07-16 02:26:21 -04:00
2006-05-14 23:09:47 -04:00
: >continuation< ( continuation -- data retain call name catch )
2005-09-18 23:22:58 -04:00
[ continuation-data ] keep
2006-05-14 23:09:47 -04:00
[ continuation-retain ] keep
2005-09-18 23:22:58 -04:00
[ continuation-call ] keep
[ continuation-name ] keep
continuation-catch ; inline
2005-06-15 23:27:28 -04:00
: ifcc ( terminator balance -- | quot: continuation -- )
[
2005-09-22 23:18:12 -04:00
continuation
2005-09-24 23:21:09 -04:00
dup continuation-data f over push f swap push dup
2005-09-24 15:21:17 -04:00
] call 2swap if ; inline
: callcc0 [ drop ] ifcc ; inline
2005-09-14 00:37:50 -04:00
: continue ( continuation -- )
>continuation<
2006-05-14 23:09:47 -04:00
set-catchstack
set-namestack
set-callstack
set-retainstack
set-datastack ;
inline
2005-09-14 00:37:50 -04:00
2005-09-23 01:22:04 -04:00
: (continue-with) 9 getenv ;
: callcc1 [ drop (continue-with) ] ifcc ; inline
2005-09-23 01:22:04 -04:00
: continue-with swap 9 setenv continue ; inline