1 /* -*-comment-start: "//";comment-end:""-*-
2 * GNU Mes --- Maxwell Equations of Software
3 * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of GNU Mes.
7 * GNU 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 * GNU 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
22 make_struct (SCM type, SCM fields, SCM printer)
24 long size = 2 + length__ (fields);
26 SCM x = make_cell__ (TSTRUCT, size, v);
27 g_cells[v] = g_cells[vector_entry (type)];
28 g_cells[v+1] = g_cells[vector_entry (printer)];
29 for (long i=2; i<size; i++)
31 SCM e = cell_unspecified;
32 if (fields != cell_nil)
35 fields = CDR (fields);
37 g_cells[v+i] = g_cells[vector_entry (e)];
45 assert (TYPE (x) == TSTRUCT);
46 return MAKE_NUMBER (LENGTH (x));
50 struct_ref_ (SCM x, long i)
52 assert (TYPE (x) == TSTRUCT);
53 assert (i < LENGTH (x));
54 SCM e = STRUCT (x) + i;
57 if (TYPE (e) == TCHAR)
58 e = MAKE_CHAR (VALUE (e));
59 if (TYPE (e) == TNUMBER)
60 e = MAKE_NUMBER (VALUE (e));
65 struct_set_x_ (SCM x, long i, SCM e)
67 assert (TYPE (x) == TSTRUCT);
68 assert (i < LENGTH (x));
69 g_cells[STRUCT (x)+i] = g_cells[vector_entry (e)];
70 return cell_unspecified;
74 struct_ref (SCM x, SCM i)
76 return struct_ref_ (x, VALUE (i));
80 struct_set_x (SCM x, SCM i, SCM e)
82 return struct_set_x_ (x, VALUE (i), e);