aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lux-lein/src/leiningen/lux/utils.clj12
-rw-r--r--luxc/src/lux.clj6
-rw-r--r--luxc/src/lux/base.clj56
-rw-r--r--luxc/src/lux/repl.clj10
4 files changed, 46 insertions, 38 deletions
diff --git a/lux-lein/src/leiningen/lux/utils.clj b/lux-lein/src/leiningen/lux/utils.clj
index 40eb5bad8..17315f39c 100644
--- a/lux-lein/src/leiningen/lux/utils.clj
+++ b/lux-lein/src/leiningen/lux/utils.clj
@@ -39,7 +39,7 @@
nil))
jar-paths))
stdlib-path (prepare-path (some (fn [^:private path]
- (if (.contains path "com/github/luxlang/lux-stdlib")
+ (if (.contains path "com/github/luxlang/stdlib")
path
nil))
jar-paths))
@@ -70,7 +70,8 @@
" " output-dir))))
(defn repl-path [project source-paths]
- (let [jar-paths (->> ^java.net.URLClassLoader (ClassLoader/getSystemClassLoader)
+ (let [output-dir (get-in project [:lux :target] output-dir)
+ jar-paths (->> ^java.net.URLClassLoader (ClassLoader/getSystemClassLoader)
(.getURLs)
(map #(.getFile ^java.net.URL %))
(filter #(.endsWith ^String % ".jar")))
@@ -80,7 +81,7 @@
nil))
jar-paths))
stdlib-path (prepare-path (some (fn [^:private path]
- (if (.contains path "com/github/luxlang/lux-stdlib")
+ (if (.contains path "com/github/luxlang/stdlib")
path
nil))
jar-paths))
@@ -99,7 +100,10 @@
java-cmd (get project :java-cmd "java")
jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))]
(str java-cmd " " jvm-opts " " vm-options " -cp " (str compiler-path java.io.File/pathSeparator class-path)
- " lux repl " (->> source-paths (interpose unit-separator) (apply str))))))
+ " lux repl "
+ (->> (get project :resource-paths (list)) (interpose unit-separator) (apply str))
+ " " (->> source-paths (interpose unit-separator) (apply str))
+ " " output-dir))))
(defn run-process [command working-directory pre post]
(let [process (.exec (Runtime/getRuntime) command nil working-directory)]
diff --git a/luxc/src/lux.clj b/luxc/src/lux.clj
index e6fc3f4cc..c1e04b9a3 100644
--- a/luxc/src/lux.clj
+++ b/luxc/src/lux.clj
@@ -31,8 +31,10 @@
(&/$Cons "debug" (&/$Cons program-module (&/$Cons resources-dirs (&/$Cons source-dirs (&/$Cons target-dir (&/$Nil))))))
(time (&compiler/compile-program &/$Debug program-module (process-dirs resources-dirs) (process-dirs source-dirs) target-dir))
- (&/$Cons "repl" (&/$Cons source-dirs (&/$Nil)))
- (&repl/repl (process-dirs source-dirs))
+ (&/$Cons "repl" (&/$Cons resources-dirs (&/$Cons source-dirs (&/$Cons target-dir (&/$Nil)))))
+ (&repl/repl (process-dirs resources-dirs)
+ (process-dirs source-dirs)
+ target-dir)
_
(println "Can't understand command.")))
diff --git a/luxc/src/lux/base.clj b/luxc/src/lux/base.clj
index 21a093272..e0ca876ca 100644
--- a/luxc/src/lux/base.clj
+++ b/luxc/src/lux/base.clj
@@ -621,7 +621,7 @@
(defn try-all% [monads]
(|case monads
($Nil)
- (fail "There are no alternatives to try!")
+ (fail "[Error] There are no alternatives to try!")
($Cons m monads*)
(fn [state]
@@ -641,7 +641,7 @@
(defn try-all-% [prefix monads]
(|case monads
($Nil)
- (fail "There are no alternatives to try!")
+ (fail "[Error] There are no alternatives to try!")
($Cons m monads*)
(fn [state]
@@ -851,14 +851,14 @@
(return* state datum)
_
- ((fail-with-loc "Writer hasn't been set.") state)))))
+ ((fail-with-loc "[Error] Writer hasn't been set.") state)))))
(def get-top-local-env
(fn [state]
(try (let [top (|head (get$ $scopes state))]
(return* state top))
(catch Throwable _
- ((fail-with-loc "No local environment.") state)))))
+ ((fail-with-loc "[Error] No local environment.") state)))))
(def gen-id
(fn [state]
@@ -927,10 +927,33 @@
(|tail %))
state))))))
+(let [!out! *out*]
+ (defn |log! [& parts]
+ (binding [*out* !out!]
+ (do (print (apply str parts))
+ (flush)))))
+
+(defn |last [xs]
+ (|case xs
+ ($Cons x ($Nil))
+ x
+
+ ($Cons x xs*)
+ (|last xs*)
+
+ _
+ (assert false (adt->text xs))))
+
+(def get-scope-name
+ (fn [state]
+ (return* state (->> state (get$ $scopes) |head (get$ $name)))))
+
(defn without-repl-closure [body]
- (|do [_mode get-mode]
+ (|do [_mode get-mode
+ current-scope get-scope-name]
(fn [state]
- (let [output (body (if (in-repl? _mode)
+ (let [output (body (if (and (in-repl? _mode)
+ (->> current-scope |last (= "REPL")))
(update$ $scopes |tail state)
state))]
(|case output
@@ -953,10 +976,6 @@
_
output)))))
-(def get-scope-name
- (fn [state]
- (return* state (->> state (get$ $scopes) |head (get$ $name)))))
-
(defn with-writer [writer body]
(fn [state]
(let [old-writer (->> state (get$ $host) (get$ $writer))
@@ -1445,17 +1464,6 @@
_
(assert false (adt->text xs))))
-(defn |last [xs]
- (|case xs
- ($Cons x ($Nil))
- x
-
- ($Cons x xs*)
- (|last xs*)
-
- _
- (assert false (adt->text xs))))
-
(defn |partition [n xs]
(->> xs ->seq (partition-all n) (map ->list) ->list))
@@ -1505,12 +1513,6 @@
_
class-name)]))))
-(let [!out! *out*]
- (defn |log! [& parts]
- (binding [*out* !out!]
- (do (print (apply str parts))
- (flush)))))
-
(defn |eitherL [left right]
(fn [compiler]
(|case (run-state left compiler)
diff --git a/luxc/src/lux/repl.clj b/luxc/src/lux/repl.clj
index 195f3dc3e..1c727f246 100644
--- a/luxc/src/lux/repl.clj
+++ b/luxc/src/lux/repl.clj
@@ -24,14 +24,14 @@
(defn ^:private repl-cursor [repl-line]
(&/T [repl-module repl-line 0]))
-(defn ^:private init [source-dirs]
- (do (&compiler/init!)
+(defn ^:private init [resources-dirs source-dirs target-dir]
+ (do (&compiler/init! resources-dirs target-dir)
(|case ((|do [_ (&compiler/compile-module source-dirs "lux")
_ (&cache/delete repl-module)
_ (&module/create-module repl-module 0)
_ (fn [?state]
(return* (&/set$ &/$source
- (&/|list (&/T [(repl-cursor -1) "(;import lux)"]))
+ (&/|list (&/T [(repl-cursor -1) "(;module: lux)"]))
?state)
nil))
analysed-tokens (&analyser/repl-analyse &optimizer/optimize &compiler/eval! (partial &compiler/compile-module source-dirs) &compiler/all-compilers)
@@ -50,9 +50,9 @@
))
;; [Values]
-(defn repl [source-dirs]
+(defn repl [resources-dirs source-dirs target-dir]
(with-open [input (->> System/in (new InputStreamReader) (new BufferedReader))]
- (loop [state (init source-dirs)
+ (loop [state (init resources-dirs source-dirs target-dir)
repl-line 0
multi-line? false]
(let [_ (if (not multi-line?)