Search in sources :

Example 1 with CatcherObject

use of com.oracle.truffle.api.test.host.HostExceptionTest.CatcherObject in project graal by oracle.

the class MultiClassLoaderTest method before.

@Before
public void before() {
    context = Context.newBuilder().allowAllAccess(true).build();
    ProxyLanguage.setDelegate(new ProxyLanguage() {

        @Override
        protected LanguageContext createContext(Env contextEnv) {
            env = contextEnv;
            return super.createContext(contextEnv);
        }

        @Override
        protected CallTarget parse(ParsingRequest request) throws Exception {
            String req = request.getSource().getCharacters().toString();
            if (req.startsWith("get:")) {
                String name = req.substring(4);
                RootCallTarget reader = new RootNode(ProxyLanguage.get(null)) {

                    @Override
                    public Object execute(VirtualFrame frame) {
                        Object obj = frame.getArguments()[0];
                        try {
                            Object hash = InteropLibrary.getFactory().getUncached(obj).readMember(obj, "hash");
                            return InteropLibrary.getFactory().getUncached(hash).readMember(hash, name);
                        } catch (UnsupportedMessageException | UnknownIdentifierException e) {
                            throw new IllegalStateException(e);
                        }
                    }
                }.getCallTarget();
                return RootNode.createConstantNode(new CatcherObject(reader)).getCallTarget();
            }
            throw new IllegalArgumentException();
        }
    });
    context.initialize(ProxyLanguage.ID);
    context.enter();
    assertNotNull(env);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Env(com.oracle.truffle.api.TruffleLanguage.Env) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) CatcherObject(com.oracle.truffle.api.test.host.HostExceptionTest.CatcherObject) CatcherObject(com.oracle.truffle.api.test.host.HostExceptionTest.CatcherObject) RootCallTarget(com.oracle.truffle.api.RootCallTarget) Before(org.junit.Before)

Aggregations

CallTarget (com.oracle.truffle.api.CallTarget)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 Env (com.oracle.truffle.api.TruffleLanguage.Env)1 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 CatcherObject (com.oracle.truffle.api.test.host.HostExceptionTest.CatcherObject)1 ProxyLanguage (com.oracle.truffle.api.test.polyglot.ProxyLanguage)1 Before (org.junit.Before)1