Search in sources :

Example 1 with Source

use of com.oracle.truffle.api.source.Source in project TrufflePascal by Aspect26.

the class PascalLanguage method parse.

/**
     * Gets source from the request, parses it and return call target that, if called, executes
     * given script in Pascal language.
     * @param request parsing request
     * @throws Exception the source cannot be passed
     */
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
    Source source = request.getSource();
    this.currentParser.reset();
    parseSource(source);
    return Truffle.getRuntime().createCallTarget(this.currentParser.getRootNode());
}
Also used : Source(com.oracle.truffle.api.source.Source)

Example 2 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class BreakpointSnippets method example.

@SuppressFBWarnings("")
public void example() {
    SuspendedCallback suspendedCallback = new SuspendedCallback() {

        public void onSuspend(SuspendedEvent event) {
        }
    };
    Source someCode = Source.newBuilder("").mimeType("").name("").build();
    TruffleInstrument.Env instrumentEnvironment = null;
    // BEGIN: BreakpointSnippets.example
    try (DebuggerSession session = Debugger.find(instrumentEnvironment).startSession(suspendedCallback)) {
        // install breakpoint in someCode at line 3.
        session.install(Breakpoint.newBuilder(someCode).lineIs(3).build());
        // install breakpoint for a URI at line 3
        session.install(Breakpoint.newBuilder(someCode.getURI()).lineIs(3).build());
    }
// END: BreakpointSnippets.example
// @formatter:on
}
Also used : TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Source(com.oracle.truffle.api.source.Source)

Example 3 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceBuilderDocumentationTest method stringSample.

@Test
public void stringSample() throws Exception {
    if (!loadedOK) {
        return;
    }
    Source source = (Source) invokeStatic(SOURCE_SNIPPETS, "fromAString");
    assertNotNull("Every source must have URI", source.getURI());
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 4 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceBuilderTest method markSourceAsInternal.

@Test
public void markSourceAsInternal() {
    Source source = Source.newBuilder("anything internal").mimeType("text/plain").name("internalsrc").internal().build();
    assertTrue("This source is internal", source.isInternal());
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 5 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceBuilderTest method fileWithReload.

@Test
public void fileWithReload() throws Exception {
    File file = File.createTempFile("ChangeMe", ".java");
    file.deleteOnExit();
    String text;
    try (FileWriter w = new FileWriter(file)) {
        text = "// Hello";
        w.write(text);
    }
    Source original = Source.newBuilder(file).build();
    assertEquals(text, original.getCharacters());
    String newText;
    try (FileWriter w = new FileWriter(file)) {
        newText = "// Hello World!";
        w.write(newText);
    }
    Source reloaded = Source.newBuilder(file).build();
    assertNotEquals(original, reloaded);
    assertEquals("New source has the new text", newText, reloaded.getCharacters());
    assertEquals("Old source1 remains unchanged", text, original.getCharacters());
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) 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