core: Prepare for M2-Planet: hash.c.
* src/hash.c: Rewrite C constructs not supported by M2-Planet.
This commit is contained in:
parent
948c6ef91d
commit
7d82ad9a85
19
src/hash.c
19
src/hash.c
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* 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.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -28,7 +28,7 @@ int
|
||||||
hash_cstring (char const *s, long size)
|
hash_cstring (char const *s, long size)
|
||||||
{
|
{
|
||||||
int hash = s[0] * 37;
|
int hash = s[0] * 37;
|
||||||
if (s[0] && s[1])
|
if (s[0] != 0 && s[1] != 0)
|
||||||
hash = hash + s[1] * 43;
|
hash = hash + s[1] * 43;
|
||||||
assert (size);
|
assert (size);
|
||||||
hash = hash % size;
|
hash = hash % size;
|
||||||
|
@ -39,7 +39,7 @@ int
|
||||||
hashq_ (SCM x, long size)
|
hashq_ (SCM x, long size)
|
||||||
{
|
{
|
||||||
if (TYPE (x) == TSPECIAL || TYPE (x) == TSYMBOL)
|
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));
|
error (cell_symbol_system_error, cons (MAKE_STRING0 ("hashq_: not a symbol"), x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,8 @@ hash_table_printer (SCM table)
|
||||||
fdputc (' ', __stdout);
|
fdputc (' ', __stdout);
|
||||||
SCM buckets = struct_ref_ (table, 4);
|
SCM buckets = struct_ref_ (table, 4);
|
||||||
fdputs ("buckets: ", __stdout);
|
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);
|
SCM e = vector_ref_ (buckets, i);
|
||||||
if (e != cell_unspecified)
|
if (e != cell_unspecified)
|
||||||
|
@ -203,21 +204,20 @@ hash_table_printer (SCM table)
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
make_hashq_type () ///((internal))
|
make_hashq_type () /*:((internal)) */
|
||||||
{
|
{
|
||||||
SCM record_type = cell_symbol_record_type; // FIXME
|
|
||||||
SCM fields = cell_nil;
|
SCM fields = cell_nil;
|
||||||
fields = cons (cell_symbol_buckets, fields);
|
fields = cons (cell_symbol_buckets, fields);
|
||||||
fields = cons (cell_symbol_size, fields);
|
fields = cons (cell_symbol_size, fields);
|
||||||
fields = cons (fields, cell_nil);
|
fields = cons (fields, cell_nil);
|
||||||
fields = cons (cell_symbol_hashq_table, fields);
|
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
|
SCM
|
||||||
make_hash_table_ (long size)
|
make_hash_table_ (long size)
|
||||||
{
|
{
|
||||||
if (!size)
|
if (size == 0)
|
||||||
size = 100;
|
size = 100;
|
||||||
SCM hashq_type = make_hashq_type ();
|
SCM hashq_type = make_hashq_type ();
|
||||||
|
|
||||||
|
@ -226,7 +226,8 @@ make_hash_table_ (long size)
|
||||||
values = cons (buckets, values);
|
values = cons (buckets, values);
|
||||||
values = cons (MAKE_NUMBER (size), values);
|
values = cons (MAKE_NUMBER (size), values);
|
||||||
values = cons (cell_symbol_hashq_table, 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);
|
return make_struct (hashq_type, values, cell_unspecified);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/lib.c
10
src/lib.c
|
@ -282,14 +282,14 @@ write_port_ (SCM x, SCM p)
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
fdisplay_ (SCM x, int fd, int write_p) ///((internal))
|
fdisplay_ (SCM x, int fd, int write_p) /**((internal))*/
|
||||||
{
|
{
|
||||||
g_depth = 5;
|
g_depth = 5;
|
||||||
return display_helper (x, 0, "", fd, write_p);
|
return display_helper (x, 0, "", fd, write_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
exit_ (SCM x) ///((name . "exit"))
|
exit_ (SCM x) /**((name . "exit"))*/
|
||||||
{
|
{
|
||||||
assert (TYPE (x) == TNUMBER);
|
assert (TYPE (x) == TNUMBER);
|
||||||
exit (VALUE (x));
|
exit (VALUE (x));
|
||||||
|
@ -307,7 +307,7 @@ frame_printer (SCM frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
make_frame_type () ///((internal))
|
make_frame_type () /**((internal))*/
|
||||||
{
|
{
|
||||||
SCM record_type = cell_symbol_record_type; // FIXME
|
SCM record_type = cell_symbol_record_type; // FIXME
|
||||||
SCM fields = cell_nil;
|
SCM fields = cell_nil;
|
||||||
|
@ -336,7 +336,7 @@ make_frame (SCM stack, long index)
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
make_stack_type () ///((internal))
|
make_stack_type () /**((internal))*/
|
||||||
{
|
{
|
||||||
SCM record_type = cell_symbol_record_type; // FIXME
|
SCM record_type = cell_symbol_record_type; // FIXME
|
||||||
SCM fields = cell_nil;
|
SCM fields = cell_nil;
|
||||||
|
@ -347,7 +347,7 @@ make_stack_type () ///((internal))
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
make_stack (SCM stack) ///((arity . n))
|
make_stack (SCM stack) /**((arity . n))*/
|
||||||
{
|
{
|
||||||
SCM stack_type = make_stack_type ();
|
SCM stack_type = make_stack_type ();
|
||||||
long size = (STACK_SIZE - g_stack) / FRAME_SIZE;
|
long size = (STACK_SIZE - g_stack) / FRAME_SIZE;
|
||||||
|
|
Loading…
Reference in a new issue