Compare commits
207 Commits
Author | SHA1 | Date |
---|---|---|
|
a3d16dcbff | |
|
6c1787fc99 | |
|
93f8f84710 | |
|
7598bbb083 | |
|
9c32a88c75 | |
|
8439519475 | |
|
16a19c5f69 | |
|
abd8ca216f | |
|
af853585ed | |
|
453246ebaf | |
|
8ca7058f7c | |
|
e14dfd8686 | |
|
468df4d363 | |
|
aeff8698cc | |
|
c5ae795773 | |
|
dbb97d786e | |
|
b56c5fd3d5 | |
|
b7857f11ec | |
|
1733b0186f | |
|
898190df5f | |
|
6720641493 | |
|
70c12c70b3 | |
|
477eee6e02 | |
|
71dad67103 | |
|
486e67ac02 | |
|
5c46bebd3d | |
|
68f8805f9d | |
|
ea1a31e12e | |
|
13cd0393ae | |
|
934ff3e7c5 | |
|
305a104ab0 | |
|
977d0fd3a7 | |
|
4e1de0de94 | |
|
762cf51a6a | |
|
600524e8d9 | |
|
b7bb734d89 | |
|
4affaafd17 | |
|
aff93403da | |
|
b5d5dba3fa | |
|
1d0e07c394 | |
|
673cf8f114 | |
|
9c2c95299e | |
|
d89836e9aa | |
|
c7406e7ac4 | |
|
f13ce3806a | |
|
12bf2f02be | |
|
d88789c969 | |
|
7329e92678 | |
|
27b32b8873 | |
|
7fe0c3b625 | |
|
eaac052167 | |
|
e5ee32f7dc | |
|
7a7a1e9791 | |
|
a64fd493f9 | |
|
c31ff8fa18 | |
|
bffc1b22d1 | |
|
45552d4822 | |
|
20b4f15751 | |
|
661cc9ed3b | |
|
682dc4b700 | |
|
553ccb4e1f | |
|
9f67b34d28 | |
|
558aceca68 | |
|
969876cdfc | |
|
e47ceb9544 | |
|
f4a74037aa | |
|
ec6a803b7b | |
|
52a0bc9c62 | |
|
7129959318 | |
|
74668e9138 | |
|
844e3fe9cb | |
|
aaf5d67fcd | |
|
3c19883873 | |
|
40c207a6af | |
|
da106c2ed8 | |
|
e21ee56574 | |
|
339b2cea40 | |
|
af354fc449 | |
|
e42c2ede12 | |
|
136ea63d27 | |
|
4fbdb05004 | |
|
4e0d9e1ac7 | |
|
c28605aec5 | |
|
ccb27b9705 | |
|
70ed273469 | |
|
18c416f307 | |
|
c187ccf197 | |
|
5e08960a42 | |
|
c2464bf24a | |
|
322e308ab1 | |
|
5e6b3a9662 | |
|
269959a816 | |
|
430667bd5e | |
|
fbd8bfe240 | |
|
e8a01aba29 | |
|
d07cc02f1f | |
|
691a992830 | |
|
f512623c08 | |
|
1aa60b94e5 | |
|
51a3cee8d1 | |
|
1c69559575 | |
|
182b568097 | |
|
766344d72e | |
|
0683302270 | |
|
9284df5ba3 | |
|
55b41ba11c | |
|
ec0380e702 | |
|
5abf71249c | |
|
bd6d933099 | |
|
986b3973bb | |
|
fe22f638ae | |
|
2ec586b773 | |
|
39cfcb11eb | |
|
d12c55581f | |
|
5df5c1987f | |
|
b00d100910 | |
|
b5c0369a3b | |
|
460ff0ebf5 | |
|
f29a6e4fc8 | |
|
4f39d09c25 | |
|
5209d82c1e | |
|
dc42ee180c | |
|
84386312ef | |
|
663adaf27f | |
|
4de45663b4 | |
|
7b0462b3a3 | |
|
02f8c37101 | |
|
249d33f750 | |
|
877283096f | |
|
8e1a455074 | |
|
8be4f26a74 | |
|
02494e0803 | |
|
75ead8fd95 | |
|
88011f4bf4 | |
|
571ec85112 | |
|
43f5c970a4 | |
|
1fbeb8395e | |
|
05513ae492 | |
|
3b4f1599f0 | |
|
7fbaf941e9 | |
|
bb0d074e1e | |
|
abc564ad49 | |
|
3ac200f6d3 | |
|
5ffb27f555 | |
|
84308146f4 | |
|
945b238a6a | |
|
e62009b02d | |
|
fcc4e483af | |
|
9c1a950cc6 | |
|
6f513dd2d7 | |
|
145d277a8b | |
|
4a6b3f990c | |
|
06ca28aafb | |
|
748a856b50 | |
|
e0ac5588ae | |
|
d5321636ef | |
|
64635bd1e1 | |
|
3bd3e5edfe | |
|
9b0e04c0e3 | |
|
42a18b3425 | |
|
0dbfe669fa | |
|
9d92e839c8 | |
|
57cd02ed0d | |
|
dacc55711c | |
|
a8f1b63519 | |
|
dae845aad4 | |
|
5c45d7d9de | |
|
8458e3680d | |
|
6c64b2fc0f | |
|
b77845ae9a | |
|
191de698a7 | |
|
fb4b8bb58c | |
|
99a9ab7411 | |
|
733b927c4c | |
|
299a9ea369 | |
|
8c85bccd56 | |
|
614c9146ba | |
|
612714b26b | |
|
d2d3844738 | |
|
54fca6cad9 | |
|
2c3e96bcfc | |
|
9553e33379 | |
|
8062b7cd21 | |
|
ae3e50f5b3 | |
|
5eaefeac38 | |
|
74e0ed606c | |
|
def9c6c330 | |
|
f0c1f4c4d2 | |
|
15d860d334 | |
|
4e092fdedd | |
|
68fc0e6ec6 | |
|
8fb2ab4439 | |
|
a810bc50e0 | |
|
f478ab3805 | |
|
6a8f67efa2 | |
|
ddfb34a40d | |
|
40e0cb11b9 | |
|
c340ca3e27 | |
|
e2da1c5c7b | |
|
9694354633 | |
|
cb79d8ffb1 | |
|
0727fd39cc | |
|
62205a9925 | |
|
80e08cf1ef | |
|
04c058fe5e | |
|
a288598a06 | |
|
a8e2cc86e9 |
|
@ -33,30 +33,45 @@
|
||||||
*.mini-hex2
|
*.mini-hex2
|
||||||
*.a
|
*.a
|
||||||
*.o
|
*.o
|
||||||
|
*.h.m2
|
||||||
|
*.c.m2
|
||||||
*.seed-out
|
*.seed-out
|
||||||
|
*.stderr
|
||||||
|
*.stdout
|
||||||
|
|
||||||
|
*.x86-out
|
||||||
|
|
||||||
|
/TAGS
|
||||||
|
|
||||||
|
/lib/x86-mes/0exit-42
|
||||||
|
/lib/x86-mes/exit-42
|
||||||
|
|
||||||
/lib/tests/*/[0-9a][0-9a-z]-*
|
/lib/tests/*/[0-9a][0-9a-z]-*
|
||||||
!/lib/tests/*/*.c
|
!/lib/tests/*/*.c
|
||||||
!/lib/tests/*/*.exit
|
!/lib/tests/*/*.exit
|
||||||
!/lib/tests/*/*.stdout
|
!/lib/tests/*/*.stdout
|
||||||
|
|
||||||
|
/scaffold/*.M1
|
||||||
|
/scaffold/*.m2
|
||||||
|
/scaffold/*.hex2
|
||||||
/scaffold/argv
|
/scaffold/argv
|
||||||
/scaffold/hello
|
/scaffold/hello
|
||||||
/scaffold/main
|
/scaffold/main
|
||||||
/scaffold/micro-mes
|
/scaffold/micro-mes
|
||||||
|
/scaffold/read
|
||||||
/scaffold/tiny-mes
|
/scaffold/tiny-mes
|
||||||
|
|
||||||
/scaffold/tests/[0-9a][0-9a-z]-*
|
/scaffold/argv-m2
|
||||||
/scaffold/tests/t.*
|
/scaffold/hello-m2
|
||||||
!/scaffold/tests/*.c
|
/scaffold/main-m2
|
||||||
!/scaffold/tests/*.exit
|
/scaffold/micro-mes-m2
|
||||||
!/scaffold/tests/*.stdout
|
/scaffold/read-m2
|
||||||
|
/scaffold/tiny-mes-m2
|
||||||
|
|
||||||
/.config.make
|
/.config.make
|
||||||
/.store
|
/.store
|
||||||
/.tarball-version
|
/.tarball-version
|
||||||
|
|
||||||
/out
|
|
||||||
?
|
?
|
||||||
?.mes
|
?.mes
|
||||||
\#*#
|
\#*#
|
||||||
|
|
8
AUTHORS
8
AUTHORS
|
@ -28,6 +28,10 @@ rain1
|
||||||
scaffold/tests/90-goto-var.c
|
scaffold/tests/90-goto-var.c
|
||||||
scaffold/tests/91-goto-array.c
|
scaffold/tests/91-goto-array.c
|
||||||
|
|
||||||
|
Nathalie Kopaczewski <natkopa@gmail.com>
|
||||||
|
Fast long devision
|
||||||
|
lib/div.c (__mesabi_log2i)
|
||||||
|
|
||||||
List of imported files
|
List of imported files
|
||||||
|
|
||||||
D A Gwyn
|
D A Gwyn
|
||||||
|
@ -56,7 +60,7 @@ PEG from Guile
|
||||||
mes/module/mes/peg/
|
mes/module/mes/peg/
|
||||||
|
|
||||||
Pmatch from Guile
|
Pmatch from Guile
|
||||||
mes/module/mes/pmatch.scm
|
mes/module/system/base/pmatch.scm
|
||||||
|
|
||||||
Pretty-print from Guile
|
Pretty-print from Guile
|
||||||
mes/module/mes/pretty-print.scm
|
mes/module/mes/pretty-print.scm
|
||||||
|
@ -81,7 +85,7 @@ lib/mach/mach-init.c
|
||||||
lib/mach/*.S
|
lib/mach/*.S
|
||||||
|
|
||||||
* legalese
|
* legalese
|
||||||
Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
Copying and distribution of this file, with or without modification,
|
||||||
are permitted in any medium without royalty provided the copyright
|
are permitted in any medium without royalty provided the copyright
|
||||||
|
|
10
README
10
README
|
@ -11,8 +11,8 @@ create a full source bootstrap as part of the [[http://bootstrappable.org][boots
|
||||||
effort for UNIX-like operating systems.
|
effort for UNIX-like operating systems.
|
||||||
|
|
||||||
The Scheme interpreter is written in ~5,000 LOC of simple C, and the C
|
The Scheme interpreter is written in ~5,000 LOC of simple C, and the C
|
||||||
compiler written in Scheme and these are mutual self-hosting. This
|
compiler written in Scheme and these are mutual self-hosting. Mes can
|
||||||
mes.c is [[https://github.com/oriansj/mes-m2][being simplified]] to be transpiled by [[https://github.com/oriansj/m2-planet][M2-Planet]].
|
now be bootstrapped by [[https://github.com/oriansj/m2-planet][M2-Planet]] and [[https://savannah.nongnu.org/projects/mescc-tools][Mescc-Tools]].
|
||||||
|
|
||||||
Mes has a Garbage Collector, a library of loadable Scheme modules--
|
Mes has a Garbage Collector, a library of loadable Scheme modules--
|
||||||
notably Dominique Boucher's [[https://github.com/schemeway/lalr-scm][LALR]], Pre-R6RS [[https://www.cs.indiana.edu/chezscheme/syntax-case/old-psyntax.html][portable syntax-case]] with
|
notably Dominique Boucher's [[https://github.com/schemeway/lalr-scm][LALR]], Pre-R6RS [[https://www.cs.indiana.edu/chezscheme/syntax-case/old-psyntax.html][portable syntax-case]] with
|
||||||
|
@ -67,14 +67,14 @@ General Public Licence version 3 or later. See the file [[file:COPYING][COPYING
|
||||||
[1] https://guix.gnu.org/blog/2019/guix-reduces-bootstrap-seed-by-50/
|
[1] https://guix.gnu.org/blog/2019/guix-reduces-bootstrap-seed-by-50/
|
||||||
[2] https://www.gnu.org/software/guix
|
[2] https://www.gnu.org/software/guix
|
||||||
[3] https://bootstrappable.org
|
[3] https://bootstrappable.org
|
||||||
[4] https://github.com/oriansj/mes-m2
|
[4] https://github.com/oriansj/m2-planet
|
||||||
[5] https://github.com/oriansj/m2-planet
|
[5] https://savannah.nongnu.org/projects/mescc-tools
|
||||||
[6] https://github.com/schemeway/lalr-scm
|
[6] https://github.com/schemeway/lalr-scm
|
||||||
[7] https://www.cs.indiana.edu/chezscheme/syntax-case/old-psyntax.html
|
[7] https://www.cs.indiana.edu/chezscheme/syntax-case/old-psyntax.html
|
||||||
[8] https://www.nongnu.org/nyacc
|
[8] https://www.nongnu.org/nyacc
|
||||||
[9] https://gitlab.com/janneke/tinycc
|
[9] https://gitlab.com/janneke/tinycc
|
||||||
[10] [[http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf]]
|
[10] [[http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf]]
|
||||||
[11] https://github.com/oriansj/stage0
|
[11] https://savannah.nongnu.org/projects/stage0
|
||||||
|
|
||||||
* Legalese
|
* Legalese
|
||||||
Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <[[mailto:janneke@gnu.org][janneke@gnu.org]]>
|
Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <[[mailto:janneke@gnu.org][janneke@gnu.org]]>
|
||||||
|
|
|
@ -135,7 +135,7 @@ maintainer-clean: distclean
|
||||||
rm -f doc/version.texi
|
rm -f doc/version.texi
|
||||||
|
|
||||||
TAGS:
|
TAGS:
|
||||||
etags ${srcdest}lib/*.c ${srcdest}lib/*/*.c ${srcdest}src/*.c ${srcdest}include/*.h ${srcdest}include/sys/*.h
|
etags ${srcdest}lib/*.c ${srcdest}lib/*/*.c ${srcdest}src/*.c ${srcdest}include/*.h ${srcdest}include/*/*.h ${srcdest}include/sys/*.h
|
||||||
|
|
||||||
all-go:
|
all-go:
|
||||||
${srcdest}build-aux/build-guile.sh
|
${srcdest}build-aux/build-guile.sh
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#! @SHELL@
|
#! @SHELL@
|
||||||
|
|
||||||
# GNU Mes --- Maxwell Equations of Software
|
# GNU Mes --- Maxwell Equations of Software
|
||||||
# Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
# Copyright © 2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
#
|
#
|
||||||
# This file is part of GNU Mes.
|
# This file is part of GNU Mes.
|
||||||
#
|
#
|
||||||
|
@ -18,6 +18,10 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
# along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
if test "$V" = 1 -o "$V" = 2; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
|
||||||
LANG=
|
LANG=
|
||||||
MES_ARENA=${MES_ARENA-20000000}
|
MES_ARENA=${MES_ARENA-20000000}
|
||||||
export MES_ARENA
|
export MES_ARENA
|
||||||
|
@ -31,8 +35,14 @@ MES_PREFIX=${MES_PREFIX-$PWD}
|
||||||
. ${srcdest}build-aux/configure-lib.sh
|
. ${srcdest}build-aux/configure-lib.sh
|
||||||
. ${srcdest}build-aux/cflags.sh
|
. ${srcdest}build-aux/cflags.sh
|
||||||
|
|
||||||
|
if test -n "@M2_PLANET@"; then
|
||||||
|
echo " KAEM kaem.run"
|
||||||
|
kaem --strict --verbose
|
||||||
|
fi
|
||||||
|
|
||||||
CPPFLAGS="-D HAVE_CONFIG_H=1 -I include"
|
CPPFLAGS="-D HAVE_CONFIG_H=1 -I include"
|
||||||
AM_CFLAGS=""
|
libdir=$PWD/lib
|
||||||
|
export libdir
|
||||||
mkdir -p mescc-lib
|
mkdir -p mescc-lib
|
||||||
cp config.sh mescc-lib/config.sh
|
cp config.sh mescc-lib/config.sh
|
||||||
cd mescc-lib
|
cd mescc-lib
|
||||||
|
@ -41,6 +51,7 @@ ln -sf ${srcdest}mes .
|
||||||
ln -sf ${srcdest}module .
|
ln -sf ${srcdest}module .
|
||||||
ln -sf ${srcdest}src .
|
ln -sf ${srcdest}src .
|
||||||
AM_CPPFLAGS="-D HAVE_CONFIG_H=1 -I ${srcdest}include -I ${srcdest}include/$mes_kernel/$mes_cpu"
|
AM_CPPFLAGS="-D HAVE_CONFIG_H=1 -I ${srcdest}include -I ${srcdest}include/$mes_kernel/$mes_cpu"
|
||||||
|
AM_CFLAGS="-L ${srcdest}lib"
|
||||||
|
|
||||||
mkdir -p $mes_cpu-mes
|
mkdir -p $mes_cpu-mes
|
||||||
$CC -c $AM_CPPFLAGS $CPPFLAGS $AM_CFLAGS $CFLAGS ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/crt1.c
|
$CC -c $AM_CPPFLAGS $CPPFLAGS $AM_CFLAGS $CFLAGS ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/crt1.c
|
||||||
|
@ -59,6 +70,18 @@ done
|
||||||
echo " AR $mes_cpu-mes/libc-mini.a"
|
echo " AR $mes_cpu-mes/libc-mini.a"
|
||||||
$AR crD $mes_cpu-mes/libc-mini.a $objects
|
$AR crD $mes_cpu-mes/libc-mini.a $objects
|
||||||
|
|
||||||
|
objects=
|
||||||
|
for c in $libmescc_SOURCES; do
|
||||||
|
o=$(basename $c .c).o
|
||||||
|
if test ! -e $o -o ${srcdest}$c -nt $o; then
|
||||||
|
echo " CC $c"
|
||||||
|
$CC -c $AM_CPPFLAGS $CPPFLAGS $AM_CFLAGS $CFLAGS ${srcdest}$c
|
||||||
|
fi
|
||||||
|
objects="$objects $o"
|
||||||
|
done
|
||||||
|
echo " AR $mes_cpu-mes/libmescc.a"
|
||||||
|
$AR crD $mes_cpu-mes/libmescc.a $objects
|
||||||
|
|
||||||
objects=
|
objects=
|
||||||
for c in $libc_SOURCES; do
|
for c in $libc_SOURCES; do
|
||||||
o=$(basename $c .c).o
|
o=$(basename $c .c).o
|
||||||
|
@ -86,6 +109,7 @@ $AR crD $mes_cpu-mes/libc+tcc.a $objects
|
||||||
cd ..
|
cd ..
|
||||||
srcdest=
|
srcdest=
|
||||||
CPPFLAGS="-D HAVE_CONFIG_H=1 -I ${srcdest}include -I ${srcdest}include/$mes_kernel/$mes_cpu"
|
CPPFLAGS="-D HAVE_CONFIG_H=1 -I ${srcdest}include -I ${srcdest}include/$mes_kernel/$mes_cpu"
|
||||||
|
AM_CFLAGS="-L ${srcdest}lib"
|
||||||
|
|
||||||
objects=
|
objects=
|
||||||
for c in $mes_SOURCES; do
|
for c in $mes_SOURCES; do
|
||||||
|
@ -98,7 +122,7 @@ for c in $mes_SOURCES; do
|
||||||
done
|
done
|
||||||
echo " CCLD bin/mes-mescc"
|
echo " CCLD bin/mes-mescc"
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
$CC -nostdlib -o bin/mes-mescc -L mescc-lib mescc-lib/crt1.o $objects -lc
|
$CC $AM_CFLAGS -nostdlib -o bin/mes-mescc -L mescc-lib mescc-lib/crt1.o $objects -lc -lmescc
|
||||||
cp bin/mes-mescc bin/mes
|
cp bin/mes-mescc bin/mes
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|
|
@ -30,24 +30,11 @@ fi
|
||||||
. ./config.sh
|
. ./config.sh
|
||||||
. ${srcdest}build-aux/trace.sh
|
. ${srcdest}build-aux/trace.sh
|
||||||
. ${srcdest}build-aux/cc.sh
|
. ${srcdest}build-aux/cc.sh
|
||||||
|
. ${srcdest}build-aux/configure-lib.sh
|
||||||
|
|
||||||
trap 'test -f .log && cat .log' EXIT
|
trap 'test -f .log && cat .log' EXIT
|
||||||
|
|
||||||
mes_sources="
|
for c in $mes_SOURCES; do
|
||||||
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
|
|
||||||
"
|
|
||||||
|
|
||||||
for c in $mes_sources; do
|
|
||||||
compile $c
|
compile $c
|
||||||
done
|
done
|
||||||
if test $mes_libc = system; then
|
if test $mes_libc = system; then
|
||||||
|
|
|
@ -49,5 +49,22 @@ for c in $libc_gnu_SOURCES; do
|
||||||
done
|
done
|
||||||
cp libc+gnu.c $mes_cpu-mes
|
cp libc+gnu.c $mes_cpu-mes
|
||||||
|
|
||||||
cp ${srcdest}lib/libtcc1.c $mes_cpu-mes
|
rm -f libtcc1.c
|
||||||
|
cat > libtcc1.c <<EOF
|
||||||
|
// Generated from Mes -- do not edit
|
||||||
|
// compiler: $compiler
|
||||||
|
// cpu: $mes_cpu
|
||||||
|
// bits: $mes_bits
|
||||||
|
// libc: $mes_libc
|
||||||
|
// kernel: $mes_kernel
|
||||||
|
// system: $mes_system
|
||||||
|
|
||||||
|
EOF
|
||||||
|
for c in $libtcc1_SOURCES; do
|
||||||
|
echo "// $c" >> libtcc1.c
|
||||||
|
cat ${srcdest}$c >> libtcc1.c
|
||||||
|
echo >> libtcc1.c
|
||||||
|
done
|
||||||
|
cp libtcc1.c $mes_cpu-mes
|
||||||
|
|
||||||
cp ${srcdest}lib/posix/getopt.c $mes_cpu-mes/libgetopt.c
|
cp ${srcdest}lib/posix/getopt.c $mes_cpu-mes/libgetopt.c
|
||||||
|
|
|
@ -97,11 +97,27 @@ fi
|
||||||
-I ${srcdest}include
|
-I ${srcdest}include
|
||||||
-I ${srcdest}include/$mes_kernel/$mes_cpu
|
-I ${srcdest}include/$mes_kernel/$mes_cpu
|
||||||
"
|
"
|
||||||
if test $compiler = gcc; then
|
if test "$compiler" != bootstrap; then
|
||||||
${SHELL} ${srcdest}build-aux/build-mes.sh
|
${SHELL} ${srcdest}build-aux/build-mes.sh
|
||||||
fi
|
fi
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if test -n "$M2_PLANET"; then
|
||||||
|
(
|
||||||
|
. ${srcdest}build-aux/trace.sh
|
||||||
|
if [ -z "$V" -o "$V" = 0 ]; then
|
||||||
|
__verbose=
|
||||||
|
else
|
||||||
|
__verbose=--verbose
|
||||||
|
fi
|
||||||
|
trace "KAEM scaffold/main.kaem" kaem --strict $__verbose -f scaffold/main.kaem
|
||||||
|
trace "KAEM scaffold/hello.kaem" kaem --strict $__verbose -f scaffold/hello.kaem
|
||||||
|
trace "KAEM scaffold/argv.kaem" kaem --strict $__verbose -f scaffold/argv.kaem
|
||||||
|
trace "KAEM scaffold/read.kaem" kaem --strict $__verbose -f scaffold/read.kaem
|
||||||
|
trace "KAEM kaem.run" kaem --strict $__verbose
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
(
|
(
|
||||||
mkdir -p mescc-lib
|
mkdir -p mescc-lib
|
||||||
cp config.sh mescc-lib
|
cp config.sh mescc-lib
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# GNU Mes --- Maxwell Equations of Software
|
# GNU Mes --- Maxwell Equations of Software
|
||||||
# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
# Copyright © 2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
#
|
#
|
||||||
# This file is part of GNU Mes.
|
# This file is part of GNU Mes.
|
||||||
#
|
#
|
||||||
|
@ -29,6 +29,11 @@ if test $mes_kernel = gnu; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AM_CFLAGS=
|
AM_CFLAGS=
|
||||||
|
if test "$V" = 2; then
|
||||||
|
AM_CFLAGS="$AM_CFLAGS -v"
|
||||||
|
elif test "$V" = 3; then
|
||||||
|
AM_CFLAGS="$AM_CFLAGS -v -v"
|
||||||
|
fi
|
||||||
|
|
||||||
if test $mes_libc = mes; then
|
if test $mes_libc = mes; then
|
||||||
AM_CFLAGS="$AM_CFLAGS
|
AM_CFLAGS="$AM_CFLAGS
|
||||||
|
|
|
@ -110,6 +110,7 @@ scaffold/boot/50-primitive-load.scm
|
||||||
scaffold/boot/53-closure-display.scm
|
scaffold/boot/53-closure-display.scm
|
||||||
scaffold/boot/60-let-syntax.scm
|
scaffold/boot/60-let-syntax.scm
|
||||||
scaffold/boot/call-cc.scm
|
scaffold/boot/call-cc.scm
|
||||||
|
scaffold/boot/gc.scm
|
||||||
scaffold/boot/memory.scm
|
scaffold/boot/memory.scm
|
||||||
scaffold/boot/numbers.scm
|
scaffold/boot/numbers.scm
|
||||||
"
|
"
|
||||||
|
|
|
@ -27,6 +27,7 @@ tests/boot.test
|
||||||
tests/read.test
|
tests/read.test
|
||||||
tests/srfi-0.test
|
tests/srfi-0.test
|
||||||
tests/macro.test
|
tests/macro.test
|
||||||
|
tests/gc.test
|
||||||
tests/perform.test
|
tests/perform.test
|
||||||
tests/base.test
|
tests/base.test
|
||||||
tests/quasiquote.test
|
tests/quasiquote.test
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
# GNU Mes --- Maxwell Equations of Software
|
# GNU Mes --- Maxwell Equations of Software
|
||||||
# Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
# Copyright © 2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
#
|
#
|
||||||
# This file is part of GNU Mes.
|
# This file is part of GNU Mes.
|
||||||
#
|
#
|
||||||
|
@ -85,6 +85,7 @@ lib/tests/scaffold/33-and-or.c
|
||||||
lib/tests/scaffold/34-pre-post.c
|
lib/tests/scaffold/34-pre-post.c
|
||||||
lib/tests/scaffold/35-compare-char.c
|
lib/tests/scaffold/35-compare-char.c
|
||||||
lib/tests/scaffold/36-compare-arithmetic.c
|
lib/tests/scaffold/36-compare-arithmetic.c
|
||||||
|
lib/tests/scaffold/36-compare-arithmetic-negative.c
|
||||||
lib/tests/scaffold/37-compare-assign.c
|
lib/tests/scaffold/37-compare-assign.c
|
||||||
lib/tests/scaffold/38-compare-call-2.c
|
lib/tests/scaffold/38-compare-call-2.c
|
||||||
lib/tests/scaffold/38-compare-call-3.c
|
lib/tests/scaffold/38-compare-call-3.c
|
||||||
|
@ -104,7 +105,9 @@ lib/tests/assert/50-assert.c
|
||||||
lib/tests/mes/50-itoa.c
|
lib/tests/mes/50-itoa.c
|
||||||
lib/tests/posix/50-getenv.c
|
lib/tests/posix/50-getenv.c
|
||||||
lib/tests/stdlib/50-malloc.c
|
lib/tests/stdlib/50-malloc.c
|
||||||
|
lib/tests/string/50-memcmp.c
|
||||||
lib/tests/string/50-strcmp.c
|
lib/tests/string/50-strcmp.c
|
||||||
|
lib/tests/string/50-strcmp-itoa.c
|
||||||
lib/tests/string/50-strcpy.c
|
lib/tests/string/50-strcpy.c
|
||||||
lib/tests/string/50-strncmp.c
|
lib/tests/string/50-strncmp.c
|
||||||
lib/tests/posix/50-open-read.c
|
lib/tests/posix/50-open-read.c
|
||||||
|
@ -113,6 +116,7 @@ lib/tests/scaffold/54-argc.c
|
||||||
lib/tests/scaffold/54-argv.c
|
lib/tests/scaffold/54-argv.c
|
||||||
lib/tests/scaffold/55-char-array.c
|
lib/tests/scaffold/55-char-array.c
|
||||||
lib/tests/scaffold/60-math.c
|
lib/tests/scaffold/60-math.c
|
||||||
|
lib/tests/scaffold/60-math-itoa.c
|
||||||
lib/tests/scaffold/61-array.c
|
lib/tests/scaffold/61-array.c
|
||||||
lib/tests/scaffold/62-array.c
|
lib/tests/scaffold/62-array.c
|
||||||
lib/tests/scaffold/63-struct.c
|
lib/tests/scaffold/63-struct.c
|
||||||
|
@ -189,6 +193,9 @@ lib/tests/scaffold/70-array-in-struct-init.c
|
||||||
lib/tests/scaffold/70-struct-short-enum-init.c
|
lib/tests/scaffold/70-struct-short-enum-init.c
|
||||||
lib/tests/scaffold/70-struct-post.c
|
lib/tests/scaffold/70-struct-post.c
|
||||||
lib/tests/scaffold/70-extern.c
|
lib/tests/scaffold/70-extern.c
|
||||||
|
lib/tests/scaffold/70-ternary-arithmetic-argument.c
|
||||||
|
lib/tests/scaffold/70-function-modulo.c
|
||||||
|
lib/tests/scaffold/70-or-argument.c
|
||||||
lib/tests/setjmp/80-setjmp.c
|
lib/tests/setjmp/80-setjmp.c
|
||||||
lib/tests/stdio/80-sscanf.c
|
lib/tests/stdio/80-sscanf.c
|
||||||
lib/tests/stdlib/80-qsort.c
|
lib/tests/stdlib/80-qsort.c
|
||||||
|
@ -238,6 +245,7 @@ lib/tests/scaffold/17-compare-unsigned-char-le.c
|
||||||
lib/tests/scaffold/17-compare-unsigned-short-le.c
|
lib/tests/scaffold/17-compare-unsigned-short-le.c
|
||||||
lib/tests/scaffold/66-local-char-array.c
|
lib/tests/scaffold/66-local-char-array.c
|
||||||
lib/tests/scaffold/72-typedef-struct-def-local.c
|
lib/tests/scaffold/72-typedef-struct-def-local.c
|
||||||
|
lib/tests/scaffold/70-ternary-arithmetic-argument.c
|
||||||
lib/tests/mes/90-abtod.c
|
lib/tests/mes/90-abtod.c
|
||||||
lib/tests/mes/90-dtoab.c
|
lib/tests/mes/90-dtoab.c
|
||||||
lib/tests/scaffold/90-goto-var.c
|
lib/tests/scaffold/90-goto-var.c
|
||||||
|
|
|
@ -35,8 +35,10 @@ GUIX="@GUIX@"
|
||||||
HELP2MAN="@HELP2MAN@"
|
HELP2MAN="@HELP2MAN@"
|
||||||
HEX2="@HEX2@"
|
HEX2="@HEX2@"
|
||||||
LDFLAGS=${LDFLAGS-"@LDFLAGS@"}
|
LDFLAGS=${LDFLAGS-"@LDFLAGS@"}
|
||||||
|
KAEM="@KAEM@"
|
||||||
MAKEINFO="@MAKEINFO@"
|
MAKEINFO="@MAKEINFO@"
|
||||||
M1="@M1@"
|
M1="@M1@"
|
||||||
|
M2_PLANET="@M2_PLANET@"
|
||||||
MES_FOR_BUILD="@MES_FOR_BUILD@"
|
MES_FOR_BUILD="@MES_FOR_BUILD@"
|
||||||
NYACC="@NYACC@"
|
NYACC="@NYACC@"
|
||||||
PACKAGE="@PACKAGE@"
|
PACKAGE="@PACKAGE@"
|
||||||
|
|
|
@ -37,8 +37,9 @@ lib/mes/oputs.c
|
||||||
if test $mes_libc = mes; then
|
if test $mes_libc = mes; then
|
||||||
libc_mini_shared_SOURCES="$libc_mini_shared_SOURCES
|
libc_mini_shared_SOURCES="$libc_mini_shared_SOURCES
|
||||||
lib/mes/globals.c
|
lib/mes/globals.c
|
||||||
lib/$mes_kernel/$mes_cpu-mes-$compiler/mini.c
|
|
||||||
lib/stdlib/exit.c
|
lib/stdlib/exit.c
|
||||||
|
lib/$mes_kernel/$mes_cpu-mes-$compiler/_exit.c
|
||||||
|
lib/$mes_kernel/$mes_cpu-mes-$compiler/_write.c
|
||||||
lib/stdlib/puts.c
|
lib/stdlib/puts.c
|
||||||
lib/string/strlen.c
|
lib/string/strlen.c
|
||||||
"
|
"
|
||||||
|
@ -80,13 +81,19 @@ fi
|
||||||
libmescc_SOURCES="
|
libmescc_SOURCES="
|
||||||
lib/mes/globals.c
|
lib/mes/globals.c
|
||||||
lib/linux/$mes_cpu-mes-$compiler/syscall-internal.c
|
lib/linux/$mes_cpu-mes-$compiler/syscall-internal.c
|
||||||
|
"
|
||||||
|
|
||||||
|
if test $mes_cpu = arm; then
|
||||||
|
libmescc_SOURCES="$libmescc_SOURCES
|
||||||
lib/mes/div.c
|
lib/mes/div.c
|
||||||
"
|
"
|
||||||
|
fi
|
||||||
|
|
||||||
libmes_SOURCES="
|
libmes_SOURCES="
|
||||||
$libc_mini_shared_SOURCES
|
$libc_mini_shared_SOURCES
|
||||||
lib/ctype/isnumber.c
|
lib/ctype/isnumber.c
|
||||||
lib/mes/abtol.c
|
lib/mes/abtol.c
|
||||||
|
lib/mes/cast.c
|
||||||
lib/mes/eputc.c
|
lib/mes/eputc.c
|
||||||
lib/mes/fdgetc.c
|
lib/mes/fdgetc.c
|
||||||
lib/mes/fdputc.c
|
lib/mes/fdputc.c
|
||||||
|
@ -107,6 +114,7 @@ if test $mes_libc = mes; then
|
||||||
lib/ctype/isdigit.c
|
lib/ctype/isdigit.c
|
||||||
lib/ctype/isspace.c
|
lib/ctype/isspace.c
|
||||||
lib/ctype/isxdigit.c
|
lib/ctype/isxdigit.c
|
||||||
|
lib/mes/assert_msg.c
|
||||||
lib/posix/write.c
|
lib/posix/write.c
|
||||||
lib/stdlib/atoi.c
|
lib/stdlib/atoi.c
|
||||||
"
|
"
|
||||||
|
@ -217,6 +225,15 @@ libtcc1_SOURCES="
|
||||||
lib/libtcc1.c
|
lib/libtcc1.c
|
||||||
"
|
"
|
||||||
|
|
||||||
|
if test $mes_cpu = arm; then
|
||||||
|
libtcc1_SOURCES="$libtcc1_SOURCES
|
||||||
|
lib/mes/div.c
|
||||||
|
lib/string/__memcpy.c
|
||||||
|
lib/string/__memmove.c
|
||||||
|
lib/string/__memset.c
|
||||||
|
"
|
||||||
|
fi
|
||||||
|
|
||||||
libc_tcc_SOURCES="
|
libc_tcc_SOURCES="
|
||||||
$libc_SOURCES
|
$libc_SOURCES
|
||||||
lib/ctype/islower.c
|
lib/ctype/islower.c
|
||||||
|
@ -414,6 +431,11 @@ lib/linux/symlink.c
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mes_SOURCES="
|
mes_SOURCES="
|
||||||
|
src/builtins.c
|
||||||
|
src/cc.c
|
||||||
|
src/core.c
|
||||||
|
src/display.c
|
||||||
|
src/eval-apply.c
|
||||||
src/gc.c
|
src/gc.c
|
||||||
src/hash.c
|
src/hash.c
|
||||||
src/lib.c
|
src/lib.c
|
||||||
|
@ -422,7 +444,9 @@ src/mes.c
|
||||||
src/module.c
|
src/module.c
|
||||||
src/posix.c
|
src/posix.c
|
||||||
src/reader.c
|
src/reader.c
|
||||||
|
src/stack.c
|
||||||
src/string.c
|
src/string.c
|
||||||
src/struct.c
|
src/struct.c
|
||||||
|
src/symbol.c
|
||||||
src/vector.c
|
src/vector.c
|
||||||
"
|
"
|
||||||
|
|
|
@ -47,6 +47,9 @@ cp $_v bin/mes ${DESTDIR}${bindir}/mes
|
||||||
if test -f bin/mes-gcc; then
|
if test -f bin/mes-gcc; then
|
||||||
cp $_v bin/mes-gcc ${DESTDIR}${bindir}/mes-gcc
|
cp $_v bin/mes-gcc ${DESTDIR}${bindir}/mes-gcc
|
||||||
fi
|
fi
|
||||||
|
if test -f bin/mes-m2; then
|
||||||
|
cp $_v bin/mes-m2 ${DESTDIR}${bindir}/mes-m2
|
||||||
|
fi
|
||||||
if test -f bin/mes-mescc; then
|
if test -f bin/mes-mescc; then
|
||||||
cp $_v bin/mes-mescc ${DESTDIR}${bindir}/mes-mescc
|
cp $_v bin/mes-mescc ${DESTDIR}${bindir}/mes-mescc
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -4,7 +4,7 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes
|
||||||
!#
|
!#
|
||||||
|
|
||||||
;;; GNU Mes --- Maxwell Equations of Software
|
;;; GNU Mes --- Maxwell Equations of Software
|
||||||
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
;;; Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
;;;
|
;;;
|
||||||
;;; mes-snarf.scm: This file is part of GNU Mes.
|
;;; mes-snarf.scm: This file is part of GNU Mes.
|
||||||
;;;
|
;;;
|
||||||
|
@ -85,8 +85,7 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes
|
||||||
(cut string-replace-string <> "_to_" "->")
|
(cut string-replace-string <> "_to_" "->")
|
||||||
(cut string-replace-suffix <> "_x" "!")
|
(cut string-replace-suffix <> "_x" "!")
|
||||||
(cut string-replace-suffix <> "_x_" "!-")
|
(cut string-replace-suffix <> "_x_" "!-")
|
||||||
(cut string-replace-suffix <> "_p" "?")
|
(cut string-replace-suffix <> "_p" "?"))
|
||||||
)
|
|
||||||
(function.name f))))
|
(function.name f))))
|
||||||
(if (not (string-suffix? "-" name)) name
|
(if (not (string-suffix? "-" name)) name
|
||||||
(string-append "core:" (string-drop-right name 1))))))
|
(string-append "core:" (string-drop-right name 1))))))
|
||||||
|
@ -105,19 +104,26 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes
|
||||||
(format #f "// CONSTANT ~a ~a\n" s i)
|
(format #f "// CONSTANT ~a ~a\n" s i)
|
||||||
(format #f "#define ~a ~a\n" s i)))
|
(format #f "#define ~a ~a\n" s i)))
|
||||||
|
|
||||||
|
(define (symbol->header s i)
|
||||||
|
(let ((c (string-upcase s)))
|
||||||
|
(string-append
|
||||||
|
(format #f "\n// CONSTANT ~a ~a\n" c i)
|
||||||
|
(format #f "#define ~a ~a\n" c i)
|
||||||
|
(format #f "struct scm *~a; /* ~a */\n" s i))))
|
||||||
|
|
||||||
(define (function->header f i)
|
(define (function->header f i)
|
||||||
(let* ((arity (or (assoc-ref (function.annotation f) 'arity)
|
(let* ((arity (or (assoc-ref (function.annotation f) 'arity)
|
||||||
(if (string-null? (function.formals f)) 0
|
(if (string-null? (function.formals f)) 0
|
||||||
(length (string-split (function.formals f) #\,)))))
|
(length (string-split (function.formals f) #\,)))))
|
||||||
(n (if (eq? arity 'n) -1 arity)))
|
(n (if (eq? arity 'n) -1 arity)))
|
||||||
(format #f "SCM ~a (~a);\n" (function.name f) (function.formals f))))
|
(format #f "struct scm *~a (~a);\n" (function.name f) (function.formals f))))
|
||||||
|
|
||||||
(define (function->source f i)
|
(define (function->source f i)
|
||||||
(let* ((arity (or (assoc-ref (function.annotation f) 'arity)
|
(let* ((arity (or (assoc-ref (function.annotation f) 'arity)
|
||||||
(if (string-null? (function.formals f)) 0
|
(if (string-null? (function.formals f)) 0
|
||||||
(length (string-split (function.formals f) #\,)))))
|
(length (string-split (function.formals f) #\,)))))
|
||||||
(n (if (eq? arity 'n) -1 arity)))
|
(n (if (eq? arity 'n) -1 arity)))
|
||||||
(format #f " a = init_builtin (builtin_type, ~s, ~a, &~a, a);\n" (function.name f) n (function.name f))))
|
(format #f " a = init_builtin (builtin_type, ~s, ~a, &~a, a);\n" (function-scm-name f) n (function.name f))))
|
||||||
|
|
||||||
(define (disjoin . predicates)
|
(define (disjoin . predicates)
|
||||||
(lambda (. arguments)
|
(lambda (. arguments)
|
||||||
|
@ -125,11 +131,11 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes
|
||||||
|
|
||||||
(define (snarf-symbols string)
|
(define (snarf-symbols string)
|
||||||
(let* ((lines (string-split string #\newline))
|
(let* ((lines (string-split string #\newline))
|
||||||
(symbols (filter (cut string-prefix? " init_symbol (" <>) lines)))
|
(symbols (filter (cut string-contains <> " = init_symbol (") lines)))
|
||||||
(define (line->symbol line)
|
(define (line->symbol line)
|
||||||
((compose
|
((compose
|
||||||
(lambda (s) (string-take s (string-index s #\,)))
|
string-trim-both
|
||||||
(cut string-drop <> (string-length " init_symbol (")))
|
(lambda (s) (string-take s (string-index s #\=))))
|
||||||
line))
|
line))
|
||||||
(map line->symbol symbols)))
|
(map line->symbol symbols)))
|
||||||
|
|
||||||
|
@ -144,20 +150,28 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes
|
||||||
(receive (function rest)
|
(receive (function rest)
|
||||||
(apply values (string-split-string line " "))
|
(apply values (string-split-string line " "))
|
||||||
(and function
|
(and function
|
||||||
(equal? (string-trim previous) "SCM")
|
(or (equal? (string-trim previous) "struct scm*")
|
||||||
|
(equal? (string-trim previous) "struct scm *"))
|
||||||
(not (string-null? function))
|
(not (string-null? function))
|
||||||
(not (string-prefix? "#" function))
|
(not (string-prefix? "#" function))
|
||||||
(not (string-prefix? "/" function))
|
(not (string-prefix? "/" function))
|
||||||
rest
|
rest
|
||||||
(receive (parameter-list annotation)
|
(receive (parameter-list annotation)
|
||||||
(apply values (string-split-string rest " ///"))
|
(apply values (string-split-string rest " /*:"))
|
||||||
(let* ((parameters (string-drop parameter-list 1))
|
(let* ((parameters (string-trim-both parameter-list))
|
||||||
|
(parameters (string-drop parameters 1))
|
||||||
(parameters (string-drop-right parameters 1))
|
(parameters (string-drop-right parameters 1))
|
||||||
|
(annotation (if (string? annotation) (string-trim-both annotation)
|
||||||
|
annotation))
|
||||||
|
(annotation (if (and (string? annotation)
|
||||||
|
(string-suffix? "*/" annotation))
|
||||||
|
(string-drop-right annotation 2)
|
||||||
|
annotation))
|
||||||
(formals (if (string-null? parameters) '()
|
(formals (if (string-null? parameters) '()
|
||||||
(string-split parameters #\,)))
|
(string-split parameters #\,)))
|
||||||
(formals (map string-trim formals)))
|
(formals (map string-trim formals)))
|
||||||
(and parameters
|
(and parameters
|
||||||
(let* ((non-SCM (filter (negate (cut string-prefix? "SCM" <>)) formals)))
|
(let* ((non-SCM (filter (negate (cut string-prefix? "struct scm" <>)) formals)))
|
||||||
(and (null? non-SCM)
|
(and (null? non-SCM)
|
||||||
(let ((annotation (and annotation (with-input-from-string annotation read))))
|
(let ((annotation (and annotation (with-input-from-string annotation read))))
|
||||||
(make-function function parameters annotation))))))))))
|
(make-function function parameters annotation))))))))))
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
ptr_once='s,([^N])(MACRO|NAME|VALUE) \(([^()]*)\),\1\3->\L\2,'
|
||||||
|
ptr_once='s,([^N])(BYTES|CAR|CDR|CLOSURE|CONTINUATION|LENGTH|MACRO|NAME|PORT|REF|STRING|STRUCT|TYPE|VALUE|VARIABLE|VECTOR) \(([^()]*)\),\1\3->\L\2,'
|
||||||
|
n_once='s,N(TYPE|CAR|CDR|LENGTH|VALUE|VECTOR) \(([^()]*)\),\2->\L\1,'
|
||||||
|
ncbytes='s,NC(BYTES) \(([^()]*)\),news_\L\1 (\2),'
|
||||||
|
cbytes='s,([^N])C(BYTES) \(([^()]*)\),\1cell_\L\2 (\3),'
|
||||||
|
cstring='s,C(STRING) \(([^()]*)\),cell_bytes (STRING (\2)),'
|
||||||
|
struct='s,SCM,struct scm *,g'
|
||||||
|
struct_scm_p='s,struct scm\* ?,struct scm *,g'
|
||||||
|
|
||||||
|
sed -ri \
|
||||||
|
-e 's,POINTER_CELLS=0,POINTER_CELLS=1', \
|
||||||
|
-e 's,#define POINTER_CELLS 0,#define POINTER_CELLS 1', \
|
||||||
|
-e "$ncbytes" \
|
||||||
|
-e "$cbytes" \
|
||||||
|
-e "$cstring" \
|
||||||
|
\
|
||||||
|
-e "$ncbytes" \
|
||||||
|
-e "$cbytes" \
|
||||||
|
-e "$cstring" \
|
||||||
|
\
|
||||||
|
-e "$ptr_once" \
|
||||||
|
-e "$ptr_once" \
|
||||||
|
-e "$ptr_once" \
|
||||||
|
-e 's,->\<struct\>,->structure,g' \
|
||||||
|
-e "$struct" \
|
||||||
|
-e "$struct_scm_p" \
|
||||||
|
\
|
||||||
|
-e "$n_once" \
|
||||||
|
-e "$n_once" \
|
||||||
|
\
|
||||||
|
-e 's,CAR \(([^()]*)\),\1->cdr,' \
|
||||||
|
-e 's,CAAR \(([^()]*)\),\1->car->car,' \
|
||||||
|
-e 's,CADR \(([^()]*)\),\1->cdr->car,' \
|
||||||
|
-e 's,CDAR \(([^()]*)\),\1->car->cdr,' \
|
||||||
|
-e 's,CDDR \(([^()]*)\),\1->cdr->cdr,' \
|
||||||
|
-e 's,CADAR \(([^()]*)\),\1->car->cdr->car,' \
|
||||||
|
-e 's,CADDR \(([^()]*)\),\1->cdr->cdr->car,' \
|
||||||
|
-e 's,CDADR \(([^()]*)\),\1->cdr->car->cdr,' \
|
||||||
|
-e 's,CDDDR \(([^()]*)\),\1->cdr->cdr->cdr,' \
|
||||||
|
-e 's,CDDAR \(([^()]*)\),\1->car->cdr->cdr,' \
|
||||||
|
-e 's,CDADAR \(([^()]*)\),\1->cdr->car->cdr->car,' \
|
||||||
|
\
|
||||||
|
include/mes/builtins.h \
|
||||||
|
include/mes/mes.h \
|
||||||
|
include/mes/symbols.h \
|
||||||
|
include/mes/builtins.h \
|
||||||
|
include/m2/lib.h \
|
||||||
|
src/builtins.c \
|
||||||
|
src/cc.c \
|
||||||
|
src/core.c \
|
||||||
|
src/display.c \
|
||||||
|
src/eval-apply.c \
|
||||||
|
src/gc.c \
|
||||||
|
src/hash.c \
|
||||||
|
src/lib.c \
|
||||||
|
src/m2.c \
|
||||||
|
src/math.c \
|
||||||
|
src/mes.c \
|
||||||
|
src/module.c \
|
||||||
|
src/posix.c \
|
||||||
|
src/reader.c \
|
||||||
|
src/stack.c \
|
||||||
|
src/string.c \
|
||||||
|
src/struct.c \
|
||||||
|
src/symbol.c \
|
||||||
|
src/vector.c \
|
||||||
|
src/test/gc.c \
|
||||||
|
simple.make \
|
|
@ -1,7 +1,7 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
# GNU Mes --- Maxwell Equations of Software
|
# GNU Mes --- Maxwell Equations of Software
|
||||||
# Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
#
|
#
|
||||||
# This file is part of GNU Mes.
|
# This file is part of GNU Mes.
|
||||||
#
|
#
|
||||||
|
@ -20,17 +20,43 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
. ${srcdest}build-aux/config.sh
|
srcdest=${srcdest-./}
|
||||||
|
. ${srcdest}config.sh
|
||||||
. ${srcdest}build-aux/trace.sh
|
. ${srcdest}build-aux/trace.sh
|
||||||
|
|
||||||
trace "SNARF$snarf gc.c" ${srcdest}build-aux/mes-snarf.scm src/gc.c
|
trace "SNARF$snarf builtins.c" ${srcdest}build-aux/mes-snarf.scm src/builtins.c
|
||||||
trace "SNARF$snarf hash.c" ${srcdest}build-aux/mes-snarf.scm src/hash.c
|
trace "SNARF$snarf core.c" ${srcdest}build-aux/mes-snarf.scm src/core.c
|
||||||
trace "SNARF$snarf lib.c" ${srcdest}build-aux/mes-snarf.scm src/lib.c
|
trace "SNARF$snarf display.c" ${srcdest}build-aux/mes-snarf.scm src/display.c
|
||||||
trace "SNARF$snarf math.c" ${srcdest}build-aux/mes-snarf.scm src/math.c
|
trace "SNARF$snarf eval-apply.c" ${srcdest}build-aux/mes-snarf.scm src/eval-apply.c
|
||||||
trace "SNARF$snarf mes.c" ${srcdest}build-aux/mes-snarf.scm src/mes.c
|
trace "SNARF$snarf gc.c" ${srcdest}build-aux/mes-snarf.scm src/gc.c
|
||||||
trace "SNARF$snarf module.c" ${srcdest}build-aux/mes-snarf.scm src/module.c
|
trace "SNARF$snarf hash.c" ${srcdest}build-aux/mes-snarf.scm src/hash.c
|
||||||
trace "SNARF$snarf posix.c" ${srcdest}build-aux/mes-snarf.scm src/posix.c
|
trace "SNARF$snarf lib.c" ${srcdest}build-aux/mes-snarf.scm src/lib.c
|
||||||
trace "SNARF$snarf reader.c" ${srcdest}build-aux/mes-snarf.scm src/reader.c
|
trace "SNARF$snarf math.c" ${srcdest}build-aux/mes-snarf.scm src/math.c
|
||||||
trace "SNARF$snarf strings.c" ${srcdest}build-aux/mes-snarf.scm src/string.c
|
trace "SNARF$snarf mes.c" ${srcdest}build-aux/mes-snarf.scm src/mes.c
|
||||||
trace "SNARF$snarf struct.c" ${srcdest}build-aux/mes-snarf.scm src/struct.c
|
trace "SNARF$snarf module.c" ${srcdest}build-aux/mes-snarf.scm src/module.c
|
||||||
trace "SNARF$snarf vector.c" ${srcdest}build-aux/mes-snarf.scm src/vector.c
|
trace "SNARF$snarf posix.c" ${srcdest}build-aux/mes-snarf.scm src/posix.c
|
||||||
|
trace "SNARF$snarf reader.c" ${srcdest}build-aux/mes-snarf.scm src/reader.c
|
||||||
|
trace "SNARF$snarf stack.c" ${srcdest}build-aux/mes-snarf.scm src/stack.c
|
||||||
|
trace "SNARF$snarf strings.c" ${srcdest}build-aux/mes-snarf.scm src/string.c
|
||||||
|
trace "SNARF$snarf struct.c" ${srcdest}build-aux/mes-snarf.scm src/struct.c
|
||||||
|
trace "SNARF$snarf symbol.c" ${srcdest}build-aux/mes-snarf.scm src/symbol.c
|
||||||
|
trace "SNARF$snarf vector.c" ${srcdest}build-aux/mes-snarf.scm src/vector.c
|
||||||
|
|
||||||
|
for i in src/*.symbols.h; do
|
||||||
|
n=$(basename $i .symbols.h)
|
||||||
|
echo "/* src/$n.c */"
|
||||||
|
cat $i
|
||||||
|
mv $i $(basename $i .symbols.h).s
|
||||||
|
done > s
|
||||||
|
|
||||||
|
for i in src/*.h; do
|
||||||
|
n=$(basename $i .h)
|
||||||
|
echo "/* src/$n.c */"
|
||||||
|
cat $i
|
||||||
|
done > h
|
||||||
|
|
||||||
|
for i in src/*.i; do
|
||||||
|
n=$(basename $i .i)
|
||||||
|
echo " /* src/$n.c */"
|
||||||
|
cat $i
|
||||||
|
done > c
|
||||||
|
|
|
@ -453,7 +453,9 @@ Some influential environment variables:
|
||||||
(deps (fold (lambda (program results)
|
(deps (fold (lambda (program results)
|
||||||
(cons (check-program-version program) results))
|
(cons (check-program-version program) results))
|
||||||
'()
|
'()
|
||||||
(list (make-dep "hex2")
|
(list (make-dep "kaem" #:version '(0 6) #:optional? #t)
|
||||||
|
(make-dep "M2-Planet" #:version '(0 1 3) #:optional? #t)
|
||||||
|
(make-dep "hex2")
|
||||||
(make-dep "M1")
|
(make-dep "M1")
|
||||||
(make-dep "blood-elf")
|
(make-dep "blood-elf")
|
||||||
(make-dep "diff" #:optional? #t)
|
(make-dep "diff" #:optional? #t)
|
||||||
|
@ -513,7 +515,7 @@ Some influential environment variables:
|
||||||
"))
|
"))
|
||||||
deps)
|
deps)
|
||||||
deps))
|
deps))
|
||||||
(mesc? (file-name "cc is MES C" deps))
|
(mescc? (file-name "cc is Mes C" deps))
|
||||||
(deps (if cc
|
(deps (if cc
|
||||||
(cons (check-compile-c cc (make-dep "cc is Tiny C" #:data "#if !defined (__TINYC__)
|
(cons (check-compile-c cc (make-dep "cc is Tiny C" #:data "#if !defined (__TINYC__)
|
||||||
#error no tinycc
|
#error no tinycc
|
||||||
|
@ -542,7 +544,7 @@ Some influential environment variables:
|
||||||
(cut member <> '("pc" "portbld" "unknown")))
|
(cut member <> '("pc" "portbld" "unknown")))
|
||||||
(cdr host-type-list))))
|
(cdr host-type-list))))
|
||||||
(mes-kernel (if (string-prefix? "freebsd" mes-kernel) "freebsd" mes-kernel))
|
(mes-kernel (if (string-prefix? "freebsd" mes-kernel) "freebsd" mes-kernel))
|
||||||
(mes-compiler (cond (gcc? "gcc") (tcc? "gcc") (else "mescc")))
|
(mes-compiler (cond (gcc? "gcc") (tcc? "gcc") (mescc? "mescc") (else "bootstrap")))
|
||||||
(mes-system (string-join (list mes-cpu mes-kernel "mes") "-"))
|
(mes-system (string-join (list mes-cpu mes-kernel "mes") "-"))
|
||||||
(bash (or (and (file-exists? "/bin/bash") "/bin/bash")
|
(bash (or (and (file-exists? "/bin/bash") "/bin/bash")
|
||||||
(file-name "bash" deps)
|
(file-name "bash" deps)
|
||||||
|
@ -636,6 +638,8 @@ See \"Porting GNU Mes\" in the manual, or try --with-courage\n" mes-system)
|
||||||
("@GUILE_LOAD_PATH@" . ,(string-join guile-load-path ":"))
|
("@GUILE_LOAD_PATH@" . ,(string-join guile-load-path ":"))
|
||||||
("@GUIX@" . ,(or (file-name "guix" deps) ""))
|
("@GUIX@" . ,(or (file-name "guix" deps) ""))
|
||||||
("@HELP2MAN@" . ,(or (file-name "help2man" deps) ""))
|
("@HELP2MAN@" . ,(or (file-name "help2man" deps) ""))
|
||||||
|
("@KAEM@" . ,(or (file-name "kaem" deps) ""))
|
||||||
|
("@M2_PLANET@" . ,(or (file-name "M2-Planet" deps) ""))
|
||||||
("@MAKEINFO@" . ,(or (file-name "makeinfo" deps) ""))
|
("@MAKEINFO@" . ,(or (file-name "makeinfo" deps) ""))
|
||||||
("@MES_FOR_BUILD@" . ,(or (file-name "mes" deps)
|
("@MES_FOR_BUILD@" . ,(or (file-name "mes" deps)
|
||||||
guile))
|
guile))
|
||||||
|
@ -656,8 +660,8 @@ See \"Porting GNU Mes\" in the manual, or try --with-courage\n" mes-system)
|
||||||
(cons (string-append "@" (variable-name o) "@") (or (format #f "~a" (dependency-file-name o)) "")))
|
(cons (string-append "@" (variable-name o) "@") (or (format #f "~a" (dependency-file-name o)) "")))
|
||||||
deps))))
|
deps))))
|
||||||
|
|
||||||
(unless cc
|
(unless (or cc m2-planet)
|
||||||
(format (current-error-port) "must supply a C compiler")
|
(format (current-error-port) "must supply C compiler or M2-Planet\n")
|
||||||
(exit 2))
|
(exit 2))
|
||||||
(for-each (lambda (o)
|
(for-each (lambda (o)
|
||||||
(let* ((src (string-append srcdest o))
|
(let* ((src (string-append srcdest o))
|
||||||
|
|
|
@ -77,6 +77,8 @@ GUILE=${GUILE-$(command -v guile)} || true
|
||||||
HEX2=${HEX2-$(command -v hex2)}
|
HEX2=${HEX2-$(command -v hex2)}
|
||||||
LDPFLAGS=${LDFLAGS-}
|
LDPFLAGS=${LDFLAGS-}
|
||||||
M1=${M1-$(command -v M1)}
|
M1=${M1-$(command -v M1)}
|
||||||
|
M2_PLANET=${M1-$(command -v M2-Planet)}
|
||||||
|
KAEM=${KAEM-$(command -v kaem)}
|
||||||
MES_FOR_BUILD=${MES_FOR_BUILD-$(command -v mes || command -v guile || echo mes)}
|
MES_FOR_BUILD=${MES_FOR_BUILD-$(command -v mes || command -v guile || echo mes)}
|
||||||
GIT=${GIT-$(command -v git)} || true
|
GIT=${GIT-$(command -v git)} || true
|
||||||
PERL=${PERL-$(command -v perl)} || true
|
PERL=${PERL-$(command -v perl)} || true
|
||||||
|
@ -167,6 +169,8 @@ subst () {
|
||||||
-e s,"@HEX2FLAGS@,$HEX2FLAGS,"\
|
-e s,"@HEX2FLAGS@,$HEX2FLAGS,"\
|
||||||
-e s,"@M1@,$M1,"\
|
-e s,"@M1@,$M1,"\
|
||||||
-e s,"@M1FLAGS@,$M1FLAGS,"\
|
-e s,"@M1FLAGS@,$M1FLAGS,"\
|
||||||
|
-e s,"@M2_PLANET@,$M2_PLANET,"\
|
||||||
|
-e s,"@KAEM@,$KAEM,"\
|
||||||
-e s,"@MES_FOR_BUILD@,$MES_FOR_BUILD,"\
|
-e s,"@MES_FOR_BUILD@,$MES_FOR_BUILD,"\
|
||||||
-e s,"@numbered_arch@,$numbered_arch,"\
|
-e s,"@numbered_arch@,$numbered_arch,"\
|
||||||
-e s,"@SHELL@,$SHELL,"\
|
-e s,"@SHELL@,$SHELL,"\
|
||||||
|
|
|
@ -876,8 +876,9 @@ The @var{option}s can be among the following:
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
|
|
||||||
@item --align
|
@item --align=@var{symbol}
|
||||||
align globals
|
align @var{symbol}, the default is @code{functions}; other valid values
|
||||||
|
are: @code{globals}.
|
||||||
|
|
||||||
@item --base-address=ADRRESS
|
@item --base-address=ADRRESS
|
||||||
use BaseAddress ADDRESS [0x1000000]
|
use BaseAddress ADDRESS [0x1000000]
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
(define-public mescc-tools
|
(define-public mescc-tools
|
||||||
(package
|
(package
|
||||||
(name "mescc-tools")
|
(name "mescc-tools")
|
||||||
(version "0.7.0")
|
(version "1.1.0")
|
||||||
(source
|
(source
|
||||||
(origin
|
(origin
|
||||||
(method url-fetch)
|
(method url-fetch)
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
(file-name (string-append name "-" version ".tar.gz"))
|
(file-name (string-append name "-" version ".tar.gz"))
|
||||||
(sha256
|
(sha256
|
||||||
(base32
|
(base32
|
||||||
"1p1ijia4rm3002f5sypidl9v5gq0mlch9b0n61rpxkdsaaxjqax3"))))
|
"12cjryqfd6m6j807pvhk7i4vr2q0jiibpfrpnq5s67iq9l4rrc6b"))))
|
||||||
(build-system gnu-build-system)
|
(build-system gnu-build-system)
|
||||||
(supported-systems
|
(supported-systems
|
||||||
'("aarch64-linux" "armhf-linux" "i686-linux" "x86_64-linux"))
|
'("aarch64-linux" "armhf-linux" "i686-linux" "x86_64-linux"))
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
(add-after 'unpack 'patch-prefix
|
(add-after 'unpack 'patch-prefix
|
||||||
(lambda _
|
(lambda _
|
||||||
(substitute* "sha256.sh"
|
(substitute* "sha256.sh"
|
||||||
(("/usr/bin/sha256sum") (which "sha256sum")))
|
(("\\$\\(which sha256sum\\)") (which "sha256sum")))
|
||||||
#t)))))
|
#t)))))
|
||||||
(synopsis "Tools for the full source bootstrapping process")
|
(synopsis "Tools for the full source bootstrapping process")
|
||||||
(description
|
(description
|
||||||
|
@ -89,6 +89,43 @@ get_machine.")
|
||||||
(home-page "https://savannah.nongnu.org/projects/mescc-tools")
|
(home-page "https://savannah.nongnu.org/projects/mescc-tools")
|
||||||
(license gpl3+)))
|
(license gpl3+)))
|
||||||
|
|
||||||
|
(define-public m2-planet
|
||||||
|
(package
|
||||||
|
(name "m2-planet")
|
||||||
|
(version "1.7.0")
|
||||||
|
(source
|
||||||
|
(origin
|
||||||
|
(method git-fetch)
|
||||||
|
(uri (git-reference
|
||||||
|
(url "https://github.com/oriansj/m2-planet.git")
|
||||||
|
(commit (string-append "Release_" version))))
|
||||||
|
(file-name (string-append name "-" version ".tar.gz"))
|
||||||
|
(sha256
|
||||||
|
(base32
|
||||||
|
"052j63xv44zqy7jndjw36jpyciz00p11d78w2rhy539qa5vdzad7"))))
|
||||||
|
(native-inputs
|
||||||
|
`(("mescc-tools" ,mescc-tools)))
|
||||||
|
(build-system gnu-build-system)
|
||||||
|
(arguments
|
||||||
|
`(#:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
|
||||||
|
(string-append "CC=" ,(cc-for-target)))
|
||||||
|
#:tests? #f
|
||||||
|
#:phases (modify-phases %standard-phases
|
||||||
|
(delete 'bootstrap)
|
||||||
|
(delete 'configure)
|
||||||
|
(add-after 'unpack 'patch-prefix
|
||||||
|
(lambda _
|
||||||
|
(substitute* "sha256.sh"
|
||||||
|
(("\\$\\(which sha256sum\\)") (which "sha256sum")))
|
||||||
|
#t)))))
|
||||||
|
(synopsis "The PLAtform NEutral Transpiler")
|
||||||
|
(description
|
||||||
|
"M2-Planet, The PLAtform NEutral Transpiler, when combined with
|
||||||
|
mescc-tools compiles a subset of the C language into working binaries
|
||||||
|
with introspective steps inbetween.")
|
||||||
|
(home-page "https://savannah.nongnu.org/projects/mescc-tools")
|
||||||
|
(license gpl3+)))
|
||||||
|
|
||||||
(define-public nyacc-0.99
|
(define-public nyacc-0.99
|
||||||
(package
|
(package
|
||||||
(name "nyacc")
|
(name "nyacc")
|
||||||
|
@ -192,6 +229,7 @@ extensive examples, including parsers for the Javascript and C99 languages.")
|
||||||
'()))
|
'()))
|
||||||
("graphviz" ,graphviz)
|
("graphviz" ,graphviz)
|
||||||
("help2man" ,help2man)
|
("help2man" ,help2man)
|
||||||
|
("m2-planet" ,m2-planet)
|
||||||
("perl" ,perl) ; build-aux/gitlog-to-changelog
|
("perl" ,perl) ; build-aux/gitlog-to-changelog
|
||||||
("texinfo" ,texinfo)))
|
("texinfo" ,texinfo)))
|
||||||
(arguments
|
(arguments
|
||||||
|
|
|
@ -20,34 +20,61 @@
|
||||||
#ifndef __MES_LINUX_X86_SYSCALL_H
|
#ifndef __MES_LINUX_X86_SYSCALL_H
|
||||||
#define __MES_LINUX_X86_SYSCALL_H 1
|
#define __MES_LINUX_X86_SYSCALL_H 1
|
||||||
|
|
||||||
// libc-mini
|
/* libc-mini */
|
||||||
// #define SYS_exit 0x01
|
#ifndef SYS_exit
|
||||||
// #define SYS_write 0x04
|
// CONSTANT SYS_exit 0x01
|
||||||
|
#define SYS_exit 0x01
|
||||||
|
#endif
|
||||||
|
#ifndef SYS_write
|
||||||
|
// CONSTANT SYS_write 0x04
|
||||||
|
#define SYS_write 0x04
|
||||||
|
#endif
|
||||||
|
|
||||||
// libc
|
/* libc */
|
||||||
|
// CONSTANT SYS_fork 0x02
|
||||||
#define SYS_fork 0x02
|
#define SYS_fork 0x02
|
||||||
|
// CONSTANT SYS_read 0x03
|
||||||
#define SYS_read 0x03
|
#define SYS_read 0x03
|
||||||
|
// CONSTANT SYS_open 0x05
|
||||||
#define SYS_open 0x05
|
#define SYS_open 0x05
|
||||||
|
// CONSTANT SYS_waitpid 0x07
|
||||||
#define SYS_waitpid 0x07
|
#define SYS_waitpid 0x07
|
||||||
|
// CONSTANT SYS_wait4 0x72
|
||||||
#define SYS_wait4 0x72
|
#define SYS_wait4 0x72
|
||||||
|
// CONSTANT SYS_execve 0x0b
|
||||||
#define SYS_execve 0x0b
|
#define SYS_execve 0x0b
|
||||||
|
// CONSTANT SYS_chmod 0x0f
|
||||||
#define SYS_chmod 0x0f
|
#define SYS_chmod 0x0f
|
||||||
|
// CONSTANT SYS_access 0x21
|
||||||
#define SYS_access 0x21
|
#define SYS_access 0x21
|
||||||
|
// CONSTANT SYS_brk 0x2d
|
||||||
#define SYS_brk 0x2d
|
#define SYS_brk 0x2d
|
||||||
|
// CONSTANT SYS_ioctl 0x36
|
||||||
#define SYS_ioctl 0x36
|
#define SYS_ioctl 0x36
|
||||||
|
// CONSTANT SYS_fsync 0x76
|
||||||
#define SYS_fsync 0x76
|
#define SYS_fsync 0x76
|
||||||
|
// CONSTANT SYS_getcwd 0xb7
|
||||||
// libc+tcc
|
|
||||||
#define SYS_close 0x06
|
|
||||||
#define SYS_time 0x0d
|
|
||||||
#define SYS_lseek 0x13
|
|
||||||
#define SYS_unlink 0x0a
|
|
||||||
#define SYS_rmdir 0x28
|
|
||||||
#define SYS_gettimeofday 0x4e
|
|
||||||
#define SYS_stat 0x6a
|
|
||||||
#define SYS_getcwd 0xb7
|
#define SYS_getcwd 0xb7
|
||||||
|
// CONSTANT SYS_dup 0x29
|
||||||
|
#define SYS_dup 0x29
|
||||||
|
// CONSTANT SYS_dup2 0x3f
|
||||||
|
#define SYS_dup2 0x3f
|
||||||
|
// CONSTANT SYS_unlink 0x0a
|
||||||
|
#define SYS_unlink 0x0a
|
||||||
|
// CONSTANT SYS_gettimeofday 0x4e
|
||||||
|
#define SYS_gettimeofday 0x4e
|
||||||
|
// CONSTANT SYS_clock_gettime 0x109
|
||||||
|
#define SYS_clock_gettime 0x109
|
||||||
|
// CONSTANT SYS_time 0x0d
|
||||||
|
#define SYS_time 0x0d
|
||||||
|
|
||||||
// libc+gnu
|
/* libc+tcc */
|
||||||
|
#define SYS_close 0x06
|
||||||
|
#define SYS_lseek 0x13
|
||||||
|
#define SYS_rmdir 0x28
|
||||||
|
#define SYS_stat 0x6a
|
||||||
|
|
||||||
|
/* libc+gnu */
|
||||||
|
|
||||||
#define SYS_chdir 0x0c
|
#define SYS_chdir 0x0c
|
||||||
#define SYS_link 0x09
|
#define SYS_link 0x09
|
||||||
|
@ -56,7 +83,6 @@
|
||||||
#define SYS_kill 0x25
|
#define SYS_kill 0x25
|
||||||
#define SYS_rename 0x26
|
#define SYS_rename 0x26
|
||||||
#define SYS_mkdir 0x27
|
#define SYS_mkdir 0x27
|
||||||
#define SYS_dup 0x29
|
|
||||||
#define SYS_pipe 0x2a
|
#define SYS_pipe 0x2a
|
||||||
#define SYS_getgid 0x2f
|
#define SYS_getgid 0x2f
|
||||||
#define SYS_signal 0x30
|
#define SYS_signal 0x30
|
||||||
|
@ -64,28 +90,26 @@
|
||||||
#define SYS_rt_sigaction 0xae
|
#define SYS_rt_sigaction 0xae
|
||||||
#define SYS_signal 0x30
|
#define SYS_signal 0x30
|
||||||
#define SYS_fcntl 0x37
|
#define SYS_fcntl 0x37
|
||||||
#define SYS_dup2 0x3f
|
|
||||||
#define SYS_getrusage 0x4d
|
#define SYS_getrusage 0x4d
|
||||||
#define SYS_lstat 0x6b
|
#define SYS_lstat 0x6b
|
||||||
#define SYS_setitimer 0x68
|
#define SYS_setitimer 0x68
|
||||||
#define SYS_fstat 0x6c
|
#define SYS_fstat 0x6c
|
||||||
#define SYS_nanosleep 0xa2
|
#define SYS_nanosleep 0xa2
|
||||||
#define SYS_getdents 0x8d
|
#define SYS_getdents 0x8d
|
||||||
#define SYS_clock_gettime 0x109
|
|
||||||
|
|
||||||
// bash
|
/* bash */
|
||||||
#define SYS_setuid 0x17
|
#define SYS_setuid 0x17
|
||||||
#define SYS_geteuid 0x31
|
#define SYS_geteuid 0x31
|
||||||
#define SYS_getegid 0x32
|
#define SYS_getegid 0x32
|
||||||
#define SYS_setgid 0x3e
|
#define SYS_setgid 0x3e
|
||||||
#define SYS_getppid 0x40
|
#define SYS_getppid 0x40
|
||||||
|
|
||||||
// make+POSIX
|
/* make+POSIX */
|
||||||
#define SYS_sigprocmask 0x7e
|
#define SYS_sigprocmask 0x7e
|
||||||
|
|
||||||
// tar
|
/* tar */
|
||||||
#define SYS_symlink 0x53
|
#define SYS_symlink 0x53
|
||||||
#define SYS_readlink 0x55
|
#define SYS_readlink 0x55
|
||||||
#define SYS_mknod 0x0e
|
#define SYS_mknod 0x0e
|
||||||
|
|
||||||
#endif // __MES_LINUX_X86_SYSCALL_H
|
#endif /* __MES_LINUX_X86_SYSCALL_H */
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __M2_LIB_H
|
||||||
|
#define __M2_LIB_H
|
||||||
|
|
||||||
|
char **environ;
|
||||||
|
int __stdin;
|
||||||
|
int __stdout;
|
||||||
|
int __stderr;
|
||||||
|
int errno;
|
||||||
|
|
||||||
|
// CONSTANT EOF 0xffffffff
|
||||||
|
// CONSTANT __FILEDES_MAX 512
|
||||||
|
|
||||||
|
char* cast_intp_to_charp (int *i);
|
||||||
|
char* cast_long_to_charp (long i);
|
||||||
|
long cast_charp_to_long (char const *);
|
||||||
|
long cast_int_to_long (int i);
|
||||||
|
long cast_voidp_to_long (void const *);
|
||||||
|
|
||||||
|
char *itoa (int number);
|
||||||
|
char *ltoa (long number);
|
||||||
|
int __ungetc_p (int filedes);
|
||||||
|
int eputs (char *s);
|
||||||
|
int oputs (char *s);
|
||||||
|
int puts (char *s);
|
||||||
|
size_t strlen (char *s);
|
||||||
|
ssize_t _write ();
|
||||||
|
ssize_t write (int filedes, void *buffer, size_t size);
|
||||||
|
void __ungetc_clear (int filedes);
|
||||||
|
void __ungetc_init ();
|
||||||
|
void __ungetc_set (int filedes, int c);
|
||||||
|
|
||||||
|
struct timezone
|
||||||
|
{
|
||||||
|
int tz_minuteswest;
|
||||||
|
int tz_dsttime;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct timespec
|
||||||
|
{
|
||||||
|
long tv_sec;
|
||||||
|
long tv_nsec;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct timeval
|
||||||
|
{
|
||||||
|
long tv_sec;
|
||||||
|
long tv_usec;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __M2_LIB_H */
|
|
@ -21,396 +21,160 @@
|
||||||
#ifndef __MES_BUILTINS_H
|
#ifndef __MES_BUILTINS_H
|
||||||
#define __MES_BUILTINS_H
|
#define __MES_BUILTINS_H
|
||||||
|
|
||||||
// src/gc.mes
|
/* src/builtins.c */
|
||||||
SCM gc_check ();
|
struct scm *make_builtin (struct scm *builtin_type, struct scm *name, struct scm *arity, struct scm *function);
|
||||||
SCM gc ();
|
struct scm *builtin_name (struct scm *builtin);
|
||||||
// src/hash.mes
|
struct scm *builtin_arity (struct scm *builtin);
|
||||||
SCM hashq (SCM x, SCM size);
|
struct scm *builtin_p (struct scm *x);
|
||||||
SCM hash (SCM x, SCM size);
|
struct scm *builtin_printer (struct scm *builtin);
|
||||||
SCM hashq_get_handle (SCM table, SCM key, SCM dflt);
|
/* src/core.c */
|
||||||
SCM hashq_ref (SCM table, SCM key, SCM dflt);
|
struct scm *car (struct scm *x);
|
||||||
SCM hash_ref (SCM table, SCM key, SCM dflt);
|
struct scm *cdr (struct scm *x);
|
||||||
SCM hashq_set_x (SCM table, SCM key, SCM value);
|
struct scm *list (struct scm *x);
|
||||||
SCM hash_set_x (SCM table, SCM key, SCM value);
|
struct scm *null_p (struct scm *x);
|
||||||
SCM hash_table_printer (SCM table);
|
struct scm *eq_p (struct scm *x, struct scm *y);
|
||||||
SCM make_hash_table (SCM x);
|
struct scm *values (struct scm *x);
|
||||||
// src/lib.mes
|
struct scm *acons (struct scm *key, struct scm *value, struct scm *alist);
|
||||||
SCM procedure_name_ (SCM x);
|
struct scm *length (struct scm *x);
|
||||||
SCM display_ (SCM x);
|
struct scm *error (struct scm *key, struct scm *x);
|
||||||
SCM display_error_ (SCM x);
|
struct scm *append2 (struct scm *x, struct scm *y);
|
||||||
SCM display_port_ (SCM x, SCM p);
|
struct scm *append_reverse (struct scm *x, struct scm *y);
|
||||||
SCM write_ (SCM x);
|
struct scm *reverse_x_ (struct scm *x, struct scm *t);
|
||||||
SCM write_error_ (SCM x);
|
struct scm *assq (struct scm *x, struct scm *a);
|
||||||
SCM write_port_ (SCM x, SCM p);
|
struct scm *assoc (struct scm *x, struct scm *a);
|
||||||
SCM exit_ (SCM x);
|
/* src/display.c */
|
||||||
SCM frame_printer (SCM frame);
|
struct scm *display_ (struct scm *x);
|
||||||
SCM make_stack (SCM stack);
|
struct scm *display_error_ (struct scm *x);
|
||||||
SCM stack_length (SCM stack);
|
struct scm *display_port_ (struct scm *x, struct scm *p);
|
||||||
SCM stack_ref (SCM stack, SCM index);
|
struct scm *write_ (struct scm *x);
|
||||||
SCM xassq (SCM x, SCM a);
|
struct scm *write_error_ (struct scm *x);
|
||||||
SCM memq (SCM x, SCM a);
|
struct scm *write_port_ (struct scm *x, struct scm *p);
|
||||||
SCM equal2_p (SCM a, SCM b);
|
/* src/eval-apply.c */
|
||||||
SCM last_pair (SCM x);
|
struct scm *pairlis (struct scm *x, struct scm *y, struct scm *a);
|
||||||
SCM pair_p (SCM x);
|
struct scm *set_car_x (struct scm *x, struct scm *e);
|
||||||
// src/math.mes
|
struct scm *set_cdr_x (struct scm *x, struct scm *e);
|
||||||
SCM greater_p (SCM x);
|
struct scm *set_env_x (struct scm *x, struct scm *e, struct scm *a);
|
||||||
SCM less_p (SCM x);
|
struct scm *add_formals (struct scm *formals, struct scm *x);
|
||||||
SCM is_p (SCM x);
|
struct scm *eval_apply ();
|
||||||
SCM minus (SCM x);
|
/* src/gc.c */
|
||||||
SCM plus (SCM x);
|
struct scm *cons (struct scm *x, struct scm *y);
|
||||||
SCM divide (SCM x);
|
struct scm *gc_check ();
|
||||||
SCM modulo (SCM a, SCM b);
|
struct scm *gc ();
|
||||||
SCM multiply (SCM x);
|
/* src/hash.c */
|
||||||
SCM logand (SCM x);
|
struct scm *hashq (struct scm *x, struct scm *size);
|
||||||
SCM logior (SCM x);
|
struct scm *hash (struct scm *x, struct scm *size);
|
||||||
SCM lognot (SCM x);
|
struct scm *hashq_get_handle (struct scm *table, struct scm *key, struct scm *dflt);
|
||||||
SCM logxor (SCM x);
|
struct scm *hashq_ref (struct scm *table, struct scm *key, struct scm *dflt);
|
||||||
SCM ash (SCM n, SCM count);
|
struct scm *hash_ref (struct scm *table, struct scm *key, struct scm *dflt);
|
||||||
// src/mes.mes
|
struct scm *hashq_set_x (struct scm *table, struct scm *key, struct scm *value);
|
||||||
SCM make_cell_ (SCM type, SCM car, SCM cdr);
|
struct scm *hash_set_x (struct scm *table, struct scm *key, struct scm *value);
|
||||||
SCM type_ (SCM x);
|
struct scm *hash_table_printer (struct scm *table);
|
||||||
SCM car_ (SCM x);
|
struct scm *make_hash_table (struct scm *x);
|
||||||
SCM cdr_ (SCM x);
|
/* src/lib.c */
|
||||||
SCM arity_ (SCM x);
|
struct scm *type_ (struct scm *x);
|
||||||
SCM cons (SCM x, SCM y);
|
struct scm *car_ (struct scm *x);
|
||||||
SCM car (SCM x);
|
struct scm *cdr_ (struct scm *x);
|
||||||
SCM cdr (SCM x);
|
struct scm *xassq (struct scm *x, struct scm *a);
|
||||||
SCM list (SCM x);
|
struct scm *memq (struct scm *x, struct scm *a);
|
||||||
SCM null_p (SCM x);
|
struct scm *equal2_p (struct scm *a, struct scm *b);
|
||||||
SCM eq_p (SCM x, SCM y);
|
struct scm *last_pair (struct scm *x);
|
||||||
SCM values (SCM x);
|
struct scm *pair_p (struct scm *x);
|
||||||
SCM acons (SCM key, SCM value, SCM alist);
|
struct scm *char_to_integer (struct scm *x);
|
||||||
SCM length (SCM x);
|
struct scm *integer_to_char (struct scm *x);
|
||||||
SCM error (SCM key, SCM x);
|
/* src/math.c */
|
||||||
SCM append2 (SCM x, SCM y);
|
struct scm *greater_p (struct scm *x);
|
||||||
SCM append_reverse (SCM x, SCM y);
|
struct scm *less_p (struct scm *x);
|
||||||
SCM reverse_x_ (SCM x, SCM t);
|
struct scm *is_p (struct scm *x);
|
||||||
SCM pairlis (SCM x, SCM y, SCM a);
|
struct scm *minus (struct scm *x);
|
||||||
SCM call (SCM fn, SCM x);
|
struct scm *plus (struct scm *x);
|
||||||
SCM assq (SCM x, SCM a);
|
struct scm *divide (struct scm *x);
|
||||||
SCM assoc (SCM x, SCM a);
|
struct scm *modulo (struct scm *a, struct scm *b);
|
||||||
SCM set_car_x (SCM x, SCM e);
|
struct scm *multiply (struct scm *x);
|
||||||
SCM set_cdr_x (SCM x, SCM e);
|
struct scm *logand (struct scm *x);
|
||||||
SCM set_env_x (SCM x, SCM e, SCM a);
|
struct scm *logior (struct scm *x);
|
||||||
SCM macro_get_handle (SCM name);
|
struct scm *lognot (struct scm *x);
|
||||||
SCM add_formals (SCM formals, SCM x);
|
struct scm *logxor (struct scm *x);
|
||||||
SCM eval_apply ();
|
struct scm *ash (struct scm *n, struct scm *count);
|
||||||
SCM make_builtin_type ();
|
/* src/module.c */
|
||||||
SCM make_builtin (SCM builtin_type, SCM name, SCM arity, SCM function);
|
struct scm *make_module_type ();
|
||||||
SCM builtin_arity (SCM builtin);
|
struct scm *module_printer (struct scm *module);
|
||||||
SCM builtin_p (SCM x);
|
struct scm *module_variable (struct scm *module, struct scm *name);
|
||||||
SCM builtin_printer (SCM builtin);
|
struct scm *module_ref (struct scm *module, struct scm *name);
|
||||||
// CONSTANT cell_nil 1
|
struct scm *module_define_x (struct scm *module, struct scm *name, struct scm *value);
|
||||||
#define cell_nil 1
|
/* src/posix.c */
|
||||||
// CONSTANT cell_f 2
|
struct scm *exit_ (struct scm *x);
|
||||||
#define cell_f 2
|
struct scm *peek_byte ();
|
||||||
// CONSTANT cell_t 3
|
struct scm *read_byte ();
|
||||||
#define cell_t 3
|
struct scm *unread_byte (struct scm *i);
|
||||||
// CONSTANT cell_dot 4
|
struct scm *peek_char ();
|
||||||
#define cell_dot 4
|
struct scm *read_char (struct scm *port);
|
||||||
// CONSTANT cell_arrow 5
|
struct scm *unread_char (struct scm *i);
|
||||||
#define cell_arrow 5
|
struct scm *write_char (struct scm *i);
|
||||||
// CONSTANT cell_undefined 6
|
struct scm *write_byte (struct scm *x);
|
||||||
#define cell_undefined 6
|
struct scm *getenv_ (struct scm *s);
|
||||||
// CONSTANT cell_unspecified 7
|
struct scm *setenv_ (struct scm *s, struct scm *v);
|
||||||
#define cell_unspecified 7
|
struct scm *access_p (struct scm *file_name, struct scm *mode);
|
||||||
// CONSTANT cell_closure 8
|
struct scm *current_input_port ();
|
||||||
#define cell_closure 8
|
struct scm *open_input_file (struct scm *file_name);
|
||||||
// CONSTANT cell_circular 9
|
struct scm *open_input_string (struct scm *string);
|
||||||
#define cell_circular 9
|
struct scm *set_current_input_port (struct scm *port);
|
||||||
// CONSTANT cell_begin 10
|
struct scm *current_output_port ();
|
||||||
#define cell_begin 10
|
struct scm *current_error_port ();
|
||||||
// CONSTANT cell_call_with_current_continuation 11
|
struct scm *open_output_file (struct scm *x);
|
||||||
#define cell_call_with_current_continuation 11
|
struct scm *set_current_output_port (struct scm *port);
|
||||||
// CONSTANT cell_vm_apply 12
|
struct scm *set_current_error_port (struct scm *port);
|
||||||
#define cell_vm_apply 12
|
struct scm *chmod_ (struct scm *file_name, struct scm *mode);
|
||||||
// CONSTANT cell_vm_apply2 13
|
struct scm *isatty_p (struct scm *port);
|
||||||
#define cell_vm_apply2 13
|
struct scm *primitive_fork ();
|
||||||
// CONSTANT cell_vm_begin 14
|
struct scm *execl_ (struct scm *file_name, struct scm *args);
|
||||||
#define cell_vm_begin 14
|
struct scm *waitpid_ (struct scm *pid, struct scm *options);
|
||||||
// CONSTANT cell_vm_begin_eval 15
|
struct scm *current_time ();
|
||||||
#define cell_vm_begin_eval 15
|
struct scm *gettimeofday_ ();
|
||||||
// CONSTANT cell_vm_begin_expand 16
|
struct scm *get_internal_run_time ();
|
||||||
#define cell_vm_begin_expand 16
|
struct scm *getcwd_ ();
|
||||||
// CONSTANT cell_vm_begin_expand_eval 17
|
struct scm *dup_ (struct scm *port);
|
||||||
#define cell_vm_begin_expand_eval 17
|
struct scm *dup2_ (struct scm *old, struct scm *new);
|
||||||
// CONSTANT cell_vm_begin_expand_macro 18
|
struct scm *delete_file (struct scm *file_name);
|
||||||
#define cell_vm_begin_expand_macro 18
|
/* src/reader.c */
|
||||||
// CONSTANT cell_vm_begin_expand_primitive_load 19
|
struct scm *read_input_file_env_ (struct scm *e, struct scm *a);
|
||||||
#define cell_vm_begin_expand_primitive_load 19
|
struct scm *read_input_file_env (struct scm *a);
|
||||||
// CONSTANT cell_vm_begin_primitive_load 20
|
struct scm *read_env (struct scm *a);
|
||||||
#define cell_vm_begin_primitive_load 20
|
struct scm *reader_read_sexp (struct scm *c, struct scm *s, struct scm *a);
|
||||||
// CONSTANT cell_vm_begin_read_input_file 21
|
struct scm *reader_read_character ();
|
||||||
#define cell_vm_begin_read_input_file 21
|
struct scm *reader_read_binary ();
|
||||||
// CONSTANT cell_vm_call_with_current_continuation2 22
|
struct scm *reader_read_octal ();
|
||||||
#define cell_vm_call_with_current_continuation2 22
|
struct scm *reader_read_hex ();
|
||||||
// CONSTANT cell_vm_call_with_values2 23
|
struct scm *reader_read_string ();
|
||||||
#define cell_vm_call_with_values2 23
|
/* src/stack.c */
|
||||||
// CONSTANT cell_vm_eval 24
|
struct scm *frame_printer (struct scm *frame);
|
||||||
#define cell_vm_eval 24
|
struct scm *make_stack (struct scm *stack);
|
||||||
// CONSTANT cell_vm_eval2 25
|
struct scm *stack_length (struct scm *stack);
|
||||||
#define cell_vm_eval2 25
|
struct scm *stack_ref (struct scm *stack, struct scm *index);
|
||||||
// CONSTANT cell_vm_eval_check_func 26
|
/* src/string.c */
|
||||||
#define cell_vm_eval_check_func 26
|
struct scm *string_equal_p (struct scm *a, struct scm *b);
|
||||||
// CONSTANT cell_vm_eval_define 27
|
struct scm *symbol_to_string (struct scm *symbol);
|
||||||
#define cell_vm_eval_define 27
|
struct scm *symbol_to_keyword (struct scm *symbol);
|
||||||
// CONSTANT cell_vm_eval_macro_expand_eval 28
|
struct scm *keyword_to_string (struct scm *keyword);
|
||||||
#define cell_vm_eval_macro_expand_eval 28
|
struct scm *string_to_symbol (struct scm *string);
|
||||||
// CONSTANT cell_vm_eval_macro_expand_expand 29
|
struct scm *make_symbol (struct scm *string);
|
||||||
#define cell_vm_eval_macro_expand_expand 29
|
struct scm *string_to_list (struct scm *string);
|
||||||
// CONSTANT cell_vm_eval_pmatch_car 30
|
struct scm *list_to_string (struct scm *list);
|
||||||
#define cell_vm_eval_pmatch_car 30
|
struct scm *read_string (struct scm *port);
|
||||||
// CONSTANT cell_vm_eval_pmatch_cdr 31
|
struct scm *string_append (struct scm *x);
|
||||||
#define cell_vm_eval_pmatch_cdr 31
|
struct scm *string_length (struct scm *string);
|
||||||
// CONSTANT cell_vm_eval_set_x 32
|
struct scm *string_ref (struct scm *str, struct scm *k);
|
||||||
#define cell_vm_eval_set_x 32
|
/* src/struct.c */
|
||||||
// CONSTANT cell_vm_evlis 33
|
struct scm *make_struct (struct scm *type, struct scm *fields, struct scm *printer);
|
||||||
#define cell_vm_evlis 33
|
struct scm *struct_length (struct scm *x);
|
||||||
// CONSTANT cell_vm_evlis2 34
|
struct scm *struct_ref (struct scm *x, struct scm *i);
|
||||||
#define cell_vm_evlis2 34
|
struct scm *struct_set_x (struct scm *x, struct scm *i, struct scm *e);
|
||||||
// CONSTANT cell_vm_evlis3 35
|
/* src/vector.c */
|
||||||
#define cell_vm_evlis3 35
|
struct scm *make_vector (struct scm *x);
|
||||||
// CONSTANT cell_vm_if 36
|
struct scm *vector_length (struct scm *x);
|
||||||
#define cell_vm_if 36
|
struct scm *vector_ref (struct scm *x, struct scm *i);
|
||||||
// CONSTANT cell_vm_if_expr 37
|
struct scm *vector_entry (struct scm *x);
|
||||||
#define cell_vm_if_expr 37
|
struct scm *vector_set_x (struct scm *x, struct scm *i, struct scm *e);
|
||||||
// CONSTANT cell_vm_macro_expand 38
|
struct scm *list_to_vector (struct scm *x);
|
||||||
#define cell_vm_macro_expand 38
|
struct scm *vector_to_list (struct scm *v);
|
||||||
// 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_symbol_test 118
|
|
||||||
#define cell_symbol_test 118
|
|
||||||
// src/module.mes
|
|
||||||
SCM make_module_type ();
|
|
||||||
SCM module_printer (SCM module);
|
|
||||||
SCM module_variable (SCM module, SCM name);
|
|
||||||
SCM module_ref (SCM module, SCM name);
|
|
||||||
SCM module_define_x (SCM module, SCM name, SCM value);
|
|
||||||
// src/posix.mes
|
|
||||||
SCM peek_byte ();
|
|
||||||
SCM read_byte ();
|
|
||||||
SCM unread_byte (SCM i);
|
|
||||||
SCM peek_char ();
|
|
||||||
SCM read_char (SCM port);
|
|
||||||
SCM unread_char (SCM i);
|
|
||||||
SCM write_char (SCM i);
|
|
||||||
SCM write_byte (SCM x);
|
|
||||||
SCM getenv_ (SCM s);
|
|
||||||
SCM setenv_ (SCM s, SCM v);
|
|
||||||
SCM access_p (SCM file_name, SCM mode);
|
|
||||||
SCM current_input_port ();
|
|
||||||
SCM open_input_file (SCM file_name);
|
|
||||||
SCM open_input_string (SCM string);
|
|
||||||
SCM set_current_input_port (SCM port);
|
|
||||||
SCM current_output_port ();
|
|
||||||
SCM current_error_port ();
|
|
||||||
SCM open_output_file (SCM x);
|
|
||||||
SCM set_current_output_port (SCM port);
|
|
||||||
SCM set_current_error_port (SCM port);
|
|
||||||
SCM force_output (SCM p);
|
|
||||||
SCM chmod_ (SCM file_name, SCM mode);
|
|
||||||
SCM isatty_p (SCM port);
|
|
||||||
SCM primitive_fork ();
|
|
||||||
SCM execl_ (SCM file_name, SCM args);
|
|
||||||
SCM waitpid_ (SCM pid, SCM options);
|
|
||||||
SCM current_time ();
|
|
||||||
SCM gettimeofday_ ();
|
|
||||||
SCM get_internal_run_time ();
|
|
||||||
SCM getcwd_ ();
|
|
||||||
SCM dup_ (SCM port);
|
|
||||||
SCM dup2_ (SCM old, SCM new);
|
|
||||||
SCM delete_file (SCM file_name);
|
|
||||||
// src/reader.mes
|
|
||||||
SCM read_input_file_env_ (SCM e, SCM a);
|
|
||||||
SCM read_input_file_env (SCM a);
|
|
||||||
SCM read_env (SCM a);
|
|
||||||
SCM reader_read_sexp (SCM c, SCM s, SCM a);
|
|
||||||
SCM reader_read_character ();
|
|
||||||
SCM reader_read_binary ();
|
|
||||||
SCM reader_read_octal ();
|
|
||||||
SCM reader_read_hex ();
|
|
||||||
SCM reader_read_string ();
|
|
||||||
// src/strings.mes
|
|
||||||
SCM string_equal_p (SCM a, SCM b);
|
|
||||||
SCM symbol_to_string (SCM symbol);
|
|
||||||
SCM symbol_to_keyword (SCM symbol);
|
|
||||||
SCM keyword_to_string (SCM keyword);
|
|
||||||
SCM string_to_symbol (SCM string);
|
|
||||||
SCM make_symbol (SCM string);
|
|
||||||
SCM string_to_list (SCM string);
|
|
||||||
SCM list_to_string (SCM list);
|
|
||||||
SCM read_string (SCM port);
|
|
||||||
SCM string_append (SCM x);
|
|
||||||
SCM string_length (SCM string);
|
|
||||||
SCM string_ref (SCM str, SCM k);
|
|
||||||
// src/struct.mes
|
|
||||||
SCM make_struct (SCM type, SCM fields, SCM printer);
|
|
||||||
SCM struct_length (SCM x);
|
|
||||||
SCM struct_ref (SCM x, SCM i);
|
|
||||||
SCM struct_set_x (SCM x, SCM i, SCM e);
|
|
||||||
// src/vector.mes
|
|
||||||
SCM make_vector_ (SCM n);
|
|
||||||
SCM vector_length (SCM x);
|
|
||||||
SCM vector_ref (SCM x, SCM i);
|
|
||||||
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
|
#endif /* __MES_BUILTINS_H */
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MES_CC_H
|
||||||
|
#define __MES_CC_H
|
||||||
|
|
||||||
|
typedef struct scm* SCM;
|
||||||
|
|
||||||
|
#if __MESC__
|
||||||
|
typedef long FUNCTION;
|
||||||
|
typedef long function0_t;
|
||||||
|
typedef long function1_t;
|
||||||
|
typedef long function2_t;
|
||||||
|
typedef long function3_t;
|
||||||
|
typedef long functionn_t;
|
||||||
|
#else // !__MESC__
|
||||||
|
typedef SCM (*FUNCTION) (void);
|
||||||
|
typedef SCM (*function0_t) (void);
|
||||||
|
typedef SCM (*function1_t) (SCM);
|
||||||
|
typedef SCM (*function2_t) (SCM, SCM);
|
||||||
|
typedef SCM (*function3_t) (SCM, SCM, SCM);
|
||||||
|
typedef SCM (*functionn_t) (SCM);
|
||||||
|
#endif // !__MESC__
|
||||||
|
|
||||||
|
#endif //__MES_CC_H
|
|
@ -21,263 +21,13 @@
|
||||||
#ifndef __MES_CONSTANTS_H
|
#ifndef __MES_CONSTANTS_H
|
||||||
#define __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 */
|
/* Cell types */
|
||||||
|
|
||||||
// CONSTANT TBYTES 0
|
// CONSTANT TCHAR 0
|
||||||
#define TBYTES 0
|
#define TCHAR 0
|
||||||
// CONSTANT TCHAR 1
|
|
||||||
#define TCHAR 1
|
// CONSTANT TBYTES 1
|
||||||
|
#define TBYTES 1
|
||||||
// CONSTANT TCLOSURE 2
|
// CONSTANT TCLOSURE 2
|
||||||
#define TCLOSURE 2
|
#define TCLOSURE 2
|
||||||
// CONSTANT TCONTINUATION 3
|
// CONSTANT TCONTINUATION 3
|
||||||
|
@ -318,7 +68,31 @@
|
||||||
// CONSTANT STRUCT_PRINTER 1
|
// CONSTANT STRUCT_PRINTER 1
|
||||||
#define STRUCT_PRINTER 1
|
#define STRUCT_PRINTER 1
|
||||||
|
|
||||||
|
// CONSTANT FRAME_SIZE 5
|
||||||
#define FRAME_SIZE 5
|
#define FRAME_SIZE 5
|
||||||
|
// CONSTANT FRAME_PROCEDURE 4
|
||||||
#define FRAME_PROCEDURE 4
|
#define FRAME_PROCEDURE 4
|
||||||
|
|
||||||
#endif //__MES_CONSTANTS_H
|
// CONSTANT STDIN 0
|
||||||
|
// CONSTANT STDOUT 1
|
||||||
|
// CONSTANT STDERR 2
|
||||||
|
|
||||||
|
/* Unknown type 1
|
||||||
|
// CONSTANT EOF -1
|
||||||
|
*/
|
||||||
|
|
||||||
|
// CONSTANT O_RDONLY 0
|
||||||
|
// CONSTANT O_WRONLY 1
|
||||||
|
// CONSTANT O_CREAT 0x40
|
||||||
|
// CONSTANT O_TRUNC 0x200
|
||||||
|
|
||||||
|
// CONSTANT PATH_MAX 1024
|
||||||
|
// CONSTANT __FILEDES_MAX 512
|
||||||
|
|
||||||
|
// CONSTANT S_IRUSR 00400
|
||||||
|
// CONSTANT S_IWUSR 00200
|
||||||
|
|
||||||
|
// CONSTANT CLOCK_PROCESS_CPUTIME_ID 2
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __MES_CONSTANTS_H */
|
||||||
|
|
|
@ -23,6 +23,18 @@
|
||||||
|
|
||||||
#include <mes/lib-mini.h>
|
#include <mes/lib-mini.h>
|
||||||
|
|
||||||
|
char* cast_intp_to_charp (int const *i);
|
||||||
|
char* cast_long_to_charp (long i);
|
||||||
|
long cast_charp_to_long (char const *);
|
||||||
|
long cast_int_to_long (int i);
|
||||||
|
long cast_voidp_to_long (void const *);
|
||||||
|
|
||||||
|
// #define cast_intp_to_charp(x) ((char*) x)
|
||||||
|
// #define cast_long_to_charp(x) ((char*) x)
|
||||||
|
// #define cast_charp_to_long(x) ((long) x)
|
||||||
|
// #define cast_int_to_long(x) ((long) x)
|
||||||
|
// #define cast_voidp_to_long(x) ((long) x)
|
||||||
|
|
||||||
int __mes_debug ();
|
int __mes_debug ();
|
||||||
void __ungetc_init ();
|
void __ungetc_init ();
|
||||||
void __ungetc_clear (int filedes);
|
void __ungetc_clear (int filedes);
|
||||||
|
@ -52,6 +64,7 @@ int oputc (int c);
|
||||||
int oputs (char const *s);
|
int oputs (char const *s);
|
||||||
char *search_path (char const *file_name);
|
char *search_path (char const *file_name);
|
||||||
ssize_t _read (int fd, void *buffer, size_t size);
|
ssize_t _read (int fd, void *buffer, size_t size);
|
||||||
|
void assert_msg (int check, char *msg);
|
||||||
|
|
||||||
extern char *__brk;
|
extern char *__brk;
|
||||||
extern void (*__call_at_exit) (void);
|
extern void (*__call_at_exit) (void);
|
||||||
|
@ -66,4 +79,15 @@ void _exit (int code);
|
||||||
long brk (void *addr);
|
long brk (void *addr);
|
||||||
#endif // !SYSTEM_LIBC
|
#endif // !SYSTEM_LIBC
|
||||||
|
|
||||||
|
long __mesabi_imod (long a, long b);
|
||||||
|
long __mesabi_idiv (long a, long b);
|
||||||
|
unsigned long __mesabi_umod (unsigned long a, unsigned long b);
|
||||||
|
unsigned long __mesabi_udiv (unsigned long a, unsigned long b);
|
||||||
|
unsigned long __mesabi_uldiv (unsigned long a, unsigned long b,
|
||||||
|
unsigned long *remainder);
|
||||||
|
|
||||||
|
void *__memcpy (void *dest, void const *src, size_t n);
|
||||||
|
void *__memmove (void *dest, void const *src, size_t n);
|
||||||
|
void *__memset (void *s, int c, size_t n);
|
||||||
|
|
||||||
#endif //__MES_LIB_H
|
#endif //__MES_LIB_H
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
|
||||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
|
||||||
*
|
|
||||||
* This file is part of GNU Mes.
|
|
||||||
*
|
|
||||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or (at
|
|
||||||
* your option) any later version.
|
|
||||||
*
|
|
||||||
* GNU Mes is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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
|
|
|
@ -22,85 +22,162 @@
|
||||||
#define __MES_MES_H
|
#define __MES_MES_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "mes/cc.h"
|
||||||
typedef long SCM;
|
|
||||||
|
|
||||||
struct scm
|
struct scm
|
||||||
{
|
{
|
||||||
long type;
|
long type;
|
||||||
SCM car;
|
union
|
||||||
SCM cdr;
|
{
|
||||||
|
struct scm *car;
|
||||||
|
long car_value;
|
||||||
|
char *bytes;
|
||||||
|
long length;
|
||||||
|
struct scm *ref;
|
||||||
|
struct scm *variable;
|
||||||
|
struct scm *macro;
|
||||||
|
long port;
|
||||||
|
};
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct scm *cdr;
|
||||||
|
long cdr_value;
|
||||||
|
struct scm *closure;
|
||||||
|
struct scm *continuation;
|
||||||
|
char *name;
|
||||||
|
struct scm *string;
|
||||||
|
struct scm *structure;
|
||||||
|
long value;
|
||||||
|
FUNCTION function;
|
||||||
|
struct scm *vector;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// mes
|
/* mes */
|
||||||
extern int g_debug;
|
char *g_datadir;
|
||||||
extern char *g_buf;
|
int g_debug;
|
||||||
extern SCM g_continuations;
|
char *g_buf;
|
||||||
extern SCM g_symbols;
|
int g_continuations;
|
||||||
extern SCM g_symbol_max;
|
struct scm *g_symbols;
|
||||||
|
struct scm *g_symbol_max;
|
||||||
|
int g_mini;
|
||||||
|
|
||||||
// a/env
|
/* a/env */
|
||||||
extern SCM r0;
|
struct scm *R0;
|
||||||
// param 1
|
/* param 1 */
|
||||||
extern SCM r1;
|
struct scm *R1;
|
||||||
// save 2
|
/* save 2 */
|
||||||
extern SCM r2;
|
struct scm *R2;
|
||||||
// continuation
|
/* continuation */
|
||||||
extern SCM r3;
|
struct scm *R3;
|
||||||
// current-module
|
/* current-module */
|
||||||
extern SCM m0;
|
struct scm *M0;
|
||||||
// macro
|
/* macro */
|
||||||
extern SCM g_macros;
|
struct scm *g_macros;
|
||||||
extern SCM g_ports;
|
struct scm *g_ports;
|
||||||
|
|
||||||
// gc
|
/* gc */
|
||||||
extern long ARENA_SIZE;
|
long ARENA_SIZE;
|
||||||
extern long MAX_ARENA_SIZE;
|
long MAX_ARENA_SIZE;
|
||||||
extern long STACK_SIZE;
|
long STACK_SIZE;
|
||||||
extern long JAM_SIZE;
|
long JAM_SIZE;
|
||||||
extern long GC_SAFETY;
|
long GC_SAFETY;
|
||||||
extern long MAX_STRING;
|
long MAX_STRING;
|
||||||
extern char *g_arena;
|
char *g_arena;
|
||||||
extern long g_free;
|
struct scm *cell_arena;
|
||||||
extern SCM g_stack;
|
struct scm *cell_zero;
|
||||||
extern SCM *g_stack_array;
|
|
||||||
extern struct scm *g_cells;
|
|
||||||
extern struct scm *g_news;
|
|
||||||
|
|
||||||
SCM alloc (long n);
|
struct scm *g_free;
|
||||||
SCM apply (SCM f, SCM x, SCM a);
|
struct scm *g_symbol;
|
||||||
SCM apply_builtin (SCM fn, SCM x);
|
|
||||||
SCM cstring_to_list (char const *s);
|
struct scm **g_stack_array;
|
||||||
SCM cstring_to_symbol (char const *s);
|
struct scm *g_cells;
|
||||||
SCM display_ (SCM x);
|
struct scm *g_news;
|
||||||
SCM fdisplay_ (SCM, int, int);
|
long g_stack;
|
||||||
SCM gc_init ();
|
|
||||||
SCM gc_peek_frame ();
|
char **__execl_c_argv;
|
||||||
SCM gc_pop_frame ();
|
char *__getcwd_buf;
|
||||||
SCM gc_push_frame ();
|
char *__open_boot_buf;
|
||||||
SCM init_time (SCM a);
|
char *__open_boot_file_name;
|
||||||
SCM make_bytes (char const *s, size_t length);
|
char *__setenv_buf;
|
||||||
SCM make_cell__ (long type, SCM car, SCM cdr);
|
char *__reader_read_char_buf;
|
||||||
SCM make_hash_table_ (long size);
|
struct timespec *g_start_time;
|
||||||
SCM make_hashq_type ();
|
struct timeval *__gettimeofday_time;
|
||||||
SCM make_initial_module (SCM a);
|
struct timespec *__get_internal_run_time_ts;
|
||||||
SCM make_string (char const *s, size_t length);
|
|
||||||
SCM make_vector__ (long k);
|
struct scm *cast_charp_to_scmp (char const *i);
|
||||||
SCM read_input_file_env (SCM);
|
struct scm ** cast_charp_to_scmpp (char const *i);
|
||||||
SCM string_equal_p (SCM a, SCM b);
|
char* cast_voidp_to_charp (void const *i);
|
||||||
SCM struct_ref_ (SCM x, long i);
|
long cast_scmp_to_long (struct scm *i);
|
||||||
SCM struct_set_x_ (SCM x, long i, SCM e);
|
char* cast_scmp_to_charp (struct scm *i);
|
||||||
SCM vector_ref_ (SCM x, long i);
|
|
||||||
SCM vector_set_x_ (SCM x, long i, SCM e);
|
// #define cast_voidp_to_charp(x) ((char*) x)
|
||||||
|
// #define cast_charp_to_scmp(x) ((struct scm *) x)
|
||||||
|
// #define cast_charp_to_scmpp(x) ((struct scm **) x)
|
||||||
|
// #define cast_scmp_to_long(x) ((long) x)
|
||||||
|
// #define cast_scmp_to_charp(x) ((char*) x)
|
||||||
|
|
||||||
|
struct scm *alloc (long n);
|
||||||
|
struct scm *apply (struct scm *f, struct scm *x, struct scm *a);
|
||||||
|
struct scm *apply_builtin (struct scm *fn, struct scm *x);
|
||||||
|
struct scm *apply_builtin0 (struct scm *fn);
|
||||||
|
struct scm *apply_builtin1 (struct scm *fn, struct scm *x);
|
||||||
|
struct scm *apply_builtin2 (struct scm *fn, struct scm *x, struct scm *y);
|
||||||
|
struct scm *apply_builtin3 (struct scm *fn, struct scm *x, struct scm *y, struct scm *z);
|
||||||
|
struct scm *builtin_name (struct scm *builtin);
|
||||||
|
struct scm *cstring_to_list (char const *s);
|
||||||
|
struct scm *cstring_to_symbol (char const *s);
|
||||||
|
struct scm *cell_ref (struct scm *cell, long index);
|
||||||
|
struct scm *fdisplay_ (struct scm *, int, int);
|
||||||
|
struct scm *init_symbols ();
|
||||||
|
struct scm *init_time (struct scm *a);
|
||||||
|
struct scm *make_builtin_type ();
|
||||||
|
struct scm *make_bytes (char const *s, size_t length);
|
||||||
|
struct scm *make_cell (long type, struct scm *car, struct scm *cdr);
|
||||||
|
struct scm *make_pointer_cell (long type, long car, void *cdr);
|
||||||
|
struct scm *make_value_cell (long type, long car, long cdr);
|
||||||
|
struct scm *make_char (int n);
|
||||||
|
struct scm *make_continuation (long n);
|
||||||
|
struct scm *make_hash_table_ (long size);
|
||||||
|
struct scm *make_hashq_type ();
|
||||||
|
struct scm *make_initial_module (struct scm *a);
|
||||||
|
struct scm *make_macro (struct scm *name, struct scm *x);
|
||||||
|
struct scm *make_number (long n);
|
||||||
|
struct scm *make_ref (struct scm *x);
|
||||||
|
struct scm *make_string (char const *s, size_t length);
|
||||||
|
struct scm *make_string0 (char const *s);
|
||||||
|
struct scm *make_string_port (struct scm *x);
|
||||||
|
struct scm *make_vector_ (long k, struct scm *e);
|
||||||
|
struct scm *mes_builtins (struct scm *a);
|
||||||
|
struct scm *push_cc (struct scm *p1, struct scm *p2, struct scm *a, struct scm *c);
|
||||||
|
struct scm *struct_ref_ (struct scm *x, long i);
|
||||||
|
struct scm *struct_set_x_ (struct scm *x, long i, struct scm *e);
|
||||||
|
struct scm *vector_ref_ (struct scm *x, long i);
|
||||||
|
struct scm *vector_set_x_ (struct scm *x, long i, struct scm *e);
|
||||||
|
FUNCTION builtin_function (struct scm *builtin);
|
||||||
|
char *cell_bytes (struct scm *x);
|
||||||
|
char *news_bytes (struct scm *x);
|
||||||
int peekchar ();
|
int peekchar ();
|
||||||
int readchar ();
|
int readchar ();
|
||||||
int unreadchar ();
|
int unreadchar ();
|
||||||
long length__ (SCM x);
|
long gc_free ();
|
||||||
|
long length__ (struct scm *x);
|
||||||
size_t bytes_cells (size_t length);
|
size_t bytes_cells (size_t length);
|
||||||
void assert_max_string (size_t i, char const *msg, char *string);
|
void assert_max_string (size_t i, char const *msg, char const *string);
|
||||||
|
void assert_msg (int check, char *msg);
|
||||||
|
void assert_number (char const *name, struct scm *x);
|
||||||
|
void copy_cell (struct scm *to, struct scm *from);
|
||||||
|
void gc_ ();
|
||||||
|
void gc_dump_arena (struct scm *cells, long size);
|
||||||
|
void gc_init ();
|
||||||
|
void gc_peek_frame ();
|
||||||
|
void gc_pop_frame ();
|
||||||
|
void gc_push_frame ();
|
||||||
|
void gc_stats_ (char const* where);
|
||||||
|
void init_symbols_ ();
|
||||||
|
|
||||||
#include "mes/builtins.h"
|
#include "mes/builtins.h"
|
||||||
#include "mes/constants.h"
|
#include "mes/constants.h"
|
||||||
#include "mes/macros.h"
|
#include "mes/symbols.h"
|
||||||
|
|
||||||
#endif //__MES_MES_H
|
#endif /* __MES_MES_H */
|
||||||
|
|
|
@ -0,0 +1,150 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MES_SYMBOLS_H
|
||||||
|
#define __MES_SYMBOLS_H
|
||||||
|
|
||||||
|
struct scm *cell_nil;
|
||||||
|
struct scm *cell_f;
|
||||||
|
struct scm *cell_t;
|
||||||
|
struct scm *cell_dot;
|
||||||
|
struct scm *cell_arrow;
|
||||||
|
struct scm *cell_undefined;
|
||||||
|
struct scm *cell_unspecified;
|
||||||
|
struct scm *cell_closure;
|
||||||
|
struct scm *cell_circular;
|
||||||
|
|
||||||
|
struct scm *cell_vm_apply;
|
||||||
|
struct scm *cell_vm_apply2;
|
||||||
|
struct scm *cell_vm_begin;
|
||||||
|
struct scm *cell_vm_begin_eval;
|
||||||
|
struct scm *cell_vm_begin_expand;
|
||||||
|
struct scm *cell_vm_begin_expand_eval;
|
||||||
|
struct scm *cell_vm_begin_expand_macro;
|
||||||
|
struct scm *cell_vm_begin_expand_primitive_load;
|
||||||
|
struct scm *cell_vm_begin_primitive_load;
|
||||||
|
struct scm *cell_vm_begin_read_input_file;
|
||||||
|
struct scm *cell_vm_call_with_current_continuation2;
|
||||||
|
struct scm *cell_vm_call_with_values2;
|
||||||
|
struct scm *cell_vm_eval;
|
||||||
|
struct scm *cell_vm_eval2;
|
||||||
|
struct scm *cell_vm_eval_check_func;
|
||||||
|
struct scm *cell_vm_eval_define;
|
||||||
|
struct scm *cell_vm_eval_macro_expand_eval;
|
||||||
|
struct scm *cell_vm_eval_macro_expand_expand;
|
||||||
|
struct scm *cell_vm_eval_pmatch_car;
|
||||||
|
struct scm *cell_vm_eval_pmatch_cdr;
|
||||||
|
struct scm *cell_vm_eval_set_x;
|
||||||
|
struct scm *cell_vm_evlis;
|
||||||
|
struct scm *cell_vm_evlis2;
|
||||||
|
struct scm *cell_vm_evlis3;
|
||||||
|
struct scm *cell_vm_if;
|
||||||
|
struct scm *cell_vm_if_expr;
|
||||||
|
struct scm *cell_vm_macro_expand;
|
||||||
|
struct scm *cell_vm_macro_expand_car;
|
||||||
|
struct scm *cell_vm_macro_expand_cdr;
|
||||||
|
struct scm *cell_vm_macro_expand_define;
|
||||||
|
struct scm *cell_vm_macro_expand_define_macro;
|
||||||
|
struct scm *cell_vm_macro_expand_lambda;
|
||||||
|
struct scm *cell_vm_macro_expand_set_x;
|
||||||
|
struct scm *cell_vm_return;
|
||||||
|
|
||||||
|
struct scm *cell_symbol_lambda;
|
||||||
|
struct scm *cell_symbol_begin;
|
||||||
|
struct scm *cell_symbol_if;
|
||||||
|
struct scm *cell_symbol_quote;
|
||||||
|
struct scm *cell_symbol_define;
|
||||||
|
struct scm *cell_symbol_define_macro;
|
||||||
|
struct scm *cell_symbol_quasiquote;
|
||||||
|
struct scm *cell_symbol_unquote;
|
||||||
|
struct scm *cell_symbol_unquote_splicing;
|
||||||
|
struct scm *cell_symbol_syntax;
|
||||||
|
struct scm *cell_symbol_quasisyntax;
|
||||||
|
struct scm *cell_symbol_unsyntax;
|
||||||
|
struct scm *cell_symbol_unsyntax_splicing;
|
||||||
|
struct scm *cell_symbol_set_x;
|
||||||
|
struct scm *cell_symbol_sc_expand;
|
||||||
|
struct scm *cell_symbol_macro_expand;
|
||||||
|
struct scm *cell_symbol_portable_macro_expand;
|
||||||
|
struct scm *cell_symbol_sc_expander_alist;
|
||||||
|
struct scm *cell_symbol_call_with_values;
|
||||||
|
struct scm *cell_symbol_call_with_current_continuation;
|
||||||
|
struct scm *cell_symbol_boot_module;
|
||||||
|
struct scm *cell_symbol_current_module;
|
||||||
|
struct scm *cell_symbol_primitive_load;
|
||||||
|
struct scm *cell_symbol_car;
|
||||||
|
struct scm *cell_symbol_cdr;
|
||||||
|
struct scm *cell_symbol_not_a_number;
|
||||||
|
struct scm *cell_symbol_not_a_pair;
|
||||||
|
struct scm *cell_symbol_system_error;
|
||||||
|
struct scm *cell_symbol_throw;
|
||||||
|
struct scm *cell_symbol_unbound_variable;
|
||||||
|
struct scm *cell_symbol_wrong_number_of_args;
|
||||||
|
struct scm *cell_symbol_wrong_type_arg;
|
||||||
|
struct scm *cell_symbol_buckets;
|
||||||
|
struct scm *cell_symbol_builtin;
|
||||||
|
struct scm *cell_symbol_frame;
|
||||||
|
struct scm *cell_symbol_hashq_table;
|
||||||
|
struct scm *cell_symbol_module;
|
||||||
|
struct scm *cell_symbol_procedure;
|
||||||
|
struct scm *cell_symbol_record_type;
|
||||||
|
struct scm *cell_symbol_size;
|
||||||
|
struct scm *cell_symbol_stack;
|
||||||
|
struct scm *cell_symbol_argv;
|
||||||
|
struct scm *cell_symbol_mes_datadir;
|
||||||
|
struct scm *cell_symbol_mes_version;
|
||||||
|
struct scm *cell_symbol_internal_time_units_per_second;
|
||||||
|
struct scm *cell_symbol_compiler;
|
||||||
|
struct scm *cell_symbol_arch;
|
||||||
|
struct scm *cell_symbol_pmatch_car;
|
||||||
|
struct scm *cell_symbol_pmatch_cdr;
|
||||||
|
struct scm *cell_type_bytes;
|
||||||
|
struct scm *cell_type_char;
|
||||||
|
struct scm *cell_type_closure;
|
||||||
|
struct scm *cell_type_continuation;
|
||||||
|
struct scm *cell_type_function;
|
||||||
|
struct scm *cell_type_keyword;
|
||||||
|
struct scm *cell_type_macro;
|
||||||
|
struct scm *cell_type_number;
|
||||||
|
struct scm *cell_type_pair;
|
||||||
|
struct scm *cell_type_port;
|
||||||
|
struct scm *cell_type_ref;
|
||||||
|
struct scm *cell_type_special;
|
||||||
|
struct scm *cell_type_string;
|
||||||
|
struct scm *cell_type_struct;
|
||||||
|
struct scm *cell_type_symbol;
|
||||||
|
struct scm *cell_type_values;
|
||||||
|
struct scm *cell_type_variable;
|
||||||
|
struct scm *cell_type_vector;
|
||||||
|
struct scm *cell_type_broken_heart;
|
||||||
|
struct scm *cell_symbol_program;
|
||||||
|
struct scm *cell_symbol_test;
|
||||||
|
|
||||||
|
// CONSTANT SYMBOL_MAX 114
|
||||||
|
#define SYMBOL_MAX 114
|
||||||
|
|
||||||
|
// CONSTANT CELL_UNSPECIFIED 7
|
||||||
|
#define CELL_UNSPECIFIED 7
|
||||||
|
|
||||||
|
// CONSTANT CELL_SYMBOL_RECORD_TYPE 82
|
||||||
|
#define CELL_SYMBOL_RECORD_TYPE 82
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __MES_SYMBOLS_H */
|
|
@ -27,12 +27,22 @@
|
||||||
#else // ! SYSTEM_LIBC
|
#else // ! SYSTEM_LIBC
|
||||||
|
|
||||||
#if __arm__
|
#if __arm__
|
||||||
|
#if __GNUC__ || __TINYC__
|
||||||
|
#warning "It is not supported to use mes' setjmp implementation together with GCC. Continuing with best-effort implementation."
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
long __sp;
|
||||||
|
long __lr;
|
||||||
|
long __registers[8]; /* Note: Keep in sync with lib/arm-mes-gcc/setjmp.c */
|
||||||
|
} __jmp_buf;
|
||||||
|
#else
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
long __fp;
|
long __fp;
|
||||||
long __lr;
|
long __lr;
|
||||||
long __sp;
|
long __sp;
|
||||||
} __jmp_buf;
|
} __jmp_buf;
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
|
@ -239,6 +239,7 @@ typedef struct ucontext
|
||||||
#endif // !__i386__
|
#endif // !__i386__
|
||||||
|
|
||||||
int kill (pid_t pid, int signum);
|
int kill (pid_t pid, int signum);
|
||||||
|
int raise (int);
|
||||||
int sigaction (int signum, struct sigaction const *act, struct sigaction *oldact);
|
int sigaction (int signum, struct sigaction const *act, struct sigaction *oldact);
|
||||||
int sigaddset (sigset_t * set, int signum);
|
int sigaddset (sigset_t * set, int signum);
|
||||||
#if __MESC__
|
#if __MESC__
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2017,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
* Copyright © 2018 Peter De Wachter <pdewacht@gmail.com>
|
* Copyright © 2018 Peter De Wachter <pdewacht@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
|
@ -55,8 +55,10 @@ typedef unsigned short uint16_t;
|
||||||
typedef short int16_t;
|
typedef short int16_t;
|
||||||
typedef unsigned uint32_t;
|
typedef unsigned uint32_t;
|
||||||
typedef int int32_t;
|
typedef int int32_t;
|
||||||
|
#if __SIZEOF_LONG_LONG__ == 8
|
||||||
typedef unsigned long long uint64_t;
|
typedef unsigned long long uint64_t;
|
||||||
typedef long long int64_t;
|
typedef long long int64_t;
|
||||||
|
#endif // __SIZEOF_LONG_LONG__ == 8
|
||||||
|
|
||||||
typedef int intmax_t;
|
typedef int intmax_t;
|
||||||
typedef unsigned uintmax_t;
|
typedef unsigned uintmax_t;
|
||||||
|
|
|
@ -69,11 +69,13 @@ typedef unsigned gid_t;
|
||||||
typedef unsigned long ino_t;
|
typedef unsigned long ino_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __SIZEOF_LONG_LONG__ == 8
|
||||||
#ifndef __MES_INO64_T
|
#ifndef __MES_INO64_T
|
||||||
#define __MES_INO64_T
|
#define __MES_INO64_T
|
||||||
#undef ino64_t
|
#undef ino64_t
|
||||||
typedef unsigned long long ino64_t;
|
typedef unsigned long long ino64_t;
|
||||||
#endif
|
#endif
|
||||||
|
#endif // __SIZEOF_LONG_LONG__ == 8
|
||||||
|
|
||||||
#if !defined (__MES_INTPTR_T) && !defined (__intptr_t_defined)
|
#if !defined (__MES_INTPTR_T) && !defined (__intptr_t_defined)
|
||||||
#define __MES_INTPTR_T
|
#define __MES_INTPTR_T
|
||||||
|
@ -90,11 +92,13 @@ typedef unsigned long uintptr_t;
|
||||||
typedef long off_t;
|
typedef long off_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __SIZEOF_LONG_LONG__ == 8
|
||||||
#ifndef __MES_OFF64_T
|
#ifndef __MES_OFF64_T
|
||||||
#define __MES_OFF64_T
|
#define __MES_OFF64_T
|
||||||
#undef off64_t
|
#undef off64_t
|
||||||
typedef unsigned long long off64_t;
|
typedef unsigned long long off64_t;
|
||||||
#endif
|
#endif
|
||||||
|
#endif // __SIZEOF_LONG_LONG__ == 8
|
||||||
|
|
||||||
#ifndef __MES_PID_T
|
#ifndef __MES_PID_T
|
||||||
#define __MES_PID_T
|
#define __MES_PID_T
|
||||||
|
|
|
@ -0,0 +1,139 @@
|
||||||
|
#! /bin/sh
|
||||||
|
# Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
#
|
||||||
|
# This file is part of GNU Mes.
|
||||||
|
#
|
||||||
|
# GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
# your option) any later version.
|
||||||
|
#
|
||||||
|
# GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# kaem --verbose --strict
|
||||||
|
|
||||||
|
mkdir -p m2
|
||||||
|
|
||||||
|
M2-Planet \
|
||||||
|
--debug \
|
||||||
|
--architecture x86 \
|
||||||
|
-f include/m2/lib.h \
|
||||||
|
-f lib/linux/x86-mes-m2/crt1.c \
|
||||||
|
-f lib/linux/x86-mes-m2/mini.c \
|
||||||
|
-f lib/mes/globals.c \
|
||||||
|
-f lib/m2/cast.c \
|
||||||
|
-f lib/m2/exit.c \
|
||||||
|
-f lib/mes/mini-write.c \
|
||||||
|
-f lib/linux/x86-mes-m2/syscall.c \
|
||||||
|
-f include/linux/x86/syscall.h \
|
||||||
|
-f lib/linux/brk.c \
|
||||||
|
-f lib/stdlib/malloc.c \
|
||||||
|
-f lib/string/memset.c \
|
||||||
|
-f lib/m2/read.c \
|
||||||
|
-f lib/mes/fdgetc.c \
|
||||||
|
-f lib/stdio/getchar.c \
|
||||||
|
-f lib/stdio/putchar.c \
|
||||||
|
-f lib/m2/open.c \
|
||||||
|
-f lib/m2/mes_open.c \
|
||||||
|
-f lib/string/strlen.c \
|
||||||
|
-f lib/mes/eputs.c \
|
||||||
|
-f lib/mes/fdputc.c \
|
||||||
|
-f lib/mes/eputc.c \
|
||||||
|
\
|
||||||
|
-f include/mes/mes.h \
|
||||||
|
-f include/mes/builtins.h \
|
||||||
|
-f include/mes/constants.h \
|
||||||
|
-f include/mes/symbols.h \
|
||||||
|
\
|
||||||
|
-f lib/mes/__assert_fail.c \
|
||||||
|
-f lib/mes/assert_msg.c \
|
||||||
|
\
|
||||||
|
-f lib/mes/fdputc.c \
|
||||||
|
-f lib/string/strncmp.c \
|
||||||
|
-f lib/posix/getenv.c \
|
||||||
|
-f lib/mes/fdputs.c \
|
||||||
|
-f lib/mes/ntoab.c \
|
||||||
|
-f lib/ctype/isdigit.c \
|
||||||
|
-f lib/ctype/isxdigit.c \
|
||||||
|
-f lib/ctype/isspace.c \
|
||||||
|
-f lib/ctype/isnumber.c \
|
||||||
|
-f lib/mes/abtol.c \
|
||||||
|
-f lib/stdlib/atoi.c \
|
||||||
|
-f lib/string/memcpy.c \
|
||||||
|
-f lib/stdlib/free.c \
|
||||||
|
-f lib/stdlib/realloc.c \
|
||||||
|
-f lib/string/strcpy.c \
|
||||||
|
-f lib/mes/itoa.c \
|
||||||
|
-f lib/mes/ltoa.c \
|
||||||
|
-f lib/mes/fdungetc.c \
|
||||||
|
-f lib/posix/setenv.c \
|
||||||
|
-f lib/linux/access.c \
|
||||||
|
-f lib/m2/chmod.c \
|
||||||
|
-f lib/m2/ioctl.c \
|
||||||
|
-f lib/m2/isatty.c \
|
||||||
|
-f lib/linux/fork.c \
|
||||||
|
-f lib/m2/execve.c \
|
||||||
|
-f lib/m2/execv.c \
|
||||||
|
-f lib/m2/waitpid.c \
|
||||||
|
-f lib/linux/gettimeofday.c \
|
||||||
|
-f lib/m2/clock_gettime.c \
|
||||||
|
-f lib/m2/time.c \
|
||||||
|
-f lib/linux/_getcwd.c \
|
||||||
|
-f lib/m2/getcwd.c \
|
||||||
|
-f lib/linux/dup.c \
|
||||||
|
-f lib/linux/dup2.c \
|
||||||
|
-f lib/string/strcmp.c \
|
||||||
|
-f lib/string/memcmp.c \
|
||||||
|
-f lib/linux/unlink.c \
|
||||||
|
-f src/builtins.c \
|
||||||
|
-f src/core.c \
|
||||||
|
-f src/display.c \
|
||||||
|
-f src/eval-apply.c \
|
||||||
|
-f src/gc.c \
|
||||||
|
-f src/hash.c \
|
||||||
|
-f src/lib.c \
|
||||||
|
-f src/m2.c \
|
||||||
|
-f src/math.c \
|
||||||
|
-f src/mes.c \
|
||||||
|
-f src/module.c \
|
||||||
|
-f src/posix.c \
|
||||||
|
-f src/reader.c \
|
||||||
|
-f src/stack.c \
|
||||||
|
-f src/string.c \
|
||||||
|
-f src/struct.c \
|
||||||
|
-f src/symbol.c \
|
||||||
|
-f src/vector.c \
|
||||||
|
-o m2/mes.M1
|
||||||
|
|
||||||
|
blood-elf -f m2/mes.M1 -o m2/mes.blood-elf-M1
|
||||||
|
|
||||||
|
M1 \
|
||||||
|
--LittleEndian \
|
||||||
|
--architecture x86 \
|
||||||
|
-f lib/m2/x86/x86_defs.M1 \
|
||||||
|
-f lib/x86-mes/x86.M1 \
|
||||||
|
-f lib/linux/x86-mes-m2/crt1.M1 \
|
||||||
|
-f m2/mes.M1 \
|
||||||
|
-f m2/mes.blood-elf-M1 \
|
||||||
|
-o m2/mes.hex2
|
||||||
|
|
||||||
|
mkdir -p bin
|
||||||
|
hex2 \
|
||||||
|
--LittleEndian \
|
||||||
|
--architecture x86 \
|
||||||
|
--BaseAddress 0x1000000 \
|
||||||
|
--exec_enable \
|
||||||
|
-f lib/linux/x86-mes/elf32-header.hex2 \
|
||||||
|
-f m2/mes.hex2 \
|
||||||
|
-o bin/mes-m2
|
||||||
|
|
||||||
|
echo Running mes-m2
|
||||||
|
./bin/mes-m2 -c "(display 'Hello,M2-mes!) (newline)"
|
||||||
|
cp bin/mes-m2 bin/mes
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
|
@ -22,6 +22,11 @@
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef HAVE_FLOAT
|
||||||
|
#define HAVE_FLOAT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !__TINYC__
|
||||||
void
|
void
|
||||||
__attribute__ ((noinline))
|
__attribute__ ((noinline))
|
||||||
longjmp (jmp_buf env, int val)
|
longjmp (jmp_buf env, int val)
|
||||||
|
@ -35,7 +40,9 @@ longjmp (jmp_buf env, int val)
|
||||||
"ldr r13, [r0], #4\n\t" /* stack pointer (sp) */
|
"ldr r13, [r0], #4\n\t" /* stack pointer (sp) */
|
||||||
"ldr r14, [r0], #4\n\t" /* link register (lr) */
|
"ldr r14, [r0], #4\n\t" /* link register (lr) */
|
||||||
"ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11}\n\t"
|
"ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11}\n\t"
|
||||||
|
#if HAVE_FLOAT
|
||||||
// TODO: If using VFP, vldmia r0!, {d8-d15}
|
// TODO: If using VFP, vldmia r0!, {d8-d15}
|
||||||
|
#endif
|
||||||
"mov r0, r1\n\t"
|
"mov r0, r1\n\t"
|
||||||
:
|
:
|
||||||
: "r" (env), "r" (val));
|
: "r" (env), "r" (val));
|
||||||
|
@ -43,6 +50,58 @@ longjmp (jmp_buf env, int val)
|
||||||
// not reached
|
// not reached
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else //__TINYC__
|
||||||
|
|
||||||
|
#ifndef SETJMP_ASM
|
||||||
|
#define SETJMP_ASM 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SETJMP_ASM
|
||||||
|
|
||||||
|
__asm__ (".global longjmp\n");
|
||||||
|
__asm__ ("longjmp:\n");
|
||||||
|
__asm__ (".int 0xe52db004\n"); //push {fp} ; (str fp, [sp, #-4]!)
|
||||||
|
__asm__ (".int 0xe28db000\n"); //add fp, sp, #0
|
||||||
|
__asm__ (".int 0xe24dd00c\n"); //sub sp, sp, #12
|
||||||
|
__asm__ (".int 0xe50b0008\n"); //str r0, [fp, #-8]
|
||||||
|
__asm__ (".int 0xe50b100c\n"); //str r1, [fp, #-12]
|
||||||
|
__asm__ (".int 0xe51b3008\n"); //ldr r3, [fp, #-8]
|
||||||
|
__asm__ (".int 0xe51b200c\n"); //ldr r2, [fp, #-12]
|
||||||
|
__asm__ (".int 0xe1a00003\n"); //mov r0, r3
|
||||||
|
__asm__ (".int 0xe1a01002\n"); //mov r1, r2
|
||||||
|
__asm__ (".int 0xe3510000\n"); //cmp r1, #0
|
||||||
|
__asm__ (".int 0x03a01001\n"); //moveq r1, #1
|
||||||
|
__asm__ (".int 0xe490d004\n"); //ldr sp, [r0], #4
|
||||||
|
__asm__ (".int 0xe490e004\n"); //ldr lr, [r0], #4
|
||||||
|
__asm__ (".int 0xe8b00ff0\n"); //ldm r0!, {r4, r5, r6, r7, r8, r9, sl, fp}
|
||||||
|
#if HAVE_FLOAT
|
||||||
|
// TODO: If using VFP, vldmia r0!, {d8-d15}
|
||||||
|
#endif
|
||||||
|
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
|
||||||
|
__asm__ (".int 0xe12fff1e\n"); //bx lr
|
||||||
|
|
||||||
|
#else //!SETJMP_ASM
|
||||||
|
|
||||||
|
void
|
||||||
|
__attribute__ ((noinline))
|
||||||
|
longjmp (jmp_buf env, int val)
|
||||||
|
{
|
||||||
|
__asm__ (".int 0xe3510000\n"); //cmp r1, #0
|
||||||
|
__asm__ (".int 0x03a01001\n"); //moveq r1, #1
|
||||||
|
__asm__ (".int 0xe490d004\n"); //ldr sp, [r0], #4
|
||||||
|
__asm__ (".int 0xe490e004\n"); //ldr lr, [r0], #4
|
||||||
|
__asm__ (".int 0xe8b00ff0\n"); //ldm r0!, {r4, r5, r6, r7, r8, r9, sl, fp}
|
||||||
|
#if HAVE_FLOAT
|
||||||
|
// TODO: If using VFP, vldmia r0!, {d8-d15}
|
||||||
|
#endif
|
||||||
|
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
|
||||||
|
__asm__ (".int 0xe12fff1e\n"); //bx lr
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //!SETJMP_ASM
|
||||||
|
#endif //__TINYC__
|
||||||
|
|
||||||
|
#if !__TINYC__
|
||||||
int
|
int
|
||||||
__attribute__ ((noinline))
|
__attribute__ ((noinline))
|
||||||
setjmp (jmp_buf env)
|
setjmp (jmp_buf env)
|
||||||
|
@ -53,10 +112,58 @@ setjmp (jmp_buf env)
|
||||||
"str r13, [r0], #4\n\t" /* stack pointer (sp) */
|
"str r13, [r0], #4\n\t" /* stack pointer (sp) */
|
||||||
"str r14, [r0], #4\n\t" /* link register (lr) */
|
"str r14, [r0], #4\n\t" /* link register (lr) */
|
||||||
"stmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11}\n\t"
|
"stmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11}\n\t"
|
||||||
|
#if HAVE_FLOAT
|
||||||
// TODO: If using VFP, vstmia r0!, {d8-d15}
|
// TODO: If using VFP, vstmia r0!, {d8-d15}
|
||||||
|
#endif
|
||||||
:
|
:
|
||||||
: "r" (env)
|
: "r" (env)
|
||||||
: "r0");
|
: "r0");
|
||||||
// *INDENT-ON*
|
// *INDENT-ON*
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#else //__TINYC__
|
||||||
|
|
||||||
|
#if SETJMP_ASM
|
||||||
|
|
||||||
|
__asm__ (".global setjmp\n");
|
||||||
|
__asm__ ("setjmp:\n");
|
||||||
|
__asm__ (".int 0xe52db004\n"); //push {fp} ; (str fp, [sp, #-4]!)
|
||||||
|
__asm__ (".int 0xe28db000\n"); //add fp, sp, #0
|
||||||
|
__asm__ (".int 0xe24dd00c\n"); //sub sp, sp, #12
|
||||||
|
__asm__ (".int 0xe50b0008\n"); //str r0, [fp, #-8]
|
||||||
|
__asm__ (".int 0xe51b3008\n"); //ldr r3, [fp, #-8]
|
||||||
|
__asm__ (".int 0xe1a00003\n"); //mov r0, r3
|
||||||
|
__asm__ (".int 0xe480d004\n"); //str sp, [r0], #4
|
||||||
|
__asm__ (".int 0xe480e004\n"); //str lr, [r0], #4
|
||||||
|
__asm__ (".int 0xe28bd000\n"); //add sp, fp, #0
|
||||||
|
__asm__ (".int 0xe49db004\n"); //pop {fp} ; (ldr fp, [sp], #4)
|
||||||
|
__asm__ (".int 0xe8a00ff0\n"); //stmia r0!, {r4, r5, r6, r7, r8, r9, sl, fp}
|
||||||
|
#if HAVE_FLOAT
|
||||||
|
// TODO: If using VFP, vstmia r0!, {d8-d15}
|
||||||
|
#endif
|
||||||
|
__asm__ (".int 0xe1a0b00d\n"); //mov fp, sp
|
||||||
|
__asm__ (".int 0xe3a03000\n"); //mov r3, #0
|
||||||
|
__asm__ (".int 0xe1a00003\n"); //mov r0, r3
|
||||||
|
__asm__ (".int 0xe12fff1e\n"); //bx lr
|
||||||
|
|
||||||
|
#else //!SETJMP_ASM
|
||||||
|
|
||||||
|
int
|
||||||
|
__attribute__ ((noinline))
|
||||||
|
setjmp (jmp_buf env)
|
||||||
|
{
|
||||||
|
__asm__ (".int 0xe480d004\n"); //str sp, [r0], #4
|
||||||
|
__asm__ (".int 0xe480e004\n"); //str lr, [r0], #4
|
||||||
|
//__asm__ (".int 0xe1a0300b\n"); //mov r3, fp
|
||||||
|
__asm__ (".int 0xe59bb000\n"); //ldr fp, [fp]
|
||||||
|
__asm__ (".int 0xe8a00ff0\n"); //stmia r0!, {r4, r5, r6, r7, r8, r9, sl, fp}
|
||||||
|
#if HAVE_FLOAT
|
||||||
|
// TODO: If using VFP, vstmia r0!, {d8-d15}
|
||||||
|
#endif
|
||||||
|
__asm__ (".int 0xe1a0b00d\n"); //mov fp, sp
|
||||||
|
//__asm__ (".int 0xe1a0b003\n"); //mov fp, r3
|
||||||
|
__asm__ (".int 0xe3a00000\n"); // mov r0, #0
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //!SETJMP_ASM
|
||||||
|
#endif //__TINYC__
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
|
#define SYS_exit "0x01"
|
||||||
|
|
||||||
|
// *INDENT-OFF*
|
||||||
|
void
|
||||||
|
_exit (int code)
|
||||||
|
{
|
||||||
|
asm (
|
||||||
|
"mov $"SYS_exit",%%eax\n\t"
|
||||||
|
"mov %0,%%ebx\n\t"
|
||||||
|
"push %%ebx\n\t"
|
||||||
|
"push %%ebx\n\t"
|
||||||
|
"int $0x80\n\t"
|
||||||
|
: // no outputs "=" (r)
|
||||||
|
: "rm" (code)
|
||||||
|
: "eax", "ebx"
|
||||||
|
);
|
||||||
|
// not reached
|
||||||
|
_exit (0);
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -21,33 +21,21 @@
|
||||||
#include "mes/lib-mini.h"
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
#define SYS_exit "0x01"
|
#define SYS_exit "0x01"
|
||||||
#define SYS_write "0x04"
|
|
||||||
|
|
||||||
// *INDENT-OFF*
|
// *INDENT-OFF*
|
||||||
void
|
|
||||||
_exit (int code)
|
|
||||||
{
|
|
||||||
asm (
|
|
||||||
"mov $"SYS_exit",%%eax\n\t"
|
|
||||||
"mov %0,%%ebx\n\t"
|
|
||||||
"int $0x80\n\t"
|
|
||||||
: // no outputs "=" (r)
|
|
||||||
: "rm" (code)
|
|
||||||
: "eax", "ebx"
|
|
||||||
);
|
|
||||||
// not reached
|
|
||||||
_exit (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
_write (int filedes, void const *buffer, size_t size)
|
_write (int filedes, void const *buffer, size_t size)
|
||||||
{
|
{
|
||||||
long r;
|
long r;
|
||||||
asm (
|
asm (
|
||||||
"mov $"SYS_write",%%eax\n\t"
|
"mov $"SYS_write",%%eax\n\t"
|
||||||
"mov %1,%%ebx\n\t"
|
|
||||||
"mov %2,%%ecx\n\t"
|
|
||||||
"mov %3,%%edx\n\t"
|
"mov %3,%%edx\n\t"
|
||||||
|
"push %%edx\n\t"
|
||||||
|
"mov %2,%%ecx\n\t"
|
||||||
|
"push %%ecx\n\t"
|
||||||
|
"mov %1,%%ebx\n\t"
|
||||||
|
"push %%ebx\n\t"
|
||||||
|
"push %%ebx\n\t"
|
||||||
"int $0x80\n\t"
|
"int $0x80\n\t"
|
||||||
"mov %%eax,%0\n\t"
|
"mov %%eax,%0\n\t"
|
||||||
: "=r" (r)
|
: "=r" (r)
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
_exit ()
|
||||||
|
{
|
||||||
|
asm ("mov____$i32,%eax SYS_exit");
|
||||||
|
asm ("mov____0x8(%ebp),%ebx !8");
|
||||||
|
asm ("push___%ebx");
|
||||||
|
asm ("push___%ebx");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -18,20 +18,16 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
|
||||||
_exit ()
|
|
||||||
{
|
|
||||||
asm ("mov____$i32,%eax SYS_exit");
|
|
||||||
asm ("mov____0x8(%ebp),%ebx !8");
|
|
||||||
asm ("int____$0x80");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_write ()
|
_write ()
|
||||||
{
|
{
|
||||||
asm ("mov____$i32,%eax SYS_write");
|
asm ("mov____$i32,%eax SYS_write");
|
||||||
asm ("mov____0x8(%ebp),%ebx !8");
|
|
||||||
asm ("mov____0x8(%ebp),%ecx !12");
|
|
||||||
asm ("mov____0x8(%ebp),%edx !16");
|
asm ("mov____0x8(%ebp),%edx !16");
|
||||||
|
asm ("push___%edx");
|
||||||
|
asm ("mov____0x8(%ebp),%ecx !12");
|
||||||
|
asm ("push___%ecx");
|
||||||
|
asm ("mov____0x8(%ebp),%ebx !8");
|
||||||
|
asm ("push___%ebx");
|
||||||
|
asm ("push___%ebx");
|
||||||
asm ("int____$0x80");
|
asm ("int____$0x80");
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -20,4 +20,4 @@
|
||||||
|
|
||||||
#include "mes/lib-mini.h"
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
// your mini mach here
|
// your mach _exit here
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
|
// your mach _write here
|
180
lib/libtcc1.c
180
lib/libtcc1.c
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2017,2018,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -23,21 +23,37 @@
|
||||||
double
|
double
|
||||||
__divdi3 (double a, double b)
|
__divdi3 (double a, double b)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__divdi3 stub\n");
|
eputs ("__divdi3 stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
return ((long) a / (long) b);
|
#endif
|
||||||
|
long ai = a;
|
||||||
|
long bi = b;
|
||||||
|
#if __arm__ && __TINYC__
|
||||||
|
return __mesabi_idiv (ai, bi);
|
||||||
|
#else
|
||||||
|
return ai / bi;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
__moddi3 (double a, double b)
|
__moddi3 (double a, double b)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__moddi3 stub\n");
|
eputs ("__moddi3 stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
return ((long) a % (long) b);
|
#endif
|
||||||
|
long ai = a;
|
||||||
|
long bi = b;
|
||||||
|
#if __arm__ && __TINYC__
|
||||||
|
return __mesabi_imod (ai, bi);
|
||||||
|
#else
|
||||||
|
return ai % bi;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
|
@ -48,15 +64,21 @@ unsigned long
|
||||||
__udivdi3 (unsigned long a, long ah, unsigned long b)
|
__udivdi3 (unsigned long a, long ah, unsigned long b)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__udivdi3 stub\n");
|
eputs ("__udivdi3 stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
if (!b)
|
#endif
|
||||||
return 0;
|
|
||||||
unsigned long ai = a;
|
unsigned long ai = a;
|
||||||
unsigned long bi = b;
|
unsigned long bi = b;
|
||||||
|
if (!b)
|
||||||
|
return 0;
|
||||||
|
#if __arm__ && __TINYC__
|
||||||
|
return __mesabi_idiv (ai, bi);
|
||||||
|
#else
|
||||||
return ai / bi;
|
return ai / bi;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
|
@ -67,13 +89,19 @@ unsigned long
|
||||||
__umoddi3 (unsigned long a, long ah, unsigned long b)
|
__umoddi3 (unsigned long a, long ah, unsigned long b)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__umoddi3 stub\n");
|
eputs ("__umoddi3 stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
|
#endif
|
||||||
unsigned long ai = a;
|
unsigned long ai = a;
|
||||||
unsigned long bi = b;
|
unsigned long bi = b;
|
||||||
|
#if __arm__ && __TINYC__
|
||||||
|
return __mesabi_imod (ai, bi);
|
||||||
|
#else
|
||||||
return ai % bi;
|
return ai % bi;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
|
@ -84,17 +112,21 @@ unsigned long
|
||||||
__lshrdi3 (unsigned long a, long ah, long b)
|
__lshrdi3 (unsigned long a, long ah, long b)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__lshrdi3 stub\n");
|
eputs ("__lshrdi3 stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
#if 0 // In some instances, this recurses
|
|
||||||
return a >> b;
|
return a >> b;
|
||||||
#else
|
#else // __TINYC__
|
||||||
for (int i = 0; i < b; i++)
|
for (int i = 0; i < b; i++)
|
||||||
|
#if __arm__
|
||||||
|
a = __mesabi_idiv (a, 2);
|
||||||
|
#else // !__arm__
|
||||||
a /= 2;
|
a /= 2;
|
||||||
|
#endif // !__arm__
|
||||||
return a;
|
return a;
|
||||||
#endif
|
#endif // __TINYC__
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
|
@ -105,17 +137,17 @@ long
|
||||||
__ashldi3 (long a, long ah, long b)
|
__ashldi3 (long a, long ah, long b)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__ashldi3 stub\n");
|
eputs ("__ashldi3 stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
#if 0 // In some instances, this recurses
|
|
||||||
return a << b;
|
return a << b;
|
||||||
#else
|
#else // __TINYC__
|
||||||
for (int i = 0; i < b; i++)
|
for (int i = 0; i < b; i++)
|
||||||
a += a;
|
a += a;
|
||||||
return a;
|
return a;
|
||||||
#endif
|
#endif // __TINYC__
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
|
@ -126,31 +158,57 @@ long
|
||||||
__ashrdi3 (long a, long ah, long b)
|
__ashrdi3 (long a, long ah, long b)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__ashrdi3 stub\n");
|
eputs ("__ashrdi3 stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
#if 0 // In some instances, this recurses
|
return a >> b;
|
||||||
return a >> b;
|
#else // __TINYC__
|
||||||
#else
|
|
||||||
for (int i = 0; i < b; i++)
|
for (int i = 0; i < b; i++)
|
||||||
|
#if __arm__
|
||||||
|
a = __mesabi_idiv (a, 2);
|
||||||
|
#else // !__arm__
|
||||||
a /= 2;
|
a /= 2;
|
||||||
|
#endif // !__arm__
|
||||||
return a;
|
return a;
|
||||||
|
#endif // __TINYC__
|
||||||
|
}
|
||||||
|
|
||||||
|
#if HAVE_FLOAT_STUB || HAVE_FLOAT
|
||||||
|
double
|
||||||
|
__attribute__((weak))
|
||||||
|
#if HAVE_LONG_LONG && HAVE_FLOAT
|
||||||
|
__floatundidf (unsigned long long a)
|
||||||
|
#else
|
||||||
|
__floatundidf (unsigned long a)
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
#if !__TINYC__
|
||||||
|
static int stub = 0;
|
||||||
|
if (__mes_debug () && !stub)
|
||||||
|
eputs ("__floatundidf stub\n");
|
||||||
|
stub = 1;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_LONG_LONG && HAVE_FLOAT
|
#if HAVE_LONG_LONG && HAVE_FLOAT
|
||||||
long double
|
long double
|
||||||
|
__attribute__((weak))
|
||||||
__floatundixf (unsigned long long a)
|
__floatundixf (unsigned long long a)
|
||||||
#else
|
#else
|
||||||
double
|
double
|
||||||
|
__attribute__((weak))
|
||||||
__floatundixf (unsigned long a)
|
__floatundixf (unsigned long a)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__floatundixf stub\n");
|
eputs ("__floatundixf stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,12 +217,15 @@ unsigned long long
|
||||||
#else
|
#else
|
||||||
unsigned long
|
unsigned long
|
||||||
#endif
|
#endif
|
||||||
|
__attribute__((weak))
|
||||||
__fixunsxfdi (double a1)
|
__fixunsxfdi (double a1)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__fixunsxfdi stub\n");
|
eputs ("__fixunsxfdi stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,27 +236,32 @@ int
|
||||||
#else // !__TINYCC__
|
#else // !__TINYCC__
|
||||||
long long
|
long long
|
||||||
#endif // !__TINYCC__
|
#endif // !__TINYCC__
|
||||||
|
__attribute__((weak))
|
||||||
__fixdfdi (double a1)
|
__fixdfdi (double a1)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__fixdfdi stub\n");
|
eputs ("__fixdfdi stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
unsigned long long
|
unsigned long long
|
||||||
__fixxfdi (double a1)
|
|
||||||
#else
|
#else
|
||||||
unsigned long
|
unsigned long
|
||||||
__fixxfdi (double a1)
|
|
||||||
#endif
|
#endif
|
||||||
|
__attribute__((weak))
|
||||||
|
__fixxfdi (double a1)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__fixxfdi stub\n");
|
eputs ("__fixxfdi stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,11 +270,93 @@ long long
|
||||||
#else
|
#else
|
||||||
long
|
long
|
||||||
#endif
|
#endif
|
||||||
|
__attribute__((weak))
|
||||||
__fixsfdi (double a1)
|
__fixsfdi (double a1)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
static int stub = 0;
|
static int stub = 0;
|
||||||
if (__mes_debug () && !stub)
|
if (__mes_debug () && !stub)
|
||||||
eputs ("__fixsfdi stub\n");
|
eputs ("__fixsfdi stub\n");
|
||||||
stub = 1;
|
stub = 1;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
__attribute__((weak))
|
||||||
|
__fixunsdfdi (double num, double den)
|
||||||
|
{
|
||||||
|
#if !__TINYC__
|
||||||
|
static int stub = 0;
|
||||||
|
if (__mes_debug () && !stub)
|
||||||
|
eputs ("__fixunsdfdi stub\n");
|
||||||
|
stub = 1;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif // HAVE_FLOAT_STUB || HAVE_FLOAT
|
||||||
|
|
||||||
|
int
|
||||||
|
__attribute__((weak))
|
||||||
|
__fixunsdfsi (int a, int b)
|
||||||
|
{
|
||||||
|
#if !__TINYC__
|
||||||
|
static int stub = 0;
|
||||||
|
if (__mes_debug () && !stub)
|
||||||
|
eputs ("__fixunsdfsi stub\n");
|
||||||
|
stub = 1;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __arm__
|
||||||
|
int
|
||||||
|
__attribute__((weak))
|
||||||
|
__floatdisf (int a, int b)
|
||||||
|
{
|
||||||
|
#if !__TINYC__
|
||||||
|
static int stub = 0;
|
||||||
|
if (__mes_debug () && !stub)
|
||||||
|
eputs ("__floatdisf stub\n");
|
||||||
|
stub = 1;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__attribute__((weak))
|
||||||
|
__floatdidf (int a, int b)
|
||||||
|
{
|
||||||
|
#if !__TINYC__
|
||||||
|
static int stub = 0;
|
||||||
|
if (__mes_debug () && !stub)
|
||||||
|
eputs ("__floatdidf stub\n");
|
||||||
|
stub = 1;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__divsi3 (int num, int den)
|
||||||
|
{
|
||||||
|
return __mesabi_idiv (num, den);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__modsi3 (int num, int den)
|
||||||
|
{
|
||||||
|
return __mesabi_imod (num, den);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__udivsi3 (int num, int den)
|
||||||
|
{
|
||||||
|
return __mesabi_udiv (num, den);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__umodsi3 (int num, int den)
|
||||||
|
{
|
||||||
|
return __mesabi_umod (num, den);
|
||||||
|
}
|
||||||
|
#endif //__arm__
|
||||||
|
|
|
@ -18,14 +18,15 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <mes/lib-mini.h>
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
char *
|
char *
|
||||||
_getcwd (char *buffer, size_t size)
|
_getcwd (char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
int r = _sys_call2 (SYS_getcwd, (long) buffer, (long) size);
|
long long_buffer = cast_charp_to_long (buffer);
|
||||||
|
int r = _sys_call2 (SYS_getcwd, long_buffer, size);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
return buffer;
|
return buffer;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -27,7 +27,6 @@ int
|
||||||
_open3 (char const *file_name, int flags, int mask)
|
_open3 (char const *file_name, int flags, int mask)
|
||||||
{
|
{
|
||||||
int r = _sys_call3 (SYS_open, (long) file_name, (int) flags, (int) mask);
|
int r = _sys_call3 (SYS_open, (long) file_name, (int) flags, (int) mask);
|
||||||
__ungetc_init ();
|
|
||||||
if (r > 2)
|
if (r > 2)
|
||||||
{
|
{
|
||||||
__ungetc_clear (r);
|
__ungetc_clear (r);
|
||||||
|
|
|
@ -18,11 +18,14 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
access (char const *file_name, int how)
|
access (char const *file_name, int how)
|
||||||
{
|
{
|
||||||
return _sys_call2 (SYS_access, (long) file_name, (int) how);
|
long long_file_name = cast_charp_to_long (file_name);
|
||||||
|
long long_how = cast_int_to_long (how);
|
||||||
|
return _sys_call2 (SYS_access, long_file_name, long_how);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
|
@ -21,10 +21,9 @@
|
||||||
|
|
||||||
#include "mes/lib-mini.h"
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
#define SYS_exit "0x01"
|
|
||||||
#define SYS_write "0x04"
|
|
||||||
|
|
||||||
// *INDENT-OFF*
|
// *INDENT-OFF*
|
||||||
|
#if !__TINYC__
|
||||||
|
#define SYS_exit "0x01"
|
||||||
void
|
void
|
||||||
_exit (int code)
|
_exit (int code)
|
||||||
{
|
{
|
||||||
|
@ -39,22 +38,14 @@ _exit (int code)
|
||||||
// not reached
|
// not reached
|
||||||
_exit (0);
|
_exit (0);
|
||||||
}
|
}
|
||||||
|
#else //__TINYC__
|
||||||
ssize_t
|
#define SYS_exit 0x01
|
||||||
_write (int filedes, void const *buffer, size_t size)
|
void
|
||||||
|
_exit (int code)
|
||||||
{
|
{
|
||||||
long r;
|
int c = SYS_exit;
|
||||||
asm (
|
__asm__ (".int 0xe51b7004\n"); //ldr r7, [fp, #-4] ; "c"
|
||||||
"mov r7, $"SYS_write"\n\t"
|
__asm__ (".int 0xe59b000c\n"); //ldr r0, [fp, #12] ; code
|
||||||
"mov r0, %1\n\t"
|
__asm__ (".int 0xef000000\n"); //svc 0x00000000
|
||||||
"mov r1, %2\n\t"
|
|
||||||
"mov r3, %3\n\t"
|
|
||||||
"swi $0\n\t"
|
|
||||||
"mov %0, r0\n\t"
|
|
||||||
: "=r" (r)
|
|
||||||
: "r" (filedes), "r" (buffer), "r" (size)
|
|
||||||
: "r0", "r1", "r2", "r7"
|
|
||||||
);
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
// *INDENT-ON*
|
#endif //__TINYC__
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
|
// *INDENT-OFF*
|
||||||
|
#if !__TINYC__
|
||||||
|
#define SYS_write "0x04"
|
||||||
|
ssize_t
|
||||||
|
_write (int filedes, void const *buffer, size_t size)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
asm (
|
||||||
|
"mov r7, $"SYS_write"\n\t"
|
||||||
|
"mov r0, %1\n\t"
|
||||||
|
"mov r1, %2\n\t"
|
||||||
|
"mov r3, %3\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
"mov %0, r0\n\t"
|
||||||
|
: "=r" (r)
|
||||||
|
: "r" (filedes), "r" (buffer), "r" (size)
|
||||||
|
: "r0", "r1", "r2", "r7"
|
||||||
|
);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#else //__TINYC__
|
||||||
|
#define SYS_write 0x04
|
||||||
|
ssize_t
|
||||||
|
_write (int filedes, void const *buffer, size_t size)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
int c = SYS_write;
|
||||||
|
__asm__ (".int 0xe51b7008\n"); //ldr r7, [fp, #-8] ; <c>
|
||||||
|
__asm__ (".int 0xe59b000c\n"); //ldr r0, [fp, #12] ; filedes
|
||||||
|
__asm__ (".int 0xe59b1010\n"); //ldr r1, [fp, #16] ; buffer
|
||||||
|
__asm__ (".int 0xe59b2014\n"); //ldr r2, [fp, #20] ; size
|
||||||
|
__asm__ (".int 0xef000000\n"); //svc 0x00000000
|
||||||
|
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#endif //__TINYC__
|
||||||
|
// *INDENT-ON*
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
|
@ -22,11 +22,11 @@
|
||||||
#include <mes/lib-mini.h>
|
#include <mes/lib-mini.h>
|
||||||
//int main (int argc, char *argv[], char *envp[]);
|
//int main (int argc, char *argv[], char *envp[]);
|
||||||
|
|
||||||
/* Note: GCC automatically emits a preable in order to set up the frame pointer:
|
/* Note: GCC automatically emits a preable in order to set up the
|
||||||
"push {fp}"
|
frame pointer: "push {fp}" "add fp, sp, 0"
|
||||||
"add fp, sp, 0"
|
|
||||||
*/
|
*/
|
||||||
// *INDENT-OFF*
|
// *INDENT-OFF*
|
||||||
|
#if !__TINYC__
|
||||||
void
|
void
|
||||||
_start ()
|
_start ()
|
||||||
{
|
{
|
||||||
|
@ -70,8 +70,87 @@ _start ()
|
||||||
"ldr r1,[sp, #4]\n\t" /* argv */
|
"ldr r1,[sp, #4]\n\t" /* argv */
|
||||||
"ldr r2,[sp, #8]\n\t" /* envp */
|
"ldr r2,[sp, #8]\n\t" /* envp */
|
||||||
"bl main\n\t"
|
"bl main\n\t"
|
||||||
"mov r7, #1\n\t"
|
"mov r7, #1\n\t"
|
||||||
"swi #0\n\t"
|
"swi #0\n\t"
|
||||||
"wfi \n\t"
|
"wfi \n\t"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
#else //__TINYC__
|
||||||
|
void
|
||||||
|
_start ()
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int *in = &__stdin;
|
||||||
|
int *out = &__stdout;
|
||||||
|
int *err = &__stderr;
|
||||||
|
char ***env = &environ;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
*in = 0x22;
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
*out = 0x33;
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
*err = 0x44;
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
*env = 0x55;
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* environ = argv + argc + 1 */
|
||||||
|
__asm__ (".int 0xe59b000c\n"); //ldr r0, [fp, #12]
|
||||||
|
__asm__ (".int 0xe28b1010\n"); //add r1, fp, #16
|
||||||
|
|
||||||
|
__asm__ (".int 0xe2802001\n"); //add r2, r0, #1
|
||||||
|
__asm__ (".int 0xe1a02102\n"); //lsl r2, r2, #2
|
||||||
|
__asm__ (".int 0xe0822001\n"); //add r2, r2, r1
|
||||||
|
|
||||||
|
// setup argc, argv, envp parameters on stack
|
||||||
|
__asm__ (".int 0xe52d2004\n"); //push {r2} ; (str r2, [sp, #-4]!)
|
||||||
|
__asm__ (".int 0xe52d1004\n"); //push {r1} ; (str r1, [sp, #-4]!)
|
||||||
|
__asm__ (".int 0xe52d0004\n"); //push {r0} ; (str r0, [sp, #-4]!)
|
||||||
|
__asm__ (".int 0xe1a02002\n"); //mov r2, r2
|
||||||
|
|
||||||
|
// *in = 0;
|
||||||
|
__asm__ (".int 0xe3a01000\n"); //mov r1, #0
|
||||||
|
__asm__ (".int 0xe51b0004\n"); //ldr r0, [fp, #-4]
|
||||||
|
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
|
||||||
|
// *out = 1;
|
||||||
|
__asm__ (".int 0xe3a01001\n"); //mov r1, #1
|
||||||
|
__asm__ (".int 0xe51b0008\n"); //ldr r0, [fp, #-8]
|
||||||
|
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
|
||||||
|
// *err = 2;
|
||||||
|
__asm__ (".int 0xe3a01002\n"); //mov r1, #2
|
||||||
|
__asm__ (".int 0xe51b000c\n"); //ldr r0, [fp, #-12]
|
||||||
|
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
|
||||||
|
// *env = [sp, #8]
|
||||||
|
__asm__ (".int 0xe59d1008\n"); //ldr r1, [sp, #8]
|
||||||
|
__asm__ (".int 0xe51b0010\n"); //ldr r0, [fp, #-16]
|
||||||
|
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
|
||||||
|
// setup argc, argv, envp parameters in registers
|
||||||
|
__asm__ (".int 0xe59d0000\n"); //ldr r0, [sp]
|
||||||
|
__asm__ (".int 0xe59d1004\n"); //ldr r1, [sp, #4]
|
||||||
|
__asm__ (".int 0xe59d2008\n"); //ldr r2, [sp, #8]
|
||||||
|
main ();
|
||||||
|
|
||||||
|
__asm__ (".int 0xe3a07001\n"); //mov r7, #1
|
||||||
|
__asm__ (".int 0xef000000\n"); //svc 0x00000000
|
||||||
|
__asm__ (".int 0xe320f003\n"); //wfi
|
||||||
|
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||||
|
}
|
||||||
|
#endif //__TINYC__
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <linux/x86/syscall.h>
|
#include <linux/x86/syscall.h>
|
||||||
|
|
||||||
|
#if !__TINYC__
|
||||||
// *INDENT-OFF*
|
// *INDENT-OFF*
|
||||||
long
|
long
|
||||||
__sys_call (long sys_call)
|
__sys_call (long sys_call)
|
||||||
|
@ -36,7 +37,23 @@ __sys_call (long sys_call)
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
#else //__TINYC__
|
||||||
|
long
|
||||||
|
__sys_call (long sys_call)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
|
||||||
|
// __asm__ (".int 0xe1a00001\n"); //mov r0, r1
|
||||||
|
// __asm__ (".int 0xe1a01002\n"); //mov r1, r2
|
||||||
|
// __asm__ (".int 0xe1a02003\n"); //mov r2, r3
|
||||||
|
// __asm__ (".int 0xe1a03004\n"); //mov r3, r4
|
||||||
|
__asm__ (".int 0xef000000\n"); //svc 0x00000000
|
||||||
|
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#endif //__TINYC__
|
||||||
|
|
||||||
|
#if !__TINYC__
|
||||||
long
|
long
|
||||||
__sys_call1 (long sys_call, long one)
|
__sys_call1 (long sys_call, long one)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +69,23 @@ __sys_call1 (long sys_call, long one)
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
#else //__TINYC__
|
||||||
|
long
|
||||||
|
__sys_call1 (long sys_call, long one)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
|
||||||
|
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
|
||||||
|
// __asm__ (".int 0xe1a01002\n"); //mov r1, r2
|
||||||
|
// __asm__ (".int 0xe1a02003\n"); //mov r2, r3
|
||||||
|
// __asm__ (".int 0xe1a03004\n"); //mov r3, r4
|
||||||
|
__asm__ (".int 0xef000000\n"); //svc 0x00000000
|
||||||
|
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#endif //__TINYC__
|
||||||
|
|
||||||
|
#if !__TINYC__
|
||||||
long
|
long
|
||||||
__sys_call2 (long sys_call, long one, long two)
|
__sys_call2 (long sys_call, long one, long two)
|
||||||
{
|
{
|
||||||
|
@ -69,7 +102,23 @@ __sys_call2 (long sys_call, long one, long two)
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
#else //__TINYC__
|
||||||
|
long
|
||||||
|
__sys_call2 (long sys_call, long one, long two)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
|
||||||
|
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
|
||||||
|
__asm__ (".int 0xe1a01002\n"); //mov r1, r2
|
||||||
|
// __asm__ (".int 0xe1a02003\n"); //mov r2, r3
|
||||||
|
// __asm__ (".int 0xe1a03004\n"); //mov r3, r4
|
||||||
|
__asm__ (".int 0xef000000\n"); //svc 0x00000000
|
||||||
|
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#endif //__TINYC__
|
||||||
|
|
||||||
|
#if !__TINYC__
|
||||||
long
|
long
|
||||||
__sys_call3 (long sys_call, long one, long two, long three)
|
__sys_call3 (long sys_call, long one, long two, long three)
|
||||||
{
|
{
|
||||||
|
@ -87,7 +136,23 @@ __sys_call3 (long sys_call, long one, long two, long three)
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
#else //__TINYC__
|
||||||
|
long
|
||||||
|
__sys_call3 (long sys_call, long one, long two, long three)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
|
||||||
|
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
|
||||||
|
__asm__ (".int 0xe1a01002\n"); //mov r1, r2
|
||||||
|
__asm__ (".int 0xe1a02003\n"); //mov r2, r3
|
||||||
|
// __asm__ (".int 0xe1a03004\n"); //mov r3, r4
|
||||||
|
__asm__ (".int 0xef000000\n"); //svc 0x00000000
|
||||||
|
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#endif //__TINYC__
|
||||||
|
|
||||||
|
#if !__TINYC__
|
||||||
long
|
long
|
||||||
__sys_call4 (long sys_call, long one, long two, long three, long four)
|
__sys_call4 (long sys_call, long one, long two, long three, long four)
|
||||||
{
|
{
|
||||||
|
@ -106,6 +171,21 @@ __sys_call4 (long sys_call, long one, long two, long three, long four)
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
#else //__TINYC__
|
||||||
|
long
|
||||||
|
__sys_call4 (long sys_call, long one, long two, long three, long four)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
|
||||||
|
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
|
||||||
|
__asm__ (".int 0xe1a01002\n"); //mov r1, r2
|
||||||
|
__asm__ (".int 0xe1a02003\n"); //mov r2, r3
|
||||||
|
__asm__ (".int 0xe1a03004\n"); //mov r3, r4
|
||||||
|
__asm__ (".int 0xef000000\n"); //svc 0x00000000
|
||||||
|
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#endif //__TINYC__
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
long
|
long
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
* Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
_exit ()
|
||||||
|
{
|
||||||
|
asm ("SYS_exit mov____$i8,%r7");
|
||||||
|
asm ("!8 ldr____%r0,(%fp,+#$i8)");
|
||||||
|
asm ("swi____$0");
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
* Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
|
* Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
|
@ -19,14 +19,6 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
|
||||||
_exit ()
|
|
||||||
{
|
|
||||||
asm ("SYS_exit mov____$i8,%r7");
|
|
||||||
asm ("!8 ldr____%r0,(%fp,+#$i8)");
|
|
||||||
asm ("swi____$0");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_write ()
|
_write ()
|
||||||
{
|
{
|
|
@ -18,11 +18,13 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
long
|
long
|
||||||
brk (void *addr)
|
brk (void *addr)
|
||||||
{
|
{
|
||||||
return _sys_call1 (SYS_brk, (long) addr);
|
long long_addr = cast_voidp_to_long (addr);
|
||||||
|
return _sys_call1 (SYS_brk, long_addr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -25,5 +26,7 @@
|
||||||
int
|
int
|
||||||
chmod (char const *file_name, mode_t mask)
|
chmod (char const *file_name, mode_t mask)
|
||||||
{
|
{
|
||||||
return _sys_call2 (SYS_chmod, (long) file_name, (long) mask);
|
long long_file_name = cast_charp_to_long (file_name);
|
||||||
|
long long_mask = cast_int_to_long (mask);
|
||||||
|
return _sys_call2 (SYS_chmod, long_file_name, long_mask);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -25,5 +26,7 @@
|
||||||
int
|
int
|
||||||
clock_gettime (clockid_t clk_id, struct timespec *tp)
|
clock_gettime (clockid_t clk_id, struct timespec *tp)
|
||||||
{
|
{
|
||||||
return _sys_call2 (SYS_clock_gettime, (long) clk_id, (long) tp);
|
long long_clk_id = cast_int_to_long (clk_id);
|
||||||
|
long long_tp = cast_voidp_to_long (tp);
|
||||||
|
return _sys_call2 (SYS_clock_gettime, long_clk_id, long_tp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,5 +24,6 @@
|
||||||
int
|
int
|
||||||
dup (int old)
|
dup (int old)
|
||||||
{
|
{
|
||||||
return _sys_call1 (SYS_dup, (int) old);
|
long long_old = old;
|
||||||
|
return _sys_call1 (SYS_dup, long_old);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,5 +24,7 @@
|
||||||
int
|
int
|
||||||
dup2 (int old, int new)
|
dup2 (int old, int new)
|
||||||
{
|
{
|
||||||
return _sys_call2 (SYS_dup2, (int) old, (int) new);
|
long long_old = old;
|
||||||
|
long long_new = new;
|
||||||
|
return _sys_call2 (SYS_dup2, long_old, long_new);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
@ -25,5 +26,7 @@
|
||||||
int
|
int
|
||||||
gettimeofday (struct timeval *tv, struct timezone *tz)
|
gettimeofday (struct timeval *tv, struct timezone *tz)
|
||||||
{
|
{
|
||||||
return _sys_call2 (SYS_gettimeofday, (long) tv, (long) tz);
|
long long_tv = cast_voidp_to_long (tv);
|
||||||
|
long long_tz = cast_voidp_to_long (tz);
|
||||||
|
return _sys_call2 (SYS_gettimeofday, long_tv, long_tz);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,21 +26,23 @@
|
||||||
ssize_t
|
ssize_t
|
||||||
read (int filedes, void *buffer, size_t size)
|
read (int filedes, void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
ssize_t bytes = _sys_call3 (SYS_read, (int) filedes, (long) buffer, (long) size);
|
long long_filedes = filedes;
|
||||||
|
ssize_t bytes = _sys_call3 (SYS_read, long_filedes, buffer, size);
|
||||||
if (__mes_debug () > 4)
|
if (__mes_debug () > 4)
|
||||||
{
|
{
|
||||||
if (bytes == 1)
|
if (bytes == 1)
|
||||||
{
|
{
|
||||||
eputs ("read fd=");
|
eputs ("read fd=");
|
||||||
eputs (itoa ((int) filedes));
|
eputs (itoa (filedes));
|
||||||
eputs (" c=");
|
eputs (" c=");
|
||||||
eputc (*(char *) buffer);
|
char *s = buffer;
|
||||||
|
eputc (s[0]);
|
||||||
eputs ("\n");
|
eputs ("\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
eputs ("read fd=");
|
eputs ("read fd=");
|
||||||
eputs (itoa ((int) filedes));
|
eputs (itoa (filedes));
|
||||||
eputs (" bytes=");
|
eputs (" bytes=");
|
||||||
eputs (itoa (bytes));
|
eputs (itoa (bytes));
|
||||||
eputs ("\n");
|
eputs ("\n");
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
/* Linux' SYS_time syscall is a compatibility shim for SYS_gettimeofday.
|
/* Linux' SYS_time syscall is a compatibility shim for SYS_gettimeofday.
|
||||||
Therefore, prefer SYS_gettimeofday. */
|
Therefore, prefer SYS_gettimeofday. */
|
||||||
|
|
||||||
#if SYS_gettimeofday
|
#if defined (SYS_gettimeofday)
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ time (time_t * result)
|
||||||
return tv.tv_sec;
|
return tv.tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif SYS_time
|
#elif defined (SYS_time)
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
time (time_t * result)
|
time (time_t * result)
|
||||||
|
|
|
@ -18,11 +18,13 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
unlink (char const *file_name)
|
unlink (char const *file_name)
|
||||||
{
|
{
|
||||||
return _sys_call1 (SYS_unlink, (long) file_name);
|
long long_file_name = cast_charp_to_long (file_name);
|
||||||
|
return _sys_call1 (SYS_unlink, long_file_name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
|
#define SYS_exit "0x01"
|
||||||
|
|
||||||
|
// *INDENT-OFF*
|
||||||
|
void
|
||||||
|
_exit (int code)
|
||||||
|
{
|
||||||
|
asm (
|
||||||
|
"mov $"SYS_exit",%%eax\n\t"
|
||||||
|
"mov %0,%%ebx\n\t"
|
||||||
|
"int $0x80\n\t"
|
||||||
|
: // no outputs "=" (r)
|
||||||
|
: "rm" (code)
|
||||||
|
: "eax", "ebx"
|
||||||
|
);
|
||||||
|
// not reached
|
||||||
|
// _exit (0); // tcc has a problem with this
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -20,40 +20,18 @@
|
||||||
|
|
||||||
#include "mes/lib-mini.h"
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
#define SYS_exit "0x01"
|
|
||||||
#define SYS_write "0x04"
|
#define SYS_write "0x04"
|
||||||
|
|
||||||
// *INDENT-OFF*
|
// *INDENT-OFF*
|
||||||
void
|
|
||||||
_exit (int code)
|
|
||||||
{
|
|
||||||
asm (
|
|
||||||
"mov $"SYS_exit",%%eax\n\t"
|
|
||||||
"mov %0,%%ebx\n\t"
|
|
||||||
"push %%ebx\n\t"
|
|
||||||
"push %%ebx\n\t"
|
|
||||||
"int $0x80\n\t"
|
|
||||||
: // no outputs "=" (r)
|
|
||||||
: "rm" (code)
|
|
||||||
: "eax", "ebx"
|
|
||||||
);
|
|
||||||
// not reached
|
|
||||||
_exit (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
_write (int filedes, void const *buffer, size_t size)
|
_write (int filedes, void const *buffer, size_t size)
|
||||||
{
|
{
|
||||||
long r;
|
long r;
|
||||||
asm (
|
asm (
|
||||||
"mov $"SYS_write",%%eax\n\t"
|
"mov $"SYS_write",%%eax\n\t"
|
||||||
"mov %3,%%edx\n\t"
|
|
||||||
"push %%edx\n\t"
|
|
||||||
"mov %2,%%ecx\n\t"
|
|
||||||
"push %%ecx\n\t"
|
|
||||||
"mov %1,%%ebx\n\t"
|
"mov %1,%%ebx\n\t"
|
||||||
"push %%ebx\n\t"
|
"mov %2,%%ecx\n\t"
|
||||||
"push %%ebx\n\t"
|
"mov %3,%%edx\n\t"
|
||||||
"int $0x80\n\t"
|
"int $0x80\n\t"
|
||||||
"mov %%eax,%0\n\t"
|
"mov %%eax,%0\n\t"
|
||||||
: "=r" (r)
|
: "=r" (r)
|
|
@ -0,0 +1,59 @@
|
||||||
|
### GNU Mes --- Maxwell Equations of Software
|
||||||
|
### Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
###
|
||||||
|
### This file is part of GNU Mes.
|
||||||
|
###
|
||||||
|
### GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
### under the terms of the GNU General Public License as published by
|
||||||
|
### the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
### your option) any later version.
|
||||||
|
###
|
||||||
|
### GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
### WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
### GNU General Public License for more details.
|
||||||
|
###
|
||||||
|
### You should have received a copy of the GNU General Public License
|
||||||
|
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
:_start
|
||||||
|
push___%ebp
|
||||||
|
mov____%esp,%ebp
|
||||||
|
sub____$i32,%esp %0x1054
|
||||||
|
mov____$i8,%eax !0
|
||||||
|
mov____%eax,0x32 &GLOBAL___stdin
|
||||||
|
mov____$i8,%eax !1
|
||||||
|
mov____%eax,0x32 &GLOBAL___stdout
|
||||||
|
mov____$i8,%eax !2
|
||||||
|
mov____%eax,0x32 &GLOBAL___stderr
|
||||||
|
mov____%ebp,%eax
|
||||||
|
add____$i8,%eax !4
|
||||||
|
movzbl_(%eax),%eax
|
||||||
|
add____$i8,%eax !3
|
||||||
|
shl____$i8,%eax !0x02
|
||||||
|
add____%ebp,%eax
|
||||||
|
mov____%eax,0x32 &GLOBAL_environ
|
||||||
|
|
||||||
|
mov____%esp,%edi ; M2-Planet calling convention pushes forward
|
||||||
|
mov____%ebp,%eax ; argc
|
||||||
|
add____$i8,%eax !4
|
||||||
|
movzbl_(%eax),%eax
|
||||||
|
push___%eax
|
||||||
|
|
||||||
|
mov____%ebp,%eax ; argv
|
||||||
|
add____$i8,%eax !8
|
||||||
|
push___%eax
|
||||||
|
|
||||||
|
mov____0x32,%eax &GLOBAL_environ
|
||||||
|
push___%eax
|
||||||
|
|
||||||
|
mov____%edi,%ebp ; M2-Planet calling convention
|
||||||
|
call32 %FUNCTION_main
|
||||||
|
add____$i8,%esp !0x0
|
||||||
|
test___%eax,%eax
|
||||||
|
mov____%eax,%ebx
|
||||||
|
mov____$i32,%eax %1
|
||||||
|
int____$0x80
|
||||||
|
hlt
|
||||||
|
leave
|
||||||
|
ret
|
|
@ -0,0 +1,68 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
|
int __stdin;
|
||||||
|
int __stdout;
|
||||||
|
int __stderr;
|
||||||
|
char **environ;
|
||||||
|
int main (int argc, char **argv, char **envp);
|
||||||
|
|
||||||
|
/* FIXME: this is going to be called `FUNCTION__start'
|
||||||
|
int
|
||||||
|
_start ()
|
||||||
|
{
|
||||||
|
asm ("mov____$i8,%eax !0");
|
||||||
|
asm ("mov____%eax,0x32 &GLOBAL___stdin");
|
||||||
|
|
||||||
|
asm ("mov____$i8,%eax !1");
|
||||||
|
asm ("mov____%eax,0x32 &GLOBAL___stdout");
|
||||||
|
|
||||||
|
asm ("mov____$i8,%eax !2");
|
||||||
|
asm ("mov____%eax,0x32 &GLOBAL___stderr");
|
||||||
|
|
||||||
|
asm ("mov____%ebp,%eax");
|
||||||
|
asm ("add____$i8,%eax !4");
|
||||||
|
|
||||||
|
asm ("movzbl_(%eax),%eax");
|
||||||
|
asm ("add____$i8,%eax !3");
|
||||||
|
|
||||||
|
asm ("shl____$i8,%eax !0x02");
|
||||||
|
asm ("add____%ebp,%eax");
|
||||||
|
asm ("mov____%eax,0x32 &GLOBAL_environ");
|
||||||
|
asm ("push___%eax");
|
||||||
|
|
||||||
|
asm ("mov____%ebp,%eax");
|
||||||
|
asm ("add____$i8,%eax !8");
|
||||||
|
asm ("push___%eax");
|
||||||
|
|
||||||
|
asm ("mov____%ebp,%eax");
|
||||||
|
asm ("add____$i8,%eax !4");
|
||||||
|
asm ("movzbl_(%eax),%eax");
|
||||||
|
asm ("push___%eax");
|
||||||
|
main ();
|
||||||
|
|
||||||
|
asm ("mov____%eax,%ebx");
|
||||||
|
asm ("mov____$i32,%eax %1");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
asm ("hlt");
|
||||||
|
}
|
||||||
|
*/
|
|
@ -22,22 +22,16 @@ void
|
||||||
_exit ()
|
_exit ()
|
||||||
{
|
{
|
||||||
asm ("mov____$i32,%eax SYS_exit");
|
asm ("mov____$i32,%eax SYS_exit");
|
||||||
asm ("mov____0x8(%ebp),%ebx !8");
|
asm ("mov____0x8(%ebp),%ebx !-4");
|
||||||
asm ("push___%ebx");
|
|
||||||
asm ("push___%ebx");
|
|
||||||
asm ("int____$0x80");
|
asm ("int____$0x80");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_write ()
|
_write (int filedes, void *buffer, int size)
|
||||||
{
|
{
|
||||||
asm ("mov____$i32,%eax SYS_write");
|
asm ("mov____$i32,%eax SYS_write");
|
||||||
asm ("mov____0x8(%ebp),%edx !16");
|
asm ("mov____0x8(%ebp),%ebx !-4");
|
||||||
asm ("push___%edx");
|
asm ("mov____0x8(%ebp),%ecx !-8");
|
||||||
asm ("mov____0x8(%ebp),%ecx !12");
|
asm ("mov____0x8(%ebp),%edx !-12");
|
||||||
asm ("push___%ecx");
|
|
||||||
asm ("mov____0x8(%ebp),%ebx !8");
|
|
||||||
asm ("push___%ebx");
|
|
||||||
asm ("push___%ebx");
|
|
||||||
asm ("int____$0x80");
|
asm ("int____$0x80");
|
||||||
}
|
}
|
|
@ -0,0 +1,139 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <linux/x86/syscall.h>
|
||||||
|
|
||||||
|
int errno;
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call (int sys_call)
|
||||||
|
{
|
||||||
|
asm ("mov____0x8(%ebp),%eax !-4");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call1 (int sys_call, int one)
|
||||||
|
{
|
||||||
|
asm ("mov____0x8(%ebp),%eax !-4");
|
||||||
|
asm ("mov____0x8(%ebp),%ebx !-8");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call2 (int sys_call, int one, int two)
|
||||||
|
{
|
||||||
|
asm ("mov____0x8(%ebp),%eax !-4");
|
||||||
|
asm ("mov____0x8(%ebp),%ebx !-8");
|
||||||
|
asm ("mov____0x8(%ebp),%ecx !-12");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call3 (int sys_call, int one, int two, int three)
|
||||||
|
{
|
||||||
|
asm ("mov____0x8(%ebp),%eax !-4");
|
||||||
|
asm ("mov____0x8(%ebp),%ebx !-8");
|
||||||
|
asm ("mov____0x8(%ebp),%ecx !-12");
|
||||||
|
asm ("mov____0x8(%ebp),%edx !-16");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call4 (int sys_call, int one, int two, int three, int four)
|
||||||
|
{
|
||||||
|
asm ("mov____0x8(%ebp),%eax !-4");
|
||||||
|
asm ("mov____0x8(%ebp),%ebx !-8");
|
||||||
|
asm ("mov____0x8(%ebp),%ecx !-12");
|
||||||
|
asm ("mov____0x8(%ebp),%edx !-16");
|
||||||
|
asm ("mov____0x8(%ebp),%esi !-24");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
_sys_call (int sys_call)
|
||||||
|
{
|
||||||
|
int r = __sys_call (sys_call);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
errno = -r;
|
||||||
|
r = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errno = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
_sys_call1 (int sys_call, int one)
|
||||||
|
{
|
||||||
|
int r = __sys_call1 (sys_call, one);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
errno = -r;
|
||||||
|
r = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errno = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
_sys_call2 (int sys_call, int one, int two)
|
||||||
|
{
|
||||||
|
int r = __sys_call2 (sys_call, one, two);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
errno = -r;
|
||||||
|
r = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errno = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
_sys_call3 (int sys_call, int one, int two, int three)
|
||||||
|
{
|
||||||
|
int r = __sys_call3 (sys_call, one, two, three);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
errno = -r;
|
||||||
|
r = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errno = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
_sys_call4 (int sys_call, int one, int two, int three, int four)
|
||||||
|
{
|
||||||
|
int r = __sys_call4 (sys_call, one, two, three, four);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
errno = -r;
|
||||||
|
r = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errno = 0;
|
||||||
|
return r;
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
_exit ()
|
||||||
|
{
|
||||||
|
asm ("mov____$i32,%eax SYS_exit");
|
||||||
|
asm ("mov____0x8(%ebp),%ebx !8");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
_write ()
|
||||||
|
{
|
||||||
|
asm ("mov____$i32,%eax SYS_write");
|
||||||
|
asm ("mov____0x8(%ebp),%ebx !8");
|
||||||
|
asm ("mov____0x8(%ebp),%ecx !12");
|
||||||
|
asm ("mov____0x8(%ebp),%edx !16");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
|
#define SYS_exit "0x3c"
|
||||||
|
|
||||||
|
// *INDENT-OFF*
|
||||||
|
void
|
||||||
|
_exit (int code)
|
||||||
|
{
|
||||||
|
asm (
|
||||||
|
"mov $"SYS_exit",%%rax\n\t"
|
||||||
|
"mov %0,%%rdi\n\t"
|
||||||
|
"syscall \n\t"
|
||||||
|
: // no outputs "=" (r)
|
||||||
|
: "rm" (code)
|
||||||
|
);
|
||||||
|
// not reached
|
||||||
|
_exit (0);
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -20,24 +20,9 @@
|
||||||
|
|
||||||
#include "mes/lib-mini.h"
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
#define SYS_exit "0x3c"
|
|
||||||
#define SYS_write "0x01"
|
#define SYS_write "0x01"
|
||||||
|
|
||||||
// *INDENT-OFF*
|
// *INDENT-OFF*
|
||||||
void
|
|
||||||
_exit (int code)
|
|
||||||
{
|
|
||||||
asm (
|
|
||||||
"mov $"SYS_exit",%%rax\n\t"
|
|
||||||
"mov %0,%%rdi\n\t"
|
|
||||||
"syscall \n\t"
|
|
||||||
: // no outputs "=" (r)
|
|
||||||
: "rm" (code)
|
|
||||||
);
|
|
||||||
// not reached
|
|
||||||
_exit (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
_write (int filedes, void const *buffer, size_t size)
|
_write (int filedes, void const *buffer, size_t size)
|
||||||
{
|
{
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2018,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
_exit (int status)
|
||||||
|
{
|
||||||
|
#if 1 // !MES_CCAMD64
|
||||||
|
asm ("mov____0x8(%rbp),%rdi !0x10");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
asm ("mov____$i32,%rax SYS_exit");
|
||||||
|
asm ("syscall");
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2018,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -20,17 +20,6 @@
|
||||||
|
|
||||||
#include "mes/lib-mini.h"
|
#include "mes/lib-mini.h"
|
||||||
|
|
||||||
void
|
|
||||||
_exit (int status)
|
|
||||||
{
|
|
||||||
#if 1 // !MES_CCAMD64
|
|
||||||
asm ("mov____0x8(%rbp),%rdi !0x10");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
asm ("mov____$i32,%rax SYS_exit");
|
|
||||||
asm ("syscall");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_write (int filedes, void const *buffer, size_t size)
|
_write (int filedes, void const *buffer, size_t size)
|
||||||
{
|
{
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
|
|
||||||
|
#undef cast_intp_to_charp
|
||||||
|
#undef cast_long_to_charp
|
||||||
|
#undef cast_charp_to_long
|
||||||
|
#undef cast_int_to_long
|
||||||
|
#undef cast_voidp_to_long
|
||||||
|
|
||||||
|
char*
|
||||||
|
cast_intp_to_charp (int const *i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
cast_long_to_charp (long i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_charp_to_long (char const *i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_int_to_long (int i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_voidp_to_long (void const *i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/syscall.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
chmod (char const *file_name, int mask)
|
||||||
|
{
|
||||||
|
long long_file_name = file_name;
|
||||||
|
long long_mask = mask;
|
||||||
|
return _sys_call2 (SYS_chmod, long_file_name, long_mask);
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/syscall.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
clock_gettime (long clk_id, struct timespec *tp)
|
||||||
|
{
|
||||||
|
long long_tp = tp;
|
||||||
|
return _sys_call2 (SYS_clock_gettime, clk_id, tp);
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
execv (char *file_name, char **argv)
|
||||||
|
{
|
||||||
|
return execve (file_name, argv, environ);
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/syscall.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
execve (char const *file_name, char **argv, char **env)
|
||||||
|
{
|
||||||
|
long long_file_name = file_name;
|
||||||
|
long long_argv = argv;
|
||||||
|
long long_env = env;
|
||||||
|
return _sys_call3 (SYS_execve, file_name, argv, env);
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
|
|
||||||
|
void _exit (int code);
|
||||||
|
|
||||||
|
void
|
||||||
|
exit (int code)
|
||||||
|
{
|
||||||
|
_exit (code);
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <mes/lib.h>
|
||||||
|
|
||||||
|
// CONSTANT PATH_MAX 1024
|
||||||
|
|
||||||
|
char *
|
||||||
|
getcwd (char *buffer, int size)
|
||||||
|
{
|
||||||
|
if (__getcwd_buf == 0)
|
||||||
|
__getcwd_buf = malloc (PATH_MAX);
|
||||||
|
char *buf = __itoa_buf;
|
||||||
|
if (buffer != 0)
|
||||||
|
return _getcwd (buffer, size);
|
||||||
|
return _getcwd (buf, PATH_MAX);
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/syscall.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
ioctl (int filedes, long command, int data)
|
||||||
|
{
|
||||||
|
long long_filedes = filedes;
|
||||||
|
long long_command = command;
|
||||||
|
long long_data = data;
|
||||||
|
int r = _sys_call3 (SYS_ioctl, long_filedes, long_command, long_data);
|
||||||
|
return r;
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termio.h>
|
||||||
|
|
||||||
|
// CONSTANT TCGETS 0x5401
|
||||||
|
#define TCGETS 0x5401
|
||||||
|
|
||||||
|
struct ktermios
|
||||||
|
{
|
||||||
|
unsigned c_iflag;
|
||||||
|
unsigned c_oflag;
|
||||||
|
unsigned c_cflag;
|
||||||
|
unsigned c_lflag;
|
||||||
|
char c_line;
|
||||||
|
char c_cc[19];
|
||||||
|
unsigned c_ispeed;
|
||||||
|
unsigned c_ospeed;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ktermios *__isatty_kernel_termios;
|
||||||
|
|
||||||
|
int
|
||||||
|
isatty (int filedes)
|
||||||
|
{
|
||||||
|
if (__isatty_kernel_termios == 0)
|
||||||
|
__isatty_kernel_termios = malloc (sizeof (struct ktermios));
|
||||||
|
int r = ioctl (filedes, TCGETS, __isatty_kernel_termios);
|
||||||
|
return r == 0;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
mes_open (char *file_name, int flags, int mask)
|
||||||
|
{
|
||||||
|
int filedes = open (file_name, flags, mask);
|
||||||
|
if (filedes > 2)
|
||||||
|
__ungetc_clear (filedes);
|
||||||
|
return filedes;
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
open (char *file_name, int flags, int mask)
|
||||||
|
{
|
||||||
|
int r = _sys_call3 (SYS_open, file_name, flags, mask);
|
||||||
|
if (r > 2)
|
||||||
|
__ungetc_clear (r);
|
||||||
|
return r;
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* aSCM with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/syscall.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <mes/lib.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
SCM
|
||||||
|
read (int filedes, void *buffer, SCM size)
|
||||||
|
{
|
||||||
|
SCM bytes = _sys_call3 (SYS_read, filedes, buffer, size);
|
||||||
|
return bytes;
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/syscall.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
long
|
||||||
|
time (long *result)
|
||||||
|
{
|
||||||
|
return _sys_call1 (SYS_time, result);
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/syscall.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
waitpid (int pid, int *status_ptr, int options)
|
||||||
|
{
|
||||||
|
long long_pid = pid;
|
||||||
|
long long_status_ptr = status_ptr;
|
||||||
|
long long_options = options;
|
||||||
|
#if __i386__
|
||||||
|
return _sys_call3 (SYS_waitpid, long_pid, long_status_ptr, long_options);
|
||||||
|
#elif __x86_64__
|
||||||
|
return _sys_call4 (SYS_wait4, long_pid, long_status_ptr, long_options, 0);
|
||||||
|
#else
|
||||||
|
#error arch not supported
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
## Copyright (C) 2017 Jeremiah Orians
|
||||||
|
## This file is part of M2-Planet.
|
||||||
|
##
|
||||||
|
## M2-Planet 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.
|
||||||
|
##
|
||||||
|
## M2-Planet 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 M2-Planet. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
DEFINE ADD_IMMEDIATE_to_eax 81C0
|
||||||
|
DEFINE ADD_IMMEDIATE_to_ebp 81C5
|
||||||
|
DEFINE ADD_eax_to_ebx 01C3
|
||||||
|
DEFINE ADD_ebp_to_eax 01E8
|
||||||
|
DEFINE ADD_ebx_to_eax 01D8
|
||||||
|
DEFINE AND_eax_ebx 21D8
|
||||||
|
DEFINE CALL_IMMEDIATE E8
|
||||||
|
DEFINE CALL_eax FFD0
|
||||||
|
DEFINE CMP 39C3
|
||||||
|
DEFINE COPY_eax_to_ebx 89C3
|
||||||
|
DEFINE COPY_eax_to_ecx 89C1
|
||||||
|
DEFINE COPY_ebp_to_eax 89E8
|
||||||
|
DEFINE COPY_ebx_to_eax 89D8
|
||||||
|
DEFINE COPY_ebx_to_edx 89DA
|
||||||
|
DEFINE COPY_ecx_to_ebp 89CD
|
||||||
|
DEFINE COPY_edi_to_ebp 89fd
|
||||||
|
DEFINE COPY_esp_to_ebp 89E5
|
||||||
|
DEFINE COPY_esp_to_ecx 89E1
|
||||||
|
DEFINE COPY_esp_to_edi 89E7
|
||||||
|
DEFINE CDTQ 99
|
||||||
|
DEFINE DIVIDE_eax_by_ebx_into_eax F7FB
|
||||||
|
DEFINE DIVIDES_eax_by_ebx_into_eax F7F3
|
||||||
|
DEFINE INT_80 CD80
|
||||||
|
DEFINE JUMP E9
|
||||||
|
DEFINE JUMP_EQ 0F84
|
||||||
|
DEFINE JUMP_NE 0F85
|
||||||
|
DEFINE JUMP_EQ8 74
|
||||||
|
DEFINE JUMP_NE8 75
|
||||||
|
DEFINE LOAD_BASE_ADDRESS_eax 8D85
|
||||||
|
DEFINE LOAD_BYTE 0FBE00
|
||||||
|
DEFINE LOAD_EFFECTIVE_ADDRESS 8D8424
|
||||||
|
DEFINE LOAD_EFFECTIVE_ADDRESS_ebx 8D9C24
|
||||||
|
DEFINE LOAD_EFFECTIVE_ADDRESS_ecx 8D8C24
|
||||||
|
DEFINE LOAD_EFFECTIVE_ADDRESS_edx 8D9424
|
||||||
|
DEFINE LOAD_ESP_IMMEDIATE_into_eax 8B8424
|
||||||
|
DEFINE LOAD_IMMEDIATE_eax B8
|
||||||
|
DEFINE LOAD_IMMEDIATE_ebx BB
|
||||||
|
DEFINE LOAD_IMMEDIATE_ecx B9
|
||||||
|
DEFINE LOAD_IMMEDIATE_edx BA
|
||||||
|
DEFINE LOAD_INTEGER 8B00
|
||||||
|
DEFINE LOAD_INTEGER_ebx 8B1B
|
||||||
|
DEFINE LOAD_INTEGER_ecx 8B09
|
||||||
|
DEFINE LOAD_INTEGER_edx 8B12
|
||||||
|
DEFINE MODULUS_eax_from_ebx_into_ebx F7FB
|
||||||
|
DEFINE MODULUSS_eax_from_ebx_into_ebx F7F3
|
||||||
|
DEFINE MOVEZBL 0FB6C0
|
||||||
|
DEFINE MOVE_ebx_to_eax 89D8
|
||||||
|
DEFINE MOVE_ecx_to_eax 89C8
|
||||||
|
DEFINE MOVE_edx_to_eax 89D0
|
||||||
|
DEFINE MULTIPLY_eax_by_ebx_into_eax F7EB
|
||||||
|
DEFINE MULTIPLYS_eax_by_ebx_into_eax F7E3
|
||||||
|
DEFINE NULL 00000000
|
||||||
|
DEFINE NOT_eax F7D0
|
||||||
|
DEFINE OR_eax_ebx 09D8
|
||||||
|
DEFINE POP_eax 58
|
||||||
|
DEFINE POP_ebx 5B
|
||||||
|
DEFINE POP_ebp 5D
|
||||||
|
DEFINE POP_edi 5F
|
||||||
|
DEFINE PUSH_eax 50
|
||||||
|
DEFINE PUSH_ebx 53
|
||||||
|
DEFINE PUSH_ebp 55
|
||||||
|
DEFINE PUSH_edi 57
|
||||||
|
DEFINE RETURN C3
|
||||||
|
DEFINE SAL_eax_Immediate8 C1E0
|
||||||
|
DEFINE SHL_eax_cl D3E0
|
||||||
|
DEFINE SAL_eax_cl D3F0
|
||||||
|
DEFINE SHR_eax_cl D3E8
|
||||||
|
DEFINE SAR_eax_cl D3F8
|
||||||
|
DEFINE SETA 0F97C0
|
||||||
|
DEFINE SETAE 0F93C0
|
||||||
|
DEFINE SETB 0F92C0
|
||||||
|
DEFINE SETBE 0F96C0
|
||||||
|
DEFINE SETE 0F94C0
|
||||||
|
DEFINE SETLE 0F9EC0
|
||||||
|
DEFINE SETL 0F9CC0
|
||||||
|
DEFINE SETGE 0F9DC0
|
||||||
|
DEFINE SETG 0F9FC0
|
||||||
|
DEFINE SETNE 0F95C0
|
||||||
|
DEFINE STORE_CHAR 8803
|
||||||
|
DEFINE STORE_INTEGER 8903
|
||||||
|
DEFINE SUBTRACT_eax_from_ebx_into_ebx 29C3
|
||||||
|
DEFINE TEST 85C0
|
||||||
|
DEFINE XCHG_eax_ebx 93
|
||||||
|
DEFINE XOR_ebx_eax_into_eax 31D8
|
|
@ -28,5 +28,5 @@ __assert_fail (char *s)
|
||||||
eputs ("\n");
|
eputs ("\n");
|
||||||
char *fail = s;
|
char *fail = s;
|
||||||
fail = 0;
|
fail = 0;
|
||||||
*fail = 0;
|
fail[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -24,27 +24,32 @@
|
||||||
long
|
long
|
||||||
abtol (char const **p, int base)
|
abtol (char const **p, int base)
|
||||||
{
|
{
|
||||||
char const *s = *p;
|
char const *s = p[0];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int sign_p = 0;
|
int sign_p = 0;
|
||||||
if (!base)
|
int m = '0';
|
||||||
|
if (base == 0)
|
||||||
base = 10;
|
base = 10;
|
||||||
while (isspace (*s))
|
while (isspace (s[0]) != 0)
|
||||||
s++;
|
s = s + 1;
|
||||||
if (*s && *s == '+')
|
if (s[0] != 0 && s[0] == '+')
|
||||||
s++;
|
s = s + 1;
|
||||||
if (*s && *s == '-')
|
if (s[0] != 0 && s[0] == '-')
|
||||||
{
|
{
|
||||||
sign_p = 1;
|
sign_p = 1;
|
||||||
s++;
|
s = s + 1;
|
||||||
}
|
}
|
||||||
while (isnumber (*s, base))
|
while (isnumber (s[0], base) != 0)
|
||||||
{
|
{
|
||||||
i *= base;
|
i = i * base;
|
||||||
int m = *s > '9' ? 'a' - 10 : '0';
|
if (s[0] > '9')
|
||||||
i += *s - m;
|
m = 'a' - 10;
|
||||||
s++;
|
i = i + s[0] - m;
|
||||||
|
s = s + 1;
|
||||||
}
|
}
|
||||||
*p = s;
|
p[0] = s;
|
||||||
return sign_p ? -i : i;
|
if (sign_p != 0)
|
||||||
|
return -i;
|
||||||
|
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2019 Jeremiah Orians <jeremiah@pdp10.guru>
|
||||||
|
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
assert_msg (int bool, char *msg)
|
||||||
|
{
|
||||||
|
if (bool == 0)
|
||||||
|
__assert_fail (msg);
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
|
|
||||||
|
#undef cast_intp_to_charp
|
||||||
|
#undef cast_long_to_charp
|
||||||
|
#undef cast_charp_to_long
|
||||||
|
#undef cast_int_to_long
|
||||||
|
#undef cast_voidp_to_long
|
||||||
|
|
||||||
|
char*
|
||||||
|
cast_intp_to_charp (int const *i)
|
||||||
|
{
|
||||||
|
return (char*)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
cast_long_to_charp (long i)
|
||||||
|
{
|
||||||
|
return (char*)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_charp_to_long (char const *i)
|
||||||
|
{
|
||||||
|
return (long)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_int_to_long (int i)
|
||||||
|
{
|
||||||
|
return (long)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_voidp_to_long (void const *i)
|
||||||
|
{
|
||||||
|
return (long)i;
|
||||||
|
}
|
238
lib/mes/div.c
238
lib/mes/div.c
|
@ -1,7 +1,8 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
* Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
* Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||||
|
* Copyright © 2020 Nathalie Kopaczewski <natkopa@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -24,43 +25,203 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
typedef struct
|
struct ldiv_t
|
||||||
{
|
{
|
||||||
long quot;
|
long quot;
|
||||||
long rem;
|
long rem;
|
||||||
} ldiv_t;
|
};
|
||||||
|
|
||||||
int __raise(int);
|
int __raise (int);
|
||||||
|
|
||||||
|
#if __TINYC__
|
||||||
|
#define __raise(x) -1
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
__mesabi_div0 (void)
|
__mesabi_div0 (void)
|
||||||
{
|
{
|
||||||
if (__raise(SIGFPE) < 0) { /* could not raise SIGFPE */
|
if (__raise (SIGFPE) < 0) /* could not raise SIGFPE */
|
||||||
/* Fail in any way possible */
|
{
|
||||||
unsigned char* x = (unsigned char*) 0;
|
/* Fail in any way possible */
|
||||||
*x = 2;
|
unsigned char *x = (unsigned char *) 0;
|
||||||
}
|
*x = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ULONG_HIGHBITMASK LONG_MIN
|
||||||
|
#define ULONG_BITCOUNT (sizeof (unsigned long)*8)
|
||||||
|
|
||||||
|
/** Compute the logarithm of base 2 of D. The result is rounded down.
|
||||||
|
That is equal to the highest-index set bit in D.
|
||||||
|
|
||||||
|
The idea is to shift D to the right in order to find the index i of the first most-significant digit > 0.
|
||||||
|
|
||||||
|
The computation is done by bisection, for speed.
|
||||||
|
|
||||||
|
Recurse:
|
||||||
|
Two halves are determined of the remaining slice.
|
||||||
|
The first half checked is the higher-significant half.
|
||||||
|
If that higher-significant half is not zero, recurse on that one.
|
||||||
|
Otherwise, recurse on the lower-significant half.
|
||||||
|
|
||||||
|
Precondition: D > 0 */
|
||||||
|
static unsigned int
|
||||||
|
__mesabi_log2i (unsigned long D)
|
||||||
|
{
|
||||||
|
unsigned int n = ULONG_BITCOUNT;
|
||||||
|
unsigned int i = 0U;
|
||||||
|
unsigned long D1;
|
||||||
|
while (n >= 2U)
|
||||||
|
{ /* while still two halves possible */
|
||||||
|
n >>= 1U;
|
||||||
|
/* D1: higher-significant half of D */
|
||||||
|
D1 = D >> n;
|
||||||
|
if (D1 > 0UL)
|
||||||
|
{
|
||||||
|
/* We know that the resulting index has to be in the higher-significant half.
|
||||||
|
In that case, lower-significant half of D is superfluous for determination of i,
|
||||||
|
therefore scroll and continue with higher-significant half. */
|
||||||
|
D = D1;
|
||||||
|
i += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static void
|
||||||
|
test_log2i (void)
|
||||||
|
{
|
||||||
|
assert (log2i (1) == 0);
|
||||||
|
assert (log2i (1) == 0);
|
||||||
|
assert (log2i (2) == 1);
|
||||||
|
assert (log2i (3) == 1);
|
||||||
|
assert (log2i (4) == 2);
|
||||||
|
assert (log2i (5) == 2);
|
||||||
|
assert (log2i (6) == 2);
|
||||||
|
assert (log2i (7) == 2);
|
||||||
|
assert (log2i (8) == 3);
|
||||||
|
assert (log2i (9) == 3);
|
||||||
|
assert (log2i (10) == 3);
|
||||||
|
assert (log2i (11) == 3);
|
||||||
|
assert (log2i (12) == 3);
|
||||||
|
assert (log2i (13) == 3);
|
||||||
|
assert (log2i (71) == 6);
|
||||||
|
assert (log2i (72) == 6);
|
||||||
|
assert (log2i (73) == 6);
|
||||||
|
assert (log2i (74) == 6);
|
||||||
|
assert (log2i (75) == 6);
|
||||||
|
assert (log2i (99) == 6);
|
||||||
|
assert (log2i (2147483648) == 31);
|
||||||
|
assert (log2i (3221225471) == 31);
|
||||||
|
assert (log2i (4294967294) == 31);
|
||||||
|
assert (log2i (4294967295) == 31);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Perform unsigned integer division of N by D; store the remainder
|
||||||
|
into *REMAINDER; return the quotient.
|
||||||
|
|
||||||
|
This is currently implemented as long division.
|
||||||
|
|
||||||
|
R is the remainder. R >= 0. R starts at N.
|
||||||
|
|
||||||
|
QUOTIENT is built up bit by bit starting at the most significant bit [*].
|
||||||
|
|
||||||
|
Values D', starting at D << ULONG_BITCOUNT [*], going down to 1,
|
||||||
|
divided by 2 each time, are iterated over, doing: If R >= D',
|
||||||
|
subtract D' from R, and append new LSB 1 to the QUOTIENT.
|
||||||
|
Otherwise, subtract 0 from R (implicit), and append new LSB 0 to the
|
||||||
|
QUOTIENT (0 is the implicit default).
|
||||||
|
|
||||||
|
[*] As a special consideration for C throwing away bits when
|
||||||
|
left-shifting, D' starts at the highest value that will not lose
|
||||||
|
bits in this way instead. (ULONG_BITCOUNT - log2i(D) - 1) is
|
||||||
|
the number of leading zeroes in D in binary radix.
|
||||||
|
|
||||||
|
Precondition: D > 0 */
|
||||||
|
static unsigned long
|
||||||
|
__mesabi_uldiv1 (unsigned long N, unsigned long D, unsigned long *remainder)
|
||||||
|
{
|
||||||
|
// Note: __mesabi_log2i(D) < ULONG_BITCOUNT
|
||||||
|
unsigned int j = ULONG_BITCOUNT - __mesabi_log2i (D); /* Note: Or j = __mesabi_log2i(N) + 1 - __mesabi_log2i(D) */
|
||||||
|
// Note: assert(j - 1 == __builtin_clzl(D)); on GCC
|
||||||
|
unsigned long quotient = 0UL;
|
||||||
|
unsigned long R = N;
|
||||||
|
for (D <<= (j - 1); j > 0U; --j, D >>= 1U)
|
||||||
|
{
|
||||||
|
quotient <<= 1U;
|
||||||
|
if (R >= D)
|
||||||
|
{
|
||||||
|
R -= D;
|
||||||
|
quotient |= 1UL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*remainder = R;
|
||||||
|
return quotient;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static void
|
||||||
|
assert_uldiv (unsigned long N, unsigned long D, unsigned long expected_quotient,
|
||||||
|
unsigned long expected_remainder)
|
||||||
|
{
|
||||||
|
unsigned long remainder;
|
||||||
|
unsigned long quotient;
|
||||||
|
quotient = uldiv (N, D, &remainder);
|
||||||
|
printf ("%lu/%lu = %lu;%lu\n", N, D, quotient, remainder);
|
||||||
|
assert (quotient == expected_quotient);
|
||||||
|
assert (remainder == expected_remainder);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_uldiv (void)
|
||||||
|
{
|
||||||
|
//assert_uldiv(0, 0, 0, 0);
|
||||||
|
assert_uldiv (0, 1, 0, 0);
|
||||||
|
assert_uldiv (1, 1, 1, 0);
|
||||||
|
assert_uldiv (72, 5, 14, 2);
|
||||||
|
assert_uldiv (0xffffffff, 1, 0xffffffff, 0);
|
||||||
|
assert_uldiv (0xffffffff, 2, 0x7fffffff, 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Compare gcc: __udivmoddi4 */
|
/* Compare gcc: __udivmoddi4 */
|
||||||
unsigned long
|
unsigned long
|
||||||
__mesabi_uldiv (unsigned long a, unsigned long b, unsigned long* remainder)
|
__mesabi_uldiv (unsigned long a, unsigned long b, unsigned long *remainder)
|
||||||
{
|
{
|
||||||
unsigned long tmp;
|
unsigned long tmp;
|
||||||
if (!remainder)
|
if (!remainder)
|
||||||
remainder = &tmp;
|
remainder = &tmp;
|
||||||
*remainder = 0;
|
*remainder = 0;
|
||||||
if (b == 1)
|
switch (b)
|
||||||
return a;
|
|
||||||
else if (b == 0)
|
|
||||||
__mesabi_div0();
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
unsigned long x;
|
case 64UL:
|
||||||
for (x = 0; a >= b; a -= b)
|
*remainder = a & 63UL;
|
||||||
++x;
|
return a >> 6UL;
|
||||||
*remainder = a;
|
case 32UL:
|
||||||
return x;
|
*remainder = a & 31UL;
|
||||||
|
return a >> 5UL;
|
||||||
|
case 16UL:
|
||||||
|
*remainder = a & 15UL;
|
||||||
|
return a >> 4UL;
|
||||||
|
case 8UL:
|
||||||
|
*remainder = a & 7UL;
|
||||||
|
return a >> 3UL;
|
||||||
|
case 4UL:
|
||||||
|
*remainder = a & 3UL;
|
||||||
|
return a >> 2UL;
|
||||||
|
case 2UL:
|
||||||
|
*remainder = a & 1UL;
|
||||||
|
return a >> 1UL;
|
||||||
|
case 1UL:
|
||||||
|
*remainder = 0;
|
||||||
|
return a;
|
||||||
|
case 0UL:
|
||||||
|
__mesabi_div0 ();
|
||||||
|
return 0UL;
|
||||||
|
default:
|
||||||
|
return __mesabi_uldiv1 (a, b, remainder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,11 +229,11 @@ __mesabi_uldiv (unsigned long a, unsigned long b, unsigned long* remainder)
|
||||||
Maintainer: Be careful to satisfy quot * b + rem == a.
|
Maintainer: Be careful to satisfy quot * b + rem == a.
|
||||||
That means that rem can be negative. */
|
That means that rem can be negative. */
|
||||||
void
|
void
|
||||||
__mesabi_ldiv(long a, long b, ldiv_t* result)
|
__mesabi_ldiv (long a, long b, struct ldiv_t *result)
|
||||||
{
|
{
|
||||||
int negate_result = (a < 0) ^ (b < 0);
|
int negate_result = (a < 0) ^ (b < 0);
|
||||||
if (b == LONG_MIN)
|
if (b == LONG_MIN)
|
||||||
__mesabi_div0();
|
__mesabi_div0 ();
|
||||||
if (a != LONG_MIN)
|
if (a != LONG_MIN)
|
||||||
{
|
{
|
||||||
int negative_a = (a < 0);
|
int negative_a = (a < 0);
|
||||||
|
@ -80,7 +241,7 @@ __mesabi_ldiv(long a, long b, ldiv_t* result)
|
||||||
a = -a;
|
a = -a;
|
||||||
if (b < 0)
|
if (b < 0)
|
||||||
b = -b;
|
b = -b;
|
||||||
result->quot = __mesabi_uldiv(a, b, &result->rem);
|
result->quot = __mesabi_uldiv (a, b, &result->rem);
|
||||||
if (negate_result)
|
if (negate_result)
|
||||||
result->quot = -result->quot;
|
result->quot = -result->quot;
|
||||||
if (negative_a)
|
if (negative_a)
|
||||||
|
@ -98,13 +259,13 @@ __mesabi_ldiv(long a, long b, ldiv_t* result)
|
||||||
negate_result = !negate_result;
|
negate_result = !negate_result;
|
||||||
}
|
}
|
||||||
else if (b == 0)
|
else if (b == 0)
|
||||||
__mesabi_div0();
|
__mesabi_div0 ();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long x;
|
long x;
|
||||||
for (x = 0; a <= -b; a += b)
|
for (x = 0; a <= -b; a += b)
|
||||||
++x;
|
++x;
|
||||||
result->rem = a; /* negative */
|
result->rem = a; /* negative */
|
||||||
result->quot = x;
|
result->quot = x;
|
||||||
}
|
}
|
||||||
if (negate_result)
|
if (negate_result)
|
||||||
|
@ -115,15 +276,30 @@ __mesabi_ldiv(long a, long b, ldiv_t* result)
|
||||||
long
|
long
|
||||||
__mesabi_imod (long a, long b)
|
__mesabi_imod (long a, long b)
|
||||||
{
|
{
|
||||||
ldiv_t result;
|
struct ldiv_t result;
|
||||||
__mesabi_ldiv(a, b, &result);
|
__mesabi_ldiv (a, b, &result);
|
||||||
return result.rem;
|
return result.rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
long
|
||||||
__mesabi_idiv (int a, int b)
|
__mesabi_idiv (long a, long b)
|
||||||
{
|
{
|
||||||
ldiv_t result;
|
struct ldiv_t result;
|
||||||
__mesabi_ldiv(a, b, &result);
|
__mesabi_ldiv (a, b, &result);
|
||||||
return result.quot;
|
return result.quot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long
|
||||||
|
__mesabi_umod (unsigned long a, unsigned long b)
|
||||||
|
{
|
||||||
|
unsigned long result;
|
||||||
|
__mesabi_uldiv (a, b, &result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long
|
||||||
|
__mesabi_udiv (unsigned long a, unsigned long b)
|
||||||
|
{
|
||||||
|
unsigned long result;
|
||||||
|
return __mesabi_uldiv (a, b, &result);
|
||||||
|
}
|
||||||
|
|
|
@ -19,42 +19,57 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <mes/lib.h>
|
#include <mes/lib.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int __ungetc_buf[__FILEDES_MAX + 1] = { 0 };
|
int errno;
|
||||||
|
int *__ungetc_buf;
|
||||||
|
|
||||||
int
|
int
|
||||||
__ungetc_p (int filedes)
|
__ungetc_p (int filedes)
|
||||||
{
|
{
|
||||||
|
if (__ungetc_buf == 0)
|
||||||
|
__ungetc_init ();
|
||||||
return __ungetc_buf[filedes] >= 0;
|
return __ungetc_buf[filedes] >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
__ungetc_init ()
|
__ungetc_init ()
|
||||||
{
|
{
|
||||||
if (__ungetc_buf[__FILEDES_MAX] == 0)
|
if (__ungetc_buf == 0)
|
||||||
memset (__ungetc_buf, -1, (__FILEDES_MAX + 1) * sizeof (int));
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
__ungetc_buf = malloc ((__FILEDES_MAX + 1) * sizeof (int));
|
||||||
|
errno = save_errno;
|
||||||
|
memset (__ungetc_buf, -1, (__FILEDES_MAX + 1) * sizeof (int));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
__ungetc_clear (int filedes)
|
__ungetc_clear (int filedes)
|
||||||
{
|
{
|
||||||
|
if (__ungetc_buf == 0)
|
||||||
|
__ungetc_init ();
|
||||||
__ungetc_buf[filedes] = -1;
|
__ungetc_buf[filedes] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
__ungetc_set (int filedes, int c)
|
__ungetc_set (int filedes, int c)
|
||||||
{
|
{
|
||||||
|
if (__ungetc_buf == 0)
|
||||||
|
__ungetc_init ();
|
||||||
__ungetc_buf[filedes] = c;
|
__ungetc_buf[filedes] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
fdgetc (int fd)
|
fdgetc (int fd)
|
||||||
{
|
{
|
||||||
__ungetc_init ();
|
if (__ungetc_buf == 0)
|
||||||
|
__ungetc_init ();
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
int i = __ungetc_buf[fd];
|
int i = __ungetc_buf[fd];
|
||||||
|
@ -65,10 +80,10 @@ fdgetc (int fd)
|
||||||
int r = read (fd, &c, 1);
|
int r = read (fd, &c, 1);
|
||||||
if (r < 1)
|
if (r < 1)
|
||||||
return -1;
|
return -1;
|
||||||
i = (int) c;
|
i = c;
|
||||||
}
|
}
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
i += 256;
|
i = i + 256;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
int
|
int
|
||||||
fdputc (int c, int fd)
|
fdputc (int c, int fd)
|
||||||
{
|
{
|
||||||
write (fd, (char *) &c, 1);
|
char *p = cast_intp_to_charp (&c);
|
||||||
|
write (fd, p, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <mes/lib.h>
|
#include <mes/lib.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int
|
int
|
||||||
fdungetc (int c, int fd)
|
fdungetc (int c, int fd)
|
||||||
{
|
{
|
||||||
__ungetc_init ();
|
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
return c;
|
return c;
|
||||||
else if (__ungetc_p (fd))
|
else if (__ungetc_p (fd))
|
||||||
|
@ -32,7 +30,7 @@ fdungetc (int c, int fd)
|
||||||
eputs (" ***MES C LIB*** fdungetc ungetc buffer overflow fd=");
|
eputs (" ***MES C LIB*** fdungetc ungetc buffer overflow fd=");
|
||||||
eputs (itoa (fd));
|
eputs (itoa (fd));
|
||||||
eputs ("\n");
|
eputs ("\n");
|
||||||
assert (0);
|
assert_msg (0, "0");
|
||||||
}
|
}
|
||||||
__ungetc_set (fd, c);
|
__ungetc_set (fd, c);
|
||||||
return c;
|
return c;
|
||||||
|
|
|
@ -32,7 +32,6 @@ int __stderr = STDERR;
|
||||||
int
|
int
|
||||||
mes_open (char const *file_name, int flags, int mask)
|
mes_open (char const *file_name, int flags, int mask)
|
||||||
{
|
{
|
||||||
__ungetc_init ();
|
|
||||||
int filedes = open (file_name, flags, mask);
|
int filedes = open (file_name, flags, mask);
|
||||||
if (filedes > 2)
|
if (filedes > 2)
|
||||||
__ungetc_clear (filedes);
|
__ungetc_clear (filedes);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue