diff options
author | Eduardo Julian | 2016-01-17 00:30:06 -0400 |
---|---|---|
committer | Eduardo Julian | 2016-01-17 00:30:06 -0400 |
commit | e65d1f96a807c4cc88f9e082562bdf963949479e (patch) | |
tree | 0eb05f2c8cc4ef16593d24904e165a71524cb694 /src/lux/compiler/case.clj | |
parent | 1ec9e04527bf6ca5f9e86125bc605b8519497d2a (diff) |
- Now using the new utility methods in LuxUtils for working with variants/sums.
Diffstat (limited to '')
-rw-r--r-- | src/lux/compiler/case.clj | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/lux/compiler/case.clj b/src/lux/compiler/case.clj index 314e7a6d3..1b0e023eb 100644 --- a/src/lux/compiler/case.clj +++ b/src/lux/compiler/case.clj @@ -23,6 +23,7 @@ ;; [Utils] (defn ^:private compile-match [^MethodVisitor writer ?match $target $else] + "(-> [MethodVisitor CaseAnalysis Label Label] Unit)" (|case ?match (&a-case/$StoreTestAC ?idx) (if (< ?idx 0) @@ -115,27 +116,27 @@ (.visitJumpInsn Opcodes/GOTO $target)))) (&a-case/$VariantTestAC ?tag ?count ?test) - (doto writer - (.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;") - (.visitInsn Opcodes/DUP) - (.visitLdcInsn (int 1)) - (.visitInsn Opcodes/AALOAD) - (.visitLdcInsn ?tag) - (&&/wrap-long) - (.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/lang/Object" "equals" "(Ljava/lang/Object;)Z") - (.visitJumpInsn Opcodes/IFEQ $else) - (.visitInsn Opcodes/DUP) - (.visitLdcInsn (int 2)) - (.visitInsn Opcodes/AALOAD) - (-> (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)])))) + (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] |