From 4bcfc155c10cb5b1418015c05fc229bc7acdb707 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 18 Aug 2020 23:01:53 +0200 Subject: [PATCH] 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. --- build-aux/configure-lib.sh | 1 + build-aux/pointer.sh | 6 +++++ include/mes/mes.h | 4 +++ kaem.run | 1 + simple.make | 6 +++-- src/cc.c | 50 ++++++++++++++++++++++++++++++++++++++ src/eval-apply.c | 42 ++++++-------------------------- src/m2.c | 50 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 123 insertions(+), 37 deletions(-) create mode 100644 src/cc.c create mode 100644 src/m2.c diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index 8bce4f5e..92867f85 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -431,6 +431,7 @@ fi mes_SOURCES=" src/builtins.c +src/cc.c src/core.c src/display.c src/eval-apply.c diff --git a/build-aux/pointer.sh b/build-aux/pointer.sh index 38a19e89..2254f325 100755 --- a/build-aux/pointer.sh +++ b/build-aux/pointer.sh @@ -39,20 +39,26 @@ sed -ri \ -e 's,CDDR \(([^()]*)\),\1->cdr->cdr,' \ -e 's,CADAR \(([^()]*)\),\1->car->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,CDDAR \(([^()]*)\),\1->car->cdr->cdr,' \ -e 's,CDADAR \(([^()]*)\),\1->cdr->car->cdr->car,' \ \ include/mes/builtins.h \ include/mes/mes.h \ include/mes/symbols.h \ include/mes/builtins.h \ + include/m2/lib.h \ + include/mes/m2.h \ src/builtins.c \ + src/cc.c \ src/core.c \ src/display.c \ src/eval-apply.c \ src/gc.c \ src/hash.c \ src/lib.c \ + src/m2.c \ src/math.c \ src/mes.c \ src/module.c \ diff --git a/include/mes/mes.h b/include/mes/mes.h index 27d79378..937b0b1c 100644 --- a/include/mes/mes.h +++ b/include/mes/mes.h @@ -112,6 +112,10 @@ struct timespec *__get_internal_run_time_ts; SCM alloc (long n); SCM apply (SCM f, SCM x, SCM a); 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 cstring_to_list (char const *s); SCM cstring_to_symbol (char const *s); diff --git a/kaem.run b/kaem.run index 2eab81ca..343f1b8e 100644 --- a/kaem.run +++ b/kaem.run @@ -107,6 +107,7 @@ M2-Planet \ -f src/gc.c \ -f src/hash.c \ -f src/lib.c \ + -f src/m2.c \ -f src/math.c \ -f src/mes.c \ -f src/module.c \ diff --git a/simple.make b/simple.make index cf367a39..dafeac30 100644 --- a/simple.make +++ b/simple.make @@ -139,7 +139,8 @@ M2_SOURCES = \ lib/linux/dup2.c \ lib/string/strcmp.c \ lib/string/memcmp.c \ - lib/linux/unlink.c + lib/linux/unlink.c \ + src/m2.c M2_TODO = \ lib/m2/file_print.c \ @@ -172,7 +173,8 @@ GCC_SOURCES = \ lib/mes/ntoab.c \ lib/mes/itoa.c \ lib/mes/ltoa.c \ - lib/mes/assert_msg.c + lib/mes/assert_msg.c \ + src/cc.c mes-gcc: bin/mes-gcc mes-m2: bin/mes-m2 diff --git a/src/cc.c b/src/cc.c new file mode 100644 index 00000000..2b377584 --- /dev/null +++ b/src/cc.c @@ -0,0 +1,50 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +#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); +} diff --git a/src/eval-apply.c b/src/eval-apply.c index 6a757ef8..6ae8f2ff 100644 --- a/src/eval-apply.c +++ b/src/eval-apply.c @@ -309,45 +309,17 @@ apply_builtin (SCM fn, SCM x) /*:((internal)) */ x = cons (a, cons (CADAR (d), d)); } -#if __M2_PLANET__ - FUNCTION fp = builtin_function (fn); if (arity == 0) - return fp (); - else if (arity == 1) - return fp (CAR (x)); + return apply_builtin0 (fn); + if (arity == 1) + return apply_builtin1 (fn, CAR (x)); else if (arity == 2) - return fp (CAR (x), CADR (x)); + return apply_builtin2 (fn, CAR (x), CADR (x)); 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) - return fp (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 apply_builtin1 (fn, x); + return cell_unspecified; } diff --git a/src/m2.c b/src/m2.c new file mode 100644 index 00000000..006af805 --- /dev/null +++ b/src/m2.c @@ -0,0 +1,50 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +#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); +}