diff options
author | Eduardo Julian | 2016-01-17 14:04:44 -0400 |
---|---|---|
committer | Eduardo Julian | 2016-01-17 14:04:44 -0400 |
commit | 89169382b9ade7d4692315ce02d5fbb747965d0d (patch) | |
tree | 664a134b73055062079b5c295c04dcd5da8bdf6c | |
parent | c9bc2d1721cc44b74c5f36f9409790762a2ec73d (diff) |
- Made an optimization to variants/sums, by encoding the last/tail flag as a pointer (with null as false, and everything else as true).
Diffstat (limited to '')
-rw-r--r-- | src/lux/base.clj | 2 | ||||
-rw-r--r-- | src/lux/compiler/host.clj | 9 | ||||
-rw-r--r-- | src/lux/compiler/lux.clj | 13 |
3 files changed, 12 insertions, 12 deletions
diff --git a/src/lux/base.clj b/src/lux/base.clj index aead20b41..05668a245 100644 --- a/src/lux/base.clj +++ b/src/lux/base.clj @@ -160,7 +160,7 @@ (to-array (conj elems product-tag)))) (defn V [^Long tag value] - (to-array [sum-tag (int tag) false value])) + (to-array [sum-tag (int tag) nil value])) ;; Constructors (def None$ (V $None unit-tag)) diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj index 2e584c7c6..2514dfaa5 100644 --- a/src/lux/compiler/host.clj +++ b/src/lux/compiler/host.clj @@ -802,9 +802,8 @@ (.visitFrame Opcodes/F_NEW (int 2) (to-array ["[Ljava/lang/Object;" Opcodes/INTEGER]) (int 2) (to-array [Opcodes/INTEGER Opcodes/INTEGER])) (.visitVarInsn Opcodes/ALOAD 0) ;; tag, sum-tag, sum (.visitLdcInsn (int 2)) ;; tag, sum-tag, sum, last-index? - (.visitInsn Opcodes/AALOAD) ;; tag, sum-tag, last?' - &&/unwrap-boolean ;; tag, sum-tag, last? - (.visitJumpInsn Opcodes/IFEQ $not-right) ;; tag, sum-tag + (.visitInsn Opcodes/AALOAD) ;; tag, sum-tag, last? + (.visitJumpInsn Opcodes/IFNULL $not-right) ;; tag, sum-tag (.visitInsn Opcodes/ISUB) ;; sub-tag (.visitVarInsn Opcodes/ALOAD 0) ;; sub-tag, sum (.visitLdcInsn (int 3)) ;; sub-tag, sum, sub-sum-idx @@ -821,7 +820,7 @@ (.visitMaxs 0 0) (.visitEnd))) =sum-make-method (let [$is-null (new Label)] - (doto (.visitMethod =class (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) "sum_make" "(ILjava/lang/Boolean;Ljava/lang/Object;)[Ljava/lang/Object;" nil nil) + (doto (.visitMethod =class (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) "sum_make" "(ILjava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;" nil nil) (.visitCode) (.visitVarInsn Opcodes/ALOAD 2) (.visitJumpInsn Opcodes/IFNULL $is-null) @@ -845,7 +844,7 @@ (.visitVarInsn Opcodes/ALOAD 2) (.visitInsn Opcodes/AASTORE) (.visitInsn Opcodes/ARETURN) - (.visitFrame Opcodes/F_NEW (int 3) (to-array [Opcodes/INTEGER "java/lang/Boolean" "java/lang/Object"]) (int 0) (to-array [])) + (.visitFrame Opcodes/F_NEW (int 3) (to-array [Opcodes/INTEGER "java/lang/Object" "java/lang/Object"]) (int 0) (to-array [])) (.visitLabel $is-null) (.visitTypeInsn Opcodes/NEW "java/lang/IllegalStateException") (.visitInsn Opcodes/DUP) diff --git a/src/lux/compiler/lux.clj b/src/lux/compiler/lux.clj index dba42eb21..87de12497 100644 --- a/src/lux/compiler/lux.clj +++ b/src/lux/compiler/lux.clj @@ -83,13 +83,14 @@ (.visitInsn Opcodes/AASTORE))]] (return nil))))) -(defn compile-variant [compile ?tag tail? ?value] +(defn compile-variant [compile tag tail? value] (|do [^MethodVisitor *writer* &/get-writer - :let [_ (doto *writer* - (.visitLdcInsn (int ?tag)) - (.visitFieldInsn Opcodes/GETSTATIC "java/lang/Boolean" (if tail? "TRUE" "FALSE") "Ljava/lang/Boolean;"))] - _ (compile ?value) - :let [_ (.visitMethodInsn *writer* Opcodes/INVOKESTATIC "lux/LuxUtils" "sum_make" "(ILjava/lang/Boolean;Ljava/lang/Object;)[Ljava/lang/Object;")]] + :let [_ (.visitLdcInsn *writer* (int tag)) + _ (if tail? + (.visitLdcInsn *writer* "") + (.visitInsn *writer* Opcodes/ACONST_NULL))] + _ (compile value) + :let [_ (.visitMethodInsn *writer* Opcodes/INVOKESTATIC "lux/LuxUtils" "sum_make" "(ILjava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;")]] (return nil))) (defn compile-local [compile ?idx] |