]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/modules/rpc/rpc.factor
Merge branch 'master' of git://factorcode.org/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
3 parser sequences serialize vocabs vocabs.parser words ;
4 IN: modules.rpc
5
6 DEFER: get-words
7
8 : with-in-vocab ( vocab quot -- vocab ) over
9   [ '[ _ set-current-vocab @ ] current-vocab name>> swap dip set-current-vocab ] dip vocab ; inline
10
11 : remote-quot ( addrspec vocabspec effect str -- quot )
12    '[ _ 5000 <inet> binary
13       [
14          _ serialize _ in>> length narray serialize _ serialize flush deserialize dup length firstn
15       ] with-client
16     ] ;
17
18 : define-remote ( addrspec vocabspec effect str -- ) [
19       [ remote-quot ] 2keep create-in -rot define-declared word make-inline
20    ] with-compilation-unit ;
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-vocab ;