aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/js/case.lux38
1 files changed, 36 insertions, 2 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 b8a0cd00d..11869fa7b 100644
--- a/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation/js/case.lux
@@ -77,10 +77,15 @@
Statement
(_.statement ..peek-and-pop-cursor))
+(def: length
+ (|>> (_.the "length")))
+
+(def: last-index
+ (|>> ..length (_.- (_.i32 +1))))
+
(def: peek-cursor
Expression
- (.let [idx (|> @cursor (_.the "length") (_.- (_.i32 +1)))]
- (|> @cursor (_.at idx))))
+ (|> @cursor (_.at (last-index @cursor))))
(def: save-cursor!
Statement
@@ -93,6 +98,24 @@
(def: fail-pm! _.break)
+(def: (count-pops path)
+ (-> Path [Nat Path])
+ (.case path
+ (^ ($_ synthesis.path/seq
+ #synthesis.Pop
+ path'))
+ (.let [[pops post-pops] (count-pops path')]
+ [(inc pops) post-pops])
+
+ _
+ [0 path]))
+
+(def: (multi-pop-cursor! pops)
+ (-> Nat Statement)
+ (.let [popsJS (_.i32 (.int pops))]
+ (_.statement (|> @cursor (_.do "splice" (list (|> @cursor ..length (_.- popsJS))
+ popsJS))))))
+
(exception: #export unrecognized-path)
(def: (pattern-matching' generate pathP)
@@ -144,6 +167,17 @@
(_.define (..register register) ..peek-and-pop-cursor)
then!)))
+ (^ ($_ synthesis.path/seq
+ #synthesis.Pop
+ #synthesis.Pop
+ nextP))
+ (.let [[extra-pops nextP'] (count-pops nextP)]
+ (do ////.monad
+ [next! (pattern-matching' generate nextP')]
+ (/////wrap ($_ _.then
+ (multi-pop-cursor! (n/+ 2 extra-pops))
+ next!))))
+
(^template [<tag> <computation>]
(^ (<tag> leftP rightP))
(do ////.monad