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));
}
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));
}
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);
}
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;
}
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);
}
Aggregations