(.module: [lux (#- Module) [type (#+ :share)] ["@" target (#+ Host)] [abstract [monad (#+ do)]] [control ["." io (#+ IO io)] ["." try (#+ Try)] [parser [cli (#+ program:)]] [security ["!" capability]] [concurrency ["." promise (#+ Promise) ("#@." monad)]]] [data [binary (#+ Binary)] ["." product] ["." text ["%" format (#+ format)]] [collection ["." dictionary] ["." row (#+ Row)] ["." list ("#@." functor fold)]]] [time ["." instant (#+ Instant)]] [world ["." file (#+ File Path)] ["." console]] [tool [compiler ["." phase] [default ["." platform (#+ Platform)]] [language [lux ["." syntax] ["." analysis [macro (#+ Expander)]] ["." generation (#+ Buffer)] ["." directive] [phase [extension (#+ Extender)]]]] [meta ["." archive (#+ Archive) [descriptor (#+ Module)]]]] ## ["." 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)] ## TODO: Clean-up ASAP. ## (def: (save-artifacts! system state [packager package]) ## (All [] ## (-> (file.System Promise) ## (directive.State+ ) ## [(-> (Row [Module (generation.Buffer 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@wrap (#try.Failure error))))) (def: #export (compiler target partial-host-extension expander host-analysis platform host generation-bundle host-directive-bundle program extender service packager,package) (All [] (-> Path Text Expander analysis.Bundle (IO (Platform )) Host (generation.Bundle ) (directive.Bundle ) (-> expression artifact) Extender Service [(-> (Row [Module (generation.Buffer 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 runtime-buffer] (:share [] {(Platform ) platform} {(Promise (Try [(directive.State+ ) (Buffer artifact)])) (platform.initialize target host (get@ #/cli.module configuration) expander host-analysis platform generation-bundle host-directive-bundle program extender)}) [archive state] (:share [] {(Platform ) platform} {(Promise (Try [Archive (directive.State+ )])) (platform.compile target partial-host-extension expander platform host 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)) ))))