diff options
Diffstat (limited to '')
-rw-r--r-- | new-luxc/source/luxc/generator/runtime.jvm.lux | 103 |
1 files changed, 25 insertions, 78 deletions
diff --git a/new-luxc/source/luxc/generator/runtime.jvm.lux b/new-luxc/source/luxc/generator/runtime.jvm.lux index e8831d005..5c6ce29a6 100644 --- a/new-luxc/source/luxc/generator/runtime.jvm.lux +++ b/new-luxc/source/luxc/generator/runtime.jvm.lux @@ -10,7 +10,11 @@ ["ls" synthesis]) ["&;" analyser] ["&;" synthesizer] - (generator ["&;" common]))) + (generator ["&;" common] + (host ["$" jvm] + (jvm ["$t" type] + ["$d" def] + ["$i" inst]))))) (jvm-import java.lang.Object) (jvm-import java.lang.String) @@ -21,95 +25,38 @@ (jvm-import (java.lang.Class a) (getField [String] Field)) -(type: Flags Int) -(type: Descriptor Text) - (jvm-import org.objectweb.asm.Opcodes (#static ACC_PUBLIC int) (#static ACC_SUPER int) (#static ACC_FINAL int) (#static ACC_STATIC int) - (#static DUP int) - (#static PUTSTATIC int) - (#static ILOAD int) - (#static ALOAD int) - (#static ANEWARRAY int) - (#static AASTORE int) - (#static RETURN int) - (#static ARETURN int) - (#static V1_6 int) - ) - -(jvm-import org.objectweb.asm.MethodVisitor - (visitCode [] void) - (visitEnd [] void) - (visitInsn [int] void) - (visitLdcInsn [Object] void) - (visitFieldInsn [int String String String] void) - (visitVarInsn [int int] void) - (visitTypeInsn [int String] void) - (visitMaxs [int int] void)) - -(jvm-import org.objectweb.asm.FieldVisitor - (visitEnd [] void)) + (#static V1_6 int)) (jvm-import org.objectweb.asm.ClassWriter (#static COMPUTE_MAXS int) (new [int]) (visit [int int String String String (Array String)] void) (visitEnd [] void) - (visitField [int String String String Object] FieldVisitor) - (visitMethod [int String String String (Array String)] MethodVisitor) (toByteArray [] Byte-Array)) -(def: (generate-adt-methods writer) - (-> ClassWriter ClassWriter) - (let [## I commented-out some parts because a null-check was - ## done to ensure variants were never created with null - ## values (this would interfere later with - ## pattern-matching). - ## Since Lux itself does not have null values as part of - ## the language, the burden of ensuring non-nulls was - ## shifted to library code dealing with host-interop, to - ## ensure variant-making was as fast as possible. - ## The null-checking code was left as comments in case I - ## ever change my mind. - _ (let [## $is-null (new Label) - visitor (ClassWriter.visitMethod [(i.+ Opcodes.ACC_PUBLIC Opcodes.ACC_STATIC) - "sum_make" "(ILjava/lang/Object;Ljava/lang/Object;)[Ljava/lang/Object;" - (host;null) (host;null)] - writer) - _ (do-to visitor - (MethodVisitor.visitCode []) - ## (MethodVisitor.visitVarInsn [Opcodes.ALOAD 2]) - ## (MethodVisitor.visitJumpInsn [Opcodes.IFNULL $is-null]) - (MethodVisitor.visitLdcInsn [(host;l2i 3)]) - (MethodVisitor.visitTypeInsn [Opcodes.ANEWARRAY "java/lang/Object"]) - (MethodVisitor.visitInsn [Opcodes.DUP]) - (MethodVisitor.visitLdcInsn [(host;l2i 0)]) - (MethodVisitor.visitVarInsn [Opcodes.ILOAD 0])) - _ (&common;wrap-int visitor) - _ (do-to visitor - (MethodVisitor.visitInsn [Opcodes.AASTORE]) - (MethodVisitor.visitInsn [Opcodes.DUP]) - (MethodVisitor.visitLdcInsn [(host;l2i 1)]) - (MethodVisitor.visitVarInsn [Opcodes.ALOAD 1]) - (MethodVisitor.visitInsn [Opcodes.AASTORE]) - (MethodVisitor.visitInsn [Opcodes.DUP]) - (MethodVisitor.visitLdcInsn [(host;l2i 2)]) - (MethodVisitor.visitVarInsn [Opcodes.ALOAD 2]) - (MethodVisitor.visitInsn [Opcodes.AASTORE]) - (MethodVisitor.visitInsn [Opcodes.ARETURN]) - ## (MethodVisitor.visitLabel [$is-null]) - ## (MethodVisitor.visitTypeInsn [Opcodes.NEW "java/lang/IllegalStateException"]) - ## (MethodVisitor.visitInsn [Opcodes.DUP]) - ## (MethodVisitor.visitLdcInsn ["Cannot create variant for null pointer"]) - ## (MethodVisitor.visitMethodInsn [Opcodes.INVOKESPECIAL "java/lang/IllegalStateException" "<init>" "(Ljava/lang/String;)V"]) - ## (MethodVisitor.visitInsn [Opcodes.ATHROW]) - (MethodVisitor.visitMaxs [0 0]) - (MethodVisitor.visitEnd []))] - [])] - writer)) +(def: $Object $;Type ($t;class "java.lang.Object" (list))) + +(def: add-adt-methods + $;Def + (let [store-tag (|>. $i;DUP ($i;int 0) ($i;ILOAD +0) $i;wrap-int $i;AASTORE) + store-flag (|>. $i;DUP ($i;int 1) ($i;ALOAD +1) $i;AASTORE) + store-value (|>. $i;DUP ($i;int 2) ($i;ALOAD +2) $i;AASTORE)] + (|>. ($d;method #$;Public + {#$;staticM true #$;finalM false #$;synchronizedM false} + "sum_make" + ($t;method (list $t;int $Object $Object) + (#;Some ($t;array +1 $Object)) + (list)) + (|>. ($i;array $Object +3) + store-tag + store-flag + store-value + $i;ARETURN))))) (def: #export generate (Lux &common;Bytecode) @@ -120,7 +67,7 @@ ($_ i.+ Opcodes.ACC_PUBLIC Opcodes.ACC_FINAL Opcodes.ACC_SUPER) &common;runtime-class-name (host;null) "java/lang/Object" (host;null)])) - generate-adt-methods) + add-adt-methods) bytecode (ClassWriter.toByteArray [] (do-to writer (ClassWriter.visitEnd [])))] _ (&common;store-class &common;runtime-class-name bytecode)] (wrap bytecode))) |