Permalink
Please sign in to comment.
Browse files
Support code reflection in the cljs repl.
A few changes have been made to support runtime code reflection in a cljs repl. These include small changes to cljs.analyzer, a separation of the server element of cljs.repl.browser into cljs.repl.server, and the addition of two new namespaces: cljs.repl.reflect (in src/clj) and clojure.reflect (in src/cljs). cljs.analyzer: - Arbitrary metadata declared on symbols will now be added to the AST. This supports the addition of docstrings. - Fix a subtle bug in cljs.analyzer/analyze-file, where an uncommon code-path would lead to the failed coercion of an absolute-path into a URL. An absolute path, including a `file://` protocol, can now be passed into the function successfully. cljs.repl: - Add function to analyze source on repl-env -setup. This is used to support reflection on user-defined cljs source files, as well as to populate the cljs.analyzer/namespaces atom on repl startup. cljs.repl.browser: - The server element of this namespace has been factored out into cljs.repl.server to support other services that may require that functionality. cljs.repl.server: - Expose a simple HTTP method and predicate dispatch system to register handler functions for incoming requests. (Note: this system seems to be relatively brittle, and future change may be warranted.) cljs.repl.reflect: - Registers a server handler for incoming requests to "/reflect". - Queries cljs.analyzer/namespaces for meta information relevant to a symbol, responding to requests with compiled javascript. - Can use "fixed point" macroexpansion on cljs macro forms. clojure.reflect: - Expose a set of simple functions for querying meta information of a symbol, as well as macroexpanding a cljs form.
- Loading branch information...
Showing
with
377 additions
and 196 deletions.
- +1 −0 .gitignore
- +2 −1 samples/repl/src/repl/test.cljs
- +16 −0 script/browser-repl
- +6 −5 src/clj/cljs/analyzer.clj
- +13 −3 src/clj/cljs/repl.clj
- +47 −187 src/clj/cljs/repl/browser.clj
- +74 −0 src/clj/cljs/repl/reflect.clj
- +173 −0 src/clj/cljs/repl/server.clj
- +45 −0 src/cljs/clojure/reflect.cljs
| @@ -0,0 +1,16 @@ | |||
| #!/bin/sh | |||
|
|
|||
| if [ "$CLOJURESCRIPT_HOME" = "" ]; then | |||
| CLOJURESCRIPT_HOME="`dirname $0`/.." | |||
| fi | |||
|
|
|||
| CLJSC_CP='' | |||
| for next in lib/*: src/clj: src/cljs: test/cljs; do | |||
| CLJSC_CP=$CLJSC_CP$CLOJURESCRIPT_HOME'/'$next | |||
| done | |||
|
|
|||
| java -server -cp $CLJSC_CP clojure.main -e " | |||
| (require '[cljs.repl :as r]) | |||
| (require '[cljs.repl.browser :as b]) | |||
| (r/repl (b/repl-env)) | |||
| " | |||
Oops, something went wrong.
0 comments on commit
b5b20fd