(.module: [lux #* [type (#+ :share)] [abstract [monad (#+ do)]] [control ["." io (#+ IO io)] [parser [cli (#+ program:)]] [security ["!" capability]]] [data ["." product] ["." error (#+ Error)] ["." text format] [collection ["." dictionary] ["." row] ["." list ("#@." functor fold)]]] [time ["." instant (#+ Instant)]] [host ["_" js]] [world ["." file (#+ File)] ["." console]] [tool [compiler ["." statement] ["." phase [macro (#+ Expander)] ["." generation]] [default ["." platform (#+ Platform)] ["." syntax]] [meta ["." archive (#+ Archive)] [packager ["." script]]]] ## ["." interpreter] ]] [/ ["." cli (#+ Service)]]) (def: (or-crash! failure-description action) (All [a] (-> Text (IO (Error a)) (IO a))) (do io.monad [?output action] (case ?output (#error.Failure error) (exec (log! (format text.new-line failure-description text.new-line error text.new-line)) (io.exit +1)) (#error.Success output) (wrap output)))) (def: (save-artifacts! system state) (All [anchor expression statement] (-> (file.System IO) (statement.State+ anchor expression statement) (IO (Error Any)))) (let [?outcome (phase.run' state (:share [anchor expression statement] {(statement.State+ anchor expression statement) state} {(statement.Operation anchor expression statement (generation.Output statement)) (statement.lift-generation generation.output)}))] (case ?outcome (#error.Success [state output]) (do (error.with io.monad) [file (: (IO (Error (File IO))) (file.get-file io.monad system "program.js"))] (!.use (:: file over-write) (script.package output))) (#error.Failure error) (:: io.monad wrap (#error.Failure error))))) (def: #export (compiler expander platform bundle program service) (All [anchor expression statement] (-> Expander (IO (Platform IO anchor expression statement)) (generation.Bundle anchor expression statement) (-> expression statement) Service (IO Any))) (do io.monad [platform platform console (:: @ map error.assume console.system)] (case service (#cli.Compilation configuration) (<| (or-crash! "Compilation failed:") (do (error.with io.monad) [state (:share [anchor expression statement] {(Platform IO anchor expression statement) platform} {(IO (Error (statement.State+ anchor expression statement))) (platform.initialize expander platform bundle program)}) [archive state] (:share [anchor expression statement] {(Platform IO anchor expression statement) platform} {(IO (Error [Archive (statement.State+ anchor expression statement)])) (platform.compile expander platform configuration archive.empty state)}) _ (save-artifacts! (get@ #platform.&file-system platform) state) ## _ (cache/io.clean target ...) ] (wrap (log! "Compilation complete!")))) (#cli.Interpretation configuration) ## TODO: Fix the interpreter... (undefined) ## (<| (or-crash! "Interpretation failed:") ## (interpreter.run (error.with io.monad) console platform configuration bundle)) )))