|
1 | 1 | /* |
2 | | - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
34 | 34 | import com.oracle.truffle.api.profiles.ConditionProfile; |
35 | 35 | import com.oracle.truffle.r.ffi.impl.nodes.AttributesAccessNodesFactory.ATTRIBNodeGen; |
36 | 36 | import com.oracle.truffle.r.ffi.impl.nodes.AttributesAccessNodesFactory.CopyMostAttribNodeGen; |
| 37 | +import com.oracle.truffle.r.ffi.impl.nodes.AttributesAccessNodesFactory.RfSetAttribNodeGen; |
37 | 38 | import com.oracle.truffle.r.ffi.impl.nodes.AttributesAccessNodesFactory.SetAttribNodeGen; |
38 | 39 | import com.oracle.truffle.r.ffi.impl.nodes.AttributesAccessNodesFactory.TAGNodeGen; |
39 | 40 | import com.oracle.truffle.r.nodes.attributes.CopyOfRegAttributesNode; |
40 | 41 | import com.oracle.truffle.r.nodes.attributes.GetAttributeNode; |
41 | 42 | import com.oracle.truffle.r.nodes.attributes.GetAttributesNode; |
| 43 | +import com.oracle.truffle.r.nodes.attributes.RemoveAttributeNode; |
42 | 44 | import com.oracle.truffle.r.nodes.attributes.SetAttributeNode; |
43 | 45 | import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.GetRowNamesAttributeNode; |
44 | 46 | import com.oracle.truffle.r.nodes.function.opt.UpdateShareableChildValueNode; |
@@ -91,6 +93,53 @@ private String castToString(Object name) { |
91 | 93 | } |
92 | 94 | } |
93 | 95 |
|
| 96 | + /** |
| 97 | + * Sets a single attribute. |
| 98 | + */ |
| 99 | + public abstract static class RfSetAttribNode extends FFIUpCallNode.Arg3 { |
| 100 | + @Child private CastNode castNameNode; |
| 101 | + |
| 102 | + public static RfSetAttribNode create() { |
| 103 | + return RfSetAttribNodeGen.create(); |
| 104 | + } |
| 105 | + |
| 106 | + @Specialization(guards = "!isNull(value)") |
| 107 | + protected Object setValue(RAttributable target, Object name, Object value, |
| 108 | + @Cached("create()") SetAttributeNode setAttribNode) { |
| 109 | + setAttribNode.execute(target, (String) getCastNameNode().doCast(name), value); |
| 110 | + return RNull.instance; |
| 111 | + } |
| 112 | + |
| 113 | + @Specialization |
| 114 | + protected Object setValue(@SuppressWarnings("unused") RNull target, @SuppressWarnings("unused") Object name, @SuppressWarnings("unused") Object value) { |
| 115 | + return RNull.instance; |
| 116 | + } |
| 117 | + |
| 118 | + @Specialization |
| 119 | + protected Object unsetValue(RAttributable target, Object name, @SuppressWarnings("unused") RNull nullVal, |
| 120 | + @Cached("create()") RemoveAttributeNode removeAttributeNode) { |
| 121 | + removeAttributeNode.execute(target, (String) getCastNameNode().doCast(name)); |
| 122 | + return RNull.instance; |
| 123 | + } |
| 124 | + |
| 125 | + @Fallback |
| 126 | + protected Object others(Object target, Object name, Object value) { |
| 127 | + throw unsupportedTypes("Rf_setAttrib", target, name, value); |
| 128 | + } |
| 129 | + |
| 130 | + protected static boolean isNull(Object o) { |
| 131 | + return o == RNull.instance; |
| 132 | + } |
| 133 | + |
| 134 | + private CastNode getCastNameNode() { |
| 135 | + if (castNameNode == null) { |
| 136 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 137 | + castNameNode = insert(newCastBuilder().asStringVector().findFirst().buildCastNode()); |
| 138 | + } |
| 139 | + return castNameNode; |
| 140 | + } |
| 141 | + } |
| 142 | + |
94 | 143 | public abstract static class ATTRIB extends FFIUpCallNode.Arg1 { |
95 | 144 |
|
96 | 145 | @Specialization |
@@ -208,6 +257,10 @@ public static CopyMostAttrib create() { |
208 | 257 | } |
209 | 258 | } |
210 | 259 |
|
| 260 | + /** |
| 261 | + * Overrides the attributes pairlist of given object with a new pairlist. In FastR, we have to |
| 262 | + * convert the pairlist to our representation. |
| 263 | + */ |
211 | 264 | public abstract static class SetAttribNode extends FFIUpCallNode.Arg2 { |
212 | 265 |
|
213 | 266 | public static SetAttribNode create() { |
|
0 commit comments