summaryrefslogtreecommitdiffstats
path: root/txr.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-04-04 20:01:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-04-04 20:01:02 -0700
commit274cb70971d6a2cebcd887350b4b8602b32743d7 (patch)
tree07344e7330788fa23d35ad34b0a6bf48dcd97661 /txr.c
parent5484325557ee4201fd04772049145ad95ff7dbc4 (diff)
downloadtxr-274cb70971d6a2cebcd887350b4b8602b32743d7.tar.gz
txr-274cb70971d6a2cebcd887350b4b8602b32743d7.tar.bz2
txr-274cb70971d6a2cebcd887350b4b8602b32743d7.zip
Implement compiled file loading.
* eval.c (load): If open_txr_file indicates compiled file by setting txr_lisp_p to character #\o, use read_compiled_file. * match.c (v_load): Likewise. * parser.c (open_txr_file): Recognize the .tlo suffix, and also try to open a .tlo version of an unsuffixed file before trying it as .tl. Indicate a .tlo file by setting txr_lisp_p to the character #\o rather than t. (read_file_common): New static function, made from contents of read_eval_stream. Will either evaluate forms or load compiled code by instantiating virtual machine descriptions and performing their top-level execution. (read_eval_stream): Now a wrapper for read_file_common. (read_compiled_file): New function. * parser.h (read_compiled_file): Declared. * txr.c (help): List new --compiled option. (txr_main): If --compiled is specified, set txr_lisp_p to #\o to load as compiled code. Update error message that -c is not compatible with --lisp or --compiled. If txr_lisp_p is #\o, then use read_compiled_file.
Diffstat (limited to 'txr.c')
-rw-r--r--txr.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/txr.c b/txr.c
index 30f5c8ae..14cc6642 100644
--- a/txr.c
+++ b/txr.c
@@ -139,6 +139,7 @@ static void help(void)
" Use of txr implies agreement with the disclaimer\n"
" section at the bottom of the license.\n"
"--lisp Treat unsuffixed query files as TXR Lisp.\n"
+"--compiled Treat unsuffixed query files as compiled TXR Lisp.\n"
"--lisp-bindings Synonym for -l\n"
"--debugger Synonym for -d\n"
"--noninteractive Synonym for -n\n"
@@ -677,6 +678,9 @@ int txr_main(int argc, char **argv)
} else if (equal(opt, lit("lisp"))) {
txr_lisp_p = t;
continue;
+ } else if (equal(opt, lit("compiled"))) {
+ txr_lisp_p = chr('o');
+ continue;
#if HAVE_FORK_STUFF
} else if (equal(opt, lit("reexec"))) {
exec_wrap(prog_path, arg_list);
@@ -787,7 +791,7 @@ int txr_main(int argc, char **argv)
case 'c':
if (txr_lisp_p) {
format(std_error,
- lit("~a: -c not compatible with --lisp; use -e\n"),
+ lit("~a: -c not compatible with --lisp or --compiled; use -e\n"),
prog_string, nao);
return EXIT_FAILURE;
}
@@ -1036,7 +1040,11 @@ int txr_main(int argc, char **argv)
reg_varl(car(binding), cdr(binding));
}
- {
+ if (txr_lisp_p == chr('o')) {
+ val result = read_compiled_file(parse_stream, std_error);
+ if (!enter_repl)
+ return result ? 0 : EXIT_FAILURE;
+ } else {
val result = read_eval_stream_noerr(parse_stream, spec_file_str,
std_error);