public Assembler push(int value) { if (value >= -1 && value <= 5) { mv.visitInsn(ICONST_0 + value); } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { mv.visitIntInsn(BIPUSH, value); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { mv.visitIntInsn(SIPUSH, value); } else { mv.visitLdcInsn(value); } return this; }
public Assembler ldc(Object o) { if (o instanceof Integer) { int i = (int) o; if (i >= -1 && i <= 5) { int opcode = -1; switch (i) { case 0: { opcode = ICONST_0; break; } case 1: { opcode = ICONST_1; break; } case 2: { opcode = ICONST_2; break; } case 3: { opcode = ICONST_3; break; } case 4: { opcode = ICONST_4; break; } case 5: { opcode = ICONST_5; break; } case -1: { opcode = ICONST_M1; break; } } mv.visitInsn(opcode); return this; } } if (o instanceof Long) { long l = (long) o; if (l >= 0 && l <= 1) { int opcode = -1; switch ((int) l) { case 0: { opcode = LCONST_0; break; } case 1: { opcode = LCONST_1; break; } } mv.visitInsn(opcode); return this; } } mv.visitLdcInsn(o); return this; }
public Assembler println(String msg) { mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn(msg); invokeVirtual("java/io/PrintStream", "println", "(Ljava/lang/String;)V"); return this; }
public Assembler ldc(Object o) { mv.visitLdcInsn(o); return this; }