diff options
author | Eduardo Julian | 2017-01-11 21:39:30 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-01-11 21:39:30 -0400 |
commit | 8b158ecbd330dce3603ba5e854fb21ca482c0b64 (patch) | |
tree | 3980fe603fa72740713e0a496f33a5123ae4a876 /luxc | |
parent | e44d30c41694a574ae00b55c333e39e4e83c478a (diff) |
- Fixed some bugs in the REPL.
Diffstat (limited to '')
-rw-r--r-- | luxc/src/lux.clj | 6 | ||||
-rw-r--r-- | luxc/src/lux/base.clj | 56 | ||||
-rw-r--r-- | luxc/src/lux/repl.clj | 10 |
3 files changed, 38 insertions, 34 deletions
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?) |