From 17f11d14178db6e8367ba598bc2e4a1f0fae4d59 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 11 Dec 2023 07:21:04 -0800 Subject: 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 ). The value of that is thrown away, and the termination status is always unsuccessful. In this patch, (return-from load ) is made to work such that the value of will determine the exit status, according to the same interpretation that (exit ) 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. --- tests/019/load-ret.tl | 10 ++++++++++ tests/019/load-ret/bad.tl | 1 + tests/019/load-ret/script.tl | 1 + 3 files changed, 12 insertions(+) create mode 100644 tests/019/load-ret/bad.tl create mode 100644 tests/019/load-ret/script.tl (limited to 'tests') 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])) -- cgit v1.2.3