summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-05-01 21:31:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-05-01 21:31:45 -0700
commit065dde19dfbe50e91e313e5b3ccc033cfbe47f74 (patch)
tree2ba6874a603e014b4be5e7e273eac2b62bae2ab5 /parser.c
parent488c1ba59416a0b2ce87a36d7df3026e334d66b9 (diff)
downloadtxr-065dde19dfbe50e91e313e5b3ccc033cfbe47f74.tar.gz
txr-065dde19dfbe50e91e313e5b3ccc033cfbe47f74.tar.bz2
txr-065dde19dfbe50e91e313e5b3ccc033cfbe47f74.zip
loading: try unsuffixed files directly last.
In this patch we change the strategy for resolving unsuffixed paths in load and @(load). In load, an unsuffixed name is tried with a .tlo suffix, then .tl and only if those don't resolve to a file it is tried as-is. The previous order is as-is, .tlo, .tl. Similarly in @(load), but unsuffixed paths are tried as .txr, then .tlo, then .tl. The motivation for this is to avoid probing the filesystem multiple times the optimized case that we care about: loading .tlo files from Lisp. * parser.c (open_txr_file): Rearrange the probing strategy. Also recognize .txr_profile as a suffix, treating it like .tl. This is so that we don't probe for .txr_profile.tlo and .txr_profile.tl before finding the profile. (load_rcfile): Take advantage of the new path-not-found exception. We avoid wastefully checking with path-exists-p to avoid calling open_txr_file. We just let open_txr_file throw an exception if the file doesn't exist, and then distinguish the non-existence case in the handler. * txr.1: Updated @(load) and load documentation.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c75
1 files changed, 41 insertions, 34 deletions
diff --git a/parser.c b/parser.c
index 89efaca4..f879e50f 100644
--- a/parser.c
+++ b/parser.c
@@ -439,58 +439,67 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
suffix = tl;
else if (match_str(spec_file, lit(".tlo"), negone))
suffix = tlo;
+ else if (match_str(spec_file, lit(".txr_profile"), negone))
+ suffix = tl;
else
suffix = none;
errno = 0;
{
- val spec_file_try = spec_file;
- FILE *in = w_fopen(c_str(spec_file_try), L"r");
+ val spec_file_try = nil;
+ FILE *in = 0;
- if (in != 0) {
- switch (suffix) {
- case tl:
- *txr_lisp_p = t;
- break;
- case tlo:
- *txr_lisp_p = chr('o');
- break;
- case txr:
- *txr_lisp_p = nil;
- break;
- default:
- break;
- }
- }
-
-#ifdef ENOENT
- if (in == 0 && errno != ENOENT)
- goto except;
- errno = 0;
-#endif
-
- if (suffix == none && in == 0 && !*txr_lisp_p) {
+ if (suffix == none && !*txr_lisp_p) {
spec_file_try = scat(lit("."), spec_file, lit("txr"), nao);
in = w_fopen(c_str(spec_file_try), L"r");
#ifdef ENOENT
if (in == 0 && errno != ENOENT)
goto except;
- errno = 0;
#endif
}
-
if (suffix == none) {
if (in == 0) {
spec_file_try = scat(lit("."), spec_file, lit("tlo"), nao);
+ errno = 0;
in = w_fopen(c_str(spec_file_try), L"r");
*txr_lisp_p = chr('o');
+#ifdef ENOENT
+ if (in == 0 && errno != ENOENT)
+ goto except;
+#endif
}
if (in == 0) {
spec_file_try = scat(lit("."), spec_file, lit("tl"), nao);
+ errno = 0;
in = w_fopen(c_str(spec_file_try), L"r");
*txr_lisp_p = t;
+#ifdef ENOENT
+ if (in == 0 && errno != ENOENT)
+ goto except;
+#endif
+ }
+ }
+
+ if (in == 0) {
+ spec_file_try = spec_file;
+ errno = 0;
+ in = w_fopen(c_str(spec_file_try), L"r");
+ if (in != 0) {
+ switch (suffix) {
+ case tl:
+ *txr_lisp_p = t;
+ break;
+ case tlo:
+ *txr_lisp_p = chr('o');
+ break;
+ case txr:
+ *txr_lisp_p = nil;
+ break;
+ default:
+ break;
+ }
}
}
@@ -705,10 +714,6 @@ static void load_rcfile(val name)
val stream = nil;
val catch_syms = cons(error_s, nil);
val path_private_to_me_p = intern(lit("path-private-to-me-p"), user_package);
- val path_exists_p = intern(lit("path-exists-p"), user_package);
-
- if (!funcall1(path_exists_p, name))
- return;
uw_catch_begin (catch_syms, sy, va);
@@ -730,9 +735,11 @@ static void load_rcfile(val name)
uw_catch(sy, va)
{
(void) va;
- format(std_output, lit("** type ~s exception while loading ~a\n"),
- sy, name, nao);
- format(std_output, lit("** details: ~a\n"), car(va), nao);
+ if (stream || sy != path_not_found_s) {
+ format(std_output, lit("** type ~s exception while loading ~a\n"),
+ sy, name, nao);
+ format(std_output, lit("** details: ~a\n"), car(va), nao);
+ }
}
uw_unwind {