A statically-typed bytecode-interpreted programming language in C with zero dependencies.
Bytecode Interpretation From Scratch in C
git clone https://github.com/williamalexakis/phase.git
cd phase
mkdir build
cd build
cmake ..
cmake --build .Hello World
entry {
out("Hello world!")
}Functions
func add(num1: int, num2: int): void {
out(num1 + num2)
}
entry {
add(5, 5)
}Loops
entry {
let num: int = 0
while num < 11 {
out(num)
num += 1
}
}INPUT → Lexer → Parser → Type Checker → Bytecode Generator → Virtual Machine → OUTPUT
Programs are compiled into hexadecimal bytecode and executed by a stack-based VM supporting 25 opcodes. For example, Hello World translates to:
0x0000 → 00 00 00 → OP_PUSH_CONST 0
0x0003 → 01 → OP_PRINT
0x0004 → 18 → OP_HALT
phase --help— list commands and flagsphase <file.phase> --tokens— print the token streamphase <file.phase> --ast— print the ASTphase <file.phase> --loud— print a success message on exit