core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
|
|
|
* Copyright © 2016,2017,2018,2019 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Commentary:
|
|
|
|
Essential functions, used by the eval/apply core.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Code: */
|
|
|
|
|
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
assoc_string (struct scm *x, struct scm *a) /*:((internal)) */
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *b;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
while (a != cell_nil)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
b = a->car;
|
|
|
|
if (b->car->type == TSTRING)
|
|
|
|
if (string_equal_p (x, b->car) == cell_t)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return b;
|
2020-10-18 09:34:32 +00:00
|
|
|
a = a->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
if (a != cell_nil)
|
2020-10-18 09:34:32 +00:00
|
|
|
return a->car;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return cell_f;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
car (struct scm *x)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
#if !__MESC_MES__
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->type != TPAIR)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
error (cell_symbol_not_a_pair, cons (x, cell_symbol_car));
|
|
|
|
#endif
|
2020-10-18 09:34:32 +00:00
|
|
|
return x->car;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
cdr (struct scm *x)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
#if !__MESC_MES__
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->type != TPAIR)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
error (cell_symbol_not_a_pair, cons (x, cell_symbol_cdr));
|
|
|
|
#endif
|
2020-10-18 09:34:32 +00:00
|
|
|
return x->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
list (struct scm *x) /*:((arity . n)) */
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
null_p (struct scm *x)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
if (x == cell_nil)
|
|
|
|
return cell_t;
|
|
|
|
return cell_f;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
eq_p (struct scm *x, struct scm *y)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
if (x == y)
|
|
|
|
return cell_t;
|
2020-10-18 09:34:32 +00:00
|
|
|
int t = x->type;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
if (t == TKEYWORD)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (y->type == TKEYWORD)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return string_equal_p (x, y);
|
|
|
|
return cell_f;
|
|
|
|
}
|
|
|
|
if (t == TCHAR)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (y->type != TCHAR)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return cell_f;
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->value == y->value)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return cell_t;
|
|
|
|
return cell_f;
|
|
|
|
}
|
|
|
|
if (t == TNUMBER)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (y->type != TNUMBER)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return cell_f;
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->value == y->value)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return cell_t;
|
|
|
|
return cell_f;
|
|
|
|
}
|
|
|
|
return cell_f;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
values (struct scm *x) /*:((arity . n)) */
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *v = cons (0, x);
|
|
|
|
v->type = TVALUES;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
acons (struct scm *key, struct scm *value, struct scm *alist)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
return cons (cons (key, value), alist);
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
2020-10-18 09:34:32 +00:00
|
|
|
length__ (struct scm *x) /*:((internal)) */
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
long n = 0;
|
|
|
|
while (x != cell_nil)
|
|
|
|
{
|
|
|
|
n = n + 1;
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->type != TPAIR)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return -1;
|
2020-10-18 09:34:32 +00:00
|
|
|
x = x->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
length (struct scm *x)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
return make_number (length__ (x));
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
error (struct scm *key, struct scm *x)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
2022-11-14 04:25:55 +00:00
|
|
|
#if !__MESC_MES__ && !__M2__
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *throw = module_ref (R0, cell_symbol_throw);
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
if (throw != cell_undefined)
|
|
|
|
return apply (throw, cons (key, cons (x, cell_nil)), R0);
|
|
|
|
#endif
|
|
|
|
display_error_ (key);
|
|
|
|
eputs (": ");
|
|
|
|
write_error_ (x);
|
|
|
|
eputs ("\n");
|
|
|
|
assert_msg (0, "ERROR");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
append2 (struct scm *x, struct scm *y)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
if (x == cell_nil)
|
|
|
|
return y;
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->type != TPAIR)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
error (cell_symbol_not_a_pair, cons (x, cstring_to_symbol ("append2")));
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *r = cell_nil;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
while (x != cell_nil)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
r = cons (x->car, r);
|
|
|
|
x = x->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
return reverse_x_ (r, y);
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
append_reverse (struct scm *x, struct scm *y)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
|
|
|
if (x == cell_nil)
|
|
|
|
return y;
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->type != TPAIR)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
error (cell_symbol_not_a_pair, cons (x, cstring_to_symbol ("append-reverse")));
|
|
|
|
while (x != cell_nil)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
y = cons (x->car, y);
|
|
|
|
x = x->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
reverse_x_ (struct scm *x, struct scm *t)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x != cell_nil && x->type != TPAIR)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
error (cell_symbol_not_a_pair, cons (x, cstring_to_symbol ("core:reverse!")));
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *r = t;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
while (x != cell_nil)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
t = x->cdr;
|
|
|
|
x->cdr = r;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
r = x;
|
|
|
|
x = t;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
assq (struct scm *x, struct scm *a)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (a->type != TPAIR)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return cell_f;
|
2020-10-18 09:34:32 +00:00
|
|
|
int t = x->type;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
|
|
|
|
if (t == TSYMBOL || t == TSPECIAL)
|
|
|
|
while (a != cell_nil)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x == a->car->car)
|
|
|
|
return a->car;
|
|
|
|
a = a->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
else if (t == TCHAR || t == TNUMBER)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
long v = x->value;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
while (a != cell_nil)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (v == a->car->car->value)
|
|
|
|
return a->car;
|
|
|
|
a = a->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (t == TKEYWORD)
|
|
|
|
{
|
|
|
|
while (a != cell_nil)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (string_equal_p (x, a->car->car) == cell_t)
|
|
|
|
return a->car;
|
|
|
|
a = a->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* pointer equality, e.g. on strings. */
|
|
|
|
while (a != cell_nil)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x == a->car->car)
|
|
|
|
return a->car;
|
|
|
|
a = a->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
return cell_f;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
assoc (struct scm *x, struct scm *a)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (x->type == TSTRING)
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
return assoc_string (x, a);
|
|
|
|
while (a != cell_nil)
|
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
if (equal2_p (x, a->car->car) == cell_t)
|
|
|
|
return a->car;
|
|
|
|
a = a->cdr;
|
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 06:49:23 +00:00
|
|
|
}
|
|
|
|
return cell_f;
|
|
|
|
}
|