Record Class LoopIterationCondition

java.lang.Object
java.lang.Record
org.ek9lang.compiler.phase7.support.LoopIterationCondition
Record Components:
scopeId - the iteration scope the condition ran in (the case scope id of a while loop)
instructions - SCOPE_ENTER, the evaluation, SCOPE_EXIT
resultVariable - the EK9 Boolean holding the condition
primitiveCondition - the primitive boolean to branch on

public record LoopIterationCondition(String scopeId, List<IRInstr> instructions, String resultVariable, String primitiveCondition) extends Record
THE loop condition in its own per-iteration scope (IR tidy FLOW-10): the scope is entered and left on every iteration so the condition's temporaries are released each time round.

While, do-while and for-in all build their condition this way and differ only in WHAT they evaluate inside the scope (a user expression, or iterator.hasNext()) and in whether it comes before or after the body. This is ScopedInstructionExecutor.executeWithScopeId(Function, DebugInfo) plus the two values the loop needs afterwards: the condition's Boolean result variable and the primitive boolean it is branched on. The call order is exactly the hand-rolled one - scope id, then whatever the evaluator generates (temporaries, nested scope ids) - so numbering is unchanged.

  • Constructor Details

    • LoopIterationCondition

      public LoopIterationCondition(String scopeId, List<IRInstr> instructions, String resultVariable, String primitiveCondition)
      Creates an instance of a LoopIterationCondition record class.
      Parameters:
      scopeId - the value for the scopeId record component
      instructions - the value for the instructions record component
      resultVariable - the value for the resultVariable record component
      primitiveCondition - the value for the primitiveCondition record component
  • Method Details

    • inIterationScope

      public static LoopIterationCondition inIterationScope(ScopedInstructionExecutor executor, DebugInfo debugInfo, Function<String, LoopIterationCondition.Evaluated> evaluator)
      Evaluate a loop condition inside its own iteration scope.
      Parameters:
      executor - THE scoped body
      debugInfo - debug information for the scope instructions
      evaluator - given the new scope's id, generates the condition and says where its result is
      Returns:
      the scope id, the complete instruction list and the condition's variables
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • scopeId

      public String scopeId()
      Returns the value of the scopeId record component.
      Returns:
      the value of the scopeId record component
    • instructions

      public List<IRInstr> instructions()
      Returns the value of the instructions record component.
      Returns:
      the value of the instructions record component
    • resultVariable

      public String resultVariable()
      Returns the value of the resultVariable record component.
      Returns:
      the value of the resultVariable record component
    • primitiveCondition

      public String primitiveCondition()
      Returns the value of the primitiveCondition record component.
      Returns:
      the value of the primitiveCondition record component