aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2016-10-30 01:19:49 -0400
committerEduardo Julian2016-10-30 01:19:49 -0400
commit969cfa5f52085de2b92fc47387a9550a07a34452 (patch)
treee60b2b0cab478026c27374625dbfe537c37ef628
parent8d7472544db3e0b1cccb0660fa5715cec7e559b0 (diff)
- Fixed a bug in how the output-dir and output-package are handled.
- Now taking output-dir from command-line arguments.
-rw-r--r--src/lux.clj8
-rw-r--r--src/lux/compiler.clj11
-rw-r--r--src/lux/compiler/base.clj7
-rw-r--r--src/lux/compiler/cache.clj15
-rw-r--r--src/lux/host.clj2
5 files changed, 20 insertions, 23 deletions
diff --git a/src/lux.clj b/src/lux.clj
index a8efa19f7..e6fc3f4cc 100644
--- a/src/lux.clj
+++ b/src/lux.clj
@@ -25,11 +25,11 @@
(defn -main [& args]
(|case (&/->list args)
- (&/$Cons "release" (&/$Cons program-module (&/$Cons resources-dirs (&/$Cons source-dirs (&/$Nil)))))
- (time (&compiler/compile-program &/$Release program-module (process-dirs resources-dirs) (process-dirs source-dirs)))
+ (&/$Cons "release" (&/$Cons program-module (&/$Cons resources-dirs (&/$Cons source-dirs (&/$Cons target-dir (&/$Nil))))))
+ (time (&compiler/compile-program &/$Release program-module (process-dirs resources-dirs) (process-dirs source-dirs) target-dir))
- (&/$Cons "debug" (&/$Cons program-module (&/$Cons resources-dirs (&/$Cons source-dirs (&/$Nil)))))
- (time (&compiler/compile-program &/$Debug program-module (process-dirs resources-dirs) (process-dirs source-dirs)))
+ (&/$Cons "debug" (&/$Cons program-module (&/$Cons resources-dirs (&/$Cons source-dirs (&/$Cons target-dir (&/$Nil))))))
+ (time (&compiler/compile-program &/$Debug program-module (process-dirs resources-dirs) (process-dirs source-dirs) target-dir))
(&/$Cons "repl" (&/$Cons source-dirs (&/$Nil)))
(&repl/repl (process-dirs source-dirs))
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index 44584e801..030df1dd6 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -122,10 +122,11 @@
(defn init!
"(-> (List Text) Null)"
- [resources-dirs]
- (do (&&parallel/setup!)
+ [resources-dirs target-dir]
+ (do (reset! &&/!output-dir target-dir)
+ (&&parallel/setup!)
(reset! !source->last-line {})
- (.mkdirs (java.io.File. &&/output-dir))
+ (.mkdirs (java.io.File. target-dir))
(let [class-loader (ClassLoader/getSystemClassLoader)
addURL (doto (.getDeclaredMethod java.net.URLClassLoader "addURL" (into-array [java.net.URL]))
(.setAccessible true))]
@@ -261,8 +262,8 @@
))
)))
-(defn compile-program [mode program-module resources-dir source-dirs]
- (do (init! resources-dir)
+(defn compile-program [mode program-module resources-dir source-dirs target-dir]
+ (do (init! resources-dir target-dir)
(let [m-action (|do [_ (compile-module source-dirs "lux")]
(compile-module source-dirs program-module))]
(|case (m-action (&/init-state mode))
diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj
index 499bc2644..a369b7436 100644
--- a/src/lux/compiler/base.clj
+++ b/src/lux/compiler/base.clj
@@ -26,7 +26,8 @@
(java.lang.reflect Field)))
;; [Constants]
-5
+(def !output-dir (atom nil))
+
(def ^:const ^String function-class "lux/Function")
(def ^:const ^String lux-utils-class "lux/LuxRT")
(def ^:const ^String unit-tag-field "unit_tag")
@@ -59,14 +60,14 @@
(defn ^:private write-output [module name data]
(let [module* (&host/->module-class module)
- module-dir (str output-dir "/" module*)]
+ module-dir (str @!output-dir "/" module*)]
(.mkdirs (File. module-dir))
(write-file (str module-dir "/" name ".class") data)))
(defn class-exists? [^String module ^String class-name]
"(-> Text Text (IO Bool))"
(|do [_ (return nil)
- :let [full-path (str output-dir "/" module "/" class-name ".class")
+ :let [full-path (str @!output-dir "/" module "/" class-name ".class")
exists? (.exists (File. full-path))]]
(return exists?)))
diff --git a/src/lux/compiler/cache.clj b/src/lux/compiler/cache.clj
index 955f73d9b..c0b0bc344 100644
--- a/src/lux/compiler/cache.clj
+++ b/src/lux/compiler/cache.clj
@@ -47,12 +47,12 @@
(defn cached? [module]
"(-> Text Bool)"
- (.exists (new File (str &&/output-dir "/" (&host/->module-class module) "/" module-class))))
+ (.exists (new File (str @&&/!output-dir "/" (&host/->module-class module) "/" module-class))))
(defn delete [module]
"(-> Text (Lux Null))"
(fn [state]
- (do (clean-file (new File (str &&/output-dir "/" (&host/->module-class module))))
+ (do (clean-file (new File (str @&&/!output-dir "/" (&host/->module-class module))))
(return* state nil))))
(defn ^:private module-dirs
@@ -68,16 +68,13 @@
(defn clean [state]
"(-> Compiler Null)"
(let [needed-modules (->> state (&/get$ &/$modules) &/|keys &/->seq set)
- output-dir-prefix (str (.getAbsolutePath (new File &&/output-dir)) "/")
+ output-dir-prefix (str (.getAbsolutePath (new File @&&/!output-dir)) "/")
outdated? #(->> % (contains? needed-modules) not)
- outdated-modules (->> (new File &&/output-dir)
+ outdated-modules (->> (new File @&&/!output-dir)
.listFiles (filter #(.isDirectory %))
(map module-dirs) doall (apply concat)
(map #(-> ^File % .getAbsolutePath (string/replace output-dir-prefix "")))
- (filter outdated?))
- program-file (new File &&/output-package)]
- (when (.exists program-file)
- (.delete program-file))
+ (filter outdated?))]
(doseq [^String f outdated-modules]
(clean-file (new File (str output-dir-prefix f))))
nil))
@@ -121,7 +118,7 @@
(|do [loader &/loader
!classes &/classes
:let [module* (&host-generics/->class-name module)
- module-path (str &&/output-dir "/" module)
+ module-path (str @&&/!output-dir "/" module)
class-name (str module* "._")
old-classes @!classes
^Class module-class (do (swap! !classes assoc class-name (read-file (File. (str module-path "/_.class"))))
diff --git a/src/lux/host.clj b/src/lux/host.clj
index de8c6cca1..26176b840 100644
--- a/src/lux/host.clj
+++ b/src/lux/host.clj
@@ -427,8 +427,6 @@
^ClassLoader loader &/loader
!classes &/classes
:let [_ (swap! !classes assoc store-name bytecode)
- ;; _ (with-open [stream (java.io.BufferedOutputStream. (java.io.FileOutputStream. (str "target/jvm/" dummy-full-name ".class")))]
- ;; (.write stream bytecode))
_ (.loadClass loader store-name)]
_ (&/push-dummy-name real-name store-name)]
(return nil)))