Soul of a tiny new machine. More thorough tests → More comprehensible and rewrite-friendly software → More resilient society.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Kartik K. Agaram 444227b3c4 first bit of animation 1 year ago
archive 6206 2 years ago
editor 7842 - new directory organization 1 year ago
html . 1 year ago
linux . 1 year ago
shell shell: roll back a change to the 'when' macro 1 year ago
tools . 1 year ago
.gitattributes 6690 2 years ago
101screen.subx clean up magic constants 1 year ago
102keyboard.subx . 1 year ago
103grapheme.subx . 1 year ago
104test.subx 7842 - new directory organization 1 year ago
105string-equal.subx 7842 - new directory organization 1 year ago
106stream.subx 7842 - new directory organization 1 year ago
108write.subx print call stack on all low-level errors 1 year ago
109stream-equal.subx 6769 - support for creating fake files in Mu tests 2 years ago
112read-byte.subx print call stack on all low-level errors 1 year ago
113write-stream.subx 7842 - new directory organization 1 year ago
115write-byte.subx print call stack on all low-level errors 1 year ago
117write-int-hex.subx 7842 - new directory organization 1 year ago
118parse-hex-int.subx print call stack on all low-level errors 1 year ago
120allocate.subx print call stack on all low-level errors 1 year ago
121new-stream.subx print call stack on all low-level errors 1 year ago
123slice.subx print call stack on all low-level errors 1 year ago
124next-token.subx 7842 - new directory organization 1 year ago
126write-int-decimal.subx print call stack on all low-level errors 1 year ago
127next-word.subx 7329 - snapshot: advent day 4 part 2 2 years ago
301array-equal.subx 7842 - new directory organization 1 year ago
302stack_allocate.subx 7254 2 years ago
308allocate-array.subx 7254 2 years ago
309stream.subx print call stack on all low-level errors 1 year ago
310copy-bytes.subx 7254 2 years ago
311decimal-int.subx . 1 year ago
312copy.subx 7842 - new directory organization 1 year ago
313index-bounds-check.subx always check for null in 'index' instructions 1 year ago
314divide.subx 7290 2 years ago
315stack-debug.subx . 1 year ago
316colors.subx primitive: read r/g/b for color 1 year ago
317abort.subx grow a few buffers until shell/ loads 1 year ago
400.mu dump addresses of call stack on abort 1 year ago
403unicode.mu 7842 - new directory organization 1 year ago
408float.mu 7276 2 years ago
411string.mu 7690 2 years ago
412render-float-decimal.mu 7842 - new directory organization 1 year ago
500fake-screen.mu . 1 year ago
501draw-text.mu . 1 year ago
502test.mu update vocabulary documentation 1 year ago
503manhattan-line.mu 7842 - new directory organization 1 year ago
504test-screen.mu start cleaning up pixel graphics 1 year ago
505colors.mu primitive: convert r/g/b to h/s/l 1 year ago
506math.mu reimplement Bresenham line in Mu 1 year ago
507line.mu hestified life: initial commit 1 year ago
508circle.mu reimplement Bresenham circle in Mu 1 year ago
509bezier.mu first bit of animation 1 year ago
LICENSE.txt 7489 - include GNU Unifont 2 years ago
README.md . 1 year ago
bezier.c clean up 1 year ago
bochsrc load debug info into code disk 1 year ago
bochsrc.2disks load debug info into code disk 1 year ago
boot.subx . 1 year ago
boot0.hex . 1 year ago
cheatsheet.pdf 5485 - promote SubX to top-level 3 years ago
colors.mu tool: compute nearby colors in default palette 1 year ago
ex1.mu snapshot: stupid debugging session 1 year ago
ex2.mu load debug info from disk on abort 1 year ago
ex3.mu . 1 year ago
ex4.mu . 1 year ago
ex5.mu . 1 year ago
ex6.mu . 1 year ago
ex7.mu . 1 year ago
ex8.mu . 1 year ago
ex9.mu . 1 year ago
ex10.mu . 1 year ago
ex11.mu bugfix in bezier 1 year ago
help make online help more obvious 1 year ago
hest-life.mu first bit of animation 1 year ago
life.mu . 1 year ago
mandelbrot-fixed.mu mandelbrot: add some garish color 1 year ago
mandelbrot.mu mandelbrot: add some garish color 1 year ago
misc_checks some hacky checks for common errors 1 year ago
misc_checks.subx some hacky checks for common errors 1 year ago
modrm.pdf 5485 - promote SubX to top-level 3 years ago
mu-init.subx always check for null in 'index' instructions 1 year ago
mu.md explicitly pass data disk to main 1 year ago
mu_instructions support checking overflow flag everywhere 1 year ago
rpn.mu tool: compute nearby colors in default palette 1 year ago
sib.pdf 5485 - promote SubX to top-level 3 years ago
subx.md . 1 year ago
subx_bare.md . 1 year ago
subx_opcodes support checking overflow flag everywhere 1 year ago
translate rename boot.hex to boot.subx 1 year ago
translate_emulated rename boot.hex to boot.subx 1 year ago
translate_subx grow a few buffers until shell/ loads 1 year ago
translate_subx_emulated grow a few buffers until shell/ loads 1 year ago
vimrc.vim belatedly migrate stale example definitions 1 year ago
vocabulary.md . 1 year ago

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

Currently Mu requires a 32-bit x86 processor.

Goals

In priority order:

  • Reward curiosity.
  • Safe.
    • Thorough test coverage. If you break something you should immediately see an error message. If you can manually test for something you should be able to write an automated test for it.
    • Memory leaks over memory corruption.
  • Teach the computer bottom-up.

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

  • Speed. Staying close to machine code should naturally keep Mu fast enough.
  • Efficiency. Controlling the number of abstractions should naturally keep Mu using far less than the gigabytes of memory modern computers have.
  • Portability. Mu will run on any computer as long as it's x86. I will enthusiastically contribute to support for other processors -- in separate forks. Readers shouldn't have to think about processors they don't have.
  • Compatibility. The goal is to get off mainstream stacks, not to perpetuate them. Sometimes the right long-term solution is to bump the major version number.
  • Syntax. Mu code is meant to be comprehended by running, not just reading. For now it's a thin memory-safe veneer over machine code. I'm working on a high-level "shell" for the Mu computer.

Toolchain

The Mu stack consists of:

  • the Mu type-safe and memory-safe language;
  • SubX, an unsafe notation for a subset of x86 machine code; and
  • bare SubX, a more rudimentary form of SubX without certain syntax sugar.

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 ex2.mu  # ~2 mins to emit code.img

Mu programs can be written for two very different environments:

  • At the top-level, Mu programs emit a bootable image that runs without an OS (under emulation; I haven't tested on native hardware yet). There's rudimentary support for some core peripherals: a 1024x768 screen, a keyboard with some key-combinations, a PS/2 mouse that must be polled, a slow ATA disk drive. No hardware acceleration, no virtual memory, no process separation, no multi-tasking, no network. Boot always runs all tests, and only gets to main if all tests pass.

  • The top-level is built using tools created under the linux/ sub-directory. This sub-directory contains an entirely separate set of libraries intended for building programs that run with just a Linux kernel, reading from stdin and writing to stdout. The Mu compiler is such a program, at linux/mu.subx. Individual programs typically run tests if given a command-line argument called test.

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:

Forks

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!

  • mu-normie: with a more standard build system that organizes the repo by header files and compilation units. Stays in sync with this repo.
  • mu-x86_64: experimental fork for 64-bit x86 in collaboration with Max Bernstein. It's brought up a few concrete open problems that I don't have good solutions for yet.
  • uCISC: a 16-bit processor being designed from scratch by Robert Butler and programmed with a SubX-like syntax.
  • subv: experimental SubX-like syntax by s-ol bekic for the RISC-V instruction set.

Desiderata

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

Credits

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

  • Peter Naur for articulating the paramount problem of programming: communicating a codebase to others;
  • Christopher Alexander and Richard Gabriel for the intellectual tools for reasoning about the higher order design of a codebase;
  • David Parnas and others for highlighting the value of separating concerns and stepwise refinement;
  • The folklore of debugging by print and the trace facility in many Lisp systems;
  • Automated tests for showing the value of developing programs inside an elaborate harness;

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: