refactor(kernel): add binder structure
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
eb0abf557d
commit
d6d72ba80e
5 changed files with 36 additions and 18 deletions
|
@ -149,15 +149,13 @@ expr_binder::expr_binder(expr_kind k, name const & n, expr const & t, expr const
|
||||||
t.has_param_univ() || b.has_param_univ(),
|
t.has_param_univ() || b.has_param_univ(),
|
||||||
std::max(get_depth(t), get_depth(b)) + 1,
|
std::max(get_depth(t), get_depth(b)) + 1,
|
||||||
std::max(get_free_var_range(t), dec(get_free_var_range(b)))),
|
std::max(get_free_var_range(t), dec(get_free_var_range(b)))),
|
||||||
m_name(n),
|
m_binder(n, t, i),
|
||||||
m_domain(t),
|
m_body(b) {
|
||||||
m_body(b),
|
|
||||||
m_info(i) {
|
|
||||||
lean_assert(k == expr_kind::Lambda || k == expr_kind::Pi);
|
lean_assert(k == expr_kind::Lambda || k == expr_kind::Pi);
|
||||||
}
|
}
|
||||||
void expr_binder::dealloc(buffer<expr_cell*> & todelete) {
|
void expr_binder::dealloc(buffer<expr_cell*> & todelete) {
|
||||||
dec_ref(m_body, todelete);
|
dec_ref(m_body, todelete);
|
||||||
dec_ref(m_domain, todelete);
|
dec_ref(m_binder.m_type, todelete);
|
||||||
delete(this);
|
delete(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,20 +238,33 @@ public:
|
||||||
bool operator==(expr_binder_info const & i1, expr_binder_info const & i2);
|
bool operator==(expr_binder_info const & i1, expr_binder_info const & i2);
|
||||||
inline bool operator!=(expr_binder_info const & i1, expr_binder_info const & i2) { return !(i1 == i2); }
|
inline bool operator!=(expr_binder_info const & i1, expr_binder_info const & i2) { return !(i1 == i2); }
|
||||||
|
|
||||||
|
class binder {
|
||||||
|
friend class expr_binder;
|
||||||
|
name m_name;
|
||||||
|
expr m_type;
|
||||||
|
expr_binder_info m_info;
|
||||||
|
public:
|
||||||
|
binder(name const & n, expr const & t, expr_binder_info const & bi):
|
||||||
|
m_name(n), m_type(t), m_info(bi) {}
|
||||||
|
name const & get_name() const { return m_name; }
|
||||||
|
expr const & get_type() const { return m_type; }
|
||||||
|
expr_binder_info const & get_info() const { return m_info; }
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef list<binder> telescope;
|
||||||
|
|
||||||
/** \brief Super class for lambda and pi */
|
/** \brief Super class for lambda and pi */
|
||||||
class expr_binder : public expr_composite {
|
class expr_binder : public expr_composite {
|
||||||
name m_name;
|
binder m_binder;
|
||||||
expr m_domain;
|
|
||||||
expr m_body;
|
expr m_body;
|
||||||
expr_binder_info m_info;
|
|
||||||
friend class expr_cell;
|
friend class expr_cell;
|
||||||
void dealloc(buffer<expr_cell*> & todelete);
|
void dealloc(buffer<expr_cell*> & todelete);
|
||||||
public:
|
public:
|
||||||
expr_binder(expr_kind k, name const & n, expr const & t, expr const & e, expr_binder_info const & i = expr_binder_info());
|
expr_binder(expr_kind k, name const & n, expr const & t, expr const & e, expr_binder_info const & i = expr_binder_info());
|
||||||
name const & get_name() const { return m_name; }
|
name const & get_name() const { return m_binder.get_name(); }
|
||||||
expr const & get_domain() const { return m_domain; }
|
expr const & get_domain() const { return m_binder.get_type(); }
|
||||||
expr const & get_body() const { return m_body; }
|
expr const & get_body() const { return m_body; }
|
||||||
expr_binder_info const & get_info() const { return m_info; }
|
expr_binder_info const & get_info() const { return m_binder.get_info(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief Let expressions */
|
/** \brief Let expressions */
|
||||||
|
|
|
@ -22,7 +22,7 @@ environment add_inductive(environment const & env,
|
||||||
// TODO(Leo)
|
// TODO(Leo)
|
||||||
std::cout << "add_inductive\n";
|
std::cout << "add_inductive\n";
|
||||||
for (auto l : level_params) { std::cout << l << " "; } std::cout << "\n";
|
for (auto l : level_params) { std::cout << l << " "; } std::cout << "\n";
|
||||||
for (auto e : params) { std::cout << std::get<0>(e) << " "; } std::cout << "\n";
|
for (auto e : params) { std::cout << e.get_name() << " "; } std::cout << "\n";
|
||||||
for (auto d : decls) { std::cout << std::get<0>(d) << " "; } std::cout << "\n";
|
for (auto d : decls) { std::cout << std::get<0>(d) << " "; } std::cout << "\n";
|
||||||
if (univ_offset) std::cout << "offset: " << *univ_offset << "\n";
|
if (univ_offset) std::cout << "offset: " << *univ_offset << "\n";
|
||||||
return env;
|
return env;
|
||||||
|
|
|
@ -16,12 +16,6 @@ namespace inductive {
|
||||||
/** \brief Return a normalizer extension for inductive dataypes. */
|
/** \brief Return a normalizer extension for inductive dataypes. */
|
||||||
std::unique_ptr<normalizer_extension> mk_extension();
|
std::unique_ptr<normalizer_extension> mk_extension();
|
||||||
|
|
||||||
/** \brief Simple telescope */
|
|
||||||
typedef list<std::tuple<name, // binder name, used only for pretty printing
|
|
||||||
expr, // type
|
|
||||||
expr_binder_info
|
|
||||||
>> telescope;
|
|
||||||
|
|
||||||
/** \brief Introduction rule */
|
/** \brief Introduction rule */
|
||||||
typedef std::tuple<name, // introduction rule name
|
typedef std::tuple<name, // introduction rule name
|
||||||
telescope, // arguments
|
telescope, // arguments
|
||||||
|
|
|
@ -19,6 +19,7 @@ Author: Leonardo de Moura
|
||||||
#include "kernel/metavar.h"
|
#include "kernel/metavar.h"
|
||||||
#include "kernel/error_msgs.h"
|
#include "kernel/error_msgs.h"
|
||||||
#include "kernel/type_checker.h"
|
#include "kernel/type_checker.h"
|
||||||
|
#include "kernel/inductive/inductive.h"
|
||||||
#include "library/occurs.h"
|
#include "library/occurs.h"
|
||||||
#include "library/io_state_stream.h"
|
#include "library/io_state_stream.h"
|
||||||
#include "library/expr_lt.h"
|
#include "library/expr_lt.h"
|
||||||
|
@ -1632,6 +1633,18 @@ static void open_type_checker(lua_State * L) {
|
||||||
SET_GLOBAL_FUN(add_declaration, "add_decl");
|
SET_GLOBAL_FUN(add_declaration, "add_decl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
telescope to_telescope(lua_State * L, int idx) {
|
||||||
|
luaL_checktype(L, idx, LUA_TTABLE);
|
||||||
|
lua_pushvalue(L, idx); // push table on the top
|
||||||
|
int sz = objlen(L, -1); // get table size
|
||||||
|
telescope r;
|
||||||
|
for (int i = sz; i >= 1; i--) {
|
||||||
|
// TODO(Leo)
|
||||||
|
}
|
||||||
|
lua_pop(L, 1); // pop table from the top
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
void open_kernel_module(lua_State * L) {
|
void open_kernel_module(lua_State * L) {
|
||||||
open_level(L);
|
open_level(L);
|
||||||
open_list_level(L);
|
open_list_level(L);
|
||||||
|
|
Loading…
Reference in a new issue