00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUDYN_MISC_H
00019 #define CUDYN_MISC_H
00020
00021 #include <cudyn/fwd.h>
00022 #include <cuoo/properties.h>
00023 #include <cuoo/halloc.h>
00024 #include <cudyn/typetpl.h>
00025 #include <cudyn/type.h>
00026 #include <cu/idr.h>
00027 #include <cu/ptr.h>
00028 #include <stdlib.h>
00029 #include <stdint.h>
00030
00031 CU_BEGIN_DECLARATIONS
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 CUDYN_ETYPEARR_DCLN( int8, int8_t)
00050 CUDYN_ETYPEARR_DCLN( uint8, uint8_t)
00051 CUDYN_ETYPEARR_DCLN( int16, int16_t)
00052 CUDYN_ETYPEARR_DCLN(uint16, uint16_t)
00053 CUDYN_ETYPEARR_DCLN( int32, int32_t)
00054 CUDYN_ETYPEARR_DCLN(uint32, uint32_t)
00055 CUDYN_ETYPEARR_DCLN( int64, int64_t)
00056 CUDYN_ETYPEARR_DCLN(uint64, uint64_t)
00057
00058
00059
00060
00061
00062
00063
00064 extern cudyn_elmtype_t cudynP_unit_type;
00065 extern cuex_t cudynP_unit_value;
00066
00067 CU_SINLINE cuoo_type_t cudyn_unit_type()
00068 { return cudyn_elmtype_to_type(cudynP_unit_type); }
00069
00070 CU_SINLINE cuex_t cudyn_unit_value()
00071 { return cudynP_unit_value; }
00072
00073
00074
00075 extern cudyn_elmtype_t cudynP_bool_type;
00076
00077 CU_SINLINE cuoo_type_t cudyn_bool_type()
00078 { return cudyn_elmtype_to_type(cudynP_bool_type); }
00079
00080 CU_SINLINE cuex_t cudyn_bool(cu_bool_t x)
00081 {
00082 x = !!x;
00083 return cuoo_halloc(cudyn_bool_type(), sizeof(cu_word_t), &x);
00084 }
00085
00086 CU_SINLINE cu_bool_t cudyn_is_bool(cuex_t ex)
00087 { return cuex_meta(ex) == cuoo_type_to_meta(cudyn_bool_type()); }
00088
00089 CU_SINLINE cu_bool_t cudyn_to_bool(cuex_t ex)
00090 { return *(cu_word_t *)((char *)ex + CUOO_HCOBJ_SHIFT); }
00091
00092 extern cuex_t cudynP_true;
00093 extern cuex_t cudynP_false;
00094
00095 #define cudyn_true() cudynP_true
00096 #define cudyn_false() cudynP_false
00097
00098
00099
00100 CUDYN_ETYPEARR_DCLN(float, float)
00101 CUDYN_ETYPEARR_DCLN(double, double)
00102
00103
00104
00105 CUDYN_ETYPEARR_DCLN(char, char)
00106
00107
00108
00109 CUDYN_ARRTYPE_DCLN(cuex, cuex_t)
00110 CUDYN_ETYPEARR_DCLN(metaint, cuex_meta_t)
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 CUDYN_ETYPEARR_ALIAS(uchar, unsigned char, uint8)
00124
00125 #if CUCONF_SIZEOF_SHORT == 2
00126 CUDYN_ETYPEARR_ALIAS(short, short, int16)
00127 CUDYN_ETYPEARR_ALIAS(ushort, unsigned short, uint16)
00128 #elif CUCONF_SIZEOF_SHORT == 4
00129 CUDYN_ETYPEARR_ALIAS(short, short, int16)
00130 CUDYN_ETYPEARR_ALIAS(ushort, unsigned short, uint16)
00131 #else
00132 # error "Missing configuration macros or unexpected sizeof(short)"
00133 #endif
00134
00135 #if CUCONF_SIZEOF_INT == 2
00136 CUDYN_ETYPEARR_ALIAS(int, int, int16)
00137 CUDYN_ETYPEARR_ALIAS(uint, unsigned int, uint16)
00138 #elif CUCONF_SIZEOF_INT == 4
00139 CUDYN_ETYPEARR_ALIAS(int, int, int32)
00140 CUDYN_ETYPEARR_ALIAS(uint, unsigned int, uint32)
00141 #elif CUCONF_SIZEOF_INT == 8
00142 CUDYN_ETYPEARR_ALIAS(int, int, int64)
00143 CUDYN_ETYPEARR_ALIAS(uint, unsigned int, uint64)
00144 #else
00145 # error "Missing configuration macros or unexpected sizeof(int)"
00146 #endif
00147
00148 #if CUCONF_SIZEOF_LONG == 2
00149 CUDYN_ETYPEARR_ALIAS(long, long, int16)
00150 CUDYN_ETYPEARR_ALIAS(ulong, unsigned long, uint16)
00151 #elif CUCONF_SIZEOF_LONG == 4
00152 CUDYN_ETYPEARR_ALIAS(long, long, int32)
00153 CUDYN_ETYPEARR_ALIAS(ulong, unsigned long, uint32)
00154 #elif CUCONF_SIZEOF_LONG == 8
00155 CUDYN_ETYPEARR_ALIAS(long, long, int64)
00156 CUDYN_ETYPEARR_ALIAS(ulong, unsigned long, uint64)
00157 #else
00158 # error "Missing configuration macros or unexpected sizeof(long)"
00159 #endif
00160
00161 CU_SINLINE cuex_t
00162 cudyn_ptr(cudyn_ptrtype_t ptrtype, void *ptr)
00163 {
00164 return cuoo_halloc(cudyn_ptrtype_to_type(ptrtype), sizeof(void *), &ptr);
00165 }
00166
00167 CU_SINLINE void *
00168 cudyn_to_ptr(cuex_t e)
00169 { return *(void **)((char *)e + CUOO_HCOBJ_SHIFT); }
00170
00171
00172
00173
00174
00175 unsigned long cudyn_castget_ulong(cuex_t e);
00176
00177 cuex_t cudyn_load(cuoo_type_t t, void *ptr);
00178
00179
00180 CU_END_DECLARATIONS
00181
00182 #endif