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

Support Early Returns #100

Open
franklinsch opened this issue Jan 25, 2018 · 2 comments
Open

Support Early Returns #100

franklinsch opened this issue Jan 25, 2018 · 2 comments

Comments

@franklinsch
Copy link
Collaborator

franklinsch commented Jan 25, 2018

Currently, an if-else block cannot have an early return in either body.

if ... {
  return 
} else {
}
// more code
@franklinsch
Copy link
Collaborator Author

How can we do this in IULIA?

@DJRHails
Copy link
Member

DJRHails commented Jul 6, 2018

Interesting rabbit hole:

Originally the thought was IULIA/YUL can support this using labels - which are now depreciated. However Jumping doesn't update stack reference, this means that if any local variables are used within an if/else block the jump to the end of the function breaks everything.

We are therefore left with a few options as far as I can see:

  1. Support early returns only when there are no local variables
  2. Add a boolean at the start of every function - isReturned - which is set on ret := being updated. Then at the exit of every if/else block it would check isReturned, and jump to end of current scope if set. Recursing up until finally the end of scope is the function end.
  3. Don't support early returns in any sense
  4. 🌟 Think of some clever way to track how many local variables have been added, then POP before jumping.
  • Update: Probably the best way to "hack" this feature would be to have a function root variable that gets incremented as the stack increases then pop that many times before jumping.

@DJRHails DJRHails changed the title Support combination of early returns in if-else blocks Support Early Returns Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants