← Back

The machine demo, first cut: a batch run in the browser

The Roc machine runs Codex programs on the ladder, on the command line, and now in the browser. This note is the plan for that first page, and where it stands.

Where it stands

The page is built: http://143.244.172.148:9203/machine/batch/.

One Roc compiler bug had to be worked around. The WebAssembly build fails to link when a function copies a record holding nested records with lists in several branches. The machine's command-line parser did exactly that. The parser now carries the network card and the timer beside its record, and a standalone program that shows the bug is kept in roc-apps/findings/wasm-reloc-order/.

What the page shows

You pick a program, press Run, and see what it did to the machine:

Each run fills three panes:

"Batch" means the program runs from start to finish in one go, as it does on the ladder. Nothing waits for a key. An interactive machine is a later step.

How Codex's pieces map to it

Cobblestone is an operating system written in Codex. Its bottom layer (boot, interrupts, the scheduler) is x86 code that Codex's compiler generates, so it is not Codex we can turn into Roc. The Roc machine stands in for that layer: it starts in the state x86's boot leaves behind, and its doors do what the kernel's helper routines do. Everything above it is ordinary Codex that rocemit turns into Roc: the FAT16 and FAT32 file system code, the network card driver and DHCP, the drawing code.

The pieces to build

  1. A browser platform for emitted programs. Today's browser platform only takes the hand-written app. The native platform (machine/native) already runs emitted programs: it gives them a console and answers the disk from files. The browser one has the same shape, answered by the page instead: the console goes to a buffer the page reads, and the disk is a buffer the page loaded the image into.
  2. A tap on the wire. The network card and the network behind it are Roc code inside the machine, so the page cannot see the frames. A small module with one door, "a frame went by", is called where the card transmits and where an answer arrives. On the ladder it does nothing; in the browser it hands the frame to the page. It is the same seam as the disk's.
  3. The page. A program picker, Run, and the three panes.
  4. The build. Each featured program is emitted, wired to the browser platform the way machine/native/run.sh wires it to the native one, and built with roc build --target=wasm32 --opt=dev while we iterate (an LLVM build is for the finished page). It lands in the preview root, ~/build/roc-apps/next/machine/, served on :9203.

Risks, checked first

Later