feat: implement generics, explicit type casting, and static globals#306
Merged
LunaStev merged 1 commit intowavefnd:masterfrom Mar 8, 2026
Conversation
This commit introduces the foundational infrastructure for generic
programming, explicit type casting via the `as` operator, and global
static variables. It also significantly matures the target-specific
preprocessing and backend control.
Changes:
- **Generics Support**:
- **AST & Parser**: Added `generic_params` to `FunctionNode` and
`StructNode`. Added `type_args` to function calls.
- **Parsing**: Implemented `parse_generic_param_names` and enhanced
the type parser to handle nested generic arguments and
top-level split logic.
- **Stdlib**: Refactored core modules to provide generic utilities,
including `TypedBuffer<T>`, `ptr_swap<T>`, and generic math functions
(`num_abs`, `num_min`, etc.).
- **Monomorphization**: Integrated a monomorphization pass into the
compilation runner.
- **Language Enhancements**:
- **Type Casting**: Introduced the `as` keyword and `Expression::Cast`
to support explicit type conversions in both runtime and
compile-time contexts.
- **Statics**: Added the `static` keyword for global variables,
including backend support for global LLVM symbols.
- **Null Support**: Added a native `null` literal and ensured type
compatibility with pointers.
- **Backend & Cross-Platform**:
- **Target Control**: Expanded the `BackendOptions` to allow
overriding target triples, CPU architectures, and ABIs.
- **ABI Refinement**: Updated `abi_c.rs` to support both x86_64 and
Arm64 for Linux and Darwin (macOS), including improved aggregate
splitting logic for ARM64.
- **Robust Preprocessing**: Overhauled `#[target(os="...")]`
preprocessing to correctly ignore braces and semicolons inside
comments or string literals.
- **CLI & Documentation**:
- Updated `README.md` to document the new **Tiered Platform Policy**
and added a section for building from source.
- Expanded the CLI with advanced `--llvm` and linker options.
- Added a reference to the `doom.wave` example.
These features significantly increase the expressiveness of the Wave
language and provide the tools necessary for writing reusable,
platform-aware systems code.
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 a major leap in Wave's expressiveness and system-level capabilities. It implements the foundational infrastructure for Generic Programming, introduces explicit Type Casting via the
asoperator, and adds support for Global Static Variables. Additionally, it matures the compiler's cross-platform architecture with robust target-specific preprocessing and granular backend control for x86_64 and ARM64.Key Changes
1. Generic Programming (Generics)
generic_paramstoFunctionNodeandStructNode, andtype_argsto function calls/struct initializers.ptr<TypedBuffer<i32>>).TypedBuffer<T>,ptr_swap<T>, and numeric functions likenum_abs<T>andnum_min<T>.2. Language Primitives:
static,as, andnullstatickeyword for declaring global variables with persistent storage in the LLVM data segment.as): Added theaskeyword for explicit type conversions (e.g.,x as i64), providing safe widening/narrowing and pointer-to-integer casts.null: Added a formalnullliteral, ensuring strict type compatibility with pointer types across the backend.3. Backend & Cross-Platform Robustness
BackendOptionsto allow users to override target triples, CPU architectures, and ABIs via the CLI.abi_c.rsto support the System V ABI for both x86_64 and ARM64 on Linux and macOS (Darwin), including optimized aggregate splitting for Apple Silicon.#[target(os="...")]preprocessor to be "context-aware," ensuring it ignores braces and semicolons inside comments or string literals.4. Tooling & Documentation
README.mdto formalize Tiers 1–4 of platform support, setting clear expectations for architecture stability.--llvmand-Cflags for fine-grained backend and linker control.doom.waveexample to showcase the language's capabilities.Example Usage
Generics & Type Casting:
Benefits
swapormin) once and using them across any type.staticandasprovide the low-level primitives necessary for memory-mapped I/O and OS development.