mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
2018-07-22 13:24:36 +01:00
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
* Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
*
|
2018-07-22 13:24:36 +01:00
|
|
|
* This file is part of GNU Mes.
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
*
|
2018-07-22 13:24:36 +01:00
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
2018-07-22 13:24:36 +01:00
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-22 13:24:36 +01:00
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
*/
|
|
|
|
|
2019-06-08 14:36:22 +01:00
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
2017-05-02 22:30:46 +01:00
|
|
|
#include <errno.h>
|
2019-06-08 14:36:22 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-10-28 17:26:55 +00:00
|
|
|
// CONSTANT FRAME_SIZE 5
|
|
|
|
#define FRAME_SIZE 5
|
|
|
|
|
2019-10-22 14:57:49 +01:00
|
|
|
#if __M2_PLANET__
|
|
|
|
#define M2_CELL_SIZE 12
|
|
|
|
// CONSTANT M2_CELL_SIZE 12
|
|
|
|
#else
|
|
|
|
#define M2_CELL_SIZE 1
|
|
|
|
// CONSTANT M2_CELL_SIZE 12
|
|
|
|
#endif
|
|
|
|
|
2019-10-22 07:55:41 +01:00
|
|
|
char *
|
|
|
|
cell_bytes (SCM x)
|
|
|
|
{
|
2019-10-22 14:57:49 +01:00
|
|
|
#if POINTER_CELLS
|
|
|
|
char *p = x;
|
|
|
|
return p + (2 * sizeof (long));
|
|
|
|
#else
|
2019-10-22 07:55:41 +01:00
|
|
|
return &CDR (x);
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
2019-10-22 07:55:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
news_bytes (SCM x)
|
|
|
|
{
|
2019-10-27 12:45:18 +00:00
|
|
|
#if POINTER_CELLS
|
|
|
|
char *p = x;
|
|
|
|
return p + (2 * sizeof (long));
|
|
|
|
#else
|
2019-10-22 07:55:41 +01:00
|
|
|
return &NCDR (x);
|
2019-10-27 12:45:18 +00:00
|
|
|
#endif
|
2019-10-22 07:55:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 22:04:22 +00:00
|
|
|
void
|
|
|
|
gc_init ()
|
2019-06-08 14:36:22 +01:00
|
|
|
{
|
|
|
|
#if SYSTEM_LIBC
|
2019-10-20 12:23:47 +01:00
|
|
|
ARENA_SIZE = 100000000; /* 2.3GiB */
|
2019-10-27 12:45:18 +00:00
|
|
|
#elif ! __M2_PLANET__
|
2019-10-20 12:23:47 +01:00
|
|
|
ARENA_SIZE = 300000; /* 32b: 3MiB, 64b: 6 MiB */
|
2019-10-27 12:45:18 +00:00
|
|
|
#else
|
|
|
|
ARENA_SIZE = 20000000;
|
2019-06-08 14:36:22 +01:00
|
|
|
#endif
|
|
|
|
STACK_SIZE = 20000;
|
|
|
|
|
2019-10-27 12:45:18 +00:00
|
|
|
#if !POINTER_CELLS
|
|
|
|
JAM_SIZE = 20000;
|
|
|
|
MAX_ARENA_SIZE = 100000000;
|
|
|
|
#elif !__M2_PLANET__
|
2019-10-22 14:57:49 +01:00
|
|
|
JAM_SIZE = 1000;
|
2019-10-27 12:45:18 +00:00
|
|
|
MAX_ARENA_SIZE = 10000000;
|
2019-10-22 14:57:49 +01:00
|
|
|
#else
|
2019-06-08 14:36:22 +01:00
|
|
|
JAM_SIZE = 20000;
|
2019-10-27 12:45:18 +00:00
|
|
|
MAX_ARENA_SIZE = 20000000;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
2019-06-08 14:36:22 +01:00
|
|
|
GC_SAFETY = 2000;
|
|
|
|
MAX_STRING = 524288;
|
|
|
|
|
|
|
|
char *p;
|
2019-10-27 12:45:18 +00:00
|
|
|
p = getenv ("MES_MAX_ARENA");
|
|
|
|
if (p != 0)
|
2019-06-08 14:36:22 +01:00
|
|
|
MAX_ARENA_SIZE = atoi (p);
|
2019-10-27 12:45:18 +00:00
|
|
|
p = getenv ("MES_ARENA");
|
|
|
|
if (p != 0)
|
2019-06-08 14:36:22 +01:00
|
|
|
ARENA_SIZE = atoi (p);
|
|
|
|
JAM_SIZE = ARENA_SIZE / 10;
|
2019-10-27 12:45:18 +00:00
|
|
|
p = getenv ("MES_JAM");
|
|
|
|
if (p != 0)
|
2019-06-08 14:36:22 +01:00
|
|
|
JAM_SIZE = atoi (p);
|
|
|
|
GC_SAFETY = ARENA_SIZE / 100;
|
2019-10-27 12:45:18 +00:00
|
|
|
p = getenv ("MES_SAFETY");
|
|
|
|
if (p != 0)
|
2019-06-08 14:36:22 +01:00
|
|
|
GC_SAFETY = atoi (p);
|
2019-10-27 12:45:18 +00:00
|
|
|
p = getenv ("MES_STACK");
|
|
|
|
if (p != 0)
|
2019-06-08 14:36:22 +01:00
|
|
|
STACK_SIZE = atoi (p);
|
2019-10-27 12:45:18 +00:00
|
|
|
p = getenv ("MES_MAX_STRING");
|
|
|
|
if (p != 0)
|
2019-06-08 14:36:22 +01:00
|
|
|
MAX_STRING = atoi (p);
|
|
|
|
|
|
|
|
long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm);
|
2019-11-02 07:54:56 +00:00
|
|
|
#if! POINTER_CELLS
|
|
|
|
long alloc_bytes = arena_bytes + (STACK_SIZE * sizeof (SCM));
|
2019-10-22 14:57:49 +01:00
|
|
|
#else
|
2019-10-27 12:45:18 +00:00
|
|
|
long alloc_bytes = (arena_bytes * 2) + (STACK_SIZE * sizeof (struct scm*));
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
2019-10-27 12:45:18 +00:00
|
|
|
g_arena = malloc (alloc_bytes);
|
|
|
|
g_cells = g_arena;
|
2019-06-08 14:36:22 +01:00
|
|
|
|
2019-11-02 07:54:56 +00:00
|
|
|
#if! POINTER_CELLS
|
2019-10-27 12:45:18 +00:00
|
|
|
g_stack_array = g_arena + arena_bytes;
|
|
|
|
#else
|
|
|
|
g_stack_array = g_arena + (arena_bytes * 2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !POINTER_CELLS
|
2019-10-22 14:57:49 +01:00
|
|
|
/* The vector that holds the arenea. */
|
2019-10-27 12:45:18 +00:00
|
|
|
cell_arena = -1;
|
2019-10-22 14:57:49 +01:00
|
|
|
#else
|
|
|
|
/* The vector that holds the arenea. */
|
2019-10-27 12:45:18 +00:00
|
|
|
cell_arena = g_cells;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
2019-10-27 12:45:18 +00:00
|
|
|
|
|
|
|
cell_zero = cell_arena + M2_CELL_SIZE;
|
|
|
|
|
|
|
|
g_cells = g_cells + M2_CELL_SIZE; /* Hmm? */
|
|
|
|
|
2019-10-22 14:57:49 +01:00
|
|
|
TYPE (cell_arena) = TVECTOR;
|
|
|
|
LENGTH (cell_arena) = 1000;
|
2019-10-27 12:45:18 +00:00
|
|
|
VECTOR (cell_arena) = cell_zero;
|
|
|
|
|
|
|
|
TYPE (cell_zero) = TCHAR;
|
|
|
|
VALUE (cell_zero) = 'c';
|
2019-10-22 14:57:49 +01:00
|
|
|
|
|
|
|
#if !POINTER_CELLS
|
|
|
|
g_free = 1;
|
|
|
|
#else
|
|
|
|
g_free = g_cells + M2_CELL_SIZE;
|
|
|
|
#endif
|
2019-06-08 14:36:22 +01:00
|
|
|
|
2019-10-27 12:45:18 +00:00
|
|
|
/* FIXME: remove MES_MAX_STRING, grow dynamically. */
|
2019-10-20 12:23:47 +01:00
|
|
|
g_buf = malloc (MAX_STRING);
|
2019-06-08 14:36:22 +01:00
|
|
|
}
|
|
|
|
|
2019-10-22 14:57:49 +01:00
|
|
|
long
|
|
|
|
gc_free ()
|
2019-06-08 14:36:22 +01:00
|
|
|
{
|
2019-10-22 14:57:49 +01:00
|
|
|
#if POINTER_CELLS
|
|
|
|
return g_free - g_cells;
|
|
|
|
#else
|
|
|
|
return g_free;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gc_stats_ (char const* where)
|
|
|
|
{
|
2019-10-27 12:45:18 +00:00
|
|
|
#if !POINTER_CELLS
|
2019-10-22 14:57:49 +01:00
|
|
|
long i = g_free;
|
2019-10-27 12:45:18 +00:00
|
|
|
#else
|
|
|
|
long i = g_free - g_cells;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
|
|
|
eputs (where);
|
|
|
|
eputs (": [");
|
|
|
|
eputs (ntoab (i, 10, 0));
|
|
|
|
eputs ("]\n");
|
2019-06-08 14:36:22 +01:00
|
|
|
}
|
2018-11-11 15:25:36 +00:00
|
|
|
|
2019-10-20 23:40:50 +01:00
|
|
|
SCM
|
|
|
|
alloc (long n)
|
|
|
|
{
|
|
|
|
SCM x = g_free;
|
2019-10-24 20:56:49 +01:00
|
|
|
g_free = g_free + (n * M2_CELL_SIZE);
|
2019-10-27 12:45:18 +00:00
|
|
|
#if !POINTER_CELLS
|
2019-10-22 14:57:49 +01:00
|
|
|
long i = g_free;
|
2019-10-27 12:45:18 +00:00
|
|
|
#else
|
|
|
|
long i = g_free - g_cells;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
|
|
|
if (i > ARENA_SIZE)
|
2019-10-20 23:40:50 +01:00
|
|
|
assert_msg (0, "alloc: out of memory");
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_cell (long type, SCM car, SCM cdr)
|
|
|
|
{
|
|
|
|
SCM x = g_free;
|
2019-10-24 20:56:49 +01:00
|
|
|
g_free = g_free + M2_CELL_SIZE;
|
2019-10-27 12:45:18 +00:00
|
|
|
#if !POINTER_CELLS
|
2019-10-22 14:57:49 +01:00
|
|
|
long i = g_free;
|
2019-10-27 12:45:18 +00:00
|
|
|
#else
|
|
|
|
long i = g_free - g_cells;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
|
|
|
if (i > ARENA_SIZE)
|
2019-10-20 23:40:50 +01:00
|
|
|
assert_msg (0, "alloc: out of memory");
|
|
|
|
TYPE (x) = type;
|
|
|
|
CAR (x) = car;
|
|
|
|
CDR (x) = cdr;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2019-10-22 14:57:49 +01:00
|
|
|
void
|
|
|
|
copy_cell (SCM to, SCM from)
|
|
|
|
{
|
|
|
|
TYPE (to) = TYPE (from);
|
|
|
|
CAR (to) = CAR (from);
|
|
|
|
CDR (to) = CDR (from);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
copy_news (SCM to, SCM from)
|
|
|
|
{
|
|
|
|
NTYPE (to) = TYPE (from);
|
|
|
|
NCAR (to) = CAR (from);
|
|
|
|
NCDR (to) = CDR (from);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
copy_stack (long index, SCM from)
|
|
|
|
{
|
|
|
|
g_stack_array[index] = from;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
cell_ref (SCM cell, long index)
|
|
|
|
{
|
2019-10-24 20:56:49 +01:00
|
|
|
return cell + (index * M2_CELL_SIZE);
|
2019-10-22 14:57:49 +01:00
|
|
|
}
|
|
|
|
|
2019-10-20 23:40:50 +01:00
|
|
|
SCM
|
|
|
|
cons (SCM x, SCM y)
|
|
|
|
{
|
|
|
|
return make_cell (TPAIR, x, y);
|
|
|
|
}
|
|
|
|
|
2019-10-21 20:57:55 +01:00
|
|
|
size_t
|
|
|
|
bytes_cells (size_t length)
|
|
|
|
{
|
2019-10-28 16:00:15 +00:00
|
|
|
return (sizeof (long) + sizeof (long) + length - 1 + sizeof (SCM)) / sizeof (SCM);
|
2019-10-21 20:57:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2019-10-22 14:57:49 +01:00
|
|
|
char *p = cell_bytes (x);
|
2019-10-21 20:57:55 +01:00
|
|
|
if (length == 0)
|
|
|
|
p[0] = 0;
|
|
|
|
else
|
2019-10-28 16:00:15 +00:00
|
|
|
memcpy (p, s, length);
|
2019-10-21 20:57:55 +01:00
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
SCM
|
|
|
|
make_char (int n)
|
|
|
|
{
|
|
|
|
return make_cell (TCHAR, 0, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_continuation (long n)
|
|
|
|
{
|
|
|
|
return make_cell (TCONTINUATION, n, g_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_macro (SCM name, SCM x) /*:((internal)) */
|
|
|
|
{
|
|
|
|
return make_cell (TMACRO, x, STRING (name));
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_number (long n)
|
|
|
|
{
|
|
|
|
return make_cell (TNUMBER, 0, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_ref (SCM x) /*:((internal)) */
|
|
|
|
{
|
|
|
|
return make_cell (TREF, x, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_string (char const *s, size_t length)
|
|
|
|
{
|
|
|
|
if (length > MAX_STRING)
|
|
|
|
assert_max_string (length, "make_string", s);
|
|
|
|
SCM x = make_cell (TSTRING, length, 0);
|
2019-10-28 16:00:15 +00:00
|
|
|
SCM v = make_bytes (s, length + 1);
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
CDR (x) = v;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_string0 (char const *s)
|
|
|
|
{
|
|
|
|
return make_string (s, strlen (s));
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_string_port (SCM x) /*:((internal)) */
|
|
|
|
{
|
|
|
|
return make_cell (TPORT, -length__ (g_ports) - 2, x);
|
|
|
|
}
|
|
|
|
|
2019-10-22 14:57:49 +01:00
|
|
|
void
|
|
|
|
gc_init_news ()
|
|
|
|
{
|
2019-10-27 12:45:18 +00:00
|
|
|
#if !POINTER_CELLS
|
|
|
|
g_news = g_cells + g_free;
|
|
|
|
SCM ncell_arena = cell_arena;
|
|
|
|
#else
|
2019-10-22 14:57:49 +01:00
|
|
|
g_news = g_free;
|
2019-10-27 12:45:18 +00:00
|
|
|
SCM ncell_arena = g_news;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SCM ncell_zero = ncell_arena + M2_CELL_SIZE;
|
|
|
|
|
|
|
|
g_news = g_news + M2_CELL_SIZE;
|
|
|
|
|
|
|
|
NTYPE (ncell_arena) = TVECTOR;
|
|
|
|
NLENGTH (ncell_arena) = LENGTH (cell_arena);
|
|
|
|
|
|
|
|
#if !POINTER_CELLS
|
|
|
|
NVECTOR (ncell_arena) = 0;
|
2019-10-22 14:57:49 +01:00
|
|
|
#else
|
2019-10-27 12:45:18 +00:00
|
|
|
NVECTOR (ncell_arena) = g_news;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
2019-10-27 12:45:18 +00:00
|
|
|
|
|
|
|
NTYPE (ncell_zero) = TCHAR;
|
|
|
|
NVALUE (ncell_zero) = 'n';
|
2019-10-22 14:57:49 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 22:04:22 +00:00
|
|
|
void
|
|
|
|
gc_up_arena ()
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2019-05-18 12:27:42 +01:00
|
|
|
long old_arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm);
|
2018-04-25 07:35:05 +01:00
|
|
|
if (ARENA_SIZE >> 1 < MAX_ARENA_SIZE >> 2)
|
|
|
|
{
|
2019-10-20 12:23:47 +01:00
|
|
|
ARENA_SIZE = ARENA_SIZE << 1;
|
|
|
|
JAM_SIZE = JAM_SIZE << 1;
|
|
|
|
GC_SAFETY = GC_SAFETY << 1;
|
2018-04-25 07:35:05 +01:00
|
|
|
}
|
|
|
|
else
|
2019-05-18 12:27:42 +01:00
|
|
|
ARENA_SIZE = MAX_ARENA_SIZE - JAM_SIZE;
|
|
|
|
long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm);
|
2019-10-27 12:45:18 +00:00
|
|
|
#if !POINTER_CELLS
|
|
|
|
long stack_offset = arena_bytes;
|
|
|
|
long realloc_bytes = (arena_bytes * 2) + (STACK_SIZE * sizeof (struct scm));
|
|
|
|
#else
|
|
|
|
long stack_offset = (arena_bytes * 2);
|
|
|
|
long realloc_bytes = arena_bytes + (STACK_SIZE * sizeof (struct scm));
|
|
|
|
#endif
|
|
|
|
void *p = realloc (g_cells - M2_CELL_SIZE, realloc_bytes);
|
2019-10-20 12:23:47 +01:00
|
|
|
if (p == 0)
|
2018-04-14 07:15:49 +01:00
|
|
|
{
|
|
|
|
eputs ("realloc failed, g_free=");
|
|
|
|
eputs (itoa (g_free));
|
|
|
|
eputs (":");
|
2019-10-27 12:45:18 +00:00
|
|
|
#if !POINTER_CELLS
|
2019-10-22 14:57:49 +01:00
|
|
|
long i = g_free;
|
2019-10-27 12:45:18 +00:00
|
|
|
#else
|
|
|
|
long i = g_free - g_cells;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
|
|
|
eputs (itoa (ARENA_SIZE - i));
|
2018-04-14 07:15:49 +01:00
|
|
|
eputs ("\n");
|
2019-10-20 15:07:04 +01:00
|
|
|
assert_msg (0, "0");
|
2018-04-14 07:15:49 +01:00
|
|
|
exit (1);
|
|
|
|
}
|
2019-10-20 12:23:47 +01:00
|
|
|
g_cells = p;
|
2019-10-27 12:45:18 +00:00
|
|
|
memcpy (p + stack_offset, p + old_arena_bytes, STACK_SIZE * sizeof (SCM));
|
2019-10-24 20:56:49 +01:00
|
|
|
g_cells = g_cells + M2_CELL_SIZE;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
}
|
|
|
|
|
2017-12-14 06:05:53 +00:00
|
|
|
void
|
2019-10-30 22:04:22 +00:00
|
|
|
gc_flip ()
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2019-10-22 14:57:49 +01:00
|
|
|
#if POINTER_CELLS
|
|
|
|
g_cells = g_news;
|
2019-10-27 12:45:18 +00:00
|
|
|
cell_arena = g_news - M2_CELL_SIZE;
|
|
|
|
cell_zero = cell_arena + M2_CELL_SIZE;
|
|
|
|
cell_nil = cell_zero + M2_CELL_SIZE;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
2019-10-27 12:45:18 +00:00
|
|
|
|
2018-04-09 06:12:38 +01:00
|
|
|
if (g_debug > 2)
|
2019-10-22 14:57:49 +01:00
|
|
|
gc_stats_ (";;; => jam");
|
2019-10-27 12:45:18 +00:00
|
|
|
|
2019-10-22 14:57:49 +01:00
|
|
|
#if POINTER_CELLS
|
2019-10-27 12:45:18 +00:00
|
|
|
/* Nothing. */
|
|
|
|
return;
|
2019-10-22 14:57:49 +01:00
|
|
|
#else
|
2018-04-25 07:35:05 +01:00
|
|
|
if (g_free > JAM_SIZE)
|
|
|
|
JAM_SIZE = g_free + g_free / 2;
|
2019-10-27 12:45:18 +00:00
|
|
|
memcpy (g_cells, g_news, g_free * sizeof (struct scm));
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2019-10-20 12:23:47 +01:00
|
|
|
gc_copy (SCM old) /*:((internal)) */
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
if (TYPE (old) == TBROKEN_HEART)
|
2019-10-20 12:23:47 +01:00
|
|
|
return CAR (old);
|
|
|
|
SCM new = g_free;
|
2019-10-24 20:56:49 +01:00
|
|
|
g_free = g_free + M2_CELL_SIZE;
|
2019-10-22 14:57:49 +01:00
|
|
|
copy_news (new, old);
|
2019-05-18 12:27:42 +01:00
|
|
|
if (NTYPE (new) == TSTRUCT || NTYPE (new) == TVECTOR)
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
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.
2017-03-26 14:55:12 +01:00
|
|
|
NVECTOR (new) = g_free;
|
2019-10-20 12:23:47 +01:00
|
|
|
long i;
|
|
|
|
for (i = 0; i < LENGTH (old); i = i + 1)
|
|
|
|
{
|
2019-10-22 14:57:49 +01:00
|
|
|
copy_news (g_free, cell_ref (VECTOR (old), i));
|
2019-10-24 20:56:49 +01:00
|
|
|
g_free = g_free + M2_CELL_SIZE;
|
2019-10-20 12:23:47 +01:00
|
|
|
}
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
}
|
2018-11-11 15:25:36 +00:00
|
|
|
else if (NTYPE (new) == TBYTES)
|
|
|
|
{
|
2019-10-22 07:55:41 +01:00
|
|
|
char const *src = cell_bytes (old);
|
|
|
|
char *dest = news_bytes (new);
|
2019-10-24 20:56:49 +01:00
|
|
|
size_t length = NLENGTH (new);
|
2019-10-28 16:00:15 +00:00
|
|
|
memcpy (dest, src, length);
|
2019-10-24 20:56:49 +01:00
|
|
|
g_free = g_free + ((bytes_cells (length) - 1) * M2_CELL_SIZE);
|
2018-11-11 15:25:36 +00:00
|
|
|
|
|
|
|
if (g_debug > 4)
|
|
|
|
{
|
2019-05-18 12:27:42 +01:00
|
|
|
eputs ("gc copy bytes: ");
|
|
|
|
eputs (src);
|
|
|
|
eputs ("\n");
|
|
|
|
eputs (" length: ");
|
|
|
|
eputs (itoa (LENGTH (old)));
|
|
|
|
eputs ("\n");
|
|
|
|
eputs (" nlength: ");
|
|
|
|
eputs (itoa (NLENGTH (new)));
|
|
|
|
eputs ("\n");
|
|
|
|
eputs (" ==> ");
|
|
|
|
eputs (dest);
|
|
|
|
eputs ("\n");
|
2018-11-11 15:25:36 +00:00
|
|
|
}
|
|
|
|
}
|
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.
2017-03-26 14:55:12 +01:00
|
|
|
TYPE (old) = TBROKEN_HEART;
|
|
|
|
CAR (old) = new;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2019-10-20 12:23:47 +01:00
|
|
|
gc_relocate_car (SCM new, SCM car) /*:((internal)) */
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2019-10-20 12:23:47 +01:00
|
|
|
NCAR (new) = car;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2019-10-20 12:23:47 +01:00
|
|
|
gc_relocate_cdr (SCM new, SCM cdr) /*:((internal)) */
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2019-10-20 12:23:47 +01:00
|
|
|
NCDR (new) = cdr;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
|
|
|
|
2017-12-14 06:05:53 +00:00
|
|
|
void
|
2019-10-22 14:57:49 +01:00
|
|
|
gc_loop (SCM scan)
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2018-04-12 20:33:38 +01:00
|
|
|
SCM car;
|
|
|
|
SCM cdr;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
while (scan < g_free)
|
|
|
|
{
|
2019-10-28 16:00:15 +00:00
|
|
|
long t = NTYPE (scan);
|
|
|
|
if (t == TBROKEN_HEART)
|
2019-11-02 07:54:56 +00:00
|
|
|
assert_msg (0, "broken heart");
|
2019-10-28 16:00:15 +00:00
|
|
|
if (t == TMACRO
|
|
|
|
|| t == TPAIR
|
|
|
|
|| t == TREF
|
|
|
|
|| t == TVARIABLE)
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2019-10-20 12:23:47 +01:00
|
|
|
car = gc_copy (NCAR (scan));
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
gc_relocate_car (scan, car);
|
|
|
|
}
|
2019-10-27 12:45:18 +00:00
|
|
|
if (t == TCLOSURE
|
|
|
|
|| t == TCONTINUATION
|
|
|
|
|| t == TKEYWORD
|
|
|
|
|| t == TMACRO
|
|
|
|
|| t == TPAIR
|
|
|
|
|| t == TPORT
|
|
|
|
|| t == TSPECIAL
|
|
|
|
|| t == TSTRING
|
|
|
|
/*|| t == TSTRUCT handled by gc_copy */
|
|
|
|
|| t == TSYMBOL
|
|
|
|
|| t == TVALUES
|
|
|
|
/*|| t == TVECTOR handled by gc_copy */
|
|
|
|
)
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2019-10-20 12:23:47 +01:00
|
|
|
cdr = gc_copy (NCDR (scan));
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
gc_relocate_cdr (scan, cdr);
|
|
|
|
}
|
2019-10-28 16:00:15 +00:00
|
|
|
if (t == TBYTES)
|
2019-10-22 14:57:49 +01:00
|
|
|
scan = scan + (bytes_cells (NLENGTH (scan)) * M2_CELL_SIZE);
|
2019-10-28 16:00:15 +00:00
|
|
|
else
|
2019-10-22 14:57:49 +01:00
|
|
|
scan = scan + M2_CELL_SIZE;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
}
|
2017-12-14 06:05:53 +00:00
|
|
|
gc_flip ();
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
}
|
|
|
|
|
2017-04-01 22:00:50 +01:00
|
|
|
SCM
|
|
|
|
gc_check ()
|
|
|
|
{
|
2019-10-22 14:57:49 +01:00
|
|
|
#if POINTER_CELLS
|
2019-10-27 12:45:18 +00:00
|
|
|
if ((g_free - g_cells) + GC_SAFETY < ARENA_SIZE)
|
|
|
|
return cell_unspecified;
|
2019-10-22 14:57:49 +01:00
|
|
|
#else
|
2019-10-27 12:45:18 +00:00
|
|
|
if (g_free + GC_SAFETY < ARENA_SIZE)
|
|
|
|
return cell_unspecified;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
2019-10-27 12:45:18 +00:00
|
|
|
return gc ();
|
2017-04-01 22:00:50 +01:00
|
|
|
}
|
|
|
|
|
2019-10-28 16:00:15 +00:00
|
|
|
void
|
|
|
|
gc_ ()
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2018-04-25 07:35:05 +01:00
|
|
|
gc_init_news ();
|
2018-04-09 06:12:38 +01:00
|
|
|
if (g_debug == 2)
|
2017-12-09 07:33:50 +00:00
|
|
|
eputs (".");
|
2018-04-09 06:12:38 +01:00
|
|
|
if (g_debug > 2)
|
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.
2017-03-26 14:55:12 +01:00
|
|
|
{
|
2019-10-22 14:57:49 +01:00
|
|
|
gc_stats_ (";;; gc");
|
|
|
|
eputs (";;; free: [");
|
2019-10-27 12:45:18 +00:00
|
|
|
eputs (itoa (ARENA_SIZE - gc_free ()));
|
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.
2017-03-26 14:55:12 +01:00
|
|
|
eputs ("]...");
|
|
|
|
}
|
2019-10-27 12:45:18 +00:00
|
|
|
#if !POINTER_CELLS
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
g_free = 1;
|
2019-10-27 12:45:18 +00:00
|
|
|
#else
|
|
|
|
g_free = g_news + M2_CELL_SIZE;
|
2019-10-22 14:57:49 +01:00
|
|
|
#endif
|
2018-04-14 07:15:49 +01:00
|
|
|
|
2019-10-27 12:45:18 +00:00
|
|
|
if (ARENA_SIZE < MAX_ARENA_SIZE && g_cells == g_arena + M2_CELL_SIZE)
|
2018-04-14 07:15:49 +01:00
|
|
|
{
|
|
|
|
if (g_debug == 2)
|
|
|
|
eputs ("+");
|
|
|
|
if (g_debug > 2)
|
|
|
|
{
|
|
|
|
eputs (" up[");
|
2019-10-20 12:23:47 +01:00
|
|
|
eputs (itoa (g_cells));
|
2018-04-14 07:15:49 +01:00
|
|
|
eputs (",");
|
2019-10-20 12:23:47 +01:00
|
|
|
eputs (itoa (g_news));
|
2018-04-14 07:15:49 +01:00
|
|
|
eputs (":");
|
|
|
|
eputs (itoa (ARENA_SIZE));
|
|
|
|
eputs (",");
|
|
|
|
eputs (itoa (MAX_ARENA_SIZE));
|
|
|
|
eputs ("]...");
|
|
|
|
}
|
|
|
|
gc_up_arena ();
|
|
|
|
}
|
|
|
|
|
2019-10-27 12:45:18 +00:00
|
|
|
#if POINTER_CELLS
|
|
|
|
SCM save_gfree = g_free;
|
|
|
|
#endif
|
2019-10-22 14:57:49 +01:00
|
|
|
SCM s;
|
2019-10-24 20:56:49 +01:00
|
|
|
for (s = cell_nil; s < g_symbol_max; s = s + M2_CELL_SIZE)
|
2019-10-22 14:57:49 +01:00
|
|
|
gc_copy (s);
|
2019-10-27 12:45:18 +00:00
|
|
|
|
2019-10-22 14:57:49 +01:00
|
|
|
#if POINTER_CELLS
|
2019-10-27 12:45:18 +00:00
|
|
|
#if GC_TEST
|
|
|
|
cell_nil = save_gfree;
|
|
|
|
#else
|
|
|
|
long save_gsymbols = g_symbols;
|
|
|
|
cell_nil = save_gfree;
|
2019-10-22 14:57:49 +01:00
|
|
|
g_symbols = 0;
|
2019-10-27 12:45:18 +00:00
|
|
|
g_free = save_gfree;
|
2019-10-22 14:57:49 +01:00
|
|
|
init_symbols_ ();
|
|
|
|
g_symbol_max = g_symbol;
|
|
|
|
g_symbols = save_gsymbols;
|
|
|
|
#endif
|
2019-10-27 12:45:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
g_symbols = gc_copy (g_symbols);
|
|
|
|
g_macros = gc_copy (g_macros);
|
|
|
|
g_ports = gc_copy (g_ports);
|
|
|
|
M0 = gc_copy (M0);
|
|
|
|
long i;
|
|
|
|
for (i = g_stack; i < STACK_SIZE; i = i + 1)
|
|
|
|
copy_stack (i, gc_copy (g_stack_array[i]));
|
|
|
|
|
2019-10-22 14:57:49 +01:00
|
|
|
gc_loop (cell_nil);
|
2018-04-14 07:15:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
gc ()
|
|
|
|
{
|
2019-05-27 20:30:48 +01:00
|
|
|
if (g_debug > 5)
|
2018-04-14 07:15:49 +01:00
|
|
|
{
|
|
|
|
eputs ("symbols: ");
|
|
|
|
write_error_ (g_symbols);
|
|
|
|
eputs ("\n");
|
|
|
|
eputs ("R0: ");
|
2019-10-20 21:32:53 +01:00
|
|
|
write_error_ (R0);
|
2018-04-14 07:15:49 +01:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
|
|
|
gc_push_frame ();
|
|
|
|
gc_ ();
|
|
|
|
gc_pop_frame ();
|
2019-05-27 20:30:48 +01:00
|
|
|
if (g_debug > 5)
|
2018-04-14 07:15:49 +01:00
|
|
|
{
|
|
|
|
eputs ("symbols: ");
|
|
|
|
write_error_ (g_symbols);
|
|
|
|
eputs ("\n");
|
|
|
|
eputs ("R0: ");
|
2019-10-20 21:32:53 +01:00
|
|
|
write_error_ (R0);
|
2018-04-14 07:15:49 +01:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
2019-10-28 16:00:15 +00:00
|
|
|
return cell_unspecified;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
}
|
2019-06-08 14:36:22 +01:00
|
|
|
|
2019-10-28 17:26:55 +00:00
|
|
|
void
|
|
|
|
gc_push_frame ()
|
2019-06-08 14:36:22 +01:00
|
|
|
{
|
2019-10-28 17:26:55 +00:00
|
|
|
if (g_stack < FRAME_SIZE)
|
2019-10-20 15:07:04 +01:00
|
|
|
assert_msg (0, "STACK FULL");
|
2019-10-20 12:23:47 +01:00
|
|
|
g_stack_array[g_stack - 1] = cell_f;
|
2019-10-20 21:32:53 +01:00
|
|
|
g_stack_array[g_stack - 2] = R0;
|
|
|
|
g_stack_array[g_stack - 3] = R1;
|
|
|
|
g_stack_array[g_stack - 4] = R2;
|
|
|
|
g_stack_array[g_stack - 5] = R3;
|
2019-10-28 17:26:55 +00:00
|
|
|
g_stack = g_stack - FRAME_SIZE;
|
2019-06-08 14:36:22 +01:00
|
|
|
}
|
|
|
|
|
2019-10-28 17:26:55 +00:00
|
|
|
void
|
|
|
|
gc_peek_frame ()
|
2019-06-08 14:36:22 +01:00
|
|
|
{
|
2019-10-20 21:32:53 +01:00
|
|
|
R3 = g_stack_array[g_stack];
|
|
|
|
R2 = g_stack_array[g_stack + 1];
|
|
|
|
R1 = g_stack_array[g_stack + 2];
|
|
|
|
R0 = g_stack_array[g_stack + 3];
|
2019-10-28 17:26:55 +00:00
|
|
|
g_stack_array[g_stack + FRAME_PROCEDURE];
|
2019-06-08 14:36:22 +01:00
|
|
|
}
|
|
|
|
|
2019-10-28 17:26:55 +00:00
|
|
|
void
|
|
|
|
gc_pop_frame ()
|
2019-06-08 14:36:22 +01:00
|
|
|
{
|
2019-10-28 17:26:55 +00:00
|
|
|
gc_peek_frame ();
|
|
|
|
g_stack = g_stack + FRAME_SIZE;
|
2019-06-08 14:36:22 +01:00
|
|
|
}
|