Skip to content

Commit 6e9b85f

Browse files
committed
cargo fmt
1 parent 101c6c3 commit 6e9b85f

File tree

3 files changed

+50
-55
lines changed

3 files changed

+50
-55
lines changed

crates/lean_compiler/src/c_compile_final.rs

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ pub fn compile_to_low_level_bytecode(
9292
let mut hints = BTreeMap::new();
9393

9494
for (label, pc) in label_to_pc.clone() {
95-
let pc_hints: &mut Vec<Hint> =
96-
match hints.try_insert(pc, vec![]) {
97-
Ok(pc_hints) => pc_hints,
98-
Err(_) => hints.get_mut(&pc).unwrap(),
99-
};
95+
let pc_hints: &mut Vec<Hint> = match hints.try_insert(pc, vec![]) {
96+
Ok(pc_hints) => pc_hints,
97+
Err(_) => hints.get_mut(&pc).unwrap(),
98+
};
10099
pc_hints.push(Hint::Label { label });
101100
}
102101

@@ -152,46 +151,43 @@ fn compile_block(
152151
_ => None,
153152
};
154153

155-
let codegen_jump =
156-
|hints: &BTreeMap<CodeAddress, Vec<Hint>>,
157-
low_level_bytecode: &mut Vec<Instruction>,
158-
condition: IntermediateValue,
159-
dest: IntermediateValue,
160-
updated_fp: Option<IntermediateValue>| {
161-
let dest = try_as_mem_or_constant(&dest)
162-
.expect("Fatal: Could not materialize jump destination");
163-
let label =
164-
match dest {
165-
MemOrConstant::Constant(dest) => {
166-
hints.get(&usize::try_from(dest.as_canonical_u32()).unwrap())
167-
.map(|hints: &Vec<Hint>| hints.iter().find_map(|x| {
168-
match x {
169-
Hint::Label { label } => Some(label),
170-
_ => None,
171-
}
172-
}))
173-
.flatten()
174-
.expect("Fatal: Unlabeled jump destination")
175-
.clone()
176-
},
177-
MemOrConstant::MemoryAfterFp { offset } => {
178-
if offset >= 0 {
179-
format!("fp+{offset}")
180-
} else {
181-
format!("fp-{offset}")
182-
}
183-
},
184-
};
185-
let updated_fp = updated_fp
186-
.map(|fp| try_as_mem_or_fp(&fp).unwrap())
187-
.unwrap_or(MemOrFp::Fp);
188-
low_level_bytecode.push(Instruction::Jump {
189-
condition: try_as_mem_or_constant(&condition).unwrap(),
190-
label,
191-
dest,
192-
updated_fp,
193-
});
154+
let codegen_jump = |hints: &BTreeMap<CodeAddress, Vec<Hint>>,
155+
low_level_bytecode: &mut Vec<Instruction>,
156+
condition: IntermediateValue,
157+
dest: IntermediateValue,
158+
updated_fp: Option<IntermediateValue>| {
159+
let dest =
160+
try_as_mem_or_constant(&dest).expect("Fatal: Could not materialize jump destination");
161+
let label = match dest {
162+
MemOrConstant::Constant(dest) => hints
163+
.get(&usize::try_from(dest.as_canonical_u32()).unwrap())
164+
.map(|hints: &Vec<Hint>| {
165+
hints.iter().find_map(|x| match x {
166+
Hint::Label { label } => Some(label),
167+
_ => None,
168+
})
169+
})
170+
.flatten()
171+
.expect("Fatal: Unlabeled jump destination")
172+
.clone(),
173+
MemOrConstant::MemoryAfterFp { offset } => {
174+
if offset >= 0 {
175+
format!("fp+{offset}")
176+
} else {
177+
format!("fp-{offset}")
178+
}
179+
}
194180
};
181+
let updated_fp = updated_fp
182+
.map(|fp| try_as_mem_or_fp(&fp).unwrap())
183+
.unwrap_or(MemOrFp::Fp);
184+
low_level_bytecode.push(Instruction::Jump {
185+
condition: try_as_mem_or_constant(&condition).unwrap(),
186+
label,
187+
dest,
188+
updated_fp,
189+
});
190+
};
195191

196192
let mut pc = pc_start;
197193
for instruction in block {
@@ -266,11 +262,10 @@ fn compile_block(
266262
condition,
267263
dest,
268264
updated_fp,
269-
} => {
270-
codegen_jump(hints, low_level_bytecode, condition, dest, updated_fp)
271-
}
265+
} => codegen_jump(hints, low_level_bytecode, condition, dest, updated_fp),
272266
IntermediateInstruction::Jump { dest, updated_fp } => {
273-
let one = IntermediateValue::Constant(ConstExpression::Value(ConstantValue::Scalar(1)));
267+
let one =
268+
IntermediateValue::Constant(ConstExpression::Value(ConstantValue::Scalar(1)));
274269
codegen_jump(hints, low_level_bytecode, one, dest, updated_fp)
275270
}
276271
IntermediateInstruction::Poseidon2_16 { arg_a, arg_b, res } => {

crates/lean_vm/src/isa/hint.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::core::{Label, DIMENSION, F, LOG_VECTOR_LEN, SourceLineNumber, VECTOR_LEN};
1+
use crate::core::{DIMENSION, F, LOG_VECTOR_LEN, Label, SourceLineNumber, VECTOR_LEN};
22
use crate::diagnostics::RunnerError;
33
use crate::execution::{ExecutionHistory, Memory};
44
use crate::isa::operands::MemOrConstant;
@@ -53,9 +53,7 @@ pub enum Hint {
5353
location: SourceLineNumber,
5454
},
5555
/// Jump destination label (for debugging purposes)
56-
Label {
57-
label: Label,
58-
},
56+
Label { label: Label },
5957
}
6058

6159
/// Execution state for hint processing
@@ -173,7 +171,7 @@ impl Hint {
173171
*ctx.cpu_cycles_before_new_line = 0;
174172
Ok(false)
175173
}
176-
Self::Label { label: _ } => { Ok(false) }
174+
Self::Label { label: _ } => Ok(false),
177175
}
178176
}
179177
}
@@ -225,7 +223,9 @@ impl Display for Hint {
225223
Self::Inverse { arg, res_offset } => {
226224
write!(f, "m[fp + {res_offset}] = inverse({arg})")
227225
}
228-
Self::LocationReport { location: line_number } => {
226+
Self::LocationReport {
227+
location: line_number,
228+
} => {
229229
write!(f, "source line number: {line_number}")
230230
}
231231
Self::Label { label } => {

crates/lean_vm/src/isa/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use super::Operation;
44
use super::operands::{MemOrConstant, MemOrFp, MemOrFpOrConstant};
5-
use crate::core::{Label, DIMENSION, EF, F, VECTOR_LEN};
5+
use crate::core::{DIMENSION, EF, F, Label, VECTOR_LEN};
66
use crate::diagnostics::RunnerError;
77
use crate::execution::Memory;
88
use crate::witness::{

0 commit comments

Comments
 (0)