Search in sources :

Example 56 with Source

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

the class DIScopeBuilder method extend.

private static SourceSection extend(SourceSection base) {
    if (base == null) {
        return null;
    }
    SourceSection section;
    try {
        final Source source = base.getSource();
        final int length = source.getLength() - base.getCharIndex();
        section = source.createSection(base.getCharIndex(), length);
    } catch (Throwable ignored) {
        section = base;
    }
    return section;
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) Source(com.oracle.truffle.api.source.Source)

Example 57 with Source

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

the class NFITest method loadLibrary.

private static TruffleObject loadLibrary(String lib) {
    String testBackend = System.getProperty("native.test.backend");
    String sourceString;
    if (testBackend != null) {
        sourceString = String.format("with %s %s", testBackend, lib);
    } else {
        sourceString = lib;
    }
    Source source = Source.newBuilder(sourceString).name("loadLibrary").mimeType("application/x-native").build();
    CallTarget target = runWithPolyglot.getTruffleTestEnv().parse(source);
    return (TruffleObject) target.call();
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Source(com.oracle.truffle.api.source.Source) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 58 with Source

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

the class NFILanguage method parse.

@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
    CharSequence nfiSource = request.getSource().getCharacters();
    NativeSource source = Parser.parseNFISource(nfiSource);
    String backendId;
    if (source.isDefaultBackend()) {
        backendId = "native";
    } else {
        backendId = source.getNFIBackendId();
    }
    Source backendSource = Source.newBuilder(source.getLibraryDescriptor()).mimeType("trufflenfi/" + backendId).name("<nfi-impl>").build();
    CallTarget backendTarget = getContextReference().get().env.parse(backendSource);
    DirectCallNode loadLibrary = DirectCallNode.create(backendTarget);
    return Truffle.getRuntime().createCallTarget(new NFIRootNode(this, loadLibrary, source));
}
Also used : NativeSource(com.oracle.truffle.nfi.types.NativeSource) CallTarget(com.oracle.truffle.api.CallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Source(com.oracle.truffle.api.source.Source) NativeSource(com.oracle.truffle.nfi.types.NativeSource)

Example 59 with Source

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

the class TruffleTCK method multiplyTwoVariables.

/**
 * @since 0.8 or earlier
 */
@Test
public void multiplyTwoVariables() throws Exception {
    final String firstVar = "var" + (char) ('A' + RANDOM.nextInt(24));
    final String secondVar = "var" + (char) ('0' + RANDOM.nextInt(10));
    String mulCode = multiplyCode(firstVar, secondVar);
    // @formatter:off
    Source source = Source.newBuilder("TCK42:" + mimeType() + ":" + mulCode).name("evaluate " + firstVar + " * " + secondVar).mimeType("application/x-tck").build();
    // @formatter:on
    final PolyglotEngine.Value evalSource = vm().eval(source);
    final PolyglotEngine.Value invokeMul = evalSource.execute(firstVar, secondVar);
    Object result = invokeMul.get();
    assertTrue("Expecting numeric result, was:" + result + " for " + firstVar + " and " + secondVar, result instanceof Number);
    assertEquals("Right value for " + firstVar + " and " + secondVar, 42, ((Number) result).intValue());
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TestObject(com.oracle.truffle.tck.impl.TestObject) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 60 with Source

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

the class TruffleTCK method testInvalidTestMethod.

/**
 * @since 0.8 or earlier
 */
@Test(expected = Exception.class)
public void testInvalidTestMethod() throws Exception {
    String mime = mimeType();
    String code = invalidCode();
    // @formatter:off
    Source invalidCode = Source.newBuilder(code).name("Invalid code").mimeType(mime).build();
    // @formatter:on
    Object ret = vm().eval(invalidCode).get();
    fail("Should yield IOException, but returned " + ret);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TestObject(com.oracle.truffle.tck.impl.TestObject) 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