summaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-03-16 21:10:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-03-16 21:10:45 -0700
commitc609898ed0bdb212bd5b53758cd22f617d9760df (patch)
tree1b682bafec94f08afbfc5f774e586d3eeb6e6a91 /struct.c
parent166ae3842267745d7ffea5aecf8eaf1f95d58e4a (diff)
downloadtxr-c609898ed0bdb212bd5b53758cd22f617d9760df.tar.gz
txr-c609898ed0bdb212bd5b53758cd22f617d9760df.tar.bz2
txr-c609898ed0bdb212bd5b53758cd22f617d9760df.zip
New function: static-slot-home.
* struct.c (struct_init): Register intrinsic function static-slot-home. (lookup_static_slot_desc_load): New static function. (static_slot_home): New function. * struct.h (static_slot_home): Declared. * txr.1: Documented.
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/struct.c b/struct.c
index eeac788d..a4e9eb8f 100644
--- a/struct.c
+++ b/struct.c
@@ -150,6 +150,8 @@ void struct_init(void)
reg_fun(intern(lit("clear-dirty"), user_package), func_n1(clear_dirty));
reg_fun(intern(lit("static-slot-ensure"), user_package),
func_n4o(static_slot_ensure, 3));
+ reg_fun(intern(lit("static-slot-home"), user_package),
+ func_n2(static_slot_home));
reg_fun(intern(lit("call-super-method"), user_package),
func_n2v(call_super_method));
reg_fun(intern(lit("call-super-fun"), user_package),
@@ -861,6 +863,17 @@ static loc lookup_static_slot_load(struct struct_type *st, val sym)
return ptr;
}
+static struct stslot *lookup_static_slot_desc_load(struct struct_type *st,
+ val sym)
+{
+ struct stslot *stsl = lookup_static_slot_desc(st, sym);
+ if (stsl == 0) {
+ lisplib_try_load(sym);
+ return lookup_static_slot_desc(st, sym);
+ }
+ return stsl;
+}
+
static noreturn void no_such_slot(val ctx, val type, val slot)
{
uw_throwf(error_s, lit("~a: ~s has no slot named ~s"),
@@ -1114,6 +1127,19 @@ val static_slot_ensure(val stype, val sym, val newval, val no_error_p)
return static_slot_ens_rec(stype, sym, newval, no_error_p, self, 0);
}
+val static_slot_home(val stype, val sym)
+{
+ val self = lit("static-slot-home");
+ struct struct_type *st = stype_handle(&stype, self);
+ struct stslot *stsl = lookup_static_slot_desc_load(st, sym);
+ if (stsl) {
+ val home = stsl->home_type;
+ struct struct_type *sh = stype_handle(&home, self);
+ return sh->name;
+ }
+ no_such_static_slot(self, stype, sym);
+}
+
static val call_super_method(val inst, val sym, struct args *args)
{
val type = struct_type(inst);