feat: advanced L-value parsing and robust LLVM codegen for structs, arrays, and inline asm#268
Merged
LunaStev merged 1 commit intowavefnd:masterfrom Jan 12, 2026
Conversation
…rays, and inline asm This commit introduces significant improvements to both the parser and the LLVM backend. The parser now correctly handles complex lvalues (field access and indexing), while the LLVM backend has been refactored to support recursive address generation, array literals, and robust inline assembly type coercion. Changes: - **Parser Enhancements**: - Implemented `parse_lvalue_tail` to support chained field access (`.`) and indexing (`[]`). - Refactored `parse_struct` to be more robust, including whitespace/newline skipping and improved field type parsing. - Updated `parse_type_from_stream` to handle generic types like `ptr<T>` using a centralized generic collector. - Refactored assignment parsing to validate "assignability" via `is_assignable`. - **LLVM Backend & Codegen**: - **Address Generation**: Heavily refactored `generate_address_ir` in `address.rs` to recursively resolve addresses for field access, array indexing, and dereferences. - **Array Support**: Added `gen_array_literal` for IR generation of array initializers and improved `IndexAccess` to handle both pointer-based and value-based indexing. - **Inline Assembly**: Overhauled `gen_asm_stmt_ir` to support a wider range of output types with automatic bitcasting and integer/pointer/float coercion. - **Constants**: Added support for the `null` keyword as a null pointer constant. - **Coercion**: Improved function call argument coercion, specifically for passing pointers-to-arrays and pointers-to-structs. - **Syntax & Cleanup**: - Updated dereference syntax in tests (transitioning towards `deref` keyword usage). - Cleaned up manual pointer/dereference logic in `stmt.rs` and `pointers.rs`. - **Tooling**: - Updated `run_tests.py` with specific handling for new test cases and dependencies. These changes enable more complex data structure manipulations and provide a more stable foundation for future language features. 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 significantly enhances Wave's capability to handle complex data structures and low-level operations. By implementing recursive L-value parsing and a more robust LLVM backend, the compiler now supports chained memory access (e.g.,
obj.field[index].subfield), proper array literal initialization, and sophisticated type coercion for inline assembly and function calls.Key Changes
1. Advanced Parser & L-value Logic
parse_lvalue_tailto support recursive field access (.) and indexing ([]). This allows expressions likea.b[i].cto be treated as a single assignable target.parse_structto better handle whitespace, newlines, and improved field type detection.parse_type_from_streamto use a centralized collector for generic types, ensuring consistent handling of types likeptr<T>orptr<ptr<i32>>.is_assignablechecks during assignment parsing to prevent invalid operations on non-L-value expressions.2. LLVM Backend & Codegen Overhaul
generate_address_irinaddress.rs. It now recursively navigates through structs and arrays to calculate precise memory addresses for nested data structures.gen_array_literalto generate IR for array initializers and improvedIndexAccessto handle both pointer-based and value-based indexing seamlessly.gen_asm_stmt_irto support various output types. It now performs automatic bitcasting and coercion between integers, pointers, and floats to match assembly register requirements.nullkeyword as a native constant for null pointers across the backend.3. Tooling
run_tests.pywith specific configurations for new test cases and dependency tracking.