Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/lean_compiler/src/b_compile_intermediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ impl Compiler {
}

impl SimpleExpr {
fn to_mem_after_fp_or_constant(&self, compiler: &Compiler) -> IntermediaryMemOrFpOrConstant {
fn to_mem_after_fp_or_constant(&self, compiler: &Compiler) -> IntermediateValue {
match self {
Self::Var(var) => IntermediaryMemOrFpOrConstant::MemoryAfterFp {
Self::Var(var) => IntermediateValue::MemoryAfterFp {
offset: compiler.get_offset(&var.clone().into()),
},
Self::Constant(c) => IntermediaryMemOrFpOrConstant::Constant(c.clone()),
Self::ConstMallocAccess { malloc_label, offset } => IntermediaryMemOrFpOrConstant::MemoryAfterFp {
Self::Constant(c) => IntermediateValue::Constant(c.clone()),
Self::ConstMallocAccess { malloc_label, offset } => IntermediateValue::MemoryAfterFp {
offset: compiler.get_offset(&VarOrConstMallocAccess::ConstMallocAccess {
malloc_label: *malloc_label,
offset: offset.clone(),
Expand Down Expand Up @@ -436,7 +436,7 @@ fn compile_lines(
instructions.push(IntermediateInstruction::Deref {
shift_0: new_fp_pos.into(),
shift_1: (2 + args.len() + i).into(),
res: IntermediaryMemOrFpOrConstant::MemoryAfterFp {
res: IntermediateValue::MemoryAfterFp {
offset: compiler.get_offset(&ret_var.clone().into()),
},
});
Expand Down Expand Up @@ -623,12 +623,12 @@ fn setup_function_call(
IntermediateInstruction::Deref {
shift_0: new_fp_pos.into(),
shift_1: ConstExpression::zero(),
res: IntermediaryMemOrFpOrConstant::Constant(ConstExpression::label(return_label.clone())),
res: IntermediateValue::Constant(ConstExpression::label(return_label.clone())),
},
IntermediateInstruction::Deref {
shift_0: new_fp_pos.into(),
shift_1: ConstExpression::one(),
res: IntermediaryMemOrFpOrConstant::Fp,
res: IntermediateValue::Fp,
},
];

Expand Down
6 changes: 3 additions & 3 deletions crates/lean_compiler/src/c_compile_final.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ fn compile_block(
shift_0: eval_const_expression(&shift_0, compiler).to_usize(),
shift_1: eval_const_expression(&shift_1, compiler).to_usize(),
res: match res {
IntermediaryMemOrFpOrConstant::MemoryAfterFp { offset } => MemOrFpOrConstant::MemoryAfterFp {
IntermediateValue::MemoryAfterFp { offset } => MemOrFpOrConstant::MemoryAfterFp {
offset: eval_const_expression_usize(&offset, compiler),
},
IntermediaryMemOrFpOrConstant::Fp => MemOrFpOrConstant::Fp,
IntermediaryMemOrFpOrConstant::Constant(c) => {
IntermediateValue::Fp => MemOrFpOrConstant::Fp,
IntermediateValue::Constant(c) => {
MemOrFpOrConstant::Constant(eval_const_expression(&c, compiler))
}
},
Expand Down
4 changes: 2 additions & 2 deletions crates/lean_compiler/src/ir/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::operation::HighLevelOperation;
use super::value::{IntermediaryMemOrFpOrConstant, IntermediateValue};
use super::value::IntermediateValue;
use crate::lang::ConstExpression;
use lean_vm::{BooleanExpr, CustomHint, Operation, SourceLocation, Table, TableT};
use std::fmt::{Display, Formatter};
Expand All @@ -16,7 +16,7 @@ pub enum IntermediateInstruction {
Deref {
shift_0: ConstExpression,
shift_1: ConstExpression,
res: IntermediaryMemOrFpOrConstant,
res: IntermediateValue,
}, // res = m[m[fp + shift_0]]
Panic,
Jump {
Expand Down
2 changes: 1 addition & 1 deletion crates/lean_compiler/src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pub mod value;
pub use bytecode::{IntermediateBytecode, MatchBlock};
pub use instruction::IntermediateInstruction;
pub use operation::HighLevelOperation;
pub use value::{IntermediaryMemOrFpOrConstant, IntermediateValue};
pub use value::IntermediateValue;
24 changes: 0 additions & 24 deletions crates/lean_compiler/src/ir/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,3 @@ impl Display for IntermediateValue {
}
}
}

/// More restrictive value type used in specific contexts.
///
/// Similar to [`IntermediateValue`] but with different ordering constraints
/// needed for certain operations like dereferencing.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum IntermediaryMemOrFpOrConstant {
/// Memory location at frame pointer + offset.
MemoryAfterFp { offset: ConstExpression },
/// The current frame pointer.
Fp,
/// A compile-time constant value.
Constant(ConstExpression),
}

impl Display for IntermediaryMemOrFpOrConstant {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::MemoryAfterFp { offset } => write!(f, "m[fp + {offset}]"),
Self::Fp => write!(f, "fp"),
Self::Constant(c) => write!(f, "{c}"),
}
}
}