All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jruby.truffle.stdlib.bigdecimal.BigDecimalCastNodeGen Maven / Gradle / Ivy

The newest version!
// CheckStyle: start generated
package org.jruby.truffle.stdlib.bigdecimal;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.internal.SpecializationNode;
import com.oracle.truffle.api.dsl.internal.SpecializedNode;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyTypes;
import org.jruby.truffle.language.RubyTypesGen;
import org.jruby.truffle.language.SnippetNode;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;

@GeneratedBy(BigDecimalCastNode.class)
public final class BigDecimalCastNodeGen extends BigDecimalCastNode implements SpecializedNode {

    @Child private RubyNode value_;
    @Child private RubyNode roundingMode_;
    @CompilationFinal private Class valueType_;
    @Child private BaseNode_ specialization_;

    private BigDecimalCastNodeGen(RubyNode value, RubyNode roundingMode) {
        this.value_ = value;
        this.roundingMode_ = roundingMode;
        this.specialization_ = UninitializedNode_.create(this);
    }

    @Override
    public NodeCost getCost() {
        return specialization_.getNodeCost();
    }

    @Override
    public Object executeObject(VirtualFrame frameValue, Object valueValue, RoundingMode roundingModeValue) {
        return specialization_.execute1(frameValue, valueValue, roundingModeValue);
    }

    @Override
    public BigDecimal executeBigDecimal(VirtualFrame frameValue, Object valueValue, RoundingMode roundingModeValue) {
        return specialization_.executeBigDecimal(frameValue, valueValue, roundingModeValue);
    }

    @Override
    public Object execute(VirtualFrame frameValue) {
        return specialization_.execute0(frameValue);
    }

    @Override
    public void executeVoid(VirtualFrame frameValue) {
        specialization_.executeVoid(frameValue);
        return;
    }

    @Override
    public SpecializationNode getSpecializationNode() {
        return specialization_;
    }

    @Override
    public Node deepCopy() {
        return SpecializationNode.updateRoot(super.deepCopy());
    }

    public static BigDecimalCastNode create(RubyNode value, RubyNode roundingMode) {
        return new BigDecimalCastNodeGen(value, roundingMode);
    }

    @GeneratedBy(BigDecimalCastNode.class)
    private abstract static class BaseNode_ extends SpecializationNode {

        @CompilationFinal protected BigDecimalCastNodeGen root;

        BaseNode_(BigDecimalCastNodeGen root, int index) {
            super(index);
            this.root = root;
        }

        @Override
        protected final void setRoot(Node root) {
            this.root = (BigDecimalCastNodeGen) root;
        }

        @Override
        protected final Node[] getSuppliedChildren() {
            return new Node[] {root.value_, root.roundingMode_};
        }

        @Override
        public final Object acceptAndExecute(Frame frameValue, Object valueValue, Object roundingModeValue) {
            return this.execute_((VirtualFrame) frameValue, valueValue, roundingModeValue);
        }

        public abstract Object execute_(VirtualFrame frameValue, Object valueValue, Object roundingModeValue);

        public Object execute1(VirtualFrame frameValue, Object valueValue, RoundingMode roundingModeValue) {
            return execute_(frameValue, valueValue, roundingModeValue);
        }

        public BigDecimal executeBigDecimal(VirtualFrame frameValue, Object valueValue, RoundingMode roundingModeValue) {
            return (BigDecimal) execute1(frameValue, valueValue, roundingModeValue);
        }

        public Object execute0(VirtualFrame frameValue) {
            Object valueValue_ = executeValue_(frameValue);
            Object roundingModeValue_ = root.roundingMode_.execute(frameValue);
            return execute_(frameValue, valueValue_, roundingModeValue_);
        }

        public void executeVoid(VirtualFrame frameValue) {
            execute0(frameValue);
            return;
        }

        @Override
        protected final SpecializationNode createNext(Frame frameValue, Object valueValue, Object roundingModeValue) {
            if (RubyTypesGen.isImplicitLong(valueValue)) {
                return IntNode_.create(root, valueValue);
            }
            if (RubyTypesGen.isImplicitDouble(valueValue)) {
                return DoubleNode_.create(root, valueValue);
            }
            if (valueValue instanceof DynamicObject) {
                DynamicObject valueValue_ = (DynamicObject) valueValue;
                if ((RubyGuards.isRubyBignum(valueValue_))) {
                    return BignumNode_.create(root);
                }
                if ((BigDecimalCoreMethodNode.isNormalRubyBigDecimal(valueValue_))) {
                    return BigDecimalNode_.create(root);
                }
                if ((!(RubyGuards.isRubyBignum(valueValue_))) && (!(RubyGuards.isRubyBigDecimal(valueValue_)))) {
                    SnippetNode isRationalSnippet5 = (new SnippetNode());
                    CallDispatchHeadNode numeratorCallNode5 = (CallDispatchHeadNode.createMethodCall());
                    CallDispatchHeadNode denominatorCallNode5 = (CallDispatchHeadNode.createMethodCall());
                    CallDispatchHeadNode toFCallNode5 = (CallDispatchHeadNode.createMethodCall());
                    return OtherNode_.create(root, isRationalSnippet5, numeratorCallNode5, denominatorCallNode5, toFCallNode5);
                }
            }
            return null;
        }

        @Override
        protected final SpecializationNode createFallback() {
            return FallbackNode_.create(root);
        }

        @Override
        protected final SpecializationNode createPolymorphic() {
            return PolymorphicNode_.create(root);
        }

        protected final BaseNode_ getNext() {
            return (BaseNode_) this.next;
        }

        protected final Object executeValue_(Frame frameValue) {
            Class valueType_ = root.valueType_;
            try {
                if (valueType_ == double.class) {
                    return root.value_.executeDouble((VirtualFrame) frameValue);
                } else if (valueType_ == int.class) {
                    return root.value_.executeInteger((VirtualFrame) frameValue);
                } else if (valueType_ == long.class) {
                    return root.value_.executeLong((VirtualFrame) frameValue);
                } else if (valueType_ == null) {
                    CompilerDirectives.transferToInterpreterAndInvalidate();
                    Class _type = Object.class;
                    try {
                        Object _value = root.value_.execute((VirtualFrame) frameValue);
                        if (_value instanceof Double) {
                            _type = double.class;
                        } else if (_value instanceof Integer) {
                            _type = int.class;
                        } else if (_value instanceof Long) {
                            _type = long.class;
                        } else {
                            _type = Object.class;
                        }
                        return _value;
                    } finally {
                        root.valueType_ = _type;
                    }
                } else {
                    return root.value_.execute((VirtualFrame) frameValue);
                }
            } catch (UnexpectedResultException ex) {
                root.valueType_ = Object.class;
                return ex.getResult();
            }
        }

    }
    @GeneratedBy(BigDecimalCastNode.class)
    private static final class UninitializedNode_ extends BaseNode_ {

        UninitializedNode_(BigDecimalCastNodeGen root) {
            super(root, 2147483647);
        }

        @Override
        public Object execute_(VirtualFrame frameValue, Object valueValue, Object roundingModeValue) {
            return uninitialized(frameValue, valueValue, roundingModeValue);
        }

        static BaseNode_ create(BigDecimalCastNodeGen root) {
            return new UninitializedNode_(root);
        }

    }
    @GeneratedBy(BigDecimalCastNode.class)
    private static final class PolymorphicNode_ extends BaseNode_ {

        PolymorphicNode_(BigDecimalCastNodeGen root) {
            super(root, 0);
        }

        @Override
        public SpecializationNode merge(SpecializationNode newNode, Frame frameValue, Object valueValue, Object roundingModeValue) {
            return polymorphicMerge(newNode, super.merge(newNode, frameValue, valueValue, roundingModeValue));
        }

        @Override
        public Object execute_(VirtualFrame frameValue, Object valueValue, Object roundingModeValue) {
            return getNext().execute_(frameValue, valueValue, roundingModeValue);
        }

        static BaseNode_ create(BigDecimalCastNodeGen root) {
            return new PolymorphicNode_(root);
        }

    }
    @GeneratedBy(methodName = "doInt(long, Object)", value = BigDecimalCastNode.class)
    private static final class IntNode_ extends BaseNode_ {

        private final Class valueImplicitType;

        IntNode_(BigDecimalCastNodeGen root, Object valueValue) {
            super(root, 1);
            this.valueImplicitType = RubyTypesGen.getImplicitLongClass(valueValue);
        }

        @Override
        public boolean isSame(SpecializationNode other) {
            return super.isSame(other) && this.valueImplicitType == ((IntNode_) other).valueImplicitType;
        }

        @Override
        public Object execute0(VirtualFrame frameValue) {
            long valueValue_;
            try {
                if (valueImplicitType == long.class) {
                    valueValue_ = root.value_.executeLong(frameValue);
                } else if (valueImplicitType == int.class) {
                    valueValue_ = RubyTypes.promoteToLong(root.value_.executeInteger(frameValue));
                } else {
                    Object valueValue__ = executeValue_(frameValue);
                    valueValue_ = RubyTypesGen.expectImplicitLong(valueValue__, valueImplicitType);
                }
            } catch (UnexpectedResultException ex) {
                Object roundingModeValue = root.roundingMode_.execute(frameValue);
                return getNext().execute_(frameValue, ex.getResult(), roundingModeValue);
            }
            Object roundingModeValue_ = root.roundingMode_.execute(frameValue);
            return root.doInt(valueValue_, roundingModeValue_);
        }

        @Override
        public Object execute_(VirtualFrame frameValue, Object valueValue, Object roundingModeValue) {
            if (RubyTypesGen.isImplicitLong(valueValue, valueImplicitType)) {
                long valueValue_ = RubyTypesGen.asImplicitLong(valueValue, valueImplicitType);
                return root.doInt(valueValue_, roundingModeValue);
            }
            return getNext().execute_(frameValue, valueValue, roundingModeValue);
        }

        static BaseNode_ create(BigDecimalCastNodeGen root, Object valueValue) {
            return new IntNode_(root, valueValue);
        }

    }
    @GeneratedBy(methodName = "doDouble(double, Object)", value = BigDecimalCastNode.class)
    private static final class DoubleNode_ extends BaseNode_ {

        private final Class valueImplicitType;

        DoubleNode_(BigDecimalCastNodeGen root, Object valueValue) {
            super(root, 2);
            this.valueImplicitType = RubyTypesGen.getImplicitDoubleClass(valueValue);
        }

        @Override
        public boolean isSame(SpecializationNode other) {
            return super.isSame(other) && this.valueImplicitType == ((DoubleNode_) other).valueImplicitType;
        }

        @Override
        public Object execute0(VirtualFrame frameValue) {
            double valueValue_;
            try {
                if (valueImplicitType == double.class) {
                    valueValue_ = root.value_.executeDouble(frameValue);
                } else {
                    Object valueValue__ = executeValue_(frameValue);
                    valueValue_ = RubyTypesGen.expectImplicitDouble(valueValue__, valueImplicitType);
                }
            } catch (UnexpectedResultException ex) {
                Object roundingModeValue = root.roundingMode_.execute(frameValue);
                return getNext().execute_(frameValue, ex.getResult(), roundingModeValue);
            }
            Object roundingModeValue_ = root.roundingMode_.execute(frameValue);
            return root.doDouble(valueValue_, roundingModeValue_);
        }

        @Override
        public Object execute_(VirtualFrame frameValue, Object valueValue, Object roundingModeValue) {
            if (RubyTypesGen.isImplicitDouble(valueValue, valueImplicitType)) {
                double valueValue_ = RubyTypesGen.asImplicitDouble(valueValue, valueImplicitType);
                return root.doDouble(valueValue_, roundingModeValue);
            }
            return getNext().execute_(frameValue, valueValue, roundingModeValue);
        }

        static BaseNode_ create(BigDecimalCastNodeGen root, Object valueValue) {
            return new DoubleNode_(root, valueValue);
        }

    }
    @GeneratedBy(methodName = "doBignum(DynamicObject, Object)", value = BigDecimalCastNode.class)
    private static final class BignumNode_ extends BaseNode_ {

        BignumNode_(BigDecimalCastNodeGen root) {
            super(root, 3);
        }

        @Override
        public Object execute_(VirtualFrame frameValue, Object valueValue, Object roundingModeValue) {
            if (valueValue instanceof DynamicObject) {
                DynamicObject valueValue_ = (DynamicObject) valueValue;
                if ((RubyGuards.isRubyBignum(valueValue_))) {
                    return root.doBignum(valueValue_, roundingModeValue);
                }
            }
            return getNext().execute_(frameValue, valueValue, roundingModeValue);
        }

        static BaseNode_ create(BigDecimalCastNodeGen root) {
            return new BignumNode_(root);
        }

    }
    @GeneratedBy(methodName = "doBigDecimal(DynamicObject, Object)", value = BigDecimalCastNode.class)
    private static final class BigDecimalNode_ extends BaseNode_ {

        BigDecimalNode_(BigDecimalCastNodeGen root) {
            super(root, 4);
        }

        @Override
        public Object execute_(VirtualFrame frameValue, Object valueValue, Object roundingModeValue) {
            if (valueValue instanceof DynamicObject) {
                DynamicObject valueValue_ = (DynamicObject) valueValue;
                if ((BigDecimalCoreMethodNode.isNormalRubyBigDecimal(valueValue_))) {
                    return root.doBigDecimal(valueValue_, roundingModeValue);
                }
            }
            return getNext().execute_(frameValue, valueValue, roundingModeValue);
        }

        static BaseNode_ create(BigDecimalCastNodeGen root) {
            return new BigDecimalNode_(root);
        }

    }
    @GeneratedBy(methodName = "doOther(VirtualFrame, DynamicObject, Object, SnippetNode, CallDispatchHeadNode, CallDispatchHeadNode, CallDispatchHeadNode)", value = BigDecimalCastNode.class)
    private static final class OtherNode_ extends BaseNode_ {

        @Child private SnippetNode isRationalSnippet;
        @Child private CallDispatchHeadNode numeratorCallNode;
        @Child private CallDispatchHeadNode denominatorCallNode;
        @Child private CallDispatchHeadNode toFCallNode;

        OtherNode_(BigDecimalCastNodeGen root, SnippetNode isRationalSnippet, CallDispatchHeadNode numeratorCallNode, CallDispatchHeadNode denominatorCallNode, CallDispatchHeadNode toFCallNode) {
            super(root, 5);
            this.isRationalSnippet = isRationalSnippet;
            this.numeratorCallNode = numeratorCallNode;
            this.denominatorCallNode = denominatorCallNode;
            this.toFCallNode = toFCallNode;
        }

        @Override
        public Object execute_(VirtualFrame frameValue, Object valueValue, Object roundingModeValue) {
            if (valueValue instanceof DynamicObject) {
                DynamicObject valueValue_ = (DynamicObject) valueValue;
                if ((!(RubyGuards.isRubyBignum(valueValue_))) && (!(RubyGuards.isRubyBigDecimal(valueValue_)))) {
                    return root.doOther(frameValue, valueValue_, roundingModeValue, this.isRationalSnippet, this.numeratorCallNode, this.denominatorCallNode, this.toFCallNode);
                }
            }
            return getNext().execute_(frameValue, valueValue, roundingModeValue);
        }

        static BaseNode_ create(BigDecimalCastNodeGen root, SnippetNode isRationalSnippet, CallDispatchHeadNode numeratorCallNode, CallDispatchHeadNode denominatorCallNode, CallDispatchHeadNode toFCallNode) {
            return new OtherNode_(root, isRationalSnippet, numeratorCallNode, denominatorCallNode, toFCallNode);
        }

    }
    @GeneratedBy(methodName = "doBigDecimalFallback(Object, Object)", value = BigDecimalCastNode.class)
    private static final class FallbackNode_ extends BaseNode_ {

        FallbackNode_(BigDecimalCastNodeGen root) {
            super(root, 2147483646);
        }

        @TruffleBoundary
        private boolean guardFallback(Object valueValue, Object roundingModeValue) {
            return createNext(null, valueValue, roundingModeValue) == null;
        }

        @Override
        public Object execute_(VirtualFrame frameValue, Object valueValue, Object roundingModeValue) {
            if (guardFallback(valueValue, roundingModeValue)) {
                return root.doBigDecimalFallback(valueValue, roundingModeValue);
            }
            return getNext().execute_(frameValue, valueValue, roundingModeValue);
        }

        static BaseNode_ create(BigDecimalCastNodeGen root) {
            return new FallbackNode_(root);
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy