fix multi-shot callcc1 problem

cvs
Slava Pestov 2005-07-25 00:17:51 +00:00
parent cae545f930
commit 678e18859b
5 changed files with 21 additions and 16 deletions

View File

@ -1,8 +1,8 @@
! Simple IRC bot written in Factor.
IN: factorbot
USING: hashtables http io kernel math namespaces prettyprint
sequences strings words ;
USING: generic hashtables http io kernel math namespaces
prettyprint sequences strings words ;
SYMBOL: irc-stream
SYMBOL: nickname
@ -33,7 +33,7 @@ GENERIC: handle-irc
PREDICATE: string privmsg " " split1 nip "PRIVMSG" head? ;
PREDICATE: string ping "PING" head? ;
M: string handle-irc ( line -- )
M: object handle-irc ( line -- )
drop ;
: parse-privmsg ( line -- text )

View File

@ -1,6 +1,6 @@
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: kernel USING: errors lists namespaces sequences ;
IN: kernel USING: errors lists namespaces sequences words ;
TUPLE: interp data call name catch ;
@ -8,24 +8,24 @@ TUPLE: interp data call name catch ;
datastack callstack >pop> >pop>
namestack catchstack <interp> ;
: continuation ( interp -- )
interp dup interp-call >pop> >pop> drop
dup interp-data >pop> drop ;
: >interp< ( interp -- data call name catch )
[ interp-data ] keep
[ interp-call ] keep
[ interp-name ] keep
interp-catch ;
: set-interp ( interp -- )
>interp< set-catchstack set-namestack
>r set-datastack r> set-callstack ;
: continuation ( interp -- )
interp dup interp-call >pop> >pop> drop
dup interp-data >pop> drop ;
: set-interp ( interp quot -- )
>r >interp< set-catchstack set-namestack
>r set-datastack r> r> swap set-callstack call ;
: callcc0 ( quot ++ | quot: cont -- | cont: ++ )
continuation
[ set-interp ] cons swap call ;
[ [ ] set-interp ] cons swap call ;
: callcc1 ( quot ++ obj | quot: cont -- | cont: obj ++ obj )
continuation
[ [ interp-data push ] keep set-interp ] cons swap call ;
[ swap literalize set-interp ] cons swap call ;

View File

@ -29,7 +29,7 @@ vectors ;
>r over >r v>= r> r> v<= vand ;
: sum ( v -- n ) 0 [ + ] reduce ;
: product 1 [ * ] reduce ;
: product ( v -- n ) 1 [ * ] reduce ;
: conj ( v -- ? ) [ ] all? ;
: disj ( v -- ? ) [ ] contains? ;

View File

@ -27,3 +27,8 @@ USE: test
[ t ] [ 10 callcc1-test 10 count = ] unit-test
[ t ] [ callcc-namespace-test ] unit-test
: multishot-test ( -- stack )
[ dup "cc" set 5 swap call ] callcc1 "cc" get car interp-data ;
[ 5 { } ] [ multishot-test ] unit-test

View File

@ -56,8 +56,8 @@ SYMBOL: meta-executing
[
\ call push-r interp [
interp over interp-data push
set-interp
] cons cons push-r meta-interp set-interp
[ ] set-interp
] cons cons push-r meta-interp [ ] set-interp
] call set-meta-interp pop-d 2drop ;
: meta-call ( quot -- )