core: Prepare for M2-Planet: hash.c.

* src/hash.c: Rewrite C constructs not supported by M2-Planet.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-04-19 13:24:43 +02:00
parent 948c6ef91d
commit 7d82ad9a85
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
2 changed files with 15 additions and 14 deletions

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -28,7 +28,7 @@ int
hash_cstring (char const *s, long size)
{
int hash = s[0] * 37;
if (s[0] && s[1])
if (s[0] != 0 && s[1] != 0)
hash = hash + s[1] * 43;
assert (size);
hash = hash % size;
@ -39,7 +39,7 @@ int
hashq_ (SCM x, long size)
{
if (TYPE (x) == TSPECIAL || TYPE (x) == TSYMBOL)
return hash_cstring (CSTRING (x), size); // FIXME: hash x directly
return hash_cstring (CSTRING (x), size); /* FIXME: hash x directly. */
error (cell_symbol_system_error, cons (MAKE_STRING0 ("hashq_: not a symbol"), x));
}
@ -183,7 +183,8 @@ hash_table_printer (SCM table)
fdputc (' ', __stdout);
SCM buckets = struct_ref_ (table, 4);
fdputs ("buckets: ", __stdout);
for (int i = 0; i < LENGTH (buckets); i++)
int i;
for (i = 0; i < LENGTH (buckets); i = i + 1)
{
SCM e = vector_ref_ (buckets, i);
if (e != cell_unspecified)
@ -203,21 +204,20 @@ hash_table_printer (SCM table)
}
SCM
make_hashq_type () ///((internal))
make_hashq_type () /*:((internal)) */
{
SCM record_type = cell_symbol_record_type; // FIXME
SCM fields = cell_nil;
fields = cons (cell_symbol_buckets, fields);
fields = cons (cell_symbol_size, fields);
fields = cons (fields, cell_nil);
fields = cons (cell_symbol_hashq_table, fields);
return make_struct (record_type, fields, cell_unspecified);
return make_struct (cell_symbol_record_type, fields, cell_unspecified);
}
SCM
make_hash_table_ (long size)
{
if (!size)
if (size == 0)
size = 100;
SCM hashq_type = make_hashq_type ();
@ -226,7 +226,8 @@ make_hash_table_ (long size)
values = cons (buckets, values);
values = cons (MAKE_NUMBER (size), values);
values = cons (cell_symbol_hashq_table, values);
//FIXME: symbol/printer return make_struct (hashq_type, values, cstring_to_symbol ("hash-table-printer");
/*FIXME: symbol/printer
return make_struct (hashq_type, values, cstring_to_symbol ("hash-table-printer");*/
return make_struct (hashq_type, values, cell_unspecified);
}

View File

@ -282,14 +282,14 @@ write_port_ (SCM x, SCM p)
}
SCM
fdisplay_ (SCM x, int fd, int write_p) ///((internal))
fdisplay_ (SCM x, int fd, int write_p) /**((internal))*/
{
g_depth = 5;
return display_helper (x, 0, "", fd, write_p);
}
SCM
exit_ (SCM x) ///((name . "exit"))
exit_ (SCM x) /**((name . "exit"))*/
{
assert (TYPE (x) == TNUMBER);
exit (VALUE (x));
@ -307,7 +307,7 @@ frame_printer (SCM frame)
}
SCM
make_frame_type () ///((internal))
make_frame_type () /**((internal))*/
{
SCM record_type = cell_symbol_record_type; // FIXME
SCM fields = cell_nil;
@ -336,7 +336,7 @@ make_frame (SCM stack, long index)
}
SCM
make_stack_type () ///((internal))
make_stack_type () /**((internal))*/
{
SCM record_type = cell_symbol_record_type; // FIXME
SCM fields = cell_nil;
@ -347,7 +347,7 @@ make_stack_type () ///((internal))
}
SCM
make_stack (SCM stack) ///((arity . n))
make_stack (SCM stack) /**((arity . n))*/
{
SCM stack_type = make_stack_type ();
long size = (STACK_SIZE - g_stack) / FRAME_SIZE;