use of com.oracle.truffle.api.interop.UnsupportedMessageException 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.UnsupportedMessageException in project graal by oracle.
the class LanguageSPITest method testPolyglotBindingsPreserveLanguage.
@Test
public void testPolyglotBindingsPreserveLanguage() {
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
return Truffle.getRuntime().createCallTarget(new RootNode(languageInstance) {
@Override
public Object execute(VirtualFrame frame) {
Object bindings = getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
try {
ForeignAccess.sendWrite(Message.WRITE.createNode(), (TruffleObject) bindings, "exportedValue", "convertOnToString");
} catch (UnknownIdentifierException | UnsupportedTypeException | UnsupportedMessageException e) {
throw new AssertionError(e);
}
return bindings;
}
});
}
@Override
protected String toString(LanguageContext context, Object value) {
if (value.equals("convertOnToString")) {
return "myStringToString";
}
return super.toString(context, value);
}
});
Context c = Context.create();
c.eval(ProxyLanguage.ID, "");
assertEquals("Make sure language specific toString was invoked.", "myStringToString", c.getPolyglotBindings().getMember("exportedValue").toString());
}
use of com.oracle.truffle.api.interop.UnsupportedMessageException in project graal by oracle.
the class TestMemberAccess method testObjectReadIndex.
@Test
public void testObjectReadIndex() throws InteropException {
TruffleObject arrayObject = JavaInterop.asTruffleObject(new TestClass());
try {
ForeignAccess.sendRead(readNode, arrayObject, 0);
fail();
} catch (UnsupportedMessageException e) {
}
}
use of com.oracle.truffle.api.interop.UnsupportedMessageException in project graal by oracle.
the class SlowPathSerializeArgumentNode method genericWithPrepare.
@Specialization(replaces = "cacheType", guards = { "value != null" })
protected Object genericWithPrepare(NativeArgumentBuffer buffer, LibFFIType type, TruffleObject value, @Cached("createUnbox()") Node unbox, @Cached("createIsExecutable()") Node isExecutable, @Cached("createAsPointer()") AsPointerNode asPointer, @Cached("createRecursive()") SlowPathSerializeArgumentNode recursive) {
Object prepared = type.slowpathPrepareArgument(value);
if (prepared == PrepareArgument.EXECUTABLE) {
if (ForeignAccess.sendIsExecutable(isExecutable, value)) {
prepared = value;
} else {
prepared = PrepareArgument.POINTER;
}
}
if (prepared == PrepareArgument.POINTER) {
prepared = asPointer.execute(value);
} else if (prepared == PrepareArgument.UNBOX) {
Object unboxed;
try {
unboxed = ForeignAccess.sendUnbox(unbox, value);
} catch (UnsupportedMessageException ex) {
throw UnsupportedTypeException.raise(ex, new Object[] { value });
}
return recursive.execute(buffer, type, unboxed);
}
slowPathSerialize(buffer, type, prepared);
return null;
}
use of com.oracle.truffle.api.interop.UnsupportedMessageException in project sulong by graalvm.
the class LLVMTruffleReadNString method interop.
@Specialization
protected Object interop(LLVMTruffleObject objectWithOffset, int n, @Cached("createForeignReadNode()") Node foreignRead, @Cached("createToByteNode()") ForeignToLLVM toLLVM) {
long offset = objectWithOffset.getOffset();
TruffleObject object = objectWithOffset.getObject();
char[] chars = new char[n];
for (int i = 0; i < n; i++) {
Object rawValue;
try {
rawValue = ForeignAccess.sendRead(foreignRead, object, offset + i);
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException(e);
}
byte byteValue = (byte) toLLVM.executeWithTarget(rawValue);
chars[i] = (char) Byte.toUnsignedInt(byteValue);
}
return new String(chars);
}
Aggregations