Skip to content

Commit

Permalink
test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen committed Jun 7, 2023
1 parent e0581e1 commit 81817d3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion hint_accountant/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn run() {
let (ap_tracking_data, reference_ids, references, mut exec_scopes, constants) = (
ApTracking::default(),
HashMap::new(),
HashMap::new(),
Vec::new(),
ExecutionScopes::new(),
HashMap::new(),
);
Expand Down
4 changes: 2 additions & 2 deletions src/hint_processor/hint_processor_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub trait HintProcessor {
//(may contain other variables aside from those used by the hint)
reference_ids: &HashMap<String, usize>,
//List of all references (key corresponds to element of the previous dictionary)
references: &Vec<HintReference>,
references: &[HintReference],
) -> Result<Box<dyn Any>, VirtualMachineError> {
Ok(any_box!(HintProcessorData {
code: hint_code.to_string(),
Expand All @@ -52,7 +52,7 @@ pub trait HintProcessor {

fn get_ids_data(
reference_ids: &HashMap<String, usize>,
references: &Vec<HintReference>,
references: &[HintReference],
) -> Result<HashMap<String, HintReference>, VirtualMachineError> {
let mut ids_data = HashMap::<String, HintReference>::new();
for (path, ref_id) in reference_ids {
Expand Down
6 changes: 3 additions & 3 deletions src/types/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,13 +875,13 @@ mod tests {
error_message_attributes: Vec::new(),
instruction_locations: None,
identifiers: HashMap::new(),
reference_manager: Program::get_reference_list(&ReferenceManager {
references: Vec::new(),
}),
};
let program = Program {
shared_program_data: Arc::new(shared_program_data),
constants: HashMap::new(),
reference_manager: ReferenceManager {
references: Vec::new(),
},
builtins: Vec::new(),
};

Expand Down
26 changes: 13 additions & 13 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ pub mod test_utils {
error_message_attributes: crate::stdlib::vec::Vec::new(),
instruction_locations: None,
identifiers: crate::stdlib::collections::HashMap::new(),
reference_manager: Program::get_reference_list(&ReferenceManager {
references: crate::stdlib::vec::Vec::new(),
}),
};
Program {
shared_program_data: Arc::new(shared_program_data),
constants: crate::stdlib::collections::HashMap::new(),
builtins: vec![$( $builtin_name ),*],
reference_manager: ReferenceManager {
references: crate::stdlib::vec::Vec::new(),
},
}
}};
($($field:ident = $value:expr),* $(,)?) => {{
Expand Down Expand Up @@ -352,10 +352,10 @@ pub mod test_utils {
error_message_attributes: val.error_message_attributes,
instruction_locations: val.instruction_locations,
identifiers: val.identifiers,
reference_manager: Program::get_reference_list(&val.reference_manager),
}),
constants: val.constants,
builtins: val.builtins,
reference_manager: val.reference_manager,
}
}
}
Expand Down Expand Up @@ -926,13 +926,13 @@ mod test {
error_message_attributes: Vec::new(),
instruction_locations: None,
identifiers: HashMap::new(),
reference_manager: Program::get_reference_list(&ReferenceManager {
references: Vec::new(),
}),
};
let program = Program {
shared_program_data: Arc::new(shared_data),
constants: HashMap::new(),
reference_manager: ReferenceManager {
references: Vec::new(),
},
builtins: Vec::new(),
};
assert_eq!(program, program!())
Expand All @@ -950,13 +950,13 @@ mod test {
error_message_attributes: Vec::new(),
instruction_locations: None,
identifiers: HashMap::new(),
reference_manager: Program::get_reference_list(&ReferenceManager {
references: Vec::new(),
}),
};
let program = Program {
shared_program_data: Arc::new(shared_data),
constants: HashMap::new(),
reference_manager: ReferenceManager {
references: Vec::new(),
},
builtins: vec![BuiltinName::range_check],
};

Expand All @@ -975,13 +975,13 @@ mod test {
error_message_attributes: Vec::new(),
instruction_locations: None,
identifiers: HashMap::new(),
reference_manager: Program::get_reference_list(&ReferenceManager {
references: Vec::new(),
}),
};
let program = Program {
shared_program_data: Arc::new(shared_data),
constants: HashMap::new(),
reference_manager: ReferenceManager {
references: Vec::new(),
},
builtins: vec![BuiltinName::range_check],
};

Expand Down
13 changes: 4 additions & 9 deletions src/vm/errors/vm_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use thiserror::Error;
use thiserror_no_std::Error;

use crate::{
hint_processor::{
hint_processor_definition::HintReference,
hint_processor_utils::get_maybe_relocatable_from_reference,
},
hint_processor::hint_processor_utils::get_maybe_relocatable_from_reference,
serde::deserialize_program::{ApTracking, Attribute, Location, OffsetValue},
types::{instruction::Register, relocatable::MaybeRelocatable},
vm::{runners::cairo_runner::CairoRunner, vm_core::VirtualMachine},
Expand Down Expand Up @@ -177,21 +174,19 @@ fn get_value_from_simple_reference(
runner: &CairoRunner,
vm: &VirtualMachine,
) -> Option<MaybeRelocatable> {
let reference: HintReference = runner
let reference = runner
.program
.shared_program_data
.reference_manager
.get(ref_id)?
.clone()
.into();
.get(ref_id)?;
// Filter ap-based references
match reference.offset1 {
OffsetValue::Reference(Register::AP, _, _) => None,
_ => {
// Filer complex types (only felt/felt pointers)
match reference.cairo_type {
Some(ref cairo_type) if cairo_type.contains("felt") => Some(
get_maybe_relocatable_from_reference(vm, &reference, ap_tracking)?,
get_maybe_relocatable_from_reference(vm, reference, ap_tracking)?,
),
_ => None,
}
Expand Down
4 changes: 2 additions & 2 deletions src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ impl CairoRunner {
/// Gets the data used by the HintProcessor to execute each hint
pub fn get_hint_data_dictionary(
&self,
references: &Vec<HintReference>,
references: &[HintReference],
hint_executor: &mut dyn HintProcessor,
) -> Result<HashMap<usize, Vec<Box<dyn Any>>>, VirtualMachineError> {
let mut hint_data_dictionary = HashMap::<usize, Vec<Box<dyn Any>>>::new();
Expand Down Expand Up @@ -530,7 +530,7 @@ impl CairoRunner {
hint_processor: &mut dyn HintProcessor,
) -> Result<(), VirtualMachineError> {
let references = &self.program.shared_program_data.reference_manager;
let hint_data_dictionary = self.get_hint_data_dictionary(&references, hint_processor)?;
let hint_data_dictionary = self.get_hint_data_dictionary(references, hint_processor)?;

#[cfg(feature = "hooks")]
vm.execute_before_first_step(self, &hint_data_dictionary)?;
Expand Down

0 comments on commit 81817d3

Please sign in to comment.