use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class ImplicitCastTest method testImplicitCastExecute2.
@Test
public void testImplicitCastExecute2() {
ExampleArgumentNode[] args = ExampleNode.createArguments(2);
CallTarget target = ExampleNode.createTarget(ImplicitCastExecuteNodeGen.create(args));
Assert.assertEquals("s2", target.call(1L, 1L));
Assert.assertEquals(0, args[0].longInvocationCount);
Assert.assertEquals(0, args[1].longInvocationCount);
Assert.assertEquals(1, args[0].genericInvocationCount);
Assert.assertEquals(1, args[1].genericInvocationCount);
Assert.assertEquals("s2", target.call(1L, 1L));
Assert.assertEquals(1, args[0].longInvocationCount);
Assert.assertEquals(1, args[1].longInvocationCount);
Assert.assertEquals(2, args[0].genericInvocationCount);
Assert.assertEquals(2, args[1].genericInvocationCount);
Assert.assertEquals("s2", target.call(1L, 1L));
Assert.assertEquals(2, args[0].longInvocationCount);
Assert.assertEquals(2, args[1].longInvocationCount);
Assert.assertEquals(3, args[0].genericInvocationCount);
Assert.assertEquals(3, args[1].genericInvocationCount);
Assert.assertEquals(0, args[0].doubleInvocationCount);
Assert.assertEquals(0, args[1].doubleInvocationCount);
Assert.assertEquals(0, args[0].intInvocationCount);
Assert.assertEquals(0, args[1].intInvocationCount);
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class LanguageSPITest method testErrorInParse.
@Test
public void testErrorInParse() {
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected CallTarget parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest request) throws Exception {
throw new RuntimeException();
}
});
Context c = Context.create();
c.initialize(ProxyLanguage.ID);
testFails(() -> c.eval(ProxyLanguage.ID, "t0"));
testFails(() -> c.eval(ProxyLanguage.ID, "t1"));
c.close();
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class LanguageSPITest method testPolyglotBindingsMultiThreaded.
@Test
public void testPolyglotBindingsMultiThreaded() throws InterruptedException, ExecutionException, TimeoutException {
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
return true;
}
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
return Truffle.getRuntime().createCallTarget(new RootNode(languageInstance) {
@Override
public Object execute(VirtualFrame frame) {
return getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
}
});
}
});
Context c = Context.create();
ExecutorService service = Executors.newFixedThreadPool(20);
Value languageBindings = c.eval(ProxyLanguage.ID, "");
Value polyglotBindings = c.getPolyglotBindings();
List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < 2000; i++) {
futures.add(service.submit(() -> {
polyglotBindings.putMember("foo", "bar");
assertEquals("bar", polyglotBindings.getMember("foo").asString());
assertEquals("bar", languageBindings.getMember("foo").asString());
languageBindings.putMember("baz", "42");
assertEquals("42", polyglotBindings.getMember("baz").asString());
assertEquals("42", languageBindings.getMember("baz").asString());
}));
}
for (Future<?> future : futures) {
future.get(100000, TimeUnit.MILLISECONDS);
}
service.shutdown();
service.awaitTermination(100000, TimeUnit.MILLISECONDS);
c.close();
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class LanguageSPITest method testPolyglotBindingsPreserveLanguage.
@Test
public void testPolyglotBindingsPreserveLanguage() {
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
return Truffle.getRuntime().createCallTarget(new RootNode(languageInstance) {
@Override
public Object execute(VirtualFrame frame) {
Object bindings = getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
try {
ForeignAccess.sendWrite(Message.WRITE.createNode(), (TruffleObject) bindings, "exportedValue", "convertOnToString");
} catch (UnknownIdentifierException | UnsupportedTypeException | UnsupportedMessageException e) {
throw new AssertionError(e);
}
return bindings;
}
});
}
@Override
protected String toString(LanguageContext context, Object value) {
if (value.equals("convertOnToString")) {
return "myStringToString";
}
return super.toString(context, value);
}
});
Context c = Context.create();
c.eval(ProxyLanguage.ID, "");
assertEquals("Make sure language specific toString was invoked.", "myStringToString", c.getPolyglotBindings().getMember("exportedValue").toString());
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class LanguageSPITest method testErrorInFindMetaObject.
@Test
public void testErrorInFindMetaObject() {
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected Object findMetaObject(LanguageContext context, Object value) {
throw new RuntimeException();
}
@Override
protected CallTarget parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest request) throws Exception {
return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(42));
}
});
Context c = Context.create();
Value v = c.eval(ProxyLanguage.ID, "");
testFails(() -> v.getMetaObject());
testFails(() -> v.getMetaObject());
c.close();
}
Aggregations