1 /* multidispatch.h 2 * Copyright (C) 2003-2007, Parrot Foundation. 3 * Overview: 4 * This is the API header for the mmd subsystem 5 * Data Structure and Algorithms: 6 * History: 7 * Notes: 8 * References: 9 */ 10 11 #ifndef PARROT_MMD_H_GUARD 12 #define PARROT_MMD_H_GUARD 13 14 #include "parrot/config.h" 15 #include "parrot/compiler.h" 16 #include "parrot/parrot.h" 17 18 #define PARROT_MMD_MAX_CLASS_DEPTH 1000 19 #define Parrot_mmd_cache_destroy(x, y) 20 21 /* function typedefs */ 22 typedef PMC* (*mmd_f_p_ppp)(PARROT_INTERP, PMC *, PMC *, PMC *); 23 typedef PMC* (*mmd_f_p_pip)(PARROT_INTERP, PMC *, INTVAL, PMC *); 24 typedef PMC* (*mmd_f_p_pnp)(PARROT_INTERP, PMC *, FLOATVAL, PMC *); 25 typedef PMC* (*mmd_f_p_psp)(PARROT_INTERP, PMC *, STRING *, PMC *); 26 27 typedef void (*mmd_f_v_pp)(PARROT_INTERP, PMC *, PMC *); 28 typedef void (*mmd_f_v_pi)(PARROT_INTERP, PMC *, INTVAL); 29 typedef void (*mmd_f_v_pn)(PARROT_INTERP, PMC *, FLOATVAL); 30 typedef void (*mmd_f_v_ps)(PARROT_INTERP, PMC *, STRING *); 31 32 typedef INTVAL (*mmd_f_i_pp)(PARROT_INTERP, PMC *, PMC *); 33 34 typedef struct _MMD_init { 35 INTVAL func_nr; 36 INTVAL left, right; 37 funcptr_t func_ptr; 38 } MMD_init; 39 40 typedef struct _MMD_table { 41 funcptr_t *mmd_funcs; /* The functions for the MMD table */ 42 UINTVAL x; /* The x coord for each table */ 43 UINTVAL y; /* The y coord for each table */ 44 } MMD_table; 45 46 typedef struct _multi_func_list { 47 /* TT #646 48 * This STRING ideally must be const but actually can't. 49 */ 50 STRING *multi_name; 51 STRING *short_sig; 52 STRING *full_sig; 53 STRING *ns_name; 54 funcptr_t func_ptr; 55 } multi_func_list; 56 57 #define MMD_Cache PMC 58 59 /* HEADERIZER BEGIN: src/multidispatch.c */ 60 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ 61 62 PARROT_EXPORT 63 void Parrot_mmd_add_multi_from_c_args(PARROT_INTERP, 64 ARGIN(const char *sub_name), 65 ARGIN(const char *short_sig), 66 ARGIN(const char *long_sig), 67 ARGIN(funcptr_t multi_func_ptr)) 68 __attribute__nonnull__(1) 69 __attribute__nonnull__(2) 70 __attribute__nonnull__(3) 71 __attribute__nonnull__(4) 72 __attribute__nonnull__(5); 73 74 PARROT_EXPORT 75 void Parrot_mmd_add_multi_from_long_sig(PARROT_INTERP, 76 ARGIN(STRING *sub_name), 77 ARGIN(STRING *long_sig), 78 ARGIN(PMC *sub_obj)) 79 __attribute__nonnull__(1) 80 __attribute__nonnull__(2) 81 __attribute__nonnull__(3) 82 __attribute__nonnull__(4); 83 84 PARROT_EXPORT 85 void Parrot_mmd_add_multi_list_from_c_args(PARROT_INTERP, 86 ARGIN(const multi_func_list *mmd_info), 87 INTVAL elements) 88 __attribute__nonnull__(1) 89 __attribute__nonnull__(2); 90 91 PARROT_EXPORT 92 PARROT_CANNOT_RETURN_NULL 93 PARROT_WARN_UNUSED_RESULT 94 PMC* Parrot_mmd_build_type_tuple_from_sig_obj(PARROT_INTERP, 95 ARGIN(PMC *sig_obj)) 96 __attribute__nonnull__(1) 97 __attribute__nonnull__(2); 98 99 PARROT_EXPORT 100 PARROT_CANNOT_RETURN_NULL 101 MMD_Cache * Parrot_mmd_cache_create(PARROT_INTERP) 102 __attribute__nonnull__(1); 103 104 PARROT_EXPORT 105 PARROT_WARN_UNUSED_RESULT 106 PARROT_CAN_RETURN_NULL 107 PMC * Parrot_mmd_cache_lookup_by_types(PARROT_INTERP, 108 ARGMOD(MMD_Cache *cache), 109 ARGIN(const char *name), 110 ARGIN(PMC *types)) 111 __attribute__nonnull__(1) 112 __attribute__nonnull__(2) 113 __attribute__nonnull__(3) 114 __attribute__nonnull__(4) 115 FUNC_MODIFIES(*cache); 116 117 PARROT_EXPORT 118 PARROT_WARN_UNUSED_RESULT 119 PARROT_CAN_RETURN_NULL 120 PMC * Parrot_mmd_cache_lookup_by_values(PARROT_INTERP, 121 ARGMOD(MMD_Cache *cache), 122 ARGIN(const char *name), 123 ARGIN(PMC *values)) 124 __attribute__nonnull__(1) 125 __attribute__nonnull__(2) 126 __attribute__nonnull__(3) 127 __attribute__nonnull__(4) 128 FUNC_MODIFIES(*cache); 129 130 PARROT_EXPORT 131 void Parrot_mmd_cache_mark(PARROT_INTERP, ARGMOD(MMD_Cache *cache)) 132 __attribute__nonnull__(1) 133 __attribute__nonnull__(2) 134 FUNC_MODIFIES(*cache); 135 136 PARROT_EXPORT 137 void Parrot_mmd_cache_store_by_types(PARROT_INTERP, 138 ARGMOD(MMD_Cache *cache), 139 ARGIN(const char *name), 140 ARGIN(PMC *types), 141 ARGIN(PMC *chosen)) 142 __attribute__nonnull__(1) 143 __attribute__nonnull__(2) 144 __attribute__nonnull__(3) 145 __attribute__nonnull__(4) 146 __attribute__nonnull__(5) 147 FUNC_MODIFIES(*cache); 148 149 PARROT_EXPORT 150 void Parrot_mmd_cache_store_by_values(PARROT_INTERP, 151 ARGMOD(MMD_Cache *cache), 152 ARGIN(const char *name), 153 ARGIN(PMC *values), 154 ARGIN(PMC *chosen)) 155 __attribute__nonnull__(1) 156 __attribute__nonnull__(2) 157 __attribute__nonnull__(3) 158 __attribute__nonnull__(4) 159 __attribute__nonnull__(5) 160 FUNC_MODIFIES(*cache); 161 162 PARROT_EXPORT 163 PARROT_CAN_RETURN_NULL 164 PARROT_WARN_UNUSED_RESULT 165 PMC * Parrot_mmd_find_multi_from_long_sig(PARROT_INTERP, 166 ARGIN(STRING *name), 167 ARGIN(STRING *long_sig)) 168 __attribute__nonnull__(1) 169 __attribute__nonnull__(2) 170 __attribute__nonnull__(3); 171 172 PARROT_EXPORT 173 PARROT_WARN_UNUSED_RESULT 174 PARROT_CANNOT_RETURN_NULL 175 PMC* Parrot_mmd_find_multi_from_sig_obj(PARROT_INTERP, 176 ARGIN(STRING *name), 177 ARGIN(PMC *invoke_sig)) 178 __attribute__nonnull__(1) 179 __attribute__nonnull__(2) 180 __attribute__nonnull__(3); 181 182 PARROT_EXPORT 183 PARROT_CAN_RETURN_NULL 184 void Parrot_mmd_multi_dispatch_from_c_args(PARROT_INTERP, 185 ARGIN(const char *name), 186 ARGIN(const char *sig), 187 ...) 188 __attribute__nonnull__(1) 189 __attribute__nonnull__(2) 190 __attribute__nonnull__(3); 191 192 PARROT_EXPORT 193 PARROT_CAN_RETURN_NULL 194 PARROT_WARN_UNUSED_RESULT 195 PMC * Parrot_mmd_sort_manhattan_by_sig_pmc(PARROT_INTERP, 196 ARGIN(PMC *candidates), 197 ARGIN(PMC *invoke_sig)) 198 __attribute__nonnull__(1) 199 __attribute__nonnull__(2) 200 __attribute__nonnull__(3); 201 202 #define ASSERT_ARGS_Parrot_mmd_add_multi_from_c_args \ 203 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 204 PARROT_ASSERT_ARG(interp) \ 205 , PARROT_ASSERT_ARG(sub_name) \ 206 , PARROT_ASSERT_ARG(short_sig) \ 207 , PARROT_ASSERT_ARG(long_sig) \ 208 , PARROT_ASSERT_ARG(multi_func_ptr)) 209 #define ASSERT_ARGS_Parrot_mmd_add_multi_from_long_sig \ 210 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 211 PARROT_ASSERT_ARG(interp) \ 212 , PARROT_ASSERT_ARG(sub_name) \ 213 , PARROT_ASSERT_ARG(long_sig) \ 214 , PARROT_ASSERT_ARG(sub_obj)) 215 #define ASSERT_ARGS_Parrot_mmd_add_multi_list_from_c_args \ 216 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 217 PARROT_ASSERT_ARG(interp) \ 218 , PARROT_ASSERT_ARG(mmd_info)) 219 #define ASSERT_ARGS_Parrot_mmd_build_type_tuple_from_sig_obj \ 220 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 221 PARROT_ASSERT_ARG(interp) \ 222 , PARROT_ASSERT_ARG(sig_obj)) 223 #define ASSERT_ARGS_Parrot_mmd_cache_create __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 224 PARROT_ASSERT_ARG(interp)) 225 #define ASSERT_ARGS_Parrot_mmd_cache_lookup_by_types \ 226 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 227 PARROT_ASSERT_ARG(interp) \ 228 , PARROT_ASSERT_ARG(cache) \ 229 , PARROT_ASSERT_ARG(name) \ 230 , PARROT_ASSERT_ARG(types)) 231 #define ASSERT_ARGS_Parrot_mmd_cache_lookup_by_values \ 232 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 233 PARROT_ASSERT_ARG(interp) \ 234 , PARROT_ASSERT_ARG(cache) \ 235 , PARROT_ASSERT_ARG(name) \ 236 , PARROT_ASSERT_ARG(values)) 237 #define ASSERT_ARGS_Parrot_mmd_cache_mark __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 238 PARROT_ASSERT_ARG(interp) \ 239 , PARROT_ASSERT_ARG(cache)) 240 #define ASSERT_ARGS_Parrot_mmd_cache_store_by_types \ 241 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 242 PARROT_ASSERT_ARG(interp) \ 243 , PARROT_ASSERT_ARG(cache) \ 244 , PARROT_ASSERT_ARG(name) \ 245 , PARROT_ASSERT_ARG(types) \ 246 , PARROT_ASSERT_ARG(chosen)) 247 #define ASSERT_ARGS_Parrot_mmd_cache_store_by_values \ 248 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 249 PARROT_ASSERT_ARG(interp) \ 250 , PARROT_ASSERT_ARG(cache) \ 251 , PARROT_ASSERT_ARG(name) \ 252 , PARROT_ASSERT_ARG(values) \ 253 , PARROT_ASSERT_ARG(chosen)) 254 #define ASSERT_ARGS_Parrot_mmd_find_multi_from_long_sig \ 255 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 256 PARROT_ASSERT_ARG(interp) \ 257 , PARROT_ASSERT_ARG(name) \ 258 , PARROT_ASSERT_ARG(long_sig)) 259 #define ASSERT_ARGS_Parrot_mmd_find_multi_from_sig_obj \ 260 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 261 PARROT_ASSERT_ARG(interp) \ 262 , PARROT_ASSERT_ARG(name) \ 263 , PARROT_ASSERT_ARG(invoke_sig)) 264 #define ASSERT_ARGS_Parrot_mmd_multi_dispatch_from_c_args \ 265 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 266 PARROT_ASSERT_ARG(interp) \ 267 , PARROT_ASSERT_ARG(name) \ 268 , PARROT_ASSERT_ARG(sig)) 269 #define ASSERT_ARGS_Parrot_mmd_sort_manhattan_by_sig_pmc \ 270 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 271 PARROT_ASSERT_ARG(interp) \ 272 , PARROT_ASSERT_ARG(candidates) \ 273 , PARROT_ASSERT_ARG(invoke_sig)) 274 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ 275 /* HEADERIZER END: src/multidispatch.c */ 276 277 278 #endif /* PARROT_MMD_H_GUARD */ 279 280 /* 281 * Local variables: 282 * c-file-style: "parrot" 283 * End: 284 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : 285 */ 286