aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2015-10-07 02:10:47 -0400
committerEduardo Julian2015-10-07 02:10:47 -0400
commit7aae4fa5d885e9cf6a3913e1252f6c85aef15c51 (patch)
tree182e879a8c8abf2a0930f1827f9a02dc5043a7a3
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)
-rw-r--r--src/lux/compiler/base.clj2
-rw-r--r--src/lux/compiler/case.clj36
-rw-r--r--src/lux/compiler/lux.clj29
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