Definition at line 265 of file overload.cpp.
overloaded_routine_rep | ( | const generic & | name, | |
const environment & | env2 | |||
) | [inline] |
Definition at line 277 of file overload.cpp.
00277 : 00278 routine_rep (name), 00279 env (env2), 00280 serial (env->serial), 00281 nullary (exception_routine (name)), 00282 fall_back (exception_routine (name)), 00283 status (0) {} overloaded_routine_rep (const generic& name,
overloaded_routine_rep | ( | const generic & | name, | |
const vector< routine > & | funs2, | |||
const environment & | env2, | |||
const nat & | serial2, | |||
const routine & | nullary2, | |||
const table< routine, nat > & | unary2, | |||
const table< routine, nat > & | binary2, | |||
const table< routine, vector< nat > > & | n_ary2, | |||
const routine & | fall_back2, | |||
const nat & | status2 | |||
) | [inline] |
Definition at line 284 of file overload.cpp.
00293 : 00294 routine_rep (name), funs (funs2), env (env2), serial (serial2), 00295 nullary (nullary2), unary (unary2), binary (binary2), 00296 n_ary (n_ary2), fall_back (fall_back2), status (status2) {} void invalidate () const {
Reimplemented from routine_rep.
Definition at line 395 of file overload.cpp.
References mmx::is_nil(), and mmx::type().
00395 { 00396 up_to_date (); 00397 routine fun= n_ary[type (v)]; 00398 if (is_nil (fun)) fun= resolve (v); 00399 return fun->apply (v); 00400 }
Reimplemented from routine_rep.
Definition at line 388 of file overload.cpp.
References mmx::binary_id(), mmx::is_nil(), and mmx::type().
Reimplemented from routine_rep.
Definition at line 369 of file overload.cpp.
References mmx::apply(), mmx::busy(), mmx::is(), mmx::is_nil(), mmx::N(), and mmx::type().
00369 { 00370 if (is<iterator<generic> > (x1)) { 00371 vector<generic> v; 00372 iterator<generic> it= as<iterator<generic> > (x1); 00373 while (busy (it)) { 00374 generic next= *it; ++it; 00375 v << next; 00376 if (is<exception> (next)) return next; 00377 } 00378 if (N(v) == 0) return apply (); 00379 else if (N(v) == 1) return apply (v[0]); 00380 else if (N(v) == 2) return apply (v[0], v[1]); 00381 else return apply (v); 00382 } 00383 up_to_date (); 00384 routine fun= unary[type (x1)]; 00385 if (is_nil (fun)) fun= resolve (vec<generic> (x1)); 00386 return fun->apply (x1); 00387 }
generic apply | ( | ) | const [inline, virtual] |
Reimplemented from routine_rep.
Definition at line 366 of file overload.cpp.
routine clone | ( | ) | const [inline, virtual] |
Reimplemented from routine_rep.
Definition at line 456 of file overload.cpp.
References mmx::copy().
00456 { 00457 return new overloaded_routine_rep 00458 (name, funs, env, serial, 00459 nullary, copy (unary), copy (binary), 00460 copy (n_ary), fall_back, status); 00461 }
generic function_body | ( | ) | const [inline, virtual] |
Reimplemented from routine_rep.
Definition at line 448 of file overload.cpp.
References mmx::comma(), mmx::N(), and mmx::xsqtuple().
generic function_type | ( | ) | const [inline, virtual] |
Reimplemented from routine_rep.
Definition at line 440 of file overload.cpp.
References mmx::comma(), mmx::N(), and mmx::xsqtuple().
void invalidate | ( | ) | const [inline] |
Definition at line 297 of file overload.cpp.
Referenced by overloaded_routine_rep::overload().
00297 { 00298 overloaded_routine_rep* me= 00299 const_cast<overloaded_routine_rep*> (this); 00300 me->unary = table<routine,nat> (); 00301 me->binary= table<routine,nat> (); 00302 me->n_ary = table<routine,vector<nat> > (); 00303 me->serial= env->serial; 00304 }
bool is_overloaded | ( | ) | const [inline, virtual] |
void overload | ( | const routine & | fun | ) | const [inline, virtual] |
Reimplemented from routine_rep.
Definition at line 402 of file overload.cpp.
References mmx::cdr(), mmx::exact_neq(), mmx::GEN_SQTUPLE, overloaded_routine_rep::invalidate(), mmx::is_tuple_type(), mmx::N(), and mmx::type_id().
00402 { 00403 if (fun->is_overloaded ()) { 00404 vector<routine> rs= fun->meanings (); 00405 for (nat i=0; i<N(rs); i++) 00406 overload (rs[i]); 00407 return; 00408 } 00409 00410 overloaded_routine_rep* me= 00411 const_cast<overloaded_routine_rep*> (this); 00412 vector<nat> ids= fun->signature (); 00413 /* 00414 if (!using_simple () && exact_eq (fun->name, GEN_TIMES)) { 00415 mmout << fun << "\t: " << type_name (ids) << "\n"; 00416 //mmout << "\t: " << env << "\n"; 00417 } 00418 */ 00419 if (N(ids) == 0) { me->fall_back= fun; me->status |= 1; } 00420 else if (N(ids) == 1) { me->nullary= fun; me->status |= 2; } 00421 else { 00422 nat i, n= N(funs); 00423 for (i=0; i<n; i++) { 00424 vector<nat> ids2= funs[i]->signature (); 00425 if (cdr (ids) == cdr (ids2)) { 00426 me->funs[i]= fun; 00427 break; 00428 } 00429 } 00430 if (i==n) me->funs << fun; 00431 if (N(ids) == 2 && is_tuple_type (ids[1])) 00432 if (exact_neq (fun->name, GEN_SQTUPLE) || 00433 ids[1] == type_id<tuple<generic> > ()) 00434 me->nullary= via_tuple_routine (fun, vec<nat> (ids[0]), 2); 00435 } 00436 me->invalidate (); 00437 }
Definition at line 310 of file overload.cpp.
References mmx::binary_id(), mmx::cdr(), mmx::is_nil(), mmx::is_tuple_type(), mmx::N(), PENALTY_INVALID, and mmx::type().
00310 { 00311 overloaded_routine_rep* me= 00312 const_cast<overloaded_routine_rep*> (this); 00313 routine best; 00314 const vector<nat> ids= cons<nat> (0, type (args)); 00315 bool exc_args= false; 00316 bool grouped_args= false; 00317 bool genalias_args= false; 00318 for (nat i=1; i<N(ids); i++) { 00319 exc_args = exc_args || ids[i] == type_id<exception> (); 00320 grouped_args = grouped_args || is_tuple_type (ids[i]); 00321 grouped_args = grouped_args || ids[i] == type_id<iterator<generic> > (); 00322 genalias_args= genalias_args || ids[i] == type_id<alias<generic> > (); 00323 } 00324 if (exc_args) best= exception_routine (name); 00325 else if (grouped_args) 00326 best= equalize_grouped_routine (routine (me, true), ids); 00327 else if (genalias_args) 00328 best= specialize_alias_routine (routine (me, true), ids); 00329 else { 00330 vector<nat> best_ids; 00331 nat best_pen= PENALTY_INVALID; 00332 for (nat i=0; i<N(funs); i++) { 00333 vector<nat> fun_ids= funs[i]->signature (); 00334 nat pen= conversion_penalty (env, ids, fun_ids); 00335 //mmout << "Try " << name << ", " << type_name (fun_ids) 00336 //<< " on " << type_name (ids) << "\n"; 00337 if (pen <= best_pen && pen < PENALTY_INVALID) { 00338 if (pen < best_pen || 00339 conversion_penalty (env, fun_ids, best_ids) < 00340 conversion_penalty (env, best_ids, fun_ids)) 00341 { 00342 //mmout << " OK, and better (" << pen << ")\n"; 00343 best= build (env, funs[i], ids, fun_ids); 00344 best_ids= fun_ids; 00345 best_pen= pen; 00346 } 00347 //else mmout << " OK, but less good (" << pen << ")\n"; 00348 } 00349 } 00350 } 00351 if (is_nil (best)) { 00352 bool dyn_flag= false; 00353 for (nat i=0; i<N(args); i++) 00354 if (is<dynamic> (args[i])) dyn_flag= true; 00355 if (dyn_flag) { 00356 // FIXME: routine no longer freed due to circular dependency 00357 best= dynamic_routine (routine (this, true)); 00358 } 00359 else best= fall_back; 00360 } 00361 if (N(ids) == 2) me->unary [ids[1]]= best; 00362 else if (N(ids) == 3) me->binary [binary_id (ids[1], ids[2])]= best; 00363 if (N(ids) <= 7) me->n_ary [cdr (ids)]= best; 00364 return best; 00365 }
Reimplemented from routine_rep.
Definition at line 401 of file overload.cpp.
void up_to_date | ( | ) | const [inline] |
Definition at line 305 of file overload.cpp.
References mmx::is_nil().
00305 { 00306 if (!is_nil (env->next) && env->next_serial != env->next->serial) 00307 env->ensure_up_to_date (); 00308 if (serial != env->serial) invalidate (); 00309 }