[uim-commit] r2900 - in branches/r5rs: sigscheme uim
yamaken at freedesktop.org
yamaken at freedesktop.org
Fri Jan 13 02:53:34 PST 2006
Author: yamaken
Date: 2006-01-13 02:53:25 -0800 (Fri, 13 Jan 2006)
New Revision: 2900
Modified:
branches/r5rs/sigscheme/TODO
branches/r5rs/sigscheme/main.c
branches/r5rs/sigscheme/sigscheme.c
branches/r5rs/sigscheme/sigscheme.h
branches/r5rs/sigscheme/sigschemeinternal.h
branches/r5rs/sigscheme/storage-gc.c
branches/r5rs/sigscheme/storage-symbol.c
branches/r5rs/sigscheme/storage.c
branches/r5rs/uim/uim-scm.c
Log:
* This commit make memory parameter runtime-configurable
* sigscheme/sigscheme.h
- (struct ScmStorageConf_, ScmStorageConf): New type
- (scm_initialize): Add ScmStorageConf as arg
* sigscheme/sigschemeinternal.h
- (NAMEHASH_SIZE): Removed
- (scm_init_storage, scm_init_gc, scm_init_symbol): Accept
ScmStorageConf as only one argument
* sigscheme/storage.c
- (default_storage_conf): New static variable
- (scm_init_storage): Adapt to ScmStorageConf
* sigscheme/storage-gc.c
- (scm_symbol_hash_size): New extern decl
- (scm_init_gc, initialize_heap): Adapt to ScmStorageConf
- (gc_mark): Replace NAMEHASH_SIZE with scm_symbol_hash_size
* sigscheme/storage-symbol.c
- (scm_symbol_hash_size): New variable
- (scm_symbol_bound_to, symbol_name_hash): Replace NAMEHASH_SIZE
with scm_symbol_hash_size
- (initialize_symbol_hash):
* Ditto
* Adapt to ScmStorageConf
- (scm_init_symbol): Adapt to ScmStorageConf
* sigscheme/sigscheme.c
- (scm_initialize, scm_initialize_internal): Adapt to ScmStorageConf
* sigscheme/main.c
- (main): Follow the API change of scm_initialize()
* uim/uim-scm.c
- (uim_scm_init): Ditto
* sigscheme/TODO
- Update
Modified: branches/r5rs/sigscheme/TODO
===================================================================
--- branches/r5rs/sigscheme/TODO 2006-01-13 10:41:37 UTC (rev 2899)
+++ branches/r5rs/sigscheme/TODO 2006-01-13 10:53:25 UTC (rev 2900)
@@ -129,8 +129,6 @@
* Add integer->char and char->integer procedures with multibyte support
- Write test
-* Make memory parameters runtime-configurable
-
* GCC4-optimization-proof stack protection
- Update the document
Modified: branches/r5rs/sigscheme/main.c
===================================================================
--- branches/r5rs/sigscheme/main.c 2006-01-13 10:41:37 UTC (rev 2899)
+++ branches/r5rs/sigscheme/main.c 2006-01-13 10:53:25 UTC (rev 2900)
@@ -188,7 +188,7 @@
rest_argv = scm_interpret_argv(argv);
filename = rest_argv[0];
- scm_initialize();
+ scm_initialize(NULL);
#if SCM_USE_SRFI34
scm_use("srfi-34");
Modified: branches/r5rs/sigscheme/sigscheme.c
===================================================================
--- branches/r5rs/sigscheme/sigscheme.c 2006-01-13 10:41:37 UTC (rev 2899)
+++ branches/r5rs/sigscheme/sigscheme.c 2006-01-13 10:53:25 UTC (rev 2900)
@@ -113,7 +113,7 @@
/*=======================================
File Local Function Declarations
=======================================*/
-static void scm_initialize_internal(void);
+static void scm_initialize_internal(const ScmStorageConf *storage_conf);
static scm_bool scm_use_internal(const char *feature);
static scm_bool scm_register_func(const char *name, ScmFuncType func,
enum ScmFuncTypeCode type);
@@ -122,11 +122,17 @@
/*=======================================
Function Implementations
=======================================*/
+/**
+ * Initialize the interpreter
+ *
+ * @param storage_conf Storage configuration parameters. NULL instructs
+ * default.
+ */
void
-scm_initialize(void)
+scm_initialize(const ScmStorageConf *storage_conf)
{
#if SCM_GCC4_READY_GC
- SCM_GC_PROTECTED_CALL_VOID(scm_initialize_internal, ());
+ SCM_GC_PROTECTED_CALL_VOID(scm_initialize_internal, (storage_conf));
#else
ScmObj stack_start;
@@ -137,15 +143,14 @@
}
static void
-scm_initialize_internal(void)
+scm_initialize_internal(const ScmStorageConf *storage_conf)
{
/*=======================================================================
Core
=======================================================================*/
scm_set_debug_categories(SCM_DBG_ERRMSG | SCM_DBG_BACKTRACE
| scm_predefined_debug_categories());
- /* FIXME: make configurable from libsscm client */
- scm_init_storage(0x4000, 0x2000, 0x800, 1);
+ scm_init_storage(storage_conf);
scm_init_error();
scm_init_io();
Modified: branches/r5rs/sigscheme/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/sigscheme.h 2006-01-13 10:41:37 UTC (rev 2899)
+++ branches/r5rs/sigscheme/sigscheme.h 2006-01-13 10:53:25 UTC (rev 2900)
@@ -387,6 +387,18 @@
enum ScmReturnType ret_type;
};
+typedef struct ScmStorageConf_ ScmStorageConf;
+struct ScmStorageConf_ {
+ /* heap */
+ size_t heap_size; /* number of ScmCell in a heap */
+ size_t heap_alloc_threshold; /* minimum number of freecells after a GC */
+ int n_heaps_max; /* max number of heaps */
+ int n_heaps_init; /* initial number of heaps */
+
+ /* symbol table */
+ size_t symbol_hash_size; /* hash size of symbol table */
+};
+
/*=======================================
Object Representation Information
=======================================*/
@@ -646,7 +658,7 @@
SigScheme : Core Functions
===========================================================================*/
/* sigscheme.c */
-void scm_initialize(void);
+void scm_initialize(const ScmStorageConf *storage_conf);
void scm_finalize(void);
void scm_define_alias(const char *newsym, const char *sym);
void scm_provide(ScmObj feature);
Modified: branches/r5rs/sigscheme/sigschemeinternal.h
===================================================================
--- branches/r5rs/sigscheme/sigschemeinternal.h 2006-01-13 10:41:37 UTC (rev 2899)
+++ branches/r5rs/sigscheme/sigschemeinternal.h 2006-01-13 10:53:25 UTC (rev 2900)
@@ -368,9 +368,6 @@
/* Macros For Handling Continuation Object */
#define INVALID_CONTINUATION_OPAQUE NULL
-/* Symbol Name Hash Size */
-#define NAMEHASH_SIZE 1024
-
/* error handlings */
#define SCM_ERR_HEADER "Error: "
@@ -455,13 +452,11 @@
Function Declarations
=======================================*/
/* storage.c */
-void scm_init_storage(size_t heap_size, size_t heap_alloc_threshold,
- int n_heaps_max, int n_heaps_init);
+void scm_init_storage(const ScmStorageConf *conf);
void scm_finalize_storage(void);
/* storage-gc.c */
-void scm_init_gc(size_t heap_size, size_t heap_alloc_threshold,
- int n_heaps_max, int n_heaps_init);
+void scm_init_gc(const ScmStorageConf *conf);
void scm_finalize_gc(void);
ScmObj scm_alloc_cell(void);
@@ -478,7 +473,7 @@
ScmObj scm_trace_stack(void);
/* storage-symbol.c */
-void scm_init_symbol(void);
+void scm_init_symbol(const ScmStorageConf *conf);
void scm_finalize_symbol(void);
/* env.c */
Modified: branches/r5rs/sigscheme/storage-gc.c
===================================================================
--- branches/r5rs/sigscheme/storage-gc.c 2006-01-13 10:41:37 UTC (rev 2899)
+++ branches/r5rs/sigscheme/storage-gc.c 2006-01-13 10:53:25 UTC (rev 2900)
@@ -98,14 +98,14 @@
/* storage-symbol.c */
extern ScmObj *scm_symbol_hash;
+extern size_t scm_symbol_hash_size;
/*=======================================
File Local Function Declarations
=======================================*/
static ScmObj **locate_protected_var(ScmObj *var);
-static void initialize_heap(size_t size, size_t alloc_threshold,
- int n_max, int n_init);
+static void initialize_heap(const ScmStorageConf *conf);
static void add_heap(void);
static void finalize_heap(void);
@@ -131,14 +131,13 @@
Function Implementations
=======================================*/
void
-scm_init_gc(size_t heap_size, size_t heap_alloc_threshold,
- int n_heaps_max, int n_heaps_init)
+scm_init_gc(const ScmStorageConf *conf)
{
stack_start_pointer = NULL;
protected_vars = NULL;
protected_vars_size = 0;
n_empty_protected_vars = 0;
- initialize_heap(heap_size, heap_alloc_threshold, n_heaps_max, n_heaps_init);
+ initialize_heap(conf);
}
void
@@ -268,20 +267,20 @@
Heap Allocator & Garbage Collector
============================================================================*/
static void
-initialize_heap(size_t size, size_t alloc_threshold, int n_max, int n_init)
+initialize_heap(const ScmStorageConf *conf)
{
int i;
- heap_size = size;
- heap_alloc_threshold = alloc_threshold;
- n_heaps_max = n_max;
+ heap_size = conf->heap_size;
+ heap_alloc_threshold = conf->heap_alloc_threshold;
+ n_heaps_max = conf->n_heaps_max;
n_heaps = 0;
heaps = NULL;
heaps_lowest = heaps_highest = NULL;
freelist = SCM_NULL;
/* preallocate heaps */
- for (i = 0; i < n_init; i++)
+ for (i = 0; i < conf->n_heaps_init; i++)
add_heap();
}
@@ -569,7 +568,7 @@
/* performed after above two because of cache pollution */
gc_mark_protected_var();
if (scm_symbol_hash)
- gc_mark_definite_locations_n(scm_symbol_hash, NAMEHASH_SIZE);
+ gc_mark_definite_locations_n(scm_symbol_hash, scm_symbol_hash_size);
}
static void
Modified: branches/r5rs/sigscheme/storage-symbol.c
===================================================================
--- branches/r5rs/sigscheme/storage-symbol.c 2006-01-13 10:41:37 UTC (rev 2899)
+++ branches/r5rs/sigscheme/storage-symbol.c 2006-01-13 10:53:25 UTC (rev 2900)
@@ -55,11 +55,12 @@
Variable Declarations
=======================================*/
ScmObj *scm_symbol_hash;
+size_t scm_symbol_hash_size;
/*=======================================
File Local Function Declarations
=======================================*/
-static void initialize_symbol_hash(void);
+static void initialize_symbol_hash(const ScmStorageConf *conf);
static void finalize_symbol_hash(void);
static int symbol_name_hash(const char *name);
@@ -94,10 +95,10 @@
scm_symbol_bound_to(ScmObj obj)
{
ScmObj lst, sym, val;
- int i;
+ size_t i;
DECLARE_INTERNAL_FUNCTION("scm_symbol_bound_to");
- for (i = 0; i < NAMEHASH_SIZE; i++) {
+ for (i = 0; i < scm_symbol_hash_size; i++) {
lst = scm_symbol_hash[i];
FOR_EACH (sym, lst) {
val = SCM_SYMBOL_VCELL(sym);
@@ -110,9 +111,9 @@
}
void
-scm_init_symbol(void)
+scm_init_symbol(const ScmStorageConf *conf)
{
- initialize_symbol_hash();
+ initialize_symbol_hash(conf);
}
void
@@ -125,13 +126,14 @@
Symbol table
============================================================================*/
static void
-initialize_symbol_hash(void)
+initialize_symbol_hash(const ScmStorageConf *conf)
{
- int i;
+ size_t i;
- scm_symbol_hash = scm_malloc(sizeof(ScmObj) * NAMEHASH_SIZE);
+ scm_symbol_hash_size = conf->symbol_hash_size;
+ scm_symbol_hash = scm_malloc(sizeof(ScmObj) * scm_symbol_hash_size);
- for (i = 0; i < NAMEHASH_SIZE; i++)
+ for (i = 0; i < scm_symbol_hash_size; i++)
scm_symbol_hash[i] = SCM_NULL;
}
@@ -147,7 +149,7 @@
int hash, c;
for (hash = 0; (c = *name); name++)
- hash = ((hash * 17) ^ c) % NAMEHASH_SIZE;
+ hash = ((hash * 17) ^ c) % scm_symbol_hash_size;
return hash;
}
Modified: branches/r5rs/sigscheme/storage.c
===================================================================
--- branches/r5rs/sigscheme/storage.c 2006-01-13 10:41:37 UTC (rev 2899)
+++ branches/r5rs/sigscheme/storage.c 2006-01-13 10:53:25 UTC (rev 2900)
@@ -79,6 +79,14 @@
static ScmCell unbound_cell, undef_cell;
#endif
+static const ScmStorageConf default_storage_conf = {
+ 0x4000, /* number of ScmCell in a heap */
+ 0x2000, /* number of freecells always being preserved */
+ 0x800, /* max number of heaps */
+ 1, /* initial number of heaps */
+ 0x400 /* hash size of symbol table */
+};
+
/*=======================================
File Local Function Declarations
=======================================*/
@@ -90,12 +98,14 @@
Function Implementations
=======================================*/
void
-scm_init_storage(size_t heap_size, size_t heap_alloc_threshold,
- int n_heaps_max, int n_heaps_init)
+scm_init_storage(const ScmStorageConf *conf)
{
+ if (!conf)
+ conf = &default_storage_conf;
+
initialize_special_constants();
- scm_init_gc(heap_size, heap_alloc_threshold, n_heaps_max, n_heaps_init);
+ scm_init_gc(conf);
#if 0 && (SCM_COMPAT_SIOD_BUGS && !SCM_OBJ_COMPACT)
scm_gc_protect_with_init(&scm_const_true, MAKE_INT(1));
@@ -111,7 +121,7 @@
#endif
scm_init_continuation();
- scm_init_symbol();
+ scm_init_symbol(conf);
}
void
Modified: branches/r5rs/uim/uim-scm.c
===================================================================
--- branches/r5rs/uim/uim-scm.c 2006-01-13 10:41:37 UTC (rev 2899)
+++ branches/r5rs/uim/uim-scm.c 2006-01-13 10:53:25 UTC (rev 2900)
@@ -577,6 +577,7 @@
void
uim_scm_init(const char *verbose_level)
{
+ ScmStorageConf storage_conf;
long vlevel = 2;
ScmObj output_port;
@@ -597,7 +598,12 @@
*/
scm_current_char_codec = scm_mb_find_codec("ISO-8859-1");
- scm_initialize();
+ storage_conf.heap_size = 16384;
+ storage_conf.heap_alloc_threshold = 16384;
+ storage_conf.n_heaps_max = 64;
+ storage_conf.n_heaps_init = 1;
+ storage_conf.symbol_hash_size = 1024;
+ scm_initialize(&storage_conf);
/* GC safe */
output_port = scm_make_shared_file_port(uim_output, "uim", SCM_PORTFLAG_OUTPUT);
More information about the uim-commit
mailing list