From f71aad515d95107da81a3f70d080e75675ce87e2 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 11 Jul 2018 22:11:28 -0700 Subject: compile-file: support hash bang. * share/txr/stdlib/compiler.tl (usr:compile-file): Check for a hash bang line in the source file. If so, propagate it to the compiled file. * txr.1: Documented existing support for hash bang in .tlo files, and the translation of hash bang from .tl to .tlo. --- share/txr/stdlib/compiler.tl | 4 ++++ txr.1 | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index 56db42b2..5b194263 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -1595,6 +1595,10 @@ (with-resources ((in-stream (car streams) (close-stream in-stream)) (out-stream (cadr streams) (close-stream out-stream)) (out (new list-builder))) + (iflet ((line (get-line in-stream)) + ((starts-with "#!" line))) + (put-line line out-stream) + (seek-stream in-stream 0 :from-start)) (labels ((compile-form (form) (unless (atom form) (caseq (car form) diff --git a/txr.1 b/txr.1 index 9941c972..0a377670 100644 --- a/txr.1 +++ b/txr.1 @@ -62306,6 +62306,17 @@ special variable has no influence on this. Circular structures in compiled literals are preserved; on loading, similar circular structures are reproduced. +.SS* Treatment of The Hash Bang Line + +When a source file begins with the +.code #! +("hash-bang") character sequence, the file compiler propagates that +line to the compiled file, verbatim. + +\*(TX supports the hash bang mechanism in compiled +.code .tlo +files, thereby allowing compiled scripts to be executable. + .coNP Function @ compile-toplevel .synb .mets (compile-toplevel < form << expanded-p ) -- cgit v1.2.3