Patch #300: Evolving Toward Portability: Statics, Type Casting, and Target-Specific Logic
As Wave moves closer to becoming a production-ready systems language, we are focusing on providing the primitives necessary for low-level memory management and robust platform abstraction. Our latest
Patch #300: Evolving Toward Portability: Statics, Type Casting, and Target-Specific Logic
As Wave moves closer to becoming a production-ready systems language, we are focusing on providing the primitives necessary for low-level memory management and robust platform abstraction. Our latest update introduces foundational language features and a revamped standard library designed for cross-platform portability.
1. Persistent State with static Globals
We have introduced the static keyword, enabling the declaration of global variables with persistent storage. Unlike local variables that live on the stack, static variables reside in a fixed memory location for the entire duration of the program. This is essential for managing global state, shared buffers, and system-level configurations.
2. Explicit Type Casting with as
To complement our strict type system, we’ve implemented the as operator. This allows developers to perform explicit type conversions (e.g., value as i64).
Versatility: The
asoperator is supported both in runtime expressions and during compile-time constant evaluation.Safety: It ensures that pointer casts and integer width conversions are intentional, reducing bugs caused by accidental type mismatches.
3. Smart Portability: Conditional Compilation
Building software that runs on both Linux and macOS requires the ability to write platform-specific code. We have implemented a new #[target] attribute system.
Target-Aware: Use
#[target(os="linux")]or#[target(os="macos")]to include or exclude code blocks based on the compilation target.Platform-Agnostic Stdlib: We’ve refactored the standard library to use cleaner, platform-neutral paths. You can now use
import("std::sys::fs")instead of specifying the OS, as the compiler now handles the underlying mapping automatically.
4. LLVM Backend Optimizations
We’ve made significant internal changes to how machine code is generated to help LLVM optimize your programs better:
Entry Block Allocas: All local variable allocations (
alloca) are now moved to the function's entry block. This is a standard compiler optimization technique that makes it much easier for LLVM to promote variables to CPU registers.Enhanced Constant Eval: The constant evaluator now supports sign-extension and pointer casting, allowing for more complex computations to happen at compile time.
5. Professional Tooling & CLI
The wavec toolchain is becoming more familiar to developers coming from gcc or clang:
New Build Flags: We’ve added the
-cflag for compile-only mode (generating object files) and refined the-oflag for specifying precise output paths.Tiered Platform Policy: We have officially established a Tiered Platform Support policy, documented in our
README.md, to provide clarity on which architectures and OSs are fully supported, guaranteed to build, or experimental.
6. Better Diagnostics
We continue to polish our error reporting. This update improves the rendering of error spans, making it even easier to see exactly where a syntax or semantic issue occurs in your code.
Conclusion
By providing global statics, explicit casting, and a way to handle platform differences, Wave is now better equipped to handle real-world systems tasks. These features bridge the gap between high-level code organization and the gritty reality of cross-platform hardware management.
Explore the new tiered support policy in the README.md and start building your next cross-platform tool with Wave!