List of usage examples for org.objectweb.asm Label Label
public Label()
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java
@Override public BytecodeExpression bool(Location loc, final BytecodeExpression input) { return new BaseTypeExpression(BaseTypeAdapter.BOOLEAN) { @Override//from ww w .j a v a 2 s. c o m public void generate(CodeEmitter code) { if (input.getType() == BaseTypeAdapter.BOOLEAN) { code.exec(input); } else { MethodVisitor mv = code.getMethodVisitor(); Label done = new Label(); Label isTrue = new Label(); Label isFalse = new Label(); code.exec(input); input.getType().getComparisionAdapter().coerceBoolean(code, isTrue, isFalse, isFalse); mv.visitLabel(isFalse); 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.bytecode.types.gambit.ExpressionHandler.java
@Override public BytecodeExpression isNull(Location location, final BytecodeExpression input) { return new BaseTypeExpression(BaseTypeAdapter.BOOLEAN) { @Override/*from www. j a va 2 s . co m*/ public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); code.exec(input); // it's surprising to not evaluate even if we know input isn't nullable if (input.getType().isPrimitive()) { code.pop(input.getType()); code.emitBooleanConstant(false); } else { Label done = new Label(); Label isNull = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, isNull); code.emitBooleanConstant(false); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(isNull); code.emitBooleanConstant(true); mv.visitLabel(done); } } }; }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java
@Override public BytecodeExpression coalesce(Location loc, final List<BytecodeExpression> inputs) { List<TypeWidget> widgets = Lists.newArrayList(); for (BytecodeExpression expr : inputs) { widgets.add(expr.getType());//from w ww. ja v a 2 s .co m } TypeWidget output = unify(widgets); return new BaseTypeExpression(output) { @Override public void generate(CodeEmitter code) { Label done = new Label(); MethodVisitor mv = code.getMethodVisitor(); boolean lastNullable = true; for (BytecodeExpression expr : inputs) { Label isNull = new Label(); code.exec(expr); if (code.cast(getType(), expr.getType(), isNull)) { mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(isNull); } else { lastNullable = false; break; } } if (lastNullable) { mv.visitInsn(Opcodes.ACONST_NULL); } mv.visitLabel(done); } }; }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java
@Override public BytecodeExpression list(Location loc, final List<BytecodeExpression> args) { List<TypeWidget> types = Lists.newArrayList(); for (BytecodeExpression e : args) { types.add(e.getType());//from w w w .ja v a 2s . c o m } final TypeWidget unified = unify(types).boxed(); final ListTypeWidget out = new ListTypeWidget(NotNullableTypeWidget.create(unified)); return new BaseTypeExpression(out) { @Override public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); code.exec(out.construct(constant(args.size()))); for (BytecodeExpression expr : args) { Label skip = new Label(); mv.visitInsn(Opcodes.DUP); code.exec(expr); final TypeWidget type = expr.getType(); boolean nullable = code.cast(unified, type, skip); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Collection.class), "add", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class)), true); if (nullable) { // we're either going to POP the DUPed List OR the result of add mv.visitLabel(skip); } mv.visitInsn(Opcodes.POP); } } }; }
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. c o 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/* w ww . j a v a 2 s . c om*/ 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.bytecode.types.gambit.ExpressionHandler.java
@Override public BytecodeExpression guarded(final BytecodeExpression target, final BytecodeExpression ifTargetIsNotNull, final BytecodeExpression ifTargetIsNull) { if (!target.getType().isNullable()) { return ifTargetIsNotNull; }// w ww .j a v a2s . c o m return new BaseTypeExpression(unify(ifTargetIsNotNull.getType(), ifTargetIsNull.getType())) { @Override public void generate(CodeEmitter code) { final MethodVisitor mv = code.getMethodVisitor(); Label isNull = new Label(); Label done = new Label(); code.exec(target); code.nullTest(target.getType(), isNull); code.pop(target.getType()); code.exec(ifTargetIsNotNull); code.cast(getType(), ifTargetIsNotNull.getType(), isNull); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(isNull); code.exec(ifTargetIsNull); code.cast(getType(), ifTargetIsNull.getType()); mv.visitLabel(done); } }; }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java
@Override public BytecodeExpression fallback(Location loc, final BytecodeExpression primary, final BytecodeExpression caught) { TypeWidget unified = unify(primary.getType(), caught.getType()); return new BaseTypeExpression(unified) { @Override// w w w . j a v a 2 s .c om public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); final Label start = new Label(); final Label endCatch = new Label(); final Label handler = new Label(); Label done = new Label(); // this probably should not be catching throwable and instead should be catching Exception // or permit certain Errors through only mv.visitTryCatchBlock(start, endCatch, handler, "java/lang/Throwable"); mv.visitLabel(start); code.exec(primary); Label isNull = new Label(); boolean maybeNull = code.cast(getType(), primary.getType(), isNull); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(endCatch); mv.visitLabel(handler); mv.visitInsn(Opcodes.POP); if (maybeNull) { mv.visitLabel(isNull); } code.exec(caught); code.cast(getType(), caught.getType()); mv.visitLabel(done); } }; }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.IfAdapter.java
@Override public ScopedBuilder when(final BytecodeExpression test) { final TypeWidget type = test.getType(); final Label isFalse = new Label(); body.add(new BytecodeSequence() { @Override/*ww w.j a v a 2 s.c o m*/ public void generate(CodeEmitter code) { code.exec(test); Label isTrue = new Label(); type.getComparisionAdapter().coerceBoolean(code, isTrue, isFalse, isFalse); MethodVisitor mv = code.getMethodVisitor(); mv.visitLabel(isTrue); } }); Clause block = new Clause(source, body.block()); body.add(new BytecodeSequence() { @Override public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); mv.visitJumpInsn(Opcodes.GOTO, end); mv.visitLabel(isFalse); } }); return block; }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.IterateBuilderAdapter.java
@Override public void abort(final BytecodeExpression test) { final TypeWidget type = test.getType(); body.add(new BytecodeSequence() { @Override//w ww .j a v a2 s . c o m public void generate(CodeEmitter code) { code.exec(test); Label isFalse = new Label(); type.getComparisionAdapter().coerceBoolean(code, abort, isFalse, isFalse); MethodVisitor mv = code.getMethodVisitor(); mv.visitLabel(isFalse); } }); }