From 0f951cac5df998270161e33211a07f99330600ba Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Mon, 18 May 2020 21:57:55 +0200 Subject: [PATCH] core: Remove macros from cell creation: make_bytes. * src/gc.c (bytes_cells, make_bytes): Move from string.c. * include/mes/macros.h (MAKE_BYTES0, NAME_SYMBOL): Remove. * include/mes/m2.h: Likewise. --- include/mes/m2.h | 3 --- include/mes/macros.h | 3 --- src/gc.c | 27 +++++++++++++++++++++++++++ src/string.c | 27 --------------------------- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/include/mes/m2.h b/include/mes/m2.h index 812e40fd..1c61a213 100644 --- a/include/mes/m2.h +++ b/include/mes/m2.h @@ -90,9 +90,6 @@ struct timeval #define CSTRING(x) CBYTES (STRING (x)) -#define MAKE_BYTES0(x) make_bytes (x, strlen (x)) -#define NAME_SYMBOL(symbol,name) {size_t s = strlen (name); CAR (symbol) = s; CDR (symbol) = make_bytes (name, s);} - #define MAKE_CHAR(n) make_cell (TCHAR, 0, n) #define MAKE_CONTINUATION(n) make_cell (TCONTINUATION, n, g_stack) #define MAKE_NUMBER(n) make_cell (TNUMBER, 0, n) diff --git a/include/mes/macros.h b/include/mes/macros.h index f2a816c2..f4e61115 100644 --- a/include/mes/macros.h +++ b/include/mes/macros.h @@ -58,9 +58,6 @@ #define CSTRING(x) CBYTES (STRING (x)) -#define MAKE_BYTES0(x) make_bytes (x, strlen (x)) -#define NAME_SYMBOL(symbol,name) {size_t s = strlen (name); CAR (symbol) = s; CDR (symbol) = make_bytes (name, s);} - #define MAKE_CHAR(n) make_cell (TCHAR, 0, n) #define MAKE_CONTINUATION(n) make_cell (TCONTINUATION, n, g_stack) #define MAKE_NUMBER(n) make_cell (TNUMBER, 0, (long)n) diff --git a/src/gc.c b/src/gc.c index 3ca9fa2e..e291a199 100644 --- a/src/gc.c +++ b/src/gc.c @@ -116,6 +116,33 @@ cons (SCM x, SCM y) return make_cell (TPAIR, x, y); } +size_t +bytes_cells (size_t length) +{ + return (1 + sizeof (long) + sizeof (long) + length + sizeof (SCM)) / sizeof (SCM); +} + +SCM +make_bytes (char const *s, size_t length) +{ + size_t size = bytes_cells (length); + SCM x = alloc (size); + TYPE (x) = TBYTES; + LENGTH (x) = length; +#if __M2_PLANET__ + char *p = &g_cells[x]; + p = p + 2 * sizeof (SCM); +#else + char *p = &CDR (x); +#endif + if (length == 0) + p[0] = 0; + else + memcpy (p, s, length + 1); + + return x; +} + SCM gc_up_arena () /*:((internal)) */ { diff --git a/src/string.c b/src/string.c index 4e6b91fe..c2cbe5e0 100644 --- a/src/string.c +++ b/src/string.c @@ -58,33 +58,6 @@ list_to_cstring (SCM list, size_t *size) return g_buf; } -size_t -bytes_cells (size_t length) -{ - return (1 + sizeof (long) + sizeof (long) + length + sizeof (SCM)) / sizeof (SCM); -} - -SCM -make_bytes (char const *s, size_t length) -{ - size_t size = bytes_cells (length); - SCM x = alloc (size); - TYPE (x) = TBYTES; - LENGTH (x) = length; -#if __M2_PLANET__ - char *p = &g_cells[x]; - p = p + 2 * sizeof (SCM); -#else - char *p = &CDR (x); -#endif - if (length == 0) - p[0] = 0; - else - memcpy (p, s, length + 1); - - return x; -} - SCM make_string (char const *s, size_t length) {