diff --git a/.gitignore b/.gitignore
index 72179c13..73458649 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,35 +1,32 @@
*-
-*.blood-elf-M1
-*.blood-elf-hex2
-*.go
*~
.#*
-*.0-M1
-*.0-guile
-*.0-hex2
*.E
*.S
-*.o
*.blood-elf
+*.blood-elf-M1
+*.blood-elf-hex2
*.gcc
+*.gcc-o
+*.gcc-out
+*.go
*.guile
*.log
-*.gcc-o
+*.mes-gcc
+*.mes-gcc-o
+*.mes-gcc-out
+*.mes-gcc-out
+*.mes-gcc-stdout
*.mes-o
+*.mes-out
*.mes-stdout
*.mini-M1
*.mini-guile
*.mini-hex2
-*.mlibc-gcc
-*.mlibc-o
-*.mlibc-out
-*.mlibc-stdout
+*.o
+*.seed-out
*.stderr
*.stdout
-*.tcc-guile
-!/stage0/*
-!/stage0/*.c
-/stage0/exit-42.*
/src/*.h
/src/*.i
@@ -39,11 +36,6 @@
/.store
/.tarball-version
/ChangeLog
-/a.out
-*.gcc-out
-*.mes-out
-*.mlibc-out
-*.seed-out
#keep this: bootstrap
#/mes.mes
diff --git a/GNUmakefile b/GNUmakefile
index 820b2729..506f93b3 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -14,8 +14,8 @@ all:
cc:
build-aux/build-cc.sh
-mlibc:
- build-aux/build-mlibc.sh
+mes-gcc:
+ build-aux/build-mes-gcc.sh
mes:
build-aux/build-mes.sh
@@ -43,7 +43,7 @@ seed: all-go
MES=$(GUILE) GUILE=$(GUILE) SEED=1 build-aux/build-mes.sh
cd $(MES_SEED) && MES_PREFIX=$(PWD) ./refresh.sh
MES=$(GUILE) GUILE=$(GUILE) SEED=1 build-aux/build-mes.sh
- build-aux/build-mlibc.sh
+ build-aux/build-mes-gcc.sh
cd $(TINYCC_SEED) && MES_PREFIX=$(PWD) ./refresh.sh
define HELP_TOP
@@ -53,7 +53,7 @@ Targets:
all update everything
all-go update .go files
cc update src/mes.gcc-out
- mlibc update src/mes.mlibc-out
+ mes-gcc update src/mes.mes-gcc-out
mes update src/mes
check run unit tests
clean run git clean -dfx
diff --git a/build-aux/build-cc.sh b/build-aux/build-cc.sh
index a6544ebe..f3e54150 100755
--- a/build-aux/build-cc.sh
+++ b/build-aux/build-cc.sh
@@ -50,4 +50,5 @@ build-aux/mes-snarf.scm src/posix.c
build-aux/mes-snarf.scm src/reader.c
build-aux/mes-snarf.scm src/vector.c
+ARCHDIR=1 NOLINK=1 sh build-aux/cc.sh lib/libmes
sh build-aux/cc.sh src/mes
diff --git a/build-aux/build-mlibc.sh b/build-aux/build-mes-gcc.sh
similarity index 74%
rename from build-aux/build-mlibc.sh
rename to build-aux/build-mes-gcc.sh
index 5b2a2150..71552ae9 100755
--- a/build-aux/build-mlibc.sh
+++ b/build-aux/build-mes-gcc.sh
@@ -62,17 +62,17 @@ C32FLAGS=${C32FLAGS-"
-nostdlib
"}
-NOLINK=1 sh build-aux/cc-mlibc.sh lib/crt1
-NOLINK=1 sh build-aux/cc-mlibc.sh lib/libc-mini-gcc
-NOLINK=1 sh build-aux/cc-mlibc.sh lib/libc-gcc
-NOLINK=1 sh build-aux/cc-mlibc.sh lib/libc+tcc-gcc
+ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crt1
+ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc-mini
+ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc
+ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc+tcc
-sh build-aux/cc-mlibc.sh scaffold/main
-sh build-aux/cc-mlibc.sh scaffold/hello
-sh build-aux/cc-mlibc.sh scaffold/argv
-sh build-aux/cc-mlibc.sh scaffold/malloc
-sh build-aux/cc-mlibc.sh scaffold/micro-mes
-sh build-aux/cc-mlibc.sh scaffold/tiny-mes
-sh build-aux/cc-mlibc.sh scaffold/mini-mes
+sh build-aux/cc-mes-gcc.sh scaffold/main
+sh build-aux/cc-mes-gcc.sh scaffold/hello
+sh build-aux/cc-mes-gcc.sh scaffold/argv
+sh build-aux/cc-mes-gcc.sh scaffold/malloc
+sh build-aux/cc-mes-gcc.sh scaffold/micro-mes
+sh build-aux/cc-mes-gcc.sh scaffold/tiny-mes
+sh build-aux/cc-mes-gcc.sh scaffold/mini-mes
-sh build-aux/cc-mlibc.sh src/mes
+sh build-aux/cc-mes-gcc.sh src/mes
diff --git a/build-aux/build-mes.sh b/build-aux/build-mes.sh
index 5ed83961..7166c0e0 100755
--- a/build-aux/build-mes.sh
+++ b/build-aux/build-mes.sh
@@ -55,24 +55,24 @@ HEX2FLAGS=${HEX2FLAGS-"
if [ -d "$MES_SEED" ]; then
$M1\
$M1FLAGS\
- -f stage0/x86.M1\
- -f $MES_SEED/crt1.M1\
- -o lib/crt1.o
+ -f lib/x86-mes/x86.M1\
+ -f $MES_SEED/x86-mes/crt1.S\
+ -o lib/x86-mes/crt1.o
$M1\
$M1FLAGS\
- -f stage0/x86.M1\
- -f $MES_SEED/libc-mes.M1\
- -o lib/libc-mes.o
+ -f lib/x86-mes/x86.M1\
+ -f $MES_SEED/x86-mes/libc.S\
+ -o lib/x86-mes/libc.o
$M1\
--LittleEndian\
--Architecture=1\
- -f stage0/x86.M1\
- -f $MES_SEED/mes.M1\
+ -f lib/x86-mes/x86.M1\
+ -f $MES_SEED/x86-mes/mes.S\
-o src/mes.o
$BLOOD_ELF\
- -f stage0/x86.M1\
- -f $MES_SEED/mes.M1\
- -f $MES_SEED/libc-mes.M1\
+ -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\
@@ -81,9 +81,9 @@ if [ -d "$MES_SEED" ]; then
-o src/mes.o.blood-elf
$HEX2\
$HEX2FLAGS\
- -f stage0/elf32-header.hex2\
- -f lib/crt1.o\
- -f lib/libc-mes.o\
+ -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\
@@ -91,25 +91,20 @@ if [ -d "$MES_SEED" ]; then
cp src/mes.seed-out src/mes
$M1\
$M1FLAGS\
- -f stage0/x86.M1\
- -f $MES_SEED/libc+tcc-mes.M1\
- -o lib/libc+tcc-mes.o
+ -f lib/x86-mes/x86.M1\
+ -f $MES_SEED/x86-mes/libc+tcc.S\
+ -o lib/x86-mes/libc+tcc.o
fi
PREPROCESS=1
-NOLINK=1 sh build-aux/cc-mes.sh lib/crt1
-NOLINK=1 sh build-aux/cc-mes.sh lib/libc-mini-mes
-NOLINK=1 sh build-aux/cc-mes.sh lib/libc-mes
-NOLINK=1 sh build-aux/cc-mes.sh lib/libc+tcc-mes
-
-cp lib/crt1.mes-o lib/crt1.o
-cp lib/libc-mini-mes.mes-o lib/libc-mini-mes.o
-cp lib/libc-mes.mes-o lib/libc-mes.o
-cp lib/libc+tcc-mes.mes-o lib/libc+tcc-mes.o
+ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/crt1
+ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/libc-mini
+ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/libc
+ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/libc+tcc
[ -n "$SEED" ] && exit 0
-MES_ARENA=${MES_ARENA-30000000}
+MES_ARENA=${MES_ARENA-10000000}
sh build-aux/mes-snarf.scm --mes src/gc.c
sh build-aux/mes-snarf.scm --mes src/lib.c
sh build-aux/mes-snarf.scm --mes src/math.c
diff --git a/build-aux/cc-mlibc.sh b/build-aux/cc-mes-gcc.sh
similarity index 78%
rename from build-aux/cc-mlibc.sh
rename to build-aux/cc-mes-gcc.sh
index 985db1b4..f33dab04 100755
--- a/build-aux/cc-mlibc.sh
+++ b/build-aux/cc-mes-gcc.sh
@@ -43,23 +43,35 @@ C32FLAGS=${C32FLAGS-"
-nostdinc
-nostdlib
"}
-LIBC=${LIBC-lib/libc}
+LIBC=${LIBC-c}
+if [ -n "$LIBC" ]; then
+ CC32LIBS="lib/x86-mes-gcc/lib$LIBC.o"
+fi
c=$1
+if [ -z "$ARCHDIR" ]; then
+ o="$c"
+ p="mes-gcc-"
+else
+ b=${c##*/}
+ d=${c%/*}
+ o="$d/x86-mes-gcc/$b"
+ mkdir -p $d/x86-mes-gcc
+fi
+
$CC32\
-c\
$CPPFLAGS\
$C32FLAGS\
- -o "$c".mlibc-o\
+ -o "$o".${p}o\
"$c".c
if [ -z "$NOLINK" ]; then
$CC32\
$C32FLAGS\
- -o "$c".mlibc-out\
- lib/crt1.mlibc-o\
- "$c".mlibc-o\
- $LIBC-gcc.mlibc-o\
+ -o "$o".${p}out\
+ lib/x86-mes-gcc/crt1.o\
+ "$o".${p}o\
$CC32LIBS
fi
diff --git a/build-aux/cc-mes.sh b/build-aux/cc-mes.sh
index d1dad871..f9302858 100755
--- a/build-aux/cc-mes.sh
+++ b/build-aux/cc-mes.sh
@@ -52,21 +52,31 @@ c=$1
set -e
+if [ -z "$ARCHDIR" ]; then
+ o="$c"
+ p="mes-"
+else
+ b=${c##*/}
+ d=${c%/*}
+ o="$d/x86-mes/$b"
+ mkdir -p $d/x86-mes
+fi
+
if [ -n "$PREPROCESS" ]; then
- sh $MESCC $MESCCFLAGS $CPPFLAGS -E "$c".c
- sh $MESCC $MESCCFLAGS -S "$c".E
- sh $MESCC $MESCCFLAGS -c -o "$c".mes-o "$c".S
+ sh $MESCC $MESCCFLAGS $CPPFLAGS -E -o "$o.E" "$c".c
+ sh $MESCC $MESCCFLAGS -S "$o".E
+ sh $MESCC $MESCCFLAGS -c -o "$o".${p}o "$o".S
if [ -z "$NOLINK" ]; then
- sh $MESCC $MESCCFLAGS -o "$c".mes-out "$c".mes-o $MESCCLIBS
+ sh $MESCC $MESCCFLAGS -o "$o".${p}out "$o".${p}o $MESCCLIBS
fi
elif [ -n "$COMPILE" ]; then
- sh $MESCC $MESCCFLAGS $CPPFLAGS -S "$c".c
- sh $MESCC $MESCCFLAGS -c -o "$c".mes-o "$c".S
+ sh $MESCC $MESCCFLAGS $CPPFLAGS -S -o "$o.S" "$c".c
+ sh $MESCC $MESCCFLAGS -c -o "$o".${p}o "$o".S
if [ -z "$NOLINK" ]; then
- sh $MESCC $MESCCFLAGS -o "$c".mes-out "$c".mes-o $MESCCLIBS
+ sh $MESCC $MESCCFLAGS -o "$o".${p}out "$o".${p}o $MESCCLIBS
fi
elif [ -z "$NOLINK" ]; then
- sh $MESCC $MESCCFLAGS $CPPFLAGS -o "$c".mes-out "$c".c $MESCCLIBS
+ sh $MESCC $MESCCFLAGS $CPPFLAGS -o "$o".${p}out "$c".c $MESCCLIBS
else
- sh $MESCC $MESCCFLAGS $CPPFLAGS -c -o "$c".mes-out "$c".c
+ sh $MESCC $MESCCFLAGS $CPPFLAGS -c -o "$o".${p}out "$c".c
fi
diff --git a/build-aux/cc.sh b/build-aux/cc.sh
index b85ed2d5..0b4610d6 100755
--- a/build-aux/cc.sh
+++ b/build-aux/cc.sh
@@ -41,18 +41,28 @@ CFLAGS=${CFLAGS-"
c=$1
+if [ -z "$ARCHDIR" ]; then
+ o="$c"
+ p="gcc-"
+else
+ b=${c##*/}
+ d=${c%/*}
+ o="$d/gcc/$b"
+ mkdir -p $d/gcc
+fi
+
$CC\
-c\
$CPPFLAGS\
$CFLAGS\
-D POSIX=1\
- -o "$c".gcc-o\
+ -o "$o".${p}o\
"$c".c
if [ -z "$NOLINK" ]; then
$CC\
$CFLAGS\
- -o "$c".gcc-out\
- "$c".gcc-o\
- lib/libc-gcc.gcc-o
+ -o "$o".${p}out\
+ "$o".${p}o\
+ lib/gcc/libmes.o
fi
diff --git a/build-aux/check-mescc.sh b/build-aux/check-mescc.sh
index 4546cda0..ea4002ed 100755
--- a/build-aux/check-mescc.sh
+++ b/build-aux/check-mescc.sh
@@ -26,7 +26,7 @@ export BLOOD_ELF GUILE HEX2 M1 MES MESCC
export M1FLAGS HEX2FLAGS PREPROCESS
export MES_ARENA MES_PREFIX MES_SEED
export BUILD_DEBUG
-export CC32LIBS MESCCLIBS
+export LIBC CC32LIBS MESCCLIBS
MES=${MES-src/mes}
MESCC=${MESCC-scripts/mescc}
@@ -144,17 +144,15 @@ expect=$(echo $broken | wc -w)
pass=0
fail=0
total=0
-MESCCLIBS=
-LIBC=libc/libc
for t in $tests; do
if [ -z "${t/[012][0-9]-*/}" ]; then
- LIBC="lib/libc-mini"
+ LIBC=c-mini
MESCCLIBS="-l c-mini"
elif [ -z "${t/8[0-9]-*/}" ]; then
- LIBC="lib/libc+tcc"
+ LIBC=c+tcc
MESCCLIBS="-l c+tcc"
else
- LIBC=libc/libc
+ LIBC=c
MESCCLIBS=
fi
sh build-aux/test.sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
@@ -251,6 +249,7 @@ broken="$broken
42_function_pointer
46_grep
49_bracket_evaluation
+55_lshift_type
"
#22_floating_point ; float
diff --git a/build-aux/test.sh b/build-aux/test.sh
index d8ae6e7a..33f5919e 100755
--- a/build-aux/test.sh
+++ b/build-aux/test.sh
@@ -34,21 +34,21 @@ shift
set -e
-rm -f "$t".mlibc-out
+rm -f "$t".mes-gcc-out
if [ -n "$CC32" ]; then
- sh build-aux/cc-mlibc.sh "$t"
+ sh build-aux/cc-mes-gcc.sh "$t"
r=0
[ -f "$t".exit ] && r=$(cat "$t".exit)
set +e
- "$t".mlibc-out > "$t".mlibc-stdout
+ "$t".mes-gcc-out > "$t".mes-gcc-stdout
m=$?
- cat "$t".mlibc-stdout
+ cat "$t".mes-gcc-stdout
set -e
[ $m = $r ]
if [ -f "$t".expect ]; then
- $DIFF -ub "$t".expect "$t".mlibc-stdout;
+ $DIFF -ub "$t".expect "$t".mes-gcc-stdout;
fi
fi
diff --git a/build.sh b/build.sh
index f5f89d01..79ad02d9 100755
--- a/build.sh
+++ b/build.sh
@@ -34,7 +34,7 @@ CC32=${CC32-$(command -v i686-unknown-linux-gnu-gcc)}
MESCC=${MESCC-$(command -v mescc)}
MES_SEED=${MES_SEED-../mes-seed}
GUILE=${GUILE-$(command -v guile)}
-MES_ARENA=${MES_ARENA-300000000}
+MES_ARENA=${MES_ARENA-100000000}
MES_DEBUG=${MES_DEBUG-1}
PREFIX=${PREFIX-/usr/local}
@@ -86,8 +86,8 @@ if [ -n "$CC" ]; then
fi
if [ -n "$CC32" ]; then
- sh build-aux/build-mlibc.sh
- cp src/mes.mlibc-out src/mes
+ sh build-aux/build-mes-gcc.sh
+ cp src/mes.mes-gcc-out src/mes
fi
sh build-aux/build-mes.sh
diff --git a/check.sh b/check.sh
index ce659332..6b721a8a 100755
--- a/check.sh
+++ b/check.sh
@@ -25,7 +25,7 @@ export BUILD_DEBUG
CC32=${CC32-$(command -v i686-unknown-linux-gnu-gcc)}
GUILE=${GUILE-guile}
MES=${MES-src/mes}
-MES_ARENA=${MES_ARENA-300000000}
+MES_ARENA=${MES_ARENA-100000000}
PREFIX=
if ! command -v $GUILE > /dev/null; then
diff --git a/include/30-test.i b/include/30-test.i
index 2f638f19..a9fbdb81 100644
--- a/include/30-test.i
+++ b/include/30-test.i
@@ -18,6 +18,8 @@
* along with Mes. If not, see .
*/
+#include
+
int test ();
int
diff --git a/install.sh b/install.sh
index f8b24e18..6304adb5 100755
--- a/install.sh
+++ b/install.sh
@@ -17,7 +17,7 @@ mkdir -p $MES_PREFIX/lib
cp scripts/mescc $PREFIX/bin/mescc
mkdir -p $MES_PREFIX
-tar -cf- doc guile include lib module scaffold stage0 | tar -xf- -C $MES_PREFIX
+tar -cf- doc guile include lib module scaffold | tar -xf- -C $MES_PREFIX
GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2}
DATADIR=${MODULEDIR-$PREFIX/share/mes}
diff --git a/lib/libc+tcc-gcc.c b/lib/libc+tcc-gcc.c
index 87bb0ac8..0716a2d4 100644
--- a/lib/libc+tcc-gcc.c
+++ b/lib/libc+tcc-gcc.c
@@ -29,12 +29,6 @@
#include
#include
-#include
-#include
-#include
-#include
-#include
-
int errno;
void
diff --git a/lib/libc+tcc-mes.c b/lib/libc+tcc-mes.c
index 5537c288..6949cb32 100644
--- a/lib/libc+tcc-mes.c
+++ b/lib/libc+tcc-mes.c
@@ -29,11 +29,6 @@
#include
#include
-#include
-#include
-#include
-#include
-
int errno;
void
diff --git a/lib/libc+tcc.c b/lib/libc+tcc.c
index 1e1e2939..1152e726 100644
--- a/lib/libc+tcc.c
+++ b/lib/libc+tcc.c
@@ -30,6 +30,23 @@
#include
#include
+#include
+
+#if __MESC__
+
+#include
+#include
+#include
+
+#else // !__MESC__
+
+#include
+#include
+#include
+#include
+
+#endif // !__MESC__
+
int
dlclose (void *handle)
{
@@ -108,7 +125,10 @@ ftell (FILE *stream)
int
fseek (FILE *stream, long offset, int whence)
{
- return lseek ((int)stream, offset, whence);
+ int pos = lseek ((int)stream, offset, whence);
+ if (pos >= 0)
+ return 0;
+ return -1;
}
int
diff --git a/lib/libc-gcc.c b/lib/libc-gcc.c
deleted file mode 100644
index 95c22667..00000000
--- a/lib/libc-gcc.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*-comment-start: "//";comment-end:""-*-
- * Mes --- Maxwell Equations of Software
- * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen
- *
- * This file is part of Mes.
- *
- * 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.
- *
- * 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 Mes. If not, see .
- */
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
diff --git a/lib/libc-mes.c b/lib/libc-mes.c
deleted file mode 100644
index 9c9b08d9..00000000
--- a/lib/libc-mes.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*-comment-start: "//";comment-end:""-*-
- * Mes --- Maxwell Equations of Software
- * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen
- *
- * This file is part of Mes.
- *
- * 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.
- *
- * 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 Mes. If not, see .
- */
-
-#include
-#include
-#include
-#include
-
-void _env ();
-
-#include
-#include
-#include
-#include
-#include
diff --git a/lib/libc-mini-gcc.c b/lib/libc-mini-gcc.c
deleted file mode 100644
index 5eff7e54..00000000
--- a/lib/libc-mini-gcc.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -*-comment-start: "//";comment-end:""-*-
- * Mes --- Maxwell Equations of Software
- * Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen
- *
- * This file is part of Mes.
- *
- * 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.
- *
- * 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 Mes. If not, see .
- */
-
-#include
-#include
diff --git a/lib/libc-mini-mes.c b/lib/libc-mini-mes.c
deleted file mode 100644
index bc1eadde..00000000
--- a/lib/libc-mini-mes.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -*-comment-start: "//";comment-end:""-*-
- * Mes --- Maxwell Equations of Software
- * Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen
- *
- * This file is part of Mes.
- *
- * 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.
- *
- * 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 Mes. If not, see .
- */
-
-#include
-#include
diff --git a/lib/libc-mini.c b/lib/libc-mini.c
index 23b07254..09293ccf 100644
--- a/lib/libc-mini.c
+++ b/lib/libc-mini.c
@@ -47,3 +47,13 @@ puts (char const* s)
write (1, s, i);
return 0;
}
+
+#if __MESC__
+
+#include
+
+#else // !__MESC__
+
+#include
+
+#endif // !__MESC__
diff --git a/lib/libc.c b/lib/libc.c
index 15afbcda..b50a1126 100644
--- a/lib/libc.c
+++ b/lib/libc.c
@@ -22,15 +22,45 @@
#include
#include
#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#if __MESC__
+
+#include
+
+#else // !__MESC__
+
+#include
+#include
+
+#include
+
+#endif // !__MESC__
+
+#include
+#include
int g_stdin = 0;
void _env ();
int
-eputc (int c)
+getchar ()
{
- return fdputc (c, STDERR);
+ return fdgetc (g_stdin);
+}
+
+int
+putchar (int c)
+{
+ write (STDOUT, (char*)&c, 1);
+ return 0;
}
int
@@ -62,10 +92,6 @@ fopen (char const* file_name, char const* mode)
/* Everything else is a read */
fd = open (file_name, 0, 0);
- /* Negative numbers are error codes */
- if (fd > 0)
- return 0;
-
return (FILE*)fd;
}
diff --git a/lib/libmes.c b/lib/libmes.c
index 9f09b6f3..fa67879d 100644
--- a/lib/libmes.c
+++ b/lib/libmes.c
@@ -19,6 +19,8 @@
*/
#include
+#include
+#include
int
isdigit (int c)
@@ -169,13 +171,6 @@ fdputc (int c, int fd)
return 0;
}
-int
-putchar (int c)
-{
- write (STDOUT, (char*)&c, 1);
- return 0;
-}
-
int
fdputs (char const* s, int fd)
{
@@ -192,8 +187,19 @@ fdungetc (int c, int fd)
return c;
}
+#if POSIX
+#define STDERR 2
int
-getchar ()
+eputs (char const* s)
{
- return fdgetc (g_stdin);
+ int i = strlen (s);
+ write (STDERR, s, i);
+ return 0;
+}
+#endif
+
+int
+eputc (int c)
+{
+ return fdputc (c, STDERR);
}
diff --git a/stage0/elf-0footer.hex2 b/lib/x86-mes/elf-0footer.hex2
similarity index 100%
rename from stage0/elf-0footer.hex2
rename to lib/x86-mes/elf-0footer.hex2
diff --git a/stage0/elf32-0header.hex2 b/lib/x86-mes/elf32-0header.hex2
similarity index 100%
rename from stage0/elf32-0header.hex2
rename to lib/x86-mes/elf32-0header.hex2
diff --git a/stage0/elf32-body-exit-42.hex2 b/lib/x86-mes/elf32-body-exit-42.hex2
similarity index 100%
rename from stage0/elf32-body-exit-42.hex2
rename to lib/x86-mes/elf32-body-exit-42.hex2
diff --git a/stage0/elf32-footer-single-main.hex2 b/lib/x86-mes/elf32-footer-single-main.hex2
similarity index 100%
rename from stage0/elf32-footer-single-main.hex2
rename to lib/x86-mes/elf32-footer-single-main.hex2
diff --git a/stage0/elf32-header.hex2 b/lib/x86-mes/elf32-header.hex2
similarity index 100%
rename from stage0/elf32-header.hex2
rename to lib/x86-mes/elf32-header.hex2
diff --git a/stage0/exit-42.c b/lib/x86-mes/exit-42.c
similarity index 100%
rename from stage0/exit-42.c
rename to lib/x86-mes/exit-42.c
diff --git a/stage0/x86.M1 b/lib/x86-mes/x86.M1
similarity index 100%
rename from stage0/x86.M1
rename to lib/x86-mes/x86.M1
diff --git a/module/mescc/mescc.scm b/module/mescc/mescc.scm
index 3e5b997c..49ee5671 100644
--- a/module/mescc/mescc.scm
+++ b/module/mescc/mescc.scm
@@ -100,8 +100,6 @@
hex2-file-name))
(define (mescc:link options)
- (define (library->hex2 o)
- (prefix-file options (string-append "lib/lib" o "-mes.o")))
(let* ((files (option-ref options '() '("a.c")))
(source-files (filter (disjoin .c? .E?) files))
(S-files (filter .S? files))
@@ -120,9 +118,9 @@
(list (infos->hex2 options hex2-file-name infos)))))
(libraries (filter-map (multi-opt 'library) options))
(libraries (if (pair? libraries) libraries '("c")))
- (hex2-libraries (map library->hex2 libraries))
+ (hex2-libraries (map (cut find-library options ".o" <>) libraries))
(hex2-files (append hex2-files hex2-libraries))
- (S-files (append S-files (map (cut replace-suffix <> ".S") hex2-libraries)))
+ (S-files (append S-files (map (cut find-library options ".S" <>) libraries)))
(debug-info? (option-ref options 'debug-info #f))
(S-files (cons (replace-suffix input-file-name ".S") S-files))
(elf-footer (and debug-info?
@@ -157,7 +155,7 @@
(command `(,M1
"--LittleEndian"
"--Architecture=1"
- "-f" ,(prefix-file options "stage0/x86.M1")
+ "-f" ,(arch-find options "x86.M1")
,@(append-map (cut list "-f" <>) M1-files)
"-o" ,hex2-file-name)))
(when verbose?
@@ -170,21 +168,20 @@
(elf-file-name (cond ((option-ref options 'output #f))
(else (replace-suffix input-file-name ""))))
(verbose? (option-ref options 'verbose #f))
- (elf-footer (or elf-footer (prefix-file options "stage0/elf32-footer-single-main.hex2")))
+ (elf-footer (or elf-footer (arch-find options "elf32-footer-single-main.hex2")))
(hex2 (or (getenv "HEX2") "hex2"))
(command `(,hex2
"--LittleEndian"
"--Architecture=1"
"--BaseAddress=0x1000000"
- "-f" ,(prefix-file options "stage0/elf32-header.hex2")
- "-f" ,(prefix-file options "lib/crt1.o")
+ "-f" ,(arch-find options "elf32-header.hex2")
+ "-f" ,(arch-find options "crt1.o")
,@(append-map (cut list "-f" <>) hex2-files)
"-f" ,elf-footer
"--exec_enable"
"-o" ,elf-file-name)))
(when verbose?
- (stderr "command=~s\n" command)
- (format (current-error-port) "~a\n" (string-join command)))
+ (stderr "~a\n" (string-join command)))
(and (zero? (apply system* command))
elf-file-name)))
@@ -196,7 +193,7 @@
(verbose? (option-ref options 'verbose #f))
(blood-elf (or (getenv "BLOOD_ELF") "blood-elf"))
(command `(,blood-elf
- "-f" ,(prefix-file options "stage0/x86.M1")
+ "-f" ,(arch-find options "x86.M1")
,@(append-map (cut list "-f" <>) M1-files)
"-o" ,M1-blood-elf-footer)))
(when verbose?
@@ -211,12 +208,27 @@
(base (if (pair? (cdr parts)) (drop-right parts 1))))
(string-append (string-join base ".") suffix)))
+(define (find-library options ext o)
+ (arch-find options (string-append "lib" o ext)))
+
+(define* (arch-find options file-name)
+ (let* ((path (cons (prefix-file options "lib")
+ (filter-map (multi-opt 'library-dir) options)))
+ (arch-file-name (string-append "x86-mes/" file-name))
+ (verbose? (option-ref options 'verbose #f)))
+ (when verbose?
+ (stderr "arch-find=~s\n" arch-file-name)
+ (stderr " path=~s\n" path)
+ (stderr " => ~s\n" (search-path path arch-file-name)))
+ (search-path path arch-file-name)))
+
(define (prefix-file options file-name)
(let ((prefix (option-ref options 'prefix "")))
(define (prefix-file o)
(if (string-null? prefix) o (string-append prefix "/" o)))
(prefix-file file-name)))
+
(define (multi-opt option-name) (lambda (o) (and (eq? (car o) option-name) (cdr o))))
(define (.c? o) (or (string-suffix? ".c" o)
diff --git a/scaffold/tests/77-pointer-assign.c b/scaffold/tests/77-pointer-assign.c
index ae7ce673..d34dc9df 100644
--- a/scaffold/tests/77-pointer-assign.c
+++ b/scaffold/tests/77-pointer-assign.c
@@ -57,16 +57,6 @@ add2 (void *ptab)
struct foo *hash_ident[10];
-#if !defined (__TINYC__)
-void *
-memset (void *s, int c, size_t n)
-{
- char *p = s;
- while (n--) *p++ = c;
- return s;
-}
-#endif
-
int
test ()
{
diff --git a/scaffold/tests/7j-strtoull.c b/scaffold/tests/7j-strtoull.c
index 27802ed2..a5985405 100644
--- a/scaffold/tests/7j-strtoull.c
+++ b/scaffold/tests/7j-strtoull.c
@@ -24,15 +24,6 @@
#include
#include
-#if !defined ( __TINYC__)
-unsigned long long
-strtoull (char const *p, char **end, int base)
-{
- *end = p;
- return abtoi (end, base);
-}
-#endif
-
int
test ()
{
@@ -43,10 +34,10 @@ test ()
if (strcmp (p, "foo\n")) return 2;
p = "2azar\n";
- n = strtoull (p, (char**)&p, 16);
+ n = strtoull (p, (char**)&p, 16);
if (n != 42) return 3;
eputs (p);
if (strcmp (p, "zar\n")) return 4;
-
+
return 0;
}
diff --git a/scripts/mescc b/scripts/mescc
index c9d7da92..36c5b01e 100755
--- a/scripts/mescc
+++ b/scripts/mescc
@@ -7,8 +7,10 @@ PREFIX=${PREFIX-@PREFIX@}
if [ "$PREFIX" = @PREFIX""@ -o ! -d "$PREFIX" ]
then
MES_PREFIX=${MES_PREFIX-$(cd $(dirname $0)/.. && pwd)}
- export MES_PREFIX
+else
+ MES_PREFIX=${MES_PREFIX-$PREFIX/share/mes}
fi
+export MES_PREFIX
mes_p=$(command -v mes)
if [ '(' -z "$mes_p" -a -z "$MES" ')' -o "$MES" = "guile" -o "$MES" = "mes.guile" ]; then
GODIR=${GODIR-@GODIR@}
@@ -50,7 +52,10 @@ fi
#:use-module (mescc mescc)
#:export (main))
-(define %prefix (if (string-prefix? "@PREFIX" "@PREFIX@") (or (getenv "MES_PREFIX") "") "@PREFIX@"))
+(define %prefix (or (getenv "MES_PREFIX")
+ (if (string-prefix? "@PREFIX" "@PREFIX@")
+ ""
+ "@PREFIX@/share/mes")))
(define %version (if (string-prefix? "@VERSION" "@VERSION@") "git"
"@VERSION@"))
@@ -76,6 +81,7 @@ fi
(debug-info (single-char #\g))
(help (single-char #\h))
(include (single-char #\I) (value #t))
+ (library-dir (single-char #\L) (value #t))
(library (single-char #\l) (value #t))
(preprocess (single-char #\E))
(output (single-char #\o) (value #t))
@@ -99,6 +105,7 @@ Usage: mescc [OPTION]... FILE...
-g add debug info [GDB, objdump] TODO: hex2 footer
-h, --help display this help and exit
-I DIR append DIR to include path
+ -L DIR append DIR to library path
-l LIBNAME link with LIBNAME
-o FILE write output to FILE
-S preprocess and compile only; do not assemble or link
diff --git a/src/mes.c b/src/mes.c
index f2c1e945..d98c613b 100644
--- a/src/mes.c
+++ b/src/mes.c
@@ -25,12 +25,8 @@
#include
//#define MES_MINI 1
-#if _POSIX_SOURCE
-int ARENA_SIZE = 300000000; // 32b: 4GiB, 64b: 8 GiB
-#else
int ARENA_SIZE = 200000; // 32b: 2MiB, 64b: 4 MiB
-#endif
-int MAX_ARENA_SIZE = 300000000;
+int MAX_ARENA_SIZE = 100000000;
int JAM_SIZE = 20000;
int GC_SAFETY = 2000;
diff --git a/stage0/elf32.hex3 b/stage0/elf32.hex3
deleted file mode 100644
index f937a3cb..00000000
--- a/stage0/elf32.hex3
+++ /dev/null
@@ -1,86 +0,0 @@
-;;; -*-scheme-*-
-;;; Copyright (C) 2016 Jeremiah Orians
-;;; Copyright (C) 2017 Jan (janneke) Nieuwenhuizen
-;;; This file is part of stage0.
-;;;
-;;; stage0 is free software: you an 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.
-;;;
-;;; stage0 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 stage0. If not, see .
-
-;;; elf32.hex3: 32 bit elf header in hex3
-
-;; ELF Header
-("*elf-header*"
-#X7F #x45 #X4C #x46 ; e_ident[EI_MAG0-3] ELF's magic number
-
-#x01 ; e_ident[EI_CLASS] Indicating 32 bit
-#x01 ; e_ident[EI_DATA] Indicating little endianness
-#x01 ; e_ident[EI_VERSION] Indicating original elf
-
-#x00 ; e_ident[EI_OSABI] Set at 0 because none cares
-#x00 ; e_ident[EI_ABIVERSION] See above
-
-#x00 #x00 #x00 #x00 #x00 #x00 #x00 ; e_ident[EI_PAD]
-#x02 #x00 ; e_type Indicating Executable
-#x03 #x00 ; e_machine Indicating AMD64
-#x01 #x00 #x00 #x00 ; e_version Indicating original elf
-
-#x54 #x80 #x04 #x08 ; e_entry Address of the entry point
-#x34 #x00 #x00 #x00 ; e_phoff Address of program header table
-#x00 #x00 #x00 #x00 ; e_shoff Address of section header table
-
-#x00 #x00 #x00 #x00 ; e_flags
-#x34 #x00 ; e_ehsize Indicating our 52 Byte header
-
-#x20 #x00 ; e_phentsize size of a program header table
-#x01 #x00 ; e_phnum number of entries in program table
-
-#x00 #x00 ; e_shentsize size of a section header table
-#x00 #x00 ; e_shnum number of entries in section table
-
-#x00 #x00 ; e_shstrndx index of the section names
-
-;; Program Header
-#x01 #x00 #x00 #x00 ; p_type
-#x00 #x00 #x00 #x00 ; p_offset
-
-#x00 #x80 #x04 #x08 ; p_vaddr
-#x00 #x80 #x04 #x08 ; p_physaddr
-
-;; FIXME!
-;;#x60 #x00 #x00 #x00 ; p_filesz
-;;#x60 #x00 #x00 #x00 ; p_memsz
-
-;#x65 #x01 #x00 #x00 ; p_filesz
-;#x65 #x01 #x00 #x00 ; p_memsz
-
-#xff #xff #x00 #x00 ; p_filesz
-#xff #xff #x00 #x00 ; p_memsz
-
-
-#x07 #x00 #x00 #x00 ; p_flags
-#x01 #x00 #x00 #x00 ; alignment
-
-;; _start
-; exit (42) -- works!
-;#xbb #x2a #x00 #x00 #x00 ; mov $42,%ebx
-;#xb8 #x01 #x00 #x00 #x00 ; mov $0x1,%eax
-;#xcd #x80 ; int $0x80
-)
-
-("shstr" 0
- #\. #\t #\e #\x #\t 0
- #\. #\d #\a #\t #\a 0
- #\. #\c #\o #\m #\m #\e #\n #\t 0
- #\. #\s #\h #\s #\t #\r #\t #\a #\b 0
- #\. #\s #\y #\m #\t #\a #\b 0
- #\. #\s #\t #\r #\t #\a #\b 0)