How xnacly/purple-garden works
Project type and purpose
• purple_garden is a small Lisp‐inspired language toolchain implemented in C. It functions as both a compiler (front end + code generator) and an interpreter (virtual machine), optimized for performance.
File structure
• Top‐level modules (each backed by a pair of .c/.h files):
• io.{c,h} – file reading (uses mmap)
• lexer.{c,h} – tokenizes source into a token stream
• parser.{c,h} – parses tokens into an AST
• cc.{c,h} – “compiler” that lowers AST to bytecode + global constant pool
• vm.{c,h} – register‐based virtual machine that executes bytecode
• builtins.{c,h} – built‐in functions (@println, @len, etc.) mapped at compile time
• mem.{c,h} – memory allocators (bump allocator for front end, GC/block for VM)
• common.{c,h}, strings.{c,h} – shared data structures (String windows, hashing)
• Entry point: main.c calls into each module in a linear pipeline.
• Utilities & configuration: Makefile, flake.nix, docs/, examples/, tests/.
README insights
• Describes a 4‐stage pipeline: IO → lex → parse → compile → VM run (with optional disassemble or AOT flags).
• Highlights optimizations: zero‐copy strings, bump allocators, computed goto in lexer, register‐based VM, hash interned identifiers at lex time.
• Provides performance benchmarks, disassembler output, release/test workflows.