From e3853c461b4aed337931e995ab3e7de46464377f Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Thu, 26 Jan 2017 13:45:16 +0100 Subject: [PATCH] implement TCK tests for findMetaObject and findSourceLocation --- .../truffle/r/engine/TruffleRLanguage.java | 18 +++++++++------- .../truffle/r/test/tck/FastRTckTest.java | 21 +++++++++++++++++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguage.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguage.java index af910abea6..8b6d249024 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguage.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguage.java @@ -155,18 +155,20 @@ public final class TruffleRLanguage extends TruffleLanguage<RContext> { @Override protected Object findMetaObject(RContext context, Object value) { - String ret = "Object"; - if (value instanceof RPromise) { - RPromise promise = (RPromise) value; + Object unwrappedValue = value; + if (unwrappedValue instanceof RPromise) { + RPromise promise = (RPromise) unwrappedValue; if (promise.isEvaluated()) { - value = promise.getValue(); + unwrappedValue = promise.getValue(); } } - value = RRuntime.asAbstractVector(value); // Wrap scalars "Integer", "Double" etc. - if (value instanceof RTypedValue) { - ret = ((RTypedValue) value).getRType().getName(); + unwrappedValue = RRuntime.asAbstractVector(unwrappedValue); // Wrap scalars "Integer", + // "Double" etc. + if (unwrappedValue instanceof RTypedValue) { + return ((RTypedValue) unwrappedValue).getRType().getName(); + } else { + return "Object"; } - return ret; } @Override diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRTckTest.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRTckTest.java index 11fdfeb85a..29c8ec9c31 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRTckTest.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRTckTest.java @@ -134,6 +134,19 @@ public class FastRTckTest extends TruffleTCK { "isExecutableOfForeign <- function(o) {\n" + " .fastr.interop.toBoolean(.fastr.interop.isExecutable(o))\n" + "}\n" + + "intValue <- function() 42L\n" + + "intVectorValue <- function() c(42L, 40L)\n" + + "intSequenceValue <- function() 42:50\n" + + "intType <- function() 'integer'\n" + + "doubleValue <- function() 42.1\n" + + "doubleVectorValue <- function() c(42.1, 40)\n" + + "doubleSequenceValue <- function() 42.1:50\n" + + "doubleType <- function() 'double'\n" + + "functionValue <- function() { function(x) 1 }\n" + + "functionType <- function() 'closure'\n" + + "builtinFunctionValue <- function() `+`\n" + + "builtinFunctionType <- function() 'builtin'\n" + + "valueWithSource <- function() intValue\n" + "for (name in ls()) .fastr.interop.export(name, get(name))\n", RSource.Internal.TCK_INIT ); @@ -473,12 +486,16 @@ public class FastRTckTest extends TruffleTCK { @Override protected String[] metaObjects() { - return null; // TBD add proper impl here. + return new String[]{ + "intValue", "intType", "intVectorValue", "intType", "intSequenceValue", "intType", + "doubleValue", "doubleType", "doubleVectorValue", "doubleType", "doubleSequenceValue", "doubleType", + "functionValue", "functionType", + "builtinFunctionValue", "builtinFunctionType"}; } @Override protected String valueWithSource() { - return null; // TBD add proper impl here. + return "valueWithSource"; } } -- GitLab