-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
buildIssues related to building the project or compiling errors.Issues related to building the project or compiling errors.enhancementA request for a new feature or improvement.A request for a new feature or improvement.feature requestA request for a new feature or functionality.A request for a new feature or functionality.os patchA patch required to support or improve compatibility with an operating system.A patch required to support or improve compatibility with an operating system.
Description
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
- C
- 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
archandosas build-time reserved keywords - Cannot use
archorosas 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/osas 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.
Metadata
Metadata
Assignees
Labels
buildIssues related to building the project or compiling errors.Issues related to building the project or compiling errors.enhancementA request for a new feature or improvement.A request for a new feature or improvement.feature requestA request for a new feature or functionality.A request for a new feature or functionality.os patchA patch required to support or improve compatibility with an operating system.A patch required to support or improve compatibility with an operating system.
Type
Projects
Status
Backlog