Search in sources :

Example 61 with BytecodeBlock

use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.

the class TestSetFieldBytecodeExpression method assertSetPoint.

public static void assertSetPoint(Function<BytecodeExpression, BytecodeExpression> setX) throws Exception {
    Function<Scope, BytecodeNode> nodeGenerator = scope -> {
        Variable point = scope.declareVariable(Point.class, "point");
        BytecodeExpression setExpression = setX.apply(point);
        assertEquals(setExpression.toString(), "point.x = 42;");
        return new BytecodeBlock().append(point.set(newInstance(Point.class, constantInt(3), constantInt(7)))).append(setExpression).append(point.ret());
    };
    assertBytecodeNode(nodeGenerator, type(Point.class), new Point(42, 7));
}
Also used : Variable(com.facebook.presto.bytecode.Variable) BytecodeExpressionAssertions.assertBytecodeNode(com.facebook.presto.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeNode) BytecodeExpressions.constantInt(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantInt) Throwables(com.google.common.base.Throwables) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Point(java.awt.Point) Field(java.lang.reflect.Field) BytecodeExpressions.newInstance(com.facebook.presto.bytecode.expression.BytecodeExpressions.newInstance) Function(java.util.function.Function) BytecodeExpressions.constantString(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString) BytecodeNode(com.facebook.presto.bytecode.BytecodeNode) BytecodeExpressions.setStatic(com.facebook.presto.bytecode.expression.BytecodeExpressions.setStatic) Scope(com.facebook.presto.bytecode.Scope) ParameterizedType.type(com.facebook.presto.bytecode.ParameterizedType.type) BytecodeExpressionAssertions.assertBytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) Variable(com.facebook.presto.bytecode.Variable) Scope(com.facebook.presto.bytecode.Scope) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) BytecodeExpressionAssertions.assertBytecodeNode(com.facebook.presto.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeNode) BytecodeNode(com.facebook.presto.bytecode.BytecodeNode) Point(java.awt.Point) BytecodeExpressionAssertions.assertBytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression)

Example 62 with BytecodeBlock

use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.

the class TestSetVariableBytecodeExpression method testGetField.

@Test
public void testGetField() throws Exception {
    Function<Scope, BytecodeNode> nodeGenerator = scope -> {
        Variable point = scope.declareVariable(Point.class, "point");
        BytecodeExpression setPoint = point.set(newInstance(Point.class, constantInt(3), constantInt(7)));
        assertEquals(setPoint.toString(), "point = new Point(3, 7);");
        return new BytecodeBlock().append(setPoint).append(point.ret());
    };
    assertBytecodeNode(nodeGenerator, type(Point.class), new Point(3, 7));
}
Also used : BytecodeNode(com.facebook.presto.bytecode.BytecodeNode) Variable(com.facebook.presto.bytecode.Variable) BytecodeExpressionAssertions.assertBytecodeNode(com.facebook.presto.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeNode) Scope(com.facebook.presto.bytecode.Scope) ParameterizedType.type(com.facebook.presto.bytecode.ParameterizedType.type) BytecodeExpressions.constantInt(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantInt) Assert.assertEquals(org.testng.Assert.assertEquals) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) Test(org.testng.annotations.Test) Point(java.awt.Point) BytecodeExpressions.newInstance(com.facebook.presto.bytecode.expression.BytecodeExpressions.newInstance) Function(java.util.function.Function) Variable(com.facebook.presto.bytecode.Variable) Scope(com.facebook.presto.bytecode.Scope) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) BytecodeNode(com.facebook.presto.bytecode.BytecodeNode) BytecodeExpressionAssertions.assertBytecodeNode(com.facebook.presto.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeNode) Point(java.awt.Point) Test(org.testng.annotations.Test)

Example 63 with BytecodeBlock

use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.

the class ComparisonBytecodeExpression method getBytecode.

@Override
public BytecodeNode getBytecode(MethodGenerationContext generationContext) {
    BytecodeBlock block = new BytecodeBlock().append(left).append(right);
    if (comparisonInstruction != null) {
        block.append(comparisonInstruction);
    }
    LabelNode noMatch = new LabelNode("no_match");
    LabelNode end = new LabelNode("end");
    return block.append(new JumpInstruction(noMatchJumpInstruction, noMatch)).push(true).gotoLabel(end).append(noMatch).push(false).append(end);
}
Also used : LabelNode(com.facebook.presto.bytecode.instruction.LabelNode) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) JumpInstruction(com.facebook.presto.bytecode.instruction.JumpInstruction)

Example 64 with BytecodeBlock

use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.

the class NewArrayBytecodeExpression method getBytecode.

@Override
public BytecodeNode getBytecode(MethodGenerationContext generationContext) {
    BytecodeBlock bytecodeBlock;
    if (elementType.isPrimitive()) {
        bytecodeBlock = new BytecodeBlock().append(length).append(TypeInstruction.newPrimitiveArray(elementType));
    } else {
        bytecodeBlock = new BytecodeBlock().append(length).append(TypeInstruction.newObjectArray(elementType));
    }
    if (elements != null) {
        for (int i = 0; i < elements.size(); i++) {
            BytecodeExpression element = elements.get(i);
            bytecodeBlock.dup().append(constantInt(i)).append(element).append(getArrayOpCode(elementType).getStore());
        }
    }
    return bytecodeBlock;
}
Also used : BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock)

Example 65 with BytecodeBlock

use of com.facebook.presto.bytecode.BytecodeBlock in project presto by prestodb.

the class DoWhileLoop method accept.

@Override
public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) {
    checkState(!condition.isEmpty(), "DoWhileLoop does not have a condition set");
    BytecodeBlock block = new BytecodeBlock().visitLabel(beginLabel).append(new BytecodeBlock().setDescription("body").append(body)).visitLabel(continueLabel).append(new BytecodeBlock().setDescription("condition").append(condition)).ifFalseGoto(endLabel).gotoLabel(beginLabel).visitLabel(endLabel);
    block.accept(visitor, generationContext);
}
Also used : BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock)

Aggregations

BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)82 Variable (com.facebook.presto.bytecode.Variable)57 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)43 IfStatement (com.facebook.presto.bytecode.control.IfStatement)42 Parameter (com.facebook.presto.bytecode.Parameter)38 Scope (com.facebook.presto.bytecode.Scope)33 Block (com.facebook.presto.spi.block.Block)23 BytecodeExpression (com.facebook.presto.bytecode.expression.BytecodeExpression)18 LabelNode (com.facebook.presto.bytecode.instruction.LabelNode)18 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)17 ImmutableList (com.google.common.collect.ImmutableList)16 ForLoop (com.facebook.presto.bytecode.control.ForLoop)12 Type (com.facebook.presto.spi.type.Type)12 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)11 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)11 LazyBlock (com.facebook.presto.spi.block.LazyBlock)11 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)11 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)10 List (java.util.List)9 RowExpression (com.facebook.presto.sql.relational.RowExpression)7