summaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-06 21:03:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-06 21:03:52 -0700
commit829f02b346d4060e64ec5847cbd0f066edd4a144 (patch)
treee49bb65e98537b833e1d49a88008b30b175a96c2 /struct.c
parent4adbf9319259d94604c9f5b5d27c3b3e3e0118f0 (diff)
downloadtxr-829f02b346d4060e64ec5847cbd0f066edd4a144.tar.gz
txr-829f02b346d4060e64ec5847cbd0f066edd4a144.tar.bz2
txr-829f02b346d4060e64ec5847cbd0f066edd4a144.zip
New function: clear-struct.
* struct.c (clear_struct): New function. (struct_init): Register clear-struct intrinsic. * struct.h (struct_init): Declared. * txr.1: documented clear-struct.
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/struct.c b/struct.c
index 4ff01a74..43a30a65 100644
--- a/struct.c
+++ b/struct.c
@@ -111,6 +111,7 @@ void struct_init(void)
reg_fun(intern(lit("super"), user_package), func_n1(super));
reg_fun(intern(lit("make-struct"), user_package), func_n2v(make_struct));
reg_fun(intern(lit("copy-struct"), user_package), func_n1(copy_struct));
+ reg_fun(intern(lit("clear-struct"), user_package), func_n2o(clear_struct, 1));
reg_fun(intern(lit("slot"), user_package), func_n2(slot));
reg_fun(intern(lit("slotset"), user_package), func_n3(slotset));
reg_fun(intern(lit("static-slot"), user_package), func_n2(static_slot));
@@ -393,6 +394,20 @@ val copy_struct(val strct)
return copy;
}
+val clear_struct(val strct, val value)
+{
+ const val self = lit("clear-struct");
+ struct struct_inst *si = struct_handle(strct, self);
+ struct struct_type *st = coerce(struct struct_type *, si->type->co.handle);
+ val clear_val = default_bool_arg(value);
+ cnum i;
+
+ for (i = 0; i < st->nslots; i++)
+ si->slot[i] = clear_val;
+
+ return strct;
+}
+
static int cache_set_lookup(slot_cache_entry_t *set, cnum id)
{
if (set[0].id == id)