diff --git a/eval.c b/eval.c index b91623e5..2b8510f9 100644 --- a/eval.c +++ b/eval.c @@ -2298,7 +2298,7 @@ sexp sexp_eval_string (sexp ctx, char *str) { return res; } -void sexp_scheme_init () { +void sexp_scheme_init (void) { sexp ctx; if (! scheme_initialized_p) { scheme_initialized_p = 1; diff --git a/gc.c b/gc.c index 7b4262de..c7e2e955 100644 --- a/gc.c +++ b/gc.c @@ -227,7 +227,7 @@ void* sexp_alloc (sexp ctx, size_t size) { return res; } -void sexp_gc_init () { +void sexp_gc_init (void) { sexp_uint_t size = sexp_heap_align(SEXP_INITIAL_HEAP_SIZE); heap = sexp_make_heap(size); #if USE_DEBUG_GC diff --git a/include/chibi/eval.h b/include/chibi/eval.h index 5dbc89d2..4184dd61 100644 --- a/include/chibi/eval.h +++ b/include/chibi/eval.h @@ -118,7 +118,7 @@ enum opcode_names { /**************************** prototypes ******************************/ -SEXP_API void sexp_scheme_init(); +SEXP_API void sexp_scheme_init(void); SEXP_API sexp sexp_apply(sexp context, sexp proc, sexp args); SEXP_API sexp sexp_eval(sexp context, sexp obj); SEXP_API sexp sexp_eval_string(sexp context, char *str); diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index 265e17d2..446671ea 100644 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -10,9 +10,11 @@ #include #include + #ifdef PLAN9 +#include +#include typedef unsigned long size_t; -#define offsetof(st, m) ((size_t) ((char*)&((st*)(0))->m - (char*)0)) #else #include #include @@ -103,7 +105,7 @@ typedef struct sexp_struct *sexp; #define SEXP_MIN_FIXNUM (-SEXP_MAX_FIXNUM-1) /* procedure types */ -typedef sexp (*sexp_proc0) (); +typedef sexp (*sexp_proc0) (void); typedef sexp (*sexp_proc1) (sexp); typedef sexp (*sexp_proc2) (sexp, sexp); typedef sexp (*sexp_proc3) (sexp, sexp, sexp); @@ -622,7 +624,7 @@ SEXP_API sexp sexp_user_exception (sexp ctx, sexp self, char *message, sexp obj) SEXP_API sexp sexp_type_exception (sexp ctx, char *message, sexp obj); SEXP_API sexp sexp_range_exception (sexp ctx, sexp obj, sexp start, sexp end); SEXP_API sexp sexp_print_exception(sexp ctx, sexp exn, sexp out); -SEXP_API void sexp_init(); +SEXP_API void sexp_init(void); #endif /* ! SEXP_H */ diff --git a/mkfile b/mkfile index 1c6fb068..3aff84cd 100644 --- a/mkfile +++ b/mkfile @@ -4,36 +4,22 @@ BIN=/$objtype/bin TARG=chibi-scheme MODDIR=/sys/lib/chibi-scheme -CPPFLAGS= -Iinclude -DPLAN9 -DUSE_STRING_STREAMS=0 -DUSE_DEBUG=0 -CFLAGS= -c -B $CPPFLAGS +CPPFLAGS= -Iinclude -DPLAN9 '-DUSE_STRING_STREAMS=0' '-DUSE_DEBUG=0' +CFLAGS= -p $CPPFLAGS OFILES=sexp.$O eval.$O main.$O -IFILES=${OFILES:%.$O=%.i} HFILES=include/chibi/sexp.h include/chibi/eval.h include/chibi/config.h include/chibi/install.h -%.i: %.c $HFILES - cpp $CPPFLAGS $stem.c > $target - -%.$O: %.i - $CC $CFLAGS -c -o $target $prereq - -all:V: $TARG + include/chibi/install.h -$TARG: $OFILES - $LD $LDFLAGS -o $target $prereq - -$BIN/%: % - cp $stem $target - -clean:V: - rm -f $IFILES $TARG *.[$OS] - install:V: $BIN/$TARG - mkdir -p $MODDIR + test -d $MODDIR || mkdir -p $MODDIR cp init.scm $MODDIR/ test:V: ./chibi-scheme tests/r5rs-tests.scm + +sexp.c:N: gc.c opt/bignum.c diff --git a/opt/bignum.c b/opt/bignum.c index 245c15e5..e7f9a2f9 100644 --- a/opt/bignum.c +++ b/opt/bignum.c @@ -186,12 +186,16 @@ sexp sexp_read_bignum (sexp ctx, sexp in, sexp_uint_t init, return sexp_bignum_normalize(res); } -#ifdef PLAN9 -#define log2(n) (log(n)/log(2)) -#endif +static int log2i(int v) { + int i; + for (i = 0; i < sizeof(v)*8; i++) + if ((1<<(i+1)) > v) + break; + return i; +} sexp sexp_write_bignum (sexp ctx, sexp a, sexp out, sexp_uint_t base) { - int i, str_len, lg_base = trunc(log2(base)); + int i, str_len, lg_base = log2i(base); char *data; sexp_gc_var(ctx, b, s_b); sexp_gc_var(ctx, str, s_str); diff --git a/sexp.c b/sexp.c index 4c4342a4..093c2d33 100644 --- a/sexp.c +++ b/sexp.c @@ -40,11 +40,11 @@ static char sexp_separators[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, /* x5_ */ }; -static int digit_value (c) { +static int digit_value (int c) { return (((c)<='9') ? ((c) - '0') : ((toupper(c) - 'A') + 10)); } -static int hex_digit (n) { +static int hex_digit (int n) { return ((n<=9) ? ('0' + n) : ('A' + n - 10)); } @@ -86,7 +86,7 @@ static struct sexp_struct sexp_type_specs[] = { _DEF_TYPE(SEXP_CORE, 0, 0, 0, 0, sexp_sizeof(core), 0, 0, "core-form"), _DEF_TYPE(SEXP_OPCODE, sexp_offsetof(opcode, data), 2, 0, 0, sexp_sizeof(opcode), 0, 0, "opcode"), _DEF_TYPE(SEXP_LAMBDA, sexp_offsetof(lambda, name), 8, 0, 0, sexp_sizeof(lambda), 0, 0, "lambda"), - _DEF_TYPE(SEXP_CND, sexp_offsetof(cnd, test), 3, 0, 0, sexp_sizeof(cnd), 0, 0, "conditoinal"), + _DEF_TYPE(SEXP_CND, sexp_offsetof(cnd, test), 3, 0, 0, sexp_sizeof(cnd), 0, 0, "conditional"), _DEF_TYPE(SEXP_REF, sexp_offsetof(ref, name), 2, 0, 0, sexp_sizeof(ref), 0, 0, "reference"), _DEF_TYPE(SEXP_SET, sexp_offsetof(set, var), 2, 0, 0, sexp_sizeof(set), 0, 0, "set!"), _DEF_TYPE(SEXP_SEQ, sexp_offsetof(seq, ls), 1, 0, 0, sexp_sizeof(seq), 0, 0, "sequence"), @@ -1357,7 +1357,7 @@ sexp sexp_write_to_string(sexp ctx, sexp obj) { return str; } -void sexp_init() { +void sexp_init(void) { int i; sexp ctx; if (! sexp_initialized_p) {