diff options
author | Eduardo Julian | 2020-04-16 00:22:24 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-04-16 00:22:24 -0400 |
commit | 1888b5c3288e4e7653a424e7314ea5c8277ab360 (patch) | |
tree | a40768d314bc610f9c17446d86e33eba44d5e6c8 /stdlib | |
parent | 4f1553c6f6bb579f09749d5b9ca955c43a7440a4 (diff) |
Generating definition names in a new way.
Diffstat (limited to 'stdlib')
14 files changed, 93 insertions, 58 deletions
diff --git a/stdlib/source/lux/control/exception.lux b/stdlib/source/lux/control/exception.lux index ed200189c..85236b6fa 100644 --- a/stdlib/source/lux/control/exception.lux +++ b/stdlib/source/lux/control/exception.lux @@ -146,7 +146,7 @@ (|> "-" (list.repeat 64) (text.join-with "")) text.new-line text.new-line)) -(def: #export (decorate prelude error) +(def: (decorate prelude error) (-> Text Text Text) ($_ "lux text concat" prelude diff --git a/stdlib/source/lux/debug.lux b/stdlib/source/lux/debug.lux index db18eb37e..bac74880f 100644 --- a/stdlib/source/lux/debug.lux +++ b/stdlib/source/lux/debug.lux @@ -60,7 +60,7 @@ (import: Array (#static isArray [.Any] host.Boolean)))}))) -(type: Inspector (-> Any Text)) +(def: Inspector (-> Any Text)) (def: (inspect-tuple inspect) (-> Inspector Inspector) diff --git a/stdlib/source/lux/tool/compiler/default/init.lux b/stdlib/source/lux/tool/compiler/default/init.lux index 19a71742c..0b0acd8b0 100644 --- a/stdlib/source/lux/tool/compiler/default/init.lux +++ b/stdlib/source/lux/tool/compiler/default/init.lux @@ -115,15 +115,16 @@ (All [anchor expression directive] (///directive.Operation anchor expression directive [Source (///generation.Buffer directive)]))) - (///directive.lift-analysis - (do ///phase.monad - [#let [module (get@ #///.module input)] - _ (module.create hash module) - _ (///analysis.set-current-module module) - _ (monad.map @ module.import dependencies) - #let [source (///analysis.source (get@ #///.module input) (get@ #///.code input))] - _ (///analysis.set-source-code source)] - (wrap [source ///generation.empty-buffer])))) + (do ///phase.monad + [#let [module (get@ #///.module input)] + _ (///directive.set-current-module module)] + (///directive.lift-analysis + (do ///phase.monad + [_ (module.create hash module) + _ (monad.map @ module.import dependencies) + #let [source (///analysis.source (get@ #///.module input) (get@ #///.code input))] + _ (///analysis.set-source-code source)] + (wrap [source ///generation.empty-buffer]))))) (def: (end module) (-> Module @@ -194,7 +195,7 @@ (#try.Failure error) (if (ex.match? ///syntax.end-of-file error) (#try.Success [state #.None]) - (ex.with-stack ///.cannot-compile module (#try.Failure error))))))) + (ex.with ///.cannot-compile module (#try.Failure error))))))) (def: (default-dependencies prelude input) (-> Module ///.Input (List Module)) @@ -255,7 +256,9 @@ macro.current-module) _ (///directive.lift-generation (///generation.set-buffer temporary-buffer)) - _ (monad.map @ (execute! archive) (get@ #///directive.referrals requirements)) + _ (|> requirements + (get@ #///directive.referrals) + (monad.map @ (execute! archive))) temporary-buffer (..get-current-buffer temporary-buffer)] (..iterate archive expander module source temporary-buffer (..module-aliases analysis-module))))))})]) )))))})))) diff --git a/stdlib/source/lux/tool/compiler/default/platform.lux b/stdlib/source/lux/tool/compiler/default/platform.lux index 51f4729c5..f51711289 100644 --- a/stdlib/source/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/lux/tool/compiler/default/platform.lux @@ -216,8 +216,7 @@ _ ## TODO: The "///analysis.set-current-module" below shouldn't be necessary. Remove it ASAP. ## TODO: The context shouldn't need to be re-set either. - (|> (///analysis.set-current-module module) - ///directive.lift-analysis + (|> (///directive.set-current-module module) (///phase.run' state) try.assume product.left)) diff --git a/stdlib/source/lux/tool/compiler/language/lux/analysis.lux b/stdlib/source/lux/tool/compiler/language/lux/analysis.lux index 6c081620c..8537064a4 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/analysis.lux @@ -343,15 +343,14 @@ (def: #export (with-stack exception message action) (All [e o] (-> (Exception e) e (Operation o) (Operation o))) (function (_ bundle,state) - (case (action bundle,state) + (case (exception.with exception message + (action bundle,state)) (#try.Success output) (#try.Success output) (#try.Failure error) (let [[bundle state] bundle,state] - (#try.Failure (<| (locate-error (get@ #.cursor state)) - (exception.decorate (exception.construct exception message)) - error)))))) + (#try.Failure (locate-error (get@ #.cursor state) error)))))) (template [<name> <type> <field> <value>] [(def: #export (<name> value) diff --git a/stdlib/source/lux/tool/compiler/language/lux/directive.lux b/stdlib/source/lux/tool/compiler/language/lux/directive.lux index 2c1dd3be6..8a5e0172a 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/directive.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/directive.lux @@ -1,5 +1,7 @@ (.module: [lux (#- Module) + [abstract + [monad (#+ do)]] [data [collection ["." list ("#@." monoid)]]]] @@ -57,16 +59,24 @@ ) (template [<name> <component> <operation>] - [(def: #export (<name> operation) + [(def: #export <name> (All [anchor expression directive output] (-> (<operation> output) (Operation anchor expression directive output))) - (extension.lift - (phase.sub [(get@ [<component> #..state]) - (set@ [<component> #..state])] - operation)))] + (|>> (phase.sub [(get@ [<component> #..state]) + (set@ [<component> #..state])]) + extension.lift))] [lift-analysis #..analysis analysis.Operation] [lift-synthesis #..synthesis synthesis.Operation] [lift-generation #..generation (generation.Operation anchor expression directive)] ) + +(def: #export (set-current-module module) + (All [anchor expression directive output] + (-> Module (Operation anchor expression directive Any))) + (do phase.monad + [_ (..lift-analysis + (analysis.set-current-module module))] + (..lift-generation + (generation.enter-module module)))) diff --git a/stdlib/source/lux/tool/compiler/language/lux/generation.lux b/stdlib/source/lux/tool/compiler/language/lux/generation.lux index 1cfd7db0f..84f4f35d4 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/generation.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/generation.lux @@ -4,7 +4,8 @@ [monad (#+ do)]] [control ["." try (#+ Try)] - ["." exception (#+ exception:)]] + ["." exception (#+ exception:)] + ["." function]] [data ["." product] ["." name ("#@." equivalence)] @@ -146,6 +147,11 @@ (-> Text (Operation anchor expression directive Text))) (:: phase.monad map (|>> %.nat (format prefix)) ..next)) +(def: #export (enter-module module) + (All [anchor expression directive] + (-> Module (Operation anchor expression directive Any))) + (extension.update (set@ #module module))) + (template [<name> <inputT>] [(def: #export (<name> label code) (All [anchor expression directive] @@ -200,9 +206,12 @@ (#try.Success [[bundle (set@ #registry registry' state)] id])))) -(exception: #export (unknown-definition {name Name}) +(exception: #export (unknown-definition {name Name} + {known-definitions (List Text)}) (exception.report - ["Name" (%.name name)])) + ["Definition" (name.short name)] + ["Module" (name.module name)] + ["Known Definitions" (exception.enumerate function.identity known-definitions)])) (def: #export (remember archive name) (All [anchor expression directive] @@ -217,7 +226,7 @@ (#try.Success (get@ #descriptor.registry descriptor))))] (case (artifact.remember _name registry) #.None - (exception.throw ..unknown-definition name) + (exception.throw ..unknown-definition [name (artifact.definitions registry)]) (#.Some id) (#try.Success [stateE [_module id]])))))) diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/function.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/function.lux index a4b94ec4e..6bf5fcf06 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/function.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/function.lux @@ -44,7 +44,7 @@ (do ///.monad [functionT (///extension.lift macro.expected-type)] (loop [expectedT functionT] - (/.with-stack cannot-analyse [expectedT function-name arg-name body] + (/.with-stack ..cannot-analyse [expectedT function-name arg-name body] (case expectedT (#.Named name unnamedT) (recur unnamedT) @@ -102,7 +102,7 @@ (def: #export (apply analyse argsC+ functionT functionA archive functionC) (-> Phase (List Code) Type Analysis Phase) - (<| (/.with-stack cannot-apply [functionT functionC argsC+]) + (<| (/.with-stack ..cannot-apply [functionT functionC argsC+]) (do ///.monad [[applyT argsA+] (//inference.general archive analyse functionT argsC+)]) (wrap (/.apply [functionA argsA+])))) diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/inference.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/inference.lux index 9a1e07d7a..76315bb6c 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/inference.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/inference.lux @@ -157,7 +157,7 @@ (#.Function inputT outputT) (do ///.monad [[outputT' args'A] (general archive analyse outputT args') - argA (<| (/.with-stack cannot-infer-argument [inputT argC]) + argA (<| (/.with-stack ..cannot-infer-argument [inputT argC]) (//type.with-type inputT) (analyse archive argC))] (wrap [outputT' (list& argA args'A)])) diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/module.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/module.lux index 1764dfdd6..9fae1fa1e 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/module.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/module.lux @@ -144,11 +144,10 @@ (-> Nat Text (Operation Any)) (///extension.lift (function (_ state) - (let [module (new hash)] - (#try.Success [(update@ #.modules - (plist.put name module) - state) - []]))))) + (#try.Success [(update@ #.modules + (plist.put name (new hash)) + state) + []])))) (def: #export (with-module hash name action) (All [a] (-> Nat Text (Operation a) (Operation [Module a]))) diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/structure.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/structure.lux index cd07f23c4..8d3c03628 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/structure.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/analysis/structure.lux @@ -94,7 +94,7 @@ [expectedT (///extension.lift macro.expected-type) expectedT' (//type.with-env (check.clean expectedT))] - (/.with-stack cannot-analyse-variant [expectedT' tag valueC] + (/.with-stack ..cannot-analyse-variant [expectedT' tag valueC] (case expectedT (#.Sum _) (let [flat (type.flatten-variant expectedT) @@ -199,7 +199,7 @@ (-> Archive Phase (List Code) (Operation Analysis)) (do ///.monad [expectedT (///extension.lift macro.expected-type)] - (/.with-stack cannot-analyse-tuple [expectedT membersC] + (/.with-stack ..cannot-analyse-tuple [expectedT membersC] (case expectedT (#.Product _) (..typed-product archive analyse membersC) diff --git a/stdlib/source/lux/tool/compiler/meta/archive.lux b/stdlib/source/lux/tool/compiler/meta/archive.lux index a7e1ffe16..edab30124 100644 --- a/stdlib/source/lux/tool/compiler/meta/archive.lux +++ b/stdlib/source/lux/tool/compiler/meta/archive.lux @@ -5,7 +5,8 @@ ["." monad (#+ do)]] [control ["." try (#+ Try)] - ["ex" exception (#+ exception:)]] + ["." exception (#+ exception:)] + ["." function]] [data ["." name] ["." text] @@ -21,15 +22,19 @@ ["." descriptor (#+ Module Descriptor)] ["." document (#+ Document)]]) -(exception: #export (unknown-document {module Module}) - (ex.report ["Module" module])) +(exception: #export (unknown-document {module Module} + {known-modules (List Module)}) + (exception.report + ["Module" module] + ["Known Modules" (exception.enumerate function.identity known-modules)])) (exception: #export (cannot-replace-document {module Module} {old (Document Any)} {new (Document Any)}) - (ex.report ["Module" module] - ["Old key" (signature.description (document.signature old))] - ["New key" (signature.description (document.signature new))])) + (exception.report + ["Module" module] + ["Old key" (signature.description (document.signature old))] + ["New key" (signature.description (document.signature new))])) (abstract: #export Archive {} @@ -46,7 +51,7 @@ (#.Some [existing-descriptor existing-document]) (if (is? document existing-document) (#try.Success archive) - (ex.throw cannot-replace-document [module existing-document document])) + (exception.throw cannot-replace-document [module existing-document document])) #.None (#try.Success (|> archive @@ -61,7 +66,8 @@ (#try.Success document) #.None - (ex.throw unknown-document [module]))) + (exception.throw ..unknown-document [module + (dictionary.keys (:representation archive))]))) (def: #export (archived? archive module) (-> Archive Module Bit) diff --git a/stdlib/source/lux/tool/compiler/meta/archive/artifact.lux b/stdlib/source/lux/tool/compiler/meta/archive/artifact.lux index 534749ace..256c10a22 100644 --- a/stdlib/source/lux/tool/compiler/meta/archive/artifact.lux +++ b/stdlib/source/lux/tool/compiler/meta/archive/artifact.lux @@ -3,6 +3,7 @@ [data ["." text] [collection + ["." list] ["." row (#+ Row)] ["." dictionary (#+ Dictionary)]]] [type @@ -46,8 +47,17 @@ (update@ #next inc) (update@ #artifacts (row.add {#id id #name (#.Some name)})) + (update@ #resolver (dictionary.put name id)) :abstraction)])) + (def: #export (definitions registry) + (-> Registry (List Text)) + (|> registry + :representation + (get@ #artifacts) + row.to-list + (list.search-all (get@ #name)))) + (def: #export (remember name registry) (-> Text Registry (Maybe ID)) (|> (:representation registry) diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux index 886582c34..371dbdec7 100644 --- a/stdlib/source/program/compositor.lux +++ b/stdlib/source/program/compositor.lux @@ -37,7 +37,7 @@ ["." syntax] ["." analysis [macro (#+ Expander)]] - ["." generation] + ["." generation (#+ Buffer)] ["." directive] [phase [extension (#+ Extender)]]]] @@ -46,8 +46,8 @@ [descriptor (#+ Module)]]]] ## ["." interpreter] ]] - [/ - ["." cli (#+ Service)]]) + ["." / #_ + ["#." cli (#+ Service)]]) (def: (or-crash! failure-description action) (All [a] @@ -90,7 +90,7 @@ ## (promise@wrap (#try.Failure error))))) (def: #export (compiler target partial-host-extension - expander host-analysis platform host module generation-bundle host-directive-bundle program extender + expander host-analysis platform host generation-bundle host-directive-bundle program extender service packager,package) (All [<parameters>] @@ -100,7 +100,6 @@ analysis.Bundle (IO (Platform <parameters>)) Host - Module (generation.Bundle <parameters>) (directive.Bundle <parameters>) (-> expression artifact) @@ -114,14 +113,15 @@ promise.future (:: @ map (|>> try.assume console.async)))] (case service - (#cli.Compilation configuration) + (#/cli.Compilation configuration) (<| (or-crash! "Compilation failed:") (do (try.with promise.monad) - [state (:share [<parameters>] - {(Platform <parameters>) - platform} - {(Promise (Try (directive.State+ <parameters>))) - (platform.initialize target host module expander host-analysis platform generation-bundle host-directive-bundle program extender)}) + [[state runtime-buffer] (:share [<parameters>] + {(Platform <parameters>) + platform} + {(Promise (Try [(directive.State+ <parameters>) + (Buffer artifact)])) + (platform.initialize target host (get@ #/cli.module configuration) expander host-analysis platform generation-bundle host-directive-bundle program extender)}) [archive state] (:share [<parameters>] {(Platform <parameters>) platform} @@ -132,7 +132,7 @@ ] (wrap (log! "Compilation complete!")))) - (#cli.Interpretation configuration) + (#/cli.Interpretation configuration) ## TODO: Fix the interpreter... (undefined) ## (<| (or-crash! "Interpretation failed:") |