Search in sources :

Example 1 with TruffleObject

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

the class DebugScope method getArguments.

/**
 * Get arguments of this scope. If this scope is a {@link #isFunctionScope() function} scope,
 * function arguments are returned.
 * <p>
 * This method is not thread-safe and will throw an {@link IllegalStateException} if called on
 * another thread than it was created with.
 *
 * @return an iterable of arguments, or <code>null</code> when this scope does not have a
 *         concept of arguments.
 * @since 0.26
 */
public Iterable<DebugValue> getArguments() {
    verifyValidState();
    Object argumentsObj = scope.getArguments();
    Iterable<DebugValue> arguments = null;
    if (argumentsObj != null && argumentsObj instanceof TruffleObject) {
        TruffleObject argsTO = (TruffleObject) argumentsObj;
        arguments = DebugValue.getProperties(argumentsObj, debugger, getLanguage(), this);
        if (arguments == null && ObjectStructures.isArray(debugger.getMessageNodes(), argsTO)) {
            List<Object> array = ObjectStructures.asList(debugger.getMessageNodes(), argsTO);
            arguments = new ValueInteropList(debugger, getLanguage(), array);
        }
    }
    return arguments;
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 2 with TruffleObject

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

the class DebugValue method getProperties.

static ValuePropertiesCollection getProperties(Object value, Debugger debugger, LanguageInfo language, DebugScope scope) {
    ValuePropertiesCollection properties = null;
    if (value instanceof TruffleObject) {
        TruffleObject object = (TruffleObject) value;
        Map<Object, Object> map = ObjectStructures.asMap(debugger.getMessageNodes(), object);
        if (map != null) {
            properties = new ValuePropertiesCollection(debugger, language, object, map, map.entrySet(), scope);
        }
    }
    return properties;
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 3 with TruffleObject

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

the class ObjectStructures method asMap.

static Map<Object, Object> asMap(MessageNodes nodes, TruffleObject object) {
    TruffleObject keys;
    try {
        keys = ForeignAccess.sendKeys(nodes.keys, object, true);
        boolean hasSize = ForeignAccess.sendHasSize(nodes.hasSize, keys);
        if (!hasSize) {
            return null;
        }
    } catch (UnsupportedMessageException ex) {
        return null;
    }
    return new ObjectMap(nodes, object, keys);
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 4 with TruffleObject

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

the class LanguageSPIHostInteropTest method keyInfoDefaults.

@Test
public void keyInfoDefaults() {
    TruffleObject noKeys = new NoKeysObject();
    int keyInfo = getKeyInfo(noKeys, "p1");
    assertEquals(0, keyInfo);
    TruffleObject nkio = new NoKeyInfoObject();
    keyInfo = getKeyInfo(nkio, "p1");
    assertEquals(0b111, keyInfo);
    keyInfo = getKeyInfo(nkio, "p6");
    assertEquals(0b111, keyInfo);
    keyInfo = getKeyInfo(nkio, "p7");
    assertEquals(0, keyInfo);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArrayTruffleObject(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject) Test(org.junit.Test)

Example 5 with TruffleObject

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

the class LanguageSPIHostInteropTest method invokeJavaLangObjectFields.

@Test
public void invokeJavaLangObjectFields() throws InteropException {
    Data data = new Data();
    TruffleObject obj = (TruffleObject) env.asGuestValue(data);
    Object string = ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, "toString");
    assertTrue(string instanceof String && ((String) string).startsWith(Data.class.getName() + "@"));
    Object clazz = ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, "getClass");
    assertTrue(clazz instanceof TruffleObject && env.asHostObject(clazz) == Data.class);
    assertEquals(true, ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), obj, "equals", obj));
    assertTrue(ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, "hashCode") instanceof Integer);
    for (String m : new String[] { "notify", "notifyAll", "wait" }) {
        assertThrowsExceptionWithCause(() -> ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, m), IllegalMonitorStateException.class);
    }
}
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) 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