Class ScopedInstructionExecutor
executeWithScopeId(Function, DebugInfo)
when the body or the caller needs the scope id).
Encapsulates the repetitive pattern: 1. Generate scope ID 2. Push scope onto stack (enterScope) 3. Add SCOPE_ENTER instruction 4. Execute instructions 5. Add SCOPE_EXIT instruction 6. Pop scope from stack (exitScope)
This ensures consistent scope lifecycle management across all generators, eliminating bugs from manual scope handling and reducing code duplication.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA scoped body and the id of the scope it ran in (for sites that name that scope afterwards, for example as a case scope id). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionExecute instructions within temporary scope.THE scoped body for a generator whose body needs, or whose caller needs, the scope id.
-
Constructor Details
-
ScopedInstructionExecutor
-
-
Method Details
-
execute
Execute instructions within temporary scope.The scope is automatically created, pushed onto the stack, and cleaned up after the instructions execute. This ensures proper memory management through scope-based reference counting.
- Parameters:
instructionGenerator- Supplier that generates the instructions to executedebugInfo- Debug information for scope instructions- Returns:
- Complete instruction list with SCOPE_ENTER, instructions, SCOPE_EXIT
-
executeWithScopeId
public ScopedInstructionExecutor.ScopedBlock executeWithScopeId(Function<String, List<IRInstr>> body, DebugInfo debugInfo) THE scoped body for a generator whose body needs, or whose caller needs, the scope id.Exactly the hand-rolled sequence: generateScopeId, enterScope, SCOPE_ENTER, body, SCOPE_EXIT, exitScope. The body is handed the scope id and runs between the enter and the exit, so anything it generates (scope ids, temporary names, labels) is numbered after the scope's own id, as it always was.
- Parameters:
body- Function from the new scope's id to the instructions that run inside itdebugInfo- Debug information for scope instructions- Returns:
- The scope id and the complete instruction list, SCOPE_ENTER, body, SCOPE_EXIT
-