Skip to content

Fix locals #599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/snippets/builtin_locals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

a = 5
b = 6

loc = locals()

assert loc['a'] == 5
Copy link
Contributor

Choose a reason for hiding this comment

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

(Could you do a similar test inside a function? This would help in case we try optimizing locals access in the future.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure 😀

assert loc['b'] == 6

def f():
c = 4
a = 7

loc = locals()

assert loc['a'] == 4
assert loc['c'] == 7
assert not 'b' in loc

12 changes: 2 additions & 10 deletions vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,8 @@ impl VirtualMachine {
}

pub fn get_locals(&self) -> PyObjectRef {
// let scope = &self.frames.last().unwrap().locals;
// scope.clone()
// TODO: fix this!
self.get_none()
/*
match (*scope).payload {
PyObjectPayload::Scope { scope } => { scope.locals.clone() },
_ => { panic!("Should be scope") },
} // .clone()
*/
let scope = self.current_scope();
scope.locals.clone()
}

pub fn context(&self) -> &PyContext {
Expand Down