We need an FnInfo #18

Closed
opened 2024-12-10 05:38:04 +00:00 by scott · 1 comment
Owner

🎶We need an info!🎶

The Fn Ast node type should have a field for an FnInfo object that Validate can generate. This should include:

  • a list of arities
  • it should be an enum that has a declared but not yet defined state
  • a list of bindings that it closes over

That way, when interpreting the Fn we can close over the necessary bindings.

Also, this needs to be stored out-of-band, since we can't mutate the AST when doing the validation pass.

Because of that we need a way of storing information about functions that can be a field on the Validator struct.

As it turns out, it looks like we can store this in a HashMap that uses a *const Ast pointer as the key, and an FnInfo object as the value. This map can then be borrowed by the Context object to successfully compile the function.

Also, the Validator locals bindings vector should allow storing of pointers to Ast function nodes so we can check arity for function calls where that's possible.

There should be three enum branches for that: 1. declared, not yet defined (with location info); 2. declared, with all the info; and 3. no information. (We can't even say not a function!)

That's also helpful, because at the end of a block, we can check to see if the bindings stack still has any declared-but-not-defined functions in it, and yell about it if they're there.

🎶We need an info!🎶 The `Fn` `Ast` node type should have a field for an `FnInfo` object that `Validate` can generate. This should include: * a list of arities * it should be an enum that has a declared but not yet defined state * a list of bindings that it closes over That way, when *interpreting* the `Fn` we can close over the necessary bindings. Also, this needs to be stored out-of-band, since we can't mutate the AST when doing the validation pass. Because of *that* we need a way of storing information about functions that can be a field on the `Validator` struct. As it turns out, it looks like we can store this in a HashMap that uses a `*const Ast` pointer as the key, and an `FnInfo` object as the value. This map can then be borrowed by the `Context` object to successfully compile the function. Also, the `Validator` locals bindings vector should allow storing of pointers to Ast function nodes so we can check arity for function calls where that's possible. There should be three enum branches for that: 1. declared, not yet defined (with location info); 2. declared, with all the info; and 3. no information. (We can't even say not a function!) That's also helpful, because at the end of a block, we can check to see if the bindings stack still has any declared-but-not-defined functions in it, and yell about it if they're there.
Author
Owner

Done! Fully implemented in 35e9d0373d

Done! Fully implemented in https://alea.ludus.dev/scott/rudus/commit/35e9d0373d7121b31cc3b8ab1f1c73b4cf4a61e3
scott closed this issue 2024-12-11 05:20:58 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: scott/rudus#18
No description provided.