24
24
25
25
import static com .oracle .truffle .r .nodes .builtin .CastBuilder .Predef .logicalFalse ;
26
26
import static com .oracle .truffle .r .nodes .builtin .CastBuilder .Predef .logicalValue ;
27
- import static com .oracle .truffle .r .runtime .RError .Message .MATCH_VECTOR_ARGS ;
28
27
import static com .oracle .truffle .r .runtime .builtins .RBehavior .PURE ;
29
28
import static com .oracle .truffle .r .runtime .builtins .RBuiltinKind .INTERNAL ;
30
29
31
- import java .util .Arrays ;
32
-
33
30
import com .oracle .truffle .api .dsl .Cached ;
34
- import com .oracle .truffle .api .dsl .Fallback ;
35
31
import com .oracle .truffle .api .dsl .Specialization ;
36
- import com .oracle .truffle .api .profiles .ConditionProfile ;
37
- import com .oracle .truffle .r .nodes .builtin .MatchInternalNode ;
32
+ import com .oracle .truffle .r .nodes .builtin .Match5Node ;
38
33
import com .oracle .truffle .r .nodes .builtin .RBuiltinNode ;
39
- import com .oracle .truffle .r .nodes .helpers .InheritsCheckNode ;
40
- import com .oracle .truffle .r .nodes .helpers .RFactorNodes ;
41
- import com .oracle .truffle .r .nodes .unary .CastStringNode ;
42
34
import com .oracle .truffle .r .runtime .RError .Message ;
43
- import com .oracle .truffle .r .runtime .RRuntime ;
44
- import com .oracle .truffle .r .runtime .RType ;
45
35
import com .oracle .truffle .r .runtime .builtins .RBuiltin ;
46
- import com .oracle .truffle .r .runtime .data .RDataFactory ;
47
- import com .oracle .truffle .r .runtime .data .RNull ;
48
- import com .oracle .truffle .r .runtime .data .closures .RClosures ;
49
- import com .oracle .truffle .r .runtime .data .RIntVector ;
50
- import com .oracle .truffle .r .runtime .data .model .RAbstractListVector ;
51
- import com .oracle .truffle .r .runtime .data .model .RAbstractVector ;
52
36
53
37
/*
54
38
* TODO: handle "incomparables" parameter.
@@ -60,97 +44,14 @@ public abstract class Match extends RBuiltinNode.Arg4 {
60
44
61
45
static {
62
46
Casts casts = new Casts (Match .class );
63
- // TODO initially commented out because of use of scalars, the commented out version
64
- // converted to new cast pipelines API
65
-
66
- // casts.arg("x").allowNull().mustBe(abstractVectorValue(), SHOW_CALLER,
67
- // MATCH_VECTOR_ARGS).asVectorPreserveAttrs(true);
68
- // casts.arg("table").allowNull().mustBe(abstractVectorValue()).asVectorPreserveAttrs(true);
69
47
casts .arg ("nomatch" ).asIntegerVector ().findFirst ();
70
48
casts .arg ("incomparables" ).defaultError (Message .GENERIC , "usage of 'incomparables' in match not implemented" ).allowNull ().mustBe (logicalValue ()).asLogicalVector ().findFirst ().mustBe (
71
49
logicalFalse ());
72
50
}
73
51
74
- protected boolean isCharSXP (RAbstractListVector list ) {
75
- for (int i = 0 ; i < list .getLength (); i ++) {
76
- if (!(RType .getRType (list .getDataAt (i )).equals (RType .Char ))) {
77
- return false ;
78
- }
79
- }
80
- return true ;
81
- }
82
-
83
- @ Specialization
84
- @ SuppressWarnings ("unused" )
85
- protected RIntVector match (RNull x , RNull table , int nomatch , Object incomparables ) {
86
- return RDataFactory .createIntVector (0 );
87
- }
88
-
89
52
@ Specialization
90
- @ SuppressWarnings ("unused" )
91
- protected RIntVector match (RNull x , RAbstractVector table , int nomatch , Object incomparables ) {
92
- return RDataFactory .createIntVector (0 );
93
- }
94
-
95
- @ Specialization
96
- @ SuppressWarnings ("unused" )
97
- protected RIntVector match (RAbstractVector x , RNull table , int nomatch , Object incomparables ,
98
- @ Cached ("createBinaryProfile()" ) ConditionProfile na ) {
99
- int [] data = new int [x .getLength ()];
100
- Arrays .fill (data , nomatch );
101
- return RDataFactory .createIntVector (data , na .profile (!RRuntime .isNA (nomatch )));
102
- }
103
-
104
- @ Child private InheritsCheckNode factorInheritsCheck = InheritsCheckNode .create (RRuntime .CLASS_FACTOR );
105
-
106
- protected boolean isFactor (Object o ) {
107
- return factorInheritsCheck .execute (o );
108
- }
109
-
110
- @ Specialization (guards = {"isFactor(x)" , "isFactor(table)" })
111
- protected Object matchFactor (RIntVector x , RIntVector table , int nomatch , @ SuppressWarnings ("unused" ) Object incomparables ,
112
- @ Cached ("create()" ) RFactorNodes .GetLevels getLevelsNode ,
113
- @ Cached () MatchInternalNode match ) {
114
- return match .execute (RClosures .createFactorToVector (x , true , getLevelsNode .execute (x )),
115
- RClosures .createFactorToVector (table , true , getLevelsNode .execute (table )), nomatch );
116
- }
117
-
118
- @ Specialization (guards = {"isFactor(x)" , "!isFactor(table)" })
119
- protected Object matchFactor (RIntVector x , RAbstractVector table , int nomatch , @ SuppressWarnings ("unused" ) Object incomparables ,
120
- @ Cached ("create()" ) RFactorNodes .GetLevels getLevelsNode ,
121
- @ Cached () MatchInternalNode match ) {
122
- return match .execute (RClosures .createFactorToVector (x , true , getLevelsNode .execute (x )), table , nomatch );
123
- }
124
-
125
- @ Specialization (guards = {"!isFactor(x)" , "isFactor(table)" })
126
- protected Object matchFactor (RAbstractVector x , RIntVector table , int nomatch , @ SuppressWarnings ("unused" ) Object incomparables ,
127
- @ Cached ("create()" ) RFactorNodes .GetLevels getLevelsNode ,
128
- @ Cached () MatchInternalNode match ) {
129
- return match .execute (x , RClosures .createFactorToVector (table , true , getLevelsNode .execute (table )), nomatch );
130
- }
131
-
132
- @ Specialization (guards = {"isCharSXP(x)" , "isCharSXP(table)" })
133
- protected Object matchDoubleList (RAbstractListVector x , RAbstractListVector table , int nomatchObj , @ SuppressWarnings ("unused" ) Object incomparables ,
134
- @ Cached () MatchInternalNode match ) {
135
- return match .execute (x , table , nomatchObj );
136
- }
137
-
138
- @ Specialization (guards = {"!isRIntVector(table) || !isFactor(table)" })
139
- protected Object matchList (RAbstractListVector x , RAbstractVector table , int nomatchObj , @ SuppressWarnings ("unused" ) Object incomparables ,
140
- @ Cached ("create()" ) CastStringNode cast ,
141
- @ Cached () MatchInternalNode match ) {
142
- return match .execute ((RAbstractVector ) cast .doCast (x ), table , nomatchObj );
143
- }
144
-
145
- @ Specialization (guards = {"!isRAbstractListVector(x)" , "!isRIntVector(x) || !isFactor(x)" , "!isRIntVector(table) || !isFactor(table)" })
146
- protected Object match (RAbstractVector x , RAbstractVector table , int noMatch , @ SuppressWarnings ("unused" ) Object incomparables ,
147
- @ Cached () MatchInternalNode match ) {
148
- return match .execute (x , table , noMatch );
149
- }
150
-
151
- @ Fallback
152
- @ SuppressWarnings ("unused" )
153
- protected RIntVector match (Object x , Object table , Object nomatch , Object incomparables ) {
154
- throw error (MATCH_VECTOR_ARGS );
53
+ Object doIt (Object x , Object table , int nomatch , Object incomparables ,
54
+ @ Cached Match5Node match5Node ) {
55
+ return match5Node .execute (x , table , nomatch , incomparables );
155
56
}
156
57
}
0 commit comments