feat: implement static globals, explicit type casting, and pointer arithmetic#298
Merged
LunaStev merged 1 commit intowavefnd:masterfrom Mar 2, 2026
Conversation
…nhanced diagnostics
This commit introduces several core language features, including global
static variables, explicit type casting, and pointer arithmetic. It also
significantly upgrades the compiler's resilience by introducing a
panic-guarded diagnostic system and cross-platform ABI support.
Changes:
- **Language Features**:
- **Static Globals**: Added the `static` keyword for global variables
that persist throughout the program.
- **Type Casting**: Implemented the `as` operator (e.g., `expr as type`)
for explicit type conversions, supported in both the parser and
LLVM backend.
- **Pointer Arithmetic**: Added support for `ptr + int`, `ptr - int`,
and `ptr - ptr` (pointer difference) using LLVM `gep` and `sub`
instructions.
- **Match Statement**: Finalized the `match` expression syntax and
verification, ensuring no duplicate patterns in arms.
- **Compiler Infrastructure**:
- **Panic-Guarded Diagnostics**: Introduced a robust runner that
captures backend panics and uses "source-span inference" to map
low-level LLVM errors back to the original Wave source code.
- **Cross-ABI Support**: Overhauled `abi_c.rs` to support target-specific
calling conventions for both **Linux x86_64 (SysV)** and
**macOS arm64 (Darwin)**, handling aggregate splitting and SRet rules.
- **Structured Errors**: Refactored the parser to return `ParseError`
objects containing detailed diagnostics (expected/found tokens,
help messages, and context).
- **Standard Library Updates**:
- Updated the Linux syscall layer (`fs`, `memory`, `socket`, `process`)
with explicit `as i64` casts to comply with stricter type-checking
rules for register arguments.
- Improved memory allocation safety with `null` checks and syscall
error handling.
- **Documentation**:
- Expanded `README.md` with build instructions, target support status,
and a comprehensive CLI usage guide.
These updates bridge the gap between low-level system access and
high-level safety, making Wave more suitable for systems programming
on multiple architectures.
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 significant set of core language features and architectural improvements that bridge the gap between high-level safety and low-level systems programming. Key updates include the addition of
staticglobals, theascasting operator, robust pointer arithmetic, and a "panic-guarded" diagnostic system that maps backend failures back to the Wave source code.Key Changes
1. Core Language Features
statickeyword for global variables. These persist for the lifetime of the program and are correctly initialized in the data segment.as): Implemented theasoperator (e.g.,value as i64) for explicit type conversions. The backend handles these via LLVMtrunc,zext/sext,fpext/fptrunc, andbitcastinstructions.ptr + int/ptr - int: For navigating memory buffers.ptr - ptr: To calculate the distance (offset) between two memory addresses.matchexpression syntax and added a verification pass to prevent duplicate patterns in match arms.2. Compiler Infrastructure & Diagnostics
ParseError: Refactored the frontend to return detailed error objects. These include "expected vs. found" token information, multi-line context, and actionable "help" hints.abi_c.rsmodule to support target-specific calling conventions for both Linux x86_64 (System V) and macOS arm64 (Darwin). This includes correct handling of aggregate splitting and SRet (Structured Return) rules for M1/M2/M3 chips.3. Standard Library & Safety
std/sys/linuxmodules (FS, Memory, Socket, Process) to utilize explicitas i64casts, complying with the compiler's stricter type-checking rules for system registers.nullchecks and better syscall error propagation.4. Documentation & Tooling
README.mdwith comprehensive build instructions, an updated target support matrix, and a detailed guide for the new CLI subcommands.Example Usage
Benefits