Viper is an IL-first compiler toolchain and virtual machine for exploring intermediate language design, multi-frontend architectures, and interpreter implementation techniques.
High-level frontends—like the included BASIC and ViperLang compilers—lower programs into a strongly typed, SSA-inspired intermediate language (Viper IL). The IL can be executed by the VM or compiled to native code.
Status: Early development. APIs, IL, and tooling change frequently. Not production-ready.
Latest Release: v0.1.3-dev
Or clone the repository:
git clone https://github.com/splanck/viper.git
cd viperBuild and test:
cmake -S . -B build
cmake --build build -j
ctest --test-dir build --output-on-failureRun a BASIC program:
./build/src/tools/vbasic/vbasic examples/basic/ex1_hello_cond.basRun a ViperLang program:
./build/src/tools/viper/viper demos/viperlang/frogger.viperRun an IL program directly:
./build/src/tools/ilrun/ilrun examples/il/ex1_hello_cond.ilViper is a compiler infrastructure with several components:
| Component | Description |
|---|---|
| IL | Typed, SSA-based intermediate representation |
| Frontends | Language compilers: BASIC and ViperLang |
| VM | Bytecode interpreter with pluggable dispatch strategies |
| Backends | Native code generators (AArch64, x86-64) |
| Runtime | Portable C libraries for core types, collections, I/O, text, math, graphics, input, networking, system, diagnostics, utilities, crypto, time, threading |
| Tools | Compiler drivers, verifier, disassembler |
- IL-centric: A readable, typed IR makes semantics explicit and frontends interchangeable
- Human-scale: The IL is designed to be read and edited—learn by inspecting output
- Composable: Parser, IL builder, verifier, and VM work as standalone scriptable tools
- Educational: Clear examples, golden tests, and a manageable codebase for experimentation
Viper is in early development. All components are functional but incomplete:
| Component | Notes |
|---|---|
| BASIC Frontend | Core language implemented; OOP features work but are evolving |
| ViperLang Frontend | Core language with entities, generics, imports; actively developed |
| Viper IL | Stable core; instruction set still expanding |
| Virtual Machine | Functional with multiple dispatch strategies |
| AArch64 Backend | Validated on Apple Silicon; actively developed |
| x86-64 Backend | Validated on Windows; System V and Windows x64 ABI support |
| Runtime Libraries | Expanding: core types, collections, I/O, text, math, graphics, input, networking, system, diagnostics, utilities, crypto, time, threads |
| IL Optimizer | Basic passes implemented; more planned |
| Debugger/IDE | Early work; not yet usable |
Expect breaking changes. The IL specification, APIs, and tool interfaces are not stable.
Several demos showcase the platform's capabilities. See the demos/ directory for the full list.
| Demo | Description |
|---|---|
demos/basic/frogger |
Frogger clone (console). Also runs natively on Apple Silicon. |
demos/basic/chess |
Console chess with AI opponent |
demos/basic/pacman |
Pac-Man clone with ghost AI |
demos/basic/centipede |
Classic arcade game with OOP |
demos/basic/monopoly |
Board game with 4-player AI |
demos/basic/vtris |
Tetris clone with high scores |
demos/basic/particles |
Graphics particle system using Canvas API |
| Demo | Description |
|---|---|
demos/viperlang/frogger |
Frogger with entity types and generics |
demos/viperlang/entities |
Entity system demonstration |
Run demos:
# BASIC
./build/src/tools/vbasic/vbasic demos/basic/frogger/frogger.bas
# ViperLang
./build/src/tools/viper/viper demos/viperlang/frogger.viper┌─────────────────────────────────────────┐
│ Source Language │
│ (BASIC, ViperLang) │
└─────────────────┬───────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ Frontend (Parser + Semantics + │
│ Lowering) │
└─────────────────┬───────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ Viper IL (Typed SSA) │
│ + Verifier + Optimizer │
└─────────┬───────────────┬───────────────┘
│ │
▼ ▼
┌──────────────┐ ┌──────────────────────┐
│ Virtual │ │ Native Backend │
│ Machine │ │ (AArch64, x86-64) │
└──────────────┘ └──────────────────────┘
│ │
└─────────┬─────────┘
▼
┌─────────────────────────────────────────┐
│ Viper Runtime │
│ (Collections, I/O, Text, Math, Graphics │
│ Input, Network, Threads, System) │
└─────────────────────────────────────────┘
Frontends lower to a typed IL that is compact, explicit, and inspectable.
BASIC Source:
10 LET X = 2 + 3
20 LET Y = X * 2
30 PRINT "HELLO"
40 PRINT Y
50 ENDViper IL Output:
il 0.1
extern @Viper.Console.PrintStr(str) -> void
extern @Viper.Console.PrintI64(i64) -> void
global const str @.NL = "\n"
global const str @.HELLO = "HELLO"
func @main() -> i64 {
entry:
%x = add 2, 3
%y = mul %x, 2
call @Viper.Console.PrintStr(const_str @.HELLO)
call @Viper.Console.PrintStr(const_str @.NL)
call @Viper.Console.PrintI64(%y)
call @Viper.Console.PrintStr(const_str @.NL)
ret 0
}
All frontends share the Viper Runtime, providing a growing set of modules:
| Module | Classes | Description |
|---|---|---|
| Collections | Bag, Bytes, Heap, List, Map, Queue, Ring, Seq, Stack, TreeMap |
Data structures for any use case |
| Core | Box, Object, String |
Base types and string operations |
| Crypto | Hash, KeyDerive, Rand |
CRC32, MD5, SHA1, SHA256, PBKDF2, secure RNG |
| Diagnostics | Assert, Trap |
Debugging and assertions |
| Graphics | Canvas, Color, Pixels |
2D graphics with shapes, curves, text, image transforms, screenshots |
| I/O | Archive, BinFile, Compress, Dir, File, LineReader, LineWriter, MemStream, Path, Watcher |
File system access and streaming |
| Input | Keyboard, Mouse, Pad |
Input devices for games and interactive apps |
| Math | Bits, Math, Random, Vec2, Vec3 |
Mathematical functions and vectors |
| Network | Dns, Http, HttpReq, HttpRes, Tcp, TcpServer, Udp, Url |
Networking and sockets |
| System | Environment, Exec, Machine, Terminal |
System interaction and console I/O |
| Text | Codec, Csv, Guid, Pattern, StringBuilder, Template |
String building and text encoding |
| Threads | Barrier, Gate, Monitor, RwLock, SafeI64, Thread |
Concurrent programming primitives |
| Time | Clock, Countdown, DateTime, Stopwatch |
Time utilities and measurement |
| Utilities | Convert, Fmt, Log, Parse |
Conversion, formatting, parsing, logging |
See the Runtime Library Reference for complete API documentation.
Primary tools:
| Tool | Purpose |
|---|---|
vbasic |
Run or compile BASIC programs |
viper |
Run or compile ViperLang programs |
ilrun |
Execute IL programs |
il-verify |
Validate IL with detailed diagnostics |
il-dis |
Disassemble IL for inspection |
Examples:
# Run BASIC
./build/src/tools/vbasic/vbasic program.bas
# Run ViperLang
./build/src/tools/viper/viper program.viper
# Emit IL from any frontend
./build/src/tools/vbasic/vbasic program.bas --emit-il
./build/src/tools/viper/viper program.viper --emit-il
# Run IL
./build/src/tools/ilrun/ilrun program.il
# Verify IL
./build/src/tools/il-verify/il-verify program.ilAdvanced tool:
ilc is a unified compiler driver for advanced workflows:
# Compile BASIC to native executable (experimental)
./build/src/tools/ilc/ilc front basic -emit-il program.bas > program.il
./build/src/tools/ilc/ilc codegen arm64 program.il -o program
# Compile ViperLang to native executable
./build/src/tools/ilc/ilc front viperlang -emit-il program.viper > program.il
./build/src/tools/ilc/ilc codegen arm64 program.il -o programThe VM supports three dispatch strategies:
| Strategy | Description | Portability |
|---|---|---|
switch |
Switch-based dispatch | All compilers |
table |
Function-pointer dispatch | All compilers |
threaded |
Direct-threaded (labels-as-values) | GCC/Clang only |
Set at runtime:
VIPER_DISPATCH=threaded ./build/src/tools/ilrun/ilrun program.ilBuild with threaded dispatch enabled by default:
cmake -S . -B build -DVIPER_VM_THREADED=ON- CMake 3.20+
- C++20 compiler (Clang recommended, GCC 11+, or MSVC)
cmake -S . -B build
cmake --build build -j
ctest --test-dir build --output-on-failuresudo cmake --install build --prefix /usr/localInstalls: vbasic, vpascal, viper, ilrun, ilc, il-verify, il-dis
- macOS: Use Apple Clang. ARM64 tests skip x86-64-specific checks automatically.
- Linux: Clang recommended. Force with
CC=clang CXX=clang++ cmake -S . -B build - Windows: Clang-CL preferred. Some POSIX tests are skipped.
| Document | Description |
|---|---|
| Getting Started | Build and run your first program |
| BASIC Tutorial | Learn Viper BASIC by example |
| BASIC Reference | Complete BASIC language specification |
| ViperLang Getting Started | Learn ViperLang by example |
| ViperLang Reference | Complete ViperLang language specification |
| Runtime Library | Viper.* classes, methods, and properties |
| IL Guide | IL specification and examples |
| IL Quickstart | Fast introduction to Viper IL |
| VM Architecture | VM design and internals |
| Frontend How-To | Build your own language frontend |
Developer documentation is in docs/devdocs/.
Viper is in early development and the architecture is stabilizing. We welcome:
- Bug reports and issues
- Small fixes and documentation improvements
- Feedback and suggestions
We are not currently seeking large feature PRs while the design solidifies. Feel free to fork for broader experimentation.
This repository also contains ViperOS, a capability-based microkernel operating system for AArch64. ViperOS is a separate project and does not depend on the Viper compiler.
See viperos/README.md for documentation.
Viper is licensed under the GNU General Public License v3.0 (GPL-3.0-only).
See LICENSE for the full text.