Skip to content

NEW FEATURE: Considerations in returns #159

Closed

Description

@MatiDragon-YT

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.

Activity

  1. XMDS commented on Jul 4, 2021

    @XMDS
    Member

    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.

  2. XMDS commented on Jul 4, 2021

    @XMDS
    Member

    About function commands:
    #45

  3. added this to the Language Specification milestone on Jul 6, 2021
  4. x87 commented on Sep 2, 2023

    @x87
    Collaborator
    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?

  5. MatiDragon-YT commented on Sep 3, 2023

    @MatiDragon-YT
    MemberAuthor

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

    Yes and thank

  6. x87 commented on Sep 3, 2023

    @x87
    Collaborator

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

  7. MiranDMC commented on Sep 3, 2023

    @MiranDMC

    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.

  8. x87 commented on Sep 3, 2023

    @x87
    Collaborator

    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.

  9. MiranDMC commented on Sep 4, 2023

    @MiranDMC

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

  10. MatiDragon-YT commented on Sep 5, 2023

    @MatiDragon-YT
    MemberAuthor

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

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

  11. MatiDragon-YT commented on Sep 5, 2023

    @MatiDragon-YT
    MemberAuthor

    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.

  12. MiranDMC commented on Jul 23, 2024

    @MiranDMC

    Already done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions