From 5dc245e739c480d5f6c6519fc031260df7094ce1 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 8 Jun 2019 15:36:22 +0200 Subject: [PATCH] build: Simplify. core: Make mes src/ c files separate compilation units. * include/mes/constants.h: New file. * include/mes/macros.h: New file. * include/mes/mes.h: New file. * src/gc.c: Update. * src/hash.c: Update. * src/lib.c: Update. * src/math.c: Update. * src/mes.c: Update. * src/module.c: Update. * src/posix.c: Update. * src/reader.c: Update. * src/string.c: Update. * src/struct.c: Update. * src/vector.c: Update. mes: Update datadir. * src/mes.c (g_datadir): New global. (open_boot): Rename from read_boot. (read_boot): New function. * mes/module/mes/boot-0.scm: Move from boot-0.scm.in * configure: Update. * configure.sh: Update. mescc: Create libraries from separate files. * .gitignore: Update. * build-aux/bootstrap-mes.sh: Remove. * build-aux/bootstrap.sh.in: Remove. * build-aux/build-guile.sh: Update. * build-aux/build-mes.sh: Update. * build-aux/build-scaffold.sh: New file. * build-aux/build.sh.in: Update. * build-aux/cc.sh: Update. * build-aux/check-tcc.sh: Remove. * build-aux/config.sh.in: New file. * build-aux/config.sh: Remove. * build-aux/install.sh.in: Update. * build-aux/test-boot.sh: New file. * build-aux/test-c.sh: New file. * build-aux/test-driver: New file. * build-aux/test-suite.sh: New file. * build-aux/trace.sh: Update. * build-aux/uninstall.sh.in: Update. * configure: Update. * configure.sh: Update. * lib/linux/x86-mes-mescc/crt1.c: Move from lib/linux/x86-mes. * lib/linux/x86-mes-mescc/mini.c: Likewise. * lib/linux/x86_64-mes-mescc/crt1.c: Move from lib/linux/x86_64-mes. * lib/linux/x86_64-mes-mescc/mini.c: Likewise. * lib/linux/x86-mes-gcc/syscall.c: Rename from mes.c. * lib/linux/x86-mes-mescc/syscall.c: Likewise. * lib/linux/x86_64-mes-gcc/syscall.c: Likewise. * lib/linux/x86_64-mes-mescc/syscall.c: Likewise. * lib/mes/mes_open.c: Include config.h. * lib/tests/stdio/70-printf-hello.c: Likewise. * lib/tests/stdio/70-printf-simple.c: Likewise. * scaffold/gc-test.sh: New file. * simple.sh: Update. --- .gitignore | 8 +- build-aux/GNUmakefile.in | 3 +- build-aux/bootstrap-mes.sh | 101 --- build-aux/bootstrap.sh.in | 70 -- build-aux/build-guile.sh | 48 +- build-aux/build-lib.sh | 402 ++++++++++++ build-aux/build-mes.sh | 85 +-- build-aux/build-scaffold.sh | 75 +++ build-aux/build.sh.in | 142 ++++- build-aux/cc.sh | 59 +- build-aux/check-boot.sh | 196 +++--- build-aux/check-mes.sh | 38 +- build-aux/check-mescc.sh | 497 +++++++-------- build-aux/check-tcc.sh | 161 ----- build-aux/check.sh.in | 74 ++- build-aux/config.make.in | 17 +- build-aux/config.sh | 164 ----- build-aux/{config.status.in => config.sh.in} | 44 +- build-aux/export.make | 26 +- build-aux/install.sh.in | 130 ++-- build-aux/pre-inst-env.in | 2 +- build-aux/{test-cc.sh => test-boot.sh} | 37 +- build-aux/test-c.sh | 77 +++ build-aux/test-driver | 148 +++++ build-aux/test-suite.sh | 137 ++++ build-aux/trace.sh | 14 +- build-aux/uninstall.sh.in | 91 +-- configure | 132 ++-- configure.sh | 148 +++-- include/assert.h | 4 +- lib/libgetopt.c => include/grp.h | 28 +- .../libc-mini.c => include/linux/syscall.h | 24 +- include/mes/builtins.h | 25 + include/mes/constants.h | 324 ++++++++++ include/mes/lib-mini.h | 62 +- include/mes/lib.h | 16 +- include/mes/macros.h | 80 +++ include/mes/mes.h | 106 +++ include/pwd.h | 2 + include/stdarg.h | 1 + include/string.h | 2 +- include/sys/stat.h | 1 + include/time.h | 1 - include/unistd.h | 3 + lib/assert/assert.c | 10 - lib/ctype/isxdigit.c | 3 +- lib/dirent/__getdirentries.c | 4 +- lib/dirent/readdir.c | 2 + lib/libc+gnu.c | 121 ---- lib/libc+tcc.c | 108 ---- lib/libc.c | 89 --- lib/libg.c | 147 ----- lib/linux/access.c | 3 + lib/linux/brk.c | 3 + lib/linux/chdir.c | 3 + lib/linux/chmod.c | 4 + lib/linux/clock_gettime.c | 4 +- lib/linux/close.c | 8 +- lib/linux/dup.c | 3 + lib/linux/dup2.c | 3 + lib/linux/execve.c | 3 + lib/linux/fcntl.c | 4 + lib/linux/fork.c | 3 + lib/linux/fstat.c | 4 + lib/linux/fsync.c | 3 + lib/linux/getcwd.c | 5 + lib/linux/getdents.c | 4 + lib/linux/getegid.c | 4 + lib/linux/geteuid.c | 4 + lib/linux/getgid.c | 4 + lib/linux/getpid.c | 4 + lib/linux/getppid.c | 4 + lib/linux/getrusage.c | 4 + lib/linux/gettimeofday.c | 4 +- lib/linux/getuid.c | 4 + lib/linux/gnu.c | 43 -- lib/linux/ioctl.c | 5 + lib/linux/kill.c | 4 + lib/linux/libc.c | 60 -- lib/linux/link.c | 3 + lib/linux/lseek.c | 6 +- lib/linux/lstat.c | 4 + lib/linux/mkdir.c | 4 + lib/linux/nanosleep.c | 7 +- lib/linux/open.c | 8 +- lib/linux/pipe.c | 4 + lib/linux/read.c | 5 + lib/linux/rename.c | 4 + lib/linux/rmdir.c | 5 +- lib/linux/setgid.c | 4 + lib/linux/settimer.c | 5 + lib/linux/setuid.c | 4 + lib/linux/signal.c | 5 + lib/linux/sigprogmask.c | 5 + lib/linux/stat.c | 6 +- lib/linux/time.c | 4 +- lib/linux/unlink.c | 3 + lib/linux/waitpid.c | 4 + lib/linux/x86-mes-gcc/mini.c | 4 +- lib/linux/x86-mes-gcc/{mes.c => syscall.c} | 0 lib/linux/{x86-mes => x86-mes-mescc}/crt1.c | 0 lib/linux/{x86-mes => x86-mes-mescc}/mini.c | 0 .../mes.c => x86-mes-mescc/syscall.c} | 0 lib/linux/x86_64-mes-gcc/mini.c | 4 +- lib/linux/x86_64-mes-gcc/{mes.c => syscall.c} | 0 .../{x86_64-mes => x86_64-mes-mescc}/crt1.c | 0 .../{x86_64-mes => x86_64-mes-mescc}/mini.c | 2 + .../mes.c => x86_64-mes-mescc/syscall.c} | 0 lib/{linux/tcc.c => mes/__assert_fail.c} | 16 +- lib/{libc-mini.c => mes/__mes_debug.c} | 28 +- lib/mes/eputs.c | 1 + lib/mes/fdgetc.c | 32 +- lib/{stdio => mes}/fdgets.c | 3 +- lib/mes/fdputs.c | 3 +- lib/mes/fdungetc.c | 15 +- lib/{libmes.c => mes/mes_open.c} | 36 +- lib/mes/oputs.c | 1 + lib/mes/search-path.c | 5 +- lib/posix/alarm.c | 1 + lib/posix/execl.c | 5 +- lib/posix/execv.c | 3 +- lib/posix/execvp.c | 1 + lib/posix/getenv.c | 4 +- lib/posix/isatty.c | 6 +- lib/posix/mktemp.c | 3 +- lib/posix/raise.c | 3 +- lib/posix/sbrk.c | 2 + lib/posix/setenv.c | 4 +- lib/posix/sleep.c | 2 + lib/posix/unsetenv.c | 2 + lib/stdio/fclose.c | 5 +- lib/stdio/fdopen.c | 2 +- lib/stdio/ferror.c | 2 +- lib/stdio/fflush.c | 4 +- lib/stdio/fgets.c | 5 +- lib/stdio/fileno.c | 2 +- lib/stdio/fopen.c | 20 +- lib/stdio/fread.c | 12 +- lib/stdio/fseek.c | 5 +- lib/stdio/ftell.c | 6 +- lib/stdio/fwrite.c | 6 +- lib/stdio/perror.c | 4 +- lib/stdio/remove.c | 4 +- lib/stdio/vsnprintf.c | 1 + lib/stdio/vsscanf.c | 7 +- lib/stdlib/alloca.c | 3 +- lib/stdlib/atexit.c | 1 + lib/stdlib/malloc.c | 5 +- lib/stdlib/realloc.c | 3 +- lib/stdlib/strtol.c | 9 +- lib/string/bzero.c | 5 +- lib/string/index.c | 2 +- lib/string/memcpy.c | 5 +- lib/string/strchr.c | 2 +- lib/string/strdup.c | 3 +- lib/string/strerror.c | 3 +- lib/string/strrchr.c | 4 +- lib/string/strspn.c | 2 +- lib/string/strstr.c | 4 +- lib/{stdlib => stub}/bsearch.c | 1 + lib/stub/strftime.c | 3 +- lib/tests/scaffold/54-argv.c | 4 +- lib/tests/scaffold/60-math.c | 2 +- lib/tests/scaffold/t.c | 2 +- lib/tests/stdio/70-printf-hello.c | 3 - lib/tests/stdio/70-printf-simple.c | 3 - lib/tests/stdio/70-printf.c | 3 - lib/x86-mes-gcc/setjmp.c | 3 +- lib/{x86-mes => x86-mes-mescc}/exit-42.c | 0 lib/{x86-mes => x86-mes-mescc}/setjmp.c | 3 +- lib/x86_64-mes-gcc/setjmp.c | 5 +- .../exit-42.c | 0 lib/{x86_64-mes => x86_64-mes-mescc}/setjmp.c | 3 +- mes/include | 1 - mes/lib | 1 - mes/module/mes/{boot-0.scm.in => boot-0.scm} | 9 +- mes/module/mes/boot-03.scm | 5 +- module/mescc/mescc.scm | 2 +- scaffold/boot/51-module.scm | 7 +- scaffold/gc-test.scm | 27 + build-aux/test.sh => scripts/ar.in | 35 +- scripts/mescc.in | 4 +- scripts/mescc.scm.in | 4 +- simple.sh | 244 ++++++- src/gc.c | 127 +++- src/hash.c | 8 +- src/lib.c | 10 +- src/math.c | 7 + src/mes.c | 601 +++--------------- src/module.c | 7 +- src/posix.c | 10 +- src/reader.c | 6 + src/string.c | 10 + src/struct.c | 8 +- src/vector.c | 5 + 195 files changed, 3356 insertions(+), 2719 deletions(-) delete mode 100755 build-aux/bootstrap-mes.sh delete mode 100644 build-aux/bootstrap.sh.in create mode 100755 build-aux/build-lib.sh create mode 100755 build-aux/build-scaffold.sh delete mode 100755 build-aux/check-tcc.sh delete mode 100644 build-aux/config.sh rename build-aux/{config.status.in => config.sh.in} (71%) rename build-aux/{test-cc.sh => test-boot.sh} (55%) create mode 100755 build-aux/test-c.sh create mode 100755 build-aux/test-driver create mode 100644 build-aux/test-suite.sh rename lib/libgetopt.c => include/grp.h (61%) rename lib/linux/libc-mini.c => include/linux/syscall.h (59%) create mode 100644 include/mes/constants.h create mode 100644 include/mes/macros.h create mode 100644 include/mes/mes.h delete mode 100644 lib/assert/assert.c delete mode 100644 lib/libc+gnu.c delete mode 100644 lib/libc+tcc.c delete mode 100644 lib/libc.c delete mode 100644 lib/libg.c delete mode 100644 lib/linux/gnu.c delete mode 100644 lib/linux/libc.c rename lib/linux/x86-mes-gcc/{mes.c => syscall.c} (100%) rename lib/linux/{x86-mes => x86-mes-mescc}/crt1.c (100%) rename lib/linux/{x86-mes => x86-mes-mescc}/mini.c (100%) rename lib/linux/{x86-mes/mes.c => x86-mes-mescc/syscall.c} (100%) rename lib/linux/x86_64-mes-gcc/{mes.c => syscall.c} (100%) rename lib/linux/{x86_64-mes => x86_64-mes-mescc}/crt1.c (100%) rename lib/linux/{x86_64-mes => x86_64-mes-mescc}/mini.c (97%) rename lib/linux/{x86_64-mes/mes.c => x86_64-mes-mescc/syscall.c} (100%) rename lib/{linux/tcc.c => mes/__assert_fail.c} (84%) rename lib/{libc-mini.c => mes/__mes_debug.c} (67%) rename lib/{stdio => mes}/fdgets.c (91%) rename lib/{libmes.c => mes/mes_open.c} (63%) rename lib/{stdlib => stub}/bsearch.c (98%) rename lib/{x86-mes => x86-mes-mescc}/exit-42.c (100%) rename lib/{x86-mes => x86-mes-mescc}/setjmp.c (93%) rename lib/{x86_64-mes => x86_64-mes-mescc}/exit-42.c (100%) rename lib/{x86_64-mes => x86_64-mes-mescc}/setjmp.c (95%) delete mode 120000 mes/include delete mode 120000 mes/lib rename mes/module/mes/{boot-0.scm.in => boot-0.scm} (96%) create mode 100644 scaffold/gc-test.scm rename build-aux/test.sh => scripts/ar.in (61%) mode change 100755 => 100644 mode change 100755 => 100644 scripts/mescc.in diff --git a/.gitignore b/.gitignore index e38ae458..e8f4d87c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ *.guile *.guile-log *.log +*.trs *.mes-gcc *.mes-gcc-o *.mes-gcc-out @@ -140,12 +141,12 @@ /config.status /pre-inst-env -/bootstrap.sh /build.sh /check.sh /install.sh /uninstall.sh /mes/module/mes/boot-0.scm +/scripts/ar /scripts/mescc.scm /scripts/mescc /doc/images/gcc-mesboot-graph.png @@ -156,3 +157,8 @@ /doc/web/ /lib/x86_64-mes/0exit-42 /lib/x86_64-mes/exit-42 +/config.sh +/include/mes/config.h +/gcc-lib +/mescc-lib +/bin diff --git a/build-aux/GNUmakefile.in b/build-aux/GNUmakefile.in index 3678b71e..1cfad1c6 100644 --- a/build-aux/GNUmakefile.in +++ b/build-aux/GNUmakefile.in @@ -87,7 +87,7 @@ src/${program_prefix}mes: build clean: git clean -dfx\ -e .config.make\ - -e config.status\ + -e config.sh\ -e GNUmakefile\ -e build.sh\ -e check.sh\ @@ -95,7 +95,6 @@ clean: -e uninstall.sh\ -e pre-inst-env\ -e scripts/mescc\ - -e "mes"/module/mes/boot-0.scm\ # diff --git a/build-aux/bootstrap-mes.sh b/build-aux/bootstrap-mes.sh deleted file mode 100755 index 97d4a82c..00000000 --- a/build-aux/bootstrap-mes.sh +++ /dev/null @@ -1,101 +0,0 @@ -#! /bin/sh - -# GNU Mes --- Maxwell Equations of Software -# Copyright © 2017,2018 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 . - -. ./config.status -. ${srcdest}build-aux/config.sh -. ${srcdest}build-aux/trace.sh - -set -e - -# FIXME? -#mes_program_prefix=boot-$arch- -mes_program_prefix=$program_prefix -trace "HEX2 0exit-42" $HEX2\ - $HEX2FLAGS\ - -f ${srcdest}lib/$mes_arch/elf$bits-0header.hex2\ - -f ${srcdest}lib/$mes_arch/elf$bits-body-exit-42.hex2\ - -f ${srcdest}lib/$mes_arch/elf-0footer.hex2\ - --exec_enable\ - -o lib/$mes_arch/${mes_program_prefix}0exit-42 - -trace "TEST lib/$mes_arch/${mes_program_prefix}0exit-42" echo lib/$mes_arch/${mes_program_prefix}0exit-42 -{ set +e; lib/$mes_arch/${mes_program_prefix}0exit-42; r=$?; set -e; } -[ $r != 42 ] && echo " => $r" && exit 1 - -trace "HEX2 exit-42" $HEX2\ - $HEX2FLAGS\ - -f ${srcdest}lib/$mes_arch/elf$bits-header.hex2\ - -f ${srcdest}lib/$mes_arch/elf$bits-body-exit-42.hex2\ - -f ${srcdest}lib/$mes_arch/elf$bits-footer-single-main.hex2\ - --exec_enable\ - -o lib/$mes_arch/${mes_program_prefix}exit-42 - -trace "TEST lib/$mes_arch/${mes_program_prefix}exit-42" echo lib/$mes_arch/${mes_program_prefix}exit-42 -{ set +e; lib/$mes_arch/${mes_program_prefix}exit-42; r=$?; set -e; } -[ $r != 42 ] && echo " => $r" && exit 1 - - -mkdir -p lib/$mes_arch -trace "M1 crt1.S" $M1\ - $M1FLAGS\ - -f ${srcdest}lib/$mes_arch/$arch.M1\ - -f $MES_SEED/$mes_arch/crt1.S\ - -o lib/$mes_arch/crt1.o -trace "M1 libc.S" $M1\ - $M1FLAGS\ - -f ${srcdest}lib/$mes_arch/$arch.M1\ - -f $MES_SEED/$mes_arch/libc.S\ - -o lib/$mes_arch/libc.o -trace "M1 mes.S" $M1\ - --LittleEndian\ - --architecture x86\ - -f ${srcdest}lib/$mes_arch/$arch.M1\ - -f $MES_SEED/$mes_arch/mes.S\ - -o src/mes.o -trace "BLOOD_ELF mes.S" $BLOOD_ELF\ - -f ${srcdest}lib/$mes_arch/$arch.M1\ - -f $MES_SEED/$mes_arch/mes.S\ - -f $MES_SEED/$mes_arch/libc.S\ - -o src/mes.S.blood-elf -trace "M1 mes.blood-elf" $M1\ - --LittleEndian\ - --architecture x86\ - -f src/mes.S.blood-elf\ - -o src/mes.o.blood-elf -trace "HEX2 mes.o" $HEX2\ - $HEX2FLAGS\ - -f ${srcdest}lib/$mes_arch/elf$bits-header.hex2\ - -f lib/$mes_arch/crt1.o\ - -f lib/$mes_arch/libc.o\ - -f src/mes.o\ - -f src/mes.o.blood-elf\ - --exec_enable\ - -o src/${mes_program_prefix}mes -#cp src/${mes_program_prefix}mes src/${program_prefix}mes -trace "M1 libc+tcc.S" $M1\ - $M1FLAGS\ - -f ${srcdest}lib/$mes_arch/$arch.M1\ - -f $MES_SEED/$mes_arch/libc+tcc.S\ - -o lib/$mes_arch/libc+tcc.o -trace "M1 libc+gnu.S" $M1\ - $M1FLAGS\ - -f ${srcdest}lib/$mes_arch/$arch.M1\ - -f $MES_SEED/$mes_arch/libc+gnu.S\ - -o lib/$mes_arch/libc+gnu.o diff --git a/build-aux/bootstrap.sh.in b/build-aux/bootstrap.sh.in deleted file mode 100644 index 23a8a325..00000000 --- a/build-aux/bootstrap.sh.in +++ /dev/null @@ -1,70 +0,0 @@ -#! @SHELL@ - -set -e - -if [ "$V" = 1 -o "$V" = 2 ]; then - set -x -fi - -MES_ARENA=${MES_ARENA-100000000} -MES_MAX_ARENA=${MES_MAX_ARENA-100000000} -MES_STACK=${MES_STACK-500000} - -hex2 --LittleEndian --architecture x86 --BaseAddress 0x1000000 -f lib/x86-mes/elf32-0header.hex2 -f lib/x86-mes/elf32-body-exit-42.hex2 -f lib/x86-mes/elf-0footer.hex2 --exec_enable -o lib/x86-mes/0exit-42 -hex2 --LittleEndian --architecture x86 --BaseAddress 0x1000000 -f lib/x86-mes/elf32-header.hex2 -f lib/x86-mes/elf32-body-exit-42.hex2 -f lib/x86-mes/elf32-footer-single-main.hex2 --exec_enable -o lib/x86-mes/exit-42 -M1 --LittleEndian --architecture x86 -f lib/x86-mes/x86.M1 -f @MES_SEED@/x86-mes/crt1.S -o lib/x86-mes/crt1.o -M1 --LittleEndian --architecture x86 -f lib/x86-mes/x86.M1 -f @MES_SEED@/x86-mes/libc.S -o lib/x86-mes/libc.o -M1 --LittleEndian --architecture x86 -f lib/x86-mes/x86.M1 -f @MES_SEED@/x86-mes/mes.S -o src/mes.o -blood-elf -f lib/x86-mes/x86.M1 -f @MES_SEED@/x86-mes/mes.S -f @MES_SEED@/x86-mes/libc.S -o src/mes.S.blood-elf -M1 --LittleEndian --architecture x86 -f src/mes.S.blood-elf -o src/mes.o.blood-elf -hex2 --LittleEndian --architecture x86 --BaseAddress 0x1000000 -f lib/x86-mes/elf32-header.hex2 -f lib/x86-mes/crt1.o -f lib/x86-mes/libc.o -f src/mes.o -f src/mes.o.blood-elf --exec_enable -o src/mes -M1 --LittleEndian --architecture x86 -f lib/x86-mes/x86.M1 -f @MES_SEED@/x86-mes/libc+tcc.S -o lib/x86-mes/libc+tcc.o -M1 --LittleEndian --architecture x86 -f lib/x86-mes/x86.M1 -f @MES_SEED@/x86-mes/libc+gnu.S -o lib/x86-mes/libc+gnu.o - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/linux/x86-mes/crt1.o lib/linux/x86-mes/crt1.c - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/libc-mini.x86-mes-o lib/libc-mini.c -mv lib/libc-mini.x86-mes-S lib/x86-mes/libc-mini.S -mv lib/libc-mini.x86-mes-o lib/x86-mes/libc-mini.o - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/libc.x86-mes-o lib/libc.c -mv lib/libc.x86-mes-S lib/x86-mes/libc.S -mv lib/libc.x86-mes-o lib/x86-mes/libc.o - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/libc+tcc.x86-mes-o lib/libc+tcc.c -mv lib/libc+tcc.x86-mes-S lib/x86-mes/libc+tcc.S -mv lib/libc+tcc.x86-mes-o lib/x86-mes/libc+tcc.o - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/libc+gnu.x86-mes-o lib/libc+gnu.c -mv lib/libc+gnu.x86-mes-S lib/x86-mes/libc+gnu.S -mv lib/libc+gnu.x86-mes-o lib/x86-mes/libc+gnu.o - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/main.x86-mes-o scaffold/main.c - -@GUILE@ -e main -L module scripts/mescc.scm -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/x86-mes-main scaffold/main.x86-mes-o - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/hello.x86-mes-o scaffold/hello.c - -@GUILE@ -e main -L module scripts/mescc.scm -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/x86-mes-hello scaffold/hello.x86-mes-o -l c-mini - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/argv.x86-mes-o scaffold/argv.c - -@GUILE@ -e main -L module scripts/mescc.scm -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/x86-mes-argv scaffold/argv.x86-mes-o -l c-mini - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/tests/stdlib/50-malloc.x86-mes-o lib/tests/stdlib/50-malloc.c - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/tests/posix/50-getenv.x86-mes-o lib/tests/posix/50-getenv.c - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/micro-mes.x86-mes-o scaffold/micro-mes.c - -@GUILE@ -e main -L module scripts/mescc.scm -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/x86-mes-micro-mes scaffold/micro-mes.x86-mes-o -l c - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/tiny-mes.x86-mes-o scaffold/tiny-mes.c - -@GUILE@ -e main -L module scripts/mescc.scm -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/x86-mes-tiny-mes scaffold/tiny-mes.x86-mes-o -l c - -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o src/mes.x86-mes-o src/mes.c -cp src/mes.x86-mes-S src/mes.S - -@GUILE@ -e main -L module scripts/mescc.scm -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o src/x86-mes-mes src/mes.x86-mes-o -l c -cp src/x86-mes-mes src/mes diff --git a/build-aux/build-guile.sh b/build-aux/build-guile.sh index 3056d11e..bd304509 100755 --- a/build-aux/build-guile.sh +++ b/build-aux/build-guile.sh @@ -18,37 +18,34 @@ # You should have received a copy of the GNU General Public License # along with GNU Mes. If not, see . -if [ ! "$config_status" ]; then - . ./config.status -fi +set -e + +. ./config.sh -. ${srcdest}build-aux/config.sh . ${srcdest}build-aux/trace.sh GUILE_AUTO_COMPILE=0 -set -e - SCM_FILES=" -${srcdest}module/mes/getopt-long.scm -${srcdest}module/mes/guile.scm -${srcdest}module/mes/misc.scm -${srcdest}module/mes/test.scm -${srcdest}module/mescc/M1.scm -${srcdest}module/mescc/as.scm -${srcdest}module/mescc/bytevectors.scm -${srcdest}module/mescc/compile.scm -${srcdest}module/mescc/i386/as.scm -${srcdest}module/mescc/i386/info.scm -${srcdest}module/mescc/x86_64/as.scm -${srcdest}module/mescc/x86_64/info.scm -${srcdest}module/mescc/info.scm -${srcdest}module/mescc.scm -${srcdest}module/mescc/mescc.scm -${srcdest}module/mescc/preprocess.scm +module/mes/getopt-long.scm +module/mes/guile.scm +module/mes/misc.scm +module/mes/test.scm +module/mescc/M1.scm +module/mescc/as.scm +module/mescc/bytevectors.scm +module/mescc/compile.scm +module/mescc/i386/as.scm +module/mescc/i386/info.scm +module/mescc/x86_64/as.scm +module/mescc/x86_64/info.scm +module/mescc/info.scm +module/mescc.scm +module/mescc/mescc.scm +module/mescc/preprocess.scm " SCRIPTS=" -${srcdest}build-aux/mes-snarf.scm +build-aux/mes-snarf.scm " export host=$($GUILE -c "(display %host-type)") @@ -61,7 +58,8 @@ fi for i in $SCM_FILES $SCRIPTS; do b=$(basename $i) go=${i%%.scm}.go - if [ $i -nt $go ]; then - trace "GUILEC $i" $GUILD compile -L ${srcdest}module -L ${srcdest}build-aux -L ${srcdest}scripts -o $go $i + f=${srcdest}$i + if test $f -nt $go; then + trace "GUILEC $f" $GUILD compile -L ${srcdest}module -L ${srcdest}build-aux -L ${srcdest}scripts -o $go $f fi done diff --git a/build-aux/build-lib.sh b/build-aux/build-lib.sh new file mode 100755 index 00000000..fc0eb42e --- /dev/null +++ b/build-aux/build-lib.sh @@ -0,0 +1,402 @@ +#! /bin/sh + +# GNU Mes --- Maxwell Equations of Software +# Copyright © 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 . + +set -e +set -u + +V=${V-1} + +if [ "$V" = 2 ]; then + set -x +fi + +. ./config.sh +. ${srcdest}build-aux/trace.sh +. ${srcdest}build-aux/cc.sh + +trap 'test -f .log && cat .log' EXIT + +srcdest=${srcdest-} + +libc_mini_SOURCES=" +lib/mes/eputs.c +lib/mes/oputs.c +" + +if test $mes_libc = mes; then + libc_mini_SOURCES="$libc_mini_SOURCES +lib/posix/write.c +lib/string/strlen.c +lib/stdlib/puts.c +lib/stdlib/exit.c +lib/$mes_kernel/$mes_cpu-mes-$compiler/mini.c +" +fi + +libmes_SOURCES=" +$libc_mini_SOURCES +lib/mes/itoa.c +lib/mes/ltoa.c +lib/mes/ltoab.c +lib/mes/ultoa.c +lib/mes/utoa.c +lib/mes/eputc.c +lib/mes/fdgetc.c +lib/mes/fdputc.c +lib/mes/fdputs.c +lib/mes/fdungetc.c +lib/mes/mes_open.c +lib/mes/ntoab.c +lib/mes/oputc.c +" + +if test $mes_libc = mes; then + libmes_SOURCES="$libmes_SOURCES +lib/stdlib/atoi.c +lib/mes/abtol.c +lib/ctype/isdigit.c +lib/ctype/isnumber.c +lib/ctype/isspace.c +lib/ctype/isxdigit.c +" +fi + +libc_SOURCES=" +$libmes_SOURCES +lib/mes/__assert_fail.c +lib/mes/__mes_debug.c +lib/posix/execv.c +lib/posix/getenv.c +lib/posix/isatty.c +lib/posix/setenv.c +lib/posix/wait.c +lib/stdio/fgetc.c +lib/stdio/fputc.c +lib/stdio/fputs.c +lib/stdio/getc.c +lib/stdio/getchar.c +lib/stdio/putc.c +lib/stdio/putchar.c +lib/stdio/ungetc.c +lib/stdlib/free.c +lib/stdlib/malloc.c +lib/stdlib/realloc.c +lib/string/memchr.c +lib/string/memcmp.c +lib/string/memcpy.c +lib/string/memset.c +lib/string/strcmp.c +lib/string/strcpy.c +lib/string/strncmp.c +" + +if test $mes_kernel = linux; then + libc_SOURCES="$libc_SOURCES +lib/linux/access.c +lib/linux/brk.c +lib/linux/chmod.c +lib/linux/clock_gettime.c +lib/linux/dup.c +lib/linux/dup2.c +lib/linux/execve.c +lib/linux/fork.c +lib/linux/fsync.c +lib/linux/getcwd.c +lib/linux/gettimeofday.c +lib/linux/ioctl.c +lib/linux/open.c +lib/linux/read.c +lib/linux/time.c +lib/linux/unlink.c +lib/linux/waitpid.c +lib/linux/$mes_cpu-mes-$compiler/syscall.c +" +fi + +libtcc1_SOURCES=" +lib/libtcc1.c +" + +libc_tcc_SOURCES=" +$libc_SOURCES +lib/ctype/islower.c +lib/ctype/isupper.c +lib/ctype/tolower.c +lib/ctype/toupper.c +lib/mes/search-path.c +lib/posix/execvp.c +lib/stdio/fclose.c +lib/stdio/fdopen.c +lib/stdio/ferror.c +lib/stdio/fflush.c +lib/stdio/fopen.c +lib/stdio/fprintf.c +lib/stdio/fread.c +lib/stdio/fseek.c +lib/stdio/ftell.c +lib/stdio/fwrite.c +lib/stdio/printf.c +lib/stdio/remove.c +lib/stdio/snprintf.c +lib/stdio/sprintf.c +lib/stdio/sscanf.c +lib/stdio/vfprintf.c +lib/stdio/vprintf.c +lib/stdio/vsnprintf.c +lib/stdio/vsprintf.c +lib/stdio/vsscanf.c +lib/stdlib/calloc.c +lib/stdlib/qsort.c +lib/stdlib/strtof.c +lib/stdlib/strtol.c +lib/stdlib/strtold.c +lib/stdlib/strtoll.c +lib/stdlib/strtoul.c +lib/stdlib/strtoull.c +lib/string/memmem.c +lib/string/memmove.c +lib/string/strcat.c +lib/string/strchr.c +lib/string/strlwr.c +lib/string/strncpy.c +lib/string/strrchr.c +lib/string/strstr.c +lib/string/strupr.c +lib/stub/sigaction.c +lib/stub/ldexp.c +lib/stub/mprotect.c +lib/stub/localtime.c +lib/stub/sigemptyset.c +lib/ctype/islower.c +lib/ctype/isupper.c +lib/ctype/tolower.c +lib/ctype/toupper.c +lib/mes/search-path.c +lib/posix/execvp.c +lib/stdio/fclose.c +lib/stdio/fdopen.c +lib/stdio/ferror.c +lib/stdio/fflush.c +lib/stdio/fopen.c +lib/stdio/fprintf.c +lib/stdio/fread.c +lib/stdio/fseek.c +lib/stdio/ftell.c +lib/stdio/fwrite.c +lib/stdio/printf.c +lib/stdio/remove.c +lib/stdio/snprintf.c +lib/stdio/sprintf.c +lib/stdio/sscanf.c +lib/stdio/vfprintf.c +lib/stdio/vprintf.c +lib/stdio/vsnprintf.c +lib/stdio/vsprintf.c +lib/stdio/vsscanf.c +lib/stdlib/calloc.c +lib/stdlib/qsort.c +lib/stdlib/strtof.c +lib/stdlib/strtol.c +lib/stdlib/strtold.c +lib/stdlib/strtoll.c +lib/stdlib/strtoul.c +lib/stdlib/strtoull.c +lib/string/memmem.c +lib/string/memmove.c +lib/string/strcat.c +lib/string/strchr.c +lib/string/strlwr.c +lib/string/strncpy.c +lib/string/strrchr.c +lib/string/strstr.c +lib/string/strupr.c +lib/stub/sigaction.c +lib/stub/ldexp.c +lib/stub/mprotect.c +lib/stub/localtime.c +lib/stub/sigemptyset.c +xslib/stub/strtod.c +lib/$mes_cpu-mes-$compiler/setjmp.c +" + +if test $mes_kernel = linux; then + libc_tcc_SOURCES="$libc_tcc_SOURCES +lib/linux/close.c +lib/linux/lseek.c +lib/linux/rmdir.c +lib/linux/stat.c +" +fi + +libc_gnu_SOURCES=" +$libc_tcc_SOURCES +lib/ctype/isalnum.c +lib/ctype/isalpha.c +lib/ctype/isascii.c +lib/ctype/iscntrl.c +lib/ctype/isprint.c +lib/ctype/ispunct.c +lib/dirent/__getdirentries.c +lib/dirent/closedir.c +lib/dirent/opendir.c +lib/dirent/readdir.c +lib/math/fabs.c +lib/mes/fdgets.c +lib/posix/alarm.c +lib/posix/execl.c +lib/posix/mktemp.c +lib/posix/raise.c +lib/posix/sbrk.c +lib/posix/sleep.c +lib/posix/unsetenv.c +lib/stdio/clearerr.c +lib/stdio/feof.c +lib/stdio/fgets.c +lib/stdio/fileno.c +lib/stdio/freopen.c +lib/stdio/perror.c +lib/stdlib/__exit.c +lib/stdlib/abort.c +lib/stdlib/abs.c +lib/stdlib/alloca.c +lib/stdlib/atexit.c +lib/stdlib/atol.c +lib/stdlib/mbstowcs.c +lib/string/bcmp.c +lib/string/bcopy.c +lib/string/bzero.c +lib/string/index.c +lib/string/rindex.c +lib/string/strcspn.c +lib/string/strdup.c +lib/string/strerror.c +lib/string/strncat.c +lib/string/strpbrk.c +lib/string/strspn.c +lib/stub/__cleanup.c +lib/stub/bsearch.c +lib/stub/chown.c +lib/stub/ctime.c +lib/stub/fpurge.c +lib/stub/freadahead.c +lib/stub/frexp.c +lib/stub/getlogin.c +lib/stub/getpwnam.c +lib/stub/getpwuid.c +lib/stub/gmtime.c +lib/stub/pclose.c +lib/stub/popen.c +lib/stub/rand.c +lib/stub/setbuf.c +lib/stub/setlocale.c +lib/stub/setvbuf.c +lib/stub/sigaddset.c +lib/stub/sigblock.c +lib/stub/sigdelset.c +lib/stub/sigsetmask.c +lib/stub/strftime.c +lib/stub/sys_siglist.c +lib/stub/system.c +lib/stub/times.c +lib/stub/ttyname.c +lib/stub/umask.c +lib/stub/utime.c +" + +if test $mes_kernel = linux; then + libc_gnu_SOURCES="$libc_gnu_SOURCES +lib/linux/chdir.c +lib/linux/fcntl.c +lib/linux/fstat.c +lib/linux/getdents.c +lib/linux/getegid.c +lib/linux/geteuid.c +lib/linux/getgid.c +lib/linux/getpid.c +lib/linux/getppid.c +lib/linux/getrusage.c +lib/linux/getuid.c +lib/linux/kill.c +lib/linux/link.c +lib/linux/lstat.c +lib/linux/mkdir.c +lib/linux/nanosleep.c +lib/linux/pipe.c +lib/linux/rename.c +lib/linux/setgid.c +lib/linux/settimer.c +lib/linux/setuid.c +lib/linux/signal.c +lib/linux/sigprogmask.c +" +fi + +mkdir -p $mes_cpu-mes +compile lib/$mes_kernel/$mes_cpu-mes-$compiler/crt1.c +cp crt1.o $mes_cpu-mes +if test -e crt1.s; then + cp crt1.s $mes_cpu-mes +fi + +archive libc-mini.a $libc_mini_SOURCES +cp libc-mini.a $mes_cpu-mes +if test -e libc-mini.S; then + cp libc-mini.S $mes_cpu-mes +fi + +archive libmes.a $libmes_SOURCES +cp libmes.a $mes_cpu-mes +if test -e libmes.S; then + cp libmes.S $mes_cpu-mes +fi + +archive libc.a $libc_SOURCES +cp libc.a $mes_cpu-mes +if test -e libc.S; then + cp libc.S $mes_cpu-mes +fi + +archive libc+tcc.a $libc_tcc_SOURCES +cp libc+tcc.a $mes_cpu-mes +if test -e libc+tcc.S; then + cp libc+tcc.S $mes_cpu-mes +fi + +if $courageous; then + exit 0 +fi + +archive libc+gnu.a $libc_gnu_SOURCES +cp libc+gnu.a $mes_cpu-mes +if test -e libc+gnu.S; then + cp libc+gnu.S $mes_cpu-mes +fi + +archive libtcc1.a $libtcc1_SOURCES +cp libtcc1.a $mes_cpu-mes +if test -e libtcc1.S; then + cp libtcc1.S $mes_cpu-mes +fi + +archive libgetopt.a lib/posix/getopt.c +cp libgetopt.a $mes_cpu-mes +if test -e libgetopt.S; then + cp libgetopt.S $mes_cpu-mes +fi diff --git a/build-aux/build-mes.sh b/build-aux/build-mes.sh index 397fdc09..1a8bcf36 100755 --- a/build-aux/build-mes.sh +++ b/build-aux/build-mes.sh @@ -1,7 +1,7 @@ #! /bin/sh # GNU Mes --- Maxwell Equations of Software -# Copyright © 2018 Jan (janneke) Nieuwenhuizen +# Copyright © 2019 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -19,68 +19,39 @@ # along with GNU Mes. If not, see . set -e +set -u -if [ ! "$config_status" ]; then - . ./config.status +V=${V-1} + +if [ "$V" = 2 ]; then + set -x fi -. ${srcdest}build-aux/config.sh +. ./config.sh . ${srcdest}build-aux/trace.sh . ${srcdest}build-aux/cc.sh -[ "$mes_p" ] && (program_prefix= compile lib/linux/$mes_arch/crt1) -[ "$mes_p" -a ! "$gcc_p" ] && cp -f lib/linux/$mes_arch/crt1.S lib/$mes_arch/crt1.S -[ "$mes_p" -a ! "$gcc_p" ] && cp -f lib/linux/$mes_arch/crt1.o lib/$mes_arch/crt1.o +trap 'test -f .log && cat .log' EXIT - [ ! "$mesc_p" -a ! "$with_glibc_p" ] && (program_prefix= compile lib/linux/$mes_arch/crt0) -[ "$mes_p" -a "$gcc_p" ] && (program_prefix= compile lib/linux/$mes_arch/crti) -[ "$mes_p" -a "$gcc_p" ] && (program_prefix= compile lib/linux/$mes_arch/crtn) +srcdest=${srcdest-} +mes_sources=" +src/gc.c +src/hash.c +src/lib.c +src/math.c +src/mes.c +src/module.c +src/posix.c +src/reader.c +src/string.c +src/struct.c +src/vector.c +" -[ ! "$mes_p" -a ! "$mesc_p" ] && compile lib/libmes -[ ! "$mes_p" -a ! "$mesc_p" ] && archive lib/libmes - -[ "$mes_p" ] && compile lib/libc-mini -[ "$mes_p" ] && archive lib/libc-mini - -[ "$mes_p" ] && compile lib/libc -[ "$mes_p" ] && archive lib/libc - -[ "$mes_p" ] && compile lib/libc+tcc -[ "$mes_p" ] && archive lib/libc+tcc - -[ "$mes_p" ] && compile lib/libc+gnu -[ "$mes_p" ] && archive lib/libc+gnu - -[ "$mes_p" -a ! "$mesc_p" ] && compile lib/libtcc1 -[ "$mes_p" -a ! "$mesc_p" ] && archive lib/libtcc1 - -[ "$mes_p" -a ! "$mesc_p" ] && compile lib/libg -[ "$mes_p" -a ! "$mesc_p" ] && archive lib/libg - -[ "$mes_p" -a ! "$mesc_p" ] && compile lib/libgetopt -[ "$mes_p" -a ! "$mesc_p" ] && archive lib/libgetopt - -compile scaffold/main -(libc= link scaffold/main) - -compile scaffold/hello -(libc="-l c-mini" link scaffold/hello) - -compile scaffold/argv -(libc="-l c-mini" link scaffold/argv) - -[ "$mes_p" ] && compile lib/tests/stdlib/50-malloc -[ "$mes_p" ] && link lib/tests/stdlib/50-malloc - -[ "$mes_p" ] && compile lib/tests/posix/50-getenv -[ "$mes_p" ] && link lib/tests/posix/50-getenv - - -[ "$mes_p" ] && compile scaffold/micro-mes -[ "$mes_p" ] && link scaffold/micro-mes - -[ "$mes_p" ] && compile scaffold/tiny-mes -[ "$mes_p" ] && link scaffold/tiny-mes - -compile src/mes +for c in $mes_sources; do + compile $c +done +if test $mes_libc = system; then + LIBS=-lmes +fi link src/mes diff --git a/build-aux/build-scaffold.sh b/build-aux/build-scaffold.sh new file mode 100755 index 00000000..0c8897a1 --- /dev/null +++ b/build-aux/build-scaffold.sh @@ -0,0 +1,75 @@ +#! /bin/sh + +# GNU Mes --- Maxwell Equations of Software +# Copyright © 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 . + +set -e +set -u + +V=${V-1} + +if [ "$V" = 2 ]; then + set -x +fi + +. ./config.sh +. ${srcdest}build-aux/trace.sh + +if $courageous; then + echo "Applying courage" + set +e +fi + +case "$mes_cpu" in + x86_64) + stage0_cpu=amd64;; + x86) + stage0_cpu=x86;; + *) + stage0_cpu=$mes_cpu;; +esac + +trace "HEX2 0exit-42.hex2" $HEX2\ + --LittleEndian\ + --architecture $stage0_cpu\ + --BaseAddress 0x1000000\ + -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0header.hex2\ + -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-exit-42.hex2\ + -f ${srcdest}lib/$mes_cpu-mes/elf-0footer.hex2\ + --exec_enable\ + -o 0exit-42 + +trace "TEST 0exit-42" +{ set +e; ./0exit-42; r=$?; set -e; } +[ $r != 42 ] && echo " => $r" +[ $r == 42 ] + +trace "HEX2 exit-42.hex2" $HEX2\ + --LittleEndian\ + --architecture $stage0_cpu\ + --BaseAddress 0x1000000\ + -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-header.hex2\ + -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-exit-42.hex2\ + -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-footer-single-main.hex2\ + --exec_enable\ + -o exit-42 + +trace "TEST exit-42" +{ set +e; ./exit-42; r=$?; set -e; } +[ $r != 42 ] && echo " => $r" +[ $r == 42 ] diff --git a/build-aux/build.sh.in b/build-aux/build.sh.in index d9704677..4f3891d7 100644 --- a/build-aux/build.sh.in +++ b/build-aux/build.sh.in @@ -1,7 +1,7 @@ #! /bin/sh # GNU Mes --- Maxwell Equations of Software -# Copyright © 2018 Jan (janneke) Nieuwenhuizen +# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -20,34 +20,128 @@ set -e -. ./config.status -. ${srcdest}build-aux/config.sh +if test "$1" = "help"; then + cat < +# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -16,32 +16,41 @@ # You should have received a copy of the GNU General Public License # along with GNU Mes. If not, see . +objects= compile () { - flags= - [ "$mesc_p" ] && flags="$LDFLAGS $MES_CFLAGS" - trace "CC $1.c" $CC -c $CPPFLAGS $CFLAGS $flags -o "$1".${program_prefix}o "${srcdest}$1".c -} - -archive () { - l=$1 - shift - objects=$(for i in $@; do echo $i.${program_prefix}o; done) - [ -z "$objects" ] && objects=$l.${program_prefix}o - out=$(dirname "$l")/$mes_arch/$(basename "$l").a - d=$(dirname $out) - mkdir -p $d - if [ "$mesc_p" ]; then - trace "AR $l.a" mv $l.${program_prefix}o $(dirname $l)/$mes_arch/$(basename $l).o\ - && mv $l.${program_prefix}S $(dirname $l)/$mes_arch/$(basename $l).S - else - trace "AR $l.a" $AR cr $out $objects\ - && mv $objects $d + c=${srcdest}$1 + b=$(basename $c .c) + o=$b.o + objects="$objects $o" + if test $c -nt $o; then + trace "CC $c" $CC -c $CPPFLAGS $CFLAGS -o $o $c + $CC -c $CPPFLAGS $CFLAGS -o $o $c fi } -link () { - lib=$libc - [ "$with_glibc_p" ] && lib='-l mes' - out=$(dirname "$1")/${program_prefix}$(basename "$1") - trace "CCLD $1" $CC $CFLAGS $LDFLAGS -o" $out" $crt1 "$1".${program_prefix}o $2 $lib +archive () { + archive=$1 + shift + sources="$@" + objects= + for c in $sources; do + b=$(basename $c .c) + o=$b.o + compile $c + done + trace "AR $archive" $AR crD $archive $objects + objects= +} + +link () { + out=$1 + d=$(dirname $out) + mkdir -p $d + if test $mes_libc = system; then + crt1= + else + crt1=crt1.o + fi + trace "CCLD $out" $CC $CFLAGS $LDFLAGS -o $out $crt1 $objects $LIBS + objects= } diff --git a/build-aux/check-boot.sh b/build-aux/check-boot.sh index bb5660c8..7941e966 100755 --- a/build-aux/check-boot.sh +++ b/build-aux/check-boot.sh @@ -1,7 +1,7 @@ #! /bin/bash # GNU Mes --- Maxwell Equations of Software -# Copyright © 2018 Jan (janneke) Nieuwenhuizen +# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -19,120 +19,104 @@ # along with GNU Mes. If not, see . set -e +. ./config.sh +set -u -. ./config.status -. ${srcdest}build-aux/config.sh -. ${srcdest}build-aux/trace.sh +TESTS=" -tests=" +scaffold/boot/00-zero.scm +scaffold/boot/01-true.scm +scaffold/boot/02-symbol.scm +scaffold/boot/03-string.scm +scaffold/boot/04-quote.scm +scaffold/boot/05-list.scm +scaffold/boot/06-tick.scm +scaffold/boot/07-if.scm +scaffold/boot/08-if-if.scm -00-zero.scm -01-true.scm -02-symbol.scm -03-string.scm -04-quote.scm -05-list.scm -06-tick.scm -07-if.scm -08-if-if.scm +scaffold/boot/10-cons.scm +scaffold/boot/11-list.scm +scaffold/boot/11-vector.scm +scaffold/boot/12-car.scm +scaffold/boot/13-cdr.scm +scaffold/boot/14-exit.scm +scaffold/boot/15-display.scm -10-cons.scm -11-list.scm -11-vector.scm -12-car.scm -13-cdr.scm -14-exit.scm -15-display.scm +scaffold/boot/16-if-eq-quote.scm -16-if-eq-quote.scm +scaffold/boot/17-memq.scm +scaffold/boot/17-memq-keyword.scm +scaffold/boot/17-string-equal.scm +scaffold/boot/17-equal2.scm +scaffold/boot/17-string-append.scm +scaffold/boot/17-open-input-string.scm -17-memq.scm -17-memq-keyword.scm -17-string-equal.scm -17-equal2.scm -17-string-append.scm -17-open-input-string.scm +scaffold/boot/20-define.scm +scaffold/boot/20-define-quoted.scm +scaffold/boot/20-define-quote.scm -20-define.scm -20-define-quoted.scm -20-define-quote.scm +scaffold/boot/21-define-procedure.scm +scaffold/boot/22-define-procedure-2.scm +scaffold/boot/23-begin.scm +scaffold/boot/24-begin-define.scm +scaffold/boot/25-begin-define-2.scm +scaffold/boot/26-begin-define-later.scm +scaffold/boot/27-lambda-define.scm +scaffold/boot/28-define-define.scm +scaffold/boot/29-lambda-define.scm +scaffold/boot/2a-lambda-lambda.scm +scaffold/boot/2b-define-lambda.scm +scaffold/boot/2c-define-lambda-recurse.scm +scaffold/boot/2d-define-lambda-set.scm +scaffold/boot/2d-compose.scm +scaffold/boot/2e-define-first.scm +scaffold/boot/2f-define-second.scm +scaffold/boot/2f-define-second-lambda.scm +scaffold/boot/2g-vector.scm -21-define-procedure.scm -22-define-procedure-2.scm -23-begin.scm -24-begin-define.scm -25-begin-define-2.scm -26-begin-define-later.scm -27-lambda-define.scm -28-define-define.scm -29-lambda-define.scm -2a-lambda-lambda.scm -2b-define-lambda.scm -2c-define-lambda-recurse.scm -2d-define-lambda-set.scm -2d-compose.scm -2e-define-first.scm -2f-define-second.scm -2f-define-second-lambda.scm -2g-vector.scm +scaffold/boot/30-capture.scm +scaffold/boot/31-capture-define.scm +scaffold/boot/32-capture-modify-close.scm +scaffold/boot/32-capture-modify-close.scm +scaffold/boot/33-procedure-override-close.scm +scaffold/boot/34-cdr-override-close.scm +scaffold/boot/35-closure-modify.scm +scaffold/boot/36-closure-override.scm +scaffold/boot/37-closure-lambda.scm +scaffold/boot/38-simple-format.scm +scaffold/boot/39-global-define-override.scm +scaffold/boot/3a-global-define-lambda-override.scm -30-capture.scm -31-capture-define.scm -32-capture-modify-close.scm -32-capture-modify-close.scm -33-procedure-override-close.scm -34-cdr-override-close.scm -35-closure-modify.scm -36-closure-override.scm -37-closure-lambda.scm -38-simple-format.scm -39-global-define-override.scm -3a-global-define-lambda-override.scm +scaffold/boot/40-define-macro.scm +scaffold/boot/41-when.scm +scaffold/boot/42-if-when.scm +scaffold/boot/43-or.scm +scaffold/boot/44-or-if.scm +scaffold/boot/45-pass-if.scm +scaffold/boot/46-report.scm +scaffold/boot/47-pass-if-eq.scm +scaffold/boot/48-let.scm +scaffold/boot/49-macro-override.scm +scaffold/boot/4a-define-macro-define-macro.scm +scaffold/boot/4b-define-macro-define.scm +scaffold/boot/4c-quasiquote.scm +scaffold/boot/4d-let-map.scm +scaffold/boot/4e-let-global.scm +scaffold/boot/4f-string-split.scm -40-define-macro.scm -41-when.scm -42-if-when.scm -43-or.scm -44-or-if.scm -45-pass-if.scm -46-report.scm -47-pass-if-eq.scm -48-let.scm -49-macro-override.scm -4a-define-macro-define-macro.scm -4b-define-macro-define.scm -4c-quasiquote.scm -4d-let-map.scm -4e-let-global.scm -4f-string-split.scm - -50-string-append.scm -50-string-join.scm -50-primitive-load.scm -51-module.scm -52-define-module.scm -53-closure-display.scm - -60-let-syntax.scm +scaffold/boot/50-keyword.scm +scaffold/boot/50-make-string.scm +scaffold/boot/50-string-join.scm +scaffold/boot/50-primitive-load.scm +scaffold/boot/53-closure-display.scm +scaffold/boot/60-let-syntax.scm +scaffold/boot/call-cc.scm +scaffold/boot/memory.scm +scaffold/boot/numbers.scm " -for i in $tests; do - echo -n $i - if [ ! -f scaffold/boot/$i ]; then - echo ' [SKIP]' - continue; - fi - x=$( - if [ "$MES" = guile -o "$(basename $MES)" = guile ]; then - trace "TEST $i.guile" $GUILE -L ${srcdest}module -C module -L . <(echo '(use-modules (mes guile))'; cat scaffold/boot/$i) - elif [ -z "${i/5[0-9]-*/}" ]; then - cat scaffold/boot/$i | MES_BOOT=${srcdest}boot-00.scm trace "TEST $i" $MES 2>&1; - elif [ -z "${i/6[0-9]-*/}" ]; then - cat scaffold/boot/$i | MES_BOOT=${srcdest}boot-01.scm trace "TEST $i" $MES 2>&1; - else - MES_BOOT=${srcdest}scaffold/boot/$i trace "TEST $i" $MES 2>&1; - fi - ) \ - && echo ' [OK]' \ - || (r=$?; echo ' [FAIL]'; echo -e "$x"; echo scaffold/boot/$i; exit $r) -done +XFAIL_TESTS= + +test_ext=.scm +log_compiler=${srcdest}build-aux/test-boot.sh +. ${srcdest}build-aux/test-suite.sh diff --git a/build-aux/check-mes.sh b/build-aux/check-mes.sh index a2dabc89..7e4057c9 100755 --- a/build-aux/check-mes.sh +++ b/build-aux/check-mes.sh @@ -19,12 +19,10 @@ # along with GNU Mes. If not, see . set -e +. ./config.sh +set -u -. ./config.status -. ${srcdest}build-aux/config.sh -. ${srcdest}build-aux/trace.sh - -tests=" +TESTS=" tests/boot.test tests/read.test tests/srfi-0.test @@ -57,28 +55,8 @@ tests/match.test tests/psyntax.test " -mkdir -p tests -set +e -fail=0 -total=0 -for t in $tests; do - if [ ! -f $t ]; then - echo $t: [SKIP]; - continue - fi - ${top_builddir}/pre-inst-env sh "$t" > $t.${mes}log 2>&1 - r=$? - total=$(expr $total + 1) - if [ $r = 0 ]; then - echo $t: [${mes}OK] - else - echo $t: [${mes}FAIL] - fail=$(expr $fail + 1) - fi -done -if [ $fail != 0 ]; then - echo FAILED: $fail/$total - exit 1 -else - echo PASS: $total -fi +XFAIL_TESTS= + +test_ext=.test +log_compiler=sh +. ${srcdest}build-aux/test-suite.sh diff --git a/build-aux/check-mescc.sh b/build-aux/check-mescc.sh index 67b9e997..b473c9ce 100755 --- a/build-aux/check-mescc.sh +++ b/build-aux/check-mescc.sh @@ -1,7 +1,7 @@ #! /bin/sh # GNU Mes --- Maxwell Equations of Software -# Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen +# Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -19,268 +19,253 @@ # along with GNU Mes. If not, see . set -e -. ./config.status -. ${srcdest}build-aux/config.sh -. ${srcdest}build-aux/trace.sh +. ./config.sh +set -u -test_sh=${test_sh-${srcdest}build-aux/test.sh} - -tests=" -lib/tests/scaffold/t -lib/tests/scaffold/00-exit-0 -lib/tests/scaffold/01-return-0 -lib/tests/scaffold/02-return-1 -lib/tests/scaffold/03-call -lib/tests/scaffold/04-call-0 -lib/tests/scaffold/05-call-1 -lib/tests/scaffold/06-call-not-1 -lib/tests/scaffold/06-not-call-1 -lib/tests/scaffold/06-call-2 -lib/tests/scaffold/06-call-string -lib/tests/scaffold/06-call-variable -lib/tests/scaffold/06-return-void -lib/tests/scaffold/07-include -lib/tests/scaffold/08-assign -lib/tests/scaffold/08-assign-negative -lib/tests/scaffold/08-assign-global -lib/tests/scaffold/10-if-0 -lib/tests/scaffold/11-if-1 -lib/tests/scaffold/12-if-eq -lib/tests/scaffold/13-if-neq -lib/tests/scaffold/14-if-goto -lib/tests/scaffold/15-if-not-f -lib/tests/scaffold/16-if-t -lib/tests/scaffold/17-compare-char -lib/tests/scaffold/17-compare-ge -lib/tests/scaffold/17-compare-gt -lib/tests/scaffold/17-compare-le -lib/tests/scaffold/17-compare-lt -lib/tests/scaffold/17-compare-unsigned-ge -lib/tests/scaffold/17-compare-unsigned-gt -lib/tests/scaffold/17-compare-unsigned-le -lib/tests/scaffold/17-compare-unsigned-lt -lib/tests/scaffold/17-compare-unsigned-char-le -lib/tests/scaffold/17-compare-unsigned-short-le -lib/tests/scaffold/17-compare-unsigned-long-le -lib/tests/scaffold/17-compare-and -lib/tests/scaffold/17-compare-or -lib/tests/scaffold/17-compare-and-or -lib/tests/scaffold/17-compare-assign -lib/tests/scaffold/17-compare-call -lib/tests/scaffold/18-assign-shadow -lib/tests/scaffold/20-while -lib/tests/scaffold/21-char-array-simple -lib/tests/scaffold/21-char-array -lib/tests/scaffold/22-while-char-array -lib/tests/scaffold/23-global-pointer-init-null -lib/tests/scaffold/23-global-pointer-init -lib/tests/scaffold/23-global-pointer-ref -lib/tests/scaffold/23-global-pointer-pointer-ref -lib/tests/scaffold/23-pointer-sub -lib/tests/scaffold/23-pointer -lib/tests/mes/30-oputs -lib/tests/string/30-strlen -lib/tests/scaffold/32-call-wrap -lib/tests/scaffold/32-compare -lib/tests/scaffold/33-and-or -lib/tests/scaffold/34-pre-post -lib/tests/scaffold/35-compare-char -lib/tests/scaffold/36-compare-arithmetic -lib/tests/scaffold/37-compare-assign -lib/tests/scaffold/38-compare-call-2 -lib/tests/scaffold/38-compare-call-3 -lib/tests/scaffold/38-compare-call -lib/tests/scaffold/40-if-else -lib/tests/scaffold/41-ternary -lib/tests/scaffold/42-goto-label -lib/tests/scaffold/43-for-do-while -lib/tests/scaffold/44-switch -lib/tests/scaffold/44-switch-fallthrough -lib/tests/scaffold/44-switch-body-fallthrough -lib/tests/scaffold/45-void-call -lib/tests/scaffold/46-function-static -lib/tests/scaffold/47-function-expression -lib/tests/scaffold/48-global-static -lib/tests/assert/50-assert -lib/tests/mes/50-itoa -lib/tests/posix/50-getenv -lib/tests/string/50-strcmp -lib/tests/string/50-strcpy -lib/tests/string/50-strncmp -lib/tests/scaffold/51-pointer-sub -lib/tests/scaffold/54-argc -lib/tests/scaffold/54-argv -lib/tests/scaffold/55-char-array -lib/tests/scaffold/60-math -lib/tests/scaffold/61-array -lib/tests/scaffold/62-array -lib/tests/scaffold/63-struct -lib/tests/scaffold/63-struct-pointer -lib/tests/scaffold/63-struct-local -lib/tests/scaffold/63-struct-function -lib/tests/scaffold/63-struct-assign -lib/tests/scaffold/63-struct-array -lib/tests/scaffold/63-struct-array-assign -lib/tests/scaffold/63-struct-array-compare -lib/tests/scaffold/63-struct-cell -lib/tests/scaffold/64-make-cell -lib/tests/scaffold/65-read -lib/tests/scaffold/66-local-char-array -lib/tests/scaffold/70-stdarg -lib/tests/stdio/70-printf-hello -lib/tests/stdio/70-printf-simple -lib/tests/stdio/70-printf -lib/tests/stdlib/70-strtoull -lib/tests/string/70-strchr -lib/tests/scaffold/71-struct-array -lib/tests/scaffold/72-typedef-struct-def -lib/tests/scaffold/73-union-hello -lib/tests/scaffold/73-union -lib/tests/scaffold/74-multi-line-string -lib/tests/scaffold/75-struct-union -lib/tests/scaffold/76-pointer-arithmetic-pp -lib/tests/scaffold/76-pointer-arithmetic -lib/tests/scaffold/77-pointer-assign -lib/tests/scaffold/78-union-struct -lib/tests/scaffold/79-int-array-simple -lib/tests/scaffold/79-int-array -lib/tests/scaffold/7a-struct-char-array -lib/tests/scaffold/7b-struct-int-array-hello -lib/tests/scaffold/7b-struct-int-array-pointer -lib/tests/scaffold/7b-struct-int-array -lib/tests/scaffold/7c-dynarray -lib/tests/scaffold/7d-cast-char -lib/tests/scaffold/7e-struct-array-access -lib/tests/scaffold/7f-struct-pointer-arithmetic -lib/tests/scaffold/7g-struct-byte-word-field -lib/tests/scaffold/7h-struct-assign -lib/tests/scaffold/7i-struct-struct-simple -lib/tests/scaffold/7i-struct-struct -lib/tests/scaffold/7k-empty-for -lib/tests/scaffold/7k-for-each-elem-simple -lib/tests/scaffold/7k-for-each-elem -lib/tests/scaffold/7l-struct-any-size-array-simple -lib/tests/scaffold/7l-struct-any-size-array -lib/tests/scaffold/7m-struct-char-array-assign -lib/tests/scaffold/7n-struct-struct-array -lib/tests/scaffold/7o-struct-pre-post-simple -lib/tests/scaffold/7o-struct-pre-post -lib/tests/scaffold/7p-struct-cast -lib/tests/scaffold/7q-bit-field-simple -lib/tests/scaffold/7q-bit-field -lib/tests/scaffold/7r-sign-extend -lib/tests/scaffold/7s-struct-short -lib/tests/scaffold/7s-unsigned-compare -lib/tests/scaffold/7t-function-destruct -lib/tests/scaffold/7u-double -lib/tests/scaffold/7u-long-long -lib/tests/scaffold/7u-ternary-expression -lib/tests/scaffold/7u-call-ternary -lib/tests/scaffold/7u-inc-byte-word -lib/tests/scaffold/7u-struct-func -lib/tests/scaffold/7u-struct-size10 -lib/tests/scaffold/7u-vstack -lib/tests/setjmp/80-setjmp -lib/tests/stdio/80-sscanf -lib/tests/stdlib/80-qsort -lib/tests/stdlib/80-qsort-dupes -lib/tests/string/80-strncpy -lib/tests/string/80-strrchr -lib/tests/scaffold/82-define -lib/tests/scaffold/83-heterogenoous-init -lib/tests/scaffold/84-struct-field-list -lib/tests/scaffold/85-sizeof -lib/tests/dirent/90-readdir -lib/tests/io/90-stat -lib/tests/posix/90-unsetenv -lib/tests/signal/90-signal -lib/tests/stdio/90-fopen -lib/tests/stdio/90-fopen-append -lib/tests/stdio/90-fread-fwrite -lib/tests/stdio/90-fseek -lib/tests/stdlib/90-strtol -lib/tests/string/90-snprintf -lib/tests/string/90-strpbrk -lib/tests/string/90-strspn -lib/tests/scaffold/a0-call-trunc-char -lib/tests/scaffold/a0-call-trunc-short -lib/tests/scaffold/a0-call-trunc-int -lib/tests/scaffold/a0-math-divide-signed-negative -lib/tests/scaffold/a1-global-no-align -lib/tests/scaffold/a1-global-no-clobber +TESTS=" +lib/tests/scaffold/t.c +lib/tests/scaffold/00-exit-0.c +lib/tests/scaffold/01-return-0.c +lib/tests/scaffold/02-return-1.c +lib/tests/scaffold/03-call.c +lib/tests/scaffold/04-call-0.c +lib/tests/scaffold/05-call-1.c +lib/tests/scaffold/06-call-not-1.c +lib/tests/scaffold/06-not-call-1.c +lib/tests/scaffold/06-call-2.c +lib/tests/scaffold/06-call-string.c +lib/tests/scaffold/06-call-variable.c +lib/tests/scaffold/06-return-void.c +lib/tests/scaffold/07-include.c +lib/tests/scaffold/08-assign.c +lib/tests/scaffold/08-assign-negative.c +lib/tests/scaffold/08-assign-global.c +lib/tests/scaffold/10-if-0.c +lib/tests/scaffold/11-if-1.c +lib/tests/scaffold/12-if-eq.c +lib/tests/scaffold/13-if-neq.c +lib/tests/scaffold/14-if-goto.c +lib/tests/scaffold/15-if-not-f.c +lib/tests/scaffold/16-if-t.c +lib/tests/scaffold/17-compare-char.c +lib/tests/scaffold/17-compare-ge.c +lib/tests/scaffold/17-compare-gt.c +lib/tests/scaffold/17-compare-le.c +lib/tests/scaffold/17-compare-lt.c +lib/tests/scaffold/17-compare-unsigned-ge.c +lib/tests/scaffold/17-compare-unsigned-gt.c +lib/tests/scaffold/17-compare-unsigned-le.c +lib/tests/scaffold/17-compare-unsigned-lt.c +lib/tests/scaffold/17-compare-unsigned-char-le.c +lib/tests/scaffold/17-compare-unsigned-short-le.c +lib/tests/scaffold/17-compare-unsigned-long-le.c +lib/tests/scaffold/17-compare-and.c +lib/tests/scaffold/17-compare-or.c +lib/tests/scaffold/17-compare-and-or.c +lib/tests/scaffold/17-compare-assign.c +lib/tests/scaffold/17-compare-call.c +lib/tests/scaffold/18-assign-shadow.c +lib/tests/scaffold/20-while.c +lib/tests/scaffold/21-char-array-simple.c +lib/tests/scaffold/21-char-array.c +lib/tests/scaffold/22-while-char-array.c +lib/tests/scaffold/23-global-pointer-init-null.c +lib/tests/scaffold/23-global-pointer-init.c +lib/tests/scaffold/23-global-pointer-ref.c +lib/tests/scaffold/23-global-pointer-pointer-ref.c +lib/tests/scaffold/23-pointer-sub.c +lib/tests/scaffold/23-pointer.c +lib/tests/mes/30-oputs.c +lib/tests/string/30-strlen.c +lib/tests/scaffold/32-call-wrap.c +lib/tests/scaffold/32-compare.c +lib/tests/scaffold/33-and-or.c +lib/tests/scaffold/34-pre-post.c +lib/tests/scaffold/35-compare-char.c +lib/tests/scaffold/36-compare-arithmetic.c +lib/tests/scaffold/37-compare-assign.c +lib/tests/scaffold/38-compare-call-2.c +lib/tests/scaffold/38-compare-call-3.c +lib/tests/scaffold/38-compare-call.c +lib/tests/scaffold/40-if-else.c +lib/tests/scaffold/41-ternary.c +lib/tests/scaffold/42-goto-label.c +lib/tests/scaffold/43-for-do-while.c +lib/tests/scaffold/44-switch.c +lib/tests/scaffold/44-switch-fallthrough.c +lib/tests/scaffold/44-switch-body-fallthrough.c +lib/tests/scaffold/45-void-call.c +lib/tests/scaffold/46-function-static.c +lib/tests/scaffold/47-function-expression.c +lib/tests/scaffold/48-global-static.c +lib/tests/assert/50-assert.c +lib/tests/mes/50-itoa.c +lib/tests/posix/50-getenv.c +lib/tests/string/50-strcmp.c +lib/tests/string/50-strcpy.c +lib/tests/string/50-strncmp.c +lib/tests/scaffold/51-pointer-sub.c +lib/tests/scaffold/54-argc.c +lib/tests/scaffold/55-char-array.c +lib/tests/scaffold/60-math.c +lib/tests/scaffold/61-array.c +lib/tests/scaffold/62-array.c +lib/tests/scaffold/63-struct.c +lib/tests/scaffold/63-struct-pointer.c +lib/tests/scaffold/63-struct-local.c +lib/tests/scaffold/63-struct-function.c +lib/tests/scaffold/63-struct-assign.c +lib/tests/scaffold/63-struct-array.c +lib/tests/scaffold/63-struct-array-assign.c +lib/tests/scaffold/63-struct-array-compare.c +lib/tests/scaffold/63-struct-cell.c +lib/tests/scaffold/64-make-cell.c +lib/tests/scaffold/65-read.c +lib/tests/scaffold/66-local-char-array.c +lib/tests/scaffold/70-stdarg.c +lib/tests/stdio/70-printf-hello.c +lib/tests/stdio/70-printf-simple.c +lib/tests/stdio/70-printf.c +lib/tests/stdlib/70-strtoull.c +lib/tests/string/70-strchr.c +lib/tests/scaffold/71-struct-array.c +lib/tests/scaffold/72-typedef-struct-def.c +lib/tests/scaffold/73-union-hello.c +lib/tests/scaffold/73-union.c +lib/tests/scaffold/74-multi-line-string.c +lib/tests/scaffold/75-struct-union.c +lib/tests/scaffold/76-pointer-arithmetic-pp.c +lib/tests/scaffold/76-pointer-arithmetic.c +lib/tests/scaffold/77-pointer-assign.c +lib/tests/scaffold/78-union-struct.c +lib/tests/scaffold/79-int-array-simple.c +lib/tests/scaffold/79-int-array.c +lib/tests/scaffold/7a-struct-char-array.c +lib/tests/scaffold/7b-struct-int-array-hello.c +lib/tests/scaffold/7b-struct-int-array-pointer.c +lib/tests/scaffold/7b-struct-int-array.c +lib/tests/scaffold/7c-dynarray.c +lib/tests/scaffold/7d-cast-char.c +lib/tests/scaffold/7e-struct-array-access.c +lib/tests/scaffold/7f-struct-pointer-arithmetic.c +lib/tests/scaffold/7g-struct-byte-word-field.c +lib/tests/scaffold/7h-struct-assign.c +lib/tests/scaffold/7i-struct-struct-simple.c +lib/tests/scaffold/7i-struct-struct.c +lib/tests/scaffold/7k-empty-for.c +lib/tests/scaffold/7k-for-each-elem-simple.c +lib/tests/scaffold/7k-for-each-elem.c +lib/tests/scaffold/7l-struct-any-size-array-simple.c +lib/tests/scaffold/7l-struct-any-size-array.c +lib/tests/scaffold/7m-struct-char-array-assign.c +lib/tests/scaffold/7n-struct-struct-array.c +lib/tests/scaffold/7o-struct-pre-post-simple.c +lib/tests/scaffold/7o-struct-pre-post.c +lib/tests/scaffold/7p-struct-cast.c +lib/tests/scaffold/7q-bit-field-simple.c +lib/tests/scaffold/7q-bit-field.c +lib/tests/scaffold/7r-sign-extend.c +lib/tests/scaffold/7s-struct-short.c +lib/tests/scaffold/7s-unsigned-compare.c +lib/tests/scaffold/7t-function-destruct.c +lib/tests/scaffold/7u-double.c +lib/tests/scaffold/7u-long-long.c +lib/tests/scaffold/7u-ternary-expression.c +lib/tests/scaffold/7u-call-ternary.c +lib/tests/scaffold/7u-inc-byte-word.c +lib/tests/scaffold/7u-struct-func.c +lib/tests/scaffold/7u-struct-size10.c +lib/tests/scaffold/7u-vstack.c +lib/tests/setjmp/80-setjmp.c +lib/tests/stdio/80-sscanf.c +lib/tests/stdlib/80-qsort.c +lib/tests/stdlib/80-qsort-dupes.c +lib/tests/string/80-strncpy.c +lib/tests/string/80-strrchr.c +lib/tests/scaffold/82-define.c +lib/tests/scaffold/83-heterogenoous-init.c +lib/tests/scaffold/84-struct-field-list.c +lib/tests/scaffold/85-sizeof.c +lib/tests/dirent/90-readdir.c +lib/tests/io/90-stat.c +lib/tests/posix/90-unsetenv.c +lib/tests/signal/90-signal.c +lib/tests/stdio/90-fopen.c +lib/tests/stdio/90-fopen-append.c +lib/tests/stdio/90-fread-fwrite.c +lib/tests/stdio/90-fseek.c +lib/tests/stdlib/90-strtol.c +lib/tests/string/90-snprintf.c +lib/tests/string/90-strpbrk.c +lib/tests/string/90-strspn.c +lib/tests/scaffold/90-goto-var.c +lib/tests/scaffold/91-goto-array.c +lib/tests/scaffold/a0-call-trunc-char.c +lib/tests/scaffold/a0-call-trunc-short.c +lib/tests/scaffold/a0-call-trunc-int.c +lib/tests/scaffold/a0-math-divide-signed-negative.c +lib/tests/scaffold/a1-global-no-align.c +lib/tests/scaffold/a1-global-no-clobber.c " -broken="$broken -lib/tests/scaffold/17-compare-unsigned-char-le -lib/tests/scaffold/17-compare-unsigned-short-le -lib/tests/scaffold/66-local-char-array -lib/tests/scaffold/a0-call-trunc-int -lib/tests/scaffold/a0-math-divide-signed-negative -lib/tests/posix/50-getenv +XFAIL_TESTS=" +lib/tests/scaffold/54-argv.c +lib/tests/stdio/90-sprintf.c +lib/tests/stdio/90-sprintf.c " -if [ "$mes_arch" = "x86_64-gcc" ]; then - broken="$broken -lib/tests/scaffold/21-char-array -lib/tests/scaffold/41-ternary -lib/tests/scaffold/stdio/70-printf-stdarg -lib/tests/scaffold/stdio/70-printf-simple -lib/tests/scaffold/stdio/70-printf -lib/tests/setjmp/80-setjmp -lib/tests/scaffold/a1-global-no-align +if test $compiler = mescc; then + XFAIL_TESTS="$XFAIL_TESTS +lib/tests/scaffold/17-compare-unsigned-char-le.c +lib/tests/scaffold/17-compare-unsigned-short-le.c +lib/tests/scaffold/66-local-char-array.c +lib/tests/scaffold/90-goto-var.c +lib/tests/scaffold/91-goto-array.c " - # Debian: debugme itoa is broken - broken="$broken -lib/tests/scaffold/47-function-expression -lib/tests/scaffold/62-array -lib/tests/scaffold/65-read -lib/tests/scaffold/85-sizeof -lib/tests/mes/90-abtod -lib/tests/mes/90-dtoab -lib/tests/posix/90-execlp + + if test $mes_cpu = x86; then + XFAIL_TESTS="$XFAIL_TESTS +lib/tests/scaffold/60-math.c +" + fi + + if test $mes_cpu = x86_64; then + XFAIL_TESTS="$XFAIL_TESTS +lib/tests/scaffold/a0-call-trunc-int.c +" + fi +fi + +if test $mes_cpu = x86; then + XFAIL_TESTS="$XFAIL_TESTS " fi -set +e -expect=$(echo $broken | wc -w) -pass=0 -fail=0 -total=0 -for t in $tests; do - b=$(basename "$t") - if [ -z "${b/[012][0-9]-*/}" ]; then - libc= - elif [ -z "${b/[34][0-9]-*/}" ]; then - libc='-l c-mini' - elif [ -z "${b/[78][0-9a-z]-*/}" ]; then - libc='-l c+tcc' - elif [ -z "${b/9[0-9a-z]-*/}" ]; then - libc='-l c+gnu' - else - libc='-l c' - fi - sh $test_sh "$t" > "$t".log 2>&1 - r=$? - total=$(expr $total + 1) - if [ $r = 0 ]; then - echo $t: [OK] - pass=$(expr $pass + 1) - else - echo $t: [FAIL] - fail=$(expr $fail + 1) - fi -done - -[ $expect != 0 ] && echo "expect: $expect" -[ $fail != 0 ] && echo "failed: $fail" -[ $fail -lt $expect ] && echo "solved: $(expr $expect - $fail)" -echo "passed: $pass" -echo "total: $total" -if [ $fail != 0 -a $fail -gt $expect ]; then - echo FAILED: $fail/$total - exit 1 -elif [ $fail != 0 ]; then - echo PASS: $pass/$total -else - echo PASS: $total +if test $mes_cpu = x86_64; then + XFAIL_TESTS="$XFAIL_TESTS +lib/tests/stdio/70-printf-simple.c +lib/tests/stdio/70-printf-stdarg.c +lib/tests/stdio/70-printf.c +" fi + +if test $compiler = gcc; then + XFAIL_TESTS="$XFAIL_TESTS +" + + if test $mes_cpu = x86; then + XFAIL_TESTS="$XFAIL_TESTS +" + fi + + if test $mes_cpu = x86_64; then + XFAIL_TESTS="$XFAIL_TESTS +lib/tests/stdio/70-printf-hello.c +lib/tests/string/90-snprintf.c +" + fi +fi + +test_ext=.c +log_compiler=${srcdest}build-aux/test-c.sh +. ${srcdest}build-aux/test-suite.sh diff --git a/build-aux/check-tcc.sh b/build-aux/check-tcc.sh deleted file mode 100755 index e38302fd..00000000 --- a/build-aux/check-tcc.sh +++ /dev/null @@ -1,161 +0,0 @@ -#! /bin/sh - -# GNU Mes --- Maxwell Equations of Software -# Copyright © 2017,2018 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 . - -set -e -. ./config.status -. ${srcdest}build-aux/config.sh -. ${srcdest}build-aux/trace.sh - -tests=" -00_assignment -01_comment -02_printf -03_struct -04_for -05_array -06_case -07_function -08_while -09_do_while - -10_pointer -11_precedence -12_hashdefine -13_integer_literals -14_if -15_recursion -16_nesting -17_enum -18_include -19_pointer_arithmetic - -20_pointer_comparison -21_char_array -22_floating_point -23_type_coercion -24_math_library -25_quicksort -26_character_constants -27_sizeof -28_strings -29_array_address - -30_hanoi -31_args -32_led -33_ternary_op -34_array_assignment -35_sizeof -36_array_initialisers -37_sprintf -38_multiple_array_index -39_typedef - -40_stdio -41_hashif -42_function_pointer -43_void_param -44_scoped_declarations -45_empty_for -47_switch_return -48_nested_break -49_bracket_evaluation - -50_logical_second_arg -51_static -52_unnamed_enum -54_goto -55_lshift_type -" - -broken="$broken -18_include - -22_floating_point -23_type_coercion -24_math_library -26_character_constants -27_sizeof -28_strings - -34_array_assignment -39_typedef - -40_stdio -42_function_pointer -49_bracket_evaluation -55_lshift_type -" - -#22_floating_point ; float -#23_type_coercion ; float -#24_math_library ; float -#27_sizeof ; float -#28_strings ; TODO: strncpy strchr strrchr memset memcpy memcmp -#30_hanoi ; fails with GCC -#34_array_assignment ; fails with GCC -#39_typedef ;unsupported: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (typename "MyFunStruct"))) (init-declr-list (init-declr (ptr-declr (pointer) (ident "MoreFunThanEver"))))) - -#40_stdio ; f* functions -#42_function_pointer ; f* functions -#49_bracket_evaluation ; float - - -LIBC=c+gnu -MES_LIBS="-l c+gnu" - -expect=$(echo $broken | wc -w) -ARGS="arg1 arg2 arg3 arg4 arg5" -export ARGS -pass=0 -fail=0 -total=0 -mkdir -p scaffold/tinycc -set +e -for t in $tests; do - if [ ! -f $TINYCC_PREFIX/tests/tests2/"$t.c" ]; then - echo ' [SKIP]' - continue; - fi - cp $TINYCC_PREFIX/tests/tests2/$i* scaffold/tinycc - sh ${srcdest}build-aux/test.sh "scaffold/tinycc/$t" > scaffold/tinycc/"$t".log 2>&1 - r=$? - total=$(expr $total + 1) - if [ $r = 0 ]; then - echo $t: [OK] - pass=$(expr $pass + 1) - else - echo $t: [FAIL] - fail=$(expr $fail + 1) - fi -done -[ $expect != 0 ] && echo "expect: $expect" -[ $fail != 0 ] && echo "failed: $fail" -[ $fail -lt $expect ] && echo "solved: $(expr $expect - $fail)" -echo "passed: $pass" -echo "total: $total" -if [ $fail != 0 -a $fail -gt $expect ]; then - echo FAILED: $fail/$total - exit 1 -elif [ $fail != 0 ]; then - echo PASS: $pass/$total -else - echo PASS: $total -fi diff --git a/build-aux/check.sh.in b/build-aux/check.sh.in index 67247238..e7c6c490 100644 --- a/build-aux/check.sh.in +++ b/build-aux/check.sh.in @@ -20,13 +20,71 @@ set -e -. ./config.status -. ${srcdest}build-aux/config.sh -. ${srcdest}build-aux/trace.sh +. ./config.sh -./pre-inst-env bash ${srcdest}build-aux/check-boot.sh -./pre-inst-env sh ${srcdest}build-aux/check-mes.sh -./pre-inst-env bash ${srcdest}build-aux/check-mescc.sh -if [ -d $TINYCC_PREFIX/tests/tests2 ] ;then - ./pre-inst-env sh ${srcdest}build-aux/check-tcc.sh +if $courageous; then + echo "Applying courage" + set +e fi + +CFLAGS= +if test $mes_libc = mes; then + CFLAGS=" +-nostdinc +-nostdlib +-fno-builtin +" +fi + +CPPFLAGS=" +-D HAVE_CONFIG_H=1 +-I ../include +-I ${srcdir}/include +-I ${srcdir}/include/$mes_kernel/$mes_cpu +" + +LIBS= +LDFLAGS= +if test $mes_libc = mes; then + LDFLAGS=" +-nostdlib +" + LIBS=-lc +fi + +export CFLAGS +export CPPFLAGS +export LDFLAGS +#export LIBS + +./pre-inst-env sh ${srcdest}build-aux/check-boot.sh +./pre-inst-env sh ${srcdest}build-aux/check-mes.sh + +if test $compiler = gcc; then + ( + cd gcc-lib + srcdest=$srcdir/../ + srcdir=../$srcdir + ../pre-inst-env sh ${srcdest}build-aux/check-mescc.sh + ) +fi + +( + cd mescc-lib + srcdest=$srcdir/../ + srcdir=../$srcdir + compiler=mescc + mes_lib=mes + CFLAGS=" +-nostdinc +-nostdlib +-fno-builtin +" + LDFLAGS=" +-nostdlib +" + LIBS=-lc + AR="${srcdest}pre-inst-env ar" + CC="${srcdest}pre-inst-env mescc" + ../pre-inst-env sh ${srcdest}build-aux/check-mescc.sh +) diff --git a/build-aux/config.make.in b/build-aux/config.make.in index 0e9b3650..61b5fc29 100644 --- a/build-aux/config.make.in +++ b/build-aux/config.make.in @@ -20,6 +20,7 @@ AR:=@AR@ BASH:=@BASH@ BLOOD_ELF:=@BLOOD_ELF@ CC:=@CC@ +DIFF:=@DIFF@ DOT:=@DOT@ GIT:=@GIT@ GUILD:=@GUILD@ @@ -37,10 +38,13 @@ MES_FOR_BUILD:=@MES_FOR_BUILD@ MES_SEED:=@MES_SEED@ NYACC:=@NYACC@ PACKAGE:=@PACKAGE@ +PACKAGE_NAME:=@PACKAGE_NAME@ +PACKAGE_BUGREPORT:=@PACKAGE_BUGREPORT@ PERL:=@PERL@ TINYCC_PREFIX:=@TINYCC_PREFIX@ VERSION:=@VERSION@ V:=@V@ +colors:=@colors@ abs_top_builddir:=@abs_top_builddir@ abs_top_srcdir:=@abs_top_srcdir@ @@ -48,11 +52,13 @@ arch:=@arch@ build:=@build@ host:=@host@ -mes_arch:=@mes_arch@ -gcc_p:=@gcc_p@ -mes_p:=@mes_p@ -mesc_p:=@mesc_p@ -tcc_p:=@tcc_p@ +compiler:=@compiler@ +courageous:=@courageous@ +mes_system:=@mes_system@ +mes_cpu:=@mes_cpu@ +mes_bits:=@mes_bits@ +mes_libc:=@mes_libc@ +mes_kernel:=@mes_kernel@ prefix:=@prefix@ @@ -61,6 +67,7 @@ datadir:=@datadir@ docdir:=@docdir@ guile_site_ccache_dir:=@guile_site_ccache_dir@ guile_site_dir:=@guile_site_dir@ +includedir:=@includedir@ infodir:=@infodir@ libdir:=@libdir@ mandir:=@mandir@ diff --git a/build-aux/config.sh b/build-aux/config.sh deleted file mode 100644 index 2ec06642..00000000 --- a/build-aux/config.sh +++ /dev/null @@ -1,164 +0,0 @@ -# GNU Mes --- Maxwell Equations of Software -# Copyright © 2018 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 . - -srcdir=${srcdir-.} -top_builddir=${top_builddir-.} - -if [ "$V" = 2 ]; then - echo $0 - echo srcdest=${srcdest} - echo top_builddir=${top_builddir} -fi - -if [ -n "$mes_p" -a -n "$gcc_p" ]; then - crt1=lib/linux/$mes_arch/crt1.o -fi - -MES=${MES-${program_prefix}mes} -libc=${libc-"-l c"} -export libc - -if [ ! "$CC" ]; then - CC="./pre-inst-env mescc" -fi - -unset CFLAGS -unset CPPFLAGS -unset HEX2FLAGS -unset LDFLAGS -unset M1FLAGS - -export AR -export CC -export CFLAGS -export CPPFLAGS -export GUILD -export GUILE -export GUILE_LOAD_COMPILED_PATH -export GUILE_LOAD_PATH -export HEX2 -export HEX2FLAGS -export M1 -export M1FLAGS -export MES -export MES_CFLAGS -export MES_FOR_BUILD -export MES_SEED -export MESCC - -export MES_DEBUG -export MES_ARENA -export TINYCC_PREFIX -export V - -export config_status -export abs_top_builddir -export abs_top_srcdir -export arch -export datadir -export moduledir -export prefix -export program_prefix -export srcdest -export srcdir -export top_builddir - -export bits -export build -export host -export compiler -export gcc_p -export mes_p -export mesc_p -export tcc_p -export mes_arch -export with_glibc_p - -CPPFLAGS=${CPPFLAGS-" --D 'VERSION=\"$VERSION\"' --D 'MODULEDIR=\"$moduledir\"' --D 'PREFIX=\"$prefix\"' --I ${srcdest}. --I ${srcdest}lib --I ${srcdest}include -"} - -[ "$with_glibc_p" ] && CPPFLAGS="$CPPFLAGS -D SYSTEM_LIBC=1" - -LDFLAGS=${LDFLAGS-" --v --g --L lib/linux/$mes_arch --L lib/linux --L lib/$mes_arch --L lib -"} - -if [ -f "$MES_SEED/x86-mes/mes.S" ]; then - LDFLAGS="$LDFLAGS --L $MES_SEED -" -fi - -if [ -n "$gcc_p" ]; then -CFLAGS=${CFLAGS-" --v ---std=gnu99 --O0 --g -"} -fi - -if [ "$mes_p" -a "$gcc_p" ]; then -CFLAGS="$CFLAGS --fno-builtin --fno-stack-protector --nostdinc --nostdlib --Wno-discarded-qualifiers --Wno-int-to-pointer-cast --Wno-pointer-to-int-cast --Wno-pointer-sign --Wno-int-conversion --Wno-incompatible-pointer-types -" -fi - -if [ "$arch" = "x86" ]; then - HEX2FLAGS=${HEX2FLAGS-" ---LittleEndian ---architecture x86 ---BaseAddress 0x1000000 -"} - M1FLAGS=${M1FLAGS-" ---LittleEndian ---architecture x86 -"} - bits=32 -elif [ "$arch" = "x86_64" ]; then - HEX2FLAGS=${HEX2FLAGS-" ---LittleEndian ---architecture amd64 ---BaseAddress 0x1000000 -"} - M1FLAGS=${M1FLAGS-" ---LittleEndian ---architecture amd64 -"} - bits=64 -fi diff --git a/build-aux/config.status.in b/build-aux/config.sh.in similarity index 71% rename from build-aux/config.status.in rename to build-aux/config.sh.in index baa15d91..7bd137c4 100644 --- a/build-aux/config.status.in +++ b/build-aux/config.sh.in @@ -16,11 +16,12 @@ # You should have received a copy of the GNU General Public License # along with GNU Mes. If not, see . -config_status=1 -AR="@AR@" +config_sh=1 +AR=${AR-"@AR@"} BASH="@BASH@" BLOOD_ELF="@BLOOD_ELF@" -CC="@CC@" +CC=${CC-"@CC@"} +DIFF=${DIFF-@DIFF@} DOT="@DOT@" GIT="@GIT@" GUILD="@GUILD@" @@ -37,10 +38,13 @@ MES_FOR_BUILD="@MES_FOR_BUILD@" MES_SEED="@MES_SEED@" NYACC="@NYACC@" PACKAGE="@PACKAGE@" +PACKAGE_NAME="@PACKAGE_NAME@" +PACKAGE_BUGREPORT="@PACKAGE_BUGREPORT@" PERL="@PERL@" TINYCC_PREFIX="@TINYCC_PREFIX@" VERSION="@VERSION@" -V="@V@" +V=${V-"@V@"} +colors=${colors-@colors@} abs_top_builddir="@abs_top_builddir@" abs_top_srcdir="@abs_top_srcdir@" @@ -48,26 +52,44 @@ arch="@arch@" build="@build@" host="@host@" -mes_arch="@mes_arch@" -gcc_p="@gcc_p@" -mes_p="@mes_p@" -mesc_p="@mesc_p@" -tcc_p="@tcc_p@" +compiler=${compiler-@compiler@} +courageous=${courageous-@courageous@} +mes_system=@mes_system@ +mes_cpu=@mes_cpu@ +mes_bits=@mes_bits@ +mes_libc=@mes_libc@ +mes_kernel=@mes_kernel@ prefix="@prefix@" bindir="@bindir@" datadir="@datadir@" +pkgdatadir="@pkgdatadir@" docdir="@docdir@" guile_site_ccache_dir="@guile_site_ccache_dir@" guile_site_dir="@guile_site_dir@" +includedir="@includedir@" infodir="@infodir@" libdir="@libdir@" mandir="@mandir@" moduledir="@moduledir@" with_glibc_p="@with_glibc_p@" program_prefix="@program_prefix@" -srcdest="@srcdest@" -srcdir="@srcdir@" +srcdest=${srcdest-"@srcdest@"} +srcdir=${srcdir-"@srcdir@"} sysconfdir="@sysconfdir@" top_builddir="@top_builddir@" + +export PACKAGE +export PACKAGE_NAME +export PACKAGE_BUGREPORT +export AR +export CC +export DIFF +export V +export colors +export compiler +export courageous +export srcdest +export srcdir +export GUILE_AUTO_COMPILE diff --git a/build-aux/export.make b/build-aux/export.make index 74158f40..4d30a75f 100644 --- a/build-aux/export.make +++ b/build-aux/export.make @@ -17,6 +17,8 @@ # along with GNU Mes. If not, see . export PACKAGE +export PACKAGE_NAME +export PACKAGE_BUGREPORT export VERSION export abs_top_builddir @@ -40,6 +42,14 @@ export mandir export moduledir export sysconfdir +export compiler +export courageous +export mes_system +export mes_cpu +export mes_bits +export mes_libc +export mes_kernel + ifdef V export V endif @@ -48,18 +58,10 @@ ifdef DESTDIR export DESTDIR endif -ifdef arch -export arch -endif - ifdef CC export CC endif -ifdef CC64 -export CC64 -endif - ifdef BLOOD_ELF export BLOOD_ELF endif @@ -112,10 +114,6 @@ ifdef PERL export PERL endif -ifdef TCC -export TCC -endif - ifdef GUILE_LOAD_PATH export GUILE_LOAD_PATH endif @@ -139,7 +137,3 @@ endif ifdef M1FLAGS export M1FLAGS endif - -ifdef TINYCC_PREFIX -export TINYCC_PREFIX -endif diff --git a/build-aux/install.sh.in b/build-aux/install.sh.in index 36106f87..60c581c3 100644 --- a/build-aux/install.sh.in +++ b/build-aux/install.sh.in @@ -1,4 +1,4 @@ -#! /bin/sh +#! @SHELL@ # GNU Mes --- Maxwell Equations of Software # Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen @@ -20,34 +20,44 @@ set -e -. ./config.status +. ./config.sh -mes_prefix=@prefix@/share/mes +v= +_v= +if test "$V" = 2; then + set -x +fi +if test "$V" -gt 0; then + v=v + _v=-v +fi -# use bash or lose if pipes fail -if [ -n "$BASHOPTS" ]; then +set -u + +# Use bash or lose if pipes fail +if test -n "$BASHOPTS"; then set -o pipefail fi -mkdir -p ${DESTDIR}@bindir@ -if [ -f src/x86-mes-mes ]; then - cp src/x86-mes-mes ${DESTDIR}@bindir@/mes -fi -cp scripts/mescc.scm ${DESTDIR}@bindir@/mescc.scm -cp scripts/mescc ${DESTDIR}@bindir@/mescc +DESTDIR=${DESTDIR-} +mkdir -p ${DESTDIR}${bindir} +cp $_v src/mes ${DESTDIR}${bindir}/mes +cp $_v scripts/ar ${DESTDIR}${bindir}/ar +cp $_v scripts/mescc.scm ${DESTDIR}${bindir}/mescc.scm +cp $_v scripts/mescc ${DESTDIR}${bindir}/mescc sed \ - -e "s,^#! /bin/sh,#! @SHELL@," \ - scripts/diff.scm > ${DESTDIR}@bindir@/diff.scm -chmod +x ${DESTDIR}@bindir@/diff.scm + -e "s,^#! /bin/sh,#! ${SHELL}," \ + scripts/diff.scm > ${DESTDIR}${bindir}/diff.scm +chmod +x ${DESTDIR}${bindir}/diff.scm -mkdir -p ${DESTDIR}@docdir@ +mkdir -p ${DESTDIR}${docdir} -if [ -n "@PERL@" ]\ - && [ -n "@GIT@" ]\ - && @PERL@ -v > /dev/null\ - && @GIT@ status > /dev/null; then - @PERL@ ${srcdest}build-aux/gitlog-to-changelog --srcdir=. > ChangeLog +if test -n "${PERL}"\ + && test -n "${GIT}"\ + && ${PERL} -v > /dev/null\ + && ${GIT} status > /dev/null; then + ${PERL} ${srcdest}build-aux/gitlog-to-changelog --srcdir=. > ChangeLog+ fi cp\ @@ -58,66 +68,50 @@ cp\ INSTALL\ NEWS\ README\ - ${DESTDIR}@docdir@ + ${DESTDIR}${docdir} -if [ -f ChangeLog ]; then - cp ChangeLog ${DESTDIR}@docdir@ +if test -f ChangeLog+; then + cp $_v ChangeLog+ ${DESTDIR}${docdir}/ChangeLog + rm -f ChangeLog+ else - cp ChangeLog ${DESTDIR}@docdir@ + cp $_v ChangeLog ${DESTDIR}${docdir} fi -mkdir -p $DESTDIR$mes_prefix -rm -f $(find lib -type f -a -executable) -rm -f $(find lib/tests -type f -a -name '*.1') -rm -f $(find lib/tests -type f -a -name '*.2') -rm -f $(find lib/tests -type f -a -name '*.o') -rm -f $(find lib/tests -type f -a -name '*.log') -rm -f $(find lib/tests -type f -a -name '*.x86-mes*') -rm -f $(find lib/tests -type f -a -name '*.x86_64-mes*') -rm -f $(find scaffold -type f -a -executable) -rm -f $(find scaffold -type f -a -name '*.1') -rm -f $(find scaffold -type f -a -name '*.2') -rm -f $(find scaffold -type f -a -name '*.o') -rm -f $(find scaffold -type f -a -name '*.S') -rm -f $(find scaffold -type f -a -name '*.log') -rm -f $(find scaffold -type f -a -name '*.x86-mes*') -rm -f $(find scaffold -type f -a -name '*.x86_64-mes*') -if [ -z "$srcdest" ]; then - tar -cf- include lib | tar -xf- -C $DESTDIR$mes_prefix - tar -cf- --exclude='*.go' module | tar -xf- -C $DESTDIR$mes_prefix - tar -cf- scaffold | tar -xf- -C $DESTDIR$mes_prefix +mkdir -p $DESTDIR$libdir +mkdir -p $DESTDIR$pkgdatadir +# rm -f $(find lib -type f -a -executable) +# rm -f $(find scaffold -type f -a -executable) +tar -cf- -C ${srcdir} include lib/$mes_cpu-mes | tar -${v}xf- -C $DESTDIR$prefix +if test -z "$srcdest"; then + tar -cf- --exclude='*.go' module | tar -${v}xf- -C $DESTDIR$pkgdatadir else - tar -cf- -C ${srcdest} include lib | tar -xf- -C $DESTDIR$mes_prefix - tar -cf- -C lib | tar -xf- -C $DESTDIR$mes_prefix - tar -cf- -C ${srcdest} module | tar -xf- -C $DESTDIR$mes_prefix - tar -cf- -C ${srcdest} scaffold | tar -xf- -C $DESTDIR$mes_prefix + tar -cf- -C ${srcdest} module | tar -${v}xf- -C $DESTDIR$pkgdatadir fi -tar -cf- -C ${srcdest}mes module | tar -xf- -C $DESTDIR$mes_prefix - -if [ -f src/mes.x86-mes-S ]; then - cp src/mes.x86-mes-S $DESTDIR$mes_prefix/lib/x86-mes/mes.S +tar -cf- -C ${srcdest}mes module | tar -${v}xf- -C $DESTDIR$pkgdatadir +if test -d gcc-lib/$mes_cpu-mes; then + tar -cf- -C gcc-lib/$mes_cpu-mes . | tar -${v}xf- -C $DESTDIR$libdir fi -if [ -f src/mes.x86_64-mes-S ]; then - cp src/mes.x86_64-mes-S $DESTDIR$mes_prefix/lib/x86_64-mes/mes.S +if test -d mescc-lib/$mes_cpu-mes; then + tar -cf- -C mescc-lib $mes_cpu-mes | tar -${v}xf- -C $DESTDIR$libdir fi -mkdir -p ${DESTDIR}@guile_site_dir@ -mkdir -p ${DESTDIR}@guile_site_ccache_dir@ -tar -cf- -C ${srcdest}module --exclude='*.go' . | tar -xf- -C ${DESTDIR}@guile_site_dir@ -tar -cf- -C module --exclude='*.scm' . | tar -xf- -C ${DESTDIR}@guile_site_ccache_dir@ +mkdir -p ${DESTDIR}${guile_site_dir} +mkdir -p ${DESTDIR}${guile_site_ccache_dir} +tar -cf- -C ${srcdest}module --exclude='*.go' . | tar -${v}xf- -C ${DESTDIR}${guile_site_dir} +tar -cf- -C module --exclude='*.scm' . | tar -${v}xf- -C ${DESTDIR}${guile_site_ccache_dir} -if [ -f doc/mes.info ]; then - mkdir -p ${DESTDIR}@infodir@ - tar -cf- doc/mes.info* doc/images | tar -xf- --strip-components=1 -C ${DESTDIR}@infodir@ - install-info --info-dir=${DESTDIR}@infodir@ doc/mes.info +if test -f doc/mes.info; then + mkdir -p ${DESTDIR}${infodir} + tar -cf- doc/mes.info* doc/images | tar -${v}xf- --strip-components=1 -C ${DESTDIR}${infodir} + install-info --info-dir=${DESTDIR}${infodir} doc/mes.info fi -if [ -f doc/mes.1 ]; then - mkdir -p ${DESTDIR}@mandir@/man1 - cp doc/mes.1 ${DESTDIR}@mandir@/man1/ +if test -f doc/mes.1; then + mkdir -p ${DESTDIR}${mandir}/man1 + cp $_v doc/mes.1 ${DESTDIR}${mandir}/man1/ fi -if [ -f doc/mescc.1 ]; then - mkdir -p ${DESTDIR}@mandir@/man1 - cp doc/mescc.1 ${DESTDIR}@mandir@/man1/ +if test -f doc/mescc.1; then + mkdir -p ${DESTDIR}${mandir}/man1 + cp $_v doc/mescc.1 ${DESTDIR}${mandir}/man1/ fi diff --git a/build-aux/pre-inst-env.in b/build-aux/pre-inst-env.in index 0bd4baec..efc134f5 100644 --- a/build-aux/pre-inst-env.in +++ b/build-aux/pre-inst-env.in @@ -34,7 +34,7 @@ if [ -n "$srcdest" ]; then fi export GUILE_LOAD_COMPILED_PATH GUILE_LOAD_PATH -PATH="$abs_top_builddir/scripts:$abs_top_builddir/src:$abs_top_builddir/build-aux:$PATH" +PATH="$abs_top_builddir/scripts:$abs_top_builddir/scripts:$abs_top_builddir/src:$abs_top_builddir/build-aux:$PATH" export PATH MES=${MES-${abs_top_builddir}/src/${program_prefix}mes} diff --git a/build-aux/test-cc.sh b/build-aux/test-boot.sh similarity index 55% rename from build-aux/test-cc.sh rename to build-aux/test-boot.sh index ffc5bc5b..a189a3ea 100755 --- a/build-aux/test-cc.sh +++ b/build-aux/test-boot.sh @@ -1,7 +1,7 @@ #! /bin/sh # GNU Mes --- Maxwell Equations of Software -# Copyright © 2018 Jan (janneke) Nieuwenhuizen +# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -20,30 +20,19 @@ set -e -if [ ! "$config_status" ]; then - . ./config.status +if [ "$V" = 2 ]; then + set -x fi -. ${srcdest}build-aux/config.sh -. ${srcdest}build-aux/trace.sh -. ${srcdest}build-aux/cc.sh +t=${1-scaffold/boot/00-zero.scm} +b=$(basename "$t" .scm) -t=${1-scaffold/tests/t} -o="$t" - -rm -f "${program_prefix}$o" -compile "$t" -link "$t" - -r=0 -[ -f "$t".exit ] && r=$(cat "$t".exit) -set +e -$(dirname "$o")/${program_prefix}$(basename "$o") $ARGS > "$o".${program_prefix}1 2> "$o".${program_prefix}2 -m=$? -cat "$o".${program_prefix}1 -set -e - -[ $m = $r ] -if [ -f "$t".stdout ]; then - $DIFF -ub "$t".stdout "$o".${program_prefix}1 +if [ "$(basename $MES)" = guile ]; then + $MES -L ${srcdest}module -C module -L . -c '(begin (use-modules (mes guile)) (include-from-path "'"$t"'"))' +elif [ -z "${b/5[0-9]-*/}" ]; then + cat "$t" | MES_BOOT=boot-00.scm $MES +elif [ -z "${b/6[0-9]-*/}" ]; then + cat "$t" | MES_BOOT=boot-01.scm $MES +else + MES_BOOT=$t $MES; fi diff --git a/build-aux/test-c.sh b/build-aux/test-c.sh new file mode 100755 index 00000000..1ca2d1de --- /dev/null +++ b/build-aux/test-c.sh @@ -0,0 +1,77 @@ +#! /bin/sh + +# GNU Mes --- Maxwell Equations of Software +# Copyright © 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 . + +set -e + +if [ "$V" = 2 ]; then + set -x +fi + +t=${1-lib/tests/scaffold/t.c} +b=$(dirname "$t")/$(basename "$t" .c) +o="$b" +o=lib/tests/${b#*lib/tests/} +if [ "$o" = "$b" ]; then + o=$(basename "$t" .c) +fi + +rm -f "$o" +CC=${CC-gcc} + +i=$(basename "$t" .c) +if [ -z "${i/[012][0-9]-*/}" ]; then + LIBS= +elif [ -z "${i/[34][0-9]-*/}" ]; then + LIBS='-l c-mini' +elif [ -z "${i/[78][0-9a-z]-*/}" ]; then + LIBS='-l c+tcc' +elif [ -z "${i/9[0-9a-z]-*/}" ]; then + LIBS='-l c+gnu' +else + LIBS='-l c' +fi + +if test $mes_libc = system; then + crt1= + LIBS=-lmes +else + crt1=crt1.o +fi + +$CC -c $CPPFLAGS $CFLAGS -o "$o".o "$t" +$CC $CFLAGS $LDFLAGS -L . -o "$o" $crt1 "$o".o $LIBS + +set +e +#timeout 2 "$o" -s --long file0 file1 > "$o".1 2> "$o".2 +timeout 2 "$o" > "$o".1 2> "$o".2 +r=$? +set -e +if [ -f "$b".exit ]; then + e=$(cat "$b".exit) +else + e=0 +fi +[ $r = $e ] || exit 1 +if [ -f "$b".stdout ]; then + $DIFF -ub "$b".stdout "$o".1 +fi +if [ -f "$b".stderr ]; then + $DIFF -ub "$b".stderr "$o".2 +fi diff --git a/build-aux/test-driver b/build-aux/test-driver new file mode 100755 index 00000000..2930e80b --- /dev/null +++ b/build-aux/test-driver @@ -0,0 +1,148 @@ +#!/bin/sh +# test-driver - basic testsuite driver script. + +scriptversion=2018-03-07.03; # UTC + +# Copyright (C) 2011-2018 Free Software Foundation, Inc. +# +# This program 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 2, or (at your option) +# any later version. +# +# This program 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 this program. If not, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# This file is maintained in Automake, please report +# bugs to or send patches to +# . + +# Make unconditional expansion of undefined variables an error. This +# helps a lot in preventing typo-related bugs. +set -u + +usage_error () +{ + echo "$0: $*" >&2 + print_usage >&2 + exit 2 +} + +print_usage () +{ + cat <$log_file 2>&1 +estatus=$? + +if test $enable_hard_errors = no && test $estatus -eq 99; then + tweaked_estatus=1 +else + tweaked_estatus=$estatus +fi + +case $tweaked_estatus:$expect_failure in + 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; + 0:*) col=$grn res=PASS recheck=no gcopy=no;; + 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; + 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; + *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; + *:*) col=$red res=FAIL recheck=yes gcopy=yes;; +esac + +# Report the test outcome and exit status in the logs, so that one can +# know whether the test passed or failed simply by looking at the '.log' +# file, without the need of also peaking into the corresponding '.trs' +# file (automake bug#11814). +echo "$res $test_name (exit status: $estatus)" >>$log_file + +# Report outcome to console. +echo "${col}${res}${std}: $test_name" + +# Register the test result, and other relevant metadata. +echo ":test-result: $res" > $trs_file +echo ":global-test-result: $res" >> $trs_file +echo ":recheck: $recheck" >> $trs_file +echo ":copy-in-global-log: $gcopy" >> $trs_file + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: diff --git a/build-aux/test-suite.sh b/build-aux/test-suite.sh new file mode 100644 index 00000000..32909df8 --- /dev/null +++ b/build-aux/test-suite.sh @@ -0,0 +1,137 @@ +#! /bin/sh + +# GNU Mes --- Maxwell Equations of Software +# Copyright © 2011-2018 Free Software Foundation, Inc. +# Copyright © 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 . + +# Adapted from GNU Automake + +TEST_SUITE_LOG=test-suite.log +dry_run=false +create_global_log=cat +subdir=$(basename $(pwd)) + +TEST_LOGS= +for t in $TESTS; do + b=$(dirname $t)/$(basename $t $test_ext) + d=$(dirname $t) + case " `echo $XFAIL_TESTS` " in + *[\ \ ]$t[\ \ ]*) + fail=yes;; + *) + fail=no;; + esac + mkdir -p $d + sh ${srcdest}build-aux/test-driver\ + --test-name $t \ + --log-file $b.log\ + --trs-file $b.trs\ + --color-tests $colors\ + --enable-hard-errors no\ + --expect-failure $fail\ + -- $log_compiler\ + ${srcdest}$t + TEST_LOGS="$TEST_LOGS $b.log" +done + +if test $colors = yes; then + red='' + grn='' + lgn='' + blu='' + mgn='' + brg='' + std='' +else + mgn= red= grn= lgn= blu= brg= std= +fi +bases="$TEST_LOGS" +bases=`for i in $bases; do echo $i; done | sed 's/\.log$//'` +bases=`echo $bases` +ws='[ ]' +results=`for b in $bases; do echo $b.trs; done` +test -n "$results" || results=/dev/null +all=` grep "^$ws*:test-result:" $results | wc -l` +pass=` grep "^$ws*:test-result:$ws*PASS" $results | wc -l` +fail=` grep "^$ws*:test-result:$ws*FAIL" $results | wc -l` +skip=` grep "^$ws*:test-result:$ws*SKIP" $results | wc -l` +xfail=`grep "^$ws*:test-result:$ws*XFAIL" $results | wc -l` +xpass=`grep "^$ws*:test-result:$ws*XPASS" $results | wc -l` +error=`grep "^$ws*:test-result:$ws*ERROR" $results | wc -l` +if test `expr $fail + $xpass + $error` -eq 0; then + success=true +else + success=false +fi +br='==================='; br=$br$br$br$br +result_count () +{ + if test x"$1" = x"--maybe-color"; then + maybe_colorize=yes + elif test x"$1" = x"--no-color"; then + maybe_colorize=no + else + echo "$@: invalid 'result_count' usage" >&2; exit 4 + fi + shift + desc=$1 count=$2 + if test $maybe_colorize = yes && test $count -gt 0; then + color_start=$3 color_end=$std + else + color_start= color_end= + fi + echo "${color_start}# $desc $count${color_end}" +} +create_testsuite_report () +{ + result_count $1 "TOTAL:" $all "$brg" + result_count $1 "PASS: " $pass "$grn" + result_count $1 "SKIP: " $skip "$blu" + result_count $1 "XFAIL:" $xfail "$lgn" + result_count $1 "FAIL: " $fail "$red" + result_count $1 "XPASS:" $xpass "$red" + result_count $1 "ERROR:" $error "$mgn" +} +{ + echo "${PACKAGE}: ${subdir}/${TEST_SUITE_LOG}" + create_testsuite_report --no-color + echo + echo + for b in $bases; do echo $b; done\ + | $create_global_log +} >${TEST_SUITE_LOG}.tmp || exit 1 +mv ${TEST_SUITE_LOG}.tmp ${TEST_SUITE_LOG} +if $success; then + col="$grn" + else + col="$red" + test x"$V" = x0 || cat ${TEST_SUITE_LOG} +fi +echo "${col}$br${std}" +echo "${col}Testsuite summary for ${PACKAGE_NAME}${std}" +echo "${col}$br${std}" +create_testsuite_report --maybe-color +echo "$col$br$std" +if $success; then :; else + echo "${col}See ${subdir}/${TEST_SUITE_LOG}${std}" + if test -n "${PACKAGE_BUGREPORT}"; then + echo "${col}Please report to ${PACKAGE_BUGREPORT}${std}" + fi + echo "$col$br$std" +fi +$success || exit 1 diff --git a/build-aux/trace.sh b/build-aux/trace.sh index 9573d788..d8477845 100644 --- a/build-aux/trace.sh +++ b/build-aux/trace.sh @@ -16,26 +16,34 @@ # You should have received a copy of the GNU General Public License # along with GNU Mes. If not, see . +LOG= if [ -z "$V" -o "$V" = 0 ]; then trace () { echo " $1" shift - eval "$@" $LOG + echo "$@" >> build.log + eval "$@ $LOG" + cat .log 1>&2 + cat .log >> build.log } - LOG=" >>build.log 2>&1" + LOG=" >.log 2>&1" fi if [ "$V" = 1 ]; then trace () { shift echo "$@" + echo "$@" >> build.log eval "$@ $LOG" + cat .log 1>&2 + cat .log >> build.log } - LOG=" >>build.log 2>&1" + LOG=" >.log 2>&1" fi if [ "$V" = 2 ]; then set -x trace () { shift + echo "$@" >> build.log eval "$@" } fi diff --git a/build-aux/uninstall.sh.in b/build-aux/uninstall.sh.in index 6acae1d7..e1815d81 100644 --- a/build-aux/uninstall.sh.in +++ b/build-aux/uninstall.sh.in @@ -20,31 +20,45 @@ #set -e -. ./config.status -. ${srcdest}build-aux/config.sh -. ${srcdest}build-aux/trace.sh +. ./config.sh -GUILE=${GUILE-$(command -v guile)} || true -if [ -z "$GUILE" -o "$GUILE" = true ]; then - GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2} -else - GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')} +v= +_v= +if test "$V" = 2; then + set -x +fi +if test "$V" -gt 0; then + v=v + _v=-v fi -datadir=${datadir-$prefix/share} -docdir=${docdir-$datadir/doc/mes-$VERSION} -infodir=${infodir-$datadir/info} -mandir=${mandir-$datadir/man} -moduledir=${moduledir-$datadir/mes/module} -guile_site_dir=${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION} -guile_site_ccache_dir=${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache} +set -u -MES_PREFIX=${MES_PREFIX-$prefix/share/mes} +rm ${DESTDIR}${bindir}/mes +rm ${DESTDIR}${bindir}/ar +rm ${DESTDIR}${bindir}/mescc +rm ${DESTDIR}${bindir}/mescc.scm +rm ${DESTDIR}${bindir}/diff.scm +rmdir ${DESTDIR}${bindir} || : -rm $DESTDIR$prefix/bin/mes -rm $DESTDIR$prefix/bin/mescc -rm -f $DESTDIR$prefix/bin/diff.scm -rmdir $DESTDIR$prefix/bin || : +rm -r ${DESTDIR}${libdir}/$mes_cpu-mes +rm ${DESTDIR}${libdir}/libc-mini.a +rm ${DESTDIR}${libdir}/libmes.a +if cmp gcc-lib/libc.a ${DESTDIR}${libdir}/libc.a; then + rm ${DESTDIR}${libdir}/libc.a +fi +if cmp gcc-lib/libtcc1.a ${DESTDIR}${libdir}/libtcc1.a; then + rm ${DESTDIR}${libdir}/libtcc1.a +fi +rm ${DESTDIR}${libdir}/libc+tcc.a +rm ${DESTDIR}${libdir}/libc+gnu.a + +rm -r ${DESTDIR}${includedir}/mes +rm $(grep -lr _MES_ ${DESTDIR}${includedir}) +rmdir ${DESTDIR}${includedir}/linux/x86 +rmdir ${DESTDIR}${includedir}/linux/x86_64 +rmdir ${DESTDIR}${includedir}/linux +rmdir -p ${DESTDIR}${includedir}/sys for i in\ AUTHORS\ @@ -56,28 +70,27 @@ for i in\ NEWS\ README\ ;do - rm $DESTDIR$docdir/$i || :; + rm ${DESTDIR}${docdir}/$i || :; done -rmdir $DESTDIR$docdir || : +rm -r ${DESTDIR}${pkgdatadir} +rm -r ${DESTDIR}${guile_site_ccache_dir}/mes +rm -r ${DESTDIR}${guile_site_ccache_dir}/mescc -rm -r $DESTDIR$MES_PREFIX -rm -r $DESTDIR$guile_site_ccache_dir/mes -rm -r $DESTDIR$guile_site_ccache_dir/mescc +rm -r ${DESTDIR}${guile_site_dir}/mes +rm ${DESTDIR}${guile_site_dir}/mescc.scm +rm -r ${DESTDIR}${guile_site_dir}/mescc -rm -r $DESTDIR$guile_site_dir/mes -rm -r $DESTDIR$guile_site_dir/mescc +rm ${DESTDIR}${infodir}/dir +rm ${DESTDIR}${infodir}/mes.info* +rm ${DESTDIR}${infodir}/images/gcc-mesboot* +rm ${DESTDIR}${infodir}/images/README +rm ${DESTDIR}${mandir}/man1/mes.1 +rm ${DESTDIR}${mandir}/man1/mescc.1 -rm $DESTDIR$prefix/share/info/dir -rm $DESTDIR$prefix/share/info/mes.info* -rm $DESTDIR$prefix/share/info/images/gcc-mesboot* -rm $DESTDIR$prefix/share/info/images/README -rm $DESTDIR$mandir/man1/mes.1 -rm $DESTDIR$mandir/man1/mescc.1 - -rmdir -p $DESTDIR$prefix/share/doc -rmdir -p $DESTDIR$prefix/share/info/images -rmdir -p $DESTDIR$guile_site_dir -rmdir -p $DESTDIR$guile_site_ccache_dir -rmdir -p $DESTDIR$mandir/man1 +rmdir -p ${DESTDIR}${docdir} +rmdir -p ${DESTDIR}${infodir}/images +rmdir -p ${DESTDIR}${guile_site_dir} +rmdir -p ${DESTDIR}${guile_site_ccache_dir} +rmdir -p ${DESTDIR}${mandir}/man1 true diff --git a/configure b/configure index 5b3c52e7..85106f38 100755 --- a/configure +++ b/configure @@ -32,6 +32,12 @@ MES_ARENA=100000000 exec ${SCHEME-guile} -L . --no-auto-compile -e '(configure)' #:use-module (ice-9 rdelim) #:export (main)) +(define *shell* "sh") +(define PACKAGE "mes") +(define PACKAGE-NAME "GNU Mes") +(define PACKAGE-BUGREPORT "bug-mes@gnu.org") +(define VERSION "0.19") + (cond-expand (guile) (mes (mes-use-module (srfi srfi-1)) @@ -63,10 +69,6 @@ MES_ARENA=100000000 exec ${SCHEME-guile} -L . --no-auto-compile -e '(configure)' (and (and warn? (format (current-error-port) "warning: not found: ~a\n" name)) default))) -(define *shell* "sh") -(define PACKAGE "mes") -(define VERSION "0.19") - ;;; Utility (define (logf port string . rest) (apply format (cons* port string rest)) @@ -279,6 +281,7 @@ MES_ARENA=100000000 exec ${SCHEME-guile} -L . --no-auto-compile -e '(configure)' (bindir (value #t)) (datadir (value #t)) (docdir (value #t)) + (includedir (value #t)) (libdir (value #t)) (srcdir (value #t)) (sysconfdir (value #t)) @@ -290,14 +293,15 @@ MES_ARENA=100000000 exec ${SCHEME-guile} -L . --no-auto-compile -e '(configure)' (with-courage) (infodir (value #t)) (mandir (value #t)) + (disable-colors) + (enable-colors) (disable-silent-rules) (enable-silent-rules) + (with-system-libc) (enable-fast-install) ; Ignored for Guix - (includedir (value #t)) ; Ignored for Debian (mandir (value #t)) ; Ignored for Debian (localstatedir (value #t)) ; Ignored for Debian - (libdir (value #t)) ; Ignored for Debian (libexecdir (value #t)) ; Ignored for Debian (runstatedir (value #t)) ; Ignored for Debian (disable-maintainer-mode) ; Ignored for Debian @@ -320,17 +324,24 @@ Defaults for the options are specified in brackets. Options: -h, --help display this help --build=BUILD configure for building on BUILD [guessed] + --colors no colorized output --disable-silent-rules verbose build output [V=1] --host=HOST cross-compile to build programs to run on HOST [BUILD] - --mes use Mes C Library -v, --verbose be verbose - --with-courage assert being courageous to configure for unsupported platform + --with-courage Assert that even if this platform is unsupported, + you will be courageous and port GNU Mes to it + (see \"Porting GNU Mes\" in the manual.) --with-cheating cheat using Guile instead of Mes + --with-system-libc use system libc Installation directories: --prefix=DIR install in prefix DIR [~a] + + --bindir=DIR user executables [PREFIX/bin] + --includedir=DIR C header files [PREFIX/include] --infodir=DIR info documentation [PREFIX/share/info] + --libdir=DIR object code libraries [EPREFIX/lib] --mandir=DIR man pages [PREFIX/share/man] Program names: @@ -343,8 +354,6 @@ Ignored for Guix: Ignored for Debian: --disable-dependency-tracking --disable-maintainer-mode - --includedir=DIR - --libdir=DIR --libexecdir=DIR --localstatedir=DIR --runstatedir=DIR @@ -356,7 +365,6 @@ Some influential environment variables: GUILD guild command MES_FOR_BUILD build system MES [can be mes or guile] MES_SEED location of mes-seed - TINYCC_PREFIX location of tinycc [for tests/test2] " PACKAGE VERSION (getenv "prefix"))) (define (main args) @@ -376,11 +384,9 @@ Some influential environment variables: (bindir (option-ref options 'bindir "${prefix}/bin")) (datadir (option-ref options 'datadir "${prefix}/share")) (docdir (option-ref options 'docdir "${datadir}/doc/mes-${VERSION}")) + (includedir (option-ref options 'libdir "${prefix}/include")) (libdir (option-ref options 'libdir "${prefix}/lib")) - (moduledir "${datadir}/mes/module") - (moduledir/ (string-append - (gulp-pipe* "echo" prefix) - "/share/mes/module/")) + (pkgdatadir (string-append datadir "/mes")) (guile-effective-version (effective-version)) (guile-site-dir (if (equal? prefix ".") (canonicalize-path ".") (string-append prefix "/share/guile/site/" guile-effective-version))) @@ -397,8 +403,11 @@ Some influential environment variables: (with-cheating? (option-ref options 'with-cheating #f)) (with-courage? (option-ref options 'with-courage #f)) + (disable-colors? (option-ref options 'disable-colors #f)) + (enable-colors? (option-ref options 'enable-colors #f)) (disable-silent-rules? (option-ref options 'disable-silent-rules #f)) (enable-silent-rules? (option-ref options 'enable-silent-rules #f)) + (with-system-libc? (option-ref options 'with-system-libc #f)) (vars (filter (cut string-index <> #\=) (option-ref options '() '()))) (help? (option-ref options 'help #f)) (mes? (option-ref options 'mes #f))) @@ -425,6 +434,7 @@ Some influential environment variables: (list (make-dep "hex2" #:version '(0 3)) (make-dep "M1" #:version '(0 3)) (make-dep "blood-elf" #:version '(0 1)) + (make-dep "diff" #:optional? #t) (make-dep "guile" #:version '(2 0) #:commands '("guile-2.2" "guile-2.0" "guile-2" "guile") #:optional? #t) (make-dep "mes" #:version '(0 18) #:optional? #t) (make-dep "guix" #:version '(0 13) #:optional? #t) @@ -483,16 +493,23 @@ Some influential environment variables: (cons (check-link-c cc (make-dep "if cc can create executables" #:data "int main () {return 0;}")) deps) deps)) - (mes? (or mes? (not (file-name "if cc can create executables" deps)))) + (system-libc? (and with-system-libc? (file-name "if cc can create executables" deps))) (build-type (or (and cc (gulp-pipe* cc "-dumpmachine")) build-type)) - (arch (car (string-split build-type #\-))) - (arch (if (member arch '("i386" "i486" "i586" "i686")) "x86" - arch)) - (mes-arch arch) - (mes-arch (if mes? (string-append mes-arch "-mes") mes-arch)) - (mes-arch (if gcc? (string-append mes-arch "-gcc") mes-arch)) - (mes-arch (if tcc? (string-append mes-arch "-gcc") mes-arch)) - (posix? (and (not mesc?) (not mes?)))) + (build-type-list (string-split build-type #\-)) + (mes-cpu (car build-type-list)) + (mes-cpu (if (member mes-cpu '("i386" "i486" "i586" "i686")) "x86" + mes-cpu)) + (mes-bits (if (member mes-cpu '("x86_64")) "64" + "32")) + (mes-libc (if system-libc? "system" "mes")) + + (kernel-list (filter (compose not (cut equal? <> "unknown")) (cdr build-type-list))) + (mes-kernel (cond ((or (equal? '("linux" "gnu") kernel-list) + (equal? "linux" (car kernel-list))) "linux") + ((equal? '( "gnu") kernel-list) "gnu") + (else "unknown"))) + (compiler (if gcc? "gcc" "mescc")) + (mes-system (string-join (list mes-cpu mes-kernel "mes") "-"))) (define* (substitute file-name pairs #:key (target (if (string-suffix? ".in" file-name) @@ -508,8 +525,8 @@ Some influential environment variables: line pairs)) (loop (read-line in 'concat)))))))) - (when (and (not (member arch '("x86" "x86_64"))) (not with-courage?)) - (stderr "platform not supported: ~a, try --with-courage\n" arch) + (when (and (not (member mes-system '("x86-linux-mes" "x86_64-linux-mes"))) (not with-courage?)) + (stderr "platform not supported: ~a, try --with-courage\n" mes-system) (exit 1)) (when (pair? missing) (stderr "\nMissing dependencies: ~a\n" (string-join (map dependency-name missing))) @@ -523,18 +540,20 @@ Some influential environment variables: (zero? (system* "git" "commit" "--allow-empty" "-m" "Import mes"))))) (let ((pairs `(("@PACKAGE@" . ,PACKAGE) + ("@PACKAGE_NAME@" . ,PACKAGE-NAME) + ("@PACKAGE_BUGREPORT@" . ,PACKAGE-BUGREPORT) ("@VERSION@" . ,VERSION) - ("@arch@" . ,arch) ("@build@" . ,build-type) ("@host@" . ,host-type) - ("@gcc_p@" . ,(if gcc? "1" "")) - ("@mes_arch@" . ,mes-arch) - ("@mes_p@" . ,(if mes? "1" "")) - ("@mesc_p@" . ,(if mesc? "1" "")) - ("@with_glibc_p@" . ,(if posix? "1" "")) - ("@tcc_p@" . ,(if tcc? "1" "")) + ("@courageous@" . ,(if with-courage? "true" "false")) + ("@compiler@" . ,compiler) + ("@mes_bits@" . ,mes-bits) + ("@mes_kernel@" . ,mes-kernel) + ("@mes_cpu@" . ,mes-cpu) + ("@mes_libc@" . ,mes-libc) + ("@mes_system@" . ,mes-system) ("@abs_top_srcdir@" . ,abs-top-srcdir) ("@abs_top_builddir@" . ,abs-top-builddir) @@ -547,21 +566,24 @@ Some influential environment variables: ("@program_prefix@" . ,program-prefix) ("@bindir@" . ,bindir) ("@datadir@" . ,datadir) + ("@pkgdatadir@" . ,pkgdatadir) ("@docdir@" . ,docdir) ("@guile_site_ccache_dir@" . ,guile-site-ccache-dir) ("@guile_site_dir@" . ,guile-site-dir) ("@infodir@" . ,infodir) + ("@includedir@" . ,includedir) ("@libdir@" . ,libdir) ("@mandir@" . ,mandir) - ("@moduledir@" . ,moduledir) ("@sysconfdir@" . ,sysconfdir) ("@GUILE_EFFECTIVE_VERSION@" . ,(effective-version)) + ("@colors@" . ,(if disable-colors? "no" "yes")) ("@V@" . ,(if disable-silent-rules? "1" "0")) ("@AR@" . ,(or (file-name "ar" deps) "")) ("@BASH@" . ,(or (file-name "bash" deps) "")) ("@CC@" . ,(or (file-name "cc" deps) "")) + ("@DIFF@" . ,(or (file-name "diff" deps) (string-append abs-top-builddir "/pre-inst-env diff.scm"))) ("@DOT@" . ,(or (file-name "dot" deps) "")) ("@GIT@" . ,(or (file-name "git" deps) "")) ("@GUILE@" . ,guile) @@ -578,7 +600,6 @@ Some influential environment variables: ("@HEX2FLAGS@" . ,(or (getenv "HEX2FLAGS") "")) ("@M1FLAGS@" . ,(or (getenv "M1FLAGS") "")) - ("mes/module/" . ,(string-append moduledir/)) ,@(map (lambda (o) (cons (string-append "@" (variable-name o) "@") (or (format #f "~a" (dependency-file-name o)) ""))) @@ -596,35 +617,52 @@ Some influential environment variables: (substitute src pairs #:target target))) '( "build-aux/GNUmakefile.in" - "build-aux/config.status.in" + "build-aux/config.sh.in" "build-aux/build.sh.in" - "build-aux/bootstrap.sh.in" "build-aux/check.sh.in" "build-aux/install.sh.in" "build-aux/pre-inst-env.in" "build-aux/uninstall.sh.in" - "mes/module/mes/boot-0.scm.in" + "scripts/ar.in" "scripts/mescc.scm.in" "scripts/mescc.in" )) (chmod "pre-inst-env" #o755) + (chmod "scripts/ar" #o755) (chmod "scripts/mescc" #o755) (chmod "scripts/mescc.scm" #o755) (chmod "build.sh" #o755) - (chmod "bootstrap.sh" #o755) (chmod "check.sh" #o755) (chmod "install.sh" #o755) (chmod "uninstall.sh" #o755) + + (system* "mkdir" "-p" "include/mes") + (let ((pkgdatadir (gulp-pipe* "sh" "-c" (string-append "prefix=" prefix + ";datadir=" datadir + ";echo ${datadir}/mes")))) + (with-output-to-file "include/mes/config.h" + (lambda _ + (if system-libc? + (display "#define SYSTEM_LIBC 1 +") + (display "#undef SYSTEM_LIBC +")) + (display (string-append " +#define VERSION \"" VERSION "\" +#define pkgdatadir \"" pkgdatadir "\" +"))))) (substitute (string-append srcdest "build-aux/config.make.in") pairs #:target ".config.make")) (let ((make (and=> (file-name "make" deps) basename))) - (format (current-output-port) - " -GNU Mes is configured for ~a + (display (string-append " +GNU Mes is configured for + compiler: " compiler " + cpu: " mes-cpu " + bits: " mes-bits " + libc: " mes-libc " + kernel: " mes-kernel " + system: " mes-system " Run: - ~a to build mes - ~a help for help on other targets\n" - mes-arch - (or make "./build.sh") - (or make "./build.sh")))))) + " (or make "./build.sh") " to build mes + " (or make "./build.sh") " help for help on other targets\n")))))) diff --git a/configure.sh b/configure.sh index a2798cef..22396ceb 100755 --- a/configure.sh +++ b/configure.sh @@ -1,7 +1,7 @@ #! /bin/sh # GNU Mes --- Maxwell Equations of Software -# Copyright © 2018 Jan (janneke) Nieuwenhuizen +# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -24,16 +24,27 @@ VERSION=0.19 srcdir=${srcdir-$(dirname $0)} . ${srcdest}build-aux/trace.sh -# parse --mes +# parse --with-system-libc cmdline=$(echo " $@") -p=${cmdline/ --mes/} -if [ "$p" != "$cmdline" ]; then - mes_p=${mes_p-1} +p=${cmdline/ --with-system-libc/} +if test "$p" != "$cmdline"; then + mes_libc=${mes_libc-system} +else + mes_libc=mes +fi + +# parse --with-courage +cmdline=$(echo " $@") +p=${cmdline/ --with-courage/} +if test "$p" != "$cmdline"; then + courageous=true +else + courageous=false fi # parse --prefix=PREFIX p=${cmdline/ --prefix=/ -prefix=} -if [ "$p" != "$cmdline" ]; then +if test "$p" != "$cmdline"; then p=${p##* -prefix=} p=${p% *} p=${p% -*} @@ -45,7 +56,7 @@ fi # parse --program-prefix= p=${cmdline/ --program-prefix=/ -program-prefix=} -if [ "$p" != "$cmdline" ]; then +if test "$p" != "$cmdline"; then p=${p##* -program-prefix=} p=${p% *} p=${p% -*} @@ -56,10 +67,11 @@ AR=${AR-$(command -v ar)} || true BASH=${BASH-$(command -v bash)} BLOOD_ELF=${BLOOD_ELF-$(command -v blood-elf)} CC=${CC-$(command -v gcc)} || true +DIFF=${DIFF-$(command -v diff || echo $PWD/pre-inst-env diff.scm)} GUILD=${GUILD-$(command -v guild)} || true GUILE_TOOLS=${GUILE_TOOLS-$(command -v guile-tools)} || true -if [ ! "$GUILD" ]; then - if [ "$GUILE_TOOLS" ]; then +if test ! "$GUILD"; then + if test "$GUILE_TOOLS"; then GUILD=$GUILE_TOOLS else GUILD=true @@ -73,7 +85,7 @@ GIT=${GIT-$(command -v git)} || true PERL=${PERL-$(command -v perl)} || true MES_SEED=${MES_SEED-../mes-seed} -if [ "$srcdir" = . ]; then +if test "$srcdir" = .; then top_builddir=. else srcdest=${srcdest} @@ -82,7 +94,7 @@ fi abs_top_srcdir=${abs_top_srcdir-$(cd ${srcdir} && pwd)} abs_top_builddir=$PWD -if [ -z "$GUILE" -o "$GUILE" = true ]; then +if test -z "$GUILE" -o "$GUILE" = true; then GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2} else GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')} @@ -91,6 +103,7 @@ bindir=$(eval echo ${bindir-$prefix/bin}) datadir=$(eval echo ${datadir-$prefix/share}) docdir=$(eval echo ${docdir-$datadir/doc/mes-$VERSION}) infodir=$(eval echo ${infodir-$datadir/info}) +includedir=$(eval echo ${libdir-$prefix/include}) libdir=$(eval echo ${libdir-$prefix/lib}) mandir=$(eval echo ${mandir-$datadir/man}) moduledir=$(eval echo ${moduledir-$datadir/mes/module}) @@ -101,17 +114,18 @@ guile_site_ccache_dir=$(eval echo ${guile_site_ccache_dir-$prefix/lib/guile/$GUI subst () { sed \ -e s,"@PACKAGE@,$PACKAGE,"\ + -e s,"@PACKAGE_NAME@,$PACKAGE_NAME,"\ + -e s,"@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,"\ -e s,"@VERSION@,$VERSION,"\ - -e s,"@arch@,$arch,"\ -e s,"@build@,$build,"\ -e s,"@host@,$host,"\ -e s,"@compiler@,$compiler,"\ - -e s,"@gcc_p@,$gcc_p,"\ - -e s,"@mes_p@,$mes_p,"\ - -e s,"@mesc_p@,$mesc_p,"\ - -e s,"@tcc_p@,$tcc_p,"\ - -e s,"@mes_arch@,$mes_arch,"\ - -e s,"@with_glibc_p@,$with_glibc_p,"\ + -e s,"@courageous@,$courageous,"\ + -e s,"@mes_bits@,$mes_bits,"\ + -e s,"@mes_kernel@,$mes_kernel,"\ + -e s,"@mes_cpu@,$mes_cpu,"\ + -e s,"@mes_libc@,$mes_libc,"\ + -e s,"@mes_system@,$mes_system,"\ -e s,"@abs_top_srcdir@,$abs_top_srcdir,"\ -e s,"@abs_top_builddir@,$abs_top_builddir,"\ -e s,"@top_builddir@,$top_builddir,"\ @@ -125,6 +139,7 @@ subst () { -e s,"@guile_site_dir@,$guile_site_dir,"\ -e s,"@guile_site_ccache_dir@,$guile_site_ccache_dir,"\ -e s,"@infodir@,$infodir,"\ + -e s,"@includedir@,$includedir,"\ -e s,"@libdir@,$libdir,"\ -e s,"@mandir@,$mandir,"\ -e s,"@moduledir@,$moduledir,"\ @@ -135,6 +150,7 @@ subst () { -e s,"@BASH@,$BASH,"\ -e s,"@BLOOD_ELF@,$BLOOD_ELF,"\ -e s,"@CC@,$CC,"\ + -e s,"@DIFF@,$DIFF,"\ -e s,"@GIT@,$GIT,"\ -e s,"@GUILD@,$GUILD,"\ -e s,"@GUILE@,$GUILE,"\ @@ -152,68 +168,88 @@ subst () { $1 > $2 } -subst ${srcdest}build-aux/pre-inst-env.in pre-inst-env -chmod +x pre-inst-env -subst ${srcdest}scripts/mescc.in scripts/mescc -chmod +x scripts/mescc -subst ${srcdest}scripts/mescc.scm.in scripts/mescc.scm -chmod +x scripts/mescc.scm - -host=${host-$($CC -dumpmachine 2>/dev/null || echo x86)} -if [ -z "$host" ]; then - arch=${arch-$(get_machine || uname -m)} +host=${host-$($CC -dumpmachine 2>/dev/null)} +if test -z "$host$host_type"; then + mes_cpu=${arch-$(get_machine || uname -m)} else - arch=${host%%-*} + mes_cpu=${host%%-*} fi -if [ "$arch" = i386\ - -o "$arch" = i486\ - -o "$arch" = i586\ - -o "$arch" = i686\ - ]; then - arch=x86 +if test "$mes_cpu" = i386\ + || test "$mes_cpu" = i486\ + || test "$mes_cpu" = i586\ + || test "$mes_cpu" = i686; then + mes_cpu=x86 fi +case "$host" in + *linux-gnu|*linux) + mes_kernel=linux;; + *gnu) + mes_kernel=gnu;; + *) + mes_kernel=linux;; +esac + +case "$mes_cpu" in + x86_64) + mes_bits=64;; + *) + mes_bits=32;; +esac # if $CC --version | grep gcc; then #2>/dev/null; then - gcc_p=1 compiler=gcc elif $CC --version | grep tcc; then #2>/dev/null; then - tcc_p=1 - compiler=tcc + compiler=gcc else - mes_p=1 - mesc_p=1 compiler=mescc fi -mes_arch=$arch -if [ "$mes_p" -o "$mesc_p" ]; then - mes_arch=$arch-mes -fi +mes_system=$mes_cpu-$mes_kernel-mes -if [ ! "$mesc_p" ]; then - mes_arch=$mes_arch-$compiler -fi -if [ ! "$mesc_p" -a ! "$mes_p" ]; then - with_glibc_p=1 -fi - -subst ${srcdest}mes/module/mes/boot-0.scm.in mes/module/mes/boot-0.scm subst ${srcdest}build-aux/GNUmakefile.in GNUmakefile -subst ${srcdest}build-aux/config.status.in config.status +subst ${srcdest}build-aux/config.sh.in config.sh subst ${srcdest}build-aux/build.sh.in build.sh chmod +x build.sh -subst ${srcdest}build-aux/bootstrap.sh.in bootstrap.sh -chmod +x bootstrap.sh subst ${srcdest}build-aux/check.sh.in check.sh chmod +x check.sh subst ${srcdest}build-aux/install.sh.in install.sh chmod +x install.sh +subst ${srcdest}build-aux/pre-inst-env.in pre-inst-env +chmod +x pre-inst-env +subst ${srcdest}scripts/ar.in scripts/ar +chmod +x scripts/ar +subst ${srcdest}scripts/mescc.scm.in scripts/mescc.scm +chmod +x scripts/mescc.scm +subst ${srcdest}scripts/mescc.in scripts/mescc +chmod +x scripts/mescc subst ${srcdest}build-aux/uninstall.sh.in uninstall.sh chmod +x uninstall.sh +mkdir -p include/mes +if test $mes_libc = system; then + cat >> include/mes/config.h <> include/mes/config.h <> include/mes/config.h < #else // ! SYSTEM_LIBC -#define assert(x) ((x) ? (void)0 : assert_fail (#x)) -void assert_fail (char *s); +#define assert(x) ((x) ? (void)0 : __assert_fail (#x)) +void __assert_fail (char *s); #endif // ! SYSTEM_LIBC #endif // __MES_ASSERT_H diff --git a/lib/libgetopt.c b/include/grp.h similarity index 61% rename from lib/libgetopt.c rename to include/grp.h index 3eb4cc23..f77a5e45 100644 --- a/lib/libgetopt.c +++ b/include/grp.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -17,5 +17,29 @@ * You should have received a copy of the GNU General Public License * along with GNU Mes. If not, see . */ +#ifndef __MES_GRP_H +#define __MES_GRP_H 1 -#include +#if SYSTEM_LIBC +#undef __MES_GRP_H +#include_next +#else // ! SYSTEM_LIBC + +#include + +struct group +{ + char *gr_name; + gid_t gr_gid; + char **gr_mem; +}; + +struct group *getgrent (void); +void endgrent (void); +void setgrent (void); +struct group *getgrgid (gid_t gid); +struct group *getgrnam (char const *name); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_GRP_H diff --git a/lib/linux/libc-mini.c b/include/linux/syscall.h similarity index 59% rename from lib/linux/libc-mini.c rename to include/linux/syscall.h index c101d7b7..0af5fd70 100644 --- a/lib/linux/libc-mini.c +++ b/include/linux/syscall.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,18 +18,14 @@ * along with GNU Mes. If not, see . */ -#include +#ifndef __MES_SYSCALL_H +#define __MES_SYSCALL_H -#if __MESC__ && __i386__ -#include -#elif __MESC__ && __x86_64__ -#include -#elif __i386__ -#include -#elif __x86_64__ -#include -#else -#error arch not supported -#endif +long _sys_call (long sys_call); +long _sys_call1 (long sys_call, long one); +long _sys_call2 (long sys_call, long one, long two); +long _sys_call3 (long sys_call, long one, long two, long three); +long _sys_call4 (long sys_call, long one, long two, long three, long four); +long _sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six); -#include +#endif //__MES_SYSCALL_H diff --git a/include/mes/builtins.h b/include/mes/builtins.h index cfd0b92d..ddb48902 100644 --- a/include/mes/builtins.h +++ b/include/mes/builtins.h @@ -1,3 +1,26 @@ +/* -*-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 . + */ + +#ifndef __MES_BUILTINS_H +#define __MES_BUILTINS_H + // src/gc.mes SCM gc_check (); SCM gc (); @@ -389,3 +412,5 @@ SCM vector_entry (SCM x); SCM vector_set_x (SCM x, SCM i, SCM e); SCM list_to_vector (SCM x); SCM vector_to_list (SCM v); + +#endif //__MES_BUILTINS_H diff --git a/include/mes/constants.h b/include/mes/constants.h new file mode 100644 index 00000000..7606beb6 --- /dev/null +++ b/include/mes/constants.h @@ -0,0 +1,324 @@ +/* -*-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 . + */ + +#ifndef __MES_CONSTANTS_H +#define __MES_CONSTANTS_H + +/* Symbols */ + +// CONSTANT cell_nil 1 +#define cell_nil 1 +// CONSTANT cell_f 2 +#define cell_f 2 +// CONSTANT cell_t 3 +#define cell_t 3 +// CONSTANT cell_dot 4 +#define cell_dot 4 +// CONSTANT cell_arrow 5 +#define cell_arrow 5 +// CONSTANT cell_undefined 6 +#define cell_undefined 6 +// CONSTANT cell_unspecified 7 +#define cell_unspecified 7 +// CONSTANT cell_closure 8 +#define cell_closure 8 +// CONSTANT cell_circular 9 +#define cell_circular 9 +// CONSTANT cell_begin 10 +#define cell_begin 10 +// CONSTANT cell_call_with_current_continuation 11 +#define cell_call_with_current_continuation 11 + +// CONSTANT cell_vm_apply 12 +#define cell_vm_apply 12 +// CONSTANT cell_vm_apply2 13 +#define cell_vm_apply2 13 +// CONSTANT cell_vm_begin 14 +#define cell_vm_begin 14 +// CONSTANT cell_vm_begin_eval 15 +#define cell_vm_begin_eval 15 +// CONSTANT cell_vm_begin_expand 16 +#define cell_vm_begin_expand 16 +// CONSTANT cell_vm_begin_expand_eval 17 +#define cell_vm_begin_expand_eval 17 +// CONSTANT cell_vm_begin_expand_macro 18 +#define cell_vm_begin_expand_macro 18 +// CONSTANT cell_vm_begin_expand_primitive_load 19 +#define cell_vm_begin_expand_primitive_load 19 +// CONSTANT cell_vm_begin_primitive_load 20 +#define cell_vm_begin_primitive_load 20 +// CONSTANT cell_vm_begin_read_input_file 21 +#define cell_vm_begin_read_input_file 21 +// CONSTANT cell_vm_call_with_current_continuation2 22 +#define cell_vm_call_with_current_continuation2 22 +// CONSTANT cell_vm_call_with_values2 23 +#define cell_vm_call_with_values2 23 +// CONSTANT cell_vm_eval 24 +#define cell_vm_eval 24 +// CONSTANT cell_vm_eval2 25 +#define cell_vm_eval2 25 +// CONSTANT cell_vm_eval_check_func 26 +#define cell_vm_eval_check_func 26 +// CONSTANT cell_vm_eval_define 27 +#define cell_vm_eval_define 27 +// CONSTANT cell_vm_eval_macro_expand_eval 28 +#define cell_vm_eval_macro_expand_eval 28 +// CONSTANT cell_vm_eval_macro_expand_expand 29 +#define cell_vm_eval_macro_expand_expand 29 +// CONSTANT cell_vm_eval_pmatch_car 30 +#define cell_vm_eval_pmatch_car 30 +// CONSTANT cell_vm_eval_pmatch_cdr 31 +#define cell_vm_eval_pmatch_cdr 31 +// CONSTANT cell_vm_eval_set_x 32 +#define cell_vm_eval_set_x 32 +// CONSTANT cell_vm_evlis 33 +#define cell_vm_evlis 33 +// CONSTANT cell_vm_evlis2 34 +#define cell_vm_evlis2 34 +// CONSTANT cell_vm_evlis3 35 +#define cell_vm_evlis3 35 +// CONSTANT cell_vm_if 36 +#define cell_vm_if 36 +// CONSTANT cell_vm_if_expr 37 +#define cell_vm_if_expr 37 +// CONSTANT cell_vm_macro_expand 38 +#define cell_vm_macro_expand 38 +// CONSTANT cell_vm_macro_expand_car 39 +#define cell_vm_macro_expand_car 39 +// CONSTANT cell_vm_macro_expand_cdr 40 +#define cell_vm_macro_expand_cdr 40 +// CONSTANT cell_vm_macro_expand_define 41 +#define cell_vm_macro_expand_define 41 +// CONSTANT cell_vm_macro_expand_define_macro 42 +#define cell_vm_macro_expand_define_macro 42 +// CONSTANT cell_vm_macro_expand_lambda 43 +#define cell_vm_macro_expand_lambda 43 +// CONSTANT cell_vm_macro_expand_set_x 44 +#define cell_vm_macro_expand_set_x 44 +// CONSTANT cell_vm_return 45 +#define cell_vm_return 45 + +// CONSTANT cell_symbol_dot 46 +#define cell_symbol_dot 46 +// CONSTANT cell_symbol_lambda 47 +#define cell_symbol_lambda 47 +// CONSTANT cell_symbol_begin 48 +#define cell_symbol_begin 48 +// CONSTANT cell_symbol_if 49 +#define cell_symbol_if 49 +// CONSTANT cell_symbol_quote 50 +#define cell_symbol_quote 50 +// CONSTANT cell_symbol_define 51 +#define cell_symbol_define 51 +// CONSTANT cell_symbol_define_macro 52 +#define cell_symbol_define_macro 52 + +// CONSTANT cell_symbol_quasiquote 53 +#define cell_symbol_quasiquote 53 +// CONSTANT cell_symbol_unquote 54 +#define cell_symbol_unquote 54 +// CONSTANT cell_symbol_unquote_splicing 55 +#define cell_symbol_unquote_splicing 55 +// CONSTANT cell_symbol_syntax 56 +#define cell_symbol_syntax 56 +// CONSTANT cell_symbol_quasisyntax 57 +#define cell_symbol_quasisyntax 57 +// CONSTANT cell_symbol_unsyntax 58 +#define cell_symbol_unsyntax 58 +// CONSTANT cell_symbol_unsyntax_splicing 59 +#define cell_symbol_unsyntax_splicing 59 + +// CONSTANT cell_symbol_set_x 60 +#define cell_symbol_set_x 60 + +// CONSTANT cell_symbol_sc_expand 61 +#define cell_symbol_sc_expand 61 +// CONSTANT cell_symbol_macro_expand 62 +#define cell_symbol_macro_expand 62 +// CONSTANT cell_symbol_portable_macro_expand 63 +#define cell_symbol_portable_macro_expand 63 +// CONSTANT cell_symbol_sc_expander_alist 64 +#define cell_symbol_sc_expander_alist 64 + +// CONSTANT cell_symbol_call_with_values 65 +#define cell_symbol_call_with_values 65 +// CONSTANT cell_symbol_call_with_current_continuation 66 +#define cell_symbol_call_with_current_continuation 66 +// CONSTANT cell_symbol_boot_module 67 +#define cell_symbol_boot_module 67 +// CONSTANT cell_symbol_current_module 68 +#define cell_symbol_current_module 68 +// CONSTANT cell_symbol_primitive_load 69 +#define cell_symbol_primitive_load 69 +// CONSTANT cell_symbol_read_input_file 70 +#define cell_symbol_read_input_file 70 +// CONSTANT cell_symbol_write 71 +#define cell_symbol_write 71 +// CONSTANT cell_symbol_display 72 +#define cell_symbol_display 72 + +// CONSTANT cell_symbol_car 73 +#define cell_symbol_car 73 +// CONSTANT cell_symbol_cdr 74 +#define cell_symbol_cdr 74 +// CONSTANT cell_symbol_not_a_number 75 +#define cell_symbol_not_a_number 75 +// CONSTANT cell_symbol_not_a_pair 76 +#define cell_symbol_not_a_pair 76 +// CONSTANT cell_symbol_system_error 77 +#define cell_symbol_system_error 77 +// CONSTANT cell_symbol_throw 78 +#define cell_symbol_throw 78 +// CONSTANT cell_symbol_unbound_variable 79 +#define cell_symbol_unbound_variable 79 +// CONSTANT cell_symbol_wrong_number_of_args 80 +#define cell_symbol_wrong_number_of_args 80 +// CONSTANT cell_symbol_wrong_type_arg 81 +#define cell_symbol_wrong_type_arg 81 + +// CONSTANT cell_symbol_buckets 82 +#define cell_symbol_buckets 82 +// CONSTANT cell_symbol_builtin 83 +#define cell_symbol_builtin 83 +// CONSTANT cell_symbol_frame 84 +#define cell_symbol_frame 84 +// CONSTANT cell_symbol_hashq_table 85 +#define cell_symbol_hashq_table 85 +// CONSTANT cell_symbol_module 86 +#define cell_symbol_module 86 +// CONSTANT cell_symbol_procedure 87 +#define cell_symbol_procedure 87 +// CONSTANT cell_symbol_record_type 88 +#define cell_symbol_record_type 88 +// CONSTANT cell_symbol_size 89 +#define cell_symbol_size 89 +// CONSTANT cell_symbol_stack 90 +#define cell_symbol_stack 90 + +// CONSTANT cell_symbol_argv 91 +#define cell_symbol_argv 91 +// CONSTANT cell_symbol_mes_datadir 92 +#define cell_symbol_mes_datadir 92 +// CONSTANT cell_symbol_mes_version 93 +#define cell_symbol_mes_version 93 + +// CONSTANT cell_symbol_internal_time_units_per_second 94 +#define cell_symbol_internal_time_units_per_second 94 +// CONSTANT cell_symbol_compiler 95 +#define cell_symbol_compiler 95 +// CONSTANT cell_symbol_arch 96 +#define cell_symbol_arch 96 +// CONSTANT cell_symbol_pmatch_car 97 +#define cell_symbol_pmatch_car 97 +// CONSTANT cell_symbol_pmatch_cdr 98 +#define cell_symbol_pmatch_cdr 98 + +// CONSTANT cell_type_bytes 99 +#define cell_type_bytes 99 +// CONSTANT cell_type_char 100 +#define cell_type_char 100 +// CONSTANT cell_type_closure 101 +#define cell_type_closure 101 +// CONSTANT cell_type_continuation 102 +#define cell_type_continuation 102 +// CONSTANT cell_type_function 103 +#define cell_type_function 103 +// CONSTANT cell_type_keyword 104 +#define cell_type_keyword 104 +// CONSTANT cell_type_macro 105 +#define cell_type_macro 105 +// CONSTANT cell_type_number 106 +#define cell_type_number 106 +// CONSTANT cell_type_pair 107 +#define cell_type_pair 107 +// CONSTANT cell_type_port 108 +#define cell_type_port 108 +// CONSTANT cell_type_ref 109 +#define cell_type_ref 109 +// CONSTANT cell_type_special 110 +#define cell_type_special 110 +// CONSTANT cell_type_string 111 +#define cell_type_string 111 +// CONSTANT cell_type_struct 112 +#define cell_type_struct 112 +// CONSTANT cell_type_symbol 113 +#define cell_type_symbol 113 +// CONSTANT cell_type_values 114 +#define cell_type_values 114 +// CONSTANT cell_type_variable 115 +#define cell_type_variable 115 +// CONSTANT cell_type_vector 116 +#define cell_type_vector 116 +// CONSTANT cell_type_broken_heart 117 +#define cell_type_broken_heart 117 + +// CONSTANT cell_test 118 +#define cell_test 118 + +/* Cell types */ + +// CONSTANT TBYTES 0 +#define TBYTES 0 +// CONSTANT TCHAR 1 +#define TCHAR 1 +// CONSTANT TCLOSURE 2 +#define TCLOSURE 2 +// CONSTANT TCONTINUATION 3 +#define TCONTINUATION 3 +// CONSTANT TKEYWORD 4 +#define TKEYWORD 4 +// CONSTANT TMACRO 5 +#define TMACRO 5 +// CONSTANT TNUMBER 6 +#define TNUMBER 6 +// CONSTANT TPAIR 7 +#define TPAIR 7 +// CONSTANT TPORT 8 +#define TPORT 8 +// CONSTANT TREF 9 +#define TREF 9 +// CONSTANT TSPECIAL 10 +#define TSPECIAL 10 +// CONSTANT TSTRING 11 +#define TSTRING 11 +// CONSTANT TSTRUCT 12 +#define TSTRUCT 12 +// CONSTANT TSYMBOL 13 +#define TSYMBOL 13 +// CONSTANT TVALUES 14 +#define TVALUES 14 +// CONSTANT TVARIABLE 15 +#define TVARIABLE 15 +// CONSTANT TVECTOR 16 +#define TVECTOR 16 +// CONSTANT TBROKEN_HEART 17 +#define TBROKEN_HEART 17 + +/* Struct types */ + +// CONSTANT STRUCT_TYPE 0 +#define STRUCT_TYPE 0 +// CONSTANT STRUCT_PRINTER 1 +#define STRUCT_PRINTER 1 + +#define FRAME_SIZE 5 +#define FRAME_PROCEDURE 4 + +#endif //__MES_CONSTANTS_H diff --git a/include/mes/lib-mini.h b/include/mes/lib-mini.h index f04f64e4..4cc8d96d 100644 --- a/include/mes/lib-mini.h +++ b/include/mes/lib-mini.h @@ -21,7 +21,40 @@ #ifndef __MES_LIB_MINI_H #define __MES_LIB_MINI_H -#if !SYSTEM_LIBC +#if HAVE_CONFIG_H +#include +#endif + +// CONSTANT STDIN 0 +#ifndef STDIN +#define STDIN 0 +#endif + +// CONSTANT STDOUT 1 +#ifndef STDOUT +#define STDOUT 1 +#endif + +// CONSTANT STDERR 2 +#ifndef STDERR +#define STDERR 2 +#endif + +char **environ; +int __stdin; +int __stdout; +int __stderr; + +int eputs (char const *s); +int puts (char const *s); +int oputs (char const *s); + +#if SYSTEM_LIBC + +#include +#include + +#else //!SYSTEM_LIBC #ifndef _SIZE_T #define _SIZE_T @@ -57,33 +90,6 @@ typedef int error_t; int errno; #endif // !__MES_ERRNO_T -#endif //!WITH_LIBC - -// CONSTANT STDIN 0 -#ifndef STDIN -#define STDIN 0 -#endif - -// CONSTANT STDOUT 1 -#ifndef STDOUT -#define STDOUT 1 -#endif - -// CONSTANT STDERR 2 -#ifndef STDERR -#define STDERR 2 -#endif - -char **environ; -int __stdin; -int __stdout; -int __stderr; - -int eputs (char const *s); -int puts (char const *s); -int oputs (char const *s); - -#if !SYSTEM_LIBC size_t strlen (char const *s); ssize_t _write (); ssize_t write (int filedes, void const *buffer, size_t size); diff --git a/include/mes/lib.h b/include/mes/lib.h index 3e74c2dd..dc4c0d2d 100644 --- a/include/mes/lib.h +++ b/include/mes/lib.h @@ -35,16 +35,12 @@ char *ltoab (long x, int base); char *ntoab (long number, int base, int signed_p); char *ultoa (unsigned long number); char *utoa (unsigned number); -int atoi (char const *s); int eputc (int c); int fdgetc (int fd); +char * fdgets (char *s, int count, int fd); int fdputc (int c, int fd); int fdputs (char const *s, int fd); int fdungetc (int c, int fd); -int _fdungetc_p (int fd); -int isdigit (int c); -int isspace (int c); -int isxdigit (int c); int mes_open (char const *file_name, int flags, int mask); int _open2 (char const *file_name, int flags); int _open3 (char const *file_name, int flags, int mask); @@ -52,4 +48,14 @@ int oputc (int c); int oputs (char const *s); char *search_path (char const *file_name); +#if !SYSTEM_LIBC + +extern char *__brk; +extern void (*__call_at_exit) (void); +void __assert_fail (char *s); +void _exit (int code); +long brk (void *addr); + +#endif // !SYSTEM_LIBC + #endif //__MES_LIB_H diff --git a/include/mes/macros.h b/include/mes/macros.h new file mode 100644 index 00000000..86dd0970 --- /dev/null +++ b/include/mes/macros.h @@ -0,0 +1,80 @@ +/* -*-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 . + */ + +#ifndef __MES_MACROS_H +#define __MES_MACROS_H + +#define TYPE(x) g_cells[x].type +#define CAR(x) g_cells[x].car +#define CDR(x) g_cells[x].cdr + +#define NTYPE(x) g_news[x].type +#define NCAR(x) g_news[x].car +#define NCDR(x) g_news[x].cdr + +#define BYTES(x) g_cells[x].car +#define LENGTH(x) g_cells[x].car +#define REF(x) g_cells[x].car +#define START(x) (g_cells[x].car >> 16) +#define LEN(x) (g_cells[x].car & 0xffff) +#define VARIABLE(x) g_cells[x].car + +#define CLOSURE(x) g_cells[x].cdr +#define CONTINUATION(x) g_cells[x].cdr + +#define CBYTES(x) (char*)&g_cells[x].cdr +#define CSTRING_STRUCT(x) (char*)&g_cells[x.cdr].cdr + +#define MACRO(x) g_cells[x].car +#define NAME(x) g_cells[x].cdr +#define PORT(x) g_cells[x].car +#define STRING(x) g_cells[x].cdr +#define STRUCT(x) g_cells[x].cdr +#define VALUE(x) g_cells[x].cdr +#define VECTOR(x) g_cells[x].cdr + +#define NLENGTH(x) g_news[x].car +#define NCBYTES(x) (char*)&g_news[x].cdr +#define NVALUE(x) g_news[x].cdr +#define NSTRING(x) g_news[x].cdr +#define NVECTOR(x) g_news[x].cdr + +#define CSTRING(x) CBYTES (STRING (x)) + +#define MAKE_BYTES0(x) make_bytes (x, strlen (x)) +#define NAME_SYMBOL(symbol,name) {size_t s = strlen (name); CAR (symbol) = s; CDR (symbol) = make_bytes (name, s);} + +#define MAKE_CHAR(n) make_cell__ (TCHAR, 0, n) +#define MAKE_CONTINUATION(n) make_cell__ (TCONTINUATION, n, g_stack) +#define MAKE_NUMBER(n) make_cell__ (TNUMBER, 0, (long)n) +#define MAKE_REF(n) make_cell__ (TREF, n, 0) +#define MAKE_STRING0(x) make_string (x, strlen (x)) +#define MAKE_STRING_PORT(x) make_cell__ (TPORT, -length__ (g_ports) - 2, x) +#define MAKE_MACRO(name, x) make_cell__ (TMACRO, x, STRING (name)) + +#define CAAR(x) CAR (CAR (x)) +#define CADR(x) CAR (CDR (x)) +#define CDAR(x) CDR (CAR (x)) +#define CDDR(x) CDR (CDR (x)) +#define CADAR(x) CAR (CDR (CAR (x))) +#define CADDR(x) CAR (CDR (CDR (x))) +#define CDADAR(x) CAR (CDR (CAR (CDR (x)))) + +#endif //__MES_MACROS_H diff --git a/include/mes/mes.h b/include/mes/mes.h new file mode 100644 index 00000000..a9b6ba93 --- /dev/null +++ b/include/mes/mes.h @@ -0,0 +1,106 @@ +/* -*-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 . + */ + +#ifndef __MES_MES_H +#define __MES_MES_H + +#include + +typedef long SCM; + +struct scm +{ + long type; + SCM car; + SCM cdr; +}; + +// mes +extern int g_debug; +extern char *g_buf; +extern SCM g_continuations; +extern SCM g_symbols; +extern SCM g_symbol_max; + +// a/env +extern SCM r0; +// param 1 +extern SCM r1; +// save 2 +extern SCM r2; +// continuation +extern SCM r3; +// current-module +extern SCM m0; +// macro +extern SCM g_macros; +extern SCM g_ports; + +// gc +extern long ARENA_SIZE; +extern long MAX_ARENA_SIZE; +extern long STACK_SIZE; +extern long JAM_SIZE; +extern long GC_SAFETY; +extern long MAX_STRING; +extern char *g_arena; +extern long g_free; +extern SCM g_stack; +extern SCM *g_stack_array; +extern struct scm *g_cells; +extern struct scm *g_news; + +SCM alloc (long n); +SCM apply (SCM f, SCM x, SCM a); +SCM apply_builtin (SCM fn, SCM x); +SCM cstring_to_list (char const *s); +SCM cstring_to_symbol (char const *s); +SCM display_ (SCM x); +SCM fdisplay_ (SCM, int, int); +SCM gc_init (); +SCM gc_peek_frame (); +SCM gc_pop_frame (); +SCM gc_push_frame (); +SCM init_time (SCM a); +SCM make_bytes (char const *s, size_t length); +SCM make_cell__ (long type, SCM car, SCM cdr); +SCM make_hash_table_ (long size); +SCM make_hashq_type (); +SCM make_initial_module (SCM a); +SCM make_string (char const *s, size_t length); +SCM make_vector__ (long k); +SCM read_input_file_env (SCM); +SCM string_equal_p (SCM a, SCM b); +SCM struct_ref_ (SCM x, long i); +SCM struct_set_x_ (SCM x, long i, SCM e); +SCM vector_ref_ (SCM x, long i); +SCM vector_set_x_ (SCM x, long i, SCM e); +int peekchar (); +int readchar (); +int unreadchar (); +long length__ (SCM x); +size_t bytes_cells (size_t length); +void assert_max_string (size_t i, char const *msg, char *string); + +#include "mes/builtins.h" +#include "mes/constants.h" +#include "mes/macros.h" + +#endif //__MES_MES_H diff --git a/include/pwd.h b/include/pwd.h index 90bef063..992c45f9 100644 --- a/include/pwd.h +++ b/include/pwd.h @@ -25,6 +25,8 @@ #include_next #else // ! SYSTEM_LIBC +#include + struct passwd { char *pw_name; diff --git a/include/stdarg.h b/include/stdarg.h index 239d4443..34061d06 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -37,6 +37,7 @@ typedef char *va_list; #define va_end(ap) (void)((ap) = 0) #define va_copy(dest, src) dest = src +int vexec (char const *file_name, va_list ap); int vfprintf (FILE * stream, char const *template, va_list ap); int vprintf (char const *format, va_list ap); int vsprintf (char *str, char const *format, va_list ap); diff --git a/include/string.h b/include/string.h index da981444..e8748dd6 100644 --- a/include/string.h +++ b/include/string.h @@ -51,7 +51,7 @@ void *memmove (void *dest, void const *src, size_t n); void *memset (void *s, int c, size_t n); void *memchr (void const *block, int c, size_t size); int memcmp (void const *s1, void const *s2, size_t n); - +void *memmem (void const *haystack, int haystack_len, void const *needle, int needle_len); char *strcat (char *dest, char const *src); char *strchr (char const *s, int c); int strcasecmp (char const *s1, char const *s2); diff --git a/include/sys/stat.h b/include/sys/stat.h index 230d6d89..d078435b 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -83,6 +83,7 @@ struct stat // *INDENT-ON* int chmod (char const *file_name, mode_t mode); +int fstat (int filedes, struct stat *buf); int mkdir (char const *file_name, mode_t mode); int chown (char const *file_name, uid_t owner, gid_t group); int rmdir (char const *file_name); diff --git a/include/time.h b/include/time.h index e28dcbba..ca3d9ff8 100644 --- a/include/time.h +++ b/include/time.h @@ -59,7 +59,6 @@ struct timespec int clock_gettime (clockid_t clk_id, struct timespec *tp); struct tm *localtime (time_t const *timep); struct tm *gmtime (time_t const *time); - time_t time (time_t * tloc); #endif // ! SYSTEM_LIBC diff --git a/include/unistd.h b/include/unistd.h index b2b18c1c..44792f90 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -65,6 +65,7 @@ int execl (char const *file_name, char const *arg, ...); int execve (char const *file, char *const argv[], char *const env[]); int execvp (char const *file, char *const argv[]); int fork (void); +int fsync (int filedes); char *getcwd (char *buf, size_t size); uid_t getuid (void); gid_t getgid (void); @@ -72,6 +73,8 @@ int setgid (gid_t newgid); int setuid (uid_t newuid); uid_t geteuid (void); gid_t getegid (void); +pid_t getpid (void); +pid_t getppid (void); int isatty (int fd); int link (char const *oldname, char const *newname); off_t lseek (int fd, off_t offset, int whence); diff --git a/lib/assert/assert.c b/lib/assert/assert.c deleted file mode 100644 index 428410ba..00000000 --- a/lib/assert/assert.c +++ /dev/null @@ -1,10 +0,0 @@ -void -assert_fail (char *s) -{ - eputs ("assert fail: "); - eputs (s); - eputs ("\n"); - char *fail = s; - fail = 0; - *fail = 0; -} diff --git a/lib/ctype/isxdigit.c b/lib/ctype/isxdigit.c index 54b28571..13f7a66d 100644 --- a/lib/ctype/isxdigit.c +++ b/lib/ctype/isxdigit.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,7 @@ */ #include +#include int isxdigit (int c) diff --git a/lib/dirent/__getdirentries.c b/lib/dirent/__getdirentries.c index 46adb74d..0c5d9250 100644 --- a/lib/dirent/__getdirentries.c +++ b/lib/dirent/__getdirentries.c @@ -1,7 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright (C) 1993 Free Software Foundation, Inc. - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -31,5 +31,5 @@ __getdirentries (int filedes, char *buffer, size_t nbytes, off_t * basep) if (basep) *basep = lseek (filedes, (off_t) 0, SEEK_CUR); - return read (filedes, buf, nbytes); + return read (filedes, buffer, nbytes); } diff --git a/lib/dirent/readdir.c b/lib/dirent/readdir.c index 3f38d044..2e340e22 100644 --- a/lib/dirent/readdir.c +++ b/lib/dirent/readdir.c @@ -32,6 +32,8 @@ #include +int getdents (int filedes, char *buffer, size_t nbytes); + /* Read a directory entry from DIRP. */ struct dirent * readdir (DIR * dirp) diff --git a/lib/libc+gnu.c b/lib/libc+gnu.c deleted file mode 100644 index 9f533e17..00000000 --- a/lib/libc+gnu.c +++ /dev/null @@ -1,121 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 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 - -#if __GNU__ -#error TODO, see wip-hurd -#elif __linux__ -#include -#else -#error both __GNU__ and _linux__ are undefined, choose one -#endif - -// m4 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// binutils -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// gcc - -#include -#include -#include -#include -#include -#include -#include - -#if !__GNU__ -#include -#endif - -#include -#include - -#include -#include -#include -#include - -// diffutils -#include - -// make -#include -#include -#include -#include -#include - -// bash -#include -#include -#include -#include diff --git a/lib/libc+tcc.c b/lib/libc+tcc.c deleted file mode 100644 index a788dc91..00000000 --- a/lib/libc+tcc.c +++ /dev/null @@ -1,108 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -int errno; - -#if __GNU__ -#include -#elif __linux__ -#include -#else -#error both __GNU__ and _linux__ are undefined, choose one -#endif - -#if __MESC__ && __i386__ -#include -#elif __MESC__ && __x86_64__ -#include -#elif __i386__ -#include -#elif __x86_64__ -#include -#else -#error arch not supported -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/lib/libc.c b/lib/libc.c deleted file mode 100644 index 27abb994..00000000 --- a/lib/libc.c +++ /dev/null @@ -1,89 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 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 -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#if __GNU__ -#include -#elif __linux__ -#include -#else -#error both __GNU__ and _linux__ are undefined, choose one -#endif - -void _env (); - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) - -int -__mes_debug () -{ - static int __mes_debug = -1; - if (__mes_debug == -1) - { - char *p = getenv ("MES_DEBUG"); - __mes_debug = p ? MAX (atoi (p), 1) : 0; - } - return __mes_debug; -} - - -#if !___GNU__ -#include -#include -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include diff --git a/lib/libg.c b/lib/libg.c deleted file mode 100644 index 166b8a5f..00000000 --- a/lib/libg.c +++ /dev/null @@ -1,147 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 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 . - */ - -// gcc/xgcc wants -lg with all these -// what's the story here? - -#include - -#define exit __exit -#define fprintf _fprintf -#define longjmp _longjmp -#define malloc _malloc -#define printf _printf -#define putchar _putchar -#define puts _puts -#define setjmp _setjmp -#define signal _signal -#define strcmp _strcmp -#define sprintf _sprintf -#define sscanf _sscanf - -#include - -#if __GNU__ -#include -#elif __linux__ -#include -#else -#error both __GNU__ and _linux__ are undefined, choose one -#endif - -// m4 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// binutils -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// gcc - -#include -#include -#include -#include -#include -#include -#include - -#if !__GNU__ -#include -#endif - -//#include -#include - -int -__libc_subinit () -{ - static int stub = 0; - if (__mes_debug () && !stub) - eputs ("__libc_subinit stub\n"); - stub = 1; - return 0; -} - -int -__syscall_error () -{ - static int stub = 0; - if (__mes_debug () && !stub) - eputs ("__syscall_error stub\n"); - stub = 1; - return 0; -} - -int -__fpu_control () -{ - static int stub = 0; - if (__mes_debug () && !stub) - eputs ("__fpu_control stub\n"); - stub = 1; - return 0; -} diff --git a/lib/linux/access.c b/lib/linux/access.c index e064f460..596697c7 100644 --- a/lib/linux/access.c +++ b/lib/linux/access.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int access (char const *file_name, int how) { diff --git a/lib/linux/brk.c b/lib/linux/brk.c index 2d880218..9566f19c 100644 --- a/lib/linux/brk.c +++ b/lib/linux/brk.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + long brk (void *addr) { diff --git a/lib/linux/chdir.c b/lib/linux/chdir.c index 12f2e2e4..ada7feec 100644 --- a/lib/linux/chdir.c +++ b/lib/linux/chdir.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int chdir (char const *file_name) { diff --git a/lib/linux/chmod.c b/lib/linux/chmod.c index 6a7e76a5..235b3456 100644 --- a/lib/linux/chmod.c +++ b/lib/linux/chmod.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int chmod (char const *file_name, mode_t mask) { diff --git a/lib/linux/clock_gettime.c b/lib/linux/clock_gettime.c index ee6a385e..2b090650 100644 --- a/lib/linux/clock_gettime.c +++ b/lib/linux/clock_gettime.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include +#include #include int diff --git a/lib/linux/close.c b/lib/linux/close.c index 591031b7..91a049c4 100644 --- a/lib/linux/close.c +++ b/lib/linux/close.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,10 +18,14 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int close (int filedes) { if (filedes > 2) - __ungetc_buf[filedes] = -1; + __ungetc_clear (filedes); return _sys_call1 (SYS_close, (int) filedes); } diff --git a/lib/linux/dup.c b/lib/linux/dup.c index 5a5bd5d0..02d01283 100644 --- a/lib/linux/dup.c +++ b/lib/linux/dup.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int dup (int old) { diff --git a/lib/linux/dup2.c b/lib/linux/dup2.c index c93fdbd2..f61344f5 100644 --- a/lib/linux/dup2.c +++ b/lib/linux/dup2.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int dup2 (int old, int new) { diff --git a/lib/linux/execve.c b/lib/linux/execve.c index 477ada92..51c8b4ff 100644 --- a/lib/linux/execve.c +++ b/lib/linux/execve.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int execve (char const *file_name, char *const argv[], char *const env[]) { diff --git a/lib/linux/fcntl.c b/lib/linux/fcntl.c index c923a3dc..e10e7348 100644 --- a/lib/linux/fcntl.c +++ b/lib/linux/fcntl.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int fcntl (int filedes, int command, ...) { diff --git a/lib/linux/fork.c b/lib/linux/fork.c index d87560a5..1f5c25fc 100644 --- a/lib/linux/fork.c +++ b/lib/linux/fork.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int fork () { diff --git a/lib/linux/fstat.c b/lib/linux/fstat.c index ca31e184..19d3f6a9 100644 --- a/lib/linux/fstat.c +++ b/lib/linux/fstat.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int fstat (int filedes, struct stat *statbuf) { diff --git a/lib/linux/fsync.c b/lib/linux/fsync.c index 7a584de1..0eef6db4 100644 --- a/lib/linux/fsync.c +++ b/lib/linux/fsync.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int fsync (int filedes) { diff --git a/lib/linux/getcwd.c b/lib/linux/getcwd.c index 847a6dcf..fbb67282 100644 --- a/lib/linux/getcwd.c +++ b/lib/linux/getcwd.c @@ -18,6 +18,11 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include +#include + char * _getcwd (char *buffer, size_t size) { diff --git a/lib/linux/getdents.c b/lib/linux/getdents.c index 16a5567c..5ebafa45 100644 --- a/lib/linux/getdents.c +++ b/lib/linux/getdents.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int getdents (int filedes, char *buffer, size_t nbytes) { diff --git a/lib/linux/getegid.c b/lib/linux/getegid.c index a813c0a0..5ad2f2c6 100644 --- a/lib/linux/getegid.c +++ b/lib/linux/getegid.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + gid_t getegid () { diff --git a/lib/linux/geteuid.c b/lib/linux/geteuid.c index e4d198be..4fcf9fd1 100644 --- a/lib/linux/geteuid.c +++ b/lib/linux/geteuid.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + uid_t geteuid () { diff --git a/lib/linux/getgid.c b/lib/linux/getgid.c index c8b61838..4402b528 100644 --- a/lib/linux/getgid.c +++ b/lib/linux/getgid.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + gid_t getgid () { diff --git a/lib/linux/getpid.c b/lib/linux/getpid.c index 3b30a4ee..9cab47ae 100644 --- a/lib/linux/getpid.c +++ b/lib/linux/getpid.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + pid_t getpid () { diff --git a/lib/linux/getppid.c b/lib/linux/getppid.c index 82b0febe..7eea4539 100644 --- a/lib/linux/getppid.c +++ b/lib/linux/getppid.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + pid_t getppid () { diff --git a/lib/linux/getrusage.c b/lib/linux/getrusage.c index b9e84611..2a789949 100644 --- a/lib/linux/getrusage.c +++ b/lib/linux/getrusage.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int getrusage (int processes, struct rusage *rusage) { diff --git a/lib/linux/gettimeofday.c b/lib/linux/gettimeofday.c index 6cef5653..fbdc35c3 100644 --- a/lib/linux/gettimeofday.c +++ b/lib/linux/gettimeofday.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include +#include #include int diff --git a/lib/linux/getuid.c b/lib/linux/getuid.c index 5bbe5ed7..e6edd257 100644 --- a/lib/linux/getuid.c +++ b/lib/linux/getuid.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + uid_t getuid () { diff --git a/lib/linux/gnu.c b/lib/linux/gnu.c deleted file mode 100644 index 9cd01695..00000000 --- a/lib/linux/gnu.c +++ /dev/null @@ -1,43 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/lib/linux/ioctl.c b/lib/linux/ioctl.c index 8b4f9fae..5e45c8c7 100644 --- a/lib/linux/ioctl.c +++ b/lib/linux/ioctl.c @@ -18,6 +18,11 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include +#include + int ioctl (int filedes, unsigned long command, ...) { diff --git a/lib/linux/kill.c b/lib/linux/kill.c index 174886ba..4298a9db 100644 --- a/lib/linux/kill.c +++ b/lib/linux/kill.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int kill (pid_t pid, int signum) { diff --git a/lib/linux/libc.c b/lib/linux/libc.c deleted file mode 100644 index 8f7c6ee5..00000000 --- a/lib/linux/libc.c +++ /dev/null @@ -1,60 +0,0 @@ -/* -*-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 - -#include -#include -#include -#include -#include -#include -#include -#include - -#if __MESC__ && __i386__ -#include -#elif __MESC__ && __x86_64__ -#include -#elif __i386__ -#include -#elif __x86_64__ -#include -#else -#error arch not supported -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/lib/linux/link.c b/lib/linux/link.c index 2b13af0e..cf8dec32 100644 --- a/lib/linux/link.c +++ b/lib/linux/link.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int link (char const *old_name, char const *new_name) { diff --git a/lib/linux/lseek.c b/lib/linux/lseek.c index ca673133..9d21659b 100644 --- a/lib/linux/lseek.c +++ b/lib/linux/lseek.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + off_t lseek (int filedes, off_t offset, int whence) { diff --git a/lib/linux/lstat.c b/lib/linux/lstat.c index c091181b..039de0e1 100644 --- a/lib/linux/lstat.c +++ b/lib/linux/lstat.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int lstat (char const *file_name, struct stat *statbuf) { diff --git a/lib/linux/mkdir.c b/lib/linux/mkdir.c index cadb60c8..53188888 100644 --- a/lib/linux/mkdir.c +++ b/lib/linux/mkdir.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int mkdir (char const *file_name, mode_t mode) { diff --git a/lib/linux/nanosleep.c b/lib/linux/nanosleep.c index 0172b200..bc838a4f 100644 --- a/lib/linux/nanosleep.c +++ b/lib/linux/nanosleep.c @@ -18,8 +18,13 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include +#include + int -nanosleep (const struct timespec *requested_time, struct timespec *remaining) +nanosleep (struct timespec const *requested_time, struct timespec const *remaining) { return _sys_call2 (SYS_nanosleep, (long) requested_time, (long) remaining); } diff --git a/lib/linux/open.c b/lib/linux/open.c index 951e50ed..28c65739 100644 --- a/lib/linux/open.c +++ b/lib/linux/open.c @@ -18,13 +18,19 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include +#include +#include + int _open3 (char const *file_name, int flags, int mask) { int r = _sys_call3 (SYS_open, (long) file_name, (int) flags, (int) mask); __ungetc_init (); if (r > 2) - __ungetc_buf[r] = -1; + __ungetc_clear (r); return r; } diff --git a/lib/linux/pipe.c b/lib/linux/pipe.c index 4fbfd4ad..0ed4c23e 100644 --- a/lib/linux/pipe.c +++ b/lib/linux/pipe.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int pipe (int filedes[2]) { diff --git a/lib/linux/read.c b/lib/linux/read.c index 9f9ae4af..4db3877f 100644 --- a/lib/linux/read.c +++ b/lib/linux/read.c @@ -18,6 +18,11 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include +#include + ssize_t read (int filedes, void *buffer, size_t size) { diff --git a/lib/linux/rename.c b/lib/linux/rename.c index 6acc00a5..492c734d 100644 --- a/lib/linux/rename.c +++ b/lib/linux/rename.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int rename (char const *old_name, char const *new_name) { diff --git a/lib/linux/rmdir.c b/lib/linux/rmdir.c index e923b853..7c096832 100644 --- a/lib/linux/rmdir.c +++ b/lib/linux/rmdir.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int rmdir (char const *file_name) { diff --git a/lib/linux/setgid.c b/lib/linux/setgid.c index 468be9cc..5512c622 100644 --- a/lib/linux/setgid.c +++ b/lib/linux/setgid.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int setgid (gid_t newgid) { diff --git a/lib/linux/settimer.c b/lib/linux/settimer.c index 6ca2ac2c..a66240f1 100644 --- a/lib/linux/settimer.c +++ b/lib/linux/settimer.c @@ -18,6 +18,11 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include +#include + int setitimer (int which, struct itimerval const *new, struct itimerval *old) { diff --git a/lib/linux/setuid.c b/lib/linux/setuid.c index 7d317816..5157dcae 100644 --- a/lib/linux/setuid.c +++ b/lib/linux/setuid.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int setuid (uid_t newuid) { diff --git a/lib/linux/signal.c b/lib/linux/signal.c index 3e33ada8..a8fb0eaa 100644 --- a/lib/linux/signal.c +++ b/lib/linux/signal.c @@ -18,6 +18,11 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include +#include + #if __x86_64__ void _restorer (void) diff --git a/lib/linux/sigprogmask.c b/lib/linux/sigprogmask.c index 40d9ff41..c0326a28 100644 --- a/lib/linux/sigprogmask.c +++ b/lib/linux/sigprogmask.c @@ -18,6 +18,11 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include +#include + int sigprocmask (int how, sigset_t const *set, sigset_t * oldset) { diff --git a/lib/linux/stat.c b/lib/linux/stat.c index d34c73d8..d8f4465b 100644 --- a/lib/linux/stat.c +++ b/lib/linux/stat.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + int stat (char const *file_name, struct stat *statbuf) { diff --git a/lib/linux/time.c b/lib/linux/time.c index 1b4acc52..17af241f 100644 --- a/lib/linux/time.c +++ b/lib/linux/time.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include +#include #include time_t diff --git a/lib/linux/unlink.c b/lib/linux/unlink.c index 97e6ef90..3889a067 100644 --- a/lib/linux/unlink.c +++ b/lib/linux/unlink.c @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + int unlink (char const *file_name) { diff --git a/lib/linux/waitpid.c b/lib/linux/waitpid.c index 3d3aa0bb..49d9c188 100644 --- a/lib/linux/waitpid.c +++ b/lib/linux/waitpid.c @@ -18,6 +18,10 @@ * along with GNU Mes. If not, see . */ +#include +#include +#include + pid_t waitpid (pid_t pid, int *status_ptr, int options) { diff --git a/lib/linux/x86-mes-gcc/mini.c b/lib/linux/x86-mes-gcc/mini.c index b247f6e9..dac77fda 100644 --- a/lib/linux/x86-mes-gcc/mini.c +++ b/lib/linux/x86-mes-gcc/mini.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include "mes/lib-mini.h" + #define SYS_exit "0x01" #define SYS_write "0x04" diff --git a/lib/linux/x86-mes-gcc/mes.c b/lib/linux/x86-mes-gcc/syscall.c similarity index 100% rename from lib/linux/x86-mes-gcc/mes.c rename to lib/linux/x86-mes-gcc/syscall.c diff --git a/lib/linux/x86-mes/crt1.c b/lib/linux/x86-mes-mescc/crt1.c similarity index 100% rename from lib/linux/x86-mes/crt1.c rename to lib/linux/x86-mes-mescc/crt1.c diff --git a/lib/linux/x86-mes/mini.c b/lib/linux/x86-mes-mescc/mini.c similarity index 100% rename from lib/linux/x86-mes/mini.c rename to lib/linux/x86-mes-mescc/mini.c diff --git a/lib/linux/x86-mes/mes.c b/lib/linux/x86-mes-mescc/syscall.c similarity index 100% rename from lib/linux/x86-mes/mes.c rename to lib/linux/x86-mes-mescc/syscall.c diff --git a/lib/linux/x86_64-mes-gcc/mini.c b/lib/linux/x86_64-mes-gcc/mini.c index 1f70382b..8381ebc0 100644 --- a/lib/linux/x86_64-mes-gcc/mini.c +++ b/lib/linux/x86_64-mes-gcc/mini.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include "mes/lib-mini.h" + #define SYS_exit "0x3c" #define SYS_write "0x01" diff --git a/lib/linux/x86_64-mes-gcc/mes.c b/lib/linux/x86_64-mes-gcc/syscall.c similarity index 100% rename from lib/linux/x86_64-mes-gcc/mes.c rename to lib/linux/x86_64-mes-gcc/syscall.c diff --git a/lib/linux/x86_64-mes/crt1.c b/lib/linux/x86_64-mes-mescc/crt1.c similarity index 100% rename from lib/linux/x86_64-mes/crt1.c rename to lib/linux/x86_64-mes-mescc/crt1.c diff --git a/lib/linux/x86_64-mes/mini.c b/lib/linux/x86_64-mes-mescc/mini.c similarity index 97% rename from lib/linux/x86_64-mes/mini.c rename to lib/linux/x86_64-mes-mescc/mini.c index 15fcf244..e68c5a3a 100644 --- a/lib/linux/x86_64-mes/mini.c +++ b/lib/linux/x86_64-mes-mescc/mini.c @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include "mes/lib-mini.h" + void _exit (int status) { diff --git a/lib/linux/x86_64-mes/mes.c b/lib/linux/x86_64-mes-mescc/syscall.c similarity index 100% rename from lib/linux/x86_64-mes/mes.c rename to lib/linux/x86_64-mes-mescc/syscall.c diff --git a/lib/linux/tcc.c b/lib/mes/__assert_fail.c similarity index 84% rename from lib/linux/tcc.c rename to lib/mes/__assert_fail.c index b6f6d8d0..39ea594a 100644 --- a/lib/linux/tcc.c +++ b/lib/mes/__assert_fail.c @@ -18,9 +18,15 @@ * along with GNU Mes. If not, see . */ -#include +#include -#include -#include -#include -#include +void +__assert_fail (char *s) +{ + eputs ("assert fail: "); + eputs (s); + eputs ("\n"); + char *fail = s; + fail = 0; + *fail = 0; +} diff --git a/lib/libc-mini.c b/lib/mes/__mes_debug.c similarity index 67% rename from lib/libc-mini.c rename to lib/mes/__mes_debug.c index cbf543ca..3badb4d8 100644 --- a/lib/libc-mini.c +++ b/lib/mes/__mes_debug.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,17 +18,19 @@ * along with GNU Mes. If not, see . */ -#include -#include -#include -#include +#include "mes/lib.h" +#include -#if __GNU__ -#include -#elif __linux__ -#include -#else -#error both __GNU__ and _linux__ are undefined, choose one -#endif +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#include +int +__mes_debug () +{ + static int __mes_debug = -1; + if (__mes_debug == -1) + { + char *p = getenv ("MES_DEBUG"); + __mes_debug = p ? MAX (atoi (p), 1) : 0; + } + return __mes_debug; +} diff --git a/lib/mes/eputs.c b/lib/mes/eputs.c index 8aa75207..4ffcbc96 100644 --- a/lib/mes/eputs.c +++ b/lib/mes/eputs.c @@ -19,6 +19,7 @@ */ #include +#include int eputs (char const *s) diff --git a/lib/mes/fdgetc.c b/lib/mes/fdgetc.c index 74dfb27b..8dfa256c 100644 --- a/lib/mes/fdgetc.c +++ b/lib/mes/fdgetc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -20,15 +20,37 @@ #include #include +#include #include +#include -int __ungetc_buf[RLIMIT_NOFILE + 1] = { 0 }; +#define __UNGETC_MAX 1024 + +int __ungetc_buf[__UNGETC_MAX + 1] = { 0 }; + +int +__ungetc_p (int filedes) +{ + return __ungetc_buf[filedes] >= 0; +} void __ungetc_init () { - if (__ungetc_buf[RLIMIT_NOFILE] == 0) - memset (__ungetc_buf, -1, (RLIMIT_NOFILE + 1) * sizeof (int)); + if (__ungetc_buf[__UNGETC_MAX] == 0) + memset (__ungetc_buf, -1, (__UNGETC_MAX + 1) * sizeof (int)); +} + +void +__ungetc_clear (int filedes) +{ + __ungetc_buf[filedes] = -1; +} + +void +__ungetc_set (int filedes, int c) +{ + __ungetc_buf[filedes] = c; } int @@ -45,7 +67,7 @@ fdgetc (int fd) int r = read (fd, &c, 1); if (r < 1) return -1; - i = c; + i = (int) c; } if (i < 0) i += 256; diff --git a/lib/stdio/fdgets.c b/lib/mes/fdgets.c similarity index 91% rename from lib/stdio/fdgets.c rename to lib/mes/fdgets.c index b151a451..c9073528 100644 --- a/lib/stdio/fdgets.c +++ b/lib/mes/fdgets.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include char * diff --git a/lib/mes/fdputs.c b/lib/mes/fdputs.c index 73063dcb..7c6d4abd 100644 --- a/lib/mes/fdputs.c +++ b/lib/mes/fdputs.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,7 @@ */ #include +#include int fdputs (char const *s, int fd) diff --git a/lib/mes/fdungetc.c b/lib/mes/fdungetc.c index 05d28662..20ef9e87 100644 --- a/lib/mes/fdungetc.c +++ b/lib/mes/fdungetc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,7 @@ */ #include +#include int fdungetc (int c, int fd) @@ -26,19 +27,13 @@ fdungetc (int c, int fd) __ungetc_init (); if (c == -1) return c; - else if (__ungetc_buf[fd] != -1) + else if (__ungetc_p (fd)) { eputs (" ***MES C LIB*** fdungetc ungetc buffer overflow fd="); eputs (itoa (fd)); eputs ("\n"); - exit (1); + assert (0); } - __ungetc_buf[fd] = c; + __ungetc_set (fd, c); return c; } - -int -_fdungetc_p (int fd) -{ - return __ungetc_buf[fd] >= 0; -} diff --git a/lib/libmes.c b/lib/mes/mes_open.c similarity index 63% rename from lib/libmes.c rename to lib/mes/mes_open.c index 7b76da28..5ab184f5 100644 --- a/lib/libmes.c +++ b/lib/mes/mes_open.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -20,26 +20,6 @@ #include #include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #if SYSTEM_LIBC #include @@ -53,15 +33,12 @@ int mes_open (char const *file_name, int flags, int mask) { __ungetc_init (); - int r = open (file_name, flags, mask); - if (r > 2) - __ungetc_buf[r] = -1; - return r; + int filedes = open (file_name, flags, mask); + if (filedes > 2) + __ungetc_clear (filedes); + return filedes; } -#include -#include - #else // !SYSTEM_LIBC int @@ -71,6 +48,3 @@ mes_open (char const *file_name, int flags, int mask) } #endif // !SYSTEM_LIBC - -#include -#include diff --git a/lib/mes/oputs.c b/lib/mes/oputs.c index bcdf9d98..3d1e4382 100644 --- a/lib/mes/oputs.c +++ b/lib/mes/oputs.c @@ -19,6 +19,7 @@ */ #include +#include int oputs (char const *s) diff --git a/lib/mes/search-path.c b/lib/mes/search-path.c index 8398babb..afedf139 100644 --- a/lib/mes/search-path.c +++ b/lib/mes/search-path.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,9 @@ */ #include +#include +#include +#include char * search_path (char const *file_name) diff --git a/lib/posix/alarm.c b/lib/posix/alarm.c index 5261c2e7..c425203d 100644 --- a/lib/posix/alarm.c +++ b/lib/posix/alarm.c @@ -19,6 +19,7 @@ */ #include +#include unsigned int alarm (unsigned int seconds) diff --git a/lib/posix/execl.c b/lib/posix/execl.c index 59182549..bae7a066 100644 --- a/lib/posix/execl.c +++ b/lib/posix/execl.c @@ -19,6 +19,7 @@ */ #include +#include #include int @@ -36,12 +37,12 @@ execl (char const *file_name, char const *arg, ...) va_list ap; va_start (ap, arg); - argv[i++] = file_name; + argv[i++] = (char *)file_name; arg = va_arg (ap, char const *); while (arg) { argv[i++] = arg; - arg = va_arg (ap, char const *); + arg = va_arg (ap, char *); if (__mes_debug () > 2) { eputs ("arg["); diff --git a/lib/posix/execv.c b/lib/posix/execv.c index b5a29bf9..0dc8c628 100644 --- a/lib/posix/execv.c +++ b/lib/posix/execv.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include int diff --git a/lib/posix/execvp.c b/lib/posix/execvp.c index bc801375..8d906a5a 100644 --- a/lib/posix/execvp.c +++ b/lib/posix/execvp.c @@ -19,6 +19,7 @@ */ #include +#include #include int diff --git a/lib/posix/getenv.c b/lib/posix/getenv.c index 8b58d635..b8c58baa 100644 --- a/lib/posix/getenv.c +++ b/lib/posix/getenv.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include +#include #include char * diff --git a/lib/posix/isatty.c b/lib/posix/isatty.c index 41353146..85c84097 100644 --- a/lib/posix/isatty.c +++ b/lib/posix/isatty.c @@ -18,7 +18,11 @@ * along with GNU Mes. If not, see . */ -#include +#include +#include +#include +#include +#include typedef unsigned char cc_t; typedef unsigned int speed_t; diff --git a/lib/posix/mktemp.c b/lib/posix/mktemp.c index 8226b5f9..01799e4c 100644 --- a/lib/posix/mktemp.c +++ b/lib/posix/mktemp.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include char * diff --git a/lib/posix/raise.c b/lib/posix/raise.c index f05c210f..f6937191 100644 --- a/lib/posix/raise.c +++ b/lib/posix/raise.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include int diff --git a/lib/posix/sbrk.c b/lib/posix/sbrk.c index 723db5f1..fb17f715 100644 --- a/lib/posix/sbrk.c +++ b/lib/posix/sbrk.c @@ -18,7 +18,9 @@ * along with GNU Mes. If not, see . */ +#include #include +#include #if __SBRK_CHAR_PTRDIFF char * diff --git a/lib/posix/setenv.c b/lib/posix/setenv.c index c8de6087..1660f3fa 100644 --- a/lib/posix/setenv.c +++ b/lib/posix/setenv.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include +#include #include int diff --git a/lib/posix/sleep.c b/lib/posix/sleep.c index 4e3377a4..9fafdd8a 100644 --- a/lib/posix/sleep.c +++ b/lib/posix/sleep.c @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include +#include #include unsigned int diff --git a/lib/posix/unsetenv.c b/lib/posix/unsetenv.c index 70aed68a..726f6267 100644 --- a/lib/posix/unsetenv.c +++ b/lib/posix/unsetenv.c @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include +#include #include void diff --git a/lib/stdio/fclose.c b/lib/stdio/fclose.c index 04ffbfa8..b4505233 100644 --- a/lib/stdio/fclose.c +++ b/lib/stdio/fclose.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,10 +19,11 @@ */ #include +#include int fclose (FILE * stream) { - int fd = (int) stream; + int fd = (long) stream; return close (fd); } diff --git a/lib/stdio/fdopen.c b/lib/stdio/fdopen.c index 4be1adcd..5c5d5dd6 100644 --- a/lib/stdio/fdopen.c +++ b/lib/stdio/fdopen.c @@ -23,5 +23,5 @@ FILE * fdopen (int fd, char const *mode) { - return (FILE *) fd; + return (FILE *) (long) fd; } diff --git a/lib/stdio/ferror.c b/lib/stdio/ferror.c index 009f48b9..a7b6b7b4 100644 --- a/lib/stdio/ferror.c +++ b/lib/stdio/ferror.c @@ -23,7 +23,7 @@ int ferror (FILE * stream) { - int fd = (int) stream; + int fd = (long) stream; if (fd == -1) return -1; return 0; diff --git a/lib/stdio/fflush.c b/lib/stdio/fflush.c index 3951bf1f..89e29bc9 100644 --- a/lib/stdio/fflush.c +++ b/lib/stdio/fflush.c @@ -19,9 +19,11 @@ */ #include +#include +#include int fflush (FILE * stream) { - fsync ((int) stream); + fsync ((long) stream); } diff --git a/lib/stdio/fgets.c b/lib/stdio/fgets.c index 1635d5ab..8773ce44 100644 --- a/lib/stdio/fgets.c +++ b/lib/stdio/fgets.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,10 +18,11 @@ * along with GNU Mes. If not, see . */ +#include #include char * fgets (char *s, int count, FILE * stream) { - return fdgets (s, count, (int) stream); + return fdgets (s, count, (int) (long) stream); } diff --git a/lib/stdio/fileno.c b/lib/stdio/fileno.c index 971f0667..ca97d9f4 100644 --- a/lib/stdio/fileno.c +++ b/lib/stdio/fileno.c @@ -23,5 +23,5 @@ int fileno (FILE * stream) { - return (int) stream; + return (int) (long) stream; } diff --git a/lib/stdio/fopen.c b/lib/stdio/fopen.c index 68f23e58..be4c3f62 100644 --- a/lib/stdio/fopen.c +++ b/lib/stdio/fopen.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * Copyright © 2018 Jeremiah Orians * * This file is part of GNU Mes. @@ -20,13 +20,11 @@ */ #include +#include +#include #include - -//#if __GNUC__ && __x86_64__ -#if __x86_64__ -#undef open -#define open _open3 -#endif +#include +#include FILE * fopen (char const *file_name, char const *opentype) @@ -53,10 +51,10 @@ fopen (char const *file_name, char const *opentype) { char *plus_p = strchr (opentype, '+'); int flags = plus_p ? O_RDWR | O_CREAT : O_WRONLY | O_CREAT | O_TRUNC; - fd = open (file_name, flags, mode); + fd = _open3 (file_name, flags, mode); } else - fd = open (file_name, 0, 0); + fd = _open3 (file_name, 0, 0); if (__mes_debug ()) { @@ -68,11 +66,11 @@ fopen (char const *file_name, char const *opentype) if (!fd) { eputs (" ***MES LIB C*** fopen of stdin: signal me in band\n"); - exit (1); + assert (0); } if (fd < 0) fd = 0; - return (FILE *) fd; + return (FILE *) (long) fd; } #undef open diff --git a/lib/stdio/fread.c b/lib/stdio/fread.c index 9b6f2e80..77f3b864 100644 --- a/lib/stdio/fread.c +++ b/lib/stdio/fread.c @@ -20,11 +20,13 @@ #include #include +#include +#include int -_fungetc_p (FILE * stream) +__fungetc_p (FILE * stream) { - return _fdungetc_p ((int) stream); + return __ungetc_p ((int) (long) stream); } size_t @@ -37,11 +39,11 @@ fread (void *data, size_t size, size_t count, FILE * stream) char *buf = (char *) data; int bytes = 0; - while (_fungetc_p (stream) && todo-- && ++bytes) + while (__fungetc_p (stream) && todo-- && ++bytes) *buf++ = fgetc (stream); if (todo) { - int r = read ((int) stream, buf, todo); + int r = read ((int) (long) stream, buf, todo); if (r < 0 && !bytes) bytes = r; else @@ -51,7 +53,7 @@ fread (void *data, size_t size, size_t count, FILE * stream) if (__mes_debug ()) { eputs ("fread fd="); - eputs (itoa ((int) stream)); + eputs (itoa ((int) (long) stream)); eputs (" bytes="); eputs (itoa (bytes)); eputs ("\n"); diff --git a/lib/stdio/fseek.c b/lib/stdio/fseek.c index 62e5a4ff..268f9792 100644 --- a/lib/stdio/fseek.c +++ b/lib/stdio/fseek.c @@ -20,15 +20,16 @@ #include #include +#include int fseek (FILE * stream, long offset, int whence) { - off_t pos = lseek ((int) stream, offset, whence); + off_t pos = lseek ((int) (long) stream, offset, whence); if (__mes_debug ()) { eputs ("fread fd="); - eputs (itoa ((int) stream)); + eputs (itoa ((int) (long) stream)); eputs (" =>"); eputs (itoa (pos)); eputs ("\n"); diff --git a/lib/stdio/ftell.c b/lib/stdio/ftell.c index 8bdac53a..aa8ddd33 100644 --- a/lib/stdio/ftell.c +++ b/lib/stdio/ftell.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,10 +18,12 @@ * along with GNU Mes. If not, see . */ +#include #include +#include long ftell (FILE * stream) { - return lseek ((int) stream, 0, SEEK_CUR); + return lseek ((int) (long) stream, 0, SEEK_CUR); } diff --git a/lib/stdio/fwrite.c b/lib/stdio/fwrite.c index 74487758..995450e9 100644 --- a/lib/stdio/fwrite.c +++ b/lib/stdio/fwrite.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -27,7 +27,7 @@ fwrite (void const *data, size_t size, size_t count, FILE * stream) if (__mes_debug () > 1) { eputs ("fwrite "); - eputs (itoa ((int) stream)); + eputs (itoa ((int) (long) stream)); eputs (" "); eputs (itoa (size)); eputs ("\n"); @@ -35,7 +35,7 @@ fwrite (void const *data, size_t size, size_t count, FILE * stream) if (!size || !count) return 0; - int bytes = write ((int) stream, data, size * count); + int bytes = write ((int) (long) stream, data, size * count); if (__mes_debug () > 2) { diff --git a/lib/stdio/perror.c b/lib/stdio/perror.c index 8ac72364..21f0f1e4 100644 --- a/lib/stdio/perror.c +++ b/lib/stdio/perror.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,7 +18,9 @@ * along with GNU Mes. If not, see . */ +#include #include +#include void perror (char const *message) diff --git a/lib/stdio/remove.c b/lib/stdio/remove.c index f50b1d0a..ebc7c938 100644 --- a/lib/stdio/remove.c +++ b/lib/stdio/remove.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,8 @@ */ #include +#include +#include int remove (char const *file_name) diff --git a/lib/stdio/vsnprintf.c b/lib/stdio/vsnprintf.c index beec362a..1e3ba4f1 100644 --- a/lib/stdio/vsnprintf.c +++ b/lib/stdio/vsnprintf.c @@ -19,6 +19,7 @@ */ #include +#include #include #include diff --git a/lib/stdio/vsscanf.c b/lib/stdio/vsscanf.c index 10f874f2..4ea05f27 100644 --- a/lib/stdio/vsscanf.c +++ b/lib/stdio/vsscanf.c @@ -19,13 +19,16 @@ */ #include +#include #include #include +#include +#include int vsscanf (char const *s, char const *template, va_list ap) { - char const *p = s; + char *p = (char *) s; char const *t = template; int count = 0; while (*t && *p) @@ -59,7 +62,7 @@ vsscanf (char const *s, char const *template, va_list ap) case 'u': { int *d = va_arg (ap, int *); - *d = abtol (&p, 10); + *d = abtol ((char const **)&p, 10); count++; break; } diff --git a/lib/stdlib/alloca.c b/lib/stdlib/alloca.c index 5c8bf008..c04a632e 100644 --- a/lib/stdlib/alloca.c +++ b/lib/stdlib/alloca.c @@ -3,7 +3,7 @@ Taken from GNU binutils 2.10.1. Minor changes - Copyright © 2018 Jan (janneke) Nieuwenhuizen + Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen This implementation of the PWB library alloca function, which is used to allocate space off the run-time stack so @@ -24,6 +24,7 @@ allocating any. It is a good idea to use alloca(0) in your main control loop, etc. to force garbage collection. */ +#include #include #define ALIGN_SIZE 4 diff --git a/lib/stdlib/atexit.c b/lib/stdlib/atexit.c index df35321e..218ae854 100644 --- a/lib/stdlib/atexit.c +++ b/lib/stdlib/atexit.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include int diff --git a/lib/stdlib/malloc.c b/lib/stdlib/malloc.c index e16f0036..970f9fdb 100644 --- a/lib/stdlib/malloc.c +++ b/lib/stdlib/malloc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + char *__brk = 0; void * diff --git a/lib/stdlib/realloc.c b/lib/stdlib/realloc.c index e8bd20a6..f48df4fc 100644 --- a/lib/stdlib/realloc.c +++ b/lib/stdlib/realloc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,7 @@ */ #include +#include void * realloc (void *ptr, size_t size) diff --git a/lib/stdlib/strtol.c b/lib/stdlib/strtol.c index 0c592b2d..ff937d93 100644 --- a/lib/stdlib/strtol.c +++ b/lib/stdlib/strtol.c @@ -20,6 +20,7 @@ #include #include +#include long strtol (char const *string, char **tailptr, int base) @@ -31,9 +32,9 @@ strtol (char const *string, char **tailptr, int base) } if (tailptr) { - *tailptr = string; - return abtol (tailptr, base); + *tailptr = (char *) string; + return abtol ((char const **) tailptr, base); } - char **p = &string; - return abtol (p, base); + char **p = (char **) &string; + return abtol ((char const **) p, base); } diff --git a/lib/string/bzero.c b/lib/string/bzero.c index 69bdcca3..54329d67 100644 --- a/lib/string/bzero.c +++ b/lib/string/bzero.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,10 +18,11 @@ * along with GNU Mes. If not, see . */ +#include #include int bzero (void *block, size_t size) { - return memset (block, 0, size); + return (int) (long) memset (block, 0, size); } diff --git a/lib/string/index.c b/lib/string/index.c index 3841d94c..9904211b 100644 --- a/lib/string/index.c +++ b/lib/string/index.c @@ -23,5 +23,5 @@ int index (char const *s, int c) { - return strchr (s, c); + return (int) (long) strchr (s, c); } diff --git a/lib/string/memcpy.c b/lib/string/memcpy.c index 307f6433..289a4063 100644 --- a/lib/string/memcpy.c +++ b/lib/string/memcpy.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,9 @@ * along with GNU Mes. If not, see . */ +#include +#include + void * memcpy (void *dest, void const *src, size_t n) { diff --git a/lib/string/strchr.c b/lib/string/strchr.c index d6d0cbc8..da1a7073 100644 --- a/lib/string/strchr.c +++ b/lib/string/strchr.c @@ -27,7 +27,7 @@ strchr (char const *s, int c) while (*p || !c) { if (c == *p) - return p; + return (char *) p; p++; } return 0; diff --git a/lib/string/strdup.c b/lib/string/strdup.c index e87b8ee1..2510bacf 100644 --- a/lib/string/strdup.c +++ b/lib/string/strdup.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include char * diff --git a/lib/string/strerror.c b/lib/string/strerror.c index c0c31c65..ef176a42 100644 --- a/lib/string/strerror.c +++ b/lib/string/strerror.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include char *sys_errlist[] = { diff --git a/lib/string/strrchr.c b/lib/string/strrchr.c index 175ab2a2..08766fd0 100644 --- a/lib/string/strrchr.c +++ b/lib/string/strrchr.c @@ -28,12 +28,12 @@ strrchr (char const *s, int c) return 0; char const *p = s + n; if (!*p && !c) - return p; + return (char *) p; p--; while (n-- && (*p || !c)) { if (c == *p) - return p; + return (char *) p; p--; } return 0; diff --git a/lib/string/strspn.c b/lib/string/strspn.c index d668d29d..0c8a37cf 100644 --- a/lib/string/strspn.c +++ b/lib/string/strspn.c @@ -23,7 +23,7 @@ size_t strspn (char const *string, char const *skipset) { - char *p = string; + char *p = (char *) string; while (*p) if (!strchr (skipset, *p)) break; diff --git a/lib/string/strstr.c b/lib/string/strstr.c index fa783b4a..f9e5bd2b 100644 --- a/lib/string/strstr.c +++ b/lib/string/strstr.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,7 +18,9 @@ * along with GNU Mes. If not, see . */ +#include #include +#include char * strstr (char const *haystack, char const *needle) diff --git a/lib/stdlib/bsearch.c b/lib/stub/bsearch.c similarity index 98% rename from lib/stdlib/bsearch.c rename to lib/stub/bsearch.c index a6303021..58c7e1af 100644 --- a/lib/stdlib/bsearch.c +++ b/lib/stub/bsearch.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include void * diff --git a/lib/stub/strftime.c b/lib/stub/strftime.c index 34ecb5d7..bdefeef4 100644 --- a/lib/stub/strftime.c +++ b/lib/stub/strftime.c @@ -19,6 +19,7 @@ */ #include +#include size_t strftime (char *s, size_t size, char const *template, struct tm const *brokentime) @@ -27,5 +28,5 @@ strftime (char *s, size_t size, char const *template, struct tm const *brokentim if (__mes_debug () && !stub) eputs ("strftime stub\n"); stub = 1; - return template; + return 0; } diff --git a/lib/tests/scaffold/54-argv.c b/lib/tests/scaffold/54-argv.c index 2d892ac6..65da62de 100644 --- a/lib/tests/scaffold/54-argv.c +++ b/lib/tests/scaffold/54-argv.c @@ -27,11 +27,11 @@ int main (int argc, char *argv[]) { oputs ("\n"); - oputs ("t: argv[0] == \"test/scaffold....\"\n"); + oputs ("t: argv[0] == \"lib/test/scaffold....\"\n"); oputs ("argv0="); oputs (argv[0]); oputs ("\n"); - if (strncmp (argv[0], "test/scaffold", 5)) + if (strncmp (argv[0], "lib/test/scaffold", 5)) return 1; oputs ("t: *argv\"\n"); diff --git a/lib/tests/scaffold/60-math.c b/lib/tests/scaffold/60-math.c index 19d7edd2..76e55092 100644 --- a/lib/tests/scaffold/60-math.c +++ b/lib/tests/scaffold/60-math.c @@ -171,7 +171,7 @@ ok1: return 30; oputs ("t: 0b11 == 3\n"); - if (0 b11 != 3) + if (0b11 != 3) return 31; oputs ("t: 0x11 == 3\n"); diff --git a/lib/tests/scaffold/t.c b/lib/tests/scaffold/t.c index 7e9eafd3..42b4e802 100644 --- a/lib/tests/scaffold/t.c +++ b/lib/tests/scaffold/t.c @@ -139,7 +139,7 @@ main (int argc, char *argv[]) return 9; if (TCHAR != 0) return 11; - if (strncmp (argv[0], "test/scaffold", 5)) + if (strncmp (argv[0], "lib/test/scaffold", 5)) return 12; if (strcmp (env[0], "foo")) return 13; diff --git a/lib/tests/stdio/70-printf-hello.c b/lib/tests/stdio/70-printf-hello.c index cbe13bfe..a15547d8 100644 --- a/lib/tests/stdio/70-printf-hello.c +++ b/lib/tests/stdio/70-printf-hello.c @@ -27,9 +27,6 @@ int main () { -#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC - return 0; -#endif int i = 42; char *s = "mes"; char buf[20]; diff --git a/lib/tests/stdio/70-printf-simple.c b/lib/tests/stdio/70-printf-simple.c index f0542766..f72dc3fd 100644 --- a/lib/tests/stdio/70-printf-simple.c +++ b/lib/tests/stdio/70-printf-simple.c @@ -27,9 +27,6 @@ int main () { -#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC - return 0; -#endif char *s = "mes"; char c = 'm'; int i = 3; diff --git a/lib/tests/stdio/70-printf.c b/lib/tests/stdio/70-printf.c index aa6687cf..7b1702cf 100644 --- a/lib/tests/stdio/70-printf.c +++ b/lib/tests/stdio/70-printf.c @@ -27,9 +27,6 @@ int main () { -#if __GNUC__ && __x86_64__ - return 0; -#endif char *s = "mes"; char c = 'm'; int i = 3; diff --git a/lib/x86-mes-gcc/setjmp.c b/lib/x86-mes-gcc/setjmp.c index df65cf98..5a3ac86a 100644 --- a/lib/x86-mes-gcc/setjmp.c +++ b/lib/x86-mes-gcc/setjmp.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,7 @@ */ #include +#include void longjmp (jmp_buf env, int val) diff --git a/lib/x86-mes/exit-42.c b/lib/x86-mes-mescc/exit-42.c similarity index 100% rename from lib/x86-mes/exit-42.c rename to lib/x86-mes-mescc/exit-42.c diff --git a/lib/x86-mes/setjmp.c b/lib/x86-mes-mescc/setjmp.c similarity index 93% rename from lib/x86-mes/setjmp.c rename to lib/x86-mes-mescc/setjmp.c index 8decb6e3..db445789 100644 --- a/lib/x86-mes/setjmp.c +++ b/lib/x86-mes-mescc/setjmp.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,7 @@ */ #include +#include void longjmp (jmp_buf env, int val) diff --git a/lib/x86_64-mes-gcc/setjmp.c b/lib/x86_64-mes-gcc/setjmp.c index 85bb3894..b2741601 100644 --- a/lib/x86_64-mes-gcc/setjmp.c +++ b/lib/x86_64-mes-gcc/setjmp.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,7 @@ */ #include +#include void longjmp (jmp_buf env, int val) @@ -46,7 +47,7 @@ setjmp (jmp_buf env) : //no inputs "" ); // *INDENT-ON* - env[0].__bp = p; + env[0].__bp = (long) p; env[0].__pc = p[1]; env[0].__sp = p[0]; return 0; diff --git a/lib/x86_64-mes/exit-42.c b/lib/x86_64-mes-mescc/exit-42.c similarity index 100% rename from lib/x86_64-mes/exit-42.c rename to lib/x86_64-mes-mescc/exit-42.c diff --git a/lib/x86_64-mes/setjmp.c b/lib/x86_64-mes-mescc/setjmp.c similarity index 95% rename from lib/x86_64-mes/setjmp.c rename to lib/x86_64-mes-mescc/setjmp.c index ebf5c1ce..2947d190 100644 --- a/lib/x86_64-mes/setjmp.c +++ b/lib/x86_64-mes-mescc/setjmp.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,6 +19,7 @@ */ #include +#include void longjmp (jmp_buf env, int val) diff --git a/mes/include b/mes/include deleted file mode 120000 index f5030fe8..00000000 --- a/mes/include +++ /dev/null @@ -1 +0,0 @@ -../include \ No newline at end of file diff --git a/mes/lib b/mes/lib deleted file mode 120000 index dc598c56..00000000 --- a/mes/lib +++ /dev/null @@ -1 +0,0 @@ -../lib \ No newline at end of file diff --git a/mes/module/mes/boot-0.scm.in b/mes/module/mes/boot-0.scm similarity index 96% rename from mes/module/mes/boot-0.scm.in rename to mes/module/mes/boot-0.scm index c1736fba..fc1e1d11 100644 --- a/mes/module/mes/boot-0.scm.in +++ b/mes/module/mes/boot-0.scm @@ -136,10 +136,7 @@ (if (null? (cdr rest)) (car rest) (append2 (car rest) (apply append (cdr rest)))))) -(define %prefix (getenv "MES_PREFIX")) -(define %moduledir - (if (not %prefix) "mes/module/" - (string-append %prefix "/module/"))) +(define %moduledir (string-append %datadir "/module/")) (include (string-append %moduledir "mes/type-0.mes")) @@ -175,8 +172,6 @@ (define-macro (use-modules . rest) #t) ;; end boot-03.scm -(define %version (if (eq? (car (string->list "@VERSION@")) #\@) "git" - "@VERSION@")) (define (effective-version) %version) (mes-use-module (srfi srfi-1)) @@ -186,7 +181,7 @@ (mes-use-module (mes posix)) (define-macro (include-from-path file) - (let loop ((path (cons* %moduledir "@srcdir@/module" (string-split (or (getenv "GUILE_LOAD_PATH") "") #\:)))) + (let loop ((path (cons* %moduledir "module" (string-split (or (getenv "GUILE_LOAD_PATH") "") #\:)))) (cond ((and=> (getenv "MES_DEBUG") (compose (lambda (o) (> o 2)) string->number)) (core:display-error (string-append "include-from-path: " file " [PATH:" (string-join path ":") "]\n"))) ((and=> (getenv "MES_DEBUG") (compose (lambda (o) (> o 1)) string->number)) diff --git a/mes/module/mes/boot-03.scm b/mes/module/mes/boot-03.scm index 248b95b4..c4e8b61c 100644 --- a/mes/module/mes/boot-03.scm +++ b/mes/module/mes/boot-03.scm @@ -136,10 +136,7 @@ (if (null? (cdr rest)) (car rest) (append2 (car rest) (apply append (cdr rest)))))) -(define %prefix (getenv "MES_PREFIX")) -(define %moduledir - (if (not %prefix) "mes/module/" - (string-append %prefix "/module/"))) +(define %moduledir (string-append %datadir "/module/")) (include (string-append %moduledir "mes/type-0.mes")) diff --git a/module/mescc/mescc.scm b/module/mescc/mescc.scm index 33603c2e..333b05b0 100644 --- a/module/mescc/mescc.scm +++ b/module/mescc/mescc.scm @@ -140,7 +140,7 @@ '("c"))) (libraries (filter-map (multi-opt 'library) options)) (libraries (delete-duplicates (append libraries default-libraries))) - (hex2-libraries (map (cut find-library options ".o" <>) libraries)) + (hex2-libraries (map (cut find-library options ".a" <>) libraries)) (hex2-files (append hex2-files hex2-libraries)) (S-files (append S-files (map (cut find-library options ".S" <>) libraries))) (debug-info? (option-ref options 'debug-info #f)) diff --git a/scaffold/boot/51-module.scm b/scaffold/boot/51-module.scm index 7d3e30ae..6ff30949 100644 --- a/scaffold/boot/51-module.scm +++ b/scaffold/boot/51-module.scm @@ -44,8 +44,6 @@ (define (string . lst) (list->string lst)) - (define %prefix (getenv "MES_PREFIX")) - (define (not x) (if x #f #t)) (define (map1 f lst) (if (null? lst) (list) @@ -53,10 +51,7 @@ (define map map1) - (define %moduledir - (if (not %prefix ) "mes/module/" - (list->string - (append (string->list %prefix) (string->list "/module/"))))) + (define %moduledir (string-append %datadir "/module/")) (define-macro (load file) (list 'begin diff --git a/scaffold/gc-test.scm b/scaffold/gc-test.scm new file mode 100644 index 00000000..c6a23619 --- /dev/null +++ b/scaffold/gc-test.scm @@ -0,0 +1,27 @@ +;;; GNU Mes --- Maxwell Equations of Software +;;; Copyright © 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 . + +(gc) +;; (display (gc-stats)) +;; (newline) +(define (loop n) + (if (> n 0) (loop (- n 1)))) +(loop 100000) +(gc) +;; (display (gc-stats)) +;; (newline) diff --git a/build-aux/test.sh b/scripts/ar.in old mode 100755 new mode 100644 similarity index 61% rename from build-aux/test.sh rename to scripts/ar.in index 55a4fed6..290c172e --- a/build-aux/test.sh +++ b/scripts/ar.in @@ -1,7 +1,7 @@ -#! /bin/sh +#! @BASH@ # GNU Mes --- Maxwell Equations of Software -# Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen +# Copyright © 2019 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -18,20 +18,19 @@ # You should have received a copy of the GNU General Public License # along with GNU Mes. If not, see . -set -e -. ./config.status -. ${srcdest}build-aux/config.sh - -sh ${srcdest}build-aux/test-cc.sh $1 - -if [ ! "$mesc_p" ]; then - #FIXME: c&p - unset CFLAGS CPPFLAGS LDFLAGS gcc_p tcc_p with_glibc_p - MES=${MES-guile} - mesc_p=1 - mes_p=1 - mes_arch=x86-mes - program_prefix=$mes_arch- - CC="./pre-inst-env mescc" - sh ${srcdest}build-aux/test-cc.sh $1 +if [ "$V" = 2 ]; then + set -x fi + +command=$1 +archive=$2 +shift +shift +M1_archive=$(dirname "$archive")/$(basename "$archive" .a).S +declare -a M1_objects +for o in "$@"; do + ((i++)) + M1_objects[$i]=$(dirname "$o")/$(basename "$o" .o).S +done +cat "${M1_objects[@]}" > "$M1_archive" +cat "$@" > "$archive" diff --git a/scripts/mescc.in b/scripts/mescc.in old mode 100755 new mode 100644 index d3190bc7..176d95ea --- a/scripts/mescc.in +++ b/scripts/mescc.in @@ -28,14 +28,14 @@ export MES_ARENA MES_STACK=${MES_STACK-500000} export MES_STACK -MES_PREFIX=${MES_PREFIX-/usr/share/mes} +MES_PREFIX=${MES_PREFIX-@prefix@} export MES_PREFIX GUILE_LOAD_PATH=@guile_site_dir@${GUILE_LOAD_PATH+:}${GUILE_LOAD_PATH} export GUILE_LOAD_PATH MES=${MES-@prefix@/bin/mes} -bindir=${bindir-@prefix@/bin/mes} +bindir=${bindir-@bindir@/mes} if [ ! -f $bindir/mescc.scm ]; then bindir=$(dirname $0) diff --git a/scripts/mescc.scm.in b/scripts/mescc.scm.in index 05e67ad5..6a6a3372 100644 --- a/scripts/mescc.scm.in +++ b/scripts/mescc.scm.in @@ -2,7 +2,7 @@ --no-auto-compile -e main -L @guile_site_dir@ -C @guile_site_ccache_dir@ -s !# ;;; GNU Mes --- Maxwell Equations of Software -;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen ;;; ;;; This file is part of GNU Mes. ;;; @@ -22,7 +22,7 @@ (setenv "%prefix" (or (getenv "MES_PREFIX") (if (string-prefix? "@prefix" "@prefix@") "" - "@prefix@/share/mes"))) + "@prefix@"))) (setenv "%version" (if (string-prefix? "@VERSION" "@VERSION@") "git" "@VERSION@")) diff --git a/simple.sh b/simple.sh index bc3f6b9d..f87d0977 100755 --- a/simple.sh +++ b/simple.sh @@ -20,21 +20,89 @@ set -ex -# We need mes/module/mes/boot-0.scm created -# Create traditional GNU config.h with the needed defines? -./configure - -rm -f src/strings.h - ################################################################################ -# GLIBC build -rm -rf out-glibc -mkdir out-glibc -gcc -c -D SYSTEM_LIBC=1 -I include -I lib -o out-glibc/libmes.o lib/libmes.c -gcc -c -D SYSTEM_LIBC=1 -D VERSION=\"0.19\" -D MODULEDIR=\"module\" -D PREFIX=\"/usr/local\" -I include -o out-glibc/mes.o src/mes.c -gcc out-glibc/mes.o out-glibc/libmes.o -o out-glibc/mes +# SYSTEM_LIBC build -MES_PREFIX=mes out-glibc/mes --help +## Clean ## +rm -rf out-system-libc +mkdir out-system-libc + +## Configure ## +mes_cpu=x86_64 +mes_bits=64 +cat > include/mes/config.h < include/mes/config.h <. */ -#include +#include "mes/lib.h" +#include "mes/mes.h" -size_t bytes_cells (size_t length); +#include +#include +#include +#include + +long ARENA_SIZE; +long MAX_ARENA_SIZE; +long STACK_SIZE; +long JAM_SIZE; +long GC_SAFETY; +long MAX_STRING; +char *g_arena; +long g_free; +SCM g_stack; +SCM *g_stack_array; +struct scm *g_cells; +struct scm *g_news; + +SCM +gc_init () ///((internal)) +{ +#if SYSTEM_LIBC + ARENA_SIZE = 100000000; // 2.3GiB +#else + ARENA_SIZE = 300000; // 32b: 3MiB, 64b: 6 MiB +#endif + MAX_ARENA_SIZE = 100000000; + STACK_SIZE = 20000; + + JAM_SIZE = 20000; + GC_SAFETY = 2000; + MAX_STRING = 524288; + + char *p; + if (p = getenv ("MES_MAX_ARENA")) + MAX_ARENA_SIZE = atoi (p); + if (p = getenv ("MES_ARENA")) + ARENA_SIZE = atoi (p); + JAM_SIZE = ARENA_SIZE / 10; + if (p = getenv ("MES_JAM")) + JAM_SIZE = atoi (p); + GC_SAFETY = ARENA_SIZE / 100; + if (p = getenv ("MES_SAFETY")) + GC_SAFETY = atoi (p); + if (p = getenv ("MES_STACK")) + STACK_SIZE = atoi (p); + if (p = getenv ("MES_MAX_STRING")) + MAX_STRING = atoi (p); + + long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm); + void *a = malloc (arena_bytes + STACK_SIZE * sizeof (SCM)); + g_cells = (struct scm *) a; + g_stack_array = (SCM *) (a + arena_bytes); + + TYPE (0) = TVECTOR; + LENGTH (0) = 1000; + VECTOR (0) = 0; + g_cells++; + TYPE (0) = TCHAR; + VALUE (0) = 'c'; + + // FIXME: remove MES_MAX_STRING, grow dynamically + g_buf = (char *) malloc (MAX_STRING); + + return 0; +} + +SCM +gc_init_news () ///((internal)) +{ + g_news = g_cells + g_free; + NTYPE (0) = TVECTOR; + NLENGTH (0) = 1000; + NVECTOR (0) = 0; + g_news++; + NTYPE (0) = TCHAR; + NVALUE (0) = 'n'; + return 0; +} SCM gc_up_arena () ///((internal)) @@ -159,19 +238,6 @@ gc_check () return cell_unspecified; } -SCM -gc_init_news () ///((internal)) -{ - g_news = g_cells + g_free; - NTYPE (0) = TVECTOR; - NLENGTH (0) = 1000; - NVECTOR (0) = 0; - g_news++; - NTYPE (0) = TCHAR; - NVALUE (0) = 'n'; - return 0; -} - SCM gc_ () ///((internal)) { @@ -247,3 +313,34 @@ gc () eputs ("\n"); } } + +SCM +gc_push_frame () ///((internal)) +{ + if (g_stack < 5) + assert (!"STACK FULL"); + g_stack_array[--g_stack] = cell_f; + g_stack_array[--g_stack] = r0; + g_stack_array[--g_stack] = r1; + g_stack_array[--g_stack] = r2; + g_stack_array[--g_stack] = r3; + return g_stack; +} + +SCM +gc_peek_frame () ///((internal)) +{ + r3 = g_stack_array[g_stack]; + r2 = g_stack_array[g_stack + 1]; + r1 = g_stack_array[g_stack + 2]; + r0 = g_stack_array[g_stack + 3]; + return g_stack_array[g_stack + FRAME_PROCEDURE]; +} + +SCM +gc_pop_frame () ///((internal)) +{ + SCM x = gc_peek_frame (); + g_stack += 5; + return x; +} diff --git a/src/hash.c b/src/hash.c index 5d60a61f..e85777d7 100644 --- a/src/hash.c +++ b/src/hash.c @@ -18,9 +18,11 @@ * along with GNU Mes. If not, see . */ -SCM make_vector__ (long k); -SCM vector_ref_ (SCM x, long i); -SCM vector_set_x_ (SCM x, long i, SCM e); +#include "mes/lib.h" +#include "mes/mes.h" + +#include +#include int hash_cstring (char const *s, long size) diff --git a/src/lib.c b/src/lib.c index 39cf7187..424a1ccc 100644 --- a/src/lib.c +++ b/src/lib.c @@ -18,13 +18,13 @@ * along with GNU Mes. If not, see . */ -// CONSTANT STRUCT_TYPE 0 -#define STRUCT_TYPE 0 -// CONSTANT STRUCT_PRINTER 1 -#define STRUCT_PRINTER 1 +#include "mes/lib.h" +#include "mes/mes.h" + +#include +#include int g_depth; -SCM fdisplay_ (SCM, int, int); SCM display_helper (SCM x, int cont, char *sep, int fd, int write_p) diff --git a/src/math.c b/src/math.c index 1241a28e..390707f8 100644 --- a/src/math.c +++ b/src/math.c @@ -18,7 +18,14 @@ * along with GNU Mes. If not, see . */ +#include "mes/lib.h" +#include "mes/mes.h" + +#include +#include #include +#include +#include void assert_number (char const *name, SCM x) diff --git a/src/mes.c b/src/mes.c index aa3363f0..b676ad75 100644 --- a/src/mes.c +++ b/src/mes.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,92 +18,35 @@ * along with GNU Mes. If not, see . */ -#include -#include +#include "mes/lib.h" +#include "mes/mes.h" + #include -#include +#include #include #include -#include +#include -//#define MES_MINI 1 -#if SYSTEM_LIBC -long ARENA_SIZE = 100000000; // 2.3GiB -#else -long ARENA_SIZE = 300000; // 32b: 3MiB, 64b: 6 MiB -#endif -long MAX_ARENA_SIZE = 100000000; -long STACK_SIZE = 20000; +char g_datadir[1024]; +int g_debug; +char *g_buf; +SCM g_continuations; +SCM g_symbols; +SCM g_symbol_max; -long JAM_SIZE = 20000; -long GC_SAFETY = 2000; - -long MAX_STRING = 524288; - -char *g_arena = 0; -typedef long SCM; - -int g_debug = 0; -long g_free = 0; - -char *g_buf = 0; - -SCM g_continuations = 0; -SCM g_symbols = 0; -SCM g_stack = 0; -SCM *g_stack_array = 0; -#define FRAME_SIZE 5 -#define FRAME_PROCEDURE 4 // a/env -SCM r0 = 0; +SCM r0; // param 1 -SCM r1 = 0; +SCM r1; // save 2 -SCM r2 = 0; +SCM r2; // continuation -SCM r3 = 0; +SCM r3; // current-module -SCM m0 = 0; +SCM m0; // macro -SCM g_macros = 0; -SCM g_ports = 1; - -// CONSTANT TBYTES 0 -#define TBYTES 0 -// CONSTANT TCHAR 1 -#define TCHAR 1 -// CONSTANT TCLOSURE 2 -#define TCLOSURE 2 -// CONSTANT TCONTINUATION 3 -#define TCONTINUATION 3 -// CONSTANT TKEYWORD 4 -#define TKEYWORD 4 -// CONSTANT TMACRO 5 -#define TMACRO 5 -// CONSTANT TNUMBER 6 -#define TNUMBER 6 -// CONSTANT TPAIR 7 -#define TPAIR 7 -// CONSTANT TPORT 8 -#define TPORT 8 -// CONSTANT TREF 9 -#define TREF 9 -// CONSTANT TSPECIAL 10 -#define TSPECIAL 10 -// CONSTANT TSTRING 11 -#define TSTRING 11 -// CONSTANT TSTRUCT 12 -#define TSTRUCT 12 -// CONSTANT TSYMBOL 13 -#define TSYMBOL 13 -// CONSTANT TVALUES 14 -#define TVALUES 14 -// CONSTANT TVARIABLE 15 -#define TVARIABLE 15 -// CONSTANT TVECTOR 16 -#define TVECTOR 16 -// CONSTANT TBROKEN_HEART 17 -#define TBROKEN_HEART 17 +SCM g_macros; +SCM g_ports; #if __MESC__ typedef long function0_t; @@ -119,338 +62,6 @@ typedef SCM (*function3_t) (SCM, SCM, SCM); typedef SCM (*functionn_t) (SCM); #endif // !__MESC__ -struct scm -{ - long type; - SCM car; - SCM cdr; -}; - -#if __MESC__ -//FIXME -char *foobar = 0; -struct scm *g_cells = foobar; -struct scm *g_news = foobar; -#else -struct scm *g_cells = 0; -struct scm *g_news = 0; -#endif - -// CONSTANT cell_nil 1 -#define cell_nil 1 -// CONSTANT cell_f 2 -#define cell_f 2 -// CONSTANT cell_t 3 -#define cell_t 3 -// CONSTANT cell_dot 4 -#define cell_dot 4 -// CONSTANT cell_arrow 5 -#define cell_arrow 5 -// CONSTANT cell_undefined 6 -#define cell_undefined 6 -// CONSTANT cell_unspecified 7 -#define cell_unspecified 7 -// CONSTANT cell_closure 8 -#define cell_closure 8 -// CONSTANT cell_circular 9 -#define cell_circular 9 -// CONSTANT cell_begin 10 -#define cell_begin 10 -// CONSTANT cell_call_with_current_continuation 11 -#define cell_call_with_current_continuation 11 - -// CONSTANT cell_vm_apply 12 -#define cell_vm_apply 12 -// CONSTANT cell_vm_apply2 13 -#define cell_vm_apply2 13 -// CONSTANT cell_vm_begin 14 -#define cell_vm_begin 14 -// CONSTANT cell_vm_begin_eval 15 -#define cell_vm_begin_eval 15 -// CONSTANT cell_vm_begin_expand 16 -#define cell_vm_begin_expand 16 -// CONSTANT cell_vm_begin_expand_eval 17 -#define cell_vm_begin_expand_eval 17 -// CONSTANT cell_vm_begin_expand_macro 18 -#define cell_vm_begin_expand_macro 18 -// CONSTANT cell_vm_begin_expand_primitive_load 19 -#define cell_vm_begin_expand_primitive_load 19 -// CONSTANT cell_vm_begin_primitive_load 20 -#define cell_vm_begin_primitive_load 20 -// CONSTANT cell_vm_begin_read_input_file 21 -#define cell_vm_begin_read_input_file 21 -// CONSTANT cell_vm_call_with_current_continuation2 22 -#define cell_vm_call_with_current_continuation2 22 -// CONSTANT cell_vm_call_with_values2 23 -#define cell_vm_call_with_values2 23 -// CONSTANT cell_vm_eval 24 -#define cell_vm_eval 24 -// CONSTANT cell_vm_eval2 25 -#define cell_vm_eval2 25 -// CONSTANT cell_vm_eval_check_func 26 -#define cell_vm_eval_check_func 26 -// CONSTANT cell_vm_eval_define 27 -#define cell_vm_eval_define 27 -// CONSTANT cell_vm_eval_macro_expand_eval 28 -#define cell_vm_eval_macro_expand_eval 28 -// CONSTANT cell_vm_eval_macro_expand_expand 29 -#define cell_vm_eval_macro_expand_expand 29 -// CONSTANT cell_vm_eval_pmatch_car 30 -#define cell_vm_eval_pmatch_car 30 -// CONSTANT cell_vm_eval_pmatch_cdr 31 -#define cell_vm_eval_pmatch_cdr 31 -// CONSTANT cell_vm_eval_set_x 32 -#define cell_vm_eval_set_x 32 -// CONSTANT cell_vm_evlis 33 -#define cell_vm_evlis 33 -// CONSTANT cell_vm_evlis2 34 -#define cell_vm_evlis2 34 -// CONSTANT cell_vm_evlis3 35 -#define cell_vm_evlis3 35 -// CONSTANT cell_vm_if 36 -#define cell_vm_if 36 -// CONSTANT cell_vm_if_expr 37 -#define cell_vm_if_expr 37 -// CONSTANT cell_vm_macro_expand 38 -#define cell_vm_macro_expand 38 -// CONSTANT cell_vm_macro_expand_car 39 -#define cell_vm_macro_expand_car 39 -// CONSTANT cell_vm_macro_expand_cdr 40 -#define cell_vm_macro_expand_cdr 40 -// CONSTANT cell_vm_macro_expand_define 41 -#define cell_vm_macro_expand_define 41 -// CONSTANT cell_vm_macro_expand_define_macro 42 -#define cell_vm_macro_expand_define_macro 42 -// CONSTANT cell_vm_macro_expand_lambda 43 -#define cell_vm_macro_expand_lambda 43 -// CONSTANT cell_vm_macro_expand_set_x 44 -#define cell_vm_macro_expand_set_x 44 -// CONSTANT cell_vm_return 45 -#define cell_vm_return 45 - -// CONSTANT cell_symbol_dot 46 -#define cell_symbol_dot 46 -// CONSTANT cell_symbol_lambda 47 -#define cell_symbol_lambda 47 -// CONSTANT cell_symbol_begin 48 -#define cell_symbol_begin 48 -// CONSTANT cell_symbol_if 49 -#define cell_symbol_if 49 -// CONSTANT cell_symbol_quote 50 -#define cell_symbol_quote 50 -// CONSTANT cell_symbol_define 51 -#define cell_symbol_define 51 -// CONSTANT cell_symbol_define_macro 52 -#define cell_symbol_define_macro 52 - -// CONSTANT cell_symbol_quasiquote 53 -#define cell_symbol_quasiquote 53 -// CONSTANT cell_symbol_unquote 54 -#define cell_symbol_unquote 54 -// CONSTANT cell_symbol_unquote_splicing 55 -#define cell_symbol_unquote_splicing 55 -// CONSTANT cell_symbol_syntax 56 -#define cell_symbol_syntax 56 -// CONSTANT cell_symbol_quasisyntax 57 -#define cell_symbol_quasisyntax 57 -// CONSTANT cell_symbol_unsyntax 58 -#define cell_symbol_unsyntax 58 -// CONSTANT cell_symbol_unsyntax_splicing 59 -#define cell_symbol_unsyntax_splicing 59 - -// CONSTANT cell_symbol_set_x 60 -#define cell_symbol_set_x 60 - -// CONSTANT cell_symbol_sc_expand 61 -#define cell_symbol_sc_expand 61 -// CONSTANT cell_symbol_macro_expand 62 -#define cell_symbol_macro_expand 62 -// CONSTANT cell_symbol_portable_macro_expand 63 -#define cell_symbol_portable_macro_expand 63 -// CONSTANT cell_symbol_sc_expander_alist 64 -#define cell_symbol_sc_expander_alist 64 - -// CONSTANT cell_symbol_call_with_values 65 -#define cell_symbol_call_with_values 65 -// CONSTANT cell_symbol_call_with_current_continuation 66 -#define cell_symbol_call_with_current_continuation 66 -// CONSTANT cell_symbol_boot_module 67 -#define cell_symbol_boot_module 67 -// CONSTANT cell_symbol_current_module 68 -#define cell_symbol_current_module 68 -// CONSTANT cell_symbol_primitive_load 69 -#define cell_symbol_primitive_load 69 -// CONSTANT cell_symbol_read_input_file 70 -#define cell_symbol_read_input_file 70 -// CONSTANT cell_symbol_write 71 -#define cell_symbol_write 71 -// CONSTANT cell_symbol_display 72 -#define cell_symbol_display 72 - -// CONSTANT cell_symbol_car 73 -#define cell_symbol_car 73 -// CONSTANT cell_symbol_cdr 74 -#define cell_symbol_cdr 74 -// CONSTANT cell_symbol_not_a_number 75 -#define cell_symbol_not_a_number 75 -// CONSTANT cell_symbol_not_a_pair 76 -#define cell_symbol_not_a_pair 76 -// CONSTANT cell_symbol_system_error 77 -#define cell_symbol_system_error 77 -// CONSTANT cell_symbol_throw 78 -#define cell_symbol_throw 78 -// CONSTANT cell_symbol_unbound_variable 79 -#define cell_symbol_unbound_variable 79 -// CONSTANT cell_symbol_wrong_number_of_args 80 -#define cell_symbol_wrong_number_of_args 80 -// CONSTANT cell_symbol_wrong_type_arg 81 -#define cell_symbol_wrong_type_arg 81 - -// CONSTANT cell_symbol_buckets 82 -#define cell_symbol_buckets 82 -// CONSTANT cell_symbol_builtin 83 -#define cell_symbol_builtin 83 -// CONSTANT cell_symbol_frame 84 -#define cell_symbol_frame 84 -// CONSTANT cell_symbol_hashq_table 85 -#define cell_symbol_hashq_table 85 -// CONSTANT cell_symbol_module 86 -#define cell_symbol_module 86 -// CONSTANT cell_symbol_procedure 87 -#define cell_symbol_procedure 87 -// CONSTANT cell_symbol_record_type 88 -#define cell_symbol_record_type 88 -// CONSTANT cell_symbol_size 89 -#define cell_symbol_size 89 -// CONSTANT cell_symbol_stack 90 -#define cell_symbol_stack 90 - -// CONSTANT cell_symbol_argv 91 -#define cell_symbol_argv 91 -// CONSTANT cell_symbol_mes_prefix 92 -#define cell_symbol_mes_prefix 92 -// CONSTANT cell_symbol_mes_version 93 -#define cell_symbol_mes_version 93 - -// CONSTANT cell_symbol_internal_time_units_per_second 94 -#define cell_symbol_internal_time_units_per_second 94 -// CONSTANT cell_symbol_compiler 95 -#define cell_symbol_compiler 95 -// CONSTANT cell_symbol_arch 96 -#define cell_symbol_arch 96 -// CONSTANT cell_symbol_pmatch_car 97 -#define cell_symbol_pmatch_car 97 -// CONSTANT cell_symbol_pmatch_cdr 98 -#define cell_symbol_pmatch_cdr 98 - -// CONSTANT cell_type_bytes 99 -#define cell_type_bytes 99 -// CONSTANT cell_type_char 100 -#define cell_type_char 100 -// CONSTANT cell_type_closure 101 -#define cell_type_closure 101 -// CONSTANT cell_type_continuation 102 -#define cell_type_continuation 102 -// CONSTANT cell_type_function 103 -#define cell_type_function 103 -// CONSTANT cell_type_keyword 104 -#define cell_type_keyword 104 -// CONSTANT cell_type_macro 105 -#define cell_type_macro 105 -// CONSTANT cell_type_number 106 -#define cell_type_number 106 -// CONSTANT cell_type_pair 107 -#define cell_type_pair 107 -// CONSTANT cell_type_port 108 -#define cell_type_port 108 -// CONSTANT cell_type_ref 109 -#define cell_type_ref 109 -// CONSTANT cell_type_special 110 -#define cell_type_special 110 -// CONSTANT cell_type_string 111 -#define cell_type_string 111 -// CONSTANT cell_type_struct 112 -#define cell_type_struct 112 -// CONSTANT cell_type_symbol 113 -#define cell_type_symbol 113 -// CONSTANT cell_type_values 114 -#define cell_type_values 114 -// CONSTANT cell_type_variable 115 -#define cell_type_variable 115 -// CONSTANT cell_type_vector 116 -#define cell_type_vector 116 -// CONSTANT cell_type_broken_heart 117 -#define cell_type_broken_heart 117 - -// CONSTANT cell_test 118 -#define cell_test 118 - -#include "mes/builtins.h" - -#define TYPE(x) g_cells[x].type -#define CAR(x) g_cells[x].car -#define CDR(x) g_cells[x].cdr - -#define NTYPE(x) g_news[x].type -#define NCAR(x) g_news[x].car -#define NCDR(x) g_news[x].cdr - -#define BYTES(x) g_cells[x].car -#define LENGTH(x) g_cells[x].car -#define REF(x) g_cells[x].car -#define START(x) (g_cells[x].car >> 16) -#define LEN(x) (g_cells[x].car & 0xffff) -#define VARIABLE(x) g_cells[x].car - -#define CLOSURE(x) g_cells[x].cdr -#define CONTINUATION(x) g_cells[x].cdr - -#define CBYTES(x) (char*)&g_cells[x].cdr -#define CSTRING_STRUCT(x) (char*)&g_cells[x.cdr].cdr - -#define MACRO(x) g_cells[x].car -#define NAME(x) g_cells[x].cdr -#define PORT(x) g_cells[x].car -#define STRING(x) g_cells[x].cdr -#define STRUCT(x) g_cells[x].cdr -#define VALUE(x) g_cells[x].cdr -#define VECTOR(x) g_cells[x].cdr - -#define NLENGTH(x) g_news[x].car -#define NCBYTES(x) (char*)&g_news[x].cdr -#define NVALUE(x) g_news[x].cdr -#define NSTRING(x) g_news[x].cdr -#define NVECTOR(x) g_news[x].cdr - -#define CSTRING(x) CBYTES (STRING (x)) - -#define MAKE_BYTES0(x) make_bytes (x, strlen (x)) -#define NAME_SYMBOL(symbol,name) {size_t s = strlen (name); CAR (symbol) = s; CDR (symbol) = make_bytes (name, s);} - -#define MAKE_CHAR(n) make_cell__ (TCHAR, 0, n) -#define MAKE_CONTINUATION(n) make_cell__ (TCONTINUATION, n, g_stack) -#define MAKE_NUMBER(n) make_cell__ (TNUMBER, 0, (long)n) -#define MAKE_REF(n) make_cell__ (TREF, n, 0) -#define MAKE_STRING0(x) make_string (x, strlen (x)) -#define MAKE_STRING_PORT(x) make_cell__ (TPORT, -length__ (g_ports) - 2, x) -#define MAKE_MACRO(name, x) make_cell__ (TMACRO, x, STRING (name)) - -#define CAAR(x) CAR (CAR (x)) -#define CADR(x) CAR (CDR (x)) -#define CDAR(x) CDR (CAR (x)) -#define CDDR(x) CDR (CDR (x)) -#define CADAR(x) CAR (CDR (CAR (x))) -#define CADDR(x) CAR (CDR (CDR (x))) -#define CDADAR(x) CAR (CDR (CAR (CDR (x)))) - -SCM apply_builtin (SCM fn, SCM x); -SCM cstring_to_list (char const *s); -SCM cstring_to_symbol (char const *s); -SCM make_bytes (char const *s, size_t length); -SCM make_hash_table_ (long size); -SCM read_input_file_env (SCM); -SCM string_equal_p (SCM a, SCM b); - SCM alloc (long n) { @@ -624,8 +235,6 @@ length (SCM x) return MAKE_NUMBER (length__ (x)); } -SCM apply (SCM, SCM, SCM); - SCM error (SCM key, SCM x) { @@ -651,8 +260,6 @@ assert_defined (SCM x, SCM e) ///((internal)) return e; } -SCM make_string (char const *s, size_t length); - SCM check_formals (SCM f, SCM formals, SCM args) ///((internal)) { @@ -710,37 +317,6 @@ check_apply (SCM f, SCM e) ///((internal)) return cell_unspecified; } -SCM -gc_push_frame () ///((internal)) -{ - if (g_stack < 5) - assert (!"STACK FULL"); - g_stack_array[--g_stack] = cell_f; - g_stack_array[--g_stack] = r0; - g_stack_array[--g_stack] = r1; - g_stack_array[--g_stack] = r2; - g_stack_array[--g_stack] = r3; - return g_stack; -} - -SCM -gc_peek_frame () ///((internal)) -{ - r3 = g_stack_array[g_stack]; - r2 = g_stack_array[g_stack + 1]; - r1 = g_stack_array[g_stack + 2]; - r0 = g_stack_array[g_stack + 3]; - return g_stack_array[g_stack + FRAME_PROCEDURE]; -} - -SCM -gc_pop_frame () ///((internal)) -{ - SCM x = gc_peek_frame (); - g_stack += 5; - return x; -} - SCM append2 (SCM x, SCM y) { @@ -1013,11 +589,6 @@ expand_variable (SCM x, SCM formals) ///((internal)) return expand_variable_ (x, formals, 1); } -SCM struct_ref_ (SCM x, long i); -SCM vector_ref_ (SCM x, long i); -SCM make_vector__ (long k); -SCM vector_set_x_ (SCM x, long i, SCM e); - SCM eval_apply () { @@ -1652,30 +1223,6 @@ mes_g_stack (SCM a) ///((internal)) return r0; } -// Jam Collector -SCM g_symbol_max; - -SCM -gc_init_cells () ///((internal)) -{ - long arena_bytes = (ARENA_SIZE + JAM_SIZE) * sizeof (struct scm); - void *p = malloc (arena_bytes + STACK_SIZE * sizeof (SCM)); - g_cells = (struct scm *) p; - g_stack_array = (SCM *) (p + arena_bytes); - - TYPE (0) = TVECTOR; - LENGTH (0) = 1000; - VECTOR (0) = 0; - g_cells++; - TYPE (0) = TCHAR; - VALUE (0) = 'c'; - - // FIXME: remove MES_MAX_STRING, grow dynamically - g_buf = (char *) malloc (MAX_STRING); - - return 0; -} - void init_symbol (long x, long type, char const *name) { @@ -1690,8 +1237,6 @@ init_symbol (long x, long type, char const *name) SCM mes_symbols () ///((internal)) { - gc_init_cells (); - g_free = cell_symbol_test + 1; g_symbol_max = g_free; g_symbols = make_hash_table_ (500); @@ -1796,7 +1341,7 @@ mes_symbols () ///((internal)) init_symbol (cell_symbol_stack, TSYMBOL, ""); init_symbol (cell_symbol_argv, TSYMBOL, "%argv"); - init_symbol (cell_symbol_mes_prefix, TSYMBOL, "%prefix"); + init_symbol (cell_symbol_mes_datadir, TSYMBOL, "%datadir"); init_symbol (cell_symbol_mes_version, TSYMBOL, "%version"); init_symbol (cell_symbol_internal_time_units_per_second, TSYMBOL, "internal-time-units-per-second"); @@ -1835,7 +1380,7 @@ mes_symbols () ///((internal)) a = acons (cell_symbol_call_with_current_continuation, cell_call_with_current_continuation, a); a = acons (cell_symbol_mes_version, MAKE_STRING0 (VERSION), a); - a = acons (cell_symbol_mes_prefix, MAKE_STRING0 (PREFIX), a); + a = acons (cell_symbol_mes_datadir, MAKE_STRING0 (g_datadir), a); a = acons (cell_type_bytes, MAKE_NUMBER (TBYTES), a); a = acons (cell_type_char, MAKE_NUMBER (TCHAR), a); @@ -2196,59 +1741,77 @@ mes_builtins (SCM a) ///((internal)) } int -open_boot (char *prefix, char const *boot, char const *location) +try_open_boot (char *file_name, char const *boot, char const *location) { - strcpy (prefix + strlen (prefix), boot); + strcpy (file_name + strlen (file_name), boot); if (g_debug > 1) { eputs ("mes: reading boot-0 ["); eputs (location); eputs ("]: "); - eputs (prefix); + eputs (file_name); eputs ("\n"); } - int fd = mes_open (prefix, O_RDONLY, 0); + int fd = mes_open (file_name, O_RDONLY, 0); if (g_debug && fd > 0) { eputs ("mes: read boot-0: "); - eputs (prefix); + eputs (file_name); eputs ("\n"); } return fd; } -SCM -read_boot () ///((internal)) +void +open_boot () { __stdin = -1; - char prefix[1024]; char boot[1024]; + char file_name[1024]; + strcpy (g_datadir, "."); + if (g_debug > 1) + { + eputs (";;; pkgdatadir="); + eputs (pkgdatadir); + eputs ("\n"); + } if (getenv ("MES_BOOT")) strcpy (boot, getenv ("MES_BOOT")); else strcpy (boot, "boot-0.scm"); if (getenv ("MES_PREFIX")) { - strcpy (prefix, getenv ("MES_PREFIX")); - strcpy (prefix + strlen (prefix), "/module"); - strcpy (prefix + strlen (prefix), "/mes/"); - __stdin = open_boot (prefix, boot, "MES_PREFIX"); + strcpy (g_datadir, getenv ("MES_PREFIX")); + strcpy (file_name, g_datadir); + strcpy (file_name + strlen (file_name), "/module/mes/"); + __stdin = try_open_boot (file_name, boot, "MES_PREFIX"); + if (__stdin < 0) + { + strcpy (g_datadir, getenv ("MES_PREFIX")); + strcpy (g_datadir + strlen (g_datadir), "/share/mes"); + strcpy (file_name, g_datadir); + strcpy (file_name + strlen (file_name), "/module/mes/"); + __stdin = try_open_boot (file_name, boot, "MES_PREFIX/share/mes"); + } } if (__stdin < 0) { - char const *p = MODULEDIR "/mes/"; - strcpy (prefix, p); - __stdin = open_boot (prefix, boot, "MODULEDIR"); + strcpy (g_datadir, pkgdatadir); + strcpy (file_name, g_datadir); + strcpy (file_name + strlen (file_name), "/module/mes/"); + __stdin = try_open_boot (file_name, boot, "pkgdatadir"); } if (__stdin < 0) { - strcpy (prefix, "mes/module/mes/"); - __stdin = open_boot (prefix, boot, "."); + strcpy (g_datadir, "mes"); + strcpy (file_name, g_datadir); + strcpy (file_name + strlen (file_name), "/module/mes/"); + __stdin = try_open_boot (file_name, boot, "mes"); } if (__stdin < 0) { - prefix[0] = 0; - __stdin = open_boot (prefix, boot, ""); + file_name[0] = 0; + __stdin = try_open_boot (file_name, boot, ""); } if (__stdin < 0) { @@ -2257,49 +1820,31 @@ read_boot () ///((internal)) eputs ("\n"); exit (1); } +} +SCM +read_boot () ///((internal)) +{ r2 = read_input_file_env (r0); __stdin = STDIN; return r2; } -#include "hash.c" -#include "module.c" -#include "posix.c" -#include "math.c" -#include "lib.c" -#include "vector.c" -#include "string.c" -#include "struct.c" -#include "gc.c" -#include "reader.c" - -int -main (int argc, char *argv[]) +void +init () { char *p; if (p = getenv ("MES_DEBUG")) g_debug = atoi (p); - if (g_debug > 1) - { - eputs (";;; MODULEDIR="); - eputs (MODULEDIR); - eputs ("\n"); - } - if (p = getenv ("MES_MAX_ARENA")) - MAX_ARENA_SIZE = atoi (p); - if (p = getenv ("MES_ARENA")) - ARENA_SIZE = atoi (p); - JAM_SIZE = ARENA_SIZE / 10; - if (p = getenv ("MES_JAM")) - JAM_SIZE = atoi (p); - GC_SAFETY = ARENA_SIZE / 100; - if (p = getenv ("MES_SAFETY")) - GC_SAFETY = atoi (p); - if (p = getenv ("MES_STACK")) - STACK_SIZE = atoi (p); - if (p = getenv ("MES_MAX_STRING")) - MAX_STRING = atoi (p); + open_boot (); + gc_init (); + g_ports = 1; +} + +int +main (int argc, char *argv[]) +{ + init (); SCM a = mes_environment (argc, argv); a = mes_builtins (a); diff --git a/src/module.c b/src/module.c index e16839f5..48db2330 100644 --- a/src/module.c +++ b/src/module.c @@ -18,9 +18,10 @@ * along with GNU Mes. If not, see . */ -SCM struct_ref_ (SCM x, long i); -SCM struct_set_x_ (SCM x, long i, SCM e); -SCM cstring_to_symbol (char const *s); +#include "mes/lib.h" +#include "mes/mes.h" + +#include SCM make_module_type () ///(internal)) diff --git a/src/posix.c b/src/posix.c index 4a10a279..7ba2e991 100644 --- a/src/posix.c +++ b/src/posix.c @@ -18,18 +18,20 @@ * along with GNU Mes. If not, see . */ +#include "mes/lib.h" +#include "mes/mes.h" + +#include #include #include #include +#include #include +#include #include #include -#include #include -int readchar (); -int unreadchar (); - int peekchar () { diff --git a/src/reader.c b/src/reader.c index ccface38..c8ecea49 100644 --- a/src/reader.c +++ b/src/reader.c @@ -19,7 +19,13 @@ * along with GNU Mes. If not, see . */ +#include "mes/lib.h" +#include "mes/mes.h" + +#include #include +#include +#include SCM read_input_file_env_ (SCM e, SCM a) diff --git a/src/string.c b/src/string.c index 3506c6bc..f75d7e1e 100644 --- a/src/string.c +++ b/src/string.c @@ -18,6 +18,16 @@ * along with GNU Mes. If not, see . */ +#include "mes/lib.h" +#include "mes/mes.h" + +#include + +#include +#include + +long MAX_STRING; + void assert_max_string (size_t i, char const *msg, char *string) { diff --git a/src/struct.c b/src/struct.c index 0eb9be91..4e06a5ed 100644 --- a/src/struct.c +++ b/src/struct.c @@ -18,10 +18,10 @@ * along with GNU Mes. If not, see . */ -// CONSTANT STRUCT_TYPE 0 -#define STRUCT_TYPE 0 -// CONSTANT STRUCT_PRINTER 1 -#define STRUCT_PRINTER 1 +#include "mes/lib.h" +#include "mes/mes.h" + +#include SCM make_struct (SCM type, SCM fields, SCM printer) diff --git a/src/vector.c b/src/vector.c index e7882483..05323bf5 100644 --- a/src/vector.c +++ b/src/vector.c @@ -18,6 +18,11 @@ * along with GNU Mes. If not, see . */ +#include "mes/lib.h" +#include "mes/mes.h" + +#include + SCM make_vector__ (long k) {