aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/phase
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/tool/compiler/phase/directive.lux30
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation.lux18
2 files changed, 25 insertions, 23 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/directive.lux b/stdlib/source/lux/tool/compiler/phase/directive.lux
index f79f2b586..dc4115610 100644
--- a/stdlib/source/lux/tool/compiler/phase/directive.lux
+++ b/stdlib/source/lux/tool/compiler/phase/directive.lux
@@ -36,12 +36,10 @@
(def: #export (phase expander)
(-> Expander Phase)
(let [analyze (analysisP.phase expander)]
- (function (compile code)
+ (function (recur code)
(case code
(^ [_ (#.Form (list& [_ (#.Text name)] inputs))])
- (do //.monad
- [requirements (//extension.apply compile [name inputs])]
- (wrap requirements))
+ (//extension.apply recur [name inputs])
(^ [_ (#.Form (list& macro inputs))])
(do //.monad
@@ -58,22 +56,20 @@
(wrap macro)
#.None
- (//.throw macro-was-not-found macro-name))]
+ (//.throw ..macro-was-not-found macro-name))]
(//extension.lift (//macro.expand expander macro-name macro inputs)))
_
- (//.throw invalid-macro-call code))))
- requirements (case expansion
- (^ (list& <lux_def_module> referrals))
- (do @
- [requirements (compile <lux_def_module>)]
- (wrap (update@ #/.referrals (list;compose referrals) requirements)))
+ (//.throw ..invalid-macro-call code))))]
+ (case expansion
+ (^ (list& <lux_def_module> referrals))
+ (|> (recur <lux_def_module>)
+ (:: @ map (update@ #/.referrals (list;compose referrals))))
- _
- (|> expansion
- (monad.map @ compile)
- (:: @ map (list;fold /.merge-requirements /.no-requirements))))]
- (wrap requirements))
+ _
+ (|> expansion
+ (monad.map @ recur)
+ (:: @ map (list;fold /.merge-requirements /.no-requirements)))))
_
- (//.throw not-a-directive code))))))
+ (//.throw ..not-a-directive code))))))
diff --git a/stdlib/source/lux/tool/compiler/phase/generation.lux b/stdlib/source/lux/tool/compiler/phase/generation.lux
index 2f6e28ed2..35fa850be 100644
--- a/stdlib/source/lux/tool/compiler/phase/generation.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation.lux
@@ -90,12 +90,16 @@
[Bundle extension.Bundle]
)
+(def: #export (fresh-context scope-name)
+ (-> Text Context)
+ {#scope-name scope-name
+ #inner-functions 0})
+
(def: #export (state host)
(All [anchor expression directive]
(-> (Host expression directive)
(..State anchor expression directive)))
- {#context {#scope-name ""
- #inner-functions 0}
+ {#context (..fresh-context "")
#anchor #.None
#host host
#buffer #.None
@@ -110,7 +114,7 @@
(Operation anchor expression directive output)))
(function (_ [bundle state])
(let [old (get@ #context state)]
- (case (expr [bundle (set@ #context [specific-scope 0] state)])
+ (case (expr [bundle (set@ #context (..fresh-context specific-scope) state)])
(#try.Success [[bundle' state']
output])
(#try.Success [[bundle' (set@ #context old state')]
@@ -125,10 +129,12 @@
(Operation anchor expression directive [Text output])))
(function (_ [bundle state])
(let [[old-scope old-inner] (get@ #context state)
- new-scope (format old-scope "c" (%.nat old-inner))]
- (case (expr [bundle (set@ #context [new-scope 0] state)])
+ new-scope (format old-scope "$c" (%.nat old-inner))]
+ (case (expr [bundle (set@ #context (..fresh-context new-scope) state)])
(#try.Success [[bundle' state'] output])
- (#try.Success [[bundle' (set@ #context [old-scope (inc old-inner)] state')]
+ (#try.Success [[bundle' (set@ #context {#scope-name old-scope
+ #inner-functions (inc old-inner)}
+ state')]
[new-scope output]])
(#try.Failure error)