2013-08-17 01:59:56 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#include "context_to_lambda.h"
|
|
|
|
|
|
|
|
namespace lean {
|
2013-08-17 03:39:24 +00:00
|
|
|
static expr g_fake = Const(name(name(0u), "context_to_lambda"));
|
2013-08-17 01:59:56 +00:00
|
|
|
expr context_to_lambda(context const & c, expr const & e) {
|
|
|
|
if (!c) {
|
|
|
|
return e;
|
|
|
|
} else {
|
|
|
|
context_entry const & entry = head(c);
|
|
|
|
expr t;
|
|
|
|
if (entry.get_body())
|
2013-08-17 03:39:24 +00:00
|
|
|
t = mk_app(g_fake, entry.get_domain(), entry.get_body());
|
2013-08-17 01:59:56 +00:00
|
|
|
else
|
2013-08-17 03:39:24 +00:00
|
|
|
t = mk_app(g_fake, entry.get_domain());
|
2013-08-17 01:59:56 +00:00
|
|
|
return context_to_lambda(tail(c), mk_lambda(entry.get_name(), t, e));
|
|
|
|
}
|
|
|
|
}
|
2013-08-17 03:39:24 +00:00
|
|
|
bool is_fake_context(expr const & e) {
|
|
|
|
return is_lambda(e) && is_app(abst_domain(e)) && arg(abst_domain(e),0) == g_fake;
|
|
|
|
}
|
|
|
|
name const & fake_context_name(expr const & e) {
|
|
|
|
lean_assert(is_fake_context(e));
|
|
|
|
return abst_name(e);
|
|
|
|
}
|
|
|
|
expr const & fake_context_domain(expr const & e) {
|
|
|
|
lean_assert(is_fake_context(e));
|
|
|
|
return arg(abst_domain(e), 1);
|
|
|
|
}
|
|
|
|
expr const & fake_context_value(expr const & e) {
|
|
|
|
lean_assert(is_fake_context(e));
|
|
|
|
if (num_args(abst_domain(e)) > 2)
|
|
|
|
return arg(abst_domain(e), 2);
|
|
|
|
else
|
|
|
|
return expr::null();
|
|
|
|
}
|
|
|
|
expr const & fake_context_rest(expr const & e) {
|
|
|
|
return abst_body(e);
|
|
|
|
}
|
2013-08-17 01:59:56 +00:00
|
|
|
}
|