diff options
-rw-r--r-- | struct.c | 26 | ||||
-rw-r--r-- | txr.1 | 37 |
2 files changed, 34 insertions, 29 deletions
@@ -274,7 +274,7 @@ static struct struct_inst *struct_handle(val obj, val ctx) ctx, obj, nao); } -static struct struct_type *stype_handle(val *pobj, val ctx) +static struct struct_type *stype_handle_impl(val *pobj, val obj_ok, val ctx) { val obj = *pobj; @@ -291,7 +291,7 @@ static struct struct_type *stype_handle(val *pobj, val ctx) case COBJ: if (obj->co.cls == struct_type_cls) return coerce(struct struct_type *, obj->co.handle); - if (obj->co.cls == struct_cls) + if (obj_ok && obj->co.cls == struct_cls) return struct_handle(obj, ctx)->type; /* fallthrough */ default: @@ -300,6 +300,16 @@ static struct struct_type *stype_handle(val *pobj, val ctx) } } +static struct struct_type *stype_handle(val *pobj, val ctx) +{ + return stype_handle_impl(pobj, nil, ctx); +} + +static struct struct_type *stype_handle_obj(val *pobj, val ctx) +{ + return stype_handle_impl(pobj, t, ctx); +} + static void static_slot_home_fixup(struct struct_type *st) { cnum i; @@ -635,15 +645,7 @@ val super(val type, val idx) self, idx, nao); { - struct struct_type *st; - - if (structp(type)) { - struct struct_inst *si = coerce(struct struct_inst *, type->co.handle); - st = si->type; - } else { - st = stype_handle(&type, self); - } - + struct struct_type *st = stype_handle_obj(&type, self); return if2(ix < st->nsupers, st->sus[ix]->self); } } @@ -1613,7 +1615,7 @@ val struct_type(val strct) val struct_type_name(val stype) { - struct struct_type *st = stype_handle(&stype, lit("struct-type-name")); + struct struct_type *st = stype_handle_obj(&stype, lit("struct-type-name")); return st->name; } @@ -28993,39 +28993,42 @@ returned by .coNP Function @ struct-type-name .synb -.mets (struct-type-name << type ) +.mets (struct-type-name << type-or-struct ) .syne .desc The .code struct-type-name -function returns the symbol which serves as the name of -.metn type , -which must be either a struct type object (such as the return value of +function determines a structure type from the +.meta type-or-struct +and returns that structure type's symbolic name. + +The +.meta type-or-struct +argument must be either a struct type object (such as the return value of a successful lookup via .codn find-struct-type ), -or else a struct type name. +a symbol which names a struct type, +or else a struct instance. .coNP Function @ super .synb -.mets (super << type ) +.mets (super >> [ type-or-struct ]) .syne .desc The .code super -function returns the struct type object which is the -supertype of -.metn type , -or returns +function determines a structure type from the +.meta type-or-struct +and returns the struct type object which is +the supertype of that type, or else .code nil -if -.meta type -has no supertype. +if that type has no supertype. The -.meta type -argument must be either a struct type object, a -a symbol which names a struct type (which is resolved to that type), -or else a structure instance (which is resolved to its structure type). +.meta type-or-struct +argument must be either a struct type object, +a symbol which names a struct type, +or else a struct instance. .coNP Function @ make-struct .synb |