core: eval-apply: Prepare for M2-Planet.

* src/eval-apply.c (apply_builtin): Split M2-Planet specific and CC
specifi part off to ..
* src/cc.c: New file, and
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* src/m2.c: New file.
* simple.make (MES_SOURCES, M2_SOURCES): Likewise.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-08-18 23:01:53 +02:00
parent 99040a38c4
commit 4bcfc155c1
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
8 changed files with 123 additions and 37 deletions

View file

@ -431,6 +431,7 @@ fi
mes_SOURCES=" mes_SOURCES="
src/builtins.c src/builtins.c
src/cc.c
src/core.c src/core.c
src/display.c src/display.c
src/eval-apply.c src/eval-apply.c

View file

@ -39,20 +39,26 @@ sed -ri \
-e 's,CDDR \(([^()]*)\),\1->cdr->cdr,' \ -e 's,CDDR \(([^()]*)\),\1->cdr->cdr,' \
-e 's,CADAR \(([^()]*)\),\1->car->cdr->car,' \ -e 's,CADAR \(([^()]*)\),\1->car->cdr->car,' \
-e 's,CADDR \(([^()]*)\),\1->cdr->cdr->car,' \ -e 's,CADDR \(([^()]*)\),\1->cdr->cdr->car,' \
-e 's,CDADR \(([^()]*)\),\1->cdr->car->cdr,' \
-e 's,CDDDR \(([^()]*)\),\1->cdr->cdr->cdr,' \ -e 's,CDDDR \(([^()]*)\),\1->cdr->cdr->cdr,' \
-e 's,CDDAR \(([^()]*)\),\1->car->cdr->cdr,' \
-e 's,CDADAR \(([^()]*)\),\1->cdr->car->cdr->car,' \ -e 's,CDADAR \(([^()]*)\),\1->cdr->car->cdr->car,' \
\ \
include/mes/builtins.h \ include/mes/builtins.h \
include/mes/mes.h \ include/mes/mes.h \
include/mes/symbols.h \ include/mes/symbols.h \
include/mes/builtins.h \ include/mes/builtins.h \
include/m2/lib.h \
include/mes/m2.h \
src/builtins.c \ src/builtins.c \
src/cc.c \
src/core.c \ src/core.c \
src/display.c \ src/display.c \
src/eval-apply.c \ src/eval-apply.c \
src/gc.c \ src/gc.c \
src/hash.c \ src/hash.c \
src/lib.c \ src/lib.c \
src/m2.c \
src/math.c \ src/math.c \
src/mes.c \ src/mes.c \
src/module.c \ src/module.c \

View file

@ -112,6 +112,10 @@ struct timespec *__get_internal_run_time_ts;
SCM alloc (long n); SCM alloc (long n);
SCM apply (SCM f, SCM x, SCM a); SCM apply (SCM f, SCM x, SCM a);
SCM apply_builtin (SCM fn, SCM x); SCM apply_builtin (SCM fn, SCM x);
SCM apply_builtin0 (SCM fn);
SCM apply_builtin1 (SCM fn, SCM x);
SCM apply_builtin2 (SCM fn, SCM x, SCM y);
SCM apply_builtin3 (SCM fn, SCM x, SCM y, SCM z);
SCM builtin_name (SCM builtin); SCM builtin_name (SCM builtin);
SCM cstring_to_list (char const *s); SCM cstring_to_list (char const *s);
SCM cstring_to_symbol (char const *s); SCM cstring_to_symbol (char const *s);

View file

@ -107,6 +107,7 @@ M2-Planet \
-f src/gc.c \ -f src/gc.c \
-f src/hash.c \ -f src/hash.c \
-f src/lib.c \ -f src/lib.c \
-f src/m2.c \
-f src/math.c \ -f src/math.c \
-f src/mes.c \ -f src/mes.c \
-f src/module.c \ -f src/module.c \

View file

@ -139,7 +139,8 @@ M2_SOURCES = \
lib/linux/dup2.c \ lib/linux/dup2.c \
lib/string/strcmp.c \ lib/string/strcmp.c \
lib/string/memcmp.c \ lib/string/memcmp.c \
lib/linux/unlink.c lib/linux/unlink.c \
src/m2.c
M2_TODO = \ M2_TODO = \
lib/m2/file_print.c \ lib/m2/file_print.c \
@ -172,7 +173,8 @@ GCC_SOURCES = \
lib/mes/ntoab.c \ lib/mes/ntoab.c \
lib/mes/itoa.c \ lib/mes/itoa.c \
lib/mes/ltoa.c \ lib/mes/ltoa.c \
lib/mes/assert_msg.c lib/mes/assert_msg.c \
src/cc.c
mes-gcc: bin/mes-gcc mes-gcc: bin/mes-gcc
mes-m2: bin/mes-m2 mes-m2: bin/mes-m2

50
src/cc.c Normal file
View file

@ -0,0 +1,50 @@
/* -*-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/>.
*/
#include "mes/lib.h"
#include "mes/mes.h"
SCM
apply_builtin0 (SCM fn)
{
SCM (*fp) (void) = (function0_t) builtin_function (fn);
return fp ();
}
SCM
apply_builtin1 (SCM fn, SCM x)
{
SCM (*fp) (SCM) = (function1_t) builtin_function (fn);
return fp (x);
}
SCM
apply_builtin2 (SCM fn, SCM x, SCM y)
{
SCM (*fp) (SCM, SCM) = (function2_t) builtin_function (fn);
return fp (x, y);
}
SCM
apply_builtin3 (SCM fn, SCM x, SCM y, SCM z)
{
SCM (*fp) (SCM, SCM, SCM) = (function3_t) builtin_function (fn);
return fp (x, y, z);
}

View file

@ -309,45 +309,17 @@ apply_builtin (SCM fn, SCM x) /*:((internal)) */
x = cons (a, cons (CADAR (d), d)); x = cons (a, cons (CADAR (d), d));
} }
#if __M2_PLANET__
FUNCTION fp = builtin_function (fn);
if (arity == 0) if (arity == 0)
return fp (); return apply_builtin0 (fn);
else if (arity == 1) if (arity == 1)
return fp (CAR (x)); return apply_builtin1 (fn, CAR (x));
else if (arity == 2) else if (arity == 2)
return fp (CAR (x), CADR (x)); return apply_builtin2 (fn, CAR (x), CADR (x));
else if (arity == 3) else if (arity == 3)
return fp (CAR (x), CADR (x), CADDR (x)); return apply_builtin3 (fn, CAR (x), CADR (x), CAR (CDDR (x)));
else if (arity == -1) else if (arity == -1)
return fp (x); return apply_builtin1 (fn, x);
#else // !__M2_PLANET__
if (arity == 0)
{
SCM (*fp) (void) = (function0_t) builtin_function (fn);
return fp ();
}
else if (arity == 1)
{
SCM (*fp) (SCM) = (function1_t) builtin_function (fn);
return fp (CAR (x));
}
else if (arity == 2)
{
SCM (*fp) (SCM, SCM) = (function2_t) builtin_function (fn);
return fp (CAR (x), CADR (x));
}
else if (arity == 3)
{
SCM (*fp) (SCM, SCM, SCM) = (function3_t) builtin_function (fn);
return fp (CAR (x), CADR (x), CAR (CDDR (x)));
}
else if (arity == -1)
{
SCM (*fp) (SCM) = (function1_t) builtin_function (fn);
return fp (x);
}
#endif //! __M2_PLANET__
return cell_unspecified; return cell_unspecified;
} }

50
src/m2.c Normal file
View file

@ -0,0 +1,50 @@
/* -*-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/>.
*/
#include "mes/lib.h"
#include "mes/mes.h"
SCM
apply_builtin0 (SCM fn)
{
FUNCTION fp = builtin_function (fn);
return fp ();
}
SCM
apply_builtin1 (SCM fn, SCM x)
{
FUNCTION fp = builtin_function (fn);
return fp (x);
}
SCM
apply_builtin2 (SCM fn, SCM x, SCM y)
{
FUNCTION fp = builtin_function (fn);
return fp (x, y);
}
SCM
apply_builtin3 (SCM fn, SCM x, SCM y, SCM z)
{
FUNCTION fp = builtin_function (fn);
return fp (x, y, z);
}