A multi-pass, multi-architecture compiler for a subset of the C language, implemented in Zig. This project targets macOS on both Intel (x86_64) and Apple Silicon (ARM64).
- Language Constructs: Integers (
int), Characters (char),voidfunctions, Structs, Enums, andtypedef. - Control Flow:
if/else,while,for,do-while,switch/case,break, andcontinue. - Operators: Arithmetic (prefix/postfix), bitwise, comparison, logical, and ternary (
? :). - Memory: Support for pointers (
&,*), arrays, and global variables. - Architectures: Code generation for ARM64 and x86_64 (macOS).
- Optimization: Constant folding at the AST level.
- Zig: Version 0.13.0 or 0.14.0 (for best compatibility).
- macOS: Target system for assembly and linking.
Run the following command to build the project:
zig buildThe compiled binary will be located in zig-out/bin/compiler.
To compile a .simple source file (a subset of C) into an executable:
# Compile to ARM64 assembly (default)
./zig-out/bin/compiler --arch arm64 examples/arithmetic.simple
# Assemble and link the generated out.asm
mv out.asm out.s
clang -arch arm64 -o my_app out.s
# Run the app
./my_app
echo "Exit code: $?"To run the automated test suite, which verifies 26 test cases across both supported architectures:
./test.shFor a detailed language specification and usage guide, see DOCUMENTATION.md.
For a deep dive into the system architecture and internal design, see ARCHITECTURE.md.
MIT