core: Drop support for number based cells.

This removes the POINTER_CELLS define and all its references.

* simple.make (CFLAGS): Remove -D POINTER_CELLS.
* include/mes/mes.h: Remove #define POINTER_CELLS.
* include/mes/cc.h: Remove !POINTER_CELLS branches.
* include/mes/macros.h: Likewise.
* src/gc.c: Likewise.
* src/symbol.c: Likewise.
* src/test/gc.c: Likewise.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-09-20 11:32:38 +02:00
parent 5c9f2edd90
commit 1cdbadfe98
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
7 changed files with 3 additions and 188 deletions

View file

@ -21,11 +21,7 @@
#ifndef __MES_CC_H #ifndef __MES_CC_H
#define __MES_CC_H #define __MES_CC_H
#if POINTER_CELLS
typedef struct scm* SCM; typedef struct scm* SCM;
#else
typedef long SCM;
#endif
#if __MESC__ #if __MESC__
typedef long FUNCTION; typedef long FUNCTION;

View file

@ -21,8 +21,6 @@
#ifndef __MES_MACROS_H #ifndef __MES_MACROS_H
#define __MES_MACROS_H #define __MES_MACROS_H
#if POINTER_CELLS
#define TYPE(x) g_cells[x - g_cells].type #define TYPE(x) g_cells[x - g_cells].type
#define CAR(x) g_cells[x - g_cells].car #define CAR(x) g_cells[x - g_cells].car
#define CDR(x) g_cells[x - g_cells].cdr #define CDR(x) g_cells[x - g_cells].cdr
@ -56,43 +54,6 @@
#define NSTRING(x) g_news[x - g_news].string #define NSTRING(x) g_news[x - g_news].string
#define NVECTOR(x) g_news[x - g_news].vector #define NVECTOR(x) g_news[x - g_news].vector
#else
#define TYPE(x) g_cells[x].type
#define CAR(x) g_cells[x].car
#define CDR(x) g_cells[x].cdr
#define NTYPE(x) g_news[x].type
#define NCAR(x) g_news[x].car
#define NCDR(x) g_news[x].cdr
#define STYPE(x) TYPE (g_stack_array[x])
#define SCAR(x) CAR (g_stack_array[x])
#define SCDR(x) CDR (g_stack_array[x])
#define BYTES(x) g_cells[x].car
#define LENGTH(x) g_cells[x].car
#define REF(x) g_cells[x].car
#define VARIABLE(x) g_cells[x].car
#define CLOSURE(x) g_cells[x].cdr
#define CONTINUATION(x) g_cells[x].cdr
#define MACRO(x) g_cells[x].car
#define NAME(x) g_cells[x].cdr
#define PORT(x) g_cells[x].car
#define STRING(x) g_cells[x].cdr
#define STRUCT(x) g_cells[x].cdr
#define VALUE(x) g_cells[x].cdr
#define VECTOR(x) g_cells[x].cdr
#define NLENGTH(x) g_news[x].car
#define NVALUE(x) g_news[x].cdr
#define NSTRING(x) g_news[x].cdr
#define NVECTOR(x) g_news[x].cdr
#endif
#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))

View file

@ -21,8 +21,6 @@
#ifndef __MES_MES_H #ifndef __MES_MES_H
#define __MES_MES_H #define __MES_MES_H
#define POINTER_CELLS 0
#include <sys/types.h> #include <sys/types.h>
#include "mes/cc.h" #include "mes/cc.h"
@ -86,13 +84,8 @@ char *g_arena;
SCM cell_arena; SCM cell_arena;
SCM cell_zero; SCM cell_zero;
#if !POINTER_CELLS
long g_free;
long g_symbol;
#else
SCM g_free; SCM g_free;
SCM g_symbol; SCM g_symbol;
#endif
SCM *g_stack_array; SCM *g_stack_array;
struct scm *g_cells; struct scm *g_cells;

View file

@ -40,7 +40,6 @@ CFLAGS:= \
-D _GNU_SOURCE \ -D _GNU_SOURCE \
-D const= \ -D const= \
-ggdb \ -ggdb \
-D POINTER_CELLS=0 \
-D SYSTEM_LIBC=1 \ -D SYSTEM_LIBC=1 \
-D 'MES_VERSION="git"' \ -D 'MES_VERSION="git"' \
-D 'MES_PKGDATADIR="/usr/local/share/mes"' \ -D 'MES_PKGDATADIR="/usr/local/share/mes"' \

119
src/gc.c
View file

@ -28,34 +28,21 @@
int g_dump_filedes; int g_dump_filedes;
#if __M2_PLANET__
#define M2_CELL_SIZE 12
// CONSTANT M2_CELL_SIZE 12
#else
#define M2_CELL_SIZE 1 #define M2_CELL_SIZE 1
// CONSTANT M2_CELL_SIZE 12 // CONSTANT M2_CELL_SIZE 12
#endif
char * char *
cell_bytes (SCM x) cell_bytes (SCM x)
{ {
#if POINTER_CELLS
char *p = x; char *p = x;
return p + (2 * sizeof (long)); return p + (2 * sizeof (long));
#else
return &CDR (x);
#endif
} }
char * char *
news_bytes (SCM x) news_bytes (SCM x)
{ {
#if POINTER_CELLS
char *p = x; char *p = x;
return p + (2 * sizeof (long)); return p + (2 * sizeof (long));
#else
return &NCDR (x);
#endif
} }
void void
@ -70,16 +57,8 @@ gc_init ()
#endif #endif
STACK_SIZE = 20000; STACK_SIZE = 20000;
#if !POINTER_CELLS
JAM_SIZE = 20000;
MAX_ARENA_SIZE = 100000000;
#elif !__M2_PLANET__
JAM_SIZE = 10; JAM_SIZE = 10;
MAX_ARENA_SIZE = 10000000; MAX_ARENA_SIZE = 10000000;
#else
JAM_SIZE = 10;
MAX_ARENA_SIZE = 20000000;
#endif
GC_SAFETY = 2000; GC_SAFETY = 2000;
MAX_STRING = 524288; MAX_STRING = 524288;
@ -112,13 +91,8 @@ gc_init ()
g_cells = g_arena; g_cells = g_arena;
g_stack_array = g_arena + arena_bytes; g_stack_array = g_arena + arena_bytes;
#if !POINTER_CELLS
/* The vector that holds the arenea. */
cell_arena = -1;
#else
/* The vector that holds the arenea. */ /* The vector that holds the arenea. */
cell_arena = g_cells; cell_arena = g_cells;
#endif
cell_zero = cell_arena + M2_CELL_SIZE; cell_zero = cell_arena + M2_CELL_SIZE;
@ -131,11 +105,7 @@ gc_init ()
TYPE (cell_zero) = TCHAR; TYPE (cell_zero) = TCHAR;
VALUE (cell_zero) = 'c'; VALUE (cell_zero) = 'c';
#if !POINTER_CELLS
g_free = 1;
#else
g_free = g_cells + M2_CELL_SIZE; g_free = g_cells + M2_CELL_SIZE;
#endif
/* FIXME: remove MES_MAX_STRING, grow dynamically. */ /* FIXME: remove MES_MAX_STRING, grow dynamically. */
g_buf = malloc (MAX_STRING); g_buf = malloc (MAX_STRING);
@ -144,22 +114,14 @@ gc_init ()
long long
gc_free () gc_free ()
{ {
#if POINTER_CELLS
return (g_free - g_cells) / M2_CELL_SIZE; return (g_free - g_cells) / M2_CELL_SIZE;
#else
return g_free;
#endif
} }
void void
gc_stats_ (char const* where) gc_stats_ (char const* where)
{ {
#if !POINTER_CELLS
long i = g_free;
#else
long i = g_free - g_cells; long i = g_free - g_cells;
i = i / M2_CELL_SIZE; i = i / M2_CELL_SIZE;
#endif
eputs (where); eputs (where);
eputs (": ["); eputs (": [");
eputs (ltoa (i)); eputs (ltoa (i));
@ -171,12 +133,8 @@ alloc (long n)
{ {
SCM x = g_free; SCM x = g_free;
g_free = g_free + (n * M2_CELL_SIZE); g_free = g_free + (n * M2_CELL_SIZE);
#if !POINTER_CELLS
long i = g_free;
#else
long i = g_free - g_cells; long i = g_free - g_cells;
i = i / M2_CELL_SIZE; i = i / M2_CELL_SIZE;
#endif
if (i > ARENA_SIZE) if (i > ARENA_SIZE)
assert_msg (0, "alloc: out of memory"); assert_msg (0, "alloc: out of memory");
@ -188,12 +146,8 @@ make_cell (long type, SCM car, SCM cdr)
{ {
SCM x = g_free; SCM x = g_free;
g_free = g_free + M2_CELL_SIZE; g_free = g_free + M2_CELL_SIZE;
#if !POINTER_CELLS
long i = g_free;
#else
long i = g_free - g_cells; long i = g_free - g_cells;
i = i / M2_CELL_SIZE; i = i / M2_CELL_SIZE;
#endif
if (i > ARENA_SIZE) if (i > ARENA_SIZE)
assert_msg (0, "alloc: out of memory"); assert_msg (0, "alloc: out of memory");
TYPE (x) = type; TYPE (x) = type;
@ -314,26 +268,15 @@ make_string_port (SCM x) /*:((internal)) */
void void
gc_init_news () gc_init_news ()
{ {
#if !POINTER_CELLS
g_news = g_cells + g_free;
SCM ncell_arena = cell_arena;
#else
g_news = g_free; g_news = g_free;
SCM ncell_arena = g_news; SCM ncell_arena = g_news;
#endif
SCM ncell_zero = ncell_arena + M2_CELL_SIZE; SCM ncell_zero = ncell_arena + M2_CELL_SIZE;
g_news = g_news + M2_CELL_SIZE; g_news = g_news + M2_CELL_SIZE;
NTYPE (ncell_arena) = TVECTOR; NTYPE (ncell_arena) = TVECTOR;
NLENGTH (ncell_arena) = LENGTH (cell_arena); NLENGTH (ncell_arena) = LENGTH (cell_arena);
#if !POINTER_CELLS
NVECTOR (ncell_arena) = 0;
#else
NVECTOR (ncell_arena) = g_news; NVECTOR (ncell_arena) = g_news;
#endif
NTYPE (ncell_zero) = TCHAR; NTYPE (ncell_zero) = TCHAR;
NVALUE (ncell_zero) = 'n'; NVALUE (ncell_zero) = 'n';
@ -352,25 +295,16 @@ gc_up_arena ()
else else
ARENA_SIZE = MAX_ARENA_SIZE - JAM_SIZE; ARENA_SIZE = MAX_ARENA_SIZE - JAM_SIZE;
long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm); long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm);
#if !POINTER_CELLS
long stack_offset = arena_bytes;
long realloc_bytes = arena_bytes + (STACK_SIZE * sizeof (struct scm));
#else
long stack_offset = (arena_bytes * 2); long stack_offset = (arena_bytes * 2);
long realloc_bytes = (arena_bytes * 2) + (STACK_SIZE * sizeof (struct scm)); long realloc_bytes = (arena_bytes * 2) + (STACK_SIZE * sizeof (struct scm));
#endif
void *p = realloc (g_cells - M2_CELL_SIZE, realloc_bytes); void *p = realloc (g_cells - M2_CELL_SIZE, realloc_bytes);
if (p == 0) if (p == 0)
{ {
eputs ("realloc failed, g_free="); eputs ("realloc failed, g_free=");
eputs (ltoa (g_free)); eputs (ltoa (g_free));
eputs (":"); eputs (":");
#if !POINTER_CELLS
long i = g_free;
#else
long i = g_free - g_cells; long i = g_free - g_cells;
i = i / M2_CELL_SIZE; i = i / M2_CELL_SIZE;
#endif
eputs (ltoa (ARENA_SIZE - i)); eputs (ltoa (ARENA_SIZE - i));
eputs ("\n"); eputs ("\n");
assert_msg (0, "0"); assert_msg (0, "0");
@ -468,7 +402,6 @@ gc_cellcpy (struct scm *dest, struct scm *src, size_t n)
void void
gc_flip () gc_flip ()
{ {
#if POINTER_CELLS
if (g_free - g_news > JAM_SIZE) if (g_free - g_news > JAM_SIZE)
JAM_SIZE = (g_free - g_news) + ((g_free - g_news) / 2); JAM_SIZE = (g_free - g_news) + ((g_free - g_news) / 2);
@ -486,25 +419,8 @@ gc_flip ()
for (i = g_stack; i < STACK_SIZE; i = i + 1) for (i = g_stack; i < STACK_SIZE; i = i + 1)
g_stack_array[i] = g_stack_array[i] - dist; g_stack_array[i] = g_stack_array[i] - dist;
#else
g_cells = g_news;
cell_arena = g_news - M2_CELL_SIZE;
cell_zero = cell_arena + M2_CELL_SIZE;
cell_nil = cell_zero + M2_CELL_SIZE;
#endif
if (g_debug > 2) if (g_debug > 2)
gc_stats_ (";;; => jam"); gc_stats_ (";;; => jam");
#if POINTER_CELLS
/* Nothing. */
return;
#else
if (g_free > JAM_SIZE)
JAM_SIZE = g_free + g_free / 2;
memcpy (g_cells, g_news, g_free * sizeof (struct scm));
#endif
} }
SCM SCM
@ -618,11 +534,7 @@ gc_loop (SCM scan)
SCM SCM
gc_check () gc_check ()
{ {
#if !POINTER_CELLS
long used = g_free + GC_SAFETY;
#else
long used = ((g_free - g_cells) / M2_CELL_SIZE) + GC_SAFETY; long used = ((g_free - g_cells) / M2_CELL_SIZE) + GC_SAFETY;
#endif
if (used >= ARENA_SIZE) if (used >= ARENA_SIZE)
return gc (); return gc ();
return cell_unspecified; return cell_unspecified;
@ -641,11 +553,7 @@ gc_ ()
eputs (ltoa (ARENA_SIZE - gc_free ())); eputs (ltoa (ARENA_SIZE - gc_free ()));
eputs ("]..."); eputs ("]...");
} }
#if !POINTER_CELLS
g_free = 1;
#else
g_free = g_news + M2_CELL_SIZE; g_free = g_news + M2_CELL_SIZE;
#endif
if (ARENA_SIZE < MAX_ARENA_SIZE && g_cells == g_arena + M2_CELL_SIZE) if (ARENA_SIZE < MAX_ARENA_SIZE && g_cells == g_arena + M2_CELL_SIZE)
{ {
@ -760,14 +668,10 @@ void
gc_dump_register (char const* n, SCM r) gc_dump_register (char const* n, SCM r)
{ {
dumps (n); dumps (": "); dumps (n); dumps (": ");
#if !POINTER_CELLS
long i = r;
#else
long i = r; long i = r;
long a = g_arena; long a = g_arena;
i = i - a; i = i - a;
i = i / M2_CELL_SIZE; i = i / M2_CELL_SIZE;
#endif
dumps (ltoa (i)); dumps (ltoa (i));
dumps ("\n"); dumps ("\n");
} }
@ -802,13 +706,8 @@ gc_dump_stack ()
void void
gc_dump_arena (struct scm *cells, long size) gc_dump_arena (struct scm *cells, long size)
{ {
#if !POINTER_CELLS
SCM end = size;
struct scm *dist = 0;
#else
SCM end = g_cells + (size * M2_CELL_SIZE); SCM end = g_cells + (size * M2_CELL_SIZE);
struct scm *dist = cells; struct scm *dist = cells;
#endif
if (g_dump_filedes == 0) if (g_dump_filedes == 0)
g_dump_filedes = mes_open ("dump.mo", O_CREAT|O_WRONLY, 0644); g_dump_filedes = mes_open ("dump.mo", O_CREAT|O_WRONLY, 0644);
dumps ("stack="); dumps (ltoa (g_stack)); dumpc ('\n'); dumps ("stack="); dumps (ltoa (g_stack)); dumpc ('\n');
@ -834,7 +733,6 @@ gc_dump_arena (struct scm *cells, long size)
{ {
dumps (ltoa (t)); dumps (ltoa (t));
dumpc (' '); dumpc (' ');
#if POINTER_CELLS
if (t == TMACRO if (t == TMACRO
|| t == TPAIR || t == TPAIR
|| t == TREF || t == TREF
@ -844,12 +742,10 @@ gc_dump_arena (struct scm *cells, long size)
/* dumps ("["); dumps (ltoa (a)); dumps ("]"); */ /* dumps ("["); dumps (ltoa (a)); dumps ("]"); */
} }
else else
#endif
dumps (ltoa (a)); dumps (ltoa (a));
dumpc (' '); dumpc (' ');
if (t != TBYTES) if (t != TBYTES)
{ {
#if POINTER_CELLS
if (t == TCLOSURE if (t == TCLOSURE
|| t == TCONTINUATION || t == TCONTINUATION
|| t == TKEYWORD || t == TKEYWORD
@ -866,12 +762,10 @@ gc_dump_arena (struct scm *cells, long size)
dumps (ltoa ((cells->cdr - dist) / M2_CELL_SIZE)); dumps (ltoa ((cells->cdr - dist) / M2_CELL_SIZE));
/* dumps ("["); dumps (ltoa (d)); dumps ("]"); */ /* dumps ("["); dumps (ltoa (d)); dumps ("]"); */
} }
else if (t == TNUMBER && d > 1000)
dumps (ltoa (1001));
else else
#endif dumps (ltoa (d));
if (t == TNUMBER && d > 1000)
dumps (ltoa (1001));
else
dumps (ltoa (d));
} }
if (t == TBYTES) if (t == TBYTES)
{ {
@ -890,13 +784,6 @@ gc_dump_arena (struct scm *cells, long size)
cells = cells + c * M2_CELL_SIZE; cells = cells + c * M2_CELL_SIZE;
size = size - c; size = size - c;
} }
#if 0
else if (t == TSTRUCT)
{
cells = cells + (a + 1) * M2_CELL_SIZE;
size = size - a - 1;
}
#endif
else else
{ {
cells = cells + M2_CELL_SIZE; cells = cells + M2_CELL_SIZE;

View file

@ -33,11 +33,7 @@
// CONSTANT M2_CELL_SIZE 12 // CONSTANT M2_CELL_SIZE 12
#endif #endif
#if !POINTER_CELLS
long g_symbol;
#else
SCM g_symbol; SCM g_symbol;
#endif
SCM SCM
init_symbol (SCM x, long type, char const *name) init_symbol (SCM x, long type, char const *name)
@ -184,11 +180,7 @@ init_symbols_ () /*:((internal)) */
SCM SCM
init_symbols () /*:((internal)) */ init_symbols () /*:((internal)) */
{ {
#if !POINTER_CELLS
g_free = 1;
#else
g_free = g_cells + M2_CELL_SIZE; g_free = g_cells + M2_CELL_SIZE;
#endif
g_symbols = 0; g_symbols = 0;
cell_nil = g_free; cell_nil = g_free;

View file

@ -24,26 +24,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if POINTER_CELLS
#define M2_CELL_SIZE 1 #define M2_CELL_SIZE 1
// CONSTANT M2_CELL_SIZE 12 // CONSTANT M2_CELL_SIZE 12
#else
#define M2_CELL_SIZE 1
// CONSTANT M2_CELL_SIZE 1
#endif
int g_debug; int g_debug;
void void
test_setup () test_setup ()
{ {
#if POINTER_CELLS
cell_arena = g_arena; cell_arena = g_arena;
g_cells = cell_arena + M2_CELL_SIZE; g_cells = cell_arena + M2_CELL_SIZE;
cell_zero = g_cells; cell_zero = g_cells;
#else
cell_zero = 0;
#endif
cell_nil = cell_zero + M2_CELL_SIZE; cell_nil = cell_zero + M2_CELL_SIZE;
cell_f = cell_nil + M2_CELL_SIZE; cell_f = cell_nil + M2_CELL_SIZE;
@ -186,11 +177,7 @@ main (int argc, char **argv, char **envp)
setenv ("MES_ARENA", "100", 1); setenv ("MES_ARENA", "100", 1);
setenv ("MES_MAX_ARENA", "100", 1); setenv ("MES_MAX_ARENA", "100", 1);
gc_init (); gc_init ();
#if POINTER_CELLS
cell_zero = g_cells; cell_zero = g_cells;
#else
cell_zero = 0;
#endif
cell_nil = cell_zero + M2_CELL_SIZE; cell_nil = cell_zero + M2_CELL_SIZE;
cell_f = cell_nil + M2_CELL_SIZE; cell_f = cell_nil + M2_CELL_SIZE;
g_symbols = cell_zero; g_symbols = cell_zero;