diff options
author | Eduardo Julian | 2019-03-18 18:36:18 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-03-18 18:36:18 -0400 |
commit | 285de1ae1925c2b030bd96032498ccbaa6fc90c9 (patch) | |
tree | 3b1de3dc90b3f9f8b21289f37b6fb043c447fec4 /stdlib/source/lux/tool | |
parent | 0fcb373ed1cdc2750f02e5535d29569dd8ae5a5b (diff) |
Cobbled together a simple packager.
Diffstat (limited to '')
6 files changed, 147 insertions, 69 deletions
diff --git a/stdlib/source/lux/tool/compiler/default/init.lux b/stdlib/source/lux/tool/compiler/default/init.lux index 4686441f1..10476cfc5 100644 --- a/stdlib/source/lux/tool/compiler/default/init.lux +++ b/stdlib/source/lux/tool/compiler/default/init.lux @@ -1,5 +1,6 @@ (.module: [lux (#- Module) + [type (#+ :share)] [control ["." monad (#+ do)] ["ex" exception (#+ exception:)]] @@ -119,7 +120,10 @@ (///statement.Operation anchor expression statement a))) (def: (begin dependencies hash input) - (-> (List Module) Nat ///.Input (Operation Source)) + (-> (List Module) Nat ///.Input + (All [anchor expression statement] + (///statement.Operation anchor expression statement + [Source (generation.Buffer statement)]))) (///statement.lift-analysis (do ///phase.monad [#let [module (get@ #///.module input)] @@ -128,32 +132,67 @@ _ (monad.map @ module.import dependencies) #let [source (///analysis.source (get@ #///.module input) (get@ #///.code input))] _ (///analysis.set-source-code source)] - (wrap source)))) + (wrap [source generation.empty-buffer])))) -(def: end +(def: (end module) (-> Module (Operation Any)) - (|>> module.set-compiled - ///statement.lift-analysis)) + (do ///phase.monad + [_ (///statement.lift-analysis + (module.set-compiled module))] + (///statement.lift-generation + (generation.save-buffer! module)))) -(def: (iteration expander reader source) - (-> Expander Reader Source (Operation [Source Requirements])) - (let [execute! (statementP.phase expander)] - (do ///phase.monad - [[source code] (///statement.lift-analysis - (..read source reader)) - requirements (execute! code) - _ (..refresh expander)] - (wrap [source requirements])))) - -(def: (iterate expander module source) - (-> Expander Module Source (Operation (Maybe [Source Requirements]))) +## TODO: Inline ASAP +(def: (get-current-buffer old-buffer) + (All [statement] + (-> (generation.Buffer statement) + (All [anchor expression] + (///statement.Operation anchor expression statement + (generation.Buffer statement))))) + (///statement.lift-generation + generation.buffer)) + +## TODO: Inline ASAP +(def: (process-statement expander pre-buffer code) + (All [statement] + (-> Expander (generation.Buffer statement) Code + (All [anchor expression] + (///statement.Operation anchor expression statement + [Requirements (generation.Buffer statement)])))) + (do ///phase.monad + [_ (///statement.lift-generation + (generation.set-buffer pre-buffer)) + requirements (let [execute! (statementP.phase expander)] + (execute! code)) + post-buffer (..get-current-buffer pre-buffer)] + (wrap [requirements post-buffer]))) + +(def: (iteration expander reader source pre-buffer) + (All [statement] + (-> Expander Reader Source (generation.Buffer statement) + (All [anchor expression] + (///statement.Operation anchor expression statement + [Source Requirements (generation.Buffer statement)])))) + (do ///phase.monad + [[source code] (///statement.lift-analysis + (..read source reader)) + [requirements post-buffer] (process-statement expander pre-buffer code) + _ (..refresh expander)] + (wrap [source requirements post-buffer]))) + +(def: (iterate expander module source pre-buffer) + (All [statement] + (-> Expander Module Source (generation.Buffer statement) + (All [anchor expression] + (///statement.Operation anchor expression statement + (Maybe [Source Requirements (generation.Buffer statement)]))))) (do ///phase.monad [reader (///statement.lift-analysis (..reader module //syntax.no-aliases source))] (function (_ state) - (case (///phase.run' state (..iteration expander reader source)) - (#error.Success [state source&requirements]) - (#error.Success [state (#.Some source&requirements)]) + (case (///phase.run' state (..iteration expander reader source pre-buffer)) + (#error.Success [state source&requirements&buffer]) + (#error.Success [state (#.Some source&requirements&buffer)]) (#error.Failure error) (if (ex.match? //syntax.end-of-file error) @@ -177,14 +216,14 @@ #///.process (function (_ state archive) (do error.monad [#let [hash (text;hash (get@ #///.code input))] - [state source] (<| (///phase.run' state) - (..begin dependencies hash input)) + [state [source buffer]] (<| (///phase.run' state) + (..begin dependencies hash input)) #let [module (get@ #///.module input)]] (loop [iteration (<| (///phase.run' state) - (..iterate expander module source))] + (..iterate expander module source buffer))] (do @ - [[state ?source&requirements] iteration] - (case ?source&requirements + [[state ?source&requirements&buffer] iteration] + (case ?source&requirements&buffer #.None (do @ [[state analysis-module] (<| (///phase.run' state) @@ -202,8 +241,8 @@ (wrap [state (#.Right [[descriptor (document.write key analysis-module)] (dictionary.new text.hash)])])) - - (#.Some [source requirements]) + + (#.Some [source requirements buffer]) (wrap [state (#.Left {#///.dependencies (|> requirements (get@ #///statement.imports) @@ -213,7 +252,7 @@ (do ///phase.monad [_ (monad.map @ execute! (get@ #///statement.referrals requirements)) _ (..refresh expander)] - (..iterate expander module source)))))})]) + (..iterate expander module source buffer)))))})]) )))))})))) (def: #export key diff --git a/stdlib/source/lux/tool/compiler/meta/packager/script.lux b/stdlib/source/lux/tool/compiler/meta/packager/script.lux new file mode 100644 index 000000000..e51afe7a2 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/meta/packager/script.lux @@ -0,0 +1,38 @@ +(.module: + [lux #* + [data + ["." text + format + ["." encoding]] + [collection + ["." dictionary] + ["." row] + ["." list ("#@." functor fold)]]] + [host + ["_" js]] + [tool + [compiler + [phase + [generation (#+ Output)]]]] + [world + [binary (#+ Binary)]]]) + +(def: #export (package outputs) + (All [statements] + (-> (Output statements) Binary)) + (|> outputs + dictionary.entries + (list@map (function (_ [module buffer]) + (|> buffer + row.to-list + (:coerce (List [Name _.Statement])) + (list@fold (function (_ [artifact content] pre!) + (|> content + (_.comment (%name artifact)) + (_.then pre!))) + (_.comment module + _.use-strict)) + (: _.Statement) + _.code))) + (text.join-with text.new-line) + encoding.to-utf8)) diff --git a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux index 18bb58fbd..4f36ef89f 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux @@ -36,12 +36,11 @@ Synthesis (Operation anchor expression statement [Type expression Any]))) (////statement.lift-generation - (///generation.with-buffer - (do ///.monad - [codeT (generate codeS) - count ///generation.next - codeV (///generation.evaluate! (format "evaluate" (%n count)) codeT)] - (wrap [code//type codeT codeV]))))) + (do ///.monad + [codeT (generate codeS) + count ///generation.next + codeV (///generation.evaluate! (format "evaluate" (%n count)) codeT)] + (wrap [code//type codeT codeV])))) (def: (evaluate! type codeC) (All [anchor expression statement] @@ -71,11 +70,11 @@ Synthesis (Operation anchor expression statement [Type expression Text Any]))) (////statement.lift-generation - (///generation.with-buffer - (do ///.monad - [codeT (generate codeS) - codeN+V (///generation.define! name codeT)] - (wrap [code//type codeT codeN+V]))))) + (do ///.monad + [codeT (generate codeS) + [target-name value statement] (///generation.define! name codeT) + _ (///generation.save! name statement)] + (wrap [code//type codeT target-name value])))) (def: (definition name ?type codeC) (All [anchor expression statement] @@ -270,10 +269,9 @@ (-> expression statement) Synthesis (///generation.Operation anchor expression statement Any))) - (///generation.with-buffer - (do ///.monad - [programG (generate programS)] - (///generation.save! ["" ""] (program programG))))) + (do ///.monad + [programG (generate programS)] + (///generation.save! ["" ""] (program programG)))) (def: (def::program program) (All [anchor expression statement] diff --git a/stdlib/source/lux/tool/compiler/phase/generation.lux b/stdlib/source/lux/tool/compiler/phase/generation.lux index 3fe3f867b..203c5d4ab 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation.lux @@ -19,14 +19,6 @@ [// [synthesis (#+ Synthesis)]]]) -(do-template [<name>] - [(exception: #export (<name>) - "")] - - [no-active-buffer] - [no-anchor] - ) - (exception: #export (cannot-interpret {error Text}) (exception.report ["Error" error])) @@ -61,19 +53,19 @@ evaluate!) (: (-> Text statement (Error Any)) execute!) - (: (-> Name expression (Error [Text Any])) + (: (-> Name expression (Error [Text Any statement])) define!)) (type: #export (Buffer statement) (Row [Name statement])) -(type: #export (Outputs statement) (Dictionary Path (Buffer statement))) +(type: #export (Output statement) (Dictionary Path (Buffer statement))) (type: #export (State anchor expression statement) {#context Context #anchor (Maybe anchor) #host (Host expression statement) #buffer (Maybe (Buffer statement)) - #outputs (Outputs statement) + #output (Output statement) #counter Nat #name-cache (Dictionary Name Text)}) @@ -97,7 +89,7 @@ #anchor #.None #host host #buffer #.None - #outputs (dictionary.new text.hash) + #output (dictionary.new text.hash) #counter 0 #name-cache (dictionary.new name.hash)}) @@ -122,10 +114,14 @@ (extension.read (|>> (get@ #context) (get@ #scope-name)))) +(def: #export empty-buffer Buffer row.empty) + (do-template [<tag> <with-declaration> <with-type> <with-value> - <get> <get-type> <exception>] - [(def: #export <with-declaration> + <set> <get> <get-type> <exception>] + [(exception: #export <exception>) + + (def: #export <with-declaration> (All [anchor expression statement output] <with-type>) (function (_ body) (function (_ [bundle state]) @@ -146,27 +142,34 @@ (#error.Success [stateE output]) #.None - (exception.throw <exception> []))))] + (exception.throw <exception> [])))) + + (def: #export (<set> value) + (All [anchor expression statement] + (-> <get-type> (Operation anchor expression statement Any))) + (function (_ [bundle state]) + (#error.Success [[bundle (set@ <tag> (#.Some value) state)] + []])))] [#anchor (with-anchor anchor) (-> anchor (Operation anchor expression statement output) (Operation anchor expression statement output)) anchor - anchor anchor no-anchor] + set-anchor anchor anchor no-anchor] [#buffer with-buffer (-> (Operation anchor expression statement output) (Operation anchor expression statement output)) - row.empty - buffer (Buffer statement) no-active-buffer] + ..empty-buffer + set-buffer buffer (Buffer statement) no-active-buffer] ) -(def: #export outputs +(def: #export output (All [anchor expression statement] - (Operation anchor expression statement (Outputs statement))) - (extension.read (get@ #outputs))) + (Operation anchor expression statement (Output statement))) + (extension.read (get@ #output))) (def: #export next (All [anchor expression statement] @@ -194,7 +197,7 @@ (def: #export (define! name code) (All [anchor expression statement] - (-> Name expression (Operation anchor expression statement [Text Any]))) + (-> Name expression (Operation anchor expression statement [Text Any statement]))) (function (_ (^@ stateE [bundle state])) (case (:: (get@ #host state) define! name code) (#error.Success output) @@ -224,7 +227,7 @@ (-> Path (Operation anchor expression statement Any))) (do //.monad [buffer ..buffer] - (extension.update (update@ #outputs (dictionary.put target buffer))))) + (extension.update (update@ #output (dictionary.put target buffer))))) (def: #export (remember lux-name) (All [anchor expression statement] diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/loop.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/loop.lux index e0ec074d3..d905db9a2 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/js/loop.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/js/loop.lux @@ -7,7 +7,7 @@ ["." text format] [collection - ["." list ("#;." functor)]]] + ["." list ("#@." functor)]]] [host ["_" js (#+ Computation Var)]]] ["." // #_ @@ -29,7 +29,7 @@ #let [closure (_.function @scope (|> initsS+ list.enumerate - (list;map (|>> product.left (n/+ start) //case.register))) + (list@map (|>> product.left (n/+ start) //case.register))) (_.return bodyO))]] (wrap (_.apply/* closure initsO+)))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux index 5e2da39de..cb65b8b85 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux @@ -743,7 +743,7 @@ runtime//array )) -(def: #export artifact Text (format prefix ".js")) +(def: #export artifact Text prefix) (def: #export generate (Operation Any) |