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:
parent
7932d4bad7
commit
0f951cac5d
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
27
src/gc.c
27
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)) */
|
||||
{
|
||||
|
|
27
src/string.c
27
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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue