Class DynamicObject.PutNode
java.lang.Object
com.oracle.truffle.api.nodes.Node
com.oracle.truffle.api.object.DynamicObject.PutNode
- All Implemented Interfaces:
NodeInterface, Cloneable
- Enclosing class:
DynamicObject
Sets the value of an existing property or adds a new property if no such property exists.
Additional variants allow setting property flags, only setting the property if it's either
absent or present, and setting constant properties stored in the shape.
- Since:
- 25.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Node
Node.Child, Node.Children -
Method Summary
Modifier and TypeMethodDescriptionstatic DynamicObject.PutNodecreate()final voidexecute(DynamicObject receiver, Object key, Object value) Sets the value of an existing property or adds a new property if no such property exists.final booleanexecuteIfAbsent(DynamicObject receiver, Object key, Object value) Sets the value of the property if absent, otherwise returnsfalse.final booleanexecuteIfPresent(DynamicObject receiver, Object key, Object value) Sets the value of the property if present, otherwise returnsfalse.final voidexecuteWithFlags(DynamicObject receiver, Object key, Object value, int propertyFlags) Likeexecute(DynamicObject, Object, Object), but additionally assigns flags to the property.final booleanexecuteWithFlagsIfAbsent(DynamicObject receiver, Object key, Object value, int propertyFlags) LikeexecuteIfAbsent(DynamicObject, Object, Object)but also sets property flags.final booleanexecuteWithFlagsIfPresent(DynamicObject receiver, Object key, Object value, int propertyFlags) LikeexecuteIfPresent(DynamicObject, Object, Object)but also sets property flags.static DynamicObject.PutNodeMethods inherited from class Node
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, reportReplace, toString
-
Method Details
-
execute
Sets the value of an existing property or adds a new property if no such property exists. A newly added property will have flags 0; flags of existing properties will not be changed. UseexecuteWithFlags(DynamicObject, Object, Object, int)to set property flags as well.Usage examples:
Simple use of
DynamicObject.PutNodewith a pre-interned symbol key.abstract static class SetSimpleNode extends Node { abstract Object execute(DynamicObject receiver, Object key, Object value); @Specialization static Object doCached(MyDynamicObjectSubclass receiver, Symbol key, Object value, @Cached DynamicObject.PutNode putNode) { putNode.execute(receiver, key, value); return value; } }Simple use of
DynamicObject.PutNodewith a string key cached by equality.abstract static class SetStringKeyNode extends Node { abstract Object execute(DynamicObject receiver, Object key, Object value); @Specialization(guards = "equalNode.execute(key, cachedKey, UTF_16)", limit = "3") static Object doCached(MyDynamicObjectSubclass receiver, TruffleString key, Object value, @Cached("key") TruffleString cachedKey, @Cached TruffleString.EqualNode equalNode, @Cached DynamicObject.PutNode putNode) { putNode.execute(receiver, cachedKey, value); return value; } }- Parameters:
key- the property key, compared by identity (==), not equality (equals). SeeDynamicObjectfor more information.value- the value to be set- See Also:
-
executeIfPresent
Sets the value of the property if present, otherwise returnsfalse.- Parameters:
key- property identifiervalue- value to be set- Returns:
trueif the property was present and the value set, otherwisefalse- See Also:
-
executeIfAbsent
Sets the value of the property if absent, otherwise returnsfalse.- Parameters:
key- property identifiervalue- value to be set- Returns:
trueif the property was absent and the value set, otherwisefalse- See Also:
-
executeWithFlags
public final void executeWithFlags(DynamicObject receiver, Object key, Object value, int propertyFlags) Likeexecute(DynamicObject, Object, Object), but additionally assigns flags to the property. If the property already exists, its flags will be updated before the value is set.- Parameters:
key- property identifiervalue- value to be setpropertyFlags- flags to be set- See Also:
-
executeWithFlagsIfPresent
public final boolean executeWithFlagsIfPresent(DynamicObject receiver, Object key, Object value, int propertyFlags) LikeexecuteIfPresent(DynamicObject, Object, Object)but also sets property flags. -
executeWithFlagsIfAbsent
public final boolean executeWithFlagsIfAbsent(DynamicObject receiver, Object key, Object value, int propertyFlags) LikeexecuteIfAbsent(DynamicObject, Object, Object)but also sets property flags. -
create
- Since:
- 25.1
-
getUncached
- Since:
- 25.1
-