aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2015-09-11 22:16:58 -0400
committerEduardo Julian2015-09-11 22:16:58 -0400
commit5148900e02c8e05808afc8a3ec7fc51a901bcc7b (patch)
tree8ea4d23410b23369f8498660f1089a68ebcf8827
parent5a26c40dc215dfb22a77cad28455deff28ca9976 (diff)
- Abandoned the old format for classes of having module names separated by underscores, and now using slashes and putting submodules inside the directories of their parent modules.
-rw-r--r--src/lux/analyser/module.clj2
-rw-r--r--src/lux/compiler.clj2
-rw-r--r--src/lux/compiler/base.clj8
-rw-r--r--src/lux/compiler/cache.clj17
-rw-r--r--src/lux/compiler/package.clj18
-rw-r--r--src/lux/host.clj13
6 files changed, 35 insertions, 25 deletions
diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj
index 6740d6515..97365ba08 100644
--- a/src/lux/analyser/module.clj
+++ b/src/lux/analyser/module.clj
@@ -204,7 +204,7 @@
[exported? (&/$ValueD ?type _)]
((|do [_ (&type/check &type/Macro ?type)
^ClassLoader loader &/loader
- :let [macro (-> (.loadClass loader (str (&host/->module-class module) "." (&/normalize-name name)))
+ :let [macro (-> (.loadClass loader (str (&host/->class-name module) "." (&/normalize-name name)))
(.getField &/datum-field)
(.get nil))]]
(fn [state*]
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index e16a84b20..da9896bd5 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -392,7 +392,7 @@
.visitEnd))]
_ (&&/save-class! (str id) bytecode)
loader &/loader]
- (-> (.loadClass ^ClassLoader loader (str (&host/->module-class module) "." id))
+ (-> (.loadClass ^ClassLoader loader (str (&host/->class-name module) "." id))
(.getField &/eval-field)
(.get nil)
return))))
diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj
index edb1441ca..7c1297aad 100644
--- a/src/lux/compiler/base.clj
+++ b/src/lux/compiler/base.clj
@@ -26,8 +26,8 @@
;; [Constants]
(def ^String version "0.3")
(def ^String input-dir "source")
-(def ^String output-dir "target/jvm")
-(def ^String output-package (str output-dir "/program.jar"))
+(def ^String output-dir "target/jvm/")
+(def ^String output-package (str output-dir "program.jar"))
(def ^String function-class "lux/Function")
;; Formats
@@ -55,7 +55,7 @@
(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)))
@@ -69,7 +69,7 @@
module &/get-module-name
loader &/loader
!classes &/classes
- :let [real-name (str (&host/->module-class module) "." name)
+ :let [real-name (str (&host/->class-name module) "." name)
_ (swap! !classes assoc real-name bytecode)
_ (when (not eval?)
(write-output module name bytecode))
diff --git a/src/lux/compiler/cache.clj b/src/lux/compiler/cache.clj
index da7ce35e9..e47da2678 100644
--- a/src/lux/compiler/cache.clj
+++ b/src/lux/compiler/cache.clj
@@ -32,11 +32,9 @@
(defn ^:private clean-file [^File file]
"(-> File (,))"
- (if (.isDirectory file)
- (do (doseq [f (seq (.listFiles file))]
- (clean-file f))
- (.delete file))
- (.delete file)))
+ (doseq [f (seq (.listFiles file))
+ :when (not (.isDirectory f))]
+ (.delete f)))
(defn ^:private get-field [^String field-name ^Class class]
"(-> Text Class Object)"
@@ -45,12 +43,12 @@
;; [Resources]
(defn cached? [module]
"(-> Text Bool)"
- (.exists (new File (str &&/output-dir "/" (&host/->module-class module) "/_.class"))))
+ (.exists (new File (str &&/output-dir (&host/->module-class module) "/" &/module-class-name ".class"))))
(defn delete [module]
"(-> Text (Lux (,)))"
(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 clean [state]
@@ -80,8 +78,8 @@
(return true)
(if (cached? module)
(do ;; (prn 'load/HASH module module-hash)
- (let [module* (&host/->module-class module)
- module-path (str &&/output-dir "/" module*)
+ (let [module* (&host/->class-name module)
+ module-path (str &&/output-dir module)
class-name (str module* "._")
^Class module-meta (do (swap! !classes assoc class-name (read-file (File. (str module-path "/_.class"))))
(&&/load-class! loader class-name))]
@@ -98,6 +96,7 @@
(&/->list imports)))]
(if (->> loads &/->seq (every? true?))
(do (doseq [^File file (seq (.listFiles (File. module-path)))
+ :when (not (.isDirectory file))
:let [file-name (.getName file)]
:when (not= "_.class" file-name)]
(let [real-name (second (re-find #"^(.*)\.class$" file-name))
diff --git a/src/lux/compiler/package.clj b/src/lux/compiler/package.clj
index b1468e540..4f703f5d1 100644
--- a/src/lux/compiler/package.clj
+++ b/src/lux/compiler/package.clj
@@ -30,6 +30,7 @@
(defn ^:private write-class! [^String path ^File file ^JarOutputStream out]
"(-> Text File JarOutputStream Unit)"
+ ;; (prn 'write-class! path file)
(with-open [in (new BufferedInputStream (new FileInputStream file))]
(let [buffer (byte-array (* 10 kilobyte))]
(doto out
@@ -42,11 +43,18 @@
))
))
-(defn ^:private write-module! [^File file ^JarOutputStream out]
- "(-> File JarOutputStream Unit)"
- (let [module-name (.getName file)]
- (doseq [$class (.listFiles file)]
- (write-class! module-name $class out))))
+(let [output-dir-size (.length &&/output-dir)]
+ (defn ^:private write-module! [^File file ^JarOutputStream out]
+ "(-> File JarOutputStream Unit)"
+ (let [module-name (.substring (.getPath file) output-dir-size) ;; (.getName file)
+ ;; _ (prn 'write-module! module-name file (.getPath file) (.substring (.getPath file) output-dir-size))
+ inner-files (.listFiles file)
+ inner-modules (filter #(.isDirectory %) inner-files)
+ inner-classes (filter #(not (.isDirectory %)) inner-files)]
+ (doseq [$class inner-classes]
+ (write-class! module-name $class out))
+ (doseq [$module inner-modules]
+ (write-module! $module out)))))
;; [Resources]
(defn package [module]
diff --git a/src/lux/host.clj b/src/lux/host.clj
index 3d61eec6a..2290f2f0a 100644
--- a/src/lux/host.clj
+++ b/src/lux/host.clj
@@ -10,12 +10,15 @@
clojure.core.match.array
(lux [base :as & :refer [|do return* return fail fail* |let |case]]
[type :as &type]))
- (:import (java.lang.reflect Field Method Modifier)))
+ (:import (java.lang.reflect Field Method Modifier)
+ java.util.regex.Pattern))
;; [Constants]
(def prefix "lux.")
(def function-class (str prefix "Function"))
-(def module-separator "_")
+(def module-separator "/")
+(def class-name-separator ".")
+(def class-separator "/")
;; [Utils]
(defn ^:private class->type [^Class class]
@@ -35,13 +38,13 @@
;; [Resources]
(defn ^String ->class [class]
- (string/replace class #"\." "/"))
+ (string/replace class (-> class-name-separator Pattern/quote re-pattern) class-separator))
(defn ^String ->class-name [module]
- (string/replace module #"/" "."))
+ (string/replace module (-> module-separator Pattern/quote re-pattern) class-name-separator))
(defn ^String ->module-class [module-name]
- (string/replace module-name #"/" module-separator))
+ (string/replace module-name (-> module-separator Pattern/quote re-pattern) class-separator))
(def ->package ->module-class)