diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lux/compiler/base.clj | 2 | ||||
-rw-r--r-- | src/lux/compiler/case.clj | 36 | ||||
-rw-r--r-- | src/lux/compiler/lux.clj | 29 |
3 files changed, 37 insertions, 30 deletions
diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj index 7825bef94..cf835a590 100644 --- a/src/lux/compiler/base.clj +++ b/src/lux/compiler/base.clj @@ -24,7 +24,7 @@ (java.lang.reflect Field))) ;; [Constants] -(def ^String version "0.3") +(def ^String version "0.4") (def ^String input-dir "source") (def ^String output-dir "target/jvm/") (def ^String output-package (str output-dir "program.jar")) 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 diff --git a/src/lux/compiler/lux.clj b/src/lux/compiler/lux.clj index 01e4ffd5b..ef80d89aa 100644 --- a/src/lux/compiler/lux.clj +++ b/src/lux/compiler/lux.clj @@ -53,19 +53,22 @@ (defn compile-tuple [compile ?elems] (|do [^MethodVisitor *writer* &/get-writer - :let [num-elems (&/|length ?elems) - _ (doto *writer* - (.visitLdcInsn (int num-elems)) - (.visitTypeInsn Opcodes/ANEWARRAY "java/lang/Object"))] - _ (&/map2% (fn [idx elem] - (|do [:let [_ (doto *writer* - (.visitInsn Opcodes/DUP) - (.visitLdcInsn (int idx)))] - ret (compile elem) - :let [_ (.visitInsn *writer* Opcodes/AASTORE)]] - (return ret))) - (&/|range num-elems) ?elems)] - (return nil))) + :let [num-elems (&/|length ?elems)]] + (if (= 0 num-elems) + (|do [:let [_ (.visitInsn *writer* Opcodes/ACONST_NULL)]] + (return nil)) + (|do [:let [_ (doto *writer* + (.visitLdcInsn (int num-elems)) + (.visitTypeInsn Opcodes/ANEWARRAY "java/lang/Object"))] + _ (&/map2% (fn [idx elem] + (|do [:let [_ (doto *writer* + (.visitInsn Opcodes/DUP) + (.visitLdcInsn (int idx)))] + ret (compile elem) + :let [_ (.visitInsn *writer* Opcodes/AASTORE)]] + (return ret))) + (&/|range num-elems) ?elems)] + (return nil))))) (defn compile-variant [compile ?tag ?value] (|do [^MethodVisitor *writer* &/get-writer |