Have the shell remember whether a line worked

Groundwork for scripts, and invisible until there is something to read it:
the suite passes unchanged, which is the point of doing it on its own.

A script has to decide whether to run the next line, and nothing in the
shell knew whether the last one worked. LineFailed is cleared as each line
is read and set by the fourteen paths that fail.

Cleared at the start rather than set at the end, because there are thirty
seven ways back to the prompt and only fourteen are failures - and the
twenty three successes would have to be found again every time a command
grew a new way to finish. A command that says nothing worked. Twelve of the
fourteen already funnelled through fileComplain, so this is fourteen lines
rather than the refactor it looked like.

It is deliberately NOT LastStatus, which was the obvious place and is
wrong. That one is a program's own answer, reported by the status command
and recorded by two tests; clearing it as each line began wiped the answer
before the command that reports it could read its own line. The tests said
so immediately. Two questions, two bytes - and a program exiting non-zero
now sets both, because a program answering "no" is one of the ways a line
can fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
Anachronaut
2026-08-30 15:38:02 -04:00
co-authored by Claude Opus 5
parent e52d8d84f8
commit fc56e815fc
+60 -14
View File
@@ -168,6 +168,20 @@ promptSay:
LDA.0
BNA quitRanOut
; ---- How this line went, assumed good until something says otherwise ----
;
; Cleared here rather than set at the end of each command, and that is what makes this
; affordable. There are thirty seven ways back to this prompt and only fourteen of them
; are failures, so marking the failures costs fourteen lines and marking the successes
; would cost twenty three - and the twenty three would have to be found again every time
; a command grew a new way to finish. A command that says nothing worked.
;
; A PROGRAM SETS THIS ITSELF, from handleExit, and it runs after this point - so what a
; program made of its work is what stands, not the zero written here before it started.
SETD.1 LineFailed
RSTA
STA.1
SETD.0 CommandLine
CALL textSplit
@@ -268,6 +282,17 @@ promptSay:
CALL textSame
BRQ doAssemble
; ---- A command that did not work ----
;
; The one place a failure is recorded, so that the thing reading lines out of a file can
; tell whether to go on. It says nothing: whatever sent us here has already said what was
; wrong in words, and a number after that is noise. See LastStatus.
commandFailed:
INIA 0x01
SETD.1 LineFailed
STA.1
BRI prompt
promptUnknown:
; Nothing built in matched, so the disk is asked before anybody is told they are wrong. A
; word this shell does not know is very often the name of a program sitting right there,
@@ -337,7 +362,7 @@ promptSayUnknown:
SETD.0 CommandLine
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; Running out of console leaves the cursor part way along a line, because there was no
; return at the end to move it on. Somebody who typed "exit" has already pressed one, and
@@ -544,7 +569,7 @@ dirNoDisk:
SETD.0 NoDisk
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; DP0 names a string. Q is how many spaces pad it out to twenty four columns. A name
; already that long gets one space, so that it cannot run into the number after it.
@@ -724,13 +749,13 @@ loadFailed:
LDD.0.1
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
loadNothingNamed:
SETD.0 LoadWhat
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; ---- loadProgram ----
;
@@ -1504,7 +1529,7 @@ fileNoDisk:
fileComplain:
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; ---- run ----
;
@@ -1552,7 +1577,7 @@ runNothing:
SETD.0 NothingLoaded
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; DP0 is a string, DP1 is where it should go, and B is how much room there is counting
; the zero on the end. What does not fit is left behind, and what is written is a string
@@ -2264,6 +2289,12 @@ handlePrintNumber:
; that failed has already said so in words, and a number beside that would be noise. It is
; here for the thing that cannot read words - whatever comes to run programs in sequence and
; has to decide whether to run the next one.
;
; IT IS NOT LineFailed, and the difference is worth keeping. This one is a PROGRAM'S answer
; and belongs to whoever asks for it, which the shell's own status command does and a test
; records. Zeroing it as each line began - which is what the script reader wanted - wiped
; the answer before the command that reports it could read its own line. Two questions, two
; bytes.
handleLastStatus:
SETD.2 LastStatus
LDA.2
@@ -2333,6 +2364,15 @@ handleExit:
SETD.1 LastStatus
STA.1
; And the line that started it failed, if the program says it did. The script reader asks
; one question - did this line work - and a program answering "no" is one of the ways it
; can be answered.
BRA exitWorked
INIA 0x01
SETD.1 LineFailed
STA.1
exitWorked:
SETD.1 SystemStack
LDD.0.1
MVDS.0
@@ -2445,13 +2485,13 @@ bankNotThere:
SETD.0 NoSuchBank
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
bankWhat:
SETD.0 BankUsage
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; x [address] - sixty four bytes. d [address] - eight instructions. Without an address
; either carries on from where the last one stopped, so reading through memory is one
@@ -2603,12 +2643,12 @@ dumpBadWhere:
SETD.0 ExamineUsage
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
dumpNoBank:
SETD.0 NoSuchBank
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; s <address> <byte> <byte> ...
;
@@ -2663,13 +2703,13 @@ setReadOnly:
SETD.0 ReadOnlyText
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
setWhat:
SETD.0 SetUsage
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; g <address>
;
@@ -2699,7 +2739,7 @@ goWhat:
SETD.0 GoUsage
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; DP0 names text that textHexWord has just read a number off the front of. LEAVES DP3 past
; the digits and any spaces after them, ready for the next one.
@@ -3079,7 +3119,7 @@ assembleWhat:
SETD.0 AsmUsage
CALL printString
CALL newLine
BRI prompt
BRI commandFailed
; The mnemonic is in CommandLine's place - AsmLine - and TextRest is what followed it.
; Puts the bytes down and steps the cursor past them.
@@ -3463,6 +3503,12 @@ Banner:
PromptText:
"> "
; Nothing has run yet, so nothing has failed yet.
; Whether the line the shell is on failed. Read by the script reader and by nothing else,
; which is why it is a plain flag and not a number: a script wants to know whether to go on,
; not what went wrong, and what went wrong has already been said in words.
LineFailed:
0x00
LastStatus:
0x00