aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2015-05-27 01:17:41 -0400
committerEduardo Julian2015-05-27 01:17:41 -0400
commit20889fab030a5ad8de94ae26afffbc4488c44a16 (patch)
tree740012d3b944acc2db93411c6f21e013b703f5b7
parent5e45ec0419293fdde30cc9e3f0326e44ddd7442a (diff)
- Now storing the hash of the source file as a final, static field of the generated class.
-rw-r--r--src/lux/compiler.clj10
-rw-r--r--src/lux/reader.clj4
2 files changed, 9 insertions, 5 deletions
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index e491fbdfe..db2c92c42 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -349,12 +349,16 @@
(if (.equals ^Object name "lux")
(return* state nil)
(fail* "[Compiler Error] Can't redefine a module!"))
- (let [=class (doto (new ClassWriter ClassWriter/COMPUTE_MAXS)
+ (let [file-name (str "source/" name ".lux")
+ file-content (slurp file-name)
+ =class (doto (new ClassWriter ClassWriter/COMPUTE_MAXS)
(.visit Opcodes/V1_5 (+ Opcodes/ACC_PUBLIC Opcodes/ACC_SUPER)
- (&host/->class name) nil "java/lang/Object" nil))]
+ (&host/->class name) nil "java/lang/Object" nil))
+ _ (doto (.visitField =class (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC) "_hash" "I" nil (hash file-content))
+ .visitEnd)]
(matchv ::M/objects [((&/exhaust% compiler-step)
(->> state
- (&/set$ &/$SOURCE (&reader/from (str "source/" name ".lux")))
+ (&/set$ &/$SOURCE (&reader/from file-name file-content))
(&/set$ &/$ENVS (&/|list (&/env name)))
(&/update$ &/$HOST #(&/set$ &/$WRITER (&/V "lux;Some" =class) %))
(&/update$ &/$MODULES #(&/|put name &a-module/init-module %))))]
diff --git a/src/lux/reader.clj b/src/lux/reader.clj
index b1fcc4740..fa5d659bf 100644
--- a/src/lux/reader.clj
+++ b/src/lux/reader.clj
@@ -124,8 +124,8 @@
(&/T (&/T file-name line-num column-num*) line)))))
(&/V "No" (str "[Reader Error] Text failed: " text))))))
-(defn from [file-name]
- (let [lines (&/->list (string/split-lines (slurp file-name)))]
+(defn from [file-name file-content]
+ (let [lines (&/->list (string/split-lines file-content))]
(&/|map (fn [line+line-num]
(|let [[line-num line] line+line-num]
(&/T (&/T file-name line-num 0)