Class IRGenerationStack

java.lang.Object
org.ek9lang.compiler.phase7.generation.IRGenerationStack

public class IRGenerationStack extends Object
Stack-based scope, debug, and context management for IR generation.

This stack provides the transient context management that eliminates parameter threading throughout the IR generation process. Modeled after the successful ScopeStack pattern used in phases 1-6.

Each frame on the stack represents a scope context (method, function, block, expression) with its associated scope ID, debug information, and other contextual information needed for IR generation.

The stack automatically handles nested scope management and provides navigation capabilities to find containing scopes of specific types.

  • Constructor Details

    • IRGenerationStack

      public IRGenerationStack(IRStackFrame baseFrame)
      Create a new IR generation stack with a base frame.
  • Method Details

    • getVeryBaseFrame

      public IRStackFrame getVeryBaseFrame()
      Get the very base frame of the stack (usually module level).
    • push

      public IRStackFrame push(IRStackFrame frame)
      Push a new frame onto the stack.
    • peek

      public IRStackFrame peek()
      Look at the top frame without removing it.
    • pop

      public IRStackFrame pop()
      Pop a frame off the stack.
    • isEmpty

      public boolean isEmpty()
      Check if the stack is empty.
    • currentScopeId

      public String currentScopeId()
      Get current scope ID from the top frame.
    • currentDebugInfo

      public Optional<DebugInfo> currentDebugInfo()
      Get current debug info from the top frame.
    • hasLeftHandSide

      public boolean hasLeftHandSide()
      Check if current scope has a left-hand side (for result variable decisions).
    • currentFrameType

      public IRFrameType currentFrameType()
      Get current frame type from the top frame.
    • traverseBackToFrameType

      public Optional<IRStackFrame> traverseBackToFrameType(IRFrameType frameType)
      Navigate back up the stack to find the first frame of the specified type. Useful for finding containing method/function contexts from nested blocks.
    • traverseBackToMethodOrFunction

      public Optional<IRStackFrame> traverseBackToMethodOrFunction()
      Navigate back up the stack to find the first method or function frame. Used for capturing context information in nested expressions.
    • traverseBackToAggregate

      public Optional<IRStackFrame> traverseBackToAggregate()
      Navigate back up the stack to find the containing aggregate (class/record/trait). Used for synthesis operations that need access to the containing type.
    • depth

      public int depth()
      Get the depth of the stack (for debugging/testing).
    • traverseBackToContextData

      public <T> Optional<T> traverseBackToContextData(Class<T> contextType)
      Navigate back up the stack to find the first frame with context data of the specified type. Used to find IRContext or other contextual information stored in stack frames.
    • isInFrameType

      public boolean isInFrameType(IRFrameType frameType)
      Check if we're currently in a specific frame type.
    • isInAnyFrameType

      public boolean isInAnyFrameType(IRFrameType... frameTypes)
      Check if we're currently in any of the specified frame types.