Search in sources :

Example 16 with Source

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);
        }
    });
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) Source(com.oracle.truffle.api.source.Source)

Example 17 with Source

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));
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 18 with Source

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();
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 19 with Source

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);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 20 with Source

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"));
    }
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Aggregations

Source (com.oracle.truffle.api.source.Source)113 Test (org.junit.Test)65 RootNode (com.oracle.truffle.api.nodes.RootNode)23 File (java.io.File)20 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)16 Node (com.oracle.truffle.api.nodes.Node)16 SourceSection (com.oracle.truffle.api.source.SourceSection)16 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)15 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)11 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CallTarget (com.oracle.truffle.api.CallTarget)5 FileWriter (java.io.FileWriter)5 RootCallTarget (com.oracle.truffle.api.RootCallTarget)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)3 Script (com.oracle.truffle.tools.chromeinspector.types.Script)3