feat: support compound assignment operators (+=, -=, *=, /=, %=) - #8
Merged
Conversation
- Lexer emits PlusEqual/MinusEqual/StarEqual/SlashEqual/PercentEqual - VarAssignStatement carries an optional compound BinaryOp; parsing is shared between statement position and for-loop post expressions - Codegen emits the lvalue once, then load-apply-store for compound ops, restricted to int targets - Unit tests for lexing/parsing plus e2e tests including compound assignment through a pointer and in for-post; verified against clang Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
Adds C compound assignment operators:
+=,-=,*=,/=,%=.PlusEqual/MinusEqual/StarEqual/SlashEqual/PercentEqualtokens (one-character lookahead in the existing operator arms).VarAssignStatementnow carriesop: Option<BinaryOp>(Nonefor plain=). The= / op=tail parsing is factored into a sharedparse_assignmenthelper used by both statement position and thefor-loop post clause, sofor (...; ...; i += 1)works.*p += 2); compound assignment is type-checked to int targets.Tests: lexer + parser unit tests and 3 e2e tests (all five operators chained, compound assignment through a pointer, compound assignment in for-post). Suite is 29 unit + 30 e2e green, clippy/fmt clean, and the behavior is differentially verified against clang.
cc @hand-burger — this is the compound-assignment follow-up mentioned on #7;
++/--coming next on top of this.🤖 Generated with Claude Code