-
Notifications
You must be signed in to change notification settings - Fork 81
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
Better function call syntax for Pancake #994
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Make tail calls be of the form return f(); ...where they used to be of the form f(); Previously, if one wrote something like this: fun main() { f(); f(); } fun f() { ... } ...then the second call to f will never be executed, because the tail call eats up the stack frame and makes main return whatever the first call returned. This is confusing. Stand-alone function calls are still allowed, but parse to returning calls that save the return value in the variable ""; this should always be fresh since nothing parses to an empty variable.
DecCall is intended to support the following pattern: x = f(e1,...,en) Call (SOME(NONE, _)) is intended to support stand-alone calls, i.e. returning calls whose arguments are ignored
It's confusing that return f(); parses to TailCall, not RetCall
I first expected to need shape annotations on functions, but this is a dead end: function pointers make it so that we cannot statically determine which function is being called. Instead I've put shape annotations on the declaring calls themselves. At some point in the future we should probably make declarations available (mandatory or optional) on all declarations.
The cheats left are not trivial, but it's looking doable.
Declaring calls belong with the blocks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit revamps the function call syntax of Pancake to make it more intuitive. Previously two kinds of function calls were accepted as declarations:
This syntax is confusing --- the tail call will immediately return from
f()
, causing the second call tog()
to be never evaluated, contrary to programmer intuition.In the new style, we allow (and distinguish for purposes of compilation) four kinds of calls:
Declaring calls, unlike other calls, cannot have exception handlers; if
g()
above raises an exception, this would leavex
uninitialised. Note that declaring calls need a shape annotation on the variable, because in general the shape of the return value is not statically known. (I initially tried adding this annotation on the function declaration instead, but this incorrectly assumes it is always statically known which function is being called).Stand-alone calls have their return values ignored, but unlike tail calls, won't cause the callee to also return.
Tail calls have the
return
in front of them; hopefully that way nobody will be surprised when they return :)