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/>.
25 SCM cache_invalidate (SCM x){}
26 SCM cache_invalidate_range (SCM p,SCM a){}
27 SCM cache_save (SCM p){}
28 SCM cache_lookup (SCM x){}
31 SCM env_cache_cars[CACHE_SIZE];
32 SCM env_cache_cdrs[CACHE_SIZE];
33 int cache_threshold = 0;
37 int n = g_cells[car (p)].hits;
38 if (n < cache_threshold) return cell_unspecified;
40 for (int i=0; i < CACHE_SIZE; i++) {
41 if (!env_cache_cars[i]) {
45 if (env_cache_cars[i] == car (p)) return cell_unspecified;
46 if (n > g_cells[env_cache_cars[i]].hits) {
47 n = g_cells[env_cache_cars[i]].hits;
52 cache_threshold = g_cells[car (p)].hits;
53 env_cache_cars[j] = car (p);
54 env_cache_cdrs[j] = cdr (p);
56 return cell_unspecified;
62 for (int i=0; i < CACHE_SIZE; i++) {
63 if (!env_cache_cars[i]) break;
64 if (env_cache_cars[i] == x) return env_cache_cdrs[i];
66 return cell_undefined;
70 cache_invalidate (SCM x)
72 for (int i=0; i < CACHE_SIZE; i++) {
73 if (env_cache_cars[i] == x) {
74 env_cache_cars[i] = 0;
78 return cell_unspecified;
82 cache_invalidate_range (SCM p, SCM a)
85 cache_invalidate (caar (p));
88 return cell_unspecified;
92 assq_ref_cache (SCM x, SCM a) ///((internal))
95 SCM c = cache_lookup (x);
96 if (c != cell_undefined) return c;
98 while (a != cell_nil && x != CAAR (a)) {i++;a = cdr (a);}
99 if (a == cell_nil) return cell_undefined;
100 if (i>ENV_HEAD) cache_save (car (a));