Skip to content

Commit abb83a2

Browse files
committed
Replace EXIT with END
The way to terminate a program in traditional BASIC is via the END keyword, not a special EXIT command. Make it so now. This is particularly tricky because we need to discern between bare END calls and END IF statements in the parser, which means we have to redo how IF statements are parsed altogether.
1 parent dcef7a6 commit abb83a2

23 files changed

Lines changed: 328 additions & 285 deletions

.github/workflows/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set -eux
2020
# and ensure that the resulting binary is minimally functional.
2121
rm -f "${HOME}/.cargo/bin/endbasic"
2222
cargo install --path cli "${@}"
23-
ret=0; echo "EXIT 123" | "${HOME}/.cargo/bin/endbasic" || ret="$?"
23+
ret=0; echo "END 123" | "${HOME}/.cargo/bin/endbasic" || ret="$?"
2424
if [ "${ret}" -ne 123 ]; then
2525
echo "Installed endbasic binary doesn't seem to work" 1>&2
2626
exit 1

.github/workflows/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ sanity_check() {
2727
local bin="${1}"; shift
2828

2929
local ret=0
30-
echo "EXIT 123" | "${bin}" || ret="${?}"
30+
echo "END 123" | "${bin}" || ret="${?}"
3131
[ "${ret}" -eq 123 ] || err "Packaged endbasic doesn't seem to work"
3232
}
3333

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ for the time being.**
9999
`PI`, so that they do not accept `()`. This matches traditional BASIC
100100
implementations.
101101

102+
* Replaced the `EXIT` command with the `END` keyword.
103+
102104
## Changes in version 0.9.0
103105

104106
**Released on 2022-06-05.**

cli/tests/repl/exit-nonzero.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515

1616
' Exits with an error code.
1717

18-
EXIT 78: PRINT "Should not be executed"
18+
END 78: PRINT "Should not be executed"
1919
PRINT "Should not be executed either"

cli/tests/repl/exit-saved.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ EDIT ' Insert stored program until an escape character.
2323
PRINT "Still here!"
2424

2525

26-
EXIT ' Asks for confirmation before exiting.
26+
END ' Asks for confirmation before exiting.
2727
no
2828
RUN
2929

30-
EXIT 123 ' Asks for confirmation before exiting.
30+
END 123 ' Asks for confirmation before exiting.
3131
no
3232
RUN
3333

3434
SAVE "test.bas"
3535

36-
EXIT ' Doesn't ask for confirmation any more.
36+
END ' Doesn't ask for confirmation any more.
3737
PRINT "Should not be reached"

cli/tests/repl/exit-unsaved.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ EDIT ' Insert stored program until an escape character.
2323
PRINT "Still here!"
2424

2525

26-
EXIT ' Asks for confirmation before exiting.
26+
END ' Asks for confirmation before exiting.
2727
no
2828
RUN
2929

30-
EXIT 123 ' Asks for confirmation before exiting.
30+
END 123 ' Asks for confirmation before exiting.
3131
no
3232
RUN
3333

34-
EXIT ' Asks for confirmation before exiting.
34+
END ' Asks for confirmation before exiting.
3535
yes
3636
PRINT "Should not be reached"

cli/tests/repl/exit-zero.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515

1616
' Exits cleanly.
1717

18-
EXIT 0: PRINT "Should not be executed"
18+
END 0: PRINT "Should not be executed"
1919
PRINT "Should not be executed either"

cli/tests/repl/help.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ HELP "DIR"
8888
PRINT "Output from HELP \"EDIT\":"
8989
HELP "EDIT"
9090

91-
PRINT "Output from HELP \"EXIT\":"
92-
HELP "EXIT"
93-
9491
PRINT "Output from HELP \"GFX_LINE\":"
9592
HELP "GFX_LINE"
9693

cli/tests/repl/help.out

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Output from HELP:
2929
Type HELP followed by the name of a topic for details.
3030
Type HELP "HELP" for details on how to specify topic names.
3131
Type LOAD "DEMOS:/TOUR.BAS": RUN for a guided tour.
32+
Type END or press CTRL+D to exit.
3233

3334
Output from HELP "ARRAY":
3435

@@ -196,7 +197,6 @@ Output from HELP "INTERPRETER":
196197
Interpreter
197198

198199
>> CLEAR Restores initial machine state but keeps the stored program.
199-
>> EXIT Exits the interpreter.
200200
>> HELP Prints interactive help.
201201
>> SLEEP Suspends program execution.
202202

@@ -237,6 +237,7 @@ Output from HELP "LANG":
237237

238238
Misc:
239239
st1: st2 Separates statements (same as a newline).
240+
END [code%] Terminates the program.
240241
REM text Comment until end of line.
241242
' text Comment until end of line.
242243
, Long separator for arguments to builtin call.
@@ -370,14 +371,6 @@ Output from HELP "EDIT":
370371

371372
Interactively edits the stored program.
372373

373-
Output from HELP "EXIT":
374-
375-
EXIT [code%]
376-
377-
Exits the interpreter.
378-
379-
The optional code indicates the return value to return to the system.
380-
381374
Output from HELP "GFX_LINE":
382375

383376
GFX_LINE x1%, y1%, x2%, y2%

core/examples/config.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ fn main() {
3636

3737
// Execute the sample script. All this script can do is modify the state of the machine itself.
3838
// In other words: the script can set variables in the machine's environment, but that's it.
39-
let result = block_on(machine.exec(&mut INPUT.as_bytes())).expect("Execution error");
40-
assert!(result == StopReason::Eof, "We did not register an EXIT command");
39+
loop {
40+
match block_on(machine.exec(&mut INPUT.as_bytes())).expect("Execution error") {
41+
StopReason::Eof => break,
42+
StopReason::Exited(i) => println!("Script explicitly exited with code {}", i),
43+
StopReason::Break => (), // Ignore signals.
44+
}
45+
}
4146

4247
// Now that our script has run, inspect the variables it set on the machine.
4348
match machine.get_var_as_int("foo_value") {

0 commit comments

Comments
 (0)