Package com.facebook.presto.byteCode

Examples of com.facebook.presto.byteCode.Variable


                        .add(arg("position", int.class))
                        .build());

        method.comment("Filter: %s", filter.toString());

        Variable positionVariable = context.getVariable("position");
        Variable wasNullVariable = context.declareVariable(type(boolean.class), "wasNull");

        ByteCodeExpressionVisitor visitor = new ByteCodeExpressionVisitor(
                callSiteBinder,
                fieldReferenceCompiler(callSiteBinder, positionVariable, wasNullVariable),
                metadata.getFunctionRegistry());
View Full Code Here


                        .add(arg("output", BlockBuilder.class))
                        .build());

        method.comment("Projection: %s", projection.toString());

        Variable positionVariable = context.getVariable("position");
        Variable outputVariable = context.getVariable("output");

        Variable wasNullVariable = context.declareVariable(type(boolean.class), "wasNull");

        Block body = method.getBody()
                .comment("boolean wasNull = false;")
                .putVariable(wasNullVariable, false);
View Full Code Here

            return coerceToType(context, elseValue, resultType);
        }

        // evaluate the value and store it in a variable
        LabelNode nullValue = new LabelNode("nullCondition");
        Variable tempVariable = context.createTempVariable(valueType);
        Block block = new Block(context)
                .append(coerceToType(context, value, valueType).getNode())
                .append(ifWasNullClearPopAndGoto(context, nullValue, void.class, valueType))
                .putVariable(tempVariable.getLocalVariableDefinition());

        // build the statements
        elseValue = typedByteCodeNode(new Block(context).visitLabel(nullValue).append(coerceToType(context, elseValue, resultType).getNode()), resultType);
        // reverse list because current if statement builder doesn't support if/else so we need to build the if statements bottom up
        for (TypedWhenClause whenClause : Lists.reverse(new ArrayList<>(whenClauses))) {
            LabelNode nullCondition = new LabelNode("nullCondition");
            Block condition = new Block(context)
                    .append(coerceToType(context, whenClause.condition, valueType).getNode())
                    .append(ifWasNullPopAndGoto(context, nullCondition, boolean.class, valueType))
                    .getVariable(tempVariable.getLocalVariableDefinition())
                    .invokeStatic(Operations.class, "equal", boolean.class, valueType, valueType)
                    .visitLabel(nullCondition)
                    .putVariable("wasNull", false);

            elseValue = typedByteCodeNode(new IfStatement(context,
View Full Code Here

            LabelNode matchLabel,
            LabelNode noMatchLabel,
            Collection<TypedByteCodeNode> testValues,
            boolean checkForNulls)
    {
        Variable caseWasNull = null;
        if (checkForNulls) {
            caseWasNull = context.createTempVariable(boolean.class);
        }

        Block caseBlock = new Block(context)
                .visitLabel(caseLabel);

        if (checkForNulls) {
            caseBlock.putVariable(caseWasNull.getLocalVariableDefinition(), false);
        }

        LabelNode elseLabel = new LabelNode("else");
        Block elseBlock = new Block(context)
                .visitLabel(elseLabel);

        if (checkForNulls) {
            elseBlock.getVariable(caseWasNull.getLocalVariableDefinition())
                    .putVariable("wasNull");
        }

        elseBlock.gotoLabel(noMatchLabel);

        ByteCodeNode elseNode = elseBlock;
        for (TypedByteCodeNode testNode : testValues) {
            LabelNode testLabel = new LabelNode("test");
            IfStatementBuilder test = ifStatementBuilder(context);

            Block condition = new Block(context)
                    .visitLabel(testLabel)
                    .dup(type)
                    .append(coerceToType(context, testNode, type).getNode());

            if (checkForNulls) {
                condition.getVariable("wasNull")
                        .putVariable(caseWasNull.getLocalVariableDefinition())
                        .append(ifWasNullPopAndGoto(context, elseLabel, void.class, type, type));
            }
            condition.invokeStatic(Operations.class, "equal", boolean.class, type, type);
            test.condition(condition);
View Full Code Here

        // determine the type of the value and result
        Class<?> valueType = expressionTypes.get(node.getOperand()).getJavaType();

        // evaluate the value and store it in a variable
        LabelNode nullValue = new LabelNode("nullCondition");
        Variable tempVariable = context.createTempVariable(valueType);
        Block block = new Block(context)
                .append(value)
                .append(ifWasNullClearPopAndGoto(context, nullValue, void.class, valueType))
                .putVariable(tempVariable.getLocalVariableDefinition());

        ByteCodeNode getTempVariableNode = VariableInstruction.loadVariable(tempVariable.getLocalVariableDefinition());

        // build the statements
        elseValue = new Block(context).visitLabel(nullValue).append(elseValue);
        // reverse list because current if statement builder doesn't support if/else so we need to build the if statements bottom up
        for (TypedWhenClause whenClause : Lists.reverse(new ArrayList<>(whenClauses))) {
View Full Code Here

            LabelNode matchLabel,
            LabelNode noMatchLabel,
            Collection<ByteCodeNode> testValues,
            boolean checkForNulls)
    {
        Variable caseWasNull = null;
        if (checkForNulls) {
            caseWasNull = context.createTempVariable(boolean.class);
        }

        Block caseBlock = new Block(context)
                .visitLabel(caseLabel);

        if (checkForNulls) {
            caseBlock.putVariable(caseWasNull.getLocalVariableDefinition(), false);
        }

        LabelNode elseLabel = new LabelNode("else");
        Block elseBlock = new Block(context)
                .visitLabel(elseLabel);

        if (checkForNulls) {
            elseBlock.getVariable(caseWasNull.getLocalVariableDefinition())
                    .putVariable("wasNull");
        }

        elseBlock.gotoLabel(noMatchLabel);

        FunctionBinding equalsFunction = bootstrapFunctionBinder.bindOperator(
                OperatorType.EQUAL,
                getSessionByteCode,
                ImmutableList.<ByteCodeNode>of(NOP, NOP),
                ImmutableList.of(type, type));

        ByteCodeNode elseNode = elseBlock;
        for (ByteCodeNode testNode : testValues) {
            LabelNode testLabel = new LabelNode("test");
            IfStatementBuilder test = ifStatementBuilder(context);

            Block condition = new Block(context)
                    .visitLabel(testLabel)
                    .dup(type.getJavaType())
                    .append(testNode);

            if (checkForNulls) {
                condition.getVariable("wasNull")
                        .putVariable(caseWasNull.getLocalVariableDefinition())
                        .append(ifWasNullPopAndGoto(context, elseLabel, void.class, type.getJavaType(), type.getJavaType()));
            }
            condition.invokeDynamic(equalsFunction.getName(), equalsFunction.getCallSite().type(), equalsFunction.getBindingId());
            test.condition(condition);
View Full Code Here

                arg("session", ConnectorSession.class),
                arg("cursor", RecordCursor.class),
                arg("count", int.class),
                arg("pageBuilder", PageBuilder.class));

        Variable sessionVariable = context.getVariable("session");
        Variable cursorVariable = context.getVariable("cursor");
        Variable countVariable = context.getVariable("count");
        Variable pageBuilderVariable = context.getVariable("pageBuilder");

        Variable completedPositionsVariable = context.declareVariable(int.class, "completedPositions");

        method.getBody()
                .comment("int completedPositions = 0;")
                .putVariable(completedPositionsVariable, 0);
View Full Code Here

                arg("session", ConnectorSession.class),
                arg("cursor", RecordCursor.class));

        method.comment("Filter: %s", filter);

        Variable wasNullVariable = context.declareVariable(type(boolean.class), "wasNull");
        Variable cursorVariable = context.getVariable("cursor");

        ByteCodeExpressionVisitor visitor = new ByteCodeExpressionVisitor(callSiteBinder, fieldReferenceCompiler(cursorVariable, wasNullVariable), metadata.getFunctionRegistry());

        LabelNode end = new LabelNode("end");
        method.getBody()
View Full Code Here

                arg("cursor", RecordCursor.class),
                arg("output", BlockBuilder.class));

        method.comment("Projection: %s", projection.toString());

        Variable outputVariable = context.getVariable("output");

        Variable cursorVariable = context.getVariable("cursor");
        Variable wasNullVariable = context.declareVariable(type(boolean.class), "wasNull");

        Block body = method.getBody()
                .comment("boolean wasNull = false;")
                .putVariable(wasNullVariable, false);
View Full Code Here

                arg("page", Page.class),
                arg("start", int.class),
                arg("end", int.class),
                arg("pageBuilder", PageBuilder.class));

        Variable sessionVariable = context.getVariable("session");
        Variable pageVariable = context.getVariable("page");
        Variable startVariable = context.getVariable("start");
        Variable endVariable = context.getVariable("end");
        Variable pageBuilderVariable = context.getVariable("pageBuilder");

        Variable positionVariable = context.declareVariable(int.class, "position");

        method.getBody()
                .comment("int position = start;")
                .getVariable(startVariable)
                .putVariable(positionVariable);

        List<Integer> allInputChannels = getInputChannels(Iterables.concat(projections, ImmutableList.of(filter)));
        for (int channel : allInputChannels) {
            Variable blockVariable = context.declareVariable(com.facebook.presto.spi.block.Block.class, "block_" + channel);
            method.getBody()
                    .comment("Block %s = page.getBlock(%s);", blockVariable.getName(), channel)
                    .getVariable(pageVariable)
                    .push(channel)
                    .invokeVirtual(Page.class, "getBlock", com.facebook.presto.spi.block.Block.class, int.class)
                    .putVariable(blockVariable);
        }
View Full Code Here

TOP

Related Classes of com.facebook.presto.byteCode.Variable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.