core: Remove CBYTES, CSTRING, NCBYTES macros.
* src/gc.c (cell_bytes, news_bytes): New function. * include/mes/macros.h (CBYTES, CSTRING, NCBYTES): Remove. Update users. * include/mes/m2.h: Likewise.
This commit is contained in:
parent
a25dff6837
commit
94e40691ba
|
@ -83,13 +83,10 @@ struct timeval
|
||||||
|
|
||||||
#define NLENGTH(x) ((x*struct_size)+g_news)->car
|
#define NLENGTH(x) ((x*struct_size)+g_news)->car
|
||||||
|
|
||||||
#define NCBYTES(x) (((x*struct_size)+g_news) + 8)
|
|
||||||
#define NVALUE(x) ((x*struct_size)+g_news)->cdr
|
#define NVALUE(x) ((x*struct_size)+g_news)->cdr
|
||||||
#define NSTRING(x) ((x*struct_size)+g_news)->cdr
|
#define NSTRING(x) ((x*struct_size)+g_news)->cdr
|
||||||
#define NVECTOR(x) ((x*struct_size)+g_news)->cdr
|
#define NVECTOR(x) ((x*struct_size)+g_news)->cdr
|
||||||
|
|
||||||
#define CSTRING(x) CBYTES (STRING (x))
|
|
||||||
|
|
||||||
#define CAAR(x) CAR (CAR (x))
|
#define CAAR(x) CAR (CAR (x))
|
||||||
#define CADR(x) CAR (CDR (x))
|
#define CADR(x) CAR (CDR (x))
|
||||||
#define CDAR(x) CDR (CAR (x))
|
#define CDAR(x) CDR (CAR (x))
|
||||||
|
|
|
@ -37,8 +37,6 @@
|
||||||
#define CLOSURE(x) g_cells[x].cdr
|
#define CLOSURE(x) g_cells[x].cdr
|
||||||
#define CONTINUATION(x) g_cells[x].cdr
|
#define CONTINUATION(x) g_cells[x].cdr
|
||||||
|
|
||||||
#define CBYTES(x) (char*)&g_cells[x].cdr
|
|
||||||
|
|
||||||
#define MACRO(x) g_cells[x].car
|
#define MACRO(x) g_cells[x].car
|
||||||
#define NAME(x) g_cells[x].cdr
|
#define NAME(x) g_cells[x].cdr
|
||||||
#define PORT(x) g_cells[x].car
|
#define PORT(x) g_cells[x].car
|
||||||
|
@ -48,13 +46,10 @@
|
||||||
#define VECTOR(x) g_cells[x].cdr
|
#define VECTOR(x) g_cells[x].cdr
|
||||||
|
|
||||||
#define NLENGTH(x) g_news[x].car
|
#define NLENGTH(x) g_news[x].car
|
||||||
#define NCBYTES(x) (char*)&g_news[x].cdr
|
|
||||||
#define NVALUE(x) g_news[x].cdr
|
#define NVALUE(x) g_news[x].cdr
|
||||||
#define NSTRING(x) g_news[x].cdr
|
#define NSTRING(x) g_news[x].cdr
|
||||||
#define NVECTOR(x) g_news[x].cdr
|
#define NVECTOR(x) g_news[x].cdr
|
||||||
|
|
||||||
#define CSTRING(x) CBYTES (STRING (x))
|
|
||||||
|
|
||||||
#define CAAR(x) CAR (CAR (x))
|
#define CAAR(x) CAR (CAR (x))
|
||||||
#define CADR(x) CAR (CDR (x))
|
#define CADR(x) CAR (CDR (x))
|
||||||
#define CDAR(x) CDR (CAR (x))
|
#define CDAR(x) CDR (CAR (x))
|
||||||
|
|
|
@ -78,7 +78,6 @@ SCM alloc (long n);
|
||||||
SCM apply (SCM f, SCM x, SCM a);
|
SCM apply (SCM f, SCM x, SCM a);
|
||||||
SCM apply_builtin (SCM fn, SCM x);
|
SCM apply_builtin (SCM fn, SCM x);
|
||||||
SCM builtin_name (SCM builtin);
|
SCM builtin_name (SCM builtin);
|
||||||
FUNCTION builtin_function (SCM builtin);
|
|
||||||
SCM cstring_to_list (char const *s);
|
SCM cstring_to_list (char const *s);
|
||||||
SCM cstring_to_symbol (char const *s);
|
SCM cstring_to_symbol (char const *s);
|
||||||
SCM fdisplay_ (SCM, int, int);
|
SCM fdisplay_ (SCM, int, int);
|
||||||
|
@ -109,6 +108,9 @@ SCM struct_ref_ (SCM x, long i);
|
||||||
SCM struct_set_x_ (SCM x, long i, SCM e);
|
SCM struct_set_x_ (SCM x, long i, SCM e);
|
||||||
SCM vector_ref_ (SCM x, long i);
|
SCM vector_ref_ (SCM x, long i);
|
||||||
SCM vector_set_x_ (SCM x, long i, SCM e);
|
SCM vector_set_x_ (SCM x, long i, SCM e);
|
||||||
|
FUNCTION builtin_function (SCM builtin);
|
||||||
|
char *cell_bytes (SCM x);
|
||||||
|
char *news_bytes (SCM x);
|
||||||
int peekchar ();
|
int peekchar ();
|
||||||
int readchar ();
|
int readchar ();
|
||||||
int unreadchar ();
|
int unreadchar ();
|
||||||
|
|
|
@ -189,28 +189,28 @@ display_helper (SCM x, int cont, char *sep, int fd, int write_p)
|
||||||
fdputs (" ", fd);
|
fdputs (" ", fd);
|
||||||
x = STRING (x);
|
x = STRING (x);
|
||||||
fdputc ('"', fd);
|
fdputc ('"', fd);
|
||||||
fdwrite_string (CSTRING (x), LENGTH (x), fd);
|
fdwrite_string (cell_bytes (STRING (x)), LENGTH (x), fd);
|
||||||
fdputc ('"', fd);
|
fdputc ('"', fd);
|
||||||
fdputs (">", fd);
|
fdputs (">", fd);
|
||||||
}
|
}
|
||||||
else if (t == TKEYWORD)
|
else if (t == TKEYWORD)
|
||||||
{
|
{
|
||||||
fdputs ("#:", fd);
|
fdputs ("#:", fd);
|
||||||
fdwrite_string (CSTRING (x), LENGTH (x), fd);
|
fdwrite_string (cell_bytes (STRING (x)), LENGTH (x), fd);
|
||||||
}
|
}
|
||||||
else if (t == TSTRING)
|
else if (t == TSTRING)
|
||||||
{
|
{
|
||||||
if (write_p == 1)
|
if (write_p == 1)
|
||||||
{
|
{
|
||||||
fdputc ('"', fd);
|
fdputc ('"', fd);
|
||||||
fdwrite_string (CSTRING (x), LENGTH (x), fd);
|
fdwrite_string (cell_bytes (STRING (x)), LENGTH (x), fd);
|
||||||
fdputc ('"', fd);
|
fdputc ('"', fd);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fdputs (CSTRING (x), fd);
|
fdputs (cell_bytes (STRING (x)), fd);
|
||||||
}
|
}
|
||||||
else if (t == TSPECIAL || t == TSYMBOL)
|
else if (t == TSPECIAL || t == TSYMBOL)
|
||||||
fdwrite_string (CSTRING (x), LENGTH (x), fd);
|
fdwrite_string (cell_bytes (STRING (x)), LENGTH (x), fd);
|
||||||
else if (t == TREF)
|
else if (t == TREF)
|
||||||
fdisplay_ (REF (x), fd, write_p);
|
fdisplay_ (REF (x), fd, write_p);
|
||||||
else if (t == TSTRUCT)
|
else if (t == TSTRUCT)
|
||||||
|
|
16
src/gc.c
16
src/gc.c
|
@ -25,6 +25,18 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
cell_bytes (SCM x)
|
||||||
|
{
|
||||||
|
return &CDR (x);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
news_bytes (SCM x)
|
||||||
|
{
|
||||||
|
return &NCDR (x);
|
||||||
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
gc_init () /*:((internal)) */
|
gc_init () /*:((internal)) */
|
||||||
{
|
{
|
||||||
|
@ -261,8 +273,8 @@ gc_copy (SCM old) /*:((internal)) */
|
||||||
}
|
}
|
||||||
else if (NTYPE (new) == TBYTES)
|
else if (NTYPE (new) == TBYTES)
|
||||||
{
|
{
|
||||||
char const *src = CBYTES (old);
|
char const *src = cell_bytes (old);
|
||||||
char *dest = NCBYTES (new);
|
char *dest = news_bytes (new);
|
||||||
size_t length = NLENGTH (new);
|
size_t length = NLENGTH (new);
|
||||||
memcpy (dest, src, length + 1);
|
memcpy (dest, src, length + 1);
|
||||||
g_free = g_free + bytes_cells (length) - 1;
|
g_free = g_free + bytes_cells (length) - 1;
|
||||||
|
|
|
@ -38,7 +38,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 (cell_bytes (STRING (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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ int
|
||||||
hash_ (SCM x, long size)
|
hash_ (SCM x, long size)
|
||||||
{
|
{
|
||||||
if (TYPE (x) == TSTRING)
|
if (TYPE (x) == TSTRING)
|
||||||
return hash_cstring (CSTRING (x), size);
|
return hash_cstring (cell_bytes (STRING (x)), size);
|
||||||
assert_msg (0, "0");
|
assert_msg (0, "0");
|
||||||
return hashq_ (x, size);
|
return hashq_ (x, size);
|
||||||
}
|
}
|
||||||
|
|
28
src/posix.c
28
src/posix.c
|
@ -47,7 +47,7 @@ peekchar ()
|
||||||
size_t length = LENGTH (string);
|
size_t length = LENGTH (string);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return -1;
|
return -1;
|
||||||
char const *p = CSTRING (string);
|
char const *p = cell_bytes (STRING (string));
|
||||||
return p[0];
|
return p[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ readchar ()
|
||||||
size_t length = LENGTH (string);
|
size_t length = LENGTH (string);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return -1;
|
return -1;
|
||||||
char const *p = CSTRING (string);
|
char const *p = cell_bytes (STRING (string));
|
||||||
int c = p[0];
|
int c = p[0];
|
||||||
p = p + 1;
|
p = p + 1;
|
||||||
STRING (port) = make_string (p, length - 1);
|
STRING (port) = make_string (p, length - 1);
|
||||||
|
@ -78,10 +78,10 @@ unreadchar (int c)
|
||||||
SCM port = current_input_port ();
|
SCM port = current_input_port ();
|
||||||
SCM string = STRING (port);
|
SCM string = STRING (port);
|
||||||
size_t length = LENGTH (string);
|
size_t length = LENGTH (string);
|
||||||
char *p = CSTRING (string);
|
char *p = cell_bytes (STRING (string));
|
||||||
p = p - 1;
|
p = p - 1;
|
||||||
string = make_string (p, length + 1);
|
string = make_string (p, length + 1);
|
||||||
p = CSTRING (string);
|
p = cell_bytes (STRING (string));
|
||||||
p[0] = c;
|
p[0] = c;
|
||||||
STRING (port) = string;
|
STRING (port) = string;
|
||||||
return c;
|
return c;
|
||||||
|
@ -159,7 +159,7 @@ SCM
|
||||||
getenv_ (SCM s) /*:((name . "getenv")) */
|
getenv_ (SCM s) /*:((name . "getenv")) */
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
p = getenv (CSTRING (s));
|
p = getenv (cell_bytes (STRING (s)));
|
||||||
if (p != 0)
|
if (p != 0)
|
||||||
return make_string0 (p);
|
return make_string0 (p);
|
||||||
return cell_f;
|
return cell_f;
|
||||||
|
@ -169,15 +169,15 @@ SCM
|
||||||
setenv_ (SCM s, SCM v) /*:((name . "setenv")) */
|
setenv_ (SCM s, SCM v) /*:((name . "setenv")) */
|
||||||
{
|
{
|
||||||
char *buf = __setenv_buf;
|
char *buf = __setenv_buf;
|
||||||
strcpy (buf, CSTRING (s));
|
strcpy (buf, cell_bytes (STRING (s)));
|
||||||
setenv (buf, CSTRING (v), 1);
|
setenv (buf, cell_bytes (STRING (v)), 1);
|
||||||
return cell_unspecified;
|
return cell_unspecified;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
access_p (SCM file_name, SCM mode)
|
access_p (SCM file_name, SCM mode)
|
||||||
{
|
{
|
||||||
if (access (CSTRING (file_name), VALUE (mode)) == 0)
|
if (access (cell_bytes (STRING (file_name)), VALUE (mode)) == 0)
|
||||||
return cell_t;
|
return cell_t;
|
||||||
return cell_f;
|
return cell_f;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ current_input_port ()
|
||||||
SCM
|
SCM
|
||||||
open_input_file (SCM file_name)
|
open_input_file (SCM file_name)
|
||||||
{
|
{
|
||||||
int filedes = mes_open (CSTRING (file_name), O_RDONLY, 0);
|
int filedes = mes_open (cell_bytes (STRING (file_name)), O_RDONLY, 0);
|
||||||
if (filedes == -1)
|
if (filedes == -1)
|
||||||
error (cell_symbol_system_error, cons (make_string0 ("No such file or directory"), file_name));
|
error (cell_symbol_system_error, cons (make_string0 ("No such file or directory"), file_name));
|
||||||
return make_number (filedes);
|
return make_number (filedes);
|
||||||
|
@ -247,7 +247,7 @@ open_output_file (SCM x) /*:((arity . n)) */
|
||||||
int mode = S_IRUSR | S_IWUSR;
|
int mode = S_IRUSR | S_IWUSR;
|
||||||
if (TYPE (x) == TPAIR && TYPE (car (x)) == TNUMBER)
|
if (TYPE (x) == TPAIR && TYPE (car (x)) == TNUMBER)
|
||||||
mode = VALUE (car (x));
|
mode = VALUE (car (x));
|
||||||
return make_number (mes_open (CSTRING (file_name), O_WRONLY | O_CREAT | O_TRUNC, mode));
|
return make_number (mes_open (cell_bytes (STRING (file_name)), O_WRONLY | O_CREAT | O_TRUNC, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
|
@ -273,7 +273,7 @@ set_current_error_port (SCM port)
|
||||||
SCM
|
SCM
|
||||||
chmod_ (SCM file_name, SCM mode) /*:((name . "chmod")) */
|
chmod_ (SCM file_name, SCM mode) /*:((name . "chmod")) */
|
||||||
{
|
{
|
||||||
chmod (CSTRING (file_name), VALUE (mode));
|
chmod (cell_bytes (STRING (file_name)), VALUE (mode));
|
||||||
return cell_unspecified;
|
return cell_unspecified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,13 +300,13 @@ execl_ (SCM file_name, SCM args) /*:((name . "execl")) */
|
||||||
if (length__ (args) > 1000)
|
if (length__ (args) > 1000)
|
||||||
error (cell_symbol_system_error,
|
error (cell_symbol_system_error,
|
||||||
cons (file_name, cons (make_string0 ("too many arguments"), cons (file_name, args))));
|
cons (file_name, cons (make_string0 ("too many arguments"), cons (file_name, args))));
|
||||||
c_argv[i] = CSTRING (file_name);
|
c_argv[i] = cell_bytes (STRING (file_name));
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
while (args != cell_nil)
|
while (args != cell_nil)
|
||||||
{
|
{
|
||||||
assert_msg (TYPE (CAR (args)) == TSTRING, "TYPE (CAR (args)) == TSTRING");
|
assert_msg (TYPE (CAR (args)) == TSTRING, "TYPE (CAR (args)) == TSTRING");
|
||||||
SCM arg = CAR (args);
|
SCM arg = CAR (args);
|
||||||
c_argv[i] = CSTRING (arg);
|
c_argv[i] = cell_bytes (STRING (arg));
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
args = CDR (args);
|
args = CDR (args);
|
||||||
if (g_debug > 2)
|
if (g_debug > 2)
|
||||||
|
@ -420,6 +420,6 @@ dup2_ (SCM old, SCM new) /*:((name . "dup2")) */
|
||||||
SCM
|
SCM
|
||||||
delete_file (SCM file_name)
|
delete_file (SCM file_name)
|
||||||
{
|
{
|
||||||
unlink (CSTRING (file_name));
|
unlink (cell_bytes (STRING (file_name)));
|
||||||
return cell_unspecified;
|
return cell_unspecified;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ string_equal_p (SCM a, SCM b) /*:((name . "string=?")) */
|
||||||
if (a == b
|
if (a == b
|
||||||
|| STRING (a) == STRING (b)
|
|| STRING (a) == STRING (b)
|
||||||
|| (LENGTH (a) == 0 && LENGTH (b) == 0)
|
|| (LENGTH (a) == 0 && LENGTH (b) == 0)
|
||||||
|| (LENGTH (a) == LENGTH (b) && !memcmp (CSTRING (a), CSTRING (b), LENGTH (a))))
|
|| (LENGTH (a) == LENGTH (b) && !memcmp (cell_bytes (STRING (a)), cell_bytes (STRING (b)), LENGTH (a))))
|
||||||
return cell_t;
|
return cell_t;
|
||||||
|
|
||||||
return cell_f;
|
return cell_f;
|
||||||
|
@ -150,7 +150,7 @@ cstring_to_symbol (char const *s)
|
||||||
SCM
|
SCM
|
||||||
string_to_list (SCM string)
|
string_to_list (SCM string)
|
||||||
{
|
{
|
||||||
return bytes_to_list (CSTRING (string), LENGTH (string));
|
return bytes_to_list (cell_bytes (STRING (string)), LENGTH (string));
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
|
@ -192,7 +192,7 @@ string_append (SCM x) /*:((arity . n)) */
|
||||||
{
|
{
|
||||||
SCM string = CAR (x);
|
SCM string = CAR (x);
|
||||||
assert_msg (TYPE (string) == TSTRING, "TYPE (string) == TSTRING");
|
assert_msg (TYPE (string) == TSTRING, "TYPE (string) == TSTRING");
|
||||||
memcpy (p, CSTRING (string), LENGTH (string) + 1);
|
memcpy (p, cell_bytes (STRING (string)), LENGTH (string) + 1);
|
||||||
p = p + LENGTH (string);
|
p = p + LENGTH (string);
|
||||||
size = size + LENGTH (string);
|
size = size + LENGTH (string);
|
||||||
if (size > MAX_STRING)
|
if (size > MAX_STRING)
|
||||||
|
@ -218,6 +218,6 @@ string_ref (SCM str, SCM k)
|
||||||
size_t i = VALUE (k);
|
size_t i = VALUE (k);
|
||||||
if (i > size)
|
if (i > size)
|
||||||
error (cell_symbol_system_error, cons (make_string0 ("value out of range"), k));
|
error (cell_symbol_system_error, cons (make_string0 ("value out of range"), k));
|
||||||
char const *p = CSTRING (str);
|
char const *p = cell_bytes (STRING (str));
|
||||||
return make_char (p[i]);
|
return make_char (p[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue