Skip to content
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

Closes #81. Capture self as part of a closure. #131

Merged
merged 1 commit into from
Jan 27, 2018

Conversation

faultyserver
Copy link
Member

Closures (blocks and anonymous functions) now also "capture" the value of self where they are defined. This is actually done by the functor itself, rather than the ClosureScope, but that implementation is transparent to the rest of the interpreter.

This PR also adds a few extra specs to ensure that Invocations always restore the original value of self after executing.

Closures (blocks and anonymous functions) now also "capture" the value of `self` where they are defined. This is actually done by the functor itself, rather than the `ClosureScope`, but that implementation is transparent to the rest of the interpreter.
@faultyserver faultyserver added this to the Next milestone Jan 27, 2018
@faultyserver faultyserver merged commit fe72e5a into myst-lang:master Jan 27, 2018
@faultyserver faultyserver deleted the bug/self_closures branch January 27, 2018 02:04
faultyserver added a commit to faultyserver/myst that referenced this pull request Jan 27, 2018
…r blocks on static methods.

`Invocation` was incorrectly determining the value of `self` to use when calling a function. Before myst-lang#131, it was only checking if the Call had a receiver, and would use that value if it did. After myst-lang#131, if the Call did _not_ have a receiver, it would then check if the functor was a closure, and use the closed value of `self` if it was.

Now, Invocations _always_ perform both checks, with closures taking higher precedence than Call receivers (though, both will be pushed to the stack if the conditions are met).

Before this commit, I was very confused why static methods weren't working while non-static methods were. I assumed it was an issue with `scope` vs `instance_scope` on Types or something like that, but had no idea.

Now, though, I'm even more confused how _any_ case was working previously, as the Call receiver was _always_ being pushed as the value of `self`. At least with this version of the code, the value of `self` that will be present is more explicit and well-specified. ¯\_(ツ)_/¯
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.

1 participant