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