update.
[chise/concord.git] / symbol.c
index 94cf020..96d1fee 100644 (file)
--- a/symbol.c
+++ b/symbol.c
@@ -53,6 +53,20 @@ COS_Symbol_ent cos_symbol_ent_t = { {COS_OBJECT_PREFIX_OBJECT,
 COS_Symbol cos_Qt = &cos_symbol_ent_t;
 
 
+COS_String_ent cos_string_ent_composition = { {COS_OBJECT_PREFIX_OBJECT,
+                                              COS_Object_Type_String,
+                                              1},
+                                             3, "composition"};
+
+COS_Symbol_ent cos_symbol_ent_composition = { {COS_OBJECT_PREFIX_OBJECT,
+                                              COS_Object_Type_Symbol,
+                                              1},
+                                             &cos_string_ent_composition,
+                                             NULL};
+
+COS_Symbol cos_Qcomposition = &cos_symbol_ent_composition;
+
+
 COS_Symbol_Table cos_default_symbol_table = NULL;
 
 
@@ -73,8 +87,8 @@ cos_make_symbol (COS_String string)
 int
 cos_retain_symbol (COS_Object obj)
 {
-  cos_retain_object (((COS_Symbol)obj)->value);
-  cos_retain_object (((COS_Symbol)obj)->name);
+  //cos_retain_object (((COS_Symbol)obj)->value);
+  //cos_retain_object (((COS_Symbol)obj)->name);
   return 0;
 }
 
@@ -84,6 +98,10 @@ cos_release_symbol (COS_Object obj)
   if (obj == NULL)
     return 0;
 
+  if ( (obj == cos_Qnil) || (obj == cos_Qt) ||
+       (obj == cos_Qcomposition) )
+    return 0;
+
   if ( ((COS_Symbol)obj)->value != NULL)
     cos_release_object (((COS_Symbol)obj)->value);
 
@@ -92,6 +110,12 @@ cos_release_symbol (COS_Object obj)
   return 0;
 }
 
+int
+cos_symbol_p (COS_object obj)
+{
+  return COS_OBJECT_SYMBOL_P (obj);
+}
+
 COS_Symbol
 cos_symbol_table_intern (COS_Symbol_Table table, COS_object name)
 {
@@ -123,10 +147,13 @@ cos_symbol_table_intern (COS_Symbol_Table table, COS_object name)
          table->data[i] = entry;
          return entry;
        }
-      else if ( (entry->name->size == key_string->size)
+      else if ( COS_OBJECT_SYMBOL_P (entry)
+               && COS_OBJECT_STRING_P (entry->name)
+               && (entry->name->size == key_string->size)
                && (memcmp (entry->name->data,
                            key_string->data, key_string->size) == 0) )
        {
+         cos_retain_object ((COS_object)entry);
          return entry;
        }
     }
@@ -238,6 +265,7 @@ cos_intern (COS_object name)
       cos_default_symbol_table = cos_make_symbol_table();
       cos_symbol_table_set (cos_default_symbol_table, cos_Qnil);
       cos_symbol_table_set (cos_default_symbol_table, cos_Qt);
+      cos_symbol_table_set (cos_default_symbol_table, cos_Qcomposition);
     }
   return cos_symbol_table_intern (cos_default_symbol_table, name);
 }
@@ -273,6 +301,26 @@ cos_symbol_table_set (COS_Symbol_Table table, COS_Symbol symbol)
 }
 
 int
+cos_print_symbol_table (COS_Symbol_Table table)
+{
+  int i;
+  COS_Symbol entry;
+
+  if (table == NULL)
+    table = cos_default_symbol_table;
+
+  printf ("#[symbol_table %lX\tsize = %d", table->size);
+  for (i = 0; i < table->size; i++)
+    {
+      entry = table->data[i];
+      printf ("\n\t%d : ", i);
+      cos_print_object (entry);
+    }
+  printf ("\t]\n");
+  return 0;
+}
+
+int
 cos_symbol_table_grow (COS_Symbol_Table table)
 {
   COS_Symbol_Table new_table
@@ -283,6 +331,8 @@ cos_symbol_table_grow (COS_Symbol_Table table)
   if (new_table == NULL)
     return -1;
 
+  //printf ("\n(old table is ");
+  //cos_print_symbol_table (table);
   for (i = 0; i < table->size; i++)
     {
       COS_Symbol entry = table->data[i];
@@ -302,5 +352,8 @@ cos_symbol_table_grow (COS_Symbol_Table table)
   table->size = new_table->size;
   table->data = new_table->data;
   free (new_table);
+  //printf ("\t)\n(new table is ");
+  //cos_print_symbol_table (table);
+  //printf ("\t)\n");
   return 0;
 }