diff --git a/eval.c b/eval.c index 9aed9e18..66ab8649 100644 --- a/eval.c +++ b/eval.c @@ -148,7 +148,7 @@ static sexp sexp_flatten_dot (sexp ctx, sexp ls) { return sexp_nreverse(ctx, sexp_reverse_flatten_dot(ctx, ls)); } -static int sexp_param_index (sexp lambda, sexp name) { +int sexp_param_index (sexp lambda, sexp name) { sexp ls = sexp_lambda_params(lambda); int i = 0; for (i=0; sexp_pairp(ls); ls=sexp_cdr(ls), i++) diff --git a/gc.c b/gc.c index 455b1a85..b7f275f2 100644 --- a/gc.c +++ b/gc.c @@ -177,11 +177,11 @@ sexp_heap sexp_make_heap (size_t size) { sexp_free_list free, next; sexp_heap h; #if SEXP_USE_MMAP_GC - h = mmap(NULL, sizeof(struct sexp_heap) + size + sexp_heap_align(1), + h = mmap(NULL, sizeof(struct sexp_heap_t) + size + sexp_heap_align(1), PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, 0, 0); #else - h = malloc(sizeof(struct sexp_heap) + size + sexp_heap_align(1)); + h = malloc(sizeof(struct sexp_heap_t) + size + sexp_heap_align(1)); #endif if (! h) return NULL; h->size = size; diff --git a/include/chibi/eval.h b/include/chibi/eval.h index 7fa0b1ae..22b82f7f 100644 --- a/include/chibi/eval.h +++ b/include/chibi/eval.h @@ -5,6 +5,10 @@ #ifndef SEXP_EVAL_H #define SEXP_EVAL_H +#ifdef __cplusplus +extern "C" { +#endif + #include "chibi/sexp.h" /************************* additional types ***************************/ @@ -129,6 +133,7 @@ SEXP_API sexp sexp_analyze (sexp context, sexp x); SEXP_API sexp sexp_apply (sexp context, sexp proc, sexp args); SEXP_API sexp sexp_apply_optimization (sexp context, sexp proc, sexp ast); SEXP_API sexp sexp_free_vars (sexp context, sexp x, sexp fv); +SEXP_API int sexp_param_index (sexp lambda, sexp name); SEXP_API sexp sexp_eval (sexp context, sexp obj, sexp env); SEXP_API sexp sexp_eval_string (sexp context, char *str, sexp env); SEXP_API sexp sexp_load (sexp context, sexp expr, sexp env); @@ -164,5 +169,9 @@ SEXP_API sexp sexp_make_getter (sexp ctx, sexp name, sexp type, sexp index); SEXP_API sexp sexp_make_setter (sexp ctx, sexp name, sexp type, sexp index); #endif +#ifdef __cplusplus +} /* extern "C" */ +#endif + #endif /* ! SEXP_EVAL_H */ diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index a47ae337..054be66c 100644 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -5,6 +5,10 @@ #ifndef SEXP_H #define SEXP_H +#ifdef __cplusplus +extern "C" { +#endif + #define SEXP_MODULE_PATH_VAR "CHIBI_MODULE_PATH" #include "chibi/features.h" @@ -129,14 +133,14 @@ typedef sexp (*sexp_proc5) (sexp, sexp, sexp, sexp, sexp); typedef sexp (*sexp_proc6) (sexp, sexp, sexp, sexp, sexp, sexp); typedef sexp (*sexp_proc7) (sexp, sexp, sexp, sexp, sexp, sexp, sexp); -typedef struct sexp_free_list *sexp_free_list; -struct sexp_free_list { +typedef struct sexp_free_list_t *sexp_free_list; +struct sexp_free_list_t { sexp_uint_t size; sexp_free_list next; }; -typedef struct sexp_heap *sexp_heap; -struct sexp_heap { +typedef struct sexp_heap_t *sexp_heap; +struct sexp_heap_t { sexp_uint_t size; sexp_free_list free_list; sexp_heap next; @@ -811,7 +815,7 @@ SEXP_API sexp sexp_append2(sexp ctx, sexp a, sexp b); SEXP_API sexp sexp_memq(sexp ctx, sexp x, sexp ls); SEXP_API sexp sexp_assq(sexp ctx, sexp x, sexp ls); SEXP_API sexp sexp_length(sexp ctx, sexp ls); -SEXP_API sexp sexp_c_string(sexp ctx, char *str, sexp_sint_t slen); +SEXP_API sexp sexp_c_string(sexp ctx, const char *str, sexp_sint_t slen); SEXP_API sexp sexp_make_string(sexp ctx, sexp len, sexp ch); SEXP_API sexp sexp_substring (sexp ctx, sexp str, sexp start, sexp end); SEXP_API sexp sexp_string_concatenate (sexp ctx, sexp str_ls, sexp sep); @@ -819,7 +823,7 @@ SEXP_API sexp sexp_intern(sexp ctx, char *str); SEXP_API sexp sexp_string_to_symbol(sexp ctx, sexp str); SEXP_API sexp sexp_make_vector(sexp ctx, sexp len, sexp dflt); SEXP_API sexp sexp_list_to_vector(sexp ctx, sexp ls); -SEXP_API sexp sexp_make_cpointer(sexp ctx, sexp_uint_t typeid, void* value, sexp parent, int freep); +SEXP_API sexp sexp_make_cpointer(sexp ctx, sexp_uint_t type_id, void* value, sexp parent, int freep); SEXP_API sexp sexp_write(sexp ctx, sexp obj, sexp out); SEXP_API sexp sexp_display(sexp ctx, sexp obj, sexp out); SEXP_API sexp sexp_flush_output(sexp ctx, sexp out); @@ -862,5 +866,9 @@ SEXP_API sexp sexp_finalize_c_type (sexp ctx, sexp obj); #define sexp_current_error_port(ctx) sexp_env_global_ref(sexp_context_env(ctx),sexp_global(ctx,SEXP_G_CUR_ERR_SYMBOL),SEXP_FALSE) #define sexp_debug(ctx, msg, obj) (sexp_write_string(ctx, msg, sexp_current_error_port(ctx)), sexp_write(ctx, obj, sexp_current_error_port(ctx)), sexp_write_char(ctx, '\n', sexp_current_error_port(ctx))) +#ifdef __cplusplus +} /* extern "C" */ +#endif + #endif /* ! SEXP_H */ diff --git a/sexp.c b/sexp.c index dd32415d..b6304431 100644 --- a/sexp.c +++ b/sexp.c @@ -623,7 +623,7 @@ sexp sexp_make_string(sexp ctx, sexp len, sexp ch) { return s; } -sexp sexp_c_string(sexp ctx, char *str, sexp_sint_t slen) { +sexp sexp_c_string(sexp ctx, const char *str, sexp_sint_t slen) { sexp_sint_t len = ((slen >= 0) ? slen : strlen(str)); sexp s = sexp_make_string(ctx, sexp_make_fixnum(len), SEXP_VOID); memcpy(sexp_string_data(s), str, len); @@ -709,7 +709,7 @@ sexp sexp_intern(sexp ctx, char *str) { #if SEXP_USE_HUFF_SYMS res = 0; for ( ; (c=*p); p++) { - if ((c < 0) || (c > 127)) + if ((unsigned char)c > 127) goto normal_intern; he = huff_table[(unsigned char)c]; newbits = he.len; @@ -773,10 +773,10 @@ sexp sexp_list_to_vector(sexp ctx, sexp ls) { return vec; } -sexp sexp_make_cpointer (sexp ctx, sexp_uint_t typeid, void *value, sexp parent, int freep) { +sexp sexp_make_cpointer (sexp ctx, sexp_uint_t type_id, void *value, sexp parent, int freep) { sexp ptr; if (! value) return SEXP_FALSE; - ptr = sexp_alloc_type(ctx, cpointer, typeid); + ptr = sexp_alloc_type(ctx, cpointer, type_id); if (sexp_exceptionp(ptr)) return ptr; sexp_freep(ptr) = freep; sexp_cpointer_value(ptr) = value;