Skip to content

Conversation

@LunaStev
Copy link
Member

@LunaStev LunaStev commented Jan 12, 2026

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

  • Chained Accessors: Implemented parse_lvalue_tail to support recursive field access (.) and indexing ([]). This allows expressions like a.b[i].c to be treated as a single assignable target.
  • Robust Struct Parsing: Refactored parse_struct to better handle whitespace, newlines, and improved field type detection.
  • Generic Type Parsing: Updated parse_type_from_stream to use a centralized collector for generic types, ensuring consistent handling of types like ptr<T> or ptr<ptr<i32>>.
  • Assignability Validation: Integrated is_assignable checks during assignment parsing to prevent invalid operations on non-L-value expressions.

2. LLVM Backend & Codegen Overhaul

  • Recursive Address Resolution: Heavily refactored generate_address_ir in address.rs. It now recursively navigates through structs and arrays to calculate precise memory addresses for nested data structures.
  • Array Literals: Added gen_array_literal to generate IR for array initializers and improved IndexAccess to handle both pointer-based and value-based indexing seamlessly.
  • Inline Assembly (ASM) Upgrades: Overhauled gen_asm_stmt_ir to support various output types. It now performs automatic bitcasting and coercion between integers, pointers, and floats to match assembly register requirements.
  • Null Pointer Support: Added the null keyword as a native constant for null pointers across the backend.
  • Argument Coercion: Improved function call logic to automatically handle pointers-to-arrays and pointers-to-structs, simplifying passing complex data to functions.

3. Tooling

  • Test Runner: Updated run_tests.py with specific configurations for new test cases and dependency tracking.

…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>
@LunaStev LunaStev self-assigned this Jan 12, 2026
@LunaStev LunaStev added this to Wave Jan 12, 2026
@LunaStev LunaStev merged commit d174058 into wavefnd:master Jan 12, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this to Done in Wave Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant