1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of Mes.
7 * Mes is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
12 * Mes is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Mes. If not, see <http://www.gnu.org/licenses/>.
22 gc_up_arena () ///((internal))
27 void *p = realloc (g_cells-1, 2*ARENA_SIZE*sizeof(struct scm));
30 p = realloc (p-sizeof (struct scm), 2*ARENA_SIZE*sizeof(struct scm));
34 if (!p) error (cell_symbol_system_error, cons (MAKE_STRING (cstring_to_list (strerror (errno))), MAKE_NUMBER (g_free)));
35 g_cells = (struct scm*)p;
43 gc_flip () ///((internal))
45 struct scm *cells = g_cells;
50 eputs (";;; => jam[");
51 eputs (itoa (g_free));
58 gc_copy (SCM old) ///((internal))
60 if (TYPE (old) == TBROKEN_HEART) return g_cells[old].car;
62 g_news[new] = g_cells[old];
63 if (NTYPE (new) == TVECTOR)
65 NVECTOR (new) = g_free;
66 for (int i=0; i<LENGTH (old); i++)
67 g_news[g_free++] = g_cells[VECTOR (old)+i];
69 TYPE (old) = TBROKEN_HEART;
75 gc_relocate_car (SCM new, SCM car) ///((internal))
77 g_news[new].car = car;
78 return cell_unspecified;
82 gc_relocate_cdr (SCM new, SCM cdr) ///((internal))
84 g_news[new].cdr = cdr;
85 return cell_unspecified;
89 gc_loop (SCM scan) ///((internal))
93 if (NTYPE (scan) == TCLOSURE
94 || NTYPE (scan) == TCONTINUATION
95 || NTYPE (scan) == TFUNCTION
96 || NTYPE (scan) == TKEYWORD
97 || NTYPE (scan) == TMACRO
98 || NTYPE (scan) == TPAIR
99 || NTYPE (scan) == TREF
101 || NTYPE (scan) == TSPECIAL
102 || NTYPE (scan) == TSTRING
103 || NTYPE (scan) == TSYMBOL)
105 SCM car = gc_copy (g_news[scan].car);
106 gc_relocate_car (scan, car);
108 if ((NTYPE (scan) == TCLOSURE
109 || NTYPE (scan) == TCONTINUATION
110 || NTYPE (scan) == TMACRO
111 || NTYPE (scan) == TPAIR
112 || NTYPE (scan) == TVALUES)
113 && g_news[scan].cdr) // allow for 0 terminated list of symbols
115 SCM cdr = gc_copy (g_news[scan].cdr);
116 gc_relocate_cdr (scan, cdr);
126 if (g_free + GC_SAFETY > ARENA_SIZE)
127 gc_pop_frame (gc (gc_push_frame ()));
128 return cell_unspecified;
137 eputs (itoa (g_free));
139 eputs (itoa (ARENA_SIZE - g_free));
143 if (g_cells < g_news && ARENA_SIZE < MAX_ARENA_SIZE) gc_up_arena ();
144 for (int i=g_free; i<g_symbol_max; i++)
147 g_symbols = gc_copy (g_symbols);
148 SCM new = gc_copy (g_stack);