diff options
author | Eduardo Julian | 2019-10-15 00:50:03 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-10-15 00:50:03 -0400 |
commit | 2b5351eb4624ce3c3ada994caaaea77c9d397eb8 (patch) | |
tree | e886dc45f96fcaa21687747dd6481fed1ca1c769 /stdlib/source/lux/tool | |
parent | 7d2607a34183662bb640644888fb52281a2d3ab4 (diff) |
Compiler extensions have been tested to work.
Diffstat (limited to '')
7 files changed, 66 insertions, 54 deletions
diff --git a/stdlib/source/lux/tool/compiler/analysis.lux b/stdlib/source/lux/tool/compiler/analysis.lux index e59397ed9..5d9d899ab 100644 --- a/stdlib/source/lux/tool/compiler/analysis.lux +++ b/stdlib/source/lux/tool/compiler/analysis.lux @@ -129,8 +129,11 @@ <tag> content))] - [variable #reference.Variable] - [constant #reference.Constant] + [variable #reference.Variable] + [constant #reference.Constant] + + [variable/local reference.local] + [variable/foreign reference.foreign] ) (template [<name> <tag>] diff --git a/stdlib/source/lux/tool/compiler/default/init.lux b/stdlib/source/lux/tool/compiler/default/init.lux index 40549f8d0..c053445f2 100644 --- a/stdlib/source/lux/tool/compiler/default/init.lux +++ b/stdlib/source/lux/tool/compiler/default/init.lux @@ -29,11 +29,11 @@ [".P" synthesis] ["." generation] [".P" directive] - ["." extension + ["." extension (#+ Extender) [".E" analysis] [".E" synthesis] [directive - [".S" lux]]]] + [".D" lux]]]] [meta [archive ["." signature] @@ -47,7 +47,7 @@ #.version //.version #.mode #.Build}) -(def: #export (state target expander host-analysis host generate generation-bundle host-directive-bundle program) +(def: #export (state target expander host-analysis host generate generation-bundle host-directive-bundle program extender) (All [anchor expression directive] (-> Text Expander @@ -57,13 +57,14 @@ (generation.Bundle anchor expression directive) (///directive.Bundle anchor expression directive) (-> expression directive) + Extender (///directive.State+ anchor expression directive))) (let [synthesis-state [synthesisE.bundle ///synthesis.init] generation-state [generation-bundle (generation.state host)] eval (//evaluation.evaluator expander synthesis-state generation-state generate) analysis-state [(analysisE.bundle eval host-analysis) (///analysis.state (..info target) host)]] - [(dictionary.merge (luxS.bundle expander host-analysis program) + [(dictionary.merge (luxD.bundle expander host-analysis program extender) host-directive-bundle) {#///directive.analysis {#///directive.state analysis-state #///directive.phase (analysisP.phase expander)} diff --git a/stdlib/source/lux/tool/compiler/default/platform.lux b/stdlib/source/lux/tool/compiler/default/platform.lux index 04937092a..b37e74c2b 100644 --- a/stdlib/source/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/lux/tool/compiler/default/platform.lux @@ -23,7 +23,7 @@ ["#." phase [macro (#+ Expander)] ## TODO: Get rid of this import ASAP - [extension (#+)] + [extension (#+ Extender)] ["." generation (#+ Buffer)] [analysis ["." module]]] @@ -57,7 +57,7 @@ <State+> (as-is (///directive.State+ anchor expression directive)) <Bundle> (as-is (generation.Bundle anchor expression directive))] - (def: #export (initialize target expander host-analysis platform generation-bundle host-directive-bundle program) + (def: #export (initialize target expander host-analysis platform generation-bundle host-directive-bundle program extender) (All <type-vars> (-> Text Expander @@ -66,6 +66,7 @@ <Bundle> (///directive.Bundle anchor expression directive) (-> expression directive) + Extender (! (Try <State+>)))) (|> (do ///phase.monad [_ (:share [anchor expression directive] @@ -95,7 +96,8 @@ (get@ #phase platform) generation-bundle host-directive-bundle - program)) + program + extender)) (:: try.functor map product.left) (:: (get@ #&monad platform) wrap)) diff --git a/stdlib/source/lux/tool/compiler/phase/analysis/primitive.lux b/stdlib/source/lux/tool/compiler/phase/analysis/primitive.lux index 766dc6616..392ae4d8e 100644 --- a/stdlib/source/lux/tool/compiler/phase/analysis/primitive.lux +++ b/stdlib/source/lux/tool/compiler/phase/analysis/primitive.lux @@ -15,16 +15,16 @@ [_ (//type.infer <type>)] (wrap (#/.Primitive (<tag> value)))))] - [bit Bit #/.Bit] - [nat Nat #/.Nat] - [int Int #/.Int] - [rev Rev #/.Rev] - [frac Frac #/.Frac] - [text Text #/.Text] + [bit .Bit #/.Bit] + [nat .Nat #/.Nat] + [int .Int #/.Int] + [rev .Rev #/.Rev] + [frac .Frac #/.Frac] + [text .Text #/.Text] ) (def: #export unit (Operation Analysis) (do ///.monad - [_ (//type.infer Any)] + [_ (//type.infer .Any)] (wrap (#/.Primitive #/.Unit)))) diff --git a/stdlib/source/lux/tool/compiler/phase/extension.lux b/stdlib/source/lux/tool/compiler/phase/extension.lux index a0564cedd..7ba769476 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension.lux @@ -61,13 +61,16 @@ (list.sort text@<) (exception.enumerate %.text))])) -(def: #export (install name handler) +(type: #export (Extender s i o) + (-> Any (Handler s i o))) + +(def: #export (install extender name handler) (All [s i o] - (-> Text (Handler s i o) (Operation s i o Any))) + (-> (Extender s i o) Text (Handler s i o) (Operation s i o Any))) (function (_ [bundle state]) (case (dictionary.get name bundle) #.None - (#try.Success [[(dictionary.put name handler bundle) state] + (#try.Success [[(dictionary.put name (extender handler) bundle) state] []]) _ diff --git a/stdlib/source/lux/tool/compiler/phase/extension/directive/lux.lux b/stdlib/source/lux/tool/compiler/phase/extension/directive/lux.lux index 9344169f2..5f62d4d50 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/directive/lux.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/directive/lux.lux @@ -19,7 +19,7 @@ ["." code]] ["." type (#+ :share :by-example) ("#@." equivalence) ["." check]]] - ["." /// + ["." /// (#+ Extender) ["#." bundle] ["#." analysis] ["#/" // @@ -243,35 +243,38 @@ (define-alias alias def-name)))] (wrap /////directive.no-requirements)))])) -(template [<mame> <type> <scope>] - [(def: <mame> +(template [<description> <mame> <type> <scope>] + [(def: (<mame> extender) (All [anchor expression directive] - (Handler anchor expression directive)) + (-> Extender + (Handler anchor expression directive))) (function (handler extension-name phase inputsC+) (case inputsC+ - (^ (list [_ (#.Text name)] valueC)) + (^ (list nameC valueC)) (do ////.monad - [[_ handlerT handlerV] (evaluate! (:by-example [anchor expression directive] - {(Handler anchor expression directive) - handler} - <type>) - valueC) + [[_ _ name] (evaluate! Text nameC) + [_ _ handlerV] (evaluate! (:by-example [anchor expression directive] + {(Handler anchor expression directive) + handler} + <type>) + valueC) _ (<| <scope> - (///.install name) + (///.install extender (:coerce Text name)) (:share [anchor expression directive] {(Handler anchor expression directive) handler} {<type> - (:assume handlerV)}))] + (:assume handlerV)})) + #let [_ (log! (format <description> " " (%.text (:coerce Text name))))]] (wrap /////directive.no-requirements)) _ (////.throw ///.invalid-syntax [extension-name %.code inputsC+]))))] - [def::analysis /////analysis.Handler /////directive.lift-analysis] - [def::synthesis /////synthesis.Handler /////directive.lift-synthesis] - [def::generation (////generation.Handler anchor expression directive) /////directive.lift-generation] - [def::directive (/////directive.Handler anchor expression directive) (<|)] + ["Analysis" def::analysis /////analysis.Handler /////directive.lift-analysis] + ["Synthesis" def::synthesis /////synthesis.Handler /////directive.lift-synthesis] + ["Generation" def::generation (////generation.Handler anchor expression directive) /////directive.lift-generation] + ["Directive" def::directive (/////directive.Handler anchor expression directive) (<|)] ) ## TODO; Both "prepare-program" and "define-program" exist only @@ -321,25 +324,33 @@ _ (////.throw ///.invalid-syntax [extension-name %.code inputsC+])))) -(def: (bundle::def expander host-analysis program) +(def: (bundle::def expander host-analysis program extender) (All [anchor expression directive] - (-> Expander /////analysis.Bundle (-> expression directive) (Bundle anchor expression directive))) + (-> Expander + /////analysis.Bundle + (-> expression directive) + Extender + (Bundle anchor expression directive))) (<| (///bundle.prefix "def") (|> ///bundle.empty (dictionary.put "module" def::module) (dictionary.put "alias" def::alias) (dictionary.put "type tagged" (def::type-tagged expander host-analysis)) - (dictionary.put "analysis" def::analysis) - (dictionary.put "synthesis" def::synthesis) - (dictionary.put "generation" def::generation) - (dictionary.put "directive" def::directive) + (dictionary.put "analysis" (def::analysis extender)) + (dictionary.put "synthesis" (def::synthesis extender)) + (dictionary.put "generation" (def::generation extender)) + (dictionary.put "directive" (def::directive extender)) (dictionary.put "program" (def::program program)) ))) -(def: #export (bundle expander host-analysis program) +(def: #export (bundle expander host-analysis program extender) (All [anchor expression directive] - (-> Expander /////analysis.Bundle (-> expression directive) (Bundle anchor expression directive))) + (-> Expander + /////analysis.Bundle + (-> expression directive) + Extender + (Bundle anchor expression directive))) (<| (///bundle.prefix "lux") (|> ///bundle.empty (dictionary.put "def" (lux::def expander host-analysis)) - (dictionary.merge (..bundle::def expander host-analysis program))))) + (dictionary.merge (..bundle::def expander host-analysis program extender))))) diff --git a/stdlib/source/lux/tool/compiler/synthesis.lux b/stdlib/source/lux/tool/compiler/synthesis.lux index e44432bcb..3d1f7c6e3 100644 --- a/stdlib/source/lux/tool/compiler/synthesis.lux +++ b/stdlib/source/lux/tool/compiler/synthesis.lux @@ -228,20 +228,12 @@ <tag> content))] + [variable //reference.variable] + [constant //reference.constant] [variable/local //reference.local] [variable/foreign //reference.foreign] ) -(template [<name> <tag>] - [(template: #export (<name> content) - (.<| #..Reference - <tag> - content))] - - [variable //reference.variable] - [constant //reference.constant] - ) - (template [<name> <family> <tag>] [(template: #export (<name> content) (.<| #..Control |