Skip to content
Snippets Groups Projects
Commit f43dc9dd authored by Lukas Stadler's avatar Lukas Stadler
Browse files

more consistent formatting in REngine.toString

parent 7f2354b7
No related branches found
No related tags found
No related merge requests found
......@@ -544,13 +544,10 @@ final class REngine implements Engine, Engine.Timings {
@Override
@TruffleBoundary
public void printResult(Object result) {
// this supports printing of non-R values (via toString for now)
if (result == null || result instanceof TruffleObject && !(result instanceof RTypedValue)) {
RContext.getInstance().getConsoleHandler().println(toString(result));
} else if (result instanceof CharSequence && !(result instanceof String)) {
RContext.getInstance().getConsoleHandler().println(toString(result));
} else {
public void printResult(Object originalResult) {
Object result = evaluatePromise(originalResult);
result = RRuntime.asAbstractVector(result);
if (result instanceof RTypedValue) {
Object resultValue = evaluatePromise(result);
Object printMethod = REnvironment.globalEnv().findFunction("print");
RFunction function = (RFunction) evaluatePromise(printMethod);
......@@ -562,19 +559,27 @@ final class REngine implements Engine, Engine.Timings {
if (resultValue instanceof RShareable && !((RShareable) resultValue).isSharedPermanent()) {
((RShareable) resultValue).decRefCount();
}
} else {
// this supports printing of non-R values (via toString for now)
RContext.getInstance().getConsoleHandler().println(toString(result));
}
}
@Override
public String toString(Object result) {
private static String toString(Object originalResult) {
Object result = evaluatePromise(originalResult);
result = RRuntime.asAbstractVector(result);
// this supports printing of non-R values (via toString for now)
if (result == null || (result instanceof TruffleObject && !(result instanceof RTypedValue))) {
return "foreign()";
} else if (result instanceof CharSequence && !(result instanceof String)) {
if (result instanceof RTypedValue) {
return PrettyPrinterNode.prettyPrintDefault(result);
} else if (result == null) {
return "[external object (null)]";
} else if (result instanceof TruffleObject) {
assert !(result instanceof RTypedValue);
return "[external object]";
} else if (result instanceof CharSequence) {
return "[1] \"" + String.valueOf(result) + "\"";
} else {
Object resultValue = evaluatePromise(result);
return PrettyPrinterNode.prettyPrintDefault(resultValue);
return String.valueOf(result);
}
}
......
......@@ -195,8 +195,6 @@ public interface Engine {
*/
void printResult(Object value);
String toString(Object value);
/**
* This function a special fast path to create functions from code directly, without executing
* the intermediate "function" expression.
......
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