#include <environment.hpp>
Definition at line 40 of file environment.hpp.
| environment_rep | ( | ) | [inline] |
| environment_rep | ( | const environment & | e ) | [inline] |
Definition at line 74 of file environment.hpp.
: next (e), serial (0), next_serial (next->serial), env_type (0) {}
| ~environment_rep | ( | ) | [inline] |
Definition at line 76 of file environment.hpp.
{}
| bool contains | ( | const generic & | var ) | const |
Definition at line 32 of file environment.cpp.
References environment_rep::bindings, mmx::is_nil(), and environment_rep::next.
Referenced by environment_rep::set_converter().
{
if (bindings->contains (var)) return true;
else if (is_nil (next)) return false;
else if (next->contains (var)) {
environment_rep* me= const_cast<environment_rep*> (this);
me->bindings [var]= next[var];
return true;
}
else return false;
}
| void ensure_up_to_date | ( | ) | const |
Definition at line 127 of file environment.cpp.
References mmx::is_nil(), environment_rep::next, environment_rep::next_serial, and environment_rep::serial.
Referenced by environment_rep::get_converter().
{
if (!is_nil (next)) {
next->ensure_up_to_date ();
if (next_serial != next->serial) {
environment_rep* me= const_cast<environment_rep*> (this);
me->serial++;
me->next_serial= next->serial;
}
}
}
| generic get | ( | const generic & | var ) | const |
Definition at line 56 of file environment.cpp.
References environment_rep::bindings, mmx::is_nil(), and environment_rep::next.
{
generic val;
if (bindings->get (var, val)) return val;
else if (is_nil (next)) return val;
else if (next->get (var, val)) {
environment_rep* me= const_cast<environment_rep*> (this);
me->bindings [var]= val;
return val;
}
else return val;
}
| bool get | ( | const generic & | var, |
| generic & | val | ||
| ) | const |
Definition at line 44 of file environment.cpp.
References environment_rep::bindings, mmx::is_nil(), and environment_rep::next.
{
if (bindings->get (var, val)) return true;
else if (is_nil (next)) return false;
else if (next->get (var, val)) {
environment_rep* me= const_cast<environment_rep*> (this);
me->bindings [var]= val;
return true;
}
else return false;
}
| generic get_converter | ( | nat | src, |
| nat | dest, | ||
| nat & | pen | ||
| ) | const |
Definition at line 166 of file environment.cpp.
References environment_rep::ensure_up_to_date(), environment_rep::next, mmx::read(), environment_rep::serial, environment_rep::set(), and mmx::tag().
{
//mmout << "Convert: " << src << ", " << dest << "\n";
if (src == dest) {
pen= 0;
return as<generic> (identity_routine (vec<nat> (dest, src)));
}
if (dest == 0) {
if (is_alias_type (src)) {
routine r;
alias_getter (src, r);
pen= PENALTY_FALL_BACK;
return as<generic> (r);
}
else {
pen= PENALTY_FALL_BACK;
return as<generic> (identity_routine (vec<nat> (dest, src)));
}
}
ensure_up_to_date ();
generic stamp;
bool ok= get (tag (GEN_CACHE_CONVERTERS, src), stamp);
if (!ok || !is<nat> (stamp) || serial != as<nat> (stamp)) {
environment_rep* me= const_cast<environment_rep*> (this);
table<routine,nat> funt;
table<nat,nat> trvt;
table<nat,nat> pent;
vector<nat> todo;
// setup identity converter
routine id= identity_routine (vec<nat> (src, src));
me->set (tag (GEN_CACHE_CONVERTER, src, src), as<generic> (id));
me->set (tag (GEN_CACHE_PENALTY, src, src), as<generic> ((nat) 0));
funt [src]= id;
trvt [src]= 3;
pent [src]= 0;
todo << src;
// setup converter to generic
if (src != 0) {
if (is_alias_type (src)) {
routine r;
alias_getter (src, r);
id= r;
}
else id= identity_routine (vec<nat> ((nat) 0, src));
me->set (tag (GEN_CACHE_CONVERTER, src, (nat) 0), as<generic> (id));
me->set (tag (GEN_CACHE_PENALTY, src, (nat) 0),
as<generic> ((nat) PENALTY_FALL_BACK));
funt [0]= id;
trvt [0]= 3;
pent [0]= PENALTY_FALL_BACK;
todo << 0;
}
// transitive closure
for (nat i=0; i<N(todo); i++) {
nat cur= read (todo, i);
generic cvs;
if (get (tag (GEN_CONVERTERS, cur), cvs)) {
generic all= gen (GEN_CONVERTERS, as<generic> (cur));
vector<nat> succ= as<vector<nat> > (cvs);
for (nat j=0; j<N(succ); j++) {
nat next = read (succ, j);
generic next_fun= get (tag (GEN_CONVERTER, cur, next));
generic next_trv= get (tag (GEN_TRANSITIVE, cur, next));
generic next_pen= get (tag (GEN_PENALTY, cur, next));
ASSERT (is<routine> (next_fun), "routine expected (get_converter)");
ASSERT (is<nat> (next_trv), "nat expected (get_converter)");
ASSERT (is<nat> (next_pen), "nat expected (get_converter)");
nat trv1= read (trvt, cur), trv2= as<nat> (next_trv);
nat pen1= read (pent, cur), pen2= as<nat> (next_pen);
nat trv= (trv1&1) + (trv2&2);
nat pen= max (pen1, pen2);
if (((trv1&2) != 0 ||
(trv2&1) != 0) &&
(!funt->contains (next) ||
pen <= read (pent, next)) &&
(pen < read (pent, next) ||
(trv & (~read (trvt, next))) > 0))
{
routine fun=
compose (as<routine> (next_fun), read (funt, cur));
me->set (tag (GEN_CACHE_CONVERTER, src, next), as<generic>(fun));
me->set (tag (GEN_CACHE_PENALTY, src, next), as<generic>(pen));
funt [next]= fun;
trvt [next]= trv;
pent [next]= pen;
todo << next;
//mmout << "Converter " << type_name (src) << " -> "
// << type_name (next) << ": " << pen << "\n";
}
}
}
}
// time stamp
me->set (tag (GEN_CACHE_CONVERTERS, src), as<generic> (serial));
}
generic fun;
if (get (tag (GEN_CACHE_CONVERTER, src, dest), fun)) {
generic penalty;
get (tag (GEN_CACHE_PENALTY, src, dest), penalty);
VERIFY (is<nat> (penalty), "penalty not found");
pen= as<nat> (penalty);
return fun;
}
pen= PENALTY_INVALID;
return as<generic> (routine ());
}
| generic name | ( | ) | const |
Definition at line 25 of file environment.cpp.
References environment_rep::bindings, mmx::is_nil(), and environment_rep::next.
| void reset | ( | const generic & | var ) | [inline] |
Definition at line 81 of file environment.hpp.
References environment_rep::bindings.
{
mmx::reset (bindings, var); }
| generic & set | ( | const generic & | var ) | [inline] |
Definition at line 77 of file environment.hpp.
References environment_rep::bindings.
Referenced by environment_rep::get_converter().
{
return bindings [var]; }
| void set | ( | const generic & | var, |
| const generic & | val | ||
| ) | [inline] |
Definition at line 79 of file environment.hpp.
References environment_rep::bindings.
{
bindings [var]= val; }
| void set_converter | ( | nat | src, |
| nat | dest, | ||
| const generic & | val, | ||
| nat | trv, | ||
| nat | pen | ||
| ) |
Definition at line 139 of file environment.cpp.
References environment_rep::contains(), environment_rep::serial, and mmx::tag().
{
/*
mmout << "Set converter " << as_lisp (type_name (src));
mmout << " -> " << as_lisp (type_name (dest));
mmout << ", trv= " << trv;
mmout << ", pen= " << pen;
mmout << "\n";
*/
// add the converter
set (tag (GEN_CONVERTER, src, dest), val);
set (tag (GEN_TRANSITIVE, src, dest), as<generic> (trv));
set (tag (GEN_PENALTY, src, dest), as<generic> (pen));
// add the converter to the list of converters
generic t= tag (GEN_CONVERTERS, src);
if (!contains (t)) set (t, as<generic> (vec<nat> ()));
set (t, as<generic> (cons<nat> (dest, as<vector<nat> > (get (t)))));
// time stamp
environment_rep* me= const_cast<environment_rep*> (this);
me->serial++;
}
| list< string > strings_for_completion | ( | ) | const |
Definition at line 69 of file environment.cpp.
References environment_rep::bindings.
{
list<string> vars;
iterator<generic> tmp = entries (bindings);
for ( ; busy (tmp); ++tmp)
if (is<literal> (*tmp))
vars = cons (literal_to_string (*tmp), vars);
tmp = iterate (all_type_names ());
for ( ; busy (tmp); ++tmp) {
generic g= *tmp;
while (is<compound> (g) && N(g)>0) g= g[0];
if (is<literal> (g))
vars = cons (literal_to_string (g), vars);
}
return vars;
}
| void verify_if_unknown_types | ( | ) | const |
Definition at line 89 of file environment.cpp.
References environment_rep::bindings, and mmx::type_name().
{
extern generic type_name (nat id);
iterator<generic> tmp = entries (bindings);
generic val;
bool exists_unknown;
for ( ; busy (tmp); ++tmp)
if (get (*tmp, val) && is<routine> (val)) {
routine f= as<routine> (val);
vector<routine> vf;
if ((*f) -> is_overloaded ())
vf = (*f) -> meanings ();
else
vf << f;
for (nat k=0; k<N(vf); k++) {
f = vf[k];
vector<nat> ids= f->signature ();
exists_unknown = false;
for (nat i=0; i<N(ids); i++) {
if ((ids[i] == 1) || (type_name (ids[i]) == GEN_UNSPECIFIED_TYPE))
exists_unknown = true;
}
if (exists_unknown)
mmout << "Warning: unresolved type encountered in "
<< *tmp << ": " << f << "\n";
}
}
}
friend class environment [friend] |
Definition at line 68 of file environment.hpp.
| table<generic,generic,exact_eq_table> bindings |
Definition at line 42 of file environment.hpp.
Referenced by environment_rep::contains(), environment_rep::get(), environment_rep::name(), environment_rep::reset(), environment_rep::set(), environment_rep::strings_for_completion(), and environment_rep::verify_if_unknown_types().
| nat env_type |
Definition at line 46 of file environment.hpp.
Referenced by mmx::set_environment_type().
Definition at line 43 of file environment.hpp.
Referenced by environment_rep::contains(), environment_rep::ensure_up_to_date(), environment_rep::get(), environment_rep::get_converter(), and environment_rep::name().
| nat next_serial |
Definition at line 45 of file environment.hpp.
Referenced by environment_rep::ensure_up_to_date().
| nat serial |
Definition at line 44 of file environment.hpp.
Referenced by environment_rep::ensure_up_to_date(), environment_rep::get_converter(), and environment_rep::set_converter().
1.7.2