chore(*): remove C API

This commit is contained in:
Leonardo de Moura 2018-04-10 16:48:02 -07:00
parent 75f91df707
commit ee8a79a270
49 changed files with 1 additions and 4126 deletions

View file

@ -427,13 +427,12 @@ else()
endif()
add_library(leanstatic ${LEAN_LIBRARY_TYPE} ${LEAN_OBJS})
target_link_libraries(leanstatic ${EXTRA_LIBS})
add_subdirectory(api)
# The DLL (shared library) is not being generated correctly when we use cross-compilation (i.e., generate the Windows DLL using Linux).
# For some strange reason, it contains a copy of pthread_equal.
# Remark: this problem does not happen when we generate the DLL using msys2 on Windows.
if (NOT("${CROSS_COMPILE}" MATCHES "ON"))
if ("${STATIC}" MATCHES "OFF")
add_library(leanshared SHARED shared/init.cpp $<TARGET_OBJECTS:api> ${LEAN_OBJS})
add_library(leanshared SHARED shared/init.cpp ${LEAN_OBJS})
target_link_libraries(leanshared ${EXTRA_LIBS})
install(TARGETS leanshared DESTINATION lib)
endif()
@ -458,12 +457,6 @@ add_subdirectory(tests/library)
add_subdirectory(tests/frontends/lean)
add_subdirectory(tests/shell)
# The DLL (shared library) is not being generated correctly when we use cross-compilation (i.e., generate the Windows DLL using Linux).
# For some strange reason, it contains a copy of pthread_equal.
if (NOT("${CROSS_COMPILE}" MATCHES "ON") AND ("${STATIC}" MATCHES "OFF"))
add_subdirectory(tests/shared)
endif()
# Include style check
if (NOT(${CMAKE_SYSTEM_NAME} MATCHES "Windows") AND PYTHONINTERP_FOUND)
include(StyleCheck)

View file

@ -1,6 +0,0 @@
add_library(api OBJECT string.cpp exception.cpp name.cpp options.cpp univ.cpp
expr.cpp decl.cpp env.cpp ios.cpp module.cpp type_checker.cpp inductive.cpp
parser.cpp)
FILE(GLOB LEAN_API_INCLUDE_FILES lean*.h)
install(FILES ${LEAN_API_INCLUDE_FILES} DESTINATION include)

View file

@ -1,156 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "api/string.h"
#include "api/exception.h"
#include "api/decl.h"
using namespace lean; // NOLINT
lean_bool lean_decl_mk_axiom(lean_name n, lean_list_name p, lean_expr t, lean_decl * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(p);
check_nonnull(t);
*r = of_decl(new declaration(mk_axiom(to_name_ref(n), to_list_name_ref(p), to_expr_ref(t))));
LEAN_CATCH;
}
lean_bool lean_decl_mk_const(lean_name n, lean_list_name p, lean_expr t, lean_decl * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(p);
check_nonnull(t);
*r = of_decl(new declaration(mk_constant_assumption(to_name_ref(n), to_list_name_ref(p), to_expr_ref(t))));
LEAN_CATCH;
}
lean_bool lean_decl_mk_def(lean_name n, lean_list_name p, lean_expr t, lean_expr v, unsigned h, lean_bool o, lean_decl * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(p);
check_nonnull(t);
check_nonnull(v);
*r = of_decl(new declaration(mk_definition(to_name_ref(n), to_list_name_ref(p), to_expr_ref(t), to_expr_ref(v), reducibility_hints::mk_regular(h, static_cast<bool>(o)))));
LEAN_CATCH;
}
lean_bool lean_decl_mk_def_with(lean_env e, lean_name n, lean_list_name p, lean_expr t, lean_expr v, lean_bool o, lean_decl * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e);
check_nonnull(n);
check_nonnull(p);
check_nonnull(t);
check_nonnull(v);
*r = of_decl(new declaration(mk_definition(to_env_ref(e), to_name_ref(n), to_list_name_ref(p), to_expr_ref(t), to_expr_ref(v), static_cast<bool>(o))));
LEAN_CATCH;
}
// TODO(Leo): delete unnecessary argument h
lean_bool lean_decl_mk_thm(lean_name n, lean_list_name p, lean_expr t, lean_expr v, unsigned /* h */, lean_decl * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(p);
check_nonnull(t);
check_nonnull(v);
*r = of_decl(new declaration(mk_theorem(to_name_ref(n), to_list_name_ref(p), to_expr_ref(t), to_expr_ref(v))));
LEAN_CATCH;
}
// TODO(Leo): delete unnecessary argument e
lean_bool lean_decl_mk_thm_with(lean_env /* e */, lean_name n, lean_list_name p, lean_expr t, lean_expr v, lean_decl * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(p);
check_nonnull(t);
check_nonnull(v);
*r = of_decl(new declaration(mk_theorem(to_name_ref(n), to_list_name_ref(p), to_expr_ref(t), to_expr_ref(v))));
LEAN_CATCH;
}
void lean_decl_del(lean_decl d) {
delete to_decl(d);
}
lean_decl_kind lean_decl_get_kind(lean_decl d) {
if (!d)
return LEAN_DECL_CONST;
if (to_decl_ref(d).is_theorem())
return LEAN_DECL_THM;
else if (to_decl_ref(d).is_definition())
return LEAN_DECL_DEF;
else if (to_decl_ref(d).is_axiom())
return LEAN_DECL_AXIOM;
else if (to_decl_ref(d).is_constant_assumption())
return LEAN_DECL_CONST;
else
return LEAN_DECL_CONST;
}
lean_bool lean_decl_get_name(lean_decl d, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(d);
*r = of_name(new name(to_decl_ref(d).get_name()));
LEAN_CATCH;
}
lean_bool lean_decl_get_univ_params(lean_decl d, lean_list_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(d);
*r = of_list_name(new list<name>(to_decl_ref(d).get_univ_params()));
LEAN_CATCH;
}
lean_bool lean_decl_get_type(lean_decl d, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(d);
*r = of_expr(new expr(to_decl_ref(d).get_type()));
LEAN_CATCH;
}
static void check_def_thm(lean_decl d) {
check_nonnull(d);
if (lean_decl_get_kind(d) != LEAN_DECL_DEF && lean_decl_get_kind(d) != LEAN_DECL_THM)
throw exception("invalid argument, definition or theorem expected");
}
lean_bool lean_decl_get_value(lean_decl d, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_def_thm(d);
*r = of_expr(new expr(to_decl_ref(d).get_value()));
LEAN_CATCH;
}
lean_bool lean_decl_get_height(lean_decl d, unsigned * r, lean_exception * ex) {
LEAN_TRY;
check_def_thm(d);
*r = to_decl_ref(d).get_hints().get_height();
LEAN_CATCH;
}
static void check_def(lean_decl d) {
check_nonnull(d);
if (lean_decl_get_kind(d) != LEAN_DECL_DEF)
throw exception("invalid argument, definition expected");
}
lean_bool lean_decl_get_conv_opt(lean_decl d, lean_bool * r, lean_exception * ex) {
LEAN_TRY;
check_def(d);
*r = to_decl_ref(d).get_hints().use_self_opt();
LEAN_CATCH;
}
lean_bool lean_decl_check(lean_env e, lean_decl d, lean_cert_decl * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e);
check_nonnull(d);
*r = of_cert_decl(new certified_declaration(check(to_env_ref(e), to_decl_ref(d))));
LEAN_CATCH;
}
void lean_cert_decl_del(lean_cert_decl d) {
delete to_cert_decl(d);
}

View file

@ -1,24 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "kernel/declaration.h"
#include "kernel/type_checker.h"
#include "api/expr.h"
#include "api/lean_decl.h"
namespace lean {
inline declaration * to_decl(lean_decl n) { return reinterpret_cast<declaration *>(n); }
inline declaration const & to_decl_ref(lean_decl n) { return *reinterpret_cast<declaration *>(n); }
inline lean_decl of_decl(declaration * n) { return reinterpret_cast<lean_decl>(n); }
inline certified_declaration * to_cert_decl(lean_cert_decl n) { return reinterpret_cast<certified_declaration *>(n); }
inline certified_declaration const & to_cert_decl_ref(lean_cert_decl n) { return *reinterpret_cast<certified_declaration *>(n); }
inline lean_cert_decl of_cert_decl(certified_declaration * n) { return reinterpret_cast<lean_cert_decl>(n); }
inline environment * to_env(lean_env n) { return reinterpret_cast<environment *>(n); }
inline environment const & to_env_ref(lean_env n) { return *reinterpret_cast<environment *>(n); }
inline lean_env of_env(environment * n) { return reinterpret_cast<lean_env>(n); }
}

View file

@ -1,77 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "kernel/environment.h"
#include "kernel/standard_kernel.h"
#include "library/module.h"
#include "api/decl.h"
#include "api/string.h"
#include "api/exception.h"
#include "api/lean_env.h"
using namespace lean; // NOLINT
lean_bool lean_env_mk_std(unsigned t, lean_env * r, lean_exception * ex) {
LEAN_TRY;
*r = of_env(new environment(mk_environment(t)));
LEAN_CATCH;
}
lean_bool lean_env_add(lean_env e, lean_cert_decl d, lean_env * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e);
check_nonnull(d);
*r = of_env(new environment(module::add(to_env_ref(e), to_cert_decl_ref(d))));
LEAN_CATCH;
}
lean_bool lean_env_replace(lean_env e, lean_cert_decl d, lean_env * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e);
check_nonnull(d);
*r = of_env(new environment(to_env_ref(e).replace(to_cert_decl_ref(d))));
LEAN_CATCH;
}
void lean_env_del(lean_env e) {
delete to_env(e);
}
unsigned lean_env_trust_level(lean_env e) {
return e ? to_env_ref(e).trust_lvl() : 0;
}
lean_bool lean_env_contains_decl(lean_env e, lean_name n) {
return e && n && to_env_ref(e).find(to_name_ref(n));
}
lean_bool lean_env_get_decl(lean_env e, lean_name n, lean_decl * d, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e);
check_nonnull(n);
*d = of_decl(new declaration(to_env_ref(e).get(to_name_ref(n))));
LEAN_CATCH;
}
lean_bool lean_env_is_descendant(lean_env e1, lean_env e2) {
return e1 && e2 && to_env_ref(e1).is_descendant(to_env_ref(e2));
}
lean_bool lean_env_forget(lean_env e, lean_env * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e);
*r = of_env(new environment(to_env_ref(e).forget()));
LEAN_CATCH;
}
lean_bool lean_env_for_each_decl(lean_env e, void (*f)(lean_decl), lean_exception * ex) {
LEAN_TRY;
check_nonnull(e);
to_env_ref(e).for_each_declaration([&](declaration const & d) {
f(of_decl(new declaration(d)));
});
return lean_true;
LEAN_CATCH;
}

View file

@ -1,59 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "kernel/kernel_exception.h"
#include "kernel/type_checker.h"
#include "library/print.h"
#include "util/parser_exception.h"
#include "api/exception.h"
#include "api/string.h"
using namespace lean; // NOLINT
namespace lean {
memout_exception * get_memout_exception() {
static memout_exception g_memout;
return &g_memout;
}
void check_nonnull(void const * ptr) {
if (!ptr)
throw exception("invalid argument, it must be a nonnull pointer");
}
}
void lean_exception_del(lean_exception e) {
lean::throwable * t = lean::to_exception(e);
if (t != lean::get_memout_exception()) {
delete t;
}
}
char const * lean_exception_get_message(lean_exception e) {
if (!e)
return 0;
try {
return lean::mk_string(lean::to_exception(e)->what());
} catch (...) {
return 0;
}
}
lean_exception_kind lean_exception_get_kind(lean_exception e) {
lean::throwable * ex = lean::to_exception(e);
if (!ex)
return LEAN_NULL_EXCEPTION;
if (dynamic_cast<lean::memout_exception*>(ex))
return LEAN_OUT_OF_MEMORY;
if (dynamic_cast<lean::system_exception*>(ex))
return LEAN_SYSTEM_EXCEPTION;
if (dynamic_cast<lean::kernel_exception*>(ex))
return LEAN_KERNEL_EXCEPTION;
if (dynamic_cast<lean::interrupted*>(ex))
return LEAN_INTERRUPTED;
if (dynamic_cast<lean::parser_exception*>(ex))
return LEAN_PARSER_EXCEPTION;
return LEAN_OTHER_EXCEPTION;
}

View file

@ -1,60 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include <string>
#include "util/exception.h"
#include "library/exception.h"
#include "api/lean_macros.h"
#include "api/lean_bool.h"
#include "api/lean_exception.h"
namespace lean {
inline throwable * to_exception(lean_exception e) { return reinterpret_cast<throwable *>(e); }
inline lean_exception of_exception(throwable * e) { return reinterpret_cast<lean_exception>(e); }
class memout_exception : public throwable {
public:
memout_exception() {}
virtual ~memout_exception() noexcept {}
virtual char const * what() const noexcept { return "out of memory"; }
virtual throwable * clone() const { return new memout_exception(); }
virtual void rethrow() const { throw *this; }
};
class system_exception : public throwable {
public:
system_exception():throwable("unknown exception") {}
system_exception(std::string const & msg):throwable(msg) {}
system_exception(std::exception const & ex):throwable(ex.what()) {}
virtual ~system_exception() noexcept {}
virtual throwable * clone() const { return new system_exception(what()); }
virtual void rethrow() const { throw *this; }
};
memout_exception * get_memout_exception();
void check_nonnull(void const *);
}
#define LEAN_TRY try {
#define LEAN_CATCH \
} catch (lean::parser_nested_exception & e) { \
*ex = of_exception(e.get_exception().clone()); \
return lean_false; \
} catch (lean::exception & e) { \
*ex = of_exception(e.clone()); \
return lean_false; \
} catch (std::bad_alloc &) { \
*ex = of_exception(lean::get_memout_exception()); \
return lean_false; \
} catch (std::exception & e) { \
*ex = of_exception(new lean::system_exception(e)); \
return lean_false; \
} catch (...) { \
*ex = of_exception(new lean::system_exception()); \
return lean_false; \
} \
return lean_true

View file

@ -1,397 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "library/expr_lt.h"
#include "api/univ.h"
#include "api/expr.h"
#include "api/string.h"
#include "api/exception.h"
namespace lean {
void to_buffer(unsigned sz, lean_expr const * ns, buffer<expr> & r) {
check_nonnull(ns);
for (unsigned i = 0; i < sz; i++) {
check_nonnull(ns[i]);
r.push_back(to_expr_ref(ns[i]));
}
}
}
using namespace lean; // NOLINT
lean_bool lean_expr_mk_var(unsigned i, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
*r = of_expr(new expr(mk_var(i)));
LEAN_CATCH;
}
lean_bool lean_expr_mk_sort(lean_univ u, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
*r = of_expr(new expr(mk_sort(to_level_ref(u))));
LEAN_CATCH;
}
lean_bool lean_expr_mk_const(lean_name n, lean_list_univ us, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(us);
*r = of_expr(new expr(mk_constant(to_name_ref(n), to_list_level_ref(us))));
LEAN_CATCH;
}
lean_bool lean_expr_mk_app(lean_expr f, lean_expr a, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(f);
check_nonnull(a);
*r = of_expr(new expr(mk_app(to_expr_ref(f), to_expr_ref(a))));
LEAN_CATCH;
}
static binder_info to_binder_info(lean_binder_kind k) {
switch (k) {
case LEAN_BINDER_DEFAULT: return binder_info();
case LEAN_BINDER_IMPLICIT: return mk_implicit_binder_info();
case LEAN_BINDER_STRICT_IMPLICIT: return mk_strict_implicit_binder_info();
case LEAN_BINDER_INST_IMPLICIT: return mk_inst_implicit_binder_info();
}
lean_unreachable();
}
static lean_binder_kind of_binder_info(binder_info k) {
if (k.is_implicit())
return LEAN_BINDER_IMPLICIT;
else if (k.is_inst_implicit())
return LEAN_BINDER_INST_IMPLICIT;
else if (k.is_strict_implicit())
return LEAN_BINDER_STRICT_IMPLICIT;
else
return LEAN_BINDER_DEFAULT;
}
lean_bool lean_expr_mk_lambda(lean_name n, lean_expr t, lean_expr b, lean_binder_kind k, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(t);
check_nonnull(b);
*r = of_expr(new expr(mk_lambda(to_name_ref(n), to_expr_ref(t), to_expr_ref(b), to_binder_info(k))));
LEAN_CATCH;
}
lean_bool lean_expr_mk_pi(lean_name n, lean_expr t, lean_expr b, lean_binder_kind k, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(t);
check_nonnull(b);
*r = of_expr(new expr(mk_pi(to_name_ref(n), to_expr_ref(t), to_expr_ref(b), to_binder_info(k))));
LEAN_CATCH;
}
lean_bool lean_expr_mk_macro(lean_macro_def m, lean_list_expr args, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(m);
check_nonnull(args);
buffer<expr> _args;
to_buffer(to_list_expr_ref(args), _args);
*r = of_expr(new expr(mk_macro(to_macro_definition_ref(m), _args.size(), _args.data())));
LEAN_CATCH;
}
lean_bool lean_expr_mk_local(lean_name n, lean_expr t, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(t);
*r = of_expr(new expr(mk_local(to_name_ref(n), to_expr_ref(t))));
LEAN_CATCH;
}
lean_bool lean_expr_mk_local_ext(lean_name n, lean_name pp_n, lean_expr t, lean_binder_kind k, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(pp_n);
check_nonnull(t);
*r = of_expr(new expr(mk_local(to_name_ref(n), to_name_ref(pp_n), to_expr_ref(t), to_binder_info(k))));
LEAN_CATCH;
}
lean_bool lean_expr_mk_metavar(lean_name n, lean_expr t, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(t);
*r = of_expr(new expr(mk_metavar(to_name_ref(n), to_expr_ref(t))));
LEAN_CATCH;
}
lean_bool lean_expr_to_string(lean_expr e, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e);
std::ostringstream out;
out << to_expr_ref(e);
*r = mk_string(out.str());
LEAN_CATCH;
}
void lean_expr_del(lean_expr e) {
delete to_expr(e);
}
void lean_macro_def_del(lean_macro_def m) {
delete to_macro_definition(m);
}
lean_bool lean_macro_def_eq(lean_macro_def m1, lean_macro_def m2, lean_bool * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(m1);
check_nonnull(m2);
*r = to_macro_definition_ref(m1) == to_macro_definition_ref(m2);
LEAN_CATCH;
}
lean_bool lean_macro_def_to_string(lean_macro_def m, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(m);
std::ostringstream out;
to_macro_definition_ref(m).display(out);
*r = mk_string(out.str());
LEAN_CATCH;
}
lean_expr_kind lean_expr_get_kind(lean_expr e) {
if (!e)
return LEAN_EXPR_VAR;
switch (to_expr_ref(e).kind()) {
case expr_kind::Var: return LEAN_EXPR_VAR;
case expr_kind::Sort: return LEAN_EXPR_SORT;
case expr_kind::Constant: return LEAN_EXPR_CONST;
case expr_kind::Meta: return LEAN_EXPR_META;
case expr_kind::Local: return LEAN_EXPR_LOCAL;
case expr_kind::App: return LEAN_EXPR_APP;
case expr_kind::Lambda: return LEAN_EXPR_LAMBDA;
case expr_kind::Pi: return LEAN_EXPR_PI;
case expr_kind::Let: return LEAN_EXPR_LET;
case expr_kind::Macro: return LEAN_EXPR_MACRO;
}
lean_unreachable();
}
lean_bool lean_expr_eq(lean_expr e1, lean_expr e2, lean_bool * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e1);
check_nonnull(e2);
*r = to_expr_ref(e1) == to_expr_ref(e2);
LEAN_CATCH;
}
lean_bool lean_expr_lt(lean_expr e1, lean_expr e2, lean_bool * b, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e1);
check_nonnull(e2);
*b = is_lt(to_expr_ref(e1), to_expr_ref(e2), false);
LEAN_CATCH;
}
lean_bool lean_expr_quick_lt(lean_expr e1, lean_expr e2, lean_bool * b, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e1);
check_nonnull(e2);
*b = is_lt(to_expr_ref(e1), to_expr_ref(e2), true);
LEAN_CATCH;
}
static void check_expr_kind(lean_expr e, lean_expr_kind k, char const * msg) {
check_nonnull(e);
if (lean_expr_get_kind(e) != k)
throw exception(msg);
}
lean_bool lean_expr_get_var_idx(lean_expr e, unsigned * i, lean_exception * ex) {
LEAN_TRY;
check_expr_kind(e, LEAN_EXPR_VAR, "invalid argument, variable expected");
*i = var_idx(to_expr_ref(e));
LEAN_CATCH;
}
lean_bool lean_expr_get_sort_univ(lean_expr e, lean_univ * u, lean_exception * ex) {
LEAN_TRY;
check_expr_kind(e, LEAN_EXPR_SORT, "invalid argument, sort expected");
*u = of_level(new level(sort_level(to_expr_ref(e))));
LEAN_CATCH;
}
static void check_constant(lean_expr e) {
check_expr_kind(e, LEAN_EXPR_CONST, "invalid argument, constant expected");
}
lean_bool lean_expr_get_const_name(lean_expr e, lean_name * n, lean_exception * ex) {
LEAN_TRY;
check_constant(e);
*n = of_name(new name(const_name(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_expr_get_const_univs(lean_expr e, lean_list_univ * us, lean_exception * ex) {
LEAN_TRY;
check_constant(e);
*us = of_list_level(new list<level>(const_levels(to_expr_ref(e))));
LEAN_CATCH;
}
static void check_app(lean_expr e) {
check_expr_kind(e, LEAN_EXPR_APP, "invalid argument, function application expected");
}
lean_bool lean_expr_get_app_fun(lean_expr e, lean_expr * f, lean_exception * ex) {
LEAN_TRY;
check_app(e);
*f = of_expr(new expr(app_fn(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_expr_get_app_arg(lean_expr e, lean_expr * a, lean_exception * ex) {
LEAN_TRY;
check_app(e);
*a = of_expr(new expr(app_arg(to_expr_ref(e))));
LEAN_CATCH;
}
static void check_mlocal(lean_expr e) {
check_nonnull(e);
if (lean_expr_get_kind(e) != LEAN_EXPR_LOCAL && lean_expr_get_kind(e) != LEAN_EXPR_META)
throw exception("invalid argument, local constant or meta-variable expected");
}
static void check_local(lean_expr e) {
check_expr_kind(e, LEAN_EXPR_LOCAL, "invalid argument, local constant expected");
}
lean_bool lean_expr_get_mlocal_name(lean_expr e, lean_name * n, lean_exception * ex) {
LEAN_TRY;
check_mlocal(e);
*n = of_name(new name(mlocal_name(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_expr_get_mlocal_type(lean_expr e, lean_expr * t, lean_exception * ex) {
LEAN_TRY;
check_mlocal(e);
*t = of_expr(new expr(mlocal_type(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_expr_get_local_pp_name(lean_expr e, lean_name * n, lean_exception * ex) {
LEAN_TRY;
check_local(e);
*n = of_name(new name(mlocal_pp_name(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_expr_get_local_binder_kind(lean_expr e, lean_binder_kind * k, lean_exception * ex) {
LEAN_TRY;
check_local(e);
*k = of_binder_info(local_info(to_expr_ref(e)));
LEAN_CATCH;
}
static void check_binding(lean_expr e) {
check_nonnull(e);
if (lean_expr_get_kind(e) != LEAN_EXPR_PI && lean_expr_get_kind(e) != LEAN_EXPR_LAMBDA)
throw exception("invalid argument, lambda or Pi expression expected");
}
lean_bool lean_expr_get_binding_name(lean_expr e, lean_name * n, lean_exception * ex) {
LEAN_TRY;
check_binding(e);
*n = of_name(new name(binding_name(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_expr_get_binding_domain(lean_expr e, lean_expr * d, lean_exception * ex) {
LEAN_TRY;
check_binding(e);
*d = of_expr(new expr(binding_domain(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_expr_get_binding_body(lean_expr e, lean_expr * b, lean_exception * ex) {
LEAN_TRY;
check_binding(e);
*b = of_expr(new expr(binding_body(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_expr_get_binding_binder_kind(lean_expr e, lean_binder_kind * k, lean_exception * ex) {
LEAN_TRY;
check_binding(e);
*k = of_binder_info(binding_info(to_expr_ref(e)));
LEAN_CATCH;
}
static void check_macro(lean_expr e) {
check_expr_kind(e, LEAN_EXPR_MACRO, "invalid argument, macro application expected");
}
lean_bool lean_expr_get_macro_def(lean_expr e, lean_macro_def * d, lean_exception * ex) {
LEAN_TRY;
check_macro(e);
*d = of_macro_definition(new macro_definition(macro_def(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_expr_get_macro_args(lean_expr e, lean_list_expr * as, lean_exception * ex) {
LEAN_TRY;
check_macro(e);
buffer<expr> args;
args.append(macro_num_args(to_expr_ref(e)), macro_args(to_expr_ref(e)));
*as = of_list_expr(new list<expr>(to_list(args)));
LEAN_CATCH;
}
lean_bool lean_list_expr_mk_nil(lean_list_expr * r, lean_exception * ex) {
LEAN_TRY;
*r = of_list_expr(new list<expr>());
LEAN_CATCH;
}
lean_bool lean_list_expr_mk_cons(lean_expr h, lean_list_expr t, lean_list_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(h);
check_nonnull(t);
*r = of_list_expr(new list<expr>(to_expr_ref(h), to_list_expr_ref(t)));
LEAN_CATCH;
}
void lean_list_expr_del(lean_list_expr l) {
delete to_list_expr(l);
}
lean_bool lean_list_expr_is_cons(lean_list_expr l) {
return l && !is_nil(to_list_expr_ref(l));
}
lean_bool lean_list_expr_eq(lean_list_expr l1, lean_list_expr l2, lean_bool * b, lean_exception * ex) {
LEAN_TRY;
check_nonnull(l1);
check_nonnull(l2);
*b = to_list_expr_ref(l1) == to_list_expr_ref(l2);
LEAN_CATCH;
}
lean_bool lean_list_expr_head(lean_list_expr l, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(l);
if (!lean_list_expr_is_cons(l))
throw lean::exception("invalid argument, non-nil list expected");
*r = of_expr(new expr(head(to_list_expr_ref(l))));
LEAN_CATCH;
}
lean_bool lean_list_expr_tail(lean_list_expr l, lean_list_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(l);
if (!lean_list_expr_is_cons(l))
throw lean::exception("invalid argument, non-nil list expected");
*r = of_list_expr(new list<expr>(tail(to_list_expr_ref(l))));
LEAN_CATCH;
}

View file

@ -1,24 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "kernel/expr.h"
#include "api/univ.h"
#include "api/lean_expr.h"
namespace lean {
inline expr * to_expr(lean_expr n) { return reinterpret_cast<expr *>(n); }
inline expr const & to_expr_ref(lean_expr n) { return *reinterpret_cast<expr *>(n); }
inline lean_expr of_expr(expr * n) { return reinterpret_cast<lean_expr>(n); }
void to_buffer(unsigned sz, lean_expr const * ns, buffer<expr> & r);
inline list<expr> * to_list_expr(lean_list_expr n) { return reinterpret_cast<list<expr> *>(n); }
inline list<expr> const & to_list_expr_ref(lean_list_expr n) { return *reinterpret_cast<list<expr> *>(n); }
inline lean_list_expr of_list_expr(list<expr> * n) { return reinterpret_cast<lean_list_expr>(n); }
inline macro_definition * to_macro_definition(lean_macro_def n) { return reinterpret_cast<macro_definition *>(n); }
inline macro_definition const & to_macro_definition_ref(lean_macro_def n) { return *reinterpret_cast<macro_definition *>(n); }
inline lean_macro_def of_macro_definition(macro_definition * n) { return reinterpret_cast<lean_macro_def>(n); }
}

View file

@ -1,155 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "library/module.h"
#include "api/decl.h"
#include "api/inductive.h"
#include "api/string.h"
#include "api/exception.h"
using namespace lean; // NOLINT
using namespace lean::inductive; // NOLINT
lean_bool lean_inductive_decl_mk(lean_name n, lean_list_name ps, unsigned nparams, lean_expr t, lean_list_expr cs, lean_inductive_decl * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
check_nonnull(ps);
check_nonnull(t);
check_nonnull(cs);
for (expr const & c : to_list_expr_ref(cs)) {
if (!is_local(c))
throw exception("invalid inductive type, constructor must be a local constant");
}
*r = of_inductive_decl(new inductive_decl(to_name_ref(n), to_list_name_ref(ps), nparams, to_expr_ref(t), to_list_expr_ref(cs)));
LEAN_CATCH;
}
void lean_inductive_decl_del(lean_inductive_decl t) {
delete to_inductive_decl(t);
}
lean_bool lean_get_recursor_name(lean_name n, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
*r = of_name(new name(get_elim_name(to_name_ref(n))));
LEAN_CATCH;
}
lean_bool lean_inductive_decl_get_name(lean_inductive_decl t, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(t);
*r = of_name(new name(to_inductive_decl_ref(t).m_name));
LEAN_CATCH;
}
lean_bool lean_inductive_decl_get_type(lean_inductive_decl t, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(t);
*r = of_expr(new expr(to_inductive_decl_ref(t).m_type));
LEAN_CATCH;
}
lean_bool lean_inductive_decl_get_constructors(lean_inductive_decl t, lean_list_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(t);
*r = of_list_expr(new list<expr>(to_inductive_decl_ref(t).m_intro_rules));
LEAN_CATCH;
}
lean_bool lean_inductive_decl_get_univ_params(lean_inductive_decl d, lean_list_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(d);
*r = of_list_name(new list<name>(to_inductive_decl_ref(d).m_level_params));
LEAN_CATCH;
}
lean_bool lean_inductive_decl_get_num_params(lean_inductive_decl d, unsigned * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(d);
*r = to_inductive_decl_ref(d).m_num_params;
LEAN_CATCH;
}
lean_bool lean_env_add_inductive(lean_env env, lean_inductive_decl d, lean_env * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(d);
bool is_trusted = true;
*r = of_env(new environment(module::add_inductive(to_env_ref(env), to_inductive_decl_ref(d), is_trusted)));
LEAN_CATCH;
}
lean_bool lean_env_is_inductive_type(lean_env env, lean_name n, lean_inductive_decl * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(n);
if (auto d = is_inductive_decl(to_env_ref(env), to_name_ref(n))) {
*r = of_inductive_decl(new inductive_decl(*d));
return lean_true;
} else {
return lean_false;
}
LEAN_CATCH;
}
lean_bool lean_env_is_constructor(lean_env env, lean_name n, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(n);
if (auto d = is_intro_rule(to_env_ref(env), to_name_ref(n))) {
*r = of_name(new name(*d));
return lean_true;
} else {
return lean_false;
}
LEAN_CATCH;
}
lean_bool lean_env_is_recursor(lean_env env, lean_name n, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(n);
if (auto d = is_elim_rule(to_env_ref(env), to_name_ref(n))) {
*r = of_name(new name(*d));
return lean_true;
} else {
return lean_false;
}
LEAN_CATCH;
}
lean_bool lean_env_get_inductive_type_num_indices(lean_env env, lean_name n, unsigned * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(n);
if (auto d = get_num_indices(to_env_ref(env), to_name_ref(n))) {
*r = *d;
return lean_true;
} else {
return lean_false;
}
LEAN_CATCH;
}
lean_bool lean_env_get_inductive_type_num_minor_premises(lean_env env, lean_name n, unsigned * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(n);
if (auto d = get_num_minor_premises(to_env_ref(env), to_name_ref(n))) {
*r = *d;
return lean_true;
} else {
return lean_false;
}
LEAN_CATCH;
}
lean_bool lean_env_get_inductive_type_has_dep_elim(lean_env env, lean_name n, lean_bool * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(n);
*r = has_dep_elim(to_env_ref(env), to_name_ref(n));
LEAN_CATCH;
}

View file

@ -1,19 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "kernel/inductive/inductive.h"
#include "api/expr.h"
#include "api/lean_decl.h"
#include "api/lean_inductive.h"
namespace lean {
using inductive::intro_rule;
using inductive::inductive_decl;
inline inductive_decl * to_inductive_decl(lean_inductive_decl n) { return reinterpret_cast<inductive_decl *>(n); }
inline inductive_decl const & to_inductive_decl_ref(lean_inductive_decl n) { return *reinterpret_cast<inductive_decl *>(n); }
inline lean_inductive_decl of_inductive_decl(inductive_decl * n) { return reinterpret_cast<lean_inductive_decl>(n); }
}

View file

@ -1,122 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "library/io_state_stream.h"
#include "frontends/lean/pp.h"
#include "api/string.h"
#include "api/exception.h"
#include "api/decl.h"
#include "api/lean_env.h"
#include "api/ios.h"
using namespace lean; // NOLINT
lean_bool lean_ios_mk_std(lean_options o, lean_ios * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(o);
io_state ios(mk_pretty_formatter_factory(), to_options_ref(o));
*r = of_io_state(new io_state(ios));
LEAN_CATCH;
}
lean_bool lean_ios_mk_buffered(lean_options o, lean_ios * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(o);
io_state ios(mk_pretty_formatter_factory(), to_options_ref(o));
ios.set_regular_channel(std::make_shared<string_output_channel>());
ios.set_diagnostic_channel(std::make_shared<string_output_channel>());
*r = of_io_state(new io_state(ios));
LEAN_CATCH;
}
void lean_ios_del(lean_ios ios) {
delete to_io_state(ios);
}
lean_bool lean_ios_is_std(lean_ios ios) {
if (!ios)
return lean_false;
return dynamic_cast<string_output_channel*>(&to_io_state_ref(ios).get_regular_channel()) == nullptr;
}
lean_bool lean_ios_set_options(lean_ios ios, lean_options o, lean_exception * ex) {
LEAN_TRY;
check_nonnull(ios);
check_nonnull(o);
to_io_state(ios)->set_options(to_options_ref(o));
LEAN_CATCH;
}
lean_bool lean_ios_get_options(lean_ios ios, lean_options * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(ios);
*r = of_options(new options(to_io_state_ref(ios).get_options()));
LEAN_CATCH;
}
static void check_nonstd(lean_ios ios) {
check_nonnull(ios);
if (lean_ios_is_std(ios))
throw exception("invalid argument, buffered IO state expected");
}
lean_bool lean_ios_get_regular(lean_ios ios, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonstd(ios);
*r = mk_string(static_cast<string_output_channel&>(to_io_state_ref(ios).get_regular_channel()).str());
LEAN_CATCH;
}
lean_bool lean_ios_get_diagnostic(lean_ios ios, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonstd(ios);
*r = mk_string(static_cast<string_output_channel&>(to_io_state_ref(ios).get_diagnostic_channel()).str());
LEAN_CATCH;
}
lean_bool lean_ios_reset_regular(lean_ios ios, lean_exception * ex) {
LEAN_TRY;
check_nonstd(ios);
to_io_state(ios)->set_regular_channel(std::make_shared<string_output_channel>());
LEAN_CATCH;
}
lean_bool lean_ios_reset_diagnostic(lean_ios ios, lean_exception * ex) {
LEAN_TRY;
check_nonstd(ios);
to_io_state(ios)->set_diagnostic_channel(std::make_shared<string_output_channel>());
LEAN_CATCH;
}
lean_bool lean_expr_to_pp_string(lean_env env, lean_ios ios, lean_expr e, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(ios);
check_nonnull(e);
options const & o = to_io_state_ref(ios).get_options();
type_checker tc(to_env_ref(env));
formatter fmt = to_io_state_ref(ios).get_formatter_factory()(to_env_ref(env), o, tc);
std::ostringstream out;
out << mk_pair(fmt(to_expr_ref(e)), o);
*r = mk_string(out.str());
LEAN_CATCH;
}
lean_bool lean_exception_to_pp_string(lean_env env, lean_ios ios, lean_exception e, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(ios);
check_nonnull(e);
io_state new_ios(to_io_state_ref(ios));
std::shared_ptr<output_channel> aux(new string_output_channel());
new_ios.set_regular_channel(aux);
new_ios.set_diagnostic_channel(aux);
type_checker tc(to_env_ref(env));
io_state_stream ioss(to_env_ref(env), new_ios, tc);
throwable * _e = to_exception(e);
ioss << _e->what();
*r = mk_string(static_cast<string_output_channel const *>(aux.get())->str());
LEAN_CATCH;
}

View file

@ -1,15 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "library/io_state.h"
#include "api/expr.h"
#include "api/lean_ios.h"
namespace lean {
inline io_state * to_io_state(lean_ios n) { return reinterpret_cast<io_state *>(n); }
inline io_state const & to_io_state_ref(lean_ios n) { return *reinterpret_cast<io_state *>(n); }
inline lean_ios of_io_state(io_state * n) { return reinterpret_cast<lean_ios>(n); }
}

View file

@ -1,26 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_H
#define _LEAN_H
#include "lean_macros.h" // NOLINT
#include "lean_bool.h" // NOLINT
#include "lean_string.h" // NOLINT
#include "lean_exception.h" // NOLINT
#include "lean_name.h" // NOLINT
#include "lean_options.h" // NOLINT
#include "lean_univ.h" // NOLINT
#include "lean_expr.h" // NOLINT
#include "lean_decl.h" // NOLINT
#include "lean_env.h" // NOLINT
#include "lean_ios.h" // NOLINT
#include "lean_module.h" // NOLINT
#include "lean_type_checker.h" // NOLINT
#include "lean_inductive.h" // NOLINT
#include "lean_parser.h" // NOLINT
#endif

View file

@ -1,14 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_BOOL_H
#define _LEAN_BOOL_H
#define lean_bool int
#define lean_true 1
#define lean_false 0
#endif

View file

@ -1,97 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_DECL_H
#define _LEAN_DECL_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Declaration API
*/
/*@{*/
LEAN_DEFINE_TYPE(lean_env);
LEAN_DEFINE_TYPE(lean_decl);
LEAN_DEFINE_TYPE(lean_cert_decl);
typedef enum {
LEAN_DECL_CONST,
LEAN_DECL_AXIOM,
LEAN_DECL_DEF,
LEAN_DECL_THM
} lean_decl_kind;
/** \brief Create an axiom with name \c n, universe parameters names \c p, and type \c t
\remark Recall that declarations are universe polymorphic in Lean. */
lean_bool lean_decl_mk_axiom(lean_name n, lean_list_name p, lean_expr t, lean_decl * r, lean_exception * ex);
/** \brief Create an constant with name \c n, universe parameters names \c p, and type \c t
\remark Constants and axioms are essentially the same thing in Lean. */
lean_bool lean_decl_mk_const(lean_name n, lean_list_name p, lean_expr t, lean_decl * r, lean_exception * ex);
/** \brief Create a definition with name \c n, universe parameters names \c p, type \c t, value \c v,
definitional height \c h and a flag \c o indicating whether normalization will lazily unfold it or not. */
lean_bool lean_decl_mk_def(lean_name n, lean_list_name p, lean_expr t, lean_expr v, unsigned h, lean_bool o, lean_decl * r, lean_exception * ex);
/** \brief Create a definition with name \c n, universe parameters names \c p, type \c t, value \c v,
and a flag \c o indicating whether normalization will lazily unfold it or not.
\remark The definitional height is computed using the information in the given environment. */
lean_bool lean_decl_mk_def_with(lean_env e, lean_name n, lean_list_name p, lean_expr t, lean_expr v, lean_bool o, lean_decl * r, lean_exception * ex);
/** \brief Create a theorem with name \c n, universe parameters names \c p, type \c t, value \c v, definitional height \c h \remark
Theorems and definitions are essentially the same thing in Lean. The main difference is how the normalizer treats them. The
normalizer will only unfold a theorem if there is nothing else to be done when checking whether two terms are definitionally equal
or not. */
lean_bool lean_decl_mk_thm(lean_name n, lean_list_name p, lean_expr t, lean_expr v, unsigned h, lean_decl * r, lean_exception * ex);
/** \brief Create a theorem with name \c n, universe parameters names \c p, type \c t, value \c v, definitional height \c h \remark
Theorems and definitions are essentially the same thing in Lean. The main difference is how the normalizer treats them. The
normalizer will only unfold a theorem if there is nothing else to be done when checking whether two terms are definitionally equal
or not.
\remark The definitional height is computed using the information in the given environment. */
lean_bool lean_decl_mk_thm_with(lean_env e, lean_name n, lean_list_name p, lean_expr t, lean_expr v, lean_decl * r, lean_exception * ex);
/** \brief Delete/dispose the given declaration. */
void lean_decl_del(lean_decl d);
/** \brief Return the kind of the given declaration.
\remark Return LEAN_DECL_CONST if d is null. */
lean_decl_kind lean_decl_get_kind(lean_decl d);
/** \brief Store in \c r the name the given declaration. */
lean_bool lean_decl_get_name(lean_decl d, lean_name * r, lean_exception * ex);
/** \brief Store in \c r the list of universe parameter names of the given declaration. */
lean_bool lean_decl_get_univ_params(lean_decl d, lean_list_name * r, lean_exception * ex);
/** \brief Store in \c r the type of the given declaration. */
lean_bool lean_decl_get_type(lean_decl d, lean_expr * r, lean_exception * ex);
/** \brief Store in \c r the value of the given theorem or definition.
\pre lean_decl_get_kind(d) == LEAN_DECL_THM || lean_decl_get_kind(d) == LEAN_DECL_DEF
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_decl_get_value(lean_decl d, lean_expr * r, lean_exception * ex);
/** \brief Store in \c r the definitional height of the given theorem or definition.
\pre lean_decl_get_kind(d) == LEAN_DECL_THM || lean_decl_get_kind(d) == LEAN_DECL_DEF
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_decl_get_height(lean_decl d, unsigned * r, lean_exception * ex);
/** \brief Store in \c r whether lazy unfolding is considered for the given definition.
\pre lean_decl_get_kind(d) == LEAN_DECL_DEF
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_decl_get_conv_opt(lean_decl d, lean_bool * r, lean_exception * ex);
/** \brief Create a certified declaration by type checking the given declaration with respect to the given environment
\remark exceptions: LEAN_KERNEL_EXCEPTION */
lean_bool lean_decl_check(lean_env e, lean_decl d, lean_cert_decl * r, lean_exception * ex);
/** \brief Delete/dispose the given certified declaration. */
void lean_cert_decl_del(lean_cert_decl d);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,69 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_ENV_H
#define _LEAN_ENV_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Environment API
*/
/*@{*/
/** \brief Create a standard environment (i.e., proof irrelevant, and containing an impredicative Prop) with trust level \c t.
If the trust level is 0, then all imported modules are retype-checked, and declarations containing macros are rejected. */
lean_bool lean_env_mk_std(unsigned t, lean_env * r, lean_exception * ex);
/** Trust all macros implemented in Lean, and do no retype-check imported modules */
#define LEAN_TRUST_HIGH 100000
/** \brief Create a new environment by adding the given certified declaration \c d to the environment \c e.
\remark exceptions: LEAN_KERNEL_EXCEPTION */
lean_bool lean_env_add(lean_env e, lean_cert_decl d, lean_env * r, lean_exception * ex);
/** \brief Replace the axiom with the name of the given certified theorem \c d with \c d.
This procedure throws an exception if:
- The theorem was certified in an environment which is not an ancestor of \c e.
- The environment does not contain an axiom with the given name.
\remark exceptions: LEAN_KERNEL_EXCEPTION */
lean_bool lean_env_replace(lean_env e, lean_cert_decl d, lean_env * r, lean_exception * ex);
/** \brief Delete/dispose the given environment. */
void lean_env_del(lean_env e);
/** \brief Return the trust level of the given environment */
unsigned lean_env_trust_level(lean_env e);
/** \brief Return true iff \c e contains a declaration with name \c n. */
lean_bool lean_env_contains_decl(lean_env e, lean_name n);
/** \brief Store in \c d the declaration with name \c n in \c e.
\remark exceptions: LEAN_KERNEL_EXCEPTION */
lean_bool lean_env_get_decl(lean_env e, lean_name n, lean_decl * d, lean_exception * ex);
/** \brief Return true when \c e1 is a descendant of \c e2, that is, \c e1 was created by adding declarations to \c e2. */
lean_bool lean_env_is_descendant(lean_env e1, lean_env e2);
/** \brief Return a new environment, where its "history" has been truncated/forgotten.
That is, <tt>is_descendant(r, e2)</tt> will return false for any environment \c e2 that
is not pointer equal to the result. */
lean_bool lean_env_forget(lean_env e, lean_env * r, lean_exception * ex);
/** \brief Execute \c f for each declaration in \c env.
\remark Every declaration passed to \c f must be disposed using \c lean_decl_del. */
lean_bool lean_env_for_each_decl(lean_env e, void (*f)(lean_decl), lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,62 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_EXCEPTION_H
#define _LEAN_EXCEPTION_H
#ifdef __cplusplus
extern "C" {
#endif
LEAN_DEFINE_TYPE(lean_exception);
/** \brief Delete an exception object allocated by Lean.
This is a NOOP if \c e is null.
*/
void lean_exception_del(lean_exception e);
/** \brief Return basic string/message describing the exception.
\remark The string must be deallocated using #lean_string_del.
\remark After we define the Lean environment object, we can
provide richer messages.
\remark The result is null if the operation failed or \c e is null.
*/
char const * lean_exception_get_message(lean_exception e);
/** \brief Return basic string/message describing the exception.
\remark The string must be deallocated using #lean_string_del.
This function is similar to #lean_exception_get_message, but produces
more information if available.
*/
char const * lean_exception_get_detailed_message(lean_exception e);
/** \brief Exceptions and errors signed by the Lean API.
The first four (LEAN_NULL_EXCEPTION, LEAN_SYSTEM_EXCEPTION, LEAN_OUT_OF_MEMORY, LEAN_INTERRUPTED)
are considered to be low-level exceptions.
In principle, any procedure that has the argument <tt>lean_exception * ex</tt> may return one
of them.
The remaining ones can be viewed as "real" (or high-level) exceptions, and
we document the procedures that may throw them.
*/
typedef enum {
LEAN_NULL_EXCEPTION, // null (aka there is no exception)
LEAN_SYSTEM_EXCEPTION, // exception generated by the C++ runtime
LEAN_OUT_OF_MEMORY, // out of memory exception
LEAN_INTERRUPTED, // execution was interrupted by user request
LEAN_KERNEL_EXCEPTION, // type checking error
LEAN_PARSER_EXCEPTION, // parser exception
LEAN_OTHER_EXCEPTION // other (TODO) lean exceptions
} lean_exception_kind;
/** \brief Return the kind of the given exception. */
lean_exception_kind lean_exception_get_kind(lean_exception e);
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,192 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_EXPR_H
#define _LEAN_EXPR_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Expression API
*/
/*@{*/
LEAN_DEFINE_TYPE(lean_macro_def);
LEAN_DEFINE_TYPE(lean_expr);
LEAN_DEFINE_TYPE(lean_list_expr);
typedef enum {
LEAN_EXPR_VAR,
LEAN_EXPR_SORT,
LEAN_EXPR_CONST,
LEAN_EXPR_LOCAL,
LEAN_EXPR_META,
LEAN_EXPR_APP,
LEAN_EXPR_LAMBDA,
LEAN_EXPR_PI,
LEAN_EXPR_LET,
LEAN_EXPR_MACRO,
} lean_expr_kind;
typedef enum {
LEAN_BINDER_DEFAULT, // (x : A)
LEAN_BINDER_IMPLICIT, // {x : A}
LEAN_BINDER_STRICT_IMPLICIT, // {{x : A}}
LEAN_BINDER_INST_IMPLICIT // [x : A]
} lean_binder_kind;
/** \brief Create a variable with de-Bruijn index \c i.
This is a bounded variable. */
lean_bool lean_expr_mk_var(unsigned i, lean_expr * r, lean_exception * ex);
/** \brief r := Type.{u} */
lean_bool lean_expr_mk_sort(lean_univ u, lean_expr * r, lean_exception * ex);
/** \brief Create a constant with name \c n and universe parameters <tt>us[0], ..., us[sz-1]</tt>,
and store the result in \c r. */
lean_bool lean_expr_mk_const(lean_name n, lean_list_univ us, lean_expr * r, lean_exception * ex);
/** \brief Create a function application, r := f a */
lean_bool lean_expr_mk_app(lean_expr f, lean_expr a, lean_expr * r, lean_exception * ex);
/** \brief Create a lambda abstraction, r := (fun n : t, b)
\remark The parameter \c k specifies the kind of binder annotation (i.e., it corresponds to (), {}, {{}}, [] decorations in the lean front-end) */
lean_bool lean_expr_mk_lambda(lean_name n, lean_expr t, lean_expr b, lean_binder_kind k, lean_expr * r, lean_exception * ex);
/** \brief Create a Pi abstraction, r := (Pi n : t, b)
\remark The parameter \c k specifies the kind of binder annotation (i.e., it corresponds to (), {}, {{}}, [] decorations in the lean front-end) */
lean_bool lean_expr_mk_pi(lean_name n, lean_expr t, lean_expr b, lean_binder_kind k, lean_expr * r, lean_exception * ex);
/** \brief Create a macro application */
lean_bool lean_expr_mk_macro(lean_macro_def m, lean_list_expr args, lean_expr * r, lean_exception * ex);
/** \brief Create a local constant with name \c n and type \c t, and store the result in \c r.
\remark We use local constants to represent free variables. */
lean_bool lean_expr_mk_local(lean_name n, lean_expr t, lean_expr * r, lean_exception * ex);
/** \brief Create a local constant with internal name \c n and pretty print name \c pp_n, and type \c t, and store the result in \c r.
\remark We use local constants to represent free variables.
\remark The parameter \c k specifies the kind of binder annotation (i.e., it corresponds to (), {}, {{}}, [] decorations in the lean front-end). */
lean_bool lean_expr_mk_local_ext(lean_name n, lean_name pp_n, lean_expr t, lean_binder_kind k, lean_expr * r, lean_exception * ex);
/** \brief Create a meta-variable (aka unification variable) with name \c n and type \c t, and store the result in \c r. */
lean_bool lean_expr_mk_metavar(lean_name n, lean_expr t, lean_expr * r, lean_exception * ex);
/** \brief Delete/dispose the given macro definition. */
void lean_macro_def_del(lean_macro_def m);
/** \brief Store \c lean_true in \c r iff the two given macro definitions are equal. */
lean_bool lean_macro_def_eq(lean_macro_def m1, lean_macro_def m2, lean_bool * r, lean_exception * ex);
/** \brief Store in \c r a (crude) string representation of the given macro definition.
\remark \c r must be deleted using #lean_string_del. */
lean_bool lean_macro_def_to_string(lean_macro_def m, char const ** r, lean_exception * ex);
/** \brief Store in \c r a (crude) string representation of the given expression.
\remark \c r must be deleted using #lean_string_del.
\remark To use the nicer pretty printer, we have an API that also takes a lean_environment object as argument. */
lean_bool lean_expr_to_string(lean_expr e, char const ** r, lean_exception * ex);
/** \brief Delete/dispose the given expression. */
void lean_expr_del(lean_expr e);
/** \brief Return the kind of the given expression.
\remark Return LEAN_EXPR_VAR if e is null. */
lean_expr_kind lean_expr_get_kind(lean_expr e);
/** \brief Store \c lean_true in \c r iff the two given expressions are equal. */
lean_bool lean_expr_eq(lean_expr e1, lean_expr e2, lean_bool * r, lean_exception * ex);
/** \brief Store true in \c b if \c e1 is smaller than \c e2 in the internal total order. */
lean_bool lean_expr_lt(lean_expr e1, lean_expr e2, lean_bool * b, lean_exception * ex);
/** \brief Store true in \c b if \c e1 is smaller than \c e2 in the internal total order.
Similar to #lean_expr_lt, but it is more efficient because it first compares
the hashcodes associated with \c e1 and \c e2. */
lean_bool lean_expr_quick_lt(lean_expr e1, lean_expr e2, lean_bool * b, lean_exception * ex);
/** \brief Store in \c i the de-Brujin index of the given variable.
\pre lean_expr_get_kind(e) == LEAN_EXPR_VAR
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_var_idx(lean_expr e, unsigned * i, lean_exception * ex);
/** \brief Stgore in \c u the universe of the given sort.
\pre lean_expr_get_kind(e) == LEAN_EXPR_SORT
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_sort_univ(lean_expr e, lean_univ * u, lean_exception * ex);
/** \brief Store in \c n the name of the given constant.
\pre lean_expr_get_kind(e) == LEAN_EXPR_CONST
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_const_name(lean_expr e, lean_name * n, lean_exception * ex);
/** \brief Store in \c us the universes parameters of the given constant.
\pre lean_expr_get_kind(e) == LEAN_EXPR_CONST
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_const_univs(lean_expr e, lean_list_univ * us, lean_exception * ex);
/** \brief Store in \c f the function of the given function application.
\pre lean_expr_get_kind(e) == LEAN_EXPR_APP
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_app_fun(lean_expr e, lean_expr * f, lean_exception * ex);
/** \brief Store in \c a the argument of the given function application.
\pre lean_expr_get_kind(e) == LEAN_EXPR_APP
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_app_arg(lean_expr e, lean_expr * a, lean_exception * ex);
/** \brief Store in \c n the name the given local constant or meta-variable.
\pre lean_expr_get_kind(e) == LEAN_EXPR_LOCAL || lean_expr_get_kind(e) == LEAN_EXPR_META
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_mlocal_name(lean_expr e, lean_name * n, lean_exception * ex);
/** \brief Store in \c t the type the given local constant or meta-variable.
\pre lean_expr_get_kind(e) == LEAN_EXPR_LOCAL || lean_expr_get_kind(e) == LEAN_EXPR_META
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_mlocal_type(lean_expr e, lean_expr * t, lean_exception * ex);
/** \brief Store in \c n the pretty printing name the given local constant.
\pre lean_expr_get_kind(e) == LEAN_EXPR_LOCAL
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_local_pp_name(lean_expr e, lean_name * n, lean_exception * ex);
/** \brief Store in \c k the binder_kind associated with the given local constant.
\pre lean_expr_get_kind(e) == LEAN_EXPR_LOCAL
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_local_binder_kind(lean_expr e, lean_binder_kind * k, lean_exception * ex);
/** \brief Store in \c n the name associated with the given binding expression (i.e., lambda or Pi).
\pre lean_expr_get_kind(e) == LEAN_EXPR_LAMBDA || lean_expr_get_kind(e) == LEAN_EXPR_PI
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_binding_name(lean_expr e, lean_name * n, lean_exception * ex);
/** \brief Store in \c d the domain of the given binding (i.e., lambda or Pi).
\pre lean_expr_get_kind(e) == LEAN_EXPR_LAMBDA || lean_expr_get_kind(e) == LEAN_EXPR_PI
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_binding_domain(lean_expr e, lean_expr * d, lean_exception * ex);
/** \brief Store in \c b the body of the given binding (i.e., lambda or Pi).
\pre lean_expr_get_kind(e) == LEAN_EXPR_LAMBDA || lean_expr_get_kind(e) == LEAN_EXPR_PI
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_binding_body(lean_expr e, lean_expr * b, lean_exception * ex);
/** \brief Store in \c k the binder_kind of the given binding (i.e., lambda or Pi).
\pre lean_expr_get_kind(e) == LEAN_EXPR_LAMBDA || lean_expr_get_kind(e) == LEAN_EXPR_PI
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_binding_binder_kind(lean_expr e, lean_binder_kind * k, lean_exception * ex);
/** \brief Store in \c d the macro definition of the given macro application.
\pre lean_expr_get_kind(e) == LEAN_EXPR_MACRO
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_macro_def(lean_expr e, lean_macro_def * d, lean_exception * ex);
/** \brief Store in \c as the arguments of the given macro application.
\pre lean_expr_get_kind(e) == LEAN_EXPR_MACRO
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_expr_get_macro_args(lean_expr e, lean_list_expr * as, lean_exception * ex);
/** \brief Create the empty list of exprs */
lean_bool lean_list_expr_mk_nil(lean_list_expr * r, lean_exception * ex);
/** \brief Create the list <tt>h :: t</tt> */
lean_bool lean_list_expr_mk_cons(lean_expr h, lean_list_expr t, lean_list_expr * r, lean_exception * ex);
/** \brief Delete/dispose the given list of exprs */
void lean_list_expr_del(lean_list_expr l);
/** \brief Return true iff the list is a "cons" (i.e., it is not the nil list) */
lean_bool lean_list_expr_is_cons(lean_list_expr l);
/** \brief Return true in \c b iff the two given lists are equal */
lean_bool lean_list_expr_eq(lean_list_expr n1, lean_list_expr n2, lean_bool * b, lean_exception * ex);
/** \brief Store in \c r the head of the given list
\pre lean_list_expr_is_cons(l)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_list_expr_head(lean_list_expr l, lean_expr * r, lean_exception * ex);
/** \brief Store in \c r the tail of the given list
\pre lean_list_expr_is_cons(l)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_list_expr_tail(lean_list_expr l, lean_list_expr * r, lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,76 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_INDUCTIVE_H
#define _LEAN_INDUCTIVE_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Inductive datatypes API
*/
/*@{*/
LEAN_DEFINE_TYPE(lean_inductive_decl);
/** \brief Create a new inductive type with name \c n, level parameters \c ps, \c nparams parameters, type \c t, and constructors (aka introduction rules \c cs)
\remark \c cs must be a list of local constants.
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_inductive_decl_mk(lean_name n, lean_list_name ps, unsigned nparams, lean_expr t, lean_list_expr cs, lean_inductive_decl * r, lean_exception * ex);
/** \brief Dispose/delete the given inductive type */
void lean_inductive_decl_del(lean_inductive_decl t);
/** \brief Return the name of the recursor (aka eliminator) associated with an inductive type name \c n */
lean_bool lean_get_recursor_name(lean_name n, lean_name * r, lean_exception * ex);
/** \brief Store in \c r the name of the given inductive type. */
lean_bool lean_inductive_decl_get_name(lean_inductive_decl t, lean_name * r, lean_exception * ex);
/** \brief Store in \c r the type of the given inductive type. */
lean_bool lean_inductive_decl_get_type(lean_inductive_decl t, lean_expr * r, lean_exception * ex);
/** \brief Store in \c r the list of constructors of the given inductive type. */
lean_bool lean_inductive_decl_get_constructors(lean_inductive_decl t, lean_list_expr * r, lean_exception * ex);
/** \brief Store in \c r the list of universe parameter names of the given inductive declaration. */
lean_bool lean_inductive_decl_get_univ_params(lean_inductive_decl d, lean_list_name * r, lean_exception * ex);
/** \brief Store in \c r the number of parameters of the given inductive declaration. */
lean_bool lean_inductive_decl_get_num_params(lean_inductive_decl d, unsigned * r, lean_exception * ex);
/** \brief Add the inductive declaration \c d to the given environment */
lean_bool lean_env_add_inductive(lean_env env, lean_inductive_decl d, lean_env * r, lean_exception * ex);
/** \brief Return lean_true if \c n is the name of an inductive type in the given environment,
and store the inductive declaration that it is part of in \c r. */
lean_bool lean_env_is_inductive_type(lean_env env, lean_name n, lean_inductive_decl * r, lean_exception * ex);
/** \brief Return lean_true if \c n is the name of a constructor in the given environment, and
store the name of the associated inductive type in \c r. */
lean_bool lean_env_is_constructor(lean_env env, lean_name n, lean_name * r, lean_exception * ex);
/** \brief Return lean_true if \c n is the name of a recursor (aka eliminator) in the given environment, and
store the name of the associated inductive type in \c r. */
lean_bool lean_env_is_recursor(lean_env env, lean_name n, lean_name * r, lean_exception * ex);
/** \brief Return lean_true if \c n is the name of an inductive type in the given environment, and
store the number of indices in \c r. */
lean_bool lean_env_get_inductive_type_num_indices(lean_env env, lean_name n, unsigned * r, lean_exception * ex);
/** \brief Return lean_true if \c n is the name of an inductive type in the given environment, and
store the number of minor premises in \c r. */
lean_bool lean_env_get_inductive_type_num_minor_premises(lean_env env, lean_name n, unsigned * r, lean_exception * ex);
/** \brief Return lean_true if \c n is the name of an inductive type in the given environment, and
store lean_true in \c r if the inductive type supports dependent elimination. */
lean_bool lean_env_get_inductive_type_has_dep_elim(lean_env env, lean_name n, lean_bool * r, lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,76 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_IOS_H
#define _LEAN_IOS_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name IO state API
*/
/*@{*/
LEAN_DEFINE_TYPE(lean_ios);
/** \brief Create IO state object that sends the regular and diagnostic output to standard out and standard error */
lean_bool lean_ios_mk_std(lean_options o, lean_ios * r, lean_exception * ex);
/** \brief Create IO state object that sends the regular and diagnostic output to string buffers. */
lean_bool lean_ios_mk_buffered(lean_options o, lean_ios * r, lean_exception * ex);
/** \brief Delete IO state object. */
void lean_ios_del(lean_ios ios);
/** \brief Return true iff it is standard IO state (i.e., it was created using #lean_ios_mk_std */
lean_bool lean_ios_is_std(lean_ios ios);
/** \brief Update the set of configurations options in the given IO state object */
lean_bool lean_ios_set_options(lean_ios ios, lean_options o, lean_exception * ex);
/** \brief Store in \c r the set of configuration options associated with the given IO state object. */
lean_bool lean_ios_get_options(lean_ios ios, lean_options * r, lean_exception * ex);
/** \brief Store in \c r the content of the regular output stream.
\pre !lean_ios_is_std(ios)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_ios_get_regular(lean_ios ios, char const ** r, lean_exception * ex);
/** \brief Store in \c r the content of the diagnostic output stream.
\pre !lean_ios_is_std(ios)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_ios_get_diagnostic(lean_ios ios, char const ** r, lean_exception * ex);
/** \brief Reset the regular output stream.
\pre !lean_ios_is_std(ios)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_ios_reset_regular(lean_ios ios, lean_exception * ex);
/** \brief Reset the diagnostic output stream.
\pre !lean_ios_is_std(ios)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_ios_reset_diagnostic(lean_ios ios, lean_exception * ex);
/** \brief Store in \c r a pretty printed representation of \c e */
lean_bool lean_expr_to_pp_string(lean_env env, lean_ios ios, lean_expr e, char const ** r, lean_exception * ex);
/** \brief Store in \c r a pretty printed representation of the exception \c e */
lean_bool lean_exception_to_pp_string(lean_env env, lean_ios ios, lean_exception e, char const ** r, lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,26 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_MACROS_H
#define _LEAN_MACROS_H
#ifndef LEAN_API
#ifdef __GNUC__
#define LEAN_API __attribute__ ((visibility ("default")))
#else
#define LEAN_API
#endif
#endif
#ifndef LEAN_DEFINE_TYPE
#define LEAN_DEFINE_TYPE(T) typedef struct _ ## T *T
#endif
#ifndef LEAN_DEFINE_VOID
#define LEAN_DEFINE_VOID(T) typedef void* T
#endif
#endif

View file

@ -1,38 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_MODULE_H
#define _LEAN_MODULE_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Module API
*/
/*@{*/
/** \brief Import the given modules (i.e., pre-compiled .olean files)
\remark exceptions: LEAN_KERNEL_EXCEPTION, LEAN_OTHER_EXCEPTION */
lean_bool lean_env_import(lean_env env, lean_ios ios, lean_list_name modules, lean_env * r, lean_exception * ex);
/** \brief Export to the given file name the declarations added to the environment
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_env_export(lean_env env, char const * fname, lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,96 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_NAME_H
#define _LEAN_NAME_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Hierarchical names API
*/
/*@{*/
LEAN_DEFINE_TYPE(lean_name);
/** \brief Create the anonymous name */
lean_bool lean_name_mk_anonymous(lean_name * r, lean_exception * ex);
/** \brief Create the name <tt>pre.s</tt>
\remark \c r must be disposed using #lean_name_del */
lean_bool lean_name_mk_str(lean_name pre, char const * s, lean_name * r, lean_exception * ex);
/** \brief Create the name <tt>pre.i</tt>.
\pre !lean_name_is_anonymous(pre)
\remark \c r must be disposed using #lean_name_del
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_name_mk_idx(lean_name pre, unsigned i, lean_name * r, lean_exception * ex);
/** \brief Delete/dispose the given hierarchical name */
void lean_name_del(lean_name n);
/** \brief Return lean_true iff \c n is the anonymous */
lean_bool lean_name_is_anonymous(lean_name n);
/** \brief Return lean_true iff \c n is a name of the form <tt>pre.s</tt> where \c s is a string. */
lean_bool lean_name_is_str(lean_name n);
/** \brief Return lean_true iff \c n is a name of the form <tt>pre.i</tt> where \c i is an unsigned integer. */
lean_bool lean_name_is_idx(lean_name n);
/** \brief Return true iff the two given hierarchical names are equal */
lean_bool lean_name_eq(lean_name n1, lean_name n2);
/** \brief Return true if \c n1 is smaller than \c n2 in the internal total order. */
lean_bool lean_name_lt(lean_name n1, lean_name n2);
/** \brief Return true if \c n1 is smaller than \c n2 in the internal total order.
Similar to #lean_name_lt, but it is more efficient because it first compares
the hashcodes associated with \c n1 and \c n2. */
lean_bool lean_name_quick_lt(lean_name n1, lean_name n2);
/** \brief Return the prefix of the given name.
\pre !lean_name_is_anonymous(n)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_name_get_prefix(lean_name n, lean_name * r, lean_exception * ex);
/** \brief Store in \c r the suffix of the given name as a string.
\pre lean_name_is_str(n)
\remark \c r must be disposed using #lean_name_del
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_name_get_str(lean_name n, char const ** r, lean_exception * ex);
/** \brief Store in \c r the suffix of the given name as a unsigned integer.
\pre lean_name_is_idx(n)
\remark \c r must be deleted using #lean_string_del
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_name_get_idx(lean_name n, unsigned * r, lean_exception * ex);
/** \brief Store in \c r a string representation of the given hierarchical name.
\remark \c r must be deleted using #lean_string_del */
lean_bool lean_name_to_string(lean_name n, char const **r, lean_exception * ex);
LEAN_DEFINE_TYPE(lean_list_name);
/** \brief Create the empty list of names */
lean_bool lean_list_name_mk_nil(lean_list_name * r, lean_exception * ex);
/** \brief Create the list <tt>h :: t</tt> */
lean_bool lean_list_name_mk_cons(lean_name h, lean_list_name t, lean_list_name * r, lean_exception * ex);
/** \brief Delete/dispose the given list of names */
void lean_list_name_del(lean_list_name l);
/** \brief Return true iff the list is a "cons" (i.e., it is not the nil list) */
lean_bool lean_list_name_is_cons(lean_list_name l);
/** \brief Return true iff the two given lists are equal */
lean_bool lean_list_name_eq(lean_list_name n1, lean_list_name n2);
/** \brief Store in \c r the head of the given list
\pre lean_list_name_is_cons(l)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_list_name_head(lean_list_name l, lean_name * r, lean_exception * ex);
/** \brief Store in \c r the tail of the given list
\pre lean_list_name_is_cons(l)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_list_name_tail(lean_list_name l, lean_list_name * r, lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,97 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_OPTIONS_H
#define _LEAN_OPTIONS_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Configuration options API
A configuration options is essentially a mapping from names to values.
*/
/*@{*/
LEAN_DEFINE_TYPE(lean_options);
/** \brief Create an empty configuration options object. */
lean_bool lean_options_mk_empty(lean_options * r, lean_exception * ex);
/** \brief r := o[n := v]
\remark \c r must be disposed using #lean_options_del */
lean_bool lean_options_set_bool(lean_options o, lean_name n, lean_bool v, lean_options * r, lean_exception * ex);
/** \brief r := o[n := v]
\remark \c r must be disposed using #lean_options_del */
lean_bool lean_options_set_int(lean_options o, lean_name n, int v, lean_options * r, lean_exception * ex);
/** \brief r := o[n := v]
\remark \c r must be disposed using #lean_options_del */
lean_bool lean_options_set_unsigned(lean_options o, lean_name n, unsigned v, lean_options * r, lean_exception * ex);
/** \brief r := o[n := v]
\remark \c r must be disposed using #lean_options_del */
lean_bool lean_options_set_double(lean_options o, lean_name n, double v, lean_options * r, lean_exception * ex);
/** \brief r := o[n := v]
\remark \c r must be disposed using #lean_options_del */
lean_bool lean_options_set_string(lean_options o, lean_name n, char const * v, lean_options * r, lean_exception * ex);
/** \brief Combine the options o1 and o2 and store the result in \c r.
\remark The assignments in o2 overrides the ones in o1.
\remark \c r must be disposed using #lean_options_del */
lean_bool lean_options_join(lean_options o1, lean_options o2, lean_options * r, lean_exception * ex);
/** \brief Delete/dispose the given options object. */
void lean_options_del(lean_options o);
/** \brief Store in \c r a string representation of the given options object.
\remark \c r must be deleted using #lean_string_del
*/
lean_bool lean_options_to_string(lean_options o, char const ** r, lean_exception * ex);
/** \brief Return true iff the two given options object are equal. */
lean_bool lean_options_eq(lean_options o1, lean_options o2);
/** \brief Return true iff the given options object is empty. */
lean_bool lean_options_empty(lean_options o);
/** \brief Return true iff the given options object contains the entry \c n. */
lean_bool lean_options_contains(lean_options o, lean_name n);
/** \brief Store in \c r the value assigned to \c n in the options \c o.
\pre lean_options_contains(o, n)
\remark If the value associated with \c n is not a Boolean, the result is lean_false
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_options_get_bool(lean_options o, lean_name n, lean_bool * r, lean_exception * ex);
/** \brief Store in \c r the value assigned to \c n in the options \c o.
\pre lean_options_contains(o, n)
\remark If the value associated with \c n is not a numeric value, the result is 0
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_options_get_int(lean_options o, lean_name n, int * r, lean_exception * ex);
/** \brief Store in \c r the value assigned to \c n in the options \c o.
\pre lean_options_contains(o, n)
\remark If the value associated with \c n is not a numeric value, the result is 0
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_options_get_unsigned(lean_options o, lean_name n, unsigned * r, lean_exception * ex);
/** \brief Store in \c r the value assigned to \c n in the options \c o.
\pre lean_options_contains(o, n)
\remark If the value associated with \c n is not a double, the result is 0.0
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_options_get_double(lean_options o, lean_name n, double * r, lean_exception * ex);
/** \brief Store in \c r the value assigned to \c n in the options \c o.
\pre lean_options_contains(o, n)
\remark If the value associated with \c n is not a double, the result is the empty string ""
\remark \c r must be deleted using #lean_string_del.
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_options_get_string(lean_options o, lean_name n, char const ** r, lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,47 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_PARSER_H
#define _LEAN_PARSER_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Parser API
*/
/*@{*/
/** \brief Parse the file \c fname using \c env and \c ios.
Store the updated environment and ios at \c new_env and \c new_ios.
\remark We return a new ios object because Lean has commands for updating configuration options.
\remark exceptions: LEAN_KERNEL_EXCEPTION, LEAN_PARSER_EXCEPTION, LEAN_UNIFIER_EXCEPTION, LEAN_TACTIC_EXCEPTION, LEAN_OTHER_EXCEPTION */
lean_bool lean_parse_file(lean_env env, lean_ios ios, char const * fname, lean_env * new_env, lean_ios * new_ios, lean_exception * ex);
/** \brief Parse the commands in the string \c str using \c env and \c ios.
Store the updated environment and ios at \c new_env and \c new_ios.
\remark We return a new ios object because Lean has commands for updating configuration options.
\remark exceptions: LEAN_KERNEL_EXCEPTION, LEAN_PARSER_EXCEPTION, LEAN_UNIFIER_EXCEPTION, LEAN_TACTIC_EXCEPTION, LEAN_OTHER_EXCEPTION */
lean_bool lean_parse_commands(lean_env env, lean_ios ios, char const * str, lean_env * new_env, lean_ios * new_ios, lean_exception * ex);
/** \brief Parse (and elaborate) the expression in the string \c str using \c env and \c ios.
Store the elaborated expression in \c new_expr, and automatically generated universe parameters in \c new_ps.
\remark exceptions: LEAN_KERNEL_EXCEPTION, LEAN_PARSER_EXCEPTION, LEAN_UNIFIER_EXCEPTION, LEAN_TACTIC_EXCEPTION, LEAN_OTHER_EXCEPTION */
lean_bool lean_parse_expr(lean_env env, lean_ios ios, char const * str, lean_expr * new_expr, lean_list_name * new_ps, lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,19 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_STRING_H
#define _LEAN_STRING_H
#ifdef __cplusplus
extern "C" {
#endif
/** \brief Delete a string allocated by Lean */
void lean_string_del(char const * s);
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,58 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_TYPE_CHECKER_H
#define _LEAN_TYPE_CHECKER_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Type checker API
*/
/*@{*/
LEAN_DEFINE_TYPE(lean_type_checker);
/** \brief Create a type checker object for the given environment. */
lean_bool lean_type_checker_mk(lean_env e, lean_type_checker * r, lean_exception * ex);
/** \brief Dispose/delete the given type checker */
void lean_type_checker_del(lean_type_checker t);
/** \brief Infer the type of \c e using \c t. Store the result in \c r.
\remark \c e must not contain any subterm v s.t. lean_expr_get_kind(v) == LEAN_EXPR_VAR
\remark exceptions: LEAN_KERNEL_EXCEPTION */
lean_bool lean_type_checker_infer(lean_type_checker t, lean_expr e, lean_expr * r, lean_exception * ex);
/** \brief Type check and infer the type of \c e using \c t. Store the result in \c r.
\remark \c e must not contain any subterm v s.t. lean_expr_get_kind(v) == LEAN_EXPR_VAR
\remark exceptions: LEAN_KERNEL_EXCEPTION */
lean_bool lean_type_checker_check(lean_type_checker t, lean_expr e, lean_expr * r, lean_exception * ex);
/** \brief Compute the weak-head-normal-form of \c e using \c t. Store the result in \c r.
\remark \c e must not contain any subterm v s.t. lean_expr_get_kind(v) == LEAN_EXPR_VAR
\remark exceptions: LEAN_KERNEL_EXCEPTION */
lean_bool lean_type_checker_whnf(lean_type_checker t, lean_expr e, lean_expr * r, lean_exception * ex);
/** \brief Store true in \c r iff \c e1 and \c e2 are definitionally equal.
\remark \c e must not contain any subterm v s.t. lean_expr_get_kind(v) == LEAN_EXPR_VAR
\remark exceptions: LEAN_KERNEL_EXCEPTION */
lean_bool lean_type_checker_is_def_eq(lean_type_checker t, lean_expr e1, lean_expr e2, lean_bool * r, lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,126 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#ifndef _LEAN_UNIV_H
#define _LEAN_UNIV_H
#ifdef __cplusplus
extern "C" {
#endif
/**
\defgroup capi C API
*/
/*@{*/
/**
@name Universe API
*/
/*@{*/
LEAN_DEFINE_TYPE(lean_univ);
typedef enum {
LEAN_UNIV_ZERO,
LEAN_UNIV_SUCC,
LEAN_UNIV_MAX,
LEAN_UNIV_IMAX,
LEAN_UNIV_PARAM,
LEAN_UNIV_META
} lean_univ_kind;
/** \brief Create the base universe zero */
lean_bool lean_univ_mk_zero(lean_univ * r, lean_exception * ex);
/** \brief Create the successor universe */
lean_bool lean_univ_mk_succ(lean_univ u, lean_univ * r, lean_exception * ex);
/** \brief r := max(u1, u2) */
lean_bool lean_univ_mk_max(lean_univ u1, lean_univ u2, lean_univ * r, lean_exception * ex);
/** \brief r := imax(u1, u2) */
lean_bool lean_univ_mk_imax(lean_univ u1, lean_univ u2, lean_univ * r, lean_exception * ex);
/** \brief Create a universe parameter with the given name. */
lean_bool lean_univ_mk_param(lean_name n, lean_univ * r, lean_exception * ex);
/** \brief Create a universe meta-variable with the given name. */
lean_bool lean_univ_mk_meta(lean_name n, lean_univ * r, lean_exception * ex);
/** \brief Store in \c r a string representation of the given universe object.
\remark \c r must be deleted using #lean_string_del */
lean_bool lean_univ_to_string(lean_univ u, char const ** r, lean_exception * ex);
/** \brief Similar to \c lean_univ_to_string, but uses pretty printing options in \c o,
when converting objection into a string. */
lean_bool lean_univ_to_string_using(lean_univ u, lean_options o, char const ** r, lean_exception * ex);
/** \brief Delete/dispose the given universe object. */
void lean_univ_del(lean_univ u);
/** \brief Return the kind of the given universe.
\remark Return LEAN_UNIV_ZERO if u is null. */
lean_univ_kind lean_univ_get_kind(lean_univ u);
/** \brief Store \c lean_true in \c r iff the two given universe object are equal. */
lean_bool lean_univ_eq(lean_univ u1, lean_univ u2, lean_bool * r, lean_exception * ex);
/** \brief Store true in \c b if \c u1 is smaller than \c u2 in the internal total order. */
lean_bool lean_univ_lt(lean_univ u1, lean_univ u2, lean_bool * b, lean_exception * ex);
/** \brief Store true in \c b if \c u1 is smaller than \c u2 in the internal total order.
Similar to #lean_univ_lt, but it is more efficient because it first compares
the hashcodes associated with \c u1 and \c u2. */
lean_bool lean_univ_quick_lt(lean_univ u1, lean_univ u2, lean_bool * b, lean_exception * ex);
/** \brief If \c r contains \c lean_true, then forall assignments \c A that assigns all parameters,
and metavariables occuring in \c u1 and \c u2, we have that the
universe level u1[A] is bigger or equal to u2[A]. */
lean_bool lean_univ_geq(lean_univ u1, lean_univ u2, lean_bool * r, lean_exception * ex);
/** \brief Store the predecessor universe of \c u in \c r.
\pre lean_univ_get_kind(u) == LEAN_UNIV_SUCC
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_univ_get_pred(lean_univ u, lean_univ * r, lean_exception * ex);
/** \brief Store the left-hand-side of the max/imax universe \c u in \c r.
\pre lean_univ_get_kind(u) == LEAN_UNIV_MAX || lean_univ_get_kind(u) == LEAN_UNIV_IMAX
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_univ_get_max_lhs(lean_univ u, lean_univ * r, lean_exception * ex);
/** \brief Store the right-hand-side of the max/imax universe \c u in \c r.
\pre lean_univ_get_kind(u) == LEAN_UNIV_MAX || lean_univ_get_kind(u) == LEAN_UNIV_IMAX
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_univ_get_max_rhs(lean_univ u, lean_univ * r, lean_exception * ex);
/** \brief Store the name of the given universe in \c r.
\pre lean_univ_get_kind(u) == LEAN_UNIV_PARAM ||
lean_univ_get_kind(u) == LEAN_UNIV_META
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_univ_get_name(lean_univ u, lean_name * r, lean_exception * ex);
/** \brief Store in \c r the normal for of the given universe */
lean_bool lean_univ_normalize(lean_univ u, lean_univ * r, lean_exception * ex);
LEAN_DEFINE_TYPE(lean_list_univ);
/** \brief Create the empty list of univs */
lean_bool lean_list_univ_mk_nil(lean_list_univ * r, lean_exception * ex);
/** \brief Create the list <tt>h :: t</tt> */
lean_bool lean_list_univ_mk_cons(lean_univ h, lean_list_univ t, lean_list_univ * r, lean_exception * ex);
/** \brief Delete/dispose the given list of univs */
void lean_list_univ_del(lean_list_univ l);
/** \brief Return true iff the list is a "cons" (i.e., it is not the nil list) */
lean_bool lean_list_univ_is_cons(lean_list_univ l);
/** \brief Store true in \c b iff the two given lists are equal */
lean_bool lean_list_univ_eq(lean_list_univ n1, lean_list_univ n2, lean_bool * b, lean_exception * ex);
/** \brief Store in \c r the head of the given list
\pre lean_list_univ_is_cons(l)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_list_univ_head(lean_list_univ l, lean_univ * r, lean_exception * ex);
/** \brief Store in \c r the tail of the given list
\pre lean_list_univ_is_cons(l)
\remark exceptions: LEAN_OTHER_EXCEPTION */
lean_bool lean_list_univ_tail(lean_list_univ l, lean_list_univ * r, lean_exception * ex);
/** \brief Instantiate the universe parameters names in <tt>ns</tt> with <tt>us</tt> in \c u,
and store the result in \c r.
\remark The given lists must have the same length. */
lean_bool lean_univ_instantiate(lean_univ u, lean_list_name ns, lean_list_univ us, lean_univ * r, lean_exception * ex);
/*@}*/
/*@}*/
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,42 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <string>
#include <vector>
#include "util/lean_path.h"
#include "library/module.h"
#include "library/util.h"
#include "api/decl.h"
#include "api/string.h"
#include "api/exception.h"
#include "api/ios.h"
#include "api/lean_env.h"
#include "api/lean_module.h"
using namespace lean; // NOLINT
lean_bool lean_env_import(lean_env env, lean_ios ios, lean_list_name modules, lean_env * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(ios);
check_nonnull(modules);
auto new_env = to_env_ref(env);
std::vector<module_name> imports;
for (name const & n : to_list_name_ref(modules)) {
module_name m(n);
imports.push_back(m);
}
new_env = import_modules(new_env, "", imports, mk_olean_loader(standard_search_path().get_path()));
*r = of_env(new environment(new_env));
LEAN_CATCH;
}
lean_bool lean_env_export(lean_env env, char const * fname, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
auto lm = export_module(to_env_ref(env), fname);
std::ofstream out(fname, std::ofstream::binary);
write_module(lm, out);
LEAN_CATCH;
}

View file

@ -1,153 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "api/name.h"
#include "api/string.h"
#include "api/exception.h"
namespace lean {
void to_buffer(unsigned sz, lean_name const * ns, buffer<name> & r) {
check_nonnull(ns);
for (unsigned i = 0; i < sz; i++) {
check_nonnull(ns[i]);
r.push_back(to_name_ref(ns[i]));
}
}
}
using namespace lean; // NOLINT
lean_bool lean_name_mk_anonymous(lean_name * r, lean_exception * ex) {
LEAN_TRY;
*r = of_name(new name());
LEAN_CATCH;
}
lean_bool lean_name_mk_str(lean_name pre, char const * s, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(pre);
check_nonnull(s);
*r = of_name(new name(to_name_ref(pre), s));
LEAN_CATCH;
}
lean_bool lean_name_mk_idx(lean_name pre, unsigned i, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(pre);
name const & p = to_name_ref(pre);
if (p.is_anonymous())
throw lean::exception("invalid argument, prefix is an anonymous name");
*r = of_name(new name(to_name_ref(pre), i));
LEAN_CATCH;
}
void lean_name_del(lean_name n) {
delete to_name(n);
}
lean_bool lean_name_is_anonymous(lean_name n) {
return n && to_name_ref(n).is_anonymous();
}
lean_bool lean_name_is_str(lean_name n) {
return n && to_name_ref(n).is_string();
}
lean_bool lean_name_is_idx(lean_name n) {
return n && to_name_ref(n).is_numeral();
}
lean_bool lean_name_eq(lean_name n1, lean_name n2) {
return n1 && n2 && to_name_ref(n1) == to_name_ref(n2);
}
lean_bool lean_name_lt(lean_name n1, lean_name n2) {
return n1 && n2 && cmp(to_name_ref(n1), to_name_ref(n2)) < 0;
}
lean_bool lean_name_quick_lt(lean_name n1, lean_name n2) {
return n1 && n2 && quick_cmp(to_name_ref(n1), to_name_ref(n2)) < 0;
}
lean_bool lean_name_get_prefix(lean_name n, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
if (to_name_ref(n).is_anonymous())
throw lean::exception("invalid argument, argument is an anonymous name");
else if (to_name_ref(n).is_atomic())
*r = of_name(new name());
else
*r = of_name(new name(to_name_ref(n).get_prefix()));
LEAN_CATCH;
}
lean_bool lean_name_get_str(lean_name n, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
if (!lean_name_is_str(n))
throw lean::exception("invalid argument, it is not a string name");
*r = mk_string(to_name_ref(n).get_string());
LEAN_CATCH;
}
lean_bool lean_name_get_idx(lean_name n, unsigned * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
if (!lean_name_is_idx(n))
throw lean::exception("invalid argument, it is not an indexed name");
*r = to_name_ref(n).get_numeral();
LEAN_CATCH;
}
lean_bool lean_name_to_string(lean_name n, char const **r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
*r = mk_string(to_name_ref(n).to_string());
LEAN_CATCH;
}
lean_bool lean_list_name_mk_nil(lean_list_name * r, lean_exception * ex) {
LEAN_TRY;
*r = of_list_name(new list<name>());
LEAN_CATCH;
}
lean_bool lean_list_name_mk_cons(lean_name h, lean_list_name t, lean_list_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(h);
check_nonnull(t);
*r = of_list_name(new list<name>(to_name_ref(h), to_list_name_ref(t)));
LEAN_CATCH;
}
void lean_list_name_del(lean_list_name l) {
delete to_list_name(l);
}
lean_bool lean_list_name_is_cons(lean_list_name l) {
return l && !is_nil(to_list_name_ref(l));
}
lean_bool lean_list_name_eq(lean_list_name l1, lean_list_name l2) {
return l1 && l2 && to_list_name_ref(l1) == to_list_name_ref(l2);
}
lean_bool lean_list_name_head(lean_list_name l, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(l);
if (!lean_list_name_is_cons(l))
throw lean::exception("invalid argument, non-nil list expected");
*r = of_name(new name(head(to_list_name_ref(l))));
LEAN_CATCH;
}
lean_bool lean_list_name_tail(lean_list_name l, lean_list_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(l);
if (!lean_list_name_is_cons(l))
throw lean::exception("invalid argument, non-nil list expected");
*r = of_list_name(new list<name>(tail(to_list_name_ref(l))));
LEAN_CATCH;
}

View file

@ -1,20 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "util/name.h"
#include "api/exception.h"
#include "api/lean_name.h"
namespace lean {
inline name * to_name(lean_name n) { return reinterpret_cast<name *>(n); }
inline name const & to_name_ref(lean_name n) { return *reinterpret_cast<name *>(n); }
inline lean_name of_name(name * n) { return reinterpret_cast<lean_name>(n); }
void to_buffer(unsigned sz, lean_name const * ns, buffer<name> & r);
inline list<name> * to_list_name(lean_list_name n) { return reinterpret_cast<list<name> *>(n); }
inline list<name> const & to_list_name_ref(lean_list_name n) { return *reinterpret_cast<list<name> *>(n); }
inline lean_list_name of_list_name(list<name> * n) { return reinterpret_cast<lean_list_name>(n); }
}

View file

@ -1,134 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <string>
#include "util/sstream.h"
#include "api/name.h"
#include "api/string.h"
#include "api/options.h"
using namespace lean; // NOLINT
lean_bool lean_options_mk_empty(lean_options * r, lean_exception * ex) {
LEAN_TRY;
*r = of_options(new options());
LEAN_CATCH;
}
lean_bool lean_options_set_bool(lean_options o, lean_name n, lean_bool v, lean_options * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(o);
check_nonnull(n);
*r = of_options(new options(to_options_ref(o).update(to_name_ref(n), static_cast<bool>(v))));
LEAN_CATCH;
}
lean_bool lean_options_set_int(lean_options o, lean_name n, int v, lean_options * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(o);
check_nonnull(n);
*r = of_options(new options(to_options_ref(o).update(to_name_ref(n), v)));
LEAN_CATCH;
}
lean_bool lean_options_set_unsigned(lean_options o, lean_name n, unsigned v, lean_options * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(o);
check_nonnull(n);
*r = of_options(new options(to_options_ref(o).update(to_name_ref(n), v)));
LEAN_CATCH;
}
lean_bool lean_options_set_double(lean_options o, lean_name n, double v, lean_options * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(o);
check_nonnull(n);
*r = of_options(new options(to_options_ref(o).update(to_name_ref(n), v)));
LEAN_CATCH;
}
lean_bool lean_options_set_string(lean_options o, lean_name n, char const * v, lean_options * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(o);
check_nonnull(n);
check_nonnull(v);
*r = of_options(new options(to_options_ref(o).update(to_name_ref(n), std::string(v).c_str())));
LEAN_CATCH;
}
lean_bool lean_options_join(lean_options o1, lean_options o2, lean_options * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(o1);
check_nonnull(o2);
*r = of_options(new options(join(to_options_ref(o1), to_options_ref(o2))));
LEAN_CATCH;
}
void lean_options_del(lean_options o) {
delete to_options(o);
}
lean_bool lean_options_to_string(lean_options o, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(o);
std::ostringstream out;
out << to_options_ref(o);
*r = mk_string(out.str());
LEAN_CATCH;
}
lean_bool lean_options_eq(lean_options o1, lean_options o2) {
return o1 && o2 && to_options_ref(o1) == to_options_ref(o2);
}
lean_bool lean_options_empty(lean_options o) {
return o && to_options_ref(o).empty();
}
lean_bool lean_options_contains(lean_options o, lean_name n) {
return o && n && to_options_ref(o).contains(to_name_ref(n));
}
static void check_entry(lean_options o, lean_name n) {
check_nonnull(o);
check_nonnull(n);
if (!lean_options_contains(o, n))
throw exception(sstream() << "options object does not contain entry '" << to_name_ref(n) << "'");
}
lean_bool lean_options_get_bool(lean_options o, lean_name n, lean_bool * r, lean_exception * ex) {
LEAN_TRY;
check_entry(o, n);
*r = to_options_ref(o).get_bool(to_name_ref(n), false);
LEAN_CATCH;
}
lean_bool lean_options_get_int(lean_options o, lean_name n, int * r, lean_exception * ex) {
LEAN_TRY;
check_entry(o, n);
*r = to_options_ref(o).get_int(to_name_ref(n), 0);
LEAN_CATCH;
}
lean_bool lean_options_get_unsigned(lean_options o, lean_name n, unsigned * r, lean_exception * ex) {
LEAN_TRY;
check_entry(o, n);
*r = to_options_ref(o).get_unsigned(to_name_ref(n), 0);
LEAN_CATCH;
}
lean_bool lean_options_get_double(lean_options o, lean_name n, double * r, lean_exception * ex) {
LEAN_TRY;
check_entry(o, n);
*r = to_options_ref(o).get_double(to_name_ref(n), 0.0);
LEAN_CATCH;
}
lean_bool lean_options_get_string(lean_options o, lean_name n, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_entry(o, n);
*r = mk_string(to_options_ref(o).get_string(to_name_ref(n), ""));
LEAN_CATCH;
}

View file

@ -1,16 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "util/sexpr/options.h"
#include "api/exception.h"
#include "api/name.h"
#include "api/lean_options.h"
namespace lean {
inline options * to_options(lean_options n) { return reinterpret_cast<options *>(n); }
inline options const & to_options_ref(lean_options n) { return *reinterpret_cast<options *>(n); }
inline lean_options of_options(options * n) { return reinterpret_cast<lean_options>(n); }
}

View file

@ -1,65 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <string>
#include "frontends/lean/module_parser.h"
#include "frontends/lean/parser.h"
#include "api/string.h"
#include "api/exception.h"
#include "api/decl.h"
#include "api/ios.h"
#include "api/lean_parser.h"
using namespace lean; // NOLINT
lean_bool lean_parse_file(lean_env env, lean_ios ios, char const * fname, lean_env * new_env, lean_ios * new_ios, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(ios);
check_nonnull(fname);
environment _env = to_env_ref(env);
io_state _ios = to_io_state_ref(ios);
parse_commands(_env, _ios, fname);
*new_env = of_env(new environment(_env));
*new_ios = of_io_state(new io_state(_ios));
LEAN_CATCH;
}
lean_bool lean_parse_commands(lean_env env, lean_ios ios, char const * str, lean_env * new_env, lean_ios * new_ios, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(ios);
check_nonnull(str);
char const * strname = "[string]";
environment _env = to_env_ref(env);
io_state _ios = to_io_state_ref(ios);
// bool use_exceptions = true; TODO(gabriel)
auto p = std::make_shared<module_parser>(strname, str, _env, mk_dummy_loader());
p->use_separate_tasks(false);
auto res = p->parse({});
while (res.m_next) res = get(res.m_next);
*new_env = of_env(new environment(res.m_snapshot_at_end->m_env));
*new_ios = of_io_state(new io_state(_ios, res.m_snapshot_at_end->m_options));
LEAN_CATCH;
}
lean_bool lean_parse_expr(lean_env env, lean_ios ios, char const * str, lean_expr * new_expr, lean_list_name * new_ps, lean_exception * ex) {
LEAN_TRY;
check_nonnull(env);
check_nonnull(ios);
check_nonnull(str);
std::istringstream in(str);
char const * strname = "[string]";
environment _env = to_env_ref(env);
io_state _ios = to_io_state_ref(ios);
bool use_exceptions = true;
parser p(_env, _ios, mk_dummy_loader(), in, strname, use_exceptions);
expr e = p.parse_expr();
expr _e; level_param_names _ps;
std::tie(_e, _ps) = p.elaborate(strname, list<expr>(), e);
*new_expr = of_expr(new expr(_e));
*new_ps = of_list_name(new list<name>(_ps));
LEAN_CATCH;
}

View file

@ -1,37 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <string>
#include <string.h> // NOLINT
#include "api/lean_string.h"
#include "api/string.h"
namespace lean {
char const * mk_string(std::string const & s) {
char * r = new char[s.size() + 1];
for (unsigned i = 0; i < s.size(); i++)
r[i] = s[i];
r[s.size()] = 0;
return r;
}
char const * mk_string(char const * s) {
unsigned sz = strlen(s);
char * r = new char[sz + 1];
for (unsigned i = 0; i < sz; i++)
r[i] = s[i];
r[sz] = 0;
return r;
}
void del_string(char const * s) {
delete[] s;
}
}
void lean_string_del(char const * s) {
lean::del_string(s);
}

View file

@ -1,13 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include <string>
namespace lean {
char const * mk_string(std::string const &);
char const * mk_string(char const *);
void del_string(char const *);
}

View file

@ -1,54 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "api/string.h"
#include "api/exception.h"
#include "api/type_checker.h"
using namespace lean; // NOLINT
lean_bool lean_type_checker_mk(lean_env e, lean_type_checker * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(e);
*r = of_type_checker(new type_checker(to_env_ref(e)));
LEAN_CATCH;
}
void lean_type_checker_del(lean_type_checker t) {
delete to_type_checker(t);
}
lean_bool lean_type_checker_infer(lean_type_checker t, lean_expr e, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(t);
check_nonnull(e);
*r = of_expr(new expr(to_type_checker_ref(t).infer(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_type_checker_check(lean_type_checker t, lean_expr e, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(t);
check_nonnull(e);
*r = of_expr(new expr(to_type_checker_ref(t).check(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_type_checker_whnf(lean_type_checker t, lean_expr e, lean_expr * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(t);
check_nonnull(e);
*r = of_expr(new expr(to_type_checker_ref(t).whnf(to_expr_ref(e))));
LEAN_CATCH;
}
lean_bool lean_type_checker_is_def_eq(lean_type_checker t, lean_expr e1, lean_expr e2, lean_bool * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(t);
check_nonnull(e1);
check_nonnull(e2);
*r = to_type_checker_ref(t).is_def_eq(to_expr_ref(e1), to_expr_ref(e2));
LEAN_CATCH;
}

View file

@ -1,17 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "kernel/declaration.h"
#include "kernel/type_checker.h"
#include "api/expr.h"
#include "api/decl.h"
#include "api/lean_type_checker.h"
namespace lean {
inline type_checker * to_type_checker(lean_type_checker n) { return reinterpret_cast<type_checker *>(n); }
inline type_checker & to_type_checker_ref(lean_type_checker n) { return *reinterpret_cast<type_checker *>(n); }
inline lean_type_checker of_type_checker(type_checker * n) { return reinterpret_cast<lean_type_checker>(n); }
}

View file

@ -1,249 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <string>
#include "util/sstream.h"
#include "api/name.h"
#include "api/string.h"
#include "api/univ.h"
#include "api/lean_univ.h"
namespace lean {
void to_buffer(unsigned sz, lean_univ const * us, buffer<level> & r) {
check_nonnull(us);
for (unsigned i = 0; i < sz; i++) {
check_nonnull(us[i]);
r.push_back(to_level_ref(us[i]));
}
}
}
using namespace lean; // NOLINT
lean_bool lean_univ_mk_zero(lean_univ * r, lean_exception * ex) {
LEAN_TRY;
*r = of_level(new level());
LEAN_CATCH;
}
lean_bool lean_univ_mk_succ(lean_univ u, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
*r = of_level(new level(mk_succ(to_level_ref(u))));
LEAN_CATCH;
}
lean_bool lean_univ_mk_max(lean_univ u1, lean_univ u2, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u1);
check_nonnull(u2);
*r = of_level(new level(mk_max(to_level_ref(u1), to_level_ref(u2))));
LEAN_CATCH;
}
lean_bool lean_univ_mk_imax(lean_univ u1, lean_univ u2, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u1);
check_nonnull(u2);
*r = of_level(new level(mk_imax(to_level_ref(u1), to_level_ref(u2))));
LEAN_CATCH;
}
lean_bool lean_univ_mk_param(lean_name n, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
*r = of_level(new level(mk_param_univ(to_name_ref(n))));
LEAN_CATCH;
}
lean_bool lean_univ_mk_meta(lean_name n, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(n);
*r = of_level(new level(mk_meta_univ(to_name_ref(n))));
LEAN_CATCH;
}
lean_bool lean_univ_to_string(lean_univ u, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
std::ostringstream out;
out << pp(to_level_ref(u));
*r = mk_string(out.str());
LEAN_CATCH;
}
lean_bool lean_univ_to_string_using(lean_univ u, lean_options o, char const ** r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
check_nonnull(o);
std::ostringstream out;
out << mk_pair(pp(to_level_ref(u), to_options_ref(o)), to_options_ref(o));
*r = mk_string(out.str());
LEAN_CATCH;
}
void lean_univ_del(lean_univ u) {
delete to_level(u);
}
lean_univ_kind lean_univ_get_kind(lean_univ u) {
if (!u)
return LEAN_UNIV_ZERO;
switch (to_level_ref(u).kind()) {
case level_kind::Zero: return LEAN_UNIV_ZERO;
case level_kind::Succ: return LEAN_UNIV_SUCC;
case level_kind::Max: return LEAN_UNIV_MAX;
case level_kind::IMax: return LEAN_UNIV_IMAX;
case level_kind::Param: return LEAN_UNIV_PARAM;
case level_kind::Meta: return LEAN_UNIV_META;
}
lean_unreachable();
}
lean_bool lean_univ_eq(lean_univ u1, lean_univ u2, lean_bool * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u1);
check_nonnull(u2);
*r = to_level_ref(u1) == to_level_ref(u2);
LEAN_CATCH;
}
lean_bool lean_univ_lt(lean_univ u1, lean_univ u2, lean_bool * b, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u1);
check_nonnull(u2);
*b = is_lt(to_level_ref(u1), to_level_ref(u2), false);
LEAN_CATCH;
}
lean_bool lean_univ_quick_lt(lean_univ u1, lean_univ u2, lean_bool * b, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u1);
check_nonnull(u2);
*b = is_lt(to_level_ref(u1), to_level_ref(u2), true);
LEAN_CATCH;
}
lean_bool lean_univ_geq(lean_univ u1, lean_univ u2, lean_bool * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u1);
check_nonnull(u2);
*r = is_geq(to_level_ref(u1), to_level_ref(u2));
LEAN_CATCH;
}
lean_bool lean_univ_get_pred(lean_univ u, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
if (lean_univ_get_kind(u) != LEAN_UNIV_SUCC)
throw exception("invalid argument, argument is not a successor universe");
*r = of_level(new level(succ_of(to_level_ref(u))));
LEAN_CATCH;
}
lean_bool lean_univ_get_max_lhs(lean_univ u, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
if (lean_univ_get_kind(u) == LEAN_UNIV_MAX)
*r = of_level(new level(max_lhs(to_level_ref(u))));
else if (lean_univ_get_kind(u) == LEAN_UNIV_IMAX)
*r = of_level(new level(imax_lhs(to_level_ref(u))));
else
throw exception("invalid argument, argument is not a max/imax universe");
LEAN_CATCH;
}
lean_bool lean_univ_get_max_rhs(lean_univ u, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
if (lean_univ_get_kind(u) == LEAN_UNIV_MAX)
*r = of_level(new level(max_rhs(to_level_ref(u))));
else if (lean_univ_get_kind(u) == LEAN_UNIV_IMAX)
*r = of_level(new level(imax_rhs(to_level_ref(u))));
else
throw exception("invalid argument, argument is not a max/imax universe");
LEAN_CATCH;
}
lean_bool lean_univ_get_name(lean_univ u, lean_name * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
if (lean_univ_get_kind(u) == LEAN_UNIV_PARAM)
*r = of_name(new name(param_id(to_level_ref(u))));
else if (lean_univ_get_kind(u) == LEAN_UNIV_META)
*r = of_name(new name(meta_id(to_level_ref(u))));
else
throw exception("invalid argument, argument is not a parameter/global/meta universe");
LEAN_CATCH;
}
lean_bool lean_univ_normalize(lean_univ u, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
*r = of_level(new level(normalize(to_level_ref(u))));
LEAN_CATCH;
}
lean_bool lean_list_univ_mk_nil(lean_list_univ * r, lean_exception * ex) {
LEAN_TRY;
*r = of_list_level(new list<level>());
LEAN_CATCH;
}
lean_bool lean_list_univ_mk_cons(lean_univ h, lean_list_univ t, lean_list_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(h);
check_nonnull(t);
*r = of_list_level(new list<level>(to_level_ref(h), to_list_level_ref(t)));
LEAN_CATCH;
}
void lean_list_univ_del(lean_list_univ l) {
delete to_list_level(l);
}
lean_bool lean_list_univ_is_cons(lean_list_univ l) {
return l && !is_nil(to_list_level_ref(l));
}
lean_bool lean_list_univ_eq(lean_list_univ l1, lean_list_univ l2, lean_bool * b, lean_exception * ex) {
LEAN_TRY;
check_nonnull(l1);
check_nonnull(l2);
*b = to_list_level_ref(l1) == to_list_level_ref(l2);
LEAN_CATCH;
}
lean_bool lean_list_univ_head(lean_list_univ l, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(l);
if (!lean_list_univ_is_cons(l))
throw lean::exception("invalid argument, non-nil list expected");
*r = of_level(new level(head(to_list_level_ref(l))));
LEAN_CATCH;
}
lean_bool lean_list_univ_tail(lean_list_univ l, lean_list_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(l);
if (!lean_list_univ_is_cons(l))
throw lean::exception("invalid argument, non-nil list expected");
*r = of_list_level(new list<level>(tail(to_list_level_ref(l))));
LEAN_CATCH;
}
/** \brief Instantiate the universe parameters names <tt>ns[i]</tt> with <tt>us[i]</tt> in \c u,
and store the result in \c r.
\remark \c ns and \c us are arrays of names and universes, and both have size \c sz.
*/
lean_bool lean_univ_instantiate(lean_univ u, lean_list_name ns, lean_list_univ us, lean_univ * r, lean_exception * ex) {
LEAN_TRY;
check_nonnull(u);
check_nonnull(ns);
check_nonnull(us);
if (length(to_list_name_ref(ns)) != length(to_list_level_ref(us)))
throw lean::exception("invalid arguments, the given lists must have the same length");
*r = of_level(new level(instantiate(to_level_ref(u), to_list_name_ref(ns), to_list_level_ref(us))));
LEAN_CATCH;
}

View file

@ -1,22 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "util/name.h"
#include "kernel/level.h"
#include "api/exception.h"
#include "api/options.h"
#include "api/lean_univ.h"
namespace lean {
inline level * to_level(lean_univ n) { return reinterpret_cast<level *>(n); }
inline level const & to_level_ref(lean_univ n) { return *reinterpret_cast<level *>(n); }
inline lean_univ of_level(level * n) { return reinterpret_cast<lean_univ>(n); }
void to_buffer(unsigned sz, lean_univ const * us, buffer<level> & r);
inline list<level> * to_list_level(lean_list_univ n) { return reinterpret_cast<list<level> *>(n); }
inline list<level> const & to_list_level_ref(lean_list_univ n) { return *reinterpret_cast<list<level> *>(n); }
inline lean_list_univ of_list_level(list<level> * n) { return reinterpret_cast<lean_list_univ>(n); }
}

View file

@ -1,45 +0,0 @@
add_executable(shared_test shared.cpp)
target_link_libraries(shared_test ${EXTRA_LIBS} leanshared)
add_test(NAME shared_test
WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/shared_test")
add_executable(c_name_test name.c)
target_link_libraries(c_name_test ${EXTRA_LIBS} leanshared)
add_test(NAME c_name_test
WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/c_name_test")
add_executable(c_options_test options.c)
target_link_libraries(c_options_test ${EXTRA_LIBS} leanshared)
add_test(NAME c_options_test
WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/c_options_test")
add_executable(c_univ_test univ.c)
target_link_libraries(c_univ_test ${EXTRA_LIBS} leanshared)
add_test(NAME c_univ_test
WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/c_univ_test")
add_executable(c_expr_test expr.c)
target_link_libraries(c_expr_test ${EXTRA_LIBS} leanshared)
add_test(NAME c_expr_test
WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/c_expr_test")
# add_executable(c_env_test env.c)
# target_link_libraries(c_env_test ${EXTRA_LIBS} leanshared)
# add_test(NAME c_env_test
# WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
# COMMAND "${CMAKE_CURRENT_BINARY_DIR}/c_env_test")
# SET_TESTS_PROPERTIES(c_env_test
# PROPERTIES ENVIRONMENT "LEAN_PATH=${LEAN_SOURCE_DIR}/../library")
add_executable(thread_test thread.cpp)
target_link_libraries(thread_test ${EXTRA_LIBS} leanshared)
add_test(NAME thread_test
WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/thread_test")
SET_TESTS_PROPERTIES(thread_test
PROPERTIES ENVIRONMENT "LEAN_PATH=${LEAN_SOURCE_DIR}/../library")

View file

@ -1,550 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <stdlib.h>
#include <stdio.h>
#include "api/lean.h"
void check_core(int v, unsigned l) {
if (!v) {
printf("Test failed at line %d\n", l);
exit(1);
}
}
#define check(v) check_core(v, __LINE__)
lean_name mk_name(char const * n) {
lean_exception ex;
lean_name a, r;
check(lean_name_mk_anonymous(&a, &ex));
check(lean_name_mk_str(a, n, &r, &ex));
lean_name_del(a);
return r;
}
lean_univ mk_uparam(char const * n) {
lean_exception ex;
lean_univ r;
lean_name _n = mk_name(n);
check(lean_univ_mk_param(_n, &r, &ex));
lean_name_del(_n);
return r;
}
lean_list_name mk_unary_name_list(lean_name u) {
lean_exception ex;
lean_list_name n, r;
check(lean_list_name_mk_nil(&n, &ex));
check(lean_list_name_mk_cons(u, n, &r, &ex));
lean_list_name_del(n);
return r;
}
lean_env mk_env() {
lean_exception ex;
lean_env r;
check(lean_env_mk_std(LEAN_TRUST_HIGH, &r, &ex));
return r;
}
lean_expr mk_constant(char const * n, lean_list_univ us) {
lean_exception ex;
lean_name _n = mk_name(n);
lean_expr r;
check(lean_expr_mk_const(_n, us, &r, &ex));
lean_name_del(_n);
return r;
}
lean_expr mk_var(unsigned i) {
lean_exception ex;
lean_expr r;
check(lean_expr_mk_var(i, &r, &ex));
return r;
}
lean_expr mk_sort(lean_univ u) {
lean_exception ex;
lean_expr r;
check(lean_expr_mk_sort(u, &r, &ex));
return r;
}
/** create a constant with a single universe parameter */
lean_expr mk_const(char const * n, lean_univ u) {
lean_exception ex;
lean_name _n = mk_name(n);
lean_list_univ l1, l2;
check(lean_list_univ_mk_nil(&l1, &ex));
check(lean_list_univ_mk_cons(u, l1, &l2, &ex));
lean_expr r;
check(lean_expr_mk_const(_n, l2, &r, &ex));
lean_name_del(_n);
lean_list_univ_del(l1);
lean_list_univ_del(l2);
return r;
}
lean_expr mk_pi(char const * n, lean_expr d, lean_expr c) {
lean_exception ex;
lean_name name = mk_name(n);
lean_expr r;
check(lean_expr_mk_pi(name, d, c, LEAN_BINDER_DEFAULT, &r, &ex));
lean_name_del(name);
return r;
}
lean_expr mk_lambda(char const * n, lean_expr d, lean_expr c) {
lean_exception ex;
lean_name name = mk_name(n);
lean_expr r;
check(lean_expr_mk_lambda(name, d, c, LEAN_BINDER_DEFAULT, &r, &ex));
lean_name_del(name);
return r;
}
lean_expr mk_local(char const * n, lean_expr t) {
lean_exception ex;
lean_name _n = mk_name(n);
lean_expr r;
check(lean_expr_mk_local(_n, t, &r, &ex));
lean_name_del(_n);
return r;
}
lean_decl mk_def(char const * n, lean_list_name p, lean_expr t, lean_expr v) {
lean_exception ex;
lean_name name = mk_name(n);
lean_decl r;
check(lean_decl_mk_def(name, p, t, v, 0, lean_true, &r, &ex));
lean_name_del(name);
return r;
}
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_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_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);
}
void test_add_univ() {
lean_exception ex;
lean_name u = mk_name("u");
lean_name v = mk_name("v");
lean_env env = mk_env();
lean_env new_env;
check(lean_env_add_univ(env, u, &new_env, &ex));
check(lean_env_contains_univ(new_env, u));
check(!lean_env_contains_univ(new_env, v));
check(lean_env_for_each_univ(new_env, print_univ_and_del, &ex));
lean_name_del(u);
lean_name_del(v);
lean_env_del(env);
lean_env_del(new_env);
}
void test_id() {
lean_exception ex;
lean_univ l = mk_uparam("l");
lean_env env = mk_env();
lean_expr v0 = mk_var(0);
lean_expr v1 = mk_var(1);
lean_expr AA = mk_pi("a", v0, v1);
lean_expr Type = mk_sort(l);
lean_expr id_type = mk_pi("A", Type, AA);
lean_expr f = mk_lambda("a", v0, v0);
lean_expr id_val = mk_lambda("A", Type, f);
lean_name l_name = mk_name("l");
lean_list_name id_ps = mk_unary_name_list(l_name);
lean_decl id_def = mk_def("id", id_ps, id_type, id_val);
lean_name id_name = mk_name("id");
lean_cert_decl id_cert_def;
lean_env new_env;
lean_univ zero, one;
lean_bool is_lt;
check(lean_expr_lt(f, id_val, &is_lt, &ex) && is_lt);
check(lean_expr_lt(id_val, f, &is_lt, &ex) && !is_lt);
printf("id type: ");
print_expr(id_type);
printf("id value: ");
print_expr(id_val);
printf("-------\n");
/* type check definition */
check(lean_decl_check(env, id_def, &id_cert_def, &ex));
/* add certified definition to environment */
check(lean_env_add(env, id_cert_def, &new_env, &ex));
check(!lean_env_contains_decl(env, id_name));
check(lean_env_contains_decl(new_env, id_name));
check(lean_env_for_each_decl(new_env, print_decl_and_del, &ex));
check(lean_univ_mk_zero(&zero, &ex));
check(lean_univ_mk_succ(zero, &one, &ex));
check(lean_univ_lt(zero, one, &is_lt, &ex) && is_lt);
check(lean_univ_lt(one, zero, &is_lt, &ex) && !is_lt);
{
lean_type_checker tc;
lean_expr T0 = mk_sort(zero);
lean_expr T1 = mk_sort(one);
lean_expr id1 = mk_const("id", one);
lean_expr id1T1, id1T1T0;
lean_expr n1;
check(lean_expr_mk_app(id1, T1, &id1T1, &ex));
check(lean_expr_mk_app(id1T1, T0, &id1T1T0, &ex));
check(lean_type_checker_mk(new_env, &tc, &ex));
printf("WHNF test\n");
print_expr(id1T1T0);
check(lean_type_checker_whnf(tc, id1T1T0, &n1, &ex));
printf("=====>\n");
print_expr(n1);
lean_expr_del(n1);
printf("Infer type test\n");
print_expr(id1T1);
check(lean_type_checker_infer(tc, id1T1, &n1, &ex));
printf("=====>\n");
print_expr(n1);
lean_expr_del(n1);
lean_type_checker_del(tc);
lean_expr_del(T0);
lean_expr_del(T1);
lean_expr_del(id1);
lean_expr_del(id1T1);
lean_expr_del(id1T1T0);
}
lean_univ_del(l);
lean_env_del(env);
lean_expr_del(v0);
lean_expr_del(v1);
lean_expr_del(Type);
lean_expr_del(AA);
lean_expr_del(id_type);
lean_expr_del(f);
lean_expr_del(id_val);
lean_decl_del(id_def);
lean_list_name_del(id_ps);
lean_name_del(l_name);
lean_cert_decl_del(id_cert_def);
lean_env_del(new_env);
lean_name_del(id_name);
lean_univ_del(zero);
lean_univ_del(one);
}
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);
}
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 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);
}
lean_univ mk_one() {
lean_exception ex;
lean_univ zero, one;
check(lean_univ_mk_zero(&zero, &ex));
check(lean_univ_mk_succ(zero, &one, &ex));
lean_univ_del(zero);
return one;
}
lean_univ mk_max(lean_univ u1, lean_univ u2) {
lean_exception ex;
lean_univ r;
check(lean_univ_mk_max(u1, u2, &r, &ex));
return r;
}
lean_expr mk_app(lean_expr f, lean_expr a) {
lean_exception ex;
lean_expr r;
check(lean_expr_mk_app(f, a, &r, &ex));
return r;
}
void test_inductive() {
// declare list type
lean_exception ex = 0;
lean_env env = mk_env();
lean_name l_name = mk_name("l");
lean_univ l = mk_uparam("l");
lean_univ one = mk_one();
lean_univ m1l = mk_max(one, l);
lean_expr Typel = mk_sort(l);
lean_expr Typem1l = mk_sort(m1l);
lean_expr list_type = mk_pi("A", Typel, Typem1l);
lean_name list_name = mk_name("list");
lean_expr list = mk_const("list", l);
lean_expr v0 = mk_var(0);
// nil : Pi (A : Type.{l}), list.{l} A
lean_expr list_v0 = mk_app(list, v0);
lean_expr nil_type = mk_pi("A", Typel, list_v0);
lean_expr nil = mk_local("nil", nil_type);
// cons : Pi (A : Type.{l}), A -> list.{l} A -> list.{l} A
lean_expr v1 = mk_var(1);
lean_expr v2 = mk_var(2);
lean_expr list_v2 = mk_app(list, v2);
lean_expr list_v1 = mk_app(list, v1);
lean_expr cons_type1 = mk_pi("tail", list_v1, list_v2);
lean_expr cons_type2 = mk_pi("head", v0, cons_type1);
lean_expr cons_type = mk_pi("A", Typel, cons_type2);
lean_expr cons = mk_local("cons", cons_type);
//
lean_list_expr cs1, cs2, list_cs;
lean_inductive_type list_ind_type;
lean_list_inductive_type li1, list_ind_types;
lean_list_name ls1, ls;
lean_inductive_decl list_decl;
lean_env new_env;
check(lean_list_name_mk_nil(&ls1, &ex));
check(lean_list_name_mk_cons(l_name, ls1, &ls, &ex));
check(lean_list_expr_mk_nil(&cs1, &ex));
check(lean_list_expr_mk_cons(nil, cs1, &cs2, &ex));
check(lean_list_expr_mk_cons(cons, cs2, &list_cs, &ex));
check(lean_inductive_type_mk(list_name, list_type, list_cs, &list_ind_type, &ex));
check(lean_list_inductive_type_mk_nil(&li1, &ex));
check(lean_list_inductive_type_mk_cons(list_ind_type, li1, &list_ind_types, &ex));
check(lean_inductive_decl_mk(ls, 1, list_ind_types, &list_decl, &ex));
check(lean_env_add_inductive(env, list_decl, &new_env, &ex));
{
unsigned n;
lean_inductive_decl d;
lean_name cons_name = mk_name("cons");
lean_name r_name;
lean_list_inductive_type types;
check(lean_env_get_inductive_type_num_indices(new_env, list_name, &n, &ex) && n == 0);
check(lean_env_get_inductive_type_num_minor_premises(new_env, list_name, &n, &ex) && n == 2);
check(!lean_env_is_inductive_type(env, list_name, &d, &ex));
check(lean_env_is_inductive_type(new_env, list_name, &d, &ex));
check(lean_inductive_decl_get_num_params(d, &n, &ex) && n == 1);
check(lean_inductive_decl_get_types(d, &types, &ex));
check(lean_list_inductive_type_is_cons(types));
check(lean_env_is_constructor(new_env, cons_name, &r_name, &ex) && lean_name_eq(list_name, r_name));
lean_list_inductive_type_del(types);
lean_inductive_decl_del(d);
lean_name_del(cons_name);
lean_name_del(r_name);
}
lean_env_del(env);
lean_name_del(list_name);
lean_name_del(l_name);
lean_univ_del(l);
lean_univ_del(one);
lean_univ_del(m1l);
lean_expr_del(Typel);
lean_expr_del(Typem1l);
lean_expr_del(list_type);
lean_expr_del(list);
lean_expr_del(v0);
lean_expr_del(list_v0);
lean_expr_del(nil_type);
lean_expr_del(nil);
lean_expr_del(v1);
lean_expr_del(v2);
lean_expr_del(list_v2);
lean_expr_del(list_v1);
lean_expr_del(cons_type1);
lean_expr_del(cons_type2);
lean_expr_del(cons_type);
lean_expr_del(cons);
lean_list_expr_del(cs1);
lean_list_expr_del(cs2);
lean_list_expr_del(list_cs);
lean_inductive_type_del(list_ind_type);
lean_list_inductive_type_del(li1);
lean_list_inductive_type_del(list_ind_types);
lean_list_name_del(ls1);
lean_list_name_del(ls);
lean_inductive_decl_del(list_decl);
lean_env_del(new_env);
}
void test_parser() {
lean_exception ex = 0;
lean_env env = mk_env();
lean_ios ios;
lean_env new_env;
lean_ios new_ios;
lean_options o;
check(lean_options_mk_empty(&o, &ex));
check(lean_ios_mk_std(o, &ios, &ex));
check(lean_parse_commands(env, ios, "import standard open nat definition double (a : nat) := a + a check double 4 eval double 4",
&new_env, &new_ios, &ex));
{
lean_name double_name = mk_name("double");
lean_decl double_decl;
lean_expr double_decl_value;
char const * s;
check(lean_env_get_decl(new_env, double_name, &double_decl, &ex));
check(lean_decl_get_value(double_decl, &double_decl_value, &ex));
check(lean_expr_to_pp_string(new_env, new_ios, double_decl_value, &s, &ex));
printf("definition of double\n%s\n", s);
lean_name_del(double_name);
lean_decl_del(double_decl);
lean_expr_del(double_decl_value);
lean_string_del(s);
}
{
lean_expr e;
lean_list_name ps;
// remark: we can use notation from the namespace nat because we have executed 'open nat'
// when we created new_env
check(lean_parse_expr(new_env, new_ios, "double (2 + 3)", &e, &ps, &ex));
char const * s;
check(lean_expr_to_pp_string(new_env, new_ios, e, &s, &ex));
printf("parsed expression: %s\n", s);
lean_string_del(s);
lean_expr_del(e);
lean_list_name_del(ps);
}
lean_options_del(o);
lean_env_del(env);
lean_env_del(new_env);
lean_ios_del(ios);
lean_ios_del(new_ios);
}
void test_parser_error() {
lean_exception ex = 0;
lean_env env = mk_env();
lean_ios ios;
lean_env new_env;
lean_ios new_ios;
lean_options o;
check(lean_options_mk_empty(&o, &ex));
check(lean_ios_mk_std(o, &ios, &ex));
check(!lean_parse_commands(env, ios, "import data.nat open nat definition double (a : nat) := a + true",
&new_env, &new_ios, &ex));
{
lean_exception ex2 = 0;
char const * s1 = lean_exception_get_message(ex);
char const * s2 = lean_exception_get_detailed_message(ex);
char const * s3;
printf("\nexception kind: %d\n", lean_exception_get_kind(ex));
printf("exception message: %s\n", s1);
printf("exception detailed message: %s\n", s2);
check(lean_exception_to_pp_string(env, ios, ex, &s3, &ex2));
printf("exception: %s\n", s3);
lean_string_del(s1);
lean_string_del(s2);
lean_string_del(s3);
}
lean_options_del(o);
lean_exception_del(ex);
lean_env_del(env);
lean_ios_del(ios);
}
int main() {
test_add_univ();
test_id();
test_path();
test_import();
test_inductive();
test_parser();
test_parser_error();
return 0;
}

View file

@ -1,86 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <stdlib.h>
#include <stdio.h>
#include "api/lean.h"
void check_core(int v, unsigned l) {
if (!v) {
printf("Test failed at line %d\n", l);
exit(1);
}
}
#define check(v) check_core(v, __LINE__)
void test_var() {
lean_exception ex;
lean_expr e1, e2, e3;
lean_bool b; unsigned i;
check(lean_expr_mk_var(0, &e1, &ex));
check(lean_expr_mk_var(1, &e2, &ex));
check(lean_expr_mk_var(0, &e3, &ex));
check(lean_expr_eq(e1, e3, &b, &ex) && b);
check(lean_expr_eq(e1, e2, &b, &ex) && !b);
check(lean_expr_get_var_idx(e1, &i, &ex) && i == 0);
check(lean_expr_get_var_idx(e2, &i, &ex) && i == 1);
check(lean_expr_get_kind(e1) == LEAN_EXPR_VAR);
check(lean_expr_get_kind(e2) == LEAN_EXPR_VAR);
lean_expr_del(e1);
lean_expr_del(e2);
lean_expr_del(e3);
}
void test_const() {
lean_exception ex;
lean_name n1, n2, n3, n4;
lean_univ u1;
lean_list_univ l1, l2, l3, l4;
lean_expr e1, e2, e3;
lean_bool b;
char const * s;
check(lean_name_mk_anonymous(&n1, &ex));
check(lean_name_mk_str(n1, "id", &n2, &ex));
check(lean_name_mk_str(n1, "func", &n3, &ex));
check(lean_univ_mk_zero(&u1, &ex));
check(lean_list_univ_mk_nil(&l1, &ex));
check(lean_list_univ_mk_cons(u1, l1, &l2, &ex));
check(lean_list_univ_mk_cons(u1, l2, &l3, &ex));
check(lean_expr_mk_const(n2, l2, &e1, &ex));
check(lean_expr_mk_const(n2, l3, &e2, &ex));
check(lean_expr_mk_const(n3, l3, &e3, &ex));
check(lean_expr_eq(e1, e1, &b, &ex) && b);
check(lean_expr_eq(e1, e2, &b, &ex) && !b);
check(lean_expr_get_const_name(e2, &n4, &ex));
check(lean_name_eq(n2, n4));
check(lean_expr_get_const_univs(e3, &l4, &ex));
check(lean_list_univ_eq(l3, l4, &b, &ex) && b);
check(lean_expr_get_kind(e1) == LEAN_EXPR_CONST);
check(lean_expr_get_kind(e2) == LEAN_EXPR_CONST);
check(lean_expr_get_kind(e3) == LEAN_EXPR_CONST);
check(lean_expr_to_string(e3, &s, &ex));
printf("expr: %s\n", s);
lean_name_del(n1);
lean_name_del(n2);
lean_name_del(n3);
lean_name_del(n4);
lean_univ_del(u1);
lean_list_univ_del(l1);
lean_list_univ_del(l2);
lean_list_univ_del(l3);
lean_list_univ_del(l4);
lean_expr_del(e1);
lean_expr_del(e2);
lean_expr_del(e3);
lean_string_del(s);
}
int main() {
test_var();
test_const();
return 0;
}

View file

@ -1,86 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <stdlib.h>
#include <stdio.h>
#include "api/lean.h"
void check_core(int v, unsigned l) {
if (!v) {
printf("Test failed at line %d\n", l);
exit(1);
}
}
#define check(v) check_core(v, __LINE__)
void anonymous_unique() {
lean_exception ex;
lean_name a1, a2;
check(lean_name_mk_anonymous(&a1, &ex));
check(lean_name_mk_anonymous(&a2, &ex));
check(lean_name_eq(a1, a2));
lean_name_del(a1);
lean_name_del(a2);
}
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;
}

View file

@ -1,76 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "api/lean.h"
void check_core(int v, unsigned l) {
if (!v) {
printf("Test failed at line %d\n", l);
exit(1);
}
}
#define check(v) check_core(v, __LINE__)
int main() {
lean_exception ex;
lean_name an, verbose, pp, pp_unicode, seed, output;
lean_options o1, o2, o3, o4, o5, o6;
char const * s1;
char const * s2;
lean_bool b; unsigned u;
check(lean_name_mk_anonymous(&an, &ex));
check(lean_name_mk_str(an, "verbose", &verbose, &ex));
check(lean_name_mk_str(an, "pp", &pp, &ex));
check(lean_name_mk_str(pp, "unicode", &pp_unicode, &ex));
check(lean_name_mk_str(an, "seed", &seed, &ex));
check(lean_name_mk_str(an, "output", &output, &ex));
check(lean_options_mk_empty(&o1, &ex));
check(lean_options_set_bool(o1, pp_unicode, lean_true, &o2, &ex));
check(lean_options_set_unsigned(o2, verbose, 10, &o3, &ex));
check(lean_options_set_double(o3, seed, 1.23, &o4, &ex));
check(lean_options_set_bool(o1, pp_unicode, lean_true, &o5, &ex));
check(lean_options_eq(o2, o5));
check(lean_options_to_string(o4, &s1, &ex));
printf("Lean options: %s\n", s1);
check(lean_options_get_bool(o3, pp_unicode, &b, &ex));
check(b == lean_true);
check(lean_options_get_unsigned(o4, verbose, &u, &ex));
check(u == 10);
check(lean_options_set_string(o4, output, "~/tmp/file.olean", &o6, &ex));
check(lean_options_get_string(o6, output, &s2, &ex));
check(strcmp("~/tmp/file.olean", s2) == 0);
lean_name_del(an);
lean_name_del(verbose);
lean_name_del(pp);
lean_name_del(pp_unicode);
lean_name_del(seed);
lean_name_del(output);
lean_options_del(o1);
lean_options_del(o2);
lean_options_del(o3);
lean_options_del(o4);
lean_options_del(o5);
lean_options_del(o6);
lean_string_del(s1);
lean_string_del(s2);
return 0;
}

View file

@ -1,47 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "kernel/environment.h"
#include "kernel/type_checker.h"
#include "kernel/abstract.h"
#include "init/init.h"
using namespace lean;
static environment add_decl(environment const & env, declaration const & d) {
auto cd = check(env, d);
return env.add(cd);
}
int main() {
environment env;
std::cout << "Lean (empty) environment was successfully created\n";
name base("base");
expr Prop = mk_Prop();
env = add_decl(env, mk_constant_assumption(name(base, 0u), level_param_names(), Prop >> (Prop >> Prop)));
expr x = Local("x", Prop);
expr y = Local("y", Prop);
for (unsigned i = 1; i <= 100; i++) {
expr prev = Const(name(base, i-1));
env = add_decl(env, mk_definition(env, name(base, i), level_param_names(), Prop >> (Prop >> Prop),
Fun({x, y}, mk_app(prev, mk_app(prev, x, y), mk_app(prev, y, x)))));
}
expr Type = mk_Type();
expr A = Local("A", Type);
expr a = Local("a", A);
env = add_decl(env, mk_definition("id", level_param_names(),
Pi(A, A >> A),
Fun({A, a}, a), reducibility_hints::mk_abbreviation()));
type_checker checker(env);
expr f96 = Const(name(base, 96));
expr f97 = Const(name(base, 97));
expr f98 = Const(name(base, 98));
expr f3 = Const(name(base, 3));
expr c1 = mk_local("c1", Prop);
expr c2 = mk_local("c2", Prop);
expr id = Const("id");
std::cout << checker.whnf(mk_app(f3, c1, c2)) << "\n";
return 0;
}

View file

@ -1,79 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <iostream>
#include "api/lean.h"
void check_core(int v, unsigned l) {
if (!v) {
printf("Test failed at line %d\n", l);
exit(1);
}
}
#define check(v) check_core(v, __LINE__)
lean_name mk_name(char const * n) {
lean_exception ex;
lean_name a, r;
check(lean_name_mk_anonymous(&a, &ex));
check(lean_name_mk_str(a, n, &r, &ex));
lean_name_del(a);
return r;
}
lean_list_name mk_unary_name_list(lean_name u) {
lean_exception ex;
lean_list_name n, r;
check(lean_list_name_mk_nil(&n, &ex));
check(lean_list_name_mk_cons(u, n, &r, &ex));
lean_list_name_del(n);
return r;
}
lean_env mk_env() {
lean_exception ex;
lean_env r;
check(lean_env_mk_std(LEAN_TRUST_HIGH, &r, &ex));
return r;
}
void test_import() {
lean_exception ex;
lean_env env = mk_env();
lean_name std = mk_name("init");
lean_list_name ms = mk_unary_name_list(std);
lean_options o;
lean_ios ios;
lean_env new_env;
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));
lean_env_del(env);
lean_env_del(new_env);
lean_name_del(std);
lean_list_name_del(ms);
lean_options_del(o);
lean_ios_del(ios);
}
#if defined(LEAN_MULTI_THREAD)
#include <thread>
int main() {
std::thread t1(test_import);
std::thread t2(test_import);
t1.join();
t2.join();
return 0;
}
#else
int main() {
test_import();
test_import();
return 0;
}
#endif

View file

@ -1,94 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <stdlib.h>
#include <stdio.h>
#include "api/lean.h"
void check_core(int v, unsigned l) {
if (!v) {
printf("Test failed at line %d\n", l);
exit(1);
}
}
#define check(v) check_core(v, __LINE__)
int main() {
lean_exception ex;
lean_name a, l, pp, pp_unicode;
lean_options o1, o2;
lean_univ zero, one, p1, 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, "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_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_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(pp);
lean_name_del(pp_unicode);
lean_options_del(o1);
lean_options_del(o2);
lean_univ_del(zero);
lean_univ_del(one);
lean_univ_del(p1);
lean_univ_del(m1);
lean_univ_del(u);
lean_univ_del(n);
lean_univ_del(i);
lean_string_del(s1);
return 0;
}