diff options
author | Eduardo Julian | 2020-06-11 00:28:20 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-06-11 00:28:20 -0400 |
commit | def9629b35a434b3441aa15b89746b21d6c298ec (patch) | |
tree | 1b7f6ef8cc76a0d9f4e3c74d4d20239a43955873 /stdlib/source/lux/tool | |
parent | bbb6356a4a4f853dc48a54f1668c6712f0ef659f (diff) |
Updated test for function optimization.
Diffstat (limited to '')
5 files changed, 41 insertions, 20 deletions
diff --git a/stdlib/source/lux/tool/compiler/language/lux/analysis.lux b/stdlib/source/lux/tool/compiler/language/lux/analysis.lux index 71009473a..f3dc89993 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/analysis.lux @@ -39,14 +39,16 @@ (#Frac Frac) (#Text Text)) -(type: #export Tag Nat) +(type: #export Tag + Nat) (type: #export (Variant a) {#lefts Nat #right? Bit #value a}) -(type: #export (Tuple a) (List a)) +(type: #export (Tuple a) + (List a)) (type: #export (Composite a) (#Variant (Variant a)) @@ -186,21 +188,26 @@ [control/case #..Case] ) -(template [<name> <type> <tag>] +(template: #export (unit) + (#..Primitive #..Unit)) + +(template [<name> <tag>] [(template: #export (<name> value) (#..Primitive (<tag> value)))] - [bit Bit #..Bit] - [nat Nat #..Nat] - [int Int #..Int] - [rev Rev #..Rev] - [frac Frac #..Frac] - [text Text #..Text] + [bit #..Bit] + [nat #..Nat] + [int #..Int] + [rev #..Rev] + [frac #..Frac] + [text #..Text] ) -(type: #export (Abstraction c) [Environment Arity c]) +(type: #export (Abstraction c) + [Environment Arity c]) -(type: #export (Application c) [c (List c)]) +(type: #export (Application c) + [c (List c)]) (def: (last? size tag) (-> Nat Tag Bit) diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/synthesis/case.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/synthesis/case.lux index 3e2bbd321..3c80060c2 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/synthesis/case.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/synthesis/case.lux @@ -184,12 +184,6 @@ (#///analysis.Reference (///reference.local <output>))] (list)]) -(def: #export (synthesize-masking synthesize archive input @variable @output) - (-> Phase Archive Synthesis Register Register (Operation Synthesis)) - (if (n.= @variable @output) - (///@wrap input) - (..synthesize-case synthesize archive input (!masking @variable @output)))) - (def: #export (synthesize-let synthesize archive input @variable body) (-> Phase Archive Synthesis Register Analysis (Operation Synthesis)) (do ///.monad @@ -197,6 +191,12 @@ (synthesize archive body))] (wrap (/.branch/let [input @variable body])))) +(def: #export (synthesize-masking synthesize archive input @variable @output) + (-> Phase Archive Synthesis Register Register (Operation Synthesis)) + (if (n.= @variable @output) + (///@wrap input) + (..synthesize-let synthesize archive input @variable (#///analysis.Reference (///reference.local @output))))) + (def: #export (synthesize-if synthesize archive test then else) (-> Phase Archive Synthesis Analysis Analysis (Operation Synthesis)) (do ///.monad diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/synthesis/function.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/synthesis/function.lux index 358a63c31..896ec2161 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/synthesis/function.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/synthesis/function.lux @@ -5,7 +5,7 @@ [control ["." exception (#+ exception:)]] [data - ["." maybe] + ["." maybe ("#@." functor)] ["." text ["%" format (#+ format)]] [number @@ -59,6 +59,19 @@ [locals /.locals] (wrap (|> functionS (//loop.optimization true locals argsS) + (maybe@map (: (-> Synthesis Synthesis) + (function (_ synthesis) + (case synthesis + (^ (<| /.loop/scope [start inits] + /.loop/scope [start' inits'] + output)) + (if (and (n.= start start') + (list.empty? inits')) + (/.loop/scope [start inits output]) + synthesis) + + _ + synthesis)))) (maybe.default <apply>)))) (wrap <apply>)) diff --git a/stdlib/source/lux/tool/compiler/language/lux/synthesis.lux b/stdlib/source/lux/tool/compiler/language/lux/synthesis.lux index c010b05c3..590653281 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/synthesis.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/synthesis.lux @@ -397,7 +397,7 @@ (#Extension [name args]) (|> (list@map %synthesis args) (text.join-with " ") - (format (%.text name)) + (format (%.text name) " ") (text.enclose ["(" ")"])))) (def: #export %path diff --git a/stdlib/source/lux/tool/compiler/reference/variable.lux b/stdlib/source/lux/tool/compiler/reference/variable.lux index e0c814e8d..cea605e93 100644 --- a/stdlib/source/lux/tool/compiler/reference/variable.lux +++ b/stdlib/source/lux/tool/compiler/reference/variable.lux @@ -12,7 +12,8 @@ [text ["%" format (#+ Format)]]]]) -(type: #export Register Nat) +(type: #export Register + Nat) (type: #export Variable (#Local Register) |