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

REmbedded API: support main loop initialization in Rf_initEmbeddedR

Additionally restructured the Rembedded.c file to logical blocks, add visual dividers, clean-up the code.
parent c0fa91c7
No related branches found
No related tags found
No related merge requests found
......@@ -71,7 +71,7 @@ public class REmbedded {
* initialize FastR as we cannot do that until the embedding system has had a chance to adjust
* the {@link RStartParams}, which happens after this call returns.
*/
private static void initializeR(String[] args) {
private static void initializeR(String[] args, boolean initMainLoop) {
assert context == null;
RContext.setEmbedded();
RCmdOptions options = RCmdOptions.parseArguments(RCmdOptions.Client.R, args, false);
......@@ -86,6 +86,13 @@ public class REmbedded {
context = Context.newBuilder().allowHostAccess(true).arguments("R", options.getArguments()).in(input).out(stdOut).err(stdErr).build();
consoleHandler.setContext(context);
context.eval(INIT);
if (initMainLoop) {
context.enter();
RContext.getInstance().completeEmbeddedInitialization();
// TODO: push callbacks
// stay in the context TODO should we?
}
}
/**
......@@ -110,12 +117,10 @@ public class REmbedded {
*/
private static final Source INIT = Source.newBuilder("R", "1", "<embedded>").buildLiteral();
/**
* GnuR distinguishes {@code setup_Rmainloop} and {@code run_Rmainloop}. Currently we don't have
* the equivalent separation in FastR.
*/
private static void setupRmainloop() {
// nothing to do
private static void endRmainloop(int status) {
context.leave();
context.close();
Utils.systemExit(status);
}
/**
......@@ -135,8 +140,7 @@ public class REmbedded {
* Testing vehicle, emulates a native upcall.
*/
public static void main(String[] args) {
initializeR(args);
setupRmainloop();
initializeR(args, false);
runRmainloop();
}
......
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