feat: implement input() statement and L-value generation #259
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 the
input()statement to support interactive console applications and performs a significant refactor of the expression code generation logic. By separating L-value (address) generation from R-value (value) generation, the compiler now supports more complex assignment targets and memory-modifying operations.Key Changes
1. Interactive
input()StatementStatementNode::Inputand implementedparse_inputto supportinput("format", targets...)syntax.wave_format_to_scanfto bridge Wave format strings with C-stylescanf.scanf, passing the memory addresses of target variables.scanfsuccessfully reads the expected number of arguments; otherwise, the program exits with code 1.2. L-Value Generation & Codegen Refactor
expression.rsinto a module containingmod.rs,rvalue.rs, andlvalue.rs.generate_lvalue_ir): Implemented dedicated logic to retrieve the memory address of an expression. This supports:arr[i],obj.field, and even combined forms like(deref p).field[idx].3. Interactive Runtime Support
Stdio::inherit()for the child process. This allows the compiled Wave program to interact directly with the user's terminal for standard input/output.4. Testing
test74.waveto demonstrate and verify the newinput()functionality.Example Usage