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

com.oracle.truffle.sl.builtins.SLPrintlnBuiltinFactory Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * The Universal Permissive License (UPL), Version 1.0
 *
 * Subject to the condition set forth below, permission is hereby granted to any
 * person obtaining a copy of this software, associated documentation and/or
 * data (collectively the "Software"), free of charge and under any and all
 * copyright rights in the Software, and any and all patent rights owned or
 * freely licensable by each licensor hereunder covering either (i) the
 * unmodified Software as contributed to or provided by such licensor, or (ii)
 * the Larger Works (as defined below), to deal in both
 *
 * (a) the Software, and
 *
 * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
 * one is included with the Software each a "Larger Work" to which the Software
 * is contributed by such licensors),
 *
 * without restriction, including without limitation the rights to copy, create
 * derivative works of, display, perform, and distribute the Software and make,
 * use, sell, offer for sale, import, export, have made, and have sold the
 * Software and the Larger Work(s), and to sublicense the foregoing rights on
 * either these or other terms.
 *
 * This license is subject to the following condition:
 *
 * The above copyright notice and either this complete permission notice or at a
 * minimum a reference to the UPL must be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
// CheckStyle: start generated
package com.oracle.truffle.sl.builtins;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.internal.NodeFactoryBase;
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.sl.nodes.SLExpressionNode;
import com.oracle.truffle.sl.nodes.SLTypesGen;
import com.oracle.truffle.sl.runtime.SLContext;

@GeneratedBy(SLPrintlnBuiltin.class)
public final class SLPrintlnBuiltinFactory extends NodeFactoryBase {

    private static SLPrintlnBuiltinFactory instance;

    private SLPrintlnBuiltinFactory() {
        super(SLPrintlnBuiltin.class, new Class[] {SLExpressionNode.class}, new Class[][] {new Class[] {SLExpressionNode[].class, SLContext.class}});
    }

    @Override
    public SLPrintlnBuiltin createNode(Object... arguments) {
        if (arguments.length == 2 && (arguments[0] == null || arguments[0] instanceof SLExpressionNode[]) && (arguments[1] == null || arguments[1] instanceof SLContext)) {
            return create((SLExpressionNode[]) arguments[0], (SLContext) arguments[1]);
        } else {
            throw new IllegalArgumentException("Invalid create signature.");
        }
    }

    public static NodeFactory getInstance() {
        if (instance == null) {
            instance = new SLPrintlnBuiltinFactory();
        }
        return instance;
    }

    public static SLPrintlnBuiltin create(SLExpressionNode[] arguments, SLContext context) {
        return new SLPrintlnBuiltinNodeGen(arguments, context);
    }

    @GeneratedBy(SLPrintlnBuiltin.class)
    public static final class SLPrintlnBuiltinNodeGen extends SLPrintlnBuiltin implements SpecializedNode {

        private final SLContext context;
        @Child private SLExpressionNode arguments0_;
        @CompilationFinal private Class arguments0Type_;
        @Child private BaseNode_ specialization_;

        private SLPrintlnBuiltinNodeGen(SLExpressionNode[] arguments, SLContext context) {
            this.context = context;
            this.arguments0_ = arguments != null && 0 < arguments.length ? arguments[0] : null;
            this.specialization_ = UninitializedNode_.create(this);
        }

        @Override
        public SLContext getContext() {
            return this.context;
        }

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

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

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

        @Override
        public boolean executeBoolean(VirtualFrame frameValue) throws UnexpectedResultException {
            return specialization_.executeBoolean(frameValue);
        }

        @Override
        public long executeLong(VirtualFrame frameValue) throws UnexpectedResultException {
            return specialization_.executeLong(frameValue);
        }

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

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

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

            protected final SLPrintlnBuiltinNodeGen root;

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

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

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

            public abstract Object execute_(VirtualFrame frameValue, Object arguments0Value);

            public Object execute(VirtualFrame frameValue) {
                Object arguments0Value_ = executeArguments0_(frameValue);
                return execute_(frameValue, arguments0Value_);
            }

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

            public boolean executeBoolean(VirtualFrame frameValue) throws UnexpectedResultException {
                return SLTypesGen.expectBoolean(execute(frameValue));
            }

            public long executeLong(VirtualFrame frameValue) throws UnexpectedResultException {
                return SLTypesGen.expectLong(execute(frameValue));
            }

            @Override
            protected final SpecializationNode createNext(Frame frameValue, Object arguments0Value) {
                if (arguments0Value instanceof Long) {
                    return Println0Node_.create(root);
                }
                if (arguments0Value instanceof Boolean) {
                    return Println1Node_.create(root);
                }
                if (arguments0Value instanceof String) {
                    return Println2Node_.create(root);
                }
                return Println3Node_.create(root);
            }

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

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

            protected final Object executeArguments0_(Frame frameValue) {
                Class arguments0Type_ = root.arguments0Type_;
                try {
                    if (arguments0Type_ == boolean.class) {
                        return root.arguments0_.executeBoolean((VirtualFrame) frameValue);
                    } else if (arguments0Type_ == long.class) {
                        return root.arguments0_.executeLong((VirtualFrame) frameValue);
                    } else if (arguments0Type_ == null) {
                        CompilerDirectives.transferToInterpreterAndInvalidate();
                        Class _type = Object.class;
                        try {
                            Object _value = root.arguments0_.executeGeneric((VirtualFrame) frameValue);
                            if (_value instanceof Boolean) {
                                _type = boolean.class;
                            } else if (_value instanceof Long) {
                                _type = long.class;
                            } else {
                                _type = Object.class;
                            }
                            return _value;
                        } finally {
                            root.arguments0Type_ = _type;
                        }
                    } else {
                        return root.arguments0_.executeGeneric((VirtualFrame) frameValue);
                    }
                } catch (UnexpectedResultException ex) {
                    root.arguments0Type_ = Object.class;
                    return ex.getResult();
                }
            }

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

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

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

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

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

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

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

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

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

        }
        @GeneratedBy(methodName = "println(long)", value = SLPrintlnBuiltin.class)
        private static final class Println0Node_ extends BaseNode_ {

            Println0Node_(SLPrintlnBuiltinNodeGen root) {
                super(root, 1);
            }

            @Override
            public Object execute(VirtualFrame frameValue) {
                try {
                    return executeLong(frameValue);
                } catch (UnexpectedResultException ex) {
                    return ex.getResult();
                }
            }

            @Override
            public long executeLong(VirtualFrame frameValue) throws UnexpectedResultException {
                long arguments0Value_;
                try {
                    arguments0Value_ = root.arguments0_.executeLong(frameValue);
                } catch (UnexpectedResultException ex) {
                    return SLTypesGen.expectLong(getNext().execute_(frameValue, ex.getResult()));
                }
                return root.println(arguments0Value_);
            }

            @Override
            public Object execute_(VirtualFrame frameValue, Object arguments0Value) {
                if (arguments0Value instanceof Long) {
                    long arguments0Value_ = (long) arguments0Value;
                    return root.println(arguments0Value_);
                }
                return getNext().execute_(frameValue, arguments0Value);
            }

            static BaseNode_ create(SLPrintlnBuiltinNodeGen root) {
                return new Println0Node_(root);
            }

        }
        @GeneratedBy(methodName = "println(boolean)", value = SLPrintlnBuiltin.class)
        private static final class Println1Node_ extends BaseNode_ {

            Println1Node_(SLPrintlnBuiltinNodeGen root) {
                super(root, 2);
            }

            @Override
            public Object execute(VirtualFrame frameValue) {
                try {
                    return executeBoolean(frameValue);
                } catch (UnexpectedResultException ex) {
                    return ex.getResult();
                }
            }

            @Override
            public boolean executeBoolean(VirtualFrame frameValue) throws UnexpectedResultException {
                boolean arguments0Value_;
                try {
                    arguments0Value_ = root.arguments0_.executeBoolean(frameValue);
                } catch (UnexpectedResultException ex) {
                    return SLTypesGen.expectBoolean(getNext().execute_(frameValue, ex.getResult()));
                }
                return root.println(arguments0Value_);
            }

            @Override
            public Object execute_(VirtualFrame frameValue, Object arguments0Value) {
                if (arguments0Value instanceof Boolean) {
                    boolean arguments0Value_ = (boolean) arguments0Value;
                    return root.println(arguments0Value_);
                }
                return getNext().execute_(frameValue, arguments0Value);
            }

            static BaseNode_ create(SLPrintlnBuiltinNodeGen root) {
                return new Println1Node_(root);
            }

        }
        @GeneratedBy(methodName = "println(String)", value = SLPrintlnBuiltin.class)
        private static final class Println2Node_ extends BaseNode_ {

            Println2Node_(SLPrintlnBuiltinNodeGen root) {
                super(root, 3);
            }

            @Override
            public Object execute_(VirtualFrame frameValue, Object arguments0Value) {
                if (arguments0Value instanceof String) {
                    String arguments0Value_ = (String) arguments0Value;
                    return root.println(arguments0Value_);
                }
                return getNext().execute_(frameValue, arguments0Value);
            }

            static BaseNode_ create(SLPrintlnBuiltinNodeGen root) {
                return new Println2Node_(root);
            }

        }
        @GeneratedBy(methodName = "println(Object)", value = SLPrintlnBuiltin.class)
        private static final class Println3Node_ extends BaseNode_ {

            Println3Node_(SLPrintlnBuiltinNodeGen root) {
                super(root, 4);
            }

            @Override
            public Object execute_(VirtualFrame frameValue, Object arguments0Value) {
                return root.println(arguments0Value);
            }

            static BaseNode_ create(SLPrintlnBuiltinNodeGen root) {
                return new Println3Node_(root);
            }

        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy