diff --git a/GNUmakefile b/GNUmakefile index 96178863..416e0cd7 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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 index 00000000..781f4702 --- /dev/null +++ b/libc/include/assert.h @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ +#ifndef __ASSERT_H +#define __ASSERT_H 1 + +#if __GNUC__ && POSIX +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include_next +#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 index 00000000..2c7f20a7 --- /dev/null +++ b/libc/include/ctype.h @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ +#ifndef __CTYPE_H +#define __CTYPE_H 1 + +#if __GNUC__ && POSIX +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include_next + +#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 index 00000000..6a735c09 --- /dev/null +++ b/libc/include/errno.h @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ +#ifndef __ERRNO_H +#define __ERRNO_H 1 + +#if __GNUC__ && POSIX +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include_next +#endif // ! (__GNUC__ && POSIX) + +#endif // __ERRNO_H diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h new file mode 100644 index 00000000..18e73f6f --- /dev/null +++ b/libc/include/fcntl.h @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ +#ifndef __FCNTL_H +#define __FCNTL_H 1 + +#if __GNUC__ && POSIX +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include_next + +#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 index 00000000..1f008d40 --- /dev/null +++ b/libc/include/limits.h @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ +#ifndef __LIMITS_H +#define __LIMITS_H 1 + +#if __GNUC__ && POSIX +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include_next + +#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 index 00000000..ec2a1f9a --- /dev/null +++ b/libc/include/mlibc.h @@ -0,0 +1,26 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2016,2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ + +#ifndef __MLIBC_H +#define __MLIBC_H + +char const* itoa (int); + +#endif //__MLIBC_H diff --git a/libc/include/stdio.h b/libc/include/stdio.h index 52a2c180..87842e35 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -1,6 +1,66 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2016,2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ #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 + +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 index 00000000..efa79bc9 --- /dev/null +++ b/libc/include/stdlib.h @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ +#ifndef __STDLIB_H +#define __STDLIB_H 1 + +#if __GNUC__ && POSIX +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include_next +#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 index 00000000..91e2010c --- /dev/null +++ b/libc/include/string.h @@ -0,0 +1,41 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ +#ifndef __STRING_H +#define __STRING_H 1 + +#if __GNUC__ && POSIX +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include_next + +#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 index 00000000..ae917a49 --- /dev/null +++ b/libc/include/unistd.h @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ +#ifndef __UNISTD_H +#define __UNISTD_H 1 + +#if __GNUC__ && POSIX +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include_next + +#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 diff --git a/libc/mlibc.c b/libc/mlibc.c index 450d879d..44530e2c 100644 --- a/libc/mlibc.c +++ b/libc/mlibc.c @@ -21,22 +21,12 @@ char **g_environment = 0; int g_stdin = 0; -#define EOF -1 -#define STDIN 0 -#define STDOUT 1 -#define STDERR 2 +#include +#include #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 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 -#include -#include #include -#include -#include -#include #include #include +#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 diff --git a/libc/mstart.c b/libc/mstart.c index 6e6aaeb4..8bdbec98 100644 --- a/libc/mstart.c +++ b/libc/mstart.c @@ -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 index 00000000..6fd8fb64 --- /dev/null +++ b/make/bin-mlibc.make @@ -0,0 +1,5 @@ +C_FLAGS:=-nostdinc --include mstart.c -fno-builtin +LD_FLAGS:=-nostdlib +CROSS:=$(CC32:%gcc=%) + +include make/bin.make diff --git a/make/bin.make b/make/bin.make index ce037dfd..a6a04b6c 100644 --- a/make/bin.make +++ b/make/bin.make @@ -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) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 4a87e155..00e69c17 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -1732,8 +1732,24 @@ (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; diff --git a/scaffold/cons-mes.c b/scaffold/cons-mes.c index 7e4784c6..093db77e 100644 --- a/scaffold/cons-mes.c +++ b/scaffold/cons-mes.c @@ -22,15 +22,11 @@ #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 +#include +#include +#include +#include char arena[2000]; @@ -878,7 +874,3 @@ main (int argc, char *argv[]) return 0; } -#if !__MESC__ -#include "mstart.c" -#endif - diff --git a/scaffold/hello.c b/scaffold/hello.c index 882f9c7b..2f704de8 100644 --- a/scaffold/hello.c +++ b/scaffold/hello.c @@ -18,15 +18,7 @@ * along with Mes. If not, see . */ -#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 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 diff --git a/scaffold/m.c b/scaffold/m.c index 27020261..2758287c 100644 --- a/scaffold/m.c +++ b/scaffold/m.c @@ -18,15 +18,7 @@ * along with Mes. If not, see . */ -#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 int main (int argc, char *argv[]) @@ -40,7 +32,3 @@ main (int argc, char *argv[]) } return c; } - -#if !__MESC__ && !POSIX -#include "mstart.c" -#endif diff --git a/scaffold/malloc.c b/scaffold/malloc.c index 5bb48b95..9aeddc97 100644 --- a/scaffold/malloc.c +++ b/scaffold/malloc.c @@ -22,14 +22,7 @@ #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 int main (int argc, char *argv[]) @@ -59,7 +52,3 @@ main (int argc, char *argv[]) } return 0; } - -#if __GNUC__ -#include "mstart.c" -#endif diff --git a/scaffold/micro-mes.c b/scaffold/micro-mes.c index 8cafd8dc..a057f0f5 100644 --- a/scaffold/micro-mes.c +++ b/scaffold/micro-mes.c @@ -22,15 +22,7 @@ #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 typedef int SCM; @@ -79,7 +71,3 @@ main (int argc, char *argv[]) int i = argc; return i; } - -#if !__MESC__ -#include "mstart.c" -#endif diff --git a/scaffold/mini-mes.c b/scaffold/mini-mes.c index 6ba40f23..ef6415bc 100644 --- a/scaffold/mini-mes.c +++ b/scaffold/mini-mes.c @@ -22,15 +22,11 @@ #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 +#include +#include +#include +#include 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 diff --git a/scaffold/scaffold.make b/scaffold/scaffold.make index 91e81b5b..f273ae18 100644 --- a/scaffold/scaffold.make +++ b/scaffold/scaffold.make @@ -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 diff --git a/scaffold/t.c b/scaffold/t.c index 00550383..363ab8f3 100644 --- a/scaffold/t.c +++ b/scaffold/t.c @@ -18,14 +18,9 @@ * along with Mes. If not, see . */ -#if __MESC__ -int g_stdin = 0; -#define assert(x) ((x) ? (void)0 : assert_fail (#x)) -#endif - -#if !__MESC__ -#include "mlibc.c" -#endif +#include +#include +#include struct scm { int type; @@ -924,7 +919,3 @@ main (int argc, char *argv[]) return 22; } - -#if !POSIX && !__MESC__ -#include "mstart.c" -#endif diff --git a/scaffold/tiny-mes.c b/scaffold/tiny-mes.c index 8a8e4fac..0617deeb 100644 --- a/scaffold/tiny-mes.c +++ b/scaffold/tiny-mes.c @@ -22,15 +22,7 @@ #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 char arena[300]; @@ -346,7 +338,3 @@ main (int argc, char *argv[]) return 0; } - -#if !__MESC__ -#include "mstart.c" -#endif diff --git a/src/gc.c b/src/gc.c index aa4eea44..e140b499 100644 --- a/src/gc.c +++ b/src/gc.c @@ -18,6 +18,8 @@ * along with Mes. If not, see . */ +#include + SCM gc_up_arena () ///((internal)) { diff --git a/src/lib.c b/src/lib.c index 048429a9..81192026 100644 --- a/src/lib.c +++ b/src/lib.c @@ -18,6 +18,10 @@ * along with Mes. If not, see . */ +#if !__MESC__ +#define fputs fdputs +#endif + int g_depth; SCM fdisplay_ (SCM, int); diff --git a/src/math.c b/src/math.c index 9fe8b9c2..c0b6190b 100644 --- a/src/math.c +++ b/src/math.c @@ -18,6 +18,8 @@ * along with Mes. If not, see . */ +#include + SCM greater_p (SCM x) ///((name . ">") (arity . n)) { diff --git a/src/mes.c b/src/mes.c index 266d2ff4..c2801512 100644 --- a/src/mes.c +++ b/src/mes.c @@ -18,15 +18,11 @@ * along with Mes. If not, see . */ -#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 +#include +#include +#include +#include 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 diff --git a/src/posix.c b/src/posix.c index 5f6901da..abb4ac70 100644 --- a/src/posix.c +++ b/src/posix.c @@ -18,6 +18,8 @@ * along with Mes. If not, see . */ +#include + int ungetchar (int c) { diff --git a/src/reader.c b/src/reader.c index fe6dab5e..8883398f 100644 --- a/src/reader.c +++ b/src/reader.c @@ -18,11 +18,7 @@ * along with Mes. If not, see . */ -// #if _POSIX_SOURCE -// #undef fputs -// #undef fdputs -// #undef fdputc -// #endif +#include SCM ___end_of_mes___ () diff --git a/src/src.make b/src/src.make index 3c8b64ee..62246d17 100644 --- a/src/src.make +++ b/src/src.make @@ -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 $(