diff options
-rw-r--r-- | eval.c | 4 | ||||
-rw-r--r-- | lib.c | 23 | ||||
-rw-r--r-- | lib.h | 4 | ||||
-rw-r--r-- | txr.1 | 20 |
4 files changed, 35 insertions, 16 deletions
@@ -6761,8 +6761,8 @@ void eval_init(void) reg_var(package_alist_s = intern(lit("*package-alist*"), user_package), packages); reg_var(package_s = intern(lit("*package*"), user_package), (opt_compat && opt_compat <= 190) ? user_package : public_package); - reg_fun(intern(lit("make-package"), user_package), func_n1(make_package)); - reg_fun(intern(lit("make-anon-package"), system_package), func_n0(make_anon_package)); + reg_fun(intern(lit("make-package"), user_package), func_n2o(make_package, 1)); + reg_fun(intern(lit("make-anon-package"), system_package), func_n1o(make_anon_package, 0)); reg_fun(intern(lit("find-package"), user_package), func_n1(find_package)); reg_fun(intern(lit("delete-package"), user_package), func_n1(delete_package)); reg_fun(intern(lit("merge-delete-package"), user_package), func_n2o(merge_delete_package, 1)); @@ -5910,10 +5910,11 @@ val gensym(val prefix) return make_sym(name); } -static val make_package_common(val name) +static val make_package_common(val name, val weak) { - val sh = make_hash(nil, nil, lit("t")); /* don't have t yet! */ - val hh = make_hash(nil, nil, lit("t")); + val weak_vals = default_null_arg(weak); + val sh = make_hash(nil, weak_vals, lit("t")); /* don't have t yet! */ + val hh = make_hash(nil, weak_vals, lit("t")); val obj = make_obj(); obj->pk.type = PKG; obj->pk.name = name; @@ -5922,7 +5923,7 @@ static val make_package_common(val name) return obj; } -val make_package(val name) +val make_package(val name, val weak) { if (find_package(name)) { uw_throwf(error_s, lit("make-package: ~s exists already"), name, nao); @@ -5932,15 +5933,15 @@ val make_package(val name) uw_throwf(error_s, lit("make-package: package name can't be empty string"), nao); } else { - val obj = make_package_common(name); + val obj = make_package_common(name, weak); mpush(cons(name, obj), cur_package_alist_loc); return obj; } } -val make_anon_package(void) +val make_anon_package(val weak) { - return make_package_common(lit("#<anon-package>")); + return make_package_common(lit("#<anon-package>"), weak); } val packagep(val obj) @@ -11878,10 +11879,10 @@ static void obj_init(void) null_list = cons(nil, nil); hash_s = make_sym(lit("hash")); - system_package = make_package(lit("sys")); - keyword_package = make_package(lit("keyword")); - user_package = make_package(lit("usr")); - public_package = make_package(lit("pub")); + system_package = make_package(lit("sys"), nil); + keyword_package = make_package(lit("keyword"), nil); + user_package = make_package(lit("usr"), nil); + public_package = make_package(lit("pub"), nil); rehome_sym(hash_s, user_package); @@ -928,8 +928,8 @@ val compl_span_str(val str, val set); val break_str(val str, val set); val make_sym(val name); val gensym(val prefix); -val make_package(val name); -val make_anon_package(void); +val make_package(val name, val weak); +val make_anon_package(val weak); val packagep(val obj); val find_package(val name); val delete_package(val package); @@ -54483,7 +54483,7 @@ uses to form the name of the new symbol. .coNP Function @ make-package .synb -.mets (make-package << name ) +.mets (make-package < name <> [ weak ]) .syne .desc The @@ -54499,6 +54499,24 @@ should be performed with the macro rather than by direct use of .codn make-package . +If the +.meta weak +parameter is given an argument which is a Boolean true, then the resulting +package holds symbols weakly, from a garbage collection point of view. If the +only reference to a symbol is that which occurs inside the weak package, then +that symbol may be removed from the package and reclaimed by the garbage +collector. + +Note: weak packages address the following problem. The application creates a +package for the purpose of reading Lisp data. Symbols occurring in that data +therefore are interned into the package. Subsequently, the application retains +references to some of the symbols, discarding the others. If the package isn't +weak, then because the application is retaining some of the symbols, and those +symbols hold a reference to the package, and the package holds a reference to +all symbols that were interned in it, all of the symbols are retained. If a +weak package is used, then the uninterested symbols are eligible for garbage +collection. + .coNP Function @ delete-package .synb .mets (delete-package << package ) |