From ecb53b05a226d8d3d8e612f949cb3ad6ac0600ce Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 28 Dec 2019 17:00:04 -0400 Subject: Implemented an alternative method for extensible JVM bytecode generation. --- new-luxc/source/luxc/lang/host/jvm/inst.lux | 73 +++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 20 deletions(-) (limited to 'new-luxc/source/luxc/lang/host/jvm/inst.lux') diff --git a/new-luxc/source/luxc/lang/host/jvm/inst.lux b/new-luxc/source/luxc/lang/host/jvm/inst.lux index e52d11d9b..b673c7d7e 100644 --- a/new-luxc/source/luxc/lang/host/jvm/inst.lux +++ b/new-luxc/source/luxc/lang/host/jvm/inst.lux @@ -72,21 +72,27 @@ ## Jump (~~ (declare IF_ICMPEQ IF_ICMPGT IF_ICMPLT IF_ICMPNE IF_ICMPGE IF_ICMPLE - IF_ACMPEQ IFNULL + IF_ACMPEQ IF_ACMPNE IFNULL IFNONNULL IFEQ IFNE IFLT IFLE IFGT IFGE GOTO)) + (~~ (declare BIPUSH SIPUSH)) + (~~ (declare ICONST_M1 ICONST_0 ICONST_1 ICONST_2 ICONST_3 ICONST_4 ICONST_5 + LCONST_0 LCONST_1 + FCONST_0 FCONST_1 FCONST_2 + DCONST_0 DCONST_1)) (#static ACONST_NULL int) ## Var - (~~ (declare ILOAD LLOAD DLOAD ALOAD - ISTORE LSTORE ASTORE)) + (~~ (declare IINC + ILOAD LLOAD FLOAD DLOAD ALOAD + ISTORE LSTORE FSTORE DSTORE ASTORE)) ## Arithmetic - (~~ (declare IADD ISUB IMUL IDIV IREM - LADD LSUB LMUL LDIV LREM LCMP - FADD FSUB FMUL FDIV FREM FCMPG FCMPL - DADD DSUB DMUL DDIV DREM DCMPG DCMPL)) + (~~ (declare IADD ISUB IMUL IDIV IREM INEG + LADD LSUB LMUL LDIV LREM LNEG LCMP + FADD FSUB FMUL FDIV FREM FNEG FCMPG FCMPL + DADD DSUB DMUL DDIV DREM DNEG DCMPG DCMPL)) ## Bit-wise (~~ (declare IAND IOR IXOR ISHL ISHR IUSHR @@ -162,21 +168,45 @@ [string Text function.identity] ) -(template: (prefix short) +(template: (!prefix short) (`` ((~~ (template.identifier ["org/objectweb/asm/Opcodes::" short]))))) +(template [] + [(def: #export + Inst + (function (_ visitor) + (do-to visitor + (org/objectweb/asm/MethodVisitor::visitInsn (!prefix )))))] + + [ICONST_M1] [ICONST_0] [ICONST_1] [ICONST_2] [ICONST_3] [ICONST_4] [ICONST_5] + [LCONST_0] [LCONST_1] + [FCONST_0] [FCONST_1] [FCONST_2] + [DCONST_0] [DCONST_1] + ) + (def: #export NULL Inst (function (_ visitor) (do-to visitor - (org/objectweb/asm/MethodVisitor::visitInsn (prefix ACONST_NULL))))) + (org/objectweb/asm/MethodVisitor::visitInsn (!prefix ACONST_NULL))))) + +(template [] + [(def: #export ( constant) + (-> Int Inst) + (function (_ visitor) + (do-to visitor + (org/objectweb/asm/MethodVisitor::visitIntInsn (!prefix ) constant))))] + + [BIPUSH] + [SIPUSH] + ) (template [] [(def: #export Inst (function (_ visitor) (do-to visitor - (org/objectweb/asm/MethodVisitor::visitInsn (prefix )))))] + (org/objectweb/asm/MethodVisitor::visitInsn (!prefix )))))] [NOP] @@ -192,23 +222,23 @@ [L2D] [L2F] [L2I] ## Integer arithmetic - [IADD] [ISUB] [IMUL] [IDIV] [IREM] + [IADD] [ISUB] [IMUL] [IDIV] [IREM] [INEG] ## Integer bitwise [IAND] [IOR] [IXOR] [ISHL] [ISHR] [IUSHR] ## Long arithmetic - [LADD] [LSUB] [LMUL] [LDIV] [LREM] + [LADD] [LSUB] [LMUL] [LDIV] [LREM] [LNEG] [LCMP] ## Long bitwise [LAND] [LOR] [LXOR] [LSHL] [LSHR] [LUSHR] ## Float arithmetic - [FADD] [FSUB] [FMUL] [FDIV] [FREM] [FCMPG] [FCMPL] + [FADD] [FSUB] [FMUL] [FDIV] [FREM] [FNEG] [FCMPG] [FCMPL] ## Double arithmetic - [DADD] [DSUB] [DMUL] [DDIV] [DREM] + [DADD] [DSUB] [DMUL] [DDIV] [DREM] [DNEG] [DCMPG] [DCMPL] ## Array @@ -232,15 +262,18 @@ [RETURN] [IRETURN] [LRETURN] [FRETURN] [DRETURN] [ARETURN] ) +(type: #export Register Nat) + (template [] [(def: #export ( register) - (-> Nat Inst) + (-> Register Inst) (function (_ visitor) (do-to visitor - (org/objectweb/asm/MethodVisitor::visitVarInsn (prefix ) (.int register)))))] + (org/objectweb/asm/MethodVisitor::visitVarInsn (!prefix ) (.int register)))))] - [ILOAD] [LLOAD] [DLOAD] [ALOAD] - [ISTORE] [LSTORE] [ASTORE] + [IINC] + [ILOAD] [LLOAD] [FLOAD] [DLOAD] [ALOAD] + [ISTORE] [LSTORE] [FSTORE] [DSTORE] [ASTORE] ) (template [ ] @@ -317,11 +350,11 @@ (-> //.Label Inst) (function (_ visitor) (do-to visitor - (org/objectweb/asm/MethodVisitor::visitJumpInsn (prefix ) @where))))] + (org/objectweb/asm/MethodVisitor::visitJumpInsn (!prefix ) @where))))] [IF_ICMPEQ] [IF_ICMPGT] [IF_ICMPLT] [IF_ICMPNE] [IF_ICMPGE] [IF_ICMPLE] - [IF_ACMPEQ] [IFNULL] + [IF_ACMPEQ] [IF_ACMPNE] [IFNULL] [IFNONNULL] [IFEQ] [IFNE] [IFLT] [IFLE] [IFGT] [IFGE] [GOTO] ) -- cgit v1.2.3