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

org.jruby.truffle.interop.ForeignInvokeNodeSub Maven / Gradle / Ivy

The newest version!
package org.jruby.truffle.interop;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import java.util.List;

/**
 * This message resolution is generated by {@link org.jruby.truffle.interop.RubyMessageResolution.ForeignInvokeNode}
 * It is used by the foreign access factory {@link org.jruby.truffle.interop.RubyMessageResolutionForeign}
 */
public abstract class ForeignInvokeNodeSub extends org.jruby.truffle.interop.RubyMessageResolution.ForeignInvokeNode {
    public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1, Object o2);
    @Specialization
    protected Object accessWithTarget(com.oracle.truffle.api.frame.VirtualFrame frame, com.oracle.truffle.api.object.DynamicObject receiver, java.lang.String name, java.lang.Object[] arguments) {
        return access(frame, receiver, name, arguments);
    }
    private static final class INVOKERootNode extends RootNode {
        protected INVOKERootNode(Class> language) {
            super(language, null, null);
        }

        @Child private ForeignInvokeNodeSub node = org.jruby.truffle.interop.ForeignInvokeNodeSubNodeGen.create();
        @Override
        public Object execute(VirtualFrame frame) {
            try {
              Object receiver = ForeignAccess.getReceiver(frame);
              List arguments = ForeignAccess.getArguments(frame);
              Object identifier = arguments.get(0);
              Object[] args = new Object[arguments.size() - 1];
              for (int i = 0; i < arguments.size() - 1; i++) {
                args[i] = arguments.get(i + 1);
              }
              return node.executeWithTarget(frame, receiver, identifier, args);
            } catch (UnsupportedSpecializationException e) {
                if (e.getNode() instanceof ForeignInvokeNodeSub) {
                  throw UnsupportedTypeException.raise(e, e.getSuppliedValues());
                } else {
                  throw e;
                }
            }
        }

    }
    public static RootNode createRoot(Class> language) {
        return new INVOKERootNode(language);
    }
}