2018-10-13 16:34:27 +01:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2019-01-13 10:02:28 +00:00
|
|
|
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
* Copyright © 2019 Jeremiah Orians <jeremiah@pdp10.guru>
|
2018-10-13 16:34:27 +01:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
struct_length (struct scm *x)
|
|
|
|
{
|
|
|
|
assert (x->type == TSTRUCT);
|
|
|
|
return make_number (x->length);
|
|
|
|
}
|
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
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
struct_ref_ (struct scm *x, long i)
|
2018-10-13 16:34:27 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
assert (x->type == TSTRUCT);
|
|
|
|
assert (i < x->length);
|
|
|
|
struct scm *f = x->cdr + i;
|
|
|
|
|
|
|
|
if (f->type == TREF)
|
2018-10-13 16:34:27 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
return f->car;
|
2018-10-13 16:34:27 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
if (f->type == TCHAR)
|
|
|
|
{
|
|
|
|
return make_char (f->value);
|
|
|
|
}
|
2018-10-13 16:34:27 +01:00
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
if (f->type == TNUMBER)
|
|
|
|
{
|
|
|
|
return make_number (f->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
2018-10-13 16:34:27 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
struct_set_x_ (struct scm *x, long i, struct scm *e)
|
2018-10-13 16:34:27 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
assert (x->type == TSTRUCT);
|
|
|
|
assert (i < x->length);
|
|
|
|
struct scm *v = vector_entry (e);
|
|
|
|
struct scm *y = x->cdr + i;
|
|
|
|
/* The below is likely going to be a problem for M2-Planet until we add pointer dereferencing */
|
|
|
|
*y = *v;
|
2018-10-13 16:34:27 +01:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
2018-10-14 08:10:30 +01:00
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
struct_ref (struct scm *x, struct scm *i) /* External */
|
2018-10-14 08:10:30 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *h = i;
|
|
|
|
struct scm *y = x;
|
|
|
|
return struct_ref_ (y, h->value);
|
2018-10-14 08:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
struct_set_x (struct scm *x, struct scm *i, struct scm *e)
|
2018-10-14 08:10:30 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *h = i;
|
|
|
|
struct scm *y = x;
|
|
|
|
return struct_set_x_ (y, h->value, e);
|
2018-10-14 08:10:30 +01:00
|
|
|
}
|