core: Prepare gc.c for mescc, non-POSIX_SOURCE.
* mes.c (NLENGTH, NVALUE, NVECTOR): New macros. (mes_builtins): Add comment on .i include order. * module/language/c99/compiler.mes (mescc): Add define _POSIX_SOURCE=0. * gc.c (gc_up_arena, gc_flip, gc_loop, gc)[!_POSIX_SOURCE]: Use eputs rather than fprintf. (gc_loop): Use CAR, TYPE, NVECTOR rather than .car, .type, .vector. * gc.c (gc_up_arena)[!_POSIX_SOURCE]: Add non-POSIX mlib.c implementation.
This commit is contained in:
parent
17f89b2c78
commit
6a816687e8
|
@ -98,6 +98,7 @@ module/mes/read-0.mo: module/mes/read-0.mes mes
|
|||
|
||||
dump: module/mes/read-0.mo
|
||||
|
||||
mes-32: gc.c lib.c math.c posix.c vector.c
|
||||
mes-32: mes.c lib.c
|
||||
rm -f mes mes.o
|
||||
guix environment --system=i686-linux --ad-hoc gcc-toolchain -- bash -c 'make mes CC=i686-unknown-linux-gnu-gcc LIBRARY_PATH=$${PATH%%/bin:*}/lib'
|
||||
|
@ -130,6 +131,7 @@ mescc-check: t-check
|
|||
|
||||
mini-mes: mini-mes.h mini-mes.i mini-mes.environment.i mini-mes.symbols.i
|
||||
mini-mes: vector.c
|
||||
mini-mes: gc.c
|
||||
mini-mes: mlibc.c mstart.c
|
||||
mini-mes: GNUmakefile
|
||||
mini-mes: module/mes/read-0-32.mo
|
||||
|
|
52
gc.c
52
gc.c
|
@ -21,12 +21,29 @@
|
|||
SCM
|
||||
gc_up_arena () ///((internal))
|
||||
{
|
||||
#if _POSIX_SOURCE
|
||||
ARENA_SIZE *= 2;
|
||||
void *p = realloc (g_cells-1, 2*ARENA_SIZE*sizeof(struct scm));
|
||||
#else
|
||||
ARENA_SIZE = ARENA_SIZE * 2;
|
||||
//p = realloc (g_cells-1, 2*ARENA_SIZE*sizeof(struct scm));
|
||||
int size = ARENA_SIZE * 2;
|
||||
size = size * 12;
|
||||
char *p = size;
|
||||
p = realloc (g_cells-1, size);
|
||||
g_cells = p;
|
||||
#endif
|
||||
|
||||
#if _POSIX_SOURCE
|
||||
if (!p) error (cell_symbol_system_error, cons (MAKE_STRING (cstring_to_list (strerror (errno))), MAKE_NUMBER (g_free)));
|
||||
g_cells = (struct scm*)p;
|
||||
g_cells++;
|
||||
#else
|
||||
//assert (p);
|
||||
//g_cells = (struct scm*)p;
|
||||
#endif
|
||||
gc_init_news ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
SCM
|
||||
|
@ -35,7 +52,16 @@ gc_flip () ///((internal))
|
|||
struct scm *cells = g_cells;
|
||||
g_cells = g_news;
|
||||
g_news = cells;
|
||||
#if _POSIX_SOURCE
|
||||
if (g_debug) fprintf (stderr, " => jam[%d]\n", g_free);
|
||||
#else
|
||||
if (g_debug)
|
||||
{
|
||||
eputs (" => jam[");
|
||||
eputs (itoa (g_free));
|
||||
eputs ("]\n");
|
||||
}
|
||||
#endif
|
||||
return g_stack;
|
||||
}
|
||||
|
||||
|
@ -47,12 +73,12 @@ gc_copy (SCM old) ///((internal))
|
|||
g_news[new] = g_cells[old];
|
||||
if (NTYPE (new) == TVECTOR)
|
||||
{
|
||||
g_news[new].vector = g_free;
|
||||
NVECTOR (new) = g_free;
|
||||
for (int i=0; i<LENGTH (old); i++)
|
||||
g_news[g_free++] = g_cells[VECTOR (old)+i];
|
||||
}
|
||||
g_cells[old].type = TBROKEN_HEART;
|
||||
g_cells[old].car = new;
|
||||
TYPE (old) = TBROKEN_HEART;
|
||||
CAR (old) = new;
|
||||
return new;
|
||||
}
|
||||
|
||||
|
@ -108,7 +134,16 @@ gc_loop (SCM scan) ///((internal))
|
|||
SCM
|
||||
gc ()
|
||||
{
|
||||
#if _POSIX_SOURCE
|
||||
if (g_debug) fprintf (stderr, "***gc[%d]...", g_free);
|
||||
#else
|
||||
if (g_debug)
|
||||
{
|
||||
eputs ("***gc[");
|
||||
eputs (itoa (g_free));
|
||||
eputs ("]...");
|
||||
}
|
||||
#endif
|
||||
g_free = 1;
|
||||
if (g_cells < g_news && ARENA_SIZE < MAX_ARENA_SIZE) gc_up_arena ();
|
||||
for (int i=g_free; i<g_symbol_max; i++)
|
||||
|
@ -116,7 +151,16 @@ gc ()
|
|||
make_tmps (g_news);
|
||||
g_symbols = gc_copy (g_symbols);
|
||||
SCM new = gc_copy (g_stack);
|
||||
if (g_debug) fprintf (stderr, "new=%d\n", new, g_stack);
|
||||
#if _POSIX_SOURCE
|
||||
if (g_debug) fprintf (stderr, "new=%d\n", new);
|
||||
#else
|
||||
if (g_debug)
|
||||
{
|
||||
eputs ("new=");
|
||||
eputs (itoa (new));
|
||||
eputs ("\n");
|
||||
}
|
||||
#endif
|
||||
g_stack = new;
|
||||
return gc_loop (1);
|
||||
}
|
||||
|
|
11
mes.c
11
mes.c
|
@ -209,9 +209,17 @@ SCM r3 = 0; // continuation
|
|||
#define VALUE(x) g_cells[x].value
|
||||
#define VECTOR(x) g_cells[x].vector
|
||||
#define FUNCTION(x) g_functions[g_cells[x].function]
|
||||
#define NCAR(x) g_news[x].car
|
||||
|
||||
#define NTYPE(x) g_news[x].type
|
||||
|
||||
#define NCAR(x) g_news[x].car
|
||||
#define NLENGTH(x) g_news[x].length
|
||||
|
||||
#define NCDR(x) g_news[x].cdr
|
||||
#define NVALUE(x) g_news[x].value
|
||||
#define NVECTOR(x) g_news[x].vector
|
||||
|
||||
|
||||
#define CAAR(x) CAR (CAR (x))
|
||||
#define CADR(x) CAR (CDR (x))
|
||||
#define CDAR(x) CDR (CAR (x))
|
||||
|
@ -998,6 +1006,7 @@ mes_builtins (SCM a) ///((internal))
|
|||
{
|
||||
#include "mes.i"
|
||||
|
||||
// Do not sort: Order of these includes define builtins
|
||||
#include "posix.i"
|
||||
#include "math.i"
|
||||
#include "lib.i"
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
(parse-c99
|
||||
#:inc-dirs (string-split (getenv "C_INCLUDE_PATH") #\:)
|
||||
#:cpp-defs '(
|
||||
"_POSIX_SOURCE=0"
|
||||
"__GNUC__=0"
|
||||
"__MESC__=1"
|
||||
"__NYACC__=1" ;; REMOVEME
|
||||
|
|
Loading…
Reference in a new issue