DEV Community

Nader Mahbub Khan Nabil
Nader Mahbub Khan Nabil

Posted on

Building a 100% Freestanding, Zero-CRT JIT & AOT Compiler Engine in C++20 for Anastasia Assembly (.ana)

Hi everyone,Hope you all are doing well :)

Over the past few months, I built Anastasia Engine v7.1: a high-throughput, bare-metal JIT & AOT compiler engine for custom Anastasia Assembly (.ana).

The primary architectural goal was simple: 0 external dynamic dependencies and 0 standard C runtime (libc/libstdc++) linking. The entire engine compiles under -ffreestanding -nostdlib -fno-exceptions -fno-rtti and operates directly on raw Linux & Win32 kernel syscalls (raw_mmap, raw_mprotect, raw_clone, raw_futex, raw_io_uring).

Here is how it works under the hood and why I built it.


Core Technical Highlights

  • 100% Freestanding Zero-CRT Architecture: Zero external third-party C++ runtime dependencies (AnaEncoder). Executes directly on bare-metal syscall boundaries.

  • Native String Literals & Zero-Linker .rodata Emission: const-string support with parse-time zero-copy length tracking. Features a JIT read-only interned string pool and an AOT freestanding ELF linker (ElfEmitter) capable of emitting .rodata sections and patching RIP-relative relocations (R_X86_64_PC32 / R_AARCH64_ADR_PREL_PG_HI21) without needing ld or link.exe.

  • Multi-Architecture Native Encoders: Native x86_64 instruction encoder (AnaEncoder) featuring VEX (256-bit AVX2) and EVEX (512-bit AVX-512) byte-packing, paired with a fixed 32-bit AArch64 (ARM64) backend.

  • SSA Optimization & Autovectorization:

    • SSA Counted-Loop Autovectorizer: Transforms scalar loops into 256-bit or 512-bit packed SIMD vector operations.
    • Non-Temporal Store Streaming: Emits non-temporal stores (vmovntdq + sfence) to bypass L1/L2/L3 cache pollution on large array writes.
    • Escape Analysis & Scalar Replacement: Allocates non-escaping objects directly to virtual registers (0 heap allocations).
  • Zero-Copy Hardware Async I/O (io_uring): Submission Queue (SQ) and Completion Queue (CQ) ring buffers managed directly via kernel raw_mmap.

  • 199 Verified Engine Tests: Passes 199/199 tests (40 Core Engine QA + 30 LeetCode + 30 Codeforces 1800+ + 100 Hardcore Algorithm & Stress Tests).


Anastasia Assembly (.ana) Code Example

.fn compute_factorial(p0: i64) -> i64
    .registers 3 local

    move-const v0, 1         ; Accumulator = 1
    move-const v1, 1         ; Counter i = 1

loop_start:
    if-ge v1, p0, loop_end   ; Exit loop if i >= N
    mul-int/64 v0, v0, v1    ; acc *= i
    add-int/64 v1, v1, 1     ; i++
    goto loop_start

loop_end:
    sink-mem v0              ; Preserve side-effects in volatile sink
    return-val v0            ; Return factorial result
.end_fn
Enter fullscreen mode Exit fullscreen mode

CLI & Execution Modes

# 1. Execute Anastasia Assembly program in microsecond JIT Mode
./build/anastasia_engine program.ana

# 2. Compile Anastasia Assembly program to Relocatable ELF Object File (AOT Mode)
./build/anastasia_engine --aot input.ana output.o

# 3. Run full ecosystem test suite (199 / 199 Tests)
./build.sh --test
Enter fullscreen mode Exit fullscreen mode

I'd love to hear your feedback on the architecture, SSA passes, or freestanding codegen!

👉 GitHub Repository: github.com/nadermkhan/anastasia

👉 Technical Documentation: doc/doc.md

Thanks <3

Top comments (0)