diff --git a/vm/src/sysmodule.rs b/vm/src/sysmodule.rs index e2713d7834..966c6b5a91 100644 --- a/vm/src/sysmodule.rs +++ b/vm/src/sysmodule.rs @@ -21,7 +21,7 @@ fn argv(ctx: &PyContext) -> PyObjectRef { fn frame_idx(vm: &mut VirtualMachine, offset: Option<&PyObjectRef>) -> Result { if let Some(int) = offset { if let Some(offset) = objint::get_value(&int).to_usize() { - if offset > vm.frames.len() - 1 { + if offset > vm.frames.borrow().len() - 1 { return Err(vm.new_value_error("call stack is not deep enough".to_string())); } return Ok(offset); @@ -39,8 +39,8 @@ fn getframe(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { ); let idx = frame_idx(vm, offset)?; - let idx = vm.frames.len() - idx - 1; - let frame = &vm.frames[idx]; + let idx = vm.frames.borrow().len() - idx - 1; + let frame = &vm.frames.borrow()[idx]; Ok(frame.clone()) } diff --git a/vm/src/vm.rs b/vm/src/vm.rs index ac97e8e9c3..4ec850eeae 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -6,6 +6,7 @@ extern crate rustpython_parser; +use std::cell::{Ref, RefCell}; use std::collections::hash_map::HashMap; use std::collections::hash_set::HashSet; use std::rc::Rc; @@ -46,7 +47,7 @@ pub struct VirtualMachine { pub sys_module: PyObjectRef, pub stdlib_inits: HashMap, pub ctx: PyContext, - pub frames: Vec, + pub frames: RefCell>, pub wasm_id: Option, } @@ -69,7 +70,7 @@ impl VirtualMachine { sys_module: sysmod, stdlib_inits, ctx, - frames: vec![], + frames: RefCell::new(vec![]), wasm_id: None, } } @@ -87,21 +88,24 @@ impl VirtualMachine { } pub fn run_frame(&mut self, frame: PyObjectRef) -> PyResult { - self.frames.push(frame.clone()); + self.frames.borrow_mut().push(frame.clone()); let frame = objframe::get_value(&frame); let result = frame.run(self); - self.frames.pop(); + self.frames.borrow_mut().pop(); result } - pub fn current_frame(&self) -> &Frame { - let current_frame = &self.frames[self.frames.len() - 1]; - objframe::get_value(current_frame) + pub fn current_frame(&self) -> Ref { + Ref::map(self.frames.borrow(), |frames| { + let index = frames.len() - 1; + let current_frame = &frames[index]; + objframe::get_value(current_frame) + }) } - pub fn current_scope(&self) -> &Scope { + pub fn current_scope(&self) -> Ref { let frame = self.current_frame(); - &frame.scope + Ref::map(frame, |f| &f.scope) } pub fn class(&mut self, module: &str, class: &str) -> PyObjectRef { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy