Example usage for org.objectweb.asm Opcodes ICONST_0

List of usage examples for org.objectweb.asm Opcodes ICONST_0

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ICONST_0.

Prototype

int ICONST_0

To view the source code for org.objectweb.asm Opcodes ICONST_0.

Click Source Link

Usage

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java

@Override
public BytecodeExpression matches(Location loc, final BytecodeExpression left, final BytecodeExpression right) {
    return new BaseTypeExpression(BaseTypeAdapter.BOOLEAN) {
        @Override//from   w w  w  .  j  a v  a2 s. co m
        public void generate(CodeEmitter code) {
            Label done = new Label();
            Label anyIsNull = new Label();
            CodeEmitter.BinaryCoercion coerce = code.binaryCoercion(right, Pattern.class, left,
                    CharSequence.class, anyIsNull, anyIsNull, anyIsNull);
            MethodVisitor mv = code.getMethodVisitor();
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Pattern.class), "matcher",
                    Type.getMethodDescriptor(Type.getType(Matcher.class), Type.getType(CharSequence.class)),
                    false);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Matcher.class), "matches",
                    Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false);
            if (coerce.leftNullable || coerce.rightNullable) {
                mv.visitJumpInsn(Opcodes.GOTO, done);
                mv.visitLabel(anyIsNull);
                mv.visitInsn(Opcodes.ICONST_0);
                mv.visitLabel(done);
            }
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java

@Override
public BytecodeExpression in(Location loc, final BytecodeExpression left, final BytecodeExpression right) {
    return new BaseTypeExpression(BaseTypeAdapter.BOOLEAN) {
        @Override//from   ww  w  .  ja  v a2s .co m
        public void generate(CodeEmitter code) {
            Label done = new Label();
            Label anyIsNull = new Label();
            CodeEmitter.BinaryCoercion coerce = code.binaryCoercion(right, Collection.class, left, Object.class,
                    anyIsNull, anyIsNull, anyIsNull);
            MethodVisitor mv = code.getMethodVisitor();
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Collection.class), "contains",
                    Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class)), true);
            if (coerce.leftNullable || coerce.rightNullable) {
                mv.visitJumpInsn(Opcodes.GOTO, done);
                mv.visitLabel(anyIsNull);
                mv.visitInsn(Opcodes.ICONST_0);
                mv.visitLabel(done);
            }
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java

public void emitIntConstant(int constant) {
    switch (constant) {
    case -1://from  w w w  .ja  v  a2 s  . c  o m
        methodVisitor.visitInsn(Opcodes.ICONST_M1);
        break;
    case 0:
        methodVisitor.visitInsn(Opcodes.ICONST_0);
        break;
    case 1:
        methodVisitor.visitInsn(Opcodes.ICONST_1);
        break;
    case 2:
        methodVisitor.visitInsn(Opcodes.ICONST_2);
        break;
    case 3:
        methodVisitor.visitInsn(Opcodes.ICONST_3);
        break;
    case 4:
        methodVisitor.visitInsn(Opcodes.ICONST_4);
        break;
    case 5:
        methodVisitor.visitInsn(Opcodes.ICONST_5);
        break;
    default:
        methodVisitor.visitLdcInsn(constant);
    }
}

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 .j a  v  a2  s  . co  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);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.EqualsExpression.java

private void emitFalse(CodeEmitter code) {
    code.getMethodVisitor().visitInsn(negate ? Opcodes.ICONST_1 : Opcodes.ICONST_0);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.EqualsExpression.java

private void emitTrue(CodeEmitter code) {
    code.getMethodVisitor().visitInsn(negate ? Opcodes.ICONST_0 : Opcodes.ICONST_1);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.EqualsExpression.java

private void emitNegate(MethodVisitor mv) {
    Label truth = new Label();
    Label skip = new Label();
    mv.visitJumpInsn(Opcodes.IFNE, truth);
    mv.visitInsn(Opcodes.ICONST_1);//from  ww  w. j  a  v a 2s.co  m
    mv.visitJumpInsn(Opcodes.GOTO, skip);
    mv.visitLabel(truth);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitLabel(skip);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.MulticompareExpression.java

@Override
public void generate(CodeEmitter code) {
    CodeEmitter scope = code.createScope();
    MethodVisitor mv = scope.getMethodVisitor();
    AssignableValue var = scope.allocate(BaseTypeAdapter.INT32);
    for (BytecodeExpression expr : expressions) {
        Label areEqual = new Label();
        scope.exec(var.write(expr));
        scope.exec(var.read());
        mv.visitJumpInsn(Opcodes.IFEQ, areEqual);
        scope.exec(var.read());
        scope.gotoExitScope();/*w  ww.  j a v a 2  s .c  om*/
        mv.visitLabel(areEqual);
    }
    mv.visitInsn(Opcodes.ICONST_0);
    scope.endScope();
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.ArrayIndexAdapter.java

@Override
public BytecodeExpression length(final BytecodeExpression inputExpr) {
    return new BaseTypeExpression(BaseTypeAdapter.INT32) {
        @Override/*from   w  w  w. j a  va 2  s .  c  om*/
        public void generate(CodeEmitter code) {
            Label done = new Label();
            Label isNull = new Label();
            MethodVisitor mv = code.getMethodVisitor();
            code.exec(inputExpr);
            boolean nullable = code.nullTest(inputExpr.getType(), isNull);
            mv.visitInsn(Opcodes.ARRAYLENGTH);
            if (nullable) {
                mv.visitJumpInsn(Opcodes.GOTO, done);
                mv.visitLabel(isNull);
                mv.visitInsn(Opcodes.ICONST_0);
                mv.visitLabel(done);
            }
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.CollectionSizeExpression.java

@Override
public void generate(CodeEmitter code) {
    Label done = new Label();
    Label isNull = new Label();
    MethodVisitor mv = code.getMethodVisitor();
    code.exec(target);//from   w w w  .ja v a  2 s.  com
    boolean nullable = code.nullTest(target.getType(), isNull);
    code.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Collection.class),
            "size", Type.getMethodDescriptor(Type.INT_TYPE), true);
    if (nullable) {
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(isNull);
        mv.visitInsn(Opcodes.ICONST_0);
        mv.visitLabel(done);
    }
}