Skip to content

bugc: add the % operator - #321

Merged
gnidan merged 1 commit into
mainfrom
bugc-modulo
Oct 4, 2026
Merged

gnidan merged 1 commit into
mainfrom
bugc-modulo

Conversation

@gnidan

@gnidan gnidan commented Oct 4, 2026

Copy link
Copy Markdown
Member

BUG had no way to take a remainder. The IR already had a mod binary op, the EVM generator already mapped it to MOD, and constant folding already handled it, so only the front end was missing. This adds % to the parser, at the same precedence as * and /, and lets the typechecker accept it on numeric operands. IR generation already mapped % to mod.

BUG has no signed integer types, so MOD is the only opcode involved; there is no SMOD case. A zero divisor behaves as it does for /: the constant folder leaves x % 0 alone, and at run time the EVM's MOD returns 0.

Tests cover parsing and precedence, typechecking, IR generation, constant folding, and a behavioral test that compiles and runs programs at optimization levels 0 through 3 (1071 % 462 is 147, and x % 0 is 0, as is x / 0).

@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-10-04 18:16 UTC

@gnidan
gnidan merged commit 94fef6a into main Oct 4, 2026
7 checks passed
@gnidan
gnidan deleted the bugc-modulo branch October 4, 2026 18:13
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