summaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-03 17:16:51 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-03 17:16:51 -0700
commitf55a50575bfe83ad320612833811640e5d8f8f12 (patch)
tree31db049b207ee494a01d0ab2fe66a86ba5366e34 /struct.c
parent38a2d429dfdc271ded13b3e446d75285fc875511 (diff)
downloadtxr-f55a50575bfe83ad320612833811640e5d8f8f12.tar.gz
txr-f55a50575bfe83ad320612833811640e5d8f8f12.tar.bz2
txr-f55a50575bfe83ad320612833811640e5d8f8f12.zip
New umeth and umethod macro and function.
* share/txr/stdlib/struct.tl (umeth): New macro. * struct.c (struct_init): Registered umethod intrinsic. (umethod_fun): New static function. (umethod): New function. * txr.1: Documented.
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/struct.c b/struct.c
index 30f0ad15..1456b3b1 100644
--- a/struct.c
+++ b/struct.c
@@ -126,6 +126,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("umethod"), user_package), func_n1(umethod));
}
static noreturn void no_such_struct(val ctx, val sym)
@@ -691,6 +692,32 @@ val super_method(val strct, val slotsym)
return func_f0v(cons(super_slot, strct), method_fun);
}
+static val umethod_fun(val sym, struct args *args)
+{
+ val self = lit("umethod");
+
+ if (args->argc == 0) {
+ uw_throwf(error_s, lit("~a: object argument required to call ~s"),
+ self, env, nao);
+ } else {
+ val strct = args->arg[0];
+ struct struct_inst *si = struct_handle(strct, self);
+
+ if (symbolp(sym)) {
+ loc ptr = lookup_slot(strct, si, sym);
+ if (!nullocp(ptr))
+ return generic_funcall(deref(ptr), args);
+ }
+
+ no_such_slot(self, si->type, sym);
+ }
+}
+
+val umethod(val slot)
+{
+ return func_f0v(slot, umethod_fun);
+}
+
static void struct_inst_print(val obj, val out, val pretty)
{
struct struct_inst *si = coerce(struct struct_inst *, obj->co.handle);