[uim-commit] r1962 - branches/r5rs/sigscheme
kzk at freedesktop.org
kzk at freedesktop.org
Thu Nov 3 04:07:42 PST 2005
Author: kzk
Date: 2005-11-03 04:07:38 -0800 (Thu, 03 Nov 2005)
New Revision: 1962
Added:
branches/r5rs/sigscheme/storage-symbol.c
Modified:
branches/r5rs/sigscheme/Makefile.am
branches/r5rs/sigscheme/datas.c
branches/r5rs/sigscheme/sigscheme.h
branches/r5rs/sigscheme/sigschemeinternal.h
Log:
* Move symbol table handling code to storage-symbol.c
* sigscheme/sigschemeinternal.h
- (NAMEHASH_SIZE): moved from datas.c
- (SigScm_InitSymbol, SigScm_FinalizeSymbol)
: new func
* sigscheme/storage-symbol.c
- (SigScm_InitSymbol, SigScm_FinalizeSymbol)
: new func
- (scm_symbol_hash): renamed from symbol_hash and now
declared in storage-symbol.c
- (initialize_symbol_hash, finalize_symbol_hash,
symbol_name_hash, Scm_Intern): moved from datas.c
* sigscheme/datas.c
- (NAMEHASH_SIZE): moved to sigschemeinternal.h
- (scm_symbol_hash): renamed from symbol_hash and now
declared in storage-symbol.c
- (initialize_symbol_hash, finalize_symbol_hash,
symbol_name_hash, Scm_Intern): moved to storage-symbol.c
- (SigScm_InitStorage): call SigScm_InitSymbol
- (SigScm_FinalizeStorage): call SigScm_FinalizeSymbol
* sigscheme/Makefile.am
- add storage-symbol.c
* sigscheme/sigscheme.h
- update comment
Modified: branches/r5rs/sigscheme/Makefile.am
===================================================================
--- branches/r5rs/sigscheme/Makefile.am 2005-11-03 11:44:25 UTC (rev 1961)
+++ branches/r5rs/sigscheme/Makefile.am 2005-11-03 12:07:38 UTC (rev 1962)
@@ -1,6 +1,7 @@
noinst_LTLIBRARIES = libsscm.la
libsscm_la_SOURCES = \
datas.c debug.c \
+ storage-symbol.c \
storage-continuation.c \
encoding.c error.c \
eval.c io.c \
Modified: branches/r5rs/sigscheme/datas.c
===================================================================
--- branches/r5rs/sigscheme/datas.c 2005-11-03 11:44:25 UTC (rev 1961)
+++ branches/r5rs/sigscheme/datas.c 2005-11-03 12:07:38 UTC (rev 1962)
@@ -115,8 +115,6 @@
/*=======================================
File Local Macro Declarations
=======================================*/
-#define NAMEHASH_SIZE 1024
-
#define SCM_NEW_OBJ_INTERNAL(VALNAME) \
do { \
if (NULLP(scm_freelist)) \
@@ -173,7 +171,6 @@
ScmObj SigScm_null_values;
#endif
-static ScmObj *symbol_hash = NULL;
static gc_protected_var *protected_var_list = NULL;
ScmObj SigScm_null, SigScm_true, SigScm_false, SigScm_eof;
@@ -185,6 +182,9 @@
/* storage-continuation.c */
extern ScmObj scm_current_dynamic_extent;
+/* storage-symbol.c */
+extern ScmObj *scm_symbol_hash;
+
/*=======================================
File Local Function Declarations
=======================================*/
@@ -211,10 +211,6 @@
static void sweep_obj(ScmObj obj);
static void gc_sweep(void);
-static void initialize_symbol_hash(void);
-static void finalize_symbol_hash(void);
-static int symbol_name_hash(const char *name);
-
static void finalize_protected_var(void);
/*=======================================
@@ -258,14 +254,14 @@
#endif
SigScm_InitContinuation();
- initialize_symbol_hash();
+ SigScm_InitSymbol();
}
void SigScm_FinalizeStorage(void)
{
SigScm_FinalizeContinuation();
finalize_heap();
- finalize_symbol_hash();
+ SigScm_FinalizeSymbol();
finalize_protected_var();
}
@@ -550,7 +546,7 @@
{
int i = 0;
for (i = 0; i < NAMEHASH_SIZE; i++) {
- mark_obj(symbol_hash[i]);
+ mark_obj(scm_symbol_hash[i]);
}
}
@@ -878,67 +874,3 @@
return obj;
}
#endif /* SCM_USE_NONSTD_FEATURES */
-
-/*============================================================================
- Symbol table
-============================================================================*/
-/*
- * Symbol Name Hash Related Functions
- *
- * - Data Structure of Symbol Name Hash
- *
- * - n = symbol_name_hash(name)
- * - symbol_hash[n] = sym_list
- * - sym_list = ( ScmObj(SYMBOL) ScmObj(SYMBOL) ... )
- *
- */
-static void initialize_symbol_hash(void)
-{
- int i = 0;
- symbol_hash = (ScmObj*)malloc(sizeof(ScmObj) * NAMEHASH_SIZE);
- for (i = 0; i < NAMEHASH_SIZE; i++) {
- symbol_hash[i] = SCM_NULL;
- }
-}
-
-static void finalize_symbol_hash(void)
-{
- free(symbol_hash);
-}
-
-static int symbol_name_hash(const char *name)
-{
- int hash = 0;
- int c;
- char *cname = (char *)name;
- while ((c = *cname++)) {
- hash = ((hash * 17) ^ c) % NAMEHASH_SIZE;
- }
- return hash;
-}
-
-ScmObj Scm_Intern(const char *name)
-{
- int n = symbol_name_hash(name);
- ScmObj sym = SCM_FALSE;
- ScmObj lst = SCM_FALSE;
- ScmObj sym_lst = symbol_hash[n];
-
- /* Search Symbol by name */
- for (lst = sym_lst; !NULLP(lst); lst = CDR(lst)) {
- sym = CAR(lst);
-
- if (strcmp(SCM_SYMBOL_NAME(sym), name) == 0) {
- return sym;
- }
- }
-
- /* If not in the sym_lst, allocate new Symbol */
- sym = Scm_NewSymbol(strdup(name), SCM_UNBOUND);
-
- /* And Append it to the head of symbol_hash */
- sym_lst = CONS(sym, sym_lst);
- symbol_hash[n] = sym_lst;
-
- return sym;
-}
Modified: branches/r5rs/sigscheme/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/sigscheme.h 2005-11-03 11:44:25 UTC (rev 1961)
+++ branches/r5rs/sigscheme/sigscheme.h 2005-11-03 12:07:38 UTC (rev 1962)
@@ -401,6 +401,8 @@
ScmObj Scm_NewCPointer(void *data);
ScmObj Scm_NewCFuncPointer(ScmCFunc func);
#endif
+
+/* storage-symbol.c */
ScmObj Scm_Intern(const char *name);
/* eval.c */
Modified: branches/r5rs/sigscheme/sigschemeinternal.h
===================================================================
--- branches/r5rs/sigscheme/sigschemeinternal.h 2005-11-03 11:44:25 UTC (rev 1961)
+++ branches/r5rs/sigscheme/sigschemeinternal.h 2005-11-03 12:07:38 UTC (rev 1962)
@@ -328,12 +328,14 @@
/* Macros For Handling Continuation Object */
#define INVALID_CONTINUATION_JMPENV NULL
-
#define CONTINUATION_JMPENV SCM_CONTINUATION_OPAQUE0
#define CONTINUATION_SET_JMPENV SCM_CONTINUATION_SET_OPAQUE0
#define CONTINUATION_DYNEXT SCM_CONTINUATION_OPAQUE1
#define CONTINUATION_SET_DYNEXT SCM_CONTINUATION_SET_OPAQUE1
+/* Symbol Name Hash Size */
+#define NAMEHASH_SIZE 1024
+
/*=======================================
Function Declarations
=======================================*/
@@ -348,6 +350,10 @@
void Scm_CallContinuation(ScmObj cont, ScmObj ret);
ScmObj Scm_DynamicWind(ScmObj before, ScmObj thunk, ScmObj after);
+/* storage-symbol.c */
+void SigScm_InitSymbol(void);
+void SigScm_FinalizeSymbol(void);
+
/* eval.c */
/* environment related functions */
ScmObj Scm_ExtendEnvironment(ScmObj vars, ScmObj vals, ScmObj env);
Copied: branches/r5rs/sigscheme/storage-symbol.c (from rev 1961, branches/r5rs/sigscheme/datas.c)
===================================================================
--- branches/r5rs/sigscheme/datas.c 2005-11-03 11:44:25 UTC (rev 1961)
+++ branches/r5rs/sigscheme/storage-symbol.c 2005-11-03 12:07:38 UTC (rev 1962)
@@ -0,0 +1,141 @@
+/*===========================================================================
+ * FileName : storage-symbol.c
+ * About : Scheme Symbol handling
+ *
+ * Copyright (C) 2005 by Kazuki Ohta (mover at hct.zaq.ne.jp)
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of authors nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+===========================================================================*/
+/*=======================================
+ System Include
+=======================================*/
+#include <string.h>
+#include <stdlib.h>
+
+/*=======================================
+ Local Include
+=======================================*/
+#include "sigscheme.h"
+#include "sigschemeinternal.h"
+
+/*=======================================
+ File Local Struct Declarations
+=======================================*/
+
+/*=======================================
+ File Local Macro Declarations
+=======================================*/
+
+/*=======================================
+ Variable Declarations
+=======================================*/
+ScmObj *scm_symbol_hash = NULL;
+
+/*=======================================
+ File Local Function Declarations
+=======================================*/
+static void initialize_symbol_hash(void);
+static void finalize_symbol_hash(void);
+static int symbol_name_hash(const char *name);
+
+/*=======================================
+ Function Implementations
+=======================================*/
+ScmObj Scm_Intern(const char *name)
+{
+ int n = symbol_name_hash(name);
+ ScmObj sym = SCM_FALSE;
+ ScmObj lst = SCM_FALSE;
+ ScmObj sym_lst = scm_symbol_hash[n];
+
+ /* Search Symbol by name */
+ for (lst = sym_lst; !NULLP(lst); lst = CDR(lst)) {
+ sym = CAR(lst);
+
+ if (strcmp(SCM_SYMBOL_NAME(sym), name) == 0) {
+ return sym;
+ }
+ }
+
+ /* If not in the sym_lst, allocate new Symbol */
+ sym = Scm_NewSymbol(strdup(name), SCM_UNBOUND);
+
+ /* And Append it to the head of symbol_hash */
+ sym_lst = CONS(sym, sym_lst);
+ scm_symbol_hash[n] = sym_lst;
+
+ return sym;
+}
+
+void SigScm_InitSymbol(void)
+{
+ initialize_symbol_hash();
+}
+
+void SigScm_FinalizeSymbol(void)
+{
+ finalize_symbol_hash();
+}
+
+/*============================================================================
+ Symbol table
+============================================================================*/
+/*
+ * Symbol Name Hash Related Functions
+ *
+ * - Data Structure of Symbol Name Hash
+ *
+ * - n = symbol_name_hash(name)
+ * - symbol_hash[n] = sym_list
+ * - sym_list = ( ScmObj(SYMBOL) ScmObj(SYMBOL) ... )
+ *
+ */
+static void initialize_symbol_hash(void)
+{
+ int i = 0;
+ scm_symbol_hash = (ScmObj*)malloc(sizeof(ScmObj) * NAMEHASH_SIZE);
+ for (i = 0; i < NAMEHASH_SIZE; i++) {
+ scm_symbol_hash[i] = SCM_NULL;
+ }
+}
+
+static void finalize_symbol_hash(void)
+{
+ free(scm_symbol_hash);
+}
+
+static int symbol_name_hash(const char *name)
+{
+ int hash = 0;
+ int c;
+ char *cname = (char *)name;
+ while ((c = *cname++)) {
+ hash = ((hash * 17) ^ c) % NAMEHASH_SIZE;
+ }
+ return hash;
+}
More information about the uim-commit
mailing list