use of org.graalvm.polyglot.nativeapi.PolyglotNativeAPITypes.PolyglotValuePointer in project graal by oracle.
the class PolyglotNativeAPI method polyglot_execute.
@CEntryPoint(name = "polyglot_execute")
public static PolyglotStatus polyglot_execute(IsolateThread isolate_thread, PolyglotValuePointer value_handle, PolyglotValuePointerPointer args, int args_size, PolyglotValuePointerPointer return_value) {
return withHandledErrors(() -> {
Value function = fetchHandle(value_handle);
Object[] jArgs = new Object[args_size];
for (int i = 0; i < args_size; i++) {
PolyglotValuePointer handle = args.read(i);
jArgs[i] = fetchHandle(handle);
}
Value result = function.execute(jArgs);
return_value.write(createHandle(result));
});
}
use of org.graalvm.polyglot.nativeapi.PolyglotNativeAPITypes.PolyglotValuePointer in project graal by oracle.
the class PolyglotNativeAPI method polyglot_create_function.
@CEntryPoint(name = "polyglot_create_function")
public static PolyglotStatus polyglot_create_function(IsolateThread isolate_thread, PolyglotContextPointer polyglot_context, PolyglotCallbackPointer callback, VoidPointer data, PolyglotValuePointerPointer value) {
return withHandledErrors(() -> {
Context c = ObjectHandles.getGlobal().get(polyglot_context);
ProxyExecutable executable = (Value... arguments) -> {
ObjectHandle[] handleArgs = new ObjectHandle[arguments.length];
for (int i = 0; i < arguments.length; i++) {
handleArgs[i] = createHandle(arguments[i]);
}
PolyglotCallbackInfo cbInfo = (PolyglotCallbackInfo) createHandle(new PolyglotCallbackInfoInternal(handleArgs, data));
try {
PolyglotValuePointer result = callback.invoke(CEntryPointContext.getCurrentIsolateThread(), cbInfo);
CallbackException ce = exceptionsTL.get();
if (ce != null) {
exceptionsTL.remove();
throw ce;
} else {
return PolyglotNativeAPI.fetchHandle(result);
}
} finally {
PolyglotCallbackInfoInternal info = fetchHandle(cbInfo);
for (ObjectHandle arg : info.arguments) {
freeHandle(arg);
}
freeHandle(cbInfo);
}
};
value.write(createHandle(c.asValue(executable)));
});
}
Aggregations