Skip to content
Snippets Groups Projects
Commit 186cc3bd authored by Mick Jordan's avatar Mick Jordan
Browse files

Merge

parents 878d7f7c 7e3415d9
Branches
No related tags found
No related merge requests found
......@@ -22,27 +22,21 @@
*/
package com.oracle.truffle.r.engine.interop;
import com.oracle.truffle.api.*;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.interop.*;
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.api.utilities.*;
import com.oracle.truffle.r.engine.*;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.r.engine.TruffleRLanguage;
import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode;
import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode;
import com.oracle.truffle.r.nodes.builtin.base.InfixEmulationFunctions.AccessArraySubscriptBuiltin;
import com.oracle.truffle.r.nodes.builtin.base.InfixEmulationFunctionsFactory.AccessArraySubscriptBuiltinNodeGen;
import com.oracle.truffle.r.runtime.*;
import com.oracle.truffle.r.runtime.data.*;
import com.oracle.truffle.r.runtime.data.model.*;
import com.oracle.truffle.r.runtime.data.RLogical;
public class VectorReadNode extends RootNode {
@CompilationFinal private boolean lengthAccess;
@Child private AccessArraySubscriptBuiltin builtin;
private final BranchProfile intIndex = BranchProfile.create();
private final BranchProfile doubleIndex = BranchProfile.create();
private final BranchProfile longIndex = BranchProfile.create();
@Child private ExtractVectorNode extract = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true);
public VectorReadNode() {
super(TruffleRLanguage.class, null, null);
......@@ -52,44 +46,8 @@ public class VectorReadNode extends RootNode {
@Override
public Object execute(VirtualFrame frame) {
Object label = ForeignAccess.getArguments(frame).get(0);
if (lengthAccess && !(label instanceof String)) {
CompilerDirectives.transferToInterpreter();
lengthAccess = false;
}
if (!lengthAccess && (label instanceof String)) {
CompilerDirectives.transferToInterpreter();
lengthAccess = true;
}
RAbstractVector arg = (RAbstractVector) ForeignAccess.getReceiver(frame);
if (lengthAccess) {
if (label.equals("length")) {
return arg.getLength();
} else {
CompilerDirectives.transferToInterpreter();
throw RInternalError.shouldNotReachHere("unknown message: " + label);
}
} else {
if (builtin == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
builtin = insert(AccessArraySubscriptBuiltinNodeGen.create(null, null, null));
}
int index;
if (label instanceof Integer) {
intIndex.enter();
index = (int) label;
} else if (label instanceof Long) {
longIndex.enter();
index = (int) (long) label;
} else if (label instanceof Double) {
doubleIndex.enter();
index = (int) (double) label;
} else {
CompilerDirectives.transferToInterpreter();
throw RInternalError.shouldNotReachHere("invalid index type: " + label);
}
return builtin.execute(frame, arg, new RArgsValuesAndNames(new Object[]{index + 1}, ArgumentsSignature.empty(1)), RRuntime.LOGICAL_TRUE, RRuntime.LOGICAL_TRUE);
}
Object receiver = ForeignAccess.getReceiver(frame);
return extract.apply(frame, receiver, new Object[]{label}, RLogical.TRUE, RLogical.TRUE);
}
}
......@@ -22,21 +22,22 @@
*/
package com.oracle.truffle.r.engine.interop;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.interop.*;
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.r.engine.*;
import com.oracle.truffle.r.runtime.data.model.*;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.r.engine.TruffleRLanguage;
import com.oracle.truffle.r.nodes.control.RLengthNode;
public class VectorSizeNode extends RootNode {
@Child private RLengthNode lengthNode = RLengthNode.create();
public VectorSizeNode() {
super(TruffleRLanguage.class, null, null);
}
@Override
public Object execute(VirtualFrame frame) {
RAbstractVector arg = (RAbstractVector) ForeignAccess.getReceiver(frame);
return arg.getLength();
return lengthNode.executeInteger(frame, ForeignAccess.getReceiver(frame));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment