int main() { lean_exception ex; lean_name a, n1, n2, n3, n4, n5, n6; char const * s1; char const * s2; char const * s3; lean_list_name l1, l2, l3, l4; unsigned idx; printf("Started name test\n"); check(lean_name_mk_anonymous(&a, &ex)); check(lean_name_is_anonymous(a)); check(lean_name_mk_str(a, "foo", &n1, &ex)); check(lean_name_mk_str(n1, "bla", &n2, &ex)); check(lean_name_to_string(n2, &s1, &ex)); printf("Lean name: %s\n", s1); check(lean_name_is_str(n2)); check(!lean_name_is_anonymous(n2)); check(!lean_name_is_idx(n2)); check(lean_name_mk_idx(n2, 1, &n3, &ex)); check(lean_name_to_string(n3, &s2, &ex)); printf("Lean name: %s\n", s2); check(lean_name_is_idx(n3)); check(lean_name_get_prefix(n3, &n4, &ex)); check(lean_name_eq(n2, n4)); check(lean_name_get_idx(n3, &idx, &ex)); check(idx == 1); check(!lean_name_get_prefix(a, &n5, &ex)); s3 = lean_exception_get_message(ex); printf("Lean exception: %s\n", s3); check(lean_list_name_mk_nil(&l1, &ex)); check(!lean_list_name_is_cons(l1)); check(lean_list_name_mk_cons(n1, l1, &l2, &ex)); check(lean_list_name_is_cons(l2)); check(lean_list_name_mk_cons(n2, l2, &l3, &ex)); check(lean_list_name_head(l3, &n6, &ex)); check(lean_name_eq(n6, n2)); check(lean_list_name_tail(l3, &l4, &ex)); check(lean_list_name_eq(l4, l2)); anonymous_unique(); lean_name_del(a); lean_name_del(n1); lean_name_del(n2); lean_name_del(n3); lean_name_del(n4); lean_name_del(n6); lean_list_name_del(l1); lean_list_name_del(l2); lean_list_name_del(l3); lean_list_name_del(l4); lean_string_del(s1); lean_string_del(s2); lean_string_del(s3); lean_exception_del(ex); return 0; }
void test_path() { lean_exception ex; char const * p; check(lean_get_std_path(&p, &ex)); printf("LEAN_PATH: %s\n", p); lean_string_del(p); check(lean_get_hott_path(&p, &ex)); printf("HLEAN_PATH: %s\n", p); lean_string_del(p); }
void test_import() { lean_exception ex; lean_env env = mk_env(); lean_name std = mk_name("standard"); lean_list_name ms = mk_unary_name_list(std); lean_options o; lean_ios ios; lean_env new_env; lean_decl nat_gcd_decl; lean_name nat = mk_name("nat"); lean_name nat_gcd; lean_expr nat_gcd_val; char const * s; check(lean_options_mk_empty(&o, &ex)); check(lean_ios_mk_std(o, &ios, &ex)); check(lean_env_import(env, ios, ms, &new_env, &ex)); check(lean_env_for_each_decl(new_env, print_decl_name_and_del, &ex)); check(lean_name_mk_str(nat, "gcd", &nat_gcd, &ex)); check(lean_env_get_decl(new_env, nat_gcd, &nat_gcd_decl, &ex)); check(lean_decl_get_value(nat_gcd_decl, &nat_gcd_val, &ex)); check(lean_expr_to_pp_string(new_env, ios, nat_gcd_val, &s, &ex)); printf("nat.gcd\n%s\n", s); lean_env_del(env); lean_name_del(std); lean_list_name_del(ms); lean_options_del(o); lean_ios_del(ios); lean_env_del(new_env); lean_name_del(nat); lean_name_del(nat_gcd); lean_decl_del(nat_gcd_decl); lean_expr_del(nat_gcd_val); lean_string_del(s); }
void print_expr(lean_expr e) { lean_exception ex; char const * s; check(lean_expr_to_string(e, &s, &ex)); printf("%s\n", s); lean_string_del(s); }
void print_univ_and_del(lean_name n) { lean_exception ex; char const * s; check(lean_name_to_string(n, &s, &ex)); printf("universe: %s\n", s); lean_string_del(s); lean_name_del(n); }
void print_decl_name_and_del(lean_decl d) { lean_exception ex; lean_name n; char const * s; check(lean_decl_get_name(d, &n, &ex)); check(lean_name_to_string(n, &s, &ex)); printf("declaration name: %s\n", s); lean_name_del(n); lean_string_del(s); lean_decl_del(d); }
void print_decl_and_del(lean_decl d) { lean_exception ex; lean_name n; lean_expr t; char const * s; check(lean_decl_get_name(d, &n, &ex)); check(lean_name_to_string(n, &s, &ex)); printf("declaration name: %s\n", s); check(lean_decl_get_type(d, &t, &ex)); printf(" type: "); print_expr(t); if (lean_decl_get_kind(d) == LEAN_DECL_DEF || lean_decl_get_kind(d) == LEAN_DECL_THM) { lean_expr v; check(lean_decl_get_value(d, &v, &ex)); printf(" value: "); print_expr(v); lean_expr_del(v); } lean_expr_del(t); lean_name_del(n); lean_string_del(s); lean_decl_del(d); }
int main() { lean_exception ex; lean_name a, l, U, pp, pp_unicode, rn; lean_options o1, o2; lean_univ zero, one, p1, g1, m1, u, n, i, ru; lean_list_name ln1, ln2; lean_list_univ lu1, lu2; char const * s1; lean_bool r; check(lean_name_mk_anonymous(&a, &ex)); check(lean_name_mk_str(a, "l_1", &l, &ex)); check(lean_name_mk_str(a, "U", &U, &ex)); check(lean_name_mk_str(a, "pp", &pp, &ex)); check(lean_name_mk_str(pp, "unicode", &pp_unicode, &ex)); check(lean_options_mk_empty(&o1, &ex)); check(lean_options_set_bool(o1, pp_unicode, lean_false, &o2, &ex)); check(lean_univ_mk_zero(&zero, &ex)); check(lean_univ_mk_succ(zero, &one, &ex)); check(lean_univ_mk_param(l, &p1, &ex)); check(lean_univ_mk_global(U, &g1, &ex)); check(lean_univ_mk_max(p1, one, &m1, &ex)); check(lean_univ_mk_succ(m1, &u, &ex)); check(lean_univ_normalize(u, &n, &ex)); check(lean_univ_to_string(n, &s1, &ex)); printf("universe: %s\n", s1); check(lean_univ_geq(one, zero, &r, &ex) && r); /* replace l_1 with one in u */ check(lean_list_name_mk_nil(&ln1, &ex)); check(lean_list_name_mk_cons(l, ln1, &ln2, &ex)); check(lean_list_univ_mk_nil(&lu1, &ex)); check(lean_list_univ_mk_cons(one, lu1, &lu2, &ex)); check(lean_univ_instantiate(u, ln2, lu2, &i, &ex)); lean_list_name_del(ln1); lean_list_name_del(ln2); lean_list_univ_del(lu1); lean_list_univ_del(lu2); lean_string_del(s1); check(lean_univ_to_string_using(i, o2, &s1, &ex)); printf("universe: %s\n", s1); check(lean_univ_get_kind(zero) == LEAN_UNIV_ZERO); check(lean_univ_get_kind(one) == LEAN_UNIV_SUCC); check(lean_univ_get_kind(n) == LEAN_UNIV_MAX); check(lean_univ_get_name(g1, &rn, &ex) && lean_name_eq(rn, U)); check(lean_univ_get_max_lhs(m1, &ru, &ex) && lean_univ_eq(ru, p1, &r, &ex) && r); lean_univ_del(ru); check(lean_univ_get_max_rhs(m1, &ru, &ex) && lean_univ_eq(ru, one, &r, &ex) && r); lean_univ_del(ru); check(lean_univ_get_pred(one, &ru, &ex) && lean_univ_eq(ru, zero, &r, &ex) && r); lean_univ_del(ru); lean_name_del(a); lean_name_del(l); lean_name_del(U); lean_name_del(pp); lean_name_del(pp_unicode); lean_name_del(rn); lean_options_del(o1); lean_options_del(o2); lean_univ_del(zero); lean_univ_del(one); lean_univ_del(p1); lean_univ_del(g1); lean_univ_del(m1); lean_univ_del(u); lean_univ_del(n); lean_univ_del(i); lean_string_del(s1); return 0; }