2018-10-15 11:36:19 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
core: Prepare for M2-Planet 1.7.0.
* src/eval-apply.c (expand_variable_, apply_builtin): Declare variables
at toplevel.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Likewise.
* src/hash.c (hash_table_printer): Likewise.
* src/lib.c (equal2_p): Likewise.
* src/math.c (greater_p, less_p, is_p, minus, plus, divide, multiply,
logand, logior, logxor): Likewise.
* src/posix.c (current_input_port, execl_): Likewise.
* src/reader.c (reader_read_string): Likewise.
* src/stack.c (make_stack): Likewise.
* src/string.c (list_to_cstring, bytes_to_list, string_append):
Likewise.
* src/struct.c (make_struct): Likewise.
* src/vector.c (vector_to_list): Likewise.
2020-12-29 12:38:38 +00:00
|
|
|
* Copyright © 2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2018-10-15 11:36:19 +00:00
|
|
|
*
|
|
|
|
* This file is part of GNU Mes.
|
|
|
|
*
|
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-08 13:36:22 +00:00
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2018-10-15 11:36:19 +00:00
|
|
|
|
|
|
|
int
|
2019-05-18 11:27:42 +00:00
|
|
|
hash_cstring (char const *s, long size)
|
2018-10-15 11:36:19 +00:00
|
|
|
{
|
2018-11-11 15:25:36 +00:00
|
|
|
int hash = s[0] * 37;
|
2020-07-16 19:19:06 +00:00
|
|
|
if (s[0] != 0)
|
|
|
|
if (s[1] != 0)
|
2020-07-16 19:56:49 +00:00
|
|
|
hash = hash + (s[1] * 43);
|
2020-07-14 13:57:49 +00:00
|
|
|
assert_msg (size != 0, "size");
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
hash = hash % size;
|
|
|
|
return hash;
|
2018-10-15 11:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-10-18 09:34:32 +00:00
|
|
|
hashq_ (struct scm *x, long size)
|
2018-10-15 11:36:19 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->type == TSPECIAL || x->type == TSYMBOL)
|
|
|
|
return hash_cstring (cell_bytes (x->string), size); /* FIXME: hash x directly. */
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2020-05-18 20:35:12 +00:00
|
|
|
error (cell_symbol_system_error, cons (make_string0 ("hashq_: not a symbol"), x));
|
2018-10-15 11:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-10-18 09:34:32 +00:00
|
|
|
hash_ (struct scm *x, long size)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->type != TSTRING)
|
2020-07-18 06:12:41 +00:00
|
|
|
{
|
|
|
|
eputs ("hash_ failed, not a string:");
|
|
|
|
display_error_ (x);
|
|
|
|
assert_msg (0, "0");
|
|
|
|
}
|
2020-10-18 09:34:32 +00:00
|
|
|
return hash_cstring (cell_bytes (x->string), size);
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
hashq (struct scm *x, struct scm *size)
|
2018-10-15 11:36:19 +00:00
|
|
|
{
|
2020-07-18 06:12:41 +00:00
|
|
|
eputs ("hashq not supporteed\n");
|
2020-05-17 14:07:04 +00:00
|
|
|
assert_msg (0, "0");
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
hash (struct scm *x, struct scm *size)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
{
|
2020-07-18 06:12:41 +00:00
|
|
|
eputs ("hash not supporteed\n");
|
2020-05-17 14:07:04 +00:00
|
|
|
assert_msg (0, "0");
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
hashq_get_handle (struct scm *table, struct scm *key, struct scm *dflt)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *s = struct_ref_ (table, 3);
|
|
|
|
long size = s->value;
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
unsigned hash = hashq_ (key, size);
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *buckets = struct_ref_ (table, 4);
|
|
|
|
struct scm *bucket = vector_ref_ (buckets, hash);
|
|
|
|
struct scm *x = cell_f;
|
|
|
|
if (dflt->type == TPAIR)
|
|
|
|
x = dflt->car;
|
|
|
|
if (bucket->type == TPAIR)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
x = assq (key, bucket);
|
|
|
|
return x;
|
2018-10-15 11:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
hashq_ref (struct scm *table, struct scm *key, struct scm *dflt)
|
2018-10-15 11:36:19 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *x = hashq_get_handle (table, key, dflt);
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
if (x != cell_f)
|
2020-10-18 09:34:32 +00:00
|
|
|
x = x->cdr;
|
2018-10-15 11:36:19 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
hash_ref (struct scm *table, struct scm *key, struct scm *dflt)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *s = struct_ref_ (table, 3);
|
|
|
|
long size = s->value;
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
unsigned hash = hash_ (key, size);
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *buckets = struct_ref_ (table, 4);
|
|
|
|
struct scm *bucket = vector_ref_ (buckets, hash);
|
|
|
|
struct scm *x = cell_f;
|
|
|
|
if (dflt->type == TPAIR)
|
|
|
|
x = dflt->car;
|
|
|
|
if (bucket->type == TPAIR)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
{
|
|
|
|
x = assoc (key, bucket);
|
|
|
|
if (x != cell_f)
|
2020-10-18 09:34:32 +00:00
|
|
|
x = x->cdr;
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
hash_set_x_ (struct scm *table, unsigned hash, struct scm *key, struct scm *value)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *buckets = struct_ref_ (table, 4);
|
|
|
|
struct scm *bucket = vector_ref_ (buckets, hash);
|
|
|
|
if (bucket->type != TPAIR)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
bucket = cell_nil;
|
|
|
|
bucket = acons (key, value, bucket);
|
|
|
|
vector_set_x_ (buckets, hash, bucket);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
hashq_set_x (struct scm *table, struct scm *key, struct scm *value)
|
2018-10-15 11:36:19 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *s = struct_ref_ (table, 3);
|
|
|
|
long size = s->value;
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
unsigned hash = hashq_ (key, size);
|
|
|
|
return hash_set_x_ (table, hash, key, value);
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
hash_set_x (struct scm *table, struct scm *key, struct scm *value)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *s = struct_ref_ (table, 3);
|
|
|
|
long size = s->value;
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
unsigned hash = hash_ (key, size);
|
|
|
|
return hash_set_x_ (table, hash, key, value);
|
2018-10-15 11:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
hash_table_printer (struct scm *table)
|
2018-10-15 13:45:41 +00:00
|
|
|
{
|
2019-05-18 11:27:42 +00:00
|
|
|
fdputs ("#<", __stdout);
|
|
|
|
display_ (struct_ref_ (table, 2));
|
|
|
|
fdputc (' ', __stdout);
|
|
|
|
fdputs ("size: ", __stdout);
|
|
|
|
display_ (struct_ref_ (table, 3));
|
|
|
|
fdputc (' ', __stdout);
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *buckets = struct_ref_ (table, 4);
|
2019-03-02 11:35:18 +00:00
|
|
|
fdputs ("buckets: ", __stdout);
|
2020-04-19 11:24:43 +00:00
|
|
|
int i;
|
core: Prepare for M2-Planet 1.7.0.
* src/eval-apply.c (expand_variable_, apply_builtin): Declare variables
at toplevel.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Likewise.
* src/hash.c (hash_table_printer): Likewise.
* src/lib.c (equal2_p): Likewise.
* src/math.c (greater_p, less_p, is_p, minus, plus, divide, multiply,
logand, logior, logxor): Likewise.
* src/posix.c (current_input_port, execl_): Likewise.
* src/reader.c (reader_read_string): Likewise.
* src/stack.c (make_stack): Likewise.
* src/string.c (list_to_cstring, bytes_to_list, string_append):
Likewise.
* src/struct.c (make_struct): Likewise.
* src/vector.c (vector_to_list): Likewise.
2020-12-29 12:38:38 +00:00
|
|
|
struct scm *e;
|
2020-10-18 09:34:32 +00:00
|
|
|
for (i = 0; i < buckets->length; i = i + 1)
|
2018-10-15 13:45:41 +00:00
|
|
|
{
|
core: Prepare for M2-Planet 1.7.0.
* src/eval-apply.c (expand_variable_, apply_builtin): Declare variables
at toplevel.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Likewise.
* src/hash.c (hash_table_printer): Likewise.
* src/lib.c (equal2_p): Likewise.
* src/math.c (greater_p, less_p, is_p, minus, plus, divide, multiply,
logand, logior, logxor): Likewise.
* src/posix.c (current_input_port, execl_): Likewise.
* src/reader.c (reader_read_string): Likewise.
* src/stack.c (make_stack): Likewise.
* src/string.c (list_to_cstring, bytes_to_list, string_append):
Likewise.
* src/struct.c (make_struct): Likewise.
* src/vector.c (vector_to_list): Likewise.
2020-12-29 12:38:38 +00:00
|
|
|
e = vector_ref_ (buckets, i);
|
2018-10-15 13:45:41 +00:00
|
|
|
if (e != cell_unspecified)
|
|
|
|
{
|
2019-03-02 11:35:18 +00:00
|
|
|
fdputc ('[', __stdout);
|
2020-10-18 09:34:32 +00:00
|
|
|
while (e->type == TPAIR)
|
2018-10-15 13:45:41 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
write_ (e->car->car);
|
|
|
|
e = e->cdr;
|
|
|
|
if (e->type == TPAIR)
|
2019-03-02 11:35:18 +00:00
|
|
|
fdputc (' ', __stdout);
|
2018-10-15 13:45:41 +00:00
|
|
|
}
|
2019-03-02 11:35:18 +00:00
|
|
|
fdputs ("]\n ", __stdout);
|
2018-10-15 13:45:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-02 11:35:18 +00:00
|
|
|
fdputc ('>', __stdout);
|
2018-10-15 13:45:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
2020-04-19 11:24:43 +00:00
|
|
|
make_hashq_type () /*:((internal)) */
|
2018-10-15 13:45:41 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *fields = cell_nil;
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
fields = cons (cell_symbol_buckets, fields);
|
|
|
|
fields = cons (cell_symbol_size, fields);
|
2018-10-15 14:57:00 +00:00
|
|
|
fields = cons (fields, cell_nil);
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
fields = cons (cell_symbol_hashq_table, fields);
|
2020-04-19 11:24:43 +00:00
|
|
|
return make_struct (cell_symbol_record_type, fields, cell_unspecified);
|
2018-10-15 13:45:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
2018-10-15 11:36:19 +00:00
|
|
|
make_hash_table_ (long size)
|
|
|
|
{
|
2020-04-19 11:24:43 +00:00
|
|
|
if (size == 0)
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
size = 100;
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *hashq_type = make_hashq_type ();
|
2018-10-15 18:42:10 +00:00
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *buckets = make_vector_ (size, cell_unspecified);
|
|
|
|
struct scm *values = cell_nil;
|
2018-10-15 13:45:41 +00:00
|
|
|
values = cons (buckets, values);
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2020-05-18 20:35:12 +00:00
|
|
|
values = cons (make_number (size), values);
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
values = cons (cell_symbol_hashq_table, values);
|
2020-04-19 11:24:43 +00:00
|
|
|
/*FIXME: symbol/printer
|
|
|
|
return make_struct (hashq_type, values, cstring_to_symbol ("hash-table-printer");*/
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2019-01-04 08:55:16 +00:00
|
|
|
return make_struct (hashq_type, values, cell_unspecified);
|
2018-10-15 11:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
make_hash_table (struct scm *x)
|
2018-10-15 11:36:19 +00:00
|
|
|
{
|
|
|
|
long size = 0;
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->type == TPAIR)
|
2018-10-15 11:36:19 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
assert_msg (x->type == TNUMBER, "x->type == TNUMBER");
|
|
|
|
size = x->value;
|
2018-10-15 11:36:19 +00:00
|
|
|
}
|
|
|
|
return make_hash_table_ (size);
|
|
|
|
}
|