From 412cbffb0e8d127b4f22733b9151c9e738fe7809 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 3 Mar 2019 14:32:34 -0400 Subject: Some refactoring around statements. --- new-luxc/source/luxc/lang/translation/jvm.lux | 1 - .../lang/translation/jvm/procedure/common.jvm.lux | 4 +- .../luxc/lang/translation/jvm/runtime.jvm.lux | 3 +- stdlib/source/lux/tool/compiler/default/init.lux | 6 +- .../source/lux/tool/compiler/default/platform.lux | 4 +- .../tool/compiler/phase/extension/statement.lux | 4 +- .../source/lux/tool/compiler/phase/statement.lux | 90 +++++++++++++--------- .../lux/tool/compiler/phase/statement/total.lux | 62 --------------- stdlib/source/lux/tool/compiler/program.lux | 4 +- stdlib/source/lux/tool/compiler/statement.lux | 46 +++++++++++ 10 files changed, 112 insertions(+), 112 deletions(-) delete mode 100644 stdlib/source/lux/tool/compiler/phase/statement/total.lux create mode 100644 stdlib/source/lux/tool/compiler/statement.lux diff --git a/new-luxc/source/luxc/lang/translation/jvm.lux b/new-luxc/source/luxc/lang/translation/jvm.lux index 01bc2b36f..d1d1a9f4c 100644 --- a/new-luxc/source/luxc/lang/translation/jvm.lux +++ b/new-luxc/source/luxc/lang/translation/jvm.lux @@ -135,7 +135,6 @@ (def: #export runtime-class "LuxRuntime") (def: #export function-class "LuxFunction") (def: #export runnable-class "LuxRunnable") -(def: #export unit "") (def: #export $Variant jvm.Type (type.array 1 ..$Object)) (def: #export $Tuple jvm.Type (type.array 1 ..$Object)) diff --git a/new-luxc/source/luxc/lang/translation/jvm/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/jvm/procedure/common.jvm.lux index f63c82108..55cf8a644 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/procedure/common.jvm.lux @@ -15,7 +15,7 @@ ["s" syntax (#+ syntax:)]] [tool [compiler - [synthesis (#+ Synthesis)] + ["." synthesis (#+ Synthesis)] ["." phase ["." extension ["." bundle]]]]] @@ -99,7 +99,7 @@ (_.label @end) ))) -(def: unitI Inst (_.string ///.unit)) +(def: unitI Inst (_.string synthesis.unit)) ## Extensions ### Lux diff --git a/new-luxc/source/luxc/lang/translation/jvm/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/jvm/runtime.jvm.lux index 0dbef1563..ae984baa9 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/runtime.jvm.lux @@ -11,6 +11,7 @@ [tool [compiler [analysis (#+ Arity)] + ["." synthesis] ["." phase ["." translation]]]]] [luxc @@ -72,7 +73,7 @@ Inst (|>> (_.int +0) _.NULL - (_.string //.unit) + (_.string synthesis.unit) variantI)) (def: (try-methodI unsafeI) diff --git a/stdlib/source/lux/tool/compiler/default/init.lux b/stdlib/source/lux/tool/compiler/default/init.lux index 0958c3b01..5de9970f6 100644 --- a/stdlib/source/lux/tool/compiler/default/init.lux +++ b/stdlib/source/lux/tool/compiler/default/init.lux @@ -19,6 +19,7 @@ ["/." // (#+ Instancer) ["." analysis] ["." synthesis] + ["." statement] ["." host] ["." phase [macro (#+ Expander)] @@ -26,8 +27,7 @@ ["." module]] [".P" synthesis] ["." translation] - ["." statement - [".S" total]] + [".P" statement] ["." extension [".E" analysis] [".E" synthesis] @@ -131,7 +131,7 @@ (def: (iteration expander reader) (-> Expander Reader ) - (let [execute (totalS.phase expander)] + (let [execute (statementP.phase expander)] (do phase.monad [code (statement.lift-analysis (..read reader)) diff --git a/stdlib/source/lux/tool/compiler/default/platform.lux b/stdlib/source/lux/tool/compiler/default/platform.lux index 959478f28..f9b4d4bd3 100644 --- a/stdlib/source/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/lux/tool/compiler/default/platform.lux @@ -11,10 +11,10 @@ ["." init] ["." syntax] ["/." // + ["." statement] ["." phase [macro (#+ Expander)] - ["." translation] - ["." statement]] + ["." translation]] ["." cli (#+ Configuration)] [meta ["." archive] diff --git a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux index 37ff93b9c..749924650 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux @@ -19,10 +19,10 @@ ["." module] ["." type]] ["." translation] - ["." statement (#+ Operation Handler Bundle)] [// ["." analysis] - ["." synthesis (#+ Synthesis)]]]]) + ["." synthesis (#+ Synthesis)] + ["." statement (#+ Operation Handler Bundle)]]]]) ## TODO: Inline "evaluate!'" into "evaluate!" ASAP (def: (evaluate!' translate code//type codeS) diff --git a/stdlib/source/lux/tool/compiler/phase/statement.lux b/stdlib/source/lux/tool/compiler/phase/statement.lux index ba84d146f..87736643c 100644 --- a/stdlib/source/lux/tool/compiler/phase/statement.lux +++ b/stdlib/source/lux/tool/compiler/phase/statement.lux @@ -1,46 +1,62 @@ (.module: - [lux #*] + [lux #* + [control + ["." monad (#+ do)] + ["." exception (#+ exception:)]] + [data + [text + format]] + ["." macro]] ["." // - ["." translation] - ["." extension] + ["//." macro (#+ Expander)] + ["//." extension] + [".P" analysis + ["." type]] [// - ["." analysis] - ["." synthesis]]]) + ["/" statement (#+ Phase)] + ["." analysis]]]) -(type: #export (Component state phase) - {#state state - #phase phase}) +(exception: #export (not-a-statement {code Code}) + (exception.report + ["Statement" (%code code)])) -(type: #export (State anchor expression statement) - {#analysis (Component analysis.State+ - analysis.Phase) - #synthesis (Component synthesis.State+ - synthesis.Phase) - #translation (Component (translation.State+ anchor expression statement) - (translation.Phase anchor expression statement))}) +(exception: #export (not-a-macro-call {code Code}) + (exception.report + ["Code" (%code code)])) -(do-template [ ] - [(type: #export ( anchor expression statement) - ( (..State anchor expression statement) Code Any))] +(exception: #export (macro-was-not-found {name Name}) + (exception.report + ["Name" (%name name)])) - [State+ extension.State] - [Operation extension.Operation] - [Phase extension.Phase] - [Handler extension.Handler] - [Bundle extension.Bundle] - ) +(def: #export (phase expander) + (-> Expander Phase) + (let [analyze (analysisP.phase expander)] + (function (compile code) + (case code + (^ [_ (#.Form (list& [_ (#.Text name)] inputs))]) + (//extension.apply compile [name inputs]) -(do-template [ ] - [(def: #export ( operation) - (All [anchor expression statement output] - (-> ( output) - (Operation anchor expression statement output))) - (extension.lift - (//.sub [(get@ [ #..state]) - (set@ [ #..state])] - operation)))] + (^ [_ (#.Form (list& macro inputs))]) + (do //.monad + [expansion (/.lift-analysis + (do @ + [macroA (type.with-type Macro + (analyze macro))] + (case macroA + (^ (analysis.constant macro-name)) + (do @ + [?macro (//extension.lift (macro.find-macro macro-name)) + macro (case ?macro + (#.Some macro) + (wrap macro) + + #.None + (//.throw macro-was-not-found macro-name))] + (//extension.lift (//macro.expand expander macro-name macro inputs))) + + _ + (//.throw not-a-macro-call code))))] + (monad.map @ compile expansion)) - [lift-analysis #..analysis analysis.Operation] - [lift-synthesis #..synthesis synthesis.Operation] - [lift-translation #..translation (translation.Operation anchor expression statement)] - ) + _ + (//.throw not-a-statement code))))) diff --git a/stdlib/source/lux/tool/compiler/phase/statement/total.lux b/stdlib/source/lux/tool/compiler/phase/statement/total.lux deleted file mode 100644 index 166425ffa..000000000 --- a/stdlib/source/lux/tool/compiler/phase/statement/total.lux +++ /dev/null @@ -1,62 +0,0 @@ -(.module: - [lux #* - [control - ["." monad (#+ do)] - ["." exception (#+ exception:)]] - [data - [text - format]] - ["." macro]] - ["." // (#+ Phase) - ["/." // - ["///." macro (#+ Expander)] - [".P" analysis - ["." type]] - ["." extension] - [// - ["." analysis]]]]) - -(exception: #export (not-a-statement {code Code}) - (exception.report - ["Statement" (%code code)])) - -(exception: #export (not-a-macro-call {code Code}) - (exception.report - ["Code" (%code code)])) - -(exception: #export (macro-was-not-found {name Name}) - (exception.report - ["Name" (%name name)])) - -(def: #export (phase expander) - (-> Expander Phase) - (let [analyze (analysisP.phase expander)] - (function (compile code) - (case code - (^ [_ (#.Form (list& [_ (#.Text name)] inputs))]) - (extension.apply compile [name inputs]) - - (^ [_ (#.Form (list& macro inputs))]) - (do ///.monad - [expansion (//.lift-analysis - (do @ - [macroA (type.with-type Macro - (analyze macro))] - (case macroA - (^ (analysis.constant macro-name)) - (do @ - [?macro (extension.lift (macro.find-macro macro-name)) - macro (case ?macro - (#.Some macro) - (wrap macro) - - #.None - (///.throw macro-was-not-found macro-name))] - (extension.lift (///macro.expand expander macro-name macro inputs))) - - _ - (///.throw not-a-macro-call code))))] - (monad.map @ compile expansion)) - - _ - (///.throw not-a-statement code))))) diff --git a/stdlib/source/lux/tool/compiler/program.lux b/stdlib/source/lux/tool/compiler/program.lux index 167f64221..265277ac7 100644 --- a/stdlib/source/lux/tool/compiler/program.lux +++ b/stdlib/source/lux/tool/compiler/program.lux @@ -15,10 +15,10 @@ ["." console]] [tool [compiler + ["." statement] [phase [macro (#+ Expander)] - ["." translation] - ["." statement]] + ["." translation]] [default ["." platform (#+ Platform)] ["." syntax]]] diff --git a/stdlib/source/lux/tool/compiler/statement.lux b/stdlib/source/lux/tool/compiler/statement.lux new file mode 100644 index 000000000..c4a8b56b1 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/statement.lux @@ -0,0 +1,46 @@ +(.module: + [lux #*] + [// + ["." analysis] + ["." synthesis] + ["." phase + ["." translation] + ["." extension]]]) + +(type: #export (Component state phase) + {#state state + #phase phase}) + +(type: #export (State anchor expression statement) + {#analysis (Component analysis.State+ + analysis.Phase) + #synthesis (Component synthesis.State+ + synthesis.Phase) + #translation (Component (translation.State+ anchor expression statement) + (translation.Phase anchor expression statement))}) + +(do-template [ ] + [(type: #export ( anchor expression statement) + ( (..State anchor expression statement) Code Any))] + + [State+ extension.State] + [Operation extension.Operation] + [Phase extension.Phase] + [Handler extension.Handler] + [Bundle extension.Bundle] + ) + +(do-template [ ] + [(def: #export ( operation) + (All [anchor expression statement output] + (-> ( output) + (Operation anchor expression statement output))) + (extension.lift + (phase.sub [(get@ [ #..state]) + (set@ [ #..state])] + operation)))] + + [lift-analysis #..analysis analysis.Operation] + [lift-synthesis #..synthesis synthesis.Operation] + [lift-translation #..translation (translation.Operation anchor expression statement)] + ) -- cgit v1.2.3