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

com.oracle.truffle.tck.ComplexNumberMessageResolutionForeign Maven / Gradle / Ivy

Go to download

A collection of tests that can certify language implementation to be compliant with most recent requirements of the Truffle infrastructure and tooling.

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

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

    private ComplexNumberMessageResolutionForeign() { }

    @Override
    public boolean canHandle(TruffleObject obj) {
        return com.oracle.truffle.tck.ComplexNumber.isInstance(obj);
    }

    @Override
    public CallTarget accessIsNull() {
      return Truffle.getRuntime().createCallTarget(ComplexIsNullSubNode.createRoot());
    }
    @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(RootNode.createConstantNode(false));
    }
    @Override
    public CallTarget accessHasSize() {
      return Truffle.getRuntime().createCallTarget(ComplexHasSizeSubNode.createRoot());
    }
    @Override
    public CallTarget accessGetSize() {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(ComplexGetSizeSubNode.createRoot());
    }
    @Override
    public CallTarget accessUnbox() {
      return null;
    }
    @Override
    public CallTarget accessRead() {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(ComplexReadSubNode.createRoot());
    }
    @Override
    public CallTarget accessWrite() {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(ComplexWriteSubNode.createRoot());
    }
    @Override
    public CallTarget accessRemove() {
      return null;
    }
    @Override
    public CallTarget accessExecute(int argumentsLength) {
      return null;
    }
    @Override
    public CallTarget accessInvoke(int argumentsLength) {
      return com.oracle.truffle.api.Truffle.getRuntime().createCallTarget(ComplexInvokeSubNode.createRoot());
    }
    @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.tck.ComplexNumberMessageResolution.ComplexWriteNode}.
     */
    abstract static class ComplexWriteSubNode extends com.oracle.truffle.tck.ComplexNumberMessageResolution.ComplexWriteNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1, Object o2);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.tck.ComplexNumber complex, java.lang.String identifier, java.lang.Number value) {
            return access(complex, identifier, value);
        }
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.tck.ComplexNumber complex, int index, java.lang.Number value) {
            return access(complex, index, value);
        }
        private static final class WRITERootNode extends RootNode {
            protected WRITERootNode() {
                super(null);
            }

            @Child private ComplexWriteSubNode node = com.oracle.truffle.tck.ComplexNumberMessageResolutionForeignFactory.ComplexWriteSubNodeGen.create();
            @Override
            public String getName() {
                return "Interop::WRITE::com.oracle.truffle.tck.ComplexNumber";
            }

            @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 ComplexWriteSubNode) {
                      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.tck.ComplexNumberMessageResolution.ComplexInvokeNode}.
     */
    abstract static class ComplexInvokeSubNode extends com.oracle.truffle.tck.ComplexNumberMessageResolution.ComplexInvokeNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1, Object o2);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.tck.ComplexNumber complex, java.lang.String identifier, java.lang.Object[] arguments) {
            return access(complex, identifier, arguments);
        }
        private static final class INVOKERootNode extends RootNode {
            protected INVOKERootNode() {
                super(null);
            }

            @Child private ComplexInvokeSubNode node = com.oracle.truffle.tck.ComplexNumberMessageResolutionForeignFactory.ComplexInvokeSubNodeGen.create();
            @Override
            public String getName() {
                return "Interop::INVOKE::com.oracle.truffle.tck.ComplexNumber";
            }

            @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 ComplexInvokeSubNode) {
                      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.tck.ComplexNumberMessageResolution.ComplexReadNode}.
     */
    abstract static class ComplexReadSubNode extends com.oracle.truffle.tck.ComplexNumberMessageResolution.ComplexReadNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.tck.ComplexNumber complex, java.lang.String identifier) {
            return access(complex, identifier);
        }
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.tck.ComplexNumber complex, int index) {
            return access(complex, index);
        }
        private static final class READRootNode extends RootNode {
            protected READRootNode() {
                super(null);
            }

            @Child private ComplexReadSubNode node = com.oracle.truffle.tck.ComplexNumberMessageResolutionForeignFactory.ComplexReadSubNodeGen.create();
            @Override
            public String getName() {
                return "Interop::READ::com.oracle.truffle.tck.ComplexNumber";
            }

            @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 ComplexReadSubNode) {
                      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.tck.ComplexNumberMessageResolution.ComplexIsNullNode}.
     */
    abstract static class ComplexIsNullSubNode extends com.oracle.truffle.tck.ComplexNumberMessageResolution.ComplexIsNullNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.tck.ComplexNumber complex) {
            return access(complex);
        }
        private static final class IS_NULLRootNode extends RootNode {
            protected IS_NULLRootNode() {
                super(null);
            }

            @Child private ComplexIsNullSubNode node = com.oracle.truffle.tck.ComplexNumberMessageResolutionForeignFactory.ComplexIsNullSubNodeGen.create();
            @Override
            public String getName() {
                return "Interop::IS_NULL::com.oracle.truffle.tck.ComplexNumber";
            }

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

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

    /**
     * This message resolution is generated by {@link com.oracle.truffle.tck.ComplexNumberMessageResolution.ComplexGetSizeNode}.
     */
    abstract static class ComplexGetSizeSubNode extends com.oracle.truffle.tck.ComplexNumberMessageResolution.ComplexGetSizeNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.tck.ComplexNumber complex) {
            return access(complex);
        }
        private static final class GET_SIZERootNode extends RootNode {
            protected GET_SIZERootNode() {
                super(null);
            }

            @Child private ComplexGetSizeSubNode node = com.oracle.truffle.tck.ComplexNumberMessageResolutionForeignFactory.ComplexGetSizeSubNodeGen.create();
            @Override
            public String getName() {
                return "Interop::GET_SIZE::com.oracle.truffle.tck.ComplexNumber";
            }

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

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

    /**
     * This message resolution is generated by {@link com.oracle.truffle.tck.ComplexNumberMessageResolution.ComplexHasSizeNode}.
     */
    abstract static class ComplexHasSizeSubNode extends com.oracle.truffle.tck.ComplexNumberMessageResolution.ComplexHasSizeNode {
        public abstract Object executeWithTarget(VirtualFrame frame, Object o0);
        @Specialization
        protected Object accessWithTarget(com.oracle.truffle.tck.ComplexNumber complex) {
            return access(complex);
        }
        private static final class HAS_SIZERootNode extends RootNode {
            protected HAS_SIZERootNode() {
                super(null);
            }

            @Child private ComplexHasSizeSubNode node = com.oracle.truffle.tck.ComplexNumberMessageResolutionForeignFactory.ComplexHasSizeSubNodeGen.create();
            @Override
            public String getName() {
                return "Interop::HAS_SIZE::com.oracle.truffle.tck.ComplexNumber";
            }

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

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