Class OwnershipInstr

java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
org.ek9lang.compiler.ir.instructions.OwnershipInstr
All Implemented Interfaces:
INode

public final class OwnershipInstr extends IRInstr
The ownership form of the IR (EK9_IR_OWNERSHIP_MODEL.md ยง10): OWN, DROP, DROP_AT_EXIT, SLOT_DECLARE, SLOT_ASSIGN, FIELD_ASSIGN. Ownership is stated per value, slot and field, so nothing is implied by the position of a RETAIN. No back end reads these: OwnershipLowering rewrites them into today's opcodes at the end of IR_OPTIMISATION.

Rendering follows every other instruction - OPCODE operand, operand - with the facts that are not operands appended in brackets: SLOT_ASSIGN total, _temp4 [consume, init].

  • Field Details

  • Method Details

    • own

      public static OwnershipInstr own(String value, DebugInfo debugInfo)
      OWN value: a new OWNED reference to the value's object (lowered: RETAIN).
    • drop

      public static OwnershipInstr drop(String value, DebugInfo debugInfo)
      DROP value: the end of an OWNED value on this path (lowered: RELEASE).
    • dropAtExit

      public static OwnershipInstr dropAtExit(String value, String scopeId, DebugInfo debugInfo)
      DROP_AT_EXIT value, scope: the end of an OWNED value at every exit of the scope's current activation (lowered: SCOPE_REGISTER).
    • slotDeclare

      public static OwnershipInstr slotDeclare(String slot, String type, String owner, boolean typed, DebugInfo debugInfo)
      SLOT_DECLARE slot, type, owner [typed]: an empty slot owned by a scope, or by CALLER.
    • slotAssign

      public static OwnershipInstr slotAssign(String slot, String value, OwnershipInstr.AssignMode mode, boolean init, DebugInfo debugInfo)
      SLOT_ASSIGN slot, value [consume|copy] [init]: drop the slot's value (unless init - a fact that it is empty) and store the new one.
    • fieldAssign

      public static OwnershipInstr fieldAssign(String objectVar, String fieldName, String ownerType, String fieldType, String value, int fieldIndex, OwnershipInstr.AssignMode mode, boolean init, DebugInfo debugInfo)
      FIELD_ASSIGN object, field, ownerType, fieldType, value, index [consume|copy] [init]: drop the field's value and store the new one. The field is described exactly as STORE_FIELD describes it. [init] is the same fact as on SLOT_ASSIGN: the field is provably empty here (a constructor's first store into it), so there is nothing to drop.
    • staticFieldAssign

      public static OwnershipInstr staticFieldAssign(String fieldName, String ownerType, String fieldType, String value, OwnershipInstr.AssignMode mode, boolean init, DebugInfo debugInfo)
      STATIC_FIELD_ASSIGN field, ownerType, fieldType, value [consume|copy] [init]: store into a static field, described exactly as STORE_STATIC_FIELD describes it.
    • staticFieldTake

      public static OwnershipInstr staticFieldTake(String result, String fieldName, String ownerType, String fieldType, DebugInfo debugInfo)
      result = STATIC_FIELD_TAKE field, ownerType, fieldType: the static's value, OWNED - its count moves to the result.
    • getValue

      public String getValue()
      The value this instruction acts on: OWN/DROP/DROP_AT_EXIT's operand, the value assigned by SLOT_ASSIGN, FIELD_ASSIGN and STATIC_FIELD_ASSIGN; null for SLOT_DECLARE and STATIC_FIELD_TAKE (whose value is its result).
    • getSlot

      public String getSlot()
      The slot declared or assigned (SLOT_DECLARE, SLOT_ASSIGN); null otherwise.
    • getScopeId

      public String getScopeId()
      The scope of DROP_AT_EXIT, or the owner (a scope id or CALLER) of SLOT_DECLARE; null otherwise.
    • getType

      public String getType()
      The declared type of a SLOT_DECLARE; null otherwise.
    • isCallerOwned

      public boolean isCallerOwned()
      True when the slot is owned by the caller (a parameter or the return variable).
    • isRegionOwned

      public boolean isRegionOwned()
      True when the slot is owned by a region - dropped at that region's exit - rather than by the CALLER or the OBJECT.
    • getFieldOperands

      public List<String> getFieldOperands()
      FIELD_ASSIGN's field description in STORE_FIELD order: object, field name, owner type, field type, and the index when the field is stored by index (absent where STORE_FIELD looks it up by name).
    • getMode

      public OwnershipInstr.AssignMode getMode()
      CONSUME or COPY for an assignment; null otherwise.
    • isTyped

      public boolean isTyped()
      True when SLOT_DECLARE carries [typed] (lowered to TYPED_REFERENCE).
    • isInit

      public boolean isInit()
      True when SLOT_ASSIGN or FIELD_ASSIGN carries the [init] fact: the slot or field is provably empty, nothing to drop.
    • toString

      public String toString()
      Overrides:
      toString in class IRInstr
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class IRInstr
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class IRInstr