aboutsummaryrefslogtreecommitdiff
path: root/new-luxc
diff options
context:
space:
mode:
authorEduardo Julian2018-08-11 14:44:42 -0400
committerEduardo Julian2018-08-11 14:44:42 -0400
commit725bcd5670a5d83c201fac147aedce01d9283d03 (patch)
tree3942735ba1b19dee9b2ba5a0818f4a6be1cf3cfe /new-luxc
parent0fe039a41571328a29b7a620643fc5e30e32b9a3 (diff)
Moved interpreter (REPL) code to stdlib.
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/repl.lux145
-rw-r--r--new-luxc/source/program.lux48
2 files changed, 23 insertions, 170 deletions
diff --git a/new-luxc/source/luxc/repl.lux b/new-luxc/source/luxc/repl.lux
deleted file mode 100644
index e8da16ae1..000000000
--- a/new-luxc/source/luxc/repl.lux
+++ /dev/null
@@ -1,145 +0,0 @@
-(.module:
- [lux #*
- [control
- [monad (#+ do)]
- ["ex" exception (#+ exception:)]]
- [data
- ["." maybe]
- ["e" error (#+ Error)]
- [text ("text/" Equivalence<Text>)
- format]
- [collection
- ["." dictionary]]]
- ["." macro]
- [type
- ["." check]]
- [language
- [syntax (#+ Aliases)]
- [".L" init]
- [".L" module]
- [".L" scope]
- [".L" extension
- [".E" analysis]]]
- [concurrency
- ["." promise]
- [task (#+ Task)]]
- ["." io]
- [world
- [file (#+ File)]
- [console (#+ Console)]]]
- [//
- ["." lang
- [".L" host]
- [".L" translation
- [jvm
- [".T" runtime]]]
- [extension
- [".E" synthesis]
- [".E" translation]
- [".E" statement]]]])
-
-(do-template [<name>]
- [(exception: #export (<name> {message Text})
- message)]
-
- [repl-initialization-failed]
- [repl-error]
- )
-
-(def: repl-module "<REPL>")
-
-(def: no-aliases Aliases (dictionary.new text.Hash<Text>))
-
-(def: (initialize source-dirs target-dir console)
- (-> (List File) File Console (Task Lux))
- (do promise.Monad<Promise>
- [output (promise.future
- (do io.Monad<IO>
- [host hostL.init-host]
- (case (macro.run' (initL.compiler host)
- (moduleL.with-module 0 repl-module
- runtimeT.translate))
- (#e.Success [compiler _])
- (|> compiler
- (set@ [#.info #.mode] #.REPL)
- (set@ #.extensions
- (:coerce Nothing
- {#extensionL.analysis analysisE.defaults
- #extensionL.synthesis synthesisE.defaults
- #extensionL.translation translationE.defaults
- #extensionL.statement statementE.defaults}))
- (translationL.translate-module source-dirs target-dir translationL.prelude))
-
- (#e.Error error)
- (wrap (#e.Error error)))))]
- (case output
- (#e.Success compiler)
- (do task.Monad<Task>
- [_ (console.write (format "\nWelcome to the REPL!\n"
- "Type \"exit\" to leave.\n\n")
- console)]
- (wrap compiler))
-
- (#e.Error message)
- (task.throw repl-initialization-failed message))))
-
-(def: (add-line line [where offset input])
- (-> Text Source Source)
- [where offset (format input "\n" line)])
-
-(def: (repl-translate source-dirs target-dir code)
- (-> (List File) File Code (Meta [Type Any]))
- (function (_ compiler)
- (case ((translationL.translate (translationL.translate-module source-dirs target-dir)
- no-aliases
- code)
- compiler)
- (#e.Success [compiler' aliases'])
- (#e.Success [compiler' [Nothing []]])
-
- (#e.Error error)
- (if (ex.match? translationL.Unrecognized-Statement error)
- ((do macro.Monad<Meta>
- [[var-id varT] (lang.with-type-env check.var)
- exprV (scopeL.with-scope repl-module
- (evalL.eval varT code))
- ?exprT (lang.with-type-env (check.read var-id))]
- (wrap [(maybe.assume ?exprT) exprV]))
- compiler)
- (#e.Error error)))))
-
-(def: fresh-source Source [[repl-module 1 0] 0 ""])
-
-(def: #export (run source-dirs target-dir)
- (-> (List File) File (Task Any))
- (do task.Monad<Task>
- [console (promise.future console.open)
- compiler (initialize source-dirs target-dir console)]
- (loop [compiler compiler
- source fresh-source
- multi-line? #0]
- (do @
- [_ (if multi-line?
- (console.write " " console)
- (console.write "> " console))
- line (console.read-line console)]
- (if (text/= "exit" line)
- (console.write "Till next time..." console)
- (case (do e.Monad<Error>
- [[source' exprC] (syntax.read repl-module no-aliases (add-line line source))]
- (macro.run' compiler
- (lang.with-current-module repl-module
- (do macro.Monad<Meta>
- [[exprT exprV] (repl-translate source-dirs target-dir exprC)]
- (wrap [source' exprT exprV])))))
- (#e.Success [compiler' [source' exprT exprV]])
- (do @
- [_ (console.write (represent compiler' exprT exprV) console)]
- (recur compiler' source' #0))
-
- (#e.Error error)
- (if (ex.match? syntax.end-of-file error)
- (recur compiler source #1)
- (exec (log! (ex.construct repl-error error))
- (recur compiler fresh-source #0))))))
- )))
diff --git a/new-luxc/source/program.lux b/new-luxc/source/program.lux
index 4e0925717..01b3a2eee 100644
--- a/new-luxc/source/program.lux
+++ b/new-luxc/source/program.lux
@@ -7,7 +7,7 @@
["." promise (#+ Promise)]
["." task (#+ Task)]]
[data
- ["e" error]
+ ["." error]
[text
format]]
["." io (#+ IO Process io)]
@@ -15,12 +15,13 @@
["." instant]]
[cli (#+ program:)]
[world
- ["." file (#+ File)]]
+ ["." file (#+ File)]
+ ["." console]]
[compiler
["." cli]
- ["." default (#+ Platform)]]]
+ ["." default (#+ Platform)]]
+ ["." interpreter]]
[luxc
- ## ["." repl]
[lang
["." host/jvm]
[translation
@@ -28,19 +29,19 @@
["." runtime]
["." expression]]]]])
-(def: (or-crash! failure-describer action)
+(def: (or-crash! failure-description action)
(All [a]
- (-> Text (Task a) (Promise a)))
- (do promise.Monad<Promise>
+ (-> Text (Process a) (IO a)))
+ (do io.Monad<IO>
[?output action]
(case ?output
- (#e.Error error)
+ (#error.Error error)
(exec (log! (format "\n"
- failure-describer "\n"
+ failure-description "\n"
error "\n"))
- (io.run (io.exit +1)))
+ (io.exit +1))
- (#e.Success output)
+ (#error.Success output)
(wrap output))))
(def: (timed action)
@@ -65,17 +66,14 @@
(program: [{service cli.service}]
(do io.Monad<IO>
- [platform ..jvm-platform]
- (wrap (: (Promise Any)
- (case service
- (#cli.Build [configuration program])
- (<| (or-crash! "Compilation failed:")
- promise.future
- ..timed
- (default.compile platform configuration program))
-
- (#cli.REPL configuration)
- (undefined)
- ## (<| (or-crash! "REPL failed:")
- ## (repl.run sources target))
- )))))
+ [platform ..jvm-platform
+ console (:: @ map error.assume console.open)]
+ (case service
+ (#cli.Compilation configuration)
+ (<| (or-crash! "Compilation failed:")
+ ..timed
+ (default.compile platform configuration))
+
+ (#cli.Interpretation configuration)
+ (<| (or-crash! "Interpretation failed:")
+ (interpreter.run io.Monad<Process> console platform configuration)))))