@@ -88,6 +88,7 @@ impl DeducedOperands {
8888pub struct VirtualMachine {
8989 pub ( crate ) run_context : RunContext ,
9090 pub builtin_runners : Vec < BuiltinRunner > ,
91+ pub simulated_builtin_runners : Vec < BuiltinRunner > ,
9192 pub segments : MemorySegmentManager ,
9293 pub ( crate ) trace : Option < Vec < TraceEntry > > ,
9394 pub ( crate ) current_step : usize ,
@@ -119,6 +120,7 @@ impl VirtualMachine {
119120 VirtualMachine {
120121 run_context,
121122 builtin_runners : Vec :: new ( ) ,
123+ simulated_builtin_runners : Vec :: new ( ) ,
122124 trace,
123125 current_step : 0 ,
124126 skip_instruction_execution : false ,
@@ -296,12 +298,17 @@ impl VirtualMachine {
296298 & self ,
297299 address : Relocatable ,
298300 ) -> Result < Option < MaybeRelocatable > , VirtualMachineError > {
299- for builtin in self . builtin_runners . iter ( ) {
300- if builtin. base ( ) as isize == address. segment_index {
301- match builtin. deduce_memory_cell ( address, & self . segments . memory ) {
302- Ok ( maybe_reloc) => return Ok ( maybe_reloc) ,
303- Err ( error) => return Err ( VirtualMachineError :: RunnerError ( error) ) ,
304- } ;
301+ let memory = & self . segments . memory ;
302+
303+ for runner in self
304+ . builtin_runners
305+ . iter ( )
306+ . chain ( self . simulated_builtin_runners . iter ( ) )
307+ {
308+ if runner. base ( ) as isize == address. segment_index {
309+ return runner
310+ . deduce_memory_cell ( address, memory)
311+ . map_err ( VirtualMachineError :: RunnerError ) ;
305312 }
306313 }
307314 Ok ( None )
@@ -916,6 +923,16 @@ impl VirtualMachine {
916923 & mut self . builtin_runners
917924 }
918925
926+ /// Returns a mutable iterator over all builtin runners used. That is, both builtin_runners and
927+ /// simulated_builtin_runners.
928+ pub fn get_all_builtin_runners_as_mut_iter (
929+ & mut self ,
930+ ) -> impl Iterator < Item = & mut BuiltinRunner > {
931+ self . builtin_runners
932+ . iter_mut ( )
933+ . chain ( self . simulated_builtin_runners . iter_mut ( ) )
934+ }
935+
919936 ///Inserts a value into a memory address given by a Relocatable value
920937 pub fn insert_value < T : Into < MaybeRelocatable > > (
921938 & mut self ,
@@ -1004,7 +1021,7 @@ impl VirtualMachine {
10041021 pub fn get_signature_builtin (
10051022 & mut self ,
10061023 ) -> Result < & mut SignatureBuiltinRunner , VirtualMachineError > {
1007- for builtin in self . get_builtin_runners_as_mut ( ) {
1024+ for builtin in self . get_all_builtin_runners_as_mut_iter ( ) {
10081025 if let BuiltinRunner :: Signature ( signature_builtin) = builtin {
10091026 return Ok ( signature_builtin) ;
10101027 } ;
@@ -1309,6 +1326,7 @@ impl VirtualMachineBuilder {
13091326 VirtualMachine {
13101327 run_context : self . run_context ,
13111328 builtin_runners : self . builtin_runners ,
1329+ simulated_builtin_runners : Vec :: new ( ) ,
13121330 trace : self . trace ,
13131331 current_step : self . current_step ,
13141332 skip_instruction_execution : self . skip_instruction_execution ,
0 commit comments