Skip to content

Add nonlocal support. #839

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
Apr 17, 2019
Merged

Add nonlocal support. #839

merged 2 commits into from
Apr 17, 2019

Conversation

windelbouwman
Copy link
Contributor

@cthulahoops I'm a bit confused about the load_cell name. Is it the same as the load_deref opcode in cpython?

@codecov-io
Copy link

codecov-io commented Apr 16, 2019

Codecov Report

Merging #839 into master will increase coverage by 0.92%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #839      +/-   ##
==========================================
+ Coverage   63.12%   64.04%   +0.92%     
==========================================
  Files          87       87              
  Lines       14344    14892     +548     
  Branches     3248     3519     +271     
==========================================
+ Hits         9055     9538     +483     
- Misses       3154     3213      +59     
- Partials     2135     2141       +6
Impacted Files Coverage Δ
vm/src/bytecode.rs 58.29% <ø> (ø) ⬆️
vm/src/compile.rs 77.94% <100%> (+0.02%) ⬆️
vm/src/frame.rs 76.08% <100%> (+8.37%) ⬆️
vm/src/obj/objrange.rs 62.22% <0%> (-1.13%) ⬇️
vm/src/symboltable.rs 55.35% <0%> (+0.35%) ⬆️
vm/src/function.rs 54.01% <0%> (+3.51%) ⬆️
vm/src/obj/objsequence.rs 64.85% <0%> (+10.44%) ⬆️
vm/src/obj/objslice.rs 76.84% <0%> (+14.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7275c7...6d1b807. Read the comment docs.

@cthulahoops
Copy link
Collaborator

@cthulahoops I'm a bit confused about the load_cell name. Is it the same as the load_deref opcode in cpython?

Yes. I think cell, deref, and nonlocal all refer to roughly the same thing. (A cell stores variables for non-local access, and you deref the cell?)

I suggest we rename load_cell to load_nonlocal.

vm/src/frame.rs Outdated
.iter()
.skip(1)
.next()
.unwrap()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This panic here is an interesting case. It looks like cpython raises SyntaxError is it can't find the relevant variable at compile time. You can't create a variable in an outer scope with nonlocal, only change it. (Unlike global.)

We can't do better than this yet, but worth using .expect("no outer scope for non-local")?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allright, good suggestion! A next topic for me would be to detect more errors at compile time, like cpython does, and raise proper syntax errors.

@windelbouwman windelbouwman merged commit 240c1e4 into master Apr 17, 2019
@windelbouwman windelbouwman deleted the nonlocal branch April 24, 2019 07:51
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.

3 participants