diff options
author | Eduardo Julian | 2016-04-18 09:04:13 -0400 |
---|---|---|
committer | Eduardo Julian | 2016-04-18 09:04:13 -0400 |
commit | 10bc5adc0e5ed50321f6a5644989b0ab34550472 (patch) | |
tree | fc234df87d803d8eb5cbafb0543e587eb5efc75d | |
parent | 011842da545d20721d3868ccd8992cb5b883eed3 (diff) |
- The compiler now takes the list of directories on which to look for source code during compilation.
-rw-r--r-- | project.clj | 2 | ||||
-rw-r--r-- | src/lux.clj | 15 | ||||
-rw-r--r-- | src/lux/compiler.clj | 12 | ||||
-rw-r--r-- | src/lux/compiler/base.clj | 3 | ||||
-rw-r--r-- | src/lux/compiler/cache.clj | 10 | ||||
-rw-r--r-- | src/lux/compiler/io.clj | 28 | ||||
-rw-r--r-- | src/lux/repl.clj | 4 |
7 files changed, 37 insertions, 37 deletions
diff --git a/project.clj b/project.clj index 93218d37b..c00605591 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject lux-jvm "0.3.2" +(defproject com.github.luxlang/luxc-jvm "0.3.3-SNAPSHOT" :description "The JVM compiler for the Lux programming language." :url "https://github.com/LuxLang/lux" :license {:name "Mozilla Public License (Version 2.0)" diff --git a/src/lux.clj b/src/lux.clj index 40e8a0d24..73e8e9126 100644 --- a/src/lux.clj +++ b/src/lux.clj @@ -14,17 +14,14 @@ (defn -main [& args] (|case (&/->list args) - (&/$Cons program-module (&/$Nil)) - (time (&compiler/compile-program &/$Release program-module)) + (&/$Cons "release" (&/$Cons program-module source-dirs)) + (time (&compiler/compile-program &/$Release program-module source-dirs)) - (&/$Cons program-module (&/$Cons "release" (&/$Nil))) - (time (&compiler/compile-program &/$Release program-module)) + (&/$Cons "debug" (&/$Cons program-module source-dirs)) + (time (&compiler/compile-program &/$Debug program-module source-dirs)) - (&/$Cons program-module (&/$Cons "debug" (&/$Nil))) - (time (&compiler/compile-program &/$Debug program-module)) - - (&/$Nil) - (&repl/repl) + (&/$Cons "repl" source-dirs) + (&repl/repl source-dirs) _ (println "Can't understand command."))) diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj index 1b852f789..91be286de 100644 --- a/src/lux/compiler.clj +++ b/src/lux/compiler.clj @@ -487,13 +487,13 @@ (.get nil) return)))) -(defn compile-module [name] +(defn compile-module [source-dirs name] (let [file-name (str name ".lux")] - (|do [file-content (&&io/read-file file-name) + (|do [file-content (&&io/read-file source-dirs file-name) :let [file-hash (hash file-content)]] (if (&&cache/cached? name) - (&&cache/load name file-hash compile-module) - (let [compiler-step (&optimizer/optimize eval! compile-module compile-token)] + (&&cache/load source-dirs name file-hash compile-module) + (let [compiler-step (&optimizer/optimize eval! (partial compile-module source-dirs) compile-token)] (|do [module-exists? (&a-module/exists? name)] (if module-exists? (fail "[Compiler Error] Can't redefine a module!") @@ -555,9 +555,9 @@ )) )) -(defn compile-program [mode program-module] +(defn compile-program [mode program-module source-dirs] (init!) - (let [m-action (&/map% compile-module (&/|list "lux" program-module))] + (let [m-action (&/map% (partial compile-module source-dirs) (&/|list "lux" program-module))] (|case (m-action (&/init-state mode)) (&/$Right ?state _) (do (println "Compilation complete!") diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj index d2f84816d..9663e692e 100644 --- a/src/lux/compiler/base.clj +++ b/src/lux/compiler/base.clj @@ -25,14 +25,11 @@ (java.lang.reflect Field))) ;; [Constants] -(def ^String input-dir "source") (def ^String output-dir "target/jvm") (def ^String output-package (str output-dir "/" "program.jar")) (def ^String function-class "lux/Function") (def ^String lux-utils-class "lux/LuxUtils") (def ^String unit-tag-field "unit_tag") -(def ^String sum-tag-field "sum_tag") -(def ^String product-tag-field "product_tag") ;; Formats (def ^String local-prefix "l") diff --git a/src/lux/compiler/cache.clj b/src/lux/compiler/cache.clj index 8d7b4b55c..1bd3a1876 100644 --- a/src/lux/compiler/cache.clj +++ b/src/lux/compiler/cache.clj @@ -82,14 +82,14 @@ tag-separator-re (->regex &&/tag-separator) def-separator-re (->regex &&/def-separator) tag-group-separator-re (->regex &&/tag-group-separator)] - (defn load [module module-hash compile-module] - "(-> Text Int (-> Text (Lux (,))) (Lux Bool))" + (defn load [source-dirs module module-hash compile-module] + "(-> (List Text) Text Int (-> Text (Lux (,))) (Lux Bool))" (|do [loader &/loader !classes &/classes already-loaded? (&a-module/exists? module) _modules &/modules :let [redo-cache (|do [_ (delete module) - _ (compile-module module)] + _ (compile-module source-dirs module)] (return false))]] (if already-loaded? (return true) @@ -105,8 +105,8 @@ (= &/compiler-version (get-field &/compiler-field module-meta))) (let [imports (string/split (get-field &/imports-field module-meta) import-separator-re)] (|do [loads (&/map% (fn [_import] - (|do [content (&&io/read-file (str _import ".lux")) - _ (load _import (hash content) compile-module)] + (|do [content (&&io/read-file source-dirs (str _import ".lux")) + _ (load source-dirs _import (hash content) compile-module)] (&/cached-module? _import))) (if (= [""] imports) &/$Nil diff --git a/src/lux/compiler/io.clj b/src/lux/compiler/io.clj index fbef27b0f..7a7f5f9a6 100644 --- a/src/lux/compiler/io.clj +++ b/src/lux/compiler/io.clj @@ -4,7 +4,7 @@ ;; You can obtain one at http://mozilla.org/MPL/2.0/. (ns lux.compiler.io - (:require (lux [base :as & :refer [|let |do return* return fail fail*]]) + (:require (lux [base :as & :refer [|case |let |do return* return fail fail*]]) (lux.compiler [base :as &&]) [lux.lib.loader :as &lib])) @@ -18,13 +18,19 @@ (reset! !libs (&lib/load))) ;; [Resources] -(defn read-file [^String file-name] - (let [file (new java.io.File (str &&/input-dir "/" file-name))] - (if (.exists file) - (return (slurp file)) - (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)))) - ))) +(defn read-file [source-dirs ^String file-name] + (|case (&/|some (fn [source-dir] + (let [file (new java.io.File (str source-dir "/" file-name))] + (if (.exists file) + (&/$Some file) + &/$None))) + source-dirs) + (&/$Some file) + (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)))))) diff --git a/src/lux/repl.clj b/src/lux/repl.clj index dd63c1764..c101e26d9 100644 --- a/src/lux/repl.clj +++ b/src/lux/repl.clj @@ -39,7 +39,7 @@ (&/T [repl-module repl-line 0])) ;; [Values] -(defn repl [] +(defn repl [source-dirs] (with-open [input (->> System/in (new InputStreamReader) (new BufferedReader))] (loop [state (init) repl-line 0] @@ -51,7 +51,7 @@ state* (&/update$ &/$source (fn [_source] (&/|++ _source line*)) state)] - (|case ((|do [analysed-tokens (&analyser/repl-analyse &compiler/eval! &compiler/compile-module &compiler/compile-token) + (|case ((|do [analysed-tokens (&analyser/repl-analyse &compiler/eval! (partial &compiler/compile-module source-dirs) &compiler/compile-token) optimized-tokens (->> analysed-tokens (&/|map &a-base/expr-term) (&/map% &optimizer/optimize-token)) |