aboutsummaryrefslogtreecommitdiff
path: root/luxc/src
diff options
context:
space:
mode:
authorEduardo Julian2017-02-19 18:22:27 -0400
committerEduardo Julian2017-02-19 18:22:27 -0400
commit4e980a83d5e7532ed58337658c0631e2282c969f (patch)
tree689cf4c6d1175ea5b7370623ae0ba34893cc1560 /luxc/src
parent71d7ff61aa914e153965a4ef6a7ae72b4fb54581 (diff)
- Now storing the compiler's version and the module-file's hash inside the module-descriptor, instead of .class files (to make it reusable across different compiler targets).
Diffstat (limited to '')
-rw-r--r--luxc/src/lux/base.clj2
-rw-r--r--luxc/src/lux/compiler/core.clj6
-rw-r--r--luxc/src/lux/compiler/js.clj2
-rw-r--r--luxc/src/lux/compiler/jvm.clj6
-rw-r--r--luxc/src/lux/compiler/jvm/cache.clj34
5 files changed, 24 insertions, 26 deletions
diff --git a/luxc/src/lux/base.clj b/luxc/src/lux/base.clj
index 1a9fadf63..bbb5f3888 100644
--- a/luxc/src/lux/base.clj
+++ b/luxc/src/lux/base.clj
@@ -220,9 +220,7 @@
("DictA" 1))
;; [Exports]
-(def ^:const hash-field "_hash")
(def ^:const value-field "_value")
-(def ^:const compiler-field "_compiler")
(def ^:const eval-field "_eval")
(def ^:const module-class-name "_")
(def ^:const +name-separator+ ";")
diff --git a/luxc/src/lux/compiler/core.clj b/luxc/src/lux/compiler/core.clj
index 4779c3c28..6dacb4e54 100644
--- a/luxc/src/lux/compiler/core.clj
+++ b/luxc/src/lux/compiler/core.clj
@@ -44,7 +44,7 @@
(return (slurp (str @!output-dir java.io.File/separator (.replace name "/" java.io.File/separator) java.io.File/separator lux-module-descriptor-name)
:encoding "UTF-8"))))
-(def generate-module-descriptor
+(defn generate-module-descriptor [file-hash]
(|do [module-name &/get-module-name
module-anns (&a-module/get-anns module-name)
defs &a-module/defs
@@ -73,7 +73,9 @@
(str type datum-separator)))))
(&/|interpose entry-separator)
(&/fold str ""))
- module-descriptor (->> (&/|list import-entries
+ module-descriptor (->> (&/|list &/compiler-version
+ (Long/toUnsignedString file-hash)
+ import-entries
tag-entries
(&&&ann/serialize-anns module-anns)
def-entries)
diff --git a/luxc/src/lux/compiler/js.clj b/luxc/src/lux/compiler/js.clj
index 5bb97728f..b17c06436 100644
--- a/luxc/src/lux/compiler/js.clj
+++ b/luxc/src/lux/compiler/js.clj
@@ -151,7 +151,7 @@
(&/$Right ?state _)
(&/run-state (|do [_ (&a-module/flag-compiled-module name)
;; _ (&&/save-class! &/module-class-name (.toByteArray =class))
- module-descriptor &&core/generate-module-descriptor
+ module-descriptor (&&core/generate-module-descriptor file-hash)
_ (&&core/write-module-descriptor! name module-descriptor)]
(return file-hash))
?state)
diff --git a/luxc/src/lux/compiler/jvm.clj b/luxc/src/lux/compiler/jvm.clj
index d0d3c1bc3..68dcb0306 100644
--- a/luxc/src/lux/compiler/jvm.clj
+++ b/luxc/src/lux/compiler/jvm.clj
@@ -188,10 +188,6 @@
=class (doto (new ClassWriter ClassWriter/COMPUTE_MAXS)
(.visit &host/bytecode-version (+ Opcodes/ACC_PUBLIC Opcodes/ACC_SUPER)
module-class-name nil "java/lang/Object" nil)
- (-> (.visitField +field-flags+ &/hash-field "I" nil file-hash)
- .visitEnd)
- (-> (.visitField +field-flags+ &/compiler-field "Ljava/lang/String;" nil &/compiler-version)
- .visitEnd)
(.visitSource file-name nil))]
_ (if (= "lux" name)
(|do [_ &&rt/compile-Function-class
@@ -206,7 +202,7 @@
(&/run-state (|do [:let [_ (.visitEnd =class)]
_ (&a-module/flag-compiled-module name)
_ (&&/save-class! &/module-class-name (.toByteArray =class))
- module-descriptor &&core/generate-module-descriptor
+ module-descriptor (&&core/generate-module-descriptor file-hash)
_ (&&core/write-module-descriptor! name module-descriptor)]
(return file-hash))
?state)
diff --git a/luxc/src/lux/compiler/jvm/cache.clj b/luxc/src/lux/compiler/jvm/cache.clj
index cfbaf3810..b2b4f2bac 100644
--- a/luxc/src/lux/compiler/jvm/cache.clj
+++ b/luxc/src/lux/compiler/jvm/cache.clj
@@ -145,10 +145,10 @@
_ (&/map% (partial process-tag-group module) tag-groups)]
(return nil)))
-(defn ^:private process-module [pre-load! source-dirs cache-table module-name module-hash loader]
+(defn ^:private process-module [pre-load! source-dirs cache-table module-name module-hash loader
+ _imports-section _tags-section _module-anns-section _defs-section]
(|do [^String descriptor (&&core/read-module-descriptor! module-name)
- :let [[imports-section tags-section module-anns-section defs-section] (.split descriptor &&core/section-separator)
- imports (let [imports (vec (.split ^String imports-section &&core/entry-separator))
+ :let [imports (let [imports (vec (.split ^String _imports-section &&core/entry-separator))
imports (if (= [""] imports)
&/$Nil
(&/->list imports))]
@@ -164,9 +164,9 @@
(|let [[_module _hash] _import]
(contains? cache-table* _module)))
imports)
- (let [tag-groups (parse-tag-groups tags-section)
- module-anns (&&&ann/deserialize-anns module-anns-section)
- def-entries (let [def-entries (vec (.split ^String defs-section &&core/entry-separator))]
+ (let [tag-groups (parse-tag-groups _tags-section)
+ module-anns (&&&ann/deserialize-anns _module-anns-section)
+ def-entries (let [def-entries (vec (.split ^String _defs-section &&core/entry-separator))]
(if (= [""] def-entries)
&/$Nil
(&/->list def-entries)))]
@@ -198,30 +198,32 @@
(.substring prefix-to-subtract)))
&/->list)))
-(defn ^:private pre-load! [source-dirs cache-table module module-hash]
- (cond (contains? cache-table module)
+(defn ^:private pre-load! [source-dirs cache-table module-name module-hash]
+ (cond (contains? cache-table module-name)
(return cache-table)
- (not (cached? module))
+ (not (cached? module-name))
(return cache-table)
:else
(|do [loader &/loader
!classes &/classes
- :let [module* (&host-generics/->class-name module)
- module-path (str @&&core/!output-dir java.io.File/separator module)
+ ^String descriptor (&&core/read-module-descriptor! module-name)
+ :let [module* (&host-generics/->class-name module-name)
+ module-path (str @&&core/!output-dir java.io.File/separator module-name)
class-name (str module* "." &/module-class-name)
^Class module-class (do (swap! !classes assoc class-name (read-file (new File (str module-path java.io.File/separator module-class-file))))
(&&/load-class! loader class-name))
installed-classes (install-all-defs-in-module !classes module* module-path)
- valid-cache? (and (= module-hash (get-field &/hash-field module-class))
- (= &/compiler-version (get-field &/compiler-field module-class)))
- drop-cache! (|do [_ (uninstall-cache module)
+ [_compiler _hash _imports-section _tags-section _module-anns-section _defs-section] (.split descriptor &&core/section-separator)
+ drop-cache! (|do [_ (uninstall-cache module-name)
:let [_ (swap! !classes (fn [_classes-dict]
(reduce dissoc _classes-dict installed-classes)))]]
(return cache-table))]]
- (if valid-cache?
- (|do [[success? cache-table*] (process-module pre-load! source-dirs cache-table module module-hash loader)
+ (if (and (= module-hash (Long/parseUnsignedLong ^String _hash))
+ (= &/compiler-version _compiler))
+ (|do [[success? cache-table*] (process-module pre-load! source-dirs cache-table module-name module-hash loader
+ _imports-section _tags-section _module-anns-section _defs-section)
_ (if success?
(return nil)
drop-cache!)]