@Override public Object execute( TranslatorDriver.ParserContext parserContext, Object self, MaterializedFrame parentFrame, org.jruby.ast.RootNode rootNode) { try { final RubyParserResult parseResult = truffleContext .getTranslator() .parse( truffleContext, truffleContext.getSourceManager().get(rootNode.getPosition().getFile()), parserContext, parentFrame, rootNode); final CallTarget callTarget = Truffle.getRuntime().createCallTarget(parseResult.getRootNode()); return callTarget.call(RubyArguments.pack(parentFrame, self, null)); } catch (ThrowException e) { throw new RaiseException(truffleContext.getCoreLibrary().nameErrorUncaughtThrow(e.getTag())); } catch (RaiseException | BreakShellException | QuitException e) { throw e; } catch (Throwable e) { e.printStackTrace(); throw new RaiseException(ExceptionTranslator.translateException(truffleContext, e)); } }
@Test public void test() { TruffleRuntime runtime = Truffle.getRuntime(); TestRootNode rootNode = new TestRootNode(new TestArgumentNode[] {new TestArgumentNode(0), new TestArgumentNode(1)}); CallTarget target = runtime.createCallTarget(rootNode); Object result = target.call(new TestArguments(20, 22)); Assert.assertEquals(42, result); }