How mightypancake/axo works
Project type and purpose
• This is a domain-specific programming language compiler (“Axo”) that reads .axo source files, parses and type-checks them, and emits readable C (and optionally WebAssembly) code. It also bundles a standard library of modules (core, math, io, std, raylib bindings, etc.) and embeds a full Lua interpreter for scripting or extension.
File structure
• Top-level build & CI:
• .github/workflows/* – CI pipelines for Linux, macOS, Windows
• makefile, shell.nix – build scripts and reproducible dev environment
• Parser front-end:
• lex.yy.c, scan.l – Flex scanner
• axo_gram.tab.c, axo_gram.y – Bison grammar
• Compiler driver & core:
• src/axo.c, src/axo.h, src/axo_err.h – main CLI driver, error handling
• src/utils/* – general utilities (hashmaps, string, memory)
• Language runtime & backends:
• src/wasm.c / src/wasm.h – WebAssembly code generation
• Embedded Lua runtime under src/lua/src/* compiled into a static lib
• Standard library modules:
• modules/*/*.axo (core, map, dict, math, io, raylib, etc.)
• Some modules include C code (hashmap.c), headers, or Lua scripts
• Examples & Tests:
• examples/ and tests/ – sample .axo programs, resources (audio, models)
README for insights
• Emphasizes compiler’s goal: modern C-like syntax → C output, no semicolons, no OOP
• Early-stage, leak-heavy code but focused on performance
Main components & relationships
a. Components:
1. CLI Front-End (axo executable)
2. Scanner (Flex) & Parser (Bison)
3. AST & Semantic Analyzer
4. Code Generators:
– C Backend
– WebAssembly Backend
5. Standard Library Loader (modules/…)
6. Embedded Lua Runtime
7. External C Compiler (gcc/clang)
b. Data flow & interactions:
– User invokes axo with .axo file → CLI reads file → Scanner → Parser → AST
– Semantic Analyzer resolves symbols, types, module imports
– Module Loader pulls in .axo modules and C/Lua components
– Code Generators emit C source (and/or WASM)
– CLI invokes external C compiler → final binary or library
c. Architectural patterns / principles:
– Classic compiler pipeline (lex → parse → analyze → codegen)
– Modular design for std library (each module self-contained)
– Backends pluggable (C vs WASM)
– Embedding of external interpreter (Lua) as a subcomponent
d. Key technologies / libraries:
– Flex / Bison for parsing
– Standard C99 for generated code
– Lua 5.x core compiled in
– Optional Raylib bindings for multimedia demos
– GNU Make, Nix for reproducible builds
– GitHub Actions for CI