Skip to content

Commit 935f912

Browse files
authored
remove IntermediaryMemOrFpOrConstant (#121)
Co-authored-by: Tom Wambsgans <[email protected]>
1 parent fe2ec24 commit 935f912

File tree

5 files changed

+13
-37
lines changed

5 files changed

+13
-37
lines changed

crates/lean_compiler/src/b_compile_intermediate.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ impl Compiler {
6565
}
6666

6767
impl SimpleExpr {
68-
fn to_mem_after_fp_or_constant(&self, compiler: &Compiler) -> IntermediaryMemOrFpOrConstant {
68+
fn to_mem_after_fp_or_constant(&self, compiler: &Compiler) -> IntermediateValue {
6969
match self {
70-
Self::Var(var) => IntermediaryMemOrFpOrConstant::MemoryAfterFp {
70+
Self::Var(var) => IntermediateValue::MemoryAfterFp {
7171
offset: compiler.get_offset(&var.clone().into()),
7272
},
73-
Self::Constant(c) => IntermediaryMemOrFpOrConstant::Constant(c.clone()),
74-
Self::ConstMallocAccess { malloc_label, offset } => IntermediaryMemOrFpOrConstant::MemoryAfterFp {
73+
Self::Constant(c) => IntermediateValue::Constant(c.clone()),
74+
Self::ConstMallocAccess { malloc_label, offset } => IntermediateValue::MemoryAfterFp {
7575
offset: compiler.get_offset(&VarOrConstMallocAccess::ConstMallocAccess {
7676
malloc_label: *malloc_label,
7777
offset: offset.clone(),
@@ -436,7 +436,7 @@ fn compile_lines(
436436
instructions.push(IntermediateInstruction::Deref {
437437
shift_0: new_fp_pos.into(),
438438
shift_1: (2 + args.len() + i).into(),
439-
res: IntermediaryMemOrFpOrConstant::MemoryAfterFp {
439+
res: IntermediateValue::MemoryAfterFp {
440440
offset: compiler.get_offset(&ret_var.clone().into()),
441441
},
442442
});
@@ -623,12 +623,12 @@ fn setup_function_call(
623623
IntermediateInstruction::Deref {
624624
shift_0: new_fp_pos.into(),
625625
shift_1: ConstExpression::zero(),
626-
res: IntermediaryMemOrFpOrConstant::Constant(ConstExpression::label(return_label.clone())),
626+
res: IntermediateValue::Constant(ConstExpression::label(return_label.clone())),
627627
},
628628
IntermediateInstruction::Deref {
629629
shift_0: new_fp_pos.into(),
630630
shift_1: ConstExpression::one(),
631-
res: IntermediaryMemOrFpOrConstant::Fp,
631+
res: IntermediateValue::Fp,
632632
},
633633
];
634634

crates/lean_compiler/src/c_compile_final.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ fn compile_block(
265265
shift_0: eval_const_expression(&shift_0, compiler).to_usize(),
266266
shift_1: eval_const_expression(&shift_1, compiler).to_usize(),
267267
res: match res {
268-
IntermediaryMemOrFpOrConstant::MemoryAfterFp { offset } => MemOrFpOrConstant::MemoryAfterFp {
268+
IntermediateValue::MemoryAfterFp { offset } => MemOrFpOrConstant::MemoryAfterFp {
269269
offset: eval_const_expression_usize(&offset, compiler),
270270
},
271-
IntermediaryMemOrFpOrConstant::Fp => MemOrFpOrConstant::Fp,
272-
IntermediaryMemOrFpOrConstant::Constant(c) => {
271+
IntermediateValue::Fp => MemOrFpOrConstant::Fp,
272+
IntermediateValue::Constant(c) => {
273273
MemOrFpOrConstant::Constant(eval_const_expression(&c, compiler))
274274
}
275275
},

crates/lean_compiler/src/ir/instruction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::operation::HighLevelOperation;
2-
use super::value::{IntermediaryMemOrFpOrConstant, IntermediateValue};
2+
use super::value::IntermediateValue;
33
use crate::lang::ConstExpression;
44
use lean_vm::{BooleanExpr, CustomHint, Operation, SourceLocation, Table, TableT};
55
use std::fmt::{Display, Formatter};
@@ -16,7 +16,7 @@ pub enum IntermediateInstruction {
1616
Deref {
1717
shift_0: ConstExpression,
1818
shift_1: ConstExpression,
19-
res: IntermediaryMemOrFpOrConstant,
19+
res: IntermediateValue,
2020
}, // res = m[m[fp + shift_0]]
2121
Panic,
2222
Jump {

crates/lean_compiler/src/ir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ pub mod value;
88
pub use bytecode::{IntermediateBytecode, MatchBlock};
99
pub use instruction::IntermediateInstruction;
1010
pub use operation::HighLevelOperation;
11-
pub use value::{IntermediaryMemOrFpOrConstant, IntermediateValue};
11+
pub use value::IntermediateValue;

crates/lean_compiler/src/ir/value.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,3 @@ impl Display for IntermediateValue {
4646
}
4747
}
4848
}
49-
50-
/// More restrictive value type used in specific contexts.
51-
///
52-
/// Similar to [`IntermediateValue`] but with different ordering constraints
53-
/// needed for certain operations like dereferencing.
54-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
55-
pub enum IntermediaryMemOrFpOrConstant {
56-
/// Memory location at frame pointer + offset.
57-
MemoryAfterFp { offset: ConstExpression },
58-
/// The current frame pointer.
59-
Fp,
60-
/// A compile-time constant value.
61-
Constant(ConstExpression),
62-
}
63-
64-
impl Display for IntermediaryMemOrFpOrConstant {
65-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
66-
match self {
67-
Self::MemoryAfterFp { offset } => write!(f, "m[fp + {offset}]"),
68-
Self::Fp => write!(f, "fp"),
69-
Self::Constant(c) => write!(f, "{c}"),
70-
}
71-
}
72-
}

0 commit comments

Comments
 (0)