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/>.
|
|
|
|
*/
|
|
|
|
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2019-01-04 08:55:16 +00:00
|
|
|
// CONSTANT STRUCT_TYPE 0
|
|
|
|
#define STRUCT_TYPE 0
|
|
|
|
// CONSTANT STRUCT_PRINTER 1
|
|
|
|
#define STRUCT_PRINTER 1
|
|
|
|
|
2018-10-13 16:34:27 +01:00
|
|
|
SCM
|
|
|
|
make_struct (SCM type, SCM fields, SCM printer)
|
|
|
|
{
|
|
|
|
long size = 2 + length__ (fields);
|
|
|
|
SCM v = alloc (size);
|
|
|
|
SCM x = make_cell__ (TSTRUCT, size, v);
|
|
|
|
g_cells[v] = g_cells[vector_entry (type)];
|
|
|
|
g_cells[v+1] = g_cells[vector_entry (printer)];
|
|
|
|
for (long i=2; i<size; i++)
|
|
|
|
{
|
|
|
|
SCM e = cell_unspecified;
|
|
|
|
if (fields != cell_nil)
|
|
|
|
{
|
|
|
|
e = CAR (fields);
|
|
|
|
fields = CDR (fields);
|
|
|
|
}
|
|
|
|
g_cells[v+i] = g_cells[vector_entry (e)];
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
struct_length (SCM x)
|
|
|
|
{
|
|
|
|
assert (TYPE (x) == TSTRUCT);
|
|
|
|
return MAKE_NUMBER (LENGTH (x));
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2018-10-14 08:10:30 +01:00
|
|
|
struct_ref_ (SCM x, long i)
|
2018-10-13 16:34:27 +01:00
|
|
|
{
|
|
|
|
assert (TYPE (x) == TSTRUCT);
|
2018-10-14 08:10:30 +01:00
|
|
|
assert (i < LENGTH (x));
|
|
|
|
SCM e = STRUCT (x) + i;
|
2018-10-13 16:34:27 +01:00
|
|
|
if (TYPE (e) == TREF)
|
|
|
|
e = REF (e);
|
|
|
|
if (TYPE (e) == TCHAR)
|
|
|
|
e = MAKE_CHAR (VALUE (e));
|
|
|
|
if (TYPE (e) == TNUMBER)
|
|
|
|
e = MAKE_NUMBER (VALUE (e));
|
|
|
|
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
|
|
|
{
|
|
|
|
assert (TYPE (x) == TSTRUCT);
|
2018-11-14 07:16:58 +00:00
|
|
|
assert (i < LENGTH (x));
|
2018-10-14 08:10:30 +01:00
|
|
|
g_cells[STRUCT (x)+i] = g_cells[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);
|
|
|
|
}
|