feat: implement increment/decrement operators and semantic mutability validation#256
Merged
LunaStev merged 1 commit intowavefnd:masterfrom Dec 25, 2025
Merged
Conversation
Add support for pre/post-increment (`++`) and pre/post-decrement (`--`)
operators, along with a new semantic validation pass.
Changes:
- AST:
- Add `IncDec` expression variant with `IncDecKind` (PreInc, PreDec,
PostInc, PostDec).
- Add `Mutability` to AST for better tracking.
- Parser:
- Parse prefix `++`/`--` in `parse_unary_expression`.
- Parse postfix `++`/`--` in `parse_expression` (using lookahead).
- Add `is_assignable` check to ensure operators are applied to valid
L-values (variables, derefs, fields, indices).
- Integrate a new `verification` module for semantic checks.
- Verification (New Module):
- Implement `validate_program` to check mutability rules.
- Ensure modifications (assignments, inc/dec) target mutable variables.
- Traverse AST nodes and scopes to track variable mutability.
- Error on immutable binding modifications.
- LLVM Codegen:
- Generate IR for `IncDec` expressions:
- Support integers, floats, and pointers.
- Handle pre/post logic (return new vs old value).
- Use `load` -> `add/sub` -> `store` pattern.
- Fix `generate_address_ir` to handle grouped expressions and dereferences properly.
- Tests:
- Add `test72.wave` and `test73.wave` covering:
- Basic variable types.
- Increment/decrement on variables and dereferenced pointers.
This update enhances the language with standard C-style inc/dec operators
and strengthens type safety through mutability verification.
Signed-off-by: LunaStev <luna@lunastev.org>
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.
This PR introduces support for standard C-style increment (
++) and decrement (--) operators in both prefix and postfix forms. Additionally, it implements a new semantic verification layer to enforce mutability rules, ensuring that variables are only modified when explicitly declared as mutable.Key Changes
1. AST & Parser Enhancements
IncDecexpression variant andIncDecKind(PreInc, PreDec, PostInc, PostDec) to the AST.parse_unary_expressionto handle prefix operators.parse_expressionwith lookahead logic to identify postfix operators.is_assignablechecks to ensure++/--are only applied to valid targets (variables, array indices, struct fields, and dereferenced pointers).2. New Semantic Verification Module
verificationmodule that performs a full AST traversal before code generation.Mutabilitystatus.let x = 5; x++;will now fail during semantic analysis).3. LLVM Code Generation
load->add/sub->storepattern for all supported types:generate_address_irto robustly handle grouped expressions and complex dereferences.4. Testing & Documentation
test72.waveandtest73.wave.Example Usage
Benefits