70 points · by Rochus · 3w ago · 31 comments
Micron is not my first langage design. I first built Oberon+, a modernized and unified Oberon, in order to under stand, by implementing it and by porting real systems to it, what Wirth’s design actually gives and where it fails. The systems ported to Oberon+ included the 2013 Project Oberon System and different versions of Oberon System 3. I then explored the opposite direction with Luon, a higher-level language for managed application progamming. Micron is the synthesis of this and my 30 years experience with C/C++ in systems programming.
The goal of Micron is to use the same language for boot code, device drivers, an operating system kernel, and ordinary applications, without requiring a garbage collector or routing machine access through a separate, unchecked system dialect (such as Oberon's SYSTEM.ADR/GET/PUT which operates on LONGINT). The language supports explicit memory layouts, signed and unsigned integer types, pointer operations, and direct calls to C without wrappers. One of its central design choices is language levels. Each module declars the level and thus the feature it needs, ranging from code that requires neither stack nor heap to garbage-collected objects. A module can import only modules at the same or a lower level. For example, a kernel module declared at level 1 cannot accidentally acquire a dependency on heap allocation through an import. Other features include generic modules, structural interfaces, and compile-time procedures. Much of what would require a preprocessor in C is expressed through typed language features.
There is a working compiler, interpreter, and IDE, along with a free textbook (http://software.rochus-keller.ch/micron-textbook.pdf). The book explains both how the language works and the reasons behind its design. Its systems-programming section walks through a port of Wirth and Gutknecht’s Project Oberon operating system to Micron, cross-compiled and linked into a single executabl that runs on an emulated RISC-V machine.
The examples also include ports of a Smalltalk-80 VM, Scheme 9, and the original P4 Pascal compiler. The compiler and interpreter implement the language specification; native backends and tooling are still work in progress, and the current native code generation prioritises simplicity over optimisation.
For more information see https://github.com/rochus-keller/Micron/blob/master/Readme.m....
The examples subdirectory (https://github.com/rochus-keller/Micron/tree/master/examples) contains:
- a Smalltalk-80 implementation,
- the original 1976 P4 Pascal compiler,
- the Scheme 9 virtual machine,
- the Project Oberon System running on the host,
- and the Micron System described in the textbook, the migrated Project Oberon System natively running on RISC-V.*I've always been super interested in Oberon (due to my Pascal / Object Pascal / Delphi heritage) and even tried things like A2 (https://en.wikipedia.org/wiki/A2_(operating_system)) but never fully got into the boat.
Micron makes me excited to try your latest incarnation.
When compilation is that fast, it leads to a different kind of a conversation with the computer. Not necessarily always a better conversation but definitely different.
Such sophistication is also necessary for variable-length arrays, anyhow, especially in loops, so it's presumably no coincidence C99 got inline declarations, compound literals, and VLAs all at the same time.
C hasn't yet fully embraced and leveraged VLAs or the dependent typing features they brought along. That gave them a bad reputation (in crippled form they're all cost for little benefit), unfortunately causing languages like Rust to avoid them. If Rust (and LLVM) had fully embraced them from the beginning, alot of sharp edges wouldn't need to exist in Rust, especially around initialization and statically vs non-statically sized types. Premature optimization (in this case regarding baseline object semantics) is the root of all evil.
Once you are happy with the code one can use the optimizing compiler set at a preferred level of optimization.
As an aside, some simple Pascal compilers would not wait for building the full AST before emitting object code.
Disabling optimisation, can also boost the compilation speed although it won't be as fast.
If, however, the comparison is against more modern languages, such as Rust, Swift, Haskell, ML etc, the actual compute effort goes into type inference, not the multi-stage compilation process, as proving type correctness is a computationally hard problem.
It seems to me that the original goals that Wirth had are still very relevant today, especially given the gigantic heaps of abstraction on abstraction on abstraction etc. that we seem to have now. To me, all the complexity is slowing things down and making things less robust.
Micron feels like the end point of what Wirth was working to. If there are easy ways to target different CPU/MCU architectures and also call existing C libraries, then I'd love to use it on my next embedded project.
The current micc has three native backends (x86, ARMv7, RV32) and a C99 transpiler. I'm currently migrating the https://github.com/rochus-keller/micronsystem3/ to the Olimex ESP32-P4 board and the Raspberry Pi 3b using the native backends; on the "Wirth RV32 machine" it is already working; both the ARM and RV32 backends have options to adapt the generated code to a certain degree (e.g. for the A10, or the ESP32-C6). So far I have no plans to support more architectures. All backends offer a "C-like" calling convention, which supports directly linking and calling into C libraries (but not for all C parameter types, my approach is converting C to MIL instead, see https://github.com/rochus-keller/c2mil/). micc also has an integrated linker.
Because the world jumped onto OOP in all its meanings, the idea of modules and parsimonious simplicity seems to have been lost. It was wonderful to learn about Micron because I had been looking hard at Pascal, Modula-2, Oberon, Active Oberon, etc. to assess how they might work in modern ground-up system design with an emphasis on security and simplicity. As long as the toolchains and debug tools exist, I'm thinking that those who value this might be willing to break from current industry practice. That is why I asked about targeting other MCUs and CPUs.
Thank you for continuing to keep the Wirth candle alight. What you have been able to do by yourself is truly impressive.
> I had been looking hard at Pascal, Modula-2, Oberon, Active Oberon, etc. to assess how they might work in modern ground-up system design with an emphasis on security and simplicity
Interesting. I did essentially the same which first brought me to Oberon+ (https://github.com/rochus-keller/oberon/) which already was able to replace the unchecked pointer aritmetics of Oberon SYSTEM by a typed foreign function interface (FFI) as part of the language. But even then the system still depends on C or assembler. That's why I came up with Micron, which eventually will be able to even initialize the machine before there is a stack, all in the same high-level language.
> I'm thinking that those who value this might be willing to break from current industry practice
Go has demonstrated that there is a market for a "simple" language (at least before they added parametric polymorphism). It's nice if my work is appreciated, but I would not be able to give support to industry to adopt the language. Thanks for the motivating words.
Seymour Cray also designed the CDC 6600, which had a much more immediate impact on IBM et al.
I'm so grateful that we have people like you and Nils M. Holm keeping lots of these old ideas about design fresh, you both inspire me to keep pushing myself in my own projects.
to what extent is it safer than C? Does it eliminate safety issues common to C like out of bounds memory access, use-after-free, double-free, race conditions? Or maybe some other kind of safety issue present in C isn't possible in Micron?
> unsafe parts are explicit
Does it have unsafe blocks or something similar?