Background
- Wave supports inline assembly, so platform-specific branching (architecture & OS) is required.
- Existing approaches have drawbacks:
- C
#ifdef → macro hell, poor readability
- Rust
#[cfg(...)] → verbose and cluttered syntax
- Wave needs a cleaner and more intuitive way to handle platform-dependent code.
Goals
- Use natural if-statement-like syntax
- Evaluate at build-time only → zero runtime overhead
- No compile-time slowdown
- Avoid confusion or conflicts with regular variables
- Must remain compatible when transitioning to the Whale toolchain
Final Decision
- Introduce
arch and os as build-time reserved keywords
- Cannot use
arch or os as regular variable names
- Values are determined by build target (
vex build --arch amd64 --os linux)
- False branches are removed at the AST stage → not included in final binary
Final Syntax
fun syscall_alloc(size: i32) {
if arch == "amd64" && os == "linux" {
asm { "mov rax, 9" }
} else if arch == "arm64" {
asm { "mov x8, 222" }
} else {
println("unsupported platform");
}
}
✅ Looks like a normal if statement
✅ Zero runtime overhead
✅ Parser instantly recognizes keywords → fast compile-time
✅ Will remain compatible with Whale toolchain
Build Flow
vex build --arch amd64 --os linux
- Wave compiler sets
arch="amd64", os="linux" as compile-time constants
- During AST generation, false branches are removed
- IR → final binary contains only the selected code
Future Keyword Extensions
- Initial set:
arch, os
- Potential future:
endian, cpu
Why this decision?
- Regular developers rarely need
arch/os as variable names
- Allowing it as a variable would increase parser complexity → potential compile-time slowdown
- Keeping them as reserved keywords ensures simpler syntax and better performance
Relation to Whale
- Whale will use the same build target parameters as LLVM → same behavior
- After migrating to Whale, AST optimizations can be even more aggressive
Conclusion:
Wave will use arch and os as build-time reserved keywords for platform-specific branching.
This approach ensures simplicity, performance, and intuitiveness, while remaining compatible with the future Whale toolchain.
Background
#ifdef→ macro hell, poor readability#[cfg(...)]→ verbose and cluttered syntaxGoals
Final Decision
archandosas build-time reserved keywordsarchorosas regular variable namesvex build --arch amd64 --os linux)Final Syntax
✅ Looks like a normal
ifstatement✅ Zero runtime overhead
✅ Parser instantly recognizes keywords → fast compile-time
✅ Will remain compatible with Whale toolchain
Build Flow
vex build --arch amd64 --os linuxarch="amd64",os="linux"as compile-time constantsFuture Keyword Extensions
arch,osendian,cpuWhy this decision?
arch/osas variable namesRelation to Whale
Conclusion:
Wave will use
archandosas build-time reserved keywords for platform-specific branching.This approach ensures simplicity, performance, and intuitiveness, while remaining compatible with the future Whale toolchain.