mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-04 19:56:36 +02:00
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:
parent
6d709264bd
commit
5d94079e4a
7 changed files with 26 additions and 34 deletions
2
eval.c
2
eval.c
|
@ -2298,7 +2298,7 @@ sexp sexp_eval_string (sexp ctx, char *str) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sexp_scheme_init () {
|
void sexp_scheme_init (void) {
|
||||||
sexp ctx;
|
sexp ctx;
|
||||||
if (! scheme_initialized_p) {
|
if (! scheme_initialized_p) {
|
||||||
scheme_initialized_p = 1;
|
scheme_initialized_p = 1;
|
||||||
|
|
2
gc.c
2
gc.c
|
@ -227,7 +227,7 @@ void* sexp_alloc (sexp ctx, size_t size) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sexp_gc_init () {
|
void sexp_gc_init (void) {
|
||||||
sexp_uint_t size = sexp_heap_align(SEXP_INITIAL_HEAP_SIZE);
|
sexp_uint_t size = sexp_heap_align(SEXP_INITIAL_HEAP_SIZE);
|
||||||
heap = sexp_make_heap(size);
|
heap = sexp_make_heap(size);
|
||||||
#if USE_DEBUG_GC
|
#if USE_DEBUG_GC
|
||||||
|
|
|
@ -118,7 +118,7 @@ enum opcode_names {
|
||||||
|
|
||||||
/**************************** prototypes ******************************/
|
/**************************** 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_apply(sexp context, sexp proc, sexp args);
|
||||||
SEXP_API sexp sexp_eval(sexp context, sexp obj);
|
SEXP_API sexp sexp_eval(sexp context, sexp obj);
|
||||||
SEXP_API sexp sexp_eval_string(sexp context, char *str);
|
SEXP_API sexp sexp_eval_string(sexp context, char *str);
|
||||||
|
|
|
@ -10,9 +10,11 @@
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef PLAN9
|
#ifdef PLAN9
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
typedef unsigned long size_t;
|
typedef unsigned long size_t;
|
||||||
#define offsetof(st, m) ((size_t) ((char*)&((st*)(0))->m - (char*)0))
|
|
||||||
#else
|
#else
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -103,7 +105,7 @@ typedef struct sexp_struct *sexp;
|
||||||
#define SEXP_MIN_FIXNUM (-SEXP_MAX_FIXNUM-1)
|
#define SEXP_MIN_FIXNUM (-SEXP_MAX_FIXNUM-1)
|
||||||
|
|
||||||
/* procedure types */
|
/* procedure types */
|
||||||
typedef sexp (*sexp_proc0) ();
|
typedef sexp (*sexp_proc0) (void);
|
||||||
typedef sexp (*sexp_proc1) (sexp);
|
typedef sexp (*sexp_proc1) (sexp);
|
||||||
typedef sexp (*sexp_proc2) (sexp, sexp);
|
typedef sexp (*sexp_proc2) (sexp, sexp);
|
||||||
typedef sexp (*sexp_proc3) (sexp, 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_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_range_exception (sexp ctx, sexp obj, sexp start, sexp end);
|
||||||
SEXP_API sexp sexp_print_exception(sexp ctx, sexp exn, sexp out);
|
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 */
|
#endif /* ! SEXP_H */
|
||||||
|
|
||||||
|
|
26
mkfile
26
mkfile
|
@ -4,36 +4,22 @@ BIN=/$objtype/bin
|
||||||
TARG=chibi-scheme
|
TARG=chibi-scheme
|
||||||
MODDIR=/sys/lib/chibi-scheme
|
MODDIR=/sys/lib/chibi-scheme
|
||||||
|
|
||||||
CPPFLAGS= -Iinclude -DPLAN9 -DUSE_STRING_STREAMS=0 -DUSE_DEBUG=0
|
CPPFLAGS= -Iinclude -DPLAN9 '-DUSE_STRING_STREAMS=0' '-DUSE_DEBUG=0'
|
||||||
CFLAGS= -c -B $CPPFLAGS
|
CFLAGS= -p $CPPFLAGS
|
||||||
|
|
||||||
OFILES=sexp.$O eval.$O main.$O
|
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
|
HFILES=include/chibi/sexp.h include/chibi/eval.h include/chibi/config.h include/chibi/install.h
|
||||||
|
|
||||||
%.i: %.c $HFILES
|
</sys/src/cmd/mkone
|
||||||
cpp $CPPFLAGS $stem.c > $target
|
|
||||||
|
|
||||||
%.$O: %.i
|
|
||||||
$CC $CFLAGS -c -o $target $prereq
|
|
||||||
|
|
||||||
all:V: $TARG
|
|
||||||
|
|
||||||
include/chibi/install.h: mkfile
|
include/chibi/install.h: mkfile
|
||||||
echo '#define sexp_module_dir "'$MODDIR'"' > include/chibi/install.h
|
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
|
install:V: $BIN/$TARG
|
||||||
mkdir -p $MODDIR
|
test -d $MODDIR || mkdir -p $MODDIR
|
||||||
cp init.scm $MODDIR/
|
cp init.scm $MODDIR/
|
||||||
|
|
||||||
test:V:
|
test:V:
|
||||||
./chibi-scheme tests/r5rs-tests.scm
|
./chibi-scheme tests/r5rs-tests.scm
|
||||||
|
|
||||||
|
sexp.c:N: gc.c opt/bignum.c
|
||||||
|
|
12
opt/bignum.c
12
opt/bignum.c
|
@ -186,12 +186,16 @@ sexp sexp_read_bignum (sexp ctx, sexp in, sexp_uint_t init,
|
||||||
return sexp_bignum_normalize(res);
|
return sexp_bignum_normalize(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PLAN9
|
static int log2i(int v) {
|
||||||
#define log2(n) (log(n)/log(2))
|
int i;
|
||||||
#endif
|
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) {
|
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;
|
char *data;
|
||||||
sexp_gc_var(ctx, b, s_b);
|
sexp_gc_var(ctx, b, s_b);
|
||||||
sexp_gc_var(ctx, str, s_str);
|
sexp_gc_var(ctx, str, s_str);
|
||||||
|
|
8
sexp.c
8
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_ */
|
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));
|
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));
|
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_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_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_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_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_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"),
|
_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;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sexp_init() {
|
void sexp_init(void) {
|
||||||
int i;
|
int i;
|
||||||
sexp ctx;
|
sexp ctx;
|
||||||
if (! sexp_initialized_p) {
|
if (! sexp_initialized_p) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue