From 6af7556d51c1b20203e96974a42f4ab0a5063916 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Tue, 23 May 2017 07:16:08 +0200 Subject: [PATCH] mescc: C99 header files and declaraions. * libc/include/assert.h (assert_fail): * libc/include/stdio.h: +int eputs (char const* s); +int fputs (char const* s); +int puts (char const* s); +int putchar (int c); +int fputc (int c, int fd); +int getchar (); * libc/include/stdlib.h: +char* getenv (char const* s) +int atoi (char const *s); +int *malloc (size_t); +int *realloc (int *p, int size); * libc/include/unistd.h (access): * src/lib.c (display_helper): * src/mes.c (read_input_file_env): * src/posix.c: Include unistd.h. --- libc/include/assert.h | 7 ++-- libc/include/ctype.h | 6 ++-- libc/include/dlfcn.h | 28 +++++++++++++++ libc/include/errno.h | 6 ++-- libc/include/fcntl.h | 6 ++-- libc/include/features.h | 28 +++++++++++++++ libc/include/inttypes.h | 41 ++++++++++++++++++++++ libc/include/limits.h | 6 ++-- libc/include/math.h | 28 +++++++++++++++ libc/include/mlibc.h | 4 +-- libc/include/setjmp.h | 32 +++++++++++++++++ libc/include/signal.h | 28 +++++++++++++++ libc/include/stdarg.h | 28 +++++++++++++++ libc/include/stdio.h | 32 ++++++++++++++--- libc/include/stdlib.h | 14 +++++--- libc/include/string.h | 10 +++--- libc/include/strings.h | 28 +++++++++++++++ libc/include/sys/cdefs.h | 28 +++++++++++++++ libc/include/sys/mman.h | 28 +++++++++++++++ libc/include/sys/stat.h | 28 +++++++++++++++ libc/include/sys/time.h | 28 +++++++++++++++ libc/include/sys/timeb.h | 28 +++++++++++++++ libc/include/sys/types.h | 28 +++++++++++++++ libc/include/sys/ucontext.h | 28 +++++++++++++++ libc/include/time.h | 28 +++++++++++++++ libc/include/unistd.h | 11 +++--- libc/libc-gcc.c | 2 +- libc/libc-mes.c | 2 +- make/install.make | 4 +++ module/language/c99/compiler.mes | 59 ++++++++++++++++---------------- src/lib.c | 2 ++ src/mes.c | 2 ++ src/posix.c | 1 + 33 files changed, 571 insertions(+), 68 deletions(-) create mode 100644 libc/include/dlfcn.h create mode 100644 libc/include/features.h create mode 100644 libc/include/inttypes.h create mode 100644 libc/include/math.h create mode 100644 libc/include/setjmp.h create mode 100644 libc/include/signal.h create mode 100644 libc/include/stdarg.h create mode 100644 libc/include/strings.h create mode 100644 libc/include/sys/cdefs.h create mode 100644 libc/include/sys/mman.h create mode 100644 libc/include/sys/stat.h create mode 100644 libc/include/sys/time.h create mode 100644 libc/include/sys/timeb.h create mode 100644 libc/include/sys/types.h create mode 100644 libc/include/sys/ucontext.h create mode 100644 libc/include/time.h diff --git a/libc/include/assert.h b/libc/include/assert.h index 781f4702..d301c196 100644 --- a/libc/include/assert.h +++ b/libc/include/assert.h @@ -17,8 +17,8 @@ * 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 +#ifndef __MES_ASSERT_H +#define __MES_ASSERT_H 1 #if __GNUC__ && POSIX #ifndef _GNU_SOURCE @@ -27,6 +27,7 @@ #include_next #else // ! (__GNUC__ && POSIX) #define assert(x) ((x) ? (void)0 : assert_fail (#x)) +void assert_fail (char* s); #endif // ! (__GNUC__ && POSIX) -#endif // __ASSERT_H +#endif // __MES_ASSERT_H diff --git a/libc/include/ctype.h b/libc/include/ctype.h index 2c7f20a7..722814c9 100644 --- a/libc/include/ctype.h +++ b/libc/include/ctype.h @@ -17,8 +17,8 @@ * 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 +#ifndef __MES_CTYPE_H +#define __MES_CTYPE_H 1 #if __GNUC__ && POSIX #ifndef _GNU_SOURCE @@ -30,4 +30,4 @@ int isdigit (int); #endif // ! (__GNUC__ && POSIX) -#endif // __CTYPE_H +#endif // __MES_CTYPE_H diff --git a/libc/include/dlfcn.h b/libc/include/dlfcn.h new file mode 100644 index 00000000..254a2377 --- /dev/null +++ b/libc/include/dlfcn.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_DLFCN_H +#define __MES_DLFCN_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_DLFCN_H + diff --git a/libc/include/errno.h b/libc/include/errno.h index 6a735c09..3ffd1a08 100644 --- a/libc/include/errno.h +++ b/libc/include/errno.h @@ -17,8 +17,8 @@ * 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 +#ifndef __MES_ERRNO_H +#define __MES_ERRNO_H 1 #if __GNUC__ && POSIX #ifndef _GNU_SOURCE @@ -27,4 +27,4 @@ #include_next #endif // ! (__GNUC__ && POSIX) -#endif // __ERRNO_H +#endif // __MES_ERRNO_H diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h index 5a7cc575..c728f8a6 100644 --- a/libc/include/fcntl.h +++ b/libc/include/fcntl.h @@ -17,8 +17,8 @@ * 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 +#ifndef __MES_FCNTL_H +#define __MES_FCNTL_H 1 #if __GNUC__ && POSIX #ifndef _GNU_SOURCE @@ -40,4 +40,4 @@ int open (char const *s, int flags, ...); #endif // ! (__GNUC__ && POSIX) -#endif // __FCNTL_H +#endif // __MES_FCNTL_H diff --git a/libc/include/features.h b/libc/include/features.h new file mode 100644 index 00000000..d4cbf27a --- /dev/null +++ b/libc/include/features.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_FEATURES_H +#define __MES_FEATURES_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_FEATURES_H + diff --git a/libc/include/inttypes.h b/libc/include/inttypes.h new file mode 100644 index 00000000..39127beb --- /dev/null +++ b/libc/include/inttypes.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 __MES_INTTYPES_H +#define __MES_INTTYPES_H 1 + +#if __GNUC__ && POSIX +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include_next +#else // ! (__GNUC__ && POSIX) + +typedef unsigned char uint8_t; +typedef char int8_t; +typedef unsigned short uint16_t; +typedef unsigned uint32_t; +typedef int int32_t; + +typedef unsigned long long uint64_t; +typedef long long int64_t; + +#endif // ! (__GNUC__ && POSIX) + +#endif // __MES_INTTYPES_H diff --git a/libc/include/limits.h b/libc/include/limits.h index 1f008d40..e4ec62cc 100644 --- a/libc/include/limits.h +++ b/libc/include/limits.h @@ -17,8 +17,8 @@ * 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 +#ifndef __MES_LIMITS_H +#define __MES_LIMITS_H 1 #if __GNUC__ && POSIX #ifndef _GNU_SOURCE @@ -31,4 +31,4 @@ #define INT_MAX 2147483647 #endif // ! (__GNUC__ && POSIX) -#endif // __LIMITS_H +#endif // __MES_LIMITS_H diff --git a/libc/include/math.h b/libc/include/math.h new file mode 100644 index 00000000..15dec7ca --- /dev/null +++ b/libc/include/math.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_MATH_H +#define __MES_MATH_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_MATH_H + diff --git a/libc/include/mlibc.h b/libc/include/mlibc.h index ec2a1f9a..84573acb 100644 --- a/libc/include/mlibc.h +++ b/libc/include/mlibc.h @@ -18,8 +18,8 @@ * along with Mes. If not, see . */ -#ifndef __MLIBC_H -#define __MLIBC_H +#ifndef __MES_MLIBC_H +#define __MES_MLIBC_H char const* itoa (int); diff --git a/libc/include/setjmp.h b/libc/include/setjmp.h new file mode 100644 index 00000000..e28153f8 --- /dev/null +++ b/libc/include/setjmp.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 __MES_SETJMP_H +#define __MES_SETJMP_H 1 + +#if __GNUC__ && POSIX +#include_next +#else // ! (__GNUC__ && POSIX) + +typedef int jmp_buf; + +#endif // ! (__GNUC__ && POSIX) + +#endif // __MES_SETJMP_H + diff --git a/libc/include/signal.h b/libc/include/signal.h new file mode 100644 index 00000000..50837dcd --- /dev/null +++ b/libc/include/signal.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_SIGNAL_H +#define __MES_SIGNAL_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_SIGNAL_H + diff --git a/libc/include/stdarg.h b/libc/include/stdarg.h new file mode 100644 index 00000000..40436a63 --- /dev/null +++ b/libc/include/stdarg.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_STDARG_H +#define __MES_STDARG_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_STDARG_H + diff --git a/libc/include/stdio.h b/libc/include/stdio.h index 608e28a0..e66bab8a 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -17,8 +17,8 @@ * 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 +#ifndef __MES_STDIO_H +#define __MES_STDIO_H 1 char **g_environment; int g_stdin; @@ -57,12 +57,34 @@ int fdputc (int c, int fd); #define ungetc fdungetc int fdungetc (int c, int fd); -#else // !POSIX +#else // ! (__GNUC__ && POSIX) +// Hmm +#define stdin 0 +#define stdout 1 +#define stderr 2 + +// TODO: fseek etc +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +#if __GNUC__ #undef fputs #undef fdputs int fdputs (char const* s, int fd); +#endif // __MES_GNUC__ -#endif // __GNUC__ && POSIX +int eputs (char const* s); +int fputs (char const* s, int fd); +int puts (char const* s); +int putchar (int c); +int fputc (int c, int fd); +int getchar (); +int ungetc (int c, int fd); -#endif // __STDIO_H +typedef int FILE; + +#endif // ! (__GNUC__ && POSIX) + +#endif // __MES_STDIO_H diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index efa79bc9..ebaba062 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -17,8 +17,8 @@ * 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 +#ifndef __MES_STDLIB_H +#define __MES_STDLIB_H 1 #if __GNUC__ && POSIX #ifndef _GNU_SOURCE @@ -27,14 +27,18 @@ #include_next #else // !(__GNUC__ && POSIX) -#ifndef __SIZE_T -#define __SIZE_T +#ifndef __MES_SIZE_T +#define __MES_SIZE_T typedef long size_t; #endif +char* getenv (char const* s); +int atoi (char const *s); void *malloc (size_t); +void *realloc (void *p, size_t size); void exit (int); + #endif // !(__GNUC__ && POSIX) -#endif // __STDLIB_H +#endif // __MES_STDLIB_H diff --git a/libc/include/string.h b/libc/include/string.h index 932be142..42fe7c69 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -17,8 +17,8 @@ * 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 +#ifndef __MES_STRING_H +#define __MES_STRING_H 1 #if __GNUC__ && POSIX #ifndef _GNU_SOURCE @@ -28,8 +28,8 @@ #else // ! (__GNUC__ && POSIX) -#ifndef __SIZE_T -#define __SIZE_T +#ifndef __MES_SIZE_T +#define __MES_SIZE_T typedef long size_t; #endif @@ -39,4 +39,4 @@ int strncmp (char const*, char const*, size_t); char *strcpy (char *dest, char const *src); #endif // ! (__GNUC__ && POSIX) -#endif // __STRING_H +#endif // __MES_STRING_H diff --git a/libc/include/strings.h b/libc/include/strings.h new file mode 100644 index 00000000..0878530e --- /dev/null +++ b/libc/include/strings.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_STRINGS_H +#define __MES_STRINGS_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_STRINGS_H + diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h new file mode 100644 index 00000000..63c7dfa7 --- /dev/null +++ b/libc/include/sys/cdefs.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_SYS_CDEFS_H +#define __MES_SYS_CDEFS_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_SYS_CDEFS_H + diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h new file mode 100644 index 00000000..522a710a --- /dev/null +++ b/libc/include/sys/mman.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_SYS_MMAN_H +#define __MES_SYS_MMAN_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_SYS_MMAN_H + diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h new file mode 100644 index 00000000..6adae743 --- /dev/null +++ b/libc/include/sys/stat.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_SYS_STAT_H +#define __MES_SYS_STAT_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_SYS_STAT_H + diff --git a/libc/include/sys/time.h b/libc/include/sys/time.h new file mode 100644 index 00000000..de788912 --- /dev/null +++ b/libc/include/sys/time.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_SYS_TIME_H +#define __MES_SYS_TIME_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_SYS_TIME_H + diff --git a/libc/include/sys/timeb.h b/libc/include/sys/timeb.h new file mode 100644 index 00000000..2cd99087 --- /dev/null +++ b/libc/include/sys/timeb.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_SYS_TIMEB_H +#define __MES_SYS_TIMEB_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_SYS_TIMEB_H + diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h new file mode 100644 index 00000000..b7b05c67 --- /dev/null +++ b/libc/include/sys/types.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_SYS_TYPES_H +#define __MES_SYS_TYPES_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_SYS_TYPES_H + diff --git a/libc/include/sys/ucontext.h b/libc/include/sys/ucontext.h new file mode 100644 index 00000000..bdf9274f --- /dev/null +++ b/libc/include/sys/ucontext.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_SYS_UCONTEXT_H +#define __MES_SYS_UCONTEXT_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_SYS_UCONTEXT_H + diff --git a/libc/include/time.h b/libc/include/time.h new file mode 100644 index 00000000..b15cf52d --- /dev/null +++ b/libc/include/time.h @@ -0,0 +1,28 @@ +/* -*-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 __MES_TIME_H +#define __MES_TIME_H 1 + +#if __GNUC__ && POSIX +#include_next +#endif // (__GNUC__ && POSIX) + +#endif // __MES_TIME_H + diff --git a/libc/include/unistd.h b/libc/include/unistd.h index ae917a49..0ba84e57 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -17,8 +17,8 @@ * 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 +#ifndef __MES_UNISTD_H +#define __MES_UNISTD_H 1 #if __GNUC__ && POSIX #ifndef _GNU_SOURCE @@ -28,13 +28,14 @@ #else // ! (__GNUC__ && POSIX) -#ifndef __SIZE_T -#define __SIZE_T +#ifndef __MES_SIZE_T +#define __MES_SIZE_T typedef long size_t; #endif +int access (char const *s, int mode); int read (int fd, void* buf, size_t n); int write (int fd, char const* s, int n); #endif // ! (__GNUC__ && POSIX) -#endif // __UNISTD_H +#endif // __MES_UNISTD_H diff --git a/libc/libc-gcc.c b/libc/libc-gcc.c index cbe6ba86..83a58f93 100644 --- a/libc/libc-gcc.c +++ b/libc/libc-gcc.c @@ -305,7 +305,7 @@ strncmp (char const* a, char const* b, size_t length) return *a - *b; } -char const* +char * getenv (char const* s) { char **p = g_environment; diff --git a/libc/libc-mes.c b/libc/libc-mes.c index 3047683f..a5f074fa 100644 --- a/libc/libc-mes.c +++ b/libc/libc-mes.c @@ -292,7 +292,7 @@ strncmp (char const* a, char const* b, int length) } char **g_environment; -char const* +char * getenv (char const* s) { char **p = g_environment; diff --git a/make/install.make b/make/install.make index 270ed061..a048086b 100644 --- a/make/install.make +++ b/make/install.make @@ -99,6 +99,10 @@ install: $(CLEAN) ChangeLog mkdir -p $(DESTDIR)$(GODIR) tar -cf- -C module $(INSTALL_GO_FILES:module/%=%)\ | tar -C $(DESTDIR)$(GODIR) -xf- + mkdir -p $(DESTDIR)$(PREFIX)/lib + $(GIT_ARCHIVE_HEAD) libc/include \ + | tar -C $(DESTDIR)$(PREFIX) --strip=1 -xf- + cp out/libc/libc-mes.guile-o $(DESTDIR)$(PREFIX)/lib/libc-mes.o release: tree-clean-p check dist git tag v$(VERSION) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 54768b92..ae7369c4 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -54,35 +54,36 @@ (define mes? (pair? (current-module))) (define* (c99-input->ast #:key (defines '()) (includes '())) - (parse-c99 - #:inc-dirs (append includes (cons* "." "libc/include" "libc" "src" "out" "out/src" (string-split (getenv "C_INCLUDE_PATH") #\:))) - #:cpp-defs `( - "POSIX=0" - "_POSIX_SOURCE=0" - "__GNUC__=0" - "__MESC__=1" - "__NYACC__=1" ;; REMOVEME - "EOF=-1" - "STDIN=0" - "STDOUT=1" - "STDERR=2" - - "INT_MIN=-2147483648" - "INT_MAX=2147483647" - - "MES_FULL=0" - "FIXED_PRIMITIVES=1" - - ,(if mes? "__MESC_MES__=1" "__MESC_MES__=0") - - ,(string-append "DATADIR=\"" %datadir "\"") - ,(string-append "DOCDIR=\"" %docdir "\"") - ,(string-append "PREFIX=\"" %prefix "\"") - ,(string-append "MODULEDIR=\"" %moduledir "\"") - ,(string-append "VERSION=\"" %version "\"") - ,@defines - ) - #:mode 'code)) + (let ((include (if (equal? %prefix "") "libc/include" (string-append %prefix "/include")))) + (parse-c99 + #:inc-dirs (append includes (cons* "." "libc" "src" "out" "out/src" include (string-split (getenv "C_INCLUDE_PATH") #\:))) + #:cpp-defs `( + "POSIX=0" + "_POSIX_SOURCE=0" + "__GNUC__=0" + "__MESC__=1" + "__NYACC__=1" ;; REMOVEME + "EOF=-1" + "STDIN=0" + "STDOUT=1" + "STDERR=2" + + "INT_MIN=-2147483648" + "INT_MAX=2147483647" + + "MES_FULL=0" + "FIXED_PRIMITIVES=1" + + ,(if mes? "__MESC_MES__=1" "__MESC_MES__=0") + + ,(string-append "DATADIR=\"" %datadir "\"") + ,(string-append "DOCDIR=\"" %docdir "\"") + ,(string-append "PREFIX=\"" %prefix "\"") + ,(string-append "MODULEDIR=\"" %moduledir "\"") + ,(string-append "VERSION=\"" %version "\"") + ,@defines + ) + #:mode 'code))) (define (ast:function? o) (and (pair? o) (eq? (car o) 'fctn-defn))) diff --git a/src/lib.c b/src/lib.c index 81192026..c8fa1e0e 100644 --- a/src/lib.c +++ b/src/lib.c @@ -25,6 +25,8 @@ int g_depth; SCM fdisplay_ (SCM, int); +SCM display_helper (SCM x, int cont, char* sep, int fd); + SCM display_helper (SCM x, int cont, char* sep, int fd) { diff --git a/src/mes.c b/src/mes.c index 0c353a93..c43d4662 100644 --- a/src/mes.c +++ b/src/mes.c @@ -1239,6 +1239,8 @@ mes_builtins (SCM a) ///((internal)) return a; } +SCM read_input_file_env (SCM); + SCM load_env (SCM a) ///((internal)) { diff --git a/src/posix.c b/src/posix.c index 63a5ccc2..c404f8b8 100644 --- a/src/posix.c +++ b/src/posix.c @@ -19,6 +19,7 @@ */ #include +#include int ungetchar (int c)