summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-07-21 20:15:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-07-21 20:15:52 -0700
commit5ff4246327fd802923faa77a3421d2384d643735 (patch)
treedf48d8818e7a91532b96a401036d30acc9cd4f58 /stdlib
parentd4d20af163a97f2af069b2c12c1672b08835d1c2 (diff)
downloadtxr-5ff4246327fd802923faa77a3421d2384d643735.tar.gz
txr-5ff4246327fd802923faa77a3421d2384d643735.tar.bz2
txr-5ff4246327fd802923faa77a3421d2384d643735.zip
compile-file: distinguish nonexistence errors.
The compile-file function must only try a different path, such as with a suffix, if a given path fails to open due to non-existence. If the failure is for another reason, like permissions. In that case we want to propagate the failure. * stdlib/compiler.tl (ign-notfound): New macro. This lets through all errors, catching only path-not-found, converting that to a nil result. (open-compile-streams): Use ign-notfound instead of ignerr when trying to open an input file for reading. Also, we lose the ignerr wrapping around the open-file. We let any error whatsoever just bubble out so that the user is better informed about what went wrong. The requirement to close the input stream is handled by the obvious unwind-protect.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/compiler.tl18
1 files changed, 10 insertions, 8 deletions
diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl
index b82f85a2..bea78e33 100644
--- a/stdlib/compiler.tl
+++ b/stdlib/compiler.tl
@@ -2240,6 +2240,9 @@
intern unintern rehome-sym
use-sym unuse-sym))
+(defmacro ign-notfound (form)
+ ^(usr:catch ,form (path-not-found (. rest))))
+
(defun open-compile-streams (in-path out-path test-fn)
(if (and (nullify in-path)
(find [in-path -1] path-sep-chars))
@@ -2253,10 +2256,10 @@
in-stream out-stream)
(casequal suff
(".txr" (error "~s: cannot compile TXR files" 'compile-file))
- (".tl" (set in-stream (ignerr (open-file in-path))
+ (".tl" (set in-stream (ign-notfound (open-file in-path))
out-path (or out-path `@{ip-nosuff}.tlo`)))
- (t (set in-stream (or (ignerr (open-file in-path))
- (ignerr (open-file `@{in-path}.tl`)))
+ (t (set in-stream (or (ign-notfound (open-file in-path))
+ (ign-notfound (open-file `@{in-path}.tl`)))
out-path (or out-path `@{in-path}.tlo`))))
(unless in-stream
@@ -2266,11 +2269,10 @@
(close-stream in-stream)
(return-from open-compile-streams nil))
- (set out-stream (ignerr (open-file out-path "w")))
-
- (unless out-stream
- (close-stream in-stream)
- (error "~s: unable to open output file ~s" 'compile-file out-path))
+ (unwind-protect
+ (set out-stream (open-file out-path "w"))
+ (unless out-stream
+ (close-stream in-stream)))
(list in-stream out-stream out-path)))