use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class InstrumentableNodeTest method assertProperties.
private static void assertProperties(Object receiver, Object... properties) {
try {
assertTrue(receiver instanceof TruffleObject);
TruffleObject obj = (TruffleObject) receiver;
Node hasKeysNode = Message.HAS_KEYS.createNode();
Node keysNode = Message.KEYS.createNode();
assertTrue(ForeignAccess.sendHasKeys(hasKeysNode, obj));
TruffleObject keys = ForeignAccess.sendKeys(keysNode, obj);
for (int i = 0; i < properties.length; i = i + 2) {
String expectedKey = (String) properties[i];
Object expectedValue = properties[i + 1];
Node readNode = Message.READ.createNode();
Object key = ForeignAccess.sendRead(readNode, keys, i / 2);
assertEquals(expectedKey, key);
assertEquals(expectedValue, ForeignAccess.sendRead(readNode, obj, key));
}
} catch (InteropException e) {
throw e.raise();
}
}
use of com.oracle.truffle.api.interop.InteropException in project sulong by graalvm.
the class LLVMPolyglotExport method doExport.
@Specialization
protected Object doExport(Object name, Object value, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
String symbolName = readString.executeWithTarget(name);
LLVMContext ctx = ctxRef.get();
Object escaped = escape.executeWithTarget(value);
try {
ForeignAccess.sendWrite(write, (TruffleObject) ctx.getEnv().getPolyglotBindings(), symbolName, escaped);
} catch (InteropException ex) {
throw ex.raise();
}
return null;
}
use of com.oracle.truffle.api.interop.InteropException in project sulong by graalvm.
the class NFIContextExtension method createNativeWrapper.
@TruffleBoundary
public TruffleObject createNativeWrapper(LLVMFunctionDescriptor descriptor) {
TruffleObject wrapper = null;
try {
String signature = getNativeSignature(descriptor.getType(), 0);
TruffleObject createNativeWrapper = getNativeFunction(descriptor.getContext(), "@createNativeWrapper", String.format("(env, %s):object", signature));
try {
wrapper = (TruffleObject) ForeignAccess.sendExecute(Message.createExecute(1).createNode(), createNativeWrapper, descriptor);
} catch (InteropException ex) {
throw new AssertionError(ex);
}
} catch (UnsupportedNativeTypeException ex) {
// ignore, fall back to tagged id
}
return wrapper;
}
use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class ObjectNFITest method deleteAPI.
@AfterClass
public static void deleteAPI() {
TruffleObject deleteAPI = lookupAndBind("delete_api", "(env, pointer):void");
try {
ForeignAccess.sendExecute(Message.createExecute(1).createNode(), deleteAPI, nativeAPI);
nativeAPI = null;
} catch (InteropException ex) {
throw new AssertionError(ex);
}
}
use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class GlobalNFITest method initContext.
@BeforeClass
public static void initContext() {
registerGlobalCallback = lookupAndBind("registerGlobalCallback", "((double):double):object");
testGlobalCallback = lookupAndBind("testGlobalCallback", "(double):double");
TruffleObject initializeGlobalContext = lookupAndBind("initializeGlobalContext", "(env):void");
try {
ForeignAccess.sendExecute(Message.createExecute(0).createNode(), initializeGlobalContext);
} catch (InteropException ex) {
throw new AssertionError(ex);
}
}
Aggregations