subverge

Saving

An installed Subverge saves after every line that changes something, without being asked, so a reboot or a power cut loses at most the line that was running.

The live ISO doesn't save anything. To keep your work, install Subverge to a disk image first. On the live ISO home returns -1 and save fails with you haven't installed yet, run install.

When saving happens

On an installed disk, these are saved straight away:

save writes root, phi and all four tabs at once. It is rarely needed, since everything is already saved, but it is harmless.

home returns the number of the drive Subverge is installed on and saves to.

Slots

The saved state lives in five slots of 1 MiB at fixed positions on the drive: slot 0 holds root and slots 1 to 4 hold the four tabs. A sixth slot of 512 KiB holds phi. A small header in front of them records each slot's length and checksum and a counter of saves. See disk layout for the exact positions.

Saving a tab rewrites only that tab's slot and the header. The other slots aren't touched.

What's in a slot

A slot holds plain omega source. A tab is written as its definitions, oldest first, followed by its stack on one line:

# saved world
[ dup * ] :sq2
[ { a b } a a * b b * + ] :hyp
"notes" :title
1 2 3

Only the newest definition of each name is written, and names removed with forget are left out, so the saved text is as short as the world allows.

Root is written as each unit's source after its #>> name header line, in order, which is the same format as the root/ files in the source tree.

At boot, root's slot is built, then each tab's slot is run as if it had been typed at that tab's prompt. A world that was saved is therefore always one that omega can read back.

Values that survive

A value survives only if it can be written as source and read back. These can:

Two things change on the way. Identity is lost: two definitions that held the very same quote hold two equal quotes after a reboot (values and objects). And memory from alloc isn't saved, so an address kept on the stack points at whatever the heap holds there after the reboot.

Not saved

After a reboot every tab starts with an empty history, its saved stack and definitions, and the title omega.

Size

Each slot holds at most 1 MiB of source, minus a little room the kernel keeps free. A tab or root that grows past that isn't saved, and the previous save of that slot stays on the disk. Nothing is printed when this happens, so keep an eye on tabs that hold very large lists or many long strings. 'name src len . prints the size in bytes of the root unit that defines name.

Damaged slots

Each slot is checked against its checksum when it is loaded. A slot that doesn't match is treated as empty: a damaged tab boots fresh, and a damaged root is replaced by the root built into the kernel.

A slot can also be intact and still fail to run, which can happen after upgrading to a kernel that removed or renamed a word. A tab whose saved world fails prints the error and starts empty. A saved root that fails to build is replaced by the built-in one, with the message the saved root didn't build, using the built-in one.

Starting over

To reset one tab, remove its definitions with forget and clear its stack with empty.

install writes the running system's current root and tabs, so installing again from an installed system copies its state. To start completely fresh, boot the live ISO with only a new blank disk image attached and install onto that.