diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-11-16 06:41:55 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-11-16 06:41:55 -0800 |
commit | dc84927c791873508f473f1d5679550882f86e91 (patch) | |
tree | a7143022cfe09d975c9984a9be7b9b2d7e2f55bc /parser.c | |
parent | cf0ac2826bc7dc06d3c63e956ec8922a358f4f80 (diff) | |
download | txr-dc84927c791873508f473f1d5679550882f86e91.tar.gz txr-dc84927c791873508f473f1d5679550882f86e91.tar.bz2 txr-dc84927c791873508f473f1d5679550882f86e91.zip |
Completion of fallback list implementation.
* lib.c (find_symbol): New function.
(symbol_present): Search the fallback list also to
determine whether the symbol is visible.
* lib.h (find_symbol): Declared.
* parser.y (sym_helper): Implement a new behavior for
qualified symbols. Interning new symbols is only allowed
for packages that have an empty fallback list.
* parser.c (get_visible_syms): New static function.
(find_matching_syms): Use get_visible_syms to get
the list of eligible symbols. This way the fallback list
of the package is included if it is the current package.
* share/txr/stdlib/package.tl (defpackage): Do not insert
a default (:use usr) if there is no :usr clause. Since
defpackage is very new, no need for backward compatibility;
the amount of code depending on this is likely zero.
* txr.1: Documented fallback list feature.
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -636,19 +636,45 @@ static void load_rcfile(val name) uw_catch_end; } +static val get_visible_syms(val package, int is_cur) +{ + val fblist; + + if (!is_cur || nilp((fblist = package_fallback_list(package)))) { + return package_symbols(package); + } else { + val symhash = copy_hash(package->pk.symhash); + + for (; fblist; fblist = cdr(fblist)) + { + val fb_pkg = car(fblist); + val hiter = hash_begin(fb_pkg->pk.symhash); + val fcell; + val new_p; + while ((fcell = hash_next(hiter))) { + val scell = gethash_c(symhash, car(fcell), mkcloc(new_p)); + if (new_p) + rplacd(scell, cdr(fcell)); + } + } + return hash_values(symhash); + } +} + static void find_matching_syms(lino_completions_t *cpl, val package, val prefix, val line_prefix, char par, val force_qualify) { - val qualify = tnil(force_qualify || package != cur_package); + int is_cur = package == cur_package; + val qualify = tnil(force_qualify || !is_cur); val pkg_name = if2(qualify, if3(package == keyword_package && !force_qualify, lit(""), package_name(package))); val syms; - for (syms = package_symbols(package); syms; syms = cdr(syms)) { + for (syms = get_visible_syms(package, is_cur); syms; syms = cdr(syms)) { val sym = car(syms); val name = symbol_name(sym); val found = if3(cpl->substring, |