mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Update loop unrolling
This commit is contained in:
parent
08d3997813
commit
044933c0fb
@ -15,12 +15,32 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_ast::*;
|
||||
use leo_errors::LoopUnrollerError;
|
||||
|
||||
use crate::Unroller;
|
||||
|
||||
impl ExpressionReconstructor for Unroller<'_> {
|
||||
type AdditionalOutput = bool;
|
||||
|
||||
fn reconstruct_array_access(&mut self, input: ArrayAccess) -> (Expression, Self::AdditionalOutput) {
|
||||
// Reconstruct the index.
|
||||
let index = self.reconstruct_expression(*input.index).0;
|
||||
// If the index is not a literal, then emit an error.
|
||||
if !matches!(index, Expression::Literal(_)) {
|
||||
self.emit_err(LoopUnrollerError::variable_array_access(input.span));
|
||||
}
|
||||
|
||||
(
|
||||
Expression::Access(AccessExpression::Array(ArrayAccess {
|
||||
array: Box::new(self.reconstruct_expression(*input.array).0),
|
||||
index: Box::new(index),
|
||||
span: input.span,
|
||||
id: input.id,
|
||||
})),
|
||||
Default::default(),
|
||||
)
|
||||
}
|
||||
|
||||
fn reconstruct_identifier(&mut self, input: Identifier) -> (Expression, Self::AdditionalOutput) {
|
||||
// Substitute the identifier with the constant value if it is a constant.
|
||||
if let Some(expr) = self.constant_propagation_table.borrow().lookup_constant(input.name) {
|
||||
|
Loading…
Reference in New Issue
Block a user