feat: implement enums, type aliases, and advanced constant evaluation - #285
Merged
LunaStev merged 1 commit intoFeb 9, 2026
Conversation
This commit introduces support for enums and type aliases, along with a
significantly more powerful constant evaluation engine. It also improves
ABI-related type coercion and provides better frontend validation.
Changes:
- **Enums & Type Aliases**:
- Introduced `enum Name -> Repr { Variant, ... }` syntax. Enum variants
are automatically treated as global constants.
- Added `type Alias = Target` syntax for type aliasing.
- Implemented a pre-codegen **Type Resolution Pass** that flattens aliases
and resolves enum types across functions, structs, and variables.
- **Advanced Constant Evaluation**:
- Overhauled the constant evaluator to support complex expressions,
including **struct literals** and **array literals** in constants.
- Implemented **iterative (multi-round) resolution** for constants,
allowing constants to depend on other constants defined elsewhere in
the program.
- Added support for `true`, `false`, and `null` keywords in constant
contexts.
- **Backend & ABI Improvements**:
- Refactored aggregate packing (`pack_agg_to_int`) and unpacking to use
`build_memcpy` instead of bit-casting, ensuring safer handling of
alignment requirements during FFI calls.
- Added robust coercion logic between aggregates (structs/arrays) and
LLVM **Vector types**, improving support for Homogeneous
Floating-point Aggregates (HFAs).
- Added automatic creation of the `target/` directory in the backend.
- **Parser & Verification**:
- Added keywords `type` and `enum` to the lexer and parser.
- Enhanced the verification pass to detect usage of undeclared
identifiers in expressions.
- Updated `validate_program` to register enum variants as global constants.
- **Maintenance**:
- Bumped version to `0.1.7-pre-beta`.
- Added comprehensive test cases (`test81.wave`, etc.) for enums,
aliases, and nested constant dependencies.
This update significantly increases the language's type system
flexibility and enables more complex compile-time computations.
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 expands the Wave type system and compile-time capabilities. It introduces
enumandtypealias support, supported by a new pre-codegen Type Resolution Pass. Additionally, the constant evaluation engine has been overhauled to support complex nested aggregates and iterative dependency resolution, while the ABI layer has been hardened for safer C FFI interactions.Key Changes
1. Enums & Type Aliases
enum Name -> Repr { Variant, ... }. Variants are automatically treated as global constants of the specified representation type.type Alias = Targetsyntax, allowing for cleaner and more descriptive type naming.2. Advanced Constant Evaluation
true,false, andnullare now valid primary expressions in constant contexts.3. Backend & ABI Improvements
pack_agg_to_int) to usebuild_memcpyinstead of raw bit-casting. This ensures that alignment requirements are respected when passing small structs through integer registers.target/directory exists before emitting object files.4. Parser & Verification
typeandenumas reserved keywords.Example Usage
Benefits
memcpyfor aggregate packing prevents subtle memory corruption bugs related to data alignment during C library calls.