1 ! Copyright (C) 2009 Sam Anklesaria.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs combinators continuations effects
4 io.encodings.binary io.servers.connection kernel namespaces
5 sequences serialize sets threads vocabs vocabs.parser init io ;
9 TUPLE: rpc-request args vocabspec wordname ;
10 SYMBOL: serving-vocabs serving-vocabs [ V{ } clone ] initialize
12 : getter ( -- ) deserialize dup serving-vocabs get-global index
13 [ vocab-words [ stack-effect ] { } assoc-map-as ]
14 [ \ no-vocab boa ] if serialize flush ;
16 : doer ( -- ) deserialize dup vocabspec>> serving-vocabs get-global index
17 [ [ args>> ] [ wordname>> ] [ vocabspec>> vocab-words ] tri at [ execute ] curry with-datastack ]
18 [ vocabspec>> \ no-vocab boa ] if serialize flush ;
21 SYNTAX: service current-vocab name>> serving-vocabs get-global adjoin ;
23 : start-rpc-server ( -- )
24 binary <threaded-server>
25 "rpcs" >>name 9012 >>insecure
27 { "getter" [ getter ] }
29 { "loader" [ deserialize vocab serialize flush ] }