Annotation Interface Executed


@Retention(CLASS) @Target(FIELD) public @interface Executed
This annotation declares a child field to be executed and used as dynamic input values for specializations. The field must have package protected, protected or public visibility for the generated subclass to access the field. The field must be manually initialized. If the value was not initialized the execution of the node will fail with a NullPointerException. A field must also be annotated with Node.Child or Node.Children.

Example usage:

 abstract class ExpressionNode extends Node {
     abstract Object execute();
 }

 abstract class AddNode extends ExpressionNode {

     @Child @Executed ExpressionNode leftNode;
     @Child @Executed ExpressionNode rightNode;

     AddNode(ExpressionNode leftNode, ExpressionNode rightNode) {
         this.leftNode = leftNode;
         this.rightNode = rightNode;
     }

     @Specialization
     protected int doAdd(int left, int right) {
         return left + right;
     }

 }
 
Since:
0.33
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The with() property allows a node to pass the result of one child's executable as an input to another child's executable.
  • Element Details

    • with

      String[] with
      The with() property allows a node to pass the result of one child's executable as an input to another child's executable. These referenced children must be defined before the current node in the execution order. The static field type must declare execute methods with as many arguments as there values specified for with(). Frame, VirtualFrame and MaterializedFrame instances are passed along implicitly and do not count as argument. Example usage:
       abstract class ExpressionNode extends Node {
           abstract Object execute();
       }
      
       abstract class ExecuteWithTargetNode extends Node {
           abstract Object execute(Object target);
       }
      
       abstract class CallNode extends ExpressionNode {
      
           @Child @Executed ExpressionNode targetNode;
           @Child @Executed(with = "targetNode") ExecuteWithTargetNode readProperty;
      
           CallNode(ExpressionNode targetNode, ExecuteWithTargetNode readProperty) {
               this.targetNode = targetNode;
               this.readProperty = readProperty;
           }
      
           @Specialization
           protected Object doCall(Object target, Object property) {
               // targetNode is executed once and its value is usable in readProperty
           }
       }
      
       
      Since:
      0.33
      Default:
      {}