From 219ad63a840bb3e153af9e9f0bdf1b9f4abd0cca Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 30 Dec 2019 02:04:00 -0400 Subject: Re-organized code-evaluation machinery. --- .../lux/tool/compiler/analysis/evaluation.lux | 41 ++++++++++++++++++++++ .../lux/tool/compiler/default/evaluation.lux | 41 ---------------------- stdlib/source/lux/tool/compiler/default/init.lux | 6 ++-- .../lux/tool/compiler/phase/extension/analysis.lux | 5 ++- .../tool/compiler/phase/extension/analysis/lux.lux | 5 ++- .../compiler/phase/extension/directive/lux.lux | 13 ++++--- 6 files changed, 54 insertions(+), 57 deletions(-) create mode 100644 stdlib/source/lux/tool/compiler/analysis/evaluation.lux delete mode 100644 stdlib/source/lux/tool/compiler/default/evaluation.lux diff --git a/stdlib/source/lux/tool/compiler/analysis/evaluation.lux b/stdlib/source/lux/tool/compiler/analysis/evaluation.lux new file mode 100644 index 000000000..5b0efc987 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/analysis/evaluation.lux @@ -0,0 +1,41 @@ +(.module: + [lux #* + [abstract + [monad (#+ do)]] + [control + ["." try]] + [data + [text + ["%" format (#+ format)]]]] + [// (#+ Operation) + [macro (#+ Expander)] + [// + ["." phase + [".P" analysis + ["." type]] + [".P" synthesis] + ["." generation] + [// + ["." synthesis]]]]]) + +(type: #export Eval + (-> Nat Type Code (Operation Any))) + +(def: #export (evaluator expander synthesis-state generation-state generate) + (All [anchor expression artifact] + (-> Expander + synthesis.State+ + (generation.State+ anchor expression artifact) + (generation.Phase anchor expression artifact) + Eval)) + (let [analyze (analysisP.phase expander)] + (function (eval count type exprC) + (do phase.monad + [exprA (type.with-type type + (analyze exprC))] + (phase.lift (do try.monad + [exprS (|> exprA synthesisP.phase (phase.run synthesis-state))] + (phase.run generation-state + (do phase.monad + [exprO (generate exprS)] + (generation.evaluate! (format "eval" (%.nat count)) exprO))))))))) diff --git a/stdlib/source/lux/tool/compiler/default/evaluation.lux b/stdlib/source/lux/tool/compiler/default/evaluation.lux deleted file mode 100644 index 2d7f32d85..000000000 --- a/stdlib/source/lux/tool/compiler/default/evaluation.lux +++ /dev/null @@ -1,41 +0,0 @@ -(.module: - [lux #* - [abstract - [monad (#+ do)]] - [control - ["." try]] - [data - [text - ["%" format (#+ format)]]]] - [/// - ["." phase - [".P" analysis - ["." type]] - [".P" synthesis] - ["." generation] - [// - [analysis (#+ Operation) - [macro (#+ Expander)]] - ["." synthesis]]]]) - -(type: #export Eval - (-> Nat Type Code (Operation Any))) - -(def: #export (evaluator expander synthesis-state generation-state generate) - (All [anchor expression artifact] - (-> Expander - synthesis.State+ - (generation.State+ anchor expression artifact) - (generation.Phase anchor expression artifact) - Eval)) - (let [analyze (analysisP.phase expander)] - (function (eval count type exprC) - (do phase.monad - [exprA (type.with-type type - (analyze exprC))] - (phase.lift (do try.monad - [exprS (|> exprA synthesisP.phase (phase.run synthesis-state))] - (phase.run generation-state - (do phase.monad - [exprO (generate exprS)] - (generation.evaluate! (format "eval" (%.nat count)) exprO))))))))) diff --git a/stdlib/source/lux/tool/compiler/default/init.lux b/stdlib/source/lux/tool/compiler/default/init.lux index 4220659b9..e31cb7107 100644 --- a/stdlib/source/lux/tool/compiler/default/init.lux +++ b/stdlib/source/lux/tool/compiler/default/init.lux @@ -17,10 +17,10 @@ ["." file]]] ["." // ["#." syntax (#+ Aliases)] - ["#." evaluation] ["/#" // (#+ Instancer) ["#." analysis - [macro (#+ Expander)]] + [macro (#+ Expander)] + ["#/." evaluation]] ["#." synthesis] ["#." directive (#+ Requirements)] ["#." phase @@ -61,7 +61,7 @@ (///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) + eval (///analysis/evaluation.evaluator expander synthesis-state generation-state generate) analysis-state [(analysisE.bundle eval host-analysis) (///analysis.state (..info target) host)]] [(dictionary.merge (luxD.bundle expander host-analysis program extender) diff --git a/stdlib/source/lux/tool/compiler/phase/extension/analysis.lux b/stdlib/source/lux/tool/compiler/phase/extension/analysis.lux index df378eebf..0f38bce97 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/analysis.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/analysis.lux @@ -4,9 +4,8 @@ [collection ["." dictionary]]]] [//// - [default - [evaluation (#+ Eval)]] - [analysis (#+ Bundle)]] + [analysis (#+ Bundle) + [evaluation (#+ Eval)]]] ["." / #_ ["#." lux]]) diff --git a/stdlib/source/lux/tool/compiler/phase/extension/analysis/lux.lux b/stdlib/source/lux/tool/compiler/phase/extension/analysis/lux.lux index b73f30a6b..0ddda71cf 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/analysis/lux.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/analysis/lux.lux @@ -28,9 +28,8 @@ [".A" case] [".A" function]] ["#/" // - [default - [evaluation (#+ Eval)]] - ["#." analysis (#+ Analysis Operation Phase Handler Bundle)]]]]) + ["#." analysis (#+ Analysis Operation Phase Handler Bundle) + [evaluation (#+ Eval)]]]]]) (def: #export (custom [syntax handler]) (All [s] 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 cc00bfa5f..faf7a0c13 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/directive/lux.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/directive/lux.lux @@ -31,9 +31,8 @@ ["#." synthesis (#+ Synthesis)] ["#." directive (#+ Import Requirements Phase Operation Handler Bundle)] ["#." analysis - [macro (#+ Expander)]] - [default - ["#." evaluation]]]]]) + [macro (#+ Expander)] + ["#/." evaluation]]]]]) (def: #export (custom [syntax handler]) (All [anchor expression directive s] @@ -131,10 +130,10 @@ (-> Expander /////analysis.Bundle (Operation anchor expression directive Any))) (do ////.monad [[bundle state] ////.get-state - #let [eval (/////evaluation.evaluator expander - (get@ [#/////directive.synthesis #/////directive.state] state) - (get@ [#/////directive.generation #/////directive.state] state) - (get@ [#/////directive.generation #/////directive.phase] state))]] + #let [eval (/////analysis/evaluation.evaluator expander + (get@ [#/////directive.synthesis #/////directive.state] state) + (get@ [#/////directive.generation #/////directive.state] state) + (get@ [#/////directive.generation #/////directive.phase] state))]] (////.set-state [bundle (update@ [#/////directive.analysis #/////directive.state] (: (-> /////analysis.State+ /////analysis.State+) -- cgit v1.2.3