diff options
-rw-r--r-- | eval.c | 33 | ||||
-rw-r--r-- | ffi.c | 8 | ||||
-rw-r--r-- | filter.c | 6 | ||||
-rw-r--r-- | hash.c | 61 | ||||
-rw-r--r-- | hash.h | 5 | ||||
-rw-r--r-- | lex.yy.c.shipped | 2 | ||||
-rw-r--r-- | lib.c | 13 | ||||
-rw-r--r-- | lisplib.c | 2 | ||||
-rw-r--r-- | match.c | 8 | ||||
-rw-r--r-- | parser.c | 6 | ||||
-rw-r--r-- | parser.l | 2 | ||||
-rw-r--r-- | parser.y | 4 | ||||
-rw-r--r-- | struct.c | 10 | ||||
-rw-r--r-- | sysif.c | 2 | ||||
-rw-r--r-- | y.tab.c.shipped | 4 |
15 files changed, 85 insertions, 81 deletions
@@ -4128,15 +4128,15 @@ static val me_case(val form, val menv) if (casesym == caseq_s || casesym == caseq_star_s) { memfuncsym = memq_s; eqfuncsym = eq_s; - hash = make_hash(nil, nil, nil); + hash = make_hash(hash_weak_none, nil); } else if (casesym == caseql_s || casesym == caseql_star_s) { memfuncsym = memql_s; eqfuncsym = eql_s; - hash = make_hash(nil, nil, nil); + hash = make_hash(hash_weak_none, nil); } else { memfuncsym = memqual_s; eqfuncsym = equal_s; - hash = make_hash(nil, nil, t); + hash = make_hash(hash_weak_none, t); } for (; consp(form); form = cdr(form)) { @@ -4723,7 +4723,7 @@ static val expand_switch(val form, val menv) val branches = second(args); val expr_ex = expand(expr, menv); val branches_ex; - val ss_hash = make_hash(nil, nil, nil); + val ss_hash = make_hash(hash_weak_none, nil); if (listp(branches)) { branches_ex = expand_list_of_form_lists(branches, menv, ss_hash); @@ -6488,21 +6488,14 @@ void eval_init(void) &call_f, &iter_begin_f, &iter_from_binding_f, &iter_more_f, &iter_item_f, &iter_step_f, &unbound_s, &origin_hash, &const_foldable_hash, convert(val *, 0)); - top_fb = make_hash(nil, nil, nil); - top_vb = make_hash(nil, nil, nil); - top_mb = make_hash(nil, nil, nil); - top_smb = make_hash(nil, nil, nil); - special = make_hash(nil, nil, nil); - builtin = make_hash(nil, nil, nil); - op_table = make_hash(nil, nil, nil); - pm_table = make_hash(nil, nil, nil); - - tweak_hash(top_fb, hash_weak_and); - tweak_hash(top_vb, hash_weak_and); - tweak_hash(top_mb, hash_weak_and); - tweak_hash(top_smb, hash_weak_and); - tweak_hash(special, hash_weak_and); - tweak_hash(builtin, hash_weak_and); + top_fb = make_hash(hash_weak_and, nil); + top_vb = make_hash(hash_weak_and, nil); + top_mb = make_hash(hash_weak_and, nil); + top_smb = make_hash(hash_weak_and, nil); + special = make_hash(hash_weak_and, nil); + builtin = make_hash(hash_weak_and, nil); + op_table = make_hash(hash_weak_none, nil); + pm_table = make_hash(hash_weak_none, nil); call_f = func_n1v(generic_funcall); iter_begin_f = func_n1(iter_begin); @@ -6511,7 +6504,7 @@ void eval_init(void) iter_item_f = func_n1(iter_item); iter_step_f = func_n1(iter_step); - origin_hash = make_eq_hash(t, nil); + origin_hash = make_eq_hash(hash_weak_keys); dwim_s = intern(lit("dwim"), user_package); progn_s = intern(lit("progn"), user_package); @@ -3647,8 +3647,8 @@ static val make_ffi_type_enum(val syntax, val enums, chk_calloc(1, sizeof *tft)); struct txr_ffi_type *btft = ffi_type_struct(base_type); - val sym_num = make_hash(nil, nil, t); - val num_sym = make_hash(nil, nil, nil); + val sym_num = make_hash(hash_weak_none, t); + val num_sym = make_hash(hash_weak_none, nil); val obj = cobj(coerce(mem_t *, tft), ffi_type_cls, &ffi_type_enum_ops); cnum lowest = INT_PTR_MAX; cnum highest = INT_PTR_MIN; @@ -6481,8 +6481,8 @@ void ffi_init(void) reg_fun(intern(lit("get-obj"), user_package), func_n2o(get_obj, 1)); reg_fun(intern(lit("fill-obj"), user_package), func_n3o(fill_obj, 2)); reg_fun(intern(lit("dyn-size"), system_package), func_n2(dyn_size)); - ffi_typedef_hash = make_hash(nil, nil, nil); - ffi_struct_tag_hash = make_hash(nil, nil, nil); + ffi_typedef_hash = make_hash(hash_weak_none, nil); + ffi_struct_tag_hash = make_hash(hash_weak_none, nil); ffi_init_types(); ffi_init_extra_types(); } @@ -52,7 +52,7 @@ val tonumber_k, toint_k, tofloat_k, hextoint_k; static val make_trie(void) { - return make_hash(nil, nil, nil); + return make_hash(hash_weak_none, nil); } static val trie_add(val trie, val key, val value) @@ -64,7 +64,7 @@ static val trie_add(val trie, val key, val value) val newnode_p; loc place = gethash_l(lit("trie-add"), node, ch, mkcloc(newnode_p)); if (newnode_p) - set(place, make_hash(nil, nil, nil)); + set(place, make_hash(hash_weak_none, nil)); node = deref(place); } @@ -1032,7 +1032,7 @@ static val html_decode(val str) void filter_init(void) { - val fh = make_hash(nil, nil, nil); + val fh = make_hash(hash_weak_none, nil); filters_s = intern(lit("*filters*"), user_package); filter_k = intern(lit("filter"), keyword_package); @@ -790,17 +790,17 @@ static_def(struct hash_ops hash_equal_ops = hash_ops_init(equal_hash, equal, hash_assoc, hash_acons_new_c)); -static val do_make_hash(val weak_keys, val weak_vals, - hash_type_t type, val seed) +static val do_make_hash(hash_weak_opt_t wkopt, hash_type_t type, val seed) { val self = lit("make-hash"); - if (weak_keys && type == hash_type_equal) { + if (type == hash_type_equal && + wkopt != hash_weak_none && wkopt != hash_weak_vals) + { uw_throwf(error_s, lit("make-hash: bad combination :weak-keys with :equal-based"), nao); } else { - int wkopt = ((weak_vals != nil) << 1) | (weak_keys != nil); struct hash *h = coerce(struct hash *, chk_malloc(sizeof *h)); val mod = num_fast(256); val table = vector(mod, nil); @@ -809,7 +809,7 @@ static val do_make_hash(val weak_keys, val weak_vals, h->seed = convert(u32_t, c_unum(default_arg(seed, if3(hash_seed_s, hash_seed, zero)), self)); - h->wkopt = convert(hash_weak_opt_t, wkopt); + h->wkopt = wkopt; h->modulus = c_num(mod, self); h->count = 0; h->table = table; @@ -817,13 +817,6 @@ static val do_make_hash(val weak_keys, val weak_vals, h->usecount = 0; - if (weak_keys) { - if (weak_keys == weak_and_k) - h->wkopt = hash_weak_and; - else if (weak_keys == weak_or_k) - h->wkopt = hash_weak_or; - } - switch (type) { case hash_type_eq: h->hops = &hash_eq_ops; @@ -841,28 +834,43 @@ static val do_make_hash(val weak_keys, val weak_vals, } } -void tweak_hash(val hash, hash_weak_opt_t wkopt) +static hash_weak_opt_t weak_opt_from_flags(val weak_keys, val weak_vals) { - val self = lit("internal-error"); - struct hash *h = coerce(struct hash *, cobj_handle(self, hash, hash_cls)); - h->wkopt = wkopt; + if (weak_keys) { + if (weak_keys == weak_and_k) + return hash_weak_and; + if (weak_keys == weak_or_k) + return hash_weak_or; + } + + switch (!!weak_vals << 1 | !!weak_keys) { + case 0: return hash_weak_none; + case 1: return hash_weak_keys; + case 2: return hash_weak_vals; + case 3: return hash_weak_or; + default: + /* notreached */ + abort(); + } } val make_seeded_hash(val weak_keys, val weak_vals, val equal_based, val seed) { - return do_make_hash(weak_keys, weak_vals, + return do_make_hash(weak_opt_from_flags(weak_keys, weak_vals), if3(equal_based, hash_type_equal, hash_type_eql), seed); } -val make_hash(val weak_keys, val weak_vals, val equal_based) +val make_hash(hash_weak_opt_t wkopt, val equal_based) { - return make_seeded_hash(weak_keys, weak_vals, equal_based, nil); + return do_make_hash(wkopt, + if3(equal_based, hash_type_equal, hash_type_eql), + nil); } -val make_eq_hash(val weak_keys, val weak_vals) +val make_eq_hash(hash_weak_opt_t wkopt) { - return do_make_hash(weak_keys, weak_vals, hash_type_eq, nil); + return do_make_hash(wkopt, hash_type_eq, nil); } val make_similar_hash(val existing) @@ -1429,6 +1437,7 @@ val hashv(struct args *args) { weak_or_k, nil, &wor }, { userdata_k, t, &userdata } }; + hash_weak_opt_t wkopt = hash_weak_none; args_keys_extract(args, akv, sizeof akv / sizeof akv[0]); @@ -1437,15 +1446,17 @@ val hashv(struct args *args) self, weak_and_k, weak_or_k, nao); if (wand) - wkeys = weak_and_k; + wkopt = hash_weak_and; else if (wor) - wkeys = weak_or_k; + wkopt = hash_weak_or; + else + wkopt = weak_opt_from_flags(wkeys, wvals); { val ebp = equal_based_p(equal, eql, eq, wkeys); val hash = if3(eq, - make_eq_hash(wkeys, wvals), - make_hash(wkeys, wvals, ebp)); + make_eq_hash(wkopt), + make_hash(wkopt, ebp)); if (userdata) set_hash_userdata(hash, userdata); return hash; @@ -47,9 +47,8 @@ extern struct cobj_class *hash_cls; ucnum equal_hash(val obj, int *count, ucnum); val make_seeded_hash(val weak_keys, val weak_vals, val equal_based, val seed); -void tweak_hash(val hash, hash_weak_opt_t); -val make_hash(val weak_keys, val weak_vals, val equal_based); -val make_eq_hash(val weak_keys, val weak_vals); +val make_hash(hash_weak_opt_t, val equal_based); +val make_eq_hash(hash_weak_opt_t); val make_similar_hash(val existing); val copy_hash(val existing); val gethash_c(val self, val hash, val key, loc new_p); diff --git a/lex.yy.c.shipped b/lex.yy.c.shipped index 5a5d7c78..83d5c5d3 100644 --- a/lex.yy.c.shipped +++ b/lex.yy.c.shipped @@ -7424,6 +7424,6 @@ void scrub_scanner(scanner_t *yyg, int yy_char, wchar_t *lexeme) void parser_l_init(void) { prot1(&form_to_ln_hash); - form_to_ln_hash = make_eq_hash(t, nil); + form_to_ln_hash = make_eq_hash(hash_weak_keys); } @@ -6379,9 +6379,10 @@ val gensym(val prefix) static val make_package_common(val name, val weak) { - val weak_vals = default_null_arg(weak); - val sh = make_hash(nil, weak_vals, t); - val hh = make_hash(nil, weak_vals, t); + hash_weak_opt_t wkopt = if3(default_null_arg(weak), + hash_weak_vals, hash_weak_none); + val sh = make_hash(wkopt, t); + val hh = make_hash(wkopt, t); val obj = make_obj(); obj->pk.type = PKG; obj->pk.name = name; @@ -12782,7 +12783,7 @@ static void obj_init(void) greater_f = func_n2(greater); prog_string = string(progname); - cobj_hash = make_hash(nil, nil, nil); + cobj_hash = make_hash(hash_weak_none, nil); } static val simple_qref_args_p(val args, val pos) @@ -13866,7 +13867,7 @@ val obj_print(val obj, val out, val pretty) if (ctx) { if (cdr(lookup_var(nil, print_circle_s))) { ctx->obj_hash_prev = ctx->obj_hash; - ctx->obj_hash = make_eq_hash(nil, nil); + ctx->obj_hash = make_eq_hash(hash_weak_none); populate_obj_hash(obj, ctx); obj_hash_merge(ctx->obj_hash_prev, ctx->obj_hash); ctx->obj_hash = ctx->obj_hash_prev; @@ -13881,7 +13882,7 @@ val obj_print(val obj, val out, val pretty) ctx->obj_hash_prev = nil; ctx->obj_hash = if2(print_circle_s && cdr(lookup_var(nil, print_circle_s)), - make_eq_hash(nil, nil)); + make_eq_hash(hash_weak_none)); ctx->depth = 0; get_set_ctx(out, ctx); if (ctx->obj_hash) @@ -963,7 +963,7 @@ val dlt_register(val dlt, void lisplib_init(void) { prot1(&dl_table); - dl_table = make_hash(nil, nil, nil); + dl_table = make_hash(hash_weak_none, nil); dlt_register(dl_table, place_instantiate, place_set_entries); dlt_register(dl_table, ver_instantiate, ver_set_entries); dlt_register(dl_table, ifa_instantiate, ifa_set_entries); @@ -4906,10 +4906,10 @@ static void dir_tables_init(void) &non_matching_directive_table, &binding_directive_table, convert(val *, 0)); - h_directive_table = make_hash(nil, nil, nil); - v_directive_table = make_hash(nil, nil, nil); - non_matching_directive_table = make_hash(nil, nil, nil); - binding_directive_table = make_hash(nil, nil, nil); + h_directive_table = make_hash(hash_weak_none, nil); + v_directive_table = make_hash(hash_weak_none, nil); + non_matching_directive_table = make_hash(hash_weak_none, nil); + binding_directive_table = make_hash(hash_weak_none, nil); sethash(v_directive_table, skip_s, cptr(coerce(mem_t *, v_skip))); sethash(v_directive_table, fuzz_s, cptr(coerce(mem_t *, v_fuzz))); @@ -481,7 +481,7 @@ void parser_resolve_circ(parser_t *p) void parser_circ_def(parser_t *p, val num, val expr) { if (!p->circ_ref_hash) { - p->circ_ref_hash = make_eq_hash(nil, nil); + p->circ_ref_hash = make_eq_hash(hash_weak_none); setcheck(p->parser, p->circ_ref_hash); } @@ -1478,7 +1478,7 @@ val repl(val bindings, val in_stream, val out_stream, val env) val var_counter_sym = intern(lit("*v"), user_package); val result_hash_sym = intern(lit("*r"), user_package); val path_private_to_me_p = intern(lit("path-private-to-me-p"), user_package); - val result_hash = make_hash(nil, nil, nil); + val result_hash = make_hash(hash_weak_none, nil); val done = nil; val counter = one; val home = if3(repl_level == 1, get_home_path(), nil); @@ -1878,7 +1878,7 @@ void parse_init(void) parser_cls = cobj_register(parser_s); protect(&stream_parser_hash, &unique_s, &catch_all, convert(val *, 0)); - stream_parser_hash = make_hash(weak_and_k, nil, nil); + stream_parser_hash = make_hash(hash_weak_and, nil); catch_all = cons(t, nil); parser_l_init(); @@ -1471,5 +1471,5 @@ void scrub_scanner(scanner_t *yyg, int yy_char, wchar_t *lexeme) void parser_l_init(void) { prot1(&form_to_ln_hash); - form_to_ln_hash = make_eq_hash(t, nil); + form_to_ln_hash = make_eq_hash(hash_weak_keys); } @@ -975,7 +975,7 @@ json_val : NUMBER { $$ = $1; } rl(cons(vector_lit_s, cons(nreverse($2), nil)), $2)); } - | '{' '}' { $$ = make_hash(nil, nil, t); } + | '{' '}' { $$ = make_hash(hash_weak_none, t); } | '{' json_pairs '}' { $$ = if3(hashp($2), $2, rl(cons(hash_lit_s, @@ -1027,7 +1027,7 @@ json_pairs : json_val json_col json_val { if (parser->quasi_level > 0 && unquotes_occur($3, 0))) { $$ = cons(list($1, $3, nao), nil); } else - { $$ = make_hash(nil, nil, t); + { $$ = make_hash(hash_weak_none, t); sethash($$, $1, $3); } } | json_pairs ',' json_val json_col json_val { if (consp($1)) @@ -159,10 +159,10 @@ void struct_init(void) struct_type_cls = cobj_register(struct_type_s); struct_cls = cobj_register(struct_s); - struct_type_hash = make_hash(nil, nil, nil); - slot_hash = make_hash(nil, nil, t); - slot_type_hash = make_hash(nil, nil, nil); - static_slot_type_hash = make_hash(nil, nil, nil); + struct_type_hash = make_hash(hash_weak_none, nil); + slot_hash = make_hash(hash_weak_none, t); + slot_type_hash = make_hash(hash_weak_none, nil); + static_slot_type_hash = make_hash(hash_weak_none, nil); struct_type_finalize_f = func_n1(struct_type_finalize); reg_fun(intern(lit("make-struct-type"), user_package), @@ -1969,7 +1969,7 @@ val method_name(val fun) val get_slot_syms(val package, val is_current, val method_only) { - val result_hash = make_hash(nil, nil, nil); + val result_hash = make_hash(hash_weak_none, nil); struct hash_iter sthi; val sth_cell; @@ -341,7 +341,7 @@ static val get_env_hash(void) return env_hash; } else { val env_strings = env(); - val hash = make_hash(nil, nil, t); + val hash = make_hash(hash_weak_none, t); for (; env_strings; env_strings = cdr(env_strings)) { val estr = car(env_strings); diff --git a/y.tab.c.shipped b/y.tab.c.shipped index 9f456895..ece9571b 100644 --- a/y.tab.c.shipped +++ b/y.tab.c.shipped @@ -5153,7 +5153,7 @@ yyreduce: /* Line 1806 of yacc.c */ #line 978 "parser.y" - { (yyval.val) = make_hash(nil, nil, t); } + { (yyval.val) = make_hash(hash_weak_none, t); } break; case 233: @@ -5297,7 +5297,7 @@ yyreduce: unquotes_occur((yyvsp[(3) - (3)].val), 0))) { (yyval.val) = cons(list((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val), nao), nil); } else - { (yyval.val) = make_hash(nil, nil, t); + { (yyval.val) = make_hash(hash_weak_none, t); sethash((yyval.val), (yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); } } break; |