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

Optional function arguments #631

Merged
merged 2 commits into from
Sep 6, 2024
Merged

Optional function arguments #631

merged 2 commits into from
Sep 6, 2024

Conversation

hugomg
Copy link
Member

@hugomg hugomg commented Sep 5, 2024

This PR allows Pallene functions to receive optional arguments. Currently any rightmost "any" argument can be optional. In the future we may want to consider a special optional type, for added type safety.

This change allows us to get rid of the math.ln hack. Good riddance!

Currently we consider rightmost "any" arguments to be optional.
In the future we could consider requiring that the programmer annotate
optional arguments with "?", and also allow things like "string?".

Dynamic Lua calls now can have a variable number of stack arguments.
Lua's math.log has an optional second parameter for the base, with the
default being the natural logarithm. Previously, Pallene didn't have
optional arguments so we needed a separate function for 1-argument
math.log. Now that's no longer necessary :)

I have checked the generated assembly and can confirm that the C
compiler can inline the pallene_math_log and directly call log() from
math.h when the base argument is known.
@hugomg hugomg requested a review from singul4ri7y September 5, 2024 12:00
@hugomg hugomg merged commit 104733f into master Sep 6, 2024
2 checks passed
@hugomg hugomg deleted the optional-arguments branch September 6, 2024 11:10
Copy link
Contributor

@singul4ri7y singul4ri7y left a comment

Choose a reason for hiding this comment

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

It looks good overall, just some minor nits.

src/pallene/coder.lua Show resolved Hide resolved
src/pallene/pallenelib.lua Show resolved Hide resolved
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.

2 participants