From a0e73c52f260e67383afd5792c1c540e9a20c339 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 20 Oct 2019 13:24:43 +0200 Subject: [PATCH] core: Prepare for M2-Planet: hash.c. * src/hash.c: Rewrite C constructs not supported by M2-Planet. --- src/hash.c | 17 +++++++++-------- src/lib.c | 10 +++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/hash.c b/src/hash.c index e85777d7..56a8bae4 100644 --- a/src/hash.c +++ b/src/hash.c @@ -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); } diff --git a/src/lib.c b/src/lib.c index 424a1ccc..0d68cbbf 100644 --- a/src/lib.c +++ b/src/lib.c @@ -281,14 +281,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)); @@ -306,7 +306,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; @@ -331,7 +331,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; @@ -342,7 +342,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;