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

NEW FEATURE: Considerations in returns #159

Closed
MatiDragon-YT opened this issue Jul 4, 2021 · 11 comments
Closed

NEW FEATURE: Considerations in returns #159

MatiDragon-YT opened this issue Jul 4, 2021 · 11 comments

Comments

@MatiDragon-YT
Copy link
Member

MatiDragon-YT commented Jul 4, 2021

I don't know how to explain this without making it seem redundant...

Syntax

return [value]

Examples

return                ->   0051: return                    // default
return true           ->   0485: return_true               // default
return false          ->   059A: return_false              // default
return is false       ->   0AA1: else_return               // CLEO
else return           ->   0AA1: else_return               // CLEO
return 0              ->   0AB2: cleo_return 1 0           // CLEO
return 1@             ->   0AB2: cleo_return 1 1@          // CLEO
return 3@ 5@ 7@       ->   0AB2: cleo_return 3 3@ 5@ 7@    // CLEO
return (4@, 6@, 8@)   ->   0AA7: function_return 4@ 6@ 8@  // CLEO
return <5@, 7@, 9@>   ->   0AA8: method_return 5@ 7@ 9@    // CLEO

Never use OP 0AA7 or 0AA8, so you are probably typing something nonsensical.

@XMDS
Copy link

XMDS commented Jul 4, 2021

They only exist as keywords
The command to call the function should not be included
I don’t really agree with this form of returning value references, we only need to update the keyword file.

@XMDS
Copy link

XMDS commented Jul 4, 2021

About function commands:
#45

@x87 x87 added this to the Language Specification milestone Jul 6, 2021
@x87
Copy link
Collaborator

x87 commented Sep 2, 2023

return 0              ->   0AB2: cleo_return 0             // CLEO

what if I want to return zero from the cleo function?

in opcode form:

0AB2: cleo_return 1 0

how do I write it using just return?

@MatiDragon-YT
Copy link
Member Author

MatiDragon-YT commented Sep 3, 2023

oops sorry, I didn't notice that error, I corrected.

Yes and thank

@x87
Copy link
Collaborator

x87 commented Sep 3, 2023

how would I write 0AB2: cleo_return 0 then? just return?

@MiranDMC
Copy link

MiranDMC commented Sep 3, 2023

This very risky. The distinction between gosub's and CLEO's return should be obvious. Worst debugging sessions I had was caused by muscle memory and using return instead of cleo_return. Scripts crashes without obvious reason.

@x87
Copy link
Collaborator

x87 commented Sep 3, 2023

That's the idea. Just like end closes the innermost loop or if statement, return acts either as 0051 or 0AB2 depending on current scope. This resolution could be done in compile-time.

@MiranDMC
Copy link

MiranDMC commented Sep 4, 2023

Hm, ok. Will it work with functions having multiple exit points?

@MatiDragon-YT
Copy link
Member Author

MatiDragon-YT commented Sep 5, 2023

how would I write 0AB2: cleo_return 0 then? just return?

return undefined or return null or !return or return void(0)

@MatiDragon-YT
Copy link
Member Author

Hm, ok. Will it work with functions having multiple exit points?
@MiranDMC

if you do a code pre-processing, i.e. a text scanner, which identifies the matches and replaces them with the necessary text, there should be no problems with anything.

in fact @x87, can't you include in SannyBuilder, a tool to create these auto-replaceable texts? This is something extremely easy to do in JavaScript, with a String.Replacer() with a RegularExpression in the first parameter and a STRING in the second.

@MiranDMC
Copy link

Already done.

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

4 participants