mescc: Support regular C99 compile, headers + mlibc.
authorJan Nieuwenhuizen <janneke@gnu.org>
Tue, 2 May 2017 21:30:46 +0000 (23:30 +0200)
committerJan Nieuwenhuizen <janneke@gnu.org>
Tue, 2 May 2017 21:30:46 +0000 (23:30 +0200)
* libc/include/assert.h: New file.
* libc/include/ctype.h: New file.
* libc/include/errno.h: New file.
* libc/include/fcntl.h: New file.
* libc/include/limits.h: New file.
* libc/include/mlibc.h: New file.
* libc/include/stdio.h: New file.
* libc/include/stdlib: New file.
* libc/include/string.h: New file.
* libc/include/unistd.h: New file.
* libc/mlibc.c: Remove declarations.
* make/bin.make (INCLUDES): Factor out standard includes.
* make/bin-mlibc.make: New file.
* scaffold/scaffold.make: Use it.
* src/src.make: Use it.
* module/language/c99/compiler.mes (ast-info): Handle more function declarations.
* scaffold/cons-mes.c: Remove mlibc definitionsa and mlibc.c include.
  Instead include <mlibc.h>.
* scaffold/hello.c: Likewise.
* scaffold/m.c: Likewise.
* scaffold/malloc.c: Likewise.
* scaffold/micro-mes.c: Likewise.
* scaffold/mini-mes.c: Likewise.
* scaffold/t.c: Likewise.
* scaffold/tiny-mes.c: Likewise.
* src/gc.c: Likewise.
* src/lib.c: Likewise.
* src/math.c: Likewise.
* src/mes.c: Likewise.
* src/posix.c: Likewise.
* src/reader.c: Likewise.

32 files changed:
GNUmakefile
libc/include/assert.h [new file with mode: 0644]
libc/include/ctype.h [new file with mode: 0644]
libc/include/errno.h [new file with mode: 0644]
libc/include/fcntl.h [new file with mode: 0644]
libc/include/limits.h [new file with mode: 0644]
libc/include/mlibc.h [new file with mode: 0644]
libc/include/stdio.h
libc/include/stdlib.h [new file with mode: 0644]
libc/include/string.h [new file with mode: 0644]
libc/include/unistd.h [new file with mode: 0644]
libc/mlibc.c
libc/mstart.c
make/bin-mlibc.make [new file with mode: 0644]
make/bin.make
module/language/c99/compiler.mes
scaffold/cons-mes.c
scaffold/hello.c
scaffold/m.c
scaffold/malloc.c
scaffold/micro-mes.c
scaffold/mini-mes.c
scaffold/scaffold.make
scaffold/t.c
scaffold/tiny-mes.c
src/gc.c
src/lib.c
src/math.c
src/mes.c
src/posix.c
src/reader.c
src/src.make

index 96178863c7d15cf5c8ea11e4e3b4f20a0f84e34f..416e0cd753dad90862e37e91ad8a54ba21ce6446 100644 (file)
@@ -5,7 +5,7 @@ QUIET:=@
 default: all
 
 MES_DEBUG:=1
-CFLAGS:=--std=gnu99 -O0 -g
+CFLAGS:=--std=gnu99 -O0 -g --include mlibc.c
 OUT:=out
 
 SUBDIRS:=\
diff --git a/libc/include/assert.h b/libc/include/assert.h
new file mode 100644 (file)
index 0000000..781f470
--- /dev/null
@@ -0,0 +1,32 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASSERT_H
+#define __ASSERT_H 1
+
+#if __GNUC__ && POSIX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include_next <assert.h>
+#else // ! (__GNUC__ && POSIX)
+#define assert(x) ((x) ? (void)0 : assert_fail (#x))
+#endif // ! (__GNUC__ && POSIX)
+
+#endif // __ASSERT_H
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
new file mode 100644 (file)
index 0000000..2c7f20a
--- /dev/null
@@ -0,0 +1,33 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __CTYPE_H
+#define __CTYPE_H 1
+
+#if __GNUC__ && POSIX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include_next <ctype.h>
+
+#else // ! (__GNUC__ && POSIX)
+int isdigit (int);
+#endif // ! (__GNUC__ && POSIX)
+
+#endif // __CTYPE_H
diff --git a/libc/include/errno.h b/libc/include/errno.h
new file mode 100644 (file)
index 0000000..6a735c0
--- /dev/null
@@ -0,0 +1,30 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ERRNO_H
+#define __ERRNO_H 1
+
+#if __GNUC__ && POSIX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include_next <errno.h>
+#endif // ! (__GNUC__ && POSIX)
+
+#endif // __ERRNO_H
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
new file mode 100644 (file)
index 0000000..18e73f6
--- /dev/null
@@ -0,0 +1,34 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __FCNTL_H
+#define __FCNTL_H 1
+
+#if __GNUC__ && POSIX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include_next <fcntl.h>
+
+#else // ! (__GNUC__ && POSIX)
+#define O_RDONLY 0
+int open (char const *s, int mode);
+#endif // ! (__GNUC__ && POSIX)
+
+#endif // __FCNTL_H
diff --git a/libc/include/limits.h b/libc/include/limits.h
new file mode 100644 (file)
index 0000000..1f008d4
--- /dev/null
@@ -0,0 +1,34 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __LIMITS_H
+#define __LIMITS_H 1
+
+#if __GNUC__ && POSIX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include_next <limits.h>
+
+#else // ! (__GNUC__ && POSIX)
+#define INT_MIN -2147483648
+#define INT_MAX 2147483647
+#endif // ! (__GNUC__ && POSIX)
+
+#endif // __LIMITS_H
diff --git a/libc/include/mlibc.h b/libc/include/mlibc.h
new file mode 100644 (file)
index 0000000..ec2a1f9
--- /dev/null
@@ -0,0 +1,26 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MLIBC_H
+#define __MLIBC_H
+
+char const* itoa (int);
+
+#endif //__MLIBC_H
index 52a2c18037bc73f052d06765cc55ad1e6acd5a98..87842e35451716da4650c5dac6e41d622c44d88a 100644 (file)
@@ -1,6 +1,66 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
 #ifndef __STDIO_H
 #define __STDIO_H 1
 
+char **g_environment;
+int g_stdin;
+
+#define EOF -1
+#define STDIN 0
+#define STDOUT 1
+#define STDERR 2
+
 int printf (char const* format, ...);
 
+#if __GNUC__ && POSIX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include_next <stdio.h>
+
+int fdputs (char const* s, int fd);
+
+#undef puts
+#define puts(x) fdputs(x, STDOUT)
+#define eputs(x) fdputs(x, STDERR)
+#define fputs fdputs
+
+#ifdef putc
+#undef putc
+#endif
+
+int getchar ();
+
+int fdputc (int c, int fd);
+
+#define fputc fdputc
+#define ungetc fdungetc
+int fdungetc (int c, int fd);
+
+#else // !POSIX
+
+#undef fputs
+#undef fdputs
+int fdputs (char const* s, int fd);
+
+#endif // __GNUC__ && POSIX
+
 #endif // __STDIO_H
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
new file mode 100644 (file)
index 0000000..efa79bc
--- /dev/null
@@ -0,0 +1,40 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __STDLIB_H
+#define __STDLIB_H 1
+
+#if __GNUC__ && POSIX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include_next <stdlib.h>
+#else  // !(__GNUC__ && POSIX)
+
+#ifndef __SIZE_T
+#define __SIZE_T
+typedef long size_t;
+#endif
+
+void *malloc (size_t);
+void exit (int);
+#endif // !(__GNUC__ && POSIX)
+
+#endif // __STDLIB_H
+
diff --git a/libc/include/string.h b/libc/include/string.h
new file mode 100644 (file)
index 0000000..91e2010
--- /dev/null
@@ -0,0 +1,41 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __STRING_H
+#define __STRING_H 1
+
+#if __GNUC__ && POSIX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include_next <string.h>
+
+#else // ! (__GNUC__ && POSIX)
+
+#ifndef __SIZE_T
+#define __SIZE_T
+typedef long size_t;
+#endif
+
+size_t strlen (char const*);
+int strcmp (char const*, char const*);
+int strncmp (char const*, char const*, size_t);
+#endif // ! (__GNUC__ && POSIX)
+
+#endif // __STRING_H
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
new file mode 100644 (file)
index 0000000..ae917a4
--- /dev/null
@@ -0,0 +1,40 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of Mes.
+ *
+ * Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __UNISTD_H
+#define __UNISTD_H 1
+
+#if __GNUC__ && POSIX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include_next <unistd.h>
+
+#else // ! (__GNUC__ && POSIX)
+
+#ifndef __SIZE_T
+#define __SIZE_T
+typedef long size_t;
+#endif
+
+int read (int fd, void* buf, size_t n);
+int write (int fd, char const* s, int n);
+#endif // ! (__GNUC__ && POSIX)
+
+#endif // __UNISTD_H
index 450d879d98b99f536f53be6608c366202ec1d089..44530e2c53113df945cf9d5ab6b4d8c47fe221bd 100644 (file)
 char **g_environment = 0;
 int g_stdin = 0;
 
-#define EOF -1
-#define STDIN 0
-#define STDOUT 1
-#define STDERR 2
+#include <stdio.h>
+#include <mlibc.h>
 
 #if __GNUC__ && !POSIX
 
-#define O_RDONLY 0
-#define INT_MIN -2147483648
-#define INT_MAX 2147483647
-
-typedef long size_t;
-void *malloc (size_t i);
-int open (char const *s, int mode);
-int read (int fd, void* buf, size_t n);
-int write (int fd, char const* s, int n);
+#include <stdlib.h>
 
 void
 exit (int code)
@@ -288,7 +278,7 @@ ungetc (int c, int fd)
 char const* itoa (int);
 
 int
-strncmp (char const* a, char const* b, int length)
+strncmp (char const* a, char const* b, size_t length)
 {
   while (*a && *b && *a == *b && --length) {a++;b++;}
   return *a - *b;
@@ -432,22 +422,13 @@ itoa (int x)
 }
 
 #if POSIX
-
 #define _GNU_SOURCE
 #include <assert.h>
-#include <ctype.h>
-#include <errno.h>
 #include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#endif // POSIX
 
-#undef puts
-#define puts(x) fdputs(x, STDOUT)
-#define eputs(x) fdputs(x, STDERR)
-#define fputs fdputs
 int
 fdputs (char const* s, int fd)
 {
@@ -456,10 +437,8 @@ fdputs (char const* s, int fd)
   return 0;
 }
 
-#ifdef putc
-#undef putc
-#endif
-#define fputc fdputc
+#if POSIX
+
 int
 fdputc (int c, int fd)
 {
@@ -496,7 +475,6 @@ getchar ()
   return i;
 }
 
-#define ungetc fdungetc
 int
 fdungetc (int c, int fd)
 {
@@ -504,15 +482,5 @@ fdungetc (int c, int fd)
   ungetc_buf[++ungetc_char] = c;
   return c;
 }
-#else
 
-#define fputs fdputs
-int
-fdputs (char const* s, int fd)
-{
-  int i = strlen (s);
-  write (fd, s, i);
-  return 0;
-}
-
-#endif
+#endif // POSIX
index 6e6aaeb49ef69d4ca8fd4202bd4b4a8ac76a15af..8bdbec98b5d01da4db8afd530db2b308e9ce5b32 100644 (file)
@@ -52,4 +52,4 @@ _start ()
        );
   exit (r);
 }
-#endif
+#endif // __GNUC__
diff --git a/make/bin-mlibc.make b/make/bin-mlibc.make
new file mode 100644 (file)
index 0000000..6fd8fb6
--- /dev/null
@@ -0,0 +1,5 @@
+C_FLAGS:=-nostdinc --include mstart.c -fno-builtin
+LD_FLAGS:=-nostdlib
+CROSS:=$(CC32:%gcc=%)
+
+include make/bin.make
index ce037dfdefc1e606371f4414352c07b309b620b4..a6a04b6c7fd29c8067c7e2ff19720edfee3b571a 100644 (file)
@@ -11,6 +11,8 @@ endif
 CLEAN+=$(O_FILES) $(OUT)/$(TARGET)
 DIST-CLEAN+=$(D_FILES)
 
+INCLUDES+=libc/include libc $(OUT)/$(DIR)
+
 $(OUT)/$(TARGET): ld:=$(CROSS)LD
 $(OUT)/$(TARGET): LD:=$(CROSS)$(LD)
 $(OUT)/$(TARGET): CC:=$(CROSS)$(CC)
index 4a87e155e230c242654d0fbd59c5589822488b66..00e69c178cc538106d35f1bb5bebea42f445aad7 100644 (file)
          (let ((types (.types info)))
            (clone info #:types (cons (cons name (assoc-ref types type)) types))))
 
+        ;; int foo ();
+        ((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list . ,param-list)))))
+         info)
+
+        ;; void foo ();
+        ((decl (decl-spec-list (type-spec (void))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list . ,param-list)))))
+         info)
+
+        ;; void foo (*);
+        ((decl (decl-spec-list (type-spec (void))) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list))))))
+         info)
+
+        ;; char const* itoa ();
+        ((decl (decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qual)) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list))))))
+         info)
+
         ;; printf (char const* format, ...)
-        ((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list ,param-list (ellipsis))))))
+        ((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list ,param-list (ellipsis))))))
          info)
 
         ;; int i = 0, j = 0;
index 7e4784c6d9279a36d5b459e678488fcd0e9a7743..093db77e2931d190935611a704e8c6b1540cb55d 100644 (file)
 #error "POSIX not supported"
 #endif
 
-#if  __MESC__
-char **g_environment;
-int g_stdin = 0;
-#define assert(x) ((x) ? (void)0 : assert_fail (#x))
-#endif
-
-#if !__MESC__
-#include "mlibc.c"
-#endif
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mlibc.h>
 
 char arena[2000];
 
@@ -878,7 +874,3 @@ main (int argc, char *argv[])
   return 0;
 }
 
-#if !__MESC__
-#include "mstart.c"
-#endif
-
index 882f9c7b0cd3464d64e223e23432bd1692f49d26..2f704de83fc3388c4b2bb93e5f8798393a1b15f5 100644 (file)
  * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#if  __MESC__
-char **g_environment;
-int g_stdin = 0;
-#define assert(x) ((x) ? (void)0 : assert_fail (#x))
-#endif
-
-#if !__MESC__
-#include "mlibc.c"
-#endif
+#include <mlibc.h>
 
 int
 main (int argc, char *argv[])
@@ -40,7 +32,3 @@ main (int argc, char *argv[])
   if (argc > 1 && !strcmp (argv[1], "--help")) {puts ("argc > 1 && --help\n"); return argc;}
   return 42;
 }
-
-#if !__MESC__ && !POSIX
-#include "mstart.c"
-#endif
index 2702026160687242459693bd1d345b264444b1d7..2758287ca5e519e1f7e7ea0aacd470333403ef49 100644 (file)
  * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#if  __MESC__
-char **g_environment;
-int g_stdin = 0;
-#define assert(x) ((x) ? (void)0 : assert_fail (#x))
-#endif
-
-#if !__MESC__
-#include "mlibc.c"
-#endif
+#include <mlibc.h>
 
 int
 main (int argc, char *argv[])
@@ -40,7 +32,3 @@ main (int argc, char *argv[])
   }
   return c;
 }
-
-#if !__MESC__ && !POSIX
-#include "mstart.c"
-#endif
index 5bb48b95ba0b621c7dd20b03b9ab34a5076d5e5b..9aeddc977d02713cf7e3b5a80d294300ba99e0b0 100644 (file)
 #error "POSIX not supported"
 #endif
 
-#if  __MESC__
-int g_stdin = 0;
-#define assert(x) ((x) ? (void)0 : assert_fail (#x))
-#endif
-
-#if !__MESC__
-#include "mlibc.c"
-#endif
+#include <mlibc.h>
 
 int
 main (int argc, char *argv[])
@@ -59,7 +52,3 @@ main (int argc, char *argv[])
     }
   return 0;
 }
-
-#if __GNUC__
-#include "mstart.c"
-#endif
index 8cafd8dcf2d768245edb9668b3cd9d54ec74d4c8..a057f0f5440178f6e4fbe179731e5785bd1b2db5 100644 (file)
 #error "POSIX not supported"
 #endif
 
-#if  __MESC__
-char **g_environment;
-int g_stdin = 0;
-#define assert(x) ((x) ? (void)0 : assert_fail (#x))
-#endif
-
-#if !__MESC__
-#include "mlibc.c"
-#endif
+#include <mlibc.h>
 
 typedef int SCM;
 
@@ -79,7 +71,3 @@ main (int argc, char *argv[])
   int i = argc;
   return i;
 }
-
-#if !__MESC__
-#include "mstart.c"
-#endif
index 6ba40f2328d8db0c427b34e7fdb79784f27bd658..ef6415bcbed23b80157fc141764c4ea0049b9062 100644 (file)
 #error "POSIX not supported"
 #endif
 
-#if  __MESC__
-char **g_environment;
-int g_stdin = 0;
-#define assert(x) ((x) ? (void)0 : assert_fail (#x))
-#endif
-
-#if !__MESC__
-#include "mlibc.c"
-#endif
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mlibc.h>
 
 int ARENA_SIZE = 100000;
 int MAX_ARENA_SIZE = 40000000;
@@ -1201,23 +1197,18 @@ bload_env (SCM a) ///((internal))
 int
 main (int argc, char *argv[])
 {
-  eputs ("Hello mini-mes!\n");
-#if _POSIX_SOURCE
-  g_debug = getenv ("MES_DEBUG");
-  if (g_debug) {eputs ("MODULEDIR=");eputs (MODULEDIR);eputs ("\n");}
-  if (getenv ("MES_ARENA")) ARENA_SIZE = atoi (getenv ("MES_ARENA"));
-#endif
-  g_debug = 1;
-  if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("Usage: mes [--dump|--load] < FILE");
-  if (argc > 1 && !strcmp (argv[1], "--version")) {puts ("Mes ");puts (VERSION);return 0;};
-  g_stdin = STDIN;
+  char *p;
+  if (p = getenv ("MES_DEBUG")) g_debug = atoi (p);
+  if (g_debug) {eputs (";;; MODULEDIR=");eputs (MODULEDIR);eputs ("\n");}
+  if (p = getenv ("MES_MAX_ARENA")) MAX_ARENA_SIZE = atoi (p);
+  if (p = getenv ("MES_ARENA")) ARENA_SIZE = atoi (p);
+  if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("Usage: mes [--dump|--load] < FILE\n");
+  if (argc > 1 && !strcmp (argv[1], "--version")) {puts ("Mes ");puts (VERSION);puts ("\n");return 0;};
   r0 = mes_environment ();
 
   SCM program = bload_env (r0);
   SCM lst = cell_nil;
-#if !__MESC__
   for (int i=argc-1; i>=0; i--) lst = cons (MAKE_STRING (cstring_to_list (argv[i])), lst);
-#endif
   r0 = acons (cell_symbol_argv, lst, r0);
   push_cc (r2, cell_unspecified, r0, cell_unspecified);
   if (g_debug)
@@ -1239,7 +1230,3 @@ main (int argc, char *argv[])
     }
   return 0;
 }
-
-#if !__MESC__
-#include "mstart.c"
-#endif
index 91e81b5b71d79e6e05a1b62fb30956dd6513fedb..f273ae1820f427c7e224055d7166345c8c9638ea 100644 (file)
@@ -29,11 +29,7 @@ include make/check.make
 
 TARGET:=m.mlibc
 C_FILES:=$(DIR)/m.c
-INCLUDES:=libc
-C_FLAGS:=-nostdinc
-LD_FLAGS:=-nostdlib
-CROSS:=$(CC32:%gcc=%)
-include make/bin.make
+include make/bin-mlibc.make
 
 TARGET:=m.mlibc
 EXPECT:=255
@@ -41,11 +37,7 @@ include make/check.make
 
 TARGET:=hello.mlibc
 C_FILES:=$(DIR)/hello.c
-INCLUDES:=libc
-C_FLAGS:=-nostdinc -g
-LD_FLAGS:=-nostdlib -g
-CROSS:=$(CC32:%gcc=%)
-include make/bin.make
+include make/bin-mlibc.make
 
 TARGET:=hello.mlibc
 EXPECT:=42
@@ -53,11 +45,7 @@ include make/check.make
 
 TARGET:=micro-mes.mlibc
 C_FILES:=$(DIR)/micro-mes.c
-INCLUDES:=libc
-C_FLAGS:=-nostdinc
-LD_FLAGS:=-nostdlib
-CROSS:=$(CC32:%gcc=%)
-include make/bin.make
+include make/bin-mlibc.make
 
 TEST:=micro-mes.mlibc-check
 $(TEST): $(OUT)/micro-mes.mlibc
@@ -66,48 +54,35 @@ include make/check.make
 
 TARGET:=tiny-mes.mlibc
 C_FILES:=$(DIR)/tiny-mes.c
-INCLUDES:=libc
-C_FLAGS:=-nostdinc
-LD_FLAGS:=-nostdlib
-CROSS:=$(CC32:%gcc=%)
-include make/bin.make
+include make/bin-mlibc.make
 
 TARGET:=tiny-mes.mlibc
 include make/check.make
 
 TARGET:=cons-mes.mlibc
 C_FILES:=$(DIR)/cons-mes.c
-INCLUDES:=libc
-C_FLAGS:=-nostdinc
-LD_FLAGS:=-nostdlib
 DEFINES:=VERSION='"$(VERSION)"'
-CROSS:=$(CC32:%gcc=%)
-include make/bin.make
+include make/bin-mlibc.make
 
 TARGET:=cons-mes.mlibc
 include make/check.make
 
 TARGET:=t.mlibc
 C_FILES:=$(DIR)/t.c
-INCLUDES:=libc
-C_FLAGS:=-nostdinc
-LD_FLAGS:=-nostdlib
-CROSS:=$(CC32:%gcc=%)
-include make/bin.make
+include make/bin-mlibc.make
 
 TARGET:=t.mlibc
 include make/check.make
 
+CROSS:=$(CC32:%gcc=%)
+#$(OUT)/$(DIR)/mini-mes.$(CROSS)o: $(SNARF.MES)
 $(OUT)/mini-mes: $(SNARF.MES)
 
 TARGET:=mini-mes.mlibc
 C_FILES:=$(DIR)/mini-mes.c
-DEFINES:=FIXED_PRIMITIVES=1 VERSION='"$(VERSION)"' PREFIX='"$(PREFIX)"'
-INCLUDES:=libc src $(OUT)/src
-C_FLAGS:=-nostdinc
-LD_FLAGS:=-nostdlib
-CROSS:=$(CC32:%gcc=%)
-include make/bin.make
+DEFINES:=FIXED_PRIMITIVES=1 VERSION='"$(VERSION)"' MODULEDIR='"$(MODULEDIR)"' PREFIX='"$(PREFIX)"'
+INCLUDES:=src $(OUT)/src
+include make/bin-mlibc.make
 
 TEST:=mini-mes.mlibc-check
 $(TEST): $(OUT)/mini-mes.mlibc
@@ -174,7 +149,7 @@ $(TEST): $(OUT)/mini-mes.guile
 include make/check.make
 
 # scripts/mescc.mes
-
+ifeq ($(MES_SKIP_MES),)
 TARGET:=m.mes
 C_FILES:=$(DIR)/m.c
 include make/mescc-mes.make
@@ -223,6 +198,7 @@ include make/mescc-mes.make
 
 TARGET:=t.mes
 include make/check.make
+endif
 
 ifneq ($(BOOTSTRAP),)
 $(OUT)/mini-mes.mes: module/mes/read-0-32.mo
index 005503832f7cfb77e5c70cb0fd2538693a2cf39e..363ab8f3a1d717ab51c3056f8d73034aa9fc6803 100644 (file)
  * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#if  __MESC__
-int g_stdin = 0;
-#define assert(x) ((x) ? (void)0 : assert_fail (#x))
-#endif
-
-#if !__MESC__
-#include "mlibc.c"
-#endif
+#include <mlibc.h>
+#include <assert.h>
+#include <stdlib.h>
 
 struct scm {
   int type;
@@ -924,7 +919,3 @@ main (int argc, char *argv[])
 
   return 22;
 }
-
-#if !POSIX && !__MESC__
-#include "mstart.c"
-#endif
index 8a8e4fac021533c8437f98bdbf6a3bb35068eea7..0617deebf9dc8c24356e0016d4533cc476f83467 100644 (file)
 #error "POSIX not supported"
 #endif
 
-#if  __MESC__
-char **g_environment;
-int g_stdin = 0;
-#define assert(x) ((x) ? (void)0 : assert_fail (#x))
-#endif
-
-#if !__MESC__
-#include "mlibc.c"
-#endif
+#include <mlibc.h>
 
 char arena[300];
 
@@ -346,7 +338,3 @@ main (int argc, char *argv[])
 
   return 0;
 }
-
-#if !__MESC__
-#include "mstart.c"
-#endif
index aa4eea44dcb1851a305d94b4245750e58015cb04..e140b499335d3857004f4eb2f2ace9ed98aa872e 100644 (file)
--- a/src/gc.c
+++ b/src/gc.c
@@ -18,6 +18,8 @@
  * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <errno.h>
+
 SCM
 gc_up_arena () ///((internal))
 {
index 048429a928c0e6fa290fb8f679f4a5ae7b3018ea..81192026e200e18188b4c86f6e2ddf73110b14aa 100644 (file)
--- a/src/lib.c
+++ b/src/lib.c
  * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#if !__MESC__
+#define fputs fdputs
+#endif
+
 int g_depth;
 SCM fdisplay_ (SCM, int);
 
index 9fe8b9c229daf98d09cc2d5a004ecdf80f608f53..c0b6190b434375fb23d4985f83509414afe00c51 100644 (file)
@@ -18,6 +18,8 @@
  * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <limits.h>
+
 SCM
 greater_p (SCM x) ///((name . ">") (arity . n))
 {
index 266d2ff4ce62efa16c0059327f5d6e666fd66c20..c2801512bebae602eaa4103ea4d6a1bf99a8db9a 100644 (file)
--- a/src/mes.c
+++ b/src/mes.c
  * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#if  __MESC__
-char **g_environment;
-int g_stdin = 0;
-#define assert(x) ((x) ? (void)0 : assert_fail (#x))
-#endif
-
-#if !__MESC__
-#include "mlibc.c"
-#endif
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mlibc.h>
 
 int ARENA_SIZE = 100000;
 int MAX_ARENA_SIZE = 20000000;
@@ -1376,7 +1372,3 @@ main (int argc, char *argv[])
     }
   return 0;
 }
-
-#if !_POSIX_SOURCE && !__MESC__
-#include "mstart.c"
-#endif
index 5f6901da7ccb4e42141462dcfd7283029a10a309..abb4ac705d220e7820c342b8ffca83a7452aa8cc 100644 (file)
@@ -18,6 +18,8 @@
  * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <fcntl.h>
+
 int
 ungetchar (int c)
 {
index fe6dab5eddad393fde8d4bdecbf7348913a2765b..8883398fe9babd1edfae38b20a1a5b56010712d7 100644 (file)
  * along with Mes.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-// #if _POSIX_SOURCE
-// #undef fputs
-// #undef fdputs
-// #undef fdputc
-// #endif
+#include <ctype.h>
 
 SCM
 ___end_of_mes___ ()
index 3c8b64eec238b2efdf673b5b249cc7c10ce94bf7..62246d17a215e310c086cc4e13d9254e507991ec 100644 (file)
@@ -40,25 +40,16 @@ snarf-mes: $(SNARF.MES)
 
 include make/reset.make
 
-# a full 32 bit cross compiler with glibc
-# CROSS:=$(CC32:%gcc=%)
 # TARGET:=$(CROSS)mes
-# $(OUT)/$(DIR)/mes.$(CROSS)o: $(SNARF.MES)
-# C_FILES:=$(DIR)/mes.c
-# DEFINES:=FIXED_PRIMITIVES=1 MES_FULL=1 POSIX=1 VERSION='"$(VERSION)"' MODULEDIR='"$(MODULEDIR)"' PREFIX='"$(PREFIX)"'
-# INCLUDES:=libc $(OUT)/src
-# include make/bin.make
-
-# a simple non-glibc cross compiler, using mlibc.
 CROSS:=$(CC32:%gcc=%)
-TARGET:=$(CROSS)mes
+$(OUT)/$(CROSS)%: $(OUT)/%.mlibc
+       @ln -sf $(<F) $@
+
+TARGET:=mes.mlibc
 $(OUT)/$(DIR)/mes.$(CROSS)o: $(SNARF.MES)
 C_FILES:=$(DIR)/mes.c
 DEFINES:=FIXED_PRIMITIVES=1 MES_FULL=1 VERSION='"$(VERSION)"' MODULEDIR='"$(MODULEDIR)"' PREFIX='"$(PREFIX)"'
-INCLUDES:=libc $(OUT)/src
-C_FLAGS:=-nostdinc
-LD_FLAGS:=-nostdlib
-include make/bin.make
+include make/bin-mlibc.make
 
 TARGET:=mes.guile
 $(OUT)/mes.mes: module/mes/read-0-32.mo