summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-11-08 21:09:45 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-11-08 21:09:45 -0800
commit847a7b6c5292bd2126303e3ab7a6916657e13a71 (patch)
tree35e76797d42dbdae9171ab436f492e754576cf78 /lib.c
parent3ccdd5c9bfc6c8a8812ef6dab12dc1a1cd2bc0ee (diff)
downloadtxr-847a7b6c5292bd2126303e3ab7a6916657e13a71.tar.gz
txr-847a7b6c5292bd2126303e3ab7a6916657e13a71.tar.bz2
txr-847a7b6c5292bd2126303e3ab7a6916657e13a71.zip
Implement *package* special var; package overhaul.
* eval.c (load): Rebind *package* in the local dynamic environment already established for the sake of *load-path*. By doing this we cause *package* to be restored to its prior value, which allows the loaded file to alter it. Common Lisp works this way. (eval_init): Register *package* variable, with the user package as its default value. * lib.c (package_s): New symbol variable. (intern, rehome_sym): Default the package argument to the current package, not to user_package. (get_user_package, get_system_package, get_keyword_package): Functions removed. (get_current_package): New function. (obj_print_impl): Revise symbol printing. Keyword and uninterned symbols are printed with : and #: prefixes. The remainder are printed with a package prefix if their home package isn't the current package. * lib.h (keyword_package, user_package, system_package): These macros are just straight aliases for the global variables, not going through the lookup mechanism, which was pointless. (cur_package): New macro. (package_s): Declared. (get_current_package): Declared. * lisplib.c (lisplib_try_load): Establish a local dynamic environment, and bind the *package* variable to the user package which the library modules expect. * parser.c (find_matching_syms, provide_completions): Treat unqualified symbols in the current package rather than user package. * parser.y (sym_helper): Intern unqualified symbols in the current package, not user package. * txr.1: Document that the variables user-package, system-package and keyword-package should not be modified. Document the *package* special variable, and that intern and rehome-sym default their package argument to its value. (Here we get rid of wrong references to the undocumented variable *user-package*).
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c37
1 files changed, 11 insertions, 26 deletions
diff --git a/lib.c b/lib.c
index 8f1ca8c4..21901c7f 100644
--- a/lib.c
+++ b/lib.c
@@ -79,7 +79,7 @@ int async_sig_enabled = 0;
val packages;
val system_package_var, keyword_package_var, user_package_var;
-val system_package_s, keyword_package_s, user_package_s;
+val package_s, system_package_s, keyword_package_s, user_package_s;
val null_s, t, cons_s, str_s, chr_s, fixnum_s, sym_s, pkg_s, fun_s, vec_s;
val lit_s, stream_s, hash_s, hash_iter_s, lcons_s, lstr_s, cobj_s, cptr_s;
@@ -4832,7 +4832,7 @@ val intern(val str, val package)
loc place;
if (null_or_missing_p(package)) {
- package = user_package;
+ package = cur_package;
} else if (stringp(package)) {
val p = find_package(package);
if (!p)
@@ -4859,7 +4859,7 @@ val rehome_sym(val sym, val package)
return nil;
if (null_or_missing_p(package)) {
- package = user_package;
+ package = cur_package;
} else if (stringp(package)) {
val p = find_package(package);
if (!p)
@@ -4893,25 +4893,9 @@ val keywordp(val sym)
return tnil(sym && symbolp(sym) && sym->s.package == keyword_package_var);
}
-loc get_user_package(void)
+val get_current_package(void)
{
- if (nilp(user_package_s))
- return mkcloc(user_package_var);
- return lookup_global_var_l(user_package_s);
-}
-
-loc get_system_package(void)
-{
- if (nilp(system_package_s))
- return mkcloc(system_package_var);
- return lookup_global_var_l(system_package_s);
-}
-
-loc get_keyword_package(void)
-{
- if (nilp(keyword_package_s))
- return mkcloc(keyword_package_var);
- return lookup_global_var_l(keyword_package_s);
+ return cdr(lookup_var(nil, package_s));
}
val func_f0(val env, val (*fun)(val))
@@ -9435,11 +9419,12 @@ dot:
break;
case SYM:
if (!pretty) {
- if (obj->s.package != user_package) {
- if (!obj->s.package)
- put_char(chr('#'), out);
- else if (obj->s.package != keyword_package)
- put_string(obj->s.package->pk.name, out);
+ if (!obj->s.package) {
+ put_string(lit("#:"), out);
+ } else if (obj->s.package == keyword_package) {
+ put_char(chr(':'), out);
+ } else if (obj->s.package != cur_package) {
+ put_string(obj->s.package->pk.name, out);
put_char(chr(':'), out);
}
}