| 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) { |