diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-12-11 07:21:04 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-12-11 07:21:04 -0800 |
commit | 17f11d14178db6e8367ba598bc2e4a1f0fae4d59 (patch) | |
tree | a6d7ec8ffea761859ade6bdb447fc3ee29cbd4ed /tests/019 | |
parent | 2b896e09bdf71fb94e40a105b681c26938daa961 (diff) | |
download | txr-17f11d14178db6e8367ba598bc2e4a1f0fae4d59.tar.gz txr-17f11d14178db6e8367ba598bc2e4a1f0fae4d59.tar.bz2 txr-17f11d14178db6e8367ba598bc2e4a1f0fae4d59.zip |
load: load block value should be exit status.
When TXR executes a top-level program, such that it will
exit when the last form in that program terminates,
it simulates a load. There is a block named load visible,
and the program can evaluate a (return-from load <expr>).
The value of that <expr> is thrown away, and the
termination status is always unsuccessful.
In this patch, (return-from load <expr>) is made to work
such that the value of <expr> will determine the exit
status, according to the same interpretation that
(exit <expr>) would give to the value.
* sysif.[ch] (exit_wrap): Static function becomes external.
* txr.c (txr_main): In the cases where we execute a file
and return from main, we now call exit_wrap instead.
The termination status is not simply based on whether
the file was successfully read, but takes into account the
load block.
* tests/019/load-ret/{script.tl,bad.tl}: New files.
* tests/019/load-ret/load-ret.tl: New tests.
* txr.1: Documented.
Diffstat (limited to 'tests/019')
-rw-r--r-- | tests/019/load-ret.tl | 10 | ||||
-rw-r--r-- | tests/019/load-ret/bad.tl | 1 | ||||
-rw-r--r-- | tests/019/load-ret/script.tl | 1 |
3 files changed, 12 insertions, 0 deletions
diff --git a/tests/019/load-ret.tl b/tests/019/load-ret.tl index a79f7da9..1c99281f 100644 --- a/tests/019/load-ret.tl +++ b/tests/019/load-ret.tl @@ -11,3 +11,13 @@ (load-for (var abc "load-ret/module2" 'abc)) nil (load-for (var abc "load-ret/module2" 'abc) (var ghi "load-ret/module2" 'ghi 2 3 4)) 9) + +(defvarl here (dir-name self-path)) + +(mtest + (sh `@{txr-exe-path} @here/load-ret/script.tl 0`) 0 + (sh `@{txr-exe-path} @here/load-ret/script.tl 1`) 1 + (sh `@{txr-exe-path} @here/load-ret/script.tl 7`) 7) + +(test + (sh `@{txr-exe-path} @here/load-ret/bad.tl 1 2> /dev/null`) 1) diff --git a/tests/019/load-ret/bad.tl b/tests/019/load-ret/bad.tl new file mode 100644 index 00000000..2d06f376 --- /dev/null +++ b/tests/019/load-ret/bad.tl @@ -0,0 +1 @@ +( diff --git a/tests/019/load-ret/script.tl b/tests/019/load-ret/script.tl new file mode 100644 index 00000000..8e13dabf --- /dev/null +++ b/tests/019/load-ret/script.tl @@ -0,0 +1 @@ +(return-from load (toint [*args* 0])) |