]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/modules/rpc/rpc.factor
Merge branch 'redis' of git://www.tiodante.com/git/factor
[factor.git] / unmaintained / modules / rpc / rpc.factor
1 USING: accessors compiler.units combinators fry generalizations io
2 io.encodings.binary io.sockets kernel namespaces
3 parser sequences serialize vocabs vocabs.parser words ;
4 IN: modules.rpc
5
6 DEFER: get-words
7
8 : remote-quot ( addrspec vocabspec effect str -- quot )
9    '[ _ 5000 <inet> binary
10       [
11          _ serialize _ in>> length narray serialize _ serialize flush deserialize dup length firstn
12       ] with-client
13     ] ;
14
15 : define-remote ( addrspec vocabspec effect str -- ) [
16       [ remote-quot ] 2keep create-in -rot define-declared word make-inline
17    ] with-compilation-unit ;
18
19 : with-in ( vocab quot -- vocab ) over
20    [ '[ _ set-in @ ] in get swap dip set-in ] dip vocab ; inline
21
22 : remote-vocab ( addrspec vocabspec -- vocab )
23    dup "-remote" append [ 
24       [ (( -- words )) [ "get-words" remote-quot ] keep call-effect ] 2keep
25       [ rot first2 swap define-remote ] 2curry each
26    ] with-in ;