Remix.run Logo
▲ whartung a day ago

> My compiler targets the 65C816 processor

Of all things...

I also have a (unpublished) '816 focused language and compiler (me and the AI).

I'm keeping it pretty conservative, as the goal is to rewrite the compiler in itself, and have it self-host. But a fellow posted this [1] about "Micron", an Oberon inspired system language.

And I'm giving a keen eye to how it handles Interfaces. I'm not sure if it will really fit, but it's an interesting idea that should be reasonably cheap on the compiler, and have no impact on the runtime.

I must say having an introspective CPU simulator as part of your unit tests can really help with writing a compiler. Not only can you test that the code is generating what it's supposed to, you can test that the code actually does what it’s supposed to.

[1] https://news.ycombinator.com/item?id=50413266

▲jdswain a day ago | parent | next [-]

I also had the goal of self hosting, and that is working, although I have made it a little easier on myself by extending the 65C816 in some small ways. The most significant for the compiler is a small extension to the registers so that the direct page and stack can be located anywhere in memory. This is primarily to allow larger operating system and app images, the compiler is quite large now so it needs this. I have a limit of 64k for each module.

One breakthrough in the compiler was when I could start to use AI to interpret instruction traces, before that I was doing it by hand and it took a very long time. Now the AI pinpoints my errors very quickly, although I'm past that stage now and don't often come across compiler errors. I do this with an emulator, also written in Oberon.

▲whartung a day ago | parent [-]

I already had a 6502 simulator that I wrote over 10 years ago. I had not touched it in a long while, but coming back to it, it was remarkably far along toward running ‘816 (or so I thought).

So I uplifted it to a full boat ‘816 core. Once I had that, compiler development accelerated since the testing was much better. The AI and unit tests could generate the code, run the code, and analyze CPU state and memory.

Real game changer.

My proto compiler is in Java, but not idiomatic Java by any means. It’s limited to static allocation and constructs available in the new language to make porting it later, ideally, mostly mechanical.

▲cmrdporcupine a day ago | parent | prev [-]

Funny. I also have a Wirth-like language like that. Targets the 816 but also the CPU in the Mega65 (45GS02) which is similar but different. Wirth-ish in terms of syntax flavour but lower level as it is explicitly designed with the 65xx architecture in mind (stack structure, calling conventions, zero page, etc). C is notoriously.. not... appropriate for that architecture.

https://github.com/rdaum/menschly

Self-hosting is not something I'm aiming for.

I have a single-level Bubble Bobble clone, a simple OS, and a scrolling/exploding demo thing in it.

And yes, AI was heavily involved. I still think it's potentially valuable.