Lesson 10 — A first look downstairs
On this page, floor blocks run on a simulated desk — the floor contract kept by a small simulation in the browser, carrying out the instructions the language's own books use. A block reaching past the desk is refused in plain words naming the limit. On real metal the same blocks run on the processor itself, exactly as the lesson teaches.
Step 1: why there is a downstairs
Everything you have written so far lives on the friendly side of the language: values are managed, every access is checked, loops and calls are guarded. That is deliberate — Nifla's stated bar is memory safety in the way Swift is memory-safe, and the friendly side keeps it.
But some programs must touch the machine itself: an operating system has no operating system beneath it. For them, the language keeps a floor — a deliberate, marked door out of the safety. A floor block holds raw processor instructions (x86-64, written the Intel way), which the compiler lays into the program untouched and unchecked. Inside a floor block you can touch any memory the program may touch — including memory that isn't yours, which is exactly why the floor is a door and not the house. Floor code runs only in compiled programs: the interpreter refuses any program that holds floor code, before anything runs, in plain words.
A floor block is handed a desk, and hands answers back on it. The numbers it is handed wait in an array pointed to by the register r10 — the first at [r10], the second at [r10 + 8] — and r11 says how many there are. The block's main answer is left in rax:
The book says it answers:
42
Read it as: take the first handed number (41), add 1, leave the answer in rax — and the floor block, as a whole, is that answer, kept here on the shelf plus.
Your turn. Write a floor block that takes the first handed number and doubles it: hand it 21 and say the answer.
The worked answer — try yours first, then peek
The book says it answers:
42
Step 2: two answers at once
Extra answers may be written into a results area at r13, with r14 saying how many — and then the block gives back a list of them all. Division is the classic case: a quotient and a remainder:
The book says it answers:
[14, 2] 16
The desk's meaning — handed numbers, one text or bytes, a main answer and extra answers — is the contract on every machine the language targets; the register letters are each target's own. The Primer's Part 4 keeps the whole desk, and Part 5 names the second target's letters.
Step 3: bare metal, briefly and honestly
Below the floor is the basement itself: bare metal. niflac --bare compiles a program into a binary that boots on its own — no operating system, no runtime. The bare subset is sterner than the hosted language, and the compiler refuses whatever it cannot honestly hold, in plain words: whole numbers only, no lists and no objects, no nothing and no maybe — every value there is a machine word with one shape. In exchange, a bare program gets the machine's own furniture: the tick count, the keyboard, the memory map, the disk — and say writes to the machine's text screen. This is a look, not a lesson; the Primer's Part 5 and the README teach it properly. One taste, compiled by this book's proof and run when the language's bare suites boot its kind:
let t = ticks()
waittick()
if ticks() > t {
say "Time passed"
}
Bare metal: this program runs on a real machine, not in a web page, so there is no Run button here.
Cardnull OS 2 is built down there — a whole operating system standing on the bare subset, its feathers visiting through Lesson 9's door. You have now seen every floor of the house you have been learning in.
That deserves a pause. The operating system is not written in some bigger language that Nifla imitates. It is written in Nifla — the language of your first lesson, of say and let and make. The subset down here is sterner because the ground is bare, but the words are the same words, all the way from hello world to the booting of a machine.
Your turn
A floor block that takes two numbers and gives back the first minus the second. Hand it 50 and 8; the answer should be 42.
The worked answer — try yours first, then peek
The book says it answers:
42
You can now…
- say what the floor is: a marked door out of the
language's safety, holding raw processor instructions, compiled programs only;
- read a floor block's desk: handed numbers at
r10,
the count at r11, the main answer in rax, extra answers at r13/r14;
- say what bare metal is — a program that boots with
nothing beneath it — and why its subset is sterner.
---