_____ _
|__ / (_) _ __
/ / | || '_ \
/ /_ | || |_) |
/____| |_|| .__/
|_|
Minimalist AOT Compiler
Zip is a minimalist, stack-and-memory-oriented esoteric language designed for high-performance native execution. This repository provides a complete toolchain, including a Lexer, Parser, AST Interpreter, and a native Ahead-of-Time (AOT) Compiler that generates x86_64 machine code for both Linux (ELF) and Windows (PE) platforms.
Zip utilizes a cell-based memory architecture.
- Addressing: Memory is accessed via the
$[index]syntax. - Storage: The compiler maps memory to a heap-allocated region using the
r12register as a base pointer. - Word Size: Each memory slot is treated as a 64-bit (8-byte) integer.
The language uses S-expressions for operation nesting:
(= $[target] value): Assignment to a memory cell.(+ a b)/(- a b): Basic 64-bit arithmetic operations.(out value): Writes a single byte (ASCII) tostdout.(in): Reads a single byte fromstdin.(repeat {condition} body): A conditional loop that executes while the condition evaluates to false.
Zip is Turing Complete as it meets the requirements for a Universal Turing Machine:
- Infinite Tape emulation: Provided by the arbitrary indexed memory
$[index]. - Pointer Indirection: Achieved through nested memory access (e.g.,
$[ $[0] ]). - Conditional Branching: Implemented via the
repeatstatement with comparison operators (-e,-ne,-l,-g).
The compiler translates the AST into raw x86_64 machine code without an external assembler or linker.
- Memory Allocation: Uses the
mmapsyscall (0x09) to reserve a 64KB memory region for the program's workspace. - Execution: Generates a standard ELF64 header with a single
LOADsegment. - Exit: Appends a
sys_exit(0x3C) syscall at the end of the instruction stream.
- Header: Generates a valid DOS MZ header and a PE COFF header.
- Section: Emits a
.textsection containing the executable code. - Entry: Uses a
ret(0xC3) based exit strategy for the execution flow.
The standard file extension for Zip source code is .zp.
- Node.js (v14+)
To interpret a program:
node zipcc.js <file.zp> -iTo compile to a native binary:
node zipcc.js <file.zp> -c -o <output_name># Read a character and print it back
(= $[0] (in))
(out $[0])
(out 10) # Newline(out 72) (out 101) (out 108) (out 108) (out 111) (out 32)
(out 87) (out 111) (out 114) (out 108) (out 100) (out 33)
(out 10)Author: Kamil Malicki License: Apache 2.0 Repository: GitHub