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_EXITresultVariable- the EK9 Boolean holding the conditionprimitiveCondition- 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordWhat an evaluator hands back from inside the iteration scope. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static LoopIterationConditioninIterationScope(ScopedInstructionExecutor executor, DebugInfo debugInfo, Function<String, LoopIterationCondition.Evaluated> evaluator) Evaluate a loop condition inside its own iteration scope.Returns the value of theinstructionsrecord component.Returns the value of theprimitiveConditionrecord component.Returns the value of theresultVariablerecord component.scopeId()Returns the value of thescopeIdrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
LoopIterationCondition
public LoopIterationCondition(String scopeId, List<IRInstr> instructions, String resultVariable, String primitiveCondition) Creates an instance of aLoopIterationConditionrecord class.- Parameters:
scopeId- the value for thescopeIdrecord componentinstructions- the value for theinstructionsrecord componentresultVariable- the value for theresultVariablerecord componentprimitiveCondition- the value for theprimitiveConditionrecord 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 bodydebugInfo- debug information for the scope instructionsevaluator- 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
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
scopeId
-
instructions
Returns the value of theinstructionsrecord component.- Returns:
- the value of the
instructionsrecord component
-
resultVariable
Returns the value of theresultVariablerecord component.- Returns:
- the value of the
resultVariablerecord component
-
primitiveCondition
Returns the value of theprimitiveConditionrecord component.- Returns:
- the value of the
primitiveConditionrecord component
-