Hacker News new | ask | show | jobs
by jdswain 2 days ago
I've got a long-term project of building an Oberon compiler. Oberon is a language in the Pascal family, the newest language from Wirth, and an attempt to remove any unnecessary features from his languages, indeed he went a little too far in some early versions of Oberon and restored a feature or two in successive versions.

Mostly I've learnt a lot from building a compiler, in particular the back-end which I didn't have much experience with. But also I've started using Oberon more and more. My compiler targets the 65C816 processor, but I ended up porting the front-end to LLVM so that I had native oberon, and used it to build a number of tools, an emulator, and actually the compiler (there was a C intermediate step).

In the end I've started to really like Oberon, and I don't miss much from more modern languages. I did add some extensions so I have a very simple form of object-orientation, and used it to implement a UI toolkit similar to AppKit, but much simpler. Some of the modern language features add more complexity than they give in benefits. And sometimes it's just better to write code than learn a new language feature or library.

Plus it's a very readable language.

7 comments

> 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

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.

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.

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.

Oberon is certainly an interesting direction. But in term of concurrency and multi-cores support it has no answer. And I argue that proper parallel programming support can not be fully solved by a library if the language has not designed for it or has built-in primitives to support it. In fact, Lalis, Sanders, Keller and others have made proposals to add concurrency support to Oberon.

The second big thing missing in Oberon is IMO the memory safety features. For today world and going forwards, I believe such features are essential.

Simplification and a lean implementation is interesting, especially as a basic for further development in a research environment. But for practical application and mass adoption, there are other demands we can’t simply ignore.

Only if you stay at the base version, instead of its descendents like Zonnon or Active Oberon.

However it is true that in 2026 they would hardly get any mainstream adoption.

Which version though?

While my interest got spiked initially by the original Project Oberon, I was more found of the paths taken by Component Pascal and Active Oberon, as language evolution.

Anyway, it was what initially opened my eyes to systems programming with GC enabled languages, and drew me into the rabbit hole of Cedar, Modula-2+, Modula-3 and co.

Was Active Oberon the foundation of A2/Bluebottle? My memory fails me.

I haven't dug into Oberon, because it's not quite Pascal enough for me to love it, and felt a bit heavier than I had hoped for syntax wise.

I'm enjoying Odin lately, and if I felt i had more time/use for Oberon I'd probably try driving it. But feel that as a "living" project Odin is more usable, it feels more constrained in syntax and concision than the larger Oberon project.

This is similar to like Genera/Lisp Machines, where I'd love to explore more (and even plan9, though that's less related to OS/Language integration in the way Bluebottle/A2 and Genera/Lisp Machines.

Yes it was, last programming language update was on 2019.

https://gitlab.inf.ethz.ch/felixf/oberon

https://gitlab.inf.ethz.ch/felixf/oberon/-/blob/main/docu/Ob...

Odin is quite interesting for those of us with Wirthian background, although not having some form of GC kind of puts it off to me. I know how it looks like and don't really miss plain manual memory management beyond building blocks.

The language is Wirth's Oberon-07, as his 2016 report defines it, with additions for objects, interfaces and literals, and with the data sizes of the 16-bit 65C816. INTEGER and SET are 16 bits, LONGINT is 32, BYTE is 8 bits unsigned, and REAL is 32 bits, with LONGREAL as another name for it. Records can have type-bound procedures, chosen at run time by the record's actual type, and the language adds OVERRIDE, SUPER, initialisers declared with PROCEDURE INIT and called as T.Make(...), and WEAK pointers. INTERFACE types are implemented by records that declare IMPLEMENTS. There are constant arrays, record and array literals such as Point{x := 1; y := 2}, an ELSE in a numeric CASE, and _ in names. Modules can be declared LARGE (code over a bank) or FRIENDS (named modules may assign to their exported variables). Like Oberon itself, it has no exceptions and no concurrency in the language: errors are compiler messages, traps or result codes, and processes come from the OS16 library. The compiler grew from Wirth's Project Oberon compiler, and follows his structure. It was initially written in C, then ported to Oberon so it could compile itself. It comes in two builds that compile the same language to the same files: oc on OS16 and oc816 on Mac/Linux, using LLVM. The OO type features were primarily added to support the UI toolkit. OS16 is the associated operating system.
Many thanks for the whole overview, looks kind of interesting approach.
Wish it retained Modula-2's stackless coroutines though.
While not the same, Active Oberon's Active Objects provide a model similar to async/await.
Thanks for this, I wasn't aware.

LATER EDIT: After looking them up I found active Oberon objects to be quite heavy and preemptively scheduled. What I liked about Modula-2 coroutines is the control over how heavy a local stack they would own and when would control transfer to them -- not suitable for real parallelism of course. But for ten thousand boids simulating a swarm of bees foraging, returning, waggle dancing, recruiting, and flying out to precise coordinates, coroutines would be pretty good fit.

Here there you go, see the citations as well.

https://www.semanticscholar.org/paper/A-Multiprocessor-Kerne...

You might need to hunt for the actual PDFs, though.

Oberon is definitely an interesting language, and there's a few self-hosting compilers coded in Oberon itself in under 6 thousand lines of Oberon.
> indeed he went a little too far in some early versions of Oberon and restored a feature or two in successive versions

Actually the most minimalistic version is the one he made for his retirement project, Oberon-07. Oberon-2 (by Mössenböck et al.) had most features. My Oberon+ is a superset of all (original) Oberon versions.

If a language features adds more in complexity than benefits, it doesn't feel very Wirth-ian (Oberon or Pascal.)

What features do you have in mind?

Floating point for GUIs is a rare and important exception. Compilers rarely need floating point.
> Oberon is a language in the Pascal family, the newest language from Wirth, and an attempt to remove any unnecessary features from his languages

And my guess this is exactly why it was never used at large.

Pascal by Wirth was also a teaching language. Hardly used. Only when Borland created Turbo Pascal --- which was the opposite of "remove any unnecessary feature" did it become tremendous successful. I took all of CP/M machines, e.g. many Apple II owners bought a Z80 card to use Turbo Pascal. Then it took the world of MSDOS. And for Windows 3.x it took the world again in storm in the form of Delphi.

Only when the software was transferred to the weird company with the weird prices and the weird name (Embarcawhatever) came the story to an end. Turbo Pascal sold for ~ 100 US$ and the Embarcawhatever asked for 1000 US$ if you also wanted the sources for the graphical objects.

That is: a striped down to the bare helpful language might be good for a university introduction course. But actually a lot more people learned Pascal with the beefed up versions "Turbo-Pascal" and "Delphi". Outside of university, just with the text book that was contained when you bought it. Or with the "Turbo-Pascal for Dummies/Grifters" type of books if you had the illegal copy.