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.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-05-18 21:57:55 +02:00
parent 7932d4bad7
commit 0f951cac5d
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
4 changed files with 27 additions and 33 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)) */
{

View File

@ -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)
{