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

public abstract static class DynamicObject.PutNode extends Node
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:
  • Method Details

    • execute

      public final void execute(DynamicObject receiver, Object key, Object value)
      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. Use executeWithFlags(DynamicObject, Object, Object, int) to set property flags as well.

      Usage examples:

      Simple use of DynamicObject.PutNode with 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.PutNode with 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). See DynamicObject for more information.
      value - the value to be set
      See Also:
    • executeIfPresent

      public final boolean executeIfPresent(DynamicObject receiver, Object key, Object value)
      Sets the value of the property if present, otherwise returns false.
      Parameters:
      key - property identifier
      value - value to be set
      Returns:
      true if the property was present and the value set, otherwise false
      See Also:
    • executeIfAbsent

      public final boolean executeIfAbsent(DynamicObject receiver, Object key, Object value)
      Sets the value of the property if absent, otherwise returns false.
      Parameters:
      key - property identifier
      value - value to be set
      Returns:
      true if the property was absent and the value set, otherwise false
      See Also:
    • executeWithFlags

      public final void executeWithFlags(DynamicObject receiver, Object key, Object value, int propertyFlags)
      Like execute(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 identifier
      value - value to be set
      propertyFlags - flags to be set
      See Also:
    • executeWithFlagsIfPresent

      public final boolean executeWithFlagsIfPresent(DynamicObject receiver, Object key, Object value, int propertyFlags)
      Like executeIfPresent(DynamicObject, Object, Object) but also sets property flags.
    • executeWithFlagsIfAbsent

      public final boolean executeWithFlagsIfAbsent(DynamicObject receiver, Object key, Object value, int propertyFlags)
      Like executeIfAbsent(DynamicObject, Object, Object) but also sets property flags.
    • create

      public static DynamicObject.PutNode create()
      Since:
      25.1
    • getUncached

      public static DynamicObject.PutNode getUncached()
      Since:
      25.1