core: Prepare for M2-Planet: M2_CELL_SIZE.
* src/gc.c (M2_CELL_SIZE): Hack for missing pointer arithmetic in M2-Planet. (gc_init, alloc, make_cell, gc_up_arena, gc_copy, gc_loop, gc_): Use it.
This commit is contained in:
parent
a6c9002c32
commit
a54f6e9028
28
src/gc.c
28
src/gc.c
|
@ -89,9 +89,9 @@ gc_init ()
|
||||||
|
|
||||||
long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm);
|
long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm);
|
||||||
#if POINTER_CELLS
|
#if POINTER_CELLS
|
||||||
void *a = malloc (arena_bytes + STACK_SIZE * sizeof (SCM) * 2);
|
void *a = malloc (arena_bytes + (STACK_SIZE * sizeof (SCM) * 2));
|
||||||
#else
|
#else
|
||||||
void *a = malloc (arena_bytes + STACK_SIZE * sizeof (SCM));
|
void *a = malloc (arena_bytes + (STACK_SIZE * sizeof (SCM)));
|
||||||
#endif
|
#endif
|
||||||
g_cells = a;
|
g_cells = a;
|
||||||
g_stack_array = a + arena_bytes;
|
g_stack_array = a + arena_bytes;
|
||||||
|
@ -106,7 +106,7 @@ gc_init ()
|
||||||
TYPE (cell_arena) = TVECTOR;
|
TYPE (cell_arena) = TVECTOR;
|
||||||
LENGTH (cell_arena) = 1000;
|
LENGTH (cell_arena) = 1000;
|
||||||
VECTOR (cell_arena) = 0;
|
VECTOR (cell_arena) = 0;
|
||||||
g_cells = g_cells + 1;
|
g_cells = g_cells + M2_CELL_SIZE;
|
||||||
TYPE (cell_arena) = TCHAR;
|
TYPE (cell_arena) = TCHAR;
|
||||||
VALUE (cell_arena) = 'c';
|
VALUE (cell_arena) = 'c';
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ SCM
|
||||||
alloc (long n)
|
alloc (long n)
|
||||||
{
|
{
|
||||||
SCM x = g_free;
|
SCM x = g_free;
|
||||||
g_free = g_free + n;
|
g_free = g_free + (n * M2_CELL_SIZE);
|
||||||
#if POINTER_CELLS
|
#if POINTER_CELLS
|
||||||
long i = g_free - g_cells;
|
long i = g_free - g_cells;
|
||||||
#else
|
#else
|
||||||
|
@ -163,7 +163,7 @@ SCM
|
||||||
make_cell (long type, SCM car, SCM cdr)
|
make_cell (long type, SCM car, SCM cdr)
|
||||||
{
|
{
|
||||||
SCM x = g_free;
|
SCM x = g_free;
|
||||||
g_free = g_free + 1;
|
g_free = g_free + M2_CELL_SIZE;
|
||||||
#if POINTER_CELLS
|
#if POINTER_CELLS
|
||||||
long i = g_free - g_cells;
|
long i = g_free - g_cells;
|
||||||
#else
|
#else
|
||||||
|
@ -202,7 +202,7 @@ copy_stack (long index, SCM from)
|
||||||
SCM
|
SCM
|
||||||
cell_ref (SCM cell, long index)
|
cell_ref (SCM cell, long index)
|
||||||
{
|
{
|
||||||
return cell + index;
|
return cell + (index * M2_CELL_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
|
@ -315,7 +315,7 @@ 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);
|
||||||
void *p = realloc (g_cells - 1, arena_bytes + STACK_SIZE * sizeof (SCM));
|
void *p = realloc (g_cells - M2_CELL_SIZE, (arena_bytes + STACK_SIZE) * sizeof (SCM));
|
||||||
if (p == 0)
|
if (p == 0)
|
||||||
{
|
{
|
||||||
eputs ("realloc failed, g_free=");
|
eputs ("realloc failed, g_free=");
|
||||||
|
@ -333,7 +333,7 @@ gc_up_arena ()
|
||||||
}
|
}
|
||||||
g_cells = p;
|
g_cells = p;
|
||||||
memcpy (p + arena_bytes, p + old_arena_bytes, STACK_SIZE * sizeof (SCM));
|
memcpy (p + arena_bytes, p + old_arena_bytes, STACK_SIZE * sizeof (SCM));
|
||||||
g_cells = g_cells + 1;
|
g_cells = g_cells + M2_CELL_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -361,7 +361,7 @@ gc_copy (SCM old) /*:((internal)) */
|
||||||
if (TYPE (old) == TBROKEN_HEART)
|
if (TYPE (old) == TBROKEN_HEART)
|
||||||
return CAR (old);
|
return CAR (old);
|
||||||
SCM new = g_free;
|
SCM new = g_free;
|
||||||
g_free = g_free + 1;
|
g_free = g_free + M2_CELL_SIZE;
|
||||||
copy_news (new, old);
|
copy_news (new, old);
|
||||||
if (NTYPE (new) == TSTRUCT || NTYPE (new) == TVECTOR)
|
if (NTYPE (new) == TSTRUCT || NTYPE (new) == TVECTOR)
|
||||||
{
|
{
|
||||||
|
@ -370,16 +370,16 @@ gc_copy (SCM old) /*:((internal)) */
|
||||||
for (i = 0; i < LENGTH (old); i = i + 1)
|
for (i = 0; i < LENGTH (old); i = i + 1)
|
||||||
{
|
{
|
||||||
copy_news (g_free, cell_ref (VECTOR (old), i));
|
copy_news (g_free, cell_ref (VECTOR (old), i));
|
||||||
g_free = g_free + 1;
|
g_free = g_free + M2_CELL_SIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (NTYPE (new) == TBYTES)
|
else if (NTYPE (new) == TBYTES)
|
||||||
{
|
{
|
||||||
char const *src = cell_bytes (old);
|
char const *src = cell_bytes (old);
|
||||||
char *dest = news_bytes (new);
|
char *dest = news_bytes (new);
|
||||||
size_t length = NLENGTH (old);
|
size_t length = NLENGTH (new);
|
||||||
memcpy (dest, src, length);
|
memcpy (dest, src, length);
|
||||||
g_free = g_free + bytes_cells (length) - 1;
|
g_free = g_free + ((bytes_cells (length) - 1) * M2_CELL_SIZE);
|
||||||
|
|
||||||
if (g_debug > 4)
|
if (g_debug > 4)
|
||||||
{
|
{
|
||||||
|
@ -519,14 +519,14 @@ gc_ ()
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM s;
|
SCM s;
|
||||||
for (s = cell_nil; s < g_symbol_max; s = s + 1)
|
for (s = cell_nil; s < g_symbol_max; s = s + M2_CELL_SIZE)
|
||||||
gc_copy (s);
|
gc_copy (s);
|
||||||
g_symbols = gc_copy (g_symbols);
|
g_symbols = gc_copy (g_symbols);
|
||||||
g_macros = gc_copy (g_macros);
|
g_macros = gc_copy (g_macros);
|
||||||
g_ports = gc_copy (g_ports);
|
g_ports = gc_copy (g_ports);
|
||||||
M0 = gc_copy (M0);
|
M0 = gc_copy (M0);
|
||||||
long i;
|
long i;
|
||||||
for (i = g_stack; i < STACK_SIZE; i = i + 1)
|
for (i = g_stack; i < STACK_SIZE; i = i + M2_CELL_SIZE)
|
||||||
copy_stack (i, gc_copy (g_stack_array[i]));
|
copy_stack (i, gc_copy (g_stack_array[i]));
|
||||||
#if POINTER_CELLS
|
#if POINTER_CELLS
|
||||||
long save_gfree = g_free;
|
long save_gfree = g_free;
|
||||||
|
|
|
@ -29,7 +29,7 @@ hash_cstring (char const *s, long size)
|
||||||
int hash = s[0] * 37;
|
int hash = s[0] * 37;
|
||||||
if (s[0] != 0)
|
if (s[0] != 0)
|
||||||
if (s[1] != 0)
|
if (s[1] != 0)
|
||||||
hash = hash + s[1] * 43;
|
hash = hash + (s[1] * 43);
|
||||||
assert_msg (size != 0, "size");
|
assert_msg (size != 0, "size");
|
||||||
hash = hash % size;
|
hash = hash % size;
|
||||||
return hash;
|
return hash;
|
||||||
|
|
24
src/symbol.c
24
src/symbol.c
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
// char const *MES_VERSION = "0.23";
|
||||||
|
|
||||||
#if __M2_PLANET__
|
#if __M2_PLANET__
|
||||||
#define M2_CELL_SIZE 12
|
#define M2_CELL_SIZE 12
|
||||||
// CONSTANT M2_CELL_SIZE 12
|
// CONSTANT M2_CELL_SIZE 12
|
||||||
|
@ -31,10 +33,10 @@
|
||||||
// CONSTANT M2_CELL_SIZE 12
|
// CONSTANT M2_CELL_SIZE 12
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if POINTER_CELLS
|
#if !POINTER_CELLS
|
||||||
SCM g_symbol;
|
|
||||||
#else
|
|
||||||
long g_symbol;
|
long g_symbol;
|
||||||
|
#else
|
||||||
|
SCM g_symbol;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
|
@ -182,26 +184,16 @@ init_symbols_ () /*:((internal)) */
|
||||||
SCM
|
SCM
|
||||||
init_symbols () /*:((internal)) */
|
init_symbols () /*:((internal)) */
|
||||||
{
|
{
|
||||||
#if POINTER_CELLS
|
#if !POINTER_CELLS
|
||||||
g_free = g_cells + M2_CELL_SIZE;
|
|
||||||
#else
|
|
||||||
g_free = 1;
|
g_free = 1;
|
||||||
|
#else
|
||||||
|
g_free = g_cells + M2_CELL_SIZE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_symbols = 0;
|
g_symbols = 0;
|
||||||
cell_nil = g_free;
|
cell_nil = g_free;
|
||||||
init_symbols_ ();
|
init_symbols_ ();
|
||||||
|
|
||||||
#if POINTER_CELLS
|
|
||||||
assert_msg ("UNSPEC", cell_unspecified - g_cells == CELL_UNSPECIFIED);
|
|
||||||
assert_msg ("RECORD-TYPE", cell_symbol_record_type - g_cells == CELL_SYMBOL_RECORD_TYPE);
|
|
||||||
g_symbol_max = g_symbol;
|
g_symbol_max = g_symbol;
|
||||||
#else
|
|
||||||
assert_msg ("UNSPEC", cell_unspecified == CELL_UNSPECIFIED);
|
|
||||||
assert_msg ("RECORD-TYPE", cell_symbol_record_type == CELL_SYMBOL_RECORD_TYPE);
|
|
||||||
g_symbol_max = g_symbol;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
g_symbols = make_hash_table_ (500);
|
g_symbols = make_hash_table_ (500);
|
||||||
init_symbols_ ();
|
init_symbols_ ();
|
||||||
g_ports = cell_nil;
|
g_ports = cell_nil;
|
||||||
|
|
10
src/vector.c
10
src/vector.c
|
@ -21,6 +21,14 @@
|
||||||
#include "mes/lib.h"
|
#include "mes/lib.h"
|
||||||
#include "mes/mes.h"
|
#include "mes/mes.h"
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
make_vector__ (long k)
|
make_vector__ (long k)
|
||||||
{
|
{
|
||||||
|
@ -98,7 +106,7 @@ list_to_vector (SCM x)
|
||||||
while (x != cell_nil)
|
while (x != cell_nil)
|
||||||
{
|
{
|
||||||
copy_cell (p, vector_entry (car (x)));
|
copy_cell (p, vector_entry (car (x)));
|
||||||
p = p + 1;
|
p = p + M2_CELL_SIZE;
|
||||||
x = cdr (x);
|
x = cdr (x);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
|
Loading…
Reference in a new issue