aboutsummaryrefslogtreecommitdiff
path: root/src/lux/compiler/case.clj
diff options
context:
space:
mode:
authorEduardo Julian2015-10-07 02:10:47 -0400
committerEduardo Julian2015-10-07 02:10:47 -0400
commit7aae4fa5d885e9cf6a3913e1252f6c85aef15c51 (patch)
tree182e879a8c8abf2a0930f1827f9a02dc5043a7a3 /src/lux/compiler/case.clj
parentbce3a19e53036d760820e9f217d0243f17e4be51 (diff)
- Increased the compiler version from 0.3 to 0.4
- Now compiling empty tuples (unit) to null pointer - Now avoiding pattern-matching over empty tuples (unit)
Diffstat (limited to 'src/lux/compiler/case.clj')
-rw-r--r--src/lux/compiler/case.clj36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/lux/compiler/case.clj b/src/lux/compiler/case.clj
index 64237f3db..20c90d661 100644
--- a/src/lux/compiler/case.clj
+++ b/src/lux/compiler/case.clj
@@ -82,22 +82,26 @@
(.visitJumpInsn Opcodes/GOTO $target))
(&a-case/$TupleTestAC ?members)
- (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))
+ (if (&/|empty? ?members)
+ (doto writer
+ (.visitInsn Opcodes/POP)
+ (.visitJumpInsn Opcodes/GOTO $target))
+ (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)))
(&a-case/$VariantTestAC ?tag ?count ?test)
(doto writer