Skip to content
Snippets Groups Projects
Commit 81ee0a4e authored by stepan's avatar stepan
Browse files

R Embedded API: intialize RFFI to be used in embedding code outside any down-call context

parent a48d0180
No related branches found
No related tags found
No related merge requests found
......@@ -89,8 +89,9 @@ public class REmbedded {
if (initMainLoop) {
context.enter();
RContext.getInstance().completeEmbeddedInitialization();
// TODO: push callbacks
RContext ctx = RContext.getInstance();
ctx.completeEmbeddedInitialization();
ctx.getRFFI().initializeEmbedded(ctx);
// stay in the context TODO should we?
}
}
......@@ -129,7 +130,9 @@ public class REmbedded {
*/
private static void runRmainloop() {
context.enter();
RContext.getInstance().completeEmbeddedInitialization();
RContext ctx = RContext.getInstance();
ctx.completeEmbeddedInitialization();
ctx.getRFFI().initializeEmbedded(ctx);
int status = RCommand.readEvalPrint(context, consoleHandler);
context.leave();
context.close();
......
......@@ -196,6 +196,11 @@ final class TruffleNFI_Context extends RFFIContext {
}
}
@Override
public void initializeEmbedded(RContext context) {
pushCallbacks();
}
@TruffleBoundary
private long initCallbacksAddress() {
// get the address of the native thread local
......
......@@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.r.runtime.RInternalError;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.RObject;
......@@ -101,6 +102,17 @@ public abstract class RFFIContext extends RFFI {
public void initializeVariables(RContext context) {
}
/**
* Invoked as part of the R embedded initialization just before returning back to the C user
* code. Should do any set-up necessary for the RFFI to be fully functional even outside the
* context of a down-call. At the moment the assumption is that embedded code is always single
* threaded and always creates exactly one context. This method shall be invoked after
* {@link #initialize(RContext)} and {@link #initializeVariables(RContext)}.
*/
public void initializeEmbedded(RContext context) {
throw RInternalError.unimplemented("R Embedding not supported with " + this.getClass().getSimpleName() + " RFFI backend.");
}
public long beforeDowncall() {
callDepth++;
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment