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.lux36
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation.lux27
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/reference.lux6
3 files changed, 50 insertions, 19 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux
index 10a3b4985..629e5af59 100644
--- a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux
+++ b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux
@@ -6,6 +6,7 @@
[io (#+ IO)]
["p" parser]]
[data
+ ["." product]
["." maybe]
["." error]
[text
@@ -20,7 +21,9 @@
["." check]]]
["." //
["#." bundle]
+ ["#." analysis]
["#/" //
+ ["#." macro (#+ Expander)]
["#." generation]
[analysis
["." module]
@@ -28,7 +31,9 @@
["#/" // #_
["#." analysis]
["#." synthesis (#+ Synthesis)]
- ["#." statement (#+ Import Operation Handler Bundle)]]]])
+ ["#." statement (#+ Import Operation Handler Bundle)]
+ [default
+ ["#." evaluation]]]]])
## TODO: Inline "evaluate!'" into "evaluate!" ASAP
(def: (evaluate!' generate code//type codeS)
@@ -123,8 +128,24 @@
(module.declare-tags tags (macro.export? annotations) (:coerce Type value)))
(wrap [])))))
-(def: lux::def
- Handler
+(def: (refresh expander)
+ (All [anchor expression statement]
+ (-> Expander (Operation anchor expression statement Any)))
+ (do ///.monad
+ [[bundle state] ///.get-state
+ #let [eval (////evaluation.evaluator expander
+ (get@ [#////statement.synthesis #////statement.state] state)
+ (get@ [#////statement.generation #////statement.state] state)
+ (get@ [#////statement.generation #////statement.phase] state))]]
+ (///.set-state [bundle
+ (update@ [#////statement.analysis #////statement.state]
+ (: (-> ////analysis.State+ ////analysis.State+)
+ (|>> product.right
+ [(//analysis.bundle eval)]))
+ state)])))
+
+(def: (lux::def expander)
+ (-> Expander Handler)
(function (_ extension-name phase inputsC+)
(case inputsC+
(^ (list [_ (#.Identifier ["" short-name])] valueC annotationsC))
@@ -142,7 +163,8 @@
_ (..define short-name value//type annotationsV valueV)
#let [_ (log! (format "Definition " (%name full-name)))]
_ (////statement.lift-generation
- (///generation.learn full-name valueN))]
+ (///generation.learn full-name valueN))
+ _ (..refresh expander)]
(wrap ////statement.no-requirements))
_
@@ -309,10 +331,10 @@
(dictionary.put "program" (def::program program))
)))
-(def: #export (bundle program)
+(def: #export (bundle expander program)
(All [anchor expression statement]
- (-> (-> expression statement) (Bundle anchor expression statement)))
+ (-> Expander (-> expression statement) (Bundle anchor expression statement)))
(<| (//bundle.prefix "lux")
(|> //bundle.empty
- (dictionary.put "def" lux::def)
+ (dictionary.put "def" (lux::def expander))
(dictionary.merge (..bundle::def program)))))
diff --git a/stdlib/source/lux/tool/compiler/phase/generation.lux b/stdlib/source/lux/tool/compiler/phase/generation.lux
index 3053752fe..edf260e19 100644
--- a/stdlib/source/lux/tool/compiler/phase/generation.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation.lux
@@ -7,12 +7,13 @@
[data
["." product]
["." error (#+ Error)]
- ["." name ("#;." equivalence)]
+ ["." name ("#@." equivalence)]
["." text
format]
[collection
["." row (#+ Row)]
- ["." dictionary (#+ Dictionary)]]]]
+ ["." dictionary (#+ Dictionary)]
+ ["." list ("#@." functor)]]]]
["." //
["." extension]
[//
@@ -21,13 +22,21 @@
[archive
[descriptor (#+ Module)]]]]])
+(type: #export Registry
+ (Dictionary Name Text))
+
(exception: #export (cannot-interpret {error Text})
(exception.report
["Error" error]))
-(exception: #export (unknown-lux-name {name Name})
+(exception: #export (unknown-lux-name {name Name} {registry Registry})
(exception.report
- ["Name" (%name name)]))
+ ["Name" (%name name)]
+ ["Registry" (|> registry
+ dictionary.keys
+ (list.sort (:: name.order <))
+ (list@map %name)
+ (text.join-with text.new-line))]))
(exception: #export (cannot-overwrite-lux-name {lux-name Name}
{old-host-name Text}
@@ -68,7 +77,7 @@
#buffer (Maybe (Buffer statement))
#output (Output statement)
#counter Nat
- #name-cache (Dictionary Name Text)})
+ #name-cache Registry})
(template [<special> <general>]
[(type: #export (<special> anchor expression statement)
@@ -118,8 +127,8 @@
(def: #export empty-buffer Buffer row.empty)
(template [<tag>
- <with-declaration> <with-type> <with-value>
- <set> <get> <get-type> <exception>]
+ <with-declaration> <with-type> <with-value>
+ <set> <get> <get-type> <exception>]
[(exception: #export <exception>)
(def: #export <with-declaration>
@@ -221,7 +230,7 @@
?buffer (extension.read (get@ #buffer))]
(case ?buffer
(#.Some buffer)
- (if (row.any? (|>> product.left (name;= name)) buffer)
+ (if (row.any? (|>> product.left (name@= name)) buffer)
(//.throw cannot-overwrite-output name)
(extension.update (set@ #buffer (#.Some (row.add [name code] buffer)))))
@@ -245,7 +254,7 @@
(#error.Success [stateE host-name])
#.None
- (exception.throw unknown-lux-name lux-name)))))
+ (exception.throw unknown-lux-name [lux-name cache])))))
(def: #export (learn lux-name host-name)
(All [anchor expression statement]
diff --git a/stdlib/source/lux/tool/compiler/phase/generation/reference.lux b/stdlib/source/lux/tool/compiler/phase/generation/reference.lux
index 4907ada5d..534d58cb1 100644
--- a/stdlib/source/lux/tool/compiler/phase/generation/reference.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation/reference.lux
@@ -7,7 +7,7 @@
format]]
[type (#+ :share)]]
["." //
- ["#/" // ("#;." monad)
+ ["#/" // ("#@." monad)
["#/" // #_
[synthesis (#+ Synthesis)]
["#." reference (#+ Register Variable Reference)]]]])
@@ -61,13 +61,13 @@
(#////reference.Foreign register)
(foreign register))
- ///;wrap)})
+ ///@wrap)})
constant (:share [expression]
{(-> Text expression)
constant}
{(All [anchor statement]
(-> Name (//.Operation anchor expression statement)))
- (|>> //.remember (///;map constant))})]
+ (|>> //.remember (///@map constant))})]
(structure
(def: local local)
(def: foreign foreign)