8000 Merge remote-tracking branch 'origin/master' · repos-javascript-compilers/wisp@1c1b817 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c1b817

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 57151ef + 666e220 commit 1c1b817

File tree

6 files changed

+51
-50
lines changed

6 files changed

+51
-50
lines changed

Readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ powerful [macros] that make it the easiest way to write JavaScript.
2020

2121
# Try _Wisp_
2222

23-
You can try _wisp_ on your browser by [trying the interactive compiler](http://jeditoolkit.com/try-wisp/) or [an online REPL](http://jeditoolkit.com/interactivate-wisp) with syntax highlighting.
23+
You can try _wisp_ on your browser by [trying the interactive compiler](http://jeditoolkit.com/try-wisp/)
24+
([repo](https://github.com/Gozala/try-wisp)) or [an online REPL](http://jeditoolkit.com/interactivate-wisp)
25+
with syntax highlighting.
2426

2527
# Install
2628

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
},
4949
"dependencies": {
5050
"escodegen": "git://github.com/Constellation/escodegen.git#master",
51-
"base64-encode": "~1.0.1"
51+
"base64-encode": "~1.0.1",
52+
"commander": ">=2.2.0"
5253
}
5354
}

src/analyzer.wisp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@
625625
(install-special! :fn analyze-fn)
626626

627627
(defn parse-references
628-
"Takes part of namespace difinition and creates hash
628+
"Takes part of namespace definition and creates hash
629629
of reference forms"
630630
[forms]
631631
(reduce (fn [references form]
@@ -763,7 +763,7 @@
763763
:context - One of the following :statement, :expression, :return. That
764764
information is included in resulting nodes and is meant for
765765
writer that may output different forms based on context.
766-
:ns - Namespace of the forms being analized.
766+
:ns - Namespace of the forms being analyzed.
767767
768768
Analyzer performs all the macro & syntax expansions and transforms form
769769
into AST node of an expression. Each such node contains at least following

src/compiler.wisp

8000
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
(:require [wisp.analyzer :refer [analyze]]
33
[wisp.reader :refer [read* read push-back-reader]]
44
[wisp.string :refer [replace]]
5-
[wisp.sequence :refer [map conj cons vec first rest empty? count]]
5+
[wisp.sequence :refer [map reduce conj cons vec first rest empty? count]]
66
[wisp.runtime :refer [error?]]
7-
[wisp.ast :refer [name]]
7+
[wisp.ast :refer [pr-str name]]
88

99
[wisp.backend.escodegen.generator :refer [generate]
1010
:rename {generate generate-js}]
@@ -82,9 +82,15 @@
8282
(:ast ast))))
8383
(catch error {:error error})))
8484

85+
expansion (if (identical? :expansion (:print options))
86+
(reduce (fn [result item]
87+
(str result (pr-str (.-form item)) "\n"))
88+
"" (.-ast ast)))
89+
8590
result {:source-uri source-uri
8691
:ast (:ast ast)
87-
:forms (:forms forms)}]
92+
:forms (:forms forms)
93+
:expansion expansion}]
8894
(conj options output result))))
8995

9096
(defn evaluate

src/reader.wisp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291

292292
(defn read-unmatched-delimiter
293293
[rdr ch]
294-
(reader-error rdr "Unmached delimiter " ch))
294+
(reader-error rdr "Unmatched delimiter " ch))
295295

296296
(defn read-list
297297
[reader _]

src/wisp.wisp

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
(:require [fs :refer [createReadStream]]
55
[path :refer [basename dirname join resolve]]
66
[module :refer [Module]]
7+
[commander]
78

89
[wisp.string :refer [split join upper-case replace]]
910
[wisp.sequence :refer [first second last count reduce rest
@@ -15,41 +16,12 @@
1516
[wisp.ast :refer [pr-str name]]
1617
[wisp.compiler :refer [compile]]))
1718

18-
19-
(defn flag?
20-
[param]
< 9E88 /td>
21-
;; HACK: Workaround for segfault #6691
22-
(identical? (subs param 0 2) (name :--)))
23-
24-
(defn flag->key
25-
[flag]
26-
(subs flag 2))
27-
28-
;; Just mungle all the `--param value` pairs into global *env* hash.
29-
(defn parse-params
30-
[params]
31-
(loop [input params
32-
output {}]
33-
(if (empty? input)
34-
output
35-
(let [name (first input)
36-
value (second input)]
37-
(if (flag? name)
38-
(if (or (nil? value) (flag? value))
39-
(recur (rest input)
40-
(assoc output (flag->key name) true))
41-
(recur (drop 2 input)
42-
(assoc output (flag->key name) value)))
43-
(recur (rest input)
44-
output))))))
45-
46-
47-
4819
(defn F438 compile-stdin
4920
[options]
5021
(with-stream-content process.stdin
5122
compile-string
52-
options))
23+
(conj {} options)))
24+
;; (conj {:source-uri options}) causes segfault for some reason
5325

5426
(defn compile-file
5527
[path options]
@@ -61,11 +33,12 @@
6133
[source options]
6234
(let [channel (or (:print options) :code)
6335
output (compile source options)
64-
content (if (= channel :code)
65-
(:code output)
66-
(JSON.stringify (get output channel) 2 2))]
67-
(.write process.stdout (or content "nil"))
68-
(if (:error output) (throw (:error output)))))
36+
content (cond
37+
(= channel :code) (:code output)
38+
(= channel :expansion) (:expansion output)
39+
:else (JSON.stringify (get output channel) 2 2))]
40+
(.write process.stdout (or content "nil"))
41+
(if (:error output) (throw (.-error output)))))
6942

7043
(defn with-stream-content
7144
[input resume options]
@@ -82,12 +55,31 @@
8255
;; https://github.com/joyent/node/blob/master/lib/module.js#L489-493
8356
(Module._load (resolve path) null true))
8457

58+
(defmacro ->
59+
[& operations]
60+
(reduce
61+
(fn [form operation]
62+
(cons (first operation)
63+
(cons form (rest operation))))
64+
(first operations)
65+
(rest operations)))
8566

8667
(defn main
8768
[]
88-
(let [options (parse-params (drop 2 process.argv))]
89-
(cond (not process.stdin.isTTY) (compile-stdin options)
90-
(< (count process.argv) 3) (start-repl)
91-
(and (= (count process.argv) 3)
92-
(not (flag? (last process.argv)))) (run (last process.argv))
93-
(:compile options) (compile-file (:compile options) options))))
69+
(let [options commander]
70+
(-> options
71+
(.usage "[options] <file ...>")
72+
(.option "-r, --run" "Compile and execute the file")
73+
(.option "-c, --compile" "Compile to JavaScript and save as .js files")
74+
(.option "-i, --interactive" "Run an interactive wisp REPL")
75+
(.option "--debug, --print <type>" "Print debug information. Possible values are `expansion`,`forms`, `ast` and `js-ast`")
76+
(.option "--no-map" "Disable source map generation")
77+
(.parse process.argv))
78+
(set! (aget options "no-map") (not (aget options "map"))) ;; commander auto translates to camelCase
79+
(cond options.run (run (get options.args 0))
80+
(not process.stdin.isTTY) (compile-stdin options)
81+
options.interactive (start-repl)
82+
options.compile (compile-file (get options.args 0) options)
83+
options.args (run options.args)
84+
:else (start-repl)
85+
)))

0 commit comments

Comments
 (0)
0