altos/scheme: More compiler warning cleanups
authorKeith Packard <keithp@keithp.com>
Wed, 13 Dec 2017 01:59:26 +0000 (17:59 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 13 Dec 2017 02:09:11 +0000 (18:09 -0800)
Make local funcs static. Don't mix decls and code.x

Signed-off-by: Keith Packard <keithp@keithp.com>
12 files changed:
src/scheme/ao_scheme.h
src/scheme/ao_scheme_builtin.c
src/scheme/ao_scheme_lambda.c
src/scheme/ao_scheme_make_const.c
src/scheme/ao_scheme_save.c
src/scheme/ao_scheme_stack.c
src/scheme/ao_scheme_string.c
src/scheme/make-const/Makefile
src/scheme/test/Makefile
src/scheme/test/ao_scheme_os.h
src/scheme/tiny-test/Makefile
src/scheme/tiny-test/ao_scheme_os.h

index 7e4b36973af6db382a162e219e586221b4463161..ad80db2f03cb433835d2e84c8da43b024ec7c8c5 100644 (file)
@@ -43,6 +43,10 @@ struct ao_scheme_os_save {
        uint16_t        const_checksum_inv;
 };
 
+#ifndef AO_SCHEME_POOL_TOTAL
+#error Must define AO_SCHEME_POOL_TOTAL for AO_SCHEME_SAVE
+#endif
+
 #define AO_SCHEME_POOL_EXTRA   (sizeof(struct ao_scheme_os_save))
 #define AO_SCHEME_POOL ((int) (AO_SCHEME_POOL_TOTAL - AO_SCHEME_POOL_EXTRA))
 
@@ -78,7 +82,7 @@ extern uint8_t ao_scheme_const[AO_SCHEME_POOL_CONST] __attribute__((aligned(4)))
 #else
 #include "ao_scheme_const.h"
 #ifndef AO_SCHEME_POOL
-#define AO_SCHEME_POOL 3072
+#error Must define AO_SCHEME_POOL
 #endif
 #ifndef AO_SCHEME_POOL_EXTRA
 #define AO_SCHEME_POOL_EXTRA 0
@@ -560,21 +564,10 @@ extern uint64_t ao_scheme_collects[2];
 extern uint64_t ao_scheme_freed[2];
 extern uint64_t ao_scheme_loops[2];
 
-/* returns 1 if the object was already marked */
-int
-ao_scheme_mark(const struct ao_scheme_type *type, void *addr);
-
 /* returns 1 if the object was already marked */
 int
 ao_scheme_mark_memory(const struct ao_scheme_type *type, void *addr);
 
-void *
-ao_scheme_move_map(void *addr);
-
-/* returns 1 if the object was already moved */
-int
-ao_scheme_move(const struct ao_scheme_type *type, void **ref);
-
 /* returns 1 if the object was already moved */
 int
 ao_scheme_move_memory(const struct ao_scheme_type *type, void **ref);
@@ -635,7 +628,7 @@ void
 ao_scheme_bool_write(ao_poly v);
 
 #ifdef AO_SCHEME_MAKE_CONST
-struct ao_scheme_bool  *ao_scheme_true, *ao_scheme_false;
+extern struct ao_scheme_bool   *ao_scheme_true, *ao_scheme_false;
 
 struct ao_scheme_bool *
 ao_scheme_bool_get(uint8_t value);
@@ -825,12 +818,8 @@ ao_scheme_number_typep(uint8_t t)
 {
        return ao_scheme_integer_typep(t) || (t == AO_SCHEME_FLOAT);
 }
-
-float
-ao_scheme_poly_number(ao_poly p);
 #else
 #define ao_scheme_number_typep ao_scheme_integer_typep
-#define ao_scheme_poly_number ao_scheme_poly_integer
 #endif
 
 /* builtin */
index 4def57045bbea9c56d77a34936941c644cf5805f..b67889930a33fbc47833435fd032c962a04c4edb 100644 (file)
@@ -127,7 +127,7 @@ ao_scheme_check_argt(ao_poly name, struct ao_scheme_cons *cons, int argc, int ty
        return _ao_scheme_bool_true;
 }
 
-int32_t
+static int32_t
 ao_scheme_arg_int(ao_poly name, struct ao_scheme_cons *cons, int argc)
 {
        ao_poly p = ao_scheme_arg(cons, argc);
@@ -306,10 +306,10 @@ ao_scheme_do_display(struct ao_scheme_cons *cons)
        return _ao_scheme_bool_true;
 }
 
-ao_poly
+static ao_poly
 ao_scheme_math(struct ao_scheme_cons *orig_cons, enum ao_scheme_builtin_id op)
 {
-       struct ao_scheme_cons *cons = cons;
+       struct ao_scheme_cons *cons;
        ao_poly ret = AO_SCHEME_NIL;
 
        for (cons = orig_cons; cons; cons = ao_scheme_cons_cdr(cons)) {
@@ -501,7 +501,7 @@ ao_scheme_do_remainder(struct ao_scheme_cons *cons)
        return ao_scheme_math(cons, builtin_remainder);
 }
 
-ao_poly
+static ao_poly
 ao_scheme_compare(struct ao_scheme_cons *cons, enum ao_scheme_builtin_id op)
 {
        ao_poly left;
@@ -545,6 +545,7 @@ ao_scheme_compare(struct ao_scheme_cons *cons, enum ao_scheme_builtin_id op)
                                default:
                                        break;
                                }
+#ifdef AO_SCHEME_FEATURE_FLOAT
                        } else if (ao_scheme_number_typep(lt) && ao_scheme_number_typep(rt)) {
                                float l, r;
 
@@ -574,6 +575,7 @@ ao_scheme_compare(struct ao_scheme_cons *cons, enum ao_scheme_builtin_id op)
                                default:
                                        break;
                                }
+#endif /* AO_SCHEME_FEATURE_FLOAT */
                        } else if (lt == AO_SCHEME_STRING && rt == AO_SCHEME_STRING) {
                                int c = strcmp(ao_scheme_poly_string(left),
                                               ao_scheme_poly_string(right));
index ec6f858c2f4fa99d95f72d8c3e01c2b93b7dd2cf..be87f4d1995d12bf8e1c7b58b6e5f5bf4338a491 100644 (file)
 
 #include "ao_scheme.h"
 
-int
+static int
 lambda_size(void *addr)
 {
        (void) addr;
        return sizeof (struct ao_scheme_lambda);
 }
 
-void
+static void
 lambda_mark(void *addr)
 {
        struct ao_scheme_lambda *lambda = addr;
@@ -33,7 +33,7 @@ lambda_mark(void *addr)
        ao_scheme_poly_mark(lambda->frame, 0);
 }
 
-void
+static void
 lambda_move(void *addr)
 {
        struct ao_scheme_lambda *lambda = addr;
@@ -65,7 +65,7 @@ ao_scheme_lambda_write(ao_poly poly)
        printf(")");
 }
 
-ao_poly
+static ao_poly
 ao_scheme_lambda_alloc(struct ao_scheme_cons *code, int args)
 {
        struct ao_scheme_lambda *lambda;
index d0a51ec8e9554846f8b5733bf16ff0845e2644c7..51bb1269a99d61cbebbb0c12d37653fca3dfa379 100644 (file)
@@ -80,7 +80,7 @@ ao_fec_crc_byte(uint8_t byte, uint16_t crc)
        return crc;
 }
 
-uint16_t
+static uint16_t
 ao_fec_crc(const uint8_t *bytes, uint8_t len)
 {
        uint16_t        crc = AO_FEC_CRC_INIT;
@@ -97,7 +97,7 @@ struct ao_scheme_macro_stack {
 
 struct ao_scheme_macro_stack *macro_stack;
 
-int
+static int
 ao_scheme_macro_push(ao_poly p)
 {
        struct ao_scheme_macro_stack *m = macro_stack;
@@ -114,7 +114,7 @@ ao_scheme_macro_push(ao_poly p)
        return 0;
 }
 
-void
+static void
 ao_scheme_macro_pop(void)
 {
        struct ao_scheme_macro_stack *m = macro_stack;
@@ -141,7 +141,7 @@ void indent(void)
 ao_poly
 ao_has_macro(ao_poly p);
 
-ao_poly
+static ao_poly
 ao_macro_test_get(ao_poly atom)
 {
        ao_poly *ref = ao_scheme_atom_ref(atom, NULL);
@@ -150,7 +150,7 @@ ao_macro_test_get(ao_poly atom)
        return AO_SCHEME_NIL;
 }
 
-ao_poly
+static ao_poly
 ao_is_macro(ao_poly p)
 {
        struct ao_scheme_builtin        *builtin;
@@ -269,7 +269,7 @@ ao_scheme_seen_builtin(struct ao_scheme_builtin *b)
        return 0;
 }
 
-int
+static int
 ao_scheme_read_eval_abort(void)
 {
        ao_poly in, out = AO_SCHEME_NIL;
@@ -297,7 +297,7 @@ struct feature {
 static struct feature *enable;
 static struct feature *disable;
 
-void
+static void
 ao_scheme_add_feature(struct feature **list, char *name)
 {
        struct feature *feature = malloc (sizeof (struct feature) + strlen(name) + 1);
@@ -359,6 +359,7 @@ main(int argc, char **argv)
        ao_poly val;
        struct ao_scheme_atom   *a;
        struct ao_scheme_builtin        *b;
+       struct feature                  *d;
        int     in_atom = 0;
        char    *out_name = NULL;
        int     c;
@@ -394,6 +395,7 @@ main(int argc, char **argv)
 
        prev_func = _builtin_last;
        target_func = 0;
+       b = NULL;
        for (f = 0; f < (int) N_FUNC; f++) {
                if (ao_scheme_has_feature(enable, funcs[f].feature) || !ao_scheme_has_feature(disable, funcs[f].feature)) {
                        if (funcs[f].func != prev_func) {
@@ -467,6 +469,9 @@ main(int argc, char **argv)
 
        fprintf(out, "/* Generated file, do not edit */\n\n");
 
+       for (d = disable; d; d = d->next)
+               fprintf(out, "#undef AO_SCHEME_FEATURE_%s\n", d->name);
+
        fprintf(out, "#define AO_SCHEME_POOL_CONST %d\n", ao_scheme_top);
        fprintf(out, "extern const uint8_t ao_scheme_const[AO_SCHEME_POOL_CONST] __attribute__((aligned(4)));\n");
        fprintf(out, "#define ao_builtin_atoms 0x%04x\n", ao_scheme_atom_poly(ao_scheme_atoms));
index af9345b8d34a88c75eacb5bc6a11cefb1ce0761e..3a595d71319beecdb28cf81e2acbc94402f7a1d5 100644 (file)
 ao_poly
 ao_scheme_do_save(struct ao_scheme_cons *cons)
 {
+#ifdef AO_SCHEME_SAVE
+       struct ao_scheme_os_save *os;
+#endif
+
        if (!ao_scheme_check_argc(_ao_scheme_atom_save, cons, 0, 0))
                return AO_SCHEME_NIL;
 
 #ifdef AO_SCHEME_SAVE
-       struct ao_scheme_os_save *os = (struct ao_scheme_os_save *) (void *) &ao_scheme_pool[AO_SCHEME_POOL];
+       os = (struct ao_scheme_os_save *) (void *) &ao_scheme_pool[AO_SCHEME_POOL];
 
        ao_scheme_collect(AO_SCHEME_COLLECT_FULL);
        os->atoms = ao_scheme_atom_poly(ao_scheme_atoms);
@@ -38,12 +42,15 @@ ao_scheme_do_save(struct ao_scheme_cons *cons)
 ao_poly
 ao_scheme_do_restore(struct ao_scheme_cons *cons)
 {
+#ifdef AO_SCHEME_SAVE
+       struct ao_scheme_os_save save;
+       struct ao_scheme_os_save *os = (struct ao_scheme_os_save *) (void *) &ao_scheme_pool[AO_SCHEME_POOL];
+#endif
        if (!ao_scheme_check_argc(_ao_scheme_atom_save, cons, 0, 0))
                return AO_SCHEME_NIL;
 
 #ifdef AO_SCHEME_SAVE
-       struct ao_scheme_os_save save;
-       struct ao_scheme_os_save *os = (struct ao_scheme_os_save *) (void *) &ao_scheme_pool[AO_SCHEME_POOL];
+       os = (struct ao_scheme_os_save *) (void *) &ao_scheme_pool[AO_SCHEME_POOL];
 
        if (!ao_scheme_os_restore_save(&save, AO_SCHEME_POOL))
                return ao_scheme_error(AO_SCHEME_INVALID, "header restore failed");
index d19dd6d6d59f1226979041fc278b384c9e77a712..e062a09332f8fb1e24d07e9753e0c781761485d6 100644 (file)
@@ -221,11 +221,12 @@ ao_scheme_stack_copy(struct ao_scheme_stack *old)
 ao_poly
 ao_scheme_stack_eval(void)
 {
+       struct ao_scheme_cons   *cons;
        struct ao_scheme_stack  *new = ao_scheme_stack_copy(ao_scheme_poly_stack(ao_scheme_v));
        if (!new)
                return AO_SCHEME_NIL;
 
-       struct ao_scheme_cons   *cons = ao_scheme_poly_cons(ao_scheme_stack->values);
+       cons = ao_scheme_poly_cons(ao_scheme_stack->values);
 
        if (!cons || !cons->cdr)
                return ao_scheme_error(AO_SCHEME_INVALID, "continuation requires a value");
index e25306cbea087d6a0964c346266ce552472d0c76..ada626c3091c1a7a3b68943e90e94f8c8236b271 100644 (file)
@@ -45,9 +45,10 @@ char *
 ao_scheme_string_copy(char *a)
 {
        int     alen = strlen(a);
+       char    *r;
 
        ao_scheme_string_stash(0, a);
-       char    *r = ao_scheme_alloc(alen + 1);
+       r = ao_scheme_alloc(alen + 1);
        a = ao_scheme_string_fetch(0);
        if (!r)
                return NULL;
@@ -60,10 +61,11 @@ ao_scheme_string_cat(char *a, char *b)
 {
        int     alen = strlen(a);
        int     blen = strlen(b);
+       char    *r;
 
        ao_scheme_string_stash(0, a);
        ao_scheme_string_stash(1, b);
-       char    *r = ao_scheme_alloc(alen + blen + 1);
+       r = ao_scheme_alloc(alen + blen + 1);
        a = ao_scheme_string_fetch(0);
        b = ao_scheme_string_fetch(1);
        if (!r)
@@ -76,11 +78,15 @@ ao_scheme_string_cat(char *a, char *b)
 ao_poly
 ao_scheme_string_pack(struct ao_scheme_cons *cons)
 {
-       int     len = ao_scheme_cons_length(cons);
+       char    *r;
+       char    *s;
+       int     len;
+
+       len = ao_scheme_cons_length(cons);
        ao_scheme_cons_stash(0, cons);
-       char    *r = ao_scheme_alloc(len + 1);
+       r = ao_scheme_alloc(len + 1);
        cons = ao_scheme_cons_fetch(0);
-       char    *s = r;
+       s = r;
 
        while (cons) {
                if (!ao_scheme_integer_typep(ao_scheme_poly_type(cons->car)))
@@ -100,10 +106,11 @@ ao_scheme_string_unpack(char *a)
        int                     i;
 
        for (i = 0; (c = a[i]); i++) {
+               struct ao_scheme_cons   *n;
                ao_scheme_cons_stash(0, cons);
                ao_scheme_cons_stash(1, tail);
                ao_scheme_string_stash(0, a);
-               struct ao_scheme_cons   *n = ao_scheme_cons_cons(ao_scheme_int_poly(c), AO_SCHEME_NIL);
+               n = ao_scheme_cons_cons(ao_scheme_int_poly(c), AO_SCHEME_NIL);
                a = ao_scheme_string_fetch(0);
                cons = ao_scheme_cons_fetch(0);
                tail = ao_scheme_cons_fetch(1);
index caf7acbe2ba3702e0b1372f73c6befeacd2bbe97..438b6a79eec7f47fb8a1312a6c6a755efbd45973 100644 (file)
@@ -10,7 +10,7 @@ HDRS=$(SCHEME_HDRS) ao_scheme_os.h
 OBJS=$(SRCS:.c=.o)
 
 CC=cc
-CFLAGS=-DAO_SCHEME_MAKE_CONST -O0 -g -I. -Wall -Wextra
+CFLAGS=-DAO_SCHEME_MAKE_CONST -O2 -g -I. -Wall -Wextra -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Wlogical-op -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast
 
 .c.o:
        $(CC) -c $(CFLAGS) $< -o $@
index d1bc4239a68104b20e6e021d10190b3d8d9c50b2..d51fa7ba8287e77ba5635b9199055af8314f4647 100644 (file)
@@ -9,7 +9,7 @@ HDRS=$(SCHEME_HDRS) ao_scheme_const.h
 
 OBJS=$(SRCS:.c=.o)
 
-CFLAGS=-O2 -g -Wall -Wextra -I. -I..
+CFLAGS=-O2 -g -Wall -Wextra -I. -I.. -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Wlogical-op -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast
 
 ao-scheme: $(OBJS)
        cc $(CFLAGS) -o $@ $(OBJS) -lm
index 958f68be123c764627eaee01d04b5bb7d1d0caf5..b225b2e874302ab458569fd97c72277f8a5a9a68 100644 (file)
@@ -28,7 +28,7 @@
 extern int ao_scheme_getc(void);
 
 static inline void
-ao_scheme_os_flush() {
+ao_scheme_os_flush(void) {
        fflush(stdout);
 }
 
index 5082df4480e0d3acbb986f2d6d09d60b344111e3..6b1fe0036e8e47bebd8cc092f7cee72aa50c6412 100644 (file)
@@ -11,7 +11,7 @@ HDRS=$(SCHEME_HDRS) ao_scheme_const.h
 
 OBJS=$(SRCS:.c=.o)
 
-CFLAGS=-O0 -g -Wall -Wextra -I. -I..
+CFLAGS=-O0 -g -Wall -Wextra -I. -I.. -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Wlogical-op -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast
 
 ao-scheme-tiny: $(OBJS)
        cc $(CFLAGS) -o $@ $(OBJS) -lm
index 7cfe39817d08153f65ea811f5a0662e3a6db9305..b9f3e31f607f080c4fdc13e970e745ba04a4c495 100644 (file)
 #include <stdlib.h>
 #include <time.h>
 
-#undef AO_SCHEME_FEATURE_FLOAT
-#undef AO_SCHEME_FEATURE_VECTOR
-#undef AO_SCHEME_FEATURE_QUASI
-#undef AO_SCHEME_FEATURE_BIGINT
-
 #define AO_SCHEME_POOL_TOTAL   4096
 #define AO_SCHEME_SAVE         1
 
 extern int ao_scheme_getc(void);
 
 static inline void
-ao_scheme_os_flush() {
+ao_scheme_os_flush(void) {
        fflush(stdout);
 }