Lines that are only run sometimes

if, else, end, and same.

IF TAKES A COMMAND, which is one rule rather than two and is why comparing
values needs no syntax of its own: "same" is an ordinary command that fails when
its two words differ, so "if same $a $b" falls out of the rule instead of being
an exception to it. Anything else that can fail is a question too - "if load
Snake.sbx" is a perfectly good one.

The shell already had the other half. LineFailed exists because a script stops at
the first line that did not work, so every command was already saying whether it
had, for a different reason entirely.

A BLOCK HAS TWO KINDS OF NOT-RUNNING. One where an else would turn it on, and
one where it would not - which is what an if pushes when something above it is
already being skipped. That is what makes nesting need no looking down the
stack: the top of it says everything.

A branch nobody is taking is not even looked at. The skipping happens BEFORE the
names are filled in, so a variable mentioned in a branch that is not running is
not an error - a line nobody runs must not be able to fail.

AND LINES MAY BE INDENTED, which they could not be before there was anything to
indent inside. Nobody writes an if inside an if without indenting what is in
them, and a leading space used to make the first word empty and match nothing.
Found by writing the test script the way anybody would write one.

CALL commandFailed became BRI commandFailed in nine places. It never returns - it
marks the line and branches to the prompt - so calling it was a lie that cost a
Stack frame each time, and fourteen other sites already branched. THE LINT RULE
FOUND THIS, three days after I wrote the rule and on my own code: two false
positives that were really the linter being right about a CALL that is not one.
It does not fix the leak on its own, since a failure inside any called routine
still abandons that frame, but it removes the cause of the commonest case and
makes the code true.

The mechanical edit then left a BRI prompt stranded behind one of them, and the
linter caught that too.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
Anachronaut
2026-09-01 20:33:33 -04:00
co-authored by Claude Opus 5
parent 4b109f704c
commit 16f8232a35
15 changed files with 523 additions and 15 deletions
+13
View File
@@ -425,6 +425,19 @@ cosmosVars | CosmOS/Source/cosmos.asm | run | cosmosVar
# Break is what makes it visible, because it prints the registers. The two dumps have to
# agree, and the failures between them are what would move it.
cosmosStack | CosmOS/Source/cosmos.asm | run | cosmosStack.in | - | disks/cosmos.img
# Lines that are only run sometimes. "if" takes a COMMAND and what follows runs only if that
# command worked - the Bourne shell's answer, and the reason "test" exists there: one rule in
# if, and comparing two things is just another command that can fail. Here that command is
# "same", and the shell already had the other half in LineFailed.
#
# AN if INSIDE A BRANCH NOBODY IS TAKING IS NOT A QUESTION. Its else must not run either, so
# it is pushed as a block that neither branch of can be taken - which is why a block has two
# kinds of not-running rather than one, and why nesting needs no looking down the stack.
#
# THE BRANCH NOBODY TAKES IS NOT EVEN LOOKED AT. The script names a variable that was never
# set, inside the branch that is not taken, and that must not be an error - so the skipping
# happens before the names are filled in, and a line nobody is running cannot fail.
cosmosBlocks | CosmOS/Source/cosmos.asm | run | cosmosBlocks.in | - | disks/cosmos.img
# The same editing offered to a PROGRAM, through osReadLine. Edit reads its lines that way,
# so a word typed with two letters the wrong way round is put right without starting the line
# again - which is the whole of what A4 buys.