List of usage examples for org.objectweb.asm Opcodes GOTO
int GOTO
To view the source code for org.objectweb.asm Opcodes GOTO.
Click Source Link
From source file:com.yahoo.yqlplus.engine.internal.compiler.BytecodeArithmeticExpression.java
@Override public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); Label isNull = new Label(); TypeWidget mathType = getType().unboxed(); if (!mathType.isPrimitive() || op == ArithmeticOperation.POW) { mv.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(Maths.class), "INSTANCE", Type.getDescriptor(Maths.class)); mv.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(ArithmeticOperation.class), op.name(), Type.getDescriptor(ArithmeticOperation.class)); }//from w w w .ja v a2 s. c o m CodeEmitter.Unification out = code.unifyAs(mathType, leftExpr, rightExpr, isNull, isNull, isNull); // now we have both sides unified as (if possible) a primitive type // compute the result if (mathType.isPrimitive()) { switch (op) { case ADD: mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.IADD)); break; case SUB: mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.ISUB)); break; case MULT: mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.IMUL)); break; case DIV: mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.IDIV)); break; case MOD: mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.IREM)); break; case POW: mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Maths.class), "binaryMath", Type.getMethodDescriptor(mathType.getJVMType(), Type.getType(ArithmeticOperation.class), mathType.getJVMType(), mathType.getJVMType()), false); break; default: throw new ProgramCompileException(loc, "Unknown BinaryMath operation: " + op); } } else if (mathType.getValueCoreType() == YQLCoreType.ANY) { String desc = Type.getMethodDescriptor(getType().getJVMType(), Type.getType(Maths.class), Type.getType(ArithmeticOperation.class), leftExpr.getType().boxed().getJVMType(), rightExpr.getType().boxed().getJVMType()); mv.visitInvokeDynamicInsn("dyn:callMethod:binaryMath", desc, Dynamic.H_DYNALIB_BOOTSTRAP); } else { throw new ProgramCompileException(loc, "Math operation %s is not defined for type %s", op, mathType.getJVMType()); } if (!getType().isPrimitive() && mathType.isPrimitive()) { code.box(mathType); } if (out.nullPossible) { Label done = new Label(); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(isNull); if (!mathType.isPrimitive() || op == ArithmeticOperation.POW) { mv.visitInsn(Opcodes.POP2); } mv.visitInsn(Opcodes.ACONST_NULL); mv.visitLabel(done); } }
From source file:com.yahoo.yqlplus.engine.internal.compiler.BytecodeNegateExpression.java
@Override public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); Label isNull = new Label(); TypeWidget mathType = getType().unboxed(); if (!mathType.isPrimitive()) { mv.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(Maths.class), "INSTANCE", Type.getDescriptor(Maths.class)); }//from w ww.jav a 2 s .c o m boolean maybeNull = code.cast(mathType, leftExpr.getType(), isNull); // compute the result if (mathType.isPrimitive()) { mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.INEG)); } else if (mathType.getValueCoreType() == YQLCoreType.ANY) { String desc = Type.getMethodDescriptor(getType().getJVMType(), Type.getType(Maths.class), leftExpr.getType().getJVMType()); mv.visitInvokeDynamicInsn("dyn:callMethod:negate", desc, Dynamic.H_DYNALIB_BOOTSTRAP); } else { throw new ProgramCompileException(loc, "Math operation NEGATE is not defined for type %s", mathType.getJVMType()); } if (!getType().isPrimitive() && mathType.isPrimitive()) { code.box(mathType); } if (maybeNull) { Label done = new Label(); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(isNull); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitLabel(done); } }
From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java
public void gotoExitScope() { methodVisitor.visitJumpInsn(Opcodes.GOTO, getEnd()); }
From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java
public Unification unifyAs(TypeWidget typeWidget, BytecodeExpression left, BytecodeExpression right, Label leftNull, Label rightNull, Label bothNull) { left.generate(this); boolean distinct = (leftNull != bothNull) && right.getType().isNullable(); Label leftIsNull = distinct ? new Label() : leftNull; boolean nullpossible = cast(typeWidget, left.getType(), leftIsNull); if (nullpossible && distinct) { Label skip = new Label(); methodVisitor.visitJumpInsn(Opcodes.GOTO, skip); methodVisitor.visitLabel(leftIsNull); right.generate(this); methodVisitor.visitJumpInsn(Opcodes.IFNULL, bothNull); methodVisitor.visitJumpInsn(Opcodes.GOTO, leftNull); methodVisitor.visitLabel(skip);/*from w ww. j ava2s .c o m*/ } Label pop = new Label(); right.generate(this); if (cast(typeWidget, right.getType(), pop)) { Label done = new Label(); nullpossible = true; methodVisitor.visitJumpInsn(Opcodes.GOTO, done); methodVisitor.visitLabel(pop); // pop the left-value pop(typeWidget); methodVisitor.visitJumpInsn(Opcodes.GOTO, rightNull); methodVisitor.visitLabel(done); } return new Unification(typeWidget, nullpossible); }
From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java
public BinaryCoercion binaryCoercion(BytecodeExpression left, Class<?> leftClazz, BytecodeExpression right, Class<?> rightClazz, Label leftNull, Label rightNull, Label bothNull) { TypeWidget leftTarget = adapt(leftClazz); TypeWidget rightTarget = adapt(rightClazz); left.generate(this); boolean distinct = (leftNull != bothNull) && right.getType().isNullable(); Label leftIsNull = distinct ? new Label() : leftNull; boolean leftMaybeNull = cast(leftTarget, left.getType(), leftIsNull); if (leftMaybeNull && distinct) { Label skip = new Label(); methodVisitor.visitJumpInsn(Opcodes.GOTO, skip); methodVisitor.visitLabel(leftIsNull); right.generate(this); methodVisitor.visitJumpInsn(Opcodes.IFNULL, bothNull); methodVisitor.visitJumpInsn(Opcodes.GOTO, leftNull); methodVisitor.visitLabel(skip);/*from w w w. j av a2 s . co m*/ } Label pop = new Label(); right.generate(this); boolean rightMaybeNull = false; if (cast(rightTarget, right.getType(), pop)) { Label done = new Label(); rightMaybeNull = true; methodVisitor.visitJumpInsn(Opcodes.GOTO, done); methodVisitor.visitLabel(pop); // pop the left-value pop(leftTarget); methodVisitor.visitJumpInsn(Opcodes.GOTO, rightNull); methodVisitor.visitLabel(done); } return new BinaryCoercion(leftMaybeNull, rightMaybeNull); }
From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java
public boolean nullTest(TypeWidget typeWidget, Label isNull) { if (typeWidget.isNullable()) { Label done = new Label(); dup(typeWidget);//from ww w . j av a 2 s . c om getMethodVisitor().visitJumpInsn(Opcodes.IFNONNULL, done); pop(typeWidget); getMethodVisitor().visitJumpInsn(Opcodes.GOTO, isNull); getMethodVisitor().visitLabel(done); return true; } return false; }
From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java
public boolean nullTestLeaveNull(TypeWidget typeWidget, Label isNull) { if (typeWidget.isNullable()) { Label done = new Label(); dup(typeWidget);//w ww. j a v a 2 s .c o m getMethodVisitor().visitJumpInsn(Opcodes.IFNONNULL, done); getMethodVisitor().visitJumpInsn(Opcodes.GOTO, isNull); getMethodVisitor().visitLabel(done); return true; } return false; }
From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java
public void notNullTest(TypeWidget typeWidget, Label isNotNull) { if (typeWidget.isNullable()) { dup(typeWidget);//w w w.java 2 s .c o m getMethodVisitor().visitJumpInsn(Opcodes.IFNONNULL, isNotNull); pop(typeWidget); } else { getMethodVisitor().visitJumpInsn(Opcodes.GOTO, isNotNull); } }
From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java
public void emitInstanceCheck(TypeWidget targetType, Class<?> clazz, Label isNotInstance) { Label is = new Label(); Label not = new Label(); nullTest(targetType, isNotInstance); emitInstanceOf(targetType, clazz, not); getMethodVisitor().visitJumpInsn(Opcodes.GOTO, is); getMethodVisitor().visitLabel(not);/*from w ww . j a va 2s . c o m*/ pop(targetType); getMethodVisitor().visitJumpInsn(Opcodes.GOTO, isNotInstance); getMethodVisitor().visitLabel(is); }
From source file:com.yahoo.yqlplus.engine.internal.compiler.CompareExpression.java
@Override public void generate(CodeEmitter code) { // a bit of a hack; should not need to go to dynamic invocation for this unless one arg is ANY Label done = new Label(); MethodVisitor mv = code.getMethodVisitor(); Label leftNull = new Label(); Label rightNull = new Label(); Label bothNull = new Label(); CodeEmitter.Unification unified = code.unifiedEmit(leftExpr, rightExpr, leftNull, rightNull, bothNull); if (unified.type.isPrimitive()) { emitPrimitiveCompare(code, unified.type); } else {/*from ww w . ja v a 2s.c o m*/ // TODO: statically determine if the unified type is Comparable -- for now treat them all like "any" CodeEmitter scope = code.createScope(); MethodVisitor mv2 = scope.getMethodVisitor(); AssignableValue right = scope.allocate(unified.type); AssignableValue left = scope.allocate(unified.type); scope.exec(right.write(unified.type)); scope.exec(left.write(unified.type)); scope.exec(left.read()); Label leftIsNotComparable = new Label(); scope.emitInstanceCheck(unified.type, Comparable.class, leftIsNotComparable); scope.exec(right.read()); mv2.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Comparable.class), "compareTo", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(Object.class)), true); scope.gotoExitScope(); mv2.visitLabel(leftIsNotComparable); scope.exec(scope.getLocal("$program").read()); scope.exec(left.read()); scope.emitIntConstant((loc != null) ? loc.getLineNumber() : -1); scope.emitIntConstant((loc != null) ? loc.getCharacterOffset() : 0); mv2.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ProgramInvocation.class), "notComparable", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Object.class), Type.INT_TYPE, Type.INT_TYPE), false); // this bit is not reachable, notComparable throws mv2.visitInsn(Opcodes.ICONST_0); mv2.visitJumpInsn(Opcodes.GOTO, done); scope.endScope(); } if (unified.nullPossible) { mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(leftNull); mv.visitInsn(Opcodes.ICONST_M1); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(rightNull); mv.visitInsn(Opcodes.ICONST_1); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(bothNull); mv.visitInsn(Opcodes.ICONST_0); } mv.visitLabel(done); }