Skip to content
Snippets Groups Projects
Commit 46f848f6 authored by Adam Welc's avatar Adam Welc
Browse files

Added handling of .Data slot for S4 objects.

parent 6951ae87
Branches
No related tags found
No related merge requests found
......@@ -17,7 +17,10 @@ import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.r.nodes.attributes.PutAttributeNode;
import com.oracle.truffle.r.nodes.attributes.PutAttributeNodeGen;
import com.oracle.truffle.r.nodes.function.ClassHierarchyNode;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.*;
import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.nodes.*;
@NodeChildren({@NodeChild(value = "object", type = RNode.class), @NodeChild(value = "name", type = RNode.class), @NodeChild(value = "value", type = RNode.class)})
......@@ -34,17 +37,39 @@ public abstract class UpdateSlotNode extends RNode {
}
@SuppressWarnings("unused")
@Specialization(guards = "name == cachedName")
@Specialization(guards = {"!isData(name)", "name == cachedName"})
protected Object updateSlotS4Cached(RAttributable object, String name, Object value, @Cached("name") String cachedName, @Cached("createAttrUpdate(cachedName)") PutAttributeNode attributeUpdate) {
attributeUpdate.execute(object.initAttributes(), value);
return object;
}
@Specialization(contains = "updateSlotS4Cached")
@Specialization(contains = "updateSlotS4Cached", guards = "!isData(name)")
protected Object updateSlotS4(RAttributable object, String name, Object value) {
assert name == name.intern();
object.setAttr(name, value);
return object;
}
protected RFunction setDataPartFunction(REnvironment methodsNamespace) {
Object f = methodsNamespace.findFunction("setDataPart");
return (RFunction) RContext.getRRuntimeASTAccess().forcePromise(f);
}
private Object setDataPart(RAttributable object, Object value) {
// TODO: any way to cache it or use a mechanism similar to overrides?
REnvironment methodsNamespace = REnvironment.getRegisteredNamespace("methods");
RFunction dataPart = setDataPartFunction(methodsNamespace);
return RContext.getEngine().evalFunction(dataPart, methodsNamespace.getFrame(), object, value, RRuntime.LOGICAL_TRUE);
}
@Specialization(guards = "isData(name)")
protected Object updateSlotS4Data(RAttributable object, @SuppressWarnings("unused") String name, Object value) {
return setDataPart(object, value);
}
protected boolean isData(String name) {
assert name == name.intern();
return name == RRuntime.DOT_DATA;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment