summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-10-27 19:58:33 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-10-27 19:58:33 -0700
commit80623a3c5ab1e1c645cdaafa2e1716cb0dcb3b60 (patch)
tree91f96a16eb91330c520f4837ebf1f0203615c1e7
parente6eb95aaecce20c3a8883022de6e300ac15cdd4f (diff)
downloadtxr-80623a3c5ab1e1c645cdaafa2e1716cb0dcb3b60.tar.gz
txr-80623a3c5ab1e1c645cdaafa2e1716cb0dcb3b60.tar.bz2
txr-80623a3c5ab1e1c645cdaafa2e1716cb0dcb3b60.zip
command line: set self-path for --compile.
I noticed that when compiling a TXR Lisp program which refers to self-path using the --compile option, the compiler complained about self-path being unbound. * txr.c (self_path_s): New global variable. (do_compile_opt): Prior to running compile-update-file, bind self-path to the source path. (txr_main): Don't define local self_path_s, but initialize the global one. Replace redundant re-intering of self-path with a reference to self_path_s. * txr.1: self-path documentation updated.
-rw-r--r--txr.128
-rw-r--r--txr.c8
2 files changed, 33 insertions, 3 deletions
diff --git a/txr.1 b/txr.1
index ef53c99a..959dbe33 100644
--- a/txr.1
+++ b/txr.1
@@ -78979,7 +78979,9 @@ smaller than 32767 bytes are strongly discouraged.
.SS* Modularization
.coNP Variable @ self-path
.desc
-This variable holds the invocation pathname of the \*(TX program.
+This variable holds the invocation pathname of a \*(TX program
+that was specified on the command line.
+
The value of
.code self-path
when \*(TL expressions are being evaluated in command-line arguments
@@ -78992,6 +78994,21 @@ when a \*(TX query is supplied on the command line via the
command-line option is the string
.strn cmdline .
+When a file is being compiled using the
+.code --compile
+option, the value of
+.code self-path
+is the source file path.
+
+When the interactive listener is entered,
+.code self-path
+is set to the value
+.strn listener ,
+even if prior to that, a file was compiled
+or executed, for which
+.code self-path
+had been set to the name of that file.
+
Note that for programs read from a file,
.code self-path
holds the resolved name, and not the invocation name. For instance if
@@ -79002,6 +79019,15 @@ whereby \*(TX infers the suffix, then
.code self-path
holds the suffixed name.
+Note that the functions
+.codn load ,
+.code compile-file
+and
+.code compile-update-file
+have no effect on the value of
+.code self-path.
+The variable is set strictly by command line processing.
+
.coNP Variable @ stdlib
.desc
The
diff --git a/txr.c b/txr.c
index 35f34212..9be7a0c5 100644
--- a/txr.c
+++ b/txr.c
@@ -82,6 +82,7 @@ int opt_compat;
int opt_dbg_expansion;
int opt_free_all;
val stdlib_path;
+val self_path_s;
#if HAVE_FORK_STUFF
#define IF_HAVE_FORK_STUFF(THEN, ELSE) THEN
@@ -455,6 +456,8 @@ static void do_compile_opt(val arg)
source = sub_str(source, zero, col_pos);
}
+ reg_varl(self_path_s, source);
+
funcall2(compile_update_file, source, target);
}
@@ -572,7 +575,6 @@ int txr_main(int argc, char **argv)
val txr_lisp_p = nil;
val enter_repl = nil;
val args_s = intern(lit("*args*"), user_package);
- val self_path_s = intern(lit("self-path"), user_package);
val compat_var = lit("TXR_COMPAT");
val compat_val = getenv_wrap(compat_var);
val orig_args = nil, ref_arg_list = nil;
@@ -582,6 +584,8 @@ int txr_main(int argc, char **argv)
static char alt_args_buf[128 + 7] = "@(txr):", *alt_args = alt_args_buf + 7;
+ self_path_s = intern(lit("self-path"), user_package);
+
if (ends_with(lit("lisp" EXE_SUFF), prog_path, nil, nil))
txr_lisp_p = t;
else if (ends_with(lit("vm" EXE_SUFF), prog_path, nil, nil))
@@ -1269,7 +1273,7 @@ repl:
"due to environment variable.\n"),
num(opt_compat), nao);
reg_var(args_s, or2(orig_args, arg_list));
- reg_varl(intern(lit("self-path"), user_package), lit("listener"));
+ reg_varl(self_path_s, lit("listener"));
env_vbind(dyn_env, package_s,
opt_compat && opt_compat <= 190 ? user_package : public_package);
env_vbind(dyn_env, load_recursive_s, nil);