refactor(kernel): add mk_local function that has only two arguments

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-06-16 14:27:26 -07:00
parent 873a5c8605
commit 07f2379dec
9 changed files with 14 additions and 13 deletions

View file

@ -105,7 +105,7 @@ environment variable_cmd_core(parser & p, bool is_axiom, binder_info const & bi)
} }
type = p.elaborate(type, ls); type = p.elaborate(type, ls);
if (in_section(p.env())) { if (in_section(p.env())) {
p.add_local_expr(n, p.save_pos(mk_local(n, n, type), pos), bi); p.add_local_expr(n, p.save_pos(mk_local(n, type), pos), bi);
return p.env(); return p.env();
} else { } else {
environment env = p.env(); environment env = p.env();

View file

@ -75,7 +75,7 @@ static expr parse_let(parser & p, pos_info const & pos) {
type = p.pi_abstract(ps, type); type = p.pi_abstract(ps, type);
value = p.lambda_abstract(ps, value); value = p.lambda_abstract(ps, value);
} }
expr l = p.save_pos(mk_local(id, id, type), pos); expr l = p.save_pos(mk_local(id, type), pos);
p.add_local(l); p.add_local(l);
expr body = abstract(parse_let_body(p, pos), l); expr body = abstract(parse_let_body(p, pos), l);
return p.save_pos(mk_let(id, type, value, body), pos); return p.save_pos(mk_let(id, type, value, body), pos);

View file

@ -136,7 +136,7 @@ static void parse_notation_local(parser & p, buffer<expr> & locals) {
if (p.curr_is_identifier()) { if (p.curr_is_identifier()) {
name n = p.get_name_val(); name n = p.get_name_val();
p.next(); p.next();
expr l = mk_local(n, n, g_local_type); // remark: the type doesn't matter expr l = mk_local(n, g_local_type); // remark: the type doesn't matter
p.add_local_expr(n, l); p.add_local_expr(n, l);
locals.push_back(l); locals.push_back(l);
} else { } else {
@ -221,7 +221,7 @@ environment notation_cmd_core(parser & p, bool overload) {
name n = p.get_name_val(); name n = p.get_name_val();
p.next(); p.next();
action a = parse_action(p, env, locals); action a = parse_action(p, env, locals);
expr l = mk_local(n, n, g_local_type); expr l = mk_local(n, g_local_type);
p.add_local_expr(n, l); p.add_local_expr(n, l);
locals.push_back(l); locals.push_back(l);
ts.push_back(transition(tk, a)); ts.push_back(transition(tk, a));

View file

@ -496,7 +496,7 @@ parameter parser::parse_binder_core(binder_info const & bi) {
} else { } else {
type = save_pos(mk_expr_placeholder(), p); type = save_pos(mk_expr_placeholder(), p);
} }
return parameter(p, save_pos(mk_local(id, id, type), p), bi); return parameter(p, save_pos(mk_local(id, type), p), bi);
} }
parameter parser::parse_binder() { parameter parser::parse_binder() {
@ -538,7 +538,7 @@ void parser::parse_binder_block(buffer<parameter> & r, binder_info const & bi) {
} }
for (auto p : names) { for (auto p : names) {
expr arg_type = type ? *type : save_pos(mk_expr_placeholder(), p.first); expr arg_type = type ? *type : save_pos(mk_expr_placeholder(), p.first);
expr local = save_pos(mk_local(p.second, p.second, arg_type), p.first); expr local = save_pos(mk_local(p.second, arg_type), p.first);
add_local(local); add_local(local);
r.push_back(parameter(p.first, local, bi)); r.push_back(parameter(p.first, local, bi));
} }

View file

@ -436,6 +436,7 @@ inline expr Const(name const & n) { return mk_constant(n); }
expr mk_macro(macro_definition const & m, unsigned num = 0, expr const * args = nullptr); expr mk_macro(macro_definition const & m, unsigned num = 0, expr const * args = nullptr);
expr mk_metavar(name const & n, expr const & t); expr mk_metavar(name const & n, expr const & t);
expr mk_local(name const & n, name const & pp_n, expr const & t); expr mk_local(name const & n, name const & pp_n, expr const & t);
inline expr mk_local(name const & n, expr const & t) { return mk_local(n, n, t); }
expr mk_app(expr const & f, expr const & a); expr mk_app(expr const & f, expr const & a);
expr mk_app(expr const & f, unsigned num_args, expr const * args); expr mk_app(expr const & f, unsigned num_args, expr const * args);
expr mk_app(unsigned num_args, expr const * args); expr mk_app(unsigned num_args, expr const * args);

View file

@ -33,14 +33,14 @@ name pick_unused_name(expr const & t, name const & s) {
std::pair<expr, expr> binding_body_fresh(expr const & b, bool preserve_type) { std::pair<expr, expr> binding_body_fresh(expr const & b, bool preserve_type) {
lean_assert(is_binding(b)); lean_assert(is_binding(b));
name n = pick_unused_name(binding_body(b), binding_name(b)); name n = pick_unused_name(binding_body(b), binding_name(b));
expr c = mk_local(n, n, preserve_type ? binding_domain(b) : expr()); expr c = mk_local(n, preserve_type ? binding_domain(b) : expr());
return mk_pair(instantiate(binding_body(b), c), c); return mk_pair(instantiate(binding_body(b), c), c);
} }
std::pair<expr, expr> let_body_fresh(expr const & l, bool preserve_type) { std::pair<expr, expr> let_body_fresh(expr const & l, bool preserve_type) {
lean_assert(is_let(l)); lean_assert(is_let(l));
name n = pick_unused_name(let_body(l), let_name(l)); name n = pick_unused_name(let_body(l), let_name(l));
expr c = mk_local(n, n, preserve_type ? let_type(l) : expr()); expr c = mk_local(n, preserve_type ? let_type(l) : expr());
return mk_pair(instantiate(let_body(l), c), c); return mk_pair(instantiate(let_body(l), c), c);
} }

View file

@ -512,7 +512,7 @@ static int expr_mk_local(lua_State * L) {
int nargs = lua_gettop(L); int nargs = lua_gettop(L);
name n = to_name_ext(L, 1); name n = to_name_ext(L, 1);
if (nargs == 2) if (nargs == 2)
return push_expr(L, mk_local(n, n, to_expr(L, 2))); return push_expr(L, mk_local(n, to_expr(L, 2)));
else else
return push_expr(L, mk_local(n, to_name_ext(L, 2), to_expr(L, 3))); return push_expr(L, mk_local(n, to_name_ext(L, 2), to_expr(L, 3)));
} }

View file

@ -60,7 +60,7 @@ static void tst1() {
auto env3 = add_decl(env2, mk_definition("id", level_param_names(), auto env3 = add_decl(env2, mk_definition("id", level_param_names(),
Pi(A, mk_Type(), A >> A), Pi(A, mk_Type(), A >> A),
Fun({{A, mk_Type()}, {x, A}}, x))); Fun({{A, mk_Type()}, {x, A}}, x)));
expr c = mk_local("c", "c", Bool); expr c = mk_local("c", Bool);
expr id = Const("id"); expr id = Const("id");
type_checker checker(env3, name_generator("tmp")); type_checker checker(env3, name_generator("tmp"));
lean_assert(checker.check(id(Bool)) == Bool >> Bool); lean_assert(checker.check(id(Bool)) == Bool >> Bool);
@ -91,8 +91,8 @@ static void tst2() {
expr f97 = Const(name(base, 97)); expr f97 = Const(name(base, 97));
expr f98 = Const(name(base, 98)); expr f98 = Const(name(base, 98));
expr f3 = Const(name(base, 3)); expr f3 = Const(name(base, 3));
expr c1 = mk_local("c1", "c1", Bool); expr c1 = mk_local("c1", Bool);
expr c2 = mk_local("c2", "c2", Bool); expr c2 = mk_local("c2", Bool);
expr id = Const("id"); expr id = Const("id");
std::cout << checker.whnf(f3(c1, c2)) << "\n"; std::cout << checker.whnf(f3(c1, c2)) << "\n";
lean_assert_eq(env.find(name(base, 98))->get_weight(), 98); lean_assert_eq(env.find(name(base, 98))->get_weight(), 98);

View file

@ -349,7 +349,7 @@ static void tst18() {
expr f = Const("f"); expr f = Const("f");
expr x = Var(0); expr x = Var(0);
expr a = Const("a"); expr a = Const("a");
expr l = mk_local("m", "m", Bool); expr l = mk_local("m", Bool);
expr m = mk_metavar("m", Bool); expr m = mk_metavar("m", Bool);
check_serializer(l); check_serializer(l);
lean_assert(!has_local(m)); lean_assert(!has_local(m));