1 /* Internal definitions of CONCORD Object System
3 Copyright (C) 2013 MORIOKA Tomohiko
4 This file is part of the CONCORD Library.
6 The CONCORD Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The CONCORD Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the CONCORD Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
35 #ifndef SIZEOF_COS_INT
36 # define SIZEOF_COS_INT SIZEOF_VOID_P
40 # define SIZEOF_INT (sizeof (int))
44 # define SIZEOF_LONG (sizeof (long))
47 #ifndef SIZEOF_LONG_LONG
48 # define SIZEOF_LONG_LONG (sizeof (long long))
52 # if SIZEOF_COS_INT == SIZEOF_LONG
54 # elif SIZEOF_COS_INT == SIZEOF_INT
56 # elif SIZEOF_COS_INT == SIZEOF_LONG_LONG
57 # define COS_INT long long
59 # error Unable to determine suitable type for COS_INT
64 # define COS_UINT unsigned COS_INT
67 #define BITS_PER_COS_INT (SIZEOF_COS_INT * BITS_PER_CHAR)
77 #define COS_POINTER_TYPE_P(type) ((type) == COS_Type_Entity)
79 #define COS_TYPE_BITS 2
80 #define COS_INT_TYPE_BITS 1
82 #define COS_INT_VAL_BITS (BITS_PER_COS_INT - COS_INT_TYPE_BITS)
83 #define COS_VAL_BITS (BITS_PER_COS_INT - COS_TYPE_BITS)
84 #define COS_INT_MAX ((COS_INT) ((1UL << (COS_INT_VAL_BITS - 1)) -1UL))
85 #define COS_INT_MIN (-(COS_INT_MAX) - 1)
88 typedef struct COS_Object_Header
92 COS_INT reference_count;
95 #define COS_OBJECT_PREFIX_OBJECT 0
97 enum COS_Object_Type {
99 COS_Object_Type_C_String,
101 COS_Object_Type_char,
102 COS_Object_Type_String,
103 COS_Object_Type_Symbol,
104 COS_Object_Type_Cons,
105 COS_Object_Type_Container,
106 COS_Object_Type_Sexp,
107 COS_Object_Type_Binary,
109 COS_Object_Type_Genre,
110 COS_Object_Type_Feature,
111 COS_Object_Type_Feature_INDEX,
112 COS_Object_Type_DB_Object
115 #define COS_FAT_OBJECT_TYPE_MIN COS_Object_Type_String
116 #define COS_OBJECT_TYPE_MAX COS_Object_Type_DB_Object
118 extern int (*COS_Object_release_function_table[]) (COS_Object);
120 struct COS_Object_ent
122 COS_Object_Header header;
125 COS_Object cos_allocate_object_0 (enum COS_Object_Type type,
128 #define COS_ALLOCATE_OBJECT(type) \
129 ((COS_##type)cos_allocate_object_0(COS_Object_Type_##type, \
130 sizeof(COS_##type##_ent)))
132 #define COS_OBJECT_INT_P(obj) \
133 ((COS_UINT)(obj) & 1)
135 #define COS_OBJECT_CHAR_P(obj) \
136 ((COS_UINT)(obj) & 2)
138 #define COS_OBJECT_C_STRING_P(obj) \
140 && (((unsigned char *)obj)[0] != COS_OBJECT_PREFIX_OBJECT))
142 #define COS_OBJECT_P(obj) \
144 && (!COS_OBJECT_INT_P (obj)) \
145 && (!COS_OBJECT_CHAR_P (obj)) \
146 && (((unsigned char *)obj)[0] == COS_OBJECT_PREFIX_OBJECT))
148 #define COS_OBJECT_TYPE_P(obj, TYPE) \
149 (COS_OBJECT_P (obj) \
150 && (((COS_Object)obj)->header.type == COS_Object_Type_##TYPE))
152 #define COS_OBJECT_STRING_P(obj) \
153 COS_OBJECT_TYPE_P (obj, String)
155 #define COS_OBJECT_SYMBOL_P(obj) \
156 COS_OBJECT_TYPE_P (obj, Symbol)
158 #define COS_OBJECT_CONS_P(obj) \
159 COS_OBJECT_TYPE_P (obj, Cons)
161 #define COS_OBJECT_DS_P(obj) \
162 COS_OBJECT_TYPE_P (obj, DS)
164 #define COS_OBJECT_GENRE_P(obj) \
165 COS_OBJECT_TYPE_P (obj, Genre)
167 #define COS_OBJECT_FEATURE_P(obj) \
168 COS_OBJECT_TYPE_P (obj, Feature)
170 #define COS_OBJECT_FEATURE_INDEX_P(obj) \
171 COS_OBJECT_TYPE_P (obj, Feature_INDEX)
174 struct COS_String_ent
176 COS_Object_Header header;
182 int cos_release_string (COS_Object obj);
185 struct COS_Symbol_ent
187 COS_Object_Header header;
193 COS_Symbol cos_make_symbol (COS_String string);
195 int cos_release_symbol (COS_Object obj);
198 typedef struct COS_Symbol_Table_ent COS_Symbol_Table_ent;
199 typedef COS_Symbol_Table_ent* COS_Symbol_Table;
201 struct COS_Symbol_Table_ent
207 COS_Symbol_Table cos_make_symbol_table (void);
209 int cos_symbol_table_grow (COS_Symbol_Table table);
211 void cos_destroy_symbol_table (COS_Symbol_Table table);
213 int cos_symbol_table_set (COS_Symbol_Table table, COS_Symbol symbol);
216 cos_symbol_table_intern (COS_Symbol_Table table, COS_object name);
221 COS_Object_Header header;
227 #define COS_CAR(obj) \
228 (((COS_Cons)(obj))->car)
229 #define COS_CDR(obj) \
230 (((COS_Cons)(obj))->cdr)
232 int cos_release_cons (COS_Object obj);
235 struct COS_Container_ent
237 COS_Object_Header header;
246 int cos_release_container (COS_Object obj);
251 COS_Object_Header header;
257 int cos_release_sexp (COS_Object obj);
260 struct COS_Binary_ent
262 COS_Object_Header header;
268 int cos_release_binary (COS_Object obj);
271 int cos_release_ds (COS_Object obj);
274 int cos_release_genre (COS_Object obj);
276 int concord_close_genre (COS_Genre genre);
279 int cos_release_feature (COS_Object obj);
281 int concord_close_feature (COS_Feature feature);
284 int cos_release_index (COS_Object obj);
286 int concord_close_index (COS_Feature_INDEX table);
289 struct COS_DB_Object_ent
291 COS_Object_Header header;
297 int cos_release_db_object (COS_Object obj);
306 #endif /* !_COS_I_H */