From 7497da72e833a1569dfea5fe3ab753469535f1db Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 16 May 2024 20:36:35 -0400 Subject: [PATCH] Adapting to new `List` type (part 21). --- .../bookmark/documentation/diagram.md | 1 + stdlib/source/library/lux/compiler.lux | 6 +- .../library/lux/compiler/default/init.lux | 17 ++- .../library/lux/compiler/default/platform.lux | 118 ++++++++-------- .../lux/compiler/language/lux/declaration.lux | 14 +- .../language/lux/phase/declaration.lux | 76 ++++++----- .../lux/phase/extension/analysis/jvm.lux | 2 +- .../lux/phase/extension/declaration/jvm.lux | 2 +- .../lux/phase/extension/declaration/lux.lux | 10 +- .../phase/extension/translation/jvm/host.lux | 2 +- .../language/lux/phase/synthesis/when.lux | 11 +- .../lux/compiler/language/lux/synthesis.lux | 22 +-- .../lux/compiler/language/lux/translation.lux | 14 +- .../library/lux/compiler/meta/export.lux | 1 - .../library/lux/compiler/meta/io/archive.lux | 29 ++-- .../library/lux/compiler/meta/io/context.lux | 64 ++++----- .../library/lux/compiler/meta/packager.lux | 20 ++- .../lux/compiler/meta/packager/jvm.lux | 127 +++++++++--------- .../library/lux/data/collection/list.lux | 20 ++- .../library/lux/target/jvm/type/alias.lux | 2 +- .../lux/compiler/language/lux/translation.lux | 3 +- 21 files changed, 284 insertions(+), 277 deletions(-) diff --git a/documentation/bookmark/documentation/diagram.md b/documentation/bookmark/documentation/diagram.md index 27d7a735a0..7b328adc93 100644 --- a/documentation/bookmark/documentation/diagram.md +++ b/documentation/bookmark/documentation/diagram.md @@ -1,4 +1,5 @@ # Reference +0. [Codemap: The code visualization you wished for](https://codemap.app/) 0. [Awesome Diagramming](https://github.com/shubhamgrg04/awesome-diagramming) diff --git a/stdlib/source/library/lux/compiler.lux b/stdlib/source/library/lux/compiler.lux index 6f73d3c7bb..b574999070 100644 --- a/stdlib/source/library/lux/compiler.lux +++ b/stdlib/source/library/lux/compiler.lux @@ -31,12 +31,12 @@ (Record [#module descriptor.Module #file file.Path - #hash Nat + #hash Natural #code Code])) (every .public (Compilation state document) (Record - [#dependencies (Stack descriptor.Module) + [#dependencies (List descriptor.Module) #process (-> state Archive (Try [state (Either (Compilation state document) (archive.Entry document))]))])) @@ -55,7 +55,7 @@ (Try (Compilation state document)))])) (every .public (Instancer state document) - (-> (Key document) (Stack Parameter) + (-> (Key document) (List Parameter) (Compiler state document))) (exception.the .public (cannot_compile [module]) diff --git a/stdlib/source/library/lux/compiler/default/init.lux b/stdlib/source/library/lux/compiler/default/init.lux index 9213ef654d..d7abb7d634 100644 --- a/stdlib/source/library/lux/compiler/default/init.lux +++ b/stdlib/source/library/lux/compiler/default/init.lux @@ -15,7 +15,6 @@ ["[0]" text (.use "[1]#[0]" hash)] [collection ["[0]" list (.use "[1]#[0]" functor)] - ["[0]" stack (.use "[1]#[0]" functor)] ["[0]" dictionary] ["[0]" set] ["[0]" sequence (.use "[1]#[0]" functor)]]] @@ -187,7 +186,7 @@ (the (begin dependencies hash input all_extensions) (for_any (_ anchor expression declaration) - (-> (Stack descriptor.Module) Natural ///.Input + (-> (List descriptor.Module) Natural ///.Input (Extensions anchor expression declaration) (///declaration.Operation anchor expression declaration [Source (Payload declaration)]))) @@ -199,7 +198,7 @@ _ (with_defaults module all_extensions)] (///declaration.of_analysis (do [! phase.monad] - [_ (stack.each' ! moduleA.import dependencies) + [_ (list.each' ! moduleA.import dependencies) .let [source (analysis.source (its ///.#module input) (its ///.#code input))] _ (analysis.set_source_code source)] (in [source [///translation.empty_buffer @@ -282,10 +281,10 @@ (the (default_dependencies prelude input) (-> descriptor.Module ///.Input - (Stack descriptor.Module)) + (List descriptor.Module)) (if (text.= prelude (its ///.#module input)) - (stack descriptor.runtime) - (stack descriptor.runtime prelude))) + (list descriptor.runtime) + (list descriptor.runtime prelude))) (the module_aliases (-> @type.Module @@ -349,7 +348,7 @@ .let [descriptor [descriptor.#hash hash descriptor.#name module descriptor.#file (its ///.#file input) - descriptor.#references (set.of_list text.hash (list.of_stack dependencies)) + descriptor.#references (set.of_list text.hash dependencies) descriptor.#state {.#Compiled}]]] (in [state {.#Right [[moduleM.#id (try.else moduleM.runtime (archive.id module archive)) @@ -365,7 +364,7 @@ (in [state {.#Left [///.#dependencies (|> requirements (its ///declaration.#imports) - (stack#each product.left)) + (list#each product.left)) ///.#process (function (_ state archive) (again (<| (phase.value' state) (do [! phase.monad] @@ -378,7 +377,7 @@ (///translation.set_registry temporary_registry)) _ (|> requirements (its ///declaration.#referrals) - (stack.each' ! (execute! archive))) + (list.each' ! (execute! archive))) temporary_payload (..get_current_payload extender)] (..iteration wrapper archive extender expander module source temporary_payload (..module_aliases analysis_module))))))]}])) )))))])))) diff --git a/stdlib/source/library/lux/compiler/default/platform.lux b/stdlib/source/library/lux/compiler/default/platform.lux index 2e6c4bcf2d..6598330bca 100644 --- a/stdlib/source/library/lux/compiler/default/platform.lux +++ b/stdlib/source/library/lux/compiler/default/platform.lux @@ -27,8 +27,7 @@ ["[0]" sequence (.only Sequence) (.use "[1]#[0]" mix)] ["[0]" set (.only Set)] ["[0]" list (.use "[1]#[0]" monoid functor mix) - ["[0]" property]] - ["[0]" stack (.use "[1]#[0]" monoid functor mix)]]] + ["[0]" property]]]] [macro ["[0]" expansion]] ["[0]" type (.only sharing) @@ -130,10 +129,9 @@ _ (for .python (|> entry (its archive.#output) sequence.as_list - list.as_stack - (stack.sub 128) - (stack.each' ! (stack.each' ! write_artifact!)) - (is (Action (Stack (Stack Any))))) + (list.sub 128) + (list.each' ! (list.each' ! write_artifact!)) + (is (Action (List (List Any))))) (|> entry (its archive.#output) sequence.as_list @@ -243,7 +241,7 @@ (its #phase platform))] _ (is (Future (Try Any)) (cache.enable! future.monad (its #file_system platform))) - [archive analysis_state] (ioW.thaw (stack) compilation_configuration (its #host platform) (its #file_system platform) context import compilation_sources) + [archive analysis_state] (ioW.thaw (list) compilation_configuration (its #host platform) (its #file_system platform) context import compilation_sources) .let [with_missing_extensions (is (for_any (_ ) (-> (//init.Extensions ) @@ -377,11 +375,11 @@ (Signal state)]) (every (Importer state) - (-> (Stack ///.Custom) descriptor.Module descriptor.Module + (-> (List ///.Custom) descriptor.Module descriptor.Module (Return state))) (every (Compiler state) - (-> (Stack ///.Custom) descriptor.Module (Importer state) moduleM.ID (Context state) descriptor.Module + (-> (List ///.Custom) descriptor.Module (Importer state) moduleM.ID (Context state) descriptor.Module (Return state))) (expansion.let [Lux_Context (..Context ) @@ -483,9 +481,9 @@ return))))) ... TODO: Find a better way, as this only works for the Lux compiler. - (the (updated_state archive extended_states state) + (the (updated_state archive state) (for_any (_ ) - (-> Archive (Stack ) + (-> Archive (Try ))) (do [! try.monad] [modules (is (Try (property.List @type.Module)) @@ -524,63 +522,63 @@ ... This currently assumes that all imports will be specified once in a single .using form. ... This might not be the case in the future. (the (with_new_dependencies new_dependencies all_dependencies) - (-> (Stack descriptor.Module) (Set descriptor.Module) + (-> (List descriptor.Module) (Set descriptor.Module) [(Set descriptor.Module) (Set descriptor.Module)]) (let [[all_dependencies duplicates _] (is [(Set descriptor.Module) (Set descriptor.Module) Bit] - (stack#mix (function (_ new [all duplicates seen_prelude?]) - (if (set.member? all new) - (if (text.= .prelude new) - (if seen_prelude? - [all (set.has new duplicates) seen_prelude?] - [all duplicates true]) - [all (set.has new duplicates) seen_prelude?]) - [(set.has new all) duplicates seen_prelude?])) - (is [(Set descriptor.Module) (Set descriptor.Module) Bit] - [all_dependencies ..empty (set.empty? all_dependencies)]) - new_dependencies))] + (list#mix (function (_ new [all duplicates seen_prelude?]) + (if (set.member? all new) + (if (text.= .prelude new) + (if seen_prelude? + [all (set.has new duplicates) seen_prelude?] + [all duplicates true]) + [all (set.has new duplicates) seen_prelude?]) + [(set.has new all) duplicates seen_prelude?])) + (is [(Set descriptor.Module) (Set descriptor.Module) Bit] + [all_dependencies ..empty (set.empty? all_dependencies)]) + new_dependencies))] [all_dependencies duplicates])) (the (after_imports customs import! module duplicates new_dependencies archive) (for_any (_ state) - (-> (Stack ///.Custom) (..Importer state) descriptor.Module (Set descriptor.Module) (Stack descriptor.Module) Archive - (Future (Try [Archive (Stack state) (Stack Text)])))) + (-> (List ///.Custom) (..Importer state) descriptor.Module (Set descriptor.Module) (List descriptor.Module) Archive + (Future (Try [Archive (List state) (List Text)])))) (if (set.empty? duplicates) (when new_dependencies - {.#Empty} - (by ..monad in [archive (stack) (stack)]) + (list) + (by ..monad in [archive (list) (list)]) - {.#Top _} + must_import! (do [! future.monad] [attempts (|> new_dependencies - (stack#each (import! customs module)) - (stack.all' !)) + (list#each (import! customs module)) + (list.all' !)) .let [[failures successes] (sum.partition attempts)]] (in {try.#Success [(|> successes - (stack#each product.left) - (stack#mix archive.composite archive)) - (stack#each product.right successes) + (list#each product.left) + (list#mix archive.composite archive)) + (list#each product.right successes) failures]}))) (future#in (exception.except ..cannot_import_twice [module duplicates])))) (the (after_lux_imports customs import! module duplicates new_dependencies [archive state]) (for_any (_ ) - (-> (Stack ///.Custom) Lux_Importer descriptor.Module (Set descriptor.Module) (Stack descriptor.Module) Lux_Context - (..Return [ (Stack Text)]))) + (-> (List ///.Custom) Lux_Importer descriptor.Module (Set descriptor.Module) (List descriptor.Module) Lux_Context + (..Return [ (List Text)]))) (do ..monad [[archive state/* errors] (after_imports customs import! module duplicates new_dependencies archive)] - (when errors - (stack.partial error _) + (when (list.item 0 errors) + {try.#Success error} (future#in {try.#Failure error}) - _ + else (in [archive (when state/* - {.#Empty} + (list) state - {.#Top _} - (try.trusted (..updated_state archive state/* state))) + else + (try.trusted (..updated_state archive state))) errors])))) (the (next_compilation module [archive state] compilation) @@ -606,7 +604,7 @@ (///.Compiler @type.Module))) (let [instancer (//init.compiler program global phase_wrapper extender expander .prelude (its #write platform) program_module program_definition all_extensions)] - (instancer $.key (stack)))) + (instancer $.key (list)))) (the (custom_compiler import context platform compilation_sources configuration compiler custom_key custom_binary custom_compilation) @@ -614,7 +612,7 @@ state document) (-> Import context.Context (List _io.Context) Configuration (///.Compiler @type.Module) (Key document) (Injection document) (///.Compilation state document) - (-> (Stack ///.Custom) descriptor.Module Lux_Importer moduleM.ID (..Context state) descriptor.Module + (-> (List ///.Custom) descriptor.Module Lux_Importer moduleM.ID (..Context state) descriptor.Module (..Return state)))) (function (_ customs importer import! @module [archive state] module) (loop (again [[archive state] [archive state] @@ -628,11 +626,11 @@ (expansion.let [ (these (do ! [_ (cache/archive.cache! (its #file_system platform) configuration archive)] (future#in {try.#Failure error})))] - (when errors - (stack.partial error _) + (when (list.item 0 errors) + {try.#Success error} - _ + else (when ((its ///.#process compilation) state archive) {try.#Success [state more|done]} (when more|done @@ -695,11 +693,11 @@ (expansion.let [ (these (do ! [_ (cache/archive.cache! (its #file_system platform) configuration archive)] (future#in {try.#Failure error})))] - (when errors - (stack.partial error _) + (when (list.item 0 errors) + {try.#Success error} - _ + else (when (next_compilation module [archive state] compilation) {try.#Success [state more|done]} (when more|done @@ -724,10 +722,10 @@ [input (io.read (its #file_system platform) importer import - (list.as_stack compilation_sources) + compilation_sources (its context.#host_module_extension context) module)] - (loop (again [customs all_customs]) + (loop (again [customs (list.as_stack all_customs)]) (when customs {.#Empty} ((..lux_compiler import context platform compilation_sources configuration compiler (compiler input)) @@ -735,19 +733,19 @@ {.#Top [custom_state custom_key custom_binary custom_of custom_compiler] tail} (when (custom_compiler input) - {try.#Failure _} - (again tail) - {try.#Success custom_compilation} (do ! [[archive' custom_state'] ((..custom_compiler import context platform compilation_sources configuration compiler custom_key custom_binary custom_compilation) all_customs importer import! @module [archive custom_state] module)] - (in [archive' lux_state])))))))) + (in [archive' lux_state])) + + {try.#Failure _} + (again tail))))))) (the .public Custom Type - (type (-> (Stack Text) + (type (-> (List Text) (Try ///.Custom)))) (exception.the .public (invalid_custom_compiler [definition type]) @@ -760,11 +758,11 @@ (the (custom import! it) (for_any (_ ) (-> Lux_Importer compiler.Compiler - (Future (Try [Lux_Context (Stack Text) Any])))) + (Future (Try [Lux_Context (List Text) Any])))) (let [/#definition (its compiler.#definition it) [/#module /#name] /#definition] (do ..monad - [context (import! (stack) descriptor.runtime /#module) + [context (import! (list) descriptor.runtime /#module) .let [[archive state] context analysis_state (its [///declaration.#analysis ///declaration.#state] @@ -774,7 +772,7 @@ (phase.value analysis_state) future#in)] (future#in (if (check.< ..Custom /#type) - {try.#Success [context (list.as_stack (its compiler.#parameters it)) /#value]} + {try.#Success [context (its compiler.#parameters it) /#value]} (exception.except ..invalid_custom_compiler [/#definition /#type])))))) (the .public (compile program global lux_compiler phase_wrapper import file_context extender expander platform compilation context @@ -798,5 +796,5 @@ lux_compiler (function.on parameters)))))) (list.all' !))] - (import! (list.as_stack customs) descriptor.runtime program_module)))) + (import! customs descriptor.runtime program_module)))) ))))) diff --git a/stdlib/source/library/lux/compiler/language/lux/declaration.lux b/stdlib/source/library/lux/compiler/language/lux/declaration.lux index aeecc42f5b..8149c1b579 100644 --- a/stdlib/source/library/lux/compiler/language/lux/declaration.lux +++ b/stdlib/source/library/lux/compiler/language/lux/declaration.lux @@ -11,7 +11,7 @@ ["[0]" try]] [data [collection - ["[0]" stack (.use "[1]#[0]" monoid)]]] + ["[0]" list (.use "[1]#[0]" monoid)]]] [macro ["[0]" template]]]] [// @@ -48,19 +48,19 @@ (every .public Requirements (Record - [#imports (Stack Import) - #referrals (Stack @type.Code)])) + [#imports (List Import) + #referrals (List @type.Code)])) (the .public no_requirements Requirements - [#imports (stack) - #referrals (stack)]) + [#imports (list) + #referrals (list)]) (the .public (merge_requirements left right) (-> Requirements Requirements Requirements) - [#imports (stack#composite (its #imports left) (its #imports right)) - #referrals (stack#composite (its #referrals left) (its #referrals right))]) + [#imports (list#composite (its #imports left) (its #imports right)) + #referrals (list#composite (its #referrals left) (its #referrals right))]) (every .public (Operation anchor expression declaration) (phase.Operation (State anchor expression declaration))) diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/declaration.lux b/stdlib/source/library/lux/compiler/language/lux/phase/declaration.lux index ea85a4c3eb..d92ae912af 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/declaration.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/declaration.lux @@ -12,8 +12,7 @@ [data ["[0]" text] [collection - ["[0]" list] - ["[0]" stack (.use "[1]#[0]" mix monoid)]]] + ["[0]" list (.use "[1]#[0]" mix monoid)]]] [macro ["^" pattern] ["[0]" expansion]] @@ -45,21 +44,19 @@ (the (requiring phase archive expansion) (for_any (_ anchor expression declaration) - (-> (Phase anchor expression declaration) Archive (Stack @type.Code) + (-> (Phase anchor expression declaration) Archive (List @type.Code) (Operation anchor expression declaration /.Requirements))) - (when expansion - {.#Empty} - (//#in /.no_requirements) - - {.#Top head tail} - (do //.monad - [head' (phase archive head) - tail' (requiring phase archive tail)] - (in (/.merge_requirements head' tail'))))) + (list.mix' //.monad + (function (_ head tail) + (by //.monad each + (/.merge_requirements tail) + (phase archive head))) + /.no_requirements + expansion)) (every Outcome (Variant - {#More (Stack @type.Code)} + {#More (List @type.Code)} {#Done /.Requirements})) (the (macro_or_extension analysis archive whole_term function_term) @@ -99,6 +96,14 @@ (//.except ..not_a_declaration [here function_term])) (//.except ..not_a_declaration [here function_term]))))) +(the (failure code) + (-> Code + Operation) + (do //.monad + [here (<| /.of_analysis + module.current_name)] + (//.except ..not_a_declaration [here code]))) + (expansion.let [ (these {@type.#Form @module (list {@type.#Name @extension [..prelude "module#"]} {@type.#Tuple @annotations annotations})})] @@ -117,43 +122,40 @@ (its [/.#translation /.#phase] state)]) archive) extension_eval (as (-> Any @type.Eval) - (wrapper (as_expected compiler_eval))) - failure (do ! - [here (<| /.of_analysis - module.current_name)] - (//.except ..not_a_declaration [here code]))] + (wrapper (as_expected compiler_eval)))] _ (//.with (has [/.#analysis /.#state @type.#eval] extension_eval state))] (when code {@type.#Form _ it} - (when (list.as_stack it) - (stack.partial term inputs) + (when (list.item 0 it) + {try.#Success term} (do ! [macro|extension (macro_or_extension analysis archive code term) - expansion|requirements (extension.reification extender - (its [/.#analysis /.#state] state) again archive - .Declaration macro|extension (list.of_stack inputs) - (|>> {#Done}) - (function (_ _) - {.#Some (<| /.of_analysis - (do ! - [macro (binding.macro macro|extension) - expansion (analysis/macro.expansion expander macro|extension macro (list.of_stack inputs))] - (in {#More (list.as_stack expansion)})))}))] + expansion|requirements (let [inputs (list.after 1 it)] + (extension.reification extender + (its [/.#analysis /.#state] state) again archive + .Declaration macro|extension inputs + (|>> {#Done}) + (function (_ _) + {.#Some (<| /.of_analysis + (do ! + [macro (binding.macro macro|extension) + expansion (analysis/macro.expansion expander macro|extension macro inputs)] + (in {#More expansion})))})))] (when expansion|requirements - {.#Left expansion} - (when expansion - (stack.partial referrals) + {#More expansion} + (when (list.item 0 expansion) + {try.#Success } (|> (again archive ) - (by ! each (revised /.#referrals (stack#composite referrals)))) + (by ! each (revised /.#referrals (list#composite (list.after 1 expansion))))) _ (..requiring again archive expansion)) - {.#Right requirements} + {#Done requirements} (in requirements))) _ - failure) + (..failure code)) _ - failure))))) + (..failure code)))))) diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/library/lux/compiler/language/lux/phase/extension/analysis/jvm.lux index 00f989c0f6..3a526f75c4 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/extension/analysis/jvm.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/extension/analysis/jvm.lux @@ -3,7 +3,7 @@ (.using [library - [lux (.except Type Module Declaration Integer Double Parameter + [lux (.except Type Module Declaration Integer Double Parameter Array #Default #Variable type with argument) ["[0]" ffi (.only import)] diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/jvm.lux b/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/jvm.lux index 415061526e..b462a7ac98 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/jvm.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/jvm.lux @@ -3,7 +3,7 @@ (.using [library - [lux (.except Type Definition Declaration Parameter + [lux (.except Type Definition Declaration Parameter Array #Variable) ["[0]" ffi (.only import)] [abstract diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/lux.lux b/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/lux.lux index 370371c27f..7e353d3ad0 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/lux.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/lux.lux @@ -23,7 +23,7 @@ ["[0]" array] ["[0]" list (.use "[1]#[0]" functor mix) ["?[1]" \\projection]] - ["[0]" stack (.use "[1]#[0]" functor mix)] + ["[0]" sequence (.use "[1]#[0]" mix)] ["[0]" set (.only Set)]]] [math [number @@ -134,13 +134,13 @@ .let [@abstraction (when codeS (synthesis.abstraction @ [env arity body]) (|> interim_artifacts - stack.last + (sequence.item 0) (maybe#each (|>> [arity]))) _ {.#None})] @module (phase.of_try (archive.id module archive)) - @self (/////translation.learn [name @abstraction] false (stack#mix set.has dependencies interim_artifacts)) + @self (/////translation.learn [name @abstraction] false (sequence#mix set.has dependencies interim_artifacts)) [target_name value declaration] (/////translation.define! [@module @self] {.#None} [(maybe#each product.right @abstraction) codeG]) _ (/////translation.save! @self {.#None} declaration)] (in [code//type codeG value])))) @@ -244,8 +244,8 @@ "" (in []) _ (module.alias alias module)))) imports))] - (in [/////declaration.#imports (list.as_stack imports) - /////declaration.#referrals (stack)])))])) + (in [/////declaration.#imports imports + /////declaration.#referrals (list)])))])) (the .public bundle Bundle diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/extension/translation/jvm/host.lux b/stdlib/source/library/lux/compiler/language/lux/phase/extension/translation/jvm/host.lux index 591db117e4..10d5e2df72 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/extension/translation/jvm/host.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/extension/translation/jvm/host.lux @@ -3,7 +3,7 @@ (.using [library - [lux (.except Type Parameter + [lux (.except Type Parameter Array argument) [abstract [monad (.only do)] diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/synthesis/when.lux b/stdlib/source/library/lux/compiler/language/lux/phase/synthesis/when.lux index d0f091ec76..3af445a6fe 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/synthesis/when.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/synthesis/when.lux @@ -18,7 +18,6 @@ ["[0]" text] [collection ["[0]" list (.use "[1]#[0]" functor mix monoid)] - ["[0]" stack (.use "[1]#[0]" mix)] ["[0]" set (.only Set)]]] [math [number @@ -259,7 +258,7 @@ (template.macro (_ <@> ) [[[{///pattern.#Bind } [<@> {analysis.#Reference (///reference.local )}]] - (stack)]])) + (list)]])) (the .public (synthesize_masking synthesize @ archive input @variable @output) (-> Phase Provenance Archive /.Term Register Register @@ -271,17 +270,17 @@ (synthesize archive [@ {analysis.#Reference (///reference.local @output)}]))] (in (/.let @ @variable input body))))) -(the .public (synthesize @ synthesize^ [headB tailB+] archive inputA) +(the .public (synthesize @ synthesize^ head,tail archive inputA) (-> Provenance Phase Match Phase) (do [! phase.monad] [inputS (synthesize^ archive inputA)] - (when [headB (list.as_stack tailB+)] + (when head,tail (!masking @ @variable @output) (..synthesize_masking synthesize^ @ archive inputS @variable @output) - [head tail] - (..synthesize_when synthesize^ @ archive inputS [head (list.of_stack tail)])))) + else + (..synthesize_when synthesize^ @ archive inputS head,tail)))) (the .public (count_pops path) (-> Path diff --git a/stdlib/source/library/lux/compiler/language/lux/synthesis.lux b/stdlib/source/library/lux/compiler/language/lux/synthesis.lux index 502cbb7ad8..f33c89a3dc 100644 --- a/stdlib/source/library/lux/compiler/language/lux/synthesis.lux +++ b/stdlib/source/library/lux/compiler/language/lux/synthesis.lux @@ -23,7 +23,6 @@ ["%" \\injection]] [collection ["[0]" list (.use "[1]#[0]" functor monoid)] - ["[0]" stack (.use "[1]#[0]" functor)] ["[0]" dictionary (.only Dictionary)]]] [math [number @@ -814,15 +813,18 @@ {#Alt {,path head tail} {#Then else}} (do [! maybe.monad] - [cases (stack.each' ! (function (_ road) - (.when (.its #then road) - {#Then then} - {.#Some [(.its #when road) then]} - - _ - {.#None})) - (stack.partial head (list.as_stack tail)))] - (in [input (list.of_stack cases) else])) + [.let [case (is (-> (Road ,type Path) + (Maybe [,type Term])) + (function (_ road) + (.when (.its #then road) + {#Then then} + {.#Some [(.its #when road) then]} + + _ + {.#None})))] + head (case head) + tail (list.each' ! case tail)] + (in [input (list#composite (list head) tail) else])) _ {.#None}))] diff --git a/stdlib/source/library/lux/compiler/language/lux/translation.lux b/stdlib/source/library/lux/compiler/language/lux/translation.lux index 9847480cf9..ba2338ff07 100644 --- a/stdlib/source/library/lux/compiler/language/lux/translation.lux +++ b/stdlib/source/library/lux/compiler/language/lux/translation.lux @@ -17,7 +17,7 @@ ["[0]" text (.only) ["%" \\injection]] [collection - ["[0]" sequence (.only Sequence)] + ["[0]" sequence (.only Sequence) (.use "[1]#[0]" functor)] ["[0]" list (.use "[1]#[0]" functor mix)] ["[0]" stack (.use "[1]#[0]" functor mix)] ["[0]" set (.only Set)]]] @@ -94,7 +94,7 @@ #registry_shift Natural #counter Natural #context (Maybe artifact.ID) - #interim_artifacts (Stack artifact.ID)])) + #interim_artifacts (Sequence artifact.ID)])) (every .public (Operation anchor expression declaration) (phase.Operation (State anchor expression declaration))) @@ -123,7 +123,7 @@ #registry_shift 0 #counter 0 #context {.#None} - #interim_artifacts (stack)]) + #interim_artifacts sequence.empty]) (the .public empty_buffer Buffer @@ -390,7 +390,7 @@ [[state' output] (body (|> state (has #registry registry') (has #context {.#Some @artifact}) - (revised #interim_artifacts (|>> {.#Top @artifact})))) + (revised #interim_artifacts (sequence.suffix @artifact)))) @module (archive.id (its #module state) archive)] (in [(has #context (its #context state) state') [[@module @artifact] @@ -399,13 +399,13 @@ (the .public (with_interim_artifacts archive body) (for_any (_ anchor expression declaration it) (-> Archive (Operation anchor expression declaration it) - (Operation anchor expression declaration [(Stack unit.ID) it]))) + (Operation anchor expression declaration [(Sequence unit.ID) it]))) (do phase.monad [module (phase.read (its #module))] (function (_ state) (do try.monad [@module (archive.id module archive) [state' output] (body state)] - (in [(has #interim_artifacts (stack) state') - [(stack#each (|>> [@module]) (its #interim_artifacts state')) + (in [(has #interim_artifacts sequence.empty state') + [(sequence#each (|>> [@module]) (its #interim_artifacts state')) output]]))))) diff --git a/stdlib/source/library/lux/compiler/meta/export.lux b/stdlib/source/library/lux/compiler/meta/export.lux index 1fe4dbc993..2ac2b8ebee 100644 --- a/stdlib/source/library/lux/compiler/meta/export.lux +++ b/stdlib/source/library/lux/compiler/meta/export.lux @@ -58,7 +58,6 @@ (-> (file.System Future) (List Source) (Future (Try tar.Tar))) (|> sources - list.as_stack (io.listing fs) (future#each (function (_ listing) (when listing diff --git a/stdlib/source/library/lux/compiler/meta/io/archive.lux b/stdlib/source/library/lux/compiler/meta/io/archive.lux index a46ce66962..a79f75b584 100644 --- a/stdlib/source/library/lux/compiler/meta/io/archive.lux +++ b/stdlib/source/library/lux/compiler/meta/io/archive.lux @@ -21,7 +21,6 @@ [set (.only Set)] ["[0]" list (.use "[1]#[0]" mix monad) ["[0]" property (.use "[1]#[0]" functor)]] - ["[0]" stack (.use "[1]#[0]" mix monad)] ["[0]" dictionary (.only Dictionary)] ["[0]" sequence (.only Sequence)]]] [macro @@ -201,20 +200,15 @@ Text "(Lux Caching System)") -(the (cache_of customs) - (-> (Stack Custom) (Projection [(module.Module Any) Registry])) - (when customs - {.#Empty} - (..of_binary $.key $.of_binary) - - {.#Top [custom_state custom_key custom_format custom_of custom_compiler] tail} - (all <>.either - (..of_binary custom_key custom_of) - (cache_of tail) - ))) +(the cache_of + (-> (List Custom) + (Projection [(module.Module Any) Registry])) + (list#mix (function (_ [custom_state custom_key custom_format custom_of custom_compiler]) + (<>.either (..of_binary custom_key custom_of))) + (..of_binary $.key $.of_binary))) (the (valid_cache customs fs context import contexts [module_name @module]) - (-> (Stack Custom) (file.System Future) Context Import (List //.Context) + (-> (List Custom) (file.System Future) Context Import (List //.Context) [descriptor.Module module.ID] (Future (Try Cache))) (expansion.let [ (these module_name @module module registry)] @@ -225,11 +219,11 @@ (if (text.= descriptor.runtime module_name) (in [true ]) (do ! - [input (//context.read fs ..pseudo_module import (list.as_stack contexts) (its context.#host_module_extension context) module_name)] + [input (//context.read fs ..pseudo_module import contexts (its context.#host_module_extension context) module_name)] (in [(cache/purge.valid? (its module.#descriptor module) input) ])))))) (the (pre_loaded_caches customs fs context import contexts archive) - (-> (Stack Custom) (file.System Future) Context Import (List //.Context) Archive + (-> (List Custom) (file.System Future) Context Import (List //.Context) Archive (Future (Try (List Cache)))) (do [! (try.with future.monad)] [... TODO: Stop needing to wrap this expression in an unnecessary "do" expression. @@ -261,7 +255,6 @@ (do [! (try.with future.monad)] [... TODO: Stop needing to wrap this expression in an unnecessary "do" expression. it (|> load_order - list.of_stack (list.only (|>> product.left (dictionary.key? purge) not)) (list.each' ! (function (_ [module_name [@module entry]]) (do ! @@ -271,7 +264,7 @@ (the (load_every_reserved_module customs configuration host_environment fs context import contexts archive) (for_any (_ expression declaration) - (-> (Stack Custom) Configuration (translation.Host expression declaration) (file.System Future) Context Import (List //.Context) Archive + (-> (List Custom) Configuration (translation.Host expression declaration) (file.System Future) Context Import (List //.Context) Archive (Future (Try [Archive analysis.State])))) (do [! (try.with future.monad)] [pre_loaded_caches (..pre_loaded_caches customs fs context import contexts archive) @@ -293,7 +286,7 @@ (the .public (thaw customs configuration host_environment fs context import contexts) (for_any (_ expression declaration) - (-> (Stack Custom) Configuration (translation.Host expression declaration) (file.System Future) Context Import (List //.Context) + (-> (List Custom) Configuration (translation.Host expression declaration) (file.System Future) Context Import (List //.Context) (Future (Try [Archive analysis.State])))) (do future.monad [binary (by fs read (cache/archive.descriptor fs))] diff --git a/stdlib/source/library/lux/compiler/meta/io/context.lux b/stdlib/source/library/lux/compiler/meta/io/context.lux index 0d1137bc88..7fe46a4e12 100644 --- a/stdlib/source/library/lux/compiler/meta/io/context.lux +++ b/stdlib/source/library/lux/compiler/meta/io/context.lux @@ -23,7 +23,6 @@ ["[0]" utf8]]] [collection ["[0]" dictionary (.only Dictionary)] - ["[0]" stack] ["[0]" list]]] ["[0]" type] [world @@ -63,19 +62,20 @@ (text context (by fs delimiter)))) (the (find_source_file fs importer contexts module extension) - (-> (file.System Future) Module (Stack Context) Module Extension + (-> (file.System Future) Module (List Context) Module Extension (Future (Try file.Path))) - (when contexts - {.#Empty} - (future#in (exception.except ..cannot_find_module [importer module])) - - {.#Top context contexts'} - (let [path (text (..path fs context module) extension)] - (do future.monad - [? (by fs file? path)] - (if ? - (in {try.#Success path}) - (find_source_file fs importer contexts' module extension)))))) + (do [! future.monad] + [path (list.one' ! + (function (_ context) + (let [path (text (..path fs context module) extension)] + (do ! + [? (by fs file? path)] + (in (if ? + {.#Some path} + {.#None}))))) + contexts)] + (in (try.or path + (exception.except ..cannot_find_module [importer module]))))) (the (full_host_extension partial_host_extension) (-> Extension @@ -83,7 +83,7 @@ (text partial_host_extension ..lux_extension)) (the (find_local_source_file fs importer import contexts partial_host_extension module) - (-> (file.System Future) Module Import (Stack Context) Extension Module + (-> (file.System Future) Module Import (List Context) Extension Module (Future (Try [file.Path Binary]))) ... Preference is explicitly being given to Lux files that have a host extension. ... Normal Lux files (i.e. without a host extension) are then picked as fallback files. @@ -120,7 +120,7 @@ (exception.except ..cannot_find_module [importer module])))))) (the (find_any_source_file fs importer import contexts partial_host_extension module) - (-> (file.System Future) Module Import (Stack Context) Extension Module + (-> (file.System Future) Module Import (List Context) Extension Module (Future (Try [file.Path Binary]))) ... Preference is explicitly being given to Lux files that have a host extension. ... Normal Lux files (i.e. without a host extension) are then picked as fallback files. @@ -134,7 +134,7 @@ (in (..find_library_source_file importer import partial_host_extension module))))) (the .public (read fs importer import contexts partial_host_extension module) - (-> (file.System Future) Module Import (Stack Context) Extension Module + (-> (file.System Future) Module Import (List Context) Extension Module (Future (Try Input))) (do (try.with future.monad) [[path binary] (..find_any_source_file fs importer import contexts partial_host_extension module)] @@ -159,10 +159,10 @@ (by fs directory_files) (by ! each (list.mix' ! (function (_ file enumeration) (if (text.ends_with? ..lux_extension file) - (do ! - [source_code (by fs read file)] - (future#in (dictionary.has' (text.replaced_once context "" file) source_code enumeration))) - (in enumeration))) + (do ! + [source_code (by fs read file)] + (future#in (dictionary.has' (text.replaced_once context "" file) source_code enumeration))) + (in enumeration))) enumeration)) (by ! conjoint))] (|> directory @@ -186,18 +186,18 @@ (maybe.else context))))) (the .public (listing fs contexts) - (-> (file.System Future) (Stack Context) + (-> (file.System Future) (List Context) (Action Enumeration)) (let [! (is (Monad Action) (try.with future.monad))] - (stack.mix' ! - (function (_ context enumeration) - (do ! - [context (..canonical fs context)] - (..context_listing fs - (text context (by fs delimiter)) - context - enumeration))) - (is Enumeration - (dictionary.empty text.hash)) - contexts))) + (list.mix' ! + (function (_ context enumeration) + (do ! + [context (..canonical fs context)] + (..context_listing fs + (text context (by fs delimiter)) + context + enumeration))) + (is Enumeration + (dictionary.empty text.hash)) + contexts))) diff --git a/stdlib/source/library/lux/compiler/meta/packager.lux b/stdlib/source/library/lux/compiler/meta/packager.lux index 5ccf64a58c..c5e98196fc 100644 --- a/stdlib/source/library/lux/compiler/meta/packager.lux +++ b/stdlib/source/library/lux/compiler/meta/packager.lux @@ -12,8 +12,7 @@ [collection [dictionary (.only Dictionary)] ["[0]" sequence] - ["[0]" list (.use "[1]#[0]" functor)] - ["[0]" stack (.use "[1]#[0]" functor)]]] + ["[0]" list (.use "[1]#[0]" functor)]]] [world ["[0]" file]]]] [// @@ -32,16 +31,15 @@ (Stack [Text Binary]))))) (every .public Order - (Stack [module.ID (Stack artifact.ID)])) + (List [module.ID (List artifact.ID)])) (the .public order (-> (cache/module.Order Any) Order) - (stack#each (function (_ [module [module_id entry]]) - (|> entry - (its archive.#registry) - registry.artifacts - sequence.as_list - (list#each (|>> product.left (its artifact.#id))) - list.as_stack - [module_id])))) + (list#each (function (_ [module [module_id entry]]) + (|> entry + (its archive.#registry) + registry.artifacts + sequence.as_list + (list#each (|>> product.left (its artifact.#id))) + [module_id])))) diff --git a/stdlib/source/library/lux/compiler/meta/packager/jvm.lux b/stdlib/source/library/lux/compiler/meta/packager/jvm.lux index 055fb6d5c5..8af6d4acea 100644 --- a/stdlib/source/library/lux/compiler/meta/packager/jvm.lux +++ b/stdlib/source/library/lux/compiler/meta/packager/jvm.lux @@ -17,7 +17,6 @@ [collection ["[0]" sequence] ["[0]" list (.use "[1]#[0]" functor)] - ["[0]" stack (.use "[1]#[0]" functor)] ["[0]" dictionary] ["[0]" set (.only Set)]]] [math @@ -54,74 +53,74 @@ ["[0]" runtime (.only Definition)]]]]]]]]]) (import java/lang/Object - "[1]::[0]") + "[1]::[0]") (import java/lang/String - "[1]::[0]") + "[1]::[0]") (import java/util/jar/Attributes - "[1]::[0]" - (put [java/lang/Object java/lang/Object] "?" java/lang/Object)) + "[1]::[0]" + (put [java/lang/Object java/lang/Object] "?" java/lang/Object)) (import java/util/jar/Attributes$Name - "[1]::[0]" - ("read_only" "static" MAIN_CLASS java/util/jar/Attributes$Name) - ("read_only" "static" MANIFEST_VERSION java/util/jar/Attributes$Name)) + "[1]::[0]" + ("read_only" "static" MAIN_CLASS java/util/jar/Attributes$Name) + ("read_only" "static" MANIFEST_VERSION java/util/jar/Attributes$Name)) (import java/util/jar/Manifest - "[1]::[0]" - (new []) - (getMainAttributes [] java/util/jar/Attributes)) + "[1]::[0]" + (new []) + (getMainAttributes [] java/util/jar/Attributes)) (import java/io/Flushable - "[1]::[0]" - (flush [] void)) + "[1]::[0]" + (flush [] void)) (import java/io/Closeable - "[1]::[0]" - (close [] void)) + "[1]::[0]" + (close [] void)) (import java/io/OutputStream - "[1]::[0]" - (write [[byte] int int] void)) + "[1]::[0]" + (write [[byte] int int] void)) (import java/io/ByteArrayOutputStream - "[1]::[0]" - (new [int]) - (toByteArray [] [byte])) + "[1]::[0]" + (new [int]) + (toByteArray [] [byte])) (import java/util/zip/ZipEntry - "[1]::[0]" - (getName [] java/lang/String) - (isDirectory [] boolean) - (getSize [] long)) + "[1]::[0]" + (getName [] java/lang/String) + (isDirectory [] boolean) + (getSize [] long)) (import java/util/zip/ZipOutputStream - "[1]::[0]" - (write [[byte] int int] void) - (closeEntry [] void)) + "[1]::[0]" + (write [[byte] int int] void) + (closeEntry [] void)) (import java/util/jar/JarEntry - "[1]::[0]" - (new [java/lang/String])) + "[1]::[0]" + (new [java/lang/String])) (import java/util/jar/JarOutputStream - "[1]::[0]" - (new [java/io/OutputStream java/util/jar/Manifest]) - (putNextEntry [java/util/zip/ZipEntry] "try" void)) + "[1]::[0]" + (new [java/io/OutputStream java/util/jar/Manifest]) + (putNextEntry [java/util/zip/ZipEntry] "try" void)) (import java/io/ByteArrayInputStream - "[1]::[0]" - (new [[byte]])) + "[1]::[0]" + (new [[byte]])) (import java/io/InputStream - "[1]::[0]" - (read [[byte] int int] int)) + "[1]::[0]" + (read [[byte] int int] int)) (import java/util/jar/JarInputStream - "[1]::[0]" - (new [java/io/InputStream]) - (getNextJarEntry [] "try" "?" java/util/jar/JarEntry)) + "[1]::[0]" + (new [java/io/InputStream]) + (getNextJarEntry [] "try" "?" java/util/jar/JarEntry)) (the byte 1) @@ -181,8 +180,8 @@ (list.mix' try.monad (function (_ [artifact custom content] sink) (if (set.member? necessary_dependencies [module artifact]) - (..write_class static module artifact custom content sink) - (by ! in sink))) + (..write_class static module artifact custom content sink) + (by ! in sink))) sink (sequence.as_list output)))) @@ -212,8 +211,8 @@ .natural (n.+ so_far))] (if (n.= expected_size so_far') - [expected_size buffer] - (again so_far')))))) + [expected_size buffer] + (again so_far')))))) (the (read_jar_entry entry input) (-> java/util/jar/JarEntry java/util/jar/JarInputStream [Natural Binary]) @@ -253,24 +252,24 @@ (text.starts_with? "META-INF/leiningen/" entry_path)) (or (text.ends_with? ".SF" entry_path) (text.ends_with? ".DSA" entry_path)))) - (when (java/util/jar/JarOutputStream::putNextEntry [(java/util/jar/JarEntry::new [(ffi.as_string entry_path)])] - sink) - {try.#Failure error} + (when (java/util/jar/JarOutputStream::putNextEntry [(java/util/jar/JarEntry::new [(ffi.as_string entry_path)])] + sink) + {try.#Failure error} + (again entries + (set.has entry_path duplicates) + sink) + + {try.#Success _} + (let [[entry_size entry_data] (read_jar_entry entry input)] + (again (set.has entry_path entries) + duplicates + (to sink + (java/util/zip/ZipOutputStream::write [entry_data (ffi.as_int +0) (ffi.as_int (.integer entry_size))]) + (java/io/Flushable::flush []) + (java/util/zip/ZipOutputStream::closeEntry []))))) (again entries - (set.has entry_path duplicates) - sink) - - {try.#Success _} - (let [[entry_size entry_data] (read_jar_entry entry input)] - (again (set.has entry_path entries) - duplicates - (to sink - (java/util/zip/ZipOutputStream::write [entry_data (ffi.as_int +0) (ffi.as_int (.integer entry_size))]) - (java/io/Flushable::flush []) - (java/util/zip/ZipOutputStream::closeEntry []))))) - (again entries - duplicates - sink)))))))) + duplicates + sink)))))))) (the .public (package static) (-> Context Packager) @@ -280,10 +279,10 @@ order (cache/module.load_order $.key archive) .let [buffer (java/io/ByteArrayOutputStream::new [(ffi.as_int (.integer ..mebi_byte))])] sink (|> order - (stack#each (function (_ [module [module_id entry]]) - [module_id (its archive.#output entry)])) - (stack.mix' ! (..write_module static necessary_dependencies) - (java/util/jar/JarOutputStream::new [buffer (..manifest program)]))) + (list#each (function (_ [module [module_id entry]]) + [module_id (its archive.#output entry)])) + (list.mix' ! (..write_module static necessary_dependencies) + (java/util/jar/JarOutputStream::new [buffer (..manifest program)]))) [entries duplicates sink] (|> host_dependencies dictionary.values (list.mix' ! ..write_host_dependency diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index 2ccea348e4..7f56c648ef 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -9,7 +9,7 @@ [hash (.only Hash)] [monoid (.only Monoid)] [functor (.only Functor)] - [monad (.only Monad)]] + [monad (.only Monad do)]] [error (.only error) ["[0]" try (.only Try)]] [data @@ -500,6 +500,24 @@ {try.#Success it}) {try.#Failure ..no_one})))) +(the .public (one' monad check it) + (for_any (_ context input output) + (-> (Monad context) (-> input (context (Maybe output))) + (-> (List input) + (context (Try output))))) + (let [limit (.list_size# it)] + (loop (value [@ 0]) + (if (n.< limit @) + (do monad + [check (check (.list_item# @ it))] + (.when check + {.#None} + (value (++ @)) + + {.#Some it} + (in {try.#Success it}))) + (by monad in {try.#Failure ..no_one}))))) + (the .public (member? = context candidate) (for_any (_ it) (-> (Equivalence it) (List it) diff --git a/stdlib/source/library/lux/target/jvm/type/alias.lux b/stdlib/source/library/lux/target/jvm/type/alias.lux index 904e4895a1..e04802f711 100644 --- a/stdlib/source/library/lux/target/jvm/type/alias.lux +++ b/stdlib/source/library/lux/target/jvm/type/alias.lux @@ -3,7 +3,7 @@ (.using [library - [lux (.except Type Parameter) + [lux (.except Type Parameter Array) [abstract [monad (.only do)] ["<>" projection (.use "[1]#[0]" functor)]] diff --git a/stdlib/source/test/lux/compiler/language/lux/translation.lux b/stdlib/source/test/lux/compiler/language/lux/translation.lux index 468d7fafc0..5831888929 100644 --- a/stdlib/source/test/lux/compiler/language/lux/translation.lux +++ b/stdlib/source/test/lux/compiler/language/lux/translation.lux @@ -11,7 +11,6 @@ [data ["[0]" text] [collection - ["[0]" stack] ["[0]" sequence]]] [math ["[0]" random (.only Random)] @@ -75,7 +74,7 @@ (n.= 0 (its /.#registry_shift it)) (n.= 0 (its /.#counter it)) (when (its /.#context it) {.#None} true _ false) - (stack.empty? (its /.#interim_artifacts it))))) + (sequence.empty? (its /.#interim_artifacts it))))) (_.for [/.#module] (all _.and (_.coverage [/.enter_module /.module]