| status | active |
|---|---|
| audience | public |
| last-verified | 2026-04-09 |
Welcome to Viper! This guide will help you build and run the Viper compiler toolchain.
For detailed, platform-specific installation instructions (prerequisites, exact install commands, and troubleshooting):
Before you begin, ensure you have:
- CMake ≥ 3.20
- C++20 Compiler: GCC, Clang, or MSVC
- Ninja (optional): For faster multi-config builds
- Python 3.x (optional): For helper scripts in
scripts/
The platform build scripts configure, compile, test, and install Viper in one step:
# macOS
./scripts/build_viper_mac.sh
# Linux
./scripts/build_viper_linux.sh
# Windows
scripts\build_viper.cmdThe compatibility wrapper ./scripts/build_viper.sh still dispatches to the correct Unix script on macOS and Linux.
After building, confirm the primary tool works correctly:
viper --versionThis should display the Viper version and IL version without errors.
Use viper init to scaffold a new project:
viper init my-appThis creates a project directory with a manifest and entry-point source file:
my-app/
viper.project # Project manifest (name, version, language, entry point)
main.zia # Entry-point source file
Run the new project:
viper run my-app| Option | Description | Default |
|---|---|---|
--lang zia |
Create a Zia project | zia |
--lang basic |
Create a BASIC project | — |
# Create a Zia project (default)
viper init my-app
# Create a BASIC project
viper init calculator --lang basicviper run examples/basic/ex1_hello_cond.basExpected output:
Hello, World!
Condition is true
Create a file hello.zia:
module Hello;
func start() {
Viper.Terminal.Say("Hello, World!");
}Run it:
viper run hello.ziaExpected output:
Hello, World!
For quick experimentation, launch the interactive REPL:
viper replThe REPL lets you type Zia code and see results immediately:
zia> "Hello from the REPL"
Hello from the REPL
zia> 2 + 3 * 4
14
zia> var x = 42
zia> x
42
zia> func square(n: Integer) -> Integer { return n * n; }
zia> square(7)
49
Type .help for available commands and .quit to exit. See the REPL Guide for full documentation.
You can inspect the generated IL or run IL programs directly:
# Emit IL from BASIC
viper build examples/basic/ex1_hello_cond.bas
# Emit IL from Zia
viper build hello.zia
# Save IL to a file
viper build examples/basic/ex1_hello_cond.bas -o hello.il
# Run the IL program directly
ilrun hello.ilFor more examples, see the BASIC Tutorial,
Zia Tutorial, and the examples/ directory.
| Tool | Purpose | Example |
|---|---|---|
viper |
Unified compiler driver — run and build | viper run program.zia |
viper init |
Scaffold a new project | viper init my-app |
vbasic |
Run/compile BASIC programs | vbasic script.bas |
zia |
Run/compile Zia programs | zia program.zia |
ilrun |
Execute IL programs | ilrun program.il |
il-verify |
Verify IL correctness | il-verify program.il |
il-dis |
Disassemble IL | il-dis program.il |
Note:
viper runis the recommended way to run programs. It auto-detects the language and can run entire project directories.
All frontends, IL, and the VM share a consistent error and trap model. Diagnostics remain uniform regardless of entry point.
Learn more: See specs/errors.md for trap kinds, handler semantics, and BASIC
ON ERRORlowering rules.
Viper guarantees consistent numeric behavior across all platforms and execution modes:
- Overflow checking: Zia defaults to checked arithmetic (traps on overflow); BASIC uses wrapping
- Division: Zia
/on integers is integer division; BASIC has separate/(float) and\(integer) - Modulo: Remainder preserves the dividend's sign (C99 semantics)
- Conversions: Casts use checked variants that trap when values are out of range
- Rounding: All rounding uses round-to-nearest-even (IEEE 754 default)
Learn more: See specs/numerics.md for complete numeric semantics.
Language Documentation:
- BASIC Tutorial — Learn Viper BASIC by example
- BASIC Reference — Complete BASIC language reference
- Zia Tutorial — Learn Zia by example
- Zia Reference — Complete Zia language reference
- IL Guide — Comprehensive IL documentation
Implementation Guides:
- Frontend How-To — Build your own language frontend
Developer Documentation:
- architecture.md — System architecture overview
- vm.md — VM and runtime internals
- contributor-guide.md — Contribution guidelines