Skip to content

Comments

Compiletime rgb() evaluation#2115

Merged
wixoaGit merged 9 commits intoOpenDreamProject:masterfrom
ike709:compilergb
Aug 22, 2025
Merged

Compiletime rgb() evaluation#2115
wixoaGit merged 9 commits intoOpenDreamProject:masterfrom
ike709:compilergb

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
Copy link
Member

@wixoaGit wixoaGit left a comment

Choose a reason for hiding this comment

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

This breaks rgb(r=1, 2, 3). It should give #010203 but it instead gives #010000.

@ike709 ike709 marked this pull request as draft February 8, 2025 17:42
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

…lergb

# Conflicts:
#	DMCompiler/SharedOperations.cs
#	OpenDreamRuntime/Procs/DMOpcodeHandlers.cs
Code was in the wrong block
@wixoaGit wixoaGit marked this pull request as ready for review August 22, 2025 02:44
@wixoaGit wixoaGit merged commit 87f79ca into OpenDreamProject:master Aug 22, 2025
18 checks passed
ColorHelpers.ColorSpace space = ColorHelpers.ColorSpace.RGB;

if (arguments.Item1 != null) {
string result = "#000000";

Check warning

Code scanning / InspectCode

Assignment is not used Warning

Value assigned is not used in any execution path
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