From a46c318bb81e2098a9226a7c3455fabb6fd012a7 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 13 May 2019 01:07:32 +0200 Subject: [PATCH] mes: Grand indent: prepare. * build-aux/indent.sh: New file. * include/mes/builtins.h: Move from src/builtins.h. * include/fcntl.h: Use // *INDENT-OFF* to prevent indent breakage. * include/locale.h: Likewise. * include/signal.h: Likewise. * include/sys/stat.h: Likewise. * include/sys/user.h: Likewise. * lib/linux/x86-mes-gcc/crt0.c: Likewise. * lib/linux/x86-mes-gcc/crt1.c: Likewise. * lib/linux/x86-mes-gcc/mes.c: Likewise. * lib/linux/x86-mes-gcc/mini.c: Likewise. * lib/linux/x86_64-mes-gcc/crt0.c: Likewise. * lib/linux/x86_64-mes-gcc/crt1.c: Likewise. * lib/linux/x86_64-mes-gcc/mes.c: Likewise. * lib/linux/x86_64-mes-gcc/mini.c: Likewise. * lib/x86_64-mes-gcc/setjmp.c: Likewise. * src/mes.c: Likewise. * src/reader.c: Likewise. --- build-aux/indent.sh | 21 ++++++++++++++ include/fcntl.h | 2 ++ include/locale.h | 3 ++ {src => include/mes}/builtins.h | 0 include/signal.h | 50 ++++++++++++++++----------------- include/sys/stat.h | 2 ++ include/sys/user.h | 46 +++++++++++++++--------------- lib/linux/x86-mes-gcc/crt0.c | 1 + lib/linux/x86-mes-gcc/crt1.c | 1 + lib/linux/x86-mes-gcc/mes.c | 1 + lib/linux/x86-mes-gcc/mini.c | 1 + lib/linux/x86_64-mes-gcc/crt0.c | 1 + lib/linux/x86_64-mes-gcc/crt1.c | 1 + lib/linux/x86_64-mes-gcc/mes.c | 1 + lib/linux/x86_64-mes-gcc/mini.c | 1 + lib/x86-mes-gcc/setjmp.c | 5 +++- lib/x86_64-mes-gcc/setjmp.c | 4 +++ src/mes.c | 2 +- src/reader.c | 5 ++-- 19 files changed, 96 insertions(+), 52 deletions(-) create mode 100755 build-aux/indent.sh rename {src => include/mes}/builtins.h (100%) diff --git a/build-aux/indent.sh b/build-aux/indent.sh new file mode 100755 index 00000000..130416c3 --- /dev/null +++ b/build-aux/indent.sh @@ -0,0 +1,21 @@ +#! /bin/sh + +# GNU Mes --- Maxwell Equations of Software +# Copyright © 2019 Jan (janneke) Nieuwenhuizen +# +# 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 . + +for i in $(find . -name '*.c' -o -name '*.h' -o -name '*.i'); do indent $i --no-tabs --line-length 110 --honour-newlines; done diff --git a/include/fcntl.h b/include/fcntl.h index 2980d47b..5d2e7bb4 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -29,6 +29,7 @@ #else // ! WITH_GLIBC +// *INDENT-OFF* #define O_RDONLY 0 #define O_WRONLY 1 #define O_RDWR 2 @@ -37,6 +38,7 @@ #define O_TRUNC 0x200 #define O_APPEND 0x400 #define O_DIRECTORY 0x10000 +// *INDENT-ON* #define FD_CLOEXEC 1 diff --git a/include/locale.h b/include/locale.h index 06a10b06..12b145a0 100644 --- a/include/locale.h +++ b/include/locale.h @@ -29,12 +29,15 @@ #else // ! WITH_GLIBC +// *INDENT-OFF* #ifndef LC_ALL #define LC_CTYPE 0 #define LC_NUMERIC 1 #define LC_COLLATE 3 #define LC_ALL 6 #endif +// *INDENT-ON* + char * setlocale (int category, char const *locale); #endif // ! WITH_GLIBC diff --git a/src/builtins.h b/include/mes/builtins.h similarity index 100% rename from src/builtins.h rename to include/mes/builtins.h diff --git a/include/signal.h b/include/signal.h index e6ed8070..db127752 100644 --- a/include/signal.h +++ b/include/signal.h @@ -31,6 +31,7 @@ typedef long stack_t; #include +// *INDENT-OFF* #define NSIG 30 #define SIGHUP 1 #define SIGINT 2 @@ -85,35 +86,34 @@ typedef long stack_t; #define SA_NOMASK SA_NODEFER #define SA_ONESHOT SA_RESETHAND - typedef struct siginfo_t { - int si_signo; - int si_errno; - int si_code; - int si_trapno; - pid_t si_pid; - uid_t si_uid; - int si_status; - clock_t si_utime; - clock_t si_stime; - sigval_t si_value; - int si_int; - void *si_ptr; - int si_overrun; - int si_timerid; - void *si_addr; - long si_band; - int si_fd; - short si_addr_lsb; - void *si_lower; - void *si_upper; - int si_pkey; - void *si_call_addr; - int si_syscall; + int si_signo; + int si_errno; + int si_code; + int si_trapno; + pid_t si_pid; + uid_t si_uid; + int si_status; + clock_t si_utime; + clock_t si_stime; + sigval_t si_value; + int si_int; + void *si_ptr; + int si_overrun; + int si_timerid; + void *si_addr; + long si_band; + int si_fd; + short si_addr_lsb; + void *si_lower; + void *si_upper; + int si_pkey; + void *si_call_addr; + int si_syscall; unsigned int si_arch; } siginfo_t; - +// *INDENT-ON* #if __MESC__ typedef long sighandler_t; diff --git a/include/sys/stat.h b/include/sys/stat.h index aab69a9a..f25d5713 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -34,6 +34,7 @@ typedef int mode_t; #endif +// *INDENT-OFF* #if __i386__ struct stat { @@ -79,6 +80,7 @@ struct stat unsigned long __foo1; }; #endif +// *INDENT-ON* int chmod (char const *file_name, mode_t mode); int mkdir (char const *file_name, mode_t mode); diff --git a/include/sys/user.h b/include/sys/user.h index 04513cf0..99d29dd9 100644 --- a/include/sys/user.h +++ b/include/sys/user.h @@ -77,32 +77,34 @@ struct user_regs_struct long int xss; }; +// *INDENT-OFF* struct user { - struct user_regs_struct regs; - int u_fpvalid; - struct user_fpregs_struct i387; - unsigned long int u_tsize; - unsigned long int u_dsize; - unsigned long int u_ssize; - unsigned long int start_code; - unsigned long int start_stack; - long int signal; - int reserved; - struct user_regs_struct* u_ar0; - struct user_fpregs_struct* u_fpstate; - unsigned long int magic; - char u_comm [32]; - int u_debugreg [8]; + struct user_regs_struct regs; + int u_fpvalid; + struct user_fpregs_struct i387; + unsigned long int u_tsize; + unsigned long int u_dsize; + unsigned long int u_ssize; + unsigned long int start_code; + unsigned long int start_stack; + long int signal; + int reserved; + struct user_regs_struct *u_ar0; + struct user_fpregs_struct *u_fpstate; + unsigned long int magic; + char u_comm [32]; + int u_debugreg [8]; }; -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1UL << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE-1)) -#define NBPG PAGE_SIZE -#define UPAGES 1 -#define HOST_TEXT_START_ADDR (u.start_code) -#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE-1)) +#define NBPG PAGE_SIZE +#define UPAGES 1 +#define HOST_TEXT_START_ADDR (u.start_code) +#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) +// *INDENT-ON* #endif // ! WITH_GLIBC diff --git a/lib/linux/x86-mes-gcc/crt0.c b/lib/linux/x86-mes-gcc/crt0.c index 8f46282f..91bfda8b 100644 --- a/lib/linux/x86-mes-gcc/crt0.c +++ b/lib/linux/x86-mes-gcc/crt0.c @@ -26,6 +26,7 @@ #include int _main (int argc, char *argv[]); +// *INDENT-OFF* void _start () { diff --git a/lib/linux/x86-mes-gcc/crt1.c b/lib/linux/x86-mes-gcc/crt1.c index a1c721e2..a909199b 100644 --- a/lib/linux/x86-mes-gcc/crt1.c +++ b/lib/linux/x86-mes-gcc/crt1.c @@ -21,6 +21,7 @@ #include //int main (int argc, char *argv[], char *envp[]); +// *INDENT-OFF* void _start () { diff --git a/lib/linux/x86-mes-gcc/mes.c b/lib/linux/x86-mes-gcc/mes.c index 261bdfe7..f6eb4e80 100644 --- a/lib/linux/x86-mes-gcc/mes.c +++ b/lib/linux/x86-mes-gcc/mes.c @@ -21,6 +21,7 @@ #include #include +// *INDENT-OFF* long _sys_call (long sys_call) { diff --git a/lib/linux/x86-mes-gcc/mini.c b/lib/linux/x86-mes-gcc/mini.c index 5e7cfc8a..b247f6e9 100644 --- a/lib/linux/x86-mes-gcc/mini.c +++ b/lib/linux/x86-mes-gcc/mini.c @@ -21,6 +21,7 @@ #define SYS_exit "0x01" #define SYS_write "0x04" +// *INDENT-OFF* void _exit (int code) { diff --git a/lib/linux/x86_64-mes-gcc/crt0.c b/lib/linux/x86_64-mes-gcc/crt0.c index b0fd0357..eb9547e8 100644 --- a/lib/linux/x86_64-mes-gcc/crt0.c +++ b/lib/linux/x86_64-mes-gcc/crt0.c @@ -29,6 +29,7 @@ int main (int argc, char *argv[]); // gcc x86_64 calling convention: // rdi, rsi, rdx, rcx, r8, r9, , +// *INDENT-OFF* void _start () { diff --git a/lib/linux/x86_64-mes-gcc/crt1.c b/lib/linux/x86_64-mes-gcc/crt1.c index ed4cacef..fa066950 100644 --- a/lib/linux/x86_64-mes-gcc/crt1.c +++ b/lib/linux/x86_64-mes-gcc/crt1.c @@ -24,6 +24,7 @@ // gcc x86_64 calling convention: // rdi, rsi, rdx, rcx, r8, r9, , +// *INDENT-OFF* void _start () { diff --git a/lib/linux/x86_64-mes-gcc/mes.c b/lib/linux/x86_64-mes-gcc/mes.c index 5e4d6b9e..15fc81c6 100644 --- a/lib/linux/x86_64-mes-gcc/mes.c +++ b/lib/linux/x86_64-mes-gcc/mes.c @@ -28,6 +28,7 @@ // #define R0 rax // #define R1 rdi +// *INDENT-OFF* long _sys_call (long sys_call) { diff --git a/lib/linux/x86_64-mes-gcc/mini.c b/lib/linux/x86_64-mes-gcc/mini.c index 115957b1..1f70382b 100644 --- a/lib/linux/x86_64-mes-gcc/mini.c +++ b/lib/linux/x86_64-mes-gcc/mini.c @@ -21,6 +21,7 @@ #define SYS_exit "0x3c" #define SYS_write "0x01" +// *INDENT-OFF* void _exit (int code) { diff --git a/lib/x86-mes-gcc/setjmp.c b/lib/x86-mes-gcc/setjmp.c index 3643b464..63ba1857 100644 --- a/lib/x86-mes-gcc/setjmp.c +++ b/lib/x86-mes-gcc/setjmp.c @@ -24,13 +24,16 @@ void longjmp (jmp_buf env, int val) { val = val == 0 ? 1 : val; - asm ("mov 0x8(%ebp),%ebp\n\t" // env* + // *INDENT-OFF* + asm ( + "mov 0x8(%ebp),%ebp\n\t" // env* "mov 0x4(%ebp),%ebx\n\t" // env->__pc "mov 0x8(%ebp),%esp\n\t" // env->__sp "mov 0x0(%ebp),%ebp\n\t" // env->__bp "jmp *%ebx\n\t" // jmp *PC ); + // *INDENT-ON* // not reached exit (42); } diff --git a/lib/x86_64-mes-gcc/setjmp.c b/lib/x86_64-mes-gcc/setjmp.c index 8967b0fd..85bb3894 100644 --- a/lib/x86_64-mes-gcc/setjmp.c +++ b/lib/x86_64-mes-gcc/setjmp.c @@ -24,12 +24,14 @@ void longjmp (jmp_buf env, int val) { val = val == 0 ? 1 : val; + // *INDENT-OFF* asm ( "mov 0x00(%rdi),%rbp\n\t" // env->__bp "mov 0x08(%rdi),%rbx\n\t" // env->__pc "mov 0x10(%rdi),%rsp\n\t" // env->__sp "jmp *%rbx\n\t" // jmp *PC ); + // *INDENT-ON* // not reached exit (42); } @@ -38,10 +40,12 @@ int setjmp (jmp_buf env) { long *p; + // *INDENT-OFF* asm ("mov %%rbp,%0" : "=r" (p) : //no inputs "" ); + // *INDENT-ON* env[0].__bp = p; env[0].__pc = p[1]; env[0].__sp = p[0]; diff --git a/src/mes.c b/src/mes.c index a4ba0812..9c37b784 100644 --- a/src/mes.c +++ b/src/mes.c @@ -385,7 +385,7 @@ struct scm *g_news = 0; // CONSTANT cell_test 118 #define cell_test 118 -#include "builtins.h" +#include "mes/builtins.h" #define TYPE(x) g_cells[x].type #define CAR(x) g_cells[x].car diff --git a/src/reader.c b/src/reader.c index 63e2ec10..2f0783e6 100644 --- a/src/reader.c +++ b/src/reader.c @@ -232,10 +232,9 @@ reader_read_hash (int c, SCM a) if (c == ':') { SCM x = reader_read_identifier_or_number (readchar ()); + SCM msg = MAKE_STRING0 ("keyword perifx ':' not followed by a symbol: "); if (TYPE (x) == TNUMBER) - error (cell_symbol_system_error, // READ error - cons (MAKE_STRING0 ("keyword perifx ':' not followed by a symbol: "), - x)); + error (cell_symbol_system_error, cons (msg, x)); return symbol_to_keyword (x); } if (c == 'b')