From d98d1cb26f8cd3aa49f9c1e9f461ae0ee176df7c Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 13 Mar 2019 19:55:56 -0400 Subject: The general shape of the compiler has been recognized as a program unto itself (albeit a program which must be parameterized). --- stdlib/source/lux/tool/compiler/cli.lux | 43 ---------- .../source/lux/tool/compiler/default/platform.lux | 6 +- stdlib/source/lux/tool/compiler/program.lux | 96 ---------------------- stdlib/source/program/compositor.lux | 96 ++++++++++++++++++++++ stdlib/source/program/compositor/cli.lux | 43 ++++++++++ 5 files changed, 143 insertions(+), 141 deletions(-) delete mode 100644 stdlib/source/lux/tool/compiler/cli.lux delete mode 100644 stdlib/source/lux/tool/compiler/program.lux create mode 100644 stdlib/source/program/compositor.lux create mode 100644 stdlib/source/program/compositor/cli.lux (limited to 'stdlib') diff --git a/stdlib/source/lux/tool/compiler/cli.lux b/stdlib/source/lux/tool/compiler/cli.lux deleted file mode 100644 index e08c83c7e..000000000 --- a/stdlib/source/lux/tool/compiler/cli.lux +++ /dev/null @@ -1,43 +0,0 @@ -(.module: - [lux #* - [control - ["p" parser]] - ["." cli (#+ CLI)] - [world - [file (#+ Path)]]] - ## [/// - ## [importer (#+ Source)]] - ) - -(type: #export Configuration - {## #sources (List Source) - #sources (List Path) - #target Path - #module Text}) - -(type: #export Service - (#Compilation Configuration) - (#Interpretation Configuration)) - -(do-template [ ] - [(def: #export - (CLI Text) - (cli.named cli.any))] - - [source "--source"] - [target "--target"] - [module "--module"] - ) - -(def: #export configuration - (CLI Configuration) - ($_ p.and - (p.some ..source) - ..target - ..module)) - -(def: #export service - (CLI Service) - ($_ p.or - (p.after (cli.this "build") ..configuration) - (p.after (cli.this "repl") ..configuration))) diff --git a/stdlib/source/lux/tool/compiler/default/platform.lux b/stdlib/source/lux/tool/compiler/default/platform.lux index 529a4ed79..7748db721 100644 --- a/stdlib/source/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/lux/tool/compiler/default/platform.lux @@ -24,12 +24,14 @@ ["." generation] [analysis ["." module]]] - ["." cli (#+ Configuration)] [meta ["." archive (#+ Archive) [descriptor (#+ Module)]] [io - ["." context]]]]]) + ["." context]]]]] + [program + [compositor + ["." cli (#+ Configuration)]]]) (type: #export (Platform ! anchor expression statement) {#&monad (Monad !) diff --git a/stdlib/source/lux/tool/compiler/program.lux b/stdlib/source/lux/tool/compiler/program.lux deleted file mode 100644 index 4a079cc0f..000000000 --- a/stdlib/source/lux/tool/compiler/program.lux +++ /dev/null @@ -1,96 +0,0 @@ -(.module: - [lux #* - [type (#+ :share)] - [cli (#+ program:)] - ["." io (#+ IO io)] - [control - [monad (#+ do)]] - [data - ["." error (#+ Error)] - ["." text - format]] - [time - ["." instant (#+ Instant)]] - [world - ["." console]] - [tool - [compiler - ["." statement] - [phase - [macro (#+ Expander)] - ["." generation]] - [default - ["." platform (#+ Platform)] - ["." syntax]] - [meta - ["." archive (#+ Archive)]]] - ## ["." interpreter] - ]] - [// - ["." cli (#+ Service)]]) - -(def: (or-crash! failure-description action) - (All [a] - (-> Text (IO (Error a)) (IO a))) - (do io.monad - [?output action] - (case ?output - (#error.Failure error) - (exec (log! (format text.new-line - failure-description text.new-line - error text.new-line)) - (io.exit +1)) - - (#error.Success output) - (wrap output)))) - -(def: (timed action) - (All [a] - (-> (-> Any (IO (Error a))) (IO (Error a)))) - (do (error.with io.monad) - [start (: (IO (Error Instant)) - (error.lift io.monad instant.now)) - result (action []) - finish (: (IO (Error Instant)) - (error.lift io.monad instant.now)) - #let [elapsed-time (instant.span start finish) - _ (log! (format text.new-line - "Elapsed time: " (%duration elapsed-time)))]] - (wrap result))) - -(def: #export (compiler expander platform bundle service) - (All [anchor expression statement] - (-> Expander - (IO (Platform IO anchor expression statement)) - (generation.Bundle anchor expression statement) - Service - (IO Any))) - (do io.monad - [platform platform - console (:: @ map error.assume console.system)] - (case service - (#cli.Compilation configuration) - (<| (or-crash! "Compilation failed:") - ..timed - (function (_ _) - (do (error.with io.monad) - [state (:share [anchor expression statement] - {(Platform IO anchor expression statement) - platform} - {(IO (Error (statement.State+ anchor expression statement))) - (platform.initialize expander platform bundle)}) - _ (:share [anchor expression statement] - {(Platform IO anchor expression statement) - platform} - {(IO (Error [Archive (statement.State+ anchor expression statement)])) - (platform.compile expander platform configuration archive.empty state)}) - ## _ (cache/io.clean target ...) - ] - (wrap (log! "Compilation complete!"))))) - - (#cli.Interpretation configuration) - ## TODO: Fix the interpreter... - (undefined) - ## (<| (or-crash! "Interpretation failed:") - ## (interpreter.run (error.with io.monad) console platform configuration bundle)) - ))) diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux new file mode 100644 index 000000000..5fb90837f --- /dev/null +++ b/stdlib/source/program/compositor.lux @@ -0,0 +1,96 @@ +(.module: + [lux #* + [type (#+ :share)] + [cli (#+ program:)] + ["." io (#+ IO io)] + [control + [monad (#+ do)]] + [data + ["." error (#+ Error)] + ["." text + format]] + [time + ["." instant (#+ Instant)]] + [world + ["." console]] + [tool + [compiler + ["." statement] + [phase + [macro (#+ Expander)] + ["." generation]] + [default + ["." platform (#+ Platform)] + ["." syntax]] + [meta + ["." archive (#+ Archive)]]] + ## ["." interpreter] + ]] + [/ + ["." cli (#+ Service)]]) + +(def: (or-crash! failure-description action) + (All [a] + (-> Text (IO (Error a)) (IO a))) + (do io.monad + [?output action] + (case ?output + (#error.Failure error) + (exec (log! (format text.new-line + failure-description text.new-line + error text.new-line)) + (io.exit +1)) + + (#error.Success output) + (wrap output)))) + +(def: (timed action) + (All [a] + (-> (-> Any (IO (Error a))) (IO (Error a)))) + (do (error.with io.monad) + [start (: (IO (Error Instant)) + (error.lift io.monad instant.now)) + result (action []) + finish (: (IO (Error Instant)) + (error.lift io.monad instant.now)) + #let [elapsed-time (instant.span start finish) + _ (log! (format text.new-line + "Elapsed time: " (%duration elapsed-time)))]] + (wrap result))) + +(def: #export (compiler expander platform bundle service) + (All [anchor expression statement] + (-> Expander + (IO (Platform IO anchor expression statement)) + (generation.Bundle anchor expression statement) + Service + (IO Any))) + (do io.monad + [platform platform + console (:: @ map error.assume console.system)] + (case service + (#cli.Compilation configuration) + (<| (or-crash! "Compilation failed:") + ..timed + (function (_ _) + (do (error.with io.monad) + [state (:share [anchor expression statement] + {(Platform IO anchor expression statement) + platform} + {(IO (Error (statement.State+ anchor expression statement))) + (platform.initialize expander platform bundle)}) + _ (:share [anchor expression statement] + {(Platform IO anchor expression statement) + platform} + {(IO (Error [Archive (statement.State+ anchor expression statement)])) + (platform.compile expander platform configuration archive.empty state)}) + ## _ (cache/io.clean target ...) + ] + (wrap (log! "Compilation complete!"))))) + + (#cli.Interpretation configuration) + ## TODO: Fix the interpreter... + (undefined) + ## (<| (or-crash! "Interpretation failed:") + ## (interpreter.run (error.with io.monad) console platform configuration bundle)) + ))) diff --git a/stdlib/source/program/compositor/cli.lux b/stdlib/source/program/compositor/cli.lux new file mode 100644 index 000000000..e08c83c7e --- /dev/null +++ b/stdlib/source/program/compositor/cli.lux @@ -0,0 +1,43 @@ +(.module: + [lux #* + [control + ["p" parser]] + ["." cli (#+ CLI)] + [world + [file (#+ Path)]]] + ## [/// + ## [importer (#+ Source)]] + ) + +(type: #export Configuration + {## #sources (List Source) + #sources (List Path) + #target Path + #module Text}) + +(type: #export Service + (#Compilation Configuration) + (#Interpretation Configuration)) + +(do-template [ ] + [(def: #export + (CLI Text) + (cli.named cli.any))] + + [source "--source"] + [target "--target"] + [module "--module"] + ) + +(def: #export configuration + (CLI Configuration) + ($_ p.and + (p.some ..source) + ..target + ..module)) + +(def: #export service + (CLI Service) + ($_ p.or + (p.after (cli.this "build") ..configuration) + (p.after (cli.this "repl") ..configuration))) -- cgit v1.2.3