dev
dev copied to clipboard
NEW FEATURE: Considerations in returns
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.
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.
About function commands: https://github.com/sannybuilder/dev/issues/45
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
?
oops sorry, I didn't notice that error, I corrected.
Yes and thank
how would I write 0AB2: cleo_return 0
then? just return
?
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.
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.
Hm, ok. Will it work with functions having multiple exit points?
how would I write
0AB2: cleo_return 0
then? justreturn
?
return undefined
or return null
or !return
or return void(0)
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.
Already done.