descriptionSoul of a tiny new machine. Track side effects in safe Assembly → More thorough tests → More malleable and rewrite-friendly software.
homepage URLhttp://akkartik.name/about
repository URLhttps://github.com/akkartik/mu.git
ownermu@akkartik.com
last changeTue, 19 Dec 2023 16:38:59 +0000 (19 08:38 -0800)
last refreshFri, 20 Sep 2024 09:26:00 +0000 (20 11:26 +0200)
content tags
add:
README.md

Mu: a human-scale computer

Mu is a minimal-dependency hobbyist computing stack (everything above the processor).

Mu is not designed to operate in large clusters providing services for millions of people. Mu is designed for you, to run one computer. (Or a few.) Running the code you want to run, and nothing else.

Here's the Mu computer running Conway's Game of Life.

git clone https://github.com/akkartik/mu
cd mu
./translate apps/life.mu  # emit a bootable code.img
qemu-system-i386 code.img

screenshot of Game of Life running on the Mu computer

(Colorized sources. This is memory-safe code, and most statements map to a single instruction of machine code.)

Rather than start from some syntax and introduce layers of translation to implement it, Mu starts from the processor's instruction set and tries to get to some safe and clear syntax with as few layers of translation as possible. The emphasis is on internal consistency at any point in time rather than compatibility with the past. (More details.)

Tests are a key mechanism here for creating a computer that others can make their own. I want to encourage a style of active and interactive reading with Mu. If something doesn't make sense, try changing it and see what tests break. Any breaking change should cause a failure in some well-named test somewhere.

Mu requires a 32-bit x86 processor. It supports a short list of generic hardware. There's no networking support yet. Development has slowed, but I still care about it. Feedback, bug reports and other forms of contribution continue to be appreciated.

Mu in the press

Goals

In priority order:

Thorough test coverage in particular deserves some elaboration. It implies that any manual test should be easy to turn into a reproducible automated test. Mu has some unconventional methods for providing this guarantee. It exposes testable interfaces for hardware using dependency injection so that tests can run on -- and make assertions against -- fake hardware. It also performs automated white-box testing which enables robust tests for performance, concurrency, fault-tolerance, etc.

Non-goals

Toolchain

The Mu stack consists of:

All Mu programs get translated through these layers into tiny zero-dependency binaries that run natively. The translators for most levels are built out of lower levels. The translator from Mu to SubX is written in SubX, and the translator from SubX to bare SubX is built in bare SubX. There is also an emulator for Mu's supported subset of x86, that's useful for debugging SubX programs.

Mu programs build natively either on Linux or on Windows using WSL 2. For Macs and other Unix-like systems, use the (much slower) emulator:

./translate_emulated apps/ex2.mu  # 2-5 minutes to emit code.img

Mu programs can be written for two very different environments:

The largest program built in Mu today is its prototyping environment for writing slow, interpreted programs in a Lisp-based high-level language.

screenshot of the Mu shell

(For more details, see the shell/ directory.)

While I currently focus on programs without an OS, the linux/ sub-directory is fairly ergonomic. There's a couple of dozen example programs to try out there. It is likely to be the option for a network stack in the foreseeable future; I have no idea how to interact on the network without Linux.

Syntax

The entire stack shares certain properties and conventions. Programs consist of functions and functions consist of statements, each performing a single operation. Operands to statements are always variables or constants. You can't perform a + b*c in a single statement; you have to break it up into two. Variables can live in memory or in registers. Registers must be explicitly specified. There are some shared lexical rules. Comments always start with '#'. Numbers are always written in hex. Many terms can have context-dependent metadata attached after '/'.

Here's an example program in Mu:

ex2.mu

More resources on Mu:

Here's an example program in SubX:

== code
Entry:
  # ebx = 1
  bb/copy-to-ebx  1/imm32
  # increment ebx
  43/increment-ebx
  # exit(ebx)
  e8/call  syscall_exit/disp32

More resources on SubX:

Mirrors and Forks

Updates to Mu can be downloaded from the following mirrors:

Forks of Mu are encouraged. If you don't like something about this repo, feel free to make a fork. If you show it to me, I'll link to it here. I might even pull features upstream!

Desiderata

If you're still reading, here are some more things to check out:

cd linux
./translate tile/*.mu
./a.elf screen

Credits

Mu builds on many ideas that have come before, especially:

On a more tactical level, this project has made progress in a series of bursts as I discovered the following resources. In autobiographical order, with no claims of completeness:

shortlog
2023-12-19 Kartik K. Agarammuch lovemain
2023-11-26 Kartik K. Agaramuse markdown syntax for images without attributes
2023-09-22 Kartik K. Agarambring apps/hest-life.mu up to date
2023-08-04 Kartik K. Agaramcouple of tweaks to Readme
2022-04-01 Kartik K. Agaramtweaks to compiler doc
2022-02-25 Kartik K. Agarammore portable
2022-02-25 Kartik Agaramklunky attempt to support BSD stat
2022-02-25 Kartik Agarammove comment to a clearer location
2022-02-25 Kartik Agaramfix a conflict between GNU and Mac/BSD
2022-02-03 Kartik Agaramupdate stale stuff in an old prototype
2022-01-23 Kartik K. Agaramtypo in shell Readme
2022-01-18 Kartik K. Agaramslack: hacky feature to browse thread by url
2022-01-17 Kartik K. Agaramslack: update instructions for downloading images
2022-01-14 Kartik K. Agaramacknowledge current status
2022-01-09 Kartik K. Agaramobsolete argument
2021-12-24 Kartik K. Agaramfix a regression from 3 commits and 12 days ago :/
...
heads
9 months ago main
9 months ago hlt
3 years ago fix-precision
5 years ago desugar
5 years ago survey
5 years ago dquotes-3
5 years ago new-segment-header
5 years ago dquotes
5 years ago dquotes-1
5 years ago carry-flag
5 years ago allocate-using-mmap
5 years ago dquotes-2
5 years ago charles-l-print-int-decimal
5 years ago charles-l-write-string-to-stream
5 years ago add-two-nums
5 years ago charles-l-add-two-nums
...