diff options
author | Eduardo Julian | 2022-01-24 23:38:55 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-01-24 23:38:55 -0400 |
commit | 9a08039adfe40f76b9d5a5351005671c15b557bf (patch) | |
tree | f7d72bd0beb1576018abb4ee6774b8f19d2ea243 | |
parent | 6f55815f7f237df406e72c7a723055bb6238fce5 (diff) |
Added explicit function inlining.
Diffstat (limited to '')
-rw-r--r-- | changelog.md | 13 | ||||
-rw-r--r-- | documentation/bookmark/recursion_schemes.md | 32 | ||||
-rw-r--r-- | lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux | 13 | ||||
-rw-r--r-- | lux-mode/lux-mode.el | 2 | ||||
-rw-r--r-- | stdlib/source/library/lux/abstract/functor.lux | 3 | ||||
-rw-r--r-- | stdlib/source/library/lux/control/function/inline.lux | 50 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/function.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/function/inline.lux | 32 |
8 files changed, 123 insertions, 26 deletions
diff --git a/changelog.md b/changelog.md new file mode 100644 index 000000000..74d4372dc --- /dev/null +++ b/changelog.md @@ -0,0 +1,13 @@ +# Based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) + +## [Un-released] +### Added +* Inline functions. +### Changed +### Removed +### Fixed +### Deprecated +### Security + +[Un-released]: https://github.com/LuxLang/lux/compare/0.6.5...HEAD + diff --git a/documentation/bookmark/recursion_schemes.md b/documentation/bookmark/recursion_schemes.md index 5c41438df..31a013123 100644 --- a/documentation/bookmark/recursion_schemes.md +++ b/documentation/bookmark/recursion_schemes.md @@ -1,18 +1,20 @@ # Reference -1. [Probability Tree Diagrams. Recursion Schemes. Why Finding the Right Solution is Sometimes Hard?](https://rpeszek.github.io/posts/2021-07-18-prob-tree-scheme.html) -1. [Unifying Structured Recursion Schemes](https://www.cs.ox.ac.uk/people/nicolas.wu/papers/URS.pdf) -1. http://maartenfokkinga.github.io/utwente/mmf91m.pdf -1. http://blog.sumtypeofway.com/an-introduction-to-recursion-schemes/ -1. http://blog.sumtypeofway.com/recursion-schemes-part-2/ -1. http://blog.sumtypeofway.com/recursion-schemes-part-iii-folds-in-context/ -1. http://blog.sumtypeofway.com/recursion-schemes-part-iv-time-is-of-the-essence/ -1. http://comonad.com/reader/2009/recursion-schemes/ -1. [Peeling the Banana: Recursion Schemes from First Principles - Zainab Ali](https://www.youtube.com/watch?v=XZ9nPZbaYfE) -1. https://github.com/passy/awesome-recursion-schemes -1. [YOW! Lambda Jam 2018 - Amy Wong - Introduction to recursion scheme](https://www.youtube.com/watch?v=YnqPdlJd38o) -1. https://bartoszmilewski.com/2018/08/20/recursion-schemes-for-higher-algebras/ -1. https://blog.sumtypeofway.com/recursion-schemes-part-6-comonads-composition-and-generality/ -1. https://chrilves.github.io/hugo/posts/recursion_schemes_intro/ -1. [Recursion Schemes: A Field Guide (Redux)](http://comonad.com/reader/2009/recursion-schemes/) +0. [An Introduction to Recursion Schemes](https://blog.sumtypeofway.com/posts/introduction-to-recursion-schemes.html) +0. [Recursion Schemes, Part II: A Mob of Morphisms](https://blog.sumtypeofway.com/posts/recursion-schemes-part-2.html) +0. [Recursion Schemes, Part III: Folds in Context](https://blog.sumtypeofway.com/posts/recursion-schemes-part-3.html) +0. [Recursion Schemes, Part IV: Time is of the Essence](https://blog.sumtypeofway.com/posts/recursion-schemes-part-4.html) +0. [Recursion Schemes, Part 4½: Better Living Through Base Functors](https://blog.sumtypeofway.com/posts/recursion-schemes-part-4-point-5.html) +0. [Recursion Schemes, Part V: Hello, Hylomorphisms](https://blog.sumtypeofway.com/posts/recursion-schemes-part-5.html) +0. [Recursion Schemes, Part VI: Comonads, Composition, and Generality](https://blog.sumtypeofway.com/posts/recursion-schemes-part-6.html) +0. [Probability Tree Diagrams. Recursion Schemes. Why Finding the Right Solution is Sometimes Hard?](https://rpeszek.github.io/posts/2021-07-18-prob-tree-scheme.html) +0. [Unifying Structured Recursion Schemes](https://www.cs.ox.ac.uk/people/nicolas.wu/papers/URS.pdf) +0. http://maartenfokkinga.github.io/utwente/mmf91m.pdf +0. http://comonad.com/reader/2009/recursion-schemes/ +0. [Peeling the Banana: Recursion Schemes from First Principles - Zainab Ali](https://www.youtube.com/watch?v=XZ9nPZbaYfE) +0. https://github.com/passy/awesome-recursion-schemes +0. [YOW! Lambda Jam 2018 - Amy Wong - Introduction to recursion scheme](https://www.youtube.com/watch?v=YnqPdlJd38o) +0. https://bartoszmilewski.com/2018/08/20/recursion-schemes-for-higher-algebras/ +0. https://chrilves.github.io/hugo/posts/recursion_schemes_intro/ +0. [Recursion Schemes: A Field Guide (Redux)](http://comonad.com/reader/2009/recursion-schemes/) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux index 78033cc96..28a5c34bc 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux @@ -1015,13 +1015,14 @@ inputs! (|> inputsTI list.enumeration (list#each (function (_ [register [type term]]) - (case (type.primitive? type) - {.#Right type} - (_.ALOAD (++ register)) - - {.#Left type} + (let [then! (case (type.primitive? type) + {.#Right type} + (_.unwrap type) + + {.#Left type} + (_.CHECKCAST type))] (|>> (_.ALOAD (++ register)) - (_.CHECKCAST type))))) + then!)))) _.fuse) store_capturedI (|> env list.size diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el index c3c9e8ec2..b41c3848a 100644 --- a/lux-mode/lux-mode.el +++ b/lux-mode/lux-mode.el @@ -400,7 +400,7 @@ Called by `imenu--generic-function'." (function-definition (altRE "function" "|>>" "<<|" "||>")) (remember (altRE "remember" "to_do" "fix_me")) (definition (altRE "\\.using" - "def:" "type:" "program:" + "def:" "type:" "program:" "inline:" "implementation:" "macro:" "syntax:" "exception:" 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)]) + (<code>.form (<>.and <code>.local_symbol (<>.some <code>.any)))) + +(def: inline + (Parser [Code [Text (List Code)] Code Code]) + (|export|.parser + ($_ <>.and + ..declaration + <code>.any + <code>.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 (` (~! <code>.any))))) + list#conjoint)]] + (in (list (` ((~! syntax:) (~ privacy) ((~ (code.local_symbol name)) [(~+ g!parameters)]) + (.# (~! meta.monad) (~' in) (.list (.`' (~ inlined)))))))))) diff --git a/stdlib/source/test/lux/control/function.lux b/stdlib/source/test/lux/control/function.lux index d9444edd1..eed6c9635 100644 --- a/stdlib/source/test/lux/control/function.lux +++ b/stdlib/source/test/lux/control/function.lux @@ -17,7 +17,8 @@ ["[1][0]" contract] ["[1][0]" memo] ["[1][0]" mixin] - ["[1][0]" mutual]]) + ["[1][0]" mutual] + ["[1][0]" inline]]) (def: .public test Test @@ -62,4 +63,5 @@ /memo.test /mixin.test /mutual.test + /inline.test )))) diff --git a/stdlib/source/test/lux/control/function/inline.lux b/stdlib/source/test/lux/control/function/inline.lux new file mode 100644 index 000000000..7c05e39e0 --- /dev/null +++ b/stdlib/source/test/lux/control/function/inline.lux @@ -0,0 +1,32 @@ +(.using + [library + [lux "*" + ["_" test {"+" Test}] + [abstract + [monad {"+" do}]] + [math + ["[0]" random] + [number + ["i" int]]]]] + [\\library + ["[0]" /]]) + +(template: (!quadrance/2 m0 m1) + [(i.+ (i.* m0 m0) (i.* m1 m1))]) + +(/.inline: .public (quadrance/2 m0 m1) + (-> Int Int Int) + (!quadrance/2 m0 m1)) + +(def: .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [.let [measurement (# ! each (i.% +1000) random.int)] + m0 measurement + m1 measurement]) + ($_ _.and + (_.cover [/.inline:] + (i.= (..!quadrance/2 m0 m1) + (..quadrance/2 m0 m1))) + ))) |