(.module: [lux #* [control [monad (#+ do)] ["p" parser]] [concurrency ["." promise (#+ Promise)] ["." task (#+ Task)]] [data ["." error] [text format]] ["." io (#+ IO Process io)] [time ["." instant]] [cli (#+ program:)] [world ["." file (#+ File)] ["." console]] [compiler ["." cli] ["." default (#+ Platform)]] ["." interpreter]] [luxc [lang ["." host/jvm] [translation ["." jvm ["." runtime] ["." expression] [procedure ["." common]]]]]]) (def: (or-crash! failure-description action) (All [a] (-> Text (Process a) (IO a))) (do io.Monad [?output action] (case ?output (#error.Error error) (exec (log! (format "\n" failure-description "\n" error "\n")) (io.exit +1)) (#error.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 console (:: @ map error.assume console.open)] (case service (#cli.Compilation configuration) (<| (or-crash! "Compilation failed:") ..timed (default.compile platform configuration common.bundle)) (#cli.Interpretation configuration) (<| (or-crash! "Interpretation failed:") (interpreter.run io.Monad console platform configuration)))))