A script is given words, and keeps them
"do build.sh cosmos.asm" looked for a file called "build.sh cosmos.asm", because scriptOpen copied the whole rest of the line into the name. So a script could be told nothing, and a launcher - a script whose entire job is to hand on what it was told - could not exist. Now the name is cut off the front and what follows is kept whole. $1 to $9 are the words of it, walked out on demand, and $args is all of them. Nothing is stored per parameter, so there is no limit on how many a script may be handed and no second number to keep in step. Both ways of starting a script pass them on: "do" and typing the name. A word that was not given is an error that stops the script, like every other name this shell does not know. Expanding it to nothing would let a command run with an argument missing and then report success, which is what stop-on-failure exists to prevent. $args is always set inside a script, empty if it was given nothing, so "if same $args" can be asked. ---- And the count that describes the block was already wrong ---- Found while adding a field to it. The state one script keeps for another is saved by a single copy of a fixed number of bytes, and that number was 71 against a block of 77: six bytes of line position had been added in the middle of it years after the count was written. So the tail of every saved script was never saved, and #quiet in a helper stayed behind in the script that called it - the opposite of what this file's own comment promises and the README documents. The unsaved line position turned out not to matter, because a loop keeps its own copy in the block record. Nothing said so. Three numbers describe this block and all three now say so in a comment, and cosmosScriptNest ends on a helper that goes quiet and a caller that must not stay that way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
co-authored by
Claude Opus 5
parent
06af7e7fbb
commit
d9ebc76cf5
@@ -296,6 +296,33 @@ printf '#! script\necho inner one\necho inner two\n' > inner.script
|
||||
# A script that runs itself, which is what the depth limit is for.
|
||||
printf '#! script\necho self\ndo loop.script\n' > loop.script
|
||||
"$TOOL" put "$DISKS/cosmos.img" loop.script >/dev/null
|
||||
# ---- And what a nested script gives back ----
|
||||
#
|
||||
# hush.script goes quiet and heard.script must not stay that way. The state one script keeps
|
||||
# for another is saved by a single copy of a fixed number of bytes, and that number was six
|
||||
# short of the block it was copying - so the last fields of it, quiet among them, were never
|
||||
# saved at all. Nothing said so: the echo simply stopped, in the caller, after the helper
|
||||
# returned. The check is that "echo aloud again" is ECHOED and not merely obeyed.
|
||||
#
|
||||
# MIND WHAT A NEW NAME HERE BEGINS WITH. Tab is checked against this disk, and a second file
|
||||
# sharing a prefix with one of the words those tests type turns a unique completion into a
|
||||
# list. "heard.script" was the first draft and it shadowed hello.sbx.
|
||||
printf '#! script\n#quiet\necho the helper is quiet\n' > hush.script
|
||||
"$TOOL" put "$DISKS/cosmos.img" hush.script >/dev/null
|
||||
printf '#! script\necho aloud first\ndo hush.script\necho aloud again\n' > aloud.script
|
||||
"$TOOL" put "$DISKS/cosmos.img" aloud.script >/dev/null
|
||||
|
||||
# ---- What a script is given ----
|
||||
#
|
||||
# args.script says what reached it; pass.script is the shape a launcher has, handing on what
|
||||
# it was told without knowing what any of it means; holds.script gives a helper different
|
||||
# words and must still have its own afterwards.
|
||||
printf '#! script\necho one is $1\necho two is $2\necho all of it is $args\n' > args.script
|
||||
"$TOOL" put "$DISKS/cosmos.img" args.script >/dev/null
|
||||
printf '#! script\nSay $args\n' > pass.script
|
||||
"$TOOL" put "$DISKS/cosmos.img" pass.script >/dev/null
|
||||
printf '#! script\necho outer has $1\ndo args.script deep down\necho outer still has $1 and $args\n' > holds.script
|
||||
"$TOOL" put "$DISKS/cosmos.img" holds.script >/dev/null
|
||||
|
||||
# ---- A disk that starts itself ----
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user