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

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

There is a newer version: 1.0.0-rc7
Show newest version
package com.oracle.truffle.sl.runtime;

import com.oracle.truffle.api.CallTarget;
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.SLObjectMessageResolution}.
 * You are supposed to use it for the receiver object {@link com.oracle.truffle.sl.runtime.SLObjectType}.
 */
public final class SLObjectMessageResolutionForeign implements StandardFactory, Factory {
    public static final ForeignAccess ACCESS = ForeignAccess.create(new SLObjectMessageResolutionForeign(), null);
    @Deprecated public static ForeignAccess createAccess() { return ForeignAccess.create(new SLObjectMessageResolutionForeign(), null); }

    private SLObjectMessageResolutionForeign() { }

    @Override
    public boolean canHandle(TruffleObject obj) {
        return com.oracle.truffle.sl.runtime.SLObjectType.isInstance(obj);
    }

    @Override
    public CallTarget accessIsNull() {
      return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
    }
    @Override
    public CallTarget accessIsExecutable() {
      return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
    }
    @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(SLForeignHasPropertiesSubNode.createRoot());
    }
    @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 com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignReadSubNode.createRoot());
    }
    @Override
    public CallTarget accessWrite() {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignWriteSubNode.createRoot());
    }
    @Override
    public CallTarget accessRemove() {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignRemoveSubNode.createRoot());
    }
    @Override
    public CallTarget accessExecute(int argumentsLength) {
      return null;
    }
    @Override
    public CallTarget accessInvoke(int argumentsLength) {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignInvokeSubNode.createRoot());
    }
    @Override
    public CallTarget accessNew(int argumentsLength) {
      return null;
    }
    @Override
    public CallTarget accessKeyInfo() {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignPropertyInfoSubNode.createRoot());
    }
    @Override
    public CallTarget accessKeys() {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(SLForeignPropertiesSubNode.createRoot());
    }
    @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.SLObjectMessageResolution.SLForeignWriteNode}.
     */
    public abstract static class SLForeignWriteSubNode extends com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignWriteNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1, Object o2);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.api.object.DynamicObject receiver, java.lang.Object name, java.lang.Object value) {
            return access(receiver, name, value);
        }
        private static final class WriteRootNode extends RootNode {
            protected WriteRootNode() {
                super(null);
            }

            @Child private SLForeignWriteSubNode node = com.oracle.truffle.sl.runtime.SLObjectMessageResolutionForeignFactory.SLForeignWriteSubNodeGen.create();
            @Override
            public Object execute(VirtualFrame frame) {
                Object receiver = ForeignAccess.getReceiver(frame);
                Object identifier = ForeignAccess.getArguments(frame).get(0);
                Object value = ForeignAccess.getArguments(frame).get(1);
                try {
                    return node.executeWithTarget(frame, receiver, identifier, value);
                } catch (UnsupportedSpecializationException e) {
                    if (e.getNode() instanceof SLForeignWriteSubNode) {
                      throw UnsupportedTypeException.raise(e, e.getSuppliedValues());
                    } else {
                      throw e;
                    }
                }
            }

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

    /**
     * This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignInvokeNode}.
     */
    public abstract static class SLForeignInvokeSubNode extends com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignInvokeNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1, Object o2);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.api.object.DynamicObject receiver, java.lang.String name, java.lang.Object[] arguments) {
            return access(receiver, name, arguments);
        }
        private static final class INVOKERootNode extends RootNode {
            protected INVOKERootNode() {
                super(null);
            }

            @Child private SLForeignInvokeSubNode node = com.oracle.truffle.sl.runtime.SLObjectMessageResolutionForeignFactory.SLForeignInvokeSubNodeGen.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 SLForeignInvokeSubNode) {
                      throw UnsupportedTypeException.raise(e, e.getSuppliedValues());
                    } else {
                      throw e;
                    }
                }
            }
        }

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

    /**
     * This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignRemoveNode}.
     */
    public abstract static class SLForeignRemoveSubNode extends com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignRemoveNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.api.object.DynamicObject receiver, java.lang.Object name) {
            return access(receiver, name);
        }
        private static final class REMOVERootNode extends RootNode {
            protected REMOVERootNode() {
                super(null);
            }

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

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

    /**
     * This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignPropertyInfoNode}.
     */
    public abstract static class SLForeignPropertyInfoSubNode extends com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignPropertyInfoNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.api.object.DynamicObject receiver, java.lang.Object name) {
            return access(receiver, name);
        }
        private static final class KEY_INFORootNode extends RootNode {
            protected KEY_INFORootNode() {
                super(null);
            }

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

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

    /**
     * This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignHasPropertiesNode}.
     */
    public abstract static class SLForeignHasPropertiesSubNode extends com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignHasPropertiesNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.api.object.DynamicObject receiver) {
            return access(receiver);
        }
        private static final class HAS_KEYSRootNode extends RootNode {
            protected HAS_KEYSRootNode() {
                super(null);
            }

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

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

    /**
     * This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignReadNode}.
     */
    public abstract static class SLForeignReadSubNode extends com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignReadNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.api.object.DynamicObject receiver, java.lang.Object name) {
            return access(receiver, name);
        }
        private static final class READRootNode extends RootNode {
            protected READRootNode() {
                super(null);
            }

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

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

    /**
     * This message resolution is generated by {@link com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignPropertiesNode}.
     */
    public abstract static class SLForeignPropertiesSubNode extends com.oracle.truffle.sl.runtime.SLObjectMessageResolution.SLForeignPropertiesNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.api.object.DynamicObject receiver) {
            return access(receiver);
        }
        private static final class KeysRootNode extends RootNode {
            protected KeysRootNode() {
                super(null);
            }

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

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