Package com.facebook.presto.byteCode.instruction

Examples of com.facebook.presto.byteCode.instruction.LabelNode


    {
        List<TypedByteCodeNode> arguments = functionBinding.getArguments();
        MethodType methodType = functionBinding.getCallSite().type();
        Class<?> unboxedReturnType = Primitives.unwrap(methodType.returnType());

        LabelNode end = new LabelNode("end");
        Block block = new Block(context)
                .setDescription("invoke")
                .comment(comment);
        ArrayList<Class<?>> stackTypes = new ArrayList<>();
        for (int i = 0; i < arguments.size(); i++) {
            TypedByteCodeNode argument = arguments.get(i);
            Class<?> argumentType = methodType.parameterList().get(i);
            block.append(coerceToType(context, argument, argumentType).getNode());

            stackTypes.add(argument.getType());
            block.append(ifWasNullPopAndGoto(context, end, unboxedReturnType, Lists.reverse(stackTypes)));
        }
        block.invokeDynamic(functionBinding.getName(), methodType, functionBinding.getBindingId());

        if (functionBinding.isNullable()) {
            if (unboxedReturnType.isPrimitive()) {
                LabelNode notNull = new LabelNode("notNull");
                block.dup(methodType.returnType())
                        .ifNotNullGoto(notNull)
                        .putVariable("wasNull", true)
                        .comment("swap boxed null with unboxed default")
                        .pop(methodType.returnType())
View Full Code Here


                    block.pushJavaDefault(Slice.class);
                    return typedByteCodeNode(block, Slice.class);
            }
        }
        else {
            LabelNode end = new LabelNode("end");
            switch (node.getType()) {
                case "BOOLEAN":
                    block.append(ifWasNullPopAndGoto(context, end, boolean.class, value.getType()));
                    block.invokeStatic(Operations.class, "castToBoolean", boolean.class, value.getType());
                    return typedByteCodeNode(block.visitLabel(end), boolean.class);
View Full Code Here

        if (!isNumber(type)) {
            throw new UnsupportedOperationException(format("not yet implemented: %s(%s, %s)", node.getType(), left.getType(), right.getType()));
        }

        Block block = new Block(context).comment(node.toString());
        LabelNode end = new LabelNode("end");

        block.append(coerceToType(context, left, type).getNode());
        block.append(ifWasNullPopAndGoto(context, end, type, left.getType()));

        block.append(coerceToType(context, right, type).getNode());
View Full Code Here

        IfStatementBuilder ifLeftIsNull = ifStatementBuilder(context)
                .comment("if left wasNull...")
                .condition(new Block(context).getVariable("wasNull"));

        LabelNode end = new LabelNode("end");
        ifLeftIsNull.ifTrue(new Block(context)
                .comment("clear the null flag, pop left value off stack, and push left null flag on the stack (true)")
                .putVariable("wasNull", false)
                .pop(left.getType()) // discard left value
                .push(true));

        LabelNode leftIsTrue = new LabelNode("leftIsTrue");
        ifLeftIsNull.ifFalse(new Block(context)
                .comment("if left is false, push false, and goto end")
                .ifTrueGoto(leftIsTrue)
                .push(false)
                .gotoLabel(end)
                .comment("left was true; push left null flag on the stack (false)")
                .visitLabel(leftIsTrue)
                .push(false));

        block.append(ifLeftIsNull.build());

        // At this point we know the left expression was either NULL or TRUE.  The stack contains a single boolean
        // value for this expression which indicates if the left value was NULL.

        // eval right!
        block.append(right.getNode());

        IfStatementBuilder ifRightIsNull = ifStatementBuilder(context)
                .comment("if right wasNull...")
                .condition(new Block(context).getVariable("wasNull"));

        // this leaves a single boolean on the stack which is ignored since the value in NULL
        ifRightIsNull.ifTrue(new Block(context)
                .comment("right was null, pop the right value off the stack; wasNull flag remains set to TRUE")
                .pop(right.getType()));

        LabelNode rightIsTrue = new LabelNode("rightIsTrue");
        ifRightIsNull.ifFalse(new Block(context)
                .comment("if right is false, pop left null flag off stack, push false and goto end")
                .ifTrueGoto(rightIsTrue)
                .pop(boolean.class)
                .push(false)
View Full Code Here

        IfStatementBuilder ifLeftIsNull = ifStatementBuilder(context)
                .comment("if left wasNull...")
                .condition(new Block(context).getVariable("wasNull"));

        LabelNode end = new LabelNode("end");
        ifLeftIsNull.ifTrue(new Block(context)
                .comment("clear the null flag, pop left value off stack, and push left null flag on the stack (true)")
                .putVariable("wasNull", false)
                .pop(left.getType()) // discard left value
                .push(true));

        LabelNode leftIsFalse = new LabelNode("leftIsFalse");
        ifLeftIsNull.ifFalse(new Block(context)
                .comment("if left is true, push true, and goto end")
                .ifFalseGoto(leftIsFalse)
                .push(true)
                .gotoLabel(end)
                .comment("left was false; push left null flag on the stack (false)")
                .visitLabel(leftIsFalse)
                .push(false));

        block.append(ifLeftIsNull.build());

        // At this point we know the left expression was either NULL or FALSE.  The stack contains a single boolean
        // value for this expression which indicates if the left value was NULL.

        // eval right!
        block.append(right.getNode());

        IfStatementBuilder ifRightIsNull = ifStatementBuilder(context)
                .comment("if right wasNull...")
                .condition(new Block(context).getVariable("wasNull"));

        // this leaves a single boolean on the stack which is ignored since the value in NULL
        ifRightIsNull.ifTrue(new Block(context)
                .comment("right was null, pop the right value off the stack; wasNull flag remains set to TRUE")
                .pop(right.getType()));

        LabelNode rightIsTrue = new LabelNode("rightIsTrue");
        ifRightIsNull.ifFalse(new Block(context)
                .comment("if right is true, pop left null flag off stack, push true and goto end")
                .ifFalseGoto(rightIsTrue)
                .pop(boolean.class)
                .push(true)
View Full Code Here

                break;
            default:
                throw new UnsupportedOperationException(format("not yet implemented: %s(%s, %s)", node.getType(), left.getType(), right.getType()));
        }

        LabelNode end = new LabelNode("end");
        Block block = new Block(context)
                .comment(node.toString());

        block.append(coerceToType(context, left, type).getNode());
        block.append(ifWasNullPopAndGoto(context, end, boolean.class, left.getType()));
View Full Code Here

            return max;
        }

        Class<?> type = getType(value, min, max);

        LabelNode end = new LabelNode("end");
        Block block = new Block(context)
                .comment(node.toString());

        block.append(coerceToType(context, value, type).getNode());
        block.append(ifWasNullPopAndGoto(context, end, boolean.class, type));
View Full Code Here

        if (value.getType() == void.class) {
            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)
View Full Code Here

            return first;
        }

        Class<?> comparisonType = getType(first, second);

        LabelNode notMatch = new LabelNode("notMatch");
        Block block = new Block(context)
                .comment(node.toString())
                .append(first.getNode())
                .append(ifWasNullPopAndGoto(context, notMatch, void.class))
                .append(coerceToType(context, typedByteCodeNode(new Block(context).dup(first.getType()), first.getType()), comparisonType).getNode())
View Full Code Here

            }
        }
        ImmutableListMultimap<Integer, TypedByteCodeNode> hashBuckets = hashBucketsBuilder.build();
        ImmutableSet<Object> constantValues = constantValuesBuilder.build();

        LabelNode end = new LabelNode("end");
        LabelNode match = new LabelNode("match");
        LabelNode noMatch = new LabelNode("noMatch");

        LabelNode defaultLabel = new LabelNode("default");

        ByteCodeNode switchBlock;
        if (constantValues.size() < 1000) {
            Block switchCaseBlocks = new Block(context);
            LookupSwitchBuilder switchBuilder = lookupSwitchBuilder();
            for (Entry<Integer, Collection<TypedByteCodeNode>> bucket : hashBuckets.asMap().entrySet()) {
                LabelNode label = new LabelNode("inHash" + bucket.getKey());
                switchBuilder.addCase(bucket.getKey(), label);
                Collection<TypedByteCodeNode> testValues = bucket.getValue();

                Block caseBlock = buildInCase(context, type, label, match, defaultLabel, testValues, false);
                switchCaseBlocks
View Full Code Here

TOP

Related Classes of com.facebook.presto.byteCode.instruction.LabelNode

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.