use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.
the class IfStatement method accept.
@Override
public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) {
checkState(!condition.isEmpty(), "IfStatement does not have a condition set");
checkState(!ifTrue.isEmpty() || !ifFalse.isEmpty(), "IfStatement does not have a true or false block set");
BytecodeBlock block = new BytecodeBlock();
// if !condition goto false;
block.append(new BytecodeBlock().setDescription("condition").append(condition));
block.ifFalseGoto(falseLabel);
if (!ifTrue.isEmpty()) {
block.append(new BytecodeBlock().setDescription("ifTrue").append(ifTrue));
}
if (!ifFalse.isEmpty()) {
// close true case by skipping to end
block.gotoLabel(outLabel);
block.visitLabel(falseLabel);
block.append(new BytecodeBlock().setDescription("ifFalse").append(ifFalse));
block.visitLabel(outLabel);
} else {
block.visitLabel(falseLabel);
}
block.accept(visitor, generationContext);
}
use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.
the class TryCatch method accept.
@Override
public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) {
LabelNode tryStart = new LabelNode("tryStart");
LabelNode tryEnd = new LabelNode("tryEnd");
LabelNode handler = new LabelNode("handler");
LabelNode done = new LabelNode("done");
BytecodeBlock block = new BytecodeBlock();
// try block
block.visitLabel(tryStart).append(tryNode).visitLabel(tryEnd).gotoLabel(done);
// handler block
block.visitLabel(handler).append(catchNode);
// all done
block.visitLabel(done);
block.accept(visitor, generationContext);
visitor.visitTryCatchBlock(tryStart.getLabel(), tryEnd.getLabel(), handler.getLabel(), exceptionName);
}
use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.
the class WhileLoop method accept.
@Override
public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) {
checkState(!condition.isEmpty(), "WhileLoop does not have a condition set");
BytecodeBlock block = new BytecodeBlock().visitLabel(continueLabel).append(condition).ifZeroGoto(endLabel).append(body).gotoLabel(continueLabel).visitLabel(endLabel);
block.accept(visitor, generationContext);
}
use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.
the class AndBytecodeExpression method getBytecode.
@Override
public BytecodeNode getBytecode(MethodGenerationContext generationContext) {
LabelNode falseLabel = new LabelNode("false");
LabelNode endLabel = new LabelNode("end");
return new BytecodeBlock().append(left).ifFalseGoto(falseLabel).append(right).ifFalseGoto(falseLabel).push(true).gotoLabel(endLabel).visitLabel(falseLabel).push(false).visitLabel(endLabel);
}
use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.
the class AbstractMinMaxBy method generateInputMethod.
private void generateInputMethod(ClassDefinition definition, CallSiteBinder binder, MethodHandle compareMethod, Type keyType, Type valueType, Class<?> stateClass) {
Parameter state = arg("state", stateClass);
Parameter value = arg("value", Block.class);
Parameter key = arg("key", Block.class);
Parameter position = arg("position", int.class);
MethodDefinition method = definition.declareMethod(a(PUBLIC, STATIC), "input", type(void.class), state, value, key, position);
if (keyType.equals(UNKNOWN)) {
method.getBody().ret();
return;
}
SqlTypeBytecodeExpression keySqlType = constantType(binder, keyType);
BytecodeBlock ifBlock = new BytecodeBlock().append(state.invoke("setFirst", void.class, keySqlType.getValue(key, position))).append(state.invoke("setFirstNull", void.class, constantBoolean(false))).append(state.invoke("setSecondNull", void.class, value.invoke("isNull", boolean.class, position)));
if (!valueType.equals(UNKNOWN)) {
SqlTypeBytecodeExpression valueSqlType = constantType(binder, valueType);
ifBlock.append(new IfStatement().condition(value.invoke("isNull", boolean.class, position)).ifFalse(state.invoke("setSecond", void.class, valueSqlType.getValue(value, position))));
}
method.getBody().append(new IfStatement().condition(or(state.invoke("isFirstNull", boolean.class), and(not(key.invoke("isNull", boolean.class, position)), loadConstant(binder, compareMethod, MethodHandle.class).invoke("invokeExact", boolean.class, keySqlType.getValue(key, position), state.invoke("getFirst", keyType.getJavaType()))))).ifTrue(ifBlock)).ret();
}
Aggregations