diff options
author | Eduardo Julian | 2021-07-08 23:59:00 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-07-08 23:59:00 -0400 |
commit | f3e869d0246e956399ec31a074c6c6299ff73602 (patch) | |
tree | ba67c7713bbe4ec48232f58a4b324bd364111f95 /stdlib | |
parent | 2b909032e7a0bd10cd7db52067d2fb701bfa95e5 (diff) |
Made sure the "phase" parameter of extensions is always usable (even across language boundaries)
Diffstat (limited to 'stdlib')
19 files changed, 1026 insertions, 760 deletions
diff --git a/stdlib/source/lux/control/parser.lux b/stdlib/source/lux/control/parser.lux index d22627fb5..4c95b5ee6 100644 --- a/stdlib/source/lux/control/parser.lux +++ b/stdlib/source/lux/control/parser.lux @@ -276,7 +276,7 @@ (All [s a] (-> (-> a Bit) (Parser s a) (Parser s a))) (do ..monad [output parser - _ (assert "Constraint failed." (test output))] + _ (..assert "Constraint failed." (test output))] (wrap output))) (def: #export (parses? parser) diff --git a/stdlib/source/lux/data/format/xml.lux b/stdlib/source/lux/data/format/xml.lux index 4409c3ab5..5d4252cfc 100644 --- a/stdlib/source/lux/data/format/xml.lux +++ b/stdlib/source/lux/data/format/xml.lux @@ -98,11 +98,14 @@ (def: tag^ namespaced_symbol^) (def: attr_name^ namespaced_symbol^) +(def: white_space^ + (Parser Text) + (<text>.some <text>.space)) + (def: spaced^ (All [a] (-> (Parser a) (Parser a))) - (let [white_space^ (<>.some <text>.space)] - (|>> (<>.before white_space^) - (<>.after white_space^)))) + (|>> (<>.before ..white_space^) + (<>.after ..white_space^))) (def: attr_value^ (Parser Text) @@ -114,15 +117,15 @@ (Parser Attrs) (<| (\ <>.monad map (dictionary.from_list name.hash)) <>.some - (<>.and (spaced^ attr_name^)) + (<>.and (..spaced^ attr_name^)) (<>.after (<text>.this "=")) - (spaced^ attr_value^))) + (..spaced^ attr_value^))) (def: (close_tag^ expected) (-> Tag (Parser [])) (do <>.monad [actual (|> tag^ - spaced^ + ..spaced^ (<>.after (<text>.this "/")) (<text>.enclosed ["<" ">"]))] (<>.assert ($_ text\compose "Close tag does not match open tag." text.new_line @@ -135,14 +138,14 @@ (|> (<text>.not (<text>.this "--")) <text>.some (<text>.enclosed ["<!--" "-->"]) - spaced^)) + ..spaced^)) (def: xml_header^ (Parser Attrs) - (|> (spaced^ attrs^) + (|> (..spaced^ attrs^) (<>.before (<text>.this "?>")) (<>.after (<text>.this "<?xml")) - spaced^)) + ..spaced^)) (def: cdata^ (Parser Text) @@ -150,7 +153,7 @@ (|> (<text>.some (<text>.not end)) (<>.after end) (<>.after (<text>.this "<![CDATA[")) - spaced^))) + ..spaced^))) (def: text^ (Parser XML) @@ -166,34 +169,36 @@ (Parser XML) (|> (<>.rec (function (_ node^) - (|> (spaced^ - (do <>.monad - [_ (<text>.this "<") - tag (spaced^ tag^) - attrs (spaced^ attrs^) - #let [no_children^ (do <>.monad - [_ (<text>.this "/>")] - (wrap (#Node tag attrs (list)))) - ## TODO: Find a way to make do without this hack. Without it, some POM files fail when parsing them in Aedifex. Something like this fails: <configuration> </configuration> - alternative_no_children^ (do <>.monad - [_ (<text>.this ">") - _ (<>.some <text>.space) - _ (..close_tag^ tag)] - (wrap (#Node tag attrs (list)))) - with_children^ (do <>.monad - [_ (<text>.this ">") - children (<>.some node^) - _ (..close_tag^ tag)] - (wrap (#Node tag attrs children)))]] - ($_ <>.either - no_children^ - alternative_no_children^ - with_children^))) + (|> (do <>.monad + [_ (<text>.this "<") + tag (..spaced^ tag^) + attrs (..spaced^ attrs^) + #let [no_children^ (do <>.monad + [_ (<text>.this "/>")] + (wrap (#Node tag attrs (list)))) + ## TODO: Find a way to make do without this hack. Without it, some POM files fail when parsing them in Aedifex. Something like this fails: <configuration> </configuration> + alternative_no_children^ (do <>.monad + [_ (<text>.this ">") + _ (<>.some <text>.space) + _ (..close_tag^ tag)] + (wrap (#Node tag attrs (list)))) + with_children^ (do <>.monad + [_ (<text>.this ">") + children (<>.either (<>.many node^) + (<>.after (<>.some ..comment^) + (wrap (: (List XML) (list))))) + _ (..close_tag^ tag)] + (wrap (#Node tag attrs children)))]] + ($_ <>.either + no_children^ + alternative_no_children^ + with_children^)) + ..spaced^ (<>.before (<>.some ..comment^)) (<>.after (<>.some ..comment^)) - (<>.either text^)))) + (<>.either ..text^)))) (<>.before (<>.some ..null^)) - (<>.after (<>.maybe xml_header^)))) + (<>.after (<>.maybe ..xml_header^)))) (def: read (-> Text (Try XML)) diff --git a/stdlib/source/lux/target/jvm.lux b/stdlib/source/lux/target/jvm.lux index 3cc306cd9..4250bf705 100644 --- a/stdlib/source/lux/target/jvm.lux +++ b/stdlib/source/lux/target/jvm.lux @@ -265,7 +265,7 @@ (#Concurrency Concurrency) (#Return Return)) -(type: #export (Instruction label) +(type: #export (Instruction embedded label) #NOP (#Constant Constant) (#Arithmetic Arithmetic) @@ -276,7 +276,8 @@ (#Local Local) (#Stack Stack) (#Comparison Comparison) - (#Control (Control label))) + (#Control (Control label)) + (#Embedded embedded)) -(type: #export (Bytecode label) - (Row (Instruction label))) +(type: #export (Bytecode embedded label) + (Row (Instruction embedded label))) diff --git a/stdlib/source/lux/time.lux b/stdlib/source/lux/time.lux index f1600bc56..3a737f113 100644 --- a/stdlib/source/lux/time.lux +++ b/stdlib/source/lux/time.lux @@ -7,10 +7,11 @@ [codec (#+ Codec)] [monad (#+ Monad do)]] [control + [pipe (#+ case>)] ["." try (#+ Try)] ["." exception (#+ exception:)] ["<>" parser - ["<t>" text (#+ Parser)]]] + ["<.>" text (#+ Parser)]]] [data ["." text ("#\." monoid)]] [math @@ -45,13 +46,13 @@ (def: parse_section (Parser Nat) - (<>.codec n.decimal (<t>.exactly 2 <t>.decimal))) + (<>.codec n.decimal (<text>.exactly 2 <text>.decimal))) -(def: parse_millis' +(def: parse_millis (Parser Nat) - (<>.either (|> (<t>.at_most 3 <t>.decimal) + (<>.either (|> (<text>.at_most 3 <text>.decimal) (<>.codec n.decimal) - (<>.after (<t>.this "."))) + (<>.after (<text>.this "."))) (\ <>.monad wrap 0))) (template [<maximum> <parser> <exception> <sub_parser>] @@ -65,15 +66,13 @@ (Parser Nat) (do <>.monad [value <sub_parser>] - (if (and (n.>= 0 value) - (n.< <maximum> value)) + (if (n.< <maximum> value) (wrap value) (<>.lift (exception.throw <exception> [value])))))] [..hours parse_hour invalid_hour ..parse_section] [..minutes parse_minute invalid_minute ..parse_section] [..seconds parse_second invalid_second ..parse_section] - [..milli_seconds parse_millis invalid_milli_second ..parse_millis'] ) (abstract: #export Time @@ -116,12 +115,14 @@ (def: &order ..order) (def: succ - (|>> :representation (n.% ..limit) :abstraction)) + (|>> :representation inc (n.% ..limit) :abstraction)) - (def: (pred time) - (:abstraction (dec (case (:representation time) - 0 ..limit - millis millis)))))) + (def: pred + (|>> :representation + (case> 0 ..limit + millis millis) + dec + :abstraction)))) (def: #export parser (Parser Time) @@ -133,9 +134,9 @@ millis (to_millis duration.milli_second)] (do {! <>.monad} [utc_hour ..parse_hour - _ (<t>.this ..separator) + _ (<text>.this ..separator) utc_minute ..parse_minute - _ (<t>.this ..separator) + _ (<text>.this ..separator) utc_second ..parse_second utc_millis ..parse_millis] (wrap (:abstraction @@ -212,4 +213,4 @@ (Codec Text Time) (def: encode ..encode) - (def: decode (<t>.run ..parser))) + (def: decode (<text>.run ..parser))) diff --git a/stdlib/source/lux/tool/compiler/default/init.lux b/stdlib/source/lux/tool/compiler/default/init.lux index e697f62a9..2803398e0 100644 --- a/stdlib/source/lux/tool/compiler/default/init.lux +++ b/stdlib/source/lux/tool/compiler/default/init.lux @@ -49,7 +49,7 @@ ["." artifact] ["." document]]]]]) -(def: #export (state target module expander host_analysis host generate generation_bundle host_directive_bundle program anchorT,expressionT,directiveT extender) +(def: #export (state target module expander host_analysis host generate generation_bundle) (All [anchor expression directive] (-> Target Module @@ -58,17 +58,13 @@ (///generation.Host expression directive) (///generation.Phase anchor expression directive) (///generation.Bundle anchor expression directive) - (///directive.Bundle anchor expression directive) - (Program expression directive) - [Type Type Type] Extender (///directive.State+ anchor expression directive))) (let [synthesis_state [synthesisE.bundle ///synthesis.init] generation_state [generation_bundle (///generation.state host module)] eval (///analysis/evaluation.evaluator expander synthesis_state generation_state generate) analysis_state [(analysisE.bundle eval host_analysis) (///analysis.state (///analysis.info ///version.version target))]] - [(dictionary.merge host_directive_bundle - (luxD.bundle expander host_analysis program anchorT,expressionT,directiveT extender)) + [extension.empty {#///directive.analysis {#///directive.state analysis_state #///directive.phase (analysisP.phase expander)} #///directive.synthesis {#///directive.state synthesis_state @@ -76,6 +72,20 @@ #///directive.generation {#///directive.state generation_state #///directive.phase generate}}])) +(def: #export (with_default_directives expander host_analysis program anchorT,expressionT,directiveT extender) + (All [anchor expression directive] + (-> Expander + ///analysis.Bundle + (Program expression directive) + [Type Type Type] + Extender + (-> (///directive.State+ anchor expression directive) + (///directive.State+ anchor expression directive)))) + (function (_ [directive_extensions sub_state]) + [(dictionary.merge directive_extensions + (luxD.bundle expander host_analysis program anchorT,expressionT,directiveT extender)) + sub_state])) + (type: Reader (-> Source (Either [Source Text] [Source Code]))) diff --git a/stdlib/source/lux/tool/compiler/default/platform.lux b/stdlib/source/lux/tool/compiler/default/platform.lux index d43259443..1e7f643ac 100644 --- a/stdlib/source/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/lux/tool/compiler/default/platform.lux @@ -7,7 +7,7 @@ ["." monad (#+ Monad do)]] [control ["." function] - ["." try (#+ Try)] + ["." try (#+ Try) ("#\." functor)] ["." exception (#+ exception:)] [concurrency ["." promise (#+ Promise Resolver) ("#\." monad)] @@ -31,7 +31,7 @@ ["." // #_ ["#." init] ["/#" // - ["#." phase] + ["#." phase (#+ Phase)] [language [lux [program (#+ Program)] @@ -61,499 +61,541 @@ ["." static (#+ Static)] ["." import (#+ Import)]]]) -(type: #export (Platform anchor expression directive) - {#&file_system (file.System Promise) - #host (///generation.Host expression directive) - #phase (///generation.Phase anchor expression directive) - #runtime (///generation.Operation anchor expression directive [Registry Output]) - #write (-> directive Binary)}) - -## TODO: Get rid of this -(type: (Action a) - (Promise (Try a))) - -## TODO: Get rid of this -(def: monad - (:coerce (Monad Action) - (try.with promise.monad))) - (with_expansions [<type_vars> (as_is anchor expression directive) - <Platform> (as_is (Platform <type_vars>)) - <State+> (as_is (///directive.State+ <type_vars>)) - <Bundle> (as_is (///generation.Bundle <type_vars>))] - - (def: writer - (Writer [Descriptor (Document .Module)]) - (_.and descriptor.writer - (document.writer $.writer))) - - (def: (cache_module static platform module_id [descriptor document output]) - (All [<type_vars>] - (-> Static <Platform> archive.ID [Descriptor (Document Any) Output] - (Promise (Try Any)))) - (let [system (get@ #&file_system platform) - write_artifact! (: (-> [artifact.ID Binary] (Action Any)) - (function (_ [artifact_id content]) - (ioW.write system static module_id artifact_id content)))] - (do {! ..monad} - [_ (ioW.prepare system static module_id) - _ (for {@.python (|> output - row.to_list - (list.chunk 128) - (monad.map ! (monad.map ! write_artifact!)) - (: (Action (List (List Any)))))} - (|> output - row.to_list - (monad.map ..monad write_artifact!) - (: (Action (List Any))))) - document (\ promise.monad wrap - (document.check $.key document))] - (ioW.cache system static module_id - (_.run ..writer [descriptor document]))))) - - ## TODO: Inline ASAP - (def: initialize_buffer! - (All [<type_vars>] - (///generation.Operation <type_vars> Any)) - (///generation.set_buffer ///generation.empty_buffer)) - - ## TODO: Inline ASAP - (def: (compile_runtime! platform) - (All [<type_vars>] - (-> <Platform> (///generation.Operation <type_vars> [Registry Output]))) - (do ///phase.monad - [_ ..initialize_buffer!] - (get@ #runtime platform))) - - (def: (runtime_descriptor registry) - (-> Registry Descriptor) - {#descriptor.hash 0 - #descriptor.name archive.runtime_module - #descriptor.file "" - #descriptor.references (set.new text.hash) - #descriptor.state #.Compiled - #descriptor.registry registry}) + <Operation> (as_is ///generation.Operation <type_vars>)] + (type: #export Phase_Wrapper + (All [s i o] (-> (Phase s i o) Any))) - (def: runtime_document - (Document .Module) - (document.write $.key (module.new 0))) - - (def: (process_runtime archive platform) - (All [<type_vars>] - (-> Archive <Platform> - (///directive.Operation <type_vars> - [Archive [Descriptor (Document .Module) Output]]))) - (do ///phase.monad - [[registry payload] (///directive.lift_generation - (..compile_runtime! platform)) - #let [[descriptor document] [(..runtime_descriptor registry) ..runtime_document]] - archive (///phase.lift (if (archive.reserved? archive archive.runtime_module) - (archive.add archive.runtime_module [descriptor document payload] archive) - (do try.monad - [[_ archive] (archive.reserve archive.runtime_module archive)] - (archive.add archive.runtime_module [descriptor document payload] archive))))] - (wrap [archive [descriptor document payload]]))) - - (def: (initialize_state extender - [analysers - synthesizers - generators - directives] - analysis_state - state) - (All [<type_vars>] - (-> Extender - [(Dictionary Text ///analysis.Handler) - (Dictionary Text ///synthesis.Handler) - (Dictionary Text ///generation.Handler) - (Dictionary Text ///directive.Handler)] - .Lux - <State+> - (Try <State+>))) - (|> (:share [<type_vars>] - <State+> - state - - (///directive.Operation <type_vars> Any) - (do ///phase.monad - [_ (///directive.lift_analysis - (///analysis.install analysis_state)) - _ (///directive.lift_analysis - (extension.with extender analysers)) - _ (///directive.lift_synthesis - (extension.with extender synthesizers)) - _ (///directive.lift_generation - (extension.with extender (:assume generators))) - _ (extension.with extender (:assume directives))] - (wrap []))) - (///phase.run' state) - (\ try.monad map product.left))) - - (def: #export (initialize static module expander host_analysis platform generation_bundle host_directive_bundle program anchorT,expressionT,directiveT extender - import compilation_sources) - (All [<type_vars>] - (-> Static - Module - Expander - ///analysis.Bundle - <Platform> - <Bundle> - (///directive.Bundle <type_vars>) - (Program expression directive) - [Type Type Type] Extender - Import (List Context) - (Promise (Try [<State+> Archive])))) - (do (try.with promise.monad) - [#let [state (//init.state (get@ #static.host static) - module - expander - host_analysis - (get@ #host platform) - (get@ #phase platform) - generation_bundle - host_directive_bundle - program - anchorT,expressionT,directiveT - extender)] - _ (ioW.enable (get@ #&file_system platform) static) - [archive analysis_state bundles] (ioW.thaw (get@ #host platform) (get@ #&file_system platform) static import compilation_sources) - state (promise\wrap (initialize_state extender bundles analysis_state state))] - (if (archive.archived? archive archive.runtime_module) - (wrap [state archive]) - (do (try.with promise.monad) - [[state [archive payload]] (|> (..process_runtime archive platform) - (///phase.run' state) - promise\wrap) - _ (..cache_module static platform 0 payload)] - (wrap [state archive]))))) - - (def: compilation_log_separator - (format text.new_line text.tab)) - - (def: (module_compilation_log module) - (All [<type_vars>] - (-> Module <State+> Text)) - (|>> (get@ [#extension.state - #///directive.generation - #///directive.state - #extension.state - #///generation.log]) - (row\fold (function (_ right left) - (format left ..compilation_log_separator right)) - module))) - - (def: with_reset_log - (All [<type_vars>] - (-> <State+> <State+>)) - (set@ [#extension.state - #///directive.generation - #///directive.state - #extension.state - #///generation.log] - row.empty)) - - (def: empty - (Set Module) - (set.new text.hash)) - - (type: Mapping - (Dictionary Module (Set Module))) - - (type: Dependence - {#depends_on Mapping - #depended_by Mapping}) - - (def: independence - Dependence - (let [empty (dictionary.new text.hash)] - {#depends_on empty - #depended_by empty})) - - (def: (depend module import dependence) - (-> Module Module Dependence Dependence) - (let [transitive_dependency (: (-> (-> Dependence Mapping) Module (Set Module)) - (function (_ lens module) - (|> dependence - lens - (dictionary.get module) - (maybe.default ..empty)))) - transitive_depends_on (transitive_dependency (get@ #depends_on) import) - transitive_depended_by (transitive_dependency (get@ #depended_by) module) - update_dependence (: (-> [Module (Set Module)] [Module (Set Module)] - (-> Mapping Mapping)) - (function (_ [source forward] [target backward]) - (function (_ mapping) - (let [with_dependence+transitives - (|> mapping - (dictionary.upsert source ..empty (set.add target)) - (dictionary.update source (set.union forward)))] - (list\fold (function (_ previous) - (dictionary.upsert previous ..empty (set.add target))) - with_dependence+transitives - (set.to_list backward))))))] - (|> dependence - (update@ #depends_on - (update_dependence - [module transitive_depends_on] - [import transitive_depended_by])) - (update@ #depended_by - ((function.flip update_dependence) - [module transitive_depends_on] - [import transitive_depended_by]))))) - - (def: (circular_dependency? module import dependence) - (-> Module Module Dependence Bit) - (let [dependence? (: (-> Module (-> Dependence Mapping) Module Bit) - (function (_ from relationship to) - (let [targets (|> dependence - relationship - (dictionary.get from) - (maybe.default ..empty))] - (set.member? targets to))))] - (or (dependence? import (get@ #depends_on) module) - (dependence? module (get@ #depended_by) import)))) - - (exception: #export (module_cannot_import_itself {module Module}) - (exception.report - ["Module" (%.text module)])) - - (exception: #export (cannot_import_circular_dependency {importer Module} - {importee Module}) - (exception.report - ["Importer" (%.text importer)] - ["importee" (%.text importee)])) - - (def: (verify_dependencies importer importee dependence) - (-> Module Module Dependence (Try Any)) - (cond (text\= importer importee) - (exception.throw ..module_cannot_import_itself [importer]) - - (..circular_dependency? importer importee dependence) - (exception.throw ..cannot_import_circular_dependency [importer importee]) - - ## else - (#try.Success []))) - - (with_expansions [<Context> (as_is [Archive <State+>]) - <Result> (as_is (Try <Context>)) - <Return> (as_is (Promise <Result>)) - <Signal> (as_is (Resolver <Result>)) - <Pending> (as_is [<Return> <Signal>]) - <Importer> (as_is (-> Module Module <Return>)) - <Compiler> (as_is (-> Module <Importer> archive.ID <Context> Module <Return>))] - (def: (parallel initial) + (type: #export (Platform <type_vars>) + {#&file_system (file.System Promise) + #host (///generation.Host expression directive) + #phase (///generation.Phase <type_vars>) + #runtime (<Operation> [Registry Output]) + #phase_wrapper (-> Archive (<Operation> Phase_Wrapper)) + #write (-> directive Binary)}) + + ## TODO: Get rid of this + (type: (Action a) + (Promise (Try a))) + + ## TODO: Get rid of this + (def: monad + (:coerce (Monad Action) + (try.with promise.monad))) + + (with_expansions [<Platform> (as_is (Platform <type_vars>)) + <State+> (as_is (///directive.State+ <type_vars>)) + <Bundle> (as_is (///generation.Bundle <type_vars>))] + + (def: writer + (Writer [Descriptor (Document .Module)]) + (_.and descriptor.writer + (document.writer $.writer))) + + (def: (cache_module static platform module_id [descriptor document output]) (All [<type_vars>] - (-> <Context> - (-> <Compiler> <Importer>))) - (let [current (stm.var initial) - pending (:share [<type_vars>] - <Context> - initial - - (Var (Dictionary Module <Pending>)) - (:assume (stm.var (dictionary.new text.hash)))) - dependence (: (Var Dependence) - (stm.var ..independence))] - (function (_ compile) - (function (import! importer module) - (do {! promise.monad} - [[return signal] (:share [<type_vars>] - <Context> - initial - - (Promise [<Return> (Maybe [<Context> - archive.ID - <Signal>])]) - (:assume - (stm.commit - (do {! stm.monad} - [dependence (if (text\= archive.runtime_module importer) - (stm.read dependence) - (do ! - [[_ dependence] (stm.update (..depend importer module) dependence)] - (wrap dependence)))] - (case (..verify_dependencies importer module dependence) - (#try.Failure error) - (wrap [(promise.resolved (#try.Failure error)) - #.None]) - - (#try.Success _) - (do ! - [[archive state] (stm.read current)] - (if (archive.archived? archive module) - (wrap [(promise\wrap (#try.Success [archive state])) - #.None]) - (do ! - [@pending (stm.read pending)] - (case (dictionary.get module @pending) - (#.Some [return signal]) - (wrap [return - #.None]) - - #.None - (case (if (archive.reserved? archive module) - (do try.monad - [module_id (archive.id module archive)] - (wrap [module_id archive])) - (archive.reserve module archive)) - (#try.Success [module_id archive]) - (do ! - [_ (stm.write [archive state] current) - #let [[return signal] (:share [<type_vars>] - <Context> - initial - - <Pending> - (promise.promise []))] - _ (stm.update (dictionary.put module [return signal]) pending)] - (wrap [return - (#.Some [[archive state] - module_id - signal])])) - - (#try.Failure error) - (wrap [(promise\wrap (#try.Failure error)) - #.None]))))))))))) - _ (case signal - #.None - (wrap []) - - (#.Some [context module_id resolver]) - (do ! - [result (compile importer import! module_id context module) - result (case result - (#try.Failure error) - (wrap result) - - (#try.Success [resulting_archive resulting_state]) - (stm.commit (do stm.monad - [[_ [merged_archive _]] (stm.update (function (_ [archive state]) - [(archive.merge resulting_archive archive) - state]) - current)] - (wrap (#try.Success [merged_archive resulting_state]))))) - _ (promise.future (resolver result))] - (wrap [])))] - return))))) - - ## TODO: Find a better way, as this only works for the Lux compiler. - (def: (updated_state archive state) + (-> Static <Platform> archive.ID [Descriptor (Document Any) Output] + (Promise (Try Any)))) + (let [system (get@ #&file_system platform) + write_artifact! (: (-> [artifact.ID Binary] (Action Any)) + (function (_ [artifact_id content]) + (ioW.write system static module_id artifact_id content)))] + (do {! ..monad} + [_ (ioW.prepare system static module_id) + _ (for {@.python (|> output + row.to_list + (list.chunk 128) + (monad.map ! (monad.map ! write_artifact!)) + (: (Action (List (List Any)))))} + (|> output + row.to_list + (monad.map ..monad write_artifact!) + (: (Action (List Any))))) + document (\ promise.monad wrap + (document.check $.key document))] + (ioW.cache system static module_id + (_.run ..writer [descriptor document]))))) + + ## TODO: Inline ASAP + (def: initialize_buffer! (All [<type_vars>] - (-> Archive <State+> (Try <State+>))) - (do {! try.monad} - [modules (monad.map ! (function (_ module) - (do ! - [[descriptor document output] (archive.find module archive) - lux_module (document.read $.key document)] - (wrap [module lux_module]))) - (archive.archived archive)) - #let [additions (|> modules - (list\map product.left) - (set.from_list text.hash))]] - (wrap (update@ [#extension.state - #///directive.analysis - #///directive.state - #extension.state] - (function (_ analysis_state) - (|> analysis_state - (:coerce .Lux) - (update@ #.modules (function (_ current) - (list\compose (list.filter (|>> product.left - (set.member? additions) - not) - current) - modules))) - :assume)) - state)))) - - (def: (set_current_module module state) + (///generation.Operation <type_vars> Any)) + (///generation.set_buffer ///generation.empty_buffer)) + + ## TODO: Inline ASAP + (def: (compile_runtime! platform) + (All [<type_vars>] + (-> <Platform> (///generation.Operation <type_vars> [Registry Output]))) + (do ///phase.monad + [_ ..initialize_buffer!] + (get@ #runtime platform))) + + (def: (runtime_descriptor registry) + (-> Registry Descriptor) + {#descriptor.hash 0 + #descriptor.name archive.runtime_module + #descriptor.file "" + #descriptor.references (set.new text.hash) + #descriptor.state #.Compiled + #descriptor.registry registry}) + + (def: runtime_document + (Document .Module) + (document.write $.key (module.new 0))) + + (def: (process_runtime archive platform) + (All [<type_vars>] + (-> Archive <Platform> + (///directive.Operation <type_vars> + [Archive [Descriptor (Document .Module) Output]]))) + (do ///phase.monad + [[registry payload] (///directive.lift_generation + (..compile_runtime! platform)) + #let [[descriptor document] [(..runtime_descriptor registry) ..runtime_document]] + archive (///phase.lift (if (archive.reserved? archive archive.runtime_module) + (archive.add archive.runtime_module [descriptor document payload] archive) + (do try.monad + [[_ archive] (archive.reserve archive.runtime_module archive)] + (archive.add archive.runtime_module [descriptor document payload] archive))))] + (wrap [archive [descriptor document payload]]))) + + (def: (initialize_state extender + [analysers + synthesizers + generators + directives] + analysis_state + state) (All [<type_vars>] - (-> Module <State+> <State+>)) - (|> (///directive.set_current_module module) + (-> Extender + [(Dictionary Text ///analysis.Handler) + (Dictionary Text ///synthesis.Handler) + (Dictionary Text (///generation.Handler <type_vars>)) + (Dictionary Text (///directive.Handler <type_vars>))] + .Lux + <State+> + (Try <State+>))) + (|> (:share [<type_vars>] + <State+> + state + + (///directive.Operation <type_vars> Any) + (do ///phase.monad + [_ (///directive.lift_analysis + (///analysis.install analysis_state)) + _ (///directive.lift_analysis + (extension.with extender analysers)) + _ (///directive.lift_synthesis + (extension.with extender synthesizers)) + _ (///directive.lift_generation + (extension.with extender (:assume generators))) + _ (extension.with extender (:assume directives))] + (wrap []))) (///phase.run' state) - try.assume - product.left)) + (\ try.monad map product.left))) - (def: #export (compile import static expander platform compilation context) + (def: (phase_wrapper archive platform state) (All [<type_vars>] - (-> Import Static Expander <Platform> Compilation <Context> <Return>)) - (let [[compilation_sources compilation_libraries compilation_target compilation_module] compilation - base_compiler (:share [<type_vars>] - <Context> - context - - (///.Compiler <State+> .Module Any) - (:assume - ((//init.compiler expander syntax.prelude (get@ #write platform)) $.key (list)))) - compiler (..parallel - context - (function (_ importer import! module_id [archive state] module) - (do {! (try.with promise.monad)} - [#let [state (..set_current_module module state)] - input (context.read (get@ #&file_system platform) - importer - import - compilation_sources - (get@ #static.host_module_extension static) - module)] - (loop [[archive state] [archive state] - compilation (base_compiler (:coerce ///.Input input)) - all_dependencies (: (List Module) - (list))] - (let [new_dependencies (get@ #///.dependencies compilation) - all_dependencies (list\compose new_dependencies all_dependencies) - continue! (:share [<type_vars>] - <Platform> - platform - - (-> <Context> (///.Compilation <State+> .Module Any) (List Module) - (Action [Archive <State+>])) - (:assume - recur))] - (do ! - [[archive state] (case new_dependencies - #.Nil - (wrap [archive state]) - - (#.Cons _) - (do ! - [archive,document+ (|> new_dependencies - (list\map (import! module)) - (monad.seq ..monad)) - #let [archive (|> archive,document+ - (list\map product.left) - (list\fold archive.merge archive))]] - (wrap [archive (try.assume - (..updated_state archive state))])))] - (case ((get@ #///.process compilation) - ## TODO: The "///directive.set_current_module" below shouldn't be necessary. Remove it ASAP. - ## TODO: The context shouldn't need to be re-set either. - (|> (///directive.set_current_module module) + (-> Archive <Platform> <State+> (Try [<State+> Phase_Wrapper]))) + (let [phase_wrapper (get@ #phase_wrapper platform)] + (|> archive + phase_wrapper + ///directive.lift_generation + (///phase.run' state)))) + + (def: (complete_extensions host_directive_bundle phase_wrapper [analysers synthesizers generators directives]) + (All [<type_vars>] + (-> (-> Phase_Wrapper (///directive.Bundle <type_vars>)) + Phase_Wrapper + [(Dictionary Text ///analysis.Handler) + (Dictionary Text ///synthesis.Handler) + (Dictionary Text (///generation.Handler <type_vars>)) + (Dictionary Text (///directive.Handler <type_vars>))] + [(Dictionary Text ///analysis.Handler) + (Dictionary Text ///synthesis.Handler) + (Dictionary Text (///generation.Handler <type_vars>)) + (Dictionary Text (///directive.Handler <type_vars>))])) + [analysers + synthesizers + generators + (dictionary.merge directives (host_directive_bundle phase_wrapper))]) + + (def: #export (initialize static module expander host_analysis platform generation_bundle host_directive_bundle program anchorT,expressionT,directiveT extender + import compilation_sources) + (All [<type_vars>] + (-> Static + Module + Expander + ///analysis.Bundle + <Platform> + <Bundle> + (-> Phase_Wrapper (///directive.Bundle <type_vars>)) + (Program expression directive) + [Type Type Type] (-> Phase_Wrapper Extender) + Import (List Context) + (Promise (Try [<State+> Archive])))) + (do {! (try.with promise.monad)} + [#let [state (//init.state (get@ #static.host static) + module + expander + host_analysis + (get@ #host platform) + (get@ #phase platform) + generation_bundle)] + _ (ioW.enable (get@ #&file_system platform) static) + [archive analysis_state bundles] (ioW.thaw (get@ #host platform) (get@ #&file_system platform) static import compilation_sources) + #let [with_missing_extensions + (: (All [<type_vars>] + (-> <Platform> (Program expression directive) <State+> (Promise (Try <State+>)))) + (function (_ platform program state) + (promise\wrap + (do try.monad + [[state phase_wrapper] (..phase_wrapper archive platform state)] + (|> state + (initialize_state (extender phase_wrapper) + (:assume (..complete_extensions host_directive_bundle phase_wrapper (:assume bundles))) + analysis_state) + (try\map (//init.with_default_directives expander host_analysis program anchorT,expressionT,directiveT (extender phase_wrapper))))))))]] + (if (archive.archived? archive archive.runtime_module) + (do ! + [state (with_missing_extensions platform program state)] + (wrap [state archive])) + (do ! + [[state [archive payload]] (|> (..process_runtime archive platform) (///phase.run' state) - try.assume - product.left) - archive) - (#try.Success [state more|done]) - (case more|done - (#.Left more) - (continue! [archive state] more all_dependencies) - - (#.Right [descriptor document output]) - (do ! - [#let [_ (debug.log! (..module_compilation_log module state)) - descriptor (set@ #descriptor.references (set.from_list text.hash all_dependencies) descriptor)] - _ (..cache_module static platform module_id [descriptor document output])] - (case (archive.add module [descriptor document output] archive) - (#try.Success archive) - (wrap [archive - (..with_reset_log state)]) - - (#try.Failure error) - (promise\wrap (#try.Failure error))))) - - (#try.Failure error) + promise\wrap) + _ (..cache_module static platform 0 payload) + + state (with_missing_extensions platform program state)] + (wrap [state archive]))))) + + (def: compilation_log_separator + (format text.new_line text.tab)) + + (def: (module_compilation_log module) + (All [<type_vars>] + (-> Module <State+> Text)) + (|>> (get@ [#extension.state + #///directive.generation + #///directive.state + #extension.state + #///generation.log]) + (row\fold (function (_ right left) + (format left ..compilation_log_separator right)) + module))) + + (def: with_reset_log + (All [<type_vars>] + (-> <State+> <State+>)) + (set@ [#extension.state + #///directive.generation + #///directive.state + #extension.state + #///generation.log] + row.empty)) + + (def: empty + (Set Module) + (set.new text.hash)) + + (type: Mapping + (Dictionary Module (Set Module))) + + (type: Dependence + {#depends_on Mapping + #depended_by Mapping}) + + (def: independence + Dependence + (let [empty (dictionary.new text.hash)] + {#depends_on empty + #depended_by empty})) + + (def: (depend module import dependence) + (-> Module Module Dependence Dependence) + (let [transitive_dependency (: (-> (-> Dependence Mapping) Module (Set Module)) + (function (_ lens module) + (|> dependence + lens + (dictionary.get module) + (maybe.default ..empty)))) + transitive_depends_on (transitive_dependency (get@ #depends_on) import) + transitive_depended_by (transitive_dependency (get@ #depended_by) module) + update_dependence (: (-> [Module (Set Module)] [Module (Set Module)] + (-> Mapping Mapping)) + (function (_ [source forward] [target backward]) + (function (_ mapping) + (let [with_dependence+transitives + (|> mapping + (dictionary.upsert source ..empty (set.add target)) + (dictionary.update source (set.union forward)))] + (list\fold (function (_ previous) + (dictionary.upsert previous ..empty (set.add target))) + with_dependence+transitives + (set.to_list backward))))))] + (|> dependence + (update@ #depends_on + (update_dependence + [module transitive_depends_on] + [import transitive_depended_by])) + (update@ #depended_by + ((function.flip update_dependence) + [module transitive_depends_on] + [import transitive_depended_by]))))) + + (def: (circular_dependency? module import dependence) + (-> Module Module Dependence Bit) + (let [dependence? (: (-> Module (-> Dependence Mapping) Module Bit) + (function (_ from relationship to) + (let [targets (|> dependence + relationship + (dictionary.get from) + (maybe.default ..empty))] + (set.member? targets to))))] + (or (dependence? import (get@ #depends_on) module) + (dependence? module (get@ #depended_by) import)))) + + (exception: #export (module_cannot_import_itself {module Module}) + (exception.report + ["Module" (%.text module)])) + + (exception: #export (cannot_import_circular_dependency {importer Module} + {importee Module}) + (exception.report + ["Importer" (%.text importer)] + ["importee" (%.text importee)])) + + (def: (verify_dependencies importer importee dependence) + (-> Module Module Dependence (Try Any)) + (cond (text\= importer importee) + (exception.throw ..module_cannot_import_itself [importer]) + + (..circular_dependency? importer importee dependence) + (exception.throw ..cannot_import_circular_dependency [importer importee]) + + ## else + (#try.Success []))) + + (with_expansions [<Context> (as_is [Archive <State+>]) + <Result> (as_is (Try <Context>)) + <Return> (as_is (Promise <Result>)) + <Signal> (as_is (Resolver <Result>)) + <Pending> (as_is [<Return> <Signal>]) + <Importer> (as_is (-> Module Module <Return>)) + <Compiler> (as_is (-> Module <Importer> archive.ID <Context> Module <Return>))] + (def: (parallel initial) + (All [<type_vars>] + (-> <Context> + (-> <Compiler> <Importer>))) + (let [current (stm.var initial) + pending (:share [<type_vars>] + <Context> + initial + + (Var (Dictionary Module <Pending>)) + (:assume (stm.var (dictionary.new text.hash)))) + dependence (: (Var Dependence) + (stm.var ..independence))] + (function (_ compile) + (function (import! importer module) + (do {! promise.monad} + [[return signal] (:share [<type_vars>] + <Context> + initial + + (Promise [<Return> (Maybe [<Context> + archive.ID + <Signal>])]) + (:assume + (stm.commit + (do {! stm.monad} + [dependence (if (text\= archive.runtime_module importer) + (stm.read dependence) + (do ! + [[_ dependence] (stm.update (..depend importer module) dependence)] + (wrap dependence)))] + (case (..verify_dependencies importer module dependence) + (#try.Failure error) + (wrap [(promise.resolved (#try.Failure error)) + #.None]) + + (#try.Success _) + (do ! + [[archive state] (stm.read current)] + (if (archive.archived? archive module) + (wrap [(promise\wrap (#try.Success [archive state])) + #.None]) + (do ! + [@pending (stm.read pending)] + (case (dictionary.get module @pending) + (#.Some [return signal]) + (wrap [return + #.None]) + + #.None + (case (if (archive.reserved? archive module) + (do try.monad + [module_id (archive.id module archive)] + (wrap [module_id archive])) + (archive.reserve module archive)) + (#try.Success [module_id archive]) + (do ! + [_ (stm.write [archive state] current) + #let [[return signal] (:share [<type_vars>] + <Context> + initial + + <Pending> + (promise.promise []))] + _ (stm.update (dictionary.put module [return signal]) pending)] + (wrap [return + (#.Some [[archive state] + module_id + signal])])) + + (#try.Failure error) + (wrap [(promise\wrap (#try.Failure error)) + #.None]))))))))))) + _ (case signal + #.None + (wrap []) + + (#.Some [context module_id resolver]) + (do ! + [result (compile importer import! module_id context module) + result (case result + (#try.Failure error) + (wrap result) + + (#try.Success [resulting_archive resulting_state]) + (stm.commit (do stm.monad + [[_ [merged_archive _]] (stm.update (function (_ [archive state]) + [(archive.merge resulting_archive archive) + state]) + current)] + (wrap (#try.Success [merged_archive resulting_state]))))) + _ (promise.future (resolver result))] + (wrap [])))] + return))))) + + ## TODO: Find a better way, as this only works for the Lux compiler. + (def: (updated_state archive state) + (All [<type_vars>] + (-> Archive <State+> (Try <State+>))) + (do {! try.monad} + [modules (monad.map ! (function (_ module) (do ! - [_ (ioW.freeze (get@ #&file_system platform) static archive)] - (promise\wrap (#try.Failure error))))))))))] - (compiler archive.runtime_module compilation_module))) - )) + [[descriptor document output] (archive.find module archive) + lux_module (document.read $.key document)] + (wrap [module lux_module]))) + (archive.archived archive)) + #let [additions (|> modules + (list\map product.left) + (set.from_list text.hash))]] + (wrap (update@ [#extension.state + #///directive.analysis + #///directive.state + #extension.state] + (function (_ analysis_state) + (|> analysis_state + (:coerce .Lux) + (update@ #.modules (function (_ current) + (list\compose (list.filter (|>> product.left + (set.member? additions) + not) + current) + modules))) + :assume)) + state)))) + + (def: (set_current_module module state) + (All [<type_vars>] + (-> Module <State+> <State+>)) + (|> (///directive.set_current_module module) + (///phase.run' state) + try.assume + product.left)) + + (def: #export (compile import static expander platform compilation context) + (All [<type_vars>] + (-> Import Static Expander <Platform> Compilation <Context> <Return>)) + (let [[compilation_sources compilation_libraries compilation_target compilation_module] compilation + base_compiler (:share [<type_vars>] + <Context> + context + + (///.Compiler <State+> .Module Any) + (:assume + ((//init.compiler expander syntax.prelude (get@ #write platform)) $.key (list)))) + compiler (..parallel + context + (function (_ importer import! module_id [archive state] module) + (do {! (try.with promise.monad)} + [#let [state (..set_current_module module state)] + input (context.read (get@ #&file_system platform) + importer + import + compilation_sources + (get@ #static.host_module_extension static) + module)] + (loop [[archive state] [archive state] + compilation (base_compiler (:coerce ///.Input input)) + all_dependencies (: (List Module) + (list))] + (let [new_dependencies (get@ #///.dependencies compilation) + all_dependencies (list\compose new_dependencies all_dependencies) + continue! (:share [<type_vars>] + <Platform> + platform + + (-> <Context> (///.Compilation <State+> .Module Any) (List Module) + (Action [Archive <State+>])) + (:assume + recur))] + (do ! + [[archive state] (case new_dependencies + #.Nil + (wrap [archive state]) + + (#.Cons _) + (do ! + [archive,document+ (|> new_dependencies + (list\map (import! module)) + (monad.seq ..monad)) + #let [archive (|> archive,document+ + (list\map product.left) + (list\fold archive.merge archive))]] + (wrap [archive (try.assume + (..updated_state archive state))])))] + (case ((get@ #///.process compilation) + ## TODO: The "///directive.set_current_module" below shouldn't be necessary. Remove it ASAP. + ## TODO: The context shouldn't need to be re-set either. + (|> (///directive.set_current_module module) + (///phase.run' state) + try.assume + product.left) + archive) + (#try.Success [state more|done]) + (case more|done + (#.Left more) + (continue! [archive state] more all_dependencies) + + (#.Right [descriptor document output]) + (do ! + [#let [_ (debug.log! (..module_compilation_log module state)) + descriptor (set@ #descriptor.references (set.from_list text.hash all_dependencies) descriptor)] + _ (..cache_module static platform module_id [descriptor document output])] + (case (archive.add module [descriptor document output] archive) + (#try.Success archive) + (wrap [archive + (..with_reset_log state)]) + + (#try.Failure error) + (promise\wrap (#try.Failure error))))) + + (#try.Failure error) + (do ! + [_ (ioW.freeze (get@ #&file_system platform) static archive)] + (promise\wrap (#try.Failure error))))))))))] + (compiler archive.runtime_module compilation_module))) + ))) diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/extension.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/extension.lux index 9803de0e4..7004b8d1a 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/extension.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/extension.lux @@ -45,6 +45,10 @@ (type: #export (Bundle s i o) <Bundle>)) +(def: #export empty + Bundle + (dictionary.new text.hash)) + (type: #export (State s i o) {#bundle (Bundle s i o) #state s}) @@ -95,7 +99,7 @@ (def: #export (with extender extensions) (All [s i o] - (-> Extender (Dictionary Text (Handler s i o)) (Operation s i o Any))) + (-> Extender (Bundle s i o) (Operation s i o Any))) (|> extensions dictionary.entries (monad.fold //.monad diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux index bb5587dfe..0c88ae795 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux @@ -9,8 +9,8 @@ ["." try (#+ Try) ("#\." monad)] ["." exception (#+ exception:)] ["<>" parser - ["<c>" code (#+ Parser)] - ["<t>" text]]] + ["<.>" code (#+ Parser)] + ["<.>" text]]] [data ["." maybe] ["." product] @@ -191,7 +191,7 @@ (def: member (Parser Member) - ($_ <>.and <c>.text <c>.text)) + ($_ <>.and <code>.text <code>.text)) (type: Method_Signature {#method .Type @@ -397,7 +397,7 @@ [objectJ (jvm_type objectT)] (|> objectJ ..signature - (<t>.run jvm_parser.array) + (<text>.run jvm_parser.array) phase.lift))) (def: (primitive_array_length_handler primitive_type) @@ -826,7 +826,7 @@ (def: object::instance? Handler (..custom - [($_ <>.and <c>.text <c>.any) + [($_ <>.and <code>.text <code>.any) (function (_ extension_name analyse archive [sub_class objectC]) (do phase.monad [_ (..ensure_fresh_class! sub_class) @@ -842,7 +842,7 @@ (template [<name> <category> <parser>] [(def: (<name> mapping typeJ) (-> Mapping (Type <category>) (Operation .Type)) - (case (|> typeJ ..signature (<t>.run (<parser> mapping))) + (case (|> typeJ ..signature (<text>.run (<parser> mapping))) (#try.Success check) (typeA.with_env check) @@ -998,7 +998,7 @@ (def: put::static Handler (..custom - [($_ <>.and ..member <c>.any) + [($_ <>.and ..member <code>.any) (function (_ extension_name analyse archive [[class field] valueC]) (do phase.monad [_ (..ensure_fresh_class! class) @@ -1022,7 +1022,7 @@ (def: get::virtual Handler (..custom - [($_ <>.and ..member <c>.any) + [($_ <>.and ..member <code>.any) (function (_ extension_name analyse archive [[class field] objectC]) (do phase.monad [_ (..ensure_fresh_class! class) @@ -1046,7 +1046,7 @@ (def: put::virtual Handler (..custom - [($_ <>.and ..member <c>.any <c>.any) + [($_ <>.and ..member <code>.any <code>.any) (function (_ extension_name analyse archive [[class field] valueC objectC]) (do phase.monad [_ (..ensure_fresh_class! class) @@ -1339,7 +1339,7 @@ (template [<name> <category> <parser>] [(def: #export <name> (Parser (Type <category>)) - (<t>.embed <parser> <c>.text))] + (<text>.embed <parser> <code>.text))] [var Var jvm_parser.var] [class Class jvm_parser.class] @@ -1349,7 +1349,7 @@ (def: input (Parser (Typed Code)) - (<c>.tuple (<>.and ..type <c>.any))) + (<code>.tuple (<>.and ..type <code>.any))) (def: (decorate_inputs typesT inputsA) (-> (List (Type Value)) (List Analysis) (List Analysis)) @@ -1358,7 +1358,8 @@ (list\map (function (_ [type value]) (/////analysis.tuple (list type value)))))) -(def: type_vars (<c>.tuple (<>.some ..var))) +(def: type_vars + (<code>.tuple (<>.some ..var))) (def: invoke::static Handler @@ -1381,7 +1382,7 @@ (def: invoke::virtual Handler (..custom - [($_ <>.and ..type_vars ..member ..type_vars <c>.any (<>.some ..input)) + [($_ <>.and ..type_vars ..member ..type_vars <code>.any (<>.some ..input)) (function (_ extension_name analyse archive [class_tvars [class method] method_tvars objectC argsTC]) (do phase.monad [_ (..ensure_fresh_class! class) @@ -1406,7 +1407,7 @@ (def: invoke::special Handler (..custom - [($_ <>.and ..type_vars ..member ..type_vars <c>.any (<>.some ..input)) + [($_ <>.and ..type_vars ..member ..type_vars <code>.any (<>.some ..input)) (function (_ extension_name analyse archive [class_tvars [class method] method_tvars objectC argsTC]) (do phase.monad [_ (..ensure_fresh_class! class) @@ -1424,7 +1425,7 @@ (def: invoke::interface Handler (..custom - [($_ <>.and ..type_vars ..member ..type_vars <c>.any (<>.some ..input)) + [($_ <>.and ..type_vars ..member ..type_vars <code>.any (<>.some ..input)) (function (_ extension_name analyse archive [class_tvars [class_name method] method_tvars objectC argsTC]) (do phase.monad [_ (..ensure_fresh_class! class_name) @@ -1452,7 +1453,7 @@ (def: invoke::constructor (..custom - [($_ <>.and ..type_vars <c>.text ..type_vars (<>.some ..input)) + [($_ <>.and ..type_vars <code>.text ..type_vars (<>.some ..input)) (function (_ extension_name analyse archive [class_tvars class method_tvars argsTC]) (do phase.monad [_ (..ensure_fresh_class! class) @@ -1491,18 +1492,18 @@ (def: annotation_parameter (Parser (Annotation_Parameter Code)) - (<c>.tuple (<>.and <c>.text <c>.any))) + (<code>.tuple (<>.and <code>.text <code>.any))) (type: #export (Annotation a) [Text (List (Annotation_Parameter a))]) (def: #export annotation (Parser (Annotation Code)) - (<c>.form (<>.and <c>.text (<>.some ..annotation_parameter)))) + (<code>.form (<>.and <code>.text (<>.some ..annotation_parameter)))) (def: #export argument (Parser Argument) - (<c>.tuple (<>.and <c>.text ..type))) + (<code>.tuple (<>.and <code>.text ..type))) (def: (annotation_parameter_analysis [name value]) (-> (Annotation_Parameter Analysis) Analysis) @@ -1603,10 +1604,10 @@ (def: #export visibility (Parser Visibility) ($_ <>.or - (<c>.text! ..public_tag) - (<c>.text! ..private_tag) - (<c>.text! ..protected_tag) - (<c>.text! ..default_tag))) + (<code>.text! ..public_tag) + (<code>.text! ..private_tag) + (<code>.text! ..protected_tag) + (<code>.text! ..default_tag))) (def: #export (visibility_analysis visibility) (-> Visibility Analysis) @@ -1631,18 +1632,18 @@ (def: #export constructor_definition (Parser (Constructor Code)) - (<| <c>.form - (<>.after (<c>.text! ..constructor_tag)) + (<| <code>.form + (<>.after (<code>.text! ..constructor_tag)) ($_ <>.and ..visibility - <c>.bit - (<c>.tuple (<>.some ..annotation)) - (<c>.tuple (<>.some ..var)) - (<c>.tuple (<>.some ..class)) - <c>.text - (<c>.tuple (<>.some ..argument)) - (<c>.tuple (<>.some ..input)) - <c>.any))) + <code>.bit + (<code>.tuple (<>.some ..annotation)) + (<code>.tuple (<>.some ..var)) + (<code>.tuple (<>.some ..class)) + <code>.text + (<code>.tuple (<>.some ..argument)) + (<code>.tuple (<>.some ..input)) + <code>.any))) (def: #export (analyse_constructor_method analyse archive selfT mapping method) (-> Phase Archive .Type Mapping (Constructor Code) (Operation Analysis)) @@ -1710,20 +1711,20 @@ (def: #export virtual_method_definition (Parser (Virtual_Method Code)) - (<| <c>.form - (<>.after (<c>.text! ..virtual_tag)) + (<| <code>.form + (<>.after (<code>.text! ..virtual_tag)) ($_ <>.and - <c>.text + <code>.text ..visibility - <c>.bit - <c>.bit - (<c>.tuple (<>.some ..annotation)) - (<c>.tuple (<>.some ..var)) - <c>.text - (<c>.tuple (<>.some ..argument)) + <code>.bit + <code>.bit + (<code>.tuple (<>.some ..annotation)) + (<code>.tuple (<>.some ..var)) + <code>.text + (<code>.tuple (<>.some ..argument)) ..return - (<c>.tuple (<>.some ..class)) - <c>.any))) + (<code>.tuple (<>.some ..class)) + <code>.any))) (def: #export (analyse_virtual_method analyse archive selfT mapping method) (-> Phase Archive .Type Mapping (Virtual_Method Code) (Operation Analysis)) @@ -1786,18 +1787,18 @@ (def: #export static_method_definition (Parser (Static_Method Code)) - (<| <c>.form - (<>.after (<c>.text! ..static_tag)) + (<| <code>.form + (<>.after (<code>.text! ..static_tag)) ($_ <>.and - <c>.text + <code>.text ..visibility - <c>.bit - (<c>.tuple (<>.some ..annotation)) - (<c>.tuple (<>.some ..var)) - (<c>.tuple (<>.some ..class)) - (<c>.tuple (<>.some ..argument)) + <code>.bit + (<code>.tuple (<>.some ..annotation)) + (<code>.tuple (<>.some ..var)) + (<code>.tuple (<>.some ..class)) + (<code>.tuple (<>.some ..argument)) ..return - <c>.any))) + <code>.any))) (def: #export (analyse_static_method analyse archive mapping method) (-> Phase Archive Mapping (Static_Method Code) (Operation Analysis)) @@ -1859,19 +1860,19 @@ (def: #export overriden_method_definition (Parser (Overriden_Method Code)) - (<| <c>.form - (<>.after (<c>.text! ..overriden_tag)) + (<| <code>.form + (<>.after (<code>.text! ..overriden_tag)) ($_ <>.and ..class - <c>.text - <c>.bit - (<c>.tuple (<>.some ..annotation)) - (<c>.tuple (<>.some ..var)) - <c>.text - (<c>.tuple (<>.some ..argument)) + <code>.text + <code>.bit + (<code>.tuple (<>.some ..annotation)) + (<code>.tuple (<>.some ..var)) + <code>.text + (<code>.tuple (<>.some ..argument)) ..return - (<c>.tuple (<>.some ..class)) - <c>.any + (<code>.tuple (<>.some ..class)) + <code>.any ))) (def: #export (analyse_overriden_method analyse archive selfT mapping method) @@ -1984,11 +1985,11 @@ Handler (..custom [($_ <>.and - (<c>.tuple (<>.some ..var)) + (<code>.tuple (<>.some ..var)) ..class - (<c>.tuple (<>.some ..class)) - (<c>.tuple (<>.some ..input)) - (<c>.tuple (<>.some ..overriden_method_definition))) + (<code>.tuple (<>.some ..class)) + (<code>.tuple (<>.some ..input)) + (<code>.tuple (<>.some ..overriden_method_definition))) (function (_ extension_name analyse archive [parameters super_class super_interfaces diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux index 400cdacb2..ade8e367f 100644 --- a/stdlib/source/lux/world/file.lux +++ b/stdlib/source/lux/world/file.lux @@ -925,10 +925,8 @@ ## ..default_separator) ## )) ## ) - - @.scheme - (as_is) - })) + } + (as_is))) (def: #export (exists? monad fs path) (All [!] (-> (Monad !) (System !) Path (! Bit))) diff --git a/stdlib/source/program/aedifex/artifact.lux b/stdlib/source/program/aedifex/artifact.lux index 9e87988ea..e5d37f7bb 100644 --- a/stdlib/source/program/aedifex/artifact.lux +++ b/stdlib/source/program/aedifex/artifact.lux @@ -2,10 +2,11 @@ [lux (#- Name) [abstract [equivalence (#+ Equivalence)] + [order (#+ Order)] [hash (#+ Hash)]] [data ["." product] - ["." text + ["." text ("#\." order) ["%" format (#+ Format)]] [collection ["." list ("#\." monoid)]]] @@ -40,6 +41,26 @@ (Equivalence Artifact) (\ ..hash &equivalence)) +(implementation: #export order + (Order Artifact) + + (def: &equivalence + ..equivalence) + + (def: (< reference subject) + (<| (or (text\< (get@ #group reference) + (get@ #group subject))) + + (and (text\= (get@ #group reference) + (get@ #group subject))) + (or (text\< (get@ #name reference) + (get@ #name subject))) + + (and (text\= (get@ #name reference) + (get@ #name subject))) + (text\< (get@ #version reference) + (get@ #version subject))))) + (template [<separator> <definition>] [(def: <definition> Text diff --git a/stdlib/source/program/aedifex/command/deps.lux b/stdlib/source/program/aedifex/command/deps.lux index de4817ba8..4dcc9d6e1 100644 --- a/stdlib/source/program/aedifex/command/deps.lux +++ b/stdlib/source/program/aedifex/command/deps.lux @@ -46,13 +46,20 @@ (list\fold dictionary.remove resolution) (///dependency/deployment.all local)) _ (console.write_line (exception.report - ["Local successes" (exception.enumerate ..format local_successes)] - ["Local failures" (exception.enumerate ..format local_failures)] - ["Remote successes" (let [remote_successes (|> remote_successes - (set.from_list ///dependency.hash) - (set.difference (set.from_list ///dependency.hash local_successes)) - set.to_list)] - (exception.enumerate ..format remote_successes))] - ["Remote failures" (exception.enumerate ..format remote_failures)]) + ["Local successes" (|> local_successes + (list.sort (\ ///dependency.order <)) + (exception.enumerate ..format))] + ["Local failures" (|> local_failures + (list.sort (\ ///dependency.order <)) + (exception.enumerate ..format))] + ["Remote successes" (|> remote_successes + (set.from_list ///dependency.hash) + (set.difference (set.from_list ///dependency.hash local_successes)) + set.to_list + (list.sort (\ ///dependency.order <)) + (exception.enumerate ..format))] + ["Remote failures" (|> remote_failures + (list.sort (\ ///dependency.order <)) + (exception.enumerate ..format))]) console)] (wrap resolution)))) diff --git a/stdlib/source/program/aedifex/dependency.lux b/stdlib/source/program/aedifex/dependency.lux index b7b605447..f06b00260 100644 --- a/stdlib/source/program/aedifex/dependency.lux +++ b/stdlib/source/program/aedifex/dependency.lux @@ -2,13 +2,14 @@ [lux (#- Type) [abstract [equivalence (#+ Equivalence)] + [order (#+ Order)] [hash (#+ Hash)]] [data ["." product] - ["." text + ["." text ("#\." order) ["%" format (#+ format)]]]] ["." // #_ - ["#" artifact (#+ Artifact) + ["#" artifact (#+ Artifact) ("#\." order) [type (#+ Type)]]]) (type: #export Dependency @@ -25,3 +26,18 @@ (def: #export equivalence (Equivalence Dependency) (\ hash &equivalence)) + +(implementation: #export order + (Order Dependency) + + (def: &equivalence + ..equivalence) + + (def: (< reference subject) + (<| (or (//\< (get@ #artifact reference) + (get@ #artifact subject))) + + (and (//\= (get@ #artifact reference) + (get@ #artifact subject))) + (text\< (get@ #type reference) + (get@ #type subject))))) diff --git a/stdlib/source/program/aedifex/dependency/resolution.lux b/stdlib/source/program/aedifex/dependency/resolution.lux index 326f2ac2d..63c3e930d 100644 --- a/stdlib/source/program/aedifex/dependency/resolution.lux +++ b/stdlib/source/program/aedifex/dependency/resolution.lux @@ -169,8 +169,8 @@ text.new_line)))] ["?" announce_fetching "Fetching" "from"] - ["Y" announce_success "Found" "at"] - ["N" announce_failure "Missed" "from"] + ["O" announce_success "Found" "at"] + ["X" announce_failure "Missed" "from"] ) (def: #export (any console repositories dependency) diff --git a/stdlib/source/program/aedifex/metadata.lux b/stdlib/source/program/aedifex/metadata.lux index 7fbe88cbc..843f2e056 100644 --- a/stdlib/source/program/aedifex/metadata.lux +++ b/stdlib/source/program/aedifex/metadata.lux @@ -17,7 +17,7 @@ (def: #export (remote_artifact_uri artifact) (-> Artifact URI) (let [/ uri.separator] - (format (get@ #//artifact.group artifact) + (format (//artifact.directory / (get@ #//artifact.group artifact)) / (get@ #//artifact.name artifact) / (get@ #//artifact.version artifact) / ..remote_file))) @@ -25,7 +25,7 @@ (def: #export (remote_project_uri artifact) (-> Artifact URI) (let [/ uri.separator] - (format (get@ #//artifact.group artifact) + (format (//artifact.directory / (get@ #//artifact.group artifact)) / (get@ #//artifact.name artifact) / ..remote_file))) diff --git a/stdlib/source/program/aedifex/metadata/snapshot.lux b/stdlib/source/program/aedifex/metadata/snapshot.lux index 6eec0c32c..518e0404a 100644 --- a/stdlib/source/program/aedifex/metadata/snapshot.lux +++ b/stdlib/source/program/aedifex/metadata/snapshot.lux @@ -41,7 +41,8 @@ ["#/." type (#+ Type)] ["#/." versioning (#+ Versioning)] ["#/." snapshot - ["#/." version]]]]]) + ["#/." version] + ["#/." stamp]]]]]) (type: #export Metadata {#artifact Artifact @@ -93,18 +94,22 @@ [group (<xml>.somewhere (..text ..<group>)) name (<xml>.somewhere (..text ..<name>)) version (<xml>.somewhere (..text ..<version>)) - versioning (\ ! map - (update@ #///artifact/versioning.versions - (: (-> (List ///artifact/snapshot/version.Version) - (List ///artifact/snapshot/version.Version)) - (|>> (case> (^ (list)) - (list {#///artifact/snapshot/version.extension ///artifact/type.jvm_library - #///artifact/snapshot/version.value version - #///artifact/snapshot/version.updated ///artifact/time.epoch}) + versioning (with_expansions [<default_version> {#///artifact/snapshot/version.extension ///artifact/type.jvm_library + #///artifact/snapshot/version.value version + #///artifact/snapshot/version.updated ///artifact/time.epoch}] + (|> (<xml>.somewhere ///artifact/versioning.parser) + (\ ! map + (update@ #///artifact/versioning.versions + (: (-> (List ///artifact/snapshot/version.Version) + (List ///artifact/snapshot/version.Version)) + (|>> (case> (^ (list)) + (list <default_version>) - versions - versions)))) - (<xml>.somewhere ///artifact/versioning.parser))] + versions + versions))))) + (<>.default {#///artifact/versioning.snapshot #///artifact/snapshot.Local + #///artifact/versioning.last_updated ///artifact/time.epoch + #///artifact/versioning.versions (list <default_version>)})))] (wrap {#artifact {#///artifact.group group #///artifact.name name #///artifact.version version} diff --git a/stdlib/source/program/aedifex/parser.lux b/stdlib/source/program/aedifex/parser.lux index 60e491dac..835b03729 100644 --- a/stdlib/source/program/aedifex/parser.lux +++ b/stdlib/source/program/aedifex/parser.lux @@ -4,7 +4,7 @@ [monad (#+ do)]] [control ["<>" parser - ["<c>" code (#+ Parser)]]] + ["<.>" code (#+ Parser)]]] [data ["." text] [collection @@ -37,25 +37,25 @@ (def: (singular input tag parser) (All [a] (-> (Dictionary Text Code) Text (Parser a) (Parser a))) - (<c>.local (..as_input (dictionary.get tag input)) - parser)) + (<code>.local (..as_input (dictionary.get tag input)) + parser)) (def: (plural input tag parser) (All [a] (-> (Dictionary Text Code) Text (Parser a) (Parser (List a)))) - (<c>.local (..as_input (dictionary.get tag input)) - (<c>.tuple (<>.some parser)))) + (<code>.local (..as_input (dictionary.get tag input)) + (<code>.tuple (<>.some parser)))) (def: group (Parser //artifact.Group) - <c>.text) + <code>.text) (def: name (Parser //artifact.Name) - <c>.text) + <code>.text) (def: version (Parser //artifact.Version) - <c>.text) + <code>.text) (def: artifact' (Parser //artifact.Artifact) @@ -63,11 +63,11 @@ (def: artifact (Parser //artifact.Artifact) - (<c>.tuple ..artifact')) + (<code>.tuple ..artifact')) (def: url (Parser URL) - <c>.text) + <code>.text) (def: scm (Parser /.SCM) @@ -75,30 +75,30 @@ (def: description (Parser Text) - <c>.text) + <code>.text) (def: license (Parser /.License) (do {! <>.monad} [input (\ ! map (dictionary.from_list text.hash) - (<c>.record (<>.some (<>.and <c>.local_tag - <c>.any))))] + (<code>.record (<>.some (<>.and <code>.local_tag + <code>.any))))] ($_ <>.and (..singular input "name" ..name) (..singular input "url" ..url) (<>.default #/.Repo (..singular input "type" - (<>.or (<c>.this! (' #repo)) - (<c>.this! (' #manual)))))))) + (<>.or (<code>.this! (' #repo)) + (<code>.this! (' #manual)))))))) (def: organization (Parser /.Organization) (do {! <>.monad} [input (\ ! map (dictionary.from_list text.hash) - (<c>.record (<>.some (<>.and <c>.local_tag - <c>.any))))] + (<code>.record (<>.some (<>.and <code>.local_tag + <code>.any))))] ($_ <>.and (..singular input "name" ..name) (..singular input "url" ..url)))) @@ -108,8 +108,8 @@ (do {! <>.monad} [input (\ ! map (dictionary.from_list text.hash) - (<c>.record (<>.some (<>.and <c>.local_tag - <c>.any))))] + (<code>.record (<>.some (<>.and <code>.local_tag + <code>.any))))] ($_ <>.and (..singular input "name" ..name) (..singular input "url" ..url) @@ -125,8 +125,8 @@ (do {! <>.monad} [input (\ ! map (dictionary.from_list text.hash) - (<c>.record (<>.some (<>.and <c>.local_tag - <c>.any))))] + (<code>.record (<>.some (<>.and <code>.local_tag + <code>.any))))] ($_ <>.and (<>.maybe (..singular input "url" ..url)) (<>.maybe (..singular input "scm" ..scm)) @@ -143,11 +143,11 @@ (def: type (Parser //artifact/type.Type) - <c>.text) + <code>.text) (def: dependency (Parser //dependency.Dependency) - (<c>.tuple + (<code>.tuple ($_ <>.and ..artifact' (<>.default //artifact/type.lux_library ..type) @@ -155,32 +155,32 @@ (def: source (Parser /.Source) - <c>.text) + <code>.text) (def: target (Parser /.Target) - <c>.text) + <code>.text) (def: module (Parser Module) - <c>.text) + <code>.text) (def: deploy_repository (Parser (List [Text //repository.Address])) - (<c>.record (<>.some - (<>.and <c>.text - ..repository)))) + (<code>.record (<>.some + (<>.and <code>.text + ..repository)))) (def: profile (Parser /.Profile) (do {! <>.monad} [input (\ ! map (dictionary.from_list text.hash) - (<c>.record (<>.some (<>.and <c>.local_tag - <c>.any)))) + (<code>.record (<>.some (<>.and <code>.local_tag + <code>.any)))) #let [^parents (: (Parser (List /.Name)) (<>.default (list) - (..plural input "parents" <c>.text))) + (..plural input "parents" <code>.text))) ^identity (: (Parser (Maybe Artifact)) (<>.maybe (..singular input "identity" ..artifact))) @@ -236,7 +236,7 @@ multi_profile (: (Parser Project) (\ <>.monad map (dictionary.from_list text.hash) - (<c>.record (<>.many (<>.and <c>.text - ..profile)))))] + (<code>.record (<>.many (<>.and <code>.text + ..profile)))))] (<>.either multi_profile default_profile))) diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux index 8b577ec09..b964e6502 100644 --- a/stdlib/source/program/compositor.lux +++ b/stdlib/source/program/compositor.lux @@ -102,10 +102,10 @@ analysis.Bundle (IO (Platform <parameters>)) (generation.Bundle <parameters>) - (directive.Bundle <parameters>) + (-> platform.Phase_Wrapper (directive.Bundle <parameters>)) (Program expression artifact) [Type Type Type] - Extender + (-> platform.Phase_Wrapper Extender) Service [Packager file.Path] (Promise Any))) diff --git a/stdlib/source/test/lux/extension.lux b/stdlib/source/test/lux/extension.lux index 8ff1cdc00..e20189fa3 100644 --- a/stdlib/source/test/lux/extension.lux +++ b/stdlib/source/test/lux/extension.lux @@ -10,18 +10,24 @@ ["." php] ["." scheme]] [abstract - [monad (#+ do)]] + ["." monad (#+ do)]] [control ["." try] ["<>" parser - ["<c>" code] - ["<a>" analysis] - ["<s>" synthesis]]] + ["<.>" code] + ["<.>" analysis] + ["<.>" synthesis]]] [data + ["." product] ["." text ("#\." equivalence) ["%" format (#+ format)]] [collection - ["." row]]] + ["." row] + ["." list ("#\." functor)]]] + [math + ["." random] + [number + ["n" nat]]] [tool [compiler ["." phase] @@ -40,81 +46,96 @@ (def: my_analysis "my analysis") (def: my_synthesis "my synthesis") (def: my_generation "my generation") +(def: dummy_generation "dummy generation") (def: my_directive "my directive") ## Generation (for {@.old (as_is)} - (as_is (analysis: (..my_generation self phase archive {parameters (<>.some <c>.any)}) - (do phase.monad - [_ (type.infer .Text)] - (wrap (#analysis.Extension self (list))))) + (as_is + ## Analysis + (analysis: (..my_analysis self phase archive {pass_through <code>.any}) + (phase archive pass_through)) - (synthesis: (..my_generation self phase archive {parameters (<>.some <a>.any)}) - (do phase.monad - [] - (wrap (#synthesis.Extension self (list))))) - )) + ## Synthesis + (analysis: (..my_synthesis self phase archive {parameters (<>.some <code>.any)}) + (let [! phase.monad] + (|> parameters + (monad.map ! (phase archive)) + (\ ! map (|>> (#analysis.Extension self)))))) -(for {@.old - (as_is)} - - (generation: (..my_generation self phase archive {parameters (<>.some <s>.any)}) - (do phase.monad - [] - (wrap (for {@.jvm - (row.row (#jvm.Constant (#jvm.LDC (#jvm.String self)))) + (synthesis: (..my_synthesis self phase archive {pass_through <analysis>.any}) + (phase archive pass_through)) - @.js (js.string self) - @.python (python.unicode self) - @.lua (lua.string self) - @.ruby (ruby.string self) - @.php (php.string self) - @.scheme (scheme.string self)}))))) + ## Generation + (analysis: (..my_generation self phase archive {parameters (<>.some <code>.any)}) + (let [! phase.monad] + (|> parameters + (monad.map ! (phase archive)) + (\ ! map (|>> (#analysis.Extension self)))))) -(for {@.old - (as_is)} - - (as_is (analysis: (..my_analysis self phase archive {parameters (<>.some <c>.any)}) - (do phase.monad - [_ (type.infer .Text)] - (wrap (#analysis.Primitive (#analysis.Text self))))) + (synthesis: (..my_generation self phase archive {parameters (<>.some <analysis>.any)}) + (let [! phase.monad] + (|> parameters + (monad.map ! (phase archive)) + (\ ! map (|>> (#synthesis.Extension self)))))) + + (generation: (..my_generation self phase archive {pass_through <synthesis>.any}) + (for {@.jvm + (\ phase.monad map (|>> #jvm.Embedded row.row) + (phase archive pass_through))} + (phase archive pass_through))) + + (analysis: (..dummy_generation self phase archive) + (\ phase.monad wrap (#analysis.Extension self (list)))) + + (synthesis: (..dummy_generation self phase archive) + (\ phase.monad wrap (#synthesis.Extension self (list)))) + + (generation: (..dummy_generation self phase archive) + (\ phase.monad wrap + (for {@.jvm + (row.row (#jvm.Constant (#jvm.LDC (#jvm.String self)))) - ## Synthesis - (analysis: (..my_synthesis self phase archive {parameters (<>.some <c>.any)}) - (do phase.monad - [_ (type.infer .Text)] - (wrap (#analysis.Extension self (list))))) + @.js (js.string self) + @.python (python.unicode self) + @.lua (lua.string self) + @.ruby (ruby.string self) + @.php (php.string self) + @.scheme (scheme.string self)}))) - (synthesis: (..my_synthesis self phase archive {parameters (<>.some <a>.any)}) - (do phase.monad - [] - (wrap (synthesis.text self)))) - - ## Directive - (directive: (..my_directive self phase archive {parameters (<>.some <c>.any)}) - (do phase.monad - [#let [_ (debug.log! (format "Successfully installed directive " (%.text self) "!"))]] - (wrap directive.no_requirements))) + ## Directive + (directive: (..my_directive self phase archive {parameters (<>.some <code>.any)}) + (do phase.monad + [#let [_ (debug.log! (format "Successfully installed directive " (%.text self) "!"))]] + (wrap directive.no_requirements))) - (`` ((~~ (static ..my_directive)))) - )) + (`` ((~~ (static ..my_directive)))) + )) (def: #export test Test (<| (_.covering /._) - (`` ($_ _.and - (~~ (template [<macro> <extension>] - [(_.cover [<macro>] - (for {@.old - false} - (text\= (`` ((~~ (static <extension>)))) - <extension>)))] + (do random.monad + [expected random.nat] + (`` ($_ _.and + (~~ (template [<macro> <extension>] + [(_.cover [<macro>] + (for {@.old + false} + (n.= expected + (`` ((~~ (static <extension>)) expected)))))] - [/.analysis: ..my_analysis] - [/.synthesis: ..my_synthesis] - [/.generation: ..my_generation])) - (_.cover [/.directive:] - true) - )))) + [/.analysis: ..my_analysis] + [/.synthesis: ..my_synthesis])) + (_.cover [/.generation:] + (for {@.old + false} + (and (n.= expected + (`` ((~~ (static ..my_generation)) expected))) + (text\= ..dummy_generation + (`` ((~~ (static ..dummy_generation)))))))) + (_.cover [/.directive:] + true) + ))))) diff --git a/stdlib/source/test/lux/time.lux b/stdlib/source/test/lux/time.lux index cc18c20e0..b22823626 100644 --- a/stdlib/source/test/lux/time.lux +++ b/stdlib/source/test/lux/time.lux @@ -1,21 +1,155 @@ (.module: [lux #* - ["_" test (#+ Test)]] + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence] + ["$." order] + ["$." enum] + ["$." codec]]}] + [control + [pipe (#+ case>)] + ["." try ("#\." functor)] + ["." exception] + [parser + ["<.>" text]]] + [data + ["." text + ["%" format (#+ format)]]] + [math + ["." random] + [number + ["n" nat]]]] ["." / #_ ["#." date] ["#." day] ["#." duration] ["#." instant] ["#." month] - ["#." year]]) + ["#." year]] + {1 + ["." / + ["." duration]]}) -(def: #export test +(def: for_implementation Test ($_ _.and - /date.test - /day.test - /duration.test - /instant.test - /month.test - /year.test - )) + (_.for [/.equivalence] + ($equivalence.spec /.equivalence random.time)) + (_.for [/.order] + ($order.spec /.order random.time)) + (_.for [/.enum] + ($enum.spec /.enum random.time)) + (_.for [/.codec] + ($codec.spec /.equivalence /.codec random.time)))) + +(def: for_clock + Test + (do {! random.monad} + [expected random.time] + (_.cover [/.clock /.time] + (|> expected + /.clock + /.time + (try\map (\ /.equivalence = expected)) + (try.default false))))) + +(def: for_ranges + Test + (do {! random.monad} + [valid_hour (\ ! map (|>> (n.% /.hours) (n.max 10)) random.nat) + valid_minute (\ ! map (|>> (n.% /.minutes) (n.max 10)) random.nat) + valid_second (\ ! map (|>> (n.% /.seconds) (n.max 10)) random.nat) + valid_milli_second (\ ! map (n.% /.milli_seconds) random.nat) + + #let [invalid_hour (|> valid_hour (n.+ /.hours)) + invalid_minute (|> valid_minute (n.+ /.minutes) (n.min 99)) + invalid_second (|> valid_second (n.+ /.seconds) (n.min 99))]] + (`` ($_ _.and + (~~ (template [<cap> <exception> <prefix> <suffix> <valid> <invalid>] + [(_.cover [<cap> <exception>] + (let [valid! + (|> <valid> + %.nat + (text.prefix <prefix>) + (text.suffix <suffix>) + (\ /.codec decode) + (case> (#try.Success _) true + (#try.Failure error) false)) + + invalid! + (|> <invalid> + %.nat + (text.prefix <prefix>) + (text.suffix <suffix>) + (\ /.codec decode) + (case> (#try.Success _) + false + + (#try.Failure error) + (exception.match? <exception> error)))] + (and valid! + invalid!)))] + + [/.hours /.invalid_hour "" ":00:00.000" valid_hour invalid_hour] + [/.minutes /.invalid_minute "00:" ":00.000" valid_minute invalid_minute] + [/.seconds /.invalid_second "00:00:" ".000" valid_second invalid_second] + )) + (_.cover [/.milli_seconds] + (|> valid_milli_second + %.nat + (format "00:00:00.") + (\ /.codec decode) + (case> (#try.Success _) true + (#try.Failure error) false))) + )))) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Time]) + (do {! random.monad} + [#let [day (.nat (duration.to_millis duration.day))] + expected random.time + + out_of_bounds (\ ! map (|>> /.to_millis (n.+ day)) + random.time)] + (`` ($_ _.and + ..for_implementation + + (_.cover [/.to_millis /.from_millis] + (|> expected + /.to_millis + /.from_millis + (try\map (\ /.equivalence = expected)) + (try.default false))) + (_.cover [/.time_exceeds_a_day] + (case (/.from_millis out_of_bounds) + (#try.Success _) + false + + (#try.Failure error) + (exception.match? /.time_exceeds_a_day error))) + (_.cover [/.midnight] + (|> /.midnight + /.to_millis + (n.= 0))) + (_.cover [/.parser] + (|> expected + (\ /.codec encode) + (<text>.run /.parser) + (try\map (\ /.equivalence = expected)) + (try.default false))) + ..for_ranges + (_.for [/.Clock] + ..for_clock) + + /date.test + /day.test + /duration.test + /instant.test + /month.test + /year.test + ))))) |