Refactored Box getting libfuncs by CellExpression::add_with_const.
#9393
+51
−40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Summary
Added a new utility method
add_with_consttoCellExpressionthat creates a cell expression representing the sum of a cell reference and a constant value, with an optimization to return the cell directly when the value is zero. This method is then used to simplify and improve the implementation of boxed struct operations in the Sierra-to-CASM compiler.Type of change
Please check one:
Why is this change needed?
The code for handling boxed structs and local-to-box conversions contained duplicated logic for adding offsets to cell references. This PR extracts this common pattern into a reusable utility method, making the code more maintainable and less error-prone. Additionally, it refactors the struct boxed deconstruct implementation to handle offsets more consistently.
What was the behavior or documentation before?
Before this change, offset calculations for boxed structs were implemented directly in each function that needed them, with duplicated logic for handling the special case of zero offsets.
What is the behavior or documentation after?
After this change, a new utility method
add_with_consthandles offset calculations consistently, with proper optimization for zero offsets. The boxed struct deconstruction logic has been refactored into a separate helper function that uses this new utility.Additional context
This refactoring improves code maintainability while preserving the same functionality. The new
boxed_members_cell_exprshelper function also provides better error handling and documentation for the boxed struct deconstruction process.