From 298c435c3466b36ce83bec90065d7ac2553b4476 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 14 Mar 2019 18:13:22 -0400 Subject: Added a peek-and-pop optimization to pattern-matching on JS. --- .../lux/tool/compiler/phase/generation/js/case.lux | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'stdlib') 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 [ ] (^ ( leftP rightP)) (do ////.monad -- cgit v1.2.3