aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2019-03-14 18:13:22 -0400
committerEduardo Julian2019-03-14 18:13:22 -0400
commit298c435c3466b36ce83bec90065d7ac2553b4476 (patch)
tree4b344818f50baa471d8f47851f947046143f0d23
parent55ea02ec50e350ededa3721063f03d365aa0a4df (diff)
Added a peek-and-pop optimization to pattern-matching on JS.
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/js/case.lux16
1 files changed, 15 insertions, 1 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 0bafcd3c0..b8a0cd00d 100644
--- a/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux
@@ -69,9 +69,13 @@
(-> Expression Statement)
(_.statement (|> @cursor (_.do "push" (list value)))))
+(def: peek-and-pop-cursor
+ Expression
+ (|> @cursor (_.do "pop" (list))))
+
(def: pop-cursor!
Statement
- (_.statement (|> @cursor (_.do "pop" (list)))))
+ (_.statement ..peek-and-pop-cursor))
(def: peek-cursor
Expression
@@ -130,6 +134,16 @@
([synthesis.member/left //runtime.product//left (<|)]
[synthesis.member/right //runtime.product//right inc])
+ (^ ($_ synthesis.path/seq
+ (#synthesis.Bind register)
+ #synthesis.Pop
+ thenP))
+ (do ////.monad
+ [then! (pattern-matching' generate thenP)]
+ (/////wrap ($_ _.then
+ (_.define (..register register) ..peek-and-pop-cursor)
+ then!)))
+
(^template [<tag> <computation>]
(^ (<tag> leftP rightP))
(do ////.monad