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

com.oracle.truffle.tck.AddOneSub 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.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 com.oracle.truffle.tck.CountAndKill.AddOne}
 * It is used by the foreign access factory {@link com.oracle.truffle.tck.CountAndKillForeign}
 */
abstract class AddOneSub extends com.oracle.truffle.tck.CountAndKill.AddOne {
    public abstract Object executeWithTarget(VirtualFrame frame, Object o0, Object o1);
    @Specialization
    protected Object accessWithTarget(com.oracle.truffle.tck.CountAndKill counter, java.lang.Object[] arguments) {
        return access(counter, arguments);
    }
    private static final class EXECUTERootNode extends RootNode {
        protected EXECUTERootNode(Class> language) {
            super(language, null, null);
        }

        @Child private AddOneSub node = com.oracle.truffle.tck.AddOneSubNodeGen.create();
        @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 AddOneSub) {
                  throw UnsupportedTypeException.raise(e, e.getSuppliedValues());
                } else {
                  throw e;
                }
            }
        }

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