Class MemoryInstr

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

public final class MemoryInstr extends IRInstr
Specialized IR instruction for memory operations (LOAD, STORE, ALLOCA, REFERENCE).

Memory instructions handle variable access, allocation, and reference declaration in the EK9 IR.

  • Method Details

    • load

      public static MemoryInstr load(String destination, String sourceLocation)
      Create LOAD instruction: LOAD dest = source_location.
    • load

      public static MemoryInstr load(String destination, String sourceLocation, DebugInfo debugInfo)
      Create LOAD instruction with debug info: LOAD dest = source_location.
    • store

      public static MemoryInstr store(String destinationLocation, String source, DebugInfo debugInfo)
      Create STORE instruction with debug info: STORE dest_location = source.
    • loadField

      public static MemoryInstr loadField(String destination, String objectVar, String fieldName, String ownerType, String fieldType, DebugInfo debugInfo)
      Create LOAD_FIELD instruction: load field value from object. Format: LOAD_FIELD dest = objectVar, fieldName, ownerType, fieldType
      Parameters:
      destination - variable to store the field value
      objectVar - variable containing the object reference
      fieldName - name of the field to access
      ownerType - fully qualified type that owns the field
      fieldType - fully qualified type of the field
      debugInfo - source location
    • storeField

      public static MemoryInstr storeField(String objectVar, String fieldName, String ownerType, String fieldType, String value, DebugInfo debugInfo)
      Create STORE_FIELD instruction: store value into object field. Format: STORE_FIELD objectVar, fieldName, ownerType, fieldType, value
      Parameters:
      objectVar - variable containing the object reference
      fieldName - name of the field to store to
      ownerType - fully qualified type that owns the field
      fieldType - fully qualified type of the field
      value - variable or temp containing the value to store
      debugInfo - source location
    • reference

      public static MemoryInstr reference(String variableName, String typeInfo)
      Create REFERENCE instruction: REFERENCE variable_name, type_info.
    • reference

      public static MemoryInstr reference(String variableName, String typeInfo, DebugInfo debugInfo)
      Create REFERENCE instruction with debug info: REFERENCE variable_name, type_info.
    • retain

      public static MemoryInstr retain(String object, DebugInfo debugInfo)
      Create RETAIN instruction with debug info: RETAIN object, i.e. increment the ARC (automatic reference counting)
    • release

      public static MemoryInstr release(String object)
      Create RELEASE instruction: RELEASE object, decrement ARC.
    • release

      public static MemoryInstr release(String object, DebugInfo debugInfo)
      Create RELEASE instruction with debug info: RELEASE object, decrement ARC.
    • isNull

      public static MemoryInstr isNull(String result, String operand, DebugInfo debugInfo)
      Create IS_NULL instruction with debug info: IS_NULL result = operand.
    • loadConstant

      public static MemoryInstr loadConstant(String result, String constantName, String moduleName, String typeName, DebugInfo debugInfo)
      Create LOAD_CONSTANT instruction: load from module constant storage. Format: LOAD_CONSTANT result = constantName, moduleName, typeName
      Parameters:
      result - destination temp variable
      constantName - the constant's field name
      moduleName - the module where the constant is defined
      typeName - the constant's fully qualified type
      debugInfo - source location
    • loadStaticField

      public static MemoryInstr loadStaticField(String result, String fieldName, String ownerType, String fieldType, DebugInfo debugInfo)
      Create LOAD_STATIC_FIELD instruction: load static field from class. Format: LOAD_STATIC_FIELD result = fieldName, ownerType, fieldType

      Used for accessing static fields like enum constants (Colour.Red). Unlike LOAD_CONSTANT which assumes _Constants class, this loads from any class's static field.

      Parameters:
      result - destination temp variable
      fieldName - the static field name
      ownerType - fully qualified type that owns the static field
      fieldType - fully qualified type of the field
      debugInfo - source location
    • storeStaticField

      public static MemoryInstr storeStaticField(String fieldName, String ownerType, String fieldType, String value, DebugInfo debugInfo)
      Create STORE_STATIC_FIELD instruction: store value into static field. Format: STORE_STATIC_FIELD fieldName, ownerType, fieldType, value

      Used for initializing static fields like enum constants in c_init.

      Parameters:
      fieldName - the static field name
      ownerType - fully qualified type that owns the static field
      fieldType - fully qualified type of the field
      value - variable holding the value to store
      debugInfo - source location
    • functionInstance

      public static MemoryInstr functionInstance(String result, String functionType, DebugInfo debugInfo)
      Create FUNCTION_INSTANCE instruction with debug info: FUNCTION_INSTANCE result = FunctionType. Gets the singleton instance of the specified function type.
    • addOperand

      public MemoryInstr addOperand(String operand)
      Description copied from class: IRInstr
      Add operand to this instruction.
      Overrides:
      addOperand in class IRInstr
    • addOperands

      public MemoryInstr addOperands(String... operands)
      Description copied from class: IRInstr
      Add multiple operands to this instruction.
      Overrides:
      addOperands in class IRInstr