MCPcopy Index your code
hub / github.com/RustPython/RustPython / init_genesis

Method init_genesis

crates/vm/src/vm/context.rs:306–396  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

304 }
305
306 fn init_genesis() -> Self {
307 flame_guard!("init Context");
308 let types = TypeZoo::init();
309 let exceptions = exceptions::ExceptionZoo::init();
310
311 #[inline]
312 fn create_object<T: PyObjectPayload>(payload: T, cls: &'static Py<PyType>) -> PyRef<T> {
313 PyRef::new_ref(payload, cls.to_owned(), None)
314 }
315
316 let none = create_object(PyNone, PyNone::static_type());
317 let ellipsis = create_object(PyEllipsis, PyEllipsis::static_type());
318 let not_implemented = create_object(PyNotImplemented, PyNotImplemented::static_type());
319
320 let typing_no_default = create_object(
321 crate::stdlib::_typing::NoDefault,
322 crate::stdlib::_typing::NoDefault::static_type(),
323 );
324
325 let int_cache_pool = Self::INT_CACHE_POOL_RANGE
326 .map(|v| {
327 PyRef::new_ref(
328 PyInt::from(BigInt::from(v)),
329 types.int_type.to_owned(),
330 None,
331 )
332 })
333 .collect();
334 let latin1_char_cache: Vec<PyRef<PyStr>> = (0u8..=255)
335 .map(|b| create_object(PyStr::from(char::from(b)), types.str_type))
336 .collect();
337 let ascii_char_cache = latin1_char_cache[..128].to_vec();
338
339 let true_value = create_object(PyBool(PyInt::from(1)), types.bool_type);
340 let false_value = create_object(PyBool(PyInt::from(0)), types.bool_type);
341
342 let empty_tuple = create_object(
343 PyTuple::new_unchecked(Vec::new().into_boxed_slice()),
344 types.tuple_type,
345 );
346 let empty_frozenset = PyRef::new_ref(
347 PyFrozenSet::default(),
348 types.frozenset_type.to_owned(),
349 None,
350 );
351
352 let string_pool = StringPool::default();
353 let names = unsafe { ConstName::new(&string_pool, types.str_type) };
354
355 let slot_new_wrapper = PyMethodDef::new_const(
356 names.__new__.as_str(),
357 PyType::__new__,
358 PyMethodFlags::METHOD,
359 None,
360 );
361 let init_cleanup_code = Self::new_init_cleanup_code(&types, &names);
362
363 let empty_str = unsafe { string_pool.intern("", types.str_type.to_owned()) };

Callers

nothing calls this directly

Calls 9

PyBoolClass · 0.85
newFunction · 0.85
collectMethod · 0.80
to_vecMethod · 0.80
internMethod · 0.80
initFunction · 0.50
mapMethod · 0.45
to_ownedMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected