(.module: [lux #* [control [monad (#+ do)] ["p" parser]] [concurrency ["." promise (#+ Promise)] ["." task (#+ Task)]] [data ["e" error] [text format]] ["." io (#+ IO Process io)] [time ["." instant]] [cli (#+ program:)] [world ["." file (#+ File)]] [compiler ["." cli] ["." default (#+ Platform)]]] [luxc ## ["." repl] [lang ["." host/jvm] [translation ["." jvm ["." runtime] ["." expression]]]]]) (def: (or-crash! failure-describer action) (All [a] (-> Text (Task a) (Promise a))) (do promise.Monad [?output action] (case ?output (#e.Error error) (exec (log! (format "\n" failure-describer "\n" error "\n")) (io.run (io.exit +1))) (#e.Success output) (wrap output)))) (def: (timed action) (All [a] (-> (Process a) (Process a))) (do io.Monad [start (io.from-io instant.now) result action finish (io.from-io instant.now) #let [elapsed-time (instant.span start finish) _ (log! (format "\n" "Elapsed time: " (%duration elapsed-time)))]] (wrap result))) (def: jvm-platform (IO (Platform Process host/jvm.Anchor host/jvm.Inst host/jvm.Definition)) (do io.Monad [host jvm.init] (wrap {#default.host host #default.phase expression.translate #default.runtime runtime.translate #default.file-system file.JVM@System}))) (program: [{service cli.service}] (do io.Monad [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)) )))))