50
50
(.waitFor (.exec (Runtime/getRuntime ) (str " mkfifo " pipe-path)))
51
51
(File. pipe-path)))
52
52
53
- (defn -main [args]
54
- (ana/with-core-macros " /cljs/lua/core"
55
- (println " Cljs/Lua repl" )
56
- (binding [ana/*cljs-ns* 'cljs.user
57
- ana/*cljs-static-fns* true
58
- *repl-verbose* false
59
- *repl-exec* true
60
- *lua-interp* (conf/get :repl :lua-runtime )]
61
- (let [; ; Lua subprocess
62
- pb (ProcessBuilder. [*lua-interp* " cljs/exec_server.lua" ])
63
- lua-process (.start pb)
64
-
65
- ; ; Read lua stdout
66
- rdr (io/reader (.getInputStream lua-process))
53
+ (defn -main [& args]
54
+ (println " Cljs/Lua repl" )
55
+ (binding [ana/*cljs-ns* 'cljs.user
56
+ ana/*cljs-static-fns* true
57
+ *repl-verbose* false
58
+ *repl-exec* true
59
+ *lua-interp* (conf/get :repl :lua-runtime )]
60
+ (let [; ; Lua subprocess
61
+ pb (ProcessBuilder. [*lua-interp* " cljs/exec_server.lua" ])
62
+ lua-process (.start pb)
63
+
64
+ ; ; Read lua stdout
65
+ rdr (io/reader (.getInputStream lua-process))
67
66
68
- ; ; Named pipes to communicate with lua subproc
69
- pipe-in (create-named-pipe " ltj" )
70
- pipe-out (create-named-pipe " jtl" )
71
- pipe-rdr (future (io/reader pipe-in))
72
- pipe-wr (future (io/writer pipe-out))
67
+ ; ; Named pipes to communicate with lua subproc
68
+ pipe-in (create-named-pipe " ltj" )
69
+ pipe-out (create-named-pipe " jtl" )
70
+ pipe-rdr (future (io/reader pipe-in))
71
+ pipe-wr (future (io/writer pipe-out))
73
72
74
- ; ; Function to analyze a form, emit lua code,
75
- ; ; pass it to the lua subproc, and get back the result
76
- eval-form (fn [env form]
77
- (let [lua-code (with-out-str (comp/emit (ana/analyze env form)))]
78
- (when *repl-verbose*
79
- (println " ---- LUA CODE ----" )
80
- (println lua-code))
81
- (when *repl-exec*
82
- (binding [*out* @pipe-wr]
83
- (println (json/json-str {:action :exec :body lua-code})))
84
- (let [resp (json/read-json (.readLine @pipe-rdr))]
85
- (if (= (:status resp) " OK" )
86
- (when *repl-show-result* (println (:body resp)))
87
- (do
88
- (println " ERROR : " (:body resp))
89
- (when *error-fatal?*
90
- (println lua-code)
91
- )))))))]
73
+ ; ; Function to analyze a form, emit lua code,
74
+ ; ; pass it to the lua subproc, and get back the result
75
+ eval-form (fn [env form]
76
+ (let [lua-code (with-out-str (comp/emit (ana/analyze env form)))]
77
+ (when *repl-verbose*
78
+ (println " ---- LUA CODE ----" )
79
+ (println lua-code))
80
+ (when *repl-exec*
81
+ (binding [*out* @pipe-wr]
82
+ (println (json/json-str {:action :exec :body lua-code})))
83
+ (let [resp (json/read-json (.readLine @pipe-rdr))]
84
+ (if (= (:status resp) " OK" )
85
+ (when *repl-show-result* (println (:body resp)))
86
+ (do
87
+ (println " ERROR : " (:body resp))
88
+ (when *error-fatal?*
89
+ (println lua-code)
90
+ )))))))]
92
91
93
- ; ; Redirect everything from subprocess stdout to own stdout
94
- (.start (Thread. (fn [] (while true (let [l (.readLine rdr)] (when l (println l)))))))
92
+ ; ; Redirect everything from subprocess stdout to own stdout
93
+ (.start (Thread. (fn [] (while true (let [l (.readLine rdr)] (when l (println l)))))))
95
94
96
- (try (do
97
- (.exitValue lua-process)
98
- (println " Lua subprocess has exited prematurely, verify you have lua installed, and required libraries : lua-json and lua-bitops" )
99
- (System/exit 0 ))
100
- (catch Exception e))
95
+ (try (do
96
+ (.exitValue lua-process)
97
+ (println " Lua subprocess has exited prematurely, verify you have lua installed, and required libraries : lua-json and lua-bitops" )
98
+ (System/exit 0 ))
99
+ (catch Exception e))
101
100
102
- ; ; Send it the two pipes names
103
- (binding [*out* (PrintWriter. (.getOutputStream lua-process))]
104
- (println (.getCanonicalPath pipe-in))
105
- (println (.getCanonicalPath pipe-out)))
101
+ ; ; Send it the two pipes names
102
+ (binding [*out* (PrintWriter. (.getOutputStream lua-process))]
103
+ (println (.getCanonicalPath pipe-in))
104
+ (println (.getCanonicalPath pipe-out)))
106
105
107
- ; ; Eval core.cljs forms
108
- (binding [*repl-verbose* false
109
- *repl-show-result* false
110
- *error-fatal?* true ]
111
- (eval-core-forms eval-form -1 ))
112
-
113
- ; ; Eval common ns forms
114
- (eval-form (nenv ) '(ns cljs.user))
115
-
116
- ; ; Repl loop
117
- (while true
118
- (.print System/out (str ana/*cljs-ns* " > " ))
119
- (.flush (System/out ))
120
- (let [env (nenv )
121
- form (read )
122
- special-fn? (and (seq? form) (contains? special-fns-set (first form)))]
123
- (if special-fn?
124
- (println (apply (special-fns (first form)) eval-form (rest form)))
125
- (eval-form env form))))))))
106
+ ; ; Eval core.cljs forms
107
+ (binding [*repl-verbose* false
108
+ *repl-show-result* false
109
+ *error-fatal?* true ]
110
+ (eval-core-forms eval-form -1 ))
111
+
112
+ ; ; Eval common ns forms
113
+ (eval-form (nenv ) '(ns cljs.user))
114
+
115
+ ; ; Repl loop
116
+ (while true
117
+ (.print System/out (str ana/*cljs-ns* " > " ))
118
+ (.flush (System/out ))
119
+ (let [env (nenv )
120
+ form (read )
121
+ special-fn? (and (seq? form) (contains? special-fns-set (first form)))]
122
+ (if special-fn?
123
+ (println (apply (special-fns (first form)) eval-form (rest form)))
124
+ (try (eval-form env form)
125
+ (catch Exception e
126
+ (.printStackTrace e))
127
+ (catch AssertionError a
128
+ (.printStackTrace a)))))))))
0 commit comments