From d73df09ab63b899724351d1e4a8569b08142cb1f Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 14 Dec 2017 07:05:53 +0100 Subject: [PATCH] core: Use array-based stack. * src/mes.c (STACK_SIZE)[MES_ARRAY_STACK]: New variable. (g_stack_array): New variable. (g_stack): Change type to SCM*. (gc_push_frame)[MES_ARRAY_STACK]: Use g_stack_array, g_stack. (gc_peek_frame): Likewise. (gc_pop_frame): Likewise. * src/gc.c (gc_check): Likewise. (gc): Likewise. --- scaffold/mini-mes.c | 2 ++ src/gc.c | 22 +++++------- src/mes.c | 87 ++++++++++++++++++++++++++++++--------------- 3 files changed, 69 insertions(+), 42 deletions(-) diff --git a/scaffold/mini-mes.c b/scaffold/mini-mes.c index 797b9d5f..18f8308f 100644 --- a/scaffold/mini-mes.c +++ b/scaffold/mini-mes.c @@ -34,6 +34,7 @@ int ARENA_SIZE = 200000; // 32b: 2MiB, 64b: 4 MiB int MAX_ARENA_SIZE = 300000000; +long STACK_SIZE = 20000; int JAM_SIZE = 20000; int GC_SAFETY = 2000; @@ -48,6 +49,7 @@ SCM g_symbols = 0; SCM g_macros = 0; SCM g_ports = 0; SCM g_stack = 0; +SCM *g_stack_array = 0; // a/env SCM r0 = 0; // param 1 diff --git a/src/gc.c b/src/gc.c index eb4163b9..fc2cd5c3 100644 --- a/src/gc.c +++ b/src/gc.c @@ -23,6 +23,7 @@ SCM gc_up_arena () ///((internal)) { + long old_arena_bytes = (ARENA_SIZE+JAM_SIZE)*sizeof (struct scm); if (ARENA_SIZE >> 1 < MAX_ARENA_SIZE >> 2) { ARENA_SIZE <<= 1; @@ -31,7 +32,8 @@ gc_up_arena () ///((internal)) } else ARENA_SIZE = MAX_ARENA_SIZE -JAM_SIZE; - void *p = realloc (g_cells-1, (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)); if (!p) { eputs ("realloc failed, g_free="); @@ -43,12 +45,13 @@ gc_up_arena () ///((internal)) exit (1); } g_cells = (struct scm*)p; + memcpy (p + arena_bytes, p + old_arena_bytes, STACK_SIZE*sizeof (SCM)); g_cells++; return 0; } -SCM +void gc_flip () ///((internal)) { if (g_debug > 2) @@ -60,7 +63,6 @@ gc_flip () ///((internal)) if (g_free > JAM_SIZE) JAM_SIZE = g_free + g_free / 2; memcpy (g_cells-1, g_news-1, (g_free+2)*sizeof (struct scm)); - return g_stack; } SCM @@ -96,7 +98,7 @@ gc_relocate_cdr (SCM new, SCM cdr) ///((internal)) return cell_unspecified; } -SCM +void gc_loop (SCM scan) ///((internal)) { SCM car; @@ -132,7 +134,7 @@ gc_loop (SCM scan) ///((internal)) } scan++; } - return gc_flip (); + gc_flip (); } SCM @@ -200,14 +202,8 @@ gc_ () ///((internal)) g_symbols = gc_copy (g_symbols); g_macros = gc_copy (g_macros); g_ports = gc_copy (g_ports); - SCM new = gc_copy (g_stack); - if (g_debug > 3) - { - eputs ("new="); - eputs (itoa (new)); - eputs ("\n"); - } - g_stack = new; + for (long i=g_stack; i