Skip to content
Snippets Groups Projects
Commit b7106b9a authored by Zbyněk Šlajchrt's avatar Zbyněk Šlajchrt
Browse files

[GR-2798] Enabling Polyglot SDK tests for FastR.

PullRequest: fastr/1097
parents 4963eac0 8114c795
No related branches found
No related tags found
No related merge requests found
......@@ -242,6 +242,18 @@ public class ListMR {
protected abstract Object execute(VirtualFrame frame, TruffleObject receiver, Object idx);
@Specialization
protected Object read(VirtualFrame frame, TruffleObject receiver, double idx,
@Cached("createKeyInfoNode()") ListKeyInfoImplNode keyInfo) {
return read(frame, receiver, (int) idx, keyInfo);
}
@Specialization
protected Object read(VirtualFrame frame, TruffleObject receiver, long idx,
@Cached("createKeyInfoNode()") ListKeyInfoImplNode keyInfo) {
return read(frame, receiver, (int) idx, keyInfo);
}
@Specialization
protected Object read(VirtualFrame frame, TruffleObject receiver, int idx,
@Cached("createKeyInfoNode()") ListKeyInfoImplNode keyInfo) {
......
......@@ -180,6 +180,7 @@ public abstract class ExtractVectorNode extends RBaseNode {
protected Object accessFieldByVectorPositions(TruffleObject object, Object[] positions, @SuppressWarnings("unused") Object exact, @SuppressWarnings("unused") Object dropDimensions,
@Cached("READ.createNode()") Node foreignRead,
@Cached("KEY_INFO.createNode()") Node keyInfoNode,
@Cached("HAS_SIZE.createNode()") Node hasSizeNode,
@Cached("create()") CastStringNode castNode,
@Cached("createFirstString()") FirstStringNode firstString,
@Cached("IS_NULL.createNode()") Node isNullNode,
......@@ -192,7 +193,7 @@ public abstract class ExtractVectorNode extends RBaseNode {
try {
for (int i = 0; i < vec.getLength(); i++) {
Object res = read(this, vec.getDataAtAsObject(i), foreignRead, keyInfoNode, object, firstString, castNode);
Object res = read(this, vec.getDataAtAsObject(i), foreignRead, keyInfoNode, hasSizeNode, object, firstString, castNode);
if (RRuntime.isForeignObject(res)) {
if (ForeignAccess.sendIsNull(isNullNode, (TruffleObject) res)) {
res = RNull.instance;
......@@ -214,6 +215,7 @@ public abstract class ExtractVectorNode extends RBaseNode {
protected Object accessField(TruffleObject object, Object[] positions, @SuppressWarnings("unused") Object exact, @SuppressWarnings("unused") Object dropDimensions,
@Cached("READ.createNode()") Node foreignRead,
@Cached("KEY_INFO.createNode()") Node keyInfoNode,
@Cached("HAS_SIZE.createNode()") Node hasSizeNode,
@Cached("positions.length") @SuppressWarnings("unused") int cachedLength,
@Cached("create()") CastStringNode castNode,
@Cached("createFirstString()") FirstStringNode firstString,
......@@ -230,7 +232,7 @@ public abstract class ExtractVectorNode extends RBaseNode {
// TODO implicite unboxing ok? method calls seem to behave this way
Object result = object;
for (int i = 0; i < pos.length; i++) {
result = read(this, pos[i], foreignRead, keyInfoNode, (TruffleObject) result, firstString, castNode);
result = read(this, pos[i], foreignRead, keyInfoNode, hasSizeNode, (TruffleObject) result, firstString, castNode);
if (pos.length > 1 && i < pos.length - 1) {
assert result instanceof TruffleObject;
}
......@@ -253,7 +255,7 @@ public abstract class ExtractVectorNode extends RBaseNode {
return foreign2RNode.execute(obj);
}
public static Object read(RBaseNode caller, Object positions, Node foreignRead, Node keyInfoNode, TruffleObject object, FirstStringNode firstString, CastStringNode castNode)
public static Object read(RBaseNode caller, Object positions, Node foreignRead, Node keyInfoNode, Node hasSizeNode, TruffleObject object, FirstStringNode firstString, CastStringNode castNode)
throws RError, InteropException {
Object pos = positions;
if (pos instanceof Integer) {
......@@ -271,7 +273,7 @@ public abstract class ExtractVectorNode extends RBaseNode {
}
int info = ForeignAccess.sendKeyInfo(keyInfoNode, object, pos);
if (KeyInfo.isReadable(info)) {
if (KeyInfo.isReadable(info) || ForeignAccess.sendHasSize(hasSizeNode, object)) {
return ForeignAccess.sendRead(foreignRead, object, pos);
} else if (pos instanceof String && !KeyInfo.isExisting(info) && JavaInterop.isJavaObject(Object.class, object)) {
TruffleObject clazz = toJavaClass(object);
......
......@@ -104,7 +104,8 @@ public abstract class ReplaceVectorNode extends RBaseNode {
protected Object accessField(TruffleObject object, Object[] positions, Object value,
@Cached("WRITE.createNode()") Node foreignWrite,
@Cached("READ.createNode()") Node foreignRead,
@Cached("KEY_INFO.createNode()") Node keyInfo,
@Cached("KEY_INFO.createNode()") Node keyInfoNode,
@Cached("HAS_SIZE.createNode()") Node hasSizeNode,
@SuppressWarnings("unused") @Cached("positions.length") int cachedLength,
@Cached("create()") CastStringNode castNode,
@Cached("createFirstString()") FirstStringNode firstString,
......@@ -113,16 +114,17 @@ public abstract class ReplaceVectorNode extends RBaseNode {
try {
TruffleObject result = object;
for (int i = 0; i < positions.length - 1; i++) {
result = (TruffleObject) ExtractVectorNode.read(this, positions[i], foreignRead, keyInfo, result, firstString, castNode);
result = (TruffleObject) ExtractVectorNode.read(this, positions[i], foreignRead, keyInfoNode, hasSizeNode, result, firstString, castNode);
}
write(positions[positions.length - 1], foreignWrite, keyInfo, result, writtenValue, firstString, castNode, r2Foreign);
write(positions[positions.length - 1], foreignWrite, keyInfoNode, hasSizeNode, result, writtenValue, firstString, castNode, r2Foreign);
return object;
} catch (InteropException e) {
throw RError.interopError(RError.findParentRBase(this), e, object);
}
}
private void write(Object position, Node foreignWrite, Node keyInfoNode, TruffleObject object, Object writtenValue, FirstStringNode firstString, CastStringNode castNode, R2Foreign r2Foreign)
private void write(Object position, Node foreignWrite, Node keyInfoNode, Node hasSizeNode, TruffleObject object, Object writtenValue, FirstStringNode firstString, CastStringNode castNode,
R2Foreign r2Foreign)
throws InteropException, RError {
Object pos = position;
if (pos instanceof Integer) {
......@@ -141,7 +143,8 @@ public abstract class ReplaceVectorNode extends RBaseNode {
}
int info = ForeignAccess.sendKeyInfo(keyInfoNode, object, pos);
if (KeyInfo.isWritable(info)) {
if (KeyInfo.isWritable(info) || ForeignAccess.sendHasSize(hasSizeNode, object) ||
(pos instanceof String && !JavaInterop.isJavaObject(Object.class, object))) {
ForeignAccess.sendWrite(foreignWrite, object, pos, r2Foreign.execute(writtenValue));
return;
} else if (pos instanceof String && !KeyInfo.isExisting(info) && JavaInterop.isJavaObject(Object.class, object)) {
......
......@@ -77,12 +77,12 @@ public class ListMRTest extends AbstractMRTest {
assertEquals(1, ForeignAccess.sendRead(Message.READ.createNode(), l, 0));
assertEquals(2.1, ForeignAccess.sendRead(Message.READ.createNode(), l, 1));
assertEquals(4d, ForeignAccess.sendRead(Message.READ.createNode(), l, 5d));
assertEquals(true, ForeignAccess.sendRead(Message.READ.createNode(), l, 2));
assertTrue(ForeignAccess.sendRead(Message.READ.createNode(), l, 4) instanceof RNull);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), l, -1), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), l, 0f), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), l, 4d), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), l, "nnnoooonnne"), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), l, 100), UnknownIdentifierException.class);
......
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