aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lux/analyser/lux.clj8
-rw-r--r--src/lux/base.clj18
-rw-r--r--src/lux/compiler.clj2
-rw-r--r--src/lux/compiler/base.clj140
-rw-r--r--src/lux/type.clj1
5 files changed, 80 insertions, 89 deletions
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index 72923c43e..6acae193f 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -393,12 +393,10 @@
(fail (str "[Analyser Error] Module can't import itself: " ?path))
(return nil))]
(&/save-module
- (|do [already-compiled? (&/source-seen? ?path)
- :let [must-compile? (not already-compiled?)
- _ (prn 'analyse-import module-name ?path already-compiled?)]
- _ (&/when% must-compile? (&/see-source ?path))
+ (|do [already-compiled? (&&module/exists? ?path)
+ :let [_ (prn 'analyse-import module-name ?path already-compiled?)]
_ (&&module/add-import ?path)
- _ (&/when% must-compile? (compile-module ?path))]
+ _ (&/when% (not already-compiled?) (compile-module ?path))]
(return (&/|list))))))
(defn analyse-export [analyse name]
diff --git a/src/lux/base.clj b/src/lux/base.clj
index 7b1e7139e..f88ca560e 100644
--- a/src/lux/base.clj
+++ b/src/lux/base.clj
@@ -33,9 +33,8 @@
(def $HOST 2)
(def $MODULES 3)
(def $SEED 4)
-(def $SEEN-SOURCES 5)
-(def $SOURCE 6)
-(def $TYPES 7)
+(def $SOURCE 5)
+(def $TYPES 6)
;; [Exports]
(def +name-separator+ ";")
@@ -491,8 +490,6 @@
(|table)
;; "lux;seed"
0
- ;; "lux;seen-sources"
- (|list)
;; "lux;source"
(V "lux;None" nil)
;; "lux;types"
@@ -711,15 +708,10 @@
(defn enumerate [xs]
(enumerate* 0 xs))
-(defn source-seen? [path]
- "(-> Text (Lux Bool))"
- (fn [state]
- (return* state (fold #(or %1 (= %2 path)) false (get$ $SEEN-SOURCES state)))))
-
-(defn see-source [path]
- "(-> Text (Lux (,)))"
+(def modules
+ "(Lux (List Text))"
(fn [state]
- (return* (update$ $SEEN-SOURCES (partial |cons path) state) nil)))
+ (return* state (|keys (get$ $MODULES state)))))
(defn when% [test body]
"(-> Bool (Lux (,)) (Lux (,)))"
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index fbf8afb89..9ecdcc6ad 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -369,7 +369,7 @@
return))))
(defn ^:private compile-module [name]
- ;; (prn 'compile-module name)
+ (prn 'compile-module name (&&/cached? name))
(if (&&/cached? name)
(do ;; (println "YOLO")
(let [file-name (str "input/" name ".lux")
diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj
index 89303c48d..a9abe44fc 100644
--- a/src/lux/compiler/base.clj
+++ b/src/lux/compiler/base.clj
@@ -133,75 +133,77 @@
(defn load-cache [module module-hash compile-module]
(|do [loader &/loader
!classes &/classes
- already-loaded? (&/source-seen? module)
+ already-loaded? (&a-module/exists? module)
+ _modules &/modules
:let [redo-cache (|do [_ (delete-cache module)
_ (compile-module module)]
(return false))]]
- (if already-loaded?
- (return true)
- (if (cached? module)
- (do (prn 'load-cache module module-hash)
- (let [module-path (str "cache/jvm/" (string/replace module #"/" " "))
- module* (string/replace 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))]
- (if (and (= module-hash (get-field "_hash" module-meta))
- (= version (get-field "_compiler" module-meta)))
- (let [imports (string/split (-> module-meta (.getField "_imports") (.get nil)) #"\t")
- ;; _ (prn module 'imports imports)
- ]
- (|do [loads (&/map% (fn [_import]
- (load-cache _import (-> (str "input/" _import ".lux") slurp hash) compile-module))
- (if (= [""] imports)
- (&/|list)
- (&/->list imports)))]
- (if (->> loads &/->seq (every? true?))
- (do (doseq [^File file (seq (.listFiles (File. module-path)))
- :let [file-name (.getName file)]
- :when (not= "_.class" file-name)]
- (let [real-name (second (re-find #"^(.*)\.class$" file-name))
- bytecode (read-file file)
- ;; _ (prn 'load-cache module real-name)
- ]
- ;; (swap! !classes assoc (str module* "." (replace-cache real-name)) bytecode)
- (swap! !classes assoc (str module* "." real-name) bytecode)
- ;; (swap! !classes assoc "__temp__" bytecode)
- ;; (swap! !classes assoc (-> (load-class! loader "__temp__") (.getField "_name") (.get nil)) bytecode)
- (write-output module real-name bytecode)))
- ;; (swap! !classes dissoc "__temp__")
- (let [defs (string/split (get-field "_defs" module-meta) #"\t")]
- ;; (prn 'load-cache module defs)
- (|do [_ (&/see-source module)
- _ (&a-module/enter-module module)
- _ (&/map% (fn [_def]
- (let [[_exported? _name _ann] (string/split _def #" ")
- ;; _ (prn '[_exported? _name _ann] [_exported? _name _ann])
- ]
- (|do [_ (case _ann
- "T" (&a-module/define module _name (&/V "lux;TypeD" nil) &type/Type)
- "M" (|do [_ (&a-module/define module _name (&/V "lux;ValueD" &type/Macro) &type/Macro)]
- (&a-module/declare-macro module _name))
- "V" (let [def-class (load-class! loader (str module* ".$" (&/normalize-ident _name)))
- ;; _ (println "Fetching _meta" module _name (str module* ".$" (&/normalize-ident _name)) def-class)
- def-type (get-field "_meta" def-class)]
- (matchv ::M/objects [def-type]
- [["lux;ValueD" _def-type]]
- (&a-module/define module _name def-type _def-type)))
- ;; else
- (let [[_ __module __name] (re-find #"^A(.*);(.*)$" _ann)]
- (|do [__type (&a-module/def-type __module __name)]
- (do ;; (prn '__type [__module __name] (&type/show-type __type))
- (&a-module/def-alias module _name __module __name __type)))))]
- (if (= "1" _exported?)
- (&a-module/export module _name)
- (return nil)))
- ))
- (if (= [""] defs)
- (&/|list)
- (&/->list defs)))]
- (return true))))
- redo-cache)))
- redo-cache)
- ))
- redo-cache))))
+ (do (prn 'load-cache module 'sources already-loaded?
+ (&/->seq _modules))
+ (if already-loaded?
+ (return true)
+ (if (cached? module)
+ (do (prn 'load-cache/HASH module module-hash)
+ (let [module-path (str "cache/jvm/" (string/replace module #"/" " "))
+ module* (string/replace 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))]
+ (if (and (= module-hash (get-field "_hash" module-meta))
+ (= version (get-field "_compiler" module-meta)))
+ (let [imports (string/split (-> module-meta (.getField "_imports") (.get nil)) #"\t")
+ _ (prn 'load-cache/IMPORTS module imports)
+ ]
+ (|do [loads (&/map% (fn [_import]
+ (load-cache _import (-> (str "input/" _import ".lux") slurp hash) compile-module))
+ (if (= [""] imports)
+ (&/|list)
+ (&/->list imports)))]
+ (if (->> loads &/->seq (every? true?))
+ (do (doseq [^File file (seq (.listFiles (File. module-path)))
+ :let [file-name (.getName file)]
+ :when (not= "_.class" file-name)]
+ (let [real-name (second (re-find #"^(.*)\.class$" file-name))
+ bytecode (read-file file)
+ ;; _ (prn 'load-cache module real-name)
+ ]
+ ;; (swap! !classes assoc (str module* "." (replace-cache real-name)) bytecode)
+ (swap! !classes assoc (str module* "." real-name) bytecode)
+ ;; (swap! !classes assoc "__temp__" bytecode)
+ ;; (swap! !classes assoc (-> (load-class! loader "__temp__") (.getField "_name") (.get nil)) bytecode)
+ (write-output module real-name bytecode)))
+ ;; (swap! !classes dissoc "__temp__")
+ (let [defs (string/split (get-field "_defs" module-meta) #"\t")]
+ ;; (prn 'load-cache module defs)
+ (|do [_ (&a-module/enter-module module)
+ _ (&/map% (fn [_def]
+ (let [[_exported? _name _ann] (string/split _def #" ")
+ ;; _ (prn '[_exported? _name _ann] [_exported? _name _ann])
+ ]
+ (|do [_ (case _ann
+ "T" (&a-module/define module _name (&/V "lux;TypeD" nil) &type/Type)
+ "M" (|do [_ (&a-module/define module _name (&/V "lux;ValueD" &type/Macro) &type/Macro)]
+ (&a-module/declare-macro module _name))
+ "V" (let [def-class (load-class! loader (str module* ".$" (&/normalize-ident _name)))
+ ;; _ (println "Fetching _meta" module _name (str module* ".$" (&/normalize-ident _name)) def-class)
+ def-type (get-field "_meta" def-class)]
+ (matchv ::M/objects [def-type]
+ [["lux;ValueD" _def-type]]
+ (&a-module/define module _name def-type _def-type)))
+ ;; else
+ (let [[_ __module __name] (re-find #"^A(.*);(.*)$" _ann)]
+ (|do [__type (&a-module/def-type __module __name)]
+ (do ;; (prn '__type [__module __name] (&type/show-type __type))
+ (&a-module/def-alias module _name __module __name __type)))))]
+ (if (= "1" _exported?)
+ (&a-module/export module _name)
+ (return nil)))
+ ))
+ (if (= [""] defs)
+ (&/|list)
+ (&/->list defs)))]
+ (return true))))
+ redo-cache)))
+ redo-cache)
+ ))
+ redo-cache)))))
diff --git a/src/lux/type.clj b/src/lux/type.clj
index 77fc6a2f8..14e87e063 100644
--- a/src/lux/type.clj
+++ b/src/lux/type.clj
@@ -177,7 +177,6 @@
(&/T "lux;types" (&/V "lux;AppT" (&/T (&/V "lux;AppT" (&/T Bindings Int)) Type)))
(&/T "lux;host" HostState)
(&/T "lux;seed" Int)
- (&/T "lux;seen-sources" (&/V "lux;AppT" (&/T List Text)))
(&/T "lux;eval?" Bool))))
$Void)))