ALL INTELLIGENCE
Hacker News AIT2·Tools

Micron Debuts Oberon-Style Systems Programming Language

Original title: Show HN: Micron – Oberon with the Power of C
42AI Score

Micron is a systems programming language with Oberon+-style syntax and C-level reach, short for MicroOberon. The project ships a compiler, interpreter and IDE, replaces the preprocessor with language concepts, and introduces language levels so one language spans boot code, drivers, kernels and applications while calling C without wrappers.

Full Report

Contents5 sections

Logo

Welcome to the Micron Programming Language

This project implements a compiler, interpreter and IDE for the Micron programming language as specified here; see also the code examples below.

Micron is a systems programming language with a syntax similar to Oberon+ and the reach of C. The name "Micron" is an abbreviation of "MicroOberon".

Micron is intended as a practical alternative to C for systems programming. It combines the modularization, strictness and simplicity of Oberon with the flexibility of C: the same language serves for boot code, drivers, an operating system kernel and ordinary applications, and it calls C without wrappers. The preprocessor is replaced by language concepts that can largely substitute its features, supplemented by explicit support for generic programming, inlining and procedures that run at compile time. Thereby the focus is always on simplicity and the greatest effect with a practicable effort.

Micron supports language levels: a module declares the level it needs, from level 0 (inlined code for hardware initialization, no stack) over level 1 (stack frames, recursion, extern C procedures), level 3 (heap, pointers, exceptions) and level 4 (type extension and dynamic dispatch) up to level 5 (garbage collection). A module can only import modules of the same or a lower level, so a kernel written at level 1 cannot depend on the heap by accident. Without the attribute, level 3 is assumed.

Documentation

In addition to the specification, a free textbook is available which shows how each feature of Micron is used and why it is designed the way it is. Part III walks through the Micron System, a port of Wirth and Gutknecht's Project Oberon operating system, which is compiled, linked and booted on an emulated RISC-V machine with a single command.

Example applications and systems

Since the start of the project in January 2024, numerous benchmarks, virtual machines and operating systems of significant size have been migrated to Micron. The following references comprise about 130 kSLOC of working Micron code.

The examples subdirectory 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.

The Are-we-fast-yet repository includes the same benchmark suite in four different implementations for comparison: procedural, hybrid, interface-based and object-oriented.

The migration of the Oberon System 3 to Micron currently runs on the emulated RISC-V machine; support for the Raspberry Pi Zero 2 is work in progress.

Try it

The following precompiled versions are available at this time:

Just download, unpack and run. The command line options are described in the micc manual.

Here is a precompiled version of the Micron System discussed in the book which you can run on Linux x86_64 by just typing ./rv32vm --elf --ram 4 --disk disk.img system.bin (requires SDL2). More information is in the Readme.md.

Code examples

Micron is case sensitive, but each reserved word and predeclared identifier exists in a fully lower-case and a fully upper-case form with identical meaning; the last example is written in the Oberon style, all others in the lower-case style used in the book. Statement separators are optional.

Low-level programming and C interoperability
GO
module Bits [level = 1]

var
    a: array 4 of int32
    p: ^int32
    u, u1: uint32

begin
    println(band(0F0FH, 00FFH))    // 15
    println(bor(1, 4))             // 5
    println(bxor(5, 1))            // 4
    println(shl(1, 5))             // 32
    println(shr(0FFH, 4))          // 15, logical
    println(asr(-16, 2))           // -4, arithmetic

    u1 := 0FFFFFFFFH
    println(cast(int32, u1))       // -1, same bits
    u := usig(-1)
    println(u)                     // 4294967295, same bits

    a[0] := 10; a[1] := 20; a[2] := 30
    p := @a[0]
    p := ptroff(p, 1)              // advance by one int32
    println(p^)                    // 20
    inc(p)
    println(p^)                    // 30
end Bits

The file is in the examples subdirectory and compiles/runs with ./micc Bits.mic --run.

GO
module Clib [level = 1]

procedure abs(x: int32): int32; extern C
procedure toupper(c: int32): int32; extern C
procedure write(fd: int32; const buf: ^[]char; n: uint32): int32
    extern C "write"

var s: array 3 of char

begin
    s := "ok"
    if write(1, @s, 2) # 2 then return end
    println(abs(-5))
    println(toupper(sigl(ord('a'))))    // 65
end Clib
Abstraction without objects
YAML
module Shapes [level = 2]

type
    Shape = interface                   // a contract, satisfied structurally
                proc area(): integer
                proc print()
            end

    Rect   = record w, h: integer end
    Circle = record radius: integer end

procedure Rect.area(): integer          // type-bound procedure, bound statically
begin
    return self.w * self.h
end Rect.area

procedure Rect.print()
begin
    print("rect "); print(self.w); print("x"); print(self.h)
end Rect.print

procedure Circle.area(): integer
begin
    return 3 * self.radius * self.radius    // coarse
end Circle.area

procedure Circle.print()
begin
    print("circle r="); print(self.radius)
end Circle.print

procedure describe(s: Shape)            // accepts any type with area and print
begin
    s.print(); print(" area="); println(s.area())
end describe

var
    r: Rect
    c: Circle

begin
    r.w := 4; r.h := 3
    c.radius := 5
    describe(@r)                        // rect 4x3 ar

> (注:更多技术实现细节与完整 API 文档请查阅原项目 README)

---
**作者发帖说明(HN)**:

I have been developing Micron (for "MicroOberon"), a lean, statically typed, modular systems programming language that combines Oberon’s simplicity and explicit module structure with C’s low-level capabilities and interoperability.

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 exam...