use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class BuiltinTest method testInvalidArguments.
@Test
public void testInvalidArguments() throws InteropException {
BuiltinTestObject testObject = new BuiltinTestObject();
InteropLibrary builtinLib = createLibrary(InteropLibrary.class, testObject);
try {
builtinLib.invokeMember(testObject, EXISTING);
Assert.fail();
} catch (ArityException e) {
}
try {
builtinLib.invokeMember(testObject, EXISTING, "", "");
Assert.fail();
} catch (ArityException e) {
}
try {
builtinLib.invokeMember(testObject, EXISTING, 42);
Assert.fail();
} catch (UnsupportedTypeException e) {
}
Object function = builtinLib.readMember(testObject, EXISTING);
InteropLibrary functionLib = createLibrary(InteropLibrary.class, function);
try {
Assert.assertEquals("test42", functionLib.execute(function));
Assert.fail();
} catch (ArityException e) {
}
try {
Assert.assertEquals("test42", functionLib.execute(function, "", ""));
Assert.fail();
} catch (ArityException e) {
}
try {
Assert.assertEquals("test42", functionLib.execute(function, 42));
Assert.fail();
} catch (UnsupportedTypeException e) {
}
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class BuiltinTest method testExisting.
@Test
public void testExisting() throws InteropException {
BuiltinTestObject testObject = new BuiltinTestObject();
InteropLibrary builtinLib = createLibrary(InteropLibrary.class, testObject);
Assert.assertTrue("test42", builtinLib.isMemberReadable(testObject, EXISTING));
Assert.assertTrue("test42", builtinLib.isMemberInvocable(testObject, EXISTING));
Object function = builtinLib.readMember(testObject, EXISTING);
InteropLibrary functionLib = createLibrary(InteropLibrary.class, function);
Assert.assertEquals("test", builtinLib.invokeMember(testObject, "testArg0"));
Assert.assertEquals("test42", builtinLib.invokeMember(testObject, EXISTING, "42"));
Assert.assertEquals("test42", builtinLib.invokeMember(testObject, "testArg2", "4", "2"));
Assert.assertEquals("test42", functionLib.execute(function, "42"));
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class BuiltinTest method testNotExisting.
@Test
public void testNotExisting() throws InteropException {
BuiltinTestObject testObject = new BuiltinTestObject();
InteropLibrary builtinLib = createLibrary(InteropLibrary.class, testObject);
Assert.assertFalse("test42", builtinLib.isMemberReadable(testObject, NOT_EXISTING));
Assert.assertFalse("test42", builtinLib.isMemberInvocable(testObject, NOT_EXISTING));
try {
builtinLib.readMember(testObject, NOT_EXISTING);
Assert.fail();
} catch (UnknownIdentifierException e) {
}
try {
builtinLib.invokeMember(testObject, NOT_EXISTING);
Assert.fail();
} catch (UnknownIdentifierException e) {
}
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class BuiltinTest method testGetMembers.
@Test
public void testGetMembers() throws InteropException {
BuiltinTestObject testObject = new BuiltinTestObject();
InteropLibrary builtinLib = createLibrary(InteropLibrary.class, testObject);
Object members = builtinLib.getMembers(testObject);
InteropLibrary membersLib = createLibrary(InteropLibrary.class, members);
Assert.assertTrue(membersLib.hasArrayElements(members));
Assert.assertEquals(4, membersLib.getArraySize(members));
Assert.assertEquals(EXISTING, membersLib.readArrayElement(members, 1));
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class AbstractExecutableTestLanguage method parse.
@Override
@SuppressWarnings("unused")
protected final CallTarget parse(ParsingRequest request) throws Exception {
ExecutableContext executableContext = TestAPIAccessor.engineAccess().getCurrentContext(AbstractExecutableTestLanguage.this.getClass());
Object[] ctxArgs = createArgumentsArray(executableContext);
onParse(request, executableContext.env, ctxArgs);
String rootNodeName = getRootName(request, executableContext.env, ctxArgs);
SourceSection srcSec = request.getSource().createSection(0, request.getSource().getLength());
return new RootNode(this, null) {
@Child
InteropLibrary interopLibrary = interop;
private final SourceSection sourceSection = srcSec;
@CompilationFinal(dimensions = 1)
private final Object[] contextArguments = ctxArgs;
@Override
public Object execute(VirtualFrame frame) {
ExecutableContext execCtx = TestAPIAccessor.engineAccess().getCurrentContext(AbstractExecutableTestLanguage.this.getClass());
try {
Object returnValue = AbstractExecutableTestLanguage.this.execute(this, execCtx.env, contextArguments, frame.getArguments());
if (returnValue == null) {
return NullObject.SINGLETON;
}
return returnValue;
} catch (AbstractTruffleException e) {
throw e;
} catch (Exception e) {
throw throwAssertionError(e);
}
}
@TruffleBoundary
private AssertionError throwAssertionError(Exception e) {
throw new AssertionError(e);
}
@Override
public String getName() {
return rootNodeName;
}
@Override
public SourceSection getSourceSection() {
return srcSec;
}
}.getCallTarget();
}
Aggregations