The tiny system, running in this page
IX · The machine · What to try · How it is in a page · The tiny programs · m-IX, the mini system
Each program of IX comes in two sizes. The tiny ones, t-IX, are the free variants: one file each, what is left of a program when compatibility is dropped and only its idea is kept. Among them are a machine of our own design, a kernel for it written in ML, a window system and a game. Below, they run: the machine is the OCaml program, compiled to JavaScript; everything on it is the tiny system's own code, compiled by its own compilers.
Boot another kernel: tiny-kernel (in ML; the screen, the windows) · t6 (in C, with a disk: a step before tiny-kernel). It has no screen: its console is the text.
Just type, wherever the mouse is: the line shows on the console, the text under the screen, at its blinking cursor, and Enter gives it to the shell. Once a program draws on the screen (the window system, a game), click the screen to type in it: a blue frame says the keys go there, one by one, to the window under the mouse. Click anywhere outside the screen to type on the console again.
ls — the programs and the files; echo hi | cat > f, cat f, wc < f, mkdir d: the shell has pipes and redirections.windows — the window system. In the screen, the right button gives a menu: New, then sweep a rectangle with the left button held, and a shell runs in it. Type ls there.tetris, typed in a window — the arrows move and turn the piece, the space drops it.calc, typed in a window — a calculator: the mouse on its buttons, or the keys (the digits, + - * /, the Enter). Hold a button and leave it before letting go: the press is taken back. temp: click in a field and type a temperature, the other field answers; the Escape quits.paint — a program that draws, on the screen or in a window; square, a game of a page.windows typed in a window — the window system in one of its own windows: a window looks to a program like the machine.And the network. The machine has a wire, drawn under the console, and this page is its other end: each dot that crosses is a packet, and each line under it says one.
ping — "are you there?", three times: a dot each way.get il.txt — a text of this site, fetched over the wire: a connection asked for, the request, the text in two packets, the end.wiki plan 9, or any words of yours — Wikipedia's article for them: its first sentences on the console, and its picture painted on the screen, a row at a time, as the packets arrive. Typed in a window of windows, the picture loads in the window.
What is honest to say: the machine does not speak to Wikipedia. It
speaks its own small protocol (IL, which
Plan 9
had instead of TCP) to the other end of its wire, and that end, this
page, asks Wikipedia as a page may, reduces the picture to the
screen's 256 colours and sends it as rows of bytes. Names, TLS, HTTP
and a picture's format are the browser's. The machine's part is the
wire, the envelope, the connection that loses nothing, and a program
that reads a row and draws it:
TinyKernelNetwork.ml,
which the page runs too, as the wire's other end.
A note on speed. The machine is paced, as a real one is: it runs a fixed number of instructions each second, so that a game plays the same on a fast computer and on a slow one. Compiled to JavaScript, it is not yet fast enough to keep that pace in most browsers. The line under the console says how close yours gets: at 60%, everything works, and tetris falls at 60% of its speed. Making the machine faster is the next thing to do. (A phone has no keys to type with.)
tiny-machine is 16 registers, one instruction format, two modes, one trap, a timer that counts instructions, pages, a console, a disk, a screen of 640 by 480 bytes and a mouse. It is three files of OCaml:
TinyMachineCPU.ml — the CPU: its instructions, its assembler, its interpreter;TinyMachineDevices.ml — what a kernel needs around it: the registers of control, the traps, the pages, the devices;TinyMachineWeb.ml — this page's part: the screen on a canvas, the keys, the mouse, a slice of instructions at each frame. In a terminal the same machine is TinyMachine.ml.
js_of_ocaml compiles
them to about 90 KB of JavaScript. The page fetches that and the
kernel's image, 1.9 MB for tiny-kernel with its programs: no server
runs anything. On the machine,
TinyKernel.ml,
TinyWindows.ml and
TinyAppTetris.ml
are ML compiled by tiny-ml, and its step t6 is C compiled by
tiny-c, both for this CPU.
From a checkout, ./tiny-machine -window tiny-kernel runs it
in a window of your own machine, and
./tiny-machine -web dir tiny-kernel makes this page's
files.
The others are in tiny/'s README, a line each with its faithful twin and the idea kept: a build system, a shell, an editor, an assembler, a C compiler, an ML compiler, a database, version control, an ARM CPU and a Raspberry Pi. t-IX's manual tells how they fit, and the code map shows them all.