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;
}
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();
}
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));
}
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());
}
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);
}
Aggregations