mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-07 05:06:37 +02:00
adding patches for C++
This commit is contained in:
parent
a7ad2d547c
commit
fea1b696a4
5 changed files with 30 additions and 13 deletions
2
eval.c
2
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));
|
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);
|
sexp ls = sexp_lambda_params(lambda);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i=0; sexp_pairp(ls); ls=sexp_cdr(ls), i++)
|
for (i=0; sexp_pairp(ls); ls=sexp_cdr(ls), i++)
|
||||||
|
|
4
gc.c
4
gc.c
|
@ -177,11 +177,11 @@ sexp_heap sexp_make_heap (size_t size) {
|
||||||
sexp_free_list free, next;
|
sexp_free_list free, next;
|
||||||
sexp_heap h;
|
sexp_heap h;
|
||||||
#if SEXP_USE_MMAP_GC
|
#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,
|
PROT_READ|PROT_WRITE|PROT_EXEC,
|
||||||
MAP_ANON|MAP_PRIVATE, 0, 0);
|
MAP_ANON|MAP_PRIVATE, 0, 0);
|
||||||
#else
|
#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
|
#endif
|
||||||
if (! h) return NULL;
|
if (! h) return NULL;
|
||||||
h->size = size;
|
h->size = size;
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
#ifndef SEXP_EVAL_H
|
#ifndef SEXP_EVAL_H
|
||||||
#define SEXP_EVAL_H
|
#define SEXP_EVAL_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "chibi/sexp.h"
|
#include "chibi/sexp.h"
|
||||||
|
|
||||||
/************************* additional types ***************************/
|
/************************* 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 (sexp context, sexp proc, sexp args);
|
||||||
SEXP_API sexp sexp_apply_optimization (sexp context, sexp proc, sexp ast);
|
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 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 (sexp context, sexp obj, sexp env);
|
||||||
SEXP_API sexp sexp_eval_string (sexp context, char *str, 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);
|
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);
|
SEXP_API sexp sexp_make_setter (sexp ctx, sexp name, sexp type, sexp index);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* ! SEXP_EVAL_H */
|
#endif /* ! SEXP_EVAL_H */
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
#ifndef SEXP_H
|
#ifndef SEXP_H
|
||||||
#define SEXP_H
|
#define SEXP_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SEXP_MODULE_PATH_VAR "CHIBI_MODULE_PATH"
|
#define SEXP_MODULE_PATH_VAR "CHIBI_MODULE_PATH"
|
||||||
|
|
||||||
#include "chibi/features.h"
|
#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_proc6) (sexp, sexp, sexp, sexp, sexp, sexp);
|
||||||
typedef sexp (*sexp_proc7) (sexp, 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;
|
typedef struct sexp_free_list_t *sexp_free_list;
|
||||||
struct sexp_free_list {
|
struct sexp_free_list_t {
|
||||||
sexp_uint_t size;
|
sexp_uint_t size;
|
||||||
sexp_free_list next;
|
sexp_free_list next;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct sexp_heap *sexp_heap;
|
typedef struct sexp_heap_t *sexp_heap;
|
||||||
struct sexp_heap {
|
struct sexp_heap_t {
|
||||||
sexp_uint_t size;
|
sexp_uint_t size;
|
||||||
sexp_free_list free_list;
|
sexp_free_list free_list;
|
||||||
sexp_heap next;
|
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_memq(sexp ctx, sexp x, sexp ls);
|
||||||
SEXP_API sexp sexp_assq(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_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_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_substring (sexp ctx, sexp str, sexp start, sexp end);
|
||||||
SEXP_API sexp sexp_string_concatenate (sexp ctx, sexp str_ls, sexp sep);
|
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_string_to_symbol(sexp ctx, sexp str);
|
||||||
SEXP_API sexp sexp_make_vector(sexp ctx, sexp len, sexp dflt);
|
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_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_write(sexp ctx, sexp obj, sexp out);
|
||||||
SEXP_API sexp sexp_display(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);
|
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_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)))
|
#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 */
|
#endif /* ! SEXP_H */
|
||||||
|
|
||||||
|
|
8
sexp.c
8
sexp.c
|
@ -623,7 +623,7 @@ sexp sexp_make_string(sexp ctx, sexp len, sexp ch) {
|
||||||
return s;
|
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_sint_t len = ((slen >= 0) ? slen : strlen(str));
|
||||||
sexp s = sexp_make_string(ctx, sexp_make_fixnum(len), SEXP_VOID);
|
sexp s = sexp_make_string(ctx, sexp_make_fixnum(len), SEXP_VOID);
|
||||||
memcpy(sexp_string_data(s), str, len);
|
memcpy(sexp_string_data(s), str, len);
|
||||||
|
@ -709,7 +709,7 @@ sexp sexp_intern(sexp ctx, char *str) {
|
||||||
#if SEXP_USE_HUFF_SYMS
|
#if SEXP_USE_HUFF_SYMS
|
||||||
res = 0;
|
res = 0;
|
||||||
for ( ; (c=*p); p++) {
|
for ( ; (c=*p); p++) {
|
||||||
if ((c < 0) || (c > 127))
|
if ((unsigned char)c > 127)
|
||||||
goto normal_intern;
|
goto normal_intern;
|
||||||
he = huff_table[(unsigned char)c];
|
he = huff_table[(unsigned char)c];
|
||||||
newbits = he.len;
|
newbits = he.len;
|
||||||
|
@ -773,10 +773,10 @@ sexp sexp_list_to_vector(sexp ctx, sexp ls) {
|
||||||
return vec;
|
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;
|
sexp ptr;
|
||||||
if (! value) return SEXP_FALSE;
|
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;
|
if (sexp_exceptionp(ptr)) return ptr;
|
||||||
sexp_freep(ptr) = freep;
|
sexp_freep(ptr) = freep;
|
||||||
sexp_cpointer_value(ptr) = value;
|
sexp_cpointer_value(ptr) = value;
|
||||||
|
|
Loading…
Add table
Reference in a new issue