Search in sources :

Example 6 with TruffleObject

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

the class LanguageSPIHostInteropTest method testSystemMethod.

@Test
public void testSystemMethod() throws InteropException {
    TruffleObject system = (TruffleObject) env.lookupHostSymbol(System.class.getName());
    Object value = ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), system, "getProperty", "file.separator");
    assertThat(value, CoreMatchers.instanceOf(String.class));
    assertThat(value, CoreMatchers.anyOf(CoreMatchers.equalTo("/"), CoreMatchers.equalTo("\\")));
    Object getProperty = ForeignAccess.sendRead(Message.READ.createNode(), system, "getProperty");
    assertThat(getProperty, CoreMatchers.instanceOf(TruffleObject.class));
    assertTrue("IS_EXECUTABLE", ForeignAccess.sendIsExecutable(Message.IS_EXECUTABLE.createNode(), (TruffleObject) getProperty));
    value = ForeignAccess.sendExecute(Message.createExecute(1).createNode(), (TruffleObject) getProperty, "file.separator");
    assertThat(value, CoreMatchers.instanceOf(String.class));
    assertThat(value, CoreMatchers.anyOf(CoreMatchers.equalTo("/"), CoreMatchers.equalTo("\\")));
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArrayTruffleObject(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArrayTruffleObject(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject) Test(org.junit.Test)

Example 7 with TruffleObject

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

the class LanguageSPIHostInteropTest method assertKeysAndProperties.

@SuppressWarnings("unchecked")
@Test
public void assertKeysAndProperties() {
    Data dataObj = new Data();
    TruffleObject data = (TruffleObject) env.asGuestValue(dataObj);
    TruffleObject keys = sendKeys(data);
    List<Object> list = context.asValue(keys).as(List.class);
    assertThat(list, CoreMatchers.hasItems("x", "y", "arr", "value", "map", "dataMap", "data", "plus"));
    Method[] objectMethods = Object.class.getMethods();
    for (Method objectMethod : objectMethods) {
        assertThat("No java.lang.Object methods", list, CoreMatchers.not(CoreMatchers.hasItem(objectMethod.getName())));
    }
    keys = sendKeys(data, true);
    list = context.asValue(keys).as(List.class);
    for (Method objectMethod : objectMethods) {
        assertThat("java.lang.Object methods", list, CoreMatchers.hasItem(objectMethod.getName()));
    }
}
Also used : Data(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.Data) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArrayTruffleObject(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject) ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArrayTruffleObject(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject) Test(org.junit.Test)

Example 8 with TruffleObject

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

the class LanguageSPIHostInteropTest method keyInfo.

@Test
public void keyInfo() {
    TruffleObject ipobj = new InternalPropertiesObject(-1, -1, 0, 0);
    int keyInfo = getKeyInfo(ipobj, "p1");
    assertTrue(KeyInfo.isReadable(keyInfo));
    assertTrue(KeyInfo.isWritable(keyInfo));
    assertFalse(KeyInfo.isInvocable(keyInfo));
    assertFalse(KeyInfo.isInternal(keyInfo));
    keyInfo = getKeyInfo(ipobj, "p6");
    assertTrue(KeyInfo.isReadable(keyInfo));
    assertTrue(KeyInfo.isWritable(keyInfo));
    assertFalse(KeyInfo.isInvocable(keyInfo));
    assertFalse(KeyInfo.isInternal(keyInfo));
    keyInfo = getKeyInfo(ipobj, "p7");
    assertEquals(0, keyInfo);
    ipobj = new InternalPropertiesObject(0b0100010, 0b0100100, 0b0011000, 0);
    keyInfo = getKeyInfo(ipobj, "p1");
    assertTrue(KeyInfo.isReadable(keyInfo));
    assertFalse(KeyInfo.isWritable(keyInfo));
    assertFalse(KeyInfo.isInvocable(keyInfo));
    keyInfo = getKeyInfo(ipobj, "p2");
    assertFalse(KeyInfo.isReadable(keyInfo));
    assertTrue(KeyInfo.isWritable(keyInfo));
    assertFalse(KeyInfo.isInvocable(keyInfo));
    keyInfo = getKeyInfo(ipobj, "p3");
    assertFalse(KeyInfo.isReadable(keyInfo));
    assertFalse(KeyInfo.isWritable(keyInfo));
    assertTrue(KeyInfo.isInvocable(keyInfo));
    keyInfo = getKeyInfo(ipobj, "p4");
    assertFalse(KeyInfo.isReadable(keyInfo));
    assertFalse(KeyInfo.isWritable(keyInfo));
    assertTrue(KeyInfo.isInvocable(keyInfo));
    keyInfo = getKeyInfo(ipobj, "p5");
    assertTrue(KeyInfo.isReadable(keyInfo));
    assertTrue(KeyInfo.isWritable(keyInfo));
    assertFalse(KeyInfo.isInvocable(keyInfo));
    keyInfo = getKeyInfo(ipobj, "p6");
    assertFalse(KeyInfo.isReadable(keyInfo));
    assertFalse(KeyInfo.isWritable(keyInfo));
    assertFalse(KeyInfo.isInvocable(keyInfo));
    keyInfo = getKeyInfo(ipobj, "p7");
    assertEquals(0, keyInfo);
    TruffleObject aobj = new ArrayTruffleObject(100);
    testArrayObject(aobj, 100);
    aobj = (TruffleObject) env.asGuestValue(new String[] { "A", "B", "C", "D" });
    testArrayObject(aobj, 4);
}
Also used : ArrayTruffleObject(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArrayTruffleObject(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject) Test(org.junit.Test)

Example 9 with TruffleObject

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

the class LanguageSPIHostInteropTest method testHasKeysDefaults.

@Test
public void testHasKeysDefaults() {
    TruffleObject noKeys = new NoKeysObject();
    assertFalse(hasKeys(noKeys));
    TruffleObject keysObj = new DefaultHasKeysObject();
    assertTrue(hasKeys(keysObj));
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArrayTruffleObject(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject) Test(org.junit.Test)

Example 10 with TruffleObject

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

the class LanguageSPIHostInteropTest method testHasKeys.

@Test
public void testHasKeys() {
    TruffleObject hasKeysObj = new HasKeysObject(true);
    assertTrue(hasKeys(hasKeysObj));
    hasKeysObj = new HasKeysObject(false);
    assertFalse(hasKeys(hasKeysObj));
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArrayTruffleObject(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject) Test(org.junit.Test)

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