mescc: x86_64 support: Refactor to abstracted assembly, add x86_64.

* module/mescc/as.scm: Support abstracted assembly.
* module/mescc/i386/as.scm: Rewrite.
* module/mescc/x86_64/as.scm: Implement.
* module/mescc/compile.scm: Refactor to abstracted assembly.
* module/mescc/M1.scm: Update for partial 64 bit support.
* module/mescc/bytevectors.scm (bytevector-u64-native-set!): New
procedure.
* module/mescc/i386/info.scm (i386:type-alist): Use 4 byte type length
also for faking double, long long, long double.
* module/mescc/info.scm:modified:
* module/mescc/x86_64/info.scm (x86_64:registers): New variable.
* lib/x86-mes/x86.M1: Update for new register scheme.
* lib/x86_64-mes/x86_64.M1: Implement.
* lib/x86-mes/setjmp.c: Implement.
* lib/x86_64-mes-gcc/setjmp.c: Implement.
* build-aux/build-cc.sh: Update for x86_64.
* build-aux/build-cc32.sh: Likewise.
* build-aux/build-mes.sh: Likewise.
* build-aux/build-x86_64-mes.sh: Likewise.
* build-aux/check-mescc.sh: Likewise.
* build-aux/test64.sh: Likewise.
* include/libmes.h: Likewise.
* include/setjmp.h: Likewise.
* include/signal.h: Likewise.
* include/stdarg.h: Likewise.
* include/sys/stat.h: Likewise.
* include/sys/types.h: Likewise.
* include/sys/wait.h: Likewise.
* include/unistd.h: Likewise.
* lib/libc+gnu.c: Likewise.
* lib/libc+tcc.c: Likewise.
* lib/linux/gnu.c: Likewise.
* lib/linux/libc-mini.c: Likewise.
* lib/linux/libc.c: Likewise.
* lib/linux/tcc.c: Likewise.
* lib/linux/x86_64-mes-gcc/mes.c: Likewise.
* lib/linux/x86_64-mes/crt1.c: Likewise.
* lib/mes/abtol.c: Likewise.
* lib/posix/mktemp.c: Likewise.
* lib/posix/wait.c: Likewise.
* lib/stdio/fopen.c: Likewise.
* lib/stdio/fputc.c: Likewise.
* lib/stdio/fseek.c: Likewise.
* lib/stdio/printf.c: Likewise.
* lib/stdio/sprintf.c: Likewise.
* lib/stdio/vfprintf.c: Likewise.
* lib/stdio/vsprintf.c: Likewise.
* lib/stdio/vsscanf.c: Likewise.
* lib/stdlib/qsort.c: Likewise.
* lib/x86-mes-gcc/setjmp.c: Likewise.
* scaffold/tests/11-if-1.c: Likewise.
* scaffold/tests/15-if-!f.c: Likewise.
* scaffold/tests/16-if-t.c: Likewise.
* scaffold/tests/21-char[].c: Likewise.
* scaffold/tests/23-pointer.c: Likewise.
* scaffold/tests/32-compare.c: Likewise.
* scaffold/tests/33-and-or.c: Likewise.
* scaffold/tests/34-pre-post.c: Likewise.
* scaffold/tests/35-compare-char.c: Likewise.
* scaffold/tests/36-compare-arithmetic.c: Likewise.
* scaffold/tests/37-compare-assign.c: Likewise.
* scaffold/tests/38-compare-call.c: Likewise.
* scaffold/tests/40-if-else.c: Likewise.
* scaffold/tests/41-?.c: Likewise.
* scaffold/tests/42-goto-label.c: Likewise.
* scaffold/tests/43-for-do-while.c: Likewise.
* scaffold/tests/44-switch.c: Likewise.
* scaffold/tests/45-void-call.c: Likewise.
* scaffold/tests/46-function-static.c: Likewise.
* scaffold/tests/51-strcmp.c: Likewise.
* scaffold/tests/51-strncmp.c: Likewise.
* scaffold/tests/53-strcpy.c: Likewise.
* scaffold/tests/54-argv.c: Likewise.
* scaffold/tests/60-math.c: Likewise.
* scaffold/tests/61-array.c: Likewise.
* scaffold/tests/63-struct-cell.c: Likewise.
* scaffold/tests/64-make-cell.c: Likewise.
* scaffold/tests/65-read.c: Likewise.
* scaffold/tests/70-printf.c: Likewise.
* scaffold/tests/71-struct-array.c: Likewise.
* scaffold/tests/72-typedef-struct-def.c: Likewise.
* scaffold/tests/74-multi-line-string.c: Likewise.
* scaffold/tests/76-pointer-arithmetic.c: Likewise.
* scaffold/tests/79-int-array.c: Likewise.
* scaffold/tests/7a-struct-char-array.c: Likewise.
* scaffold/tests/7b-struct-int-array.c: Likewise.
* scaffold/tests/7i-struct-struct.c: Likewise.
* scaffold/tests/7k-for-each-elem.c: Likewise.
* scaffold/tests/7l-struct-any-size-array.c: Likewise.
* scaffold/tests/7o-struct-pre-post.c: Likewise.
* scaffold/tests/7q-bit-field.c: Likewise.
* scaffold/tests/7s-struct-short.c: Likewise.
* scaffold/tests/80-setjmp.c: Likewise.
* scaffold/tests/81-qsort.c: Likewise.
* scaffold/tests/85-sizeof.c: Likewise.
* scaffold/tests/87-sscanf.c: Likewise.
* scaffold/tests/90-strpbrk.c: Likewise.
* scaffold/tests/91-fseek.c: Likewise.
* scaffold/tests/95-signal.c: Likewise.
* scaffold/tests/97-fopen.c: Likewise.
* scaffold/tests/99-readdir.c: Likewise.
* scaffold/tests/t.c: Likewise.
* lib/linux/x86_64-mes/mes.c: New file.
* lib/linux/x86_64-mes/mini.c: New file.
* lib/x86_64-mes/setjmp.c: New file.
* scaffold/tests/06-!call-1.c: New file.
* scaffold/tests/06-call-2.c: New file.
* scaffold/tests/06-call-variable.c: New file.
* scaffold/tests/08-assign-global.c: New file.
* scaffold/tests/08-assign-negative.c: New file.
* scaffold/tests/17-compare-and-or.c: New file.
* scaffold/tests/17-compare-and.c: New file.
* scaffold/tests/17-compare-ge.c: New file.
* scaffold/tests/17-compare-gt.c: New file.
* scaffold/tests/17-compare-le.c: New file.
* scaffold/tests/17-compare-lt.c: New file.
* scaffold/tests/17-compare-or.c: New file.
* scaffold/tests/17-compare-unsigned-ge.c: New file.
* scaffold/tests/17-compare-unsigned-gt.c: New file.
* scaffold/tests/17-compare-unsigned-le.c: New file.
* scaffold/tests/17-compare-unsigned-lt.c: New file.
* scaffold/tests/21-char[]-simple.c: New file.
* scaffold/tests/23-global-pointer-init-null.c: New file.
* scaffold/tests/23-global-pointer-init.c: New file.
* scaffold/tests/23-global-pointer-pointer-ref.c: New file.
* scaffold/tests/23-global-pointer-ref.c: New file.
* scaffold/tests/23-pointer-sub.c: New file.
* scaffold/tests/31-oputs.c: New file.
* scaffold/tests/32-call-wrap.c: New file.
* scaffold/tests/38-compare-call-2.c: New file.
* scaffold/tests/38-compare-call-3.c: New file.
* scaffold/tests/51-pointer-sub.c: New file.
* scaffold/tests/54-argc.c: New file.
* scaffold/tests/63-struct-array-assign.c: New file.
* scaffold/tests/63-struct-array-compare.c: New file.
* scaffold/tests/63-struct-array.c: New file.
* scaffold/tests/63-struct-assign.c: New file.
* scaffold/tests/63-struct-function.c: New file.
* scaffold/tests/63-struct-local.c: New file.
* scaffold/tests/63-struct-pointer.c: New file.
* scaffold/tests/63-struct.c: New file.
* scaffold/tests/70-printf-hello.c: New file.
* scaffold/tests/70-printf-simple.c: New file.
* scaffold/tests/70-stdarg.c: New file.
* scaffold/tests/70-strchr.c: New file.
* scaffold/tests/73-union-hello.c: New file.
* scaffold/tests/76-pointer-arithmetic-pp.c: New file.
* scaffold/tests/79-int-array-simple.c: New file.
* scaffold/tests/7b-struct-int-array-hello.c: New file.
* scaffold/tests/7b-struct-int-array-pointer.c: New file.
* scaffold/tests/7i-struct-struct-simple.c: New file.
* scaffold/tests/7k-for-each-elem-simple.c: New file.
* scaffold/tests/7l-struct-any-size-array-simple.c: New file.
* scaffold/tests/7o-struct-pre-post-simple.c: New file.
* scaffold/tests/7q-bit-field-simple.c: New file.
* scaffold/tests/90-strspn.c: New file.
* scaffold/tests/06-call-string.c.: Rename from 31-eputs.c.
* scaffold/tests/7t-function-destruct.c: Rename from 48-function-destruct.c.
* scaffold/tests/48-global-static.c: Rename from 49-global-static.c.
* scaffold/tests/55-char-array.c:renamed: Rename from 4a-char-array.c.
* scaffold/tests/51-itoa.c:r Rename from 52-itoa.c.
* include/signal.h:(struct sigaction):
This commit is contained in:
Jan Nieuwenhuizen 2018-08-15 18:26:55 +02:00
parent 2fac924c33
commit 7a8a2fc517
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
182 changed files with 7218 additions and 2720 deletions

View file

@ -12,11 +12,11 @@ Main author
All files except the imported files listed below
Jeremiah Orians <jeremiah@pdp10.guru>
lib/libc+tcc.c (fopen)
lib/stdio/fopen.c (first simple version of fopen)
scaffold/tests/98-fopen.c
Han-Wen Nienhuys <hanwen@xs4all.nl>
lib/libc+tcc.c (_memmem, memmem)
lib/string/memmem.c (_memmem, memmem)
rain1
scaffold/tests/90-goto-var.c

View file

@ -53,11 +53,11 @@ ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64-mes-gcc/c
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64-mes-gcc/crtn
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc-mini
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libgetopt
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc+tcc
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libtcc1
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc+gnu
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libg
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libgetopt
LIBC= sh ${srcdest}build-aux/cc64-mes.sh scaffold/main
LIBC=c-mini sh ${srcdest}build-aux/cc64-mes.sh scaffold/hello

View file

@ -51,11 +51,11 @@ ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/x86-mes-gcc/crti
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/x86-mes-gcc/crtn
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libc-mini
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libc
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libgetopt
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libc+tcc
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libtcc1
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libc+gnu
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libg
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libgetopt
LIBC= sh ${srcdest}build-aux/cc32-mes.sh scaffold/main
LIBC=c-mini sh ${srcdest}build-aux/cc32-mes.sh scaffold/hello

View file

@ -127,9 +127,9 @@ ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86-mes/crti
ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86-mes/crtn
ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc
ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libgetopt
ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc+tcc
ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc+gnu
ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libgetopt
[ -n "$SEED" ] && exit 0

View file

@ -122,16 +122,16 @@ trace "TEST lib/x86_64-mes/exit-42.x86_64-mes-out" echo lib/x86_64-mes/exi
{ set +e; lib/x86_64-mes/exit-42.x86_64-mes-out; r=$?; set -e; }
[ $r != 42 ] && echo " => $r" && exit 1
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc-mini
ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc-mini
ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86_64-mes/crt0
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86_64-mes/crti
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86_64-mes/crtn
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/linux/x86_64-mes/crt0
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/linux/x86_64-mes/crti
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/linux/x86_64-mes/crtn
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libgetopt
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc+tcc
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc+gnu
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc+tcc
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc+gnu
# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libgetopt
# [ -n "$SEED" ] && exit 0
@ -146,7 +146,7 @@ trace "TEST lib/x86_64-mes/exit-42.x86_64-mes-out" echo lib/x86_64-mes/exi
# trace "MSNARF vector.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/vector.c
# echo MES_ARENA=$MES_ARENA
# bash ${srcdest}build-aux/cc-mes.sh scaffold/main
# bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/main
MES_LIBS='-l none' bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/main

View file

@ -48,3 +48,4 @@ if [ -n "$TCC" ]; then
fi
sh ${srcdest}build-aux/build-mes.sh
sh ${srcdest}build-aux/build-x86_64-mes.sh

View file

@ -40,6 +40,11 @@ if ! command -v $GUILE > /dev/null; then
GUILE=true
fi
test_sh=${test_sh-${srcdest}build-aux/test.sh}
if [ "$arch" = "x86_64-mes" ]; then
test_sh=${srcdest}build-aux/test64.sh
fi
tests="
t
00-exit-0
@ -49,8 +54,15 @@ t
04-call-0
05-call-1
06-call-!1
06-!call-1
06-call-2
06-call-string
06-call-variable
06-return-void
07-include
08-assign
08-assign-negative
08-assign-global
10-if-0
11-if-1
12-if-==
@ -58,53 +70,97 @@ t
14-if-goto
15-if-!f
16-if-t
17-compare-ge
17-compare-gt
17-compare-le
17-compare-lt
17-compare-unsigned-ge
17-compare-unsigned-gt
17-compare-unsigned-le
17-compare-unsigned-lt
17-compare-and
17-compare-or
17-compare-and-or
17-compare-assign
17-compare-call
18-assign-shadow
20-while
21-char[]-simple
21-char[]
22-while-char[]
23-global-pointer-init-null
23-global-pointer-init
23-global-pointer-ref
23-global-pointer-pointer-ref
23-pointer-sub
23-pointer
30-strlen
31-eputs
31-oputs
32-call-wrap
32-compare
33-and-or
34-pre-post
35-compare-char
36-compare-arithmetic
37-compare-assign
38-compare-call-2
38-compare-call-3
38-compare-call
40-if-else
41-?
42-goto-label
43-for-do-while
44-switch
44-switch-fallthrough
44-switch-body-fallthrough
45-void-call
46-function-static
47-function-expression
48-function-destruct
49-global-static
4a-char-array
48-global-static
50-assert
51-pointer-sub
51-itoa
51-strcmp
51-strncmp
52-itoa
53-strcpy
54-argc
54-argv
55-char-array
60-math
61-array
62-array
63-struct
63-struct-pointer
63-struct-local
63-struct-function
63-struct-assign
63-struct-array
63-struct-array-assign
63-struct-array-compare
63-struct-cell
64-make-cell
65-read
66-local-char-array
70-strchr
70-stdarg
70-printf-hello
70-printf-simple
70-printf
71-struct-array
72-typedef-struct-def
73-union-hello
73-union
74-multi-line-string
75-struct-union
76-pointer-arithmetic-pp
76-pointer-arithmetic
77-pointer-assign
78-union-struct
79-int-array-simple
79-int-array
7a-struct-char-array
7b-struct-int-array-hello
7b-struct-int-array-pointer
7b-struct-int-array
7c-dynarray
7d-cast-char
@ -112,17 +168,33 @@ t
7f-struct-pointer-arithmetic
7g-struct-byte-word-field
7h-struct-assign
7i-struct-struct-simple
7i-struct-struct
7j-strtoull
7k-empty-for
7k-for-each-elem-simple
7k-for-each-elem
7l-struct-any-size-array-simple
7l-struct-any-size-array
7m-struct-char-array-assign
7n-struct-struct-array
7o-struct-pre-post-simple
7o-struct-pre-post
7p-struct-cast
7q-bit-field-simple
7q-bit-field
7r-sign-extend
7s-struct-short
7s-unsigned-compare
7t-function-destruct
7u-double
7u-long-long
7u-?-expression
7u-call-?
7u-inc-byte-word
7u-struct-func
7u-struct-size10
7u-vstack
80-setjmp
81-qsort
81-qsort-dupes
@ -133,6 +205,7 @@ t
86-strncpy
87-sscanf
88-strrchr
90-strspn
90-strpbrk
91-fseek
92-stat
@ -145,9 +218,8 @@ t
99-readdir
"
# 90: needs GNU, fails for mescc, passes for tcc
broken="$broken
7s-struct-short
66-local-char-array
"
# gcc not supported
@ -175,7 +247,7 @@ for t in $tests; do
LIBC=c
MES_LIBS=
fi
sh ${srcdest}build-aux/test.sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
sh $test_sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
r=$?
total=$((total+1))
if [ $r = 0 ]; then

View file

@ -145,8 +145,9 @@ pass=0
fail=0
total=0
mkdir -p scaffold/tinycc
set +e
for t in $tests; do
if [ ! -f $TINYCC_PREFIX/"$t.c" ]; then
if [ ! -f $TINYCC_PREFIX/tests/tests2/"$t.c" ]; then
echo ' [SKIP]'
continue;
fi

View file

@ -50,7 +50,7 @@ if [ -n "$CC" ]; then
fi
fi
rm -f "$t".mes-gcc-out
rm -f "$t".x86_64-mes-gcc-out
if [ -n "$CC64" ]; then
sh ${srcdest}build-aux/cc64-mes.sh "$t"
@ -68,7 +68,7 @@ if [ -n "$CC64" ]; then
fi
fi
rm -f "$o".mes-out
rm -f "$o".x86_64-mes-out
sh ${srcdest}build-aux/cc-x86_64-mes.sh "$t"
r=0

View file

@ -39,6 +39,8 @@ int _fdungetc_p (int fd);
int isdigit (int c);
int isspace (int c);
int isxdigit (int c);
int _open3 (char const *file_name, int flags, int mask);
int _open2 (char const *file_name, int flags);
int oputs (char const* s);
ssize_t write (int filedes, void const *buffer, size_t size);
char *search_path (char const *file_name);

View file

@ -27,9 +27,9 @@
typedef struct
{
int __bp;
int __pc;
int __sp;
long __bp;
long __pc;
long __sp;
} __jmp_buf;
typedef __jmp_buf jmp_buf[1];
@ -45,4 +45,3 @@ int setjmp (jmp_buf env);
#endif // ! WITH_GLIBC
#endif // __MES_SETJMP_H

View file

@ -26,8 +26,8 @@
#else //! WITH_GLIBC
typedef int sigset_t;
typedef int stack_t;
typedef long sigset_t;
typedef long stack_t;
#include <sys/types.h>
@ -85,7 +85,8 @@ typedef int stack_t;
#define SA_ONESHOT SA_RESETHAND
typedef struct siginfo_t {
typedef struct siginfo_t
{
int si_signo;
int si_errno;
int si_code;
@ -113,19 +114,29 @@ typedef struct siginfo_t {
} siginfo_t;
typedef void (*sighandler_t)(int);
struct sigaction {
union {
void (*sa_sigaction) (int signum, siginfo_t *, void *);
#if __MESC__
void (*sa_handler) (int);
typedef long sighandler_t;
#else
sighandler_t sa_handler;
typedef void (*sighandler_t)(int);
#endif
struct sigaction
{
union
{
sighandler_t sa_handler;
void (*sa_sigaction) (int signum, siginfo_t *, void *);
};
unsigned long sa_flags;
#if __x86_64__
long _foo0;
#endif
sigset_t sa_mask;
#if __x86_64__
long _foo1[15];
#endif
//unsigned long sa_flags; // x86?
void (*sa_restorer) (void);
};

View file

@ -27,15 +27,13 @@
#include <sys/types.h>
#if __GNUC__
typedef char* va_list;
#define va_start(ap, last) (void)((ap) = (char*)(&(last) + 1))
#else // !__GNUC__
typedef int va_list;
#define va_start(ap, last) (void)((ap) = (char*)(&(last) + 1))
#endif // !__GNUC__
#if __GNUC__ && __x86_64__
#define __FOO_VARARGS 1
#endif
#define va_arg(ap, type) (type)(((int*)((ap) = ((ap) + 4)))[-1])
typedef long va_list;
#define va_start(ap, last) (void)((ap) = (char*)(&(last) + 1))
#define va_arg(ap, type) (type)(((long*)((ap) = ((ap) + sizeof (void*))))[-1])
#define va_end(ap) (void)((ap) = 0)
#define va_copy(dest, src) dest = src

View file

@ -34,6 +34,7 @@
typedef int mode_t;
#endif
#if __i386__
struct stat
{
unsigned long st_dev;
@ -44,17 +45,40 @@ struct stat
unsigned short st_gid;
unsigned long st_rdev;
long st_size;
unsigned int st_blksize;
unsigned int st_blocks;
unsigned long st_blksize;
unsigned long st_blocks;
time_t st_atime;
unsigned long st_atime_usec;
time_t st_mtime;
unsigned long st_mtime_usec;
time_t st_ctime;
unsigned long st_ctime_usec;
unsigned int __foo0;
unsigned int __foo1;
unsigned long __foo0;
unsigned long __foo1;
};
#elif __x86_64__
struct stat
{
unsigned long st_dev;
unsigned long st_ino;
unsigned int st_mode;
unsigned int st_nlink;
unsigned int st_uid;
unsigned int st_gid;
unsigned long st_rdev;
long st_size;
unsigned long st_blksize;
unsigned long st_blocks;
time_t st_atime;
unsigned long st_atime_usec;
time_t st_mtime;
unsigned long st_mtime_usec;
time_t st_ctime;
unsigned long st_ctime_usec;
unsigned long __foo0;
unsigned long __foo1;
};
#endif
int chmod (char const *file_name, mode_t mode);
int mkdir (char const *file_name, mode_t mode);

View file

@ -48,25 +48,25 @@ typedef long clock_t;
#ifndef __MES_DEV_T
#define __MES_DEV_T
#undef dev_t
typedef int dev_t;
typedef long dev_t;
#endif
#if !defined (__MES_FILE_T) && ! defined (_FILE_T)
#define __MES_FILE_T
#define _FILE_T
typedef int FILE;
typedef long FILE;
#endif
#ifndef __MES_GID_T
#define __MES_GID_T
#undef gid_t
typedef int gid_t;
typedef unsigned gid_t;
#endif
#ifndef __MES_INO_T
#define __MES_INO_T
#undef ino_t
typedef unsigned ino_t;
typedef unsigned long ino_t;
#endif
#ifndef __MES_INO64_T
@ -111,7 +111,7 @@ typedef long ptrdiff_t;
#ifndef __MES_SIGVAL_T
#define __MES_SIGVAL_T
#undef clock_t
typedef int sigval_t;
typedef long sigval_t;
#endif
#ifndef __SIZE_T
@ -132,7 +132,7 @@ typedef long ssize_t;
#ifndef __MES_UID_T
#define __MES_UID_T
#undef uid_t
typedef int uid_t;
typedef unsigned uid_t;
#endif
#endif // ! WITH_GLIBC

View file

@ -62,7 +62,7 @@ int execve (char const *file, char *const argv[], char *const env[]);
int execvp (char const *file, char *const argv[]);
int fork (void);
char *getcwd (char *buf, size_t size);
uid_t getgid (void);
gid_t getgid (void);
uid_t getuid (void);
int isatty (int fd);
int link (char const *oldname, char const *newname);

View file

@ -35,6 +35,8 @@
#include <libc.c>
int errno;
#if __GNU__
#include <hurd/tcc.c>
#elif __linux__
@ -43,8 +45,10 @@
#error both __GNU__ and _linux__ are undefined, choose one
#endif
#if __MESC__
#if __MESC__ && __i386__
#include <x86-mes/setjmp.c>
#elif __MESC__ && __x86_64__
#include <x86_64-mes/setjmp.c>
#elif __i386__
#include <x86-mes-gcc/setjmp.c>
#elif __x86_64__

View file

@ -60,7 +60,7 @@ mkdir (char const *file_name, mode_t mode)
int
dup (int old)
{
return _sys_call1 (SYS_dup, (long)old);
return _sys_call1 (SYS_dup, (int)old);
}
gid_t
@ -69,28 +69,43 @@ getgid ()
return _sys_call (SYS_getgid);
}
// long _sys_call (long sys_call);
// long _sys_call4 (long sys_call, long one, long two, long three, long four);
#define SA_SIGINFO 4
#define SA_RESTORER 0x04000000
#define SYS_rt_sigreturn 15
void
_restorer (void)
{
_sys_call (SYS_rt_sigreturn);
}
# define __sigmask(sig) \
(((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
sighandler_t
signal (int signum, sighandler_t action)
{
#if __i386__
#if __MESC__
void *
signal (int signum, void * action)
#else
sighandler_t
signal (int signum, sighandler_t action)
#endif
{
return _sys_call2 (SYS_signal, signum, action);
}
#elif __x86_64__
sighandler_t
signal (int signum, sighandler_t action)
{
sighandler_t old;
_sys_call3 (SYS_rt_sigaction, signum, action, &old);
return old;
}
#else
#error arch not supported
static struct sigaction setup_action = {-1};
static struct sigaction old = {0};
setup_action.sa_handler = action;
setup_action.sa_restorer = _restorer;
setup_action.sa_mask = __sigmask (signum);
old.sa_handler = SIG_DFL;
setup_action.sa_flags = SA_RESTORER | SA_RESTART;
int r = _sys_call4 (SYS_rt_sigaction, signum, &setup_action, &old, sizeof (sigset_t));
if (r)
return 0;
return old.sa_handler;
#endif
}
int
fcntl (int filedes, int command, ...)
@ -98,7 +113,7 @@ fcntl (int filedes, int command, ...)
va_list ap;
va_start (ap, command);
int data = va_arg (ap, int);
int r = _sys_call3 (SYS_fcntl, (long)filedes, (long)command, (long)data);
int r = _sys_call3 (SYS_fcntl, (int)filedes, (int)command, (int)data);
va_end (ap);
return r;
}
@ -112,13 +127,13 @@ pipe (int filedes[2])
int
dup2 (int old, int new)
{
return _sys_call2 (SYS_dup2, (long)old, (long)new);
return _sys_call2 (SYS_dup2, (int)old, (int)new);
}
int
getrusage (int processes, struct rusage *rusage)
{
return _sys_call2 (SYS_getrusage, (long)processes, (long)rusage);
return _sys_call2 (SYS_getrusage, (int)processes, (long)rusage);
}
int
@ -142,15 +157,15 @@ setitimer (int which, struct itimerval const *new,
}
int
fstat (int fd, struct stat *statbuf)
fstat (int filedes, struct stat *statbuf)
{
return _sys_call2 (SYS_fstat, (long)fd, (long)statbuf);
return _sys_call2 (SYS_fstat, (int)filedes, (long)statbuf);
}
int
getdents (long filedes, char *buffer, size_t nbytes)
getdents (int filedes, char *buffer, size_t nbytes)
{
return _sys_call3 (SYS_getdents, (long)filedes, (long)buffer, (long)nbytes);
return _sys_call3 (SYS_getdents, (int)filedes, (long)buffer, (long)nbytes);
}
int

View file

@ -20,22 +20,16 @@
#include <errno.h>
#if __MESC__
#if __MESC__ && __i386__
#include <linux/x86-mes/mini.c>
#elif __MESC__ && __x86_64__
#include <linux/x86_64-mes/mini.c>
#elif __i386__
#include <linux/x86-mes-gcc/mini.c>
#elif __x86_64__
#include <linux/x86_64-mes-gcc/mini.c>
#else
#error arch not supported
#endif
ssize_t

View file

@ -18,31 +18,26 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libmes.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <libmes.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
#if __MESC__
#if __MESC__ && __i386__
#include <linux/x86-mes/mes.c>
#elif __MESC__ && __x86_64__
#include <linux/x86_64-mes/mes.c>
#elif __i386__
#include <linux/x86-mes-gcc/mes.c>
#elif __x86_64__
#include <linux/x86_64-mes-gcc/mes.c>
#else
#error arch not supported
#endif
int
@ -54,7 +49,7 @@ fork ()
ssize_t
read (int filedes, void *buffer, size_t size)
{
ssize_t bytes = _sys_call3 (SYS_read, (long)filedes, (long)buffer, (long)size);
ssize_t bytes = _sys_call3 (SYS_read, (int)filedes, (long)buffer, (long)size);
if (__mes_debug () > 3)
{
if (bytes == 1)
@ -71,11 +66,8 @@ read (int filedes, void *buffer, size_t size)
}
int
open (char const *file_name, int flags, ...)
_open3 (char const *file_name, int flags, int mask)
{
va_list ap;
va_start (ap, flags);
int mask = va_arg (ap, int);
#if !MES_BOOTSTRAP
if (!flags)
{
@ -83,7 +75,24 @@ open (char const *file_name, int flags, ...)
_ungetc_fd = -1;
}
#endif
int r = _sys_call3 (SYS_open, (long)file_name, (long)flags, (long)mask);
int r = _sys_call3 (SYS_open, (long)file_name, (int)flags, (int)mask);
return r;
}
int
_open2 (char const *file_name, int flags)
{
int mask = 0777;
return _open3 (file_name, flags, mask);
}
int
open (char const *file_name, int flags, ...)
{
va_list ap;
va_start (ap, flags);
int mask = va_arg (ap, int);
int r = _open3 (file_name, flags, mask);
va_end (ap);
return r;
}
@ -92,9 +101,9 @@ pid_t
waitpid (pid_t pid, int *status_ptr, int options)
{
#if __i386__
return _sys_call3 (SYS_waitpid, (long)pid, (long)status_ptr, (long)options);
return _sys_call3 (SYS_waitpid, (long)pid, (long)status_ptr, (int)options);
#elif __x86_64__
return _sys_call4 (SYS_wait4, (long)pid, (long)status_ptr, (long)options, 0);
return _sys_call4 (SYS_wait4, (long)pid, (long)status_ptr, (int)options, 0);
#else
#error arch not supported
#endif
@ -115,7 +124,7 @@ chmod (char const *file_name, mode_t mask)
int
access (char const *file_name, int how)
{
return _sys_call2 (SYS_access, (long)file_name, (long)how);
return _sys_call2 (SYS_access, (long)file_name, (int)how);
}
long
@ -130,7 +139,7 @@ ioctl (int filedes, unsigned long command, ...)
va_list ap;
va_start (ap, command);
int data = va_arg (ap, int);
int r = _sys_call3 (SYS_ioctl, (long)filedes, (long)command, (long)data);
int r = _sys_call3 (SYS_ioctl, (int)filedes, (long)command, (int)data);
va_end (ap);
return r;
}
@ -138,5 +147,5 @@ ioctl (int filedes, unsigned long command, ...)
int
fsync (int filedes)
{
return _sys_call1 (SYS_fsync, (long)filedes);
return _sys_call1 (SYS_fsync, (int)filedes);
}

View file

@ -28,13 +28,13 @@ close (int filedes)
_ungetc_pos = -1;
_ungetc_fd = -1;
}
return _sys_call1 (SYS_close, (long)filedes);
return _sys_call1 (SYS_close, (int)filedes);
}
off_t
lseek (int filedes, off_t offset, int whence)
{
return _sys_call3 (SYS_lseek, (long)filedes, (long)offset, (long)whence);
return _sys_call3 (SYS_lseek, (int)filedes, (long)offset, (int)whence);
}
int

View file

@ -19,7 +19,7 @@
*/
char **environ = 0;
int main (int argc, char *argv[], char *envp[]);
//int main (int argc, char *argv[], char *envp[]);
void
_start ()

View file

@ -19,7 +19,7 @@
*/
char **environ = 0;
int main (int argc, char *argv[]);
// int main (int argc, char *argv[]);
// gcc x86_64 calling convention:
// rdi, rsi, rdx, rcx, r8, r9, <stack0>, <stack1>

View file

@ -130,13 +130,15 @@ _sys_call4 (long sys_call, long one, long two, long three, long four)
"mov %2,%%rdi\n\t"
"mov %3,%%rsi\n\t"
"mov %4,%%rdx\n\t"
"mov %5,%%rcx\n\t"
"mov %5,%%r10\n\t"
"mov %1,%%rax\n\t"
// );
// asm (
"syscall \n\t"
"mov %%rax,%0\n\t"
: "=r" (r)
: "rm" (sys_call), "rm" (one), "rm" (two), "rm" (three), "rm" (four)
: "rax", "rdi", "rsi", "rdx", "rcx"
: "rax", "rdi", "rsi", "rdx", "r10"
);
if (r < 0)
{

View file

@ -24,6 +24,9 @@ int main (int argc, char *argv[]);
int
_start ()
{
#if 0 //MES_CCAMD64
asm ("add____$i32,%rbp %0x80"); // FIXME: corresponds to x86_64/as.scm function-preamble-fu
#endif
asm ("mov____%rbp,%rax");
asm ("add____$i8,%rax !8");
@ -33,23 +36,32 @@ _start ()
asm ("shl____$i8,%rax !0x03");
asm ("add____%rbp,%rax");
// 40017a: 48 a3 88 77 66 55 44 movabs %rax,0x1122334455667788
// 48 89 05 bd 0e 20 00 mov %rax,0x200ebd(%rip) # 601000 <_GLOBAL_OFFSET_TABLE_>
// FIXME: 64-bit addresses...DUNNO!
// asm ("mov____%rax,0x32 &environ");
// FIXME: 64-bit addresses...
asm ("mov____%rax,0x32 &environ");
#if 0 //MES_CCAMD64
asm ("mov____%rax,%rdx"); // amd
#else
asm ("push___%rax"); // bootstrap
#endif
asm ("mov____%rbp,%rax");
asm ("add____$i8,%rax !16");
asm ("mov____%rax,%rsi");
#if 0 //MES_CCAMD64
asm ("mov____%rax,%rsi"); // amd
#else
asm ("push___%rax"); // bootstrap
#endif
asm ("mov____%rbp,%rax");
asm ("add____$i8,%rax !8");
asm ("mov____(%rax),%rax");
asm ("mov____%rax,%rdi");
#if 0 //MES_CCAMD64
asm ("mov____%rax,%rdi"); // amd
#else
asm ("push___%rax"); // bootstrap
#endif
main ();
// FIXME
//asm ("call32 &main !00 !00 !00 !00");
asm ("mov____%rax,%rdi");
asm ("mov____$i32,%rax %0x3c");

123
lib/linux/x86_64-mes/mes.c Normal file
View file

@ -0,0 +1,123 @@
/* -*-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_64/syscall.h>
long
//__sys_call (long one, long two, long three, long four)
__sys_call (long sys_call, long one, long two, long three, long four)
{
#if 1 // !MES_CCAMD64
// asm ("mov____0x8(%rbp),%rdi !0x10");
// asm ("mov____0x8(%rbp),%rsi !0x18");
// asm ("mov____0x8(%rbp),%rdx !0x20");
// asm ("mov____0x8(%rbp),%rdx !0x28");
// asm ("mov____0x8(%rbp),%r10 !0x30");
asm ("mov____0x8(%rbp),%rax !0x10");
asm ("mov____0x8(%rbp),%rdi !0x18");
asm ("mov____0x8(%rbp),%rsi !0x20");
asm ("mov____0x8(%rbp),%rdx !0x28");
asm ("mov____0x8(%rbp),%r10 !0x30");
#endif
asm ("syscall");
}
long
_sys_call (long sys_call)
{
// long rax = sys_call;
// long r = __sys_call ();
long r = __sys_call (sys_call);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
long
_sys_call1 (long sys_call, long one)
{
// long rax = sys_call;
// long r = __sys_call (one);
long r = __sys_call (sys_call, one);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
long
_sys_call2 (long sys_call, long one, long two)
{
// long rax = sys_call;
// long r = __sys_call (one, two);
long r = __sys_call (sys_call, one, two);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
long
_sys_call3 (long sys_call, long one, long two, long three)
{
// long rax = sys_call;
// long r = __sys_call (one, two, three);
long r = __sys_call (sys_call, one, two, three);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
long
_sys_call4 (long sys_call, long one, long two, long three, long four)
{
// long rax = sys_call;
// long r = __sys_call (one, two, three, four);
long r = __sys_call (sys_call, one, two, three, four);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}

View file

@ -0,0 +1,43 @@
/* -*-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/>.
*/
void
_exit (int status)
{
#if 1 // !MES_CCAMD64
asm ("mov____0x8(%rbp),%rdi !0x10");
#endif
asm ("mov____$i32,%rax SYS_exit");
asm ("syscall");
}
void
_write (int filedes, void const *buffer, size_t size)
{
#if 1 // !MES_CCAMD64
asm ("mov____0x8(%rbp),%rdi !0x10");
asm ("mov____0x8(%rbp),%rsi !0x18");
asm ("mov____0x8(%rbp),%rdx !0x20");
#endif
asm ("mov____$i32,%rax SYS_write");
asm ("syscall");
}

View file

@ -26,7 +26,8 @@ abtol (char const **p, int base)
char const *s = *p;
int i = 0;
int sign = 1;
if (!base) base = 10;
if (!base)
base = 10;
if (*s && *s == '-')
{
sign = -1;

View file

@ -24,7 +24,7 @@ char *
mktemp (char *template)
{
char *p = strchr (template, '\0');
int q = (int)template;
int q = (long)template;
*--p = ((unsigned char)(q >> 4)) % 26 + 'a';
*--p = ((unsigned char)(q >> 8)) % 26 + 'a';
*--p = ((unsigned char)(q >> 12)) % 26 + 'a';

View file

@ -20,7 +20,7 @@
#include <sys/wait.h>
int
pid_t
wait (int *status_ptr)
{
return waitpid (-1, status_ptr, 0);

View file

@ -22,6 +22,12 @@
#include <libmes.h>
#include <stdio.h>
//#if __GNUC__ && __x86_64__
#if __x86_64__
#undef open
#define open _open3
#endif
FILE*
fopen (char const *file_name, char const *opentype)
{
@ -64,3 +70,5 @@ fopen (char const *file_name, char const *opentype)
fd = 0;
return (FILE*)fd;
}
#undef open

View file

@ -23,5 +23,5 @@
int
fputc (int c, FILE* stream)
{
return fdputc (c, (long)stream);
return fdputc (c, (int)stream);
}

View file

@ -24,7 +24,7 @@
int
fseek (FILE *stream, long offset, int whence)
{
int pos = lseek ((int)stream, offset, whence);
off_t pos = lseek ((int)stream, offset, whence);
if (__mes_debug ())
{
eputs ("fread fd="); eputs (itoa ((int)stream));

View file

@ -25,8 +25,14 @@ int
printf (char const* format, ...)
{
va_list ap;
int r;
#if __GNUC__ && __x86_64__
#define __FUNCTION_ARGS 1
ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3;
#undef __FUNCTION_ARGS
#endif
va_start (ap, format);
int r = vprintf (format, ap);
r = vprintf (format, ap);
va_end (ap);
return r;
}

View file

@ -25,8 +25,14 @@ int
sprintf (char *str, char const* format, ...)
{
va_list ap;
int r;
#if __GNUC__ && __x86_64__
#define __FUNCTION_ARGS 2
ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3;
#undef __FUNCTION_ARGS
#endif
va_start (ap, format);
int r = vsprintf (str, format, ap);
r = vsprintf (str, format, ap);
va_end (ap);
return r;
}

View file

@ -25,7 +25,7 @@
int
vfprintf (FILE* f, char const* format, va_list ap)
{
int fd = (int)f;
int fd = (long)f;
char const *p = format;
int count = 0;
while (*p)
@ -85,8 +85,19 @@ vfprintf (FILE* f, char const* format, va_list ap)
}
switch (c)
{
case '%': {fputc (*p, fd); count++; break;}
case 'c': {char c; c = va_arg (ap, int); fputc (c, fd); break;}
case '%':
{
fputc (*p, fd);
count++;
break;
}
case 'c':
{
char _c;
_c = va_arg (ap, long);
fputc (_c, fd);
break;
}
case 'd':
case 'i':
case 'o':
@ -94,7 +105,7 @@ vfprintf (FILE* f, char const* format, va_list ap)
case 'x':
case 'X':
{
int d = va_arg (ap, int);
long d = va_arg (ap, long);
int base = c == 'o' ? 8
: c == 'x' || c == 'X' ? 16
: 10;

View file

@ -57,7 +57,7 @@ vsprintf (char *str, char const* format, va_list ap)
}
else if (c == '*')
{
width = va_arg (ap, int);
width = va_arg (ap, long);
c = *++p;
}
if (c == '.')
@ -70,7 +70,7 @@ vsprintf (char *str, char const* format, va_list ap)
}
else if (c == '*')
{
precision = va_arg (ap, int);
precision = va_arg (ap, long);
c = *++p;
}
}
@ -85,8 +85,19 @@ vsprintf (char *str, char const* format, va_list ap)
}
switch (c)
{
case '%': {*str++ = *p; count++; break;}
case 'c': {c = va_arg (ap, int); *str++ = c; count++; break;}
case '%':
{
*str++ = *p;
count++;
break;
}
case 'c':
{
c = va_arg (ap, long);
*str++ = c;
count++;
break;
}
case 'd':
case 'i':
case 'o':
@ -94,7 +105,7 @@ vsprintf (char *str, char const* format, va_list ap)
case 'x':
case 'X':
{
int d = va_arg (ap, int);
long d = va_arg (ap, long);
int base = c == 'o' ? 8
: c == 'x' || c == 'X' ? 16
: 10;

View file

@ -41,7 +41,11 @@ vsscanf (char const *s, char const *template, va_list ap)
c = *++t;
switch (c)
{
case '%': {p++; break;}
case '%':
{
p++;
break;
}
case 'c':
{
char *c = va_arg (ap, char*);

View file

@ -40,7 +40,13 @@ qpart (void *base, size_t count, size_t size, int (*compare)(void const *, void
int c = compare (base+j*size, p);
if (c < 0)
{
#if 1 //__x86_64__
qswap (base+i*size, base+j*size, size);
#else
int p1 = base+i*size;
int p2 = base+j*size;
qswap (p1, p2, size);
#endif
i++;
}
else if (c == 0)
@ -58,6 +64,12 @@ qsort (void *base, size_t count, size_t size, int (*compare)(void const *, void
{
int p = qpart (base, count-1, size, compare);
qsort (base, p, size, compare);
#if 1 //__x86_64__
qsort (base+p*size, count-p, size, compare);
#else
int p1 = base+p*size;
int p2 = count-p;
qsort (p1, p2, size, compare);
#endif
}
}

View file

@ -19,24 +19,12 @@
*/
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
int errno;
void
longjmp (jmp_buf env, int val)
{
val = val == 0 ? 1 : val;
asm ("mov 0xc(%ebp),%eax\n\t" // val
"mov 0x8(%ebp),%ebp\n\t" // env*
asm ("mov 0x8(%ebp),%ebp\n\t" // env*
"mov 0x4(%ebp),%ebx\n\t" // env->__pc
"mov 0x8(%ebp),%esp\n\t" // env->__sp
@ -47,30 +35,12 @@ longjmp (jmp_buf env, int val)
exit (42);
}
#if 0
int
setjmp_debug (jmp_buf env, int val)
{
int i;
#if 1
i = env->__bp;
i = env->__pc;
i = env->__sp;
#else
i = env[0].__bp;
i = env[0].__pc;
i = env[0].__sp;
#endif
return val == 0 ? 1 : val;
}
#endif
int
setjmp (jmp_buf env)
{
int *p = (int*)&env;
long *p = (long*)&env;
env[0].__bp = p[-2];
env[0].__pc = p[-1];
env[0].__sp = (int)&env;
env[0].__sp = (long)&env;
return 0;
}

View file

@ -19,23 +19,12 @@
*/
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
int errno;
void
longjmp (jmp_buf env, int val)
{
val = val == 0 ? 1 : val;
asm ("mov____0x8(%ebp),%eax !0x0c"); // val
///asm ("mov____0x8(%ebp),%eax !0x0c"); // val
asm ("mov____0x8(%ebp),%ebp !0x08"); // env*
asm ("mov____0x8(%ebp),%ebx !0x4"); // env.__pc
@ -46,28 +35,10 @@ longjmp (jmp_buf env, int val)
exit (42);
}
#if 0
int
setjmp_debug (jmp_buf env, int val)
{
int i;
#if 1
i = env->__bp;
i = env->__pc;
i = env->__sp;
#else
i = env[0].__bp;
i = env[0].__pc;
i = env[0].__sp;
#endif
return val == 0 ? 1 : val;
}
#endif
int
setjmp (__jmp_buf *env)
{
int *p = (int*)&env;
long *p = (long*)&env;
env[0].__bp = p[-2];
env[0].__pc = p[-1];
env[0].__sp = (long)&env;

View file

@ -1,5 +1,5 @@
### GNU Mes --- Maxwell Equations of Software
### Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
### Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
###
### This file is part of GNU Mes.
###
@ -16,40 +16,41 @@
### You should have received a copy of the GNU General Public License
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
# reduced instruction set: eax, ebx (some ecx for shift, edx for mul, div)
# 182 instructions
DEFINE add____$i32,%eax 05
DEFINE add____$i32,%ecx 81c1
DEFINE add____$i32,%edx 81c2
DEFINE add____$i32,%ebx 81c3
DEFINE add____$i32,(%eax) 8100
DEFINE add____$i32,(%ebx) 8103
DEFINE add____$i32,0x32(%eax) 8180
DEFINE add____$i32,0x32(%ebp) 8185
DEFINE add____$i8,%eax 83c0
DEFINE add____$i8,%edx 83c2
DEFINE add____$i8,%ebx 83c3
DEFINE add____$i8,%esp 83c4
DEFINE add____$i8,(%eax) 8300
DEFINE add____$i8,(%ebx) 8303
DEFINE add____$i8,0x32 8305
DEFINE add____$i8,0x32(%eax) 8380
DEFINE add____$i8,0x32(%eax) 8380
DEFINE add____$i8,0x32(%ebp) 8385
DEFINE add____$i8,0x8(%eax) 8340
DEFINE add____$i8,0x8(%ebp) 8345
DEFINE add____%eax,%eax 01c0
DEFINE add____%ebp,%eax 01e8
DEFINE add____%edx,%eax 01d0
DEFINE add____%edx,%eax 01d0
DEFINE add____%ebx,%eax 01d8
DEFINE add____%ebx,%ebx 01db
DEFINE addb___$i8,(%eax) 8000
DEFINE addb___$i8,(%ebx) 8003
DEFINE addw___$i8,(%eax) 668100
DEFINE addw___$i8,(%ebx) 668103
DEFINE and____$i32,%eax 25
DEFINE and____%edx,%eax 21d0
DEFINE and____(%edx),%eax 2302
DEFINE and____$i32,%ebx 81e3
DEFINE and____%ebx,%eax 21d8
DEFINE call32 e8
DEFINE call___*%eax ffd0
DEFINE call___*%ebx ffd3
DEFINE cmp____$0x32,%eax 3d
DEFINE cmp____$i32,%eax 3d
DEFINE cmp____$i32,0x32(%ebp) 81bd
DEFINE cmp____$i32,0x8(%ebp) 817d
DEFINE cmp____$i8,%eax 83f8
DEFINE cmp____$i8,0x32(%ebp) 83bd
DEFINE cmp____$i8,0x8(%ebp) 837d
DEFINE cmp____%al,%dl 38c2
DEFINE cmp____%edx,%eax 39d0
DEFINE hlt f4
DEFINE idiv___%ebx f7fb
DEFINE int cd
@ -69,104 +70,86 @@ DEFINE jmp____*%ebx ffe3
DEFINE jne32 0f85
DEFINE lahf 9f
DEFINE lea____0x32(%ebp),%eax 8d85
DEFINE lea____0x32(%ebp),%edx 8d95
DEFINE lea____0x8(%ebp),%eax 8d45
DEFINE lea____0x8(%ebp),%edx 8d55
DEFINE leave c9
DEFINE mov____$i32,%eax b8
DEFINE mov____$i32,%ebx bb
DEFINE mov____$i32,%ecx b9
DEFINE mov____$i32,%edx ba
DEFINE mov____$i32,(%eax) c700
DEFINE mov____$i32,0x32 c705
DEFINE mov____$i32,0x8(%eax) c740
DEFINE mov____$i32,0x8(%ebp) c745
DEFINE mov____%al,(%edx) 8802
DEFINE mov____%al,0x8(%edx) 8842
DEFINE mov____%ax,(%edx) 668902
DEFINE mov____%ax,0x32(%edx) 668982
DEFINE mov____%ax,0x8(%edx) 668942
DEFINE mov____%al,(%ebx) 8803
DEFINE mov____%al,0x8(%ebp) 8845
DEFINE mov____%ax,(%ebx) 668903
DEFINE mov____%ax,0x8(%ebp) 668945
DEFINE mov____%dl,(%eax) 8810
DEFINE mov____%dl,0x8(%eax) 8850
DEFINE mov____%eax,%ebx 89c3
DEFINE mov____%eax,%edx 89c2
DEFINE mov____%eax,(%ecx) 8901
DEFINE mov____%eax,(%edx) 8902
DEFINE mov____%eax,%ecx 89c1
DEFINE mov____%eax,(%ebx) 8903
DEFINE mov____%eax,0x32 a3
DEFINE mov____%eax,0x32(%ebp) 8985
DEFINE mov____%eax,0x32(%edx) 8982
DEFINE mov____%eax,0x8(%ebp) 8945
DEFINE mov____%eax,0x8(%edx) 8942
DEFINE mov____%ebp,%eax 89e8
DEFINE mov____%ebp,%ecx 89e9
DEFINE mov____%ebp,%edx 89ea
DEFINE mov____%ebp,%ebx 89eb
DEFINE mov____%ebx,%eax 89d8
DEFINE mov____%ebx,%ecx 89d9
DEFINE mov____%ebx,0x32 891d
DEFINE mov____%ebx,0x32(%ebp) 899d
DEFINE mov____%ebx,0x8(%ebp) 895d
DEFINE mov____%ebx,0x8(%edx) 895a
DEFINE mov____%ecx,(%eax) 8908
DEFINE mov____%ecx,(%edx) 890a
DEFINE mov____%ecx,0x32(%ebp) 898d
DEFINE mov____%ecx,0x8(%ebp) 894d
DEFINE mov____%ecx,(%ebx) 890b
DEFINE mov____%edx,%eax 89d0
DEFINE mov____%edx,%ebx 89d3
DEFINE mov____%edx,%ecx 89d1
DEFINE mov____%edx,(%eax) 8910
DEFINE mov____%edx,0x32(%ebp) 8995
DEFINE mov____%edx,0x8(%ebp) 8955
DEFINE mov____%esp,%ebp 89e5
DEFINE mov____(%eax),%eax 8b00
DEFINE mov____(%eax),%ecx 8b08
DEFINE mov____(%edx),%eax 8b02
DEFINE mov____(%edx),%ecx 8b0a
DEFINE mov____(%edx),%edx 8b12
DEFINE mov____(%ebx),%ebx 8b1b
DEFINE mov____0x32(%eax),%eax 8b80
DEFINE mov____0x32(%eax),%ebx 8b98
DEFINE mov____0x32(%eax),%ecx 8b88
DEFINE mov____0x32(%ebp),%eax 8b85
DEFINE mov____0x32(%ebp),%eax 8b85
DEFINE mov____0x32(%ebp),%ebx 8b9d
DEFINE mov____0x32(%ebp),%ecx 8b8d
DEFINE mov____0x32(%ebp),%edx 8b95
DEFINE mov____0x32(%ebp),%edx 8b95
DEFINE mov____0x32,%eax a1
DEFINE mov____0x32,%edx 8b15
DEFINE mov____0x32,%ebx 8b1d
DEFINE mov____0x8(%eax),%eax 8b40
DEFINE mov____0x8(%eax),%ebx 8b58
DEFINE mov____0x8(%eax),%ecx 8b48
DEFINE mov____0x8(%ebp),%eax 8b45
DEFINE mov____0x8(%ebp),%ebp 8b6d
DEFINE mov____0x8(%ebp),%ebx 8b5d
DEFINE mov____0x8(%ebp),%ecx 8b4d
DEFINE mov____0x8(%ebp),%edi 8b7d
DEFINE mov____0x8(%ebp),%edx 8b55
DEFINE mov____0x8(%ebp),%esi 8b75
DEFINE mov____0x8(%ebp),%esp 8b65
DEFINE movsbl_%al,%eax 0fbec0
DEFINE movsbl_%bl,%ebx 0fbedb
DEFINE movswl_%ax,%eax 0fbfc0
DEFINE movswl_%bx,%ebx 0fbfdb
DEFINE movzbl_%al,%eax 0fb6c0
DEFINE movzbl_%al,%eax 0fb6c0
DEFINE movzbl_%dl,%edx 0fb6d2
DEFINE movzbl_%bl,%ebx 0fb6db
DEFINE movzbl_(%eax),%eax 0fb600
DEFINE movzbl_(%eax),%edx 0fb610
DEFINE movzbl_(%edx),%edx 0fb612
DEFINE movzbl_(%ebx),%ebx 0fb61b
DEFINE movzbl_0x32(%eax),%eax 0fb680
DEFINE movzbl_0x8(%eax),%eax 0fb640
DEFINE movzbl_0x8(%ebp),%eax 0fb645
DEFINE movzwl_%ax,%eax 0fb7c0
DEFINE movzwl_(%eax),%eax 0fb700
DEFINE movzwl_(%ebx),%ebx 0fb71b
DEFINE movzwl_0x32(%eax),%eax 0fb780
DEFINE movzwl_0x32(%ebp),%eax 0fb785
DEFINE movzwl_0x8(%eax),%eax 0fb740
DEFINE mul____%edx f7e2
DEFINE mul____%ebx f7e3
DEFINE mul_____%ebx f7e3
DEFINE nop 90
DEFINE not____%eax f7d0
DEFINE or_____%edx,%eax 09d0
DEFINE or_____(%edx),%eax 0b02
DEFINE not____%ebx f7d3
DEFINE or_____%ebx,%eax 09d8
DEFINE pop____%eax 58
DEFINE pop____%ebx 5b
DEFINE pop____%edx 5a
DEFINE push___$i32 68
DEFINE push___%eax 50
DEFINE push___%ebp 55
DEFINE push___%ebx 53
DEFINE push___%edx 52
DEFINE push___(%eax) ff30
DEFINE push___0x32(%ebp) ffb5
@ -174,36 +157,154 @@ DEFINE push___0x8(%ebp) ff75
DEFINE ret c3
DEFINE sahf 9e
DEFINE seta___%al 0f97c0
DEFINE seta___%bl 0f97c3
DEFINE setae__%al 0f93c0
DEFINE setae__%bl 0f93c3
DEFINE setb___%al 0f92c0
DEFINE setb___%bl 0f92c3
DEFINE setbe__%al 0f96c0
DEFINE setbe__%bl 0f96c3
DEFINE sete___%al 0f94c0
DEFINE sete___%bl 0f94c3
DEFINE setg___%al 0f9fc0
DEFINE setg___%bl 0f9fc3
DEFINE setge__%al 0f9dc0
DEFINE setge__%bl 0f9dc3
DEFINE setl___%al 0f9cc0
DEFINE setl___%bl 0f9cc3
DEFINE setle__%al 0f9ec0
DEFINE setle__%bl 0f9ec3
DEFINE setne__%al 0f95c0
DEFINE setne__%bl 0f95c3
DEFINE shl____$i8,%eax c1e0
DEFINE shl____$i8,%ebx c1e3
DEFINE shl____%cl,%eax d3e0
DEFINE shl____%cl,%ebx d3e3
DEFINE shr____%cl,%eax d3e8
DEFINE sub____$8,%esp 83ec
DEFINE sub____$i32,%esp 81ec
DEFINE sub____%al,%dl 28d0
DEFINE sub____%dl,%al 28c2
DEFINE sub____%eax,%edx 29c2
DEFINE sub____%edx,%eax 29d0
DEFINE sub____%edx,%eax 29d0
DEFINE sub____%ebx,%eax 29d8
DEFINE test___%al,%al 84c0
DEFINE test___%eax,%eax 85c0
DEFINE test___%ebx,%ebx 85db
DEFINE xchg___%eax,%ebx 93
DEFINE xchg___%eax,(%esp) 870424
DEFINE xchg___%eax,(%esp) 870424
DEFINE xchg___%ebx,(%esp) 871c24
DEFINE xor____$i32,%eax 35
DEFINE xor____$i8,%ah 80f4
DEFINE xor____%eax,%eax 31c0
DEFINE xor____%ebx,%eax 31d8
DEFINE xor____%ebx,%ebx 31db
DEFINE xor____%ecx,%ecx 31c9
DEFINE xor____%edx,%eax 31d0
DEFINE xor____%edx,%edx 31d2
# Enough for all of Mes + Mes C Libray when using all registers, i.e.,
# non-reduced instruction set
#DEFINE add____$i32,%ecx 81c1
#DEFINE add____$i32,%edx 81c2
#DEFINE add____$i32,%esi 81c6
#DEFINE add____$i8,%ecx 83c1
#DEFINE add____$i8,%edx 83c2
#DEFINE add____$i8,%esi 83c6
#DEFINE add____$i8,(%ecx) 8301
#DEFINE add____$i8,(%edx) 8302
#DEFINE add____%ecx,%ebx 01cb
#DEFINE add____%ecx,%ecx 01c9
#DEFINE add____%edx,%eax 01d0
#DEFINE add____%edx,%ecx 01d1
#DEFINE add____%edx,%edx 01d2
#DEFINE add____%esi,%edx 01f2
#DEFINE and____$i32,%ecx 81e1
#DEFINE and____$i32,%edx 81e2
#DEFINE and____%edx,%eax 21d0
#DEFINE and____(%edx),%eax 2302
#DEFINE cmp____%edx,%eax 39d0
#DEFINE idiv___%ecx f7f9
#DEFINE lea____0x32(%ebp),%edx 8d95
#DEFINE lea____0x8(%ebp),%edx 8d55
#DEFINE mov____$i32,%ecx b9
#DEFINE mov____$i32,%edx ba
#DEFINE mov____$i32,%esi be
#DEFINE mov____%al,(%edx) 8802
#DEFINE mov____%al,0x8(%edx) 8842
#DEFINE mov____%ax,(%edx) 668902
#DEFINE mov____%ax,0x32(%edx) 668982
#DEFINE mov____%ax,0x8(%edx) 668942
#DEFINE mov____%bl,(%ecx) 8819
#DEFINE mov____%eax,%edx 89c2
#DEFINE mov____%eax,%esi 89c6
#DEFINE mov____%eax,(%ecx) 8901
#DEFINE mov____%eax,(%edx) 8902
#DEFINE mov____%eax,0x32(%edx) 8982
#DEFINE mov____%eax,0x8(%edx) 8942
#DEFINE mov____%ebp,%ecx 89e9
#DEFINE mov____%ebp,%edx 89ea
#DEFINE mov____%ebp,%esi 89ee
#DEFINE mov____%ebx,(%ecx) 8919
#DEFINE mov____%ebx,0x8(%edx) 895a
#DEFINE mov____%ecx,%eax 89c8
#DEFINE mov____%ecx,%ecx 89c9
#DEFINE mov____%ecx,%edx 89ca
#DEFINE mov____%ecx,(%eax) 8908
#DEFINE mov____%ecx,(%edx) 890a
#DEFINE mov____%ecx,0x32(%ebp) 898d
#DEFINE mov____%ecx,0x8(%ebp) 894d
#DEFINE mov____%edi,%ebx 89fb
#DEFINE mov____%edx,%ecx 89d1
#DEFINE mov____%edx,(%eax) 8910
#DEFINE mov____%edx,0x32(%ebp) 8995
#DEFINE mov____%edx,0x8(%ebp) 8955
#DEFINE mov____%esi,%eax 89f0
#DEFINE mov____%esi,%ebx 89f3
#DEFINE mov____(%ecx),%ecx 8b09
#DEFINE mov____(%edx),%eax 8b02
#DEFINE mov____(%edx),%ecx 8b0a
#DEFINE mov____(%edx),%edx 8b12
#DEFINE mov____0x32(%eax),%ecx 8b88
#DEFINE mov____0x32(%ebp),%ecx 8b8d
#DEFINE mov____0x32(%ebp),%edx 8b95
#DEFINE mov____0x32,%ecx 8b0d
#DEFINE mov____0x32,%edx 8b15
#DEFINE mov____0x8(%eax),%ecx 8b48
#DEFINE movsbl_%cl,%ecx 0fbec9
#DEFINE movsbl_%dl,%edx 0fbed2
#DEFINE movswl_%cx,%ecx 0fbfc9
#DEFINE movzbl_%cl,%ecx 0fb6c9
#DEFINE movzbl_%dl,%edx 0fb6d2
#DEFINE movzbl_(%eax),%edx 0fb610
#DEFINE movzbl_(%ecx),%ecx 0fb609
#DEFINE movzbl_(%edx),%edx 0fb612
#DEFINE movzwl_(%ecx),%ecx 0fb709
#DEFINE mul____%ecx f7e1
#DEFINE mul____%edi f7e7
#DEFINE mul____%edx f7e2
#DEFINE mul____%esi f7e6
#DEFINE or_____%ecx,%ebx 09cb
#DEFINE or_____%edx,%eax 09d0
#DEFINE or_____(%edx),%eax 0b02
#DEFINE pop____%ecx 59
#DEFINE pop____%edi 5f
#DEFINE push___%ecx 51
#DEFINE push___%edi 57
#DEFINE push___%esi 56
#DEFINE shl____$i8,%ecx c1e1
#DEFINE shl____$i8,%edx c1e2
#DEFINE shl____%cl,%ecx d3e1
#DEFINE sub____%eax,%edx 29c2
#DEFINE sub____%ecx,%ebx 29cb
#DEFINE sub____%edx,%eax 29d0
#DEFINE sub____%edx,%ecx 29d1
#DEFINE xchg___%ebx,%ecx 87d9
#DEFINE xchg___%ecx,%edx 87ca
#DEFINE xor____%ecx,%ecx 31c9
#DEFINE xor____%edx,%eax 31d0
# deprecated, remove after 0.18
DEFINE sub____%esp,$i32 81ec
DEFINE sub____%esp,$i8 83ec

View file

@ -19,57 +19,31 @@
*/
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
int errno;
void
longjmp (jmp_buf env, int val)
{
val = val == 0 ? 1 : val;
asm ("mov %esi,%eax\n\t" // val
asm (
"mov 0x00(%rdi),%rbp\n\t" // env->__bp
"mov 0x08(%rdi),%rbx\n\t" // env->__pc
"mov 0x16(%rdi),%rsp\n\t" // env->__sp
"mov 0x10(%rdi),%rsp\n\t" // env->__sp
"jmp *%rbx\n\t" // jmp *PC
);
// not reached
exit (42);
}
#if 0
int
setjmp_debug (jmp_buf env, int val)
{
int i;
#if 1
i = env->__bp;
i = env->__pc;
i = env->__sp;
#else
i = env[0].__bp;
i = env[0].__pc;
i = env[0].__sp;
#endif
return val == 0 ? 1 : val;
}
#endif
int
setjmp (jmp_buf env)
{
int *p = (int*)&env;
env[0].__bp = p[-2];
env[0].__pc = p[-1];
env[0].__sp = (long)&env;
long *p;
asm ("mov %%rbp,%0"
: "=r" (p)
: //no inputs ""
);
env[0].__bp = p;
env[0].__pc = p[1];
env[0].__sp = p[0];
return 0;
}

71
lib/x86_64-mes/setjmp.c Normal file
View file

@ -0,0 +1,71 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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 <setjmp.h>
void
longjmp (jmp_buf env, int val)
{
#if 0 //MES_CCAMD64
asm ("push___%rdi");
#endif
val = val == 0 ? 1 : val;
#if 0 //MES_CCAMD64
asm ("pop____%rdi");
asm ("mov____0x8(%rdi),%rbp !0x00"); // env->__bp
asm ("mov____0x8(%rdi),%rbx !0x08"); // env->__pc
asm ("mov____0x8(%rdi),%rsp !0x10"); // env->__sp
asm ("jmp____*%rbx"); // jmp *PC
#else
asm ("mov____0x8(%rbp),%rbp !0x10"); // env*
asm ("mov____0x8(%rbp),%rbx !0x08"); // env.__pc
asm ("mov____0x8(%rbp),%rsp !0x10"); // env.__sp
asm ("mov____0x8(%rbp),%rbp !0x00"); // env.__bp
asm ("jmp____*%rbx");
#endif
// not reached
exit (42);
}
int
setjmp (__jmp_buf *env)
{
#if 0 //MES_CCAMD64
asm ("mov____%rbp,%rax");
asm ("add____$i32,%rax %0x80");
asm ("mov____0x8(%rax),%rsi !0x00");
asm ("mov____%rsi,0x8(%rdi) !0x00");
asm ("mov____0x8(%rax),%rsi !0x08");
asm ("mov____%rsi,0x8(%rdi) !0x08");
asm ("mov____%rax,%rsi");
asm ("add____$i32,%rsi %0x10");
asm ("mov____%rsi,0x8(%rdi) !0x10");
#else
long *p = (long*)&env;
env[0].__bp = p[-2];
env[0].__pc = p[-1];
env[0].__sp = (long)&env;
#endif
return 0;
}

View file

@ -16,38 +16,293 @@
### You should have received a copy of the GNU General Public License
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
# reduced instruction set: rax, rdi (some rcx for shift, rdx for mul, div)
# 184 instructions
# TODO: $i64/$0x64 instructions are missing
DEFINE add____$i32,%rax 4805
DEFINE add____$i32,%rbp 4881c5
DEFINE add____$i32,%rdi 4881c7
DEFINE add____$i32,(%rax) 8100
DEFINE add____$i32,0x32(%rbp) 8185
DEFINE add____$i8,%rax 4883c0
DEFINE add____$i8,%rdi 4883c7
DEFINE add____$i8,%rsp 4883c4
DEFINE add____$i8,(%rax) 8300
DEFINE add____$i8,(%rdi) 8307
DEFINE add____$i8,0x8(%rbp) 8345
DEFINE add____%rax,%rax 4801c0
DEFINE add____%rbp,%rax 4801e8
DEFINE add____%rdi,%rax 4801f8
DEFINE add____%rdi,%rdi 4801ff
DEFINE addb___$i8,(%rax) 8000
DEFINE addb___$i8,(%rdi) 8007
DEFINE addl___$i32,(%rax) 8100
DEFINE addl___$i32,(%rdi) 8107
DEFINE addl___$i8,(%rax) 8300
DEFINE addl___$i8,(%rdi) 8307
DEFINE addw___$i8,(%rax) 668100
DEFINE addw___$i8,(%rdi) 668107
DEFINE and____$i32,%rdi 4881e7
DEFINE and____%rdi,%rax 4821f8
DEFINE call32 e8
DEFINE call___*%rax ffd0
DEFINE call___*%rdi ffd7
DEFINE cmp____$i32,%rax 483d
DEFINE cmp____$i8,%rax 4883f8
DEFINE hlt f4
DEFINE idiv___%rdi 48f7ff
DEFINE ja32 0f87
DEFINE jae32 0f83
DEFINE jb32 0f82
DEFINE jbe32 0f86
DEFINE je32 0f84
DEFINE je8 74
DEFINE jg32 0f8f
DEFINE jge32 0f8d
DEFINE jl32 0f8c
DEFINE jle32 0f8e
DEFINE jmp32 e9
DEFINE jmp____*%rbx ffe3
DEFINE jne32 0f85
DEFINE lahf 9f
DEFINE mov____$i32,%rax 48c7c0
DEFINE mov____$i32,%rdi 48c7c7
DEFINE mov____$i32,0x8(%rbp) c745
DEFINE mov____$i64,%rax 48a1
DEFINE mov____$i64,%rax 48b8
DEFINE mov____%al,(%rdi) 8807
DEFINE mov____%al,0x32(%rbp) 8885
DEFINE mov____%al,0x8(%rbp) 8845
DEFINE mov____%ax,(%rdi) 668907
DEFINE mov____%ax,0x8(%rbp) 668945
DEFINE mov____%eax,(%rdi) 8907
DEFINE mov____%eax,0x32(%rbp) 8985
DEFINE mov____%eax,0x8(%rbp) 8945
DEFINE mov____%eax,0x8(%rbp) 8945
DEFINE mov____%edi,0x32(%rbp) 89bd
DEFINE mov____%edi,0x8(%rbp) 897d
DEFINE mov____%r8,0x8(%rbp) 4c8945
DEFINE mov____%esi,%eax 89f0
DEFINE mov____%r8,%rdi 4c89c7
DEFINE mov____%rax,%rax 4889c0
DEFINE mov____%rax,%rbx 4889c3
DEFINE mov____%rax,%rdi 4889c7
DEFINE mov____%rax,%rsi 4889c6
DEFINE mov____%rax,(%rdi) 488907
DEFINE mov____%rax,0x32 48890425
DEFINE mov____%rax,0x32(%rbp) 488985
DEFINE mov____%rax,0x8(%rbp) 488945
DEFINE mov____%rax,0x8(%rdi) 488947
DEFINE mov____%rbp,%rax 4889e8
DEFINE mov____%rbp,%rdi 4889ef
DEFINE mov____%rbp,%rsp 4889ec
DEFINE mov____%rcx,0x8(%rbp) 48894d
DEFINE mov____%rbp,0x8(%rbp) 48896d
DEFINE mov____%rdi,%r8 4989f8
DEFINE mov____%rdi,%rax 4889f8
DEFINE mov____%rdi,%rcx 4889f9
DEFINE mov____%rdi,%rdi 4889ff
DEFINE mov____%rdi,0x32 48893c25
DEFINE mov____%rdi,0x32(%rbp) 4889bd
DEFINE mov____%rdi,0x8(%rbp) 48897d
DEFINE mov____%rdx,0x8(%rbp) 488955
DEFINE mov____%rsi,0x8(%rbp) 488975
DEFINE mov____%rdx,%rax 4889d0
DEFINE mov____%rdx,%rdi 4889d7
DEFINE mov____%rsi,(%rdi) 488937
DEFINE mov____%rsp,%rbp 4889e5
DEFINE mov____(%rax),%eax 8b00
DEFINE mov____(%rax),%rax 488b00
DEFINE mov____(%rax),%rsi 488b30
DEFINE mov____(%rdi),%edi 8b3f
DEFINE mov____(%rdi),%rdi 488b3f
DEFINE mov____0x32(%rbp),%rax 488b85
DEFINE mov____0x32(%rbp),%rdi 488bbd
DEFINE mov____0x32,%rax 488b0425
DEFINE mov____0x32,%rdi 488b3c25
DEFINE mov____0x8(%rbp),%eax 8b45
DEFINE mov____0x8(%rbp),%r10 4c8b55
DEFINE mov____0x8(%rbp),%r8 4c8b45
DEFINE mov____0x8(%rbp),%rax 488b45
DEFINE mov____0x8(%rbp),%rbp 488b6d
DEFINE mov____0x8(%rbp),%rbx 488b5d
DEFINE mov____0x8(%rbp),%rcx 488b4d
DEFINE mov____0x8(%rbp),%rdi 488b7d
DEFINE mov____0x8(%rbp),%rdx 488b55
DEFINE mov____0x8(%rbp),%rsi 488b75
DEFINE mov____0x8(%rbp),%rsp 488b65
DEFINE mov____0x8(%rdi),%rax 488b47
DEFINE mov____0x8(%rdi),%rbp 488b6f
DEFINE mov____0x8(%rdi),%rsp 488b67
DEFINE movsbq_%al,%rax 480fbec0
DEFINE movsbq_%dil,%rdi 480fbeff
DEFINE movsbq_(%rax),%rax 480fbe00
DEFINE movsbq_(%rdi),%rdi 480fbe3f
DEFINE movslq_%eax,%rax 4863c0
DEFINE movslq_%edi,%rdi 4863ff
DEFINE movslq_(%rax),%rax 486300
DEFINE movslq_(%rdi),%rdi 48633f
DEFINE movswq_%ax,%rax 480fbfc0
DEFINE movswq_%di,%rdi 480fbfff
DEFINE movswq_(%rax),%rax 480fbf00
DEFINE movswq_(%rdi),%rdi 480fbf3f
DEFINE movz___(%rax),%rax 480fb600
DEFINE movzbq_%al,%rax 480fb6c0
DEFINE movzbq_%dil,%rdi 480fb6ff
DEFINE movzbq_(%rax),%rax 480fb600
DEFINE movzbq_(%rdi),%rdi 480fb63f
DEFINE movzlq_(%rax),%rax 8b00
DEFINE movzlq_(%rdi),%rdi 8b3f
DEFINE movzwq_(%rax),%rax 480fb700
DEFINE movzwq_(%rdi),%rdi 480fb73f
DEFINE mul____%rdi 48f7e7
DEFINE nop 90
DEFINE not____%rax 48f7d0
DEFINE not____%rdi 48f7d7
DEFINE or_____%rdi,%rax 4809f8
DEFINE pop____%rax 58
DEFINE pop____%rbp 5d
DEFINE pop____%rdi 5f
DEFINE pop____%rdx 5a
DEFINE push___$i32 68
DEFINE push___%rax 50
DEFINE push___%rbp 55
DEFINE push___%rdi 57
DEFINE push___%rdx 52
DEFINE ret c3
DEFINE sahf 9e
DEFINE seta___%al 0f97c0
DEFINE seta___%dil 400f97c7
DEFINE setae__%al 0f93c0
DEFINE setae__%dil 400f93c7
DEFINE setb___%al 0f92c0
DEFINE setb___%dil 400f92c7
DEFINE setbe__%al 0f96c0
DEFINE setbe__%dil 400f96c7
DEFINE sete___%al 0f94c0
DEFINE sete___%dil 400f94c7
DEFINE setg___%al 0f9fc0
DEFINE setg___%dil 400f9fc7
DEFINE setge__%al 0f9dc0
DEFINE setge__%dil 400f9dc7
DEFINE setl___%al 0f9cc0
DEFINE setle__%al 0f9ec0
DEFINE setle__%dil 400f9ec7
DEFINE setne__%al 0f95c0
DEFINE shl____$i8,%rax 48c1e0
DEFINE shl____$i8,%rdi 48c1e7
DEFINE shl____%cl,%rax 48d3e0
DEFINE shl____%cl,%rdi 48d3e7
DEFINE shr____%cl,%rax 48d3e8
DEFINE sub____$i32,%rbp 4881ed
DEFINE sub____$i32,%rsp 4881ec
DEFINE sub____%rdi,%rax 4829f8
DEFINE syscall 0f05
DEFINE test___%al,%al 84c0
DEFINE test___%rax,%rax 4885c0
DEFINE test___%rdi,%rdi 4885ff
DEFINE xchg___%rax,%rdi 4897
DEFINE xchg___%rax,(%rsp) 48870424
DEFINE xchg___%rdi,(%rsp) 48873c24
DEFINE xor____$i8,%ah 80f4
DEFINE xor____%rax,%rax 4831c0
DEFINE xor____%rdi,%rax 4831f8
DEFINE xor____%rdx,%rdx 4831d2
# Enough for all of Mes + Mes C Libray when using all registers, i.e.,
# non-reduced instruction set
#DEFINE add____$i32,%rdx 4881c2
#DEFINE add____$i32,%rsi 4881c6
#DEFINE add____$i8,%rcx 4883c1
#DEFINE add____$i8,%rdx 4883c2
#DEFINE add____$i8,%rsi 4883c6
#DEFINE add____$i8,(%rsi) 488306
#DEFINE add____%rdx,%rdx 4801d2
#DEFINE add____%rdx,%rsi 4801d6
#DEFINE add____%rsi,%rdi 4801f7
#DEFINE add____%rsi,%rsi 4801f6
#DEFINE addl___$i32,(%rsi) 8106
#DEFINE addl___$i8,(%rsi) 8306
#DEFINE and____$i32,%rsi 4881e6
#DEFINE idiv___%rcx 48f7f9
#DEFINE idiv___%rsi 48f7fe
#DEFINE mov____$i32,%r8 49c7c0
#DEFINE mov____$i32,%r9 49c7c1
#DEFINE mov____$i32,%rcx 48c7c1
#DEFINE mov____$i32,%rdx 48c7c2
#DEFINE mov____$i32,%rsi 48c7c6
#DEFINE mov____%dil,(%rsi) 40883e
#DEFINE mov____%edi,(%rsi) 893e
#DEFINE mov____%r8,%r8 4d89c0
#DEFINE mov____%r8,0x8(%rbp) 4c8945
#DEFINE mov____%r9,%r9 4d89c9
#DEFINE mov____%r9,%rdi 4c89cf
#DEFINE mov____%r9,0x8(%rbp) 4c894d
#DEFINE mov____%rax,%rbx 4889c3
#DEFINE mov____%rax,%rcx 4889c1
#DEFINE mov____%rax,%rdx 4889c2
#DEFINE mov____%rax,%rsi 4889c6
#DEFINE mov____%rbp,%rcx 4889e9
#DEFINE mov____%rbp,%rdx 4889ea
#DEFINE mov____%rbp,%rsi 4889ee
#DEFINE mov____%rcx,%rcx 4889c9
#DEFINE mov____%rcx,%rdi 4889cf
#DEFINE mov____%rcx,%rdx 4889ca
#DEFINE mov____%rcx,%rsi 4889ce
#DEFINE mov____%rcx,0x8(%rbp) 48894d
#DEFINE mov____%rdi,%rdx 4889fa
#DEFINE mov____%rdi,%rsi 4889fe
#DEFINE mov____%rdx,%rcx 4889d1
#DEFINE mov____%rdx,%rdx 4889d2
#DEFINE mov____%rdx,%rsi 4889d6
#DEFINE mov____%rdx,0x8(%rbp) 488955
#DEFINE mov____%rsi,%rax 4889f0
#DEFINE mov____%rsi,%rcx 4889f1
#DEFINE mov____%rsi,%rdi 4889f7
#DEFINE mov____%rsi,%rdx 4889f2
#DEFINE mov____%rsi,%rsi 4889f6
#DEFINE mov____%rsi,0x32 48893425
#DEFINE mov____%rsi,0x8(%rbp) 488975
#DEFINE mov____%rsi,0x8(%rdi) 488977
#DEFINE mov____(%rdx),%edx 8b12
#DEFINE mov____(%rdx),%rdx 488b12
#DEFINE mov____(%rsi),%rsi 488b36
#DEFINE mov____0x32(%rbp),%rcx 488b8d
#DEFINE mov____0x32(%rbp),%rdx 488b95
#DEFINE mov____0x32(%rbp),%rsi 488bb5
#DEFINE mov____0x32,%rcx 488b0c25
#DEFINE mov____0x32,%rdx 488b1425
#DEFINE mov____0x32,%rsi 488b3425
#DEFINE mov____0x8(%rax),%rsi 488b70
#DEFINE mov____0x8(%rdi),%rbx 488b5f
#DEFINE movsbq_%cl,%rcx 480fbec9
#DEFINE movsbq_%dl,%rdx 480fbed2
#DEFINE movsbq_%sil,%rsi 480fbef6
#DEFINE movslq_%ecx,%rcx 4863c9
#DEFINE movslq_%edx,%rdx 4863d2
#DEFINE movslq_%esi,%rsi 4863f6
#DEFINE movswq_%si,%rsi 480fbff6
#DEFINE movzbq_%dl,%rdx 480fb6d2
#DEFINE movzbq_%sil,%rsi 480fb6f6
#DEFINE movzbq_(%rsi),%rsi 480fb636
#DEFINE movzlq_(%rdx),%rdx 8b12
#DEFINE movzlq_(%rsi),%rsi 8b36
#DEFINE movzwq_(%rsi),%rsi 480fb736
#DEFINE mul____%rbx 48f7e3
#DEFINE mul____%rcx 48f7e1
#DEFINE mul____%rdx 48f7e2
#DEFINE mul____%rsi 48f7e6
#DEFINE or_____%rdx,%rsi 4809d6
#DEFINE or_____%rsi,%rdi 4809f7
#DEFINE pop____%rcx 59
#DEFINE pop____%rsi 5e
#DEFINE push___%rcx 51
#DEFINE push___%rsi 56
#DEFINE shl____$i8,%rsi 48c1e6
#DEFINE shl____%cl,%rsi 48d3e6
#DEFINE sub____$i32,%rsi 4881ee
#DEFINE sub____%rcx,%rdx 4829ca
#DEFINE sub____%rdx,%rsi 4829d6
#DEFINE sub____%rsi,%rdi 4829f7
#DEFINE test___%rdx,%rdx 4885d2
#DEFINE xchg___%rdi,%rsi 4887fe
#DEFINE xchg___%rdx,%rcx 4887d1
#DEFINE xchg___%rsi,%rdx 4887f2
DEFINE SYS_write 01000000
DEFINE SYS_exit 3c000000

View file

@ -20,4 +20,5 @@
(mes-use-module (mescc as))
(mes-use-module (mescc info))
(mes-use-module (mescc x86_64 info))
(include-from-path "mescc/x86_64/as.scm")

View file

@ -23,4 +23,3 @@
;;; Code:
(include-from-path "nyacc/version.scm")
(display "nyacc version\n")

View file

@ -69,6 +69,14 @@
(if hex? (string-append "!0x" (dec->hex o))
(string-append "!" (number->string o))))
(define (hex2:immediate2 o)
(if hex? (string-append "@0x" (dec->hex o))
(string-append "@" (number->string o))))
(define (hex2:immediate4 o)
(if hex? (string-append "%0x" (dec->hex o))
(string-append "%" (number->string o))))
(define* (display-join o #:optional (sep ""))
(let loop ((o o))
(when (pair? o)
@ -87,7 +95,8 @@
(let ((index (list-index (lambda (s) (equal? s o)) strings)))
(if index
(string-append "_string_" file-name "_" (number->string index))
(error "no such string:" o))))
(if (equal? o "%0") o ; FIXME: 64b
(error "no such string:" o)))))
(define (text->M1 o)
(cond
((char? o) (text->M1 (char->integer o)))
@ -119,6 +128,8 @@
((#:offset1 ,offset1) (hex2:offset1 offset1))
((#:immediate ,immediate) (hex2:immediate immediate))
((#:immediate1 ,immediate1) (hex2:immediate1 immediate1))
((#:immediate2 ,immediate2) (hex2:immediate2 immediate2))
((#:immediate4 ,immediate4) (hex2:immediate4 immediate4))
(_ (error "text->M1 no match o" o))))
((pair? o) (string-join (map text->M1 o)))))
(define (write-function o)
@ -147,6 +158,7 @@
(string? (not (equal? string-label "_string_#f"))))
(cond ((and (pair? o) (global? (cdr o))) (string-append "&" (global->string o)))
((and (not string?) (not function?)) (stderr "warning: unresolved label: ~s\n" label))
((equal? string-label "%0") o) ;; FIXME: 64b
(else (string-append "&" label))))))
(define (display-align size)
(let ((alignment (- 4 (modulo size 4))))

View file

@ -25,7 +25,17 @@
dec->hex
int->bv8
int->bv16
int->bv32))
int->bv32
int->bv64
get-r
get-r0
get-r1
get-r-1))
(define (int->bv64 value)
(let ((bv (make-bytevector 8)))
(bytevector-u64-native-set! bv 0 value)
bv))
(define (int->bv32 value)
(let ((bv (make-bytevector 4)))
@ -48,5 +58,20 @@
(else (format #f "~s" o))))
(define (as info instruction . rest)
(if (pair? instruction)
(append-map (lambda (o) (apply as (cons* info o rest))) instruction)
(let ((proc (assoc-ref (.instructions info) instruction)))
(apply proc info rest)))
(if (not proc) (error "no such instruction" instruction)
(apply proc info rest)))))
(define (get-r info)
(car (if (pair? (.allocated info)) (.allocated info) (.registers info))))
(define (get-r0 info)
(cadr (.allocated info)))
(define (get-r1 info)
(car (.allocated info)))
(define (get-r-1 info)
(caddr (.allocated info)))

View file

@ -22,12 +22,28 @@
(define-module (mescc bytevectors)
#:use-module (mes guile)
#:export (bytevector-u32-native-set!
#:export (bytevector-u64-native-set!
bytevector-u32-native-set!
bytevector-u16-native-set!
bytevector-u8-set!
make-bytevector))
;; rnrs compatibility
(define (bytevector-u64-native-set! bv index value)
(when (not (= 0 index)) (error "bytevector-u64-native-set! index not zero: " index " value: " value))
(let ((x (list
(modulo value #x100)
(modulo (ash value -8) #x100)
(modulo (ash value -16) #x100)
(modulo (ash value -24) #x100)
(modulo (ash value -32) #x100)
(modulo (ash value -40) #x100)
(modulo (ash value -48) #x100)
(modulo (ash value -56) #x100))))
(set-car! bv (car x))
(set-cdr! bv (cdr x))
x))
(define (bytevector-u32-native-set! bv index value)
(when (not (= 0 index)) (error "bytevector-u32-native-set! index not zero: " index " value: " value))
(let ((x (list

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -30,38 +30,31 @@
(define (x86-info)
(make <info> #:types i386:type-alist #:registers i386:registers #:instructions i386:instructions))
;; FIXME: use abstract, unlimited R0...RN and make concrete in second pass?
(define i386:registers '("eax" "ebx" "ecx" "edx" "esi"))
(define i386:registers '("eax" "ebx" "ecx" "edx" "esi" "edi"))
(define i386:type-alist
`(("char" . ,(make-type 'signed 1 #f))
("short" . ,(make-type 'signed 2 #f))
("int" . ,(make-type 'signed 4 #f))
("long" . ,(make-type 'signed 4 #f))
("default" . ,(make-type 'signed 4 #f))
;;("long long" . ,(make-type 'signed 8 #f))
;;("long long int" . ,(make-type 'signed 8 #f))
("long long" . ,(make-type 'signed 4 #f)) ;; FIXME
("*" . ,(make-type 'unsigned 4 #f))
("long long" . ,(make-type 'signed 4 #f))
("long long int" . ,(make-type 'signed 4 #f))
("void" . ,(make-type 'void 1 #f))
;; FIXME sign
("unsigned char" . ,(make-type 'unsigned 1 #f))
("unsigned short" . ,(make-type 'unsigned 2 #f))
("unsigned" . ,(make-type 'unsigned 4 #f))
("unsigned int" . ,(make-type 'unsigned 4 #f))
("unsigned long" . ,(make-type 'unsigned 4 #f))
;; ("unsigned long long" . ,(make-type 'builtin 8 #f))
;; ("unsigned long long int" . ,(make-type 'builtin 8 #f))
("unsigned long long" . ,(make-type 'unsigned 4 #f)) ;; FIXME
("unsigned long long" . ,(make-type 'unsigned 4 #f))
("unsigned long long int" . ,(make-type 'unsigned 4 #f))
("float" . ,(make-type 'float 4 #f))
("double" . ,(make-type 'float 8 #f))
("long double" . ,(make-type 'float 16 #f))
("double" . ,(make-type 'float 4 #f))
("long double" . ,(make-type 'float 4 #f))
;;
("short int" . ,(make-type 'signed 2 #f))
("unsigned short int" . ,(make-type 'unsigned 2 #f))
("long int" . ,(make-type 'signed 4 #f))

View file

@ -45,6 +45,7 @@
.break
.continue
.allocated
.pushed
.registers
.instructions
@ -118,7 +119,7 @@
structured-type?))
(define-immutable-record-type <info>
(make-<info> types constants functions globals locals statics function text post break continue allocated registers instructions)
(make-<info> types constants functions globals locals statics function text post break continue allocated pushed registers instructions)
info?
(types .types)
(constants .constants)
@ -132,12 +133,13 @@
(break .break)
(continue .continue)
(allocated .allocated)
(pushed .pushed)
(registers .registers)
(instructions .instructions))
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (statics '()) (function #f) (text '()) (post '()) (break '()) (continue '()) (allocated '()) (registers '()) (instructions '()))
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (statics '()) (function #f) (text '()) (post '()) (break '()) (continue '()) (allocated '()) (pushed 0) (registers '()) (instructions '()))
(cond ((eq? o <info>)
(make-<info> types constants functions globals locals statics function text post break continue allocated registers instructions))))
(make-<info> types constants functions globals locals statics function text post break continue allocated pushed registers instructions))))
(define (clone o . rest)
(cond ((info? o)
@ -153,6 +155,7 @@
(break (.break o))
(continue (.continue o))
(allocated (.allocated o))
(pushed (.pushed o))
(registers (.registers o))
(instructions (.instructions o)))
(let-keywords rest
@ -169,9 +172,10 @@
(break break)
(continue continue)
(allocated allocated)
(pushed pushed)
(registers registers)
(instructions instructions))
(make <info> #:types types #:constants constants #:functions functions #:globals globals #:locals locals #:statics statics #:function function #:text text #:post post #:break break #:continue continue #:allocated allocated #:registers registers #:instructions instructions))))))
(make <info> #:types types #:constants constants #:functions functions #:globals globals #:locals locals #:statics statics #:function function #:text text #:post post #:break break #:continue continue #:allocated allocated #:pushed pushed #:registers registers #:instructions instructions))))))
;; ("int" . ,(make-type 'builtin 4 #f 0 #f))
;; (make-type 'enum 4 0 fields)

View file

@ -31,13 +31,16 @@
#:use-module (mes guile)
#:export (c99-input->ast))
(format (current-error-port) "*nyacc-version*=~a\n" *nyacc-version*)
(when (getenv "MESC_DEBUG")
(format (current-error-port) "*nyacc-version*=~a\n" *nyacc-version*))
;; list of which rules you want progress reported
(define need-progress
(assoc-ref
(or (assoc-ref
'(("0.85.3" (1 2 3))
("0.86.0" (1 2 3)))
*nyacc-version*))
*nyacc-version*)
'(1 2 3)))
(define (progress o)
(when (and o (getenv "NYACC_DEBUG"))

View file

@ -26,18 +26,46 @@
#:use-module (mes guile)
#:use-module (mescc as)
#:use-module (mescc info)
#:use-module (mescc x86_64 info)
#:export (
x86_64:instructions
))
(define (x86_64:function-preamble . rest)
'(("push___%rbp")
(define (r->e o)
(string-append "e" (string-drop o 1)))
(define (r->x o)
(string-drop o 1))
(define (r->l o)
(assoc-ref
'(("rax" . "al")
("rdi" . "dil")
("rsi" . "sil")
("rdx" . "dl")
("rcx" . "cl")
("r8" . "r8b")
("r9" . "r9b"))
o))
;; AMD
(define (x86_64:function-preamble info . rest)
(format (current-error-port) "rest=~s\n" rest)
`(("push___%rbp")
("mov____%rsp,%rbp")
;;("mov____%rdi,0x8(%rbp)" "!-0x08")
;;("mov____%rsi,0x8(%rbp)" "!-0x10")
;;("mov____%rdx,0x8(%rbp)" "!-0x18")
;;("mov____%rcx,0x8(%rbp)" "!-0x20")
))
("sub____$i32,%rbp" "%0x80")
,@(list-head
'(("mov____%rdi,0x8(%rbp)" "!0x10")
("mov____%rsi,0x8(%rbp)" "!0x18")
("mov____%rdx,0x8(%rbp)" "!0x20")
("mov____%rcx,0x8(%rbp)" "!0x28")
("mov____%r8,0x8(%rbp)" "!0x30")
("mov____%r9,0x8(%rbp)" "!0x38"))
(length (car rest)))))
;; traditional
(define (x86_64:function-preamble info . rest)
(format (current-error-port) "rest=~s\n" rest)
`(("push___%rbp")
("mov____%rsp,%rbp")))
(define (x86_64:function-locals . rest)
`(
@ -45,47 +73,630 @@
("sub____$i32,%rsp" (#:immediate ,(+ (* 4 1025) (* 20 8))))
)) ; 4*1024 buf, 20 local vars
(define (x86_64:r0->local info n)
(or n (error "invalid value: x86_64:r0->local: " n))
(let ((r0 (car (if (pair? (.allocated info)) (.allocated info) (.registers info))))
(define (x86_64:r->local info n)
(let ((r (get-r info))
(n (- 0 (* 8 n))))
`(,(if (< (abs n) #x80) `(,(string-append "mov____%" r0 ",0x8(%rbp)") (#:immediate1 ,n))
`(,(string-append "mov____%" r0 ",0x32(%rbp)") (#:immediate ,n))))))
`(,(if (< (abs n) #x80) `(,(string-append "mov____%" r ",0x8(%rbp)") (#:immediate1 ,n))
`(,(string-append "mov____%" r ",0x32(%rbp)") (#:immediate ,n))))))
(define (x86_64:value->r0 info v)
(or v (error "invalid value: x86_64:value->r0: " v))
(let ((r0 (car (if (pair? (.allocated info)) (.allocated info) (.registers info)))))
`((,(string-append "mov____$i32,%" r0) (#:immediate ,v)))))
(define (x86_64:value->r info v)
(or v (error "invalid value: x86_64:value->r: " v))
(let ((r (get-r info)))
`((,(string-append "mov____$i32,%" r) (#:immediate ,v)))))
;; AMD
(define (x86_64:ret . rest)
'(("add____$i32,%rbp" "%0x80")
("mov____%rbp,%rsp")
("pop____%rbp")
("ret")))
;; traditional
(define (x86_64:ret . rest)
'(("mov____%rbp,%rsp")
("pop____%rbp")
("ret")))
(define (x86_64:r0-zero? info)
(let ((r0 (car (if (pair? (.allocated info)) (.allocated info) (.registers info)))))
`((,(string-append "test___%" r0 "," "%" r0)))))
(define (x86_64:r-zero? info)
(let ((r (car (if (pair? (.allocated info)) (.allocated info) (.registers info)))))
`((,(string-append "test___%" r "," "%" r)))))
(define (x86_64:local->r0 info n)
(or n (error "invalid value: x86_64:local->r0: " n))
(let ((r0 (car (if (pair? (.allocated info)) (.allocated info) (.registers info))))
(define (x86_64:local->r info n)
(let ((r (car (if (pair? (.allocated info)) (.allocated info) (.registers info))))
(n (- 0 (* 8 n))))
`(,(if (< (abs n) #x80) `(,(string-append "mov____0x8(%rbp),%" r0) (#:immediate1 ,n))
`(,(string-append "mov____0x32(%rbp),%" r0) (#:immediate ,n))))))
`(,(if (< (abs n) #x80) `(,(string-append "mov____0x8(%rbp),%" r) (#:immediate1 ,n))
`(,(string-append "mov____0x32(%rbp),%" r) (#:immediate ,n))))))
(define (x86_64:call-label info label n)
`((call32 (#:offset ,label))
;;("add____$i8,%esp" (#:immediate1 ,(* n 4)))
("add____$i8,%rsp" (#:immediate1 ,(* n 8))) ;; NOT AMD
))
(define x86_64:calling-convention-registers '("rax" "rdi" "rsi" "rdx" "rcx" "r8" "r9"))
;; AMD
(define (x86_64:r->arg info i)
(let ((r (get-r info))
(r1 (list-ref x86_64:calling-convention-registers (1+ i))))
`((,(string-append "mov____%" r ",%" r1))))) ; debug fail-safe check
(define (x86_64:label->arg info label i)
(let ((r0 (list-ref x86_64:registers (1+ i))))
`((,(string-append "mov____$i32,%" r0) (#:address ,label))))) ;; FIXME: 64 bits
;; traditional
(define (x86_64:r->arg info i)
(let ((r (get-r info)))
`((,(string-append "push___%" r)))))
(define (x86_64:label->arg info label i)
`(("push___$i32" (#:address ,label))))
(define (x86_64:r0+r1 info)
(let ((r1 (get-r1 info))
(r0 (get-r0 info)))
`((,(string-append "add____%" r1 ",%" r0)))))
(define (x86_64:r-negate info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "sete___%" l))
(,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:r0-r1 info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "sub____%" r1 ",%" r0)))))
(define (x86_64:zf->r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "sete___%" l))
(,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:xor-zf info)
'(("lahf")
("xor____$i8,%ah" (#:immediate1 #x40))
("sahf")))
(define (x86_64:r->local+n info id n)
(let ((n (+ (- 0 (* 8 id)) n))
(r (get-r info)))
`(,(if (< (abs n) #x80) `(,(string-append "mov____%" r ",0x8(%rbp)") (#:immediate1 ,n))
`(,(string-append "mov____%" r ",0x32(%rbp)") (#:immediate ,n))))))
(define (x86_64:r-mem-add info v)
(let ((r (get-r info)))
`(,(if (< (abs v) #x80) `(,(string-append "add____$i8,(%" r ")") (#:immediate1 ,v))
`(,(string-append "add____$i32,(%" r ")") (#:immediate ,v))))))
(define (x86_64:r-byte-mem-add info v)
(let ((r (get-r info)))
`((,(string-append "addb___$i8,(%" r ")") (#:immediate1 ,v)))))
(define (x86_64:r-word-mem-add info v)
(let ((r (get-r info)))
`((,(string-append "addw___$i8,(%" r ")") (#:immediate2 ,v)))))
(define (x86_64:local-ptr->r info n)
(let ((r (get-r info)))
(let ((n (- 0 (* 8 n))))
`((,(string-append "mov____%rbp,%" r))
,(if (< (abs n) #x80) `(,(string-append "add____$i8,%" r) (#:immediate1 ,n))
`(,(string-append "add____$i32,%" r) (#:immediate ,n)))))))
(define (x86_64:label->r info label)
(let ((r (get-r info)))
`((,(string-append "mov____$i32,%" r) (#:address ,label)))))
(define (x86_64:r0->r1 info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "mov____%" r0 ",%" r1)))))
(define (x86_64:byte-mem->r info)
(let ((r (get-r info)))
`((,(string-append "movzbq_(%" r "),%" r)))))
(define (x86_64:byte-r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:byte-signed-r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "movsbq_%" l ",%" r)))))
(define (x86_64:word-r info)
(let* ((r (get-r info))
(x (r->x r)))
`((,(string-append "movzwq_%" x ",%" r)))))
(define (x86_64:word-signed-r info)
(let* ((r (get-r info))
(x (r->x r)))
`((,(string-append "movswq_%" x ",%" r)))))
(define (x86_64:long-r info)
(let* ((r (get-r info))
(e (r->e r)))
`((,(string-append "movzlq_%" e ",%" r)))))
(define (x86_64:long-signed-r info)
(let* ((r (get-r info))
(e (r->e r)))
`((,(string-append "movslq_%" e ",%" r)))))
(define (x86_64:jump info label)
`(("jmp32 " (#:offset ,label))))
(define (x86_64:jump-nz info label)
`(("jne32 " (#:offset ,label))))
(define (x86_64:jump-z info label)
`(("je32 " (#:offset ,label))))
(define (x86_64:jump-byte-z info label)
`(("test___%al,%al")
("je32 " (#:offset ,label))))
;; signed
(define (x86_64:jump-g info label)
`(("jg32 " (#:offset ,label))))
(define (x86_64:jump-ge info label)
`(("jge32 " (#:offset ,label))))
(define (x86_64:jump-l info label)
`(("jl32 " (#:offset ,label))))
(define (x86_64:jump-le info label)
`(("jle32 " (#:offset ,label))))
;; unsigned
(define (x86_64:jump-a info label)
`(("ja32 " (#:offset ,label))))
(define (x86_64:jump-ae info label)
`(("jae32 " (#:offset ,label))))
(define (x86_64:jump-b info label)
`(("jb32 " (#:offset ,label))))
(define (x86_64:jump-be info label)
`(("jbe32 " (#:offset ,label))))
(define (x86_64:byte-r0->r1-mem info)
(let* ((r0 (get-r0 info))
(r1 (get-r1 info))
(l0 (r->l r0)))
`((,(string-append "mov____%" l0 ",(%" r1 ")")))))
(define (x86_64:label-mem->r info label)
(let ((r (get-r info)))
`((,(string-append "mov____0x32,%" r) (#:address ,label)))))
(define (x86_64:word-mem->r info)
(let ((r (get-r info)))
`((,(string-append "movzwq_(%" r "),%" r)))))
(define (x86_64:long-mem->r info)
(let ((r (get-r info)))
`((,(string-append "movzlq_(%" r "),%" r)))))
(define (x86_64:mem->r info)
(let ((r (get-r info)))
`((,(string-append "mov____(%" r "),%" r)))))
(define (x86_64:local-add info n v)
(let ((n (- 0 (* 8 n))))
`(,(if (and (< (abs n) #x80)
(< (abs v) #x80)) `("add____$i8,0x8(%rbp)" (#:immediate1 ,n) (#:immediate1 ,v))
`("add____$i32,0x32(%rbp)" (#:immediate ,n) (#:immediate ,v))))))
(define (x86_64:label-mem-add info label v)
`(,(if (< (abs v) #x80) `("add____$i8,0x32" (#:address ,label) (#:immediate1 ,v))
`("add____$i32,0x32" (#:address ,label) (#:immediate ,v)))))
(define (x86_64:nop info)
'(("nop")))
(define (x86_64:swap-r0-r1 info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "xchg___%" r0 ",%" r1)))))
;; signed
(define (x86_64:g?->r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "setg___%" l))
(,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:ge?->r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "setge__%" l))
(,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:l?->r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "setl___%" l))
(,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:le?->r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "setle__%" l))
(,(string-append "movzbq_%" l ",%" r)))))
;; unsigned
(define (x86_64:a?->r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "seta___%" l))
(,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:ae?->r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "setae__%" l))
(,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:b?->r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "setb___%" l))
(,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:be?->r info)
(let* ((r (get-r info))
(l (r->l r)))
`((,(string-append "setbe__%" l))
(,(string-append "movzbq_%" l ",%" r)))))
(define (x86_64:test-r info)
(let ((r (get-r info)))
`((,(string-append "test___%" r ",%" r)))))
(define (x86_64:r->label info label)
(let ((r (get-r info)))
`((,(string-append "mov____%" r ",0x32") (#:address ,label))))) ;; FIXME: 64 bits
(define (x86_64:call-r info n)
(let ((r (get-r info)))
`((,(string-append "call___*%" r))
("add____$i8,%rsp" (#:immediate1 ,(* n 8)))))) ;; NOT AMD
(define (x86_64:r0*r1 info)
(let ((allocated (.allocated info))
(r0 (get-r0 info))
(r1 (get-r1 info)))
(if (not (member "rdx" allocated))
`(,@(if (equal? r0 "rax") '()
`(("push___%rax"
,(string-append "mov____%" r0 ",%rax"))))
(,(string-append "mul____%" r1))
,@(if (equal? r0 "rax") '()
`((,(string-append "mov____%rax,%" r0)
"pop____%rax"))))
`(("push___%rax")
("push___%rdi")
("push___%rdx")
(,(string-append "mov____%" r1 ",%rdi"))
(,(string-append "mov____%" r0 ",%rax"))
(,(string-append "mul____%" r1))
("pop____%rdx")
("pop____%rdi")
(,(string-append "mov____%rax,%" r0))
("pop____%rax")))))
(define (x86_64:r0<<r1 info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "mov____%" r1 ",%rcx"))
(,(string-append "shl____%cl,%" r0)))))
(define (x86_64:r0>>r1 info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "mov____%" r1 ",%rcx"))
(,(string-append "shr____%cl,%" r0)))))
(define (x86_64:r0-and-r1 info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "and____%" r1 ",%" r0)))))
(define (x86_64:r0/r1 info)
(let ((allocated (.allocated info))
(r0 (get-r0 info))
(r1 (get-r1 info)))
(if (not (member "rdx" allocated))
`(,@(if (equal? r0 "rax") '()
`(("push___%rax")
(,(string-append "mov____%" r0 ",%rax"))))
("xor____%rdx,%rdx")
(,(string-append "idiv___%" r1))
,@(if (equal? r0 "rax") '()
`((,(string-append "mov____%rax,%" r0))
("pop____%rax"))))
`(("push___%rax")
("push___%rdi")
("push___%rdx")
(,(string-append "mov____%" r1 ",%rdi"))
(,(string-append "mov____%" r0 ",%rax"))
("xor____%rdx,%rdx")
(,(string-append "idiv___%rdi"))
("pop____%rdx")
("pop____%rdi")
(,(string-append "mov____%rax,%" r0))
("pop____%rax")))))
(define (x86_64:r0%r1 info)
(let ((allocated (.allocated info))
(r0 (get-r0 info))
(r1 (get-r1 info)))
(if (not (member "rdx" allocated))
`(,@(if (equal? r0 "rax") '()
`(("push___%rax")
(,(string-append "mov____%" r0 ",%rax"))))
("xor____%rdx,%rdx")
(,(string-append "idiv___%" r1))
(,(string-append "mov____%rdx,%" r0)))
`(("push___%rax")
("push___%rdi")
("push___%rdx")
(,(string-append "mov____%" r1 ",%rdi"))
(,(string-append "mov____%" r0 ",%rax"))
("xor____%rdx,%rdx")
(,(string-append "idiv___%rdi"))
("pop____%rdx")
("pop____%rdi")
(,(string-append "mov____%rdx,%" r0))
("pop____%rax")))))
(define (x86_64:r+value info v)
(let ((r (get-r info)))
`(,(if (< (abs v) #x80) `(,(string-append "add____$i8,%" r) (#:immediate1 ,v))
`(,(string-append "add____$i32,%" r) (#:immediate ,v))))))
(define (x86_64:r0->r1-mem info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "mov____%" r0 ",(%" r1 ")")))))
(define (x86_64:byte-r0->r1-mem info)
(let* ((r0 (get-r0 info))
(r1 (get-r1 info))
(l0 (r->l r0)))
`((,(string-append "mov____%" l0 ",(%" r1 ")")))))
(define (x86_64:word-r0->r1-mem info)
(let* ((r0 (get-r0 info))
(r1 (get-r1 info))
(x0 (r->x r0)))
`((,(string-append "mov____%" x0 ",(%" r1 ")")))))
(define (x86_64:long-r0->r1-mem info)
(let* ((r0 (get-r0 info))
(r1 (get-r1 info))
(e0 (r->e r0)))
`((,(string-append "mov____%" e0 ",(%" r1 ")")))))
(define (x86_64:r-cmp-value info v)
(let ((r (get-r info)))
`(,(if (< (abs v) #x80) `(,(string-append "cmp____$i8,%" r) (#:immediate1 ,v))
`(,(string-append "cmp____$i32,%" r) (#:immediate ,v))))))
(define (x86_64:push-register info r)
`((,(string-append "push___%" r))))
(define (x86_64:pop-register info r)
`((,(string-append "pop____%" r))))
(define (x86_64:return->r info)
(let ((r (car (.allocated info))))
(if (equal? r "rax") '()
`((,(string-append "mov____%rax,%" r))))))
(define (x86_64:r0-or-r1 info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "or_____%" r1 ",%" r0)))))
(define (x86_64:shl-r info n)
(let ((r (get-r info)))
`((,(string-append "shl____$i8,%" r) (#:immediate1 ,n)))))
(define (x86_64:r+r info)
(let ((r (get-r info)))
`((,(string-append "add____%" r ",%" r)))))
(define (x86_64:not-r info)
(let ((r (get-r info)))
`((,(string-append "not____%" r)))))
(define (x86_64:r0-xor-r1 info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "xor____%" r1 ",%" r0)))))
(define (x86_64:r0-mem->r1-mem info)
(let* ((registers (.registers info))
(r0 (get-r0 info))
(r1 (get-r1 info))
(r2 (car registers)))
`((,(string-append "mov____(%" r0 "),%" r2))
(,(string-append "mov____%" r2 ",(%" r1 ")")))))
(define (x86_64:r0+value info v)
(let ((r0 (get-r0 info)))
`(,(if (< (abs v) #x80) `(,(string-append "add____$i8,%" r0) (#:immediate1 ,v))
`(,(string-append "add____$i32,%" r0) (#:immediate ,v))))))
(define (x86_64:value->r0 info v)
(let ((r0 (get-r0 info)))
`((,(string-append "mov____$i32,%" r0) (#:immediate ,v)))))
(define (x86_64:r-long-mem-add info v)
(let ((r (get-r info)))
`(,(if (< (abs v) #x80) `(,(string-append "addl___$i8,(%" r ")") (#:immediate1 ,v))
`(,(string-append "addl___$i32,(%" r ")") (#:immediate ,v))))))
(define (x86_64:byte-r->local+n info id n)
(let* ((n (+ (- 0 (* 8 id)) n))
(r (get-r info))
(l (r->l r) ))
`(,(if (< (abs n) #x80) `(,(string-append "mov____%" l ",0x8(%rbp)") (#:immediate1 ,n))
`(,(string-append "mov____%" l ",0x32(%rbp)") (#:immediate ,n))))))
(define (x86_64:word-r->local+n info id n)
(let* ((n (+ (- 0 (* 8 id)) n))
(r (get-r info))
(x (r->x r) ))
`(,(if (< (abs n) #x80) `(,(string-append "mov____%" x ",0x8(%rbp)") (#:immediate1 ,n))
`(,(string-append "mov____%" x ",0x32(%rbp)") (#:immediate ,n))))))
(define (x86_64:long-r->local+n info id n)
(let* ((n (+ (- 0 (* 8 id)) n))
(r (get-r info))
(e (r->e r)))
`(,(if (< (abs n) #x80) `(,(string-append "mov____%" e ",0x8(%rbp)") (#:immediate1 ,n))
`(,(string-append "mov____%" e ",0x32(%rbp)") (#:immediate ,n))))))
(define (x86_64:r-and info v)
(let ((r (get-r info)))
`((,(string-append "and____$i32,%" r) (#:immediate ,v)))))
(define (x86_64:push-r0 info)
(let ((r0 (get-r0 info)))
`((,(string-append "push___%" r0)))))
(define (x86_64:r1->r0 info)
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
`((,(string-append "mov____%" r1 ",%" r0)))))
(define (x86_64:pop-r0 info)
(let ((r0 (get-r0 info)))
`((,(string-append "pop____%" r0)))))
(define (x86_64:swap-r-stack info)
(let ((r (get-r info)))
`((,(string-append "xchg___%" r ",(%rsp)")))))
(define (x86_64:swap-r1-stack info)
(let ((r0 (get-r0 info)))
`((,(string-append "xchg___%" r0 ",(%rsp)")))))
(define (x86_64:r2->r0 info)
(let ((r0 (get-r0 info))
(allocated (.allocated info)))
(if (> (length allocated) 2)
(let ((r2 (cadddr allocated)))
`((,(string-append "mov____%" r2 ",%" r1))))
`((,(string-append "pop____%" r0))
(,(string-append "push___%" r0))))))
(define x86_64:instructions
`(
(r2->r0 . ,x86_64:r2->r0)
(a?->r . ,x86_64:a?->r)
(ae?->r . ,x86_64:ae?->r)
(b?->r . ,x86_64:b?->r)
(be?->r . ,x86_64:be?->r)
(byte-mem->r . ,x86_64:byte-mem->r)
(byte-r . ,x86_64:byte-r)
(byte-r->local+n . ,x86_64:byte-r->local+n)
(byte-r0->r1-mem . ,x86_64:byte-r0->r1-mem)
(byte-r0->r1-mem . ,x86_64:byte-r0->r1-mem)
(byte-signed-r . ,x86_64:byte-signed-r)
(call-label . ,x86_64:call-label)
(function-preamble . ,x86_64:function-preamble)
(call-r . ,x86_64:call-r)
(function-locals . ,x86_64:function-locals)
(local->r0 . ,x86_64:local->r0)
(r0->local . ,x86_64:r0->local)
(r0-zero? . ,x86_64:r0-zero?)
(function-preamble . ,x86_64:function-preamble)
(g?->r . ,x86_64:g?->r)
(ge?->r . ,x86_64:ge?->r)
(jump . ,x86_64:jump)
(jump-a . ,x86_64:jump-a)
(jump-ae . ,x86_64:jump-ae)
(jump-b . ,x86_64:jump-b)
(jump-be . ,x86_64:jump-be)
(jump-byte-z . ,x86_64:jump-byte-z)
(jump-g . , x86_64:jump-g)
(jump-ge . , x86_64:jump-ge)
(jump-l . ,x86_64:jump-l)
(jump-le . ,x86_64:jump-le)
(jump-nz . ,x86_64:jump-nz)
(jump-z . ,x86_64:jump-z)
(l?->r . ,x86_64:l?->r)
(label->arg . ,x86_64:label->arg)
(label->r . ,x86_64:label->r)
(label-mem->r . ,x86_64:label-mem->r)
(label-mem-add . ,x86_64:label-mem-add)
(le?->r . ,x86_64:le?->r)
(local->r . ,x86_64:local->r)
(local-add . ,x86_64:local-add)
(local-ptr->r . ,x86_64:local-ptr->r)
(long-mem->r . ,x86_64:long-mem->r)
(long-r . ,x86_64:long-r)
(long-r->local+n . ,x86_64:long-r->local+n)
(long-r0->r1-mem . ,x86_64:long-r0->r1-mem)
(long-signed-r . ,x86_64:long-signed-r)
(mem->r . ,x86_64:mem->r)
(nop . ,x86_64:nop)
(not-r . ,x86_64:not-r)
(pop-r0 . ,x86_64:pop-r0)
(pop-register . ,x86_64:pop-register)
(push-r0 . ,x86_64:push-r0)
(push-register . ,x86_64:push-register)
(quad-r0->r1-mem . ,x86_64:r0->r1-mem)
(r+r . ,x86_64:r+r)
(r+value . ,x86_64:r+value)
(r->arg . ,x86_64:r->arg)
(r->label . ,x86_64:r->label)
(r->local . ,x86_64:r->local)
(r->local+n . ,x86_64:r->local+n)
(r-and . ,x86_64:r-and)
(r-byte-mem-add . ,x86_64:r-byte-mem-add)
(r-cmp-value . ,x86_64:r-cmp-value)
(r-long-mem-add . ,x86_64:r-long-mem-add)
(r-mem-add . ,x86_64:r-mem-add)
(r-negate . ,x86_64:r-negate)
(r-word-mem-add . ,x86_64:r-word-mem-add)
(r-zero? . ,x86_64:r-zero?)
(r0%r1 . ,x86_64:r0%r1)
(r0*r1 . ,x86_64:r0*r1)
(r0+r1 . ,x86_64:r0+r1)
(r0+value . ,x86_64:r0+value)
(r0->r1 . ,x86_64:r0->r1)
(r0->r1-mem . ,x86_64:r0->r1-mem)
(r0-and-r1 . ,x86_64:r0-and-r1)
(r0-mem->r1-mem . ,x86_64:r0-mem->r1-mem)
(r0-or-r1 . ,x86_64:r0-or-r1)
(r0-r1 . ,x86_64:r0-r1)
(r0-xor-r1 . ,x86_64:r0-xor-r1)
(r0/r1 . ,x86_64:r0/r1)
(r0<<r1 . ,x86_64:r0<<r1)
(r0>>r1 . ,x86_64:r0>>r1)
(r1->r0 . ,x86_64:r1->r0)
(ret . ,x86_64:ret)
(return->r . ,x86_64:return->r)
(shl-r . ,x86_64:shl-r)
(swap-r-stack . ,x86_64:swap-r-stack)
(swap-r0-r1 . ,x86_64:swap-r0-r1)
(swap-r1-stack . ,x86_64:swap-r1-stack)
(test-r . ,x86_64:test-r)
(value->r . ,x86_64:value->r)
(value->r0 . ,x86_64:value->r0)
(word-mem->r . ,x86_64:word-mem->r)
(word-r . ,x86_64:word-r)
(word-r->local+n . ,x86_64:word-r->local+n)
(word-r0->r1-mem . ,x86_64:word-r0->r1-mem)
(word-signed-r . ,x86_64:word-signed-r)
(xor-zf . ,x86_64:xor-zf)
(zf->r . ,x86_64:zf->r)
))

View file

@ -25,12 +25,12 @@
(define-module (mescc x86_64 info)
#:use-module (mescc info)
#:use-module (mescc x86_64 as)
#:export (x86_64-info))
#:export (x86_64-info
x86_64:registers))
(define (x86_64-info)
(make <info> #:types x86_64:type-alist #:registers x86_64:registers #:instructions x86_64:instructions))
;; FIXME: use abstract, unlimited R0...RN and make concrete in second pass?
(define x86_64:registers '("rax" "rdi" "rsi" "rdx" "rcx" "r8" "r9"))
(define x86_64:type-alist
`(("char" . ,(make-type 'signed 1 #f))
@ -38,30 +38,23 @@
("int" . ,(make-type 'signed 4 #f))
("long" . ,(make-type 'signed 8 #f))
("default" . ,(make-type 'signed 4 #f))
;;("long long" . ,(make-type 'signed 8 #f))
;;("long long int" . ,(make-type 'signed 8 #f))
("long long" . ,(make-type 'signed 8 #f)) ;; FIXME
("*" . ,(make-type 'unsigned 8 #f))
("long long" . ,(make-type 'signed 8 #f))
("long long int" . ,(make-type 'signed 8 #f))
("void" . ,(make-type 'void 1 #f))
;; FIXME sign
("unsigned char" . ,(make-type 'unsigned 1 #f))
("unsigned short" . ,(make-type 'unsigned 2 #f))
("unsigned" . ,(make-type 'unsigned 4 #f))
("unsigned int" . ,(make-type 'unsigned 4 #f))
("unsigned long" . ,(make-type 'unsigned 8 #f))
;; ("unsigned long long" . ,(make-type 'builtin 8 #f))
;; ("unsigned long long int" . ,(make-type 'builtin 8 #f))
("unsigned long long" . ,(make-type 'unsigned 8 #f)) ;; FIXME
("unsigned long long" . ,(make-type 'unsigned 8 #f))
("unsigned long long int" . ,(make-type 'unsigned 8 #f))
("float" . ,(make-type 'float 4 #f))
("double" . ,(make-type 'float 8 #f))
("long double" . ,(make-type 'float 16 #f))
("long double" . ,(make-type 'float 8 #f))
;;
("short int" . ,(make-type 'signed 2 #f))
("unsigned short int" . ,(make-type 'unsigned 2 #f))
("long int" . ,(make-type 'signed 8 #f))

View file

@ -18,6 +18,7 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
//V=2 CC32=i686-unknown-linux-gnu-gcc build-aux/cc32-mes.sh scaffold/main
//V=2 CC64=gcc build-aux/cc64-mes.sh scaffold/main
int

View file

@ -0,0 +1,31 @@
/* -*-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/>.
*/
int
test ()
{
return 1;
}
int
main ()
{
return !test ();
}

View file

@ -0,0 +1,32 @@
/* -*-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/>.
*/
int
test (int a, int b)
{
return a + b;
}
int
main ()
{
int i = -2;
return test (i, 2);
}

View file

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -18,12 +18,14 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libmes-mini.h>
int
test (char const *s)
{
return 0;
}
int
main ()
{
puts ("\n");
puts ("mes");
return 0;
return test ("hello\n");
}

View file

@ -0,0 +1,34 @@
/* -*-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/>.
*/
int
test (int a)
{
return 1 - a;
}
int (*f) (int);
int
main ()
{
f = &test;
return (*f) (1);
}

View file

@ -0,0 +1,33 @@
/* -*-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/>.
*/
void
test ()
{
return;
}
int
main ()
{
test ();
return 0;
}

View file

@ -0,0 +1,32 @@
/* -*-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/>.
*/
int foo;
int
main ()
{
if (foo)
return 1;
foo = 42;
if (foo != 42)
return 2;
return 0;
}

View file

@ -0,0 +1,29 @@
/* -*-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/>.
*/
int
main ()
{
int a;
int b;
a = 1;
b = -a;
return a + b;
}

View file

@ -21,6 +21,7 @@
int
main ()
{
if (1) return 0;
if (1)
return 0;
return 1;
}

View file

@ -21,8 +21,8 @@
int
main ()
{
int t = 1;
if (t)
int f = 0;
if (!f)
return 0;
return 1;
}

View file

@ -22,6 +22,7 @@ int
main ()
{
int t = 1;
if (t) return 0;
if (t)
return 0;
return 1;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
char c = 'a';
if (c >= 'A' && c <= 'Z' || c >= '0' && c <= '9')
return 1;
if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'a')
return 0;
return 2;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
char c = 'a';
if (c >= 'A' && c <= 'Z')
return 1;
if (c >= 'a' && c <= 'z')
return 0;
return 2;
}

View file

@ -0,0 +1,38 @@
/* -*-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/>.
*/
#include <libmes.h>
int
test (int i)
{
return i;
}
int
main ()
{
int a;
a = 0 == 0;
if (a != 1)
return 1;
return 0;
}

View file

@ -0,0 +1,38 @@
/* -*-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/>.
*/
#include <libmes.h>
int
test (int i)
{
return i;
}
int
main ()
{
int a;
a = test (0 == 0);
if (a != 1)
return 1;
return 0;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
int r = 0;
if (r > 0)
return 1;
if (r >= -1)
return 0;
return 2;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
int r = 0;
if (r > 0)
return 1;
if (r > -1)
return 0;
return 2;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
int r = 0;
if (r <= -1)
return 1;
if (r <= 0)
return 0;
return 2;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
int r = 0;
if (r < -1)
return 1;
if (r < 1)
return 0;
return 2;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
char c = 'a';
if (c == ' ' || c == '\n')
return 1;
if (c == 'A' || c == 'a')
return 0;
return 2;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
unsigned r = -2;
if (r <= -1)
return 0;
if (r <= -3)
return 1;
return 2;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
unsigned r = -2;
if (r > -1)
return 1;
if (r > 0)
return 0;
return 2;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
unsigned r = -2;
if (r <= -3)
return 1;
if (r <= -1)
return 0;
return 2;
}

View file

@ -0,0 +1,30 @@
/* -*-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/>.
*/
int
main ()
{
unsigned r = -2;
if (r < 0)
return 1;
if (r < -1)
return 0;
return 2;
}

View file

@ -0,0 +1,32 @@
/* -*-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/>.
*/
#include <libmes.h>
int
main ()
{
int c = 0;
{int c = 3;}
if (c)
return 1;
return 0;
}

View file

@ -0,0 +1,30 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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/>.
*/
int
main ()
{
char *s = "mes";
if (!s[0])
return 1;
if (s[1] != 'e')
return 2;
return 0;
}

View file

@ -27,10 +27,10 @@ main ()
int f;
int v = 3;
if (!s[f])
return 1;
return 2;
if (s[3])
return 1;
return 3;
if (s[v])
return 1;
return 4;
return 0;
}

View file

@ -0,0 +1,30 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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/>.
*/
int *foo;
//int bar = -1;
int
main ()
{
if (foo)
return 1;
return 0;
}

View file

@ -0,0 +1,33 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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/>.
*/
int foo = 1;
int *bar = &foo;
int baz = -1;
int
main ()
{
if (foo != 1)
return 1;
if (*bar != 1)
return 2;
return 0;
}

View file

@ -0,0 +1,33 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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/>.
*/
char *g_hello = "hello";
int
main ()
{
// char *p = g_hello;
// char **pp = &p;
char **pp = &g_hello;
if (**pp != 'h')
return 1;
return 0;
}

View file

@ -0,0 +1,31 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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/>.
*/
char *g_hello = "hello";
int
main ()
{
char *p = g_hello;
if (*p != 'h')
return 1;
return 0;
}

View file

@ -0,0 +1,32 @@
/* -*-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/>.
*/
#include <libmes.h>
int
main ()
{
char *begin = "foo";
char *end = begin + 4;
if (end - begin != 4)
return 1;
return 0;
}

View file

@ -22,45 +22,48 @@ char *g_hello = "hello";
char g_arena[4] = "XXX";
char *g_chars = g_arena;
struct foo {
int fd;
};
struct foo *file;
int
main ()
{
if (*g_hello != 'h') return 1;
if (g_hello[0] != 'h') return 2;
if (g_chars[0] != 'X') return 3;
if (*g_chars != 'X') return 4;
if (*g_hello != 'h')
return 1;
if (g_hello[0] != 'h')
return 2;
if (g_chars[0] != 'X')
return 3;
if (*g_chars != 'X')
return 4;
g_arena[0] = 'A';
if (*g_chars != 'A') return 5;
if (*g_chars != 'A')
return 5;
char *x = g_arena;
if (*x++ != 'A') return 5;
if (*x++ != 'A')
return 5;
*x++ = 'C';
if (g_chars[1] != 'C') return 7;
if (g_chars[2] != 'X') return 8;
if (g_chars[1] != 'C')
return 7;
if (g_chars[2] != 'X')
return 8;
*--x = 'X';
if (g_chars[1] != 'X') return 9;
if (g_chars[1] != 'X')
return 9;
char **pp = &x;
if (**pp != 'X') return 10;
if (**pp != 'X')
return 10;
char *p = *pp;
if (*p != 'X') return 11;
if (*p != 'X')
return 11;
char ***ppp = &pp;
if (***ppp != 'X') return 12;
if (***ppp != 'X')
return 12;
char **pp2 = *ppp;
if (**pp2 != 'X') return 13;
struct foo *f = 0;
if (f) return 14;
if (file) return 15;
if (**pp2 != 'X')
return 13;
return 0;
}

105
scaffold/tests/31-oputs.c Normal file
View file

@ -0,0 +1,105 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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 <libmes-mini.h>
#if 0
#include <linux/x86_64/syscall.h>
#define _write _xwrite
#define write xwrite
#define strlen xstrlen
#define oputs xoputs
#if __GNUC__
#define SYS_write "0x01"
#define SYS_exit "0x3c"
ssize_t
_write (int filedes, void const *buffer, size_t size)
{
long r;
asm (
"mov $"SYS_write",%%rax\n\t"
"mov %1,%%rdi\n\t"
"mov %2,%%rsi\n\t"
"mov %3,%%rdx\n\t"
"syscall \n\t"
"mov %%rax,%0\n\t"
: "=r" (r)
: "rm" (filedes), "rm" (buffer), "rm" (size)
: "rax", "rdi", "rsi", "rdx"
);
return r;
}
#else
#define SYS_write 0x01
#define SYS_exit 0x3c
void
_write (int filedes, void const *buffer, size_t size)
{
asm ("mov____0x8(%rbp),%rdi !0x10");
asm ("mov____0x8(%rbp),%rsi !0x18");
asm ("mov____0x8(%rbp),%rdx !0x20");
asm ("mov____$i32,%rax SYS_write");
asm ("syscall");
}
#endif
ssize_t
write (int filedes, void const *buffer, size_t size)
{
int r = _write (filedes, buffer, size);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
size_t
strlen (char const* s)
{
int i = 0;
while (s[i])
i++;
return i;
}
int
oputs (char const* s)
{
int i = strlen (s);
write (1, s, i);
return 0;
}
#endif
int
main ()
{
oputs ("\n");
oputs ("mes\n");
return 0;
}

View file

@ -0,0 +1,47 @@
/* -*-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/>.
*/
#include <libmes.h>
long
wrap (long a)
{
//eputs ("wrap:"); eputs (itoa (a)); eputs ("\n");
return a;
}
int
print (int a)
{
//eputs ("print:"); eputs (itoa (a)); eputs ("\n");
return a;
}
int
main ()
{
int a[2] = {101, -1};
//eputs ("b:"); eputs (itoa (a[0])); eputs ("\n");
int r = wrap (print (a[0]));
if (r != 101)
return 1;
return 0;
}

View file

@ -20,104 +20,140 @@
#include <libmes-mini.h>
int isid(char c) {
int
isid (char c)
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
}
int
main ()
main (int c)
{
int f = 0;
int t = 1;
int one = t;
puts ("\n");
puts ("t: if (f)\n");
if (f) return 1;
oputs ("\n");
oputs ("t: if (f)\n");
if (f)
return 1;
puts ("t: if (one != 1)\n");
if (one != 1) return 2;
oputs ("t: if (one != 1)\n");
if (one != 1)
return 2;
puts ("t: if (1 != one)\n");
if (1 != one) return 3;
oputs ("t: if (1 != one)\n");
if (1 != one)
return 3;
puts ("t: if (one > 1)\n");
if (one > 1) return 4;
oputs ("t: if (one > 1)\n");
if (one > 1)
return 4;
puts ("t: if (one < 0)\n");
if (one < 0) return 5;
oputs ("t: if (one < 0)\n");
if (one < 0)
return 5;
puts ("t: if (one <= 0)\n");
if (one <= 0) return 6;
oputs ("t: if (one <= 0)\n");
if (one <= 0)
return 6;
puts ("t: if (one >= 2)\n");
if (one >= 2) return 7;
oputs ("t: if (one >= 2)\n");
if (one >= 2)
return 7;
puts ("t: if (!1)\n");
if (!1) return 8;
oputs ("t: if (!1)\n");
if (!1)
return 8;
puts ("t: if (one == 0)\n");
if (one == 0) return 9;
oputs ("t: if (one == 0)\n");
if (one == 0)
return 9;
puts ("t: if (f != 0)\n");
if (one != 1) return 10;
oputs ("t: if (f != 0)\n");
if (one != 1)
return 10;
oputs ("t: if (1)\n");
if (1)
goto ok0;
puts ("t: if (1)\n");
if (1) goto ok0;
return 111;
ok0:
puts ("t: if (0); return 1; else;\n");
if (0) return 12; else goto ok1;
oputs ("t: if (0); return 1; else;\n");
if (0)
return 12; else
goto ok1;
ok1:
puts ("t: if (t)\n");
if (t) goto ok2;
oputs ("t: if (t)\n");
if (t)
goto ok2;
return 13;
ok2:
puts ("t: if (one > 0)\n");
if (one > 0) goto ok3;
oputs ("t: if (one > 0)\n");
if (one > 0)
goto ok3;
return 14;
ok3:
puts ("t: if (one < 2)\n");
if (one < 2) goto ok4;
oputs ("t: if (one < 2)\n");
if (one < 2)
goto ok4;
return 15;
ok4:
puts ("t: if (one >= 0)\n");
if (one >= 0) goto ok5;
oputs ("t: if (one >= 0)\n");
if (one >= 0)
goto ok5;
return 16;
ok5:
puts ("t: if (one >= 1)\n");
if (one >= 0) goto ok6;
oputs ("t: if (one >= 1)\n");
if (one >= 0)
goto ok6;
return 17;
ok6:
puts ("t: if (one <= 2)\n");
if (one <= 2) goto ok7;
oputs ("t: if (one <= 2)\n");
if (one <= 2)
goto ok7;
return 18;
ok7:
puts ("t: if (one <= 1)\n");
if (one <= 1) goto ok8;
oputs ("t: if (one <= 1)\n");
if (one <= 1)
goto ok8;
return 19;
ok8:
puts ("t: if (!0)\n");
if (!0) goto ok9;
oputs ("t: if (!0)\n");
if (!0)
goto ok9;
return 20;
ok9:
puts ("t: if (one == 1)\n");
if (one == 1) goto ok10;
oputs ("t: if (one == 1)\n");
if (one == 1)
goto ok10;
return 21;
ok10:
puts ("t: if (one != 0)\n");
if (one != 0) goto ok11;
oputs ("t: if (one != 0)\n");
if (one != 0)
goto ok11;
return 22;
ok11:
;
@ -125,86 +161,106 @@ main ()
int m1 = -1;
int i;
puts ("t: i = one > 0\n");
oputs ("t: i = one > 0\n");
i = one > 0;
if (!i) return 23;
if (!i)
return 23;
puts ("t: i = one >= 1\n");
oputs ("t: i = one >= 1\n");
i = one >= 1;
if (!i) return 24;
if (!i)
return 24;
puts ("t: i = one < 2\n");
oputs ("t: i = one < 2\n");
i = one < 2;
if (!i) return 25;
if (!i)
return 25;
puts ("t: i = one <= 1\n");
oputs ("t: i = one <= 1\n");
i = one <= 1;
if (!i) return 26;
if (!i)
return 26;
puts ("t: i = 0 > one\n");
oputs ("t: i = 0 > one\n");
i = 0 > one;
if (i) return 27;
if (i)
return 27;
puts ("t: i = 0 >= one\n");
oputs ("t: i = 0 >= one\n");
i = 0 >= one;
if (i) return 28;
if (i)
return 28;
puts ("t: i = 1 < one \n");
oputs ("t: i = 1 < one \n");
i = 1 < one;
if (i) return 29;
if (i)
return 29;
puts ("t: i = 2 <= one\n");
oputs ("t: i = 2 <= one\n");
i = 2 <= one;
if (i) return 30;
if (i)
return 30;
puts ("t: i = m1 > -2\n");
oputs ("t: i = m1 > -2\n");
i = m1 > -2;
if (!i) return 31;
if (!i)
return 31;
puts ("t: i = m1 >= -1\n");
oputs ("t: i = m1 >= -1\n");
i = m1 >= -1;
if (!i) return 32;
if (!i)
return 32;
puts ("t: i = m1 < 0\n");
oputs ("t: i = m1 < 0\n");
i = m1 < 0;
if (!i) return 33;
if (!i)
return 33;
puts ("t: i = m1 <= -1\n");
oputs ("t: i = m1 <= -1\n");
i = m1 <= -1;
if (!i) return 34;
if (!i)
return 34;
puts ("t: i = -1 > m1\n");
oputs ("t: i = -1 > m1\n");
i = -1 > m1;
if (i) return 35;
if (i)
return 35;
puts ("t: i = -2 >= m1\n");
oputs ("t: i = -2 >= m1\n");
i = -2 >= m1;
if (i) return 36;
if (i)
return 36;
puts ("t: i = -1 < m1 \n");
oputs ("t: i = -1 < m1 \n");
i = -1 < m1;
if (i) return 37;
if (i)
return 37;
puts ("t: i = -2 <= m1\n");
oputs ("t: i = -2 <= m1\n");
i = 0 <= m1;
if (i) return 38;
if (i)
return 38;
puts ("t: isid (0)\n");
if (isid (0)) return 39;
oputs ("t: isid (0)\n");
if (isid (0))
return 39;
puts ("t: isid (6)\n");
oputs ("t: isid (6)\n");
if (isid (6)) return 40;
if (isid (6))
return 40;
puts ("t: isid (a)\n");
if (isid ('a') != 1) return 41;
oputs ("t: isid (a)\n");
if (isid ('a') != 1)
return 41;
puts ("t: isid ( )\n");
if (isid (' ')) return 42;
oputs ("t: isid ( )\n");
if (isid (' '))
return 42;
return 0;
}

View file

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -27,26 +27,32 @@ main ()
int t = 1;
int one = t;
puts ("\n");
puts ("t: if (1 && 0)\n");
if (1 && 0) return 1;
oputs ("\n");
oputs ("t: if (1 && 0)\n");
if (1 && 0)
return 1;
puts ("t: if (!t && f)\n");
if (!t && f) return 1;
oputs ("t: if (!t && f)\n");
if (!t && f)
return 1;
puts ("t: if (t && !one)\n");
if (t && !one) return 1;
oputs ("t: if (t && !one)\n");
if (t && !one)
return 1;
puts ("t: if (f || !t)\n");
if (f || !t) return 1;
oputs ("t: if (f || !t)\n");
if (f || !t)
return 1;
puts ("t: if (1 && !0)\n");
if (1 && !0) goto ok0;
oputs ("t: if (1 && !0)\n");
if (1 && !0)
goto ok0;
return 1;
ok0:
puts ("t: if (f || t)\n");
if (f || t) goto ok1;
oputs ("t: if (f || t)\n");
if (f || t)
goto ok1;
return 1;
ok1:

View file

@ -28,28 +28,34 @@ main ()
int one = t;
int i = 0;
puts ("\n");
puts ("t: if (i++)\n");
if (i++) return 1;
oputs ("\n");
oputs ("t: if (i++)\n");
if (i++)
return 1;
puts ("t: if (--i)\n");
if (--i) return 1;
oputs ("t: if (--i)\n");
if (--i)
return 1;
puts ("t: i += 2\n");
oputs ("t: i += 2\n");
i += 2;
if (i != 2) return 1;
if (i != 2)
return 1;
puts ("t: i -= 2\n");
oputs ("t: i -= 2\n");
i -= 2;
if (i != 0) return 1;
if (i != 0)
return 1;
puts ("t: if (++i)\n");
if (++i) goto ok0;
oputs ("t: if (++i)\n");
if (++i)
goto ok0;
return 1;
ok0:
puts ("t: if (i--)\n");
if (i--) goto ok1;
oputs ("t: if (i--)\n");
if (i--)
goto ok1;
return 1;
ok1:

View file

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -32,58 +32,70 @@ main ()
char *x = g_arena;
char *y = g_chars;
puts ("\n");
puts ("t: p[0] != 'm'\n");
if (p[0] != 'm') return p[0];
oputs ("\n");
oputs ("t: p[0] != 'm'\n");
if (p[0] != 'm')
return p[0];
puts ("t: p[i] != 't'\n");
if (p[i] != 'm') return p[i];
oputs ("t: p[i] != 't'\n");
if (p[i] != 'm')
return p[i];
puts ("t: *g_chars != 'A'\n");
oputs ("t: *g_chars != 'A'\n");
g_arena[0] = 'A';
if (*g_chars != 'A') return 1;
if (*g_chars != 'A')
return 1;
puts ("t: *x != 'A'\n");
if (*x != 'A') return 1;
oputs ("t: *x != 'A'\n");
if (*x != 'A')
return 1;
puts ("t: *y != 'A'\n");
if (*y != 'A') return 1;
oputs ("t: *y != 'A'\n");
if (*y != 'A')
return 1;
puts ("t: *x != 'Q'\n");
oputs ("t: *x != 'Q'\n");
g_chars[0] = 'Q';
if (*x != 'Q') return 1;
if (*x != 'Q')
return 1;
puts ("t: *x++ != 'C'\n");
oputs ("t: *x++ != 'C'\n");
*x++ = c;
if (*g_chars != 'C') return 1;
if (*g_chars != 'C')
return 1;
puts ("t: *g_chars == 'B'\n");
oputs ("t: *g_chars == 'B'\n");
g_arena[0] = 'B';
if (*g_chars == 'B') goto ok1;
if (*g_chars == 'B')
goto ok1;
return 1;
ok1:
puts ("t: *x == 'B'\n");
oputs ("t: *x == 'B'\n");
x = g_arena;
if (*x == 'B') goto ok2;
if (*x == 'B')
goto ok2;
return 1;
ok2:
puts ("t: *y == 'B'\n");
oputs ("t: *y == 'B'\n");
y = g_chars;
if (*y == 'B') goto ok3;
if (*y == 'B')
goto ok3;
return 1;
ok3:
puts ("t: *x == 'R'\n");
oputs ("t: *x == 'R'\n");
g_chars[0] = 'R';
if (*x == 'R') goto ok4;
if (*x == 'R')
goto ok4;
return 1;
ok4:
puts ("t: *x++ == 'C'\n");
oputs ("t: *x++ == 'C'\n");
*x++ = c;
if (*g_chars == 'C') goto ok5;
if (*g_chars == 'C')
goto ok5;
return 1;
ok5:

View file

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -23,21 +23,26 @@
int
main ()
{
puts ("\n");
puts ("t: 1 + 2\n");
if (1 + 2 != 3) return 1;
oputs ("\n");
oputs ("t: 1 + 2\n");
if (1 + 2 != 3)
return 1;
puts ("t: 2 - 1\n");
if (2 - 1 != 1) return 1;
oputs ("t: 2 - 1\n");
if (0)
return 1;
puts ("t: 1 << 3\n");
if (1 << 3 != 8) return 1;
oputs ("t: 1 << 3\n");
if (1 << 3 != 8)
return 1;
puts ("t: 8 >> 3\n");
if (8 >> 3 != 1) return 1;
oputs ("t: 8 >> 3\n");
if (8 >> 3 != 1)
return 1;
puts ("t: 8 / 4\n");
if (8 / 4 != 2) return 1;
oputs ("t: 8 / 4\n");
if (8 / 4 != 2)
return 1;
return 0;
}

View file

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -27,18 +27,22 @@ main ()
int t = 1;
int one = t;
puts ("\n");
puts ("t: if (f = 0) ?\n");
if (f = 0) return 1;
oputs ("\n");
oputs ("t: if (f = 0) ?\n");
if (f = 0)
return 1;
puts ("t: if (!(t = 1)) ?\n");
if (!(t = 1)) return 1;
oputs ("t: if (!(t = 1)) ?\n");
if (!(t = 1))
return 1;
puts ("t: if ((f = 0) != 0) ?\n");
if ((f = 0) != 0) return 1;
oputs ("t: if ((f = 0) != 0) ?\n");
if ((f = 0) != 0)
return 1;
puts ("t: if ((t = 1) != 1) ?\n");
if ((t = 1) != 1) return 1;
oputs ("t: if ((t = 1) != 1) ?\n");
if ((t = 1) != 1)
return 1;
return 0;
}

View file

@ -0,0 +1,42 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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 <libmes-mini.h>
int
add (int a, int b)
{
return a + b;
}
int
identity (int i)
{
return i;
}
int
main ()
{
if (add (identity (1), identity (2)) != 3)
return 1;
return 0;
}

View file

@ -0,0 +1,42 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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 <libmes-mini.h>
int
add (int a, int b)
{
return a + b;
}
int
inc (int i)
{
return i + 1;
}
int
main ()
{
if (add (inc (0), inc (1)) != 3)
return 1;
return 0;
}

Some files were not shown because too many files have changed in this diff Show more