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

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

// 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.TruffleLanguage.ContextReference;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.sl.SLLanguage;
import com.oracle.truffle.sl.nodes.SLExpressionNode;
import com.oracle.truffle.sl.runtime.SLContext;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.locks.Lock;

@GeneratedBy(SLEvalBuiltin.class)
public final class SLEvalBuiltinFactory implements NodeFactory {

    private static final SLEvalBuiltinFactory INSTANCE = new SLEvalBuiltinFactory();

    private SLEvalBuiltinFactory() {
    }

    @Override
    public Class getNodeClass() {
        return SLEvalBuiltin.class;
    }

    @Override
    public List> getExecutionSignature() {
        return Arrays.asList(SLExpressionNode.class, SLExpressionNode.class);
    }

    @Override
    public List>> getNodeSignatures() {
        return Arrays.asList(Arrays.asList(SLExpressionNode[].class));
    }

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

    public static NodeFactory getInstance() {
        return INSTANCE;
    }

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

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

        @Child private SLExpressionNode arguments0_;
        @Child private SLExpressionNode arguments1_;
        @CompilationFinal private volatile int state_;
        @CompilationFinal private volatile int exclude_;
        @CompilationFinal private ContextReference sLLanguageContextReference_;
        @Child private EvalCachedData evalCached_cache;

        private SLEvalBuiltinNodeGen(SLExpressionNode[] arguments) {
            this.arguments0_ = arguments != null && 0 < arguments.length ? arguments[0] : null;
            this.arguments1_ = arguments != null && 1 < arguments.length ? arguments[1] : null;
        }

        @ExplodeLoop
        @Override
        protected Object execute(VirtualFrame frameValue) {
            int state = state_;
            Object arguments0Value_ = this.arguments0_.executeGeneric(frameValue);
            Object arguments1Value_ = this.arguments1_.executeGeneric(frameValue);
            if (state != 0 /* is-active evalCached(String, String, String, String, SLContext, DirectCallNode) || evalUncached(String, String, SLContext) */ && arguments0Value_ instanceof String) {
                String arguments0Value__ = (String) arguments0Value_;
                if (arguments1Value_ instanceof String) {
                    String arguments1Value__ = (String) arguments1Value_;
                    if ((state & 0b1) != 0 /* is-active evalCached(String, String, String, String, SLContext, DirectCallNode) */) {
                        EvalCachedData s1_ = this.evalCached_cache;
                        while (s1_ != null) {
                            if ((SLEvalBuiltin.stringsEqual(s1_.cachedId_, arguments0Value__)) && (SLEvalBuiltin.stringsEqual(s1_.cachedCode_, arguments1Value__))) {
                                ContextReference sLLanguageContextReference__ = this.sLLanguageContextReference_;
                                SLContext context__ = sLLanguageContextReference__.get();
                                return evalCached(arguments0Value__, arguments1Value__, s1_.cachedId_, s1_.cachedCode_, context__, s1_.callNode_);
                            }
                            s1_ = s1_.next_;
                        }
                    }
                    if ((state & 0b10) != 0 /* is-active evalUncached(String, String, SLContext) */) {
                        {
                            ContextReference sLLanguageContextReference__1 = this.sLLanguageContextReference_;
                            SLContext evalUncached_context__ = sLLanguageContextReference__1.get();
                            return evalUncached(arguments0Value__, arguments1Value__, evalUncached_context__);
                        }
                    }
                }
            }
            CompilerDirectives.transferToInterpreterAndInvalidate();
            return executeAndSpecialize(arguments0Value_, arguments1Value_);
        }

        private Object executeAndSpecialize(Object arguments0Value, Object arguments1Value) {
            Lock lock = getLock();
            boolean hasLock = true;
            lock.lock();
            int state = state_;
            int exclude = exclude_;
            try {
                if (arguments0Value instanceof String) {
                    String arguments0Value_ = (String) arguments0Value;
                    if (arguments1Value instanceof String) {
                        String arguments1Value_ = (String) arguments1Value;
                        {
                            SLContext context__ = null;
                            if ((exclude) == 0 /* is-not-excluded evalCached(String, String, String, String, SLContext, DirectCallNode) */) {
                                int count1_ = 0;
                                EvalCachedData s1_ = this.evalCached_cache;
                                if ((state & 0b1) != 0 /* is-active evalCached(String, String, String, String, SLContext, DirectCallNode) */) {
                                    while (s1_ != null) {
                                        if ((SLEvalBuiltin.stringsEqual(s1_.cachedId_, arguments0Value_)) && (SLEvalBuiltin.stringsEqual(s1_.cachedCode_, arguments1Value_))) {
                                            ContextReference sLLanguageContextReference__2 = this.sLLanguageContextReference_;
                                            if (sLLanguageContextReference__2 == null) {
                                                this.sLLanguageContextReference_ = sLLanguageContextReference__2 = super.lookupContextReference(SLLanguage.class);
                                            }
                                            context__ = sLLanguageContextReference__2.get();
                                            break;
                                        }
                                        s1_ = s1_.next_;
                                        count1_++;
                                    }
                                }
                                if (s1_ == null) {
                                    {
                                        String cachedId__ = (arguments0Value_);
                                        if ((SLEvalBuiltin.stringsEqual(cachedId__, arguments0Value_))) {
                                            String cachedCode__ = (arguments1Value_);
                                            if ((SLEvalBuiltin.stringsEqual(cachedCode__, arguments1Value_)) && count1_ < (SLEvalBuiltin.LIMIT)) {
                                                s1_ = super.insert(new EvalCachedData(evalCached_cache));
                                                s1_.cachedId_ = cachedId__;
                                                s1_.cachedCode_ = cachedCode__;
                                                ContextReference sLLanguageContextReference__3 = this.sLLanguageContextReference_;
                                                if (sLLanguageContextReference__3 == null) {
                                                    this.sLLanguageContextReference_ = sLLanguageContextReference__3 = super.lookupContextReference(SLLanguage.class);
                                                }
                                                context__ = sLLanguageContextReference__3.get();
                                                s1_.callNode_ = s1_.insertAccessor((DirectCallNode.create(parse(arguments0Value_, arguments1Value_, context__))));
                                                this.evalCached_cache = s1_;
                                                this.state_ = state = state | 0b1 /* add-active evalCached(String, String, String, String, SLContext, DirectCallNode) */;
                                            }
                                        }
                                    }
                                }
                                if (s1_ != null) {
                                    lock.unlock();
                                    hasLock = false;
                                    return evalCached(arguments0Value_, arguments1Value_, s1_.cachedId_, s1_.cachedCode_, context__, s1_.callNode_);
                                }
                            }
                        }
                        {
                            SLContext evalUncached_context__ = null;
                            ContextReference sLLanguageContextReference__4 = this.sLLanguageContextReference_;
                            if (sLLanguageContextReference__4 == null) {
                                this.sLLanguageContextReference_ = sLLanguageContextReference__4 = super.lookupContextReference(SLLanguage.class);
                            }
                            evalUncached_context__ = sLLanguageContextReference__4.get();
                            this.exclude_ = exclude = exclude | 0b1 /* add-excluded evalCached(String, String, String, String, SLContext, DirectCallNode) */;
                            this.evalCached_cache = null;
                            state = state & 0xfffffffe /* remove-active evalCached(String, String, String, String, SLContext, DirectCallNode) */;
                            this.state_ = state = state | 0b10 /* add-active evalUncached(String, String, SLContext) */;
                            lock.unlock();
                            hasLock = false;
                            return evalUncached(arguments0Value_, arguments1Value_, evalUncached_context__);
                        }
                    }
                }
                throw new UnsupportedSpecializationException(this, new Node[] {this.arguments0_, this.arguments1_}, arguments0Value, arguments1Value);
            } finally {
                if (hasLock) {
                    lock.unlock();
                }
            }
        }

        @Override
        public NodeCost getCost() {
            int state = state_;
            if (state == 0b0) {
                return NodeCost.UNINITIALIZED;
            } else if ((state & (state - 1)) == 0 /* is-single-active  */) {
                EvalCachedData s1_ = this.evalCached_cache;
                if ((s1_ == null || s1_.next_ == null)) {
                    return NodeCost.MONOMORPHIC;
                }
            }
            return NodeCost.POLYMORPHIC;
        }

        @GeneratedBy(SLEvalBuiltin.class)
        private static final class EvalCachedData extends Node {

            @Child EvalCachedData next_;
            @CompilationFinal String cachedId_;
            @CompilationFinal String cachedCode_;
            @Child DirectCallNode callNode_;

            EvalCachedData(EvalCachedData next_) {
                this.next_ = next_;
            }

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

             T insertAccessor(T node) {
                return super.insert(node);
            }

        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy