Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Lopez
QueryR
Commits
10dbeedd
Commit
10dbeedd
authored
8 years ago
by
Mick Jordan
Browse files
Options
Downloads
Patches
Plain Diff
Document REmbedded and alter site for completing initialization
parent
2e906e41
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/REmbedded.java
+40
-15
40 additions, 15 deletions
...gine/src/com/oracle/truffle/r/engine/shell/REmbedded.java
with
40 additions
and
15 deletions
com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/REmbedded.java
+
40
−
15
View file @
10dbeedd
...
...
@@ -31,39 +31,59 @@ import com.oracle.truffle.r.runtime.RCmdOptions;
import
com.oracle.truffle.r.runtime.RInternalSourceDescriptions
;
import
com.oracle.truffle.r.runtime.RStartParams
;
import
com.oracle.truffle.r.runtime.Utils
;
import
com.oracle.truffle.r.runtime.context.ContextInfo
;
import
com.oracle.truffle.r.runtime.context.RContext
;
/**
* Support for embedding FastR in a C/C++ application according to {@code Rembedded.h}. The
* embedding interface consists of several functions and can be used in several ways. Since it is
* not specified other than by example, we only have existing use-cases to work from. This is the
* sequence used by {@code RStudio}.
*
* <pre>
* Rf_initialize_R(argv, args);
* Rstart rs;
* // set some rs fields
* R_SetParams(rs);
* // set some Rinterface function callbacks
* ptr_R_WriteConsole = local_R_WriteConsole
* Rf_mainloop();
* </pre>
*
* {@code Rf_initialize_R} invokes {@link #initializeR(String[])}. This creates an
* {@link RStartParams} object in {@code embedded} mode that is recorded in the {@link ContextInfo}
* object which is itself stored as a global symbol in the associated {@link PolyglotEngine}
* instance. The FastR {@link PolyglotEngine} is then partially initialized. The call to
* {@code R_SetParams} will adjust the values stored in the {@link RStartParams} object and then
* {@code Rf_mainloop}, which calls {@link #mainloop(PolyglotEngine)} will complete the FastR
* initialization and enter the read-eval-print loop.
*/
public
class
REmbedded
{
/**
* Creates the {@link PolyglotEngine} and initializes it. Called from native code when FastR is
* embedded. Corresponds to FFI method {@code Rf_initialize_R}. N.B. This does not actually
* initialize FastR as that happens indirectly when the {@link PolyglotEngine} does the first
* {@code eval} and we cannot do that until the embedding system has had a chance to adjust the
* {@link RStartParams}.
* embedded. Corresponds to FFI method {@code Rf_initialize_R}. N.B. This does not completely
* 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
PolyglotEngine
initializeR
(
String
[]
args
)
{
RCmdOptions
options
=
RCmdOptions
.
parseArguments
(
RCmdOptions
.
Client
.
R
,
args
,
true
);
PolyglotEngine
vm
=
RCommand
.
createContextInfoFromCommandLine
(
options
,
true
);
try
{
vm
.
eval
(
INIT
);
}
catch
(
IOException
ex
)
{
Utils
.
fatalError
(
"initializeR"
);
}
return
vm
;
}
private
static
final
Source
INIT
=
Source
.
fromText
(
"1"
,
RInternalSourceDescriptions
.
GET_ECHO
).
withMimeType
(
TruffleRLanguage
.
MIME
);
/**
* Upcall from native code to prepare for the main read-eval-print loop, Since we are in
* embedded mode we first do a dummy eval that has the important side effect of creating the
* {@link RContext}. Then we use that to complete the initialization that was deferred.
*
* @param vm
* GnuR distinguishes {@code setup_Rmainloop} and {@code run_Rmainloop}. Currently we don't have
* the equivalent separation in FastR.
*/
private
static
void
setupRmainloop
(
PolyglotEngine
vm
)
{
try
{
vm
.
eval
(
INIT
);
RContext
.
getInstance
().
completeEmbeddedInitialization
();
}
catch
(
IOException
ex
)
{
Utils
.
fatalError
(
"setupRmainloop"
);
}
}
private
static
void
mainloop
(
PolyglotEngine
vm
)
{
...
...
@@ -71,7 +91,12 @@ public class REmbedded {
runRmainloop
(
vm
);
}
/**
* This is where we can complete the initialization based on what modifications were made by the
* native code after {@link #initializeR} returned.
*/
private
static
void
runRmainloop
(
PolyglotEngine
vm
)
{
RContext
.
getInstance
().
completeEmbeddedInitialization
();
RCommand
.
readEvalPrint
(
vm
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment