Skip to content

Commit 2a80638

Browse files
committed
[GR-11291] Enabling dplyr tests.
PullRequest: fastr/1657
2 parents 0378093 + e48f906 commit 2a80638

File tree

17 files changed

+168
-23
lines changed

17 files changed

+168
-23
lines changed

com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/RRuntimeASTAccessImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ public RPairList getSyntaxCaller(RCaller rl) {
146146
while (call.isPromise()) {
147147
call = call.getParent();
148148
}
149-
RSyntaxElement syntaxNode = call.getSyntaxNode();
150-
return RDataFactory.createLanguage(getOrCreateLanguageClosure(((RSyntaxNode) syntaxNode).asRNode()));
149+
if (call.isValidCaller()) {
150+
RSyntaxElement syntaxNode = call.getSyntaxNode();
151+
return RDataFactory.createLanguage(getOrCreateLanguageClosure(((RSyntaxNode) syntaxNode).asRNode()));
152+
} else {
153+
return null;
154+
}
151155
}
152156

153157
private static RBaseNode checkBuiltin(RBaseNode bn) {

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,8 +2385,8 @@ public Object octsize(Object size) {
23852385

23862386
@Override
23872387
public Object FASTR_DATAPTR(Object x) {
2388-
if (x instanceof RStringVector) {
2389-
return VectorRFFIWrapper.get((RStringVector) x);
2388+
if ((x instanceof RStringVector) || (x instanceof RList)) {
2389+
return VectorRFFIWrapper.get((TruffleObject) x);
23902390
}
23912391
CompilerDirectives.transferToInterpreter();
23922392
throw RError.error(RError.NO_CALLER, Message.GENERIC, "DATAPTR not implemented for type " + Utils.getTypeName(x));

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.truffle.r.runtime.RError.Message;
4646
import com.oracle.truffle.r.runtime.RInternalError;
4747
import com.oracle.truffle.r.runtime.RRuntime;
48+
import com.oracle.truffle.r.runtime.Utils;
4849
import com.oracle.truffle.r.runtime.data.RDataFactory;
4950
import com.oracle.truffle.r.runtime.data.RList;
5051
import com.oracle.truffle.r.runtime.data.RNull;
@@ -93,7 +94,7 @@ protected Object convert(RAbstractVector v) {
9394
for (int i = v.getLength() - 1; i >= 0; i--) {
9495
Object element = v.getDataAtAsObject(i);
9596
adjustSharing(v, element);
96-
current = RDataFactory.createPairList(element, current, names != null ? RDataFactory.createSymbol(names.getDataAt(i)) : RNull.instance, gnurType);
97+
current = RDataFactory.createPairList(element, current, names != null ? RDataFactory.createSymbol(Utils.intern(names.getDataAt(i))) : RNull.instance, gnurType);
9798
}
9899
if (current != RNull.instance) {
99100
// also copy regular attributes

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RfEvalNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.oracle.truffle.r.runtime.data.RPromise;
5151
import com.oracle.truffle.r.runtime.data.RSymbol;
5252
import com.oracle.truffle.r.runtime.env.REnvironment;
53+
import com.oracle.truffle.r.runtime.env.frame.ActiveBinding;
5354

5455
public abstract class RfEvalNode extends FFIUpCallNode.Arg2 {
5556

@@ -104,6 +105,9 @@ Object handleSymbol(RSymbol expr, Object envArg,
104105
if (result == null) {
105106
throw RError.error(RError.NO_CALLER, UNKNOWN_OBJECT, expr.getName());
106107
}
108+
if (result instanceof ActiveBinding) {
109+
result = ((ActiveBinding) result).readValue();
110+
}
107111
return result;
108112
}
109113

com.oracle.truffle.r.native/fficall/src/common/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ GNUR_APPL_SRC = $(GNUR_HOME)/src/appl
3737
GNUR_APPL_F_FILES := $(notdir $(wildcard $(GNUR_APPL_SRC)/d*.f))
3838
GNUR_APPL_C_FILES := $(notdir $(wildcard $(GNUR_APPL_SRC)/*.c))
3939

40-
GNUR_MAIN_C_FILES = errors.c colors.c devices.c engine.c format.c graphics.c plot.c plot3d.c plotmath.c rlocale.c sort.c
40+
GNUR_MAIN_C_FILES = errors.c colors.c devices.c engine.c format.c graphics.c plot.c plot3d.c plotmath.c rlocale.c sort.c duplicate.c
4141
GNUR_MAIN_SRC = $(GNUR_HOME)/src/main
4242

4343
GNUR_UNIX_C_FILES = sys-std.c

com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ SEXP Rf_lengthgets(SEXP x, R_len_t y) {
668668

669669
SEXP Rf_xlengthgets(SEXP x, R_xlen_t y) {
670670
TRACE1(x);
671-
return unimplemented("Rf_xlengthgets");
671+
return Rf_lengthgets(x, y);
672672
}
673673

674674
SEXP R_lsInternal(SEXP env, Rboolean all) {
@@ -1139,8 +1139,7 @@ SEXP SET_VECTOR_ELT(SEXP x, R_xlen_t i, SEXP v) {
11391139

11401140
SEXP *STRING_PTR(SEXP x) {
11411141
TRACE0();
1142-
unimplemented("STRING_PTR");
1143-
return NULL;
1142+
return FASTR_DATAPTR(x);
11441143
}
11451144

11461145
SEXP * NORET VECTOR_PTR(SEXP x) {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* R : A Computer Language for Statistical Data Analysis
3+
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
4+
* (C) 2004 The R Foundation
5+
* Copyright (C) 1998--2015 The R Core Team.
6+
* Copyright (c) 2013, 2018, Oracle and/or its affiliates
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, a copy is available at
20+
* https://www.R-project.org/Licenses/
21+
*/
22+
23+
24+
#ifdef HAVE_CONFIG_H
25+
#include <config.h>
26+
#endif
27+
28+
#include "Defn.h"
29+
30+
#include <R_ext/RS.h> /* S4 bit */
31+
32+
#include "duplicate.h"
33+
34+
SEXP lazy_duplicate(SEXP s) {
35+
switch (TYPEOF(s)) {
36+
case NILSXP:
37+
case SYMSXP:
38+
case ENVSXP:
39+
case SPECIALSXP:
40+
case BUILTINSXP:
41+
case EXTPTRSXP:
42+
case BCODESXP:
43+
case WEAKREFSXP:
44+
case CHARSXP:
45+
case PROMSXP:
46+
break;
47+
case CLOSXP:
48+
case LISTSXP:
49+
case LANGSXP:
50+
case DOTSXP:
51+
case EXPRSXP:
52+
case VECSXP:
53+
case LGLSXP:
54+
case INTSXP:
55+
case REALSXP:
56+
case CPLXSXP:
57+
case RAWSXP:
58+
case STRSXP:
59+
case S4SXP:
60+
SET_NAMED(s, 2);
61+
break;
62+
default:
63+
UNIMPLEMENTED_TYPE("lazy_duplicate", s);
64+
}
65+
return s;
66+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* R : A Computer Language for Statistical Data Analysis
3+
* Copyright (C) 1995--2017 The R Core Team.
4+
* Copyright (c) 2013, 2018, Oracle and/or its affiliates
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, a copy is available at
18+
* https://www.R-project.org/Licenses/
19+
*/
20+
21+
#ifndef R_DUPLICATE_H
22+
#define R_DUPLICATE_H
23+
24+
#endif /* R_DUPLICATE_H */

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ protected RAbstractStringVector doSub(String patternArg, String replacementArg,
494494
if (fixed) {
495495
if (gsub) {
496496
replacement = replacement.replace("$", "\\$");
497+
replacement = convertGroups(replacement, 0);
497498
value = Pattern.compile(pattern, Pattern.LITERAL).matcher(input).replaceAll(replacement);
498499
} else {
499500
int ix = input.indexOf(pattern);
@@ -560,9 +561,9 @@ protected RAbstractStringVector doSub(String patternArg, String replacementArg,
560561
value = sb.toString();
561562
}
562563
} else {
563-
replacement = convertGroups(replacement);
564-
565564
Matcher matcher = Pattern.compile(pattern, Pattern.DOTALL).matcher(input);
565+
replacement = convertGroups(replacement, matcher.groupCount());
566+
566567
if (gsub) {
567568
value = matcher.replaceAll(replacement);
568569
} else {
@@ -712,7 +713,7 @@ private static void pcreStringAdj(StringBuilder sb, String input, String repl, i
712713
}
713714

714715
@TruffleBoundary
715-
private static String convertGroups(String value) {
716+
private static String convertGroups(String value, int groupCount) {
716717
StringBuilder result = new StringBuilder();
717718
int i = 0;
718719
while (i < value.length()) {
@@ -723,12 +724,14 @@ private static String convertGroups(String value) {
723724
result.append('\\');
724725
} else {
725726
c = value.charAt(i);
726-
if (c >= '0' && c <= '9') {
727-
result.append('$');
727+
if (c >= '1' && c <= '9') {
728+
int gi = c - '0';
729+
if (gi <= groupCount) {
730+
result.append('$').append(c);
731+
}
728732
} else {
729-
result.append('\\');
733+
result.append('\\').append(c);
730734
}
731-
result.append(c);
732735
}
733736
} else {
734737
result.append(c);

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntimeASTAccess.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public interface RRuntimeASTAccess {
4646

4747
/**
4848
* Returns the real caller associated with {@code rl}, by locating the {@code RSyntaxNode}
49-
* associated with the node stored with {@code rl}.
49+
* associated with the node stored with {@code rl}. It may return {@code null} if there is no
50+
* valid caller.
5051
*/
5152
RPairList getSyntaxCaller(RCaller rl);
5253

@@ -76,7 +77,8 @@ public interface RRuntimeASTAccess {
7677
* Convenience method for {@code getCallerSource(getSyntaxCaller(caller))}.
7778
*/
7879
default String getCallerSource(RCaller caller) {
79-
return getCallerSource(getSyntaxCaller(caller));
80+
final RPairList syntaxCaller = getSyntaxCaller(caller);
81+
return syntaxCaller == null ? "<invalid call>" : getCallerSource(syntaxCaller);
8082
}
8183

8284
/**

0 commit comments

Comments
 (0)