use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.
the class NodeDefaultsTest method testViewDefaults.
@Test
@SuppressWarnings("hiding")
public void testViewDefaults() {
try (Context context = Context.create()) {
ProxyLanguage language = new ProxyLanguage();
ProxyLanguage.setDelegate(language);
context.initialize(ProxyLanguage.ID);
context.enter();
Frame frame = Truffle.getRuntime().createMaterializedFrame(new Object[] {});
Node n = new TestNode(ProxyLanguage.get(null), frame.getFrameDescriptor());
NodeLibrary l = createLibrary(NodeLibrary.class, n);
Object v = 42 * 42;
// Integer is not associated with a language
assertFails(() -> l.getView(n, frame, v), AssertionError.class);
Object pv = new ProxyLanguageValue();
assertSame(pv, l.getView(n, frame, pv));
}
}
use of com.oracle.truffle.api.test.polyglot.ProxyLanguage 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);
}
use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.
the class CPUSamplerTest method testSampleContextInitialization.
@Test
public void testSampleContextInitialization() {
RootNode dummy = RootNode.createConstantNode(42);
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected void initializeContext(LanguageContext c) throws Exception {
for (int i = 0; i < 50; i++) {
Thread.sleep(1);
TruffleSafepoint.pollHere(dummy);
}
}
});
sampler.setPeriod(1);
sampler.setSampleContextInitialization(true);
sampler.setCollecting(true);
context.initialize(ProxyLanguage.ID);
sampler.setCollecting(false);
Map<TruffleContext, CPUSamplerData> data = sampler.getData();
assertEquals(1, data.size());
assertEquals(0, searchInitializeContext(data).size());
}
use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.
the class CPUSamplerTest method testInitializeContext.
@Test
public void testInitializeContext() {
RootNode dummy = RootNode.createConstantNode(42);
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected void initializeContext(LanguageContext c) throws Exception {
for (int i = 0; i < 50; i++) {
Thread.sleep(1);
TruffleSafepoint.pollHere(dummy);
}
}
});
sampler.setPeriod(1);
sampler.clearData();
sampler.setCollecting(true);
context.initialize(ProxyLanguage.ID);
sampler.setCollecting(false);
Map<TruffleContext, CPUSamplerData> data = sampler.getData();
assertEquals(1, data.size());
assertEquals(0, searchInitializeContext(data).size());
}
use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.
the class IteratorTest method testArrayWithUnreadableElements.
@Test
public void testArrayWithUnreadableElements() {
String[] items = new String[10];
String[] expected = new String[items.length / 2];
for (int i = 0; i < items.length; i++) {
items[i] = Integer.toString(i);
if (i < expected.length) {
expected[i] = items[i];
}
}
setupEnv(createContext(verifyingHandler), new ProxyLanguage() {
@Override
protected CallTarget parse(TruffleLanguage.ParsingRequest request) throws Exception {
return createAST(languageInstance, new Array(items, expected.length, Array.UNLIMITED));
}
});
verifyingHandler.expect(expected);
assertFails(() -> context.eval(ProxyLanguage.ID, "Test"), PolyglotException.class, (pe) -> {
assertEquals(NonReadableElementError.MESSAGE, pe.getMessage());
assertTrue(pe.isGuestException());
assertFalse(pe.isInternalError());
});
}
Aggregations