Functions should properly close over bindings #16
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Blocks
#13 Bring Prelude into Rust
scott/rudus
Reference: scott/rudus#16
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently, this gives a panic,
unbound name foo
.Should output
:foo
. Currently, I'm pretty sure this is because functions aren't capturing their context properly when evaluating thefn
ast node (and not when they're actually run).This is what's causing the
unbound name base
errors now that I'm working on importing Prelude in #13 (comment).The proper way to do this is to do a validation/compile pass, and in that, enumerate the bindings the function closes over, and then, instead of cloning the whole locals stack, create a new locals stack that only includes those bindings that are closed over.
That will also mean that a function actually should own a context? The lifetimes are going to be wild there, but let's give it a shot.
(That also means that, thankfully, generating stack traces should be pretty straightforward?)
With the work I've done today, circa
35e9d0373d
, we have the validator properly identifying the values a function closes over, stuffing them into a hash table with the pointer to the Ast node as the key, and a HashSet containing the bindings that are closed over.What's left to do is to rework the
Fn
branch ofcontext::Context::eval
to become its ownContext
-like thing that can be.eval
ed.This is working fine in a Ludus script, as of
6a01089973
. Pulling from a simplified Prelude also works.There's some weirdness, though, in Prelude. I don't think this is done until #13 is fully accomplished.
Forward declarations were not working. They are now, with
273267f61d
. The long and short of it is that we need to update closed-over bindings after the function is defined.Still: testing required.
Looks like it works now! Same commit as before to have gotten them right.