Rewriting a Compiler for the Commander X16 and Foenix F256K

280

Modern Retro Dev returns with an update on their hobby compiler project — a tool aimed at programming for modern retro systems like the Commander X16 and Foenix F256 Jr Jr. This time, the focus is on a full rewrite of the compiler, taking it from a rough prototype to something cleaner, more structured, and ready for others to explore on GitHub.

The original version was built quickly in Python — fast to write but messy under the hood. Rather than polish that early work, the developer decided to start fresh, treating Python like modeling clay for experimenting, then switching to Rust to shape the final product. The rewrite not only cleaned up the code but also made it easier to target multiple platforms.

One of the big improvements was removing leftover experimental code — the “cruft” that builds up during hobby development. This rewrite was a chance to clear it out and design the code for long-term use. Features were added carefully, focusing on getting a minimum viable product running the classic “Sieve of Eratosthenes” benchmark — a popular test from the early days of home computing.

Current compiler features include support for unsigned 8-bit and 16-bit data types, strings, arrays, booleans, conditional statements, loops, basic math, and file writing, which was crucial for unit testing. Unit tests became a key part of development, allowing the developer to catch hidden bugs and avoid regressions.

The performance benchmark results were revealing. Prog8, a highly optimized language for 6502 systems, came out on top. C implementations using cc65 and LLVM/MOS are followed closely. The new compiler landed in the middle — faster than BASIC but trailing the more mature tools. BASIC, being interpreted, performed the slowest, but remained a good reference point.

Looking ahead, the project has several potential directions. The developer plans to add support for more systems, starting with the Foenix F256 Jr Jr. There are also ideas to generate C code for cross-platform use, write a custom assembler, build a self-hosted compiler, and eventually create a higher-level language that compiles down to the current one.

Feedback is welcome, especially on which of these ideas viewers find most interesting.

Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments