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

com.oracle.truffle.sl.nodes.util.SLUnboxNodeGen Maven / Gradle / Ivy

There is a newer version: 24.1.1
Show newest version
// CheckStyle: start generated
package com.oracle.truffle.sl.nodes.util;

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.frame.VirtualFrame;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.library.LibraryFactory;
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
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.api.nodes.UnexpectedResultException;
import com.oracle.truffle.sl.nodes.SLExpressionNode;
import com.oracle.truffle.sl.nodes.SLTypes;
import com.oracle.truffle.sl.nodes.SLTypesGen;
import com.oracle.truffle.sl.runtime.SLBigNumber;
import com.oracle.truffle.sl.runtime.SLFunction;
import com.oracle.truffle.sl.runtime.SLNull;
import java.util.concurrent.locks.Lock;

@GeneratedBy(SLUnboxNode.class)
@SuppressWarnings("unused")
public final class SLUnboxNodeGen extends SLUnboxNode {

    private static final LibraryFactory INTEROP_LIBRARY_ = LibraryFactory.resolve(InteropLibrary.class);

    @Child private SLExpressionNode child0_;
    @CompilationFinal private volatile int state_;
    @CompilationFinal private volatile int exclude_;
    @Child private FromForeign0Data fromForeign0_cache;

    private SLUnboxNodeGen(SLExpressionNode child0) {
        this.child0_ = child0;
    }

    @Override
    public Object executeGeneric(VirtualFrame frameValue) {
        int state = state_;
        if ((state & 0b11111101) == 0 /* only-active fromBoolean(boolean) */ && (state & 0b11111111) != 0  /* is-not fromString(String) && fromBoolean(boolean) && fromLong(long) && fromBigNumber(SLBigNumber) && fromFunction(SLFunction) && fromFunction(SLNull) && fromForeign(Object, InteropLibrary) && fromForeign(Object, InteropLibrary) */) {
            return executeGeneric_boolean0(frameValue, state);
        } else if ((state & 0b11111011) == 0 /* only-active fromLong(long) */ && (state & 0b11111111) != 0  /* is-not fromString(String) && fromBoolean(boolean) && fromLong(long) && fromBigNumber(SLBigNumber) && fromFunction(SLFunction) && fromFunction(SLNull) && fromForeign(Object, InteropLibrary) && fromForeign(Object, InteropLibrary) */) {
            return executeGeneric_long1(frameValue, state);
        } else {
            return executeGeneric_generic2(frameValue, state);
        }
    }

    private Object executeGeneric_boolean0(VirtualFrame frameValue, int state) {
        boolean child0Value_;
        try {
            child0Value_ = this.child0_.executeBoolean(frameValue);
        } catch (UnexpectedResultException ex) {
            return executeAndSpecialize(ex.getResult());
        }
        assert (state & 0b10) != 0 /* is-active fromBoolean(boolean) */;
        return SLUnboxNode.fromBoolean(child0Value_);
    }

    private Object executeGeneric_long1(VirtualFrame frameValue, int state) {
        long child0Value_;
        try {
            child0Value_ = this.child0_.executeLong(frameValue);
        } catch (UnexpectedResultException ex) {
            return executeAndSpecialize(ex.getResult());
        }
        assert (state & 0b100) != 0 /* is-active fromLong(long) */;
        return SLUnboxNode.fromLong(child0Value_);
    }

    @SuppressWarnings("static-method")
    @TruffleBoundary
    private Object fromForeign1Boundary(int state, Object child0Value_) {
        EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
        Node prev_ = encapsulating_.set(this);
        try {
            {
                InteropLibrary fromForeign1_interop__ = (INTEROP_LIBRARY_.getUncached(child0Value_));
                return SLUnboxNode.fromForeign(child0Value_, fromForeign1_interop__);
            }
        } finally {
            encapsulating_.set(prev_);
        }
    }

    @ExplodeLoop
    private Object executeGeneric_generic2(VirtualFrame frameValue, int state) {
        Object child0Value_ = this.child0_.executeGeneric(frameValue);
        if ((state & 0b1) != 0 /* is-active fromString(String) */ && child0Value_ instanceof String) {
            String child0Value__ = (String) child0Value_;
            return SLUnboxNode.fromString(child0Value__);
        }
        if ((state & 0b10) != 0 /* is-active fromBoolean(boolean) */ && child0Value_ instanceof Boolean) {
            boolean child0Value__ = (boolean) child0Value_;
            return SLUnboxNode.fromBoolean(child0Value__);
        }
        if ((state & 0b100) != 0 /* is-active fromLong(long) */ && child0Value_ instanceof Long) {
            long child0Value__ = (long) child0Value_;
            return SLUnboxNode.fromLong(child0Value__);
        }
        if ((state & 0b1000) != 0 /* is-active fromBigNumber(SLBigNumber) */ && SLTypesGen.isImplicitSLBigNumber((state & 0b1100000000) >>> 8 /* extract-implicit-active 0:SLBigNumber */, child0Value_)) {
            SLBigNumber child0Value__ = SLTypesGen.asImplicitSLBigNumber((state & 0b1100000000) >>> 8 /* extract-implicit-active 0:SLBigNumber */, child0Value_);
            return SLUnboxNode.fromBigNumber(child0Value__);
        }
        if ((state & 0b10000) != 0 /* is-active fromFunction(SLFunction) */ && child0Value_ instanceof SLFunction) {
            SLFunction child0Value__ = (SLFunction) child0Value_;
            return SLUnboxNode.fromFunction(child0Value__);
        }
        if ((state & 0b100000) != 0 /* is-active fromFunction(SLNull) */ && SLTypes.isSLNull(child0Value_)) {
            SLNull child0Value__ = SLTypes.asSLNull(child0Value_);
            return SLUnboxNode.fromFunction(child0Value__);
        }
        if ((state & 0b11000000) != 0 /* is-active fromForeign(Object, InteropLibrary) || fromForeign(Object, InteropLibrary) */) {
            if ((state & 0b1000000) != 0 /* is-active fromForeign(Object, InteropLibrary) */) {
                FromForeign0Data s7_ = this.fromForeign0_cache;
                while (s7_ != null) {
                    if ((s7_.interop_.accepts(child0Value_))) {
                        return SLUnboxNode.fromForeign(child0Value_, s7_.interop_);
                    }
                    s7_ = s7_.next_;
                }
            }
            if ((state & 0b10000000) != 0 /* is-active fromForeign(Object, InteropLibrary) */) {
                return this.fromForeign1Boundary(state, child0Value_);
            }
        }
        CompilerDirectives.transferToInterpreterAndInvalidate();
        return executeAndSpecialize(child0Value_);
    }

    @Override
    public boolean executeBoolean(VirtualFrame frameValue) throws UnexpectedResultException {
        int state = state_;
        if ((state & 0b11000000) != 0 /* is-active fromForeign(Object, InteropLibrary) || fromForeign(Object, InteropLibrary) */) {
            return SLTypesGen.expectBoolean(executeGeneric(frameValue));
        }
        boolean child0Value_;
        try {
            child0Value_ = this.child0_.executeBoolean(frameValue);
        } catch (UnexpectedResultException ex) {
            return SLTypesGen.expectBoolean(executeAndSpecialize(ex.getResult()));
        }
        if ((state & 0b10) != 0 /* is-active fromBoolean(boolean) */) {
            return SLUnboxNode.fromBoolean(child0Value_);
        }
        CompilerDirectives.transferToInterpreterAndInvalidate();
        return SLTypesGen.expectBoolean(executeAndSpecialize(child0Value_));
    }

    @Override
    public long executeLong(VirtualFrame frameValue) throws UnexpectedResultException {
        int state = state_;
        if ((state & 0b11000000) != 0 /* is-active fromForeign(Object, InteropLibrary) || fromForeign(Object, InteropLibrary) */) {
            return SLTypesGen.expectLong(executeGeneric(frameValue));
        }
        long child0Value_;
        try {
            child0Value_ = this.child0_.executeLong(frameValue);
        } catch (UnexpectedResultException ex) {
            return SLTypesGen.expectLong(executeAndSpecialize(ex.getResult()));
        }
        if ((state & 0b100) != 0 /* is-active fromLong(long) */) {
            return SLUnboxNode.fromLong(child0Value_);
        }
        CompilerDirectives.transferToInterpreterAndInvalidate();
        return SLTypesGen.expectLong(executeAndSpecialize(child0Value_));
    }

    @Override
    public void executeVoid(VirtualFrame frameValue) {
        int state = state_;
        try {
            if ((state & 0b11111011) == 0 /* only-active fromLong(long) */ && (state & 0b11111111) != 0  /* is-not fromString(String) && fromBoolean(boolean) && fromLong(long) && fromBigNumber(SLBigNumber) && fromFunction(SLFunction) && fromFunction(SLNull) && fromForeign(Object, InteropLibrary) && fromForeign(Object, InteropLibrary) */) {
                executeLong(frameValue);
                return;
            } else if ((state & 0b11111101) == 0 /* only-active fromBoolean(boolean) */ && (state & 0b11111111) != 0  /* is-not fromString(String) && fromBoolean(boolean) && fromLong(long) && fromBigNumber(SLBigNumber) && fromFunction(SLFunction) && fromFunction(SLNull) && fromForeign(Object, InteropLibrary) && fromForeign(Object, InteropLibrary) */) {
                executeBoolean(frameValue);
                return;
            }
            executeGeneric(frameValue);
            return;
        } catch (UnexpectedResultException ex) {
            return;
        }
    }

    private Object executeAndSpecialize(Object child0Value) {
        Lock lock = getLock();
        boolean hasLock = true;
        lock.lock();
        int state = state_;
        int exclude = exclude_;
        try {
            if (child0Value instanceof String) {
                String child0Value_ = (String) child0Value;
                this.state_ = state = state | 0b1 /* add-active fromString(String) */;
                lock.unlock();
                hasLock = false;
                return SLUnboxNode.fromString(child0Value_);
            }
            if (child0Value instanceof Boolean) {
                boolean child0Value_ = (boolean) child0Value;
                this.state_ = state = state | 0b10 /* add-active fromBoolean(boolean) */;
                lock.unlock();
                hasLock = false;
                return SLUnboxNode.fromBoolean(child0Value_);
            }
            if (child0Value instanceof Long) {
                long child0Value_ = (long) child0Value;
                this.state_ = state = state | 0b100 /* add-active fromLong(long) */;
                lock.unlock();
                hasLock = false;
                return SLUnboxNode.fromLong(child0Value_);
            }
            {
                int sLBigNumberCast0;
                if ((sLBigNumberCast0 = SLTypesGen.specializeImplicitSLBigNumber(child0Value)) != 0) {
                    SLBigNumber child0Value_ = SLTypesGen.asImplicitSLBigNumber(sLBigNumberCast0, child0Value);
                    state = (state | (sLBigNumberCast0 << 8) /* set-implicit-active 0:SLBigNumber */);
                    this.state_ = state = state | 0b1000 /* add-active fromBigNumber(SLBigNumber) */;
                    lock.unlock();
                    hasLock = false;
                    return SLUnboxNode.fromBigNumber(child0Value_);
                }
            }
            if (child0Value instanceof SLFunction) {
                SLFunction child0Value_ = (SLFunction) child0Value;
                this.state_ = state = state | 0b10000 /* add-active fromFunction(SLFunction) */;
                lock.unlock();
                hasLock = false;
                return SLUnboxNode.fromFunction(child0Value_);
            }
            if (SLTypes.isSLNull(child0Value)) {
                SLNull child0Value_ = SLTypes.asSLNull(child0Value);
                this.state_ = state = state | 0b100000 /* add-active fromFunction(SLNull) */;
                lock.unlock();
                hasLock = false;
                return SLUnboxNode.fromFunction(child0Value_);
            }
            if ((exclude) == 0 /* is-not-excluded fromForeign(Object, InteropLibrary) */) {
                int count7_ = 0;
                FromForeign0Data s7_ = this.fromForeign0_cache;
                if ((state & 0b1000000) != 0 /* is-active fromForeign(Object, InteropLibrary) */) {
                    while (s7_ != null) {
                        if ((s7_.interop_.accepts(child0Value))) {
                            break;
                        }
                        s7_ = s7_.next_;
                        count7_++;
                    }
                }
                if (s7_ == null) {
                    // assert (s7_.interop_.accepts(child0Value));
                    if (count7_ < (SLUnboxNode.LIMIT)) {
                        s7_ = super.insert(new FromForeign0Data(fromForeign0_cache));
                        s7_.interop_ = s7_.insertAccessor((INTEROP_LIBRARY_.create(child0Value)));
                        this.fromForeign0_cache = s7_;
                        this.state_ = state = state | 0b1000000 /* add-active fromForeign(Object, InteropLibrary) */;
                    }
                }
                if (s7_ != null) {
                    lock.unlock();
                    hasLock = false;
                    return SLUnboxNode.fromForeign(child0Value, s7_.interop_);
                }
            }
            {
                InteropLibrary fromForeign1_interop__ = null;
                {
                    EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
                    Node prev_ = encapsulating_.set(this);
                    try {
                        fromForeign1_interop__ = (INTEROP_LIBRARY_.getUncached(child0Value));
                        this.exclude_ = exclude = exclude | 0b1 /* add-excluded fromForeign(Object, InteropLibrary) */;
                        this.fromForeign0_cache = null;
                        state = state & 0xffffffbf /* remove-active fromForeign(Object, InteropLibrary) */;
                        this.state_ = state = state | 0b10000000 /* add-active fromForeign(Object, InteropLibrary) */;
                        lock.unlock();
                        hasLock = false;
                        return SLUnboxNode.fromForeign(child0Value, fromForeign1_interop__);
                    } finally {
                        encapsulating_.set(prev_);
                    }
                }
            }
        } finally {
            if (hasLock) {
                lock.unlock();
            }
        }
    }

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

    public static SLUnboxNode create(SLExpressionNode child0) {
        return new SLUnboxNodeGen(child0);
    }

    @GeneratedBy(SLUnboxNode.class)
    private static final class FromForeign0Data extends Node {

        @Child FromForeign0Data next_;
        @Child InteropLibrary interop_;

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

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

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

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy