From 9a08039adfe40f76b9d5a5351005671c15b557bf Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 24 Jan 2022 23:38:55 -0400 Subject: Added explicit function inlining. --- stdlib/source/library/lux/abstract/functor.lux | 3 -- .../source/library/lux/control/function/inline.lux | 50 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 stdlib/source/library/lux/control/function/inline.lux (limited to 'stdlib/source/library') diff --git a/stdlib/source/library/lux/abstract/functor.lux b/stdlib/source/library/lux/abstract/functor.lux index fb5f412a3..fb3dab4c8 100644 --- a/stdlib/source/library/lux/abstract/functor.lux +++ b/stdlib/source/library/lux/abstract/functor.lux @@ -9,9 +9,6 @@ (-> (f a) (f b)))) each))) -(type: .public (Fix f) - (f (Fix f))) - (type: .public (Or f g) (All (_ a) (.Or (f a) (g a)))) diff --git a/stdlib/source/library/lux/control/function/inline.lux b/stdlib/source/library/lux/control/function/inline.lux new file mode 100644 index 000000000..ef0836888 --- /dev/null +++ b/stdlib/source/library/lux/control/function/inline.lux @@ -0,0 +1,50 @@ +(.using + [library + [lux "*" + ["[0]" meta] + [abstract + ["[0]" monad {"+" do}]] + [control + ["<>" parser + ["<[0]>" code {"+" Parser}]]] + [data + [collection + ["[0]" list ("[1]#[0]" monad)]]] + ["[0]" macro + ["[0]" code] + [syntax {"+" syntax:} + ["|[0]|" export]]]]]) + +(def: declaration + (Parser [Text (List Code)]) + (.form (<>.and .local_symbol (<>.some .any)))) + +(def: inline + (Parser [Code [Text (List Code)] Code Code]) + (|export|.parser + ($_ <>.and + ..declaration + .any + .any + ))) + +(syntax: .public (inline: [[privacy [name parameters] type term] ..inline]) + (do [! meta.monad] + [@ meta.current_module_name + g!parameters (|> (macro.symbol "parameter") + (list.repeated (list.size parameters)) + (monad.all !)) + .let [inlined (` (("lux in-module" + (~ (code.text @)) + (.: (~ type) + (.function ((~ (code.local_symbol name)) (~+ parameters)) + (~ term)))) + (~+ (list#each (function (_ g!parameter) + (` ((~' ~) (~ g!parameter)))) + g!parameters)))) + g!parameters (|> g!parameters + (list#each (function (_ parameter) + (list parameter (` (~! .any))))) + list#conjoint)]] + (in (list (` ((~! syntax:) (~ privacy) ((~ (code.local_symbol name)) [(~+ g!parameters)]) + (.# (~! meta.monad) (~' in) (.list (.`' (~ inlined)))))))))) -- cgit v1.2.3