aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/meta/compiler/language/lux/phase/generation')
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/extension.lux24
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux47
2 files changed, 19 insertions, 52 deletions
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/extension.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/extension.lux
index fde10a521..9c8dbf379 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/extension.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/extension.lux
@@ -3,7 +3,11 @@
[lux (.except Synthesis)
[abstract
["[0]" monad (.only do)]]
+ [control
+ ["[0]" exception (.only Exception)]]
[data
+ [text
+ ["%" \\format]]
[collection
["[0]" list (.use "[1]#[0]" functor)]]]
["[0]" meta (.only)
@@ -29,16 +33,22 @@
[(All (_ of)
(-> (Vector arity of) of))]))
+(exception.def .public (incorrect_arity [expected actual])
+ (Exception [Nat Nat])
+ (exception.report
+ (list ["Expected" (%.nat expected)]
+ ["Actual" (%.nat actual)])))
+
(def arity
(syntax (_ [arity <code>.nat])
- (with_symbols [g!_ g!name g!extension g!phase g!archive g!inputs g!anchor g!expression g!declaration]
+ (with_symbols [g!_ g!extension g!phase g!archive g!inputs g!anchor g!expression g!declaration]
(do [! meta.monad]
[g!input+ (monad.all ! (list.repeated arity (macro.symbol "input")))]
(in (list (` (is (All ((, g!_) (, g!anchor) (, g!expression) (, g!declaration))
(-> ((Arity (, (code.nat arity))) (, g!expression))
- (-> Text (generation.Handler (, g!anchor) (, g!expression) (, g!declaration)))))
+ (generation.Handler (, g!anchor) (, g!expression) (, g!declaration))))
(function ((, g!_) (, g!extension))
- (function ((, g!_) (, g!name) (, g!phase) (, g!archive) (, g!inputs))
+ (function ((, g!_) (, g!phase) (, g!archive) (, g!inputs))
(when (, g!inputs)
(list (,* g!input+))
(do ///.monad
@@ -49,9 +59,7 @@
((,' in) ((, g!extension) [(,* g!input+)])))
(, g!_)
- (///.except ///extension.incorrect_arity [""
- (, (code.nat arity))
- (list.size (, g!inputs))]))
+ (///.except ..incorrect_arity [(, (code.nat arity)) (list.size (, g!inputs))]))
))))))))))
(with_template [<arity> <type> <term>]
@@ -69,8 +77,8 @@
(def .public (variadic extension)
(All (_ anchor expression declaration)
- (-> (Variadic expression) (-> Text (generation.Handler anchor expression declaration))))
- (function (_ extension_name phase archive inputsS)
+ (-> (Variadic expression) (generation.Handler anchor expression declaration)))
+ (function (_ phase archive inputsS)
(let [! ///.monad]
(|> inputsS
(monad.each ! (phase archive))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux
index d25fe3fcf..d8c4eb180 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux
@@ -39,49 +39,6 @@
["[0]" reference]
["[1]" phase (.use "[1]#[0]" monad)]]]]])
-(exception.def .public (not_an_extension [name expected actual])
- (Exception [Symbol Type Type])
- (exception.report
- (list ["Name" (%.symbol name)]
- ["Expected" (%.type expected)]
- ["Actual" (%.type actual)])))
-
-(exception.def .public (extension_error error)
- (Exception Text)
- error)
-
-(def (extension_application extender lux
- phase archive
- name parameters)
- (-> extension.Extender Lux
- Phase Archive
- Symbol (List Synthesis)
- (Operation (Bytecode Any)))
- (when (|> (do [! meta.monad]
- [definition (meta.try (meta.export name))]
- (when definition
- {try.#Success [exported? type definition]}
- (in [type {.#Left definition}])
-
- {try.#Failure error}
- (do !
- [[exported? type default] (meta.default name)]
- (in [type {.#Right default}]))))
- (is (Meta [Type (Either Any Any)]))
- (meta.result lux))
- {try.#Success [type value]}
- (if (check.subsumes? .Generation type)
- (when value
- {.#Left definition}
- ((extender definition) phase archive parameters)
-
- {.#Right default}
- ((as Handler default) phase archive parameters))
- (///.except ..not_an_extension [name .Generation type]))
-
- {try.#Failure error}
- (///.except ..extension_error [error])))
-
(def .public (generate extender lux)
(-> extension.Extender Lux Phase)
(function (phase archive synthesis)
@@ -136,5 +93,7 @@
(/function.apply phase archive application)
{synthesis.#Extension [name parameters]}
- (extension_application extender lux phase archive name parameters)
+ (extension.application extender lux phase archive .Generation name parameters
+ (|>>)
+ (function (_ _) {.#None}))
)))