diff options
Diffstat (limited to '')
-rw-r--r-- | luxc/src/lux/compiler/js.clj | 14 | ||||
-rw-r--r-- | luxc/src/lux/compiler/js/base.clj | 14 |
2 files changed, 23 insertions, 5 deletions
diff --git a/luxc/src/lux/compiler/js.clj b/luxc/src/lux/compiler/js.clj index 1537bb7de..be405ad33 100644 --- a/luxc/src/lux/compiler/js.clj +++ b/luxc/src/lux/compiler/js.clj @@ -131,7 +131,11 @@ (|do [[file-name file-content] (&&io/read-file source-dirs name) :let [file-hash (hash file-content) compile-module!! (&¶llel/parallel-compilation (partial compile-module source-dirs))]] - (&/|eitherL (&&cache/load name) + (&/|eitherL (|do [output (&&cache/load name) + ^StringBuilder total-buffer &&/get-total-buffer + :let [module-code-path (str @&&core/!output-dir java.io.File/separator name java.io.File/separator &&/module-js-name) + _ (.append total-buffer ^String (str (slurp module-code-path) "\n"))]] + (return output)) (let [compiler-step (&analyser/analyse &optimizer/optimize eval! compile-module!! all-compilers)] (|do [module-exists? (&a-module/exists? name)] (if module-exists? @@ -166,8 +170,12 @@ &&js-cache/load-def-value &&js-cache/install-all-defs-in-module &&js-cache/uninstall-all-defs-in-module) - _ (compile-module source-dirs "lux")] - (compile-module source-dirs program-module))] + _ (compile-module source-dirs "lux") + _ (compile-module source-dirs program-module) + ^StringBuilder total-buffer &&/get-total-buffer + :let [full-program-file (str @&&core/!output-dir java.io.File/separator "program.js") + _ (&&core/write-file full-program-file (.getBytes (.toString total-buffer)))]] + (return nil))] (|case (m-action (&/init-state mode (&&/js-host))) (&/$Right ?state _) (do (println "Compilation complete!") diff --git a/luxc/src/lux/compiler/js/base.clj b/luxc/src/lux/compiler/js/base.clj index 417b35d5a..7f560b87d 100644 --- a/luxc/src/lux/compiler/js/base.clj +++ b/luxc/src/lux/compiler/js/base.clj @@ -21,13 +21,16 @@ (deftuple ["interpreter" - "buffer"]) + "buffer" + "total-buffer"]) (defn js-host [] (&/$Js (&/T [;; "interpreter" (.getScriptEngine (new NashornScriptEngineFactory)) ;; "buffer" &/$None + ;; "total-buffer" + (new StringBuilder) ]))) (def ^String module-js-name "module.js") @@ -44,6 +47,10 @@ (&/$None) (&/fail-with-loc "[Error] No buffer available.")))) +(def get-total-buffer + (|do [host &/js-host] + (return (&/get$ $total-buffer host)))) + (defn run-js! [^String js-code] (|do [host &/js-host :let [interpreter ^NashornScriptEngine (&/get$ $interpreter host)]] @@ -216,12 +223,15 @@ (|do [eval? &/get-eval module &/get-module-name ^StringBuilder buffer get-buffer + ^StringBuilder total-buffer get-total-buffer + :let [buffer-code (.toString buffer) + _ (.append total-buffer ^String (str buffer-code "\n"))] :let [_ (when (not eval?) (let [^String module* (&host/->module-class module) module-dir (str @&&/!output-dir java.io.File/separator (.replace module* "/" java.io.File/separator))] (do (.mkdirs (File. module-dir)) (&&/write-file (str module-dir java.io.File/separator module-js-name) - (.getBytes (.toString buffer))))))]] + (.getBytes buffer-code)))))]] (return nil))) (defn js-module [module] |