A lightweight statically typed programming language that compiles to x86_64 Linux assembly, supporting custom data types, conditionals, arithmetic, and type-safe operations. The language was designed for educational and experimental purposes with an emphasis on low-level control and code generation.
- Basic variable declarations and assignments
- Strong type-checking with custom-defined numeric and non-numeric types
- Expressions: arithmetic, comparison, logic, and unary operations
- String literals and numeric constants
- Control flow:
if,elif,else - Typed AST with scoped variable tracking
- Code generation to ELF-compatible x86_64 assembly
- Symbol table management and register allocation
- Stack-based memory layout and
.rodatasection usage
- Linux (x86_64)
gnu(linux)ml64.exe(windows)llc & clang(LLVM)g++orclang++compilercmake
# Clone the repository
git clone https://github.com/your-username/zust.git
cd zust
# Create build directory
mkdir build && cd build
# Generate and build
makeThe compilation process follows this pipeline:
- Compile (zpiler):
.zzsource → assembly/IR - Assemble: assembly/IR → object file
- Link: object file → executable
- Execute: run the executable
Step 1: Compile to Assembly
./zpiler --format x86_64-linux -o out.asm program.zzGenerates: out.asm (x86_64 assembly)
Step 2: Assemble
as out.asm -o out.oGenerates: out.o (object file)
Step 3: Link
gcc out.o -o programGenerates: program (executable)
Step 4: Execute
./programCombined (one-liner):
./zpiler --format x86_64-linux -o out.asm program.zz && as out.asm -o out.o && gcc out.o -o program && ./programStep 1: Compile to Assembly
./zpiler --format x86_64-mswin -o out.asm program.zzGenerates: out.asm (x86_64 assembly for Windows)
Step 2: Assemble
ml64 /nologo /c out.asmGenerates: out.obj (object file)
Step 3: Link
gcc out.obj -o program.exeGenerates: program.exe (executable)
Step 4: Execute
./program.exeNote: Requires Microsoft Macro Assembler (ml64) installed. Available in Visual Studio or Windows SDK.
Step 1: Compile to LLVM IR
./zpiler --format llvm-ir -o out.ll program.zzGenerates: out.ll (LLVM intermediate representation)
Step 2: Compile to Object File
llc -filetype=obj out.ll -o out.oGenerates: out.o (object file)
Step 3: Link
gcc out.o -o program -no-pieGenerates: program (executable)
Step 4: Execute
./programCombined (one-liner):
./zpiler --format llvm-ir -o out.ll program.zz && llc -filetype=obj out.ll -o out.o && gcc out.o -o program -no-pie && ./programNote: Requires LLVM toolchain (llc) installed.
Install test dependencies:
python3 -m pip install -r requirements-dev.txtRun strict golden-output tests with pytest:
# Auto-detect native target when TARGET is not set
pytest -q
# Linux + LLVM
TARGET=linux,llvm pytest -q
# Windows
TARGET=windows pytest -q
# Update/create runtime goldens explicitly
TARGET=linux pytest -q --blessextern fn printf(fmt: string, ...) -> int32_t;
fn factorial(x: uint64_t) -> uint64_t{
fn multiply(x: uint64_t, y: uint64_t) -> uint64_t{
return x * y;
}
if(x <= 1){
return 1;
}else{
return multiply(x, factorial(x - 1));
}
}
fn main() {
printf("Factorial of 10: %d\n", factorial(10));
}
- Type safety enforced during compile-time using a dedicated
TypeChecker. - Register allocator for both general-purpose (
%r) and floating-point (%xmm) registers. - Automatic handling of
.rodataand.textsegments during code generation. - Explicit handling of stack operations for expression evaluation.
Test suites are directory-based:
tests/runtime: program must compile, run, and match exactstdout/stderr/exit codetests/runtime_fail: program must compile, run, and match exact failing output + nonzero exit codetests/compile_fail: program must fail compilation with expected exit code and required stderr substrings
Expected files live under tests/expected/<mode>/... with mirrored paths.
This project is licensed under the MIT License - see the LICENSE file for details.
Mihir Patel
Feel free to reach out for contributions, discussions, or collaborations!