From a7d6998a96315d8ac615783bc306ff473b37540d Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Mon, 14 Nov 2011 09:17:53 +0900 Subject: [PATCH] Fixing static libs and immutable strings builds. --- eval.c | 13 ++++++------- include/chibi/sexp.h | 1 + opcodes.c | 2 ++ tools/chibi-genstatic | 7 ++++--- vm.c | 2 ++ 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/eval.c b/eval.c index ee9593af..024f9ecb 100644 --- a/eval.c +++ b/eval.c @@ -1065,8 +1065,7 @@ static sexp sexp_load_dl (sexp ctx, sexp file, sexp env) { sexp_library_entry_t *entry = sexp_find_static_library(sexp_string_data(file)); if (! entry) return sexp_compile_error(ctx, "couldn't find builtin library", file); - - return entry->init(ctx, NULL, 1, env); + return entry->init(ctx, NULL, 3, env, sexp_version, SEXP_ABI_IDENTIFIER); } #else #define sexp_find_static_library(path) NULL @@ -1074,16 +1073,16 @@ static sexp sexp_load_dl (sexp ctx, sexp file, sexp env) { #ifdef __MINGW32__ #include static sexp sexp_load_dl (sexp ctx, sexp file, sexp env) { - sexp_proc4 init; + sexp_init_proc init; HINSTANCE handle = LoadLibraryA(sexp_string_data(file)); if(!handle) return sexp_compile_error(ctx, "couldn't load dynamic library", file); - init = (sexp_proc4) GetProcAddress(handle, "sexp_init_library"); + init = (sexp_init_proc) GetProcAddress(handle, "sexp_init_library"); if(!init) { FreeLibrary(handle); return sexp_compile_error(ctx, "dynamic library has no sexp_init_library", file); } - return init(ctx, NULL, 3, env, (sexp)sexp_version, (sexp)SEXP_ABI_IDENTIFIER); + return init(ctx, NULL, 3, env, sexp_version, SEXP_ABI_IDENTIFIER); } #else static sexp sexp_make_dl (sexp ctx, sexp file, void* handle) { @@ -1093,7 +1092,7 @@ static sexp sexp_make_dl (sexp ctx, sexp file, void* handle) { return res; } static sexp sexp_load_dl (sexp ctx, sexp file, sexp env) { - sexp_proc4 init; + sexp_init_proc init; sexp_gc_var2(res, old_dl); void *handle = dlopen(sexp_string_data(file), RTLD_LAZY); if (! handle) @@ -1106,7 +1105,7 @@ static sexp sexp_load_dl (sexp ctx, sexp file, sexp env) { sexp_gc_preserve2(ctx, res, old_dl); old_dl = sexp_context_dl(ctx); sexp_context_dl(ctx) = sexp_make_dl(ctx, file, handle); - res = init(ctx, NULL, 3, env, (sexp)sexp_version, (sexp)SEXP_ABI_IDENTIFIER); + res = init(ctx, NULL, 3, env, sexp_version, SEXP_ABI_IDENTIFIER); sexp_context_dl(ctx) = old_dl; sexp_gc_release2(ctx); return res; diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index 22f33c6a..bdb6e212 100755 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -206,6 +206,7 @@ typedef sexp (*sexp_proc4) (sexp, sexp, sexp_sint_t, sexp, sexp, sexp); typedef sexp (*sexp_proc5) (sexp, sexp, sexp_sint_t, sexp, sexp, sexp, sexp); typedef sexp (*sexp_proc6) (sexp, sexp, sexp_sint_t, sexp, sexp, sexp, sexp, sexp); typedef sexp (*sexp_proc7) (sexp, sexp, sexp_sint_t, sexp, sexp, sexp, sexp, sexp, sexp); +typedef sexp (*sexp_init_proc)(sexp, sexp, sexp_sint_t, sexp, const char*, sexp_abi_identifier_t); typedef struct sexp_free_list_t *sexp_free_list; struct sexp_free_list_t { diff --git a/opcodes.c b/opcodes.c index 3030a99c..8b57217a 100644 --- a/opcodes.c +++ b/opcodes.c @@ -188,7 +188,9 @@ _FN2(_I(SEXP_NUMBER), _I(SEXP_NUMBER), _I(SEXP_NUMBER), "expt", 0, sexp_expt_op) #if SEXP_USE_UTF8_STRINGS _FN2(_I(SEXP_FIXNUM), _I(SEXP_STRING), _I(SEXP_FIXNUM), "string-index->offset", 0, sexp_string_index_to_offset), _FN2(_I(SEXP_CHAR), _I(SEXP_STRING), _I(SEXP_FIXNUM), "string-ref", 0, sexp_string_utf8_index_ref), +#if SEXP_USE_MUTABLE_STRINGS _FN3(SEXP_VOID, _I(SEXP_STRING), _I(SEXP_FIXNUM), _I(SEXP_CHAR), "string-set!", 0, sexp_string_utf8_index_set), +#endif _FN3OPT(_I(SEXP_STRING), _I(SEXP_STRING), _I(SEXP_FIXNUM), _I(SEXP_FIXNUM), "substring-cursor", SEXP_FALSE, sexp_substring_op), _FN3OPT(_I(SEXP_STRING), _I(SEXP_STRING), _I(SEXP_FIXNUM), _I(SEXP_FIXNUM), "substring", SEXP_FALSE, sexp_utf8_substring_op), #else diff --git a/tools/chibi-genstatic b/tools/chibi-genstatic index e212327d..860b0e4a 100755 --- a/tools/chibi-genstatic +++ b/tools/chibi-genstatic @@ -1,7 +1,8 @@ #! /usr/bin/env chibi-scheme (import (chibi filesystem) - (chibi pathname)) + (chibi pathname) + (only (meta) find-module)) (define c-libs '()) @@ -91,7 +92,7 @@ (mod-name (map (lambda (x) (or (string->number x) (string->symbol x))) (path-split mod-path)))) (cond - ((eval `(find-module ',mod-name) *meta-env*) + ((find-module mod-name) => (lambda (mod) (cond ((assq 'include-shared (vector-ref mod 2)) @@ -131,7 +132,7 @@ (newline) (display "typedef struct {\n") (display " const char *name;\n") - (display " sexp (*init)(sexp ctx, sexp self, sexp_sint_t n, sexp env, const char* version, sexp_abi_identifier_t abi);\n") + (display " sexp_init_proc init;\n") (display "} sexp_library_entry_t;\n") (newline) (display "static sexp_library_entry_t sexp_static_libraries[] = {\n") diff --git a/vm.c b/vm.c index 7ffe08f5..932f0af2 100644 --- a/vm.c +++ b/vm.c @@ -1215,6 +1215,7 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) { sexp_bytes_set(_ARG1, _ARG2, _ARG3); top-=3; break; +#if SEXP_USE_MUTABLE_STRINGS case SEXP_OP_STRING_SET: if (! sexp_stringp(_ARG1)) sexp_raise("string-set!: not a string", sexp_list1(ctx, _ARG1)); @@ -1235,6 +1236,7 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) { #endif top-=3; break; +#endif #if SEXP_USE_UTF8_STRINGS case SEXP_OP_STRING_CURSOR_NEXT: if (! sexp_stringp(_ARG1))