From d0e4ba8124345ce990de7fdf7497dd903de6c342 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 30 Aug 2022 19:33:36 -0400 Subject: Got rid of the superfluous "lux macro" extension. --- stdlib/source/library/lux.lux | 154 +++++++++++---------- .../control/function/polymorphism/predicate.lux | 9 +- .../language/lux/phase/extension/analysis/lux.lux | 30 ---- stdlib/source/library/lux/meta/macro/local.lux | 24 ++-- stdlib/source/library/lux/meta/macro/template.lux | 20 +-- 5 files changed, 110 insertions(+), 127 deletions(-) (limited to 'stdlib/source/library') diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index df7b4ef66..f35ba4250 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -732,52 +732,54 @@ #0) ("lux def" let'' - ("lux macro" - ([_ tokens] - ({{#Item lhs {#Item rhs {#Item body {#End}}}} - (meta#in {#Item (form$ {#Item (variant$ {#Item lhs {#Item body {#End}}}) - {#Item rhs {#End}}}) - {#End}}) - - _ - (failure "Wrong syntax for let''")} - tokens))) + ("lux type as" Macro + ("lux type check" Macro' + ([_ tokens] + ({{#Item lhs {#Item rhs {#Item body {#End}}}} + (meta#in {#Item (form$ {#Item (variant$ {#Item lhs {#Item body {#End}}}) + {#Item rhs {#End}}}) + {#End}}) + + _ + (failure "Wrong syntax for let''")} + tokens)))) #0) ("lux def" function'' - ("lux macro" - ([_ tokens] - ({{#Item [_ {#Tuple {#Item arg args'}}] {#Item body {#End}}} - (meta#in {#Item (_ann {#Form {#Item (_ann {#Tuple {#Item (_ann {#Symbol ["" ""]}) - {#Item arg {#End}}}}) - {#Item ({{#End} - body - - _ - (_ann {#Form {#Item (_ann {#Symbol [..prelude "function''"]}) - {#Item (_ann {#Tuple args'}) - {#Item body {#End}}}}})} - args') - {#End}}}}) - {#End}}) - - {#Item [_ {#Symbol ["" self]}] {#Item [_ {#Tuple {#Item arg args'}}] {#Item body {#End}}}} - (meta#in {#Item (_ann {#Form {#Item (_ann {#Tuple {#Item (_ann {#Symbol ["" self]}) - {#Item arg {#End}}}}) - {#Item ({{#End} - body - - _ - (_ann {#Form {#Item (_ann {#Symbol [..prelude "function''"]}) - {#Item (_ann {#Tuple args'}) - {#Item body {#End}}}}})} - args') - {#End}}}}) - {#End}}) - - _ - (failure "Wrong syntax for function''")} - tokens))) + ("lux type as" Macro + ("lux type check" Macro' + ([_ tokens] + ({{#Item [_ {#Tuple {#Item arg args'}}] {#Item body {#End}}} + (meta#in {#Item (_ann {#Form {#Item (_ann {#Tuple {#Item (_ann {#Symbol ["" ""]}) + {#Item arg {#End}}}}) + {#Item ({{#End} + body + + _ + (_ann {#Form {#Item (_ann {#Symbol [..prelude "function''"]}) + {#Item (_ann {#Tuple args'}) + {#Item body {#End}}}}})} + args') + {#End}}}}) + {#End}}) + + {#Item [_ {#Symbol ["" self]}] {#Item [_ {#Tuple {#Item arg args'}}] {#Item body {#End}}}} + (meta#in {#Item (_ann {#Form {#Item (_ann {#Tuple {#Item (_ann {#Symbol ["" self]}) + {#Item arg {#End}}}}) + {#Item ({{#End} + body + + _ + (_ann {#Form {#Item (_ann {#Symbol [..prelude "function''"]}) + {#Item (_ann {#Tuple args'}) + {#Item body {#End}}}}})} + args') + {#End}}}}) + {#End}}) + + _ + (failure "Wrong syntax for function''")} + tokens)))) #0) ("lux def" as_def @@ -808,42 +810,48 @@ ("lux def" as_macro ("lux type check" {#Function Code Code} (function'' [expression] - (form$ {#Item (text$ "lux macro") - {#Item expression - {#End}}}))) + (form$ {#Item (text$ "lux type as") + {#Item (symbol$ [..prelude "Macro"]) + {#Item (form$ {#Item (text$ "lux type check") + {#Item (symbol$ [..prelude "Macro'"]) + {#Item expression + {#End}}}}) + {#End}}}}))) #0) ("lux def" def' - ("lux macro" - (function'' [tokens] - ({{#Item [export_policy - {#Item [[_ {#Form {#Item [name args]}}] - {#Item [type {#Item [body {#End}]}]}]}]} - (meta#in {#Item [(as_def name - (as_checked type (as_function name args body)) - export_policy) - {#End}]}) - - {#Item [export_policy {#Item [name {#Item [type {#Item [body {#End}]}]}]}]} - (meta#in {#Item [(as_def name (as_checked type body) - export_policy) - {#End}]}) - - _ - (failure "Wrong syntax for def'")} - tokens))) + ("lux type as" Macro + ("lux type check" Macro' + (function'' [tokens] + ({{#Item [export_policy + {#Item [[_ {#Form {#Item [name args]}}] + {#Item [type {#Item [body {#End}]}]}]}]} + (meta#in {#Item [(as_def name + (as_checked type (as_function name args body)) + export_policy) + {#End}]}) + + {#Item [export_policy {#Item [name {#Item [type {#Item [body {#End}]}]}]}]} + (meta#in {#Item [(as_def name (as_checked type body) + export_policy) + {#End}]}) + + _ + (failure "Wrong syntax for def'")} + tokens)))) #0) ("lux def" macro - ("lux macro" - (function'' [tokens] - ({{#Item [_ {#Form {#Item name {#Item head tail}}}] {#Item body {#End}}} - (meta#in {#Item (as_macro (as_function name {#Item head tail} body)) - {#End}}) - - _ - (failure (wrong_syntax_error [..prelude "macro"]))} - tokens))) + ("lux type as" Macro + ("lux type check" Macro' + (function'' [tokens] + ({{#Item [_ {#Form {#Item name {#Item head tail}}}] {#Item body {#End}}} + (meta#in {#Item (as_macro (as_function name {#Item head tail} body)) + {#End}}) + + _ + (failure (wrong_syntax_error [..prelude "macro"]))} + tokens)))) #1) (def' .public comment diff --git a/stdlib/source/library/lux/control/function/polymorphism/predicate.lux b/stdlib/source/library/lux/control/function/polymorphism/predicate.lux index 4ae4ca483..ed0d4097f 100644 --- a/stdlib/source/library/lux/control/function/polymorphism/predicate.lux +++ b/stdlib/source/library/lux/control/function/polymorphism/predicate.lux @@ -98,8 +98,13 @@ (function ((, g!self) (, next) (, name) [(,* parameters)]) (, (quoted default)))) )))] - (function ((, name) (,* parameters)) - ((, (quoted g!mixin)) [(,* parameters)]))))))))) + (, (when (the #parameters signature) + (list _) + (quoted g!mixin) + + _ + (` (function ((, name) (,* parameters)) + ((, (quoted g!mixin)) [(,* parameters)])))))))))))) ))))) (.def .public method diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lux.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lux.lux index 981d1a7a1..da97565c2 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lux.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lux.lux @@ -204,35 +204,6 @@ (<| (typeA.expecting input) (phase archive valueC))))])) -(exception.def .public (not_a_type symbol) - (Exception Symbol) - (exception.report - (list ["Symbol" (%.symbol symbol)]))) - -(def lux::macro - Handler - (..custom - [.any - (function (_ extension_name phase archive valueC) - (do [! ////.monad] - [_ (typeA.inference .Macro) - input_type (loop (again [input_name (symbol .Macro')]) - (do ! - [input_type (///.lifted (meta.definition (symbol .Macro')))] - (when input_type - (^.or {.#Definition [exported? def_type def_value]} - {.#Type [exported? def_value labels]}) - (in (as Type def_value)) - - (^.or {.#Tag _} - {.#Slot _}) - (////.failure (exception.error ..not_a_type [(symbol .Macro')])) - - {.#Alias real_name} - (again real_name))))] - (<| (typeA.expecting input_type) - (phase archive valueC))))])) - (def (bundle::lux eval) (-> Eval Bundle) (|> ///bundle.empty @@ -241,7 +212,6 @@ (///bundle.install "try" lux::try) (///bundle.install "type check" (lux::type::check eval)) (///bundle.install "type as" (lux::type::as eval)) - (///bundle.install "macro" ..lux::macro) (///bundle.install "type check type" (..caster .Type .Type)) (///bundle.install "in-module" lux::in_module))) diff --git a/stdlib/source/library/lux/meta/macro/local.lux b/stdlib/source/library/lux/meta/macro/local.lux index 48ca7db43..d1e9c9475 100644 --- a/stdlib/source/library/lux/meta/macro/local.lux +++ b/stdlib/source/library/lux/meta/macro/local.lux @@ -86,18 +86,18 @@ (def (pop_all macros self) (-> (List Symbol) Symbol Macro) - ("lux macro" - (function (_ _) - (do [! meta.monad] - [_ (monad.each ! ..pop_one macros) - _ (..pop_one self) - compiler meta.compiler_state] - (in (when (the .#expected compiler) - {.#Some _} - (list (' [])) - - {.#None} - (list))))))) + (//.macro + (function (_ _) + (do [! meta.monad] + [_ (monad.each ! ..pop_one macros) + _ (..pop_one self) + compiler meta.compiler_state] + (in (when (the .#expected compiler) + {.#Some _} + (list (' [])) + + {.#None} + (list))))))) (def .public (push macros) (-> (List [Symbol Macro]) (Meta Code)) diff --git a/stdlib/source/library/lux/meta/macro/template.lux b/stdlib/source/library/lux/meta/macro/template.lux index 829c971cf..77c26cfd4 100644 --- a/stdlib/source/library/lux/meta/macro/template.lux +++ b/stdlib/source/library/lux/meta/macro/template.lux @@ -135,16 +135,16 @@ (def (macro (open "_[0]")) (-> Local Macro) - ("lux macro" - (function (_ inputs compiler) - (.let [parameters_amount (list.size _#parameters) - inputs_amount (list.size inputs)] - (if (nat.= parameters_amount inputs_amount) - (.let [environment (is Environment - (|> (list.zipped_2 _#parameters inputs) - (dictionary.of_list text.hash)))] - {.#Right [compiler (list#each (..applied environment) _#template)]}) - (exception.except ..irregular_arguments [parameters_amount inputs_amount])))))) + (//.macro + (function (_ inputs compiler) + (.let [parameters_amount (list.size _#parameters) + inputs_amount (list.size inputs)] + (if (nat.= parameters_amount inputs_amount) + (.let [environment (is Environment + (|> (list.zipped_2 _#parameters inputs) + (dictionary.of_list text.hash)))] + {.#Right [compiler (list#each (..applied environment) _#template)]}) + (exception.except ..irregular_arguments [parameters_amount inputs_amount])))))) (def local (Parser Local) -- cgit v1.2.3