summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-07-21 08:13:18 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-07-21 08:13:18 -0700
commitd4d20af163a97f2af069b2c12c1672b08835d1c2 (patch)
treed0184cc16eee041d1cea665ab522b7422de3dfca
parent9f87e50086eb4a240e8c879484db0b216897ef03 (diff)
downloadtxr-d4d20af163a97f2af069b2c12c1672b08835d1c2.tar.gz
txr-d4d20af163a97f2af069b2c12c1672b08835d1c2.tar.bz2
txr-d4d20af163a97f2af069b2c12c1672b08835d1c2.zip
compile-file: revise hash bang treatment.
* stdlib/compiler.tl (translate-hash-bang): New function. (compile-file-conditionally): Use translate-hash-bang to treat hash bang line. * txr.1: Revised hash bang treatment by file compiler documented.
-rw-r--r--stdlib/compiler.tl16
-rw-r--r--txr.118
2 files changed, 27 insertions, 7 deletions
diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl
index c7ac6009..b82f85a2 100644
--- a/stdlib/compiler.tl
+++ b/stdlib/compiler.tl
@@ -2316,6 +2316,14 @@
(if (eql sti.gid sto.gid) sgid)))))
(chmod out-stream mode)))))
+(defun translate-hash-bang (hbline)
+ (flow hbline
+ (spl " ")
+ (subst "--lisp" "--compiled")
+ (mapcar [iffi (op ends-with "txrlisp")
+ (opip (trim-right "lisp") (join @1 "vm"))])
+ (ap join-with " ")))
+
(defun compile-file-conditionally (in-path out-path test-fn)
(whenlet ((success nil)
(perms nil)
@@ -2338,11 +2346,9 @@
(with-compilation-unit
(iflet ((line (get-line in-stream))
((starts-with "#!" line)))
- (progn
- (set line `@line `)
- (upd line (regsub #/--lisp[^\-]/ (ret `--compiled@[@1 -1]`)))
- (put-line (butlast line) out-stream)
- (set perms t))
+ (let ((cline (translate-hash-bang line)))
+ (set perms t)
+ (put-line cline out-stream))
(seek-stream in-stream 0 :from-start))
(labels ((compile-form (unex-form)
(let* ((form (macroexpand unex-form))
diff --git a/txr.1 b/txr.1
index 6d7aaab1..302f3785 100644
--- a/txr.1
+++ b/txr.1
@@ -85486,10 +85486,24 @@ When a source file begins with the
.code #!
(hash bang) character sequence, the file compiler propagates that
line (all characters up to and including the terminating newline) to the
-compiled file, subject to the following transformation: occurrences of
+compiled file, subject to the following transformation steps:
+.IP 1
+The line is divided into arguments, on the assumption that they are separated
+by exactly one space.
+.IP 2
+Then, all occurrences of the argument
.str --lisp
-which are not followed by a dash are replaced with
+are replaced by
.strn --compiled .
+.IP 3
+Next, all arguments which end in the suffix
+.str "txrlisp"
+have that suffix replaced by
+.strn "txrvm" .
+.IP 4
+The hash bang line is then reconstituted by joining the arguments
+with a single space.
+.PP
Furthermore, certain permissions are propagated from a hash-bang source
file to the target file. If the source file is executable to its owner,