factor/unmaintained/modules/rpc/rpc.factor

26 lines
945 B
Factor
Raw Normal View History

USING: accessors compiler.units combinators fry generalizations io
2009-05-24 23:10:56 -04:00
io.encodings.binary io.sockets kernel
parser sequences serialize vocabs vocabs.parser words ;
IN: modules.rpc
DEFER: get-words
2009-05-18 18:21:57 -04:00
: with-in-vocab ( vocab quot -- vocab ) over
2009-05-24 23:10:56 -04:00
[ '[ _ set-current-vocab @ ] current-vocab name>> swap dip set-current-vocab ] dip vocab ; inline
2009-05-18 18:21:57 -04:00
: remote-quot ( addrspec vocabspec effect str -- quot )
'[ _ 5000 <inet> binary
[
2009-04-26 19:56:24 -04:00
_ serialize _ in>> length narray serialize _ serialize flush deserialize dup length firstn
] with-client
] ;
: define-remote ( addrspec vocabspec effect str -- ) [
2009-04-26 19:56:24 -04:00
[ remote-quot ] 2keep create-in -rot define-declared word make-inline
] with-compilation-unit ;
: remote-vocab ( addrspec vocabspec -- vocab )
dup "-remote" append [
[ (( -- words )) [ "get-words" remote-quot ] keep call-effect ] 2keep
[ rot first2 swap define-remote ] 2curry each
2009-05-18 18:21:57 -04:00
] with-in-vocab ;