Skip to content

Interpreter: switch statement lowering#72

Merged
Alonely0 merged 1 commit into
uutils:mainfrom
Franklin-Qi:feature-task#70-Interpreter-switch-statement-lowering
Jul 13, 2026
Merged

Interpreter: switch statement lowering#72
Alonely0 merged 1 commit into
uutils:mainfrom
Franklin-Qi:feature-task#70-Interpreter-switch-statement-lowering

Conversation

@Franklin-Qi

Copy link
Copy Markdown
Contributor

Add AST lowering for switch: evaluate the scrutinee once into a register, emit a branch chain for each case, and jump to the default branch or past the statement when nothing matches.

Match literal cases with Eq; match regex and typed-regex cases with Matches. Support default placed anywhere in the case list, including before later cases.

Fixes #70

@Alonely0 Alonely0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

At a first glance this looks great, but my head aches a bit too much for me to continue looking at a screen today, sorry. I'll push the review comments I have and try to do some more tomorrow.

Comment thread interpreter/src/types.rs Outdated
Comment thread interpreter/src/ir/lower.rs Outdated
Comment thread interpreter/src/ir/lower.rs Outdated
@Franklin-Qi

Copy link
Copy Markdown
Contributor Author

At a first glance this looks great, but my head aches a bit too much for me to continue looking at a screen today, sorry. I'll push the review comments I have and try to do some more tomorrow.

@Alonely0 Thank you for reviewing this. If you have a headache, you might want to rest and try some meditation to relieve it (this works very well for me).

Add AST lowering for switch: evaluate the scrutinee once into a register, emit a branch chain for each case, and jump to the default branch or past the statement when nothing matches.

Match literal cases with Eq; match regex and typed-regex cases with Matches.
Support default placed anywhere in the case list, including before later cases.

Fixes uutils#70
@Franklin-Qi Franklin-Qi force-pushed the feature-task#70-Interpreter-switch-statement-lowering branch from db2dcff to a37f099 Compare July 13, 2026 03:16
@Alonely0

Copy link
Copy Markdown
Collaborator

@Alonely0 Thank you for reviewing this. If you have a headache, you might want to rest and try some meditation to relieve it (this works very well for me).

That's good advice, ty! It's mostly due to eye-strain from astigmatism, so it might do wonders. I have been trying to get into meditation for a while, so I guess that's a good reason to try.

@Alonely0 Alonely0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me! switch statements are such monsters to implement hahahah.

@Alonely0 Alonely0 merged commit 1516a7c into uutils:main Jul 13, 2026
15 checks passed
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.

Interpreter: switch statement lowering.

2 participants