Revert "mes.c: use single malloc with arena."

This reverts commit 38c364faeff430a5ee28f402d24b073f6bf9a548.
This commit is contained in:
Jan Nieuwenhuizen 2016-09-25 10:13:09 +02:00
parent b955b84d20
commit 697858f670

30
mes.c
View file

@ -69,19 +69,6 @@ typedef struct scm_t {
#define MES_C 1 #define MES_C 1
#include "mes.h" #include "mes.h"
char *g_arena;
int ARENA_SIZE = 1024 * 1024 * 1024;
void *
xmalloc (int size)
{
static char *arena_start = 0;
if (!arena_start) arena_start = g_arena;
assert (g_arena - arena_start + size < ARENA_SIZE);
char* x = g_arena;
g_arena += size;
return x;
}
scm *display_helper (FILE*, scm*, bool, char*, bool); scm *display_helper (FILE*, scm*, bool, char*, bool);
bool bool
symbol_eq (scm *x, char *s) symbol_eq (scm *x, char *s)
@ -153,7 +140,7 @@ cdr (scm *x)
scm * scm *
cons (scm *x, scm *y) cons (scm *x, scm *y)
{ {
scm *p = xmalloc (sizeof (scm)); scm *p = malloc (sizeof (scm));
p->type = PAIR; p->type = PAIR;
p->car = x; p->car = x;
p->cdr = y; p->cdr = y;
@ -580,7 +567,7 @@ append (scm *x/*...*/)
scm * scm *
make_char (int x) make_char (int x)
{ {
scm *p = xmalloc (sizeof (scm)); scm *p = malloc (sizeof (scm));
p->type = CHAR; p->type = CHAR;
p->value = x; p->value = x;
return p; return p;
@ -589,7 +576,7 @@ make_char (int x)
scm * scm *
make_macro (scm *x, char *name) make_macro (scm *x, char *name)
{ {
scm *p = xmalloc (sizeof (scm)); scm *p = malloc (sizeof (scm));
p->type = MACRO; p->type = MACRO;
p->macro = x; p->macro = x;
p->name = name; p->name = name;
@ -599,7 +586,7 @@ make_macro (scm *x, char *name)
scm * scm *
make_number (int x) make_number (int x)
{ {
scm *p = xmalloc (sizeof (scm)); scm *p = malloc (sizeof (scm));
p->type = NUMBER; p->type = NUMBER;
p->value = x; p->value = x;
return p; return p;
@ -608,7 +595,7 @@ make_number (int x)
scm * scm *
make_string (char const *s) make_string (char const *s)
{ {
scm *p = xmalloc (sizeof (scm)); scm *p = malloc (sizeof (scm));
p->type = STRING; p->type = STRING;
p->name = strdup (s); p->name = strdup (s);
return p; return p;
@ -618,7 +605,7 @@ scm *
make_symbol (char const *s) make_symbol (char const *s)
{ {
// TODO: alist lookup symbols // TODO: alist lookup symbols
scm *p = xmalloc (sizeof (scm)); scm *p = malloc (sizeof (scm));
p->type = SYMBOL; p->type = SYMBOL;
p->name = strdup (s); p->name = strdup (s);
return p; return p;
@ -627,10 +614,10 @@ make_symbol (char const *s)
scm * scm *
make_vector (int n) make_vector (int n)
{ {
scm *p = xmalloc (sizeof (scm)); scm *p = malloc (sizeof (scm));
p->type = VECTOR; p->type = VECTOR;
p->length = n; p->length = n;
p->vector = xmalloc (n * sizeof (scm*)); p->vector = malloc (n * sizeof (scm*));
return p; return p;
} }
@ -1428,7 +1415,6 @@ read_file (scm *e, scm *a)
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
g_arena = malloc (ARENA_SIZE);
scm *a = mes_environment (); scm *a = mes_environment ();
display_ (stderr, eval (cons (&symbol_begin, read_file (readenv (a), a)), a)); display_ (stderr, eval (cons (&symbol_begin, read_file (readenv (a), a)), a));
fputs ("", stderr); fputs ("", stderr);