more cleanup and portability fixes

Using <u.h> and <libc.h> for plan9, no need for separate .i file
construction.  Also mkfile now simplified and using /sys/src/cmd/mkone
(thanks to Charles Forsyth).
This commit is contained in:
Alex Shinn 2009-07-14 00:34:23 +09:00
parent 6d709264bd
commit 5d94079e4a
7 changed files with 26 additions and 34 deletions

2
eval.c
View file

@ -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;

2
gc.c
View file

@ -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

View file

@ -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);

View file

@ -10,9 +10,11 @@
#include <ctype.h>
#include <stdio.h>
#ifdef PLAN9
#include <u.h>
#include <libc.h>
typedef unsigned long size_t;
#define offsetof(st, m) ((size_t) ((char*)&((st*)(0))->m - (char*)0))
#else
#include <stddef.h>
#include <stdlib.h>
@ -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 */

26
mkfile
View file

@ -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
</sys/src/cmd/mkone
include/chibi/install.h: mkfile
echo '#define sexp_module_dir "'$MODDIR'"' > 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

View file

@ -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);

8
sexp.c
View file

@ -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) {