aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/phase/extension/statement.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/tool/compiler/phase/extension/statement.lux')
-rw-r--r--stdlib/source/lux/tool/compiler/phase/extension/statement.lux92
1 files changed, 58 insertions, 34 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux
index 29602faf7..3d944b995 100644
--- a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux
+++ b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux
@@ -18,10 +18,25 @@
["." analysis
["." module]
["." type]]
- ["." synthesis]
+ ["." synthesis (#+ Synthesis)]
["." translation]
["." statement (#+ Operation Handler Bundle)]]])
+## TODO: Inline "evaluate!'" into "evaluate!" ASAP
+(def: (evaluate!' translate code//type codeS)
+ (All [anchor expression statement]
+ (-> (translation.Phase anchor expression statement)
+ Type
+ Synthesis
+ (Operation anchor expression statement [Type expression Any])))
+ (statement.lift-translation
+ (translation.with-buffer
+ (do ///.monad
+ [codeT (translate codeS)
+ count translation.next
+ codeV (translation.evaluate! (format "evaluate" (%n count)) codeT)]
+ (wrap [code//type codeT codeV])))))
+
(def: (evaluate! type codeC)
(All [anchor expression statement]
(-> Type Code (Operation anchor expression statement [Type expression Any])))
@@ -39,15 +54,24 @@
(wrap [type codeA]))))))
codeS (statement.lift-synthesis
(synthesize codeA))]
- (statement.lift-translation
- (translation.with-buffer
- (do @
- [codeT (translate codeS)
- count translation.next
- codeV (translation.evaluate! (format "evaluate" (%n count)) codeT)]
- (wrap [code//type codeT codeV]))))))
-
-(def: (define! name ?type codeC)
+ (evaluate!' translate code//type codeS)))
+
+## TODO: Inline "definition'" into "definition" ASAP
+(def: (definition' translate name code//type codeS)
+ (All [anchor expression statement]
+ (-> (translation.Phase anchor expression statement)
+ Name
+ Type
+ Synthesis
+ (Operation anchor expression statement [Type expression Text Any])))
+ (statement.lift-translation
+ (translation.with-buffer
+ (do ///.monad
+ [codeT (translate codeS)
+ codeN+V (translation.define! name codeT)]
+ (wrap [code//type codeT codeN+V])))))
+
+(def: (definition name ?type codeC)
(All [anchor expression statement]
(-> Name (Maybe Type) Code
(Operation anchor expression statement [Type expression Text Any])))
@@ -74,12 +98,23 @@
(wrap [code//type codeA]))))))
codeS (statement.lift-synthesis
(synthesize codeA))]
- (statement.lift-translation
- (translation.with-buffer
- (do @
- [codeT (translate codeS)
- codeN+V (translation.define! name codeT)]
- (wrap [code//type codeT codeN+V]))))))
+ (definition' translate name code//type codeS)))
+
+(def: (define short-name type annotations value)
+ (All [anchor expression statement]
+ (-> Text Type Code Any
+ (Operation anchor expression statement Any)))
+ (statement.lift-analysis
+ (do ///.monad
+ [_ (module.define short-name [type annotations value])]
+ (if (macro.type? annotations)
+ (case (macro.declared-tags annotations)
+ #.Nil
+ (wrap [])
+
+ tags
+ (module.declare-tags tags (macro.export? annotations) (:coerce Type value)))
+ (wrap [])))))
(def: lux::def
Handler
@@ -91,24 +126,13 @@
(//.lift macro.current-module-name))
#let [full-name [current-module short-name]]
[_ annotationsT annotationsV] (evaluate! Code annotationsC)
- #let [annotationsV (:coerce Code annotationsV)
- type-definition? (macro.type? annotationsV)]
- [value//type valueT valueN valueV] (define! full-name
- (if type-definition?
- (#.Some Type)
- #.None)
- valueC)
- _ (statement.lift-analysis
- (do @
- [_ (module.define short-name [value//type annotationsV valueV])]
- (if type-definition?
- (case (macro.declared-tags annotationsV)
- #.Nil
- (wrap [])
-
- tags
- (module.declare-tags tags (macro.export? annotationsV) (:coerce Type valueV)))
- (wrap []))))
+ #let [annotationsV (:coerce Code annotationsV)]
+ [value//type valueT valueN valueV] (..definition full-name
+ (if (macro.type? annotationsV)
+ (#.Some Type)
+ #.None)
+ valueC)
+ _ (..define short-name value//type annotationsV valueV)
#let [_ (log! (format "Definition " (%name full-name)))]]
(statement.lift-translation
(translation.learn full-name valueN)))