feat(kernel): add get_universe_distance method
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
5fe8c32da9
commit
4424a314e0
3 changed files with 22 additions and 0 deletions
|
@ -263,6 +263,10 @@ universe_constraints const & environment_cell::get_ro_ucs() const {
|
||||||
return get_ro_universes().m_constraints;
|
return get_ro_universes().m_constraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional<int> environment_cell::get_universe_distance(name const & u1, name const & u2) const {
|
||||||
|
return get_ro_ucs().get_distance(u1, u2);
|
||||||
|
}
|
||||||
|
|
||||||
/** \brief Return true iff l1 >= l2 + k by asserted universe constraints. */
|
/** \brief Return true iff l1 >= l2 + k by asserted universe constraints. */
|
||||||
bool environment_cell::is_ge(level const & l1, level const & l2, int k) const {
|
bool environment_cell::is_ge(level const & l1, level const & l2, int k) const {
|
||||||
if (l1 == l2)
|
if (l1 == l2)
|
||||||
|
|
|
@ -126,6 +126,13 @@ public:
|
||||||
*/
|
*/
|
||||||
bool is_ge(level const & l1, level const & l2) const;
|
bool is_ge(level const & l1, level const & l2) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Return the (minimal) distance between two universes.
|
||||||
|
That is, the biggest \c k s.t. <tt>u1 >= u2 + k</tt>.
|
||||||
|
Return none if there is no such \c k.
|
||||||
|
*/
|
||||||
|
optional<int> get_universe_distance(name const & u1, name const & u2) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Return universal variable with the given name.
|
\brief Return universal variable with the given name.
|
||||||
Throw an exception if variable is not defined in this environment.
|
Throw an exception if variable is not defined in this environment.
|
||||||
|
|
|
@ -1159,6 +1159,16 @@ static int environment_import(lua_State * L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int environment_get_universe_distance(lua_State * L) {
|
||||||
|
ro_shared_environment env(L, 1);
|
||||||
|
auto r = env->get_universe_distance(to_name_ext(L, 2), to_name_ext(L, 3));
|
||||||
|
if (r)
|
||||||
|
lua_pushinteger(L, *r);
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct luaL_Reg environment_m[] = {
|
static const struct luaL_Reg environment_m[] = {
|
||||||
{"__gc", environment_gc}, // never throws
|
{"__gc", environment_gc}, // never throws
|
||||||
{"__tostring", safe_function<environment_tostring>},
|
{"__tostring", safe_function<environment_tostring>},
|
||||||
|
@ -1167,6 +1177,7 @@ static const struct luaL_Reg environment_m[] = {
|
||||||
{"has_children", safe_function<environment_has_children>},
|
{"has_children", safe_function<environment_has_children>},
|
||||||
{"parent", safe_function<environment_parent>},
|
{"parent", safe_function<environment_parent>},
|
||||||
{"add_uvar_cnstr", safe_function<environment_add_uvar_cnstr>},
|
{"add_uvar_cnstr", safe_function<environment_add_uvar_cnstr>},
|
||||||
|
{"get_universe_distance", safe_function<environment_get_universe_distance>},
|
||||||
{"is_ge", safe_function<environment_is_ge>},
|
{"is_ge", safe_function<environment_is_ge>},
|
||||||
{"get_uvar", safe_function<environment_get_uvar>},
|
{"get_uvar", safe_function<environment_get_uvar>},
|
||||||
{"add_definition", safe_function<environment_add_definition>},
|
{"add_definition", safe_function<environment_add_definition>},
|
||||||
|
|
Loading…
Reference in a new issue