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

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

There is a newer version: 1.0.0-rc7
Show newest version
// CheckStyle: start generated
/*
 * Copyright (c) 2015, 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.
 */
package com.oracle.truffle.sl.builtins;

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.DirectCallNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.sl.nodes.SLExpressionNode;
import com.oracle.truffle.sl.runtime.SLContext;

@GeneratedBy(SLEvalBuiltin.class)
public final class SLEvalBuiltinFactory extends NodeFactoryBase {

    private static SLEvalBuiltinFactory instance;

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

    @Override
    public SLEvalBuiltin 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 SLEvalBuiltinFactory();
        }
        return instance;
    }

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

    @GeneratedBy(SLEvalBuiltin.class)
    public static final class SLEvalBuiltinNodeGen extends SLEvalBuiltin implements SpecializedNode {

        private final SLContext context;
        @Child private SLExpressionNode arguments0_;
        @Child private SLExpressionNode arguments1_;
        @CompilationFinal private boolean excludeEvalCached_;
        @Child private BaseNode_ specialization_;

        private SLEvalBuiltinNodeGen(SLExpressionNode[] arguments, SLContext context) {
            this.context = context;
            this.arguments0_ = arguments != null && 0 < arguments.length ? arguments[0] : null;
            this.arguments1_ = arguments != null && 1 < arguments.length ? arguments[1] : 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 SpecializationNode getSpecializationNode() {
            return specialization_;
        }

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

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

            @CompilationFinal protected SLEvalBuiltinNodeGen root;

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

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

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

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

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

            public Object execute(VirtualFrame frameValue) {
                Object arguments0Value_ = root.arguments0_.executeGeneric(frameValue);
                Object arguments1Value_ = root.arguments1_.executeGeneric(frameValue);
                return execute_(frameValue, arguments0Value_, arguments1Value_);
            }

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

            @Override
            protected final SpecializationNode createNext(Frame frameValue, Object arguments0Value, Object arguments1Value) {
                if (arguments0Value instanceof String && arguments1Value instanceof String) {
                    String arguments0Value_ = (String) arguments0Value;
                    String arguments1Value_ = (String) arguments1Value;
                    String cachedMimeType1 = (arguments0Value_);
                    String cachedCode1 = (arguments1Value_);
                    if ((root.stringsEqual(arguments0Value_, cachedMimeType1)) && (root.stringsEqual(arguments1Value_, cachedCode1))) {
                        if (!root.excludeEvalCached_) {
                            DirectCallNode callNode1 = (DirectCallNode.create(root.parse(arguments0Value_, arguments1Value_)));
                            SpecializationNode s = EvalCachedNode_.create(root, cachedMimeType1, cachedCode1, callNode1);
                            if (countSame(s) < (3)) {
                                return s;
                            }
                        }
                    }
                    root.excludeEvalCached_ = true;
                    return EvalUncachedNode_.create(root);
                }
                return null;
            }

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

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

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

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

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

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

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

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

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

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

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

        }
        @GeneratedBy(methodName = "evalCached(VirtualFrame, String, String, String, String, DirectCallNode)", value = SLEvalBuiltin.class)
        private static final class EvalCachedNode_ extends BaseNode_ {

            private final String cachedMimeType;
            private final String cachedCode;
            @Child private DirectCallNode callNode;

            EvalCachedNode_(SLEvalBuiltinNodeGen root, String cachedMimeType, String cachedCode, DirectCallNode callNode) {
                super(root, 1);
                this.cachedMimeType = cachedMimeType;
                this.cachedCode = cachedCode;
                this.callNode = callNode;
            }

            @Override
            public SpecializationNode merge(SpecializationNode newNode, Frame frameValue, Object arguments0Value, Object arguments1Value) {
                if (newNode.getClass() == EvalUncachedNode_.class) {
                    removeSame("Contained by evalUncached(String, String)");
                }
                return super.merge(newNode, frameValue, arguments0Value, arguments1Value);
            }

            @Override
            public boolean isIdentical(SpecializationNode other, Frame frameValue, Object arguments0Value, Object arguments1Value) {
                if (arguments0Value instanceof String && arguments1Value instanceof String) {
                    String arguments0Value_ = (String) arguments0Value;
                    String arguments1Value_ = (String) arguments1Value;
                    if ((root.stringsEqual(arguments0Value_, this.cachedMimeType)) && (root.stringsEqual(arguments1Value_, this.cachedCode))) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            public Object execute_(VirtualFrame frameValue, Object arguments0Value, Object arguments1Value) {
                if (arguments0Value instanceof String && arguments1Value instanceof String) {
                    String arguments0Value_ = (String) arguments0Value;
                    String arguments1Value_ = (String) arguments1Value;
                    if ((root.stringsEqual(arguments0Value_, this.cachedMimeType)) && (root.stringsEqual(arguments1Value_, this.cachedCode))) {
                        return root.evalCached(frameValue, arguments0Value_, arguments1Value_, this.cachedMimeType, this.cachedCode, this.callNode);
                    }
                }
                return getNext().execute_(frameValue, arguments0Value, arguments1Value);
            }

            static BaseNode_ create(SLEvalBuiltinNodeGen root, String cachedMimeType, String cachedCode, DirectCallNode callNode) {
                return new EvalCachedNode_(root, cachedMimeType, cachedCode, callNode);
            }

        }
        @GeneratedBy(methodName = "evalUncached(String, String)", value = SLEvalBuiltin.class)
        private static final class EvalUncachedNode_ extends BaseNode_ {

            EvalUncachedNode_(SLEvalBuiltinNodeGen root) {
                super(root, 2);
            }

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

            static BaseNode_ create(SLEvalBuiltinNodeGen root) {
                return new EvalUncachedNode_(root);
            }

        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy