Class LocalAccessor

java.lang.Object
com.oracle.truffle.api.bytecode.LocalAccessor

public final class LocalAccessor extends Object
Operation parameter that allows an operation to get, set, and clear the value of a local.

To use a local accessor, declare a ConstantOperand on the operation. The corresponding builder method for the operation will take a BytecodeLocal argument for the local to be accessed. At run time, a LocalAccessor for the local will be supplied as a parameter to the operation.

Local accessors are useful to implement behaviour that cannot be implemented with the builtin local operations (like StoreLocal). For example, if an operation produces multiple outputs, it can write one of the outputs to a local using a local accessor. Prefer builtin operations when possible, since they automatically work with boxing elimination. Local accessors should be preferred over BytecodeNode helpers like BytecodeNode.getLocalValue(int, Frame, int), since the helpers use extra indirection.

All of the accessor methods take a bytecode node and the current frame. The bytecode node should be the current bytecode node and correspond to the root that declares the local; it should be compilation-final. The frame should contain the local.

Example usage:

 @Operation
 @ConstantOperand(type = LocalAccessor.class)
 public static final class GetLocal {
     @Specialization
     public static Object perform(VirtualFrame frame,
                     LocalAccessor accessor,
                     @Bind BytecodeNode bytecodeNode) {
         return accessor.getObject(bytecodeNode, frame);
     }
 }
 
Since:
24.2