Saving
- When saving happens
- Slots
- What's in a slot
- Values that survive
- Not saved
- Size
- Damaged slots
- Starting over
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:
- A line that changed a tab's world. Only that tab's slot is written. A line that leaves the stack and definitions as they were, such as
wordsor"hi" say, writes nothing. - A
back, since it changes the world back. - A root edit that builds. The whole of root is written to its slot. An edit that fails to build writes nothing (root).
- A change to phi. The whole of phi is written to its slot.
- A theme or logo change, which rewrites only the header sector (themes, logos).
install, which writes root, all four tabs, phi, the current theme and the current logo to the new drive.
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:
- integers and bignums;
- strings, with escapes for newlines, tabs, escape characters and the omega and aleph glyphs;
- quotes and lists, nested to any depth;
- symbols (
'name); - ordinals, written back as arithmetic such as
omega 2 ^ omega +; - cardinals, written as
0 alephor2 0 aleph ^.
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
- the back history and the prompt history;
- tab titles and screen contents;
- memory from
alloc, and anything written withpokeorout; - the JIT's compiled code, which is rebuilt as code runs.
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.
subverge