use of com.oracle.truffle.api.source.Source 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);
}
});
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class ToStringTest method toStringForUnboxValue.
@Test
public void toStringForUnboxValue() throws Exception {
engine = PolyglotEngine.newBuilder().build();
final Source src42 = Source.newBuilder("42").mimeType("application/x-unbox").name("fortyTwo.ux").build();
PolyglotEngine.Value fourtyTwo = engine.eval(src42).execute();
assertEquals("Should always work", Integer.valueOf(42), fourtyTwo.as(Integer.class));
assertEquals("Current behavior", Integer.valueOf(42), fourtyTwo.get());
assertEquals("MyLang.toString is called", "Unboxed: 42", fourtyTwo.as(String.class));
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class ContextLookupTest method twoContextsLookup.
@Test
public void twoContextsLookup() throws Exception {
LanguageLookupContext context = new LanguageLookupContext(null);
PolyglotEngine vm = createBuilder().config(LanguageLookup.MIME_TYPE, "channel", context).build();
Source s1 = Source.newBuilder("").name("").mimeType("").build();
PolyglotEngine.Value result = vm.getLanguages().get(LanguageLookup.MIME_TYPE).eval(s1);
result.get();
LanguageLookup language = context.language;
Runnable run = result.as(Runnable.class);
language.expectedContext = context;
run.run();
LanguageLookupContext context2 = new LanguageLookupContext(null);
PolyglotEngine otherVM = createBuilder().config(LanguageLookup.MIME_TYPE, "channel", context2).build();
otherVM.getLanguages().get(LanguageLookup.MIME_TYPE).eval(s1);
language.expectedContext = context;
run.run();
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class EngineTest method checkCachingOfNodes.
@Test
public void checkCachingOfNodes() {
PolyglotEngine vm1 = createBuilder().build();
register(vm1);
PolyglotEngine vm2 = createBuilder().executor(Executors.newSingleThreadExecutor()).build();
register(vm2);
PolyglotEngine.Language language1 = vm1.getLanguages().get("application/x-test-hash");
PolyglotEngine.Language language2 = vm2.getLanguages().get("application/x-test-hash");
PolyglotEngine.Language alt1 = vm1.getLanguages().get("application/x-test-hash-alt");
PolyglotEngine.Language alt2 = vm2.getLanguages().get("application/x-test-hash-alt");
final Source sharedSource = Source.newBuilder("anything").name("something").mimeType("content/unknown").build();
Object hashIn1Round1 = language1.eval(sharedSource).get();
Object hashIn2Round1 = language2.eval(sharedSource).get();
Object hashIn1Round2 = language1.eval(sharedSource).get();
Object hashIn2Round2 = language2.eval(sharedSource).get();
Object altIn1Round1 = alt1.eval(sharedSource).get();
Object altIn2Round1 = alt2.eval(sharedSource).get();
Object altIn1Round2 = alt1.eval(sharedSource).get();
Object altIn2Round2 = alt2.eval(sharedSource).get();
assertEquals("Two executions in 1st engine share the nodes", hashIn1Round1, hashIn1Round2);
assertEquals("Two executions in 2nd engine share the nodes", hashIn2Round1, hashIn2Round2);
assertEquals("Two alternative executions in 1st engine share the nodes", altIn1Round1, altIn1Round2);
assertEquals("Two alternative executions in 2nd engine share the nodes", altIn2Round1, altIn2Round2);
assertNotEquals("Two executions in different languages don't share the nodes", hashIn1Round1, altIn1Round1);
assertNotEquals("Two executions in different languages don't share the nodes", hashIn1Round1, altIn2Round1);
assertNotEquals("Two executions in different languages don't share the nodes", hashIn2Round2, altIn1Round2);
assertNotEquals("Two executions in different languages don't share the nodes", hashIn2Round2, altIn2Round2);
assertNotEquals("Two executions in different engines don't share the nodes", hashIn1Round1, hashIn2Round1);
assertNotEquals("Two executions in different engines don't share the nodes", hashIn2Round2, hashIn1Round2);
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class ExceptionDuringParsingTest method canGetAccessToOwnLanguageInstance.
@Test
public void canGetAccessToOwnLanguageInstance() throws Exception {
PolyglotEngine vm = PolyglotEngine.newBuilder().build();
PolyglotEngine.Language language = vm.getLanguages().get(L1);
assertNotNull("L1 language is defined", language);
final Source src = Source.newBuilder("parse=No, no, no!").name("Fail on parsing").mimeType(L1).build();
try {
vm.eval(src);
fail("Exception thrown");
} catch (RuntimeException ex) {
assertEquals(ex.getCause().getMessage(), "No, no, no!");
}
assertEquals("No dispose yet", 0, Ctx.disposed.size());
vm.dispose();
assertEquals("One context disposed", 1, Ctx.disposed.size());
try {
vm.eval(src);
fail("Should throw an exception");
} catch (IllegalStateException ex) {
assertTrue(ex.getMessage(), ex.getMessage().contains("disposed"));
}
try {
vm.findGlobalSymbol("nothing");
fail("Should throw an exception");
} catch (IllegalStateException ex) {
assertTrue(ex.getMessage(), ex.getMessage().contains("disposed"));
}
try {
vm.dispose();
fail("Should throw an exception");
} catch (IllegalStateException ex) {
assertTrue(ex.getMessage(), ex.getMessage().contains("disposed"));
}
}
Aggregations