diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-05-15 07:08:32 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-05-15 07:08:32 -0700 |
commit | 0d3a7519e81dc9eb26d550393bb5d988dad645bf (patch) | |
tree | f2f9f343421642c15ff20f9693788f770f0cc858 /struct.c | |
parent | 63d18cb2cb30c20c9bbf00501b253bbc1cee5011 (diff) | |
download | txr-0d3a7519e81dc9eb26d550393bb5d988dad645bf.tar.gz txr-0d3a7519e81dc9eb26d550393bb5d988dad645bf.tar.bz2 txr-0d3a7519e81dc9eb26d550393bb5d988dad645bf.zip |
oop: derived hook.
* struct.c (derived_s): New symbol variable.
(struct_init): Initialize derived_s symbol.
(make_struct_type): Check for derived method in parent, and
invoke.
* struct.h (derived_s): Declared.
* txr.1: Documented.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -99,7 +99,7 @@ struct struct_inst { val struct_type_s, meth_s, print_s, make_struct_lit_s; val init_k, postinit_k; -val slot_s; +val slot_s, derived_s; static val struct_type_hash; static val slot_hash; @@ -110,6 +110,7 @@ static val static_slot_type_hash; static val struct_type_finalize(val obj); static_forward(struct cobj_ops struct_type_ops); +static struct stslot *lookup_static_slot_desc(struct struct_type *st, val sym); static val make_struct_type_compat(val name, val super, val slots, val initfun, val boactor); static val call_super_method(val inst, val sym, struct args *); @@ -127,6 +128,7 @@ void struct_init(void) init_k = intern(lit("init"), keyword_package); postinit_k = intern(lit("postinit"), keyword_package); slot_s = intern(lit("slot"), user_package); + derived_s = intern(lit("derived"), 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); @@ -308,6 +310,7 @@ val make_struct_type(val name, val super, val super_slots = if2(su, su->slots); val all_slots = uniq(append2(super_slots, append2(static_slots, slots))); val stype = cobj(coerce(mem_t *, st), struct_type_s, &struct_type_ops); + struct stslot *dvmeth = if3(su, lookup_static_slot_desc(su, derived_s), 0); val iter; cnum sl, stsl; cnum stsl_upb = c_num(plus(length(static_slots), @@ -394,6 +397,9 @@ val make_struct_type(val name, val super, uw_purge_deferred_warning(cons(struct_type_s, name)); + if (dvmeth) + funcall2(stslot_place(dvmeth), su->self, stype); + return stype; } } |