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

SCM function handling by GOSUB return. #96

Merged
merged 4 commits into from
Mar 11, 2024
Merged

Conversation

MiranDMC
Copy link
Collaborator

@MiranDMC MiranDMC commented Mar 7, 2024

No description provided.

{
if (thread->SP == 0 && thread->IsCustom() && !IsLegacyScript(thread)) // CLEO5 - allow use of GOSUB `return` to exit cleo calls too
{
return opcode_0AB2(thread); // try CLEO's function return
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0051 isn't var args opcode. please use CleoReturnGeneric directly

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return GetInstance().OpcodeSystem.CleoReturnGeneric(0x0051, thread, false);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is thread->IsCustom() check necessary? we might be able to use it in main.scm too

Copy link

@x87 x87 Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about showing a custom message when return is found outside of any gosub or scm function?

if sp ==0 && !IsLegacyScript(thread) {
 get scm func
 if func == nullptr {
   return message ("return is used outside of subroutine (gosub or scm call), suspended")
 }
 call returnGeneric
}
call 0051

Copy link

@x87 x87 Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return true/false does not return any arguments, it's condition flag. return true/false is the same as cleo_return_with true/false

that's the point. even if you don't care about condition result you are now forced to provide one in order to use return in a function now. I used something like return true everywhere in cleo testing library.

now, with this change you should be able to use just return and get consistent results with return true/false .

Copy link

@x87 x87 Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function function: result gosub
return OK ERROR OK
return true/false OK ERROR OK
return true/false values ERROR OK ERROR

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so a function with no output and gosub will be treated in the same way. you can exit both using return or return true/false, depending on whether or not you care about condition flag.

return true/false values syntax can only be used in functions returning something.

Copy link

@x87 x87 Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0AB2: cleo_return should always exit from SCM function, even we are currently in gosub.
2002: return_with should check if we are in a gosub and exit from gosub. 0 returned values expected.
2003 return_fail should check if we are in a gosub and exit from gosub, setting condition flag to false

Copy link
Collaborator Author

@MiranDMC MiranDMC Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.
What to do with main scm is still debatable. In theory legacy mode can be enabled in cleo.ini, but then the setting will be shared between main game and all mod packs. scm3 scm4 filetype extension would make sense.

@x87 x87 mentioned this pull request Mar 9, 2024
59 tasks
@x87 x87 force-pushed the universal_return_POC branch from be46b62 to f30bedc Compare March 10, 2024 22:33
@x87
Copy link

x87 commented Mar 10, 2024

appeared to be working. tests and sanny updated to support single return in functions.

@MiranDMC MiranDMC marked this pull request as ready for review March 11, 2024 08:59
@MiranDMC MiranDMC merged commit a4a64b6 into master Mar 11, 2024
@MiranDMC MiranDMC deleted the universal_return_POC branch March 12, 2024 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants