Saving, restoring, restarting and verifying the program from within itself.


§1. Environment. The language "interpreter" here supposes that the eventual program is running in a VM which is being interpreted, and that may not be the case, but it's traditional.

[ VM_ReportOnInterpreter;
    if (standard_interpreter > 0) {
        print "Standard interpreter ",
            standard_interpreter/256, ".", standard_interpreter%256,
            " (", HDR_TERPNUMBER->0;
        print (char) HDR_TERPVERSION->0;
        print ")^";
    } else {
        print "Interpreter ", HDR_TERPNUMBER->0, " Version ";
        print (char) HDR_TERPVERSION->0;
        print "^";
    }
];

§2. Verification. This verifies that the current story file is intact.

[ VM_Verify;
    @verify ?Vmaybe;
    rfalse;
    .Vmaybe; rtrue;
];

§3. Save, restore, restart. Restart does what it says: restarts the program as if it had just loaded for the first time.

VM_Save() attempts to save the current state of the program to a file, and returns 0 if this fails, 1 if this succeeds, or 2 if in fact a restore has just succeeded. (A successful restoration should resume execution where the save succeeded, but we want to distinguish those cases.)

VM_Restore() pretends to return true or false according to whether or not it succeeds, but in fact it can only return false to indicate failure, because a successful restoration means that execution has transferred to VM_Save instead.

[ VM_Restart;
    @restart;
];

[ VM_Restore;
    restore RMaybe; rfalse;
    .RMaybe; rtrue;
];

[ VM_Save flag;
    @save -> flag;
    return flag;
];

§4. Undo. These also simply wrap the relevant opcodes.

[ VM_Undo result_code;
    @restore_undo result_code;
    return result_code;
];

[ VM_Save_Undo result_code;
    @save_undo result_code;
    return result_code;
];