Skip to content

Commit 72d639c

Browse files
committed
[GR-20016] Made RRaw interop capable.
PullRequest: fastr/2422
2 parents 39486ec + c87c920 commit 72d639c

File tree

5 files changed

+85
-150
lines changed

5 files changed

+85
-150
lines changed

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RInteropRaw.java

Lines changed: 0 additions & 133 deletions
This file was deleted.

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRaw.java

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@
2323
package com.oracle.truffle.r.runtime.data;
2424

2525
import com.oracle.truffle.api.CompilerDirectives.ValueType;
26+
import com.oracle.truffle.api.interop.InteropLibrary;
27+
import com.oracle.truffle.api.interop.UnsupportedMessageException;
28+
import com.oracle.truffle.api.library.ExportLibrary;
29+
import com.oracle.truffle.api.library.ExportMessage;
2630
import com.oracle.truffle.r.runtime.RRuntime;
2731

2832
@ValueType
29-
public final class RRaw {
33+
@ExportLibrary(InteropLibrary.class)
34+
public final class RRaw implements RTruffleObject {
3035

31-
protected final byte value;
36+
private final byte value;
3237

3338
RRaw(byte value) {
3439
this.value = value;
@@ -38,6 +43,79 @@ public byte getValue() {
3843
return value;
3944
}
4045

46+
@SuppressWarnings("static-method")
47+
@ExportMessage
48+
public boolean isNumber() {
49+
return true;
50+
}
51+
52+
@SuppressWarnings("static-method")
53+
@ExportMessage
54+
public boolean fitsInByte() {
55+
return true;
56+
}
57+
58+
@SuppressWarnings("static-method")
59+
@ExportMessage
60+
public byte asByte() {
61+
return getValue();
62+
}
63+
64+
@SuppressWarnings("static-method")
65+
@ExportMessage
66+
public boolean fitsInShort() {
67+
return true;
68+
}
69+
70+
@ExportMessage
71+
public short asShort() throws UnsupportedMessageException {
72+
return getInterop().asShort(getValue());
73+
}
74+
75+
@SuppressWarnings("static-method")
76+
@ExportMessage
77+
public boolean fitsInInt() {
78+
return true;
79+
}
80+
81+
@ExportMessage
82+
public int asInt() throws UnsupportedMessageException {
83+
return getInterop().asInt(getValue());
84+
}
85+
86+
@SuppressWarnings("static-method")
87+
@ExportMessage
88+
public boolean fitsInLong() {
89+
return true;
90+
}
91+
92+
@ExportMessage
93+
public long asLong() throws UnsupportedMessageException {
94+
return getInterop().asLong(getValue());
95+
}
96+
97+
@SuppressWarnings("static-method")
98+
@ExportMessage
99+
public boolean fitsInFloat() {
100+
return true;
101+
}
102+
103+
@ExportMessage
104+
public float asFloat() throws UnsupportedMessageException {
105+
return getInterop().asFloat(getValue());
106+
}
107+
108+
@SuppressWarnings("static-method")
109+
@ExportMessage
110+
public boolean fitsInDouble() {
111+
return true;
112+
}
113+
114+
@ExportMessage
115+
public double asDouble() throws UnsupportedMessageException {
116+
return getInterop().asDouble(getValue());
117+
}
118+
41119
@Override
42120
public boolean equals(Object obj) {
43121
if (obj instanceof RRaw) {
@@ -60,4 +138,7 @@ public static RRaw valueOf(byte value) {
60138
return new RRaw(value);
61139
}
62140

141+
private InteropLibrary getInterop() {
142+
return InteropLibrary.getFactory().create(getValue());
143+
}
63144
}

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/interop/Foreign2R.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.oracle.truffle.r.runtime.RRuntime;
3939
import com.oracle.truffle.r.runtime.data.RInteropComplex;
4040
import com.oracle.truffle.r.runtime.data.RInteropNA;
41-
import com.oracle.truffle.r.runtime.data.RInteropRaw;
4241
import com.oracle.truffle.r.runtime.data.RNull;
4342

4443
/**
@@ -131,11 +130,6 @@ public Object doInteropComplex(RInteropComplex interopComplex, @SuppressWarnings
131130
return interopComplex.getValue();
132131
}
133132

134-
@Specialization
135-
public Object doInteropRaw(RInteropRaw interopRaw, @SuppressWarnings("unused") boolean preserveByte, @SuppressWarnings("unused") boolean printWarning) {
136-
return interopRaw.getValue();
137-
}
138-
139133
@Specialization(guards = "isNA(d)")
140134
public double doDoubleNA(@SuppressWarnings("unused") double d, @SuppressWarnings("unused") boolean preserveByte, @SuppressWarnings("unused") boolean printWarning) {
141135
return Double.NaN;

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/interop/R2Foreign.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.oracle.truffle.r.runtime.data.RInteropComplex;
3636
import com.oracle.truffle.r.runtime.data.RInteropNA;
3737
import com.oracle.truffle.r.runtime.data.RInteropNA.RInteropComplexNA;
38-
import com.oracle.truffle.r.runtime.data.RInteropRaw;
3938
import com.oracle.truffle.r.runtime.data.RInteropScalar.RInteropByte;
4039
import com.oracle.truffle.r.runtime.data.RInteropScalar.RInteropChar;
4140
import com.oracle.truffle.r.runtime.data.RInteropScalar.RInteropFloat;
@@ -154,11 +153,6 @@ public Object doRawNoBox(RRaw vec, @SuppressWarnings("unused") boolean boxPrimit
154153
return vec.getValue();
155154
}
156155

157-
@Specialization(guards = "boxPrimitives")
158-
public Object doRawBox(RRaw vec, @SuppressWarnings("unused") boolean boxPrimitives) {
159-
return new RInteropRaw(vec);
160-
}
161-
162156
@Specialization
163157
public byte doInteroptByte(RInteropByte obj, @SuppressWarnings("unused") boolean boxPrimitives) {
164158
return obj.getValue();

com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/interop/RRawInteropTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package com.oracle.truffle.r.test.engine.interop;
2424

2525
import com.oracle.truffle.api.interop.TruffleObject;
26-
import com.oracle.truffle.r.runtime.data.RInteropRaw;
2726
import com.oracle.truffle.r.runtime.data.RRaw;
2827
import org.junit.Test;
2928

@@ -46,7 +45,7 @@ protected boolean shouldTestToNative(TruffleObject obj) {
4645

4746
@Override
4847
protected TruffleObject[] createTruffleObjects() throws Exception {
49-
return new TruffleObject[]{new RInteropRaw(RRaw.valueOf((byte) 1))};
48+
return new TruffleObject[]{RRaw.valueOf((byte) 1)};
5049
}
5150

5251
@Test
@@ -57,7 +56,7 @@ public void testIsNull() throws Exception {
5756

5857
@Override
5958
protected Object getUnboxed(TruffleObject obj) {
60-
return ((RRaw) ((RInteropRaw) obj).getValue()).getValue();
59+
return ((RRaw) obj).getValue();
6160
}
6261

6362
@Override

0 commit comments

Comments
 (0)