Search in sources :

Example 36 with TruffleObject

use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.

the class TestMemberAccess method testArrayOutOfBoundsAccess.

@Test
public void testArrayOutOfBoundsAccess() throws InteropException {
    Object[] array = new Object[1];
    TruffleObject arrayObject = JavaInterop.asTruffleObject(array);
    assertTrue(JavaInteropTest.isArray(arrayObject));
    ForeignAccess.sendRead(readNode, arrayObject, 0);
    try {
        ForeignAccess.sendRead(readNode, arrayObject, 1);
        fail();
    } catch (UnknownIdentifierException e) {
    }
}
Also used : UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 37 with TruffleObject

use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.

the class VarArgsTest method testStringJoin1.

@Test
public void testStringJoin1() throws InteropException {
    TruffleObject strClass = JavaInterop.asTruffleObject(String.class);
    TruffleObject join = (TruffleObject) ForeignAccess.sendRead(Message.READ.createNode(), strClass, "join");
    TruffleObject delimiter = JavaInterop.asTruffleObject(" ");
    TruffleObject elements = JavaInterop.asTruffleObject(new String[] { "Hello", "World" });
    Object result = ForeignAccess.sendExecute(Message.createExecute(2).createNode(), join, new Object[] { delimiter, elements });
    Assert.assertEquals("Hello World", result);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 38 with TruffleObject

use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.

the class VarArgsTest method testCharSequenceEllipsis.

@Test
public void testCharSequenceEllipsis() throws InteropException {
    TruffleObject mainClass = JavaInterop.asTruffleObject(Join.class);
    TruffleObject ellipsis = (TruffleObject) ForeignAccess.sendRead(Message.READ.createNode(), mainClass, "charSequenceEllipsis");
    TruffleObject element1 = JavaInterop.asTruffleObject("Hello");
    TruffleObject element2 = JavaInterop.asTruffleObject("World");
    Object result = ForeignAccess.sendExecute(Message.createExecute(2).createNode(), ellipsis, new Object[] { element1, element2 });
    Assert.assertEquals("Hello World", result);
    TruffleObject elements = JavaInterop.asTruffleObject(new String[] { "Hello", "World" });
    result = ForeignAccess.sendExecute(Message.createExecute(1).createNode(), ellipsis, elements);
    Assert.assertEquals("Hello World", result);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 39 with TruffleObject

use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.

the class VarArgsTest method testStringEllipsis.

@Test
public void testStringEllipsis() throws InteropException {
    TruffleObject mainClass = JavaInterop.asTruffleObject(Join.class);
    TruffleObject ellipsis = (TruffleObject) ForeignAccess.sendRead(Message.READ.createNode(), mainClass, "stringEllipsis");
    TruffleObject element1 = JavaInterop.asTruffleObject("Hello");
    TruffleObject element2 = JavaInterop.asTruffleObject("World");
    Object result = ForeignAccess.sendExecute(Message.createExecute(2).createNode(), ellipsis, new Object[] { element1, element2 });
    Assert.assertEquals("Hello World", result);
    TruffleObject elements = JavaInterop.asTruffleObject(new String[] { "Hello", "World" });
    result = ForeignAccess.sendExecute(Message.createExecute(1).createNode(), ellipsis, elements);
    Assert.assertEquals("Hello World", result);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 40 with TruffleObject

use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.

the class HostEntryRootNode method execute.

@Override
public final Object execute(VirtualFrame frame) {
    Object[] arguments = frame.getArguments();
    Object languageContext = arguments[0];
    T receiver = getReceiverType().cast(arguments[1]);
    Object result;
    result = executeImpl(languageContext, receiver, arguments, 2);
    assert languageContext == null || !(result instanceof TruffleObject);
    return result;
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Aggregations

TruffleObject (com.oracle.truffle.api.interop.TruffleObject)201 Test (org.junit.Test)135 ValueHostInteropTest (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)34 InteropException (com.oracle.truffle.api.interop.InteropException)18 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)17 Specialization (com.oracle.truffle.api.dsl.Specialization)16 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)14 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)12 ArrayTruffleObject (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject)10 Node (com.oracle.truffle.api.nodes.Node)9 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)8 CallTarget (com.oracle.truffle.api.CallTarget)7 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)7 TestCallback (com.oracle.truffle.nfi.test.interop.TestCallback)7 LinkedHashMap (java.util.LinkedHashMap)7 Source (com.oracle.truffle.api.source.Source)6 Method (java.lang.reflect.Method)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5