*Screenception*
Visualizing programs with side-effects in a postfix shell with a live-updating text-mode environment. Built all the way up from machine code without any dependencies (except an x86 processor and Linux kernel).
https://archive.org/details/akkartik-2min-2020-11-12
Project page: https://github.com/akkartik/mu
More context: https://mastodon.social/@akkartik/104896128141863951
*Editing functions in the Mu shell*
https://archive.org/details/akkartik-2min-2020-12-06
Long delay since my last video. Printing floating-point numbers is *really* hard. I'm still half-assing it.
As a follow-up to https://merveilles.town/@akkartik/105331619408248578, I'm tightening focus to two threads:
a) These Mu shell experiments, and
b) An extremely skeletal OS to drop the Linux kernel dependency.
Deprioritized for now:
a) Other processors: RISCV, ARM, RPi, etc.
b) Graphics, mouse, etc. Device priorities for the OS are disk then ethernet.
*Towards running Mu without Linux*
All Mu really needs so far is to print to screen and read from the keyboard. Here's a 2-minute video about achieving that:
https://archive.org/details/akkartik-2min-2020-12-24
It seems such a small thing. But I needed lots of help, as you can see from the additions to my credits: https://github.com/akkartik/mu/compare/670cbb3d33807efb2d5e0db9e54ffed42f7ef0e3..main?short_path=b335630#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
Merry Christmas to all! What a beautiful world.
Project page: https://github.com/akkartik/mu
More context: https://mastodon.social/@akkartik/104896128141863951
*Switching gears to pure graphics*
Until now Mu has followed classic Unix: stdin, stdout, pure text mode.
But giving up an OS kernel requires controlling the screen myself. Which requires various complicated probing for hardware. Then programs handling various screen sizes.
Easier: just always assume some common graphics mode. Say 1024x768 with 256 colors.
Interestingly, the default palette has far fewer than 256 colors. (Pic: 1024 cols each contain color `col%256`.)
*2020: Flood-filling the Mu computer*
A year ago I had a prototype of a C-level programming language mapping 1:1 to Assembly that I _thought_ could be type-safe.
Since then, I:
* wrote an academic paper on it
* made it type-safe
* began a high-level language atop it
* got into video, with 15 2-minute screencasts
* and ran programs written in it on bare metal, without an OS, like, 5 years before I expected to.
β€οΈ to everyone who inspired, taught, debated, encouraged.
My 2020 wrap-up is turning into a bit of a rabbit hole:
http://akkartik.name/post/mu-2020
I ended up trying to create a Wardley Map (https://en.wikipedia.org/wiki/Wardley_map) for Mu.
*Rendering text atop baremetal*
Mu can now render text atop baremetal x86.
Try clicking around from http://akkartik.github.io/mu/html/baremetal/ex5.mu.html
The boot-up machine code reads a few sectors from disk, configures a keyboard handler, and loads a bitmap font (2KB for ASCII, with the option for more).
I use GNU Unifont. I believe that means Mu is now GPL v2. So stated. IANAL and I try not to think about software IP. But a font? Copyright seems reasonable there.
Next up: a text editor!
*A more international interface for rendering text*
New 2-minute video: https://archive.org/details/akkartik-2min-2021-01-12
You get just one fixed screen resolution: 1024x768, 256 colors. Widely available on modern machines, no drivers needed.
You get just one fixed-width bitmap font. No bold/italics, no anti-aliasing.
BUT it won't make assumptions about English and left-to-right order. I eventually want anybody to be able to customize it to their language.
Main project page: https://github.com/akkartik/mu
I've been trying to visualize the default 256-color palette I get on baremetal.
http://akkartik.github.io/mu/html/baremetal/vga_palette.html
To my eyes it looks like I can/should just live in the first 128 colors.
I built a game of "snakes", but it came out more like an etch-a-sketch π
http://akkartik.github.io/mu/html/baremetal/ex7.mu.html
Play it on any non-windows:
```
git clone https://github.com/akkartik/mu
cd mu
./translate_mu_baremetal_emulated baremetal/ex7.mu
qemu-system-i386 disk.img
```
h/j/k/l to draw
It took a while, but I've finally ported a pre-existing Mu program to baremetal: an RPN calculator.
This was _hard_, purely because of cursor management. I have a greater appreciation for everything that display hardware and terminal emulators provide for text mode. Mu so far puts the onus on the programmer.
http://akkartik.github.io/mu/html/baremetal/rpn.mu.html
In the end it's interesting to visualize the changes I had to make:
vim -d apps/rpn.mu baremetal/rpn.mu
They're entirely in `main`; the rest is unchanged.
I've been reimplementing my from-scratch live-updating postfix shell to _really_ from scratch (no more OS kernel), while at the same time rewriting the prototype with lots of tests and actually giving the language some sort of rigorous basis. No demos yet, but in the meantime here's Conway's Game of Life running on baremetal Mu.
https://archive.org/details/akkartik-mu-life-2021-02-13
Sources: http://akkartik.github.io/mu/html/baremetal/life.mu.html
Main project page: https://github.com/akkartik/mu
The Mu shell is now off Linux
https://archive.org/details/akkartik-mu-shell-20210214
Starting point for the sources: http://akkartik.github.io/mu/html/baremetal/shell/line.mu.html
The architecture is now much cleaner. Functions contain lines, lines contain words, words contain gap buffers. Rendering a thing renders its constituent things. Render takes a top-left coordinate and returns a bottom-right coordinate. Each thing knows which constituent thing has its cursor, shows its cursor when rendering, redirects incoming keystrokes to it.
I'm working through Make a Lisp with Mu
So far I'm done with https://github.com/kanaka/mal/blob/master/process/guide.md#step-0-the-repl, albeit with some tweaks since it's baremetal
Today was documentation day
Primitives available in the Mu computer when running without an OS: https://github.com/akkartik/mu/blob/main/vocabulary.md
Primitives available when running on Linux: https://github.com/akkartik/mu/blob/main/linux/vocabulary.md
For starters I focused just on making things more discoverable. These files are optimized for opening in your text editor, jumping to definitions to see type signatures, etc. See https://github.com/akkartik/mu/blob/main/editor/exuberant_ctags_rc for a ctags configuration for Mu and SubX programs.
Main project page: https://github.com/akkartik/mu
Mu can now read from an ATA (IDE) disk drive on Qemu.
https://github.com/akkartik/mu/tree/main/shell#readme
It wouldn't have been possible without the lovely folks over on #osdev. And the inspiration of ColorForth (https://merveilles.town/@akkartik/105906716550232992), though I still don't understand how that driver works.
The Mu computer now has drivers for disk and mouse.
Still extremely klunky. IDE disk drives only, and the mouse driver uses polling because configuring IRQ 12 is still beyond me.
Example programs (as usual memory safe and translating 1:1 to x86 machine code)
Disk: http://akkartik.github.io/mu/html/ex9.mu.html
Mouse: http://akkartik.github.io/mu/html/ex10.mu.html
Here's video of the mouse example. There's no pointer so you have to imagine me moving the mouse around.
Like I said. Klunky.
Main project page: https://github.com/akkartik/mu
What should the signature of a program look like?
Typed languages have a fixed signature for function `main`. A list of strings, a window context, or an IO monad.
Here's the signature on the Mu computer:
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk)
A rudimentary, hokey capability system. No mouse yet. 'screen' is only used for text; pixel graphics currently go around it. 'data-disk' can't access code, and will eventually include finer-grained restrictions.
Mu's HLL is now Turing-complete, I think.
Things to notice:
* Wordstar-style menu at the bottom.
* List of available primitive functions in bottom left.
* List of globals on the left side that updates as I add definitions.
* Matching parens highlighted as I type.
* Drilling down into the trace to understand how the program was evaluated.
https://github.com/akkartik/mu/blob/main/shell/README.md
Main project page: https://github.com/akkartik/mu
Distinguishing a program's return value from its side effects
https://archive.org/details/akkartik-2min-2021-04-10 (2-minute video)
Main project page: https://github.com/akkartik/mu
Writing code _within_ the Mu computer
I tried and failed to implement Bresenham's line algo. Horizontal and vertical lines work.
No macros => lots of lambdas.
The computer keeps crashing because I type too fast (still can't brain interrupt handlers). It frequently saves to disk, but as an s-expression. Reboots lose indentation.
Ok, edit on host -> create disk image.
I have lots of little buffers. When they overflow the computer crashes. Without a call stack.
Thanks @tekknolagi for pairing!
Prototyping on the Mu computer
A 3-minute video showing what it's currently like to prototype programs on the Mu computer. There are lots of limitations. It's slow, and it can only handle short runs.
While these limitations will be relaxed over time, the goal is partly to nudge people to throw the prototype away once they know what they want, and rewrite it one level down. Therefore: encourage people to write lots of tests.
https://archive.org/details/akkartik-mu-2021-04-22
Main project page: https://github.com/akkartik/mu
I suck at colors. Anybody wanna help me paint this bikeshed for the mind?
Constraint: I only have 256 colors.
The Mu computer now has Lisp macros
Here's the Bresenham algorithm for drawing circles using a few macros. My current style is to keep line width to 41 characters and lay out two columns of functions.
Caveats:
* No nested backquotes yet.
* I can't draw circles too far down the screen due to a strange error.
* In general, error messages have been a mess ever since I stopped relying on Linux. A heavy exercise in humility.
Main project page: https://github.com/akkartik/mu
Playing with the kids on a Saturday morning
(Much faster on Linux, thanks to -enable-kvm.)
git clone https://github.com/akkartik/mu
cd mu
dd if=/dev/zero of=data.img count=20160
dd of=data.img conv=notrunc < shell/data.limg
./translate shell/*.mu # gen code.img
qemu-system-i386 -enable-kvm -m 2G -hda code.img -hdb data.img
The Mu computer now dumps a snapshot of the call stack when it fails catastrophically
This was not fun. And the debug information in the second half of the code disk is now larger than the code itself.
On the other hand, I hope debugging will now be more fun!
@akkartik nice!
@akkartik Lambdamu
@neauoire π
I've been thinking of it as mulisp. Or maybe even just Lambda as the layer above Mu?
@akkartik I've been thinking about something, did you watch the talk s-ol shared about smalltalk running on top of lisp, from yesterday?
It has gotten me thinking about implementing a Uxn assembler in Uxn itself, so I could write/assemble uxn programs from within the system.
Do you have something like this in Mu? Is lisp going to be that intermediary language for you? Any suggestions/lessons on this topic you could share?
@neauoire Uxn assembler in Uxn sounds eminently doable! Now I'm interested.
A full Smalltalk/Lisp like in that talk is a _lot_ of work. The final complexity discourages looking under the hood. Which rubs me the wrong way. Maybe you too.
The very notion of 'language' tries to pretend there's nothing underneath, which might be counter-productive.
So I'm still feeling my way with Mulisp. Maybe it's going to stay a toy, a gateway drug for kids to get into the level below.
@akkartik fair enough, that's a good answer. I'm looking forward to see how it evolves then :) Good luck with mulisp β
@neauoire I got super interested in building languages and parsers in grad school. The idea of building one language in another (or itself) is like catnip for us programmers. Like with religion or the Singularity, we all have an escapist urge to work at higher levels. But higher level languages don't actually seem to reduce mess. The mess isn't out there, it follows us. HLLs just increase CO2 emissions.
HLLs are good for prototyping. Once that's done, shrink dependencies. Like you already do.
@akkartik yeah I agree, I always thought, well, why don't people make assembly languages that are fun enough to use that there's no need to build on top of it. Maybe there are problems there I haven't encountered yet.
Lisp as the first language above bytecode sounds fun enough that no other language needs to be build on top.
@neauoire Seems worth trying, anyway π I had some ideas for removing parens and adding infix from a previous Lisp project: http://akkartik.name/post/wart. I'm planning to pull them in here for like a quick calculator mode.
I honestly don't think there's much for you to learn from "experienced" programmers. Trust your instincts β The rest of us don't know what we're talking about.
Rereading your original question, did you want to build Uxn on mulisp or Lisp? That'd also be a neat prototype.
@akkartik No no, my original question was.. I was wondering if you had considered implement mu in mu itself, I'm curious to see if you're planning on writing mu from within mu itself, when you started working on a lisp a few days back it got me wondering what you needed metaprogramming for. But you answered that well saying it was just a fun direction to take this to.
@neauoire For now the only thing I'm planning for it is exploring the trace UI and how useful it seems. No metaprogramming for now. I'm not even sure of macros at the moment.
@clacke I hung out on the readable mailing list, so yes to sweet-exprs and wisp. I'm not sure about i-expressions. But yeah, I found all those to be a little too radical: https://news.ycombinator.com/item?id=8503353#8507385. Here's the original impetus for my infix: http://arclanguage.org/item?id=16699. Compare Wart: http://arclanguage.org/item?id=16776
The whitespace-sensitive infix sprung forth from my own forehead, but I've since learned that it was also in a language called merd (http://arclanguage.org/item?id=16724)
@neauoire @akkartik do you mean "assembly" languages for actual hardware? or bytecode? the answer for the former seems obvious to me: since an assembler is meant to reflect accurately and completely on the hardware capabilities, the creation of the "fun" is in the hardware, and perhaps in the choices in representing the hardware words/macros- And the way these become not fun is through backwards compatibility, and "natural" growth trying to satisfy shifting performance requirements...
@neauoire @akkartik Sure, though,, you do probably have to sacrifice *something* if that's the thing you want to optimise for.
Worth noting, is many ARM processors provide a region in their ISA kinda analogous to the "private use" area of unicode, where you can define your own opcodes, and, in a way, create your own, or really, customise, the arm assembler.
the Xerox Alto had a similar system, which was a lot of how they built up smalltalk: by iteratively defining custom opcodes they needed
@neauoire @akkartik In xerox and arm cases they're like.. kinda like interrupt handlers. Really kinda just⦠fancy jp instructions that need fewer bytes. So it might be a little disappointing, if you want to be fully custom- but this is basically how those "java" processors work, they're just ARM processors with some custom opcodes that emulate java vm bytecode.
@neauoire @akkartik The other day I watched a video of the ARM system architect, explaining the rationale for designing the ARM RISC processor. There isn't a lot of philosophical or practical difference between microcode and just plain instructions on a restricted set- so if you make the ISA *just* the microcode, and move "custom instructions" to the compiler, you can make a faster more efficient CPU.
In theory. In practice, code size does make a difference to performance on slow memory.
@neauoire @akkartik related:: a 6502 computer hardware design that uses a coprocessor to add 44 additional instructions
https://laughtonelectronics.com/Arcana/KimKlone/Kimklone_short_summary.html
@akkartik so cool.
@akkartik
it's all fun and games until your anonymous functions become a couple lines long ;)
although at least with lisp its trivial to print only e.g. one form deep to keep it short
@s_ol The hope is that anything with this visualization will be easier than without it. It admits skipping past the long forms to drill down to the critical places, which could be short.
Though pretty printing is also an option. It's fairly well-understood for Lisp (though not by me π)
@akkartik What part is confusing?
@vertigo A lot of it makes sense, and the comments are super useful. One question I had was about the definitions of more foundational words used in the initial fragment: 1f3 a! swap
Based on https://colorforth.github.io/forth.html, it looks like the stack is in eax and *esi, while the A register is in edx. a! stores 0x1f3 in edx. swap now seems to expand to these instructions:
mov EDX, EAX;
mov EAX, [ESI];
mov [ESI], EDX
This is a swap, but it also seems to clobber edx?
@akkartik you want help picking colours from that given palette? or you want to pick which 256 colours should make it up?
@zens Good question! I'd like to stick with this palette for now please. I'm trying to configure as little on the hardware as possible, to minimize how much I have to debug on real hardware down the road.
@akkartik Solarized color scheme is a subset of the xterm 256 color pallette. I'm a big solarized dark fan (except maybe the green)
@alcinnz @zachdecook Thank you for suggesting Solarized! I just pushed an approximation of it: https://github.com/akkartik/mu/commit/2b616894fd
Unfortunately the default 256-color palette BIOS provides isn't the same as xterm's. Perhaps I should investigate switching it. The default isn't great: https://merveilles.town/@akkartik/105546913433096365
In the meantime this is definitely an improvement.
There might be a better color combination of backgrounds on the left. I plan for functions to order independently like in Tiddlywiki.
@alcinnz @zachdecook I initially wanted to write a Mu function that would return the closest available color given an RGB triple, after computing HSL distances. For now I made a small change to http://akkartik.github.io/mu/html/vga_palette.html to edit the left column of squares in a browser's inspector to compare.
I found myself zooming way in to be able to tell subtle differences. So this is an ugly hack. The Mu function would be handy.
Drilling into computations on the Mu shell
This was one of the more difficult things I've built, and yet all I've gotten working so far is some rudimentary tokenization. The reason is one little feature.. well, take a look for yourself.
https://archive.org/details/akkartik-2min-2021-02-24 (video; 2 mins)
As always, built all the way up from machine code, and designed primarily to be easy to build, easy to run, comprehensible to others. Also this time with lots of tests
https://github.com/akkartik/mu