core: Add hash_clear!.

* src/hash.c (hash_clear_x): New builtin.
* include/mes/builtins.h: Declare it.
* src/builtins.c (mes_builtins): Register it.
This commit is contained in:
Jan Nieuwenhuizen 2019-11-13 08:27:44 +01:00 committed by Jan (janneke) Nieuwenhuizen
parent d481048c10
commit 126aa3f5eb
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
3 changed files with 12 additions and 0 deletions

View File

@ -73,6 +73,7 @@ struct scm *hash_table_printer (struct scm *table);
struct scm *make_hash_table (struct scm *x);
struct scm *hash_table_p (struct scm *x);
struct scm *hash_map_to_list (struct scm *proc, struct scm *table);
struct scm *hash_clear_x (struct scm *table);
/* src/lib.c */
struct scm *type_ (struct scm *x);
struct scm *car_ (struct scm *x);

View File

@ -183,6 +183,7 @@ mes_builtins (struct scm *a) /*:((internal)) */
a = init_builtin (builtin_type, "hash-table?", 1, &hash_table_p, a);
a = init_builtin (builtin_type, "make-hash-table", -1, &make_hash_table, a);
a = init_builtin (builtin_type, "hash-map->list", 2, &hash_map_to_list, a);
a = init_builtin (builtin_type, "hash-clear!", 1, &hash_clear_x, a);
/* src/lib.c */
a = init_builtin (builtin_type, "core:type", 1, &type_, a);
a = init_builtin (builtin_type, "core:car", 1, &car_, a);

View File

@ -251,3 +251,13 @@ hash_map_to_list (struct scm *proc, struct scm *table)
}
return lst;
}
struct scm *
hash_clear_x (struct scm *table)
{
struct scm *s = struct_ref_ (table, 3);
long size = s->value;
struct scm *buckets = make_vector_ (size, cell_unspecified);
struct_set_x_ (table, 4, buckets);
return cell_unspecified;
}