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

Method run_code_obj

crates/vm/src/vm/mod.rs:1086–1111  ·  view source on GitHub ↗
(&self, code: PyRef<PyCode>, scope: Scope)

Source from the content-addressed store, hash-verified

1084 }
1085
1086 pub fn run_code_obj(&self, code: PyRef<PyCode>, scope: Scope) -> PyResult {
1087 use crate::builtins::{PyFunction, PyModule};
1088
1089 // Create a function object for module code, similar to CPython's PyEval_EvalCode
1090 let func = PyFunction::new(code.clone(), scope.globals.clone(), self)?;
1091 let func_obj = func.into_ref(&self.ctx).into();
1092
1093 // Extract builtins from globals["__builtins__"], like PyEval_EvalCode
1094 let builtins = match scope
1095 .globals
1096 .get_item_opt(identifier!(self, __builtins__), self)?
1097 {
1098 Some(b) => {
1099 if let Some(module) = b.downcast_ref::<PyModule>() {
1100 module.dict().into()
1101 } else {
1102 b
1103 }
1104 }
1105 None => self.builtins.dict().into(),
1106 };
1107
1108 let frame =
1109 Frame::new(code, scope, builtins, &[], Some(func_obj), false, self).into_ref(&self.ctx);
1110 self.run_frame(frame)
1111 }
1112
1113 #[cold]
1114 pub fn run_unraisable(&self, e: PyBaseExceptionRef, msg: Option<String>, object: PyObjectRef) {

Callers 15

bench_rustpython_codeFunction · 0.80
bench_rustpython_codeFunction · 0.80
shell_execFunction · 0.80
get_pipFunction · 0.80
mainFunction · 0.80
runFunction · 0.80
runFunction · 0.80
inject_moduleMethod · 0.80
runMethod · 0.80
evalFunction · 0.80
import_code_objFunction · 0.80
run_codeFunction · 0.80

Calls 7

newFunction · 0.85
get_item_optMethod · 0.80
run_frameMethod · 0.80
SomeClass · 0.50
cloneMethod · 0.45
into_refMethod · 0.45
dictMethod · 0.45

Tested by 1

test_nested_frozenFunction · 0.64