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

Functions and function calling needs a cleanup #38

Closed
jonathanhogg opened this issue Feb 6, 2024 · 0 comments · Fixed by #40
Closed

Functions and function calling needs a cleanup #38

jonathanhogg opened this issue Feb 6, 2024 · 0 comments · Fixed by #40
Assignees
Labels
🚀 enhancement New feature or request 💬 language Anything to do with the parser/evaluator/VM
Milestone

Comments

@jonathanhogg
Copy link
Owner

The function code is a bit of a mess, particularly where it comes to a division between native Python functions and Flitter functions. This is what I think needs doing:

  • debug() should just be a @context_func in functions.pyx and all special pleading for it removed
  • move references into the Context class and make sample() a @context_func as well
  • allow func to declare recursive functions – this should just be a case of adding the function name before the parameters onto lnames list before compiling the body and then pushing it onto the lnames stack as part of the calling convention
  • box all Flitter functions as Python function-like objects – basically turn call_helper() into a callable class wrapper around func Programs
  • make all function calling use the Python call convention – dump CallFast and have Call just use PyObject_CallObject() or PyObject_Call() depending on whether any kwargs have been popped off the stack
  • let the normal Python call stack handle and throw recursion errors as necessary

An advantage of all of this is that it will allow for higher-order functions, like passing Flitter functions into native functions as arguments. It'll also let me Cython-optimise the, currently quite slow, sample() function.

This also paves the way for possibly allowing functions to be passed into the rendering pipeline as attributes of Nodes…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 enhancement New feature or request 💬 language Anything to do with the parser/evaluator/VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant