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

Compiletime rgb() evaluation #2115

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ike709
Copy link
Collaborator

@ike709 ike709 commented Nov 29, 2024

rgb() is supposed to be considered a constant when its args are constant, as shown in the included unit test which passes in BYOND.

To facilitate this, rgb() handling has been moved to the compiler and the DMExpression now implements TryAsConstant().

As a bonus, the peephole optimizer will attempt to evaluate it at compiletime whenever Rgb's argtype is FromStack and its argcount matches a preceding PushNFloats count. That means we'll compiletime eval something like rgb(255,255,255) but not rgb(255,255,255, space=foo()).

@boring-cyborg boring-cyborg bot added the Compiler Involves the OpenDream compiler label Nov 29, 2024
@boring-cyborg boring-cyborg bot added Client Involves the OpenDream client Runtime Involves the OpenDream server/runtime labels Nov 30, 2024
@github-actions github-actions bot added size/L and removed size/S labels Nov 30, 2024
@ike709 ike709 changed the title Partial support for compiletime rgb() evaluation Compiletime rgb() evaluation Nov 30, 2024
DMCompiler/SharedOperations.cs Fixed Show fixed Hide fixed
DMCompiler/SharedOperations.cs Fixed Show fixed Hide fixed
DMCompiler/SharedOperations.cs Fixed Show fixed Hide fixed
DMCompiler/SharedOperations.cs Fixed Show fixed Hide fixed
DMCompiler/SharedOperations.cs Fixed Show fixed Hide fixed
}

// TODO: There is a difference between passing null and not passing a fourth arg at all
if (a is null) {

Check notice

Code scanning / InspectCode

'if' statement can be rewritten as '?:' expression Note

Convert into '?:' expression
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The huge ternary is less readable, so no.

Copy link
Member

Choose a reason for hiding this comment

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

Yea I think this is a notice we should turn off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client Involves the OpenDream client Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants