/* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software * Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * * Mes is free software; you can redistribute it and/or modify it * 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. * * Mes is distributed in the hope that it will be useful, but * 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 * along with Mes. If not, see . */ #include SCM gc_up_arena () ///((internal)) { ARENA_SIZE *= 2; void *p = realloc (g_cells-1, 2*ARENA_SIZE*sizeof(struct scm)); if (!p) { eputs ("realloc failed, g_free="); eputs (itoa (g_free)); eputs (":"); eputs (itoa (ARENA_SIZE - g_free)); eputs ("\n"); assert (0); exit (1); } g_cells = (struct scm*)p; g_cells++; gc_init_news (); return 0; } SCM gc_flip () ///((internal)) { struct scm *cells = g_cells; g_cells = g_news; g_news = cells; if (g_debug > 2) { eputs (";;; => jam["); eputs (itoa (g_free)); eputs ("]\n"); } return g_stack; } SCM gc_copy (SCM old) ///((internal)) { if (TYPE (old) == TBROKEN_HEART) return g_cells[old].car; SCM new = g_free++; g_news[new] = g_cells[old]; if (NTYPE (new) == TVECTOR) { NVECTOR (new) = g_free; for (int i=0; i ARENA_SIZE) gc (); return cell_unspecified; } SCM gc_ () ///((internal)) { if (g_debug == 2) eputs ("."); if (g_debug > 2) { eputs (";;; gc["); eputs (itoa (g_free)); eputs (":"); eputs (itoa (ARENA_SIZE - g_free)); eputs ("]..."); } g_free = 1; if (g_cells < g_news //&& g_free > ARENA_SIZE >> 2 && ARENA_SIZE < MAX_ARENA_SIZE) { if (g_debug == 2) eputs ("+"); if (g_debug > 2) { eputs (" up["); eputs (itoa (g_cells)); eputs (","); eputs (itoa (g_news)); eputs (":"); eputs (itoa (ARENA_SIZE)); eputs (","); eputs (itoa (MAX_ARENA_SIZE)); eputs ("]..."); } gc_up_arena (); } for (int i=g_free; i 3) { eputs ("new="); eputs (itoa (new)); eputs ("\n"); } g_stack = new; gc_loop (1); } SCM gc () { if (g_debug > 4) { eputs ("symbols: "); write_error_ (g_symbols); eputs ("\n"); eputs ("R0: "); write_error_ (r0); eputs ("\n"); } gc_push_frame (); gc_ (); gc_pop_frame (); if (g_debug > 4) { eputs ("symbols: "); write_error_ (g_symbols); eputs ("\n"); eputs ("R0: "); write_error_ (r0); eputs ("\n"); } }