Make a host
A host runs Terse32 programs: it reads a program file, runs its instructions at a fixed speed and gives the program its devices. You can write one in any language and prove it exact against the reference. This guide does it in four steps, twice, once in Go and once in Rust:
1. Run a program to its end: the program file, memory, the processor and exit. 2. Frames and the budget: 125,000 units a frame, wait_frame and the carry rule. 3. A driver shows hello: the terminal as a separate program on the device bus. 4. Prove it exact: the state hash, equal to the reference's.
Each step is a small working program in the Tersenet sources, built and checked against the reference by the sources' tests.
Two tracks
- In Go, in
examples/host/go: Make a host in Go, step 1: run a program to its end. - In Rust, in
examples/host/rust: Make a host in Rust, step 1: run a program to its end.
The two have the same design, so either explains the other. Each is a package that gains a file per step (the processor, then frames, the bus, the state) with a short program per step on top, step1 to step4. The pages list every file in full or its important part, exactly as it is in the sources. Lines of code below are counted with blank lines.
Libraries, and why the processor is written out
The examples use their language's standard library and one package more: BLAKE3, which names a program by its hash from step 3 on (lukechampine.com/blake3 in Go, the blake3 crate in Rust). They use no RISC-V emulator package. Those emulate whole computers and hide what a Terse32 host must get exactly right: what each instruction costs, whether it was fetched from ROM or RAM, where the machine pauses when its budget runs out, and which encodings must fault. The processor is about 390 lines in either language, and it is most of the work.
What the examples leave out
They run programs/hello exactly, prove it, and stop there: no input events, four of the ten System calls, one driver (the terminal), no snapshots. Step 4 says what the rest is. The full implementations:
native/core-c:tcore, an independent core in C, about 1,580 lines, which passes the conformance program with the reference drivers;crates/terse-core: the reference machine in Rust, whichterse runandterse-hostuse;crates/terse-bus, the reference core on the device bus.
The specification is The Terse32 machine and the pages after it.