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

com.oracle.truffle.sl.runtime.SLFunctionMessageResolutionForeign Maven / Gradle / Ivy

The newest version!
package com.oracle.truffle.sl.runtime;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.ForeignAccess.Factory;
import com.oracle.truffle.api.interop.ForeignAccess.StandardFactory;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.nodes.RootNode;
import java.util.List;

/**
 * This foreign access factory is generated by {@link com.oracle.truffle.sl.runtime.SLFunctionMessageResolution}.
 * You are supposed to use it for the receiver object {@link com.oracle.truffle.sl.runtime.SLFunction}.
 */
public final class SLFunctionMessageResolutionForeign implements StandardFactory, Factory {
    public static final ForeignAccess ACCESS = ForeignAccess.create(new SLFunctionMessageResolutionForeign(), CheckFunctionSubNode.createRoot());
    @Deprecated public static ForeignAccess createAccess() { return ForeignAccess.create(new SLFunctionMessageResolutionForeign(), CheckFunctionSubNode.createRoot()); }

    private SLFunctionMessageResolutionForeign() { }

    @Override
    @TruffleBoundary
    public boolean canHandle(TruffleObject obj) {
        return (boolean) Truffle.getRuntime().createCallTarget(CheckFunctionSubNode.createRoot()).call(obj);
    }

    @Override
    public CallTarget accessIsNull() {
      return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
    }
    @Override
    public CallTarget accessIsExecutable() {
      return Truffle.getRuntime().createCallTarget(SLForeignIsExecutableSubNode.createRoot());
    }
    @Override
    public CallTarget accessIsInstantiable() {
      return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
    }
    @Override
    public CallTarget accessIsBoxed() {
      return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
    }
    @Override
    public CallTarget accessHasKeys() {
      return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
    }
    @Override
    public CallTarget accessHasSize() {
      return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
    }
    @Override
    public CallTarget accessGetSize() {
      return null;
    }
    @Override
    public CallTarget accessUnbox() {
      return null;
    }
    @Override
    public CallTarget accessRead() {
      return null;
    }
    @Override
    public CallTarget accessWrite() {
      return null;
    }
    @Override
    public CallTarget accessRemove() {
      return null;
    }
    @Override
    public CallTarget accessExecute(int argumentsLength) {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignFunctionExecuteSubNode.createRoot());
    }
    @Override
    public CallTarget accessInvoke(int argumentsLength) {
      return null;
    }
    @Override
    public CallTarget accessNew(int argumentsLength) {
      return null;
    }
    @Override
    public CallTarget accessKeyInfo() {
      return null;
    }
    @Override
    public CallTarget accessKeys() {
      return null;
    }
    @Override
    public CallTarget accessIsPointer() {
      return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
    }
    @Override
    public CallTarget accessAsPointer() {
      return null;
    }
    @Override
    public CallTarget accessToNative() {
      return null;
    }
    @Override
    public CallTarget accessMessage(Message unknown) {
      return null;
    }

    /**
     * This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLFunctionMessageResolution.SLForeignFunctionExecuteNode}.
     */
    public abstract static class SLForeignFunctionExecuteSubNode extends com.oracle.truffle.sl.runtime.SLFunctionMessageResolution.SLForeignFunctionExecuteNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.sl.runtime.SLFunction receiver, java.lang.Object[] arguments) {
            return access(receiver, arguments);
        }
        private static final class EXECUTERootNode extends RootNode {
            protected EXECUTERootNode() {
                super(null);
            }

            @Child private SLForeignFunctionExecuteSubNode node = com.oracle.truffle.sl.runtime.SLFunctionMessageResolutionForeignFactory.SLForeignFunctionExecuteSubNodeGen.create();
            @Override
            public String getName() {
                return "Interop::EXECUTE::" + com.oracle.truffle.sl.runtime.SLFunction.class.getName();
            }

            @Override
            public Object execute(VirtualFrame frame) {
                try {
                  Object receiver = ForeignAccess.getReceiver(frame);
                  List arguments = ForeignAccess.getArguments(frame);
                  Object[] args = new Object[arguments.size()];
                  for (int i = 0; i < arguments.size(); i++) {
                    args[i] = arguments.get(i);
                  }
                  return node.executeWithTarget(frame, receiver, args);
                } catch (UnsupportedSpecializationException e) {
                    if (e.getNode() instanceof SLForeignFunctionExecuteSubNode) {
                      throw UnsupportedTypeException.raise(e, e.getSuppliedValues());
                    } else {
                      throw e;
                    }
                }
            }
        }

        public static RootNode createRoot() {
            return new EXECUTERootNode();
        }
    }

    /**
     * This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLFunctionMessageResolution.SLForeignIsExecutableNode}.
     */
    public abstract static class SLForeignIsExecutableSubNode extends com.oracle.truffle.sl.runtime.SLFunctionMessageResolution.SLForeignIsExecutableNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0);
        @Specialization
        protected Object accessWithTarget(java.lang.Object receiver) {
            return access(receiver);
        }
        private static final class IS_EXECUTABLERootNode extends RootNode {
            protected IS_EXECUTABLERootNode() {
                super(null);
            }

            @Child private SLForeignIsExecutableSubNode node = com.oracle.truffle.sl.runtime.SLFunctionMessageResolutionForeignFactory.SLForeignIsExecutableSubNodeGen.create();
            @Override
            public String getName() {
                return "Interop::IS_EXECUTABLE::" + com.oracle.truffle.sl.runtime.SLFunction.class.getName();
            }

            @Override
            public Object execute(VirtualFrame frame) {
                Object receiver = ForeignAccess.getReceiver(frame);
                try {
                    return node.executeWithTarget(frame, receiver);
                } catch (UnsupportedSpecializationException e) {
                    if (e.getNode() instanceof SLForeignIsExecutableSubNode) {
                      throw UnsupportedTypeException.raise(e, e.getSuppliedValues());
                    } else {
                      throw e;
                    }
                }
            }

        }
        public static RootNode createRoot() {
            return new IS_EXECUTABLERootNode();
        }
    }

    /**
     * This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLFunctionMessageResolution.CheckFunction}.
     * Generated for {@link com.oracle.truffle.sl.runtime.SLFunction}.
     */
    public abstract static class CheckFunctionSubNode extends com.oracle.truffle.sl.runtime.SLFunctionMessageResolution.CheckFunction {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o);
        @Specialization
        protected Object testWithTarget(com.oracle.truffle.api.interop.TruffleObject receiver) {
            return test(receiver);
        }
        private static final class LanguageCheckRootNode extends RootNode {
            protected LanguageCheckRootNode() {
                super(null);
            }

            @Child private CheckFunctionSubNode node = com.oracle.truffle.sl.runtime.SLFunctionMessageResolutionForeignFactory.CheckFunctionSubNodeGen.create();
            @Override
            public Object execute(VirtualFrame frame) {
                try {
                  Object receiver = ForeignAccess.getReceiver(frame);
                  return node.executeWithTarget(frame, receiver);
                } catch (UnsupportedSpecializationException e) {
                    if (e.getNode() instanceof CheckFunctionSubNode) {
                      throw UnsupportedTypeException.raise(e, e.getSuppliedValues());
                    } else {
                      throw e;
                    }
                }
            }

        }
        public static RootNode createRoot() {
            return new LanguageCheckRootNode();
        }
    }
}