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
70c2e271
Commit
70c2e271
authored
9 years ago
by
Mick Jordan
Browse files
Options
Downloads
Patches
Plain Diff
always invoke quit on eof
parent
eebb77e2
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.shell/src/com/oracle/truffle/r/shell/RCommand.java
+22
-10
22 additions, 10 deletions
...ffle.r.shell/src/com/oracle/truffle/r/shell/RCommand.java
with
22 additions
and
10 deletions
com.oracle.truffle.r.shell/src/com/oracle/truffle/r/shell/RCommand.java
+
22
−
10
View file @
70c2e271
...
...
@@ -32,6 +32,7 @@ import jline.console.*;
import
com.oracle.truffle.api.source.*
;
import
com.oracle.truffle.r.engine.*
;
import
com.oracle.truffle.r.nodes.builtin.base.*
;
import
com.oracle.truffle.r.runtime.*
;
import
com.oracle.truffle.r.runtime.RContext.ConsoleHandler
;
import
com.oracle.truffle.r.runtime.RContext.Engine
;
...
...
@@ -144,12 +145,8 @@ public class RCommand {
// long start = System.currentTimeMillis();
consoleHandler
=
new
JLineConsoleHandler
(
isInteractive
,
consoleReader
);
}
readEvalPrint
(
consoleHandler
,
args
,
filePath
);
// We should only reach here if interactive == false
// Need to call quit explicitly
Source
quitSource
=
Source
.
fromText
(
"quit(\"default\", 0L, TRUE)"
,
"<quit_file>"
);
RContext
.
getEngine
().
parseAndEval
(
quitSource
,
false
,
false
);
// never returns
readEvalPrint
(
consoleHandler
,
args
,
filePath
);
assert
false
;
}
...
...
@@ -165,6 +162,19 @@ public class RCommand {
throw
Utils
.
exit
(
0
);
}
private
static
final
Source
QUIT_EOF
=
Source
.
fromText
(
"quit(\"default\", 0L, TRUE)"
,
"<quit_file>"
);
/**
* The read-eval-print loop, which can take input from a console, command line expression or a
* file. There are two ways the repl can terminate:
* <ol>
* <li>A {@code quit} command is executed successfully, which case the system exits from the
* {@link Quit} {@code .Internal} .</li>
* <li>EOF on the input.</li>
* </ol>
* In case 2, we must implicitly execute a {@code quit("default, 0L, TRUE} command before
* exiting. So,in either case, we never return.
*/
private
static
void
readEvalPrint
(
ConsoleHandler
consoleHandler
,
String
[]
commandArgs
,
String
filePath
)
{
String
inputDescription
=
filePath
==
null
?
"<shell_input>"
:
filePath
;
Source
source
=
Source
.
fromNamedAppendableText
(
inputDescription
);
...
...
@@ -176,7 +186,7 @@ public class RCommand {
consoleHandler
.
setPrompt
(
doEcho
?
"> "
:
null
);
String
input
=
consoleHandler
.
readLine
();
if
(
input
==
null
)
{
return
;
throw
new
EOFException
()
;
}
// Start index of the new input
int
startLength
=
source
.
getLength
();
...
...
@@ -191,23 +201,25 @@ public class RCommand {
try
{
String
continuePrompt
=
getContinuePrompt
();
Source
subSource
=
Source
.
subSource
(
source
,
startLength
);
while
(
RC
ontext
.
getEngine
().
parseAndEval
(
subSource
,
true
,
true
)
==
Engine
.
INCOMPLETE_SOURCE
)
{
while
(
c
ontext
.
get
Context
Engine
().
parseAndEval
(
subSource
,
true
,
true
)
==
Engine
.
INCOMPLETE_SOURCE
)
{
consoleHandler
.
setPrompt
(
doEcho
?
continuePrompt
:
null
);
String
additionalInput
=
consoleHandler
.
readLine
();
if
(
additionalInput
==
null
)
{
return
;
throw
new
EOFException
()
;
}
source
.
appendCode
(
additionalInput
);
subSource
=
Source
.
subSource
(
source
,
startLength
);
}
}
catch
(
BrowserQuitException
ex
)
{
// Q in browser
// Q in browser
, which continues the repl
}
}
}
catch
(
BrowserQuitException
e
)
{
// can happen if user profile invokes browser
}
catch
(
UserInterruptException
e
)
{
// interrupted
// interrupted (how?)
}
catch
(
EOFException
ex
)
{
context
.
getContextEngine
().
parseAndEval
(
QUIT_EOF
,
false
,
false
);
}
finally
{
context
.
destroy
();
}
...
...
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