$ show irmen/prog8
Prog8 is a Kotlin/JVM compiler and language toolchain for retro 8-bit/16-bit platforms (C64, C128, CX16, PET32, Amiga, m68k). It compiles a high-level language to 6502/68000 assembly through a multi-stage pipeline: lexer/parser, AST construction, semantic analysis, intermediate representation, optimizer, code generation, and optional VM execution. The repository also includes an LSP server, a Gradle build with Kotest tests, CI workflows, and target-specific runtime libraries. It is primarily an application (compiler/CLI), not a data/research project.
The LLM identified 5 files worth highlighting for reuse:
Implements a complete visitor over all AST node types with before/after hooks and an AstModification framework (AstRemove, AstReplaceNode, AstInsert, AstSwapOperands, AstScopeFlatten). This is a self-contained tree-walking and rewriting engine that can be extracted for any compiler or tooling needing structured AST transformations.
Manages document versions, module caching, keyword completions, hover documentation, and module resolution (core, target-specific, CX16, user modules). Demonstrates a clean LSP service layer that separates editor protocol concerns from compiler internals; useful as a reference for adding LSP support to other compilers.
Encodes language rules for choosing integer/float types based on literal value and context (e.g., negative values force WORD, fractional values force FLOAT). The optimalInteger/optimalNumeric functions are pure, side-effect-free helpers that could be reused in any language frontend needing numeric literal type resolution.
Optimizer pass that explicitly avoids optimizing NaN float comparisons, showing correctness-aware peephole optimization. The pattern of documenting why an optimization must not fire is valuable for any compiler's constant-folding or peephole passes.
Helper that compiles source strings to assembly for multiple targets, providing a high-level API for compiler tests. This is a reusable test harness pattern for any compiler project that needs to assert on generated assembly from source snippets.