(.module: [lux (#- Module) [type (#+ :share)] ["." debug] ["@" target] [abstract [monad (#+ Monad do)]] [control ["." io (#+ IO io)] ["." try (#+ Try)] [security ["!" capability]] [concurrency ["." promise (#+ Promise) ("#\." monad)]]] [data [binary (#+ Binary)] ["." product] ["." text ["%" format (#+ format)]] [collection ["." dictionary] ["." row (#+ Row)]]] ["." world #_ ["." file (#+ File Path)] ["#/." program] ## ["." console] ] [tool [compiler ["." phase] [default ["." platform (#+ Platform)]] [language ["$" lux ["#/." program (#+ Program)] ["." syntax] ["." analysis [macro (#+ Expander)]] ["." generation (#+ Buffer Context)] ["." directive] [phase [extension (#+ Extender)]]]] [meta [packager (#+ Packager)] [archive (#+ Archive) [descriptor (#+ Module)]] [cache ["." dependency]] [io ["ioW" archive]]]] ## ["." interpreter] ]] ["." / #_ ["#." cli (#+ Service)] ["#." static (#+ Static)] ["#." export] ["#." import]]) (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 (debug.log! (format text.new_line failure_description text.new_line error text.new_line)) (io.run (\ world/program.default exit +1))) (#try.Success output) (wrap output)))) (def: (package! monad file_system [packager package] static archive context) (All [!] (-> (Monad !) (file.System !) [Packager Path] Static Archive Context (! (Try Any)))) (for {@.old (case (packager archive context) (#try.Success content) (do (try.with monad) [package (:share [!] (Monad !) monad (! (Try (File !))) (:assume (file.get_file monad file_system package)))] (!.use (\ (:share [!] (Monad !) monad (File !) (:assume package)) over_write) [content])) (#try.Failure error) (\ monad wrap (#try.Failure error)))} ## TODO: Fix whatever type_checker bug is forcing me into this compromise... (:assume (: (Promise (Try Any)) (let [monad (:coerce (Monad Promise) monad) file_system (:coerce (file.System Promise) file_system)] (case (packager archive context) (#try.Success content) (do (try.with monad) [package (: (Promise (Try (File Promise))) (file.get_file monad file_system package))] (!.use (\ (: (File Promise) package) over_write) [content])) (#try.Failure error) (\ monad wrap (#try.Failure error)))))))) (with_expansions [ (as_is anchor expression artifact)] (def: #export (compiler static expander host_analysis platform generation_bundle host_directive_bundle program anchorT,expressionT,directiveT extender service packager,package) (All [] (-> Static Expander analysis.Bundle (IO (Platform )) (generation.Bundle ) (directive.Bundle ) (Program expression artifact) [Type Type Type] Extender Service [Packager Path] (Promise Any))) (do {! promise.monad} [platform (promise.future platform)] (case service (#/cli.Compilation compilation) (<| (or_crash! "Compilation failed:") (do (try.with promise.monad) [#let [[compilation_sources compilation_libraries compilation_target compilation_module] compilation] import (/import.import (get@ #platform.&file_system platform) compilation_libraries) [state archive] (:share [] (Platform ) platform (Promise (Try [(directive.State+ ) Archive])) (:assume (platform.initialize static compilation_module expander host_analysis platform generation_bundle host_directive_bundle program anchorT,expressionT,directiveT extender import compilation_sources))) [archive state] (:share [] (Platform ) platform (Promise (Try [Archive (directive.State+ )])) (:assume (platform.compile import static expander platform compilation [archive state]))) _ (ioW.freeze (get@ #platform.&file_system platform) static archive) program_context (promise\wrap ($/program.context archive)) _ (promise.future (..package! io.monad file.default packager,package static archive program_context))] (wrap (debug.log! "Compilation complete!")))) (#/cli.Export export) (<| (or_crash! "Export failed:") (do (try.with promise.monad) [_ (/export.export (get@ #platform.&file_system platform) export)] (wrap (debug.log! "Export complete!")))) (#/cli.Interpretation interpretation) ## TODO: Fix the interpreter... (undefined) ## (<| (or_crash! "Interpretation failed:") ## (do {! promise.monad} ## [console (|> console.default ## promise.future ## (\ ! map (|>> try.assume console.async)))] ## (interpreter.run (try.with promise.monad) console platform interpretation generation_bundle))) ))))