2018-10-13 16:34:27 +01:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
|
|
|
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
*
|
|
|
|
* This file is part of GNU Mes.
|
|
|
|
*
|
|
|
|
* GNU 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.
|
|
|
|
*
|
|
|
|
* GNU 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-08 14:36:22 +01:00
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
2018-10-13 16:34:27 +01:00
|
|
|
SCM
|
|
|
|
make_struct (SCM type, SCM fields, SCM printer)
|
|
|
|
{
|
|
|
|
long size = 2 + length__ (fields);
|
2019-10-27 15:03:31 +00:00
|
|
|
SCM x = alloc (1);
|
2018-10-13 16:34:27 +01:00
|
|
|
SCM v = alloc (size);
|
2019-10-27 15:03:31 +00:00
|
|
|
TYPE (x) = TSTRUCT;
|
|
|
|
LENGTH (x) = size;
|
|
|
|
STRUCT (x) = v;
|
2019-10-22 14:57:49 +01:00
|
|
|
copy_cell (v, vector_entry (type));
|
|
|
|
copy_cell (cell_ref (v, 1), vector_entry (printer));
|
2019-10-20 12:39:12 +01:00
|
|
|
long i;
|
|
|
|
for (i = 2; i < size; i = i + 1)
|
2018-10-13 16:34:27 +01:00
|
|
|
{
|
|
|
|
SCM e = cell_unspecified;
|
|
|
|
if (fields != cell_nil)
|
|
|
|
{
|
|
|
|
e = CAR (fields);
|
|
|
|
fields = CDR (fields);
|
|
|
|
}
|
2019-10-22 14:57:49 +01:00
|
|
|
copy_cell (cell_ref (v, i), vector_entry (e));
|
2018-10-13 16:34:27 +01:00
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
struct_length (SCM x)
|
|
|
|
{
|
2019-10-20 15:07:04 +01:00
|
|
|
assert_msg (TYPE (x) == TSTRUCT, "TYPE (x) == TSTRUCT");
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_number (LENGTH (x));
|
2018-10-13 16:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2018-10-14 08:10:30 +01:00
|
|
|
struct_ref_ (SCM x, long i)
|
2018-10-13 16:34:27 +01:00
|
|
|
{
|
2019-10-20 15:07:04 +01:00
|
|
|
assert_msg (TYPE (x) == TSTRUCT, "TYPE (x) == TSTRUCT");
|
|
|
|
assert_msg (i < LENGTH (x), "i < LENGTH (x)");
|
2019-10-22 14:57:49 +01:00
|
|
|
SCM e = cell_ref (STRUCT (x), i);
|
2018-10-13 16:34:27 +01:00
|
|
|
if (TYPE (e) == TREF)
|
|
|
|
e = REF (e);
|
|
|
|
if (TYPE (e) == TCHAR)
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
e = make_char (VALUE (e));
|
2018-10-13 16:34:27 +01:00
|
|
|
if (TYPE (e) == TNUMBER)
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
e = make_number (VALUE (e));
|
2018-10-13 16:34:27 +01:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2018-10-14 08:10:30 +01:00
|
|
|
struct_set_x_ (SCM x, long i, SCM e)
|
2018-10-13 16:34:27 +01:00
|
|
|
{
|
2019-10-20 15:07:04 +01:00
|
|
|
assert_msg (TYPE (x) == TSTRUCT, "TYPE (x) == TSTRUCT");
|
|
|
|
assert_msg (i < LENGTH (x), "i < LENGTH (x)");
|
2019-10-22 14:57:49 +01:00
|
|
|
copy_cell (cell_ref (STRUCT (x), i), vector_entry (e));
|
2018-10-13 16:34:27 +01:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
2018-10-14 08:10:30 +01:00
|
|
|
|
|
|
|
SCM
|
|
|
|
struct_ref (SCM x, SCM i)
|
|
|
|
{
|
|
|
|
return struct_ref_ (x, VALUE (i));
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
struct_set_x (SCM x, SCM i, SCM e)
|
|
|
|
{
|
|
|
|
return struct_set_x_ (x, VALUE (i), e);
|
|
|
|
}
|