00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUEX_TYPEVAR_H
00019 #define CUEX_TYPEVAR_H
00020
00021 #include <cuex/fwd.h>
00022 #include <cuex/var.h>
00023 #include <atomic_ops.h>
00024
00025 CU_BEGIN_DECLARATIONS
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #define cuex_tvarmeta(qc) cuex_varmeta_kqi(cuex_varkind_tvar, qc, 0)
00041
00042 CU_SINLINE cu_bool_t cuex_is_tvarmeta_q(cuex_meta_t meta, cuex_qcode_t qc)
00043 { return meta == cuex_tvarmeta(qc); }
00044
00045 CU_SINLINE cu_bool_t cuex_is_tvarmeta(cuex_meta_t meta)
00046 { return cuex_is_varmeta_k(meta, cuex_varkind_tvar); }
00047
00048
00049 struct cuex_tvar
00050 {
00051 cu_inherit (cuoo_type);
00052 AO_t type;
00053 };
00054
00055
00056 CU_SINLINE cu_bool_t cuex_is_tvar(cuex_t ex)
00057 { return cuex_is_tvarmeta(cuex_meta(ex)); }
00058
00059
00060 CU_SINLINE cu_bool_t cuex_tvar_is_type(cuex_tvar_t tv)
00061 { return cuoo_type_shape(cu_to(cuoo_type, tv)) != CUOO_SHAPE_NONE; }
00062
00063
00064 CU_SINLINE cuoo_type_t cuex_tvar_to_type(cuex_tvar_t tv)
00065 { return cu_to(cuoo_type, tv); }
00066
00067
00068
00069 CU_SINLINE cuex_tvar_t cuex_tvar_from_type(cuoo_type_t t)
00070 { return cu_from(cuex_tvar, cuoo_type, t); }
00071
00072
00073 CU_SINLINE cuex_var_t cuex_tvar_to_var(cuex_tvar_t tv)
00074 { return (cuex_var_t)tv; }
00075
00076
00077
00078 CU_SINLINE cuex_tvar_t cuex_tvar_from_var(cuex_var_t v)
00079 { return (cuex_tvar_t)v; }
00080
00081
00082 cuex_tvar_t cuex_tvar_new_type(cuex_qcode_t qc, cuoo_type_t type);
00083
00084
00085 cuex_tvar_t cuex_tvar_new_obj(cuex_qcode_t qc, cuoo_type_t type);
00086
00087
00088 cuex_tvar_t cuex_tvar_new_as(cuex_tvar_t v);
00089
00090
00091 CU_SINLINE cuex_tvar_t cuex_tvar_new_utype(void)
00092 { return cuex_tvar_new_type(cuex_qcode_u, NULL); }
00093
00094
00095 CU_SINLINE cuex_tvar_t cuex_tvar_new_etype(void)
00096 { return cuex_tvar_new_type(cuex_qcode_e, NULL); }
00097
00098
00099 CU_SINLINE cuex_tvar_t cuex_tvar_new_uobj(void)
00100 { return cuex_tvar_new_obj(cuex_qcode_u, NULL); }
00101
00102
00103 CU_SINLINE cuex_tvar_t cuex_tvar_new_eobj(void)
00104 { return cuex_tvar_new_obj(cuex_qcode_e, NULL); }
00105
00106
00107 CU_SINLINE cuoo_type_t
00108 cuex_tvar_type(cuex_tvar_t tv) { return (cuoo_type_t)tv->type; }
00109
00110 CU_SINLINE void
00111 cuex_tvar_set_type(cuex_tvar_t tv, cuex_t type)
00112 {
00113
00114 AO_store(&tv->type, (AO_t)type);
00115 }
00116
00117
00118
00119 CU_SINLINE cuoo_type_t
00120 cuex_tvar_force_utype(cuex_tvar_t tv)
00121 {
00122 if (!tv->type)
00123 AO_compare_and_swap(&tv->type, 0, (AO_t)cuex_tvar_new_utype());
00124 return (cuoo_type_t)tv->type;
00125 }
00126
00127
00128 CU_END_DECLARATIONS
00129
00130 #endif