From eb59431c3fa2fe7f2cf672bed964f71767056454 Mon Sep 17 00:00:00 2001 From: Sam Anklesaria Date: Wed, 29 Jul 2009 15:48:54 -0500 Subject: [PATCH] modules.using rewrite --- .../modules/rpc-server}/authors.txt | 0 .../modules/rpc-server/rpc-server-docs.factor | 5 +++ extra/modules/rpc-server/rpc-server.factor | 34 ++++++++++++++ extra/modules/rpc-server/summary.txt | 1 + .../modules/rpc}/authors.txt | 0 .../modules/rpc/rpc-docs.factor | 0 extra/modules/rpc/rpc.factor | 22 +++++++++ .../modules/rpc/summary.txt | 0 .../rpc => extra/modules/using}/authors.txt | 0 extra/modules/using/summary.txt | 1 + extra/modules/using/using-docs.factor | 13 ++++++ extra/modules/using/using.factor | 27 +++++++++++ .../remote-loading/remote-loading.factor | 4 -- .../modules/remote-loading/summary.txt | 1 - .../modules/rpc-server/rpc-server.factor | 45 ------------------- unmaintained/modules/rpc-server/summary.txt | 1 - unmaintained/modules/rpc/rpc.factor | 26 ----------- unmaintained/modules/uploads/authors.txt | 1 - unmaintained/modules/uploads/summary.txt | 1 - unmaintained/modules/uploads/uploads.factor | 5 --- unmaintained/modules/using/authors.txt | 1 - unmaintained/modules/using/summary.txt | 1 - unmaintained/modules/using/tests/tags.txt | 1 - .../modules/using/tests/test-server.factor | 3 -- unmaintained/modules/using/tests/tests.factor | 4 -- unmaintained/modules/using/using-docs.factor | 15 ------- unmaintained/modules/using/using.factor | 36 --------------- 27 files changed, 103 insertions(+), 145 deletions(-) rename {unmaintained/modules/remote-loading => extra/modules/rpc-server}/authors.txt (100%) create mode 100644 extra/modules/rpc-server/rpc-server-docs.factor create mode 100644 extra/modules/rpc-server/rpc-server.factor create mode 100644 extra/modules/rpc-server/summary.txt rename {unmaintained/modules/rpc-server => extra/modules/rpc}/authors.txt (100%) rename {unmaintained => extra}/modules/rpc/rpc-docs.factor (100%) create mode 100644 extra/modules/rpc/rpc.factor rename {unmaintained => extra}/modules/rpc/summary.txt (100%) rename {unmaintained/modules/rpc => extra/modules/using}/authors.txt (100%) create mode 100644 extra/modules/using/summary.txt create mode 100644 extra/modules/using/using-docs.factor create mode 100644 extra/modules/using/using.factor delete mode 100644 unmaintained/modules/remote-loading/remote-loading.factor delete mode 100644 unmaintained/modules/remote-loading/summary.txt delete mode 100644 unmaintained/modules/rpc-server/rpc-server.factor delete mode 100644 unmaintained/modules/rpc-server/summary.txt delete mode 100644 unmaintained/modules/rpc/rpc.factor delete mode 100644 unmaintained/modules/uploads/authors.txt delete mode 100644 unmaintained/modules/uploads/summary.txt delete mode 100644 unmaintained/modules/uploads/uploads.factor delete mode 100644 unmaintained/modules/using/authors.txt delete mode 100644 unmaintained/modules/using/summary.txt delete mode 100644 unmaintained/modules/using/tests/tags.txt delete mode 100644 unmaintained/modules/using/tests/test-server.factor delete mode 100644 unmaintained/modules/using/tests/tests.factor delete mode 100644 unmaintained/modules/using/using-docs.factor delete mode 100644 unmaintained/modules/using/using.factor diff --git a/unmaintained/modules/remote-loading/authors.txt b/extra/modules/rpc-server/authors.txt similarity index 100% rename from unmaintained/modules/remote-loading/authors.txt rename to extra/modules/rpc-server/authors.txt diff --git a/extra/modules/rpc-server/rpc-server-docs.factor b/extra/modules/rpc-server/rpc-server-docs.factor new file mode 100644 index 0000000000..fc2c2344dd --- /dev/null +++ b/extra/modules/rpc-server/rpc-server-docs.factor @@ -0,0 +1,5 @@ +USING: help.syntax help.markup modules.rpc-server modules.using ; +IN: modules.rpc-server +HELP: service +{ $syntax "IN: my-vocab service" } +{ $description "Allows words defined in the vocabulary to be used as remote procedure calls by " { $link POSTPONE: USING*: } } ; \ No newline at end of file diff --git a/extra/modules/rpc-server/rpc-server.factor b/extra/modules/rpc-server/rpc-server.factor new file mode 100644 index 0000000000..c079f485d4 --- /dev/null +++ b/extra/modules/rpc-server/rpc-server.factor @@ -0,0 +1,34 @@ +USING: accessors assocs concurrency.distributed +concurrency.messaging continuations effects init kernel +namespaces sequences sets threads vocabs vocabs.parser ; +IN: modules.rpc-server +> dup serving-vocabs get-global index + [ vocab-words [ stack-effect ] { } assoc-map-as ] + [ \ no-vocab boa ] if + ] keep reply-synchronous + t ] "get-words" spawn-server "gets-thread" swap register-process ; + +: register-does-thread ( -- ) + [ receive [ data>> dup vocabspec>> serving-vocabs get-global index + [ [ args>> ] [ wordname>> ] [ vocabspec>> vocab-words ] tri at [ execute ] curry with-datastack ] + [ vocabspec>> \ no-vocab boa ] if + ] keep reply-synchronous + t ] "do-word" spawn-server "does-thread" swap register-process ; + +: register-loads-thread ( -- ) + [ [ receive vocab ] keep reply-synchronous t ] "load-words" spawn-server "loads-thread" swap register-process ; + +: add-vocabs-hook ( -- ) + [ 9012 start-node + register-gets-thread + register-does-thread + register-loads-thread + ] "start-serving-vocabs" add-init-hook ; +PRIVATE> +SYNTAX: service add-vocabs-hook + current-vocab name>> serving-vocabs get-global adjoin ; diff --git a/extra/modules/rpc-server/summary.txt b/extra/modules/rpc-server/summary.txt new file mode 100644 index 0000000000..3688644814 --- /dev/null +++ b/extra/modules/rpc-server/summary.txt @@ -0,0 +1 @@ +Serve factor words as rpcs \ No newline at end of file diff --git a/unmaintained/modules/rpc-server/authors.txt b/extra/modules/rpc/authors.txt similarity index 100% rename from unmaintained/modules/rpc-server/authors.txt rename to extra/modules/rpc/authors.txt diff --git a/unmaintained/modules/rpc/rpc-docs.factor b/extra/modules/rpc/rpc-docs.factor similarity index 100% rename from unmaintained/modules/rpc/rpc-docs.factor rename to extra/modules/rpc/rpc-docs.factor diff --git a/extra/modules/rpc/rpc.factor b/extra/modules/rpc/rpc.factor new file mode 100644 index 0000000000..e088ab2844 --- /dev/null +++ b/extra/modules/rpc/rpc.factor @@ -0,0 +1,22 @@ +USING: accessors assocs concurrency.distributed +concurrency.messaging fry generalizations io.sockets kernel +locals namespaces parser sequences vocabs vocabs.parser words ; +IN: modules.rpc + +TUPLE: rpc-request args vocabspec wordname ; + +: send-with-check ( message thread -- reply/* ) send-synchronous dup no-vocab? [ throw ] when ; + +:: define-remote ( str effect addrspec vocabspec -- ) + str create-in effect [ in>> length ] [ out>> length ] bi + '[ _ narray vocabspec str rpc-request boa "does-thread" addrspec 9012 send-with-check _ firstn ] + effect define-declared ; + +:: remote-vocab ( addrspec vocabspec -- vocab ) + vocabspec "-remote" append dup vocab [ dup set-current-vocab + vocabspec "gets-thread" addrspec 9012 send-with-check + [ first2 addrspec vocabspec define-remote ] each + ] unless ; + +: remote-load ( addr vocabspec -- voabspec ) [ swap + "loads-thread" swap 9012 send-synchronous ] keep [ dictionary get-global set-at ] keep ; \ No newline at end of file diff --git a/unmaintained/modules/rpc/summary.txt b/extra/modules/rpc/summary.txt similarity index 100% rename from unmaintained/modules/rpc/summary.txt rename to extra/modules/rpc/summary.txt diff --git a/unmaintained/modules/rpc/authors.txt b/extra/modules/using/authors.txt similarity index 100% rename from unmaintained/modules/rpc/authors.txt rename to extra/modules/using/authors.txt diff --git a/extra/modules/using/summary.txt b/extra/modules/using/summary.txt new file mode 100644 index 0000000000..62fdb05d5b --- /dev/null +++ b/extra/modules/using/summary.txt @@ -0,0 +1 @@ +Improved module import syntax with network transparency \ No newline at end of file diff --git a/extra/modules/using/using-docs.factor b/extra/modules/using/using-docs.factor new file mode 100644 index 0000000000..f03d51bbf7 --- /dev/null +++ b/extra/modules/using/using-docs.factor @@ -0,0 +1,13 @@ +USING: help.syntax help.markup strings modules.using ; +IN: modules +ARTICLE: { "modules.using" "use" } "Using the modules.using vocab" +"This vocabulary defines " { $link POSTPONE: USING*: } " as an alternative to " { $link POSTPONE: USING: } " which makes qualified imports easier. " +"Secondly, it allows loading vocabularies from remote servers, as long as the remote vocabulary can be accessed at compile time. " +"Finally, the word can treat words in remote vocabularies as remote procedure calls. Any inputs are passed to the imported words as normal, and the result will appear on the stack- the only difference is that the word isn't called locally." ; +ABOUT: { "modules.using" "use" } + +IN: syntax +HELP: USING*: +{ $syntax "USING: rpc-server::module fetch-sever:module { module qualified-name } { module => word ... } { qualified-module } { module EXCEPT word ... } { module word => importname } ;" } +{ $description "Adds vocabularies to the search path. Vocabularies can be loaded off a server or called as an rpc if preceded by a valid hostname. Bracketed pairs facilitate all types of qualified imports on both remote and local modules." } +"To use the 'USING*:' without explicitly importing modules.using first, add '\"modules.using\" require' to your .factor-boot-rc" ; \ No newline at end of file diff --git a/extra/modules/using/using.factor b/extra/modules/using/using.factor new file mode 100644 index 0000000000..2e4a097510 --- /dev/null +++ b/extra/modules/using/using.factor @@ -0,0 +1,27 @@ +USING: kernel modules.rpc peg peg-lexer peg.ebnf sequences +strings vocabs.parser ; +IN: modules.using + +EBNF: modulize +tokenpart = (!(':').)+ => [[ >string ]] +s = ':' => [[ drop ignore ]] +rpc = tokenpart s s tokenpart => [[ first2 remote-vocab ]] +remote = tokenpart s tokenpart => [[ first2 remote-load ]] +module = rpc | remote | tokenpart +;EBNF + +IN: syntax +ON-BNF: USING*: +tokenizer = +sym = !(";"|"}"|"=>"|"EXCEPT"). +modspec = sym => [[ modulize ]] +qualified-with = modspec sym => [[ first2 add-qualified ignore ]] +qualified = modspec => [[ dup add-qualified ignore ]] +from = modspec "=>" sym+ => [[ first3 nip add-words-from ignore ]] +exclude = modspec "EXCEPT" sym+ => [[ first3 nip add-words-excluding ignore ]] +rename = modspec sym "=>" sym => [[ first4 nip swapd add-renamed-word ignore ]] +long = "{" ( from | exclude | rename | qualified-with | qualified ) "}" => [[ drop ignore ]] +short = modspec => [[ use-vocab ignore ]] +wordSpec = long | short +using = wordSpec+ ";" => [[ drop ignore ]] +;ON-BNF \ No newline at end of file diff --git a/unmaintained/modules/remote-loading/remote-loading.factor b/unmaintained/modules/remote-loading/remote-loading.factor deleted file mode 100644 index 7a51f2488d..0000000000 --- a/unmaintained/modules/remote-loading/remote-loading.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: modules.rpc-server vocabs ; -IN: modules.remote-loading mem-service - -: get-vocab ( vocabstr -- vocab ) vocab ; \ No newline at end of file diff --git a/unmaintained/modules/remote-loading/summary.txt b/unmaintained/modules/remote-loading/summary.txt deleted file mode 100644 index 304f8550e4..0000000000 --- a/unmaintained/modules/remote-loading/summary.txt +++ /dev/null @@ -1 +0,0 @@ -required for listeners allowing remote loading of modules \ No newline at end of file diff --git a/unmaintained/modules/rpc-server/rpc-server.factor b/unmaintained/modules/rpc-server/rpc-server.factor deleted file mode 100644 index 0c881adef6..0000000000 --- a/unmaintained/modules/rpc-server/rpc-server.factor +++ /dev/null @@ -1,45 +0,0 @@ -USING: accessors assocs continuations effects io -io.encodings.binary io.servers.connection kernel -memoize namespaces parser sets sequences serialize -threads vocabs vocabs.parser words ; -IN: modules.rpc-server - -SYMBOL: serving-vocabs V{ } clone serving-vocabs set-global - -: do-rpc ( args word -- bytes ) - [ execute ] curry with-datastack object>bytes ; inline - -MEMO: mem-do-rpc ( args word -- bytes ) do-rpc ; inline - -: process ( vocabspec -- ) - vocab-words [ deserialize ] dip deserialize - swap at "executer" get execute( args word -- bytes ) write flush ; - -: (serve) ( -- ) - deserialize dup serving-vocabs get-global index - [ process ] [ drop ] if ; - -: start-serving-vocabs ( -- ) - [ - binary - 5000 >>insecure - [ (serve) ] >>handler - start-server - ] in-thread ; - -: (service) ( -- ) - serving-vocabs get-global empty? [ start-serving-vocabs ] when - current-vocab serving-vocabs get-global adjoin - "get-words" create-in - in get [ vocab vocab-words [ stack-effect ] { } assoc-map-as ] curry - (( -- words )) define-inline ; - -SYNTAX: service \ do-rpc "executer" set (service) ; -SYNTAX: mem-service \ mem-do-rpc "executer" set (service) ; - -load-vocab-hook [ - [ - dup words>> values - \ mem-do-rpc "memoize" word-prop [ delete-at ] curry each - ] append -] change-global diff --git a/unmaintained/modules/rpc-server/summary.txt b/unmaintained/modules/rpc-server/summary.txt deleted file mode 100644 index 396a1c8686..0000000000 --- a/unmaintained/modules/rpc-server/summary.txt +++ /dev/null @@ -1 +0,0 @@ -remote procedure call server \ No newline at end of file diff --git a/unmaintained/modules/rpc/rpc.factor b/unmaintained/modules/rpc/rpc.factor deleted file mode 100644 index fe65c9cb37..0000000000 --- a/unmaintained/modules/rpc/rpc.factor +++ /dev/null @@ -1,26 +0,0 @@ -USING: accessors compiler.units combinators fry generalizations io -io.encodings.binary io.sockets kernel -parser sequences serialize vocabs vocabs.parser words ; -IN: modules.rpc - -DEFER: get-words - -: with-in-vocab ( vocab quot -- vocab ) over - [ '[ _ set-current-vocab @ ] current-vocab name>> swap dip set-current-vocab ] dip vocab ; inline - -: remote-quot ( addrspec vocabspec effect str -- quot ) - '[ _ 5000 binary - [ - _ serialize _ in>> length narray serialize _ serialize flush deserialize dup length firstn - ] with-client - ] ; - -: define-remote ( addrspec vocabspec effect str -- ) [ - [ 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 - ] with-in-vocab ; \ No newline at end of file diff --git a/unmaintained/modules/uploads/authors.txt b/unmaintained/modules/uploads/authors.txt deleted file mode 100644 index 2300f69f11..0000000000 --- a/unmaintained/modules/uploads/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Sam Anklesaria diff --git a/unmaintained/modules/uploads/summary.txt b/unmaintained/modules/uploads/summary.txt deleted file mode 100644 index 1ba8ffe0f8..0000000000 --- a/unmaintained/modules/uploads/summary.txt +++ /dev/null @@ -1 +0,0 @@ -module pushing in remote-loading listeners \ No newline at end of file diff --git a/unmaintained/modules/uploads/uploads.factor b/unmaintained/modules/uploads/uploads.factor deleted file mode 100644 index 137a2c91d5..0000000000 --- a/unmaintained/modules/uploads/uploads.factor +++ /dev/null @@ -1,5 +0,0 @@ -USING: assocs modules.rpc-server vocabs -modules.remote-loading words ; -IN: modules.uploads service - -: upload-vocab ( word binary -- ) \ get-vocab "memoize" word-prop set-at ; \ No newline at end of file diff --git a/unmaintained/modules/using/authors.txt b/unmaintained/modules/using/authors.txt deleted file mode 100644 index 2300f69f11..0000000000 --- a/unmaintained/modules/using/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Sam Anklesaria diff --git a/unmaintained/modules/using/summary.txt b/unmaintained/modules/using/summary.txt deleted file mode 100644 index 6bafda776a..0000000000 --- a/unmaintained/modules/using/summary.txt +++ /dev/null @@ -1 +0,0 @@ -improved module import syntax \ No newline at end of file diff --git a/unmaintained/modules/using/tests/tags.txt b/unmaintained/modules/using/tests/tags.txt deleted file mode 100644 index 6bf68304bb..0000000000 --- a/unmaintained/modules/using/tests/tags.txt +++ /dev/null @@ -1 +0,0 @@ -unportable diff --git a/unmaintained/modules/using/tests/test-server.factor b/unmaintained/modules/using/tests/test-server.factor deleted file mode 100644 index 3e6b736ae1..0000000000 --- a/unmaintained/modules/using/tests/test-server.factor +++ /dev/null @@ -1,3 +0,0 @@ -USING: modules.rpc-server io.servers.connection ; -IN: modules.test-server service -: rpc-hello ( -- str ) "hello world" stop-this-server ; \ No newline at end of file diff --git a/unmaintained/modules/using/tests/tests.factor b/unmaintained/modules/using/tests/tests.factor deleted file mode 100644 index a0adca2646..0000000000 --- a/unmaintained/modules/using/tests/tests.factor +++ /dev/null @@ -1,4 +0,0 @@ -QUALIFIED-WITH: modules.using m -IN: modules.using.tests -m:USING: tools.test localhost::modules.test-server ; -[ "hello world" ] [ rpc-hello ] unit-test \ No newline at end of file diff --git a/unmaintained/modules/using/using-docs.factor b/unmaintained/modules/using/using-docs.factor deleted file mode 100644 index 15f99964d8..0000000000 --- a/unmaintained/modules/using/using-docs.factor +++ /dev/null @@ -1,15 +0,0 @@ -USING: modules.rpc-server help.syntax help.markup strings ; -QUALIFIED-WITH: modules.using m -IN: modules - -HELP: service -{ $syntax "IN: module service" } -{ $description "Starts a server for requests for remote procedure calls." } ; - -ARTICLE: { "modules" "remote-loading" } "Using the remote-loading vocabulary" -"If loaded, starts serving vocabularies, accessable through a " { $link POSTPONE: m:USING: } " form" ; - -HELP: USING: -{ $syntax "USING: rpc-server::module fetch-sever::module { module qualified-name } { module => word ... } ... ;" } -{ $description "Adds vocabularies to the front of the search path. Vocabularies can be fetched remotely, if preceded by a valid hostname. Name pairs facilitate imports like in the " -{ $link POSTPONE: QUALIFIED: } " or " { $link POSTPONE: FROM: } " forms." } ; \ No newline at end of file diff --git a/unmaintained/modules/using/using.factor b/unmaintained/modules/using/using.factor deleted file mode 100644 index 57bf3c67cd..0000000000 --- a/unmaintained/modules/using/using.factor +++ /dev/null @@ -1,36 +0,0 @@ -USING: accessors assocs kernel modules.remote-loading modules.rpc -namespaces peg peg.ebnf peg-lexer sequences vocabs vocabs.parser -strings ; -IN: modules.using - -: >qualified ( vocab prefix -- assoc ) - [ vocab-words ] [ 58 suffix ] bi* [ swap [ prepend ] dip ] curry assoc-map ; - -: >partial-vocab ( words assoc -- assoc ) - [ dupd at [ no-word-error ] unless* ] curry { } map>assoc ; - -: remote-load ( addr vocabspec -- voab ) [ "modules.remote-loading" remote-vocab use-vocab ] dip get-vocab ; - -: load'em ( vocab words/? -- ) [ swap >partial-vocab ] when* manifest get qualified-vocabs>> push ; - -EBNF: modulize -tokenpart = (!(':').)+ => [[ >string ]] -s = ':' => [[ drop ignore ]] -rpc = tokenpart s s tokenpart => [[ first2 remote-vocab ]] -remote = tokenpart s tokenpart => [[ first2 remote-load ]] -plain = tokenpart => [[ load-vocab ]] -module = rpc | remote | plain -;EBNF - -ON-BNF: USING: -tokenizer = -sym = !(";"|"}"|"=>"). -modspec = sym => [[ modulize ]] -qualified = modspec sym => [[ first2 >qualified ]] -unqualified = modspec => [[ vocab-words ]] -words = ("=>" sym+ )? => [[ [ f ] [ second ] if-empty ]] -long = "{" ( qualified | unqualified ) words "}" => [[ rest first2 load'em ignore ]] -short = modspec => [[ use-vocab ignore ]] -wordSpec = long | short -using = wordSpec+ ";" => [[ drop ignore ]] -;ON-BNF \ No newline at end of file