diff options
author | Eduardo Julian | 2016-12-31 12:30:19 -0400 |
---|---|---|
committer | Eduardo Julian | 2016-12-31 12:30:19 -0400 |
commit | 1f2acb4509f83f638cbdf5f6dc06fba40eec2418 (patch) | |
tree | fb2d86a4de2e5ef1e274e6bfa529a44f7736e8f6 | |
parent | 00cdab25b25822c3ee08c3cce43dcc05a8b64b5b (diff) |
- Prepared everything prior to pre-loading.
Diffstat (limited to '')
-rw-r--r-- | luxc/src/lux/compiler.clj | 4 | ||||
-rw-r--r-- | luxc/src/lux/compiler/cache.clj | 49 | ||||
-rw-r--r-- | luxc/src/lux/compiler/io.clj | 15 |
3 files changed, 46 insertions, 22 deletions
diff --git a/luxc/src/lux/compiler.clj b/luxc/src/lux/compiler.clj index b9b4e8de0..15b74bc9e 100644 --- a/luxc/src/lux/compiler.clj +++ b/luxc/src/lux/compiler.clj @@ -127,6 +127,7 @@ [resources-dirs ^String target-dir] (do (reset! &&/!output-dir target-dir) (&¶llel/setup!) + (&&io/init-libs!) (reset! !source->last-line {}) (.mkdirs (new java.io.File target-dir)) (let [class-loader (ClassLoader/getSystemClassLoader) @@ -258,7 +259,8 @@ (let [!err! *err*] (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")] + (let [m-action (|do [_ (&&cache/pre-load-cache! source-dirs) + _ (compile-module source-dirs "lux")] (compile-module source-dirs program-module))] (|case (m-action (&/init-state mode)) (&/$Right ?state _) diff --git a/luxc/src/lux/compiler/cache.clj b/luxc/src/lux/compiler/cache.clj index 9ba3ac815..ce0a0325b 100644 --- a/luxc/src/lux/compiler/cache.clj +++ b/luxc/src/lux/compiler/cache.clj @@ -147,13 +147,9 @@ def-value (get-field &/value-field def-class)] (&a-module/define module _name def-type def-anns def-value))))) -(defn ^:private redo-cache [compile-module module] - (|do [_ (delete module) - ;; async (compile-module module) - ] - ;; (assume-async-result @async) - (compile-module module) - )) +(defn ^:private uninstall-cache [module] + (|do [_ (delete module)] + (return false))) (defn ^:private install-module [loader module module-hash imports tag-groups module-anns def-entries] (|do [_ (&a-module/create-module module module-hash) @@ -183,10 +179,41 @@ (&/->list def-entries)))] (install-module loader module module-hash imports tag-groups module-anns def-entries)) - (redo-cache compile-module module)))) + (uninstall-cache module)))) + +(defn ^:private enumerate-cached-modules!* [^File parent] + (if (.isDirectory parent) + (let [children (for [^File child (seq (.listFiles parent)) + entry (enumerate-cached-modules!* child)] + entry)] + (if (.exists (new File parent "_.class")) + (list* (.getAbsolutePath parent) + children) + children)) + (list))) + +(defn ^:private enumerate-cached-modules! [] + (let [output-dir (new File @&&/!output-dir) + prefix-to-subtract (inc (.length (.getAbsolutePath output-dir)))] + (->> output-dir + enumerate-cached-modules!* + rest + (map #(.substring ^String % prefix-to-subtract)) + &/->list))) + +(def !pre-loaded-cache (atom nil)) +(defn pre-load-cache! [source-dirs] + (let [cached-modules (enumerate-cached-modules!) + loaded-dict (&/fold (fn [loaded-dict present-module] + (assoc loaded-dict present-module false)) + {} + cached-modules)] + (do (&/|log! (prn-str 'pre-load-cache! (&/->seq source-dirs))) + (&/|log! (prn-str 'pre-load-cache! (&/->seq cached-modules))) + (return nil)))) (defn load [source-dirs module module-hash compile-module] - "(-> (List Text) Text Int (-> Text (Lux [])) (Lux Bool))" + "(-> (List Text) Text Int (-> Text (Lux [])) (Lux Nil))" (|do [already-loaded? (&a-module/exists? module)] (if already-loaded? (return nil) @@ -204,5 +231,5 @@ (= &/compiler-version (get-field &/compiler-field module-class))) (process-module load compile-module source-dirs loader module module-hash) (do (reset! !classes old-classes) - (redo-cache compile-module module)))) - (redo-cache compile-module module))))) + (uninstall-cache module)))) + (uninstall-cache module))))) diff --git a/luxc/src/lux/compiler/io.clj b/luxc/src/lux/compiler/io.clj index ecb2066cd..179e2a097 100644 --- a/luxc/src/lux/compiler/io.clj +++ b/luxc/src/lux/compiler/io.clj @@ -11,13 +11,10 @@ ;; [Utils] (def ^:private !libs (atom nil)) -(defn ^:private libs-imported? [] - (not (nil? @!libs))) - -(defn ^:private init-libs! [] +;; [Resources] +(defn init-libs! [] (reset! !libs (&lib/load))) -;; [Resources] (defn read-file [source-dirs ^String file-name] (|case (&/|some (fn [source-dir] (let [file (new java.io.File (str source-dir "/" file-name))] @@ -29,8 +26,6 @@ (return (slurp file)) (&/$None) - (do (when (not (libs-imported?)) - (init-libs!)) - (if-let [code (get @!libs file-name)] - (return code) - (fail (str "[I/O Error] File doesn't exist: " file-name)))))) + (if-let [code (get @!libs file-name)] + (return code) + (fail (str "[I/O Error] File doesn't exist: " file-name))))) |