aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/phase
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/tool/compiler/phase')
-rw-r--r--stdlib/source/lux/tool/compiler/phase/extension/statement.lux4
-rw-r--r--stdlib/source/lux/tool/compiler/phase/statement.lux90
-rw-r--r--stdlib/source/lux/tool/compiler/phase/statement/total.lux62
3 files changed, 55 insertions, 101 deletions
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 [<special> <general>]
- [(type: #export (<special> anchor expression statement)
- (<general> (..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 [<name> <component> <operation>]
- [(def: #export (<name> operation)
- (All [anchor expression statement output]
- (-> (<operation> output)
- (Operation anchor expression statement output)))
- (extension.lift
- (//.sub [(get@ [<component> #..state])
- (set@ [<component> #..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)))))