diff options
author | Eduardo Julian | 2016-01-17 01:08:53 -0400 |
---|---|---|
committer | Eduardo Julian | 2016-01-17 01:08:53 -0400 |
commit | f54a23399de846e63cc9586f36efcb30fea10be5 (patch) | |
tree | 10e8bc8b1e0c8ca0d781a3fc7ca0128562501ca2 /src/lux/compiler/case.clj | |
parent | 80f1597b8a8cc5db3baf32b8ffb82ddf286bc3d3 (diff) |
- Made a small modification to how variants/sums are created, to ensure variants for which there is only 1 possible value just compile down to that value (into the same way that 1-tuples are compiled down to their single value).
Diffstat (limited to '')
-rw-r--r-- | src/lux/compiler/case.clj | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/lux/compiler/case.clj b/src/lux/compiler/case.clj index 1b0e023eb..c7a7145f8 100644 --- a/src/lux/compiler/case.clj +++ b/src/lux/compiler/case.clj @@ -116,27 +116,29 @@ (.visitJumpInsn Opcodes/GOTO $target)))) (&a-case/$VariantTestAC ?tag ?count ?test) - (let [$variant-else (new Label)] - (doto writer - (.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;") - (.visitInsn Opcodes/DUP) - (.visitLdcInsn (int ?tag)) - (.visitMethodInsn Opcodes/INVOKESTATIC "lux/LuxUtils" "sum_get" "([Ljava/lang/Object;I)Ljava/lang/Object;") - (.visitInsn Opcodes/DUP) - (.visitInsn Opcodes/ACONST_NULL) - (.visitJumpInsn Opcodes/IF_ACMPEQ $variant-else) - (-> (doto (compile-match ?test $value-then $value-else) - (.visitLabel $value-then) - (.visitInsn Opcodes/POP) - (.visitJumpInsn Opcodes/GOTO $target) - (.visitLabel $value-else) - (.visitInsn Opcodes/POP) - (.visitJumpInsn Opcodes/GOTO $else)) - (->> (let [$value-then (new Label) - $value-else (new Label)]))) - (.visitLabel $variant-else) - (.visitInsn Opcodes/POP) - (.visitJumpInsn Opcodes/GOTO $else))) + (if (= 1 ?count) + (compile-match ?test $target $else) + (let [$variant-else (new Label)] + (doto writer + (.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;") + (.visitInsn Opcodes/DUP) + (.visitLdcInsn (int ?tag)) + (.visitMethodInsn Opcodes/INVOKESTATIC "lux/LuxUtils" "sum_get" "([Ljava/lang/Object;I)Ljava/lang/Object;") + (.visitInsn Opcodes/DUP) + (.visitInsn Opcodes/ACONST_NULL) + (.visitJumpInsn Opcodes/IF_ACMPEQ $variant-else) + (-> (doto (compile-match ?test $value-then $value-else) + (.visitLabel $value-then) + (.visitInsn Opcodes/POP) + (.visitJumpInsn Opcodes/GOTO $target) + (.visitLabel $value-else) + (.visitInsn Opcodes/POP) + (.visitJumpInsn Opcodes/GOTO $else)) + (->> (let [$value-then (new Label) + $value-else (new Label)]))) + (.visitLabel $variant-else) + (.visitInsn Opcodes/POP) + (.visitJumpInsn Opcodes/GOTO $else)))) )) (defn ^:private separate-bodies [patterns] |