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