Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/vm/validated_memory_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use num_bigint::BigInt;
use std::collections::HashMap;

pub struct ValidatedMemoryDict {
memory: Memory,
pub memory: Memory,
validation_rules: HashMap<BigInt, Vec<(ValidationRule, ())>>,
validated_addresses: Vec<Relocatable>,
}
Expand Down
29 changes: 28 additions & 1 deletion src/vm/vm_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ struct Operands {
op1: MaybeRelocatable,
}

struct Rule {
func: fn(&VirtualMachine, &MaybeRelocatable, &()) -> Option<MaybeRelocatable>,
}

pub struct VirtualMachine {
run_context: RunContext,
prime: BigInt,
Expand All @@ -37,7 +41,7 @@ pub struct VirtualMachine {
//program: ProgramBase,
program_base: Option<MaybeRelocatable>,
validated_memory: ValidatedMemoryDict,
//auto_deduction: HashMap<i64, Vec<(Rule, ())>>,
//auto_deduction: HashMap<BigInt, Vec<(Rule, ())>>,
accessesed_addresses: Vec<MaybeRelocatable>,
trace: Vec<TraceEntry>,
current_step: BigInt,
Expand Down Expand Up @@ -286,6 +290,29 @@ impl VirtualMachine {
return None;
}

pub fn deduce_memory_cell(&mut self, addr: MaybeRelocatable) -> Option<MaybeRelocatable> {
match addr {
MaybeRelocatable::Int(_) => (),
MaybeRelocatable::RelocatableValue(ref addr_val) => {
match self.auto_deduction.get(&addr_val.segment_index) {
Some(rules) => {
for (rule, args) in rules.iter() {
match (rule.func)(self, &addr, args) {
Some(value) => {
self.validated_memory.memory.insert(&addr, &value);
return Some(value);
},
None => (),
};
}
},
None => (),
};
}
}
None
}

fn opcode_assertions(&self, instruction: &Instruction, operands: &Operands) {
match instruction.opcode {
Opcode::ASSERT_EQ => {
Expand Down