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

Better compiler accuracy for functions named differently/the same as the containing script name #1986

Closed
wants to merge 1 commit into from

Conversation

CST1229
Copy link
Contributor

@CST1229 CST1229 commented Dec 1, 2024

Description

This is a port of a very tiny compiler assembly accuracy improvement from UTMTCE.

You know that one pushi.e instruction for function definitions that is -1 sometimes and -6 other times? That instructions's value is -1 if the function's name is the same as the script it's in, and -6 if it isn't.
Not sure what effect this has on the runtime (possibly none), but it does make a difference in the assembly.

Caveats

This is done by comparing to the code entry name, I'm not sure if it should be done like that. (Iterating through all script entries might be cleaner but that would also probably be slower.)

…the containing script name

this is done using the code name, not sure if it should be.
Copy link
Member

@colinator27 colinator27 left a comment

Choose a reason for hiding this comment

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

As a small note, I think I did this already in the underanalyzer branch as part of the small compiler upgrades. I think in GM 2024 and above they changed this behavior as well (so it only uses -1), but I can fix the merge conflict for that once this gets merged in.

else
cw.Emit(Opcode.PushI, DataType.Int16).Value = (short)-1; // todo: -6 sometimes?
{
cw.Emit(Opcode.PushI, DataType.Int16).Value = (short)-6;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment explaining tbe -6, similar to above? Probably cleaner to move the comment outside the else if and have it explain both cases.

cw.Emit(Opcode.PushI, DataType.Int16).Value = (short)-16;
}
else if (cw.compileContext.OriginalCode?.Name?.Content == ("gml_GlobalScript_" + funcDefName.Text))
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems kinda messy but also dont know any other cleaner way.
I guess linq maybe, but dunno if we have access to the functions here?

@CST1229
Copy link
Contributor Author

CST1229 commented Dec 2, 2024

As a small note, I think I did this already in the underanalyzer branch as part of the small compiler upgrades.

oh i didn't know. i think i might just close this pr then?

@CST1229 CST1229 closed this Dec 2, 2024
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.

3 participants