From e5594faf0c38c5d85eb15c1305a124b220c9f428 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 13 Dec 2017 08:24:56 -0500 Subject: - Added CLI machinery to compiler. - Added extensions to the REPL. --- new-luxc/source/luxc/lang/translation.lux | 15 +++--- new-luxc/source/luxc/repl.lux | 13 ++++- new-luxc/source/program.lux | 86 ++++++++++++++++++++----------- 3 files changed, 75 insertions(+), 39 deletions(-) (limited to 'new-luxc/source') diff --git a/new-luxc/source/luxc/lang/translation.lux b/new-luxc/source/luxc/lang/translation.lux index b1e65c952..1a8ae9be0 100644 --- a/new-luxc/source/luxc/lang/translation.lux +++ b/new-luxc/source/luxc/lang/translation.lux @@ -254,13 +254,14 @@ _ (&io.write target (format hostL.runtime-class ".class") runtime-bc) _ (&io.write target (format hostL.function-class ".class") function-bc) _ (cache/io.pre-load sources target (commonT.load-definition compiler))] - (wrap (set@ #.extensions - (:! Void - {#extensionL.analysis analysisE.defaults - #extensionL.synthesis synthesisE.defaults - #extensionL.translation translationE.defaults - #extensionL.statement statementE.defaults}) - compiler)))))] + (wrap (|> compiler + (set@ [#.info #.mode] #.Build) + (set@ #.extensions + (:! Void + {#extensionL.analysis analysisE.defaults + #extensionL.synthesis synthesisE.defaults + #extensionL.translation translationE.defaults + #extensionL.statement statementE.defaults})))))))] (translate-module sources target prelude compiler))) (def: #export (translate-program sources target program) diff --git a/new-luxc/source/luxc/repl.lux b/new-luxc/source/luxc/repl.lux index 466446003..717462f22 100644 --- a/new-luxc/source/luxc/repl.lux +++ b/new-luxc/source/luxc/repl.lux @@ -34,7 +34,12 @@ [".L" host] [".L" translation] [".L" eval] - (translation [".T" runtime])))) + (translation [".T" runtime]) + [".L" extension] + (extension [".E" analysis] + [".E" synthesis] + [".E" translation] + [".E" statement])))) (exception: #export REPL-Initialization-Failed) (exception: #export REPL-Error) @@ -55,6 +60,12 @@ (#e.Success [compiler _]) (|> compiler (set@ [#.info #.mode] #.REPL) + (set@ #.extensions + (:! Void + {#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) diff --git a/new-luxc/source/program.lux b/new-luxc/source/program.lux index c36fb2114..5e60c318a 100644 --- a/new-luxc/source/program.lux +++ b/new-luxc/source/program.lux @@ -1,49 +1,57 @@ (.module: lux - (lux (control monad + (lux (control [monad #+ do] ["p" parser]) - (concurrency ["P" promise] - ["T" task]) + (concurrency [promise #+ Promise] + [task #+ Task]) (data ["e" error] text/format) [io #- run] - [cli #+ program: CLI]) + (time [instant]) + [cli #+ program: CLI] + (world [file #+ File])) (luxc [repl] (lang [".L" translation]))) -## (type: Compilation -## {#program &.Path -## #target &.Path}) +(type: Build + {#build-sources (List File) + #build-target File + #build-program Text}) -## (def: (marker tokens) -## (-> (List Text) (CLI Unit)) -## (cli.after (cli.option tokens) -## (:: Monad wrap []))) +(type: REPL + {#repl-sources (List File) + #repl-target File}) -## (def: (tagged tags) -## (-> (List Text) (CLI Text)) -## (cli.after (cli.option tags) -## cli.any)) +(def: (param [short long]) + (-> [Text Text] (CLI Text)) + (cli.somewhere (p.after (p.either (cli.this short) (cli.this long)) + cli.any))) -## (def: compilation^ -## (CLI Compilation) -## ($_ cli.seq -## (tagged (list "-p" "--program")) -## (tagged (list "-t" "--target")))) +(def: build + (CLI Build) + ($_ p.seq + (p.some (param ["-s" "--source"])) + (param ["-t" "--target"]) + (param ["-p" "--program"]))) -## (program: ([command (cli.opt compilation^)] -## [sources (cli.some (tagged (list "-s" "--source")))]) -## (case command -## #.None -## (io (log! "No REPL for you!")) +(def: repl + (CLI REPL) + ($_ p.seq + (p.some (param ["-s" "--source"])) + (param ["-t" "--target"]))) -## (#.Some [program target]) -## (exec (&compiler.compile-program program target sources) -## (io [])))) +(type: Service + (#Build Build) + (#REPL REPL)) + +(def: service + (CLI Service) + (p.alt (p.after (cli.this "build") build) + (p.after (cli.this "repl") repl))) (def: (or-crash! failure-describer action) - (All [a] (-> Text (T.Task a) (P.Promise a))) - (do P.Monad + (All [a] (-> Text (Task a) (Promise a))) + (do promise.Monad [?output action] (case ?output (#e.Error error) @@ -55,4 +63,20 @@ (#e.Success output) (wrap output)))) - +(program: ([service ..service]) + (exec + (case service + (#Build [sources target program]) + (<| (or-crash! "Compilation failed:") + (promise.future + (do io.Monad + [#let [start (io.run instant.now)] + result (translationL.translate-program sources target program) + #let [end (io.run instant.now) + _ (log! (format "\n" "Elapsed time: " (%duration (instant.span start end))))]] + (wrap result)))) + + (#REPL [sources target]) + (<| (or-crash! "REPL failed:") + (repl.run sources target))) + (io []))) -- cgit v1.2.3