Skip to content

transpile: Improve case translation - #1776

Open
Rua wants to merge 8 commits into
immunant:masterfrom
Rua:pattern-conversion
Open

transpile: Improve case translation#1776
Rua wants to merge 8 commits into
immunant:masterfrom
Rua:pattern-conversion

Conversation

@Rua

@Rua Rua commented May 4, 2026

Copy link
Copy Markdown
Contributor

Translating case statements is currently a very ad-hoc affair, so this is an attempt to make it a bit more generic and flexible. expr_to_pat now converts expressions to equivalent patterns, preserving the semantics and returning None if an expression with no equivalent is encountered.

Translation functions can now use is_pattern to detect if they are translating an expression that's meant to appear inside a Rust pattern, and adjust accordingly. That will help towards getting #1775 to work. Currently, all expressions that cannot (conservatively) be translated in pattern context return a translation error. That will then trigger fallback to directly using the ConstIntExpr value that's provided inside the Case value.

Additionally, it seems that it fixes a missing macro expansion in macrocase.c, so that's a bonus!

@Rua
Rua force-pushed the pattern-conversion branch 8 times, most recently from e63622e to 8eca20d Compare May 5, 2026 12:25
@Rua Rua changed the title transpile: Add is_pattern to ExprContext for customized case translation transpile: Improve case translation May 5, 2026
@Rua
Rua force-pushed the pattern-conversion branch 3 times, most recently from e437818 to a0d125a Compare May 5, 2026 13:59
@Rua
Rua force-pushed the pattern-conversion branch 8 times, most recently from 15a09e8 to 698955d Compare May 21, 2026 18:30
@Rua
Rua force-pushed the pattern-conversion branch 3 times, most recently from f0597ef to 8d67aeb Compare August 6, 2026 10:14
@Rua
Rua force-pushed the pattern-conversion branch from 8d67aeb to a688900 Compare August 6, 2026 10:16
@Rua
Rua marked this pull request as ready for review August 6, 2026 10:23
@Rua
Rua force-pushed the pattern-conversion branch from a688900 to 627d579 Compare August 6, 2026 10: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.

1 participant