From 5d9fe393959c4c9c9bcbd04cef3115f7f834612f Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 18 Sep 2019 19:20:50 -0400 Subject: Added packaging machinery for the JVM compiler. --- .../source/lux/tool/compiler/default/platform.lux | 24 +++++++++++-- .../source/lux/tool/compiler/meta/packager/js.lux | 36 +++++++++++++++++++ .../lux/tool/compiler/meta/packager/script.lux | 41 ---------------------- stdlib/source/program/compositor.lux | 20 ++++++----- 4 files changed, 68 insertions(+), 53 deletions(-) create mode 100644 stdlib/source/lux/tool/compiler/meta/packager/js.lux delete mode 100644 stdlib/source/lux/tool/compiler/meta/packager/script.lux (limited to 'stdlib/source') diff --git a/stdlib/source/lux/tool/compiler/default/platform.lux b/stdlib/source/lux/tool/compiler/default/platform.lux index 4ed6d6d42..04937092a 100644 --- a/stdlib/source/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/lux/tool/compiler/default/platform.lux @@ -24,7 +24,7 @@ [macro (#+ Expander)] ## TODO: Get rid of this import ASAP [extension (#+)] - ["." generation] + ["." generation (#+ Buffer)] [analysis ["." module]]] [meta @@ -67,8 +67,26 @@ (///directive.Bundle anchor expression directive) (-> expression directive) (! (Try )))) - (|> platform - (get@ #runtime) + (|> (do ///phase.monad + [_ (:share [anchor expression directive] + {(///directive.Bundle anchor expression directive) + host-directive-bundle} + {(generation.Operation anchor expression directive Any) + (generation.set-buffer (:share [anchor expression directive] + {(///directive.Bundle anchor expression directive) + host-directive-bundle} + {(Buffer directive) + generation.empty-buffer}))}) + _ (:share [anchor expression directive] + {(///directive.Bundle anchor expression directive) + host-directive-bundle} + {(generation.Operation anchor expression directive Any) + (get@ #runtime platform)})] + (:share [anchor expression directive] + {(///directive.Bundle anchor expression directive) + host-directive-bundle} + {(generation.Operation anchor expression directive Any) + (generation.save-buffer! "")})) ///directive.lift-generation (///phase.run' (//init.state target expander diff --git a/stdlib/source/lux/tool/compiler/meta/packager/js.lux b/stdlib/source/lux/tool/compiler/meta/packager/js.lux new file mode 100644 index 000000000..e4c52af5a --- /dev/null +++ b/stdlib/source/lux/tool/compiler/meta/packager/js.lux @@ -0,0 +1,36 @@ +(.module: + [lux #* + [control + [pipe (#+ case>)] + ["." function]] + [data + [binary (#+ Binary)] + ["." product] + ["." text + ["." encoding]] + [collection + ["." row] + ["." list ("#@." monad fold)]]] + [target + ["_" js]] + [tool + [compiler + [phase + [generation (#+ Output)]]]]]) + +(def: #export (package outputs) + (-> (Output _.Statement) Binary) + (|> outputs + row.to-list + (list@map (|>> product.right + row.to-list + (list@map product.right))) + list@join + (case> (#.Cons head tail) + (|> (list@fold (function.flip _.then) head tail) + (: _.Statement) + _.code + encoding.to-utf8) + + #.Nil + (encoding.to-utf8 "")))) diff --git a/stdlib/source/lux/tool/compiler/meta/packager/script.lux b/stdlib/source/lux/tool/compiler/meta/packager/script.lux deleted file mode 100644 index 8e7988f37..000000000 --- a/stdlib/source/lux/tool/compiler/meta/packager/script.lux +++ /dev/null @@ -1,41 +0,0 @@ -(.module: - [lux #* - [control - [pipe (#+ case>)]] - [data - [binary (#+ Binary)] - ["." product] - ["." text - ["." encoding]] - [collection - ["." row] - ["." list ("#@." monad fold)]]] - [target - ["_" js]] - [tool - [compiler - [phase - [generation (#+ Output)]]]]]) - -(def: #export (package outputs) - (All [statements] - (-> (Output statements) Binary)) - (|> outputs - row.to-list - (list@map (function (_ [module buffer]) - (|> buffer - row.to-list - (:coerce (List [Name _.Statement])) - (list@map product.right)))) - list@join - (case> (#.Cons head tail) - (|> (list@fold (function (_ post! pre!) - (_.then pre! post!)) - head - tail) - (: _.Statement) - _.code - encoding.to-utf8) - - #.Nil - (encoding.to-utf8 "")))) diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux index 1725e80e5..b9b2995ad 100644 --- a/stdlib/source/program/compositor.lux +++ b/stdlib/source/program/compositor.lux @@ -11,6 +11,7 @@ [security ["!" capability]]] [data + [binary (#+ Binary)] ["." product] ["." text ["%" format (#+ format)]] @@ -21,7 +22,7 @@ [time ["." instant (#+ Instant)]] [world - ["." file (#+ File)] + ["." file (#+ File Path)] ["." console]] [tool [compiler @@ -34,9 +35,7 @@ ["." platform (#+ Platform)] ["." syntax]] [meta - ["." archive (#+ Archive)] - [packager - ["." script]]]] + ["." archive (#+ Archive)]]] ## ["." interpreter] ]] [/ @@ -57,10 +56,11 @@ (#try.Success output) (wrap output)))) -(def: (save-artifacts! system state) +(def: (save-artifacts! system state [packager package]) (All [anchor expression directive] (-> (file.System IO) (directive.State+ anchor expression directive) + [(-> (generation.Output directive) Binary) Path] (IO (Try Any)))) (let [?outcome (phase.run' state (:share [anchor expression directive] @@ -73,13 +73,14 @@ (#try.Success [state output]) (do (try.with io.monad) [file (: (IO (Try (File IO))) - (file.get-file io.monad system "program.js"))] - (!.use (:: file over-write) (script.package output))) + (file.get-file io.monad system package))] + (!.use (:: file over-write) (packager output))) (#try.Failure error) (:: io.monad wrap (#try.Failure error))))) -(def: #export (compiler target partial-host-extension expander host-analysis platform generation-bundle host-directive-bundle program service) +(def: #export (compiler target partial-host-extension expander host-analysis platform generation-bundle host-directive-bundle program service + packager,package) (All [anchor expression directive] (-> Text Text @@ -90,6 +91,7 @@ (directive.Bundle anchor expression directive) (-> expression directive) Service + [(-> (generation.Output directive) Binary) Path] (IO Any))) (do io.monad [platform platform @@ -108,7 +110,7 @@ platform} {(IO (Try [Archive (directive.State+ anchor expression directive)])) (platform.compile partial-host-extension expander platform configuration archive.empty state)}) - _ (save-artifacts! (get@ #platform.&file-system platform) state) + _ (save-artifacts! (get@ #platform.&file-system platform) state packager,package) ## _ (cache/io.clean target ...) ] (wrap (log! "Compilation complete!")))) -- cgit v1.2.3