feat: implement static globals, explicit type casting, and conditional compilation#300
Merged
LunaStev merged 2 commits intowavefnd:masterfrom Mar 4, 2026
Conversation
…l compilation
feat(lang): add static globals
feat(lang): implement explicit type casting
feat(lang): add #[target] conditional compilation
refactor(llvm): move allocas to entry block
refactor(std): introduce platform-agnostic sys imports
feat(cli): update wavec build flags
This commit introduces core language features including global static
variables and explicit type casting. It also establishes a tiered platform
support policy and refactors the standard library for better cross-platform
portability.
Changes:
- **Language Features**:
- **Type Casting**: Added the `as` operator for explicit type conversions
(e.g., `x as i64`). Supported in expressions and constant evaluation.
- **Static Globals**: Introduced the `static` keyword for declaring
global variables with persistent storage.
- **Conditional Compilation**: Implemented a preprocessor-like pass for
`#[target(os="...")]` attributes, allowing OS-specific code blocks.
- **LLVM Backend**:
- Implemented global variable generation for `static` declarations.
- Refactored `build_entry_alloca` to ensure all local variables are
allocated in the function entry block, improving optimization compatibility.
- Added support for constant integer sign-extension and pointer casts
during compile-time evaluation.
- Removed legacy image-generation logic (`compile_ir_to_img_code`).
- **Standard Library & IO**:
- Refactored `std::sys` modules to use platform-agnostic import paths
(e.g., `std::sys::fs` instead of `std::sys::linux::fs`).
- Updated `errno` handling to use `__errno_location()` for better
C compatibility.
- **CLI & Tooling**:
- Updated `wavec build` syntax: added `-c` for compile-only mode and
refined `-o` for output path specification.
- Updated `README.md` to document the new Tiered Platform Policy and
build instructions.
- **Cleanup**:
- Applied consistent formatting across the lexer, parser, and utils crates.
- Improved error diagnostic rendering with better span marking.
This update moves Wave closer to being a production-ready systems language
by providing necessary primitives for memory management and platform
abstraction.
Signed-off-by: LunaStev <luna@lunastev.org>
…l compilation
feat(lang): add static globals
feat(lang): implement explicit type casting
feat(lang): add #[target] conditional compilation
refactor(llvm): move allocas to entry block
refactor(std): introduce platform-agnostic sys imports
feat(cli): update wavec build flags
This commit introduces core language features including global static
variables and explicit type casting. It also establishes a tiered platform
support policy and refactors the standard library for better cross-platform
portability.
Changes:
- **Language Features**:
- **Type Casting**: Added the `as` operator for explicit type conversions
(e.g., `x as i64`). Supported in expressions and constant evaluation.
- **Static Globals**: Introduced the `static` keyword for declaring
global variables with persistent storage.
- **Conditional Compilation**: Implemented a preprocessor-like pass for
`#[target(os="...")]` attributes, allowing OS-specific code blocks.
- **LLVM Backend**:
- Implemented global variable generation for `static` declarations.
- Refactored `build_entry_alloca` to ensure all local variables are
allocated in the function entry block, improving optimization compatibility.
- Added support for constant integer sign-extension and pointer casts
during compile-time evaluation.
- Removed legacy image-generation logic (`compile_ir_to_img_code`).
- **Standard Library & IO**:
- Refactored `std::sys` modules to use platform-agnostic import paths
(e.g., `std::sys::fs` instead of `std::sys::linux::fs`).
- Updated `errno` handling to use `__errno_location()` for better
C compatibility.
- **CLI & Tooling**:
- Updated `wavec build` syntax: added `-c` for compile-only mode and
refined `-o` for output path specification.
- Updated `README.md` to document the new Tiered Platform Policy and
build instructions.
- **Cleanup**:
- Applied consistent formatting across the lexer, parser, and utils crates.
- Improved error diagnostic rendering with better span marking.
This update moves Wave closer to being a production-ready systems language
by providing necessary primitives for memory management and platform
abstraction.
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 critical language primitives required for professional systems programming in Wave. Key additions include the
ascasting operator, globalstaticvariables, and a tiered platform abstraction layer using#[target]conditional compilation. These changes are supported by significant backend optimizations and a refactored standard library for better cross-platform portability.Key Changes
1. Core Language Features
as): Implemented theasoperator for explicit type conversions (e.g.,value as i64). This is supported both in runtime expressions and during compile-time constant evaluation.statickeyword to declare global variables with persistent storage. These are correctly initialized in the LLVM data segment.#[target]): Implemented a preprocessor-style attribute system. Using#[target(os="linux")]or#[target(os="macos")], developers can now write platform-specific code blocks within the same codebase.2. LLVM Backend Optimizations
build_entry_alloca. By moving all local variable allocations to the function's entry block, we ensure better compatibility with LLVM'smem2regpass, leading to more optimized machine code.compile_ir_to_img_code) to streamline the backend.3. Standard Library Portability
sysImports: Refactoredstd::sysso users can import modules via generic paths likestd::sys::fsrather than platform-specific paths likestd::sys::linux::fs.errnohandling to utilize__errno_location()for more reliable integration with standard C libraries.4. CLI & Tooling
-cfor compile-only mode (producing object files).-ofor specifying custom output paths.README.mdto document the new support tiers for different operating systems and architectures.Example Usage
Static Globals, Casting, and Conditional Compilation:
Benefits
#[target]attribute and agnosticstd::sysimports make it significantly easier to maintain cross-platform applications.staticvariables and explicit casting provide the low-level memory and type control necessary for systems-level development.