List of usage examples for org.objectweb.asm Label Label
public Label()
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.IterateBuilderAdapter.java
@Override public void next(BytecodeExpression test) { final BytecodeExpression testExpr = test; final TypeWidget type = testExpr.getType(); body.add(new BytecodeSequence() { @Override/*from w w w . ja va2 s. c om*/ public void generate(CodeEmitter code) { code.exec(testExpr); Label isFalse = new Label(); type.getComparisionAdapter().coerceBoolean(code, next, isFalse, isFalse); MethodVisitor mv = code.getMethodVisitor(); mv.visitLabel(isFalse); } }); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.LoopAdapter.java
@Override public void abort(final BytecodeExpression test) { final TypeWidget type = test.getType(); body.add(new BytecodeSequence() { @Override//from www .j a v a 2s . c o m public void generate(CodeEmitter code) { code.exec(test); Label isTrue = new Label(); Label isFalse = new Label(); type.getComparisionAdapter().coerceBoolean(code, isTrue, isFalse, isFalse); MethodVisitor mv = code.getMethodVisitor(); mv.visitLabel(isTrue); code.exec(result); mv.visitJumpInsn(Opcodes.GOTO, body.getEnd()); mv.visitLabel(isFalse); } }); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.LoopAdapter.java
@Override public void next(final BytecodeExpression test) { final TypeWidget type = test.getType(); body.add(new BytecodeSequence() { @Override//from ww w.j a va 2 s . c om public void generate(CodeEmitter code) { code.exec(test); Label isTrue = new Label(); Label isFalse = new Label(); type.getComparisionAdapter().coerceBoolean(code, isTrue, isFalse, isFalse); MethodVisitor mv = code.getMethodVisitor(); mv.visitLabel(isTrue); code.exec(result); mv.visitJumpInsn(Opcodes.GOTO, next); mv.visitLabel(isFalse); } }); }
From source file:com.yahoo.yqlplus.engine.internal.compiler.BooleanCompareExpression.java
@Override public void generate(CodeEmitter code) { code.exec(new CompareExpression(loc, leftExpr, rightExpr)); MethodVisitor mv = code.getMethodVisitor(); Label isTrue = new Label(); Label done = new Label(); switch (booleanComparison) { case LT:/*from ww w .j a v a 2 s. com*/ mv.visitJumpInsn(Opcodes.IFLT, isTrue); break; case LTEQ: mv.visitJumpInsn(Opcodes.IFLE, isTrue); break; case GT: mv.visitJumpInsn(Opcodes.IFGT, isTrue); break; case GTEQ: mv.visitJumpInsn(Opcodes.IFGE, isTrue); break; } code.emitBooleanConstant(false); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(isTrue); code.emitBooleanConstant(true); mv.visitLabel(done); }
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 . jav a 2s .c om*/ 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 w w . j av 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 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 w w .j a v a2 s .c om } 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);/*w ww. j av a 2 s. c om*/ } 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);//w w w .j a v a2 s .com 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);// ww w.j av a 2 s .c o m getMethodVisitor().visitJumpInsn(Opcodes.IFNONNULL, done); getMethodVisitor().visitJumpInsn(Opcodes.GOTO, isNull); getMethodVisitor().visitLabel(done); return true; } return false; }