dev icon indicating copy to clipboard operation
dev copied to clipboard

NEW FEATURE: Considerations in returns

Open MatiDragon-YT opened this issue 3 years ago • 10 comments

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.

MatiDragon-YT avatar Jul 04 '21 00:07 MatiDragon-YT

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 avatar Jul 04 '21 08:07 XMDS

About function commands: https://github.com/sannybuilder/dev/issues/45

XMDS avatar Jul 04 '21 08:07 XMDS

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?

x87 avatar Sep 02 '23 18:09 x87

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

Yes and thank

MatiDragon-YT avatar Sep 03 '23 01:09 MatiDragon-YT

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

x87 avatar Sep 03 '23 02:09 x87

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.

MiranDMC avatar Sep 03 '23 03:09 MiranDMC

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.

x87 avatar Sep 03 '23 14:09 x87

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

MiranDMC avatar Sep 04 '23 03:09 MiranDMC

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

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

MatiDragon-YT avatar Sep 05 '23 00:09 MatiDragon-YT

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.

MatiDragon-YT avatar Sep 05 '23 00:09 MatiDragon-YT

Already done.

MiranDMC avatar Jul 23 '24 00:07 MiranDMC