diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-09-06 06:58:48 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-09-06 06:58:48 -0700 |
commit | aebdc3d7c22820d7604f2c424cbc179d7ebb34d1 (patch) | |
tree | 6bea563acba130e47b19ec10b4b2d04fdf012cae /struct.c | |
parent | 13732bc2f2f66d992dfaabddd7440b7018d9b562 (diff) | |
download | txr-aebdc3d7c22820d7604f2c424cbc179d7ebb34d1.tar.gz txr-aebdc3d7c22820d7604f2c424cbc179d7ebb34d1.tar.bz2 txr-aebdc3d7c22820d7604f2c424cbc179d7ebb34d1.zip |
lib: access special methods via special slot mechanism.
* ffi.c (ffi_flex_struct_in): Use get_special_slot to obtain
length method.
* lib.c (nullify_s, from_list_s, lambda_set_s): Definitions
removed from here.
(seq_info, car, cdr, rplaca, rplacd, make_like, nullify,
replace_obj, length, empty, sub, ref, refset, dwim_set): Use
get_special_slot to obtain special method from object,
rather than maybe_slot.
(obj_init): Remove initializations of nullify_s, from_list_s
and lambda_set_s from here.
* struct.c (enum special_slot): Definition removed from here.
(nullify_s, from_list_s, lambda_set_s): Definitions moved here
from lib.c.
(special_sym): New static array.
(struct_init): Initializations of nullify_s, from_list_s
and lambda_set_s moved here from lib.c.
(get_special_slot): New function.
* struct.h (lambda_set_s): Declared.
(enum special_slot): Definition moved here.
(get_special_slot): Declared.
* txr.1: Added compat note, since get_special_slot behaves
like maybe_slot under 224 compatibility.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -72,11 +72,6 @@ struct stslot { #define stslot_loc(s) mkloc(*(s)->home, (s)->home_type) #define stslot_place(s) (*(s)->home) -enum special_slot { - equal_meth, - num_special_slots -}; - struct struct_type { val self; val name; @@ -107,6 +102,13 @@ val struct_type_s, meth_s, print_s, make_struct_lit_s; val init_k, postinit_k; val slot_s, derived_s; +val nullify_s, from_list_s, lambda_set_s; + +static val *special_sym[num_special_slots] = { + &equal_s, &nullify_s, &from_list_s, &lambda_s, &lambda_set_s, + &length_s, &car_s, &cdr_s, &rplaca_s, &rplacd_s +}; + static val struct_type_hash; static val slot_hash; static val struct_type_finalize_f; @@ -135,6 +137,9 @@ void struct_init(void) postinit_k = intern(lit("postinit"), keyword_package); slot_s = intern(lit("slot"), user_package); derived_s = intern(lit("derived"), user_package); + nullify_s = intern(lit("nullify"), user_package); + from_list_s = intern(lit("from-list"), user_package); + lambda_set_s = intern(lit("lambda-set"), user_package); struct_type_hash = make_hash(nil, nil, nil); slot_hash = make_hash(nil, nil, t); slot_type_hash = make_hash(nil, nil, nil); @@ -1759,6 +1764,15 @@ val static_slot_type_reg(val slot, val strct) return slot; } +val get_special_slot(val obj, enum special_slot spidx) +{ + val slot = *special_sym[spidx]; + if (opt_compat && opt_compat <= 224) + return maybe_slot(obj, slot); + struct struct_inst *si = coerce(struct struct_inst *, obj->co.handle); + return get_special_static_slot(si->type, spidx, slot); +} + static_def(struct cobj_ops struct_type_ops = cobj_ops_init(eq, struct_type_print, struct_type_destroy, struct_type_mark, cobj_eq_hash_op)); |