summaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-11-14 20:54:00 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-11-20 16:17:17 -0800
commit3cad8dfa357c5733c94e2a301da9184f3eb50e78 (patch)
treedda8527ead51d8cf5c8e747c32a530498562ad66 /struct.c
parent75f37374682fe01685ed4c0df0b068e475c864ec (diff)
downloadtxr-3cad8dfa357c5733c94e2a301da9184f3eb50e78.tar.gz
txr-3cad8dfa357c5733c94e2a301da9184f3eb50e78.tar.bz2
txr-3cad8dfa357c5733c94e2a301da9184f3eb50e78.zip
New uslot function and usl macro.
* struct.c (struct_init): Register uslot intrinsic function. (uslot_fun): New static function. (uslot): New function. * struct.h (uslot): Declared. * share/txr/stdlib/struct.tl (usl): New macro. * lisplib.c (struct_set_entries): Add usl macro. * txr.1: Documented uslot and usl.
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/struct.c b/struct.c
index 040b43be..acd28f68 100644
--- a/struct.c
+++ b/struct.c
@@ -133,6 +133,7 @@ void struct_init(void)
reg_fun(intern(lit("struct-type"), user_package), func_n1(struct_type));
reg_fun(intern(lit("method"), user_package), func_n2(method));
reg_fun(intern(lit("super-method"), user_package), func_n2(super_method));
+ reg_fun(intern(lit("uslot"), user_package), func_n1(uslot));
reg_fun(intern(lit("umethod"), user_package), func_n1(umethod));
}
@@ -791,6 +792,25 @@ val super_method(val strct, val slotsym)
return func_f0v(cons(super_slot, strct), method_fun);
}
+static val uslot_fun(val sym, val strct)
+{
+ val self = lit("uslot");
+ struct struct_inst *si = struct_handle(strct, self);
+
+ if (symbolp(sym)) {
+ loc ptr = lookup_slot(strct, si, sym);
+ if (!nullocp(ptr))
+ return deref(ptr);
+ }
+
+ no_such_slot(self, si->type, sym);
+}
+
+val uslot(val slot)
+{
+ return func_f1(slot, uslot_fun);
+}
+
static val umethod_fun(val sym, struct args *args)
{
val self = lit("umethod");