00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUOO_TYPE_H
00019 #define CUOO_TYPE_H
00020
00021 #include <cuoo/hcobj.h>
00022 #include <cuoo/meta.h>
00023 #include <cu/thread.h>
00024 #include <cu/inherit.h>
00025 #include <cu/conf.h>
00026 #include <cu/memory.h>
00027 #include <cu/box.h>
00028 #include <stdint.h>
00029
00030 CU_BEGIN_DECLARATIONS
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #define CUOO_SHAPEFLAG_HCV UINT16_C(0x8000)
00044
00045
00046 #define CUOO_SHAPEFLAG_FIN UINT16_C(0x4000)
00047
00048
00049 #define CUOO_SHAPEFLAG_MASK UINT16_C(0xc000)
00050
00051
00052 #define CUOO_SHAPE_NONE 0x00
00053 #define CUOO_SHAPE_OPAQUE 0x01
00054 #define CUOO_SHAPE_OPAQUE_HCV (CUOO_SHAPE_OPAQUE|CUOO_SHAPEFLAG_HCV)
00055 #define CUOO_SHAPE_METATYPE 0x02
00056 #define CUOO_SHAPE_TVAR 0x03
00057 #define CUOO_SHAPE_PROTO 0x04
00058 #define CUOO_SHAPE_CTORTYPE 0x05
00059 #define CUOO_SHAPE_BY_EXPR 0x06
00060
00061
00062 #define CUOO_SHAPE_PTRTYPE 0x08
00063 #define CUOO_SHAPE_ARRTYPE 0x09
00064 #define CUOO_SHAPE_TUPTYPE 0x0a
00065 #define CUOO_SHAPE_UNIT 0x0f
00066
00067
00068 #define CUOO_SHAPE_SCALAR_BOOL 0x10
00069 #define CUOO_SHAPE_SCALAR_CHAR 0x11
00070 #define CUOO_SHAPE_SCALAR_METAINT 0x12
00071 #define CUOO_SHAPE_SCALAR_UINT8 0x16
00072 #define CUOO_SHAPE_SCALAR_INT8 0x17
00073 #define CUOO_SHAPE_SCALAR_UINT16 0x18
00074 #define CUOO_SHAPE_SCALAR_INT16 0x19
00075 #define CUOO_SHAPE_SCALAR_UINT32 0x1a
00076 #define CUOO_SHAPE_SCALAR_INT32 0x1b
00077 #define CUOO_SHAPE_SCALAR_UINT64 0x1c
00078 #define CUOO_SHAPE_SCALAR_INT64 0x1d
00079 #define CUOO_SHAPE_SCALAR_FLOAT 0x1e
00080 #define CUOO_SHAPE_SCALAR_DOUBLE 0x1f
00081
00082 #define CUOO_SHAPE_MIN_SCALAR_INT CUOO_SHAPE_SCALAR_UINT8
00083 #define CUOO_SHAPE_MAX_SCALAR_INT CUOO_SHAPE_SCALAR_INT64
00084 #define CUOO_SHAPE_MIN_SCALAR_FP CUOO_SHAPE_SCALAR_FLOAT
00085 #define CUOO_SHAPE_MAX_SCALAR_FP CUOO_SHAPE_SCALAR_DOUBLE
00086 #define CUOO_SHAPE_MIN_SCALAR CUOO_SHAPE_SCALAR_BOOL
00087 #define CUOO_SHAPE_MAX_SCALAR CUOO_SHAPE_MAX_SCALAR_FP
00088
00089 #define CUOO_SHAPE_CULIBS_END 0x100
00090
00091
00092
00093
00094 char const *cuoo_shape_name(cuoo_shape_t shape);
00095
00096
00097
00098 size_t cuoo_shape_valsize(cuoo_shape_t shape);
00099
00100
00101 CU_SINLINE cu_bool_t
00102 cuoo_shape_is_opaque(cuoo_shape_t shape)
00103 {
00104 shape &= ~CUOO_SHAPEFLAG_MASK;
00105 return shape == CUOO_SHAPE_OPAQUE;
00106 }
00107
00108
00109 CU_SINLINE cu_bool_t
00110 cuoo_shape_is_scalar(cuoo_shape_t shape)
00111 {
00112 shape &= ~CUOO_SHAPEFLAG_MASK;
00113 return shape >= CUOO_SHAPE_MIN_SCALAR
00114 && shape <= CUOO_SHAPE_MAX_SCALAR;
00115 }
00116
00117
00118 CU_SINLINE cu_bool_t
00119 cuoo_shape_is_scalar_int(cuoo_shape_t shape)
00120 {
00121 shape &= ~CUOO_SHAPEFLAG_MASK;
00122 return shape >= CUOO_SHAPE_MIN_SCALAR_INT
00123 && shape <= CUOO_SHAPE_MAX_SCALAR_INT;
00124 }
00125
00126
00127 CU_SINLINE cu_bool_t
00128 cuoo_shape_is_scalar_fp(cuoo_shape_t shape)
00129 {
00130 shape &= ~CUOO_SHAPEFLAG_MASK;
00131 return shape >= CUOO_SHAPE_MIN_SCALAR_FP
00132 && shape <= CUOO_SHAPE_MAX_SCALAR_FP;
00133 }
00134
00135
00136 CU_SINLINE cu_bool_t
00137 cuoo_shape_is_singleton(cuoo_shape_t shape)
00138 {
00139 shape &= ~CUOO_SHAPEFLAG_MASK;
00140 return shape == CUOO_SHAPE_UNIT
00141 || (shape >= CUOO_SHAPE_MIN_SCALAR && shape <= CUOO_SHAPE_MAX_SCALAR);
00142 }
00143
00144
00145
00146
00147
00148
00149 struct cuoo_type
00150 {
00151 CUOO_HCOBJ
00152
00153
00154
00155
00156
00157
00158 cuex_t as_expr;
00159
00160 uint_least16_t shape;
00161 uint_least16_t key_sizew;
00162
00163 cu_box_t (*impl)(cu_word_t intf_number, ...);
00164 };
00165
00166 extern cuoo_type_t cuooP_type_type;
00167
00168
00169 CU_SINLINE cuoo_type_t cuoo_type_type()
00170 { return cuooP_type_type; }
00171
00172
00173
00174 CU_SINLINE cu_bool_t cuex_meta_is_type(cuex_meta_t meta)
00175 { return cuex_meta_kind(meta) == cuex_meta_kind_type; }
00176
00177
00178 CU_SINLINE cu_bool_t cuoo_is_type(cuex_t e)
00179 {
00180 cuex_meta_t m = cuex_meta(e);
00181 return cuex_meta_is_type(m)
00182 && cuoo_type_from_meta(m)->shape == CUOO_SHAPE_METATYPE;
00183 }
00184
00185
00186
00187 CU_SINLINE cuoo_type_t cuoo_type_from_ex(cuex_t e)
00188 { return (cuoo_type_t)e; }
00189
00190
00191
00192 CU_SINLINE cuex_t cuoo_type_as_expr(cuoo_type_t t)
00193 { return t->as_expr? t->as_expr : t; }
00194
00195
00196 CU_SINLINE cuoo_shape_t cuoo_type_shape(cuoo_type_t type)
00197 { return type->shape; }
00198
00199 #define cuoo_type_impl(type, ...) ((type)->impl(__VA_ARGS__))
00200 #define cuoo_type_impl_ptr(type, ...) \
00201 cu_unbox_ptr(void *, (type)->impl(__VA_ARGS__))
00202 #define cuoo_type_impl_fptr(T, type, ...) \
00203 cu_unbox_fptr(T, (type)->impl(__VA_ARGS__))
00204
00205 CU_SINLINE cu_bool_t cuoo_type_is_hctype(cuoo_type_t type)
00206 { return type->key_sizew; }
00207
00208 CU_SINLINE cu_bool_t cuoo_type_is_metatype(cuoo_type_t type)
00209 { return type->shape == CUOO_SHAPE_METATYPE; }
00210
00211 CU_SINLINE cu_bool_t cuoo_type_is_inltype(cuoo_type_t type)
00212 { return (type->shape & ~CUOO_SHAPEFLAG_MASK) >= CUOO_SHAPE_PTRTYPE; }
00213
00214 CU_SINLINE cu_bool_t cuoo_type_is_nonptr_inltype(cuoo_type_t type)
00215 { return (type->shape & ~CUOO_SHAPEFLAG_MASK) > CUOO_SHAPE_PTRTYPE; }
00216
00217 CU_SINLINE cu_bool_t cuoo_type_is_proto(cuoo_type_t type)
00218 { return type->shape == CUOO_SHAPE_PROTO; }
00219
00220
00221
00222
00223 void cuoo_type_init_general(cuoo_type_t type, cuoo_shape_t shape,
00224 cuoo_impl_t impl, cuex_t atype);
00225
00226
00227 void cuoo_type_init_general_hcs(cuoo_type_t type, cuoo_shape_t shape,
00228 cuoo_impl_t impl, cuex_t atype,
00229 size_t key_size);
00230
00231
00232 void cuoo_type_init_general_hcv(cuoo_type_t type, cuoo_shape_t shape,
00233 cuoo_impl_t impl, cuex_t atype);
00234
00235
00236 void cuoo_type_init_opaque(cuoo_type_t type, cuoo_impl_t impl);
00237
00238
00239
00240 void cuoo_type_init_opaque_hcs(cuoo_type_t type, cuoo_impl_t impl,
00241 size_t key_size);
00242
00243
00244
00245 void cuoo_type_init_opaque_hcv(cuoo_type_t type, cuoo_impl_t impl);
00246
00247
00248 cuoo_type_t cuoo_type_new_opaque(cuoo_impl_t impl);
00249
00250
00251
00252 cuoo_type_t cuoo_type_new_opaque_hcs(cuoo_impl_t impl, size_t key_size);
00253
00254
00255
00256 cuoo_type_t cuoo_type_new_opaque_hcv(cuoo_impl_t impl);
00257
00258
00259 cuoo_type_t cuoo_type_new_metatype(cuoo_impl_t impl);
00260
00261
00262
00263 cuoo_type_t cuoo_type_new_metatype_hce(cuoo_impl_t impl);
00264
00265
00266 cuoo_type_t cuoo_type_new_metatype_hcs(cuoo_impl_t impl, size_t key_size);
00267
00268
00269 cu_str_t cuoo_type_to_str_default(cuex_t type);
00270
00271
00272
00273
00274
00275 void *cuoo_impl_ptr(cuex_t obj, cu_word_t intf);
00276
00277 cu_hash_t cuex_key_hash(void *obj);
00278
00279 #ifdef CUOO_ENABLE_KEYED_PROP
00280 cuoo_propkey_t cuoo_propkey_create(void);
00281
00282 void cuoo_prop_set(cuex_t ex, cuoo_propkey_t key, void *val);
00283 void *cuoo_prop_get(cuex_t ex, cuoo_propkey_t key);
00284 #endif
00285
00286
00287
00288
00289
00290 #define cuoo_stdtype_from_type(type) (type)
00291
00292 #define cuoo_stdtype_to_type(type) (type)
00293
00294 CU_END_DECLARATIONS
00295
00296 #endif