diff options
author | Eduardo Julian | 2019-06-14 23:38:53 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-06-14 23:38:53 -0400 |
commit | 7ee04017ee2ef5376c566b00750fd521c0ecac42 (patch) | |
tree | fd7bac69714079cfc9bd44bb56fad0321350f534 /stdlib/source/lux/tool/compiler/phase/generation/js/case.lux | |
parent | fcb8ce8340f4226a38d08f9e2f108e5ec0a95018 (diff) |
Some fixes for the scripting languages.
+ Small optimizations for pattern-matching generation.
Diffstat (limited to 'stdlib/source/lux/tool/compiler/phase/generation/js/case.lux')
-rw-r--r-- | stdlib/source/lux/tool/compiler/phase/generation/js/case.lux | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux index e1182c4b5..c2e0f667e 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux @@ -170,9 +170,29 @@ (^ (/////synthesis.member/left 0)) (////@wrap (push-cursor! (_.at (_.i32 +0) ..peek-cursor))) + ## Extra optimization + (^ (/////synthesis.path/seq + (/////synthesis.member/left 0) + (/////synthesis.!bind-top register thenP))) + (do ////.monad + [then! (pattern-matching' generate thenP)] + (////@wrap ($_ _.then + (_.define (..register register) (_.at (_.i32 +0) ..peek-cursor)) + then!))) + (^template [<pm> <getter>] (^ (<pm> lefts)) - (////@wrap (push-cursor! (<getter> (_.i32 (.int lefts)) ..peek-cursor)))) + (////@wrap (push-cursor! (<getter> (_.i32 (.int lefts)) ..peek-cursor))) + + ## Extra optimization + (^ (/////synthesis.path/seq + (<pm> lefts) + (/////synthesis.!bind-top register thenP))) + (do ////.monad + [then! (pattern-matching' generate thenP)] + (////@wrap ($_ _.then + (_.define (..register register) (<getter> (_.i32 (.int lefts)) ..peek-cursor)) + then!)))) ([/////synthesis.member/left //runtime.tuple//left] [/////synthesis.member/right //runtime.tuple//right]) @@ -200,20 +220,21 @@ ([/////synthesis.path/seq _.then] [/////synthesis.path/alt alternation]))) -(def: (pattern-matching generate pathP) - (-> Phase Path (Operation Statement)) +(def: (pattern-matching stack-init generate pathP) + (-> Expression Phase Path (Operation Statement)) (do ////.monad [pattern-matching! (pattern-matching' generate pathP)] (wrap ($_ _.then (_.do-while _.false pattern-matching!) + (_.statement (//runtime.io//log stack-init)) (_.throw (_.string case.pattern-matching-error)))))) (def: #export (case generate [valueS pathP]) (-> Phase [Synthesis Path] (Operation Computation)) (do ////.monad [stack-init (generate valueS) - path! (pattern-matching generate pathP) + path! (pattern-matching stack-init generate pathP) #let [closure (<| (_.closure (list)) ($_ _.then (_.declare @temp) |