Skip to content

Keep a stack of frames on the VM.#192

Closed
cthulahoops wants to merge 2 commits into
masterfrom
framestack
Closed

Keep a stack of frames on the VM.#192
cthulahoops wants to merge 2 commits into
masterfrom
framestack

Conversation

@cthulahoops
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread vm/src/vm.rs Outdated

// Construct frame:
let mut frame = Frame::new(code.clone(), scope);
let frame = Frame::new(code.clone(), scope);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To solve this mutability issue, I think we need to wrap Frame into a PyRef rather sooner than later. Then we can refer to it from multiple places.

if let PyObjectKind::Generator { ref mut frame } = gen.borrow_mut().kind {
frame.push_value(value.clone());
match frame.run_frame(vm)? {
match vm.run_frame(frame.clone())? {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change frame into a PyRef at this point as well.

Comment thread vm/src/vm.rs Outdated
pub fn run_frame(&mut self, frame: Frame) -> Result<ExecutionResult, PyObjectRef> {
let frame = self.ctx.new_frame(frame);
self.frames.push(frame.clone());
let mut frame = objframe::get_value(&frame);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can seperate the frame into a part that is immutable (like the codeobject) and a part that is mutable (like the current program counter lasti). Or at least give the frame a PyRef to the codeobject.

Comment thread vm/src/frame.rs
},
}

#[derive(Clone)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ow yeah!

Copy link
Copy Markdown
Collaborator Author

@cthulahoops cthulahoops Nov 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work though.

I'll guess I'll have to split the frame up somehow so we don't have to keep mutable references to it around.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe so too, and we should probably use more of the PyObject and PyFrame types, which are references (Rc<RefCell<>>), and we can borrow them mutably or immutably.

@youknowone youknowone deleted the framestack branch March 7, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants