use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class LanguageSPITest method testPolyglotBindings.
@Test
public void testPolyglotBindings() {
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) {
return getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
}
});
}
});
Context c = Context.create();
Value languageBindings = c.eval(ProxyLanguage.ID, "");
Value polyglotBindings = c.getPolyglotBindings();
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());
ValueAssert.assertValue(c, polyglotBindings);
ValueAssert.assertValue(c, languageBindings);
c.close();
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class FrameDescriptorTest method localsDefaultValue.
@Test
public void localsDefaultValue() throws Exception {
Object defaultValue = "default";
FrameDescriptor d = new FrameDescriptor(defaultValue);
s1 = d.addFrameSlot("v1");
s2 = d.addFrameSlot("v2");
s3 = d.addFrameSlot("v3");
VirtualFrame f = Truffle.getRuntime().createVirtualFrame(new Object[] { 1, 2 }, d);
assertFrame(f, d);
assertFrame(f.materialize(), d);
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class FrameTest method framesCanBeMaterialized.
@Test
public void framesCanBeMaterialized() {
final TruffleRuntime runtime = Truffle.getRuntime();
class FrameRootNode extends RootNode {
FrameRootNode() {
super(null);
}
@Override
public Object execute(VirtualFrame frame) {
FrameInstance frameInstance = runtime.getCurrentFrame();
Frame readWrite = frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE);
Frame materialized = frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
assertTrue("Really materialized: " + materialized, materialized instanceof MaterializedFrame);
assertEquals("It's my frame", frame, readWrite);
return this;
}
}
FrameRootNode frn = new FrameRootNode();
Object ret = Truffle.getRuntime().createCallTarget(frn).call();
assertEquals("Returns itself", frn, ret);
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class LoopNodeTest method testLoopCountReportingInCallTarget.
@Test
public void testLoopCountReportingInCallTarget() {
final GuestLanguageNode node = new GuestLanguageNode() {
@Override
public Object execute(VirtualFrame frame) {
int[] data = new int[] { 1, 2, 3, 4, 5 };
try {
int sum = 0;
for (int i = 0; i < data.length; i++) {
sum += data[i];
}
return sum;
} finally {
LoopNode.reportLoopCount(this, data.length);
}
}
};
RootNode root = new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
return node.execute(frame);
}
};
CallTarget target = Truffle.getRuntime().createCallTarget(root);
for (int i = 0; i < 1000; i++) {
Assert.assertEquals(15, target.call());
}
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class IsMimeTypeSupportedTestLanguage method parse.
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
final Source code = request.getSource();
final String mimeType = code.getCharacters().toString();
return Truffle.getRuntime().createCallTarget(new RootNode(this) {
@Override
public Object execute(VirtualFrame frame) {
return getContextReference().get().isMimeTypeSupported(mimeType);
}
});
}
Aggregations