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

use "show" instead of "print" to display S4 objects

parent e477db2f
No related branches found
No related tags found
No related merge requests found
......@@ -85,6 +85,7 @@ import com.oracle.truffle.r.runtime.VirtualEvalFrame;
import com.oracle.truffle.r.runtime.context.Engine;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames;
import com.oracle.truffle.r.runtime.data.RAttributable;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RExpression;
import com.oracle.truffle.r.runtime.data.RFunction;
......@@ -99,6 +100,7 @@ import com.oracle.truffle.r.runtime.data.RTypedValue;
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.env.frame.FrameSlotChangeMonitor;
import com.oracle.truffle.r.runtime.nodes.RCodeBuilder;
import com.oracle.truffle.r.runtime.nodes.RNode;
import com.oracle.truffle.r.runtime.nodes.RSyntaxElement;
import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
......@@ -594,13 +596,19 @@ final class REngine implements Engine, Engine.Timings {
result = RRuntime.asAbstractVector(result);
if (result instanceof RTypedValue || result instanceof TruffleObject) {
Object resultValue = evaluatePromise(result);
Object printMethod = REnvironment.globalEnv().findFunction("print");
RFunction function = (RFunction) evaluatePromise(printMethod);
if (resultValue instanceof RShareable && !((RShareable) resultValue).isSharedPermanent()) {
((RShareable) resultValue).incRefCount();
}
MaterializedFrame callingFrame = REnvironment.globalEnv().getFrame();
CallRFunctionNode.executeSlowpath(function, RCaller.createInvalid(callingFrame), callingFrame, new Object[]{resultValue, RMissing.instance}, null);
if (result instanceof RAttributable && ((RAttributable) result).isS4()) {
Object printMethod = REnvironment.getRegisteredNamespace("methods").get("show");
RFunction function = (RFunction) evaluatePromise(printMethod);
CallRFunctionNode.executeSlowpath(function, RCaller.createInvalid(callingFrame), callingFrame, new Object[]{resultValue}, null);
} else {
Object printMethod = REnvironment.globalEnv().findFunction("print");
RFunction function = (RFunction) evaluatePromise(printMethod);
CallRFunctionNode.executeSlowpath(function, RCaller.createInvalid(callingFrame), callingFrame, new Object[]{resultValue, RMissing.instance}, null);
}
if (resultValue instanceof RShareable && !((RShareable) resultValue).isSharedPermanent()) {
((RShareable) resultValue).decRefCount();
}
......@@ -610,6 +618,27 @@ final class REngine implements Engine, Engine.Timings {
}
}
/*
* This abstracts the calling convention, etc. behind the RASTBuilder, but creating large
* amounts of CallTargets during testing is too much overhead at the moment.
*/
@SuppressWarnings("unused")
private void printAlternative(Object result) {
Object printFunction;
if (result instanceof RAttributable && ((RAttributable) result).isS4()) {
printFunction = REnvironment.getRegisteredNamespace("methods").get("show");
} else {
printFunction = REnvironment.getRegisteredNamespace("base").get("print");
}
RFunction function = (RFunction) evaluatePromise(printFunction);
MaterializedFrame callingFrame = REnvironment.globalEnv().getFrame();
// create a piece of AST to perform the call
RCodeBuilder<RSyntaxNode> builder = RContext.getASTBuilder();
RSyntaxNode call = builder.call(RSyntaxNode.LAZY_DEPARSE, builder.constant(RSyntaxNode.LAZY_DEPARSE, function), builder.constant(RSyntaxNode.LAZY_DEPARSE, result));
doMakeCallTarget(call.asRNode(), RSource.Internal.EVAL_WRAPPER.string, false, false).call(callingFrame);
}
private static String toString(Object originalResult) {
Object result = evaluatePromise(originalResult);
result = RRuntime.asAbstractVector(result);
......
......@@ -43,8 +43,7 @@ public class TestBuiltin_setS4Object extends TestBase {
@Test
public void testsetS4Object5() {
assertEval(Ignored.Unknown,
"argv <- list(structure(c('nonStructure', 'ANY', 'ANY', 'ANY'), .Names = c(NA_character_, NA_character_, NA_character_, NA_character_), package = character(0), class = structure('signature', package = 'methods')), TRUE, 0L); .Internal(setS4Object(argv[[1]], argv[[2]], argv[[3]]))");
assertEval("argv <- list(structure(c('nonStructure', 'ANY', 'ANY', 'ANY'), .Names = c(NA_character_, NA_character_, NA_character_, NA_character_), package = character(0), class = structure('signature', package = 'methods')), TRUE, 0L); .Internal(setS4Object(argv[[1]], argv[[2]], argv[[3]]))");
}
@Test
......
......@@ -144,19 +144,14 @@ public class TestMiscBuiltins extends TestBase {
assertEval("{ m <- { matrix( as.raw(11:16), nrow=2 ) } ; diag(m) <- c(as.raw(1),as.raw(2)) ; m }");
}
//@formatter:off
private static final String[] BASIC_TYPES = new String[]{
"call", "character", "complex", "double", "expression", "function", "integer", "list",
"logical", "name", "symbol", "null", "pairlist", "raw",
"call", "character", "complex", "double", "expression", "function", "integer", "list", "logical", "name", "symbol", "null", "pairlist", "raw",
};
private static final String[] BASIC_TYPE_VALUES = new String[]{
"call(\"foo\")", "\"1\"", "1i", "1", "expression(x + 1)", "function() { }",
"1L", "list()", "TRUE", "quote(x)", "NULL", "pairlist()", "raw()"
"call(\"foo\")", "\"1\"", "1i", "1", "expression(x + 1)", "function() { }", "1L", "list()", "TRUE", "quote(x)", "NULL", "pairlist()", "raw()"
};
//@formatter:on
@Test
public void testBasicTypes() {
// cross-product of all basic types and values
......
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