@@ -164,82 +164,6 @@ fn find_entrypoint_of_kind(
164
164
. expect ( "executable had no entrypoint of required kind" )
165
165
}
166
166
167
- fn extend_stack_with_builtins (
168
- stack : & mut Vec < MaybeRelocatable > ,
169
- builtins : & [ BuiltinName ] ,
170
- runners : & [ BuiltinRunner ] ,
171
- ) {
172
- let runner_map: HashMap < BuiltinName , & BuiltinRunner > = runners
173
- . iter ( )
174
- . map ( |builtin_runner| ( builtin_runner. name ( ) , builtin_runner) )
175
- . collect ( ) ;
176
- for builtin in builtins {
177
- if let Some ( builtin_runner) = runner_map. get ( & builtin) {
178
- stack. append ( & mut builtin_runner. initial_stack ( ) ) ;
179
- } else {
180
- stack. push ( Felt252 :: ZERO . into ( ) )
181
- }
182
- }
183
- }
184
-
185
- fn initialize_builtin_runner_segments (
186
- builtin_runners : & mut [ BuiltinRunner ] ,
187
- segments : & mut MemorySegmentManager ,
188
- ) {
189
- for builtin_runner in builtin_runners. iter_mut ( ) {
190
- builtin_runner. initialize_segments ( segments) ;
191
- }
192
-
193
- for builtin_runner in builtin_runners. iter_mut ( ) {
194
- if let BuiltinRunner :: Mod ( mod_builtin_runner) = builtin_runner {
195
- mod_builtin_runner. initialize_zero_segment ( segments) ;
196
- }
197
- }
198
- }
199
-
200
- /// TODO: Remove this once cyclic dependency is fixed.
201
- /// It should not be necessary, but cargo treats executable BuiltinName as a separate type
202
- /// which is why I had to create this adapter function.
203
- pub fn get_entrypoint_builtins ( entrypoint : & ExecutableEntryPoint ) -> Vec < BuiltinName > {
204
- let mut builtins = Vec :: with_capacity ( entrypoint. builtins . len ( ) ) ;
205
-
206
- for builtin in & entrypoint. builtins {
207
- let adapted_builtin = BuiltinName :: from_str ( builtin. to_str ( ) )
208
- . expect ( "should never fail under the same implementation" ) ;
209
- builtins. push ( adapted_builtin) ;
210
- }
211
-
212
- builtins
213
- }
214
-
215
- /// TODO: Determine if we receive the hint collection or build it ourselves
216
- /// This function was adapted from cairo-lang-runner
217
- pub fn build_hint_collection (
218
- hints : & [ ( usize , Vec < Hint > ) ] ,
219
- program_length : usize ,
220
- ) -> HintsCollection {
221
- let mut hint_map: BTreeMap < usize , Vec < HintParams > > = BTreeMap :: new ( ) ;
222
-
223
- for ( offset, offset_hints) in hints {
224
- hint_map. insert (
225
- * offset,
226
- offset_hints
227
- . iter ( )
228
- . map ( |hint| HintParams {
229
- code : hint. representing_string ( ) ,
230
- accessible_scopes : vec ! [ ] ,
231
- flow_tracking_data : FlowTrackingData {
232
- ap_tracking : ApTracking :: new ( ) ,
233
- reference_ids : HashMap :: new ( ) ,
234
- } ,
235
- } )
236
- . collect ( ) ,
237
- ) ;
238
- }
239
-
240
- HintsCollection :: new ( & hint_map, program_length) . expect ( "failed to build hint collection" )
241
- }
242
-
243
167
pub fn check_builtin_order ( builtins : & [ BuiltinName ] ) -> Result < ( ) , RunnerError > {
244
168
let ordered_builtins = vec ! [
245
169
BuiltinName :: output,
@@ -368,6 +292,82 @@ pub fn initialize_builtin_runners(
368
292
Ok ( builtin_runners)
369
293
}
370
294
295
+ fn initialize_builtin_runner_segments (
296
+ builtin_runners : & mut [ BuiltinRunner ] ,
297
+ segments : & mut MemorySegmentManager ,
298
+ ) {
299
+ for builtin_runner in builtin_runners. iter_mut ( ) {
300
+ builtin_runner. initialize_segments ( segments) ;
301
+ }
302
+
303
+ for builtin_runner in builtin_runners. iter_mut ( ) {
304
+ if let BuiltinRunner :: Mod ( mod_builtin_runner) = builtin_runner {
305
+ mod_builtin_runner. initialize_zero_segment ( segments) ;
306
+ }
307
+ }
308
+ }
309
+
310
+ fn extend_stack_with_builtins (
311
+ stack : & mut Vec < MaybeRelocatable > ,
312
+ builtins : & [ BuiltinName ] ,
313
+ runners : & [ BuiltinRunner ] ,
314
+ ) {
315
+ let runner_map: HashMap < BuiltinName , & BuiltinRunner > = runners
316
+ . iter ( )
317
+ . map ( |builtin_runner| ( builtin_runner. name ( ) , builtin_runner) )
318
+ . collect ( ) ;
319
+ for builtin in builtins {
320
+ if let Some ( builtin_runner) = runner_map. get ( & builtin) {
321
+ stack. append ( & mut builtin_runner. initial_stack ( ) ) ;
322
+ } else {
323
+ stack. push ( Felt252 :: ZERO . into ( ) )
324
+ }
325
+ }
326
+ }
327
+
328
+ /// TODO: Remove this once cyclic dependency is fixed.
329
+ /// It should not be necessary, but cargo treats executable BuiltinName as a separate type
330
+ /// which is why I had to create this adapter function.
331
+ pub fn get_entrypoint_builtins ( entrypoint : & ExecutableEntryPoint ) -> Vec < BuiltinName > {
332
+ let mut builtins = Vec :: with_capacity ( entrypoint. builtins . len ( ) ) ;
333
+
334
+ for builtin in & entrypoint. builtins {
335
+ let adapted_builtin = BuiltinName :: from_str ( builtin. to_str ( ) )
336
+ . expect ( "should never fail under the same implementation" ) ;
337
+ builtins. push ( adapted_builtin) ;
338
+ }
339
+
340
+ builtins
341
+ }
342
+
343
+ /// TODO: Determine if we receive the hint collection or build it ourselves
344
+ /// This function was adapted from cairo-lang-runner
345
+ pub fn build_hint_collection (
346
+ hints : & [ ( usize , Vec < Hint > ) ] ,
347
+ program_length : usize ,
348
+ ) -> HintsCollection {
349
+ let mut hint_map: BTreeMap < usize , Vec < HintParams > > = BTreeMap :: new ( ) ;
350
+
351
+ for ( offset, offset_hints) in hints {
352
+ hint_map. insert (
353
+ * offset,
354
+ offset_hints
355
+ . iter ( )
356
+ . map ( |hint| HintParams {
357
+ code : hint. representing_string ( ) ,
358
+ accessible_scopes : vec ! [ ] ,
359
+ flow_tracking_data : FlowTrackingData {
360
+ ap_tracking : ApTracking :: new ( ) ,
361
+ reference_ids : HashMap :: new ( ) ,
362
+ } ,
363
+ } )
364
+ . collect ( ) ,
365
+ ) ;
366
+ }
367
+
368
+ HintsCollection :: new ( & hint_map, program_length) . expect ( "failed to build hint collection" )
369
+ }
370
+
371
371
#[ cfg( test) ]
372
372
mod tests {
373
373
use crate :: hint_processor:: builtin_hint_processor:: builtin_hint_processor_definition:: BuiltinHintProcessor ;
0 commit comments