Skip to content
Snippets Groups Projects
Commit 4631be20 authored by Stepan Sindelar's avatar Stepan Sindelar
Browse files

Merge pull request #654 in G/fastr from...

Merge pull request #654 in G/fastr from ~STEPAN.SINDELAR_ORACLE.COM/fastr:feature/small-updates to master

* commit '0e58c141':
  Undo modifications to __S3MethodsTable__ in tests
  Use newCastBuilder() API in more places
parents 3b05010a 0e58c141
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.size;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.typeName;
import static com.oracle.truffle.r.nodes.builtin.casts.fluent.CastNodeBuilder.newCastBuilder;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
......@@ -36,7 +37,6 @@ import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ValueProfile;
import com.oracle.truffle.r.nodes.builtin.CastBuilder;
import com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.nodes.unary.CastNode;
import com.oracle.truffle.r.runtime.RError;
......@@ -84,10 +84,12 @@ public abstract class Quantifier extends RBuiltinNode {
}
private void createArgCast(int index) {
CastBuilder argCastBuilder = new CastBuilder();
argCastBuilder.arg(0).allowNull().shouldBe(integerValue().or(logicalValue()).or(instanceOf(RAbstractVector.class).and(size(0))), RError.Message.COERCING_ARGUMENT, typeName(),
"logical").asLogicalVector();
argCastNodes[index] = insert(new ProfileCastNode(argCastBuilder.getCasts()[0]));
// @formatter:off
argCastNodes[index] = insert(newCastBuilder().allowNull().
shouldBe(integerValue().or(logicalValue()).or(instanceOf(RAbstractVector.class).and(size(0))),
RError.Message.COERCING_ARGUMENT, typeName(), "logical").
asLogicalVector().buildCastNode());
// @formatter:on
}
protected boolean emptyVectorResult() {
......
......@@ -15,6 +15,7 @@ package com.oracle.truffle.r.nodes.builtin.base;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.instanceOf;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.lengthGt;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue;
import static com.oracle.truffle.r.nodes.builtin.casts.fluent.CastNodeBuilder.newCastBuilder;
import static com.oracle.truffle.r.runtime.RVisibility.CUSTOM;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX;
import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE;
......@@ -72,11 +73,8 @@ public abstract class StandardGeneric extends RBuiltinNode {
@Child private CastNode castIntScalar;
@Child private CastNode castStringScalar;
{
CastBuilder builder = new CastBuilder(2);
builder.arg(0).asIntegerVector().findFirst(RRuntime.INT_NA);
builder.arg(1).asStringVector().findFirst(RRuntime.STRING_NA);
castIntScalar = builder.getCasts()[0];
castStringScalar = builder.getCasts()[1];
castIntScalar = newCastBuilder().asIntegerVector().findFirst(RRuntime.INT_NA).buildCastNode();
castStringScalar = newCastBuilder().asStringVector().findFirst(RRuntime.STRING_NA).buildCastNode();
}
private final BranchProfile noGenFunFound = BranchProfile.create();
......
......@@ -12,6 +12,8 @@
*/
package com.oracle.truffle.r.nodes.objects;
import static com.oracle.truffle.r.nodes.builtin.casts.fluent.CastNodeBuilder.newCastBuilder;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.r.nodes.access.AccessSlotNode;
......@@ -41,11 +43,8 @@ public abstract class NewObject extends RExternalBuiltinNode.Arg1 {
@Child private CastNode castStringScalar;
@Child private CastNode castLogicalScalar;
{
CastBuilder builder = new CastBuilder();
builder.arg(0).asStringVector().findFirst(RRuntime.STRING_NA);
builder.arg(1).asLogicalVector().findFirst(RRuntime.LOGICAL_NA);
castStringScalar = builder.getCasts()[0];
castLogicalScalar = builder.getCasts()[1];
castStringScalar = newCastBuilder().asStringVector().findFirst(RRuntime.STRING_NA).buildCastNode();
castLogicalScalar = newCastBuilder().asLogicalVector().findFirst(RRuntime.LOGICAL_NA).buildCastNode();
}
@Override
......
......@@ -57569,7 +57569,7 @@ integer(0)
[49] 27795.92 28000.00
 
##com.oracle.truffle.r.test.builtins.TestBuiltin_seq_along.testWithNonStandardLength#Ignored.Unimplemented#
#{ assign('length.myclass', function(...) 42, envir=.__S3MethodsTable__.); x <- 1; class(x) <- 'myclass'; seq_along(x); }
#{ assign('length.myclass', function(...) 42, envir=.__S3MethodsTable__.); x <- 1; class(x) <- 'myclass'; res <- seq_along(x); rm('length.myclass', envir=.__S3MethodsTable__.); res }
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
[26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
 
......@@ -72332,11 +72332,11 @@ attr(,".Environment")
<environment: R_GlobalEnv>
 
##com.oracle.truffle.r.test.functions.TestS3Dispatch.testGenericDispatchThroughMethodsTable#
#{ assign('Ops.myclass', function(a,b) 42, envir=.__S3MethodsTable__.); x<-1; class(x)<-'myclass'; x+x; }
#{ assign('Ops.myclass', function(a,b) 42, envir=.__S3MethodsTable__.); x<-1; class(x)<-'myclass'; res <- x+x; rm('Ops.myclass', envir=.__S3MethodsTable__.); res; }
[1] 42
 
##com.oracle.truffle.r.test.functions.TestS3Dispatch.testGenericDispatchThroughMethodsTable#
#{ assign('[[.myclass', function(a,b) 42, envir=.__S3MethodsTable__.); x<-1; class(x)<-'myclass'; x[[99]]; }
#{ assign('[[.myclass', function(a,b) 42, envir=.__S3MethodsTable__.); x<-1; class(x)<-'myclass'; res <- x[[99]]; rm('[[.myclass', envir=.__S3MethodsTable__.); res; }
[1] 42
 
##com.oracle.truffle.r.test.functions.TestS3Dispatch.testMathGroupDispatch#
......@@ -142,6 +142,7 @@ public class TestBuiltin_seq_along extends TestBase {
// length defined in global env should not get us confused:
assertEval("{ length <- function(x) 42; seq_along(c(1,2,3)) }");
// length in __S3MethodsTable__ should work too, N.B.: needs complete S3 dispatch support
assertEval(Ignored.Unimplemented, "{ assign('length.myclass', function(...) 42, envir=.__S3MethodsTable__.); x <- 1; class(x) <- 'myclass'; seq_along(x); }");
assertEval(Ignored.Unimplemented,
"{ assign('length.myclass', function(...) 42, envir=.__S3MethodsTable__.); x <- 1; class(x) <- 'myclass'; res <- seq_along(x); rm('length.myclass', envir=.__S3MethodsTable__.); res }");
}
}
......@@ -138,8 +138,8 @@ public class TestS3Dispatch extends TestRBase {
public void testGenericDispatchThroughMethodsTable() {
// Note: `[.term` is "private" in stats, but it has entry in __S3MethodsTable__
assertEval("terms(x~z)[1];");
assertEval("{ assign('Ops.myclass', function(a,b) 42, envir=.__S3MethodsTable__.); x<-1; class(x)<-'myclass'; x+x; }");
assertEval("{ assign('[[.myclass', function(a,b) 42, envir=.__S3MethodsTable__.); x<-1; class(x)<-'myclass'; x[[99]]; }");
assertEval("{ assign('Ops.myclass', function(a,b) 42, envir=.__S3MethodsTable__.); x<-1; class(x)<-'myclass'; res <- x+x; rm('Ops.myclass', envir=.__S3MethodsTable__.); res; }");
assertEval("{ assign('[[.myclass', function(a,b) 42, envir=.__S3MethodsTable__.); x<-1; class(x)<-'myclass'; res <- x[[99]]; rm('[[.myclass', envir=.__S3MethodsTable__.); res; }");
}
@Override
......
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