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/program.lux | 86 +++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 31 deletions(-) (limited to 'new-luxc/source/program.lux') 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