summaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-06 21:32:34 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-06 21:32:34 -0700
commit8720843f7a55991fb52ca1de7be2dab341ae7517 (patch)
tree66020514008dcfbcd328a02913a3a34edbed00c9 /struct.c
parent8beabcd33ac984ee454f0871ffd45b940e279732 (diff)
downloadtxr-8720843f7a55991fb52ca1de7be2dab341ae7517.tar.gz
txr-8720843f7a55991fb52ca1de7be2dab341ae7517.tar.bz2
txr-8720843f7a55991fb52ca1de7be2dab341ae7517.zip
New function: reset-struct.
* struct.c (reset_struct): New function. (struct_init): Register reset_struct intrinsic. * struct.h (reset_struct): Declared. * txr.1: documented reset-struct.
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/struct.c b/struct.c
index 064d0e21..7162dc3e 100644
--- a/struct.c
+++ b/struct.c
@@ -113,6 +113,7 @@ void struct_init(void)
reg_fun(intern(lit("copy-struct"), user_package), func_n1(copy_struct));
reg_fun(intern(lit("replace-struct"), user_package), func_n2(replace_struct));
reg_fun(intern(lit("clear-struct"), user_package), func_n2o(clear_struct, 1));
+ reg_fun(intern(lit("reset-struct"), user_package), func_n1(reset_struct));
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));
@@ -425,6 +426,21 @@ val replace_struct(val target, val source)
return target;
}
+val reset_struct(val strct)
+{
+ const val self = lit("reset-struct");
+ struct struct_inst *si = struct_handle(strct, self);
+ struct struct_type *st = coerce(struct struct_type *, si->type->co.handle);
+ cnum i;
+
+ for (i = 0; i < st->nslots; i++)
+ si->slot[i] = nil;
+
+ call_initfun_chain(st, strct);
+
+ return strct;
+}
+
static int cache_set_lookup(slot_cache_entry_t *set, cnum id)
{
if (set[0].id == id)