mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Materialize code constants through the VM (#8867)
PyObjBag built code object constants from a Context alone, and its
frozenset arm was unimplemented!(), so ctx.new_code() panicked on code
containing a frozenset constant such as `x in {1, 2, 3}`.
IntoCodeObject now takes a VirtualMachine and uses PyVmBag for bytecode
and frozen code objects. Context::new_code, PyObjBag and
AsBag for &Context are removed; callers use VirtualMachine::new_code.
Assisted-by: Claude:claude-opus-5-5
Assisted-by: Grok:grok-4.7
This commit is contained in:
1 parent
d88c344847
commit
c8d63e848e
8 files changed
+49
-100
No files matched your search
@@ -11,7 +11,7 @@ fn run(vm: &vm::VirtualMachine) -> vm::PyResult<()> {
|
||||
// the file parameter is relative to the current file.
|
||||
let module = vm::py_compile!(file = "freeze.py");
|
||||
|
||||
let res = vm.run_code_obj(vm.ctx.new_code(module), scope);
|
||||
let res = vm.run_code_obj(vm.new_code(module), scope);
|
||||
|
||||
if let Err(exc) = res {
|
||||
vm.print_exception(&exc);
|
||||
|
||||
@@ -16,7 +16,7 @@ macro_rules! add_python_function {
|
||||
// compile the code to bytecode
|
||||
let code = vm::py_compile!(source = $src);
|
||||
// convert the rustpython_compiler_core::CodeObject to a PyRef<PyCode>
|
||||
let code = $vm.ctx.new_code(code);
|
||||
let code = $vm.new_code(code);
|
||||
|
||||
// run the python code in the scope to store the function
|
||||
$vm.run_code_obj(code, $scope.clone())
|
||||
|
||||
Reference in new issue
Block a user