aboutsummaryrefslogtreecommitdiff
path: root/src/lux/compiler/case.clj
diff options
context:
space:
mode:
authorEduardo Julian2016-01-16 22:33:43 -0400
committerEduardo Julian2016-01-16 22:33:43 -0400
commit1ec9e04527bf6ca5f9e86125bc605b8519497d2a (patch)
tree4fa71a17f91f12a618677a664fcd892a79af518f /src/lux/compiler/case.clj
parent3855f395e7cdd8e49086f2d0d82ed231e8896b69 (diff)
- Now using the new utility methods in LuxUtils for working with tuples/products.
Diffstat (limited to '')
-rw-r--r--src/lux/compiler/case.clj34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/lux/compiler/case.clj b/src/lux/compiler/case.clj
index 5e9aacc0f..314e7a6d3 100644
--- a/src/lux/compiler/case.clj
+++ b/src/lux/compiler/case.clj
@@ -95,22 +95,24 @@
(compile-match ?member $target $else)
_
- (doto writer
- (.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;")
- (-> (doto (.visitInsn Opcodes/DUP)
- (.visitLdcInsn (int idx))
- (.visitInsn Opcodes/AALOAD)
- (compile-match test $next $sub-else)
- (.visitLabel $sub-else)
- (.visitInsn Opcodes/POP)
- (.visitJumpInsn Opcodes/GOTO $else)
- (.visitLabel $next))
- (->> (|let [[idx test] idx+member
- $next (new Label)
- $sub-else (new Label)])
- (doseq [idx+member (->> ?members &/enumerate &/->seq)])))
- (.visitInsn Opcodes/POP)
- (.visitJumpInsn Opcodes/GOTO $target)))
+ (let [num-members (&/|length ?members)]
+ (doto writer
+ (.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;")
+ (-> (doto (.visitInsn Opcodes/DUP)
+ (.visitLdcInsn (int idx))
+ (.visitMethodInsn Opcodes/INVOKESTATIC "lux/LuxUtils" (if is-tail? "product_getRight" "product_getLeft") "([Ljava/lang/Object;I)Ljava/lang/Object;")
+ (compile-match test $next $sub-else)
+ (.visitLabel $sub-else)
+ (.visitInsn Opcodes/POP)
+ (.visitJumpInsn Opcodes/GOTO $else)
+ (.visitLabel $next))
+ (->> (|let [[idx test] idx+member
+ $next (new Label)
+ $sub-else (new Label)
+ is-tail? (= (dec num-members) idx)])
+ (doseq [idx+member (->> ?members &/enumerate &/->seq)])))
+ (.visitInsn Opcodes/POP)
+ (.visitJumpInsn Opcodes/GOTO $target))))
(&a-case/$VariantTestAC ?tag ?count ?test)
(doto writer