From f67181baf3222bda72ce78a48c5ad1a23a3d9def Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Mon, 8 Feb 2016 18:42:34 -0800 Subject: [PATCH] chore(*): remove support for Lua --- doc/lua/lua.md | 739 -------- doc/lua/md2lua.sh | 5 - doc/lua/test.sh | 26 - doc/lua/test_single.sh | 19 - doc/lua/univ_poly.lua | 125 -- src/CMakeLists.txt | 25 +- src/cmake/Modules/CheckLuaNewstate.cc | 20 - src/cmake/Modules/FindLua.cmake | 137 -- src/frontends/lean/CMakeLists.txt | 4 +- src/frontends/lean/notation_cmd.cpp | 12 +- src/frontends/lean/parse_table.cpp | 239 +-- src/frontends/lean/parse_table.h | 11 +- src/frontends/lean/parser.cpp | 88 +- src/frontends/lean/parser.h | 20 - src/frontends/lean/parser_bindings.cpp | 185 -- src/frontends/lean/parser_bindings.h | 18 - src/frontends/lean/parser_config.cpp | 5 - src/frontends/lean/pp.cpp | 2 - src/frontends/lean/register_module.cpp | 24 - src/frontends/lean/register_module.h | 12 - src/frontends/lean/token_table.cpp | 84 - src/frontends/lean/token_table.h | 2 - src/frontends/lean/tokens.txt | 1 - src/frontends/lean/util.cpp | 8 +- src/frontends/lua/CMakeLists.txt | 1 - src/frontends/lua/register_modules.cpp | 22 - src/frontends/lua/register_modules.h | 13 - src/init/init.cpp | 2 - src/kernel/expr.h | 1 - src/library/CMakeLists.txt | 2 +- src/library/aliases.cpp | 52 - src/library/aliases.h | 2 - src/library/app_builder.cpp | 1 - src/library/choice.cpp | 37 - src/library/choice.h | 2 - src/library/coercion.h | 1 - src/library/error_handling.cpp | 53 - src/library/explicit.cpp | 33 - src/library/explicit.h | 2 - src/library/init_module.cpp | 3 - src/library/kernel_bindings.cpp | 1966 -------------------- src/library/kernel_bindings.h | 98 - src/library/match.cpp | 86 - src/library/match.h | 2 - src/library/placeholder.cpp | 31 - src/library/placeholder.h | 2 - src/library/private.cpp | 21 - src/library/private.h | 2 - src/library/reducible.cpp | 64 - src/library/reducible.h | 1 - src/library/resolve_macro.cpp | 4 - src/library/resolve_macro.h | 2 - src/library/scoped_ext.cpp | 45 - src/library/scoped_ext.h | 3 - src/library/tactic/apply_tactic.cpp | 1 - src/library/tactic/apply_tactic.h | 1 - src/library/tactic/goal.cpp | 57 - src/library/tactic/goal.h | 4 - src/library/tactic/proof_state.cpp | 151 -- src/library/tactic/proof_state.h | 5 - src/library/tactic/tactic.cpp | 180 -- src/library/tactic/tactic.h | 4 - src/library/unifier.cpp | 161 -- src/library/unifier.h | 3 - src/shell/CMakeLists.txt | 33 - src/shell/emscripten.cpp | 9 +- src/shell/lean.cpp | 27 +- src/tests/util/lp/lp.cpp | 3 +- src/tests/util/thread.cpp | 49 - src/util/CMakeLists.txt | 4 +- src/util/exception.cpp | 52 - src/util/exception.h | 6 - src/util/init_module.cpp | 6 - src/util/lean_path.cpp | 8 +- src/util/lean_path.h | 2 - src/util/lp/core_solver_pretty_printer.cpp | 1 + src/util/lp/core_solver_pretty_printer.h | 4 +- src/util/lp/lp_primal_core_solver.h | 18 +- src/util/lua.cpp | 208 --- src/util/lua.h | 136 -- src/util/lua_list.h | 80 - src/util/lua_named_param.cpp | 151 -- src/util/lua_named_param.h | 23 - src/util/lua_pair.h | 59 - src/util/luaref.cpp | 80 - src/util/luaref.h | 38 - src/util/name.cpp | 128 -- src/util/name.h | 10 - src/util/name_generator.cpp | 28 - src/util/name_generator.h | 2 - src/util/name_set.cpp | 30 - src/util/name_set.h | 4 - src/util/numerics/mpq.cpp | 88 - src/util/numerics/mpq.h | 5 - src/util/numerics/mpz.cpp | 82 - src/util/numerics/mpz.h | 5 - src/util/rb_map.cpp | 97 - src/util/rb_map.h | 2 - src/util/script_exception.cpp | 110 -- src/util/script_exception.h | 51 - src/util/script_state.cpp | 215 --- src/util/script_state.h | 65 - src/util/sexpr/format.cpp | 97 - src/util/sexpr/format.h | 4 - src/util/sexpr/options.cpp | 214 --- src/util/sexpr/options.h | 20 - src/util/sexpr/sexpr.cpp | 287 --- src/util/sexpr/sexpr.h | 4 - src/util/splay_map.h | 3 - src/util/thread_script_state.cpp | 147 -- src/util/thread_script_state.h | 39 - tests/lean/natsucc.lean | 14 - tests/lean/natsucc.lean.expected.out | 1 - tests/lean/run/362.lean | 5 - tests/lean/run/class1.lean | 4 +- tests/lean/run/class2.lean | 4 +- tests/lean/run/class3.lean | 4 +- tests/lean/run/class8.lean | 4 +- tests/lean/run/dfun_tst.lean | 11 - tests/lean/run/hash.lean | 9 - tests/lean/run/match1.lean | 30 - tests/lean/run/match2.lean | 35 - tests/lean/run/n1.lean | 33 - tests/lean/run/n2.lean | 26 - tests/lean/run/n4.lean | 21 - tests/lean/run/reducible.lean | 35 - tests/lean/run/tactic21.lean | 4 +- tests/lean/run/trick.lean | 32 - tests/lean/t1.lean | 12 - tests/lean/t1.lean.expected.out | 2 - tests/lean/t4.lean | 59 - tests/lean/t4.lean.expected.out | 35 - tests/lean/t7.lean | 20 - tests/lean/t7.lean.expected.out | 6 - tests/lean/varcomma.lean | 15 - tests/lean/varcomma.lean.expected.out | 3 - tests/lua/ac.lua | 17 - tests/lua/acc.lua | 63 - tests/lua/alias1.lua | 50 - tests/lua/alias2.lua | 8 - tests/lua/big.lua | 23 - tests/lua/choice.lua | 14 - tests/lua/choice2.lua | 6 - tests/lua/cnstr1.lua | 16 - tests/lua/def1.lua | 67 - tests/lua/env1.lua | 9 - tests/lua/env11.lua | 36 - tests/lua/env2.lua | 9 - tests/lua/env3.lua | 20 - tests/lua/env4.lua | 6 - tests/lua/env5.lua | 57 - tests/lua/env6.lua | 21 - tests/lua/env7.lua | 9 - tests/lua/env8.lua | 13 - tests/lua/env9.lua | 6 - tests/lua/eta.lua | 16 - tests/lua/explicit.lua | 7 - tests/lua/expr1.lua | 7 - tests/lua/expr10.lua | 8 - tests/lua/expr11.lua | 6 - tests/lua/expr2.lua | 27 - tests/lua/expr3.lua | 97 - tests/lua/expr4.lua | 8 - tests/lua/expr7.lua | 10 - tests/lua/expr8.lua | 7 - tests/lua/expr9.lua | 19 - tests/lua/extra.lua | 11 - tests/lua/format1.lua | 4 - tests/lua/format2.lua | 4 - tests/lua/format3.lua | 10 - tests/lua/free.lua | 7 - tests/lua/glvl1.lua | 9 - tests/lua/goal1.lua | 16 - tests/lua/hop1.lua | 28 - tests/lua/hop2.lua | 32 - tests/lua/implua.lua | 1 - tests/lua/ind1.lua | 145 -- tests/lua/ind2.lua | 111 -- tests/lua/ind3.lua | 80 - tests/lua/ind4.lua | 26 - tests/lua/ind5.lua | 23 - tests/lua/ind6.lua | 18 - tests/lua/ind_ex.lua | 16 - tests/lua/ind_tricky.lua | 17 - tests/lua/int1.lua | 19 - tests/lua/jst1.lua | 33 - tests/lua/level1.lua | 33 - tests/lua/level2.lua | 4 - tests/lua/level3.lua | 17 - tests/lua/level4.lua | 10 - tests/lua/level5.lua | 14 - tests/lua/level6.lua | 23 - tests/lua/level7.lua | 24 - tests/lua/level8.lua | 10 - tests/lua/level9.lua | 4 - tests/lua/map2.lua | 33 - tests/lua/mod1.lua | 32 - tests/lua/mod3.lua | 3 - tests/lua/mod3_corrupted1.olean | Bin 55 -> 0 bytes tests/lua/mod3_corrupted2.olean | Bin 56 -> 0 bytes tests/lua/mod3_corrupted3.olean | Bin 55 -> 0 bytes tests/lua/mod3_corrupted4.olean | Bin 56 -> 0 bytes tests/lua/mod3b.lua | 16 - tests/lua/mod4.lua | 1 - tests/lua/mpz1.lua | 12 - tests/lua/mpz2.lua | 6 - tests/lua/n1.lua | 13 - tests/lua/n2.lua | 6 - tests/lua/n3.lua | 1 - tests/lua/n5.lua | 3 - tests/lua/n6.lua | 8 - tests/lua/n7.lua | 7 - tests/lua/name1.lua | 30 - tests/lua/name_gen1.lua | 11 - tests/lua/ns1.lua | 12 - tests/lua/ns2.lua | 5 - tests/lua/num1.lua | 47 - tests/lua/old/ceq1.lua | 92 - tests/lua/old/cex_builder1.lua | 14 - tests/lua/old/coercion_bug1.lua | 23 - tests/lua/old/context1.lua | 25 - tests/lua/old/env1.lua | 11 - tests/lua/old/env2.lua | 18 - tests/lua/old/env3.lua | 4 - tests/lua/old/env4.lua | 34 - tests/lua/old/expr1.lua | 13 - tests/lua/old/expr2.lua | 12 - tests/lua/old/expr3.lua | 4 - tests/lua/old/expr4.lua | 4 - tests/lua/old/expr5.lua | 16 - tests/lua/old/expr6.lua | 44 - tests/lua/old/expr7.lua | 19 - tests/lua/old/expr8.lua | 44 - tests/lua/old/fields.lua | 8 - tests/lua/old/fmt1.lua | 2 - tests/lua/old/front.lua | 55 - tests/lua/old/goal1.lua | 30 - tests/lua/old/hidden1.lua | 14 - tests/lua/old/hop1.lua | 29 - tests/lua/old/hop2.lua | 133 -- tests/lua/old/import.lua | 12 - tests/lua/old/io_state1.lua | 9 - tests/lua/old/is_prop1.lua | 27 - tests/lua/old/jst1.lua | 11 - tests/lua/old/localctx1.lua | 24 - tests/lua/old/m1.lua | 36 - tests/lua/old/map.lua | 89 - tests/lua/old/menv1.lua | 55 - tests/lua/old/num2.lua | 10 - tests/lua/old/parser1.lua | 12 - tests/lua/old/parser2.lua | 27 - tests/lua/old/proof_builder1.lua | 19 - tests/lua/old/proof_state1.lua | 26 - tests/lua/old/proof_stats.lua | 23 - tests/lua/old/simp1.lua | 44 - tests/lua/old/single.lua | 5 - tests/lua/old/splay1.lua | 7 - tests/lua/old/st1.lua | 21 - tests/lua/old/st2.lua | 7 - tests/lua/old/st3.lua | 46 - tests/lua/old/tactic1.lua | 17 - tests/lua/old/template1.lua | 18 - tests/lua/old/ty1.lua | 12 - tests/lua/old/ty2.lua | 12 - tests/lua/old/unify1.lua | 30 - tests/lua/opt1.lua | 25 - tests/lua/opt2.lua | 9 - tests/lua/opt3.lua | 36 - tests/lua/opt4.lua | 4 - tests/lua/order.lua | 8 - tests/lua/place1.lua | 14 - tests/lua/place2.lua | 4 - tests/lua/proof_state1.lua | 12 - tests/lua/prv.lua | 25 - tests/lua/replace1.lua | 10 - tests/lua/res1.lua | 133 -- tests/lua/sexpr1.lua | 8 - tests/lua/sexpr2.lua | 32 - tests/lua/sexpr3.lua | 6 - tests/lua/sexpr4.lua | 28 - tests/lua/sexpr5.lua | 15 - tests/lua/sexpr_bug1.lua | 20 - tests/lua/simple.lua | 2 - tests/lua/slow/extra.lua | 11 - tests/lua/slow/mod2.lua | 46 - tests/lua/slow/t1.lua | 12 - tests/lua/sorted.lua | 30 - tests/lua/subst1.lua | 34 - tests/lua/tactic1.lua | 9 - tests/lua/tag1.lua | 17 - tests/lua/tc1.lua | 23 - tests/lua/tc2.lua | 68 - tests/lua/tc3.lua | 18 - tests/lua/tc4.lua | 17 - tests/lua/tc5.lua | 44 - tests/lua/tc6.lua | 3 - tests/lua/tc7.lua | 21 - tests/lua/tc8.lua | 23 - tests/lua/tc_bug1.lua | 59 - tests/lua/test.sh | 25 - tests/lua/test_single.sh | 17 - tests/lua/token_table.lua | 45 - tests/lua/unify1.lua | 57 - tests/lua/unify2.lua | 32 - tests/lua/unify3.lua | 16 - tests/lua/unify4.lua | 26 - tests/lua/unify5.lua | 35 - tests/lua/unify6.lua | 26 - tests/lua/unify7.lua | 25 - tests/lua/yield.lua | 11 - 310 files changed, 42 insertions(+), 12093 deletions(-) delete mode 100644 doc/lua/lua.md delete mode 100755 doc/lua/md2lua.sh delete mode 100755 doc/lua/test.sh delete mode 100755 doc/lua/test_single.sh delete mode 100644 doc/lua/univ_poly.lua delete mode 100644 src/cmake/Modules/CheckLuaNewstate.cc delete mode 100644 src/cmake/Modules/FindLua.cmake delete mode 100644 src/frontends/lean/parser_bindings.cpp delete mode 100644 src/frontends/lean/parser_bindings.h delete mode 100644 src/frontends/lean/register_module.cpp delete mode 100644 src/frontends/lean/register_module.h delete mode 100644 src/frontends/lua/CMakeLists.txt delete mode 100644 src/frontends/lua/register_modules.cpp delete mode 100644 src/frontends/lua/register_modules.h delete mode 100644 src/library/kernel_bindings.cpp delete mode 100644 src/library/kernel_bindings.h delete mode 100644 src/util/lua.cpp delete mode 100644 src/util/lua.h delete mode 100644 src/util/lua_list.h delete mode 100644 src/util/lua_named_param.cpp delete mode 100644 src/util/lua_named_param.h delete mode 100644 src/util/lua_pair.h delete mode 100644 src/util/luaref.cpp delete mode 100644 src/util/luaref.h delete mode 100644 src/util/rb_map.cpp delete mode 100644 src/util/script_exception.cpp delete mode 100644 src/util/script_exception.h delete mode 100644 src/util/script_state.cpp delete mode 100644 src/util/script_state.h delete mode 100644 src/util/thread_script_state.cpp delete mode 100644 src/util/thread_script_state.h delete mode 100644 tests/lean/natsucc.lean delete mode 100644 tests/lean/natsucc.lean.expected.out delete mode 100644 tests/lean/run/dfun_tst.lean delete mode 100644 tests/lean/run/hash.lean delete mode 100644 tests/lean/run/match1.lean delete mode 100644 tests/lean/run/match2.lean delete mode 100644 tests/lean/run/n1.lean delete mode 100644 tests/lean/run/n2.lean delete mode 100644 tests/lean/run/n4.lean delete mode 100644 tests/lean/run/reducible.lean delete mode 100644 tests/lean/run/trick.lean delete mode 100644 tests/lean/t1.lean delete mode 100644 tests/lean/t1.lean.expected.out delete mode 100644 tests/lean/t4.lean delete mode 100644 tests/lean/t4.lean.expected.out delete mode 100644 tests/lean/t7.lean delete mode 100644 tests/lean/t7.lean.expected.out delete mode 100644 tests/lean/varcomma.lean delete mode 100644 tests/lean/varcomma.lean.expected.out delete mode 100644 tests/lua/ac.lua delete mode 100644 tests/lua/acc.lua delete mode 100644 tests/lua/alias1.lua delete mode 100644 tests/lua/alias2.lua delete mode 100644 tests/lua/big.lua delete mode 100644 tests/lua/choice.lua delete mode 100644 tests/lua/choice2.lua delete mode 100644 tests/lua/cnstr1.lua delete mode 100644 tests/lua/def1.lua delete mode 100644 tests/lua/env1.lua delete mode 100644 tests/lua/env11.lua delete mode 100644 tests/lua/env2.lua delete mode 100644 tests/lua/env3.lua delete mode 100644 tests/lua/env4.lua delete mode 100644 tests/lua/env5.lua delete mode 100644 tests/lua/env6.lua delete mode 100644 tests/lua/env7.lua delete mode 100644 tests/lua/env8.lua delete mode 100644 tests/lua/env9.lua delete mode 100644 tests/lua/eta.lua delete mode 100644 tests/lua/explicit.lua delete mode 100644 tests/lua/expr1.lua delete mode 100644 tests/lua/expr10.lua delete mode 100644 tests/lua/expr11.lua delete mode 100644 tests/lua/expr2.lua delete mode 100644 tests/lua/expr3.lua delete mode 100644 tests/lua/expr4.lua delete mode 100644 tests/lua/expr7.lua delete mode 100644 tests/lua/expr8.lua delete mode 100644 tests/lua/expr9.lua delete mode 100644 tests/lua/extra.lua delete mode 100644 tests/lua/format1.lua delete mode 100644 tests/lua/format2.lua delete mode 100644 tests/lua/format3.lua delete mode 100644 tests/lua/free.lua delete mode 100644 tests/lua/glvl1.lua delete mode 100644 tests/lua/goal1.lua delete mode 100644 tests/lua/hop1.lua delete mode 100644 tests/lua/hop2.lua delete mode 100644 tests/lua/implua.lua delete mode 100644 tests/lua/ind1.lua delete mode 100644 tests/lua/ind2.lua delete mode 100644 tests/lua/ind3.lua delete mode 100644 tests/lua/ind4.lua delete mode 100644 tests/lua/ind5.lua delete mode 100644 tests/lua/ind6.lua delete mode 100644 tests/lua/ind_ex.lua delete mode 100644 tests/lua/ind_tricky.lua delete mode 100644 tests/lua/int1.lua delete mode 100644 tests/lua/jst1.lua delete mode 100644 tests/lua/level1.lua delete mode 100644 tests/lua/level2.lua delete mode 100644 tests/lua/level3.lua delete mode 100644 tests/lua/level4.lua delete mode 100644 tests/lua/level5.lua delete mode 100644 tests/lua/level6.lua delete mode 100644 tests/lua/level7.lua delete mode 100644 tests/lua/level8.lua delete mode 100644 tests/lua/level9.lua delete mode 100644 tests/lua/map2.lua delete mode 100644 tests/lua/mod1.lua delete mode 100644 tests/lua/mod3.lua delete mode 100644 tests/lua/mod3_corrupted1.olean delete mode 100644 tests/lua/mod3_corrupted2.olean delete mode 100644 tests/lua/mod3_corrupted3.olean delete mode 100644 tests/lua/mod3_corrupted4.olean delete mode 100644 tests/lua/mod3b.lua delete mode 100644 tests/lua/mod4.lua delete mode 100644 tests/lua/mpz1.lua delete mode 100644 tests/lua/mpz2.lua delete mode 100644 tests/lua/n1.lua delete mode 100644 tests/lua/n2.lua delete mode 100644 tests/lua/n3.lua delete mode 100644 tests/lua/n5.lua delete mode 100644 tests/lua/n6.lua delete mode 100644 tests/lua/n7.lua delete mode 100644 tests/lua/name1.lua delete mode 100644 tests/lua/name_gen1.lua delete mode 100644 tests/lua/ns1.lua delete mode 100644 tests/lua/ns2.lua delete mode 100644 tests/lua/num1.lua delete mode 100644 tests/lua/old/ceq1.lua delete mode 100644 tests/lua/old/cex_builder1.lua delete mode 100644 tests/lua/old/coercion_bug1.lua delete mode 100644 tests/lua/old/context1.lua delete mode 100644 tests/lua/old/env1.lua delete mode 100644 tests/lua/old/env2.lua delete mode 100644 tests/lua/old/env3.lua delete mode 100644 tests/lua/old/env4.lua delete mode 100644 tests/lua/old/expr1.lua delete mode 100644 tests/lua/old/expr2.lua delete mode 100644 tests/lua/old/expr3.lua delete mode 100644 tests/lua/old/expr4.lua delete mode 100644 tests/lua/old/expr5.lua delete mode 100644 tests/lua/old/expr6.lua delete mode 100644 tests/lua/old/expr7.lua delete mode 100644 tests/lua/old/expr8.lua delete mode 100644 tests/lua/old/fields.lua delete mode 100644 tests/lua/old/fmt1.lua delete mode 100644 tests/lua/old/front.lua delete mode 100644 tests/lua/old/goal1.lua delete mode 100644 tests/lua/old/hidden1.lua delete mode 100644 tests/lua/old/hop1.lua delete mode 100644 tests/lua/old/hop2.lua delete mode 100644 tests/lua/old/import.lua delete mode 100644 tests/lua/old/io_state1.lua delete mode 100644 tests/lua/old/is_prop1.lua delete mode 100644 tests/lua/old/jst1.lua delete mode 100644 tests/lua/old/localctx1.lua delete mode 100644 tests/lua/old/m1.lua delete mode 100644 tests/lua/old/map.lua delete mode 100644 tests/lua/old/menv1.lua delete mode 100644 tests/lua/old/num2.lua delete mode 100644 tests/lua/old/parser1.lua delete mode 100644 tests/lua/old/parser2.lua delete mode 100644 tests/lua/old/proof_builder1.lua delete mode 100644 tests/lua/old/proof_state1.lua delete mode 100644 tests/lua/old/proof_stats.lua delete mode 100644 tests/lua/old/simp1.lua delete mode 100644 tests/lua/old/single.lua delete mode 100644 tests/lua/old/splay1.lua delete mode 100644 tests/lua/old/st1.lua delete mode 100644 tests/lua/old/st2.lua delete mode 100644 tests/lua/old/st3.lua delete mode 100644 tests/lua/old/tactic1.lua delete mode 100644 tests/lua/old/template1.lua delete mode 100644 tests/lua/old/ty1.lua delete mode 100644 tests/lua/old/ty2.lua delete mode 100644 tests/lua/old/unify1.lua delete mode 100644 tests/lua/opt1.lua delete mode 100644 tests/lua/opt2.lua delete mode 100644 tests/lua/opt3.lua delete mode 100644 tests/lua/opt4.lua delete mode 100644 tests/lua/order.lua delete mode 100644 tests/lua/place1.lua delete mode 100644 tests/lua/place2.lua delete mode 100644 tests/lua/proof_state1.lua delete mode 100644 tests/lua/prv.lua delete mode 100644 tests/lua/replace1.lua delete mode 100644 tests/lua/res1.lua delete mode 100644 tests/lua/sexpr1.lua delete mode 100644 tests/lua/sexpr2.lua delete mode 100644 tests/lua/sexpr3.lua delete mode 100644 tests/lua/sexpr4.lua delete mode 100644 tests/lua/sexpr5.lua delete mode 100644 tests/lua/sexpr_bug1.lua delete mode 100644 tests/lua/simple.lua delete mode 100644 tests/lua/slow/extra.lua delete mode 100644 tests/lua/slow/mod2.lua delete mode 100644 tests/lua/slow/t1.lua delete mode 100644 tests/lua/sorted.lua delete mode 100644 tests/lua/subst1.lua delete mode 100644 tests/lua/tactic1.lua delete mode 100644 tests/lua/tag1.lua delete mode 100644 tests/lua/tc1.lua delete mode 100644 tests/lua/tc2.lua delete mode 100644 tests/lua/tc3.lua delete mode 100644 tests/lua/tc4.lua delete mode 100644 tests/lua/tc5.lua delete mode 100644 tests/lua/tc6.lua delete mode 100644 tests/lua/tc7.lua delete mode 100644 tests/lua/tc8.lua delete mode 100644 tests/lua/tc_bug1.lua delete mode 100755 tests/lua/test.sh delete mode 100755 tests/lua/test_single.sh delete mode 100644 tests/lua/token_table.lua delete mode 100644 tests/lua/unify1.lua delete mode 100644 tests/lua/unify2.lua delete mode 100644 tests/lua/unify3.lua delete mode 100644 tests/lua/unify4.lua delete mode 100644 tests/lua/unify5.lua delete mode 100644 tests/lua/unify6.lua delete mode 100644 tests/lua/unify7.lua delete mode 100644 tests/lua/yield.lua diff --git a/doc/lua/lua.md b/doc/lua/lua.md deleted file mode 100644 index 0943a8523..000000000 --- a/doc/lua/lua.md +++ /dev/null @@ -1,739 +0,0 @@ -# Lua API documentation - -We the [Lua](http://www.lua.org) script language to customize and -extend [Lean](http://leanprover.net). This -[link](http://www.lua.org/docs.html) is a good starting point for -learning Lua. In this document, we focus on the Lean specific APIs. -Most of Lean components are exposed in the Lua API. - -**Remark:** the script [md2lua.sh](md2lua.sh) extracts the Lua code -examples from the `*.md` documentation files in this directory. - -## Hierarchical names - -In Lean, we use _hierarchical names_ for identifying configuration -options, constants, and kernel objects. A hierarchical name is -essentially a list of strings and integers. -The following example demonstrates how to create and manipulate -hierarchical names using the Lua API. - -```lua -local x = name("x") -- create a simple hierarchical name -local y = name("y") --- In Lua, 'assert(p)' succeeds if 'p' does not evaluate to false (or nil) -assert(x == name("x")) -- test if 'x' is equal to 'name("x")' -assert(x ~= y) -- '~=' is the not equal operator in Lua -assert(x ~= "x") - -assert(is_name(x)) -- test whether argument is a hierarchical name or not. -assert(not is_name("x")) - -local x1 = name(x, 1) -- x1 is a name composed of the string "x" and number 1 -assert(tostring(x1) == "x.1") -assert(x1 ~= name("x.1")) -- x1 is not equal to the string x.1 -assert(x1 == name("x", 1)) - -local o = name("lean", "pp", "colors") --- The previous construct is syntax sugar for the following expression -assert(o == name(name(name("lean"), "pp"), "colors")) - -assert(x < y) -- '<' is a total order on hierarchical names - -local h = x:hash() -- retrieve the hash code for 'x' -assert(h ~= y:hash()) -``` - -## Lua tables - -Tables are the only mutable, non-atomic type of data in Lua. Tables -are used to implement mappings, arrays, lists, objects, etc. Here is a -small examples demonstrating how to use Lua tables: - -```lua -local t = {} -- create an empty table -t["x"] = 10 -- insert the entry "x" -> 10 -t.x = 20 -- syntax-sugar for t["x"] = 20 -t["y"] = 30 -- insert the entry "y" -> 30 -assert(t["x"] == 20) -local p = { x = 10, y = 20 } -- create a table with two entries -assert(p.x == 10) -assert(p["x"] == 10) -assert(p.y == 20) -assert(p["y"] == 20) -``` - -Arrays are implemented by indexing tables with integers. -The arrays don't have a fixed size and grow dynamically. -The arrays in Lua usually start at index 1. The Lua libraries -use this convention. The following example initializes -an array with 100 elements. - -```lua -local a = {} -- new array -for i=1, 100 do - a[i] = 0 -end -local b = {2, 4, 6, 8, 10} -- create an array with 5 elements -assert(#b == 5) -- array has 5 elements -assert(b[1] == 2) -assert(b[2] == 4) -``` -In Lua, we cannot provide custom hash and equality functions to tables. -So, we cannot effectively use Lua tables to implement mappings where -the keys are Lean hierarchical names, expressions, etc. -The following example demonstrates the issue. - -```lua -local m = {} -- create empty table -local a = name("a") -m[a] = 10 -- map the hierarchical name 'a' to 10 -assert(m[a] == 10) -local a1 = name("a") -assert(a == a1) -- 'a' and 'a1' are the same hierarchical name -assert(m[a1] == nil) -- 'a1' is not a key in the mapping 'm' -assert(m[a] == 10) --- 'a' and 'a1' are two instances of the same object --- Lua tables assume that different instances are not equal -``` - -## Red-black tree maps - -In Lean, we provide red-black tree maps for implementing mappings where the keys are -Lean objects such as hierarchical names. The maps are implemented on -top of [red-black tree data structure](http://en.wikipedia.org/wiki/Red%E2%80%93black_tree). -We can also use Lua atomic data types as keys in these maps. -However, we should not mix different types in the same map. -The Lean map assumes that `<` is a total order on the -keys inserted in the map. - -```lua -local m = rb_map() -- create an empty red-black tree map -assert(is_rb_map(m)) -assert(#m == 0) -local a = name("a", 1) -local a1 = name("a", 1) -m:insert(a, 10) -- add the entry 'a.1' -> 10 -assert(m:find(a1) == 10) -m:insert(name("b"), 20) -assert(#m == 2) -m:erase(a) -- remove entry with key 'a.1' -assert(m:find(a) == nil) -assert(not m:contains(a)) -assert(#m == 1) -m:insert(name("c"), 30) -m:for_each( -- traverse the entries in the map - function(k, v) -- executing the given function - print(k, v) - end -) -local m2 = m:copy() -- the maps are copied in constant time -assert(#m2 == #m) -m2:insert(name("b", 2), 40) -assert(#m2 == #m + 1) -``` - -## Multiple precision numerals - -We expose [GMP](http://gmplib.org/) (GNU Multiple precision arithmetic -library) in Lua. Internally, Lean uses multiple precision numerals for -representing expressing containing numerals. -In Lua, we can create multiple precision integers (_mpz_) and multiple -precision rationals (_mpq_). The following example demonstrates how to -use `mpz` and `mpq` numerals. - -```lua -local ten = mpz(10) -- create the mpz numeral 10. -assert(is_mpz(ten)) -- test whether 'ten' is a mpz numeral or not -assert(not is_mpz(10)) -local big = mpz("100000000000000000000000") -- create a mpz numeral from a string --- The operators +, -, *, /, ^, <, <=, >, >=, ==, ~= --- The operators +, -, *, /, ^ accept mixed mpz and Lua native types -assert(ten + 1 == mpz(11)) --- In Lua, objects of different types are always different --- So, the mpz number 10 is different from the native Lua numeral 10 -assert(mpz(10) ~= 10) -assert(mpz(3) / 2 == mpz(1)) --- The second argument of ^ must be a non-negative Lua numeral -assert(mpz(10) ^ 100 > mpz("1000000000000000000000000")) -assert(mpz(3) * mpz("1000000000000000000000") == mpz("3000000000000000000000")) -assert(mpz(4) + "10" == mpz(14)) -local q1 = mpq(10) -- create the mpq numeral 10 -local q2 = q1 / 3 -- create the mpq numeral 10/3 -assert(q2 == mpq("10/3")) -local q3 = mpq(0.25) -- create the mpq numeral 1/4 -assert(q3 == mpq(1)/4) -assert(is_mpq(q3)) -- test whether 'q3' is a mpq numeral or not -assert(not is_mpq(mpz(10))) -- mpz numerals are not mpq -assert(ten == mpz(10)) -local q4 = mpq(ten) -- convert the mpz numeral 'ten' into a mpq numeral -assert(is_mpq(q4)) -assert(mpq(1)/3 + mpq(2)/3 == mpq(1)) -assert(mpq(0.5)^5 == mpq("1/32")) -assert(mpq(1)/2 > mpq("1/3")) -``` - -## S-expressions - -In Lean, we use Lisp-like non-mutable S-expressions as a basis for -building configuration options, statistics, formatting objects, and -other structured objects. S-expressions can be atomic values (nil, strings, -hierarchical names, integers, doubles, Booleans, and multiple precision -integers and rationals), or pairs (aka _cons-cell_). -The following example demonstrates how to create S-expressions using Lua. - -```lua -local s = sexpr(1, 2) -- Create a pair containing the atomic values 1 and 2 -assert(is_sexpr(s)) -- 's' is a pair -assert(s:is_cons()) -- 's' is a cons-cell/pair -assert(s:head():is_atom()) -- the 'head' is an atomic S-expression -assert(s:head() == sexpr(1)) -- the 'head' of 's' is the atomic S-expression 1 -assert(s:tail() == sexpr(2)) -- the 'head' of 's' is the atomic S-expression 2 -s = sexpr(1, 2, 3, nil) -- Create a 'list' containing 1, 2 and 3 -assert(s:length() == 3) -assert(s:head() == sexpr(1)) -assert(s:tail() == sexpr(2, 3, nil)) -assert(s:head():is_int()) -- the 'head' is an integer -assert(s:head():to_int() == 1) -- return the integer stored in the 'head' of 's' -local h, t = s:fields() -- return the 'head' and 'tail' of s -assert(h == sexpr(1)) -``` - -The following example demonstrates how to test the kind of and extract -the value stored in atomic S-expressions. - -```lua -assert(sexpr(1):is_int()) -assert(sexpr(1):to_int() == 1) -assert(sexpr(true):is_bool()) -assert(sexpr(false):to_bool() == false) -assert(sexpr("hello"):is_string()) -assert(sexpr("hello"):to_string() == "hello") -assert(sexpr(name("n", 1)):is_name()) -assert(sexpr(name("n", 1)):to_name() == name("n", 1)) -assert(sexpr(mpz(10)):is_mpz()) -assert(sexpr(mpz(10)):to_mpz() == mpz(10)) -assert(sexpr(mpq(3)/2):is_mpq()) -assert(sexpr(mpq(3)/2):to_mpq() == mpq(6)/4) -``` -We can also use the method `fields` to extract the value stored -in atomic S-expressions. It is more convenient than using -the `to_*` methods. - -```lua -assert(sexpr(10):fields() == 10) -assert(sexpr("hello"):fields() == "hello") -``` - -The `to_*` methods raise an error is the argument does not match -the expected type. Remark: in Lua, we catch errors using -the builtin function [`pcall`](http://pgl.yoyo.org/luai/i/pcall) (aka _protected call_). - -```lua -local s = sexpr(10) -local ok, ex = pcall(function() s:to_string() end) -assert(not ok) --- 'ex' is a Lean exception -assert(is_exception(ex)) -``` - -We say an S-expression `s` is a _list_ iff `s` is a pair, and the -`tail` is nil or a list. So, every _list_ is a pair, but not every -pair is a list. - -```lua -assert(sexpr(1, 2):is_cons()) -- The S-expression is a pair -assert(not sexpr(1, 2):is_list()) -- This pair is not a list -assert(sexpr(1, nil):is_list()) -- List with one element -assert(sexpr(1, 2, nil):is_list()) -- List with two elements --- The expression sexpr(1, 2, nil) is syntax-sugar --- for sexpr(1, sexpr(2, nil)) -assert(sexpr(1, 2, nil) == sexpr(1, sexpr(2, nil))) --- The methond 'length' returns the length of the list -assert(sexpr(1, 2, nil):length() == 2) -``` - -We can encode trees using S-expressions. The following example -demonstrates how to write a simple recursive function that -collects all leaves (aka atomic values) stored in a S-expression -tree. - -```lua -function collect(S) - -- We store the result in a Lua table - local result = {} - function loop(S) - if S:is_cons() then - loop(S:head()) - loop(S:tail()) - elseif not S:is_nil() then - result[#result + 1] = S:fields() - end - end - loop(S) - return result -end --- Create a simple tree -local tree = sexpr(sexpr(1, 5), sexpr(sexpr(4, 3), 5)) -local leaves = collect(tree) -- store the leaves in a Lua table -assert(#leaves == 5) -assert(leaves[1] == 1) -assert(leaves[2] == 5) -assert(leaves[3] == 4) -``` - -## Options - -Lean components can be configured used _options_ objects. The options -can be explicitly provided or read from a global variable. An options -object is a non-mutable value based on S-expressions. -An options object is essentially a list of pairs, where each pair -is a hierarchical name and a value. The following example demonstrates -how to create options objects using Lua. - -```lua --- Create an options set containing the entries --- pp.colors -> false, --- pp.unicode -> false -local o1 = options(name("pp", "colors"), false, name("pp", "unicode"), false) -assert(is_options(o1)) -print(o1) --- The same example using syntax-sugar for hierarchical names. --- The Lean-Lua API will automatically convert Lua arrays into hierarchical names. -local o2 = options({"pp", "colors"}, false, {"pp", "unicode"}, false) -print(o2) --- An error is raised if the option is not known. -local ok, ex = pcall(function() options({"pp", "foo"}, true) end) -assert(not ok) -assert(ex:what():find("unknown option 'pp.foo'")) -``` - -Options objects are non-mutable values. The method `update` returns a new -updates options object. - -```lua -local o1 = options() -- create the empty options -assert(o1:empty()) -local o2 = o1:update({'pp', 'colors'}, true) -assert(o1:empty()) -assert(not o2:empty()) -assert(o2:size() == 1) -assert(o2:get({'pp', 'colors'}) == true) -assert(o2:get{'pp', 'colors'} == true) -assert(o2:contains{'pp', 'colors'}) -assert(not o2:contains{'pp', 'unicode'}) --- We can provide a default value for 'get'. --- The default value is used if the options object does --- not contain the key. -assert(o2:get({'pp', 'width'}) == 0) -assert(o2:get({'pp', 'width'}, 10) == 10) -assert(o2:get({'pp', 'width'}, 20) == 20) -local o3 = o2:update({'pp', 'width'}, 100) -assert(o3:get({'pp', 'width'}) == 100) -assert(o3:get({'pp', 'width'}, 1) == 100) -assert(o3:get({'pp', 'width'}, 20) == 100) -``` - -The functions `get_options` and `set_options` get/set the global -options object. For example, the global options object is used -by the `print` method. - -```lua -local o = options({'pp', 'unicode'}, false) -set_options(o) -assert(get_options():contains{'pp', 'unicode'}) -``` - -# Universe levels - -Lean supports universe polymorphism. That is, declaration in Lean can -be parametrized by one or more universe level parameters. -The declarations can then be instantiated with universe level -expressions. In the standard Lean front-end, universe levels can be -omitted, and the Lean elaborator (tries) to infer them automatically -for users. In this section, we describe the API for creating and using -universe level expressions. - -In Lean, we have a hierarchy of universes: `Type.{0}` : `Type.{1}` : -`Type.{2}`, ... -We do not assume our universes are cumulative (like Coq). -In Lean, when we create an empty environment, we can specify whether -`Type.{0}` is impredicative or not. The idea is to be able to use -`Type.{0}` to represent the universe of Propositions. - -In Lean, we have the following kinds of universe level expression: -- `Zero` : the universe level expression for representing `Type.{0}`. -- `Succ(l)` : the successor of universe level `l`. -- `Max(l1, l2)` : the maximum of levels `l1` and `l2`. -- `IMax(l1, l2)` : the "impredicative" maximum. It is defined as - `IMax(x, y) = Zero` if `y` is `Zero`, and `Max(x, y)` otherwise. -- `Param(n)` : a universe level parameter named `n`. -- `Global(n)` : a global universe level named `n`. -- `Meta(n)` : a meta universe level named `n`. Meta universe - levels are used to identify placeholders that must be automatically - constructed by Lean. - -The following example demonstrates how to create universe level -expressions using Lua. - -```lua -local zero = level() -- Create level Zero -assert(is_level(zero)) -- zero is a level expression -assert(zero:is_zero()) -local one = zero + 1 -- Create level One -assert(one ~= 1) -- level one is not the constant 1 --- We can also use the API mk_level_succ instead of +1 -local two = mk_level_succ(one) -- Create level Two -assert(two == one+1) -assert(two:is_succ()) -- two is of the kind: successor -assert(two:succ_of() == one) -- it is the successor of one -local u = mk_global_univ("u") -- u is a reference to global universe level "u" -assert(u:is_global()) -assert(u:id() == name("u")) -- Retrieve u's name -local l = mk_param_univ("l") -- l is a reference to a universe level parameter -assert(l:is_param()) -assert(l:id() == name("l")) -assert(l:id() ~= "l") -- The names are not strings, but hierarchical names -assert(l:kind() == level_kind.Param) -local m = mk_meta_univ("m") -- Create a meta universe level named "m" -assert(m:is_meta()) -assert(m:id() == name("m")) -print(max_univ(l, u)) -- Create level expression Max(l, u) -assert(max_univ(l, u):is_max()) --- The max_univ API applies basic coercions automatically -assert(max_univ("l", 1) == max_univ(l, one)) -assert(max_univ("l", 1, u) == max_univ(l, max_univ(one, u))) --- The max_univ API applies basic simplifications automatically -assert(max_univ(l, l) == l) -assert(max_univ(l, zero) == l) -assert(max_univ(one, zero) == one) -print(imax_univ(l, u)) -- Create level expression IMax(l, u) -assert(imax_univ(l, u):is_imax()) --- The imax_univ API also applies basic coercions automatically -assert(imax_univ(1, "l") == imax_univ(one, l)) --- The imax_univ API applies basic simplifications automatically -assert(imax_univ(l, l) == l) -assert(imax_univ(l, zero) == zero) --- It "knows" that u+1 can never be zero -assert(imax_univ(l, u+1) == max_univ(l, u+1)) -assert(imax_univ(zero, one) == one) -assert(imax_univ(one, zero) == zero) --- The methods lhs and rhs deconstruct max and imax expressions -assert(max_univ(l, u):lhs() == l) -assert(imax_univ(l, u):rhs() == u) --- The method is_not_zero if there if for all assignments --- of the parameters, globals and meta levels, the resultant --- level expression is different from zero. -assert((l+1):is_not_zero()) -assert(not l:is_not_zero()) -assert(max_univ(l+1, u):is_not_zero()) --- The method instantiate replaces parameters with level expressions -assert(max_univ(l, u):instantiate({"l"}, {two}) == max_univ(two, u)) -local l1 = mk_param_univ("l1") -assert(max_univ(l, l1):instantiate({"l", "l1"}, {two, u+1}) == max_univ(two, u+1)) --- The method has_meta returns true, if the given level expression --- contains meta levels -assert(max_univ(m, l):has_meta()) -assert(not max_univ(u, l):has_meta()) --- The is_eqp method checks for pointer equality -local e1 = max_univ(l, u) -local e2 = max_univ(l, u) -assert(e1 == e2) -local e3 = e1 --- e1 and e3 are references to the same level expression. -assert(e1:is_eqp(e3)) -``` - -In the previous example, we learned that functions such as `max_univ` -apply basic simplifications automatically. However, they do not put -the level expressions in any normal form. We can use the method -`normalize` for that. The normalization procedure is also use to -implement the method `is_equivalent` that returns true when two level -expressions are equivalent. The Lua API also contains the method -`is_geq` that can be used to check whether a level expression -represents a universe bigger than or equal another one. - -```lua -local zero = level() -local l = mk_param_univ("l") -local u = mk_global_univ("u") -assert(max_univ(l, 1, u+1):is_equivalent(max_univ(u+1, 1, l))) -local e1 = max_univ(l, u+1)+1 -assert(e1:normalize() == max_univ(l+1, u+2)) --- norm is syntax sugar for normalize -assert(e1:norm() == max_univ(l+1, u+2)) -assert(e1:is_geq(l)) -assert(e1:is_geq(e1)) -assert(e1:is_geq(zero)) -assert(e1:is_geq(u+2)) -assert(e1:is_geq(max_univ(l, u))) -``` - -We say a universe level is _explicit_ iff it is of the form -`succ^k(zero)` - -```lua -local zero = level() -assert(zero:is_explicit()) -local two = zero+2 -assert(two:is_explicit()) -local l = mk_param_univ("l") -assert(not l:is_explicit()) -``` - -The Lua dictionary `level_kind` contains the id for all universe level -kinds. - -```lua -local zero = level() -local one = zero+1 -local l = mk_param_univ("l") -local u = mk_global_univ("u") -local m = mk_meta_univ("m") -local e1 = max_univ(l, u) -local e2 = imax_univ(m, l) -assert(zero:kind() == level_kind.Zero) -assert(one:kind() == level_kind.Succ) -assert(l:kind() == level_kind.Param) -assert(u:kind() == level_kind.Global) -assert(m:kind() == level_kind.Meta) -assert(e1:kind() == level_kind.Max) -assert(e2:kind() == level_kind.IMax) -``` - -# Expressions - -In Lean, we have the following kind of expressions: constants, -function applications, variables, lambdas, dependent function spaces -(aka Pis), let expressions, and sorts (aka Type). -There are three additional kinds of auxiliary -expressions: local constants, metavariables, and macros. - -## Constants - -Constants are essentially references to declarations in the -environment. We can create a variable using - -```lua -local f = mk_constant("f") -local a = Const("a") -- Const is an alias for mk_constant -assert(is_expr(f)) -- f is an expression -assert(f:is_constant()) -- f is a constant -``` -Lean supports universe polymorphism. When we define a constant, -theorem or axiom, we can use universe level parameters. -Thus, if a declaration `g` has two universe level parameters, -we instantiate them when we create a reference to `g`. - -```lua -local zero = level() -local one = zero+1 -local g01 = mk_constant("g", {zero, one}) -``` - -The command `mk_constant` automatically applies coercions to level -expressions. A numeral `n` is automatically converted into -`level()+n`, and a string `s` into `mk_param_univ(s)`. - -```lua -local g1l = mk_constant("g", {1, "l"}) -``` - -The method `data()` retrieves the name and universe levels of a -constant. - -```lua -local gl1 = mk_constant("g", {"l", 1}) -assert(gl1:is_constant()) -local n, ls = gl1:data() -assert(n == name("g")) -assert(#ls == 2) -assert(ls:head() == mk_param_univ("l")) -assert(ls:tail():head() == level()+1) -``` - -## Function applications - -In Lean, the expression `f t` is a function application, where `f` is -a function that is applied to `t`. - -```lua -local f = Const("f") -local t = Const("t") -local a = f(t) -- Creates the term `f t` -assert(is_expr(a)) -assert(a:is_app()) -``` - -The method `data()` retrieves the function and argument of an -application. The methods `fn()` and `arg()` retrieve the function -and argument respectively. - -```lua -local f = Const("f") -local t = Const("t") -local a = f(t) -assert(a:fn() == f) -assert(a:arg() == t) -local g, b = a:data() -assert(g == f) -assert(b == t) -``` -As usual, we write `f t s` to denote the expression -`((f t) s)`. The Lua API provides a similar convenience. - -```lua -local f = Const("f") -local t = Const("t") -local s = Const("s") -local a = f(t, s) -assert(a:fn() == f(t)) -assert(a:fn():fn() == f) -assert(a:fn():arg() == t) -assert(a:arg() == s) -``` - -## Variables - -Variables are references to local declarations in lambda and Pi -expressions. The variables are represented using -[de Bruijn indices](http://en.wikipedia.org/wiki/De_Bruijn_index). - -```lua -local x = mk_var(0) -local y = Var(1) -- Var is an alias for mk_var -assert(is_expr(x)) -assert(x:is_var()) -assert(x:data() == 0) -assert(y:data() == 1) -``` - -## Lambda abstractions - -Lambda abstraction is a converse operation to function -application. Given a variable `x`, a type `A`, and a term `t` that may or -may not contain `x`, one can construct the so-called lambda abstraction -`fun x : A, t`, or using unicode notation `λ x : A, t`. -There are many APIs for creating lambda abstractions in the Lua API. -The most basic one is `mk_lambda(x, A, t)`, where `x` is a string or -hierarchical name, and `A` and `t` are expressions. - -```lua -local x = Var(0) -local A = Const("A") -local id = mk_lambda("x", A, x) -- create the identity function -assert(is_expr(id)) -assert(id:is_lambda()) -``` - -As usual, the method `data()` retrieves the "fields" of a lambda -abstraction. - -```lua --- id is the identity function defined above. -local y, B, v = id:data() -assert(y == name("x")) -assert(B == A) -assert(v == Var(0)) -``` - -We say a variable is _free_ if it is not bound by any lambda (or Pi) -abstraction. We say an expression is _closed_ if it does not contain -free variables. The method `closed()` return `true` iff the expression -is closed. - -```lua -local f = Const("f") -local N = Const("N") -assert(not f(Var(0)):closed()) -local l1 = mk_lambda("x", N, f(Var(0))) -assert(l1:closed()) -local l2 = mk_lambda("x", N, f(Var(1))) -assert(not l2:closed()) -``` - -The method `has_free_var(i)` return `true` if the expression contains -the free variable `i`. - -```lua -local f = Const("f") -local N = Const("N") -assert(f(Var(0)):has_free_var(0)) -assert(not f(Var(0)):has_free_var(1)) -local l1 = mk_lambda("x", N, f(Var(0))) -assert(not l1:has_free_var(0)) -local l2 = mk_lambda("x", N, f(Var(1))) -assert(l2:has_free_var(0)) -assert(not l2:has_free_var(1)) -``` - -The de Bruijn indices can be lifted and lowered using the methods -`lift_free_vars` and `lower_free_vars`. - -```lua -local f = Const("f") -local N = Const("N") -assert(f(Var(0)):lift_free_vars(1) == f(Var(1))) -assert(f(Var(0)):lift_free_vars(2) == f(Var(2))) --- lift the free variables >= 2 by 3 -assert(f(Var(0), Var(2)):lift_free_vars(2, 3) == f(Var(0), Var(5))) - -assert(f(Var(1)):lower_free_vars(1) == f(Var(0))) -assert(f(Var(2)):lower_free_vars(1) == f(Var(1))) --- lower the free variables >= 2 by 1 -assert(f(Var(0), Var(2)):lower_free_vars(2, 1) == - f(Var(0), Var(1))) -``` - -It is not convenient to create complicated lambda abstractions using -de Bruijn indices. It is usually a very error-prone task. -To simplify the creation of lambda abstractions, Lean provides local constants. -A local constant is essentially a pair name and expression, where the -expression represents the type of the local constant. -The API `Fun(c, b)` automatically replace the local constant `c` in `b` with -the variable 0. It does all necessary adjustments when `b` contains nested -lambda abstractions. The API also provides `Fun(c_1, ..., c_n, b)` as -syntax-sugar for `Fun(c_1, ..., Fun(c_n, b)...)`. - -```lua -local N = Const("N") -local f = Const("f") -local c_1 = Local("c_1", N) -local c_2 = Local("c_2", N) -local c_3 = Local("c_3", N) -assert(Fun(c_1, f(c_1)) == mk_lambda("c_1", N, f(Var(0)))) -assert(Fun(c_1, c_2, f(c_1, c_2)) == - mk_lambda("c_1", N, mk_lambda("c_2", N, f(Var(1), Var(0))))) -assert(Fun(c_1, c_2, f(c_1, Fun(c_3, f(c_2, c_3)))) == - mk_lambda("c_1", N, mk_lambda("c_2", N, - f(Var(1), mk_lambda("c_3", N, f(Var(1), Var(0))))))) -```` - -Local constants can be annotated with `hints` for the Lean _elaborator_. -For example, we can say a binder is an _implicit argument_, and -must be inferred automatically by the elaborator. -These annotations are irrelevant from the kernel's point of view, -and they are just "propagated" by the Lean type checker. -The other annotations are explained later in the Section describing -the elaboration engine. - -```lua -local b = binder_info(true) -assert(is_binder_info(b)) -assert(b:is_implicit()) -local N = Const("N") -local f = Const("f") -local c1 = Local("c1", N, b) -local c2 = Local("c2", N) --- Create the expression --- fun {c1 : N} (c2 : N), (f c1 c2) --- In Lean, curly braces are used to denote --- implicit arguments -local l = Fun(c1, c2, f(c1, c2)) -local x, T, B, bi = l:data() -assert(x == name("c1")) -assert(T == N) -assert(B == Fun(c2, f(Var(1), c2))) -assert(bi:is_implicit()) -local y, T, C, bi2 = B:data() -assert(not bi2:is_implicit()) -``` diff --git a/doc/lua/md2lua.sh b/doc/lua/md2lua.sh deleted file mode 100755 index dd10fb7d5..000000000 --- a/doc/lua/md2lua.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/awk -f -BEGIN{ in_block = 0 } -!/```/{ if (in_block == 1) print $0; else print "" } -/```/{ in_block = 0; print "" } -/```lua/{ in_block = 1; print "" } diff --git a/doc/lua/test.sh b/doc/lua/test.sh deleted file mode 100755 index 22c3189f4..000000000 --- a/doc/lua/test.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# Test is all examples in the .md files are working -if [ $# -ne 1 ]; then - echo "Usage: test.sh [lean-executable-path]" - exit 1 -fi -ulimit -s unlimited -LEAN=$1 -NUM_ERRORS=0 -for f in `ls *.md`; do - echo "-- testing $f" - awk 'BEGIN{ in_block = 0 } !/```/{ if (in_block == 1) print $0; else print "" } /```/ && !/```lua/{ in_block = 0; print "" } /```lua/{ in_block = 1; print "" }' "$f" > "$f.lua" - if "$LEAN" "$f.lua" > "$f.produced.out"; then - echo "-- worked" - else - echo "ERROR executing $f.lua, produced output is at $f.produced.out" - NUM_ERRORS=$(($NUM_ERRORS+1)) - fi -done -if [ $NUM_ERRORS -gt 0 ]; then - echo "-- Number of errors: $NUM_ERRORS" - exit 1 -else - echo "-- Passed" - exit 0 -fi diff --git a/doc/lua/test_single.sh b/doc/lua/test_single.sh deleted file mode 100755 index c5d65b10c..000000000 --- a/doc/lua/test_single.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -# Test is all examples in the .md files are working -if [ $# -ne 2 ]; then - echo "Usage: test.sh [lean-executable-path] [file]" - exit 1 -fi -ulimit -s unlimited -LEAN=$1 -f=$2 -echo "-- testing $f" -awk 'BEGIN{ in_block = 0 } !/```/{ if (in_block == 1) print $0; else print "" } /```/ && !/```lua/{ in_block = 0; print "" } /```lua/{ in_block = 1; print "" }' "$f" > "$f.lua" -if "$LEAN" "$f.lua" > "$f.produced.out"; then - echo "-- worked" - exit 0 -else - echo "ERROR executing $f.lua, produced output:" - cat "$f.produced.out" - exit 1 -fi diff --git a/doc/lua/univ_poly.lua b/doc/lua/univ_poly.lua deleted file mode 100644 index f2b68a3c0..000000000 --- a/doc/lua/univ_poly.lua +++ /dev/null @@ -1,125 +0,0 @@ --- Given a term t that does not contain global universe levels, --- This procedure produces a new environment based on env, but --- without using universe polymorphism. The optional argument --- def_level is used to instantiate global universe levels used --- in the definitions t depends on. -function elim_univ_poly(env, t, def_level) - if not def_level then - -- If def_level is not provided, set it to universe 1. - def_level = level()+1 - end - - -- Create the new environment - local new_env = environment() - -- Already processed definitions - local map = rb_map() - - -- TODO(Leo): convert inductive datatypes. - - -- Return a new (based on n) that is not used in new_env - function mk_name(n) - local i = 1 - local r = n - while new_env:find(r) do - r = name(n, i) - i = i + 1 - end - return r - end - - -- Instantiate the declaration decl from env using the levels ls, - -- and add it to new_env. Return the name of this instance in new_env. - function process_declaration(decl, ls) - local new_name = mk_name(decl:name()) - local ps = decl:univ_params() - local new_type = process_expr(decl:type(), ps, ls) - local new_decl - if decl:is_axiom() then - new_decl = mk_axiom(new_name, new_type) - elseif decl:is_var_decl() then - new_decl = mk_var_decl(new_name, new_type) - else - local new_value = process_expr(decl:type(), ps, ls) - if decl:is_theorem() then - new_decl = mk_theorem(new_name, new_type, new_value) - else - -- TODO(Leo): expose update_declaration functions in the - -- Lua API. - local attrs = {opaque=decl:opaque(), - weight=decl:weight(), - module_idx=decl:module_idx(), - use_conv_opt=decl:use_conv_opt()} - new_decl = mk_definition(new_name, new_type, new_value, attrs) - end - end - new_env = add_decl(new_env, new_decl) - return new_name - end - - -- Convert a constant from env into a constant for new_env - function process_constant(e) - if e:is_constant() then - local n, ls = e:data() - local new_e = map:find(e) - if new_e then - -- constant was already mapped to new_env - return new_e - else - local decl = env:find(n) - if not decl then - error("undefined constant '" .. n .. "'") - end - local new_name = process_declaration(decl, ls) - local new_e = mk_constant(new_name) - map:insert(e, new_e) - return new_e - end - end - end - - -- Convert the expression e from env to new_env. - -- The universe level parameters ps are instantiated with - -- the explicit universe levels ls - function process_expr(e, ps, ls) - local new_e = e:instantiate_levels(ps, ls) - -- replace all constants occurring in new_env with the - -- corresponding ones from env - return new_e:replace(process_constant) - end - - -- Convert all constants occurring in t, and return the new environment. - local new_t = process_expr(t, {}, {}) - return new_env, new_t -end - -function display_env(env) - env:for_each(function(d) - print(tostring(d:name()) .. " : " .. tostring(d:type())) - end) -end - -function example1() - local env = environment() - local l = mk_param_univ("l") - local v = mk_param_univ("v") - local A = Local("A", mk_sort(l)) - local a = Local("a", A) - env = add_decl(env, mk_var_decl("eq", {l}, Pi(A, mk_arrow(A, A, Bool)))) - env = add_decl(env, mk_var_decl("group", {l}, mk_sort(l+1))) - env = add_decl(env, mk_var_decl("prod", {l, v}, mk_arrow(mk_sort(l), mk_sort(v), mk_sort(max_univ(l, v))))) - local eq2 = Const("eq", {2}) - local group1 = Const("group", {1}) - local group2 = Const("group", {2}) - local prod1 = Const("prod", {2, 3})(group1, group2) - env:type_check(prod1) -- Type check prod1 - local prod2 = Const("prod", {3, 0})(prod1, eq2(Type, Bool, Bool)) - env:type_check(prod2) -- Type check prod1 - - local new_env, new_prod2 = elim_univ_poly(env, prod2) - print("converted term: " .. tostring(new_prod2)) - print("converted environment: ") - display_env(new_env) - new_env:type_check(new_prod2) -end - -example1() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7018f3d40..ebab51520 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -269,27 +269,6 @@ if(NOT "${EMSCRIPTEN}" AND NOT "${TCMALLOC_FOUND}" AND NOT "${JEMALLOC_FOUND}" A endif() endif() -# Lua -find_package(Lua REQUIRED) -set(EXTRA_LIBS ${EXTRA_LIBS} ${LUA_LIBRARIES}) -if(NOT "${EMSCRIPTEN}" AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux") - # Lua static library for linux depends on dl.so - set(EXTRA_LIBS ${EXTRA_LIBS} -ldl) -endif() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I ${LUA_INCLUDE_DIR}") -if (HAS_LUA_NEWSTATE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D LEAN_USE_LUA_NEWSTATE") -endif() - -IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND ${LUA_FOUND} AND - "${LUA_INCLUDE_DIR}" MATCHES "jit") - # http://luajit.org/install.html - # If you're building a 64 bit application on OSX which links - # directly or indirectly against LuaJIT, you need to link your main - # executable with these flags: - set(LEAN_EXTRA_LINKER_FLAGS "${LEAN_EXTRA_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000") -ENDIF() - # Python find_package(PythonInterp REQUIRED) @@ -375,8 +354,6 @@ add_subdirectory(compiler) set(LEAN_OBJS ${LEAN_OBJS} $) add_subdirectory(frontends/lean) set(LEAN_OBJS ${LEAN_OBJS} $) -add_subdirectory(frontends/lua) -set(LEAN_OBJS ${LEAN_OBJS} $) add_subdirectory(init) set(LEAN_OBJS ${LEAN_OBJS} $) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LEAN_EXTRA_LINKER_FLAGS}") @@ -556,7 +533,7 @@ endif() if(STATIC) SET(CPACK_DEBIAN_PACKAGE_DEPENDS "python") else() - SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++-4.8-dev,libgmp-dev,libmpfr-dev,liblua5.2-dev,python") + SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++-4.8-dev,libgmp-dev,libmpfr-dev,python") endif() SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Lean Theorem Prover") SET(CPACK_DEBIAN_PACKAGE_SECTION "devel") diff --git a/src/cmake/Modules/CheckLuaNewstate.cc b/src/cmake/Modules/CheckLuaNewstate.cc deleted file mode 100644 index 784c2714f..000000000 --- a/src/cmake/Modules/CheckLuaNewstate.cc +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright (c) 2013 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include -#include -#include -#include - -static void * lua_realloc(void *, void * q, size_t, size_t sz) { return realloc(q, sz); } - -// Little program for checking whether lua_newstate is available -int main() { - lua_State * L; - L = lua_newstate(lua_realloc, 0); - lua_close(L); - return 0; -} diff --git a/src/cmake/Modules/FindLua.cmake b/src/cmake/Modules/FindLua.cmake deleted file mode 100644 index 62448fc08..000000000 --- a/src/cmake/Modules/FindLua.cmake +++ /dev/null @@ -1,137 +0,0 @@ -# Locate Lua library -# This module defines -# LUA_EXECUTABLE, if found -# LUA_FOUND, if false, do not try to link to Lua -# LUA_LIBRARIES -# LUA_INCLUDE_DIR, where to find lua.h -# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) -# -# Note that the expected include convention is -# #include "lua.h" -# and not -# #include -# This is because, the lua location is not standardized and may exist -# in locations other than lua/ - -#============================================================================= -# Copyright 2007-2009 Kitware, Inc. -# Modified to support Lua 5.2 by LuaDist 2012 -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) -# -# The required version of Lua can be specified using the -# standard syntax, e.g. FIND_PACKAGE(Lua 5.1) -# Otherwise the module will search for any available Lua implementation - -# Always search for non-versioned lua first (recommended) -SET(_POSSIBLE_LUA_INCLUDE include include/lua) -SET(_POSSIBLE_LUA_EXECUTABLE lua) -SET(_POSSIBLE_LUA_LIBRARY lua) - -# Determine possible naming suffixes (there is no standard for this) -IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) - SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}") -ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) - SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1" "jit-2.0" "jit-5.1") -ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) - -# Set up possible search names and locations -FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES}) - LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}") - LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}") - LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}") -ENDFOREACH(_SUFFIX) - -# Find the lua executable -FIND_PROGRAM(LUA_EXECUTABLE - NAMES ${_POSSIBLE_LUA_EXECUTABLE} -) - -# Find the lua header -FIND_PATH(LUA_INCLUDE_DIR lua.h - HINTS - $ENV{LUA_DIR} - PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE} - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw # Fink - /opt/local # DarwinPorts - /opt/csw # Blastwave - /opt -) - -# Find the lua library -FIND_LIBRARY(LUA_LIBRARY - NAMES ${_POSSIBLE_LUA_LIBRARY} - HINTS - $ENV{LUA_DIR} - PATH_SUFFIXES lib64 lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw - /opt/local - /opt/csw - /opt -) - -IF(LUA_LIBRARY) - # include the math library for Unix - IF(UNIX AND NOT APPLE) - FIND_LIBRARY(LUA_MATH_LIBRARY m) - SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") - # For Windows and Mac, don't need to explicitly include the math library - ELSE(UNIX AND NOT APPLE) - SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") - ENDIF(UNIX AND NOT APPLE) -ENDIF(LUA_LIBRARY) - -# Determine Lua version -IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") - FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") - - STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") - UNSET(lua_version_str) -ENDIF() - -INCLUDE(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if -# all listed variables are TRUE -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua - REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR - VERSION_VAR LUA_VERSION_STRING) - -MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE) - -# Print out version number -if (LUA_FOUND) - if (CMAKE_CROSSCOMPILING) - message(STATUS "Cross-compiling: can't find whether lua_objlen or lua_newstate is available.") - else() - try_run(LUA_CHECK LUA_CHECK_BUILD - ${LEAN_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp - ${LEAN_SOURCE_DIR}/cmake/Modules/CheckLuaNewstate.cc - CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${LUA_INCLUDE_DIR} - -DLINK_LIBRARIES=${LUA_LIBRARIES} - RUN_OUTPUT_VARIABLE LUA_TRY_OUT) - if ("${LUA_CHECK}" MATCHES "0" AND "${LUA_CHECK_BUILD}$" MATCHES "TRUE") - message(STATUS "lua_newstate works") - set(HAS_LUA_NEWSTATE TRUE) - else() - message(STATUS "lua_newstate is not supported by your Lua engine, Lean will not be able to track memory consumed by the Lua engine") - endif() - endif() -endif () diff --git a/src/frontends/lean/CMakeLists.txt b/src/frontends/lean/CMakeLists.txt index cbffcf592..129ca2be8 100644 --- a/src/frontends/lean/CMakeLists.txt +++ b/src/frontends/lean/CMakeLists.txt @@ -1,8 +1,8 @@ -add_library(lean_frontend OBJECT tokens.cpp register_module.cpp +add_library(lean_frontend OBJECT tokens.cpp token_table.cpp scanner.cpp parse_table.cpp parser_config.cpp parser.cpp parser_pos_provider.cpp builtin_cmds.cpp builtin_exprs.cpp server.cpp notation_cmd.cpp calc.cpp decl_cmds.cpp util.cpp -inductive_cmd.cpp elaborator.cpp dependencies.cpp parser_bindings.cpp +inductive_cmd.cpp elaborator.cpp dependencies.cpp begin_end_ext.cpp tactic_hint.cpp pp.cpp theorem_queue.cpp structure_cmd.cpp info_manager.cpp info_annotation.cpp find_cmd.cpp coercion_elaborator.cpp info_tactic.cpp diff --git a/src/frontends/lean/notation_cmd.cpp b/src/frontends/lean/notation_cmd.cpp index 7bb0d3605..324a1c64d 100644 --- a/src/frontends/lean/notation_cmd.cpp +++ b/src/frontends/lean/notation_cmd.cpp @@ -87,7 +87,6 @@ using notation::mk_binders_action; using notation::mk_exprs_action; using notation::mk_scoped_expr_action; using notation::mk_skip_action; -using notation::mk_ext_lua_action; using notation::transition; using notation::action; @@ -354,10 +353,6 @@ static action parse_action(parser & p, name const & prev_token, unsigned default } else if (p.curr_is_token_or_id(get_prev_tk())) { p.next(); return mk_expr_action(get_precedence(p.env(), new_tokens, prev_token)); - } else if (p.curr_is_string()) { - std::string fn = p.get_str_val(); - p.next(); - return mk_ext_lua_action(fn.c_str()); } else if (p.curr_is_token_or_id(get_scoped_tk())) { p.next(); return mk_scoped_expr_action(mk_var(0)); @@ -401,11 +396,6 @@ static action parse_action(parser & p, name const & prev_token, unsigned default } p.check_token_next(get_rparen_tk(), "invalid scoped notation argument, ')' expected"); return mk_scoped_expr_action(rec, prec ? *prec : 0); - } else if (p.curr_is_token_or_id(get_call_tk())) { - p.next(); - name fn = p.check_id_next("invalid call notation argument, identifier expected"); - p.check_token_next(get_rparen_tk(), "invalid call notation argument, ')' expected"); - return mk_ext_lua_action(fn.to_string().c_str()); } else { throw parser_error("invalid notation declaration, 'foldl', 'foldr' or 'scoped' expected", p.pos()); } @@ -568,7 +558,7 @@ static notation_entry parse_notation_core(parser & p, bool overload, notation_en ts.push_back(transition(tk, a, pp_tk)); break; case notation::action_kind::Expr: case notation::action_kind::Exprs: case notation::action_kind::ScopedExpr: - case notation::action_kind::Ext: case notation::action_kind::LuaExt: { + case notation::action_kind::Ext: { if (g_allow_local && !p.curr_is_identifier()) { ts.push_back(parse_transition(p, pt, tk, locals, new_tokens, grp, pp_tk)); break; diff --git a/src/frontends/lean/parse_table.cpp b/src/frontends/lean/parse_table.cpp index a93fcef15..513e3b4e2 100644 --- a/src/frontends/lean/parse_table.cpp +++ b/src/frontends/lean/parse_table.cpp @@ -10,7 +10,6 @@ Author: Leonardo de Moura #include "util/sstream.h" #include "kernel/free_vars.h" #include "kernel/replace_fn.h" -#include "library/kernel_bindings.h" #include "library/io_state_stream.h" #include "library/tactic/expr_to_tactic.h" #include "frontends/lean/parse_table.h" @@ -119,12 +118,6 @@ struct ext_action_cell : public action_cell { action_cell(action_kind::Ext), m_parse_fn(fn) {} }; -struct ext_lua_action_cell : public action_cell { - std::string m_lua_fn; - ext_lua_action_cell(char const * fn): - action_cell(action_kind::LuaExt), m_lua_fn(fn) {} -}; - action::action(action_cell * ptr):m_ptr(ptr) { lean_assert(ptr); } action::action():action(mk_skip_action()) {} action::action(action const & s):m_ptr(s.m_ptr) { if (m_ptr) m_ptr->inc_ref(); } @@ -150,10 +143,6 @@ ext_action_cell * to_ext_action(action_cell * c) { lean_assert(c->m_kind == action_kind::Ext); return static_cast(c); } -ext_lua_action_cell * to_ext_lua_action(action_cell * c) { - lean_assert(c->m_kind == action_kind::LuaExt); - return static_cast(c); -} unsigned action::rbp() const { return to_expr_action(m_ptr)->m_rbp; } name const & action::get_sep() const { return to_exprs_action(m_ptr)->m_token_sep; } optional const & action::get_terminator() const { return to_exprs_action(m_ptr)->m_terminator; } @@ -167,7 +156,6 @@ bool action::use_lambda_abstraction() const { return to_scoped_expr_action(m_ptr optional const & action::get_initial() const { return to_exprs_action(m_ptr)->m_ini; } bool action::is_fold_right() const { return to_exprs_action(m_ptr)->m_fold_right; } parse_fn const & action::get_parse_fn() const { return to_ext_action(m_ptr)->m_parse_fn; } -std::string const & action::get_lua_fn() const { return to_ext_lua_action(m_ptr)->m_lua_fn; } bool action::is_equal(action const & a) const { if (kind() != a.kind()) return false; @@ -178,8 +166,6 @@ bool action::is_equal(action const & a) const { return rbp() == a.rbp(); case action_kind::Ext: return m_ptr == a.m_ptr; - case action_kind::LuaExt: - return get_lua_fn() == a.get_lua_fn(); case action_kind::Exprs: return rbp() == a.rbp() && @@ -241,7 +227,6 @@ void action::display(io_state_stream & out) const { out << "binders"; break; case action_kind::Ext: out << "builtin"; break; - case action_kind::LuaExt: out << "luaext"; break; case action_kind::Expr: out << rbp(); break; case action_kind::Exprs: out << "(fold" << (is_fold_right() ? "r" : "l"); @@ -257,8 +242,9 @@ void action::display(io_state_stream & out) const { break; } } + bool action::is_simple() const { - return kind() != action_kind::Ext && kind() != action_kind::LuaExt; + return kind() != action_kind::Ext; } void action_cell::dealloc() { @@ -269,7 +255,6 @@ void action_cell::dealloc() { case action_kind::Exprs: delete(to_exprs_action(this)); break; case action_kind::ScopedExpr: delete(to_scoped_expr_action(this)); break; case action_kind::Ext: delete(to_ext_action(this)); break; - case action_kind::LuaExt: delete(to_ext_lua_action(this)); break; default: delete this; break; } } @@ -310,12 +295,10 @@ action mk_ext_action(parse_fn const & fn) { return action(new ext_action_cell(new_fn)); } -action mk_ext_lua_action(char const * fn) { return action(new ext_lua_action_cell(fn)); } - action replace(action const & a, std::function const & f) { switch (a.kind()) { case action_kind::Skip: case action_kind::Binder: case action_kind::Binders: - case action_kind::Ext: case action_kind::LuaExt: case action_kind::Expr: + case action_kind::Ext: case action_kind::Expr: return a; case action_kind::Exprs: return mk_exprs_action(a.get_sep(), f(a.get_rec()), a.get_initial() ? some_expr(f(*a.get_initial())) : none_expr(), a.get_terminator(), @@ -371,7 +354,7 @@ static void validate_transitions(bool nud, unsigned num, transition const * ts, case action_kind::Binder: case action_kind::Binders: found_binder = true; break; - case action_kind::Expr: case action_kind::Exprs: case action_kind::Ext: case action_kind::LuaExt: + case action_kind::Expr: case action_kind::Exprs: case action_kind::Ext: nargs++; break; case action_kind::ScopedExpr: @@ -478,7 +461,7 @@ static expr expand_pp_pattern(unsigned num, transition const * ts, expr const & switch (act.kind()) { case action_kind::Binder: case action_kind::Binders: case action_kind::Skip: break; - case action_kind::Ext: case action_kind::LuaExt: + case action_kind::Ext: lean_unreachable(); case action_kind::Expr: if (vidx == 0) return none_expr(); @@ -602,214 +585,4 @@ void parse_table::display(io_state_stream & out, optional const & t ::lean::notation::display(out, num, ts, es, is_nud(), tt); }); } - -typedef action notation_action; -DECL_UDATA(notation_action) - -static int mk_skip_action(lua_State * L) { return push_notation_action(L, mk_skip_action()); } -static int mk_binder_action(lua_State * L) { return push_notation_action(L, mk_binder_action()); } -static int mk_binders_action(lua_State * L) { return push_notation_action(L, mk_binders_action()); } -static int mk_expr_action(lua_State * L) { - int nargs = lua_gettop(L); - unsigned rbp = nargs == 0 ? 0 : lua_tonumber(L, 1); - return push_notation_action(L, mk_expr_action(rbp)); -} -static int mk_exprs_action(lua_State * L) { - int nargs = lua_gettop(L); - unsigned rbp = nargs <= 5 ? 0 : lua_tonumber(L, 6); - optional terminator; - if (nargs >= 4) terminator = to_optional_name(L, 4); - return push_notation_action(L, mk_exprs_action(to_name_ext(L, 1), - to_expr(L, 2), - lua_isnil(L, 3) ? none_expr() : some_expr(to_expr(L, 3)), - terminator, - lua_toboolean(L, 5), - rbp)); -} -static int mk_scoped_expr_action(lua_State * L) { - int nargs = lua_gettop(L); - unsigned rbp = nargs <= 1 ? 0 : lua_tonumber(L, 2); - bool lambda = (nargs <= 2) || lua_toboolean(L, 3); - return push_notation_action(L, mk_scoped_expr_action(to_expr(L, 1), rbp, lambda)); -} -static int mk_ext_lua_action(lua_State * L) { - char const * fn = lua_tostring(L, 1); - lua_getglobal(L, fn); - if (lua_isnil(L, -1)) - throw exception("arg #1 is a unknown function name"); - lua_pop(L, 1); - return push_notation_action(L, mk_ext_lua_action(fn)); -} -static int is_equal(lua_State * L) { - return push_boolean(L, to_notation_action(L, 1).is_equal(to_notation_action(L, 2))); -} -static void check_action(lua_State * L, int idx, std::initializer_list const & ks) { - action_kind k = to_notation_action(L, idx).kind(); - if (std::find(ks.begin(), ks.end(), k) == ks.end()) - throw exception(sstream() << "arg #" << idx << " is a notation action, but it has an unexpected kind"); -} -static int kind(lua_State * L) { return push_integer(L, static_cast(to_notation_action(L, 1).kind())); } -static int rbp(lua_State * L) { - check_action(L, 1, { action_kind::Expr, action_kind::Exprs, action_kind::ScopedExpr }); - return push_integer(L, to_notation_action(L, 1).rbp()); -} -static int sep(lua_State * L) { - check_action(L, 1, { action_kind::Exprs }); - return push_name(L, to_notation_action(L, 1).get_sep()); -} -static int rec(lua_State * L) { - check_action(L, 1, { action_kind::Exprs, action_kind::ScopedExpr }); - return push_expr(L, to_notation_action(L, 1).get_rec()); -} -static int initial(lua_State * L) { - check_action(L, 1, { action_kind::Exprs }); - return push_optional_expr(L, to_notation_action(L, 1).get_initial()); -} -static int is_fold_right(lua_State * L) { - check_action(L, 1, { action_kind::Exprs }); - return push_boolean(L, to_notation_action(L, 1).is_fold_right()); -} -static int use_lambda_abstraction(lua_State * L) { - check_action(L, 1, { action_kind::ScopedExpr }); - return push_boolean(L, to_notation_action(L, 1).use_lambda_abstraction()); -} -static int fn(lua_State * L) { - check_action(L, 1, { action_kind::LuaExt }); - return push_string(L, to_notation_action(L, 1).get_lua_fn().c_str()); -} - -static const struct luaL_Reg notation_action_m[] = { - {"__gc", notation_action_gc}, - {"is_equal", safe_function}, - {"kind", safe_function}, - {"rbp", safe_function}, - {"sep", safe_function}, - {"separator", safe_function}, - {"rec", safe_function}, - {"initial", safe_function}, - {"is_fold_right", safe_function}, - {"use_lambda_abstraction", safe_function}, - {"fn", safe_function}, - {0, 0} -}; - -static void open_notation_action(lua_State * L) { - luaL_newmetatable(L, notation_action_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, notation_action_m, 0); - - SET_GLOBAL_FUN(notation_action_pred, "is_notation_action"); - SET_GLOBAL_FUN(mk_skip_action, "skip_notation_action"); - SET_GLOBAL_FUN(mk_binder_action, "binder_notation_action"); - SET_GLOBAL_FUN(mk_binders_action, "binders_notation_action"); - SET_GLOBAL_FUN(mk_expr_action, "expr_notation_action"); - SET_GLOBAL_FUN(mk_exprs_action, "exprs_notation_action"); - SET_GLOBAL_FUN(mk_scoped_expr_action, "scoped_expr_notation_action"); - SET_GLOBAL_FUN(mk_ext_lua_action, "ext_action"); - - push_notation_action(L, mk_skip_action()); - lua_setglobal(L, "Skip"); - push_notation_action(L, mk_binder_action()); - lua_setglobal(L, "Binder"); - push_notation_action(L, mk_binders_action()); - lua_setglobal(L, "Binders"); - - lua_newtable(L); - SET_ENUM("Skip", action_kind::Skip); - SET_ENUM("Expr", action_kind::Expr); - SET_ENUM("Exprs", action_kind::Exprs); - SET_ENUM("Binder", action_kind::Binder); - SET_ENUM("Binders", action_kind::Binders); - SET_ENUM("ScopedExpr", action_kind::ScopedExpr); - SET_ENUM("Ext", action_kind::Ext); - SET_ENUM("LuaExt", action_kind::LuaExt); - lua_setglobal(L, "notation_action_kind"); -} - -static notation_action to_notation_action_ext(lua_State * L, int idx) { - if (is_notation_action(L, idx)) { - return to_notation_action(L, idx); - } else if (lua_isnumber(L, idx)) { - return mk_expr_action(lua_tonumber(L, idx)); - } else { - throw exception("notation_action expected"); - } -} - -DECL_UDATA(parse_table) -static int mk_parse_table(lua_State * L) { - int nargs = lua_gettop(L); - bool nud = nargs == 0 || lua_toboolean(L, 1); - return push_parse_table(L, parse_table(nud)); -} -static int add(lua_State * L) { - int nargs = lua_gettop(L); - buffer ts; - luaL_checktype(L, 2, LUA_TTABLE); - int sz = objlen(L, 2); - for (int i = 1; i <= sz; i++) { - lua_rawgeti(L, 2, i); - if (lua_isstring(L, -1) || is_name(L, -1)) { - ts.push_back(transition(to_name_ext(L, -1), mk_expr_action())); - lua_pop(L, 1); - } else { - luaL_checktype(L, -1, LUA_TTABLE); - lua_rawgeti(L, -1, 1); - lua_rawgeti(L, -2, 2); - ts.push_back(transition(to_name_ext(L, -2), to_notation_action_ext(L, -1))); - lua_pop(L, 3); - } - } - bool overload = (nargs <= 3) || lua_toboolean(L, 4); - return push_parse_table(L, to_parse_table(L, 1).add(ts.size(), ts.data(), to_expr(L, 3), LEAN_DEFAULT_NOTATION_PRIORITY, - overload)); -} - -static int merge(lua_State * L) { - int nargs = lua_gettop(L); - bool overload = (nargs >= 2) && lua_toboolean(L, 2); - return push_parse_table(L, to_parse_table(L, 1).merge(to_parse_table(L, 2), overload)); -} - -static int find(lua_State * L) { - list> it = to_parse_table(L, 1).find(to_name_ext(L, 2)); - if (it) { - // TODO(Leo): support multiple actions - auto p = head(it); - push_notation_action(L, p.first.get_action()); - push_parse_table(L, p.second); - return 2; - } else { - return push_nil(L); - } -} - -static int is_nud(lua_State * L) { - return push_boolean(L, to_parse_table(L, 1).is_nud()); -} - -static const struct luaL_Reg parse_table_m[] = { - {"__gc", parse_table_gc}, - {"add", safe_function}, - {"merge", safe_function}, - {"find", safe_function}, - {"is_nud", safe_function}, - {0, 0} -}; - -static void open_parse_table(lua_State * L) { - luaL_newmetatable(L, parse_table_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, parse_table_m, 0); - - SET_GLOBAL_FUN(parse_table_pred, "is_parse_table"); - SET_GLOBAL_FUN(mk_parse_table, "parse_table"); -} -} -void open_parse_table(lua_State * L) { - notation::open_notation_action(L); - notation::open_parse_table(L); -} -} +}} diff --git a/src/frontends/lean/parse_table.h b/src/frontends/lean/parse_table.h index 3b6785775..ddb3dd6af 100644 --- a/src/frontends/lean/parse_table.h +++ b/src/frontends/lean/parse_table.h @@ -8,7 +8,6 @@ Author: Leonardo de Moura #include #include #include "util/buffer.h" -#include "util/lua.h" #include "kernel/expr.h" #include "library/head_map.h" #include "frontends/lean/token_table.h" @@ -24,7 +23,7 @@ class io_state_stream; namespace notation { typedef std::function parse_fn; -enum class action_kind { Skip, Expr, Exprs, Binder, Binders, ScopedExpr, Ext, LuaExt }; +enum class action_kind { Skip, Expr, Exprs, Binder, Binders, ScopedExpr, Ext }; struct action_cell; /** @@ -72,7 +71,6 @@ public: friend action mk_scoped_expr_action(expr const & rec, unsigned rbp, bool lambda); friend action mk_ext_action_core(parse_fn const & fn); friend action mk_ext_action(parse_fn const & fn); - friend action mk_ext_lua_action(char const * lua_fn); action_kind kind() const; unsigned rbp() const; @@ -83,7 +81,6 @@ public: bool is_fold_right() const; bool use_lambda_abstraction() const; parse_fn const & get_parse_fn() const; - std::string const & get_lua_fn() const; bool is_equal(action const & a) const; bool is_equivalent(action const & a) const; @@ -92,7 +89,7 @@ public: void display(io_state_stream & out) const; - /** \brief Return true iff the action is not Ext or LuaExt */ + /** \brief Return true iff the action is not Ext */ bool is_simple() const; }; inline bool operator==(action const & a1, action const & a2) { return a1.is_equal(a2); } @@ -107,7 +104,6 @@ action mk_binders_action(unsigned rbp = 0); action mk_scoped_expr_action(expr const & rec, unsigned rbp = 0, bool lambda = true); action mk_ext_action_core(parse_fn const & fn); action mk_ext_action(parse_fn const & fn); -action mk_ext_lua_action(char const * lua_fn); /** \brief Apply \c f to expressions embedded in the given action */ action replace(action const & a, std::function const & f); @@ -185,7 +181,7 @@ public: /** \brief Given a notation definition, return the "head symbol" of every instance of the given notation. - \remark The result is none if the notation uses actions implemented in C++ or Lua. + \remark The result is none if the notation uses actions implemented in C++. The result is none if the denotation is a variable. */ optional get_head_index(unsigned num, transition const * ts, expr const & a); @@ -194,7 +190,6 @@ void initialize_parse_table(); void finalize_parse_table(); } typedef notation::parse_table parse_table; -void open_parse_table(lua_State * L); inline void initialize_parse_table() { notation::initialize_parse_table(); } inline void finalize_parse_table() { notation::finalize_parse_table(); } } diff --git a/src/frontends/lean/parser.cpp b/src/frontends/lean/parser.cpp index 26679f6d1..9e32dd8c4 100644 --- a/src/frontends/lean/parser.cpp +++ b/src/frontends/lean/parser.cpp @@ -10,7 +10,6 @@ Author: Leonardo de Moura #include #include #include "util/interrupt.h" -#include "util/script_exception.h" #include "util/sstream.h" #include "util/flet.h" #include "util/lean_path.h" @@ -47,7 +46,6 @@ Author: Leonardo de Moura #include "frontends/lean/tokens.h" #include "frontends/lean/parser.h" #include "frontends/lean/util.h" -#include "frontends/lean/parser_bindings.h" #include "frontends/lean/notation_cmd.h" #include "frontends/lean/elaborator.h" #include "frontends/lean/info_annotation.h" @@ -351,11 +349,6 @@ void parser::display_error(throwable const & ex) { ::lean::display_error(regular_stream(), &pos_provider, ex); } -void parser::display_error(script_exception const & ex) { - parser_pos_provider pos_provider(m_pos_table, get_stream_name(), m_last_script_pos); - ::lean::display_error(regular_stream(), &pos_provider, ex); -} - void parser::throw_parser_exception(char const * msg, pos_info p) { throw parser_exception(msg, get_stream_name().c_str(), p.first, p.second); } @@ -394,9 +387,6 @@ void parser::protected_call(std::function && f, std::function && sync(); if (m_use_exceptions || m_info_manager) throw; - } catch (script_exception & ex) { - reset_interrupt(); - CATCH(display_error(ex), throw_nested_exception(ex, m_last_script_pos)); } catch (throwable & ex) { reset_interrupt(); CATCH(display_error(ex), throw_nested_exception(ex, m_last_cmd_pos)); @@ -1406,28 +1396,6 @@ expr parser::parse_notation_core(parse_table t, expr * left, bool as_tactic) { scoped_info.push_back(mk_pair(ps.size(), binder_pos)); break; } - case notation::action_kind::LuaExt: - m_last_script_pos = p; - using_script([&](lua_State * L) { - scoped_set_parser scope(L, *this); - lua_getglobal(L, a.get_lua_fn().c_str()); - if (!lua_isfunction(L, -1)) - throw parser_error(sstream() << "failed to use notation implemented in Lua, " - << "Lua state does not contain function '" - << a.get_lua_fn() << "'", p); - lua_pushinteger(L, p.first); - lua_pushinteger(L, p.second); - for (unsigned i = 0; i < args.size(); i++) - push_expr(L, args[i]); - pcall(L, args.size() + 2, 1, 0); - if (!is_expr(L, -1)) - throw parser_error(sstream() << "failed to use notation implemented in Lua, value returned by function '" - << a.get_lua_fn() << "' is not an expression", p); - args.push_back(rec_save_pos(to_expr(L, -1), p)); - kinds.push_back(a.kind()); - lua_pop(L, 1); - }); - break; case notation::action_kind::Ext: args.push_back(a.get_parse_fn()(*this, args.size(), args.data(), p)); kinds.push_back(a.kind()); @@ -2091,25 +2059,6 @@ void parser::parse_command() { } } -void parser::parse_script(bool as_expr) { - m_last_script_pos = pos(); - std::string script_code = m_scanner.get_str_val(); - if (as_expr) - script_code = "return " + script_code; - next(); - using_script([&](lua_State * L) { - dostring(L, script_code.c_str()); - }); -} - -static optional try_file(name const & f, char const * ext) { - try { - return optional(find_file(f, {ext})); - } catch (...) { - return optional(); - } -} - static optional try_file(std::string const & base, optional const & k, name const & f, char const * ext) { try { return optional(find_file(base, k, f, ext)); @@ -2118,22 +2067,8 @@ static optional try_file(std::string const & base, optional &, - std::function & add_delayed_update) { - name fname; - d >> fname; - add_delayed_update([=](environment const & env, io_state const &) -> environment { - std::string rname = find_file(fname, {".lua"}); - system_import(rname.c_str()); - return env; - }); -} - void parser::parse_imports() { buffer olean_files; - buffer lua_files; bool prelude = false; std::string base = m_base_dir ? *m_base_dir : dirname(get_stream_name().c_str()); bool imported = false; @@ -2188,14 +2123,7 @@ void parser::parse_imports() { fingerprint = hash(fingerprint, f.hash()); if (k) fingerprint = hash(fingerprint, *k); - if (auto it = try_file(f, ".lua")) { - if (k) - throw parser_error(sstream() << "invalid import, failed to import '" << f - << "', relative paths are not supported for .lua files", pos()); - lua_files.push_back(f); - } else { - import_olean(k, f); - } + import_olean(k, f); next(); } } @@ -2206,13 +2134,6 @@ void parser::parse_imports() { m_env = import_modules(m_env, base, olean_files.size(), olean_files.data(), num_threads, keep_imported_thms, m_ios); m_env = update_fingerprint(m_env, fingerprint); - for (auto const & f : lua_files) { - std::string rname = find_file(f, {".lua"}); - system_import(rname.c_str()); - m_env = module::add(m_env, *g_lua_module_key, [=](environment const &, serializer & s) { - s << f; - }); - } if (imported) commit_info(1, 0); } @@ -2258,10 +2179,6 @@ bool parser::parse_commands() { parse_command(); commit_info(); break; - case scanner::token_kind::ScriptBlock: - parse_script(); - save_snapshot(); - break; case scanner::token_kind::Eof: done = true; break; @@ -2463,14 +2380,11 @@ void initialize_parser() { register_bool_option(*g_parser_parallel_import, LEAN_DEFAULT_PARSER_PARALLEL_IMPORT, "(lean parser) import modules in parallel"); g_tmp_prefix = new name(name::mk_internal_unique_name()); - g_lua_module_key = new std::string("lua_module"); - register_module_object_reader(*g_lua_module_key, lua_module_reader); g_anonymous_inst_name_prefix = new name("_inst"); } void finalize_parser() { delete g_anonymous_inst_name_prefix; - delete g_lua_module_key; delete g_tmp_prefix; delete g_parser_show_errors; delete g_parser_parallel_import; diff --git a/src/frontends/lean/parser.h b/src/frontends/lean/parser.h index 4181303cb..191e42514 100644 --- a/src/frontends/lean/parser.h +++ b/src/frontends/lean/parser.h @@ -9,17 +9,13 @@ Author: Leonardo de Moura #include #include #include "util/flet.h" -#include "util/script_state.h" #include "util/name_map.h" #include "util/exception.h" -#include "util/thread_script_state.h" -#include "util/script_exception.h" #include "util/name_generator.h" #include "kernel/environment.h" #include "kernel/expr_maps.h" #include "library/io_state.h" #include "library/io_state_stream.h" -#include "library/kernel_bindings.h" #include "library/definition_cache.h" #include "library/declaration_index.h" #include "frontends/lean/scanner.h" @@ -110,7 +106,6 @@ class parser { name_set m_include_vars; // subset of m_local_decls that is marked as include parser_scope_stack m_parser_scope_stack; pos_info m_last_cmd_pos; - pos_info m_last_script_pos; unsigned m_next_tag_idx; unsigned m_next_inst_idx; bool m_found_errors; @@ -166,23 +161,11 @@ class parser { void display_error_pos(pos_info p); void display_error(char const * msg, unsigned line, unsigned pos); void display_error(char const * msg, pos_info p); - void display_error(script_exception const & ex); void throw_parser_exception(char const * msg, pos_info p); void throw_nested_exception(throwable const & ex, pos_info p); void sync_command(); void protected_call(std::function && f, std::function && sync); - template - typename std::result_of::type using_script(F && f) { - try { - script_state S = get_thread_script_state(); - set_io_state set1(S, m_ios); - set_environment set2(S, m_env); - return f(S.get_state()); - } catch (script_nested_exception & ex) { - ex.get_exception().rethrow(); - } - } tag get_tag(expr e); expr copy_with_new_pos(expr const & e, pos_info p); @@ -200,7 +183,6 @@ class parser { void parse_imports(); void parse_command(); - void parse_script(bool as_expr = false); bool parse_commands(); unsigned curr_lbp_core(bool as_tactic) const; void process_postponed(buffer const & args, bool is_left, buffer const & kinds, @@ -364,8 +346,6 @@ public: bool curr_is_keyword() const { return curr() == scanner::token_kind::Keyword; } /** \brief Return true iff the current token is a keyword */ bool curr_is_command() const { return curr() == scanner::token_kind::CommandKeyword; } - /** \brief Return true iff the current token is a Lua script block */ - bool curr_is_script_block() const { return curr() == scanner::token_kind::ScriptBlock; } /** \brief Return true iff the current token is EOF */ bool curr_is_eof() const { return curr() == scanner::token_kind::Eof; } /** \brief Return true iff the current token is a keyword */ diff --git a/src/frontends/lean/parser_bindings.cpp b/src/frontends/lean/parser_bindings.cpp deleted file mode 100644 index df34f14f5..000000000 --- a/src/frontends/lean/parser_bindings.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* -Copyright (c) 2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include -#include -#include "kernel/abstract.h" -#include "frontends/lean/parser_bindings.h" - -namespace lean { -static char g_parser_key; -void set_global_parser(lua_State * L, parser * p) { - lua_pushlightuserdata(L, static_cast(&g_parser_key)); - lua_pushlightuserdata(L, static_cast(p)); - lua_settable(L, LUA_REGISTRYINDEX); -} - -parser * get_global_parser_ptr(lua_State * L) { - lua_pushlightuserdata(L, static_cast(&g_parser_key)); - lua_gettable(L, LUA_REGISTRYINDEX); - if (!lua_islightuserdata(L, -1)) - return nullptr; - parser * p = static_cast(const_cast(lua_topointer(L, -1))); - lua_pop(L, 1); - return p; -} - -parser & get_global_parser(lua_State * L) { - parser * p = get_global_parser_ptr(L); - if (p == nullptr) - throw exception("there is no Lean parser on the Lua stack"); - return *p; -} - -scoped_set_parser::scoped_set_parser(lua_State * L, parser & p):m_state(L) { - m_old = get_global_parser_ptr(L); - set_global_parser(L, &p); -} -scoped_set_parser::~scoped_set_parser() { - set_global_parser(m_state, m_old); -} - -static unsigned to_rbp(lua_State * L, int idx) { - int nargs = lua_gettop(L); - return idx < nargs ? 0 : lua_tointeger(L, idx); -} - -typedef pair> local_scope_cell; -typedef std::shared_ptr local_scope; -DECL_UDATA(local_scope); -static const struct luaL_Reg local_scope_m[] = { - {"__gc", local_scope_gc}, - {0, 0} -}; -int push_local_scope_ext(lua_State * L, local_environment const & lenv, buffer const & ps) { - local_scope r = std::make_shared(); - r->first = lenv; - for (auto const & p : ps) - r->second.push_back(p); - return push_local_scope(L, r); -} - -static void open_local_scope(lua_State * L) { - luaL_newmetatable(L, local_scope_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, local_scope_m, 0); - - SET_GLOBAL_FUN(local_scope_pred, "is_local_scope"); -} - -#define gparser get_global_parser(L) - -static int parse_level(lua_State * L) { return push_level(L, gparser.parse_level(to_rbp(L, 1))); } -static int parse_expr(lua_State * L) { return push_expr(L, gparser.parse_expr(to_rbp(L, 1))); } -static int parse_led(lua_State * L) { return push_expr(L, gparser.parse_led(to_expr(L, 1))); } -static int parse_binders(lua_State * L) { - buffer ps; - unsigned rbp = 0; - auto lenv = gparser.parse_binders(ps, rbp); - return push_local_scope_ext(L, lenv, ps); -} -static int parse_binder(lua_State * L) { - buffer ps; - unsigned rbp = 0; - ps.push_back(gparser.parse_binder(rbp)); - return push_local_scope_ext(L, gparser.env(), ps); -} -static int parse_scoped_expr(lua_State * L) { - local_scope const & s = to_local_scope(L, 1); - unsigned rbp = to_rbp(L, 2); - return push_expr(L, gparser.parse_scoped_expr(s->second.size(), s->second.data(), s->first, rbp)); -} -static int lambda_abstract(lua_State * L) { - int nargs = lua_gettop(L); - local_scope const & s = to_local_scope(L, 1); - expr const & e = to_expr(L, 2); - expr r; - bool using_cache = false; - if (nargs == 2) - r = gparser.rec_save_pos(Fun(s->second.size(), s->second.data(), e, using_cache), gparser.pos_of(e)); - else - r = gparser.rec_save_pos(Fun(s->second.size(), s->second.data(), e, using_cache), pos_info(lua_tointeger(L, 3), lua_tointeger(L, 4))); - return push_expr(L, r); -} -static int next(lua_State * L) { gparser.next(); return 0; } -static int curr(lua_State * L) { return push_integer(L, static_cast(gparser.curr())); } -static int curr_is_token(lua_State * L) { return push_boolean(L, gparser.curr_is_token(to_name_ext(L, 1))); } -static int curr_is_token_or_id(lua_State * L) { return push_boolean(L, gparser.curr_is_token_or_id(to_name_ext(L, 1))); } -static int curr_is_identifier(lua_State * L) { return push_boolean(L, gparser.curr_is_identifier()); } -static int curr_is_numeral(lua_State * L) { return push_boolean(L, gparser.curr_is_numeral()); } -static int curr_is_string(lua_State * L) { return push_boolean(L, gparser.curr_is_string()); } -static int curr_is_keyword(lua_State * L) { return push_boolean(L, gparser.curr_is_keyword()); } -static int curr_is_command(lua_State * L) { return push_boolean(L, gparser.curr_is_command()); } -static int curr_is_quoted_symbol(lua_State * L) { return push_boolean(L, gparser.curr_is_quoted_symbol()); } -static int check_token_next(lua_State * L) { gparser.check_token_next(to_name_ext(L, 1), lua_tostring(L, 2)); return 0; } -static int check_id_next(lua_State * L) { return push_name(L, gparser.check_id_next(lua_tostring(L, 1))); } -static int pos(lua_State * L) { - auto pos = gparser.pos(); - push_integer(L, pos.first); - push_integer(L, pos.second); - return 2; -} -static int save_pos(lua_State * L) { - return push_expr(L, gparser.save_pos(to_expr(L, 1), pos_info(lua_tointeger(L, 2), lua_tointeger(L, 3)))); -} -static int pos_of(lua_State * L) { - int nargs = lua_gettop(L); - pos_info pos; - if (nargs == 1) - pos = gparser.pos_of(to_expr(L, 1)); - else - pos = gparser.pos_of(to_expr(L, 1), pos_info(lua_tointeger(L, 2), lua_tointeger(L, 3))); - push_integer(L, pos.first); - push_integer(L, pos.second); - return 2; -} -static int env(lua_State * L) { return push_environment(L, gparser.env()); } -static int ios(lua_State * L) { return push_io_state(L, gparser.ios()); } - -void open_parser(lua_State * L) { - open_local_scope(L); - - lua_newtable(L); - SET_FUN(parse_expr, "parse_expr"); - SET_FUN(parse_level, "parse_level"); - SET_FUN(parse_led, "parse_led"); - SET_FUN(parse_binders, "parse_binders"); - SET_FUN(parse_binder, "parse_binder"); - SET_FUN(parse_scoped_expr, "parse_scoped_expr"); - SET_FUN(lambda_abstract, "lambda_abstract"); - SET_FUN(lambda_abstract, "abstract"); - SET_FUN(next, "next"); - SET_FUN(curr, "curr"); - SET_FUN(curr_is_token, "curr_is_token"); - SET_FUN(curr_is_token_or_id, "curr_is_token_or_id"); - SET_FUN(curr_is_identifier, "curr_is_identifier"); - SET_FUN(curr_is_numeral, "curr_is_numeral"); - SET_FUN(curr_is_string, "curr_is_string"); - SET_FUN(curr_is_keyword, "curr_is_keyword"); - SET_FUN(curr_is_command, "curr_is_command"); - SET_FUN(curr_is_quoted_symbol, "curr_is_quoted_symbol"); - SET_FUN(check_token_next, "check_token_next"); - SET_FUN(check_id_next, "check_id_next"); - SET_FUN(pos, "pos"); - SET_FUN(save_pos, "save_pos"); - SET_FUN(pos_of, "pos_of"); - SET_FUN(env, "env"); - SET_FUN(ios, "ios"); - lua_setglobal(L, "parser"); - - lua_newtable(L); - SET_ENUM("Keyword", scanner::token_kind::Keyword); - SET_ENUM("CommandKeyword", scanner::token_kind::CommandKeyword); - SET_ENUM("ScriptBlock", scanner::token_kind::ScriptBlock); - SET_ENUM("Identifier", scanner::token_kind::Identifier); - SET_ENUM("Numeral", scanner::token_kind::Numeral); - SET_ENUM("Decimal", scanner::token_kind::Decimal); - SET_ENUM("String", scanner::token_kind::String); - SET_ENUM("QuotedSymbol", scanner::token_kind::QuotedSymbol); - lua_setglobal(L, "token_kind"); -} -} diff --git a/src/frontends/lean/parser_bindings.h b/src/frontends/lean/parser_bindings.h deleted file mode 100644 index 6e302f26a..000000000 --- a/src/frontends/lean/parser_bindings.h +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright (c) 2014 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/lua.h" -#include "frontends/lean/parser.h" -namespace lean { -struct scoped_set_parser { - lua_State * m_state; - parser * m_old; - scoped_set_parser(lua_State * L, parser & p); - ~scoped_set_parser(); -}; -void open_parser(lua_State * L); -} diff --git a/src/frontends/lean/parser_config.cpp b/src/frontends/lean/parser_config.cpp index 6930c1ffb..a45a78e18 100644 --- a/src/frontends/lean/parser_config.cpp +++ b/src/frontends/lean/parser_config.cpp @@ -154,9 +154,6 @@ serializer & operator<<(serializer & s, action const & a) { case action_kind::ScopedExpr: s << a.get_rec() << a.rbp() << a.use_lambda_abstraction(); break; - case action_kind::LuaExt: - s << a.get_lua_fn(); - break; case action_kind::Ext: lean_unreachable(); } @@ -195,8 +192,6 @@ action read_action(deserializer & d) { d >> rec >> rbp >> use_lambda_abstraction; return notation::mk_scoped_expr_action(rec, rbp, use_lambda_abstraction); } - case action_kind::LuaExt: - return notation::mk_ext_lua_action(d.read_string().c_str()); case action_kind::Ext: break; } diff --git a/src/frontends/lean/pp.cpp b/src/frontends/lean/pp.cpp index 084d9c903..3237e2908 100644 --- a/src/frontends/lean/pp.cpp +++ b/src/frontends/lean/pp.cpp @@ -879,7 +879,6 @@ static unsigned get_num_parameters(notation_entry const & entry) { case notation::action_kind::Exprs: case notation::action_kind::ScopedExpr: case notation::action_kind::Ext: - case notation::action_kind::LuaExt: r++; } } @@ -1166,7 +1165,6 @@ auto pretty_fn::pp_notation(notation_entry const & entry, buffer> break; } case notation::action_kind::Ext: - case notation::action_kind::LuaExt: return optional(); } token_lbp = get_some_precedence(m_token_table, tk); diff --git a/src/frontends/lean/register_module.cpp b/src/frontends/lean/register_module.cpp deleted file mode 100644 index daf156007..000000000 --- a/src/frontends/lean/register_module.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright (c) 2013-2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include -#include "util/lua.h" -#include "util/script_state.h" -#include "frontends/lean/token_table.h" -#include "frontends/lean/parse_table.h" -#include "frontends/lean/parser_bindings.h" - -namespace lean { - -void open_frontend_lean(lua_State * L) { - open_token_table(L); - open_parse_table(L); - open_parser(L); -} -void register_frontend_lean_module() { - script_state::register_module(open_frontend_lean); -} -} diff --git a/src/frontends/lean/register_module.h b/src/frontends/lean/register_module.h deleted file mode 100644 index c231e6daf..000000000 --- a/src/frontends/lean/register_module.h +++ /dev/null @@ -1,12 +0,0 @@ -/* -Copyright (c) 2013-2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#pragma once -#include -namespace lean { -void open_frontend_lean(lua_State * L); -void register_frontend_lean_module(); -} diff --git a/src/frontends/lean/token_table.cpp b/src/frontends/lean/token_table.cpp index 492283ab4..cea1da1e6 100644 --- a/src/frontends/lean/token_table.cpp +++ b/src/frontends/lean/token_table.cpp @@ -179,88 +179,4 @@ void finalize_token_table() { } token_table mk_token_table() { return token_table(); } - -DECL_UDATA(token_table) -static int mk_token_table(lua_State * L) { return push_token_table(L, mk_token_table()); } -static int mk_default_token_table(lua_State * L) { return push_token_table(L, mk_default_token_table()); } -static int add_command_token(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 2) - return push_token_table(L, add_command_token(to_token_table(L, 1), lua_tostring(L, 2))); - else - return push_token_table(L, add_command_token(to_token_table(L, 1), lua_tostring(L, 2), lua_tostring(L, 3))); -} -static int add_token(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 3) - return push_token_table(L, add_token(to_token_table(L, 1), lua_tostring(L, 2), lua_tonumber(L, 3))); - else - return push_token_table(L, add_token(to_token_table(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tonumber(L, 4))); -} -static int merge(lua_State * L) { - return push_token_table(L, merge(to_token_table(L, 1), to_token_table(L, 2))); -} -static int find(lua_State * L) { - char k; - if (lua_isnumber(L, 2)) { - k = lua_tonumber(L, 2); - } else { - char const * str = lua_tostring(L, 2); - if (strlen(str) != 1) - throw exception("arg #2 must be a string of length 1"); - k = str[0]; - } - auto it = to_token_table(L, 1).find(k); - if (it) - return push_token_table(L, *it); - else - return push_nil(L); -} -static int value_of(lua_State * L) { - auto it = value_of(to_token_table(L, 1)); - if (it) { - push_boolean(L, it->is_command()); - push_name(L, it->value()); - push_integer(L, it->expr_precedence()); - return 3; - } else { - push_nil(L); - return 1; - } -} -static int for_each(lua_State * L) { - token_table const & t = to_token_table(L, 1); - luaL_checktype(L, 2, LUA_TFUNCTION); // user-fun - for_each(t, [&](char const * k, token_info const & info) { - lua_pushvalue(L, 2); - lua_pushstring(L, k); - lua_pushboolean(L, info.is_command()); - push_name(L, info.value()); - lua_pushinteger(L, info.expr_precedence()); - pcall(L, 4, 0, 0); - }); - return 0; -} - -static const struct luaL_Reg token_table_m[] = { - {"__gc", token_table_gc}, - {"add_command_token", safe_function}, - {"add_token", safe_function}, - {"merge", safe_function}, - {"find", safe_function}, - {"value_of", safe_function}, - {"for_each", safe_function}, - {0, 0} -}; - -void open_token_table(lua_State * L) { - luaL_newmetatable(L, token_table_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, token_table_m, 0); - - SET_GLOBAL_FUN(token_table_pred, "is_token_table"); - SET_GLOBAL_FUN(mk_default_token_table, "default_token_table"); - SET_GLOBAL_FUN(mk_token_table, "token_table"); -} } diff --git a/src/frontends/lean/token_table.h b/src/frontends/lean/token_table.h index 6cbccf548..49ef9dc76 100644 --- a/src/frontends/lean/token_table.h +++ b/src/frontends/lean/token_table.h @@ -9,7 +9,6 @@ Author: Leonardo de Moura #include #include "util/trie.h" #include "util/name.h" -#include "util/lua.h" #ifndef LEAN_DEFAULT_PRECEDENCE #define LEAN_DEFAULT_PRECEDENCE 1 @@ -67,7 +66,6 @@ optional get_expr_precedence(token_table const & s, char const * token optional get_tactic_precedence(token_table const & s, char const * token); bool is_token(token_table const & s, char const * token); token_info const * value_of(token_table const & s); -void open_token_table(lua_State * L); void initialize_token_table(); void finalize_token_table(); } diff --git a/src/frontends/lean/tokens.txt b/src/frontends/lean/tokens.txt index 0981ec4db..c202502db 100644 --- a/src/frontends/lean/tokens.txt +++ b/src/frontends/lean/tokens.txt @@ -136,7 +136,6 @@ tactic_infixr tactic_infixr tactic_postfix tactic_postfix tactic_prefix tactic_prefix tactic_notation tactic_notation -call call calc calc obtain obtain root _root_ diff --git a/src/frontends/lean/util.cpp b/src/frontends/lean/util.cpp index 95fefcae0..6c4605b05 100644 --- a/src/frontends/lean/util.cpp +++ b/src/frontends/lean/util.cpp @@ -40,17 +40,15 @@ void consume_until_end(parser & p) { } void check_command_period_or_eof(parser const & p) { - if (!p.curr_is_command() && !p.curr_is_eof() && !p.curr_is_token(get_period_tk()) && - !p.curr_is_script_block()) - throw parser_error("unexpected token, '.', command, Lua script, or end-of-file expected", p.pos()); + if (!p.curr_is_command() && !p.curr_is_eof() && !p.curr_is_token(get_period_tk())) + throw parser_error("unexpected token, '.', command, or end-of-file expected", p.pos()); } void check_command_period_open_binder_or_eof(parser const & p) { if (!p.curr_is_command() && !p.curr_is_eof() && !p.curr_is_token(get_period_tk()) && - !p.curr_is_script_block() && !p.curr_is_token(get_lparen_tk()) && !p.curr_is_token(get_lbracket_tk()) && !p.curr_is_token(get_lcurly_tk()) && !p.curr_is_token(get_ldcurly_tk())) - throw parser_error("unexpected token, '(', '{', '[', '⦃', '.', command, Lua script, or end-of-file expected", p.pos()); + throw parser_error("unexpected token, '(', '{', '[', '⦃', '.', command, or end-of-file expected", p.pos()); } void check_atomic(name const & n) { diff --git a/src/frontends/lua/CMakeLists.txt b/src/frontends/lua/CMakeLists.txt deleted file mode 100644 index 94f82406e..000000000 --- a/src/frontends/lua/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_library(leanlua OBJECT register_modules.cpp) diff --git a/src/frontends/lua/register_modules.cpp b/src/frontends/lua/register_modules.cpp deleted file mode 100644 index b679fbd25..000000000 --- a/src/frontends/lua/register_modules.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* -Copyright (c) 2013-2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include "util/script_state.h" -#include "util/numerics/register_module.h" -#include "util/sexpr/register_module.h" -#include "library/register_module.h" -#include "library/tactic/register_module.h" -#include "frontends/lean/register_module.h" - -namespace lean { -void register_modules() { - register_numerics_module(); - register_sexpr_module(); - register_core_module(); - register_tactic_module(); - register_frontend_lean_module(); -} -} diff --git a/src/frontends/lua/register_modules.h b/src/frontends/lua/register_modules.h deleted file mode 100644 index 5a9355174..000000000 --- a/src/frontends/lua/register_modules.h +++ /dev/null @@ -1,13 +0,0 @@ -/* -Copyright (c) 2013 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#pragma once -namespace lean { -/** - \brief Register all modules at \c script_state. -*/ -void register_modules(); -} diff --git a/src/init/init.cpp b/src/init/init.cpp index 0ca99e8d8..c477adfbf 100644 --- a/src/init/init.cpp +++ b/src/init/init.cpp @@ -20,7 +20,6 @@ Author: Leonardo de Moura #include "library/print.h" #include "compiler/init_module.h" #include "frontends/lean/init_module.h" -#include "frontends/lua/register_modules.h" #include "init/init.h" namespace lean { @@ -40,7 +39,6 @@ void initialize() { initialize_definitional_module(); initialize_compiler_module(); initialize_frontend_lean_module(); - register_modules(); } void finalize() { run_thread_finalizers(); diff --git a/src/kernel/expr.h b/src/kernel/expr.h index df13ae595..a92e9b698 100644 --- a/src/kernel/expr.h +++ b/src/kernel/expr.h @@ -12,7 +12,6 @@ Author: Leonardo de Moura #include #include #include "util/thread.h" -#include "util/lua.h" #include "util/rc.h" #include "util/name.h" #include "util/hash.h" diff --git a/src/library/CMakeLists.txt b/src/library/CMakeLists.txt index 68c1eaf6a..55dba5603 100644 --- a/src/library/CMakeLists.txt +++ b/src/library/CMakeLists.txt @@ -1,5 +1,5 @@ add_library(library OBJECT deep_copy.cpp expr_lt.cpp io_state.cpp - occurs.cpp kernel_bindings.cpp io_state_stream.cpp bin_app.cpp + occurs.cpp io_state_stream.cpp bin_app.cpp constants.cpp resolve_macro.cpp kernel_serializer.cpp max_sharing.cpp normalize.cpp shared_environment.cpp module.cpp coercion.cpp private.cpp placeholder.cpp aliases.cpp level_names.cpp diff --git a/src/library/aliases.cpp b/src/library/aliases.cpp index 2bc82cbd9..224e68a3e 100644 --- a/src/library/aliases.cpp +++ b/src/library/aliases.cpp @@ -12,7 +12,6 @@ Author: Leonardo de Moura #include "kernel/abstract.h" #include "kernel/instantiate.h" #include "library/expr_lt.h" -#include "library/kernel_bindings.h" #include "library/aliases.h" #include "library/placeholder.h" #include "library/scoped_ext.h" @@ -212,57 +211,6 @@ void for_each_expr_alias(environment const & env, std::function exs; - luaL_checktype(L, 4, LUA_TTABLE); - int n = objlen(L, 4); - for (int i = 1; i <= n; i++) { - lua_rawgeti(L, 4, i); - exs.push_back(to_name_ext(L, -1)); - lua_pop(L, 1); - } - return push_environment(L, add_aliases(to_environment(L, 1), to_name_ext(L, 2), to_name_ext(L, 3), - exs.size(), exs.data())); - } -} - -void open_aliases(lua_State * L) { - SET_GLOBAL_FUN(add_expr_alias, "add_expr_alias"); - SET_GLOBAL_FUN(add_level_alias, "add_level_alias"); - SET_GLOBAL_FUN(is_expr_aliased, "is_expr_aliased"); - SET_GLOBAL_FUN(is_level_aliased, "is_level_aliased"); - SET_GLOBAL_FUN(get_expr_aliases, "get_expr_aliases"); - SET_GLOBAL_FUN(get_level_alias, "get_level_alias"); - SET_GLOBAL_FUN(add_aliases, "add_aliases"); -} - void initialize_aliases() { g_aliases = new name("alias"); g_ext = new aliases_ext_reg(); diff --git a/src/library/aliases.h b/src/library/aliases.h index affbfb88a..c22f39fe5 100644 --- a/src/library/aliases.h +++ b/src/library/aliases.h @@ -6,7 +6,6 @@ Author: Leonardo de Moura */ #pragma once #include -#include "util/lua.h" #include "kernel/environment.h" namespace lean { @@ -57,7 +56,6 @@ bool is_exception(name const & n, name const & prefix, unsigned num_exceptions, void for_each_expr_alias(environment const & env, std::function const &)> const & fn); -void open_aliases(lua_State * L); void initialize_aliases(); void finalize_aliases(); } diff --git a/src/library/app_builder.cpp b/src/library/app_builder.cpp index fbb4d72b4..1a09c7577 100644 --- a/src/library/app_builder.cpp +++ b/src/library/app_builder.cpp @@ -12,7 +12,6 @@ Author: Leonardo de Moura #include "library/match.h" #include "library/constants.h" #include "library/app_builder.h" -#include "library/kernel_bindings.h" #include "library/tmp_type_context.h" #include "library/relation_manager.h" diff --git a/src/library/choice.cpp b/src/library/choice.cpp index 223190dfb..361a734ea 100644 --- a/src/library/choice.cpp +++ b/src/library/choice.cpp @@ -8,7 +8,6 @@ Author: Leonardo de Moura #include "util/sstream.h" #include "kernel/for_each_fn.h" #include "library/choice.h" -#include "library/kernel_bindings.h" #include "library/kernel_serializer.h" namespace lean { @@ -112,40 +111,4 @@ expr const & get_choice(expr const & e, unsigned i) { lean_assert(is_choice(e)); return macro_arg(e, i); } - -static int mk_choice(lua_State * L) { - check_atleast_num_args(L, 1); - int nargs = lua_gettop(L); - buffer args; - for (int i = 1; i <= nargs; i++) - args.push_back(to_expr(L, i)); - return push_expr(L, mk_choice(args.size(), args.data())); -} - -static int is_choice(lua_State * L) { - return push_boolean(L, is_choice(to_expr(L, 1))); -} -static void check_choice(lua_State * L, int idx) { - if (!is_choice(to_expr(L, idx))) - throw exception(sstream() << "arg #" << idx << " is not a choice-expression"); -} -static int get_num_choices(lua_State * L) { - check_choice(L, 1); - return push_integer(L, get_num_choices(to_expr(L, 1))); -} -static int get_choice(lua_State * L) { - check_choice(L, 1); - expr const & c = to_expr(L, 1); - int i = lua_tointeger(L, 2); - if (i < 0 || static_cast(i) >= get_num_choices(c)) - throw exception("arg #2 is an invalid choice index"); - return push_expr(L, get_choice(c, i)); -} - -void open_choice(lua_State * L) { - SET_GLOBAL_FUN(mk_choice, "mk_choice"); - SET_GLOBAL_FUN(is_choice, "is_choice"); - SET_GLOBAL_FUN(get_num_choices, "get_num_choices"); - SET_GLOBAL_FUN(get_choice, "get_choice"); -} } diff --git a/src/library/choice.h b/src/library/choice.h index 70345c08d..ba11819dc 100644 --- a/src/library/choice.h +++ b/src/library/choice.h @@ -5,7 +5,6 @@ Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #pragma once -#include "util/lua.h" #include "kernel/expr.h" namespace lean { @@ -45,7 +44,6 @@ list> collect_choice_symbols(expr const & e); /** \brief Format the result produced by collect_choice_symbols. */ format pp_choice_symbols(expr const & e); -void open_choice(lua_State * L); void initialize_choice(); void finalize_choice(); } diff --git a/src/library/coercion.h b/src/library/coercion.h index dfe44fea5..0a307ebe5 100644 --- a/src/library/coercion.h +++ b/src/library/coercion.h @@ -6,7 +6,6 @@ Author: Leonardo de Moura */ #pragma once #include -#include "util/lua.h" #include "kernel/environment.h" #include "library/expr_pair.h" #include "library/io_state.h" diff --git a/src/library/error_handling.cpp b/src/library/error_handling.cpp index 996fc6cee..9d13f2272 100644 --- a/src/library/error_handling.cpp +++ b/src/library/error_handling.cpp @@ -6,7 +6,6 @@ Author: Leonardo de Moura */ #include #include -#include "util/script_exception.h" #include "util/name_set.h" #include "kernel/ext_exception.h" #include "kernel/for_each_fn.h" @@ -91,64 +90,12 @@ static void display_error(io_state_stream const & ios, pos_info_provider const * ios << " " << mk_pair(j.pp(fmt, p, ex.get_substitution()), opts) << endl; } -static void display_error(io_state_stream const & ios, pos_info_provider const * p, script_exception const & ex) { - if (p) { - char const * msg = ex.get_msg(); - char const * space = msg && *msg == ' ' ? "" : " "; - switch (ex.get_source()) { - case script_exception::source::String: - display_error_pos(ios, p->get_file_name(), ex.get_line() + p->get_some_pos().first - 1, static_cast(-1)); - ios << " executing script," << space << msg << endl; - break; - case script_exception::source::File: - display_error_pos(ios, p->get_file_name(), p->get_some_pos().first, p->get_some_pos().second); - ios << " executing external script (" << ex.get_file_name() << ":" << ex.get_line() << ")," << space << msg << endl; - break; - case script_exception::source::Unknown: - display_error_pos(ios, p->get_file_name(), p->get_some_pos().first, p->get_some_pos().second); - ios << " executing script, exact error position is not available, " << ex.what() << endl; - break; - } - } else { - ios << ex.what() << endl; - } -} - -static void display_error(io_state_stream const & ios, pos_info_provider const * p, script_nested_exception const & ex) { - switch (ex.get_source()) { - case script_exception::source::String: - if (p) { - display_error_pos(ios, p->get_file_name(), ex.get_line() + p->get_some_pos().first - 1, static_cast(-1)); - ios << " executing script" << endl; - } - display_error(ios, nullptr, ex.get_exception()); - break; - case script_exception::source::File: - if (p) { - display_error_pos(ios, p->get_file_name(), p->get_some_pos().first, p->get_some_pos().second); - ios << " executing external script (" << ex.get_file_name() << ":" << ex.get_line() << ")" << endl; - } else { - display_error_pos(ios, ex.get_file_name(), ex.get_line(), -1); - ios << " executing script" << endl; - } - display_error(ios, nullptr, ex.get_exception()); - break; - case script_exception::source::Unknown: - display_error(ios, nullptr, ex.get_exception()); - break; - } -} - void display_error(io_state_stream const & ios, pos_info_provider const * p, throwable const & ex) { flycheck_error err(ios); if (auto k_ex = dynamic_cast(&ex)) { display_error(ios, p, *k_ex); } else if (auto e_ex = dynamic_cast(&ex)) { display_error(ios, p, *e_ex); - } else if (auto ls_ex = dynamic_cast(&ex)) { - display_error(ios, p, *ls_ex); - } else if (auto s_ex = dynamic_cast(&ex)) { - display_error(ios, p, *s_ex); } else if (p) { display_error_pos(ios, p->get_file_name(), p->get_some_pos().first, p->get_some_pos().second); ios << " " << ex.what() << endl; diff --git a/src/library/explicit.cpp b/src/library/explicit.cpp index 17160129e..5cc4c013b 100644 --- a/src/library/explicit.cpp +++ b/src/library/explicit.cpp @@ -7,7 +7,6 @@ Author: Leonardo de Moura #include "util/sstream.h" #include "library/annotation.h" #include "library/explicit.h" -#include "library/kernel_bindings.h" namespace lean { static name * g_explicit_name = nullptr; @@ -62,36 +61,4 @@ void finalize_explicit() { delete g_explicit_name; delete g_consume_args_name; } - -static int mk_explicit(lua_State * L) { return push_expr(L, mk_explicit(to_expr(L, 1))); } -static int is_explicit(lua_State * L) { return push_boolean(L, is_explicit(to_expr(L, 1))); } -static void check_explicit(lua_State * L, int idx) { - if (!is_explicit(to_expr(L, idx))) - throw exception(sstream() << "arg #" << idx << " is not a '@'-expression"); -} -static int get_explicit_arg(lua_State * L) { - check_explicit(L, 1); - return push_expr(L, get_explicit_arg(to_expr(L, 1))); -} - -static int mk_partial_explicit(lua_State * L) { return push_expr(L, mk_partial_explicit(to_expr(L, 1))); } -static int is_partial_explicit(lua_State * L) { return push_boolean(L, is_partial_explicit(to_expr(L, 1))); } -static void check_partial_explicit(lua_State * L, int idx) { - if (!is_partial_explicit(to_expr(L, idx))) - throw exception(sstream() << "arg #" << idx << " is not a '@'-expression"); -} -static int get_partial_explicit_arg(lua_State * L) { - check_partial_explicit(L, 1); - return push_expr(L, get_partial_explicit_arg(to_expr(L, 1))); -} - -void open_explicit(lua_State * L) { - SET_GLOBAL_FUN(mk_explicit, "mk_explicit"); - SET_GLOBAL_FUN(is_explicit, "is_explicit"); - SET_GLOBAL_FUN(get_explicit_arg, "get_explicit_arg"); - - SET_GLOBAL_FUN(mk_partial_explicit, "mk_partial_explicit"); - SET_GLOBAL_FUN(is_partial_explicit, "is_partial_explicit"); - SET_GLOBAL_FUN(get_partial_explicit_arg, "get_partial_explicit_arg"); -} } diff --git a/src/library/explicit.h b/src/library/explicit.h index 3f7a96931..b112bc571 100644 --- a/src/library/explicit.h +++ b/src/library/explicit.h @@ -5,7 +5,6 @@ Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #pragma once -#include "util/lua.h" #include "kernel/expr.h" namespace lean { @@ -70,7 +69,6 @@ expr mk_consume_args(expr const & e); bool is_consume_args(expr const & e); expr const & get_consume_args_arg(expr const & e); -void open_explicit(lua_State * L); void initialize_explicit(); void finalize_explicit(); } diff --git a/src/library/init_module.cpp b/src/library/init_module.cpp index dc15c92ab..6a50c2434 100644 --- a/src/library/init_module.cpp +++ b/src/library/init_module.cpp @@ -25,7 +25,6 @@ Author: Leonardo de Moura #include "library/coercion.h" #include "library/unifier_plugin.h" #include "library/io_state.h" -#include "library/kernel_bindings.h" #include "library/idx_metavar.h" #include "library/sorry.h" #include "library/placeholder.h" @@ -58,7 +57,6 @@ void initialize_library_module() { initialize_print(); initialize_placeholder(); initialize_idx_metavar(); - initialize_kernel_bindings(); initialize_io_state(); initialize_unifier(); initialize_kernel_serializer(); @@ -134,7 +132,6 @@ void finalize_library_module() { finalize_kernel_serializer(); finalize_unifier(); finalize_io_state(); - finalize_kernel_bindings(); finalize_idx_metavar(); finalize_placeholder(); finalize_print(); diff --git a/src/library/kernel_bindings.cpp b/src/library/kernel_bindings.cpp deleted file mode 100644 index 13a7e1db2..000000000 --- a/src/library/kernel_bindings.cpp +++ /dev/null @@ -1,1966 +0,0 @@ -/* -Copyright (c) 2013-2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include -#include -#include "util/sstream.h" -#include "util/script_state.h" -#include "util/lua_list.h" -#include "util/lua_pair.h" -#include "util/lua_named_param.h" -#include "util/lazy_list_fn.h" -#include "util/luaref.h" -#include "kernel/abstract.h" -#include "kernel/for_each_fn.h" -#include "kernel/free_vars.h" -#include "kernel/instantiate.h" -#include "kernel/metavar.h" -#include "kernel/error_msgs.h" -#include "kernel/type_checker.h" -#include "kernel/replace_fn.h" -#include "kernel/inductive/inductive.h" -#include "library/standard_kernel.h" -#include "library/occurs.h" -#include "library/io_state_stream.h" -#include "library/expr_lt.h" -#include "library/kernel_bindings.h" -#include "library/normalize.h" -#include "library/module.h" -#include "library/reducible.h" -#include "library/print.h" -#include "library/unfold_macros.h" - -// Lua Bindings for the Kernel classes. We do not include the Lua -// bindings in the kernel because we do not want to inflate the Kernel. - -// In Lua, we can use the notations -// - l + k for succ^k(l) -// - k for succ^k(zero) -// The following definition is a limit on the k's that are considered. -#ifndef LEAN_MAX_LEVEL_OFFSET_IN_LUA -#define LEAN_MAX_LEVEL_OFFSET_IN_LUA 1024 -#endif - -namespace lean { -environment get_global_environment(lua_State * L); -io_state * get_io_state_ptr(lua_State * L); -io_state get_tmp_io_state(lua_State * L); -io_state get_io_state(lua_State * L) { - if (io_state * ios = get_io_state_ptr(L)) - return *ios; - else - return get_tmp_io_state(L); -} - -// Level -DECL_UDATA(level) - -int push_optional_level(lua_State * L, optional const & l) { return l ? push_level(L, *l) : push_nil(L); } - -static level mk_offset(level const & l, int k) { - if (k < 0) throw exception(sstream() << "invalid level offset " << k << ", offsets must be nonnegative"); - else if (k > LEAN_MAX_LEVEL_OFFSET_IN_LUA) throw exception(sstream() << "invalid level offset " << k << ", offset is too big"); - level r = l; - while (k > 0) { - k--; - r = mk_succ(r); - } - return r; -} - -static level to_level_ext(lua_State * L, int idx) { - if (lua_isnumber(L, idx)) - return mk_offset(mk_level_zero(), lua_tonumber(L, idx)); - else if (lua_isstring(L, idx) || is_name(L, idx)) - return mk_param_univ(to_name_ext(L, idx)); - else - return to_level(L, idx); -} - -DEFINE_LUA_LIST(level, push_level, to_level_ext) - -static int level_add(lua_State * L) { - return push_level(L, mk_offset(to_level(L, 1), luaL_checkinteger(L, 2))); -} - -static int level_tostring(lua_State * L) { - std::ostringstream out; - options opts = get_global_options(L); - out << mk_pair(pp(to_level(L, 1), opts), opts); - lua_pushstring(L, out.str().c_str()); - return 1; -} - -static int level_eq(lua_State * L) { return push_boolean(L, to_level(L, 1) == to_level(L, 2)); } -static int level_lt(lua_State * L) { - int nargs = lua_gettop(L); - return push_boolean(L, is_lt(to_level(L, 1), to_level(L, 2), nargs == 3 && lua_toboolean(L, 3))); -} -static int mk_level_zero(lua_State * L) { return push_level(L, mk_level_zero()); } -static int mk_level_one(lua_State * L) { return push_level(L, mk_level_one()); } -static int mk_level_succ(lua_State * L) { return push_level(L, mk_succ(to_level_ext(L, 1))); } -template -static int mk_level_max_core(lua_State * L) { - int nargs = lua_gettop(L); - level r; - if (nargs == 0) { - r = mk_level_zero(); - } else if (nargs == 1) { - r = to_level_ext(L, 1); - } else { - r = F(to_level_ext(L, nargs - 1), to_level_ext(L, nargs)); - for (int i = nargs - 2; i >= 1; i--) - r = F(to_level_ext(L, i), r); - } - return push_level(L, r); -} -static int mk_level_max(lua_State * L) { return mk_level_max_core(L); } -static int mk_level_imax(lua_State * L) { return mk_level_max_core(L); } -static int mk_param_univ(lua_State * L) { return push_level(L, mk_param_univ(to_name_ext(L, 1))); } -static int mk_global_univ(lua_State * L) { return push_level(L, mk_global_univ(to_name_ext(L, 1))); } -static int mk_meta_univ(lua_State * L) { return push_level(L, mk_meta_univ(to_name_ext(L, 1))); } -#define LEVEL_PRED(P) static int level_ ## P(lua_State * L) { check_num_args(L, 1); return push_boolean(L, P(to_level(L, 1))); } -LEVEL_PRED(is_zero) -LEVEL_PRED(is_param) -LEVEL_PRED(is_global) -LEVEL_PRED(is_meta) -LEVEL_PRED(is_succ) -LEVEL_PRED(is_max) -LEVEL_PRED(is_imax) -LEVEL_PRED(is_explicit) -LEVEL_PRED(has_meta) -LEVEL_PRED(has_param) -LEVEL_PRED(is_not_zero) -static int level_normalize(lua_State * L) { return push_level(L, normalize(to_level(L, 1))); } -static int level_get_kind(lua_State * L) { return push_integer(L, static_cast(kind(to_level(L, 1)))); } -static int level_is_equivalent(lua_State * L) { return push_boolean(L, is_equivalent(to_level(L, 1), to_level_ext(L, 2))); } -static int level_is_eqp(lua_State * L) { return push_boolean(L, is_eqp(to_level(L, 1), to_level(L, 2))); } - -static int level_id(lua_State * L) { - level const & l = to_level(L, 1); - if (is_param(l)) return push_name(L, param_id(l)); - else if (is_global(l)) return push_name(L, global_id(l)); - else if (is_meta(l)) return push_name(L, meta_id(l)); - else throw exception("arg #1 must be a level parameter/global/metavariable"); -} - -static int level_lhs(lua_State * L) { - level const & l = to_level(L, 1); - if (is_max(l)) return push_level(L, max_lhs(l)); - else if (is_imax(l)) return push_level(L, imax_lhs(l)); - else throw exception("arg #1 must be a level max/imax expression"); -} - -static int level_rhs(lua_State * L) { - level const & l = to_level(L, 1); - if (is_max(l)) return push_level(L, max_rhs(l)); - else if (is_imax(l)) return push_level(L, imax_rhs(l)); - else throw exception("arg #1 must be a level max/imax expression"); -} - -static int level_succ_of(lua_State * L) { - level const & l = to_level(L, 1); - if (is_succ(l)) return push_level(L, succ_of(l)); - else throw exception("arg #1 must be a level succ expression"); -} - -static int level_instantiate(lua_State * L) { - auto ps = to_list_name_ext(L, 2); - auto ls = to_list_level_ext(L, 3); - if (length(ps) != length(ls)) - throw exception("arg #2 and #3 size do not match"); - return push_level(L, instantiate(to_level(L, 1), ps, ls)); -} - -static int level_is_geq_core(lua_State * L) { return push_boolean(L, is_geq_core(to_level(L, 1), to_level_ext(L, 2))); } -static int level_is_geq(lua_State * L) { return push_boolean(L, is_geq(to_level(L, 1), to_level_ext(L, 2))); } - -static const struct luaL_Reg level_m[] = { - {"__gc", level_gc}, // never throws - {"__tostring", safe_function}, - {"__eq", safe_function}, - {"__lt", safe_function}, - {"__add", safe_function}, - {"succ", safe_function}, - {"kind", safe_function}, - {"is_zero", safe_function}, - {"is_param", safe_function}, - {"is_global", safe_function}, - {"is_meta", safe_function}, - {"is_succ", safe_function}, - {"is_max", safe_function}, - {"is_imax", safe_function}, - {"is_explicit", safe_function}, - {"has_meta", safe_function}, - {"has_param", safe_function}, - {"is_not_zero", safe_function}, - {"is_equivalent", safe_function}, - {"is_eqp", safe_function}, - {"is_lt", safe_function}, - {"is_geq", safe_function}, - {"is_geq_core", safe_function}, - {"id", safe_function}, - {"lhs", safe_function}, - {"rhs", safe_function}, - {"succ_of", safe_function}, - {"instantiate", safe_function}, - {"normalize", safe_function}, - {"norm", safe_function}, - {0, 0} -}; - -static void open_level(lua_State * L) { - luaL_newmetatable(L, level_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, level_m, 0); - - SET_GLOBAL_FUN(mk_level_zero, "level"); - SET_GLOBAL_FUN(mk_level_zero, "mk_level_zero"); - SET_GLOBAL_FUN(mk_level_one, "mk_level_one"); - SET_GLOBAL_FUN(mk_level_succ, "mk_level_succ"); - SET_GLOBAL_FUN(mk_level_max, "mk_level_max"); - SET_GLOBAL_FUN(mk_level_imax, "mk_level_imax"); - SET_GLOBAL_FUN(mk_param_univ, "mk_param_univ"); - SET_GLOBAL_FUN(mk_global_univ, "mk_global_univ"); - SET_GLOBAL_FUN(mk_meta_univ, "mk_meta_univ"); - SET_GLOBAL_FUN(mk_level_succ, "succ_univ"); - SET_GLOBAL_FUN(mk_level_max, "max_univ"); - SET_GLOBAL_FUN(mk_level_imax, "imax_univ"); - SET_GLOBAL_FUN(mk_param_univ, "param_univ"); - SET_GLOBAL_FUN(mk_global_univ, "global_univ"); - SET_GLOBAL_FUN(mk_meta_univ, "meta_univ"); - - SET_GLOBAL_FUN(level_pred, "is_level"); - - lua_newtable(L); - SET_ENUM("Zero", level_kind::Zero); - SET_ENUM("Succ", level_kind::Succ); - SET_ENUM("Max", level_kind::Max); - SET_ENUM("IMax", level_kind::IMax); - SET_ENUM("Global", level_kind::Global); - SET_ENUM("Param", level_kind::Param); - SET_ENUM("Meta", level_kind::Meta); - lua_setglobal(L, "level_kind"); -} - -static list to_level_param_names(lua_State * L, int _idx) { - if (is_list_name(L, _idx)) { - return to_list_name(L, _idx); - } else{ - return table_to_list(L, _idx, [=](lua_State * L, int idx) -> name { - if (is_level(L, idx)) { - level const & l = to_level(L, idx); - if (is_param(l)) - return param_id(l); - else if (is_global(l)) - return global_id(l); - else - throw exception(sstream() << "arg #" << _idx << " contain a level expression that is not a parameter/global"); - } else { - return to_name_ext(L, idx); - } - }); - } -} - -// Expr_binder_info -DECL_UDATA(binder_info) -static int mk_binder_info(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 0) - return push_binder_info(L, binder_info()); - else if (nargs == 1) - return push_binder_info(L, binder_info(lua_toboolean(L, 1))); - else if (nargs == 2) - return push_binder_info(L, binder_info(lua_toboolean(L, 1), lua_toboolean(L, 2))); - else if (nargs == 3) - return push_binder_info(L, binder_info(lua_toboolean(L, 1), lua_toboolean(L, 2), lua_toboolean(L, 3))); - else - return push_binder_info(L, binder_info(lua_toboolean(L, 1), lua_toboolean(L, 2), lua_toboolean(L, 3), lua_toboolean(L, 4))); -} -static int binder_info_is_implicit(lua_State * L) { return push_boolean(L, to_binder_info(L, 1).is_implicit()); } -static int binder_info_is_contextual(lua_State * L) { return push_boolean(L, to_binder_info(L, 1).is_contextual()); } -static int binder_info_is_strict_implicit(lua_State * L) { return push_boolean(L, to_binder_info(L, 1).is_strict_implicit()); } -static int binder_info_is_inst_implicit(lua_State * L) { return push_boolean(L, to_binder_info(L, 1).is_inst_implicit()); } -static const struct luaL_Reg binder_info_m[] = { - {"__gc", binder_info_gc}, - {"is_implicit", safe_function}, - {"is_contextual", safe_function}, - {"is_strict_implicit", safe_function}, - {"is_inst_implicit", safe_function}, - {0, 0} -}; -static void open_binder_info(lua_State * L) { - luaL_newmetatable(L, binder_info_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, binder_info_m, 0); - - SET_GLOBAL_FUN(mk_binder_info, "binder_info"); - SET_GLOBAL_FUN(binder_info_pred, "is_binder_info"); -} - -// Expressions -DECL_UDATA(expr) -DEFINE_LUA_LIST(expr, push_expr, to_expr) - -int push_optional_expr(lua_State * L, optional const & e) { return e ? push_expr(L, *e) : push_nil(L); } - -expr & to_app(lua_State * L, int idx) { - expr & r = to_expr(L, idx); - if (!is_app(r)) - throw exception(sstream() << "arg #" << idx << " must be an application"); - return r; -} - -expr & to_binding(lua_State * L, int idx) { - expr & r = to_expr(L, idx); - if (!is_binding(r)) - throw exception(sstream() << "arg #" << idx << " must be a binder (i.e., lambda or Pi)"); - return r; -} - -expr & to_macro_app(lua_State * L, int idx) { - expr & r = to_expr(L, idx); - if (!is_macro(r)) - throw exception(sstream() << "arg #" << idx << " must be a macro application"); - return r; -} - -static int expr_tostring(lua_State * L) { - std::ostringstream out; - formatter fmt = mk_formatter(L); - options opts = get_global_options(L); - out << mk_pair(fmt(to_expr(L, 1)), opts); - return push_string(L, out.str().c_str()); -} - -static int expr_is_equal(lua_State * L) { return push_boolean(L, to_expr(L, 1) == to_expr(L, 2)); } -static int expr_is_bi_equal(lua_State * L) { return push_boolean(L, is_bi_equal(to_expr(L, 1), to_expr(L, 2))); } -static int expr_lt(lua_State * L) { return push_boolean(L, to_expr(L, 1) < to_expr(L, 2)); } -static int expr_mk_constant(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 1) - return push_expr(L, mk_constant(to_name_ext(L, 1))); - else - return push_expr(L, mk_constant(to_name_ext(L, 1), to_list_level_ext(L, 2))); -} -static int expr_mk_var(lua_State * L) { return push_expr(L, mk_var(luaL_checkinteger(L, 1))); } -static int expr_mk_app(lua_State * L) { - int nargs = lua_gettop(L); - expr r; - r = mk_app(to_expr(L, 1), to_expr(L, 2)); - for (int i = 3; i <= nargs; i++) - r = mk_app(r, to_expr(L, i)); - return push_expr(L, r); -} -static int expr_mk_lambda(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 3) - return push_expr(L, mk_lambda(to_name_ext(L, 1), to_expr(L, 2), to_expr(L, 3))); - else - return push_expr(L, mk_lambda(to_name_ext(L, 1), to_expr(L, 2), to_expr(L, 3), to_binder_info(L, 4))); -} -static int expr_mk_pi(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 3) - return push_expr(L, mk_pi(to_name_ext(L, 1), to_expr(L, 2), to_expr(L, 3))); - else - return push_expr(L, mk_pi(to_name_ext(L, 1), to_expr(L, 2), to_expr(L, 3), to_binder_info(L, 4))); -} -static int expr_mk_arrow(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs < 2) - throw exception("function must have at least 2 arguments"); - expr r = mk_arrow(to_expr(L, nargs - 1), to_expr(L, nargs)); - for (int i = nargs - 2; i >= 1; i--) - r = mk_arrow(to_expr(L, i), r); - return push_expr(L, r); -} - -typedef expr (*MkAbst1)(expr const & n, expr const & t, expr const & b); -typedef expr (*MkAbst2)(name const & n, expr const & t, expr const & b); - -template -static int expr_abst(lua_State * L) { - int nargs = lua_gettop(L); - check_atleast_num_args(L, 2); - expr r = to_expr(L, nargs); - for (int i = nargs - 1; i >= 1; i -= 1) { - expr l = to_expr(L, i); - if (!is_local(l)) - throw exception(sstream() << "arg #" << i << " must be a local constants"); - if (pi) - r = Pi(l, r); - else - r = Fun(l, r); - } - return push_expr(L, r); -} - -static int expr_fun(lua_State * L) { return expr_abst(L); } -static int expr_pi(lua_State * L) { return expr_abst(L); } -static int expr_mk_sort(lua_State * L) { return push_expr(L, mk_sort(to_level_ext(L, 1))); } -static int expr_mk_metavar(lua_State * L) { return push_expr(L, mk_metavar(to_name_ext(L, 1), to_expr(L, 2))); } -static int expr_mk_local(lua_State * L) { - int nargs = lua_gettop(L); - name n = to_name_ext(L, 1); - if (nargs == 2) - return push_expr(L, mk_local(n, to_expr(L, 2))); - else if (nargs == 3 && is_binder_info(L, 3)) - return push_expr(L, mk_local(n, n, to_expr(L, 2), to_binder_info(L, 3))); - else if (nargs == 3) - return push_expr(L, mk_local(n, to_name_ext(L, 2), to_expr(L, 3), binder_info())); - else - return push_expr(L, mk_local(n, to_name_ext(L, 2), to_expr(L, 3), to_binder_info(L, 4))); -} -static int expr_get_kind(lua_State * L) { return push_integer(L, static_cast(to_expr(L, 1).kind())); } - -#define EXPR_PRED(P) static int expr_ ## P(lua_State * L) { check_num_args(L, 1); return push_boolean(L, P(to_expr(L, 1))); } - -EXPR_PRED(is_constant) -EXPR_PRED(is_var) -EXPR_PRED(is_app) -EXPR_PRED(is_lambda) -EXPR_PRED(is_pi) -EXPR_PRED(is_binding) -EXPR_PRED(is_macro) -EXPR_PRED(is_metavar) -EXPR_PRED(is_local) -EXPR_PRED(is_mlocal) -EXPR_PRED(is_meta) -EXPR_PRED(has_metavar) -EXPR_PRED(has_local) -EXPR_PRED(has_param_univ) -EXPR_PRED(has_free_vars) -EXPR_PRED(closed) - -static int expr_fields(lua_State * L) { - expr & e = to_expr(L, 1); - switch (e.kind()) { - case expr_kind::Var: - return push_integer(L, var_idx(e)); - case expr_kind::Constant: - push_name(L, const_name(e)); push_list_level(L, const_levels(e)); return 2; - case expr_kind::Sort: - return push_level(L, sort_level(e)); - case expr_kind::Macro: - return push_macro_definition(L, macro_def(e)); - case expr_kind::App: - push_expr(L, app_fn(e)); push_expr(L, app_arg(e)); return 2; - case expr_kind::Lambda: - case expr_kind::Pi: - push_name(L, binding_name(e)); push_expr(L, binding_domain(e)); push_expr(L, binding_body(e)); push_binder_info(L, binding_info(e)); return 4; - case expr_kind::Meta: - case expr_kind::Local: - push_name(L, mlocal_name(e)); push_expr(L, mlocal_type(e)); return 2; - } - lean_unreachable(); // LCOV_EXCL_LINE - return 0; // LCOV_EXCL_LINE -} - -static int expr_fn(lua_State * L) { return push_expr(L, app_fn(to_app(L, 1))); } -static int expr_arg(lua_State * L) { return push_expr(L, app_arg(to_app(L, 1))); } - -static int expr_for_each(lua_State * L) { - expr const & e = to_expr(L, 1); // expr - luaL_checktype(L, 2, LUA_TFUNCTION); // user-fun - for_each(e, [&](expr const & a, unsigned offset) { - lua_pushvalue(L, 2); // push user-fun - push_expr(L, a); - lua_pushinteger(L, offset); - pcall(L, 2, 1, 0); - bool r = true; - if (lua_isboolean(L, -1)) - r = lua_toboolean(L, -1); - lua_pop(L, 1); - return r; - }); - return 0; -} - -static int expr_replace(lua_State * L) { - expr const & e = to_expr(L, 1); - luaL_checktype(L, 2, LUA_TFUNCTION); - expr r = replace(e, [&](expr const & a, unsigned offset) { - lua_pushvalue(L, 2); - push_expr(L, a); - lua_pushinteger(L, offset); - pcall(L, 2, 1, 0); - if (is_expr(L, -1)) { - expr r = to_expr(L, -1); - lua_pop(L, 1); - return some_expr(r); - } else { - lua_pop(L, 1); - return none_expr(); - } - }); - return push_expr(L, r); -} - -static int expr_has_free_var(lua_State * L) { - return push_boolean(L, has_free_var(to_expr(L, 1), luaL_checkinteger(L, 2))); -} - -static int expr_lift_free_vars(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 2) - return push_expr(L, lift_free_vars(to_expr(L, 1), luaL_checkinteger(L, 2))); - else - return push_expr(L, lift_free_vars(to_expr(L, 1), luaL_checkinteger(L, 2), luaL_checkinteger(L, 3))); -} - -static int expr_lower_free_vars(lua_State * L) { - check_atmost_num_args(L, 3); - int nargs = lua_gettop(L); - expr const & e = to_expr(L, 1); - int s = luaL_checkinteger(L, 2); - if (nargs == 2) { - return push_expr(L, lower_free_vars(e, s)); - } else { - int d = luaL_checkinteger(L, 3); - if (s < d) - throw exception(sstream() << "invalid lower_free_vars, first argument must be >= second one"); - return push_expr(L, lower_free_vars(e, s, d)); - } -} - -// Copy Lua table/array elements to r -static void copy_lua_array(lua_State * L, int tidx, buffer & r) { - luaL_checktype(L, tidx, LUA_TTABLE); - int n = objlen(L, tidx); - for (int i = 1; i <= n; i++) { - lua_rawgeti(L, tidx, i); - r.push_back(to_expr(L, -1)); - lua_pop(L, 1); - } -} - -static int expr_instantiate(lua_State * L) { - expr const & e = to_expr(L, 1); - if (is_expr(L, 2)) { - return push_expr(L, instantiate(e, to_expr(L, 2))); - } else { - buffer s; - copy_lua_array(L, 2, s); - return push_expr(L, instantiate(e, s.size(), s.data())); - } -} - -static int expr_instantiate_univ_params(lua_State * L) { - return push_expr(L, instantiate_univ_params(to_expr(L, 1), to_level_param_names(L, 2), to_list_level_ext(L, 3))); -} - -static int expr_abstract(lua_State * L) { - expr const & e = to_expr(L, 1); - if (is_expr(L, 2)) { - expr const & e2 = to_expr(L, 2); - return push_expr(L, abstract(e, 1, &e2)); - } else { - buffer s; - copy_lua_array(L, 2, s); - return push_expr(L, abstract(e, s.size(), s.data())); - } -} - -static int binding_name(lua_State * L) { return push_name(L, binding_name(to_binding(L, 1))); } -static int binding_domain(lua_State * L) { return push_expr(L, binding_domain(to_binding(L, 1))); } -static int binding_body(lua_State * L) { return push_expr(L, binding_body(to_binding(L, 1))); } -static int binding_info(lua_State * L) { return push_binder_info(L, binding_info(to_binding(L, 1))); } - -static int expr_occurs(lua_State * L) { return push_boolean(L, occurs(to_expr(L, 1), to_expr(L, 2))); } -static int expr_is_eqp(lua_State * L) { return push_boolean(L, is_eqp(to_expr(L, 1), to_expr(L, 2))); } -static int expr_hash(lua_State * L) { return push_integer(L, to_expr(L, 1).hash()); } -static int expr_hash_bi(lua_State * L) { return push_integer(L, hash_bi(to_expr(L, 1))); } -static int expr_weight(lua_State * L) { return push_integer(L, get_weight(to_expr(L, 1))); } -static int expr_is_lt(lua_State * L) { - int nargs = lua_gettop(L); - return push_boolean(L, is_lt(to_expr(L, 1), to_expr(L, 2), nargs == 3 && lua_toboolean(L, 3))); -} -static int expr_mk_macro(lua_State * L) { - buffer args; - copy_lua_array(L, 2, args); - return push_expr(L, mk_macro(to_macro_definition(L, 1), args.size(), args.data())); -} - -static int macro_def(lua_State * L) { return push_macro_definition(L, macro_def(to_macro_app(L, 1))); } -static int macro_num_args(lua_State * L) { return push_integer(L, macro_num_args(to_macro_app(L, 1))); } -static int macro_arg(lua_State * L) { return push_expr(L, macro_arg(to_macro_app(L, 1), luaL_checkinteger(L, 2))); } - -static int expr_set_tag(lua_State * L) { to_expr(L, 1).set_tag(luaL_checkinteger(L, 2)); return 0; } -static int expr_tag(lua_State * L) { - auto t = to_expr(L, 1).get_tag(); - return (t == nulltag) ? push_nil(L) : push_integer(L, t); -} - -static const struct luaL_Reg expr_m[] = { - {"__gc", expr_gc}, // never throws - {"__tostring", safe_function}, - {"__eq", safe_function}, - {"__lt", safe_function}, - {"__call", safe_function}, - {"kind", safe_function}, - {"is_var", safe_function}, - {"is_constant", safe_function}, - {"is_metavar", safe_function}, - {"is_local", safe_function}, - {"is_mlocal", safe_function}, - {"is_app", safe_function}, - {"is_lambda", safe_function}, - {"is_pi", safe_function}, - {"is_binding", safe_function}, - {"is_macro", safe_function}, - {"is_meta", safe_function}, - {"has_free_vars", safe_function}, - {"closed", safe_function}, - {"has_metavar", safe_function}, - {"has_local", safe_function}, - {"has_param_univ", safe_function}, - {"arg", safe_function}, - {"fn", safe_function}, - {"fields", safe_function}, - {"data", safe_function}, - {"weight", safe_function}, - {"binding_name", safe_function}, - {"binding_domain", safe_function}, - {"binding_body", safe_function}, - {"binding_info", safe_function}, - {"macro_def", safe_function}, - {"macro_num_args", safe_function}, - {"macro_arg", safe_function}, - {"for_each", safe_function}, - {"replace", safe_function}, - {"has_free_var", safe_function}, - {"lift_free_vars", safe_function}, - {"lower_free_vars", safe_function}, - {"instantiate", safe_function}, - {"instantiate_univs", safe_function}, - {"abstract", safe_function}, - {"occurs", safe_function}, - {"is_eqp", safe_function}, - {"is_lt", safe_function}, - {"is_equal", safe_function}, - {"is_bi_equal", safe_function}, - {"hash", safe_function}, - {"hash_bi", safe_function}, - {"tag", safe_function}, - {"set_tag", safe_function}, - {0, 0} -}; - -static int enable_expr_caching(lua_State * L) { return push_boolean(L, enable_expr_caching(lua_toboolean(L, 1))); } - -static void open_expr(lua_State * L) { - luaL_newmetatable(L, expr_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, expr_m, 0); - - SET_GLOBAL_FUN(expr_mk_constant, "mk_constant"); - SET_GLOBAL_FUN(expr_mk_constant, "Const"); - SET_GLOBAL_FUN(expr_mk_var, "mk_var"); - SET_GLOBAL_FUN(expr_mk_var, "Var"); - SET_GLOBAL_FUN(expr_mk_app, "mk_app"); - SET_GLOBAL_FUN(expr_mk_lambda, "mk_lambda"); - SET_GLOBAL_FUN(expr_mk_pi, "mk_pi"); - SET_GLOBAL_FUN(expr_mk_arrow, "mk_arrow"); - SET_GLOBAL_FUN(expr_mk_macro, "mk_macro"); - SET_GLOBAL_FUN(expr_fun, "fun"); - SET_GLOBAL_FUN(expr_fun, "Fun"); - SET_GLOBAL_FUN(expr_pi, "Pi"); - SET_GLOBAL_FUN(expr_mk_sort, "mk_sort"); - SET_GLOBAL_FUN(expr_mk_metavar, "mk_metavar"); - SET_GLOBAL_FUN(expr_mk_local, "mk_local"); - SET_GLOBAL_FUN(expr_mk_local, "Local"); - SET_GLOBAL_FUN(expr_pred, "is_expr"); - - SET_GLOBAL_FUN(enable_expr_caching, "enable_expr_caching"); - - push_expr(L, mk_Prop()); - lua_setglobal(L, "Prop"); - - push_expr(L, mk_Type()); - lua_setglobal(L, "Type"); - - lua_newtable(L); - SET_ENUM("Var", expr_kind::Var); - SET_ENUM("Constant", expr_kind::Constant); - SET_ENUM("Meta", expr_kind::Meta); - SET_ENUM("Local", expr_kind::Local); - SET_ENUM("Sort", expr_kind::Sort); - SET_ENUM("App", expr_kind::App); - SET_ENUM("Lambda", expr_kind::Lambda); - SET_ENUM("Pi", expr_kind::Pi); - SET_ENUM("Macro", expr_kind::Macro); - lua_setglobal(L, "expr_kind"); -} -// macro_definition -DECL_UDATA(macro_definition) -static int macro_get_name(lua_State * L) { return push_name(L, to_macro_definition(L, 1).get_name()); } -static int macro_trust_level(lua_State * L) { return push_integer(L, to_macro_definition(L, 1).trust_level()); } -static int macro_eq(lua_State * L) { return push_boolean(L, to_macro_definition(L, 1) == to_macro_definition(L, 2)); } -static int macro_hash(lua_State * L) { return push_integer(L, to_macro_definition(L, 1).hash()); } -static int macro_tostring(lua_State * L) { - std::ostringstream out; - formatter fmt = mk_formatter(L); - options opts = get_global_options(L); - out << mk_pair(to_macro_definition(L, 1).pp(fmt), opts); - return push_string(L, out.str().c_str()); -} - -static const struct luaL_Reg macro_definition_m[] = { - {"__gc", macro_definition_gc}, // never throws - {"__tostring", safe_function}, - {"__eq", safe_function}, - {"hash", safe_function}, - {"trust_level", safe_function}, - {"name", safe_function}, - {0, 0} -}; - -static void open_macro_definition(lua_State * L) { - luaL_newmetatable(L, macro_definition_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, macro_definition_m, 0); - - SET_GLOBAL_FUN(macro_definition_pred, "is_macro_definition"); -} - -// declaration -DECL_UDATA(declaration) -int push_optional_declaration(lua_State * L, optional const & e) { return e ? push_declaration(L, *e) : push_nil(L); } -#define DECLARATION_PRED(P) static int declaration_ ## P(lua_State * L) { check_num_args(L, 1); return push_boolean(L, to_declaration(L, 1).P()); } -DECLARATION_PRED(is_definition) -DECLARATION_PRED(is_theorem) -DECLARATION_PRED(is_axiom) -DECLARATION_PRED(is_constant_assumption) -DECLARATION_PRED(use_conv_opt) -static int declaration_get_name(lua_State * L) { return push_name(L, to_declaration(L, 1).get_name()); } -static int declaration_get_params(lua_State * L) { return push_list_name(L, to_declaration(L, 1).get_univ_params()); } -static int declaration_get_type(lua_State * L) { return push_expr(L, to_declaration(L, 1).get_type()); } -static int declaration_get_value(lua_State * L) { - if (to_declaration(L, 1).is_definition()) - return push_expr(L, to_declaration(L, 1).get_value()); - throw exception("arg #1 must be a definition"); -} -static int declaration_get_height(lua_State * L) { return push_integer(L, to_declaration(L, 1).get_height()); } -static int mk_constant_assumption(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 2) - return push_declaration(L, mk_constant_assumption(to_name_ext(L, 1), level_param_names(), to_expr(L, 2))); - else - return push_declaration(L, mk_constant_assumption(to_name_ext(L, 1), to_level_param_names(L, 2), to_expr(L, 3))); -} -static int mk_axiom(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 2) - return push_declaration(L, mk_axiom(to_name_ext(L, 1), level_param_names(), to_expr(L, 2))); - else - return push_declaration(L, mk_axiom(to_name_ext(L, 1), to_level_param_names(L, 2), to_expr(L, 3))); -} -static void get_definition_args(lua_State * L, int idx, unsigned & height, bool & use_conv_opt) { - use_conv_opt = get_bool_named_param(L, idx, "use_conv_opt", use_conv_opt); - height = get_uint_named_param(L, idx, "height", height); -} -static int mk_definition(lua_State * L) { - int nargs = lua_gettop(L); - unsigned height = 0; bool use_conv_opt = true; - if (nargs < 3) { - throw exception("mk_definition must have at least 3 arguments"); - } else if (is_environment(L, 1)) { - if (nargs < 4) { - throw exception("mk_definition must have at least 4 arguments, when the first argument is an environment"); - } else if (is_expr(L, 3)) { - get_definition_args(L, 5, height, use_conv_opt); - return push_declaration(L, mk_definition(to_environment(L, 1), to_name_ext(L, 2), level_param_names(), - to_expr(L, 3), to_expr(L, 4), use_conv_opt)); - } else { - get_definition_args(L, 6, height, use_conv_opt); - return push_declaration(L, mk_definition(to_environment(L, 1), to_name_ext(L, 2), to_level_param_names(L, 3), - to_expr(L, 4), to_expr(L, 5), use_conv_opt)); - } - } else { - if (is_expr(L, 2)) { - get_definition_args(L, 4, height, use_conv_opt); - return push_declaration(L, mk_definition(to_name_ext(L, 1), level_param_names(), to_expr(L, 2), - to_expr(L, 3), height, use_conv_opt)); - } else { - get_definition_args(L, 5, height, use_conv_opt); - return push_declaration(L, mk_definition(to_name_ext(L, 1), to_level_param_names(L, 2), - to_expr(L, 3), to_expr(L, 4), height, use_conv_opt)); - } - } -} -static void get_definition_args(lua_State * L, int idx, unsigned & height) { - height = get_uint_named_param(L, idx, "height", height); -} -static int mk_theorem(lua_State * L) { - int nargs = lua_gettop(L); - unsigned height = 0; - if (nargs == 3) { - return push_declaration(L, mk_theorem(to_name_ext(L, 1), level_param_names(), to_expr(L, 2), to_expr(L, 3), 0)); - } else if (nargs == 4) { - if (is_expr(L, 4)) { - return push_declaration(L, mk_theorem(to_name_ext(L, 1), to_level_param_names(L, 2), to_expr(L, 3), to_expr(L, 4), - height)); - } else { - get_definition_args(L, 4, height); - return push_declaration(L, mk_theorem(to_name_ext(L, 1), level_param_names(), to_expr(L, 2), to_expr(L, 3), height)); - } - } else { - get_definition_args(L, 5, height); - return push_declaration(L, mk_theorem(to_name_ext(L, 1), to_level_param_names(L, 2), to_expr(L, 3), to_expr(L, 4), height)); - } -} - -static const struct luaL_Reg declaration_m[] = { - {"__gc", declaration_gc}, // never throws - {"is_definition", safe_function}, - {"is_theorem", safe_function}, - {"is_axiom", safe_function}, - {"is_constant_assumption", safe_function}, - {"use_conv_opt", safe_function}, - {"name", safe_function}, - {"univ_params", safe_function}, - {"type", safe_function}, - {"value", safe_function}, - {"height", safe_function}, - {0, 0} -}; - -static void open_declaration(lua_State * L) { - luaL_newmetatable(L, declaration_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, declaration_m, 0); - - SET_GLOBAL_FUN(declaration_pred, "is_declaration"); - SET_GLOBAL_FUN(mk_constant_assumption, "mk_constant_assumption"); - SET_GLOBAL_FUN(mk_axiom, "mk_axiom"); - SET_GLOBAL_FUN(mk_theorem, "mk_theorem"); - SET_GLOBAL_FUN(mk_definition, "mk_definition"); -} - -// Formatter -DECL_UDATA(formatter_factory) -DECL_UDATA(formatter) - -static int formatter_call(lua_State * L) { - formatter & fmt = to_formatter(L, 1); - return push_format(L, fmt(to_expr(L, 2))); -} - -static int formatter_factory_call(lua_State * L) { - int nargs = lua_gettop(L); - formatter_factory & fmtf = to_formatter_factory(L, 1); - if (nargs == 1) - return push_formatter(L, fmtf(get_global_environment(L), get_global_options(L))); - else if (nargs == 2) - return push_formatter(L, fmtf(to_environment(L, 2), get_global_options(L))); - else - return push_formatter(L, fmtf(to_environment(L, 2), to_options(L, 3))); -} - -static const struct luaL_Reg formatter_factory_m[] = { - {"__gc", formatter_factory_gc}, // never throws - {"__call", safe_function}, - {0, 0} -}; - -static const struct luaL_Reg formatter_m[] = { - {"__gc", formatter_gc}, // never throws - {"__call", safe_function}, - {0, 0} -}; - -static char g_formatter_factory_key; -static formatter_factory * g_print_formatter_factory = nullptr; - -optional get_global_formatter_factory_core(lua_State * L) { - io_state * io = get_io_state_ptr(L); - if (io != nullptr) { - return optional(io->get_formatter_factory()); - } else { - lua_pushlightuserdata(L, static_cast(&g_formatter_factory_key)); - lua_gettable(L, LUA_REGISTRYINDEX); - if (is_formatter_factory(L, -1)) { - formatter_factory r = to_formatter_factory(L, -1); - lua_pop(L, 1); - return optional(r); - } else { - lua_pop(L, 1); - return optional(); - } - } -} - -formatter_factory get_global_formatter_factory(lua_State * L) { - auto r = get_global_formatter_factory_core(L); - if (r) - return *r; - else - return *g_print_formatter_factory; -} - -void set_global_formatter_factory(lua_State * L, formatter_factory const & fmtf) { - io_state * io = get_io_state_ptr(L); - if (io != nullptr) { - io->set_formatter_factory(fmtf); - } else { - lua_pushlightuserdata(L, static_cast(&g_formatter_factory_key)); - push_formatter_factory(L, fmtf); - lua_settable(L, LUA_REGISTRYINDEX); - } -} - -static int get_formatter_factory(lua_State * L) { - io_state * io = get_io_state_ptr(L); - if (io != nullptr) { - return push_formatter_factory(L, io->get_formatter_factory()); - } else { - return push_formatter_factory(L, get_global_formatter_factory(L)); - } -} - -formatter mk_formatter(lua_State * L) { - return get_global_formatter_factory(L)(get_global_environment(L), get_global_options(L)); -} - -static int set_formatter_factory(lua_State * L) { - set_global_formatter_factory(L, to_formatter_factory(L, 1)); - return 0; -} - -static void open_formatter(lua_State * L) { - luaL_newmetatable(L, formatter_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, formatter_m, 0); - - luaL_newmetatable(L, formatter_factory_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, formatter_factory_m, 0); - - SET_GLOBAL_FUN(formatter_pred, "is_formatter"); - SET_GLOBAL_FUN(formatter_factory_pred, "is_formatter_factory"); - SET_GLOBAL_FUN(get_formatter_factory, "get_formatter_factory"); - SET_GLOBAL_FUN(set_formatter_factory, "set_formatter_factory"); -} - -// Helper function for push pair expr, constraint_seq -int push_ecs(lua_State * L, pair const & p) { - push_expr(L, p.first); - push_constraint_seq(L, p.second); - return 2; -} - -int push_bcs(lua_State * L, pair const & p) { - push_boolean(L, p.first); - push_constraint_seq(L, p.second); - return 2; -} - -// Environment_id -DECL_UDATA(environment_id) -static int environment_id_descendant(lua_State * L) { return push_boolean(L, to_environment_id(L, 1).is_descendant(to_environment_id(L, 2))); } -static const struct luaL_Reg environment_id_m[] = { - {"__gc", environment_id_gc}, // never throws - {"is_descendant", safe_function}, - {0, 0} -}; - -static void open_environment_id(lua_State * L) { - luaL_newmetatable(L, environment_id_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, environment_id_m, 0); - - SET_GLOBAL_FUN(environment_id_pred, "is_environment_id"); -} - -// certified_declaration -DECL_UDATA(certified_declaration) -static int certified_declaration_get_declaration(lua_State * L) { return push_declaration(L, to_certified_declaration(L, 1).get_declaration()); } -static int certified_declaration_get_id(lua_State * L) { return push_environment_id(L, to_certified_declaration(L, 1). get_id()); } - -static const struct luaL_Reg certified_declaration_m[] = { - {"__gc", certified_declaration_gc}, // never throws - {"declaration", safe_function}, - {"environment_id", safe_function}, - {0, 0} -}; - -static void open_certified_declaration(lua_State * L) { - luaL_newmetatable(L, certified_declaration_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, certified_declaration_m, 0); - - SET_GLOBAL_FUN(certified_declaration_pred, "is_certified_declaration"); -} -static bool operator!=(certified_declaration const &, certified_declaration const &) { return true; } -DEFINE_LUA_LIST(certified_declaration, push_certified_declaration, to_certified_declaration) - -// Environment -DECL_UDATA(environment) -static int environment_is_descendant(lua_State * L) { return push_boolean(L, to_environment(L, 1).is_descendant(to_environment(L, 2))); } -static int environment_trust_lvl(lua_State * L) { return push_integer(L, to_environment(L, 1).trust_lvl()); } -static int environment_prop_proof_irrel(lua_State * L) { return push_boolean(L, to_environment(L, 1).prop_proof_irrel()); } -static int environment_eta(lua_State * L) { return push_boolean(L, to_environment(L, 1).eta()); } -static int environment_impredicative(lua_State * L) { return push_boolean(L, to_environment(L, 1).impredicative()); } -static int environment_add_universe(lua_State * L) { - return push_environment(L, module::add_universe(to_environment(L, 1), to_name_ext(L, 2))); -} -static int environment_is_universe(lua_State * L) { return push_boolean(L, to_environment(L, 1).is_universe(to_name_ext(L, 2))); } -static int environment_find(lua_State * L) { return push_optional_declaration(L, to_environment(L, 1).find(to_name_ext(L, 2))); } -static int environment_get(lua_State * L) { return push_declaration(L, to_environment(L, 1).get(to_name_ext(L, 2))); } -static int environment_add(lua_State * L) { - return push_environment(L, module::add(to_environment(L, 1), to_certified_declaration(L, 2))); -} -static int environment_replace(lua_State * L) { return push_environment(L, to_environment(L, 1).replace(to_certified_declaration(L, 2))); } -static int mk_bare_environment(lua_State * L) { - unsigned trust_lvl = get_uint_named_param(L, 1, "trust_lvl", 0); - trust_lvl = get_uint_named_param(L, 1, "trust_level", trust_lvl); - bool prop_proof_irrel = get_bool_named_param(L, 1, "prop_proof_irrel", true); - bool eta = get_bool_named_param(L, 1, "eta", true); - bool impredicative = get_bool_named_param(L, 1, "impredicative", true); - return push_environment(L, environment(trust_lvl, prop_proof_irrel, eta, impredicative)); -} -static unsigned get_trust_lvl(lua_State * L, int i) { - unsigned trust_lvl = 0; - if (i <= lua_gettop(L)) - trust_lvl = lua_tonumber(L, i); - return trust_lvl; -} -static int mk_environment(lua_State * L) { return push_environment(L, mk_environment(get_trust_lvl(L, 1))); } - -static int environment_forget(lua_State * L) { return push_environment(L, to_environment(L, 1).forget()); } -static int environment_whnf(lua_State * L) { return push_ecs(L, type_checker(to_environment(L, 1)).whnf(to_expr(L, 2))); } -static int environment_normalize(lua_State * L) { return push_expr(L, normalize(to_environment(L, 1), to_expr(L, 2))); } -static int environment_infer_type(lua_State * L) { return push_ecs(L, type_checker(to_environment(L, 1)).infer(to_expr(L, 2))); } -static int environment_type_check(lua_State * L) { return push_ecs(L, type_checker(to_environment(L, 1)).check(to_expr(L, 2))); } -static int environment_for_each_decl(lua_State * L) { - environment const & env = to_environment(L, 1); - luaL_checktype(L, 2, LUA_TFUNCTION); // user-fun - env.for_each_declaration([&](declaration const & d) { - lua_pushvalue(L, 2); // push user-fun - push_declaration(L, d); - pcall(L, 1, 0, 0); - }); - return 0; -} -static int environment_for_each_universe(lua_State * L) { - environment const & env = to_environment(L, 1); - luaL_checktype(L, 2, LUA_TFUNCTION); // user-fun - env.for_each_universe([&](name const & u) { - lua_pushvalue(L, 2); // push user-fun - push_name(L, u); - pcall(L, 1, 0, 0); - }); - return 0; -} - -static void to_module_name_buffer(lua_State * L, int i, buffer & r) { - if (lua_isstring(L, i) || is_name(L, i)) { - r.push_back(module_name(to_name_ext(L, i))); - } else { - luaL_checktype(L, i, LUA_TTABLE); - lua_pushvalue(L, i); - int sz = objlen(L, -1); - for (int i = 1; i <= sz; i++) { - lua_rawgeti(L, -1, i); - r.push_back(module_name(to_name_ext(L, -1))); - lua_pop(L, 1); - } - } -} - -static int import_modules(environment const & env, lua_State * L, int s) { - int nargs = lua_gettop(L); - buffer mnames; - to_module_name_buffer(L, s, mnames); - unsigned num_threads = 1; - bool keep_proofs = false; - if (nargs > s) { - num_threads = get_uint_named_param(L, s+1, "num_threads", num_threads); - keep_proofs = get_bool_named_param(L, s+1, "keep_proofs", keep_proofs); - } - std::string base; - if (nargs > s+1 && is_io_state(L, s+2)) - return push_environment(L, import_modules(env, base, mnames.size(), mnames.data(), num_threads, keep_proofs, to_io_state(L, s+2))); - else - return push_environment(L, import_modules(env, base, mnames.size(), mnames.data(), num_threads, keep_proofs, get_io_state(L))); -} - -static int import_modules(lua_State * L) { - if (is_environment(L, 1)) - return import_modules(to_environment(L, 1), L, 2); - else - return import_modules(mk_environment(), L, 1); -} - -static int export_module(lua_State * L) { - std::ofstream out(lua_tostring(L, 2), std::ofstream::binary); - export_module(out, to_environment(L, 1)); - return 0; -} - -static const struct luaL_Reg environment_m[] = { - {"__gc", environment_gc}, // never throws - {"is_descendant", safe_function}, - {"trust_lvl", safe_function}, - {"trust_level", safe_function}, - {"prop_proof_irrel", safe_function}, - {"eta", safe_function}, - {"impredicative", safe_function}, - {"add_universe", safe_function}, - {"is_universe", safe_function}, - {"find", safe_function}, - {"get", safe_function}, - {"add", safe_function}, - {"replace", safe_function}, - {"forget", safe_function}, - {"whnf", safe_function}, - {"normalize", safe_function}, - {"infer_type", safe_function}, - {"type_check", safe_function}, - {"for_each_declaration", safe_function}, - {"for_each_decl", safe_function}, - {"for_each_universe", safe_function}, - {"for_each_univ", safe_function}, - {"export", safe_function}, - {0, 0} -}; - -static char g_set_environment_key; -static environment * get_global_environment_ptr(lua_State * L) { - lua_pushlightuserdata(L, static_cast(&g_set_environment_key)); - lua_gettable(L, LUA_REGISTRYINDEX); - if (!lua_islightuserdata(L, -1)) - return nullptr; - environment * r = static_cast(const_cast(lua_topointer(L, -1))); - lua_pop(L, 1); - return r; -} -static void set_global_environment_ptr(lua_State * L, environment * env) { - lua_pushlightuserdata(L, static_cast(&g_set_environment_key)); - lua_pushlightuserdata(L, static_cast(env)); - lua_settable(L, LUA_REGISTRYINDEX); -} -environment get_global_environment(lua_State * L) { - environment * env = get_global_environment_ptr(L); - if (env == nullptr) - throw exception("Lua state does not have an environment object"); - return *env; -} - -set_environment::set_environment(lua_State * L, environment & env):m_state(L) { - m_old_env = get_global_environment_ptr(L); - set_global_environment_ptr(L, &env); -} - -set_environment::~set_environment() { - set_global_environment_ptr(m_state, m_old_env); -} - -int get_environment(lua_State * L) { - return push_environment(L, get_global_environment(L)); -} - -int set_environment(lua_State * L) { - environment * env = get_global_environment_ptr(L); - if (env == nullptr) - throw exception("Lua state does not have an environment object"); - *env = to_environment(L, 1); - return 0; -} - -static void open_environment(lua_State * L) { - luaL_newmetatable(L, environment_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, environment_m, 0); - - SET_GLOBAL_FUN(mk_bare_environment, "bare_environment"); - SET_GLOBAL_FUN(mk_environment, "environment"); - SET_GLOBAL_FUN(environment_pred, "is_environment"); - SET_GLOBAL_FUN(get_environment, "get_environment"); - SET_GLOBAL_FUN(get_environment, "get_env"); - SET_GLOBAL_FUN(set_environment, "set_environment"); - SET_GLOBAL_FUN(set_environment, "set_env"); - SET_GLOBAL_FUN(import_modules, "import_modules"); - SET_GLOBAL_FUN(export_module, "export_module"); -} - -// IO state -DECL_UDATA(io_state) - -io_state to_io_state_ext(lua_State * L, int idx) { - if (idx <= lua_gettop(L)) - return to_io_state(L, idx); - else - return get_io_state(L); -} - -int mk_io_state(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 0) - return push_io_state(L, io_state(mk_print_formatter_factory())); - else if (nargs == 1) - return push_io_state(L, io_state(to_io_state(L, 1))); - else - return push_io_state(L, io_state(to_options(L, 1), to_formatter_factory(L, 2))); -} - -static int io_state_get_options(lua_State * L) { return push_options(L, to_io_state(L, 1).get_options()); } -static int io_state_get_formatter_factory(lua_State * L) { return push_formatter_factory(L, to_io_state(L, 1).get_formatter_factory()); } -static int io_state_set_options(lua_State * L) { to_io_state(L, 1).set_options(to_options(L, 2)); return 0; } - -static mutex * g_print_mutex = nullptr; - -static void print(io_state * ios, bool reg, char const * msg) { - if (ios) { - if (reg) - ios->get_regular_channel() << msg; - else - ios->get_diagnostic_channel() << msg; - } else { - std::cout << msg; - } -} - -/** \brief Thread safe version of print function */ -static int print(lua_State * L, int start, bool reg) { - lock_guard lock(*g_print_mutex); - io_state * ios = get_io_state_ptr(L); - int n = lua_gettop(L); - int i; - lua_getglobal(L, "tostring"); - for (i = start; i <= n; i++) { - char const * s; - size_t l; - lua_pushvalue(L, -1); - lua_pushvalue(L, i); - lua_call(L, 1, 1); - s = lua_tolstring(L, -1, &l); - if (s == NULL) - throw exception("'tostring' must return a string to 'print'"); - if (i > start) { - print(ios, reg, "\t"); - } - print(ios, reg, s); - lua_pop(L, 1); - } - print(ios, reg, "\n"); - return 0; -} - -static int print(lua_State * L, io_state & ios, int start, bool reg) { - set_io_state set(L, ios); - return print(L, start, reg); -} - -static int print(lua_State * L) { return print(L, 1, true); } -static int io_state_print_regular(lua_State * L) { return print(L, to_io_state(L, 1), 2, true); } -static int io_state_print_diagnostic(lua_State * L) { return print(L, to_io_state(L, 1), 2, false); } - -static const struct luaL_Reg io_state_m[] = { - {"__gc", io_state_gc}, // never throws - {"get_options", safe_function}, - {"set_options", safe_function}, - {"get_formatter_factory", safe_function}, - {"print_diagnostic", safe_function}, - {"print_regular", safe_function}, - {"print", safe_function}, - {"diagnostic", safe_function}, - {0, 0} -}; - -static int get_global_io_state(lua_State * L) { - return push_io_state(L, get_io_state(L)); -} - -void open_io_state(lua_State * L) { - luaL_newmetatable(L, io_state_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, io_state_m, 0); - - SET_GLOBAL_FUN(io_state_pred, "is_io_state"); - SET_GLOBAL_FUN(mk_io_state, "io_state"); - SET_GLOBAL_FUN(print, "print"); - SET_GLOBAL_FUN(get_global_io_state, "get_io_state"); - SET_GLOBAL_FUN(get_global_io_state, "get_ios"); -} - -static char g_set_state_key; - -void set_global_io_state(lua_State * L, io_state & ios) { - lua_pushlightuserdata(L, static_cast(&g_set_state_key)); - lua_pushlightuserdata(L, &ios); - lua_settable(L, LUA_REGISTRYINDEX); - set_global_options(L, ios.get_options()); -} - -set_io_state::set_io_state(lua_State * L, io_state & st) { - m_state = L; - m_prev = get_io_state_ptr(L); - lua_pushlightuserdata(m_state, static_cast(&g_set_state_key)); - lua_pushlightuserdata(m_state, &st); - lua_settable(m_state, LUA_REGISTRYINDEX); - if (!m_prev) - m_prev_options = get_global_options(m_state); - set_global_options(m_state, st.get_options()); -} - -set_io_state::~set_io_state() { - lua_pushlightuserdata(m_state, static_cast(&g_set_state_key)); - lua_pushlightuserdata(m_state, m_prev); - lua_settable(m_state, LUA_REGISTRYINDEX); - if (!m_prev) - set_global_options(m_state, m_prev_options); - else - set_global_options(m_state, m_prev->get_options()); -} - -io_state * get_io_state_ptr(lua_State * L) { - lua_pushlightuserdata(L, static_cast(&g_set_state_key)); - lua_gettable(L, LUA_REGISTRYINDEX); - if (lua_islightuserdata(L, -1)) { - io_state * r = static_cast(lua_touserdata(L, -1)); - if (r) { - lua_pop(L, 1); - options o = get_global_options(L); - r->set_options(o); - return r; - } - } - lua_pop(L, 1); - return nullptr; -} - -io_state get_tmp_io_state(lua_State * L) { - return io_state(get_global_options(L), get_global_formatter_factory(L)); -} - -// Justification -DECL_UDATA(justification) - -int push_optional_justification(lua_State * L, optional const & j) { return j ? push_justification(L, *j) : push_nil(L); } - -static int justification_tostring(lua_State * L) { - std::ostringstream out; - justification & jst = to_justification(L, 1); - out << jst; - lua_pushstring(L, out.str().c_str()); - return 1; -} - -#define JST_PRED(P) static int justification_ ## P(lua_State * L) { check_num_args(L, 1); return push_boolean(L, to_justification(L, 1).P()); } -JST_PRED(is_none) -JST_PRED(is_asserted) -JST_PRED(is_assumption) -JST_PRED(is_composite) -static int justification_get_main_expr(lua_State * L) { return push_optional_expr(L, to_justification(L, 1).get_main_expr()); } -static int justification_pp(lua_State * L) { - int nargs = lua_gettop(L); - justification & j = to_justification(L, 1); - if (nargs == 1) - return push_format(L, j.pp(mk_formatter(L), nullptr, substitution())); - else if (nargs == 2 && is_substitution(L, 2)) - return push_format(L, j.pp(mk_formatter(L), nullptr, to_substitution(L, 2))); - else if (nargs == 2) - return push_format(L, j.pp(to_formatter(L, 2), nullptr, substitution())); - else - return push_format(L, j.pp(to_formatter(L, 2), nullptr, to_substitution(L, 3))); -} -static int justification_assumption_idx(lua_State * L) { - if (!to_justification(L, 1).is_assumption()) - throw exception("arg #1 must be an assumption justification"); - return push_integer(L, assumption_idx(to_justification(L, 1))); -} -static int justification_child1(lua_State * L) { - if (!to_justification(L, 1).is_composite()) - throw exception("arg #1 must be a composite justification"); - return push_justification(L, composite_child1(to_justification(L, 1))); -} -static int justification_child2(lua_State * L) { - if (!to_justification(L, 1).is_composite()) - throw exception("arg #1 must be a composite justification"); - return push_justification(L, composite_child2(to_justification(L, 1))); -} -static int justification_depends_on(lua_State * L) { return push_boolean(L, depends_on(to_justification(L, 1), luaL_checkinteger(L, 2))); } -static int mk_assumption_justification(lua_State * L) { return push_justification(L, mk_assumption_justification(luaL_checkinteger(L, 1))); } -static int mk_composite1(lua_State * L) { return push_justification(L, mk_composite1(to_justification(L, 1), to_justification(L, 2))); } -static int mk_justification(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 0) { - return push_justification(L, justification()); - } else if (nargs == 1) { - std::string s = lua_tostring(L, 1); - return push_justification(L, mk_justification(none_expr(), [=](formatter const &, substitution const &, bool) { - return format(s.c_str()); - })); - } else { - std::string s = lua_tostring(L, 1); - environment env = to_environment(L, 2); - expr e = to_expr(L, 3); - justification j = mk_justification(some_expr(e), [=](formatter const & fmt, substitution const & subst, bool) { - expr new_e = substitution(subst).instantiate(e); - format r; - r += format(s.c_str()); - r += pp_indent_expr(fmt, new_e); - return r; - }); - return push_justification(L, j); - } -} -static int justification_is_eqp(lua_State * L) { return push_boolean(L, is_eqp(to_justification(L, 1), to_justification(L, 2))); } - -static const struct luaL_Reg justification_m[] = { - {"__gc", justification_gc}, // never throws - {"__tostring", safe_function}, - {"is_none", safe_function}, - {"is_asserted", safe_function}, - {"is_assumption", safe_function}, - {"is_composite", safe_function}, - {"main_expr", safe_function}, - {"pp", safe_function}, - {"depends_on", safe_function}, - {"assumption_idx", safe_function}, - {"child1", safe_function}, - {"child2", safe_function}, - {"is_eqp", safe_function}, - {0, 0} -}; - -static void open_justification(lua_State * L) { - luaL_newmetatable(L, justification_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, justification_m, 0); - - SET_GLOBAL_FUN(mk_justification, "justification"); - SET_GLOBAL_FUN(mk_assumption_justification, "assumption_justification"); - SET_GLOBAL_FUN(mk_composite1, "mk_composite_justification"); - SET_GLOBAL_FUN(justification_pred, "is_justification"); -} - -// Constraint -DECL_UDATA(constraint) -DEFINE_LUA_LIST(constraint, push_constraint, to_constraint) -int push_optional_constraint(lua_State * L, optional const & c) { return c ? push_constraint(L, *c) : push_nil(L); } -#define CNSTR_PRED(P) static int constraint_ ## P(lua_State * L) { check_num_args(L, 1); return push_boolean(L, P(to_constraint(L, 1))); } -CNSTR_PRED(is_eq_cnstr) -CNSTR_PRED(is_level_eq_cnstr) -CNSTR_PRED(is_choice_cnstr) -static int constraint_is_eqp(lua_State * L) { return push_boolean(L, is_eqp(to_constraint(L, 1), to_constraint(L, 2))); } -static int constraint_get_kind(lua_State * L) { return push_integer(L, static_cast(to_constraint(L, 1).kind())); } -static int constraint_jst(lua_State * L) { return push_justification(L, to_constraint(L, 1).get_justification()); } -static int constraint_lhs(lua_State * L) { - constraint const & c = to_constraint(L, 1); - if (is_eq_cnstr(c)) - return push_expr(L, cnstr_lhs_expr(c)); - else if (is_level_eq_cnstr(c)) - return push_level(L, cnstr_lhs_level(c)); - else - throw exception("arg #1 must be an equality/level constraint"); -} -static int constraint_rhs(lua_State * L) { - constraint const & c = to_constraint(L, 1); - if (is_eq_cnstr(c)) - return push_expr(L, cnstr_rhs_expr(c)); - else if (is_level_eq_cnstr(c)) - return push_level(L, cnstr_rhs_level(c)); - else - throw exception("arg #1 must be an equality/level constraint"); -} -static int constraint_tostring(lua_State * L) { - std::ostringstream out; - out << to_constraint(L, 1); - return push_string(L, out.str().c_str()); -} -static int mk_eq_cnstr(lua_State * L) { - int nargs = lua_gettop(L); - return push_constraint(L, mk_eq_cnstr(to_expr(L, 1), to_expr(L, 2), - nargs >= 3 ? to_justification(L, 3) : justification())); -} -static int mk_level_eq_cnstr(lua_State * L) { - int nargs = lua_gettop(L); - return push_constraint(L, mk_level_eq_cnstr(to_level_ext(L, 1), to_level_ext(L, 2), - nargs == 3 ? to_justification(L, 3) : justification())); -} - -static choice_fn to_choice_fn(lua_State * L, int idx) { - luaL_checktype(L, idx, LUA_TFUNCTION); // user-fun - luaref f(L, idx); - return choice_fn([=](expr const & mvar, expr const & mvar_type, substitution const & s, name_generator const & ngen) { - lua_State * L = f.get_state(); - f.push(); - push_expr(L, mvar); - push_expr(L, mvar_type); - push_substitution(L, s); - push_name_generator(L, ngen); - pcall(L, 4, 1, 0); - buffer r; - if (lua_isnil(L, -1)) { - // do nothing - } else if (lua_istable(L, -1)) { - int num = objlen(L, -1); - // each entry is an alternative - for (int i = 1; i <= num; i++) { - lua_rawgeti(L, -1, i); - if (is_constraint(L, -1)) - r.push_back(constraints(to_constraint(L, -1))); - else if (is_expr(L, -1)) - r.push_back(constraints(mk_eq_cnstr(mvar, to_expr(L, -1), justification()))); - else - r.push_back(to_list_constraint_ext(L, -1)); - lua_pop(L, 1); - } - } else { - throw exception("invalid choice function, result must be an array of triples"); - } - lua_pop(L, 1); - return to_lazy(to_list(r.begin(), r.end())); - }); -} - -static int mk_choice_cnstr(lua_State * L) { - int nargs = lua_gettop(L); - expr m = to_expr(L, 1); - choice_fn fn = to_choice_fn(L, 2); - if (nargs == 2) - return push_constraint(L, mk_choice_cnstr(m, fn, 0, false, justification())); - else if (nargs == 3 && is_justification(L, 3)) - return push_constraint(L, mk_choice_cnstr(m, fn, 0, false, to_justification(L, 3))); - else if (nargs == 3) - return push_constraint(L, mk_choice_cnstr(m, fn, lua_tonumber(L, 3), false, justification())); - else if (nargs == 4) - return push_constraint(L, mk_choice_cnstr(m, fn, lua_tonumber(L, 3), lua_toboolean(L, 4), justification())); - else - return push_constraint(L, mk_choice_cnstr(m, fn, lua_tonumber(L, 3), lua_toboolean(L, 4), - to_justification(L, 5))); -} - -static int constraint_expr(lua_State * L) { - constraint const & c = to_constraint(L, 1); - if (is_choice_cnstr(c)) - return push_expr(L, cnstr_expr(c)); - else - throw exception("arg #1 must be a choice constraint"); -} - -static int constraint_delay_factor(lua_State * L) { - constraint const & c = to_constraint(L, 1); - if (is_choice_cnstr(c)) - return push_integer(L, cnstr_delay_factor(c)); - else - throw exception("arg #1 must be a choice constraint"); -} - -static const struct luaL_Reg constraint_m[] = { - {"__gc", constraint_gc}, // never throws - {"__tostring", safe_function}, - {"is_eq", safe_function}, - {"is_level_eq", safe_function}, - {"is_choice", safe_function}, - {"is_eqp", safe_function}, - {"kind", safe_function}, - {"lhs", safe_function}, - {"rhs", safe_function}, - {"justification", safe_function}, - {"expr", safe_function}, - {"delay_factor", safe_function}, - {0, 0} -}; - -// Constraint sequences -DECL_UDATA(constraint_seq) - -static int constraint_seq_mk(lua_State * L) { - unsigned nargs = lua_gettop(L); - constraint_seq cs; - for (unsigned i = 0; i < nargs; i++) { - cs += to_constraint(L, i); - } - return push_constraint_seq(L, cs); -} - -static int constraint_seq_concat(lua_State * L) { - if (is_constraint_seq(L, 1) && is_constraint(L, 2)) - return push_constraint_seq(L, to_constraint_seq(L, 1) + to_constraint(L, 2)); - else - return push_constraint_seq(L, to_constraint_seq(L, 1) + to_constraint_seq(L, 2)); -} - -static int constraint_seq_linearize(lua_State * L) { - buffer tmp; - to_constraint_seq(L, 1).linearize(tmp); - lua_newtable(L); - int i = 1; - for (constraint const & c : tmp) { - push_constraint(L, c); - lua_rawseti(L, -2, i); - i++; - } - return 1; -} - -static const struct luaL_Reg constraint_seq_m[] = { - {"__gc", constraint_seq_gc}, - {"__concat", constraint_seq_concat}, - {"concat", constraint_seq_concat}, - {"linearize", constraint_seq_linearize}, - {0, 0} -}; - -static void open_constraint(lua_State * L) { - luaL_newmetatable(L, constraint_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, constraint_m, 0); - - luaL_newmetatable(L, constraint_seq_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, constraint_seq_m, 0); - - SET_GLOBAL_FUN(constraint_pred, "is_constraint"); - SET_GLOBAL_FUN(mk_eq_cnstr, "mk_eq_cnstr"); - SET_GLOBAL_FUN(mk_level_eq_cnstr, "mk_level_eq_cnstr"); - SET_GLOBAL_FUN(mk_choice_cnstr, "mk_choice_cnstr"); - - lua_newtable(L); - SET_ENUM("Eq", constraint_kind::Eq); - SET_ENUM("LevelEq", constraint_kind::LevelEq); - SET_ENUM("Choice", constraint_kind::Choice); - lua_setglobal(L, "constraint_kind"); - - SET_GLOBAL_FUN(constraint_seq_pred, "is_constraint_seq"); - SET_GLOBAL_FUN(constraint_seq_mk, "constraint_seq"); -} - -// Substitution -DECL_UDATA(substitution) -static int mk_substitution(lua_State * L) { return push_substitution(L, substitution()); } -static int subst_assign(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 3) { - if (is_expr(L, 3)) { - if (is_expr(L, 2)) - to_substitution(L, 1).assign(to_expr(L, 2), to_expr(L, 3)); - else - to_substitution(L, 1).assign(to_name_ext(L, 2), to_expr(L, 3)); - } else { - if (is_level(L, 2)) - to_substitution(L, 1).assign(to_level(L, 2), to_level(L, 3)); - else - to_substitution(L, 1).assign(to_name_ext(L, 2), to_level(L, 3)); - } - } else { - if (is_expr(L, 3)) { - if (is_expr(L, 2)) - to_substitution(L, 1).assign(to_expr(L, 2), to_expr(L, 3), to_justification(L, 4)); - else - to_substitution(L, 1).assign(to_name_ext(L, 2), to_expr(L, 3), to_justification(L, 4)); - } else { - if (is_level(L, 2)) - to_substitution(L, 1).assign(to_level(L, 2), to_level(L, 3), to_justification(L, 4)); - else - to_substitution(L, 1).assign(to_name_ext(L, 2), to_level(L, 3), to_justification(L, 4)); - } - } - return 0; -} -static int subst_is_assigned(lua_State * L) { - if (is_expr(L, 2)) - return push_boolean(L, to_substitution(L, 1).is_assigned(to_expr(L, 2))); - else - return push_boolean(L, to_substitution(L, 1).is_assigned(to_level(L, 2))); -} -static int subst_is_expr_assigned(lua_State * L) { return push_boolean(L, to_substitution(L, 1).is_expr_assigned(to_name_ext(L, 2))); } -static int subst_is_level_assigned(lua_State * L) { return push_boolean(L, to_substitution(L, 1).is_level_assigned(to_name_ext(L, 2))); } -static int subst_occurs(lua_State * L) { return push_boolean(L, to_substitution(L, 1).occurs(to_expr(L, 2), to_expr(L, 3))); } -static int subst_occurs_expr(lua_State * L) { return push_boolean(L, to_substitution(L, 1).occurs_expr(to_name_ext(L, 2), to_expr(L, 3))); } -static int subst_instantiate(lua_State * L) { - if (is_expr(L, 2)) { - auto r = to_substitution(L, 1).instantiate_metavars(to_expr(L, 2)); - push_expr(L, r.first); push_justification(L, r.second); - } else { - auto r = to_substitution(L, 1).instantiate_metavars(to_level(L, 2)); - push_level(L, r.first); push_justification(L, r.second); - } - return 2; -} - -static int subst_instantiate_all(lua_State * L) { - auto r = to_substitution(L, 1).instantiate_metavars_all(to_expr(L, 2)); - push_expr(L, r.first); push_justification(L, r.second); - return 2; -} - -static int subst_for_each_expr(lua_State * L) { - substitution const & s = to_substitution(L, 1); - luaL_checktype(L, 2, LUA_TFUNCTION); // user-fun - s.for_each_expr([&](name const & n, expr const & e, justification const & j) { - lua_pushvalue(L, 2); // push user-fun - push_name(L, n); push_expr(L, e); push_justification(L, j); - pcall(L, 3, 0, 0); - }); - return 0; -} - -static int subst_for_each_level(lua_State * L) { - substitution const & s = to_substitution(L, 1); - luaL_checktype(L, 2, LUA_TFUNCTION); // user-fun - s.for_each_level([&](name const & n, level const & l, justification const & j) { - lua_pushvalue(L, 2); // push user-fun - push_name(L, n); push_level(L, l); push_justification(L, j); - pcall(L, 3, 0, 0); - }); - return 0; -} - -static int subst_copy(lua_State * L) { - return push_substitution(L, substitution(to_substitution(L, 1))); -} - -static const struct luaL_Reg substitution_m[] = { - {"__gc", substitution_gc}, - {"copy", safe_function}, - {"assign", safe_function}, - {"is_assigned", safe_function}, - {"is_expr_assigned", safe_function}, - {"is_level_assigned", safe_function}, - {"occurs", safe_function}, - {"occurs_expr", safe_function}, - {"instantiate", safe_function}, - {"instantiate_all", safe_function}, - {"for_each_expr", safe_function}, - {"for_each_level", safe_function}, - {0, 0} -}; - -static void open_substitution(lua_State * L) { - luaL_newmetatable(L, substitution_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, substitution_m, 0); - - SET_GLOBAL_FUN(mk_substitution, "substitution"); - SET_GLOBAL_FUN(substitution_pred, "is_substitution"); -} - -// type_checker -DECL_UDATA(type_checker_ref) - -static int mk_type_checker(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 1) { - return push_type_checker_ref(L, std::make_shared(to_environment(L, 1))); - } else { - return push_type_checker_ref(L, std::make_shared(to_environment(L, 1), - to_name_generator(L, 2).mk_child())); - } -} -static int type_checker_whnf(lua_State * L) { return push_ecs(L, to_type_checker_ref(L, 1)->whnf(to_expr(L, 2))); } -static int type_checker_ensure_pi(lua_State * L) { - if (lua_gettop(L) == 2) - return push_ecs(L, to_type_checker_ref(L, 1)->ensure_pi(to_expr(L, 2))); - else - return push_ecs(L, to_type_checker_ref(L, 1)->ensure_pi(to_expr(L, 2), to_expr(L, 3))); -} -static int type_checker_ensure_sort(lua_State * L) { - if (lua_gettop(L) == 2) - return push_ecs(L, to_type_checker_ref(L, 1)->ensure_sort(to_expr(L, 2))); - else - return push_ecs(L, to_type_checker_ref(L, 1)->ensure_sort(to_expr(L, 2), to_expr(L, 3))); -} -static int type_checker_check(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs <= 2) - return push_ecs(L, to_type_checker_ref(L, 1)->check(to_expr(L, 2), level_param_names())); - else - return push_ecs(L, to_type_checker_ref(L, 1)->check(to_expr(L, 2), to_level_param_names(L, 3))); -} -static int type_checker_infer(lua_State * L) { return push_ecs(L, to_type_checker_ref(L, 1)->infer(to_expr(L, 2))); } - -static int type_checker_is_def_eq(lua_State * L) { return push_bcs(L, to_type_checker_ref(L, 1)->is_def_eq(to_expr(L, 2), to_expr(L, 3))); } -static int type_checker_is_prop(lua_State * L) { return push_bcs(L, to_type_checker_ref(L, 1)->is_prop(to_expr(L, 2))); } - -static name * g_tmp_prefix = nullptr; - -static int mk_type_checker_with_hints(lua_State * L) { - environment const & env = to_environment(L, 1); - int nargs = lua_gettop(L); - if (nargs == 1) { - return push_type_checker_ref(L, mk_type_checker(env, name_generator(*g_tmp_prefix))); - } else { - return push_type_checker_ref(L, mk_type_checker(env, to_name_generator(L, 2).mk_child())); - } -} - -static const struct luaL_Reg type_checker_ref_m[] = { - {"__gc", type_checker_ref_gc}, - {"whnf", safe_function}, - {"ensure_pi", safe_function}, - {"ensure_sort", safe_function}, - {"check", safe_function}, - {"infer", safe_function}, - {"is_def_eq", safe_function}, - {"is_prop", safe_function}, - {0, 0} -}; - -// type_check procedure -static int type_check(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 2) { - return push_certified_declaration(L, check(to_environment(L, 1), to_declaration(L, 2))); - } else { - return push_certified_declaration(L, check(to_environment(L, 1), to_declaration(L, 2), - to_name_generator(L, 3).mk_child())); - } -} - -static int add_declaration(lua_State * L) { - int nargs = lua_gettop(L); - optional d; - environment const & env = to_environment(L, 1); - if (nargs == 2) { - d = check(env, unfold_untrusted_macros(env, to_declaration(L, 2))); - } else { - d = check(env, unfold_untrusted_macros(env, to_declaration(L, 2)), to_name_generator(L, 3).mk_child()); - } - return push_environment(L, module::add(to_environment(L, 1), *d)); -} - -static void open_type_checker(lua_State * L) { - luaL_newmetatable(L, type_checker_ref_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, type_checker_ref_m, 0); - - SET_GLOBAL_FUN(mk_type_checker, "type_checker"); - SET_GLOBAL_FUN(mk_type_checker_with_hints, "type_checker_with_hints"); - SET_GLOBAL_FUN(type_checker_ref_pred, "is_type_checker"); - SET_GLOBAL_FUN(type_check, "type_check"); - SET_GLOBAL_FUN(type_check, "check"); - SET_GLOBAL_FUN(add_declaration, "add_decl"); -} - -namespace inductive { -/** \brief Get the number of indices (if available), if they are, increment idx */ -static unsigned get_num_params(lua_State * L, int & idx) { - if (lua_isnumber(L, idx)) { - if (lua_tonumber(L, idx) < 0) - throw exception(sstream() << "arg #" << idx << " (number of parameters) must be nonnegative"); - unsigned r = lua_tonumber(L, idx); - idx++; - return r; - } else { - return 0; - } -} -static int add_inductive1(lua_State * L) { - environment env = to_environment(L, 1); - name const & Iname = to_name_ext(L, 2); - int idx = 3; - level_param_names ls; - if (!is_expr(L, idx) && !lua_isnumber(L, idx)) { - ls = to_level_param_names(L, idx); - idx++; - } - unsigned num_params = get_num_params(L, idx); - expr Itype = to_expr(L, idx); - int nargs = lua_gettop(L); - buffer irules; - for (int i = idx+1; i <= nargs; i+=2) - irules.push_back(mk_intro_rule(to_name_ext(L, i), to_expr(L, i+1))); - return push_environment(L, module::add_inductive(env, Iname, ls, num_params, Itype, to_list(irules.begin(), irules.end()))); -} -static int add_inductivek(lua_State * L) { - environment env = to_environment(L, 1); - level_param_names ls = to_level_param_names(L, 2); - int idx = 3; - unsigned num_params = get_num_params(L, idx); - int nargs = lua_gettop(L); - buffer decls; - for (; idx <= nargs; idx++) { - luaL_checktype(L, idx, LUA_TTABLE); - int decl_sz = objlen(L, idx); - if (decl_sz < 2) - throw exception("invalid add_inductive, datatype declaration must have at least a name and type"); - if (decl_sz % 2 != 0) - throw exception("invalid add_inductive, datatype declaration must have an even number of fields: (name, type)+"); - lua_rawgeti(L, idx, 1); - lua_rawgeti(L, idx, 2); - name Iname = to_name_ext(L, -2); - expr Itype = to_expr(L, -1); - lua_pop(L, 2); - buffer irules; - for (int i = 3; i <= decl_sz; i+=2) { - lua_rawgeti(L, idx, i); - lua_rawgeti(L, idx, i+1); - irules.push_back(mk_intro_rule(to_name_ext(L, -2), to_expr(L, -1))); - lua_pop(L, 2); - } - decls.push_back(inductive_decl(Iname, Itype, to_list(irules.begin(), irules.end()))); - } - if (decls.empty()) - throw exception("invalid add_inductive, at least one inductive type must be defined"); - return push_environment(L, module::add_inductive(env, ls, num_params, to_list(decls.begin(), decls.end()))); -} -static int add_inductive(lua_State * L) { - if (is_name(L, 2) || lua_isstring(L, 2)) - return add_inductive1(L); - else - return add_inductivek(L); -} -} - -static void open_inductive(lua_State * L) { - SET_GLOBAL_FUN(inductive::add_inductive, "add_inductive"); -} - -void open_kernel_module(lua_State * L) { - open_level(L); - open_list_level(L); - open_binder_info(L); - open_expr(L); - open_list_expr(L); - open_macro_definition(L); - open_declaration(L); - open_formatter(L); - open_environment_id(L); - open_certified_declaration(L); - open_list_certified_declaration(L); - open_environment(L); - open_io_state(L); - open_justification(L); - open_constraint(L); - open_list_constraint(L); - open_substitution(L); - open_type_checker(L); - open_inductive(L); -} - -void initialize_kernel_bindings() { - g_print_formatter_factory = new formatter_factory(mk_print_formatter_factory()); - g_print_mutex = new mutex(); - g_tmp_prefix = new name(name::mk_internal_unique_name()); -} -void finalize_kernel_bindings() { - delete g_tmp_prefix; - delete g_print_mutex; - delete g_print_formatter_factory; -} -} diff --git a/src/library/kernel_bindings.h b/src/library/kernel_bindings.h deleted file mode 100644 index 6a1eb1eef..000000000 --- a/src/library/kernel_bindings.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -Copyright (c) 2013-2014 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/script_state.h" -#include "kernel/environment.h" -#include "kernel/type_checker.h" - -namespace lean { -void open_kernel_module(lua_State * L); -UDATA_DEFS(level) -UDATA_DEFS(expr) -UDATA_DEFS(formatter) -UDATA_DEFS(definition) -UDATA_DEFS(macro_definition) -UDATA_DEFS(environment) -UDATA_DEFS(substitution) -UDATA_DEFS(justification) -UDATA_DEFS(constraint) -UDATA_DEFS_CORE(constraint_seq) -UDATA_DEFS(substitution) -UDATA_DEFS(io_state) -UDATA_DEFS_CORE(type_checker_ref) - -int push_optional_level(lua_State * L, optional const & e); -int push_optional_expr(lua_State * L, optional const & e); -int push_optional_justification(lua_State * L, optional const & j); -int push_optional_declaration(lua_State * L, optional const & e); -int push_optional_constraint(lua_State * L, optional const & c); -int push_list_expr(lua_State * L, list const & l); -/** - \brief Return the formatter factory object associated with the given Lua State. - This procedure checks for options at: - 1- Lean state object associated with \c L - 2- Lua Registry associated with \c L -*/ -optional get_global_formatter_factory_core(lua_State * L); -/** - \brief Similar to \c get_global_formatter_factory_core, but returns - the simple_formatter if a formatter can't be found. -*/ -formatter_factory get_global_formatter_factory(lua_State * L); -/** - \brief Update the formatter object associated with the given Lua State. - If \c L is associated with a Lean state object \c S, then we update the formatter of \c S. - Otherwise, we update the registry of \c L. -*/ -void set_global_formatter_factory(lua_State * L, formatter_factory const & fmtf); - -/** \brief Make a fresh formatter object using the global formatter factory associated with L, and the global environment */ -formatter mk_formatter(lua_State * L); - -/** \brief Set the Lua registry of a Lua state with an environment object. */ -void set_global_environment(lua_State * L, environment const & env); -environment get_global_environment(lua_State * L); -/** - \brief Auxiliary class for temporarily setting the Lua registry of a Lua state - with an environment object. -*/ -class set_environment { - lua_State * m_state; - environment * m_old_env; -public: - set_environment(lua_State * L, environment & env); - set_environment(script_state & S, environment & env):set_environment(S.get_state(), env) {} - ~set_environment(); -}; - -/** \brief Set the Lua registry of a Lua state with an io_state object. */ -void set_global_io_state(lua_State * L, io_state & ios); -/** - \brief Auxiliary class for temporarily setting the Lua registry of a Lua state - with a Lean io_state object. -*/ -class set_io_state { - lua_State * m_state; - io_state * m_prev; - options m_prev_options; -public: - set_io_state(lua_State * L, io_state & ios); - set_io_state(script_state & S, io_state & ios):set_io_state(S.get_state(), ios) {} - ~set_io_state(); -}; -/** - \brief Return the Lean state object associated with the given Lua state. - Return nullptr is there is none. -*/ -io_state * get_io_state_ptr(lua_State * L); -io_state get_io_state(lua_State * L); -io_state to_io_state_ext(lua_State * L, int idx); -void open_io_state(lua_State * L); - -void initialize_kernel_bindings(); -void finalize_kernel_bindings(); -} diff --git a/src/library/match.cpp b/src/library/match.cpp index 33940312b..2e937725c 100644 --- a/src/library/match.cpp +++ b/src/library/match.cpp @@ -10,7 +10,6 @@ Author: Leonardo de Moura #include "kernel/instantiate.h" #include "kernel/for_each_fn.h" #include "kernel/type_checker.h" -#include "library/kernel_bindings.h" #include "library/locals.h" #include "library/match.h" #include "library/idx_metavar.h" @@ -436,89 +435,4 @@ static pair get_idx_meta_univ_ranges(expr const & e) { }); return mk_pair(rlvl, rexp); } - -typedef std::shared_ptr match_plugin_ref; -DECL_UDATA(match_plugin_ref) - -static const struct luaL_Reg match_plugin_ref_m[] = { - {"__gc", match_plugin_ref_gc}, - {0, 0} -}; - -// version of whnf_match_plugin for Lua -class whnf_match_plugin2 : public whnf_match_plugin { - std::shared_ptr m_tc_ref; -public: - whnf_match_plugin2(std::shared_ptr & tc): - whnf_match_plugin(*tc), m_tc_ref(tc) {} -}; - -static int mk_whnf_match_plugin(lua_State * L) { - return push_match_plugin_ref(L, match_plugin_ref(new whnf_match_plugin2(to_type_checker_ref(L, 1)))); -} - -static int match(lua_State * L) { - int nargs = lua_gettop(L); - expr p = to_expr(L, 1); - expr t = to_expr(L, 2); - match_plugin * plugin = nullptr; - if (nargs >= 3) - plugin = to_match_plugin_ref(L, 3).get(); - if (!closed(t)) - throw exception("higher-order pattern matching failure, input term must not contain free variables"); - unsigned r1, r2; - auto r1_r2 = get_idx_meta_univ_ranges(p); - r1 = r1_r2.first; - r2 = r1_r2.second; - buffer> lsubst; - buffer> esubst; - lsubst.resize(r1); esubst.resize(r2); - if (match(p, t, lsubst, esubst, nullptr, nullptr, plugin)) { - lua_newtable(L); - int i = 1; - for (auto s : esubst) { - if (s) - push_expr(L, *s); - else - lua_pushboolean(L, false); - lua_rawseti(L, -2, i); - i = i + 1; - } - lua_newtable(L); - i = 1; - for (auto s : lsubst) { - if (s) - push_level(L, *s); - else - lua_pushboolean(L, false); - lua_rawseti(L, -2, i); - i = i + 1; - } - } else { - lua_pushnil(L); - lua_pushnil(L); - } - return 2; -} - -static int mk_idx_metauniv(lua_State * L) { - return push_level(L, mk_idx_metauniv(luaL_checkinteger(L, 1))); -} - -static int mk_idx_metavar(lua_State * L) { - return push_expr(L, mk_idx_metavar(luaL_checkinteger(L, 1), to_expr(L, 2))); -} - -void open_match(lua_State * L) { - luaL_newmetatable(L, match_plugin_ref_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, match_plugin_ref_m, 0); - - SET_GLOBAL_FUN(mk_whnf_match_plugin, "whnf_match_plugin"); - SET_GLOBAL_FUN(match_plugin_ref_pred, "is_match_plugin"); - SET_GLOBAL_FUN(mk_idx_metauniv, "mk_idx_metauniv"); - SET_GLOBAL_FUN(mk_idx_metavar, "mk_idx_metavar"); - SET_GLOBAL_FUN(match, "match"); -} } diff --git a/src/library/match.h b/src/library/match.h index b917723f8..22d96f21f 100644 --- a/src/library/match.h +++ b/src/library/match.h @@ -6,7 +6,6 @@ Author: Leonardo de Moura */ #pragma once #include -#include "util/lua.h" #include "util/optional.h" #include "util/lbool.h" #include "util/buffer.h" @@ -110,7 +109,6 @@ bool match(expr const & p, expr const & t, name const * prefix = nullptr, name_map * name_subst = nullptr, match_plugin const * plugin = nullptr, bool * assigned = nullptr); -void open_match(lua_State * L); void initialize_match(); void finalize_match(); } diff --git a/src/library/placeholder.cpp b/src/library/placeholder.cpp index 57840009a..f9ef1fe4a 100644 --- a/src/library/placeholder.cpp +++ b/src/library/placeholder.cpp @@ -7,7 +7,6 @@ Author: Leonardo de Moura #include "util/thread.h" #include "kernel/find_fn.h" #include "library/placeholder.h" -#include "library/kernel_bindings.h" namespace lean { static name * g_implicit_placeholder_name = nullptr; @@ -101,34 +100,4 @@ bool has_placeholder(expr const & e) { return false; }); } - -static int mk_level_placeholder(lua_State * L) { return push_level(L, mk_level_placeholder()); } -static int mk_expr_placeholder(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 0) - return push_expr(L, mk_expr_placeholder()); - else - return push_expr(L, mk_expr_placeholder(some_expr(to_expr(L, 1)))); -} -static int is_placeholder(lua_State * L) { - if (is_expr(L, 1)) - return push_boolean(L, is_placeholder(to_expr(L, 1))); - else - return push_boolean(L, is_placeholder(to_level(L, 1))); -} -static int has_placeholder(lua_State * L) { - if (is_expr(L, 1)) - return push_boolean(L, has_placeholder(to_expr(L, 1))); - else - return push_boolean(L, has_placeholder(to_level(L, 1))); -} -static int placeholder_type(lua_State * L) { return push_optional_expr(L, placeholder_type(to_expr(L, 1))); } - -void open_placeholder(lua_State * L) { - SET_GLOBAL_FUN(mk_level_placeholder, "mk_level_placeholder"); - SET_GLOBAL_FUN(mk_expr_placeholder, "mk_expr_placeholder"); - SET_GLOBAL_FUN(is_placeholder, "is_placeholder"); - SET_GLOBAL_FUN(placeholder_type, "placeholder_type"); - SET_GLOBAL_FUN(has_placeholder, "has_placeholder"); -} } diff --git a/src/library/placeholder.h b/src/library/placeholder.h index b9825a80d..d8e239086 100644 --- a/src/library/placeholder.h +++ b/src/library/placeholder.h @@ -5,7 +5,6 @@ Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #pragma once -#include "util/lua.h" #include "kernel/expr.h" // Placeholders are used to mark locations where additional @@ -42,7 +41,6 @@ optional placeholder_type(expr const & e); /** \brief Return true iff the given expression contains placeholders. */ bool has_placeholder(expr const & e); -void open_placeholder(lua_State * L); void initialize_placeholder(); void finalize_placeholder(); } diff --git a/src/library/private.cpp b/src/library/private.cpp index df8efd7df..7e61cddbf 100644 --- a/src/library/private.cpp +++ b/src/library/private.cpp @@ -9,7 +9,6 @@ Author: Leonardo de Moura #include "util/hash.h" #include "library/private.h" #include "library/module.h" -#include "library/kernel_bindings.h" #include "library/fingerprint.h" namespace lean { @@ -80,26 +79,6 @@ bool is_private(environment const & env, name const & n) { return static_cast(hidden_to_user_name(env, n)); } -static int add_private_name(lua_State * L) { - int nargs = lua_gettop(L); - optional h; - if (nargs > 2) - h = lua_tonumber(L, 3); - auto p = add_private_name(to_environment(L, 1), to_name_ext(L, 2), h); - push_environment(L, p.first); - push_name(L, p.second); - return 2; -} - -static int hidden_to_user_name(lua_State * L) { - return push_optional_name(L, hidden_to_user_name(to_environment(L, 1), to_name_ext(L, 2))); -} - -void open_private(lua_State * L) { - SET_GLOBAL_FUN(add_private_name, "add_private_name"); - SET_GLOBAL_FUN(hidden_to_user_name, "hidden_to_user_name"); -} - void initialize_private() { g_ext = new private_ext_reg(); g_private = new name("private"); diff --git a/src/library/private.h b/src/library/private.h index a2f17de0a..700e09345 100644 --- a/src/library/private.h +++ b/src/library/private.h @@ -7,7 +7,6 @@ Author: Leonardo de Moura #pragma once #include #include "util/optional.h" -#include "util/lua.h" #include "kernel/environment.h" namespace lean { @@ -33,7 +32,6 @@ optional hidden_to_user_name(environment const & env, name const & n); bool is_private(environment const & env, name const & n); -void open_private(lua_State * L); void initialize_private(); void finalize_private(); } diff --git a/src/library/reducible.cpp b/src/library/reducible.cpp index 51883fc28..82413f18d 100644 --- a/src/library/reducible.cpp +++ b/src/library/reducible.cpp @@ -11,7 +11,6 @@ Author: Leonardo de Moura #include "library/kernel_serializer.h" #include "library/scoped_ext.h" #include "library/reducible.h" -#include "library/kernel_bindings.h" #include "library/attribute_manager.h" namespace lean { @@ -177,67 +176,4 @@ type_checker_ptr mk_type_checker(environment const & env, reducible_behavior rb) type_checker_ptr mk_opaque_type_checker(environment const & env, name_generator && ngen) { return mk_type_checker(env, std::move(ngen), [](name const &) { return true; }); } - -static int mk_opaque_type_checker(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 0) { - type_checker_ref r(mk_opaque_type_checker(get_global_environment(L), name_generator())); - return push_type_checker_ref(L, r); - } else if (nargs == 1) { - type_checker_ref r(mk_opaque_type_checker(to_environment(L, 1), name_generator())); - return push_type_checker_ref(L, r); - } else { - type_checker_ref r(mk_opaque_type_checker(to_environment(L, 1), to_name_generator(L, 2).mk_child())); - return push_type_checker_ref(L, r); - } -} - -static int mk_reducible_checker_core(lua_State * L, reducible_behavior rb) { - int nargs = lua_gettop(L); - if (nargs == 0) { - type_checker_ref r(mk_type_checker(get_global_environment(L), name_generator(), rb)); - return push_type_checker_ref(L, r); - } else if (nargs == 1) { - type_checker_ref r(mk_type_checker(to_environment(L, 1), name_generator(), rb)); - return push_type_checker_ref(L, r); - } else { - type_checker_ref r(mk_type_checker(to_environment(L, 1), to_name_generator(L, 2).mk_child(), rb)); - return push_type_checker_ref(L, r); - } -} - -static int mk_reducible_type_checker(lua_State * L) { - return mk_reducible_checker_core(L, UnfoldReducible); -} - -static int mk_non_irreducible_type_checker(lua_State * L) { - return mk_reducible_checker_core(L, UnfoldSemireducible); -} - -static int set_reducible(lua_State * L) { - int nargs = lua_gettop(L); - environment const & env = to_environment(L, 1); - if (nargs == 3) { - return push_environment(L, set_reducible(env, to_name_ext(L, 2), - static_cast(lua_tonumber(L, 3)), - get_namespace(env), true)); - } else { - return push_environment(L, set_reducible(env, to_name_ext(L, 2), - static_cast(lua_tonumber(L, 3)), - get_namespace(env), lua_toboolean(L, 4))); - } -} - -void open_reducible(lua_State * L) { - lua_newtable(L); - SET_ENUM("Reducible", reducible_status::Reducible); - SET_ENUM("QuasiReducible", reducible_status::Quasireducible); - SET_ENUM("SemiReducible", reducible_status::Semireducible); - SET_ENUM("Irreducible", reducible_status::Irreducible); - lua_setglobal(L, "reducible_status"); - SET_GLOBAL_FUN(set_reducible, "set_reducible"); - SET_GLOBAL_FUN(mk_opaque_type_checker, "opaque_type_checker"); - SET_GLOBAL_FUN(mk_non_irreducible_type_checker, "non_irreducible_type_checker"); - SET_GLOBAL_FUN(mk_reducible_type_checker, "reducible_type_checker"); -} } diff --git a/src/library/reducible.h b/src/library/reducible.h index 04de65fa7..5d186f893 100644 --- a/src/library/reducible.h +++ b/src/library/reducible.h @@ -49,5 +49,4 @@ type_checker_ptr mk_opaque_type_checker(environment const & env, name_generator void initialize_reducible(); void finalize_reducible(); -void open_reducible(lua_State * L); } diff --git a/src/library/resolve_macro.cpp b/src/library/resolve_macro.cpp index 16488632a..6fe733221 100644 --- a/src/library/resolve_macro.cpp +++ b/src/library/resolve_macro.cpp @@ -10,7 +10,6 @@ Author: Leonardo de Moura #include "kernel/justification.h" #include "kernel/kernel_exception.h" #include "kernel/free_vars.h" -#include "library/kernel_bindings.h" #include "library/kernel_serializer.h" #include "library/bin_app.h" #include "library/constants.h" @@ -348,7 +347,4 @@ void finalize_resolve_macro() { delete g_resolve_opcode; delete g_resolve_macro_name; } - -static int mk_resolve_macro(lua_State * L) { return push_expr(L, mk_resolve_macro(to_expr(L, 1), to_expr(L, 2), to_expr(L, 3))); } -void open_resolve_macro(lua_State * L) { SET_GLOBAL_FUN(mk_resolve_macro, "resolve_macro"); } } diff --git a/src/library/resolve_macro.h b/src/library/resolve_macro.h index 7124c2742..e4c82c0c1 100644 --- a/src/library/resolve_macro.h +++ b/src/library/resolve_macro.h @@ -5,12 +5,10 @@ Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #pragma once -#include "util/lua.h" #include "kernel/expr.h" namespace lean { expr mk_resolve_macro(expr const & l, expr const & H1, expr const & H2); -void open_resolve_macro(lua_State * L); void initialize_resolve_macro(); void finalize_resolve_macro(); } diff --git a/src/library/scoped_ext.cpp b/src/library/scoped_ext.cpp index 1eb42a21b..2bbb6cafb 100644 --- a/src/library/scoped_ext.cpp +++ b/src/library/scoped_ext.cpp @@ -9,7 +9,6 @@ Author: Leonardo de Moura #include #include "util/sstream.h" #include "library/scoped_ext.h" -#include "library/kernel_bindings.h" namespace lean { typedef std::tuple entry; @@ -216,50 +215,6 @@ bool has_open_scopes(environment const & env) { return !is_nil(ext.m_namespaces); } -static int using_namespace_objects(lua_State * L) { - int nargs = lua_gettop(L); - environment const & env = to_environment(L, 1); - name n = to_name_ext(L, 2); - if (nargs == 2) - return push_environment(L, using_namespace(env, get_io_state(L), n)); - else if (nargs == 3) - return push_environment(L, using_namespace(env, get_io_state(L), n, to_name_ext(L, 3))); - else - return push_environment(L, using_namespace(env, to_io_state(L, 4), n, to_name_ext(L, 3))); -} - -static int push_scope(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 1) - return push_environment(L, push_scope(to_environment(L, 1), get_io_state(L), scope_kind::Section)); - else if (nargs == 2) - return push_environment(L, push_scope(to_environment(L, 1), get_io_state(L), scope_kind::Namespace, to_name_ext(L, 2))); - scope_kind k = static_cast(lua_tonumber(L, 3)); - if (nargs == 3) - return push_environment(L, push_scope(to_environment(L, 1), get_io_state(L), k, to_name_ext(L, 2))); - else - return push_environment(L, push_scope(to_environment(L, 1), to_io_state(L, 4), k, to_name_ext(L, 2))); -} - -static int pop_scope(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 1) - return push_environment(L, pop_scope(to_environment(L, 1), get_io_state(L))); - else - return push_environment(L, pop_scope(to_environment(L, 1), get_io_state(L), to_name_ext(L, 2))); -} - -void open_scoped_ext(lua_State * L) { - SET_GLOBAL_FUN(using_namespace_objects, "using_namespace_objects"); - SET_GLOBAL_FUN(push_scope, "push_scope"); - SET_GLOBAL_FUN(pop_scope, "pop_scope"); - - lua_newtable(L); - SET_ENUM("Namespace", scope_kind::Namespace); - SET_ENUM("Section", scope_kind::Section); - lua_setglobal(L, "scope_kind"); -} - void initialize_scoped_ext() { g_exts = new scoped_exts(); g_ext = new scope_mng_ext_reg(); diff --git a/src/library/scoped_ext.h b/src/library/scoped_ext.h index a822f7154..af87beaad 100644 --- a/src/library/scoped_ext.h +++ b/src/library/scoped_ext.h @@ -9,7 +9,6 @@ Author: Leonardo de Moura #include "util/list.h" #include "util/rb_map.h" #include "util/name.h" -#include "util/lua.h" #include "kernel/environment.h" #include "library/io_state.h" #include "library/module.h" @@ -81,8 +80,6 @@ environment mark_namespace_as_open(environment const & env, name const & n); /** \brief Return the set of namespaces marked as "open" using \c mark_namespace_as_open. */ name_set get_opened_namespaces(environment const & env); -void open_scoped_ext(lua_State * L); - /** \brief Auxilary template used to simplify the creation of environment extensions that support the scope */ template diff --git a/src/library/tactic/apply_tactic.cpp b/src/library/tactic/apply_tactic.cpp index 99f6ef056..e6c72e0b2 100644 --- a/src/library/tactic/apply_tactic.cpp +++ b/src/library/tactic/apply_tactic.cpp @@ -16,7 +16,6 @@ Author: Leonardo de Moura #include "kernel/error_msgs.h" #include "kernel/type_checker.h" #include "library/reducible.h" -#include "library/kernel_bindings.h" #include "library/unifier.h" #include "library/occurs.h" #include "library/constants.h" diff --git a/src/library/tactic/apply_tactic.h b/src/library/tactic/apply_tactic.h index 7919052c9..d2278762d 100644 --- a/src/library/tactic/apply_tactic.h +++ b/src/library/tactic/apply_tactic.h @@ -5,7 +5,6 @@ Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #pragma once -#include "util/lua.h" #include "library/tactic/elaborate.h" namespace lean { proof_state_seq apply_tactic_core(environment const & env, io_state const & ios, proof_state const & s, expr const & e, constraint_seq const & cs); diff --git a/src/library/tactic/goal.cpp b/src/library/tactic/goal.cpp index 4510ec802..7518b79dc 100644 --- a/src/library/tactic/goal.cpp +++ b/src/library/tactic/goal.cpp @@ -15,7 +15,6 @@ Author: Leonardo de Moura #include "kernel/type_checker.h" #include "kernel/metavar.h" #include "library/util.h" -#include "library/kernel_bindings.h" #include "library/tactic/goal.h" namespace lean { @@ -179,60 +178,4 @@ io_state_stream const & operator<<(io_state_stream const & out, goal const & g) out.get_stream() << mk_pair(g.pp(out.get_formatter()), opts); return out; } - -DECL_UDATA(goal) - -static int mk_goal(lua_State * L) { return push_goal(L, goal(to_expr(L, 1), to_expr(L, 2))); } -static int goal_meta(lua_State * L) { return push_expr(L, to_goal(L, 1).get_meta()); } -static int goal_type(lua_State * L) { return push_expr(L, to_goal(L, 1).get_type()); } -static int goal_tostring(lua_State * L) { - std::ostringstream out; - goal & g = to_goal(L, 1); - formatter fmt = mk_formatter(L); - options opts = get_global_options(L); - out << mk_pair(g.pp(fmt), opts); - lua_pushstring(L, out.str().c_str()); - return 1; -} -static int goal_mk_meta(lua_State * L) { - return push_expr(L, to_goal(L, 1).mk_meta(to_name_ext(L, 2), to_expr(L, 3))); -} - -static int goal_pp(lua_State * L) { - int nargs = lua_gettop(L); - goal & g = to_goal(L, 1); - if (nargs == 1) { - return push_format(L, g.pp(mk_formatter(L))); - } else { - return push_format(L, g.pp(to_formatter(L, 2))); - } -} -static int goal_validate_locals(lua_State * L) { return push_boolean(L, to_goal(L, 1).validate_locals()); } -static int goal_validate(lua_State * L) { return push_boolean(L, to_goal(L, 1).validate(to_environment(L, 2))); } -static int goal_abstract(lua_State * L) { return push_expr(L, to_goal(L, 1).abstract(to_expr(L, 2))); } -static int goal_name(lua_State * L) { return push_name(L, to_goal(L, 1).get_name()); } - -static const struct luaL_Reg goal_m[] = { - {"__gc", goal_gc}, // never throws - {"__tostring", safe_function}, - {"abstract", safe_function}, - {"mk_meta", safe_function}, - {"pp", safe_function}, - {"validate", safe_function}, - {"validate_locals", safe_function}, - {"meta", safe_function}, - {"type", safe_function}, - {"name", safe_function}, - {0, 0} -}; - -void open_goal(lua_State * L) { - luaL_newmetatable(L, goal_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, goal_m, 0); - - SET_GLOBAL_FUN(goal_pred, "is_goal"); - SET_GLOBAL_FUN(mk_goal, "goal"); -} } diff --git a/src/library/tactic/goal.h b/src/library/tactic/goal.h index 7feaea61f..33b0f80bc 100644 --- a/src/library/tactic/goal.h +++ b/src/library/tactic/goal.h @@ -6,7 +6,6 @@ Author: Leonardo de Moura */ #pragma once #include -#include "util/lua.h" #include "util/list.h" #include "util/name.h" #include "kernel/formatter.h" @@ -111,7 +110,4 @@ name get_unused_name(name const & prefix, unsigned & idx, expr const & meta); name get_unused_name(name const & prefix, expr const & meta); io_state_stream const & operator<<(io_state_stream const & out, goal const & g); - -UDATA_DEFS(goal) -void open_goal(lua_State * L); } diff --git a/src/library/tactic/proof_state.cpp b/src/library/tactic/proof_state.cpp index b0663999b..265a470ae 100644 --- a/src/library/tactic/proof_state.cpp +++ b/src/library/tactic/proof_state.cpp @@ -12,7 +12,6 @@ Author: Leonardo de Moura #include "kernel/instantiate.h" #include "kernel/abstract.h" #include "library/io_state_stream.h" -#include "library/kernel_bindings.h" #include "library/tactic/proof_state.h" #ifndef LEAN_PROOF_STATE_GOAL_NAMES @@ -99,163 +98,13 @@ proof_state apply_substitution(proof_state const & s) { return proof_state(s, goals(new_g, gs), subst); } -DECL_UDATA(goals) - -static int mk_goals(lua_State * L) { - int i = lua_gettop(L); - goals r; - if (i > 0 && is_goals(L, i)) { - r = to_goals(L, i); - i--; - } - while (i > 0) { - r = goals(to_goal(L, i), r); - i--; - } - return push_goals(L, r); -} - -static int goals_is_nil(lua_State * L) { - lua_pushboolean(L, !to_goals(L, 1)); - return 1; -} - -static int goals_head(lua_State * L) { - goals const & hs = to_goals(L, 1); - if (!hs) - throw exception("head method expects a non-empty goal list"); - return push_goal(L, head(hs)); -} - -static int goals_tail(lua_State * L) { - goals const & hs = to_goals(L, 1); - if (!hs) - throw exception("tail method expects a non-empty goal list"); - push_goals(L, tail(hs)); - return 1; -} - -static int goals_next(lua_State * L) { - goals & hs = to_goals(L, lua_upvalueindex(1)); - if (hs) { - push_goals(L, tail(hs)); - lua_replace(L, lua_upvalueindex(1)); - return push_goal(L, head(hs)); - } else { - lua_pushnil(L); - return 1; - } -} - -static int goals_items(lua_State * L) { - goals & hs = to_goals(L, 1); - push_goals(L, hs); // upvalue(1): goals - lua_pushcclosure(L, &safe_function, 1); // create closure with 1 upvalue - return 1; -} - -static int goals_len(lua_State * L) { - return push_integer(L, length(to_goals(L, 1))); -} - -static const struct luaL_Reg goals_m[] = { - {"__gc", goals_gc}, // never throws - {"__len", safe_function}, - {"size", safe_function}, - {"pairs", safe_function}, - {"is_nil", safe_function}, - {"empty", safe_function}, - {"head", safe_function}, - {"tail", safe_function}, - {0, 0} -}; - -DECL_UDATA(proof_state) - -static int mk_proof_state(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 2) { - return push_proof_state(L, proof_state(to_proof_state(L, 1), to_goals(L, 2))); - } else if (nargs == 3 && is_proof_state(L, 1)) { - return push_proof_state(L, proof_state(to_proof_state(L, 1), to_goals(L, 2), to_substitution(L, 3))); - } else if (nargs == 3) { - return push_proof_state(L, proof_state(to_goals(L, 1), to_substitution(L, 2), to_name_generator(L, 3), - constraints())); - } else { - throw exception("proof_state invalid number of arguments"); - } -} - -static name * g_tmp_prefix = nullptr; -static int to_proof_state(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 2) - return push_proof_state(L, to_proof_state(to_expr(L, 1), to_expr(L, 2), name_generator(*g_tmp_prefix))); - else - return push_proof_state(L, to_proof_state(to_expr(L, 1), to_expr(L, 2), to_name_generator(L, 3))); -} - -static int proof_state_tostring(lua_State * L) { - std::ostringstream out; - proof_state & s = to_proof_state(L, 1); - options opts = get_global_options(L); - out << mk_pair(s.pp(get_global_environment(L), get_io_state(L)), opts); - lua_pushstring(L, out.str().c_str()); - return 1; -} - -static int proof_state_get_goals(lua_State * L) { return push_goals(L, to_proof_state(L, 1).get_goals()); } -static int proof_state_get_ngen(lua_State * L) { return push_name_generator(L, to_proof_state(L, 1).get_ngen()); } -static int proof_state_get_subst(lua_State * L) { return push_substitution(L, to_proof_state(L, 1).get_subst()); } -static int proof_state_is_final_state(lua_State * L) { return push_boolean(L, to_proof_state(L, 1).is_final_state()); } -static int proof_state_pp(lua_State * L) { - int nargs = lua_gettop(L); - proof_state & s = to_proof_state(L, 1); - if (nargs == 1) - return push_format(L, s.pp(get_global_environment(L), get_io_state(L))); - else - return push_format(L, s.pp(to_environment(L, 1), to_io_state(L, 2))); -} - -static const struct luaL_Reg proof_state_m[] = { - {"__gc", proof_state_gc}, // never throws - {"__tostring", safe_function}, - {"pp", safe_function}, - {"goals", safe_function}, - {"subst", safe_function}, - {"ngen", safe_function}, - {"is_final_state", safe_function}, - {0, 0} -}; - -void open_proof_state(lua_State * L) { - luaL_newmetatable(L, goals_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, goals_m, 0); - - SET_GLOBAL_FUN(goals_pred, "is_goals"); - SET_GLOBAL_FUN(mk_goals, "goals"); - - luaL_newmetatable(L, proof_state_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, proof_state_m, 0); - - SET_GLOBAL_FUN(proof_state_pred, "is_proof_state"); - SET_GLOBAL_FUN(mk_proof_state, "proof_state"); - SET_GLOBAL_FUN(to_proof_state, "to_proof_state"); -} - void initialize_proof_state() { - g_tmp_prefix = new name(name::mk_internal_unique_name()); g_proof_state_goal_names = new name{"tactic", "goal_names"}; register_bool_option(*g_proof_state_goal_names, LEAN_PROOF_STATE_GOAL_NAMES, "(tactic) display goal names when pretty printing proof state"); } void finalize_proof_state() { - delete g_tmp_prefix; delete g_proof_state_goal_names; } } diff --git a/src/library/tactic/proof_state.h b/src/library/tactic/proof_state.h index 6f11d8bfa..788d655bb 100644 --- a/src/library/tactic/proof_state.h +++ b/src/library/tactic/proof_state.h @@ -8,7 +8,6 @@ Author: Leonardo de Moura #include #include #include -#include "util/lua.h" #include "util/optional.h" #include "util/name_set.h" #include "kernel/metavar.h" @@ -84,10 +83,6 @@ proof_state to_proof_state(expr const & meta, expr const & type, name_generator goals map_goals(proof_state const & s, std::function(goal const & g)> f); -UDATA_DEFS_CORE(goals) -UDATA_DEFS(proof_state) -void open_proof_state(lua_State * L); - void initialize_proof_state(); void finalize_proof_state(); } diff --git a/src/library/tactic/tactic.cpp b/src/library/tactic/tactic.cpp index 386f36a73..759d72fc6 100644 --- a/src/library/tactic/tactic.cpp +++ b/src/library/tactic/tactic.cpp @@ -7,7 +7,6 @@ Author: Leonardo de Moura #include #include #include -#include "util/luaref.h" #include "util/sstream.h" #include "util/interrupt.h" #include "util/lazy_list_fn.h" @@ -18,7 +17,6 @@ Author: Leonardo de Moura #include "kernel/replace_fn.h" #include "library/normalize.h" #include "library/util.h" -#include "library/kernel_bindings.h" #include "library/tactic/tactic.h" #include "library/io_state_stream.h" @@ -291,182 +289,4 @@ tactic all_goals(tactic const & t) { return r(env, ios, s); }); } - -DECL_UDATA(proof_state_seq) -static const struct luaL_Reg proof_state_seq_m[] = { - {"__gc", proof_state_seq_gc}, // never throws - {0, 0} -}; - -static int proof_state_seq_next(lua_State * L) { - proof_state_seq seq = to_proof_state_seq(L, lua_upvalueindex(1)); - auto p = seq.pull(); - if (p) { - push_proof_state_seq(L, p->second); - lua_replace(L, lua_upvalueindex(1)); - push_proof_state(L, p->first); - } else { - lua_pushnil(L); - } - return 1; -} - -static int push_proof_state_seq_it(lua_State * L, proof_state_seq const & seq) { - push_proof_state_seq(L, seq); - lua_pushcclosure(L, &safe_function, 1); // create closure with 1 upvalue - return 1; -} - -DECL_UDATA(tactic) - -[[ noreturn ]] void throw_tactic_expected(int i) { - throw exception(sstream() << "arg #" << i << " must be a tactic or a function that returns a tactic"); -} - -static int tactic_call_core(lua_State * L, tactic t, environment env, io_state ios, proof_state s) { - return push_proof_state_seq_it(L, t(env, ios, s)); -} - -static int tactic_call(lua_State * L) { - int nargs = lua_gettop(L); - tactic t = to_tactic(L, 1); - environment env = to_environment(L, 2); - if (nargs == 3) - return tactic_call_core(L, t, env, get_io_state(L), to_proof_state(L, 3)); - else - return tactic_call_core(L, t, env, to_io_state(L, 3), to_proof_state(L, 4)); -} - -typedef tactic (*binary_tactic_fn)(tactic const &, tactic const &); - -template -static int nary_tactic(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs < 2) - throw exception("tactical expects at least two arguments"); - tactic r = F(to_tactic(L, 1), to_tactic(L, 2)); - for (int i = 3; i <= nargs; i++) - r = F(r, to_tactic(L, i)); - return push_tactic(L, r); -} - -static int tactic_then(lua_State * L) { return push_tactic(L, then(to_tactic(L, 1), to_tactic(L, 2))); } -static int tactic_orelse(lua_State * L) { return push_tactic(L, orelse(to_tactic(L, 1), to_tactic(L, 2))); } -static int tactic_append(lua_State * L) { return push_tactic(L, append(to_tactic(L, 1), to_tactic(L, 2))); } -static int tactic_interleave(lua_State * L) { return push_tactic(L, interleave(to_tactic(L, 1), to_tactic(L, 2))); } -static int tactic_par(lua_State * L) { return push_tactic(L, par(to_tactic(L, 1), to_tactic(L, 2))); } -static int tactic_repeat(lua_State * L) { return push_tactic(L, repeat(to_tactic(L, 1))); } -static int tactic_repeat_at_most(lua_State * L) { return push_tactic(L, repeat_at_most(to_tactic(L, 1), luaL_checkinteger(L, 2))); } -static int tactic_take(lua_State * L) { return push_tactic(L, take(to_tactic(L, 1), luaL_checkinteger(L, 2))); } -static int tactic_try_for(lua_State * L) { return push_tactic(L, try_for(to_tactic(L, 1), luaL_checkinteger(L, 2))); } -static int tactic_using_params(lua_State * L) { return push_tactic(L, using_params(to_tactic(L, 1), to_options(L, 2))); } -static int tactic_focus(lua_State * L) { - int nargs = lua_gettop(L); - if (nargs == 1) - return push_tactic(L, focus(to_tactic(L, 1))); - else - return push_tactic(L, focus(to_tactic(L, 1), lua_tointeger(L, 2))); -} -static int mk_lua_tactic01(lua_State * L) { - luaL_checktype(L, 1, LUA_TFUNCTION); // user-fun - luaref ref(L, 1); - tactic t = tactic01([=](environment const & env, io_state const & ios, proof_state const & s) -> optional { - ref.push(); // push user-fun on the stack - push_environment(L, env); // push args... - push_io_state(L, ios); - push_proof_state(L, s); - pcall(L, 3, 1, 0); - optional r; - if (is_proof_state(L, -1)) - r = to_proof_state(L, -1); - lua_pop(L, 1); - return r; - }); - return push_tactic(L, t); -} - -static int mk_lua_cond_tactic(lua_State * L, tactic t1, tactic t2) { - luaL_checktype(L, 1, LUA_TFUNCTION); // user-fun - luaref ref(L, 1); - tactic t = tactic([=](environment const & env, io_state const & ios, proof_state const & s) -> proof_state_seq { - return mk_proof_state_seq([=]() { - ref.push(); // push user-fun on the stack - push_environment(L, env); // push args... - push_io_state(L, ios); - push_proof_state(L, s); - pcall(L, 3, 1, 0); - bool cond = lua_toboolean(L, -1); - lua_pop(L, 1); - if (cond) { - return t1(env, ios, s).pull(); - } else { - return t2(env, ios, s).pull(); - } - }); - }); - return push_tactic(L, t); -} - -static int mk_lua_cond_tactic(lua_State * L) { return mk_lua_cond_tactic(L, to_tactic(L, 2), to_tactic(L, 3)); } -static int mk_lua_when_tactic(lua_State * L) { return mk_lua_cond_tactic(L, to_tactic(L, 2), id_tactic()); } -static int mk_id_tactic(lua_State * L) { return push_tactic(L, id_tactic()); } -static int mk_now_tactic(lua_State * L) { return push_tactic(L, now_tactic()); } -static int mk_fail_tactic(lua_State * L) { return push_tactic(L, fail_tactic()); } -static int mk_beta_tactic(lua_State * L) { return push_tactic(L, beta_tactic()); } -static const struct luaL_Reg tactic_m[] = { - {"__gc", tactic_gc}, // never throws - {"__call", safe_function}, - {"__concat", safe_function}, - {"__pow", safe_function}, - {"__add", safe_function}, - {"then", safe_function}, - {"orelse", safe_function}, - {"append", safe_function}, - {"interleave", safe_function}, - {"par", safe_function}, - {"repeat", safe_function}, - {"repeat_at_most", safe_function}, - {"take", safe_function}, - {"try_for", safe_function}, - {"using_params", safe_function}, - {"using", safe_function}, - {"focus", safe_function}, - {0, 0} -}; - -void open_tactic(lua_State * L) { - luaL_newmetatable(L, proof_state_seq_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, proof_state_seq_m, 0); - SET_GLOBAL_FUN(proof_state_seq_pred, "is_proof_state_seq"); - - luaL_newmetatable(L, tactic_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, tactic_m, 0); - - SET_GLOBAL_FUN(tactic_pred, "is_tactic"); - SET_GLOBAL_FUN(mk_id_tactic, "id_tac"); - SET_GLOBAL_FUN(mk_now_tactic, "now_tac"); - SET_GLOBAL_FUN(mk_fail_tactic, "fail_tac"); - SET_GLOBAL_FUN(mk_beta_tactic, "beta_tac"); - SET_GLOBAL_FUN(mk_lua_tactic01, "tactic01"); - - // HOL-like tactic names - SET_GLOBAL_FUN(nary_tactic, "Then"); - SET_GLOBAL_FUN(nary_tactic, "OrElse"); - SET_GLOBAL_FUN(nary_tactic, "Interleave"); - SET_GLOBAL_FUN(nary_tactic, "Append"); - SET_GLOBAL_FUN(nary_tactic, "Par"); - SET_GLOBAL_FUN(tactic_repeat, "Repeat"); - SET_GLOBAL_FUN(tactic_repeat_at_most, "RepeatAtMost"); - SET_GLOBAL_FUN(mk_lua_cond_tactic, "Cond"); - SET_GLOBAL_FUN(mk_lua_when_tactic, "When"); - SET_GLOBAL_FUN(tactic_try_for, "TryFor"); - SET_GLOBAL_FUN(tactic_take, "Take"); - SET_GLOBAL_FUN(tactic_using_params, "Using"); - SET_GLOBAL_FUN(tactic_using_params, "UsingParams"); - SET_GLOBAL_FUN(tactic_focus, "Focus"); -} } diff --git a/src/library/tactic/tactic.h b/src/library/tactic/tactic.h index 72d626d68..43e9292de 100644 --- a/src/library/tactic/tactic.h +++ b/src/library/tactic/tactic.h @@ -150,8 +150,4 @@ inline tactic focus(tactic const & t) { return focus(t, 0); } tactic beta_tactic(); /** \brief Apply \c t to all goals in the proof state */ tactic all_goals(tactic const & t); - -UDATA_DEFS_CORE(proof_state_seq) -UDATA_DEFS_CORE(tactic); -void open_tactic(lua_State * L); } diff --git a/src/library/unifier.cpp b/src/library/unifier.cpp index c96ff69d8..dd0887772 100644 --- a/src/library/unifier.cpp +++ b/src/library/unifier.cpp @@ -10,7 +10,6 @@ Author: Leonardo de Moura #include #include #include "util/interrupt.h" -#include "util/luaref.h" #include "util/lazy_list_fn.h" #include "util/sstream.h" #include "util/lbool.h" @@ -30,7 +29,6 @@ Author: Leonardo de Moura #include "library/unifier.h" #include "library/reducible.h" #include "library/unifier_plugin.h" -#include "library/kernel_bindings.h" #include "library/print.h" #include "library/expr_lt.h" #include "library/projection.h" @@ -2845,163 +2843,6 @@ unify_result_seq unify(environment const & env, expr const & lhs, expr const & r } } -static int unify_simple(lua_State * L) { - int nargs = lua_gettop(L); - unify_status r; - if (nargs == 2) - r = unify_simple(to_substitution(L, 1), to_constraint(L, 2)); - else if (nargs == 3 && is_expr(L, 2)) - r = unify_simple(to_substitution(L, 1), to_expr(L, 2), to_expr(L, 3), justification()); - else if (nargs == 3 && is_level(L, 2)) - r = unify_simple(to_substitution(L, 1), to_level(L, 2), to_level(L, 3), justification()); - else if (is_expr(L, 2)) - r = unify_simple(to_substitution(L, 1), to_expr(L, 2), to_expr(L, 3), to_justification(L, 4)); - else - r = unify_simple(to_substitution(L, 1), to_level(L, 2), to_level(L, 3), to_justification(L, 4)); - return push_integer(L, static_cast(r)); -} - -DECL_UDATA(unify_result_seq) - -static const struct luaL_Reg unify_result_seq_m[] = { - {"__gc", unify_result_seq_gc}, - {0, 0} -}; - -static int unify_result_seq_next(lua_State * L) { - unify_result_seq seq = to_unify_result_seq(L, lua_upvalueindex(1)); - unify_result_seq::maybe_pair p; - p = seq.pull(); - if (p) { - push_unify_result_seq(L, p->second); - lua_replace(L, lua_upvalueindex(1)); - push_substitution(L, p->first.first); - // TODO(Leo): return postponed constraints - } else { - lua_pushnil(L); - } - return 1; -} - -static int push_unify_result_seq_it(lua_State * L, unify_result_seq const & seq) { - push_unify_result_seq(L, seq); - lua_pushcclosure(L, &safe_function, 1); // create closure with 1 upvalue - return 1; -} - -static void to_constraint_buffer(lua_State * L, int idx, buffer & cs) { - luaL_checktype(L, idx, LUA_TTABLE); - lua_pushvalue(L, idx); // put table on top of the stack - int n = objlen(L, idx); - for (int i = 1; i <= n; i++) { - lua_rawgeti(L, -1, i); - cs.push_back(to_constraint(L, -1)); - lua_pop(L, 1); - } - lua_pop(L, 1); -} - -#if 0 -static constraints to_constraints(lua_State * L, int idx) { - buffer cs; - to_constraint_buffer(L, idx, cs); - return to_list(cs.begin(), cs.end()); -} - -static unifier_plugin to_unifier_plugin(lua_State * L, int idx) { - luaL_checktype(L, idx, LUA_TFUNCTION); // user-fun - luaref f(L, idx); - return unifier_plugin([=](constraint const & c, name_generator && ngen) { - lua_State * L = f.get_state(); - f.push(); - push_constraint(L, c); - push_name_generator(L, ngen); - pcall(L, 2, 1, 0); - lazy_list r; - if (is_constraint(L, -1)) { - // single constraint - r = lazy_list(constraints(to_constraint(L, -1))); - } else if (lua_istable(L, -1)) { - int num = objlen(L, -1); - if (num == 0) { - // empty table - r = lazy_list(); - } else { - lua_rawgeti(L, -1, 1); - if (is_constraint(L, -1)) { - // array of constraints case - lua_pop(L, 1); - r = lazy_list(to_constraints(L, -1)); - } else { - lua_pop(L, 1); - buffer css; - // array of array of constraints - for (int i = 1; i <= num; i++) { - lua_rawgeti(L, -1, i); - css.push_back(to_constraints(L, -1)); - lua_pop(L, 1); - } - r = to_lazy(to_list(css.begin(), css.end())); - } - } - } else if (lua_isnil(L, -1)) { - // nil case - r = lazy_list(); - } else { - throw exception("invalid unifier plugin, the result value must be a constrant, " - "nil, an array of constraints, or an array of arrays of constraints"); - } - lua_pop(L, 1); - return r; - }); -} -#endif - -static name * g_tmp_prefix = nullptr; - -static int unify(lua_State * L) { - int nargs = lua_gettop(L); - unify_result_seq r; - environment const & env = to_environment(L, 1); - if (is_expr(L, 2)) { - if (nargs == 6) - r = unify(env, to_expr(L, 2), to_expr(L, 3), to_name_generator(L, 4).mk_child(), to_substitution(L, 5), - unifier_config(to_options(L, 6))); - else if (nargs == 5) - r = unify(env, to_expr(L, 2), to_expr(L, 3), to_name_generator(L, 4).mk_child(), to_substitution(L, 5)); - else - r = unify(env, to_expr(L, 2), to_expr(L, 3), to_name_generator(L, 4).mk_child()); - } else { - buffer cs; - to_constraint_buffer(L, 2, cs); - if (nargs == 5) - r = unify(env, cs.size(), cs.data(), to_name_generator(L, 3).mk_child(), to_substitution(L, 4), - unifier_config(to_options(L, 5))); - else if (nargs == 4) - r = unify(env, cs.size(), cs.data(), to_name_generator(L, 3).mk_child(), to_substitution(L, 4)); - else - r = unify(env, cs.size(), cs.data(), to_name_generator(L, 3).mk_child()); - } - return push_unify_result_seq_it(L, r); -} - -void open_unifier(lua_State * L) { - luaL_newmetatable(L, unify_result_seq_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, unify_result_seq_m, 0); - SET_GLOBAL_FUN(unify_result_seq_pred, "is_unify_result_seq"); - - SET_GLOBAL_FUN(unify_simple, "unify_simple"); - SET_GLOBAL_FUN(unify, "unify"); - - lua_newtable(L); - SET_ENUM("Solved", unify_status::Solved); - SET_ENUM("Failed", unify_status::Failed); - SET_ENUM("Unsupported", unify_status::Unsupported); - lua_setglobal(L, "unify_status"); -} - void initialize_unifier() { register_trace_class(name{"unifier"}); g_unifier_max_steps = new name{"unifier", "max_steps"}; @@ -3020,11 +2861,9 @@ void initialize_unifier() { "(unifier) enable/disable nonchronological backtracking in the unifier (this option is only available for debugging and benchmarking purposes, and running experiments)"); g_dont_care_cnstr = new constraint(mk_eq_cnstr(expr(), expr(), justification())); - g_tmp_prefix = new name(name::mk_internal_unique_name()); } void finalize_unifier() { - delete g_tmp_prefix; delete g_dont_care_cnstr; delete g_unifier_max_steps; delete g_unifier_normalizer_max_steps; diff --git a/src/library/unifier.h b/src/library/unifier.h index 516fc0dcf..2079a5b75 100644 --- a/src/library/unifier.h +++ b/src/library/unifier.h @@ -7,7 +7,6 @@ Author: Leonardo de Moura #pragma once #include #include -#include "util/lua.h" #include "util/lazy_list.h" #include "util/name_generator.h" #include "util/sexpr/options.h" @@ -123,8 +122,6 @@ public: substitution const & get_substitution() const { return m_subst; } }; -void open_unifier(lua_State * L); - void initialize_unifier(); void finalize_unifier(); } diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index 2afe13dc5..c4e67e2f6 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -27,13 +27,8 @@ add_test(lean_ghash2 "${CMAKE_CURRENT_BINARY_DIR}/lean" --githash) add_test(lean_path1 "${CMAKE_CURRENT_BINARY_DIR}/lean" -p) add_test(lean_path2 "${CMAKE_CURRENT_BINARY_DIR}/lean" --path) add_test(export_all "${LEAN_SOURCE_DIR}/../bin/lean" --export-all=all.out "${LEAN_SOURCE_DIR}/../library/standard.lean") -add_test(lean_luahook1 "${CMAKE_CURRENT_BINARY_DIR}/lean" --luahook=100 "${LEAN_SOURCE_DIR}/../tests/lua/big.lua") -add_test(lean_luahook2 "${CMAKE_CURRENT_BINARY_DIR}/lean" -k 100 "${LEAN_SOURCE_DIR}/../tests/lua/big.lua") -# add_test(lean_lua1 ${LEAN_SOURCE_DIR}/cmake/redirect.sh "${CMAKE_CURRENT_BINARY_DIR}/lean" "--lua" "${LEAN_SOURCE_DIR}/../tests/lua/single.lua") -# add_test(lean_lua2 ${LEAN_SOURCE_DIR}/cmake/redirect.sh "${CMAKE_CURRENT_BINARY_DIR}/lean" "-u" "${LEAN_SOURCE_DIR}/../tests/lua/single.lua") add_test(lean_unknown_option bash "${LEAN_SOURCE_DIR}/cmake/check_failure.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean" "-z") add_test(lean_unknown_file1 bash "${LEAN_SOURCE_DIR}/cmake/check_failure.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean" "boofoo.lean") -add_test(lean_unknown_file2 bash "${LEAN_SOURCE_DIR}/cmake/check_failure.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean" "boofoo.lua") add_test(lean_server_trace "${CMAKE_CURRENT_BINARY_DIR}/lean" --server-trace "${LEAN_SOURCE_DIR}/../tests/lean/interactive/consume_args.input") add_test(lean_server_trace "${CMAKE_CURRENT_BINARY_DIR}/lean" --server-trace "${LEAN_SOURCE_DIR}/../tests/lean/interactive/options_cmd.trace") add_test(lean_server_trace "${CMAKE_CURRENT_BINARY_DIR}/lean" --server-trace "${LEAN_SOURCE_DIR}/../tests/lean/interactive/commands.trace") @@ -138,25 +133,6 @@ FOREACH(T ${LEANSLOWTESTS}) set_tests_properties("leanslowtest_${T_NAME}" PROPERTIES LABELS "expensive") ENDFOREACH(T) -# LEAN LUA TESTS -file(GLOB LEANLUATESTS "${LEAN_SOURCE_DIR}/../tests/lua/*.lua") -FOREACH(T ${LEANLUATESTS}) - GET_FILENAME_COMPONENT(T_NAME ${T} NAME) - add_test(NAME "leanluatest_${T_NAME}" - WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/../tests/lua" - COMMAND bash "./test_single.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean" ${T_NAME}) -ENDFOREACH(T) - -# LEAN LUA SLOW TESTS -file(GLOB LEANLUASLOWTESTS "${LEAN_SOURCE_DIR}/../tests/lua/slow/*.lua") -FOREACH(T ${LEANLUASLOWTESTS}) - GET_FILENAME_COMPONENT(T_NAME ${T} NAME) - add_test(NAME "leanluaslowtest_${T_NAME}" - WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/../tests/lua/slow" - COMMAND bash "../test_single.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean" ${T_NAME}) - set_tests_properties("leanluaslowtest_${T_NAME}" PROPERTIES LABELS "expensive") -ENDFOREACH(T) - # LEAN DOCS file(GLOB LEANDOCS "${LEAN_SOURCE_DIR}/../doc/lean/*.org") FOREACH(T ${LEANDOCS}) @@ -166,15 +142,6 @@ FOREACH(T ${LEANDOCS}) COMMAND bash "./test_single.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean" ${T}) ENDFOREACH(T) -# LEAN LUA DOCS -file(GLOB LEANLUADOCS "${LEAN_SOURCE_DIR}/../doc/lua/*.md") -FOREACH(T ${LEANLUADOCS}) - GET_FILENAME_COMPONENT(T_NAME ${T} NAME) - add_test(NAME "leanluadoc_${T_NAME}" - WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/../doc/lua" - COMMAND bash "./test_single.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean" ${T}) -ENDFOREACH(T) - # # Create the script lean.sh # # This is used to create a soft dependency on the Lean executable # # Some rules can only be applied if the lean executable exists, diff --git a/src/shell/emscripten.cpp b/src/shell/emscripten.cpp index bc2fe99ce..bfd5e92fb 100644 --- a/src/shell/emscripten.cpp +++ b/src/shell/emscripten.cpp @@ -5,11 +5,8 @@ Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #include -#include "util/script_state.h" -#include "util/thread_script_state.h" #include "library/module.h" #include "library/standard_kernel.h" -#include "library/kernel_bindings.h" #include "library/error_handling.h" #include "frontends/lean/pp.h" #include "frontends/lean/parser.h" @@ -24,14 +21,10 @@ private: options opts; environment env; io_state ios; - script_state S; - set_environment set1; - set_io_state set2; public: emscripten_shell() : trust_lvl(LEAN_BELIEVER_TRUST_LEVEL+1), num_threads(1), opts("flycheck", true), - env(mk_environment(trust_lvl)), ios(opts, lean::mk_pretty_formatter_factory()), - S(lean::get_thread_script_state()), set1(S, env), set2(S, ios) { + env(mk_environment(trust_lvl)), ios(opts, lean::mk_pretty_formatter_factory()) { } int import_module(std::string mname) { diff --git a/src/shell/lean.cpp b/src/shell/lean.cpp index 43d759ae3..61c1c5e38 100644 --- a/src/shell/lean.cpp +++ b/src/shell/lean.cpp @@ -16,9 +16,7 @@ Author: Leonardo de Moura #include "util/sstream.h" #include "util/interrupt.h" #include "util/memory.h" -#include "util/script_state.h" #include "util/thread.h" -#include "util/thread_script_state.h" #include "util/lean_path.h" #include "util/file_lock.h" #include "util/sexpr/options.h" @@ -46,7 +44,6 @@ Author: Leonardo de Moura #include "version.h" #include "githash.h" // NOLINT -using lean::script_state; using lean::unreachable_reached; using lean::environment; using lean::io_state; @@ -54,8 +51,6 @@ using lean::io_state_stream; using lean::regular; using lean::mk_environment; using lean::mk_hott_environment; -using lean::set_environment; -using lean::set_io_state; using lean::definition_cache; using lean::pos_info; using lean::pos_info_provider; @@ -69,7 +64,7 @@ using lean::simple_pos_info_provider; using lean::shared_file_lock; using lean::exclusive_file_lock; -enum class input_kind { Unspecified, Lean, HLean, Lua, Trace }; +enum class input_kind { Unspecified, Lean, HLean, Trace }; static void on_ctrl_c(int ) { lean::request_interrupt(); @@ -95,7 +90,6 @@ static void display_help(std::ostream & out) { std::cout << " with unknown extension (default)\n"; std::cout << " --hlean use parser for Lean default input format \n"; std::cout << " and use HoTT compatible kernel for files, with unknown extension\n"; - std::cout << " --lua use Lua parser for files with unknown extension\n"; std::cout << " --server-trace use lean server trace parser for files with unknown extension\n"; std::cout << "Miscellaneous:\n"; std::cout << " --help -h display this message\n"; @@ -103,9 +97,6 @@ static void display_help(std::ostream & out) { std::cout << " --githash display the git commit hash number used to build this binary\n"; std::cout << " --path display the path used for finding Lean libraries and extensions\n"; std::cout << " --output=file -o save the final environment in binary format in the given file\n"; - std::cout << " --luahook=num -k how often the Lua interpreter checks the interrupted flag,\n"; - std::cout << " it is useful for interrupting non-terminating user scripts,\n"; - std::cout << " 0 means 'do not check'.\n"; std::cout << " --trust=num -t trust level (default: max) 0 means do not trust any macro,\n" << " and type check all imported modules\n"; std::cout << " --discard -r discard the proof of imported theorems after checking\n"; @@ -163,10 +154,8 @@ static struct option g_long_options[] = { {"help", no_argument, 0, 'h'}, {"lean", no_argument, 0, 'l'}, {"hlean", no_argument, 0, 'H'}, - {"lua", no_argument, 0, 'u'}, {"server-trace", no_argument, 0, 'R'}, {"path", no_argument, 0, 'p'}, - {"luahook", required_argument, 0, 'k'}, {"githash", no_argument, 0, 'g'}, {"output", required_argument, 0, 'o'}, {"export", required_argument, 0, 'E'}, @@ -310,15 +299,9 @@ int main(int argc, char ** argv) { case 'H': default_k = input_kind::HLean; break; - case 'u': - default_k = input_kind::Lua; - break; case 'R': default_k = input_kind::Trace; break; - case 'k': - script_state::set_check_interrupt_freq(atoi(optarg)); - break; case 'p': if (default_k == input_kind::HLean) lean::initialize_lean_path(true); @@ -458,9 +441,6 @@ int main(int argc, char ** argv) { environment env = has_hlean ? mk_hott_environment(trust_lvl) : mk_environment(trust_lvl); io_state ios(opts, lean::mk_pretty_formatter_factory()); - script_state S = lean::get_thread_script_state(); - set_environment set1(S, env); - set_io_state set2(S, ios); definition_cache cache; definition_cache * cache_ptr = nullptr; if (read_cache) { @@ -500,8 +480,6 @@ int main(int argc, char ** argv) { k = input_kind::Lean; } else if (strcmp(ext, "hlean") == 0) { k = input_kind::HLean; - } else if (strcmp(ext, "lua") == 0) { - k = input_kind::Lua; } } switch (k) { @@ -515,9 +493,6 @@ int main(int argc, char ** argv) { ok = false; } break; - case input_kind::Lua: - lean::system_import(argv[i]); - break; case input_kind::Trace: ok = lean::parse_server_trace(env, ios, argv[i], base_dir); break; diff --git a/src/tests/util/lp/lp.cpp b/src/tests/util/lp/lp.cpp index 96e537894..01e6f9882 100644 --- a/src/tests/util/lp/lp.cpp +++ b/src/tests/util/lp/lp.cpp @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE. Author: Lev Nachmanson */ +#include #include #include #include @@ -1365,7 +1366,7 @@ void random_test_on_i(unsigned i) { } void random_test() { - for (unsigned i = 0; i < UINT_MAX; i++) { + for (unsigned i = 0; i < std::numeric_limits::max(); i++) { try { random_test_on_i(i); } diff --git a/src/tests/util/thread.cpp b/src/tests/util/thread.cpp index 6ee74c4b6..1ca3f25fc 100644 --- a/src/tests/util/thread.cpp +++ b/src/tests/util/thread.cpp @@ -11,7 +11,6 @@ Author: Leonardo de Moura #include "util/debug.h" #include "util/shared_mutex.h" #include "util/interrupt.h" -#include "util/thread_script_state.h" #include "util/init_module.h" using namespace lean; @@ -184,52 +183,6 @@ static void tst6() { t1.join(); } -static __thread script_state * g_state = nullptr; - -static void tst7() { - std::cout << "start\n"; - system_import("import_test.lua"); - system_dostring("print('hello'); x = 10;"); - interruptible_thread t1([]() { - g_state = new script_state(); - g_state->dostring("x = 1"); - script_state S = get_thread_script_state(); - S.dostring("print(x)\n" - "for i = 1, 100000 do\n" - " x = x + 1\n" - "end\n" - "print(x)\n"); - delete g_state; - }); - interruptible_thread t2([]() { - g_state = new script_state(); - g_state->dostring("x = 0"); - script_state S = get_thread_script_state(); - S.dostring("print(x)\n" - "for i = 1, 20000 do\n" - " x = x + 1\n" - "end\n" - "print(x)\n"); - delete g_state; - }); - t1.join(); t2.join(); - std::cout << "done\n"; -} - -static void tst8() { - std::cout << "starting tst8\n"; - interruptible_thread t1([]() { - script_state S = get_thread_script_state(); - S.dostring("print(x)\n" - "for i = 1, 10000 do\n" - " x = x + 1\n" - "end\n" - "print(x)\n" - "print(fact(10))\n"); - }); - t1.join(); -} - int main() { save_stack_info(); initialize_util_module(); @@ -239,8 +192,6 @@ int main() { tst4(); tst5(); tst6(); - tst7(); - tst8(); run_thread_finalizers(); finalize_util_module(); run_post_thread_finalizers(); diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 0a6fd56c1..74ddb6854 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -1,8 +1,6 @@ add_library(util OBJECT debug.cpp name.cpp name_set.cpp name_generator.cpp exception.cpp interrupt.cpp hash.cpp escaped.cpp bit_tricks.cpp safe_arith.cpp ascii.cpp memory.cpp shared_mutex.cpp - realpath.cpp script_state.cpp script_exception.cpp rb_map.cpp - lua.cpp luaref.cpp lua_named_param.cpp stackinfo.cpp lean_path.cpp - serializer.cpp lbool.cpp thread_script_state.cpp bitap_fuzzy_search.cpp + realpath.cpp stackinfo.cpp lean_path.cpp serializer.cpp lbool.cpp bitap_fuzzy_search.cpp init_module.cpp thread.cpp memory_pool.cpp utf8.cpp name_map.cpp list_fn.cpp null_ostream.cpp file_lock.cpp) diff --git a/src/util/exception.cpp b/src/util/exception.cpp index 944cad897..011a22f5d 100644 --- a/src/util/exception.cpp +++ b/src/util/exception.cpp @@ -53,56 +53,4 @@ char const * memory_exception::what() const noexcept { buffer = s.str(); return buffer.c_str(); } - -constexpr char const * exception_mt = "exception_mt"; -throwable const & to_exception(lua_State * L, int i) { - return *(*static_cast(luaL_checkudata(L, i, exception_mt))); -} - -int push_exception(lua_State * L, throwable const & e) { - throwable ** mem = static_cast(lua_newuserdata(L, sizeof(throwable*))); // NOLINT - *mem = e.clone(); - luaL_getmetatable(L, exception_mt); - lua_setmetatable(L, -2); - return 1; -} - -static int exception_gc(lua_State * L) { - throwable ** mem = static_cast(lua_touserdata(L, 1)); - delete (*mem); - return 0; -} - -bool is_exception(lua_State * L, int i) { - return testudata(L, i, exception_mt); -} - -static int exception_what(lua_State * L) { - return push_string(L, to_exception(L, 1).what()); -} - -static int exception_rethrow(lua_State * L) { - lua_pushvalue(L, 1); - return lua_error(L); -} - -static int exception_pred(lua_State * L) { - return push_boolean(L, is_exception(L, 1)); -} - -static const struct luaL_Reg exception_m[] = { - {"__gc", exception_gc}, // never throws - {"what", safe_function}, - {"rethrow", exception_rethrow}, // generates a lua_error - {0, 0} -}; - -void open_exception(lua_State * L) { - luaL_newmetatable(L, exception_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, exception_m, 0); - - SET_GLOBAL_FUN(exception_pred, "is_exception"); -} } diff --git a/src/util/exception.h b/src/util/exception.h index f8be04fc4..8225e3a5e 100644 --- a/src/util/exception.h +++ b/src/util/exception.h @@ -5,7 +5,6 @@ Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #pragma once -#include "util/lua.h" #include #include #include @@ -87,9 +86,4 @@ public: virtual throwable * clone() const { return new memory_exception(m_component_name.c_str()); } virtual void rethrow() const { throw *this; } }; - -int push_exception(lua_State * L, throwable const & e); -throwable const & to_exception(lua_State * L, int i); -bool is_exception(lua_State * L, int i); -void open_exception(lua_State * L); } diff --git a/src/util/init_module.cpp b/src/util/init_module.cpp index 4fc0df7b0..4de7051ab 100644 --- a/src/util/init_module.cpp +++ b/src/util/init_module.cpp @@ -7,8 +7,6 @@ Author: Leonardo de Moura #include "util/ascii.h" #include "util/debug.h" #include "util/serializer.h" -#include "util/thread_script_state.h" -#include "util/script_state.h" #include "util/name.h" #include "util/name_generator.h" #include "util/lean_path.h" @@ -21,8 +19,6 @@ void initialize_util_module() { initialize_serializer(); initialize_thread(); initialize_ascii(); - initialize_thread_script_state(); - initialize_script_state(); initialize_name(); initialize_name_generator(); initialize_lean_path(); @@ -31,8 +27,6 @@ void finalize_util_module() { finalize_lean_path(); finalize_name_generator(); finalize_name(); - finalize_script_state(); - finalize_thread_script_state(); finalize_ascii(); finalize_thread(); finalize_serializer(); diff --git a/src/util/lean_path.cpp b/src/util/lean_path.cpp index 9c943bc26..e006b2595 100644 --- a/src/util/lean_path.cpp +++ b/src/util/lean_path.cpp @@ -196,12 +196,8 @@ bool is_olean_file(std::string const & fname) { return has_file_ext(fname, ".olean"); } -bool is_lua_file(std::string const & fname) { - return has_file_ext(fname, ".lua"); -} - bool is_known_file_ext(std::string const & fname) { - return is_lean_file(fname) || is_hlean_file(fname) || is_olean_file(fname) || is_lua_file(fname); + return is_lean_file(fname) || is_hlean_file(fname) || is_olean_file(fname); } optional check_file_core(std::string file, char const * ext) { @@ -271,7 +267,7 @@ std::string find_file(std::string const & base, optional const & k, na } std::string find_file(std::string fname) { - return find_file(fname, {".olean", ".lean", ".lua"}); + return find_file(fname, {".olean", ".lean"}); } std::string find_file(name const & fname) { diff --git a/src/util/lean_path.h b/src/util/lean_path.h index aa40742c1..cdfd0b058 100644 --- a/src/util/lean_path.h +++ b/src/util/lean_path.h @@ -40,8 +40,6 @@ std::string find_file(std::string const & base, optional const & k, na bool is_lean_file(std::string const & fname); /** \brief Return true iff fname ends with ".olean" */ bool is_olean_file(std::string const & fname); -/** \brief Return true iff fname ends with ".lua" */ -bool is_lua_file(std::string const & fname); /** \brief Return a string that replaces hierachical name separator '::' with a path separator. */ std::string name_to_file(name const & fname); diff --git a/src/util/lp/core_solver_pretty_printer.cpp b/src/util/lp/core_solver_pretty_printer.cpp index 8d212757f..0d535d673 100644 --- a/src/util/lp/core_solver_pretty_printer.cpp +++ b/src/util/lp/core_solver_pretty_printer.cpp @@ -4,6 +4,7 @@ Author: Lev Nachmanson */ +#include #include #include #include "util/lp/lp_core_solver_base.h" diff --git a/src/util/lp/core_solver_pretty_printer.h b/src/util/lp/core_solver_pretty_printer.h index 484e9817d..a07e06b5f 100644 --- a/src/util/lp/core_solver_pretty_printer.h +++ b/src/util/lp/core_solver_pretty_printer.h @@ -4,8 +4,8 @@ Author: Lev Nachmanson */ - #pragma once +#include #include #include #include @@ -43,7 +43,7 @@ class core_solver_pretty_printer { unsigned ncols() { return m_core_solver.m_A.column_count(); } unsigned nrows() { return m_core_solver.m_A.row_count(); } - unsigned m_artificial_start = UINT_MAX; + unsigned m_artificial_start = std::numeric_limits::max(); T * m_w_buff; T * m_ed_buff; vector m_exact_column_norms; diff --git a/src/util/lp/lp_primal_core_solver.h b/src/util/lp/lp_primal_core_solver.h index 075e42261..1b314ebbf 100644 --- a/src/util/lp/lp_primal_core_solver.h +++ b/src/util/lp/lp_primal_core_solver.h @@ -7,21 +7,21 @@ #pragma once #include -#include "util/numerics/double.h" -#include "util/lp/lu.h" -#include "util/lp/lp_solver.h" -#include - +#include #include -#include "util/lp/static_matrix.h" -#include "util/lp/core_solver_pretty_printer.h" +#include #include #include #include +#include #include #include +#include "util/numerics/double.h" +#include "util/lp/lu.h" +#include "util/lp/lp_solver.h" +#include "util/lp/static_matrix.h" +#include "util/lp/core_solver_pretty_printer.h" #include "util/lp/lp_core_solver_base.h" -#include #include "util/lp/breakpoint.h" #include "util/lp/binary_heap_priority_queue.h" namespace lean { @@ -55,7 +55,7 @@ public: int find_leaving_and_t_precisely(unsigned entering, X & t); static X positive_infinity() { - return convert_struct::convert(UINT_MAX); + return convert_struct::convert(std::numeric_limits::max()); } X get_harris_theta(); diff --git a/src/util/lua.cpp b/src/util/lua.cpp deleted file mode 100644 index 999fa508d..000000000 --- a/src/util/lua.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* -Copyright (c) 2013 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include -#include -#include -#include -#include -#include -#include -#include "util/lua.h" -#include "util/script_exception.h" -#include "util/debug.h" -#include "util/sstream.h" - -namespace lean { -/** - \brief luaL_setfuncs replacement. The function luaL_setfuncs is only available in Lua 5.2. -*/ -void setfuncs(lua_State * L, luaL_Reg const * l, int nup) { - luaL_checkstack(L, nup, "too many upvalues"); - for (; l->name != NULL; l++) { - // fill the table with given functions - for (int i = 0; i < nup; i++) // copy upvalues to the top - lua_pushvalue(L, -nup); - lua_pushcclosure(L, l->func, nup); // closure with those upvalues - lua_setfield(L, -(nup + 2), l->name); - } - lua_pop(L, nup); // remove upvalues -} - -/** - \brief luaL_testudata replacement. -*/ -bool testudata(lua_State * L, int ud, char const * tname) { - void * p = lua_touserdata(L, ud); - if (p != nullptr) { - if (lua_getmetatable(L, ud)) { - luaL_getmetatable(L, tname); - if (!lua_rawequal(L, -1, -2)) - p = nullptr; - lua_pop(L, 2); - return p != nullptr; - } - } - return false; // value is not a userdata with a metatable -} - -int load(lua_State * L, lua_Reader reader, void * data, char const * source) { - #if LUA_VERSION_NUM < 502 - return lua_load(L, reader, data, source); - #else - return lua_load(L, reader, data, source, nullptr); - #endif -} - -size_t objlen(lua_State * L, int idx) { - #if LUA_VERSION_NUM < 502 - return lua_objlen(L, idx); - #else - return lua_rawlen(L, idx); - #endif -} - -int lessthan(lua_State * L, int idx1, int idx2) { - #if LUA_VERSION_NUM < 502 - return lua_lessthan(L, idx1, idx2); - #else - return lua_compare(L, idx1, idx2, LUA_OPLT); - #endif -} - -int equal(lua_State * L, int idx1, int idx2) { - #if LUA_VERSION_NUM < 502 - return lua_equal(L, idx1, idx2); - #else - return lua_compare(L, idx1, idx2, LUA_OPEQ); - #endif -} - -char const * tostring(lua_State * L, int idx) { - if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ - switch (lua_type(L, idx)) { - case LUA_TNUMBER: - case LUA_TSTRING: - lua_pushvalue(L, idx); - break; - case LUA_TBOOLEAN: - lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); - break; - case LUA_TNIL: - lua_pushliteral(L, "nil"); - break; - default: { - std::ostringstream strm; - strm << lua_typename(L, idx) << ": " << lua_topointer(L, idx); - lua_pushstring(L, strm.str().c_str()); - break; - }} - } - return lua_tostring(L, -1); -} - -int get_nonnil_top(lua_State * L) { - int top = lua_gettop(L); - while (top > 0 && lua_isnil(L, top)) - top--; - return top; -} - -static void exec(lua_State * L) { - pcall(L, 0, LUA_MULTRET, 0); -} - -void check_result(lua_State * L, int result) { - if (result) { - if (is_exception(L, -1)) { - to_exception(L, -1).rethrow(); - } else { - throw script_exception(lua_tostring(L, -1)); - } - } -} - -void dofile(lua_State * L, char const * fname) { - int result = luaL_loadfile(L, fname); - check_result(L, result); - exec(L); -} - -void dostring(lua_State * L, char const * str) { - int result = luaL_loadstring(L, str); - check_result(L, result); - exec(L); -} - -void pcall(lua_State * L, int nargs, int nresults, int errorfun) { - int result = lua_pcall(L, nargs, nresults, errorfun); - check_result(L, result); -} - -bool resume(lua_State * L, int nargs) { - #if LUA_VERSION_NUM < 502 - int result = lua_resume(L, nargs); - #else - int result = lua_resume(L, nullptr, nargs); - #endif - if (result == LUA_YIELD) - return false; - if (result == 0) - return true; - check_result(L, result); - lean_unreachable(); - return true; -} - -void throw_bad_arg_error(lua_State * L, int i, char const * expected_type) { - lua_Debug ar; - if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ - throw exception(sstream() << "bad argument #" << i << " (" << expected_type << " expected)"); - lua_getinfo(L, "n", &ar); - if (strcmp(ar.namewhat, "method") == 0 || ar.name == nullptr) - throw exception(sstream() << "bad argument #" << i << " (" << expected_type << " expected)"); - throw exception(sstream() << "bad argument #" << i << " to '" << ar.name << "' (" << expected_type << " expected)"); -} - -/** - \brief Wrapper for "customers" that are only using a subset - of Lean libraries. -*/ -int safe_function_wrapper(lua_State * L, lua_CFunction f) { - try { - return f(L); - } catch (throwable & e) { - lua_Debug ar; - lua_getstack(L, 1, &ar); - lua_getinfo(L, "Sl", &ar); - if (ar.source && *(ar.source) == '@') - push_exception(L, script_nested_exception(true, ar.source+1, ar.currentline, - std::shared_ptr(e.clone()))); - else if (ar.source) - push_exception(L, script_nested_exception(false, ar.source, ar.currentline, - std::shared_ptr(e.clone()))); - else - push_exception(L, e); - } catch (std::bad_alloc &) { - lua_pushstring(L, "out of memory"); - } catch (std::exception & e) { - lua_pushstring(L, e.what()); - } catch(...) { - lua_pushstring(L, "unknown error"); - } - return lua_error(L); -} - -void check_num_args(lua_State * L, int num) { - if (lua_gettop(L) != num) throw exception("incorrect number of arguments to function"); -} -void check_atmost_num_args(lua_State * L, int high) { - if (lua_gettop(L) > high) throw exception("too many arguments to function"); -} -void check_atleast_num_args(lua_State * L, int low) { - if (lua_gettop(L) < low) throw exception("too few arguments to function"); -} -} diff --git a/src/util/lua.h b/src/util/lua.h deleted file mode 100644 index eecda7e8d..000000000 --- a/src/util/lua.h +++ /dev/null @@ -1,136 +0,0 @@ -/* -Copyright (c) 2013-2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#pragma once -#include - -namespace lean { -// ======================================= -// Lua 5.1 and 5.2 compatibility -// -// The following helper functions make sure -// we can compile using Lua 5.1 or 5.2 -void setfuncs(lua_State * L, luaL_Reg const * l, int nup); -bool testudata(lua_State * L, int idx, char const * mt); -int load(lua_State * L, lua_Reader reader, void * data, char const * source); -size_t objlen(lua_State * L, int idx); -void dofile(lua_State * L, char const * fname); -void dostring(lua_State * L, char const * str); -void pcall(lua_State * L, int nargs, int nresults, int errorfun); -char const * tostring (lua_State * L, int idx); -/** - \brief Return true iff coroutine is done, false if it has yielded, - and throws an exception if error. -*/ -bool resume(lua_State * L, int nargs); -int lessthan(lua_State * L, int idx1, int idx2); -int equal(lua_State * L, int idx1, int idx2); -int get_nonnil_top(lua_State * L); -// ======================================= - -// ======================================= -// Goodies/Macros for automating Lua binding -// generation. -/** - \brief Wrapper for invoking function f, and catching Lean exceptions. -*/ -int safe_function_wrapper(lua_State * L, lua_CFunction f); -template int safe_function(lua_State * L) { - return safe_function_wrapper(L, F); -} -template void set_global_function(lua_State * L, char const * name) { - lua_pushcfunction(L, safe_function); - lua_setglobal(L, name); -} -#define SET_GLOBAL_FUN(F, N) set_global_function(L, N) -#define SET_FUN(F, N) lua_pushstring(L, N); lua_pushcfunction(L, safe_function); lua_settable(L, -3) - -// Auxiliary macro for creating a Lua table that stores enumeration values -#define SET_ENUM(N, V) lua_pushstring(L, N); lua_pushinteger(L, static_cast(V)); lua_settable(L, -3) - -#define DECL_PUSH_CORE(NAME, T, TREF) \ -int push_ ## NAME(lua_State * L, TREF val) { \ - void * mem = lua_newuserdata(L, sizeof(T)); \ - new (mem) T(val); \ - luaL_getmetatable(L, NAME ## _mt); \ - lua_setmetatable(L, -2); \ - return 1; \ -} - -#define DECL_PUSH(T) \ -DECL_PUSH_CORE(T, T, T const &) \ -DECL_PUSH_CORE(T, T, T &&) - -#define DECL_GC(T) static int T ## _gc(lua_State * L) { static_cast(lua_touserdata(L, 1))->~T(); return 0; } - -#define DECL_PRED(T) \ -bool is_ ## T(lua_State * L, int idx) { return testudata(L, idx, T ## _mt); } \ -static int T ## _pred(lua_State * L) { check_num_args(L, 1); return push_boolean(L, is_ ## T(L, 1)); } - -void throw_bad_arg_error(lua_State * L, int i, char const * expected_type); - -/** - \brief Create basic declarations for adding a new kind of userdata in Lua - T is a Lean object type. - For example, if T == expr, it produces an implementation for the - following declarations - - constexpr char const * expr_mt = "expr"; - expr & to_expr(lua_State * L, int i); - bool is_expr(lua_State * L, int i); - static int expr_pred(lua_State * L); - static int expr_gc(lua_State * L); - int push_expr(lua_State * L, expr const & e); - int push_expr(lua_State * L, expr && e); -*/ -#define DECL_UDATA(T) \ -constexpr char const * T ## _mt = #T; \ -DECL_PRED(T) \ -T & to_ ## T(lua_State * L, int i) { if (!is_ ## T(L, i)) throw_bad_arg_error(L, i, T ## _mt); return *static_cast(luaL_checkudata(L, i, T ## _mt)); } \ -DECL_GC(T) \ -DECL_PUSH(T) - -/** - \brief Similar to DECL_UDATA, but it only declares the functions. - - For example, if T == expr, it produces the following declarations: - - class expr; - expr & to_expr(lua_State * L, int i); - bool is_expr(lua_State * L, int i); - int push_expr(lua_State * L, expr const & e); - int push_expr(lua_State * L, expr && e); -*/ -#define UDATA_DEFS_CORE(T) \ -T & to_ ## T(lua_State * L, int i); \ -bool is_ ## T(lua_State * L, int i); \ -int push_ ## T(lua_State * L, T const & e); \ -int push_ ## T(lua_State * L, T && e); -#define UDATA_DEFS(T) \ -class T; \ -UDATA_DEFS_CORE(T) -// ======================================= - -// ======================================= -// Useful macros -inline int push_boolean(lua_State * L, bool b) { lua_pushboolean(L, b); return 1; } -inline int push_string(lua_State * L, char const * s) { lua_pushstring(L, s); return 1; } -inline int push_integer(lua_State * L, lua_Integer v) { lua_pushinteger(L, v); return 1; } -inline int push_number(lua_State * L, lua_Number v) { lua_pushnumber(L, v); return 1; } -inline int push_nil(lua_State * L) { lua_pushnil(L); return 1; } -// ======================================= - -// ======================================= -// Extra validation functions - -/** \brief Throw an exception if lua_gettop(L) != num */ -void check_num_args(lua_State * L, int num); -/** \brief Throw an exception if lua_gettop(L) > high */ -void check_atmost_num_args(lua_State * L, int high); -/** \brief Throw an exception if lua_gettop(L) < low */ -void check_atleast_num_args(lua_State * L, int low); -// ======================================= -} diff --git a/src/util/lua_list.h b/src/util/lua_list.h deleted file mode 100644 index b8aaf6890..000000000 --- a/src/util/lua_list.h +++ /dev/null @@ -1,80 +0,0 @@ -/* -Copyright (c) 2014 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/list.h" -#include "util/sstream.h" - -namespace lean { -/** \brief Convert a Lua table into a list */ -template -list table_to_list(lua_State * L, int idx, Proc const & to_value) { - if (lua_istable(L, idx)) { - int n = objlen(L, idx); - list r; - for (int i = n; i >= 1; i--) { - lua_rawgeti(L, idx, i); - r = cons(to_value(L, -1), r); - lua_pop(L, 1); - } - return r; - } else { - throw exception(sstream() << "arg #" << idx << " must be a lua table"); - } -} - -#define DEFINE_LUA_LIST(T, PushVal, ToVal) \ -typedef list list_ ## T; \ -DECL_UDATA(list_ ## T) \ -static int list_ ## T ## _cons(lua_State * L) { return push_list_ ## T(L, list(ToVal(L, 1), to_list_ ## T(L, 2))); } \ -static int list_ ## T ## _nil(lua_State * L) { return push_list_ ## T(L, list()); } \ -static int list_ ## T ## _mk(lua_State * L) { \ - int nargs = lua_gettop(L); \ - return (nargs == 0) ? list_ ## T ## _nil(L) : list_ ## T ## _cons(L); \ -} \ -static int list_ ## T ## _is_nil(lua_State * L) { return push_boolean(L, is_nil(to_list_ ## T(L, 1))); } \ -static int list_ ## T ## _car(lua_State * L) { \ - list & l = to_list_ ## T(L, 1); \ - if (is_nil(l)) throw exception("arg #1 must be a cons cell"); \ - return PushVal(L, car(l)); \ -} \ -static int list_ ## T ## _cdr(lua_State * L) { \ - list & l = to_list_ ## T(L, 1); \ - if (is_nil(l)) throw exception("arg #1 must be a cons cell"); \ - return push_list_ ## T(L, cdr(l)); \ -} \ -static int list_ ## T ## _eq(lua_State * L) { return push_boolean(L, to_list_ ## T(L, 1) == to_list_ ## T(L, 2)); } \ -static int list_ ## T ## _is_eqp(lua_State * L) { return push_boolean(L, is_eqp(to_list_ ## T(L, 1), to_list_ ## T(L, 2))); } \ -static int list_ ## T ## _len(lua_State * L) { return push_integer(L, length(to_list_ ## T(L, 1))); } \ -static const struct luaL_Reg list_ ## T ## _m[] = { \ - {"__gc", list_ ## T ## _gc}, \ - {"__eq", safe_function}, \ - {"__len", safe_function}, \ - {"is_nil", safe_function}, \ - {"empty", safe_function}, \ - {"car", safe_function}, \ - {"cdr", safe_function}, \ - {"head", safe_function}, \ - {"tail", safe_function}, \ - {"is_eqp", safe_function}, \ - {0, 0} \ -}; \ -list to_list_ ## T ## _ext(lua_State * L, int idx) { \ - if (is_list_ ## T(L, idx)) \ - return to_list_ ## T(L, idx); \ - else \ - return table_to_list(L, idx, ToVal); \ -} \ -static void open_list_ ## T(lua_State * L) { \ - luaL_newmetatable(L, list_ ## T ## _mt); \ - lua_pushvalue(L, -1); \ - lua_setfield(L, -2, "__index"); \ - setfuncs(L, list_ ## T ## _m, 0); \ - \ - set_global_function(L, "list_" #T); \ - set_global_function(L, "is_list_" #T); \ -} -} diff --git a/src/util/lua_named_param.cpp b/src/util/lua_named_param.cpp deleted file mode 100644 index 532970545..000000000 --- a/src/util/lua_named_param.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* -Copyright (c) 2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include -#include "util/lua_named_param.h" -#include "util/sstream.h" -#include "util/int64.h" - -namespace lean { -bool get_bool_named_param(lua_State * L, int idx, char const * opt_name, bool def_value) { - if (lua_istable(L, idx)) { - bool result = def_value; - push_string(L, opt_name); - lua_gettable(L, idx); - if (lua_isboolean(L, -1)) { - result = lua_toboolean(L, -1); - lua_pop(L, 1); - return result; - } else if (lua_isnil(L, -1)) { - lua_pop(L, 1); - return result; - } else { - lua_pop(L, 1); - throw exception(sstream() << "field '" << opt_name << "' must be a Boolean in table at arg #" << idx); - } - } else if (idx <= lua_gettop(L) && !lua_isnil(L, idx)) { - throw exception(sstream() << "arg #" << idx << " must be a table"); - } else { - return def_value; - } -} - -int get_int_named_param(lua_State * L, int idx, char const * opt_name, int def_value) { - if (lua_istable(L, idx)) { - int result = def_value; - push_string(L, opt_name); - lua_gettable(L, idx); - if (lua_isnumber(L, -1)) { - result = lua_tointeger(L, -1); - lua_pop(L, 1); - return result; - } else if (lua_isnil(L, -1)) { - lua_pop(L, 1); - return result; - } else { - lua_pop(L, 1); - throw exception(sstream() << "field '" << opt_name << "' must be an integer in table at arg #" << idx); - } - } else if (idx <= lua_gettop(L) && !lua_isnil(L, idx)) { - throw exception(sstream() << "arg #" << idx << " must be a table"); - } else { - return def_value; - } -} - -unsigned get_uint_named_param(lua_State * L, int idx, char const * opt_name, unsigned def_value) { - if (lua_istable(L, idx)) { - push_string(L, opt_name); - lua_gettable(L, idx); - if (lua_isnumber(L, -1)) { - int64 result = lua_tointeger(L, -1); - lua_pop(L, 1); - if (result < 0 || result > static_cast(std::numeric_limits::max())) - throw exception(sstream() << "field '" << opt_name << "' must be a unsigned integer in table at arg #" << idx); - return static_cast(result); - } else if (lua_isnil(L, -1)) { - lua_pop(L, 1); - return def_value; - } else { - lua_pop(L, 1); - throw exception(sstream() << "field '" << opt_name << "' must be a unsigned integer in table at arg #" << idx); - } - } else if (idx <= lua_gettop(L) && !lua_isnil(L, idx)) { - throw exception(sstream() << "arg #" << idx << " must be a table"); - } else { - return def_value; - } -} - -optional get_opt_uint_named_param(lua_State * L, int idx, char const * opt_name, optional const & def_value) { - if (lua_istable(L, idx)) { - push_string(L, opt_name); - lua_gettable(L, idx); - if (lua_isnumber(L, -1)) { - int64 result = lua_tointeger(L, -1); - lua_pop(L, 1); - if (result < 0 || result > static_cast(std::numeric_limits::max())) - throw exception(sstream() << "field '" << opt_name << "' must be a unsigned integer in table at arg #" << idx); - return optional(static_cast(result)); - } else if (lua_isnil(L, -1)) { - lua_pop(L, 1); - return def_value; - } else { - lua_pop(L, 1); - throw exception(sstream() << "field '" << opt_name << "' must be a unsigned integer in table at arg #" << idx); - } - } else if (idx <= lua_gettop(L) && !lua_isnil(L, idx)) { - throw exception(sstream() << "arg #" << idx << " must be a table"); - } else { - return def_value; - } -} - -name_set get_name_set_named_param(lua_State * L, int idx, char const * opt_name, name_set const & def_value) { - if (lua_istable(L, idx)) { - push_string(L, opt_name); - lua_gettable(L, idx); - if (is_name_set(L, -1)) { - name_set result = to_name_set(L, -1); - lua_pop(L, 1); - return result; - } else if (lua_isnil(L, -1)) { - lua_pop(L, 1); - return def_value; - } else { - lua_pop(L, 1); - throw exception(sstream() << "field '" << opt_name << "' must be a name_set in table at arg #" << idx); - } - } else if (idx <= lua_gettop(L) && !lua_isnil(L, idx)) { - throw exception(sstream() << "arg #" << idx << " must be a table"); - } else { - return def_value; - } -} - -list get_list_name_named_param(lua_State * L, int idx, char const * opt_name, list const & def_value) { - if (lua_istable(L, idx)) { - push_string(L, opt_name); - lua_gettable(L, idx); - if (is_list_name(L, -1) || lua_istable(L, -1)) { - list result = to_list_name_ext(L, -1); - lua_pop(L, 1); - return result; - } else if (lua_isnil(L, -1)) { - lua_pop(L, 1); - return def_value; - } else { - lua_pop(L, 1); - throw exception(sstream() << "field '" << opt_name << "' must be a list of names in table at arg #" << idx); - } - } else if (idx <= lua_gettop(L) && !lua_isnil(L, idx)) { - throw exception(sstream() << "arg #" << idx << " must be a table"); - } else { - return def_value; - } -} -} - diff --git a/src/util/lua_named_param.h b/src/util/lua_named_param.h deleted file mode 100644 index e937d3152..000000000 --- a/src/util/lua_named_param.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright (c) 2014 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/lua.h" -#include "util/optional.h" -#include "util/name_set.h" - -namespace lean { -// ======================================= -// Utilities for simulating Python-like named parameters using Lua tables. -// In the following function \c idx is the position of the Lua table on the Lua stack. -bool get_bool_named_param(lua_State * L, int idx, char const * opt_name, bool def_value); -int get_int_named_param(lua_State * L, int idx, char const * opt_name, int def_value); -unsigned get_uint_named_param(lua_State * L, int idx, char const * opt_name, unsigned def_value); -optional get_opt_uint_named_param(lua_State * L, int idx, char const * opt_name, - optional const & def_value = optional()); -name_set get_name_set_named_param(lua_State * L, int idx, char const * opt_name, name_set const & def_value = name_set()); -list get_list_name_named_param(lua_State * L, int idx, char const * opt_name, list const & def_value); -} diff --git a/src/util/lua_pair.h b/src/util/lua_pair.h deleted file mode 100644 index e6488d0a4..000000000 --- a/src/util/lua_pair.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright (c) 2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#pragma once -#include -#include "util/sstream.h" - -namespace lean { -#define DEFINE_LUA_PAIR_CORE(T1, PushVal1, ToVal1, T2, PushVal2, ToVal2, MK_Name, IS_Name) \ -typedef pair pair_ ## T1 ## _ ## T2; \ -DECL_UDATA(pair_ ## T1 ## _ ## T2) \ -pair to_pair_ ## T1 ## _ ## T2 ## _ext(lua_State * L, int idx) { \ - if (is_pair_ ## T1 ## _ ## T2(L, idx)) { \ - return to_pair_ ## T1 ## _ ## T2(L, idx); \ - } else if (lua_istable(L, idx)) { \ - lua_pushvalue(L, idx); \ - int n = objlen(L, -1); \ - if (n != 2) \ - throw exception(sstream() << "arg #" << idx << " must be a table of size 2"); \ - lua_rawgeti(L, -1, 1); \ - lua_rawgeti(L, -2, 2); \ - pair r(ToVal1(L, -2), ToVal2(L, -1)); \ - lua_pop(L, 3); \ - return r; \ - } else { \ - throw exception(sstream() << "arg #" << idx << " must be a pair or a Lua table"); \ - } \ -} \ -static int pair_ ## T1 ## _ ## T2 ## _mk(lua_State * L) { return push_pair_ ## T1 ## _ ## T2(L, pair(ToVal1(L, 1), ToVal2(L, 2))); } \ -static int pair_ ## T1 ## _ ## T2 ## _first(lua_State * L) { return PushVal1(L, to_pair_ ## T1 ## _ ## T2(L, 1).first); } \ -static int pair_ ## T1 ## _ ## T2 ## _second(lua_State * L) { return PushVal2(L, to_pair_ ## T1 ## _ ## T2(L, 1).second); } \ -static const struct luaL_Reg pair_ ## T1 ## _ ## T2 ## _m[] = { \ - {"__gc", pair_ ## T1 ## _ ## T2 ## _gc}, \ - {"first", safe_function}, \ - {"second", safe_function}, \ - {0, 0} \ -}; \ -static void open_pair_ ## T1 ## _ ## T2 (lua_State * L) { \ - luaL_newmetatable(L, pair_ ## T1 ## _ ## T2 ## _mt); \ - lua_pushvalue(L, -1); \ - lua_setfield(L, -2, "__index"); \ - setfuncs(L, pair_ ## T1 ## _ ## T2 ## _m, 0); \ - \ - set_global_function(L, MK_Name); \ - set_global_function(L, IS_Name); \ -} - -#define DEFINE_LUA_PAIR(T1, PushVal1, ToVal1, T2, PushVal2, ToVal2) DEFINE_LUA_PAIR_CORE(T1, PushVal1, ToVal1, T2, PushVal2, ToVal2, "pair_" #T1 "_" #T2, "is_pair_" #T1 "_" #T2) - -// A Pair (T, T) -#define DEFINE_LUA_HOMO_PAIR(T, PushVal, ToVal) DEFINE_LUA_PAIR_CORE(T, PushVal, ToVal, T, PushVal, ToVal, "pair_" #T, "is_pair_" #T) \ -static void open_pair_ ## T(lua_State * L) { open_pair_ ## T ## _ ## T(L); } \ -pair & to_pair_ ## T(lua_State * L, int idx) { return to_pair_ ## T ## _ ## T(L, idx); } \ -pair to_pair_ ## T ## _ext(lua_State * L, int idx) { return to_pair_ ## T ## _ ## T ## _ext(L, idx); } \ -int push_pair_ ## T(lua_State * L, pair const & p) { return push_pair_ ## T ## _ ## T(L, p); } -} diff --git a/src/util/luaref.cpp b/src/util/luaref.cpp deleted file mode 100644 index 1549e768f..000000000 --- a/src/util/luaref.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* -Copyright (c) 2013 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include "util/luaref.h" -#include "util/debug.h" - -namespace lean { -luaref::luaref(lua_State * L, int i) { - lean_assert(L); - m_state = L; - lua_pushvalue(m_state, i); - m_ref = luaL_ref(m_state, LUA_REGISTRYINDEX); -} - -luaref::luaref(luaref const & r) { - m_state = r.m_state; - if (m_state) { - r.push(); - m_ref = luaL_ref(m_state, LUA_REGISTRYINDEX); - } -} - -luaref::luaref(luaref && r) { - m_state = r.m_state; - m_ref = r.m_ref; - r.m_state = nullptr; -} - -luaref::~luaref() { - if (m_state) - luaL_unref(m_state, LUA_REGISTRYINDEX, m_ref); -} - -void luaref::release() { - if (m_state) { - luaL_unref(m_state, LUA_REGISTRYINDEX, m_ref); - m_state = nullptr; - } -} - -luaref & luaref::operator=(luaref const & r) { - if (m_state != nullptr && r.m_state != nullptr && m_ref == r.m_ref) - return *this; - if (m_state) - luaL_unref(m_state, LUA_REGISTRYINDEX, m_ref); - m_state = r.m_state; - if (m_state) { - r.push(); - m_ref = luaL_ref(m_state, LUA_REGISTRYINDEX); - } - return *this; -} - -void luaref::push() const { - lean_assert(m_state); - lua_rawgeti(m_state, LUA_REGISTRYINDEX, m_ref); -} - -int luaref_lt_proc::operator()(luaref const & r1, luaref const & r2) const { - lean_assert(r1.get_state() == r2.get_state()); - lua_State * L = r1.get_state(); - r1.push(); - r2.push(); - int r; - if (lessthan(L, -2, -1)) { - r = -1; - } else if (lessthan(L, -1, -2)) { - r = 1; - } else if (equal(L, -2, -1)) { - r = 0; - } else { - throw exception("'<' is not a total order for the elements inserted on the table"); - } - lua_pop(L, 2); - return r; -} -} diff --git a/src/util/luaref.h b/src/util/luaref.h deleted file mode 100644 index ebbf9e5eb..000000000 --- a/src/util/luaref.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright (c) 2013 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include "util/lua.h" -#pragma once - -namespace lean { -/** - \brief Reference to Lua object. -*/ -class luaref { - lua_State * m_state; - int m_ref; -public: - luaref():m_state(nullptr), m_ref(0) {} - /** - \brief Create a reference to the Lua object at position \c i on \c L stack. - */ - luaref(lua_State * L, int i); - luaref(luaref const & r); - luaref(luaref && r); - ~luaref(); - void release(); - luaref & operator=(luaref const & r); - void push() const; - lua_State * get_state() const { return m_state; } -}; - -/** - \brief '<' functor for luaref. -*/ -struct luaref_lt_proc { - int operator()(luaref const & r1, luaref const & r2) const; -}; -} diff --git a/src/util/name.cpp b/src/util/name.cpp index 47ba94601..bf9b61cdd 100644 --- a/src/util/name.cpp +++ b/src/util/name.cpp @@ -19,7 +19,6 @@ Author: Leonardo de Moura #include "util/ascii.h" #include "util/utf8.h" #include "util/object_serializer.h" -#include "util/lua_list.h" namespace lean { constexpr char const * anonymous_str = "[anonymous]"; @@ -457,133 +456,6 @@ name read_name(deserializer & d) { return d.get_extension(g_name_sd->m_deserializer_extid).read(); } -DECL_UDATA(name) - -static int mk_name(lua_State * L) { - int nargs = lua_gettop(L); - name r; - for (int i = 1; i <= nargs; i++) { - switch (lua_type(L, i)) { - case LUA_TNIL: break; // skip - case LUA_TNUMBER: r = name(r, lua_tointeger(L, i)); break; - case LUA_TSTRING: r = name(r, lua_tostring(L, i)); break; - case LUA_TUSERDATA: r = r + to_name(L, i); break; - default: throw exception(sstream() << "arg #" << i << " must be a hierarchical name, string, or integer"); - } - } - return push_name(L, r); -} - -name to_name_ext(lua_State * L, int idx) { - if (lua_isstring(L, idx)) { - return luaL_checkstring(L, idx); - } else if (lua_isnil(L, idx)) { - return name(); - } else if (lua_istable(L, idx)) { - name r; - int n = objlen(L, idx); - for (int i = 1; i <= n; i++) { - lua_rawgeti(L, idx, i); - switch (lua_type(L, -1)) { - case LUA_TNIL: break; // skip - case LUA_TNUMBER: r = name(r, lua_tointeger(L, -1)); break; - case LUA_TSTRING: r = name(r, lua_tostring(L, -1)); break; - case LUA_TUSERDATA: r = r + to_name(L, -1); break; - default: throw exception("invalid array arguments, elements must be a hierarchical name, string, or integer"); - } - lua_pop(L, 1); - } - return r; - } else { - return to_name(L, idx); - } -} - -optional to_optional_name(lua_State * L, int idx) { - if (lua_isnil(L, idx)) - return optional(); - else - return optional(to_name_ext(L, idx)); -} - -int push_optional_name(lua_State * L, optional const & n) { - if (n) - return push_name(L, *n); - else - return push_nil(L); -} - -static int name_tostring(lua_State * L) { return push_string(L, to_name(L, 1).to_string().c_str()); } -static int name_eq(lua_State * L) { return push_boolean(L, to_name(L, 1) == to_name(L, 2)); } -static int name_lt(lua_State * L) { return push_boolean(L, to_name(L, 1) < to_name(L, 2)); } -static int name_hash(lua_State * L) { return push_integer(L, to_name(L, 1).hash()); } -#define NAME_PRED(P) static int name_ ## P(lua_State * L) { check_num_args(L, 1); return push_boolean(L, to_name(L, 1).P()); } -NAME_PRED(is_atomic) -NAME_PRED(is_anonymous) -NAME_PRED(is_string) -NAME_PRED(is_numeral) - -static int name_get_prefix(lua_State * L) { - if (to_name(L, 1).is_atomic()) - throw exception("invalid get_prefix, non-atomic name expected"); - return push_name(L, to_name(L, 1).get_prefix()); -} - -static int name_get_numeral(lua_State * L) { - if (!to_name(L, 1).is_numeral()) - throw exception("invalid get_numeral, hierarchical name with numeric head expected"); - return push_integer(L, to_name(L, 1).get_numeral()); -} - -static int name_get_string(lua_State * L) { - if (!to_name(L, 1).is_string()) - throw exception("invalid get_string, hierarchical name with string head expected"); - return push_string(L, to_name(L, 1).get_string()); -} - -static int name_append_before(lua_State * L) { return push_name(L, to_name(L, 1).append_before(lua_tostring(L, 2))); } -static int name_append_after(lua_State * L) { - if (lua_isnumber(L, 2)) - return push_name(L, to_name(L, 1).append_after(lua_tonumber(L, 2))); - else - return push_name(L, to_name(L, 1).append_after(lua_tostring(L, 2))); -} - -static int name_replace_prefix(lua_State * L) { return push_name(L, to_name(L, 1).replace_prefix(to_name_ext(L, 2), to_name_ext(L, 3))); } - -static const struct luaL_Reg name_m[] = { - {"__gc", name_gc}, // never throws - {"__tostring", safe_function}, - {"__eq", safe_function}, - {"__lt", safe_function}, - {"is_atomic", safe_function}, - {"is_anonymous", safe_function}, - {"is_numeral", safe_function}, - {"is_string", safe_function}, - {"get_prefix", safe_function}, - {"get_numeral", safe_function}, - {"get_string", safe_function}, - {"hash", safe_function}, - {"append_before", safe_function}, - {"append_after", safe_function}, - {"replace_prefix", safe_function}, - {0, 0} -}; - -DEFINE_LUA_LIST(name, push_name, to_name_ext) - -void open_name(lua_State * L) { - luaL_newmetatable(L, name_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, name_m, 0); - - SET_GLOBAL_FUN(mk_name, "name"); - SET_GLOBAL_FUN(name_pred, "is_name"); - - open_list_name(L); -} - void initialize_name() { g_anonymous = new name(); g_name_sd = new name_sd(); diff --git a/src/util/name.h b/src/util/name.h index b82920964..4039eb777 100644 --- a/src/util/name.h +++ b/src/util/name.h @@ -12,7 +12,6 @@ Author: Leonardo de Moura #include #include "util/rc.h" #include "util/pair.h" -#include "util/lua.h" #include "util/serializer.h" #include "util/optional.h" #include "util/list.h" @@ -224,15 +223,6 @@ serializer & operator<<(serializer & s, name const & n); name read_name(deserializer & d); inline deserializer & operator>>(deserializer & d, name & n) { n = read_name(d); return d; } -UDATA_DEFS(name) -name to_name_ext(lua_State * L, int idx); -optional to_optional_name(lua_State * L, int idx); -int push_optional_name(lua_State * L, optional const & n); -bool is_list_name(lua_State * L, int idx); -list & to_list_name(lua_State * L, int idx); -list to_list_name_ext(lua_State * L, int idx); -int push_list_name(lua_State * L, list const & l); -void open_name(lua_State * L); void initialize_name(); void finalize_name(); } diff --git a/src/util/name_generator.cpp b/src/util/name_generator.cpp index 6084f06e5..3581d4813 100644 --- a/src/util/name_generator.cpp +++ b/src/util/name_generator.cpp @@ -28,34 +28,6 @@ void swap(name_generator & a, name_generator & b) { std::swap(a.m_next_idx, b.m_next_idx); } -DECL_UDATA(name_generator) -static int mk_name_generator(lua_State * L) { - if (lua_gettop(L) == 0) - return push_name_generator(L, name_generator(*g_tmp_prefix)); - else - return push_name_generator(L, name_generator(to_name_ext(L, 1))); -} -static int name_generator_next(lua_State * L) { return push_name(L, to_name_generator(L, 1).next()); } -static int name_generator_prefix(lua_State * L) { return push_name(L, to_name_generator(L, 1).prefix()); } -static int name_generator_mk_child(lua_State * L) { return push_name_generator(L, to_name_generator(L, 1).mk_child()); } -static const struct luaL_Reg name_generator_m[] = { - {"__gc", name_generator_gc}, // never throws - {"next", safe_function}, - {"prefix", safe_function}, - {"mk_child", safe_function}, - {0, 0} -}; - -void open_name_generator(lua_State * L) { - luaL_newmetatable(L, name_generator_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, name_generator_m, 0); - - SET_GLOBAL_FUN(mk_name_generator, "name_generator"); - SET_GLOBAL_FUN(name_generator_pred, "is_name_generator"); -} - void initialize_name_generator() { g_tmp_prefix = new name(name::mk_internal_unique_name()); } diff --git a/src/util/name_generator.h b/src/util/name_generator.h index 8d218a178..7c5b6e441 100644 --- a/src/util/name_generator.h +++ b/src/util/name_generator.h @@ -38,8 +38,6 @@ public: }; void swap(name_generator & a, name_generator & b); -UDATA_DEFS(name_generator) -void open_name_generator(lua_State * L); void initialize_name_generator(); void finalize_name_generator(); } diff --git a/src/util/name_set.cpp b/src/util/name_set.cpp index 0ea3568ee..15e270925 100644 --- a/src/util/name_set.cpp +++ b/src/util/name_set.cpp @@ -17,34 +17,4 @@ name mk_unique(name_set const & s, name const & suggestion) { i++; } } - -DECL_UDATA(name_set) -static int mk_name_set(lua_State * L) { - name_set r; - int nargs = lua_gettop(L); - for (int i = 1; i <= nargs; i++) - r.insert(to_name_ext(L, i)); - return push_name_set(L, r); -} -static int name_set_insert(lua_State * L) { return push_name_set(L, insert(to_name_set(L, 1), to_name_ext(L, 2))); } -static int name_set_contains(lua_State * L) { return push_boolean(L, to_name_set(L, 1).contains(to_name_ext(L, 2))); } -static int name_set_erase(lua_State * L) { return push_name_set(L, erase(to_name_set(L, 1), to_name_ext(L, 2))); } - -static const struct luaL_Reg name_set_m[] = { - {"__gc", name_set_gc}, // never throws - {"insert", safe_function}, - {"contains", safe_function}, - {"erase", safe_function}, - {0, 0} -}; - -void open_name_set(lua_State * L) { - luaL_newmetatable(L, name_set_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, name_set_m, 0); - - SET_GLOBAL_FUN(mk_name_set, "name_set"); - SET_GLOBAL_FUN(name_set_pred, "is_name_set"); -} } diff --git a/src/util/name_set.h b/src/util/name_set.h index 5ab345e4d..7eeae93fe 100644 --- a/src/util/name_set.h +++ b/src/util/name_set.h @@ -7,7 +7,6 @@ Author: Leonardo de Moura #pragma once #include "util/rb_tree.h" #include "util/name.h" -#include "util/lua.h" namespace lean { typedef rb_tree name_set; /** \brief Make a name that does not occur in \c s, based on the given suggestion. */ @@ -20,7 +19,4 @@ name_set to_name_set(C const & ns) { r.insert(n); return r; } - -UDATA_DEFS_CORE(name_set) -void open_name_set(lua_State * L); } diff --git a/src/util/numerics/mpq.cpp b/src/util/numerics/mpq.cpp index 311b39cf9..4d38e4e11 100644 --- a/src/util/numerics/mpq.cpp +++ b/src/util/numerics/mpq.cpp @@ -164,94 +164,6 @@ void finalize_mpq() { mpq read_mpq(deserializer & d) { return mpq(d.read_string().c_str()); } - -DECL_UDATA(mpq) - -mpq to_mpq_ext(lua_State * L, int idx) { - switch (lua_type(L, idx)) { - case LUA_TNUMBER: return mpq(lua_tonumber(L, idx)); - case LUA_TSTRING: return mpq(lua_tostring(L, idx)); - case LUA_TUSERDATA: - if (is_mpz(L, idx)) { - return mpq(to_mpz(L, idx)); - } else { - return *static_cast(luaL_checkudata(L, idx, mpq_mt)); - } - default: throw exception(sstream() << "arg #" << idx << " must be a number, string, mpz or mpq"); - } -} - -static int mpq_tostring(lua_State * L) { - mpq * n = static_cast(luaL_checkudata(L, 1, mpq_mt)); - std::ostringstream out; - out << *n; - return push_string(L, out.str().c_str()); -} - -static int mpq_eq(lua_State * L) { - return push_boolean(L, to_mpq_ext(L, 1) == to_mpq_ext(L, 2)); -} - -static int mpq_lt(lua_State * L) { - return push_boolean(L, to_mpq_ext(L, 1) < to_mpq_ext(L, 2)); -} - -static int mpq_add(lua_State * L) { - return push_mpq(L, to_mpq_ext(L, 1) + to_mpq_ext(L, 2)); -} - -static int mpq_sub(lua_State * L) { - return push_mpq(L, to_mpq_ext(L, 1) - to_mpq_ext(L, 2)); -} - -static int mpq_mul(lua_State * L) { - return push_mpq(L, to_mpq_ext(L, 1) * to_mpq_ext(L, 2)); -} - -static int mpq_div(lua_State * L) { - mpq arg2 = to_mpq_ext(L, 2); - if (arg2 == 0) throw exception("division by zero"); - return push_mpq(L, to_mpq_ext(L, 1) / arg2); -} - -static int mpq_umn(lua_State * L) { - return push_mpq(L, 0 - to_mpq_ext(L, 1)); -} - -static int mpq_power(lua_State * L) { - int k = luaL_checkinteger(L, 2); - if (k < 0) throw exception("argument #2 must be positive"); - return push_mpq(L, pow(to_mpq_ext(L, 1), k)); -} - -static int mk_mpq(lua_State * L) { - mpq arg = to_mpq_ext(L, 1); - return push_mpq(L, arg); -} - -static const struct luaL_Reg mpq_m[] = { - {"__gc", mpq_gc}, // never throws - {"__tostring", safe_function}, - {"__eq", safe_function}, - {"__lt", safe_function}, - {"__add", safe_function}, - {"__sub", safe_function}, - {"__mul", safe_function}, - {"__div", safe_function}, - {"__pow", safe_function}, - {"__unm", safe_function}, - {0, 0} -}; - -void open_mpq(lua_State * L) { - luaL_newmetatable(L, mpq_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, mpq_m, 0); - - SET_GLOBAL_FUN(mk_mpq, "mpq"); - SET_GLOBAL_FUN(mpq_pred, "is_mpq"); -} } void print(lean::mpq const & v) { std::cout << v << std::endl; } diff --git a/src/util/numerics/mpq.h b/src/util/numerics/mpq.h index 384dfff4c..22f382c04 100644 --- a/src/util/numerics/mpq.h +++ b/src/util/numerics/mpq.h @@ -5,7 +5,6 @@ Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #pragma once -#include "util/lua.h" #include "util/numerics/mpz.h" namespace lean { @@ -286,10 +285,6 @@ serializer & operator<<(serializer & s, mpq const & n); mpq read_mpq(deserializer & d); inline deserializer & operator>>(deserializer & d, mpq & n) { n = read_mpq(d); return d; } -UDATA_DEFS(mpq) -mpq to_mpq_ext(lua_State * L, int idx); -void open_mpq(lua_State * L); - void initialize_mpq(); void finalize_mpq(); } diff --git a/src/util/numerics/mpz.cpp b/src/util/numerics/mpz.cpp index 36f89237d..cec9410bc 100644 --- a/src/util/numerics/mpz.cpp +++ b/src/util/numerics/mpz.cpp @@ -102,88 +102,6 @@ serializer & operator<<(serializer & s, mpz const & n) { mpz read_mpz(deserializer & d) { return mpz(d.read_string().c_str()); } - -DECL_UDATA(mpz) -mpz to_mpz_ext(lua_State * L, int idx) { - switch (lua_type(L, idx)) { - case LUA_TNUMBER: return mpz(static_cast(lua_tointeger(L, idx))); - case LUA_TSTRING: return mpz(lua_tostring(L, idx)); - case LUA_TUSERDATA: return *static_cast(luaL_checkudata(L, idx, mpz_mt)); - default: throw exception(sstream() << "arg #" << idx << " must be a number, string or mpz"); - } -} - -static int mpz_tostring(lua_State * L) { - mpz * n = static_cast(luaL_checkudata(L, 1, mpz_mt)); - std::ostringstream out; - out << *n; - return push_string(L, out.str().c_str()); -} - -static int mpz_eq(lua_State * L) { - return push_boolean(L, to_mpz_ext(L, 1) == to_mpz_ext(L, 2)); -} - -static int mpz_lt(lua_State * L) { - return push_boolean(L, to_mpz_ext(L, 1) < to_mpz_ext(L, 2)); -} - -static int mpz_add(lua_State * L) { - return push_mpz(L, to_mpz_ext(L, 1) + to_mpz_ext(L, 2)); -} - -static int mpz_sub(lua_State * L) { - return push_mpz(L, to_mpz_ext(L, 1) - to_mpz_ext(L, 2)); -} - -static int mpz_mul(lua_State * L) { - return push_mpz(L, to_mpz_ext(L, 1) * to_mpz_ext(L, 2)); -} - -static int mpz_div(lua_State * L) { - mpz arg2 = to_mpz_ext(L, 2); - if (arg2 == 0) throw exception("division by zero"); - return push_mpz(L, to_mpz_ext(L, 1) / arg2); -} - -static int mpz_umn(lua_State * L) { - return push_mpz(L, 0 - to_mpz_ext(L, 1)); -} - -static int mpz_power(lua_State * L) { - int k = luaL_checkinteger(L, 2); - if (k < 0) throw exception("argument #2 must be positive"); - return push_mpz(L, pow(to_mpz_ext(L, 1), k)); -} - -static int mk_mpz(lua_State * L) { - mpz arg = to_mpz_ext(L, 1); - return push_mpz(L, arg); -} - -static const struct luaL_Reg mpz_m[] = { - {"__gc", mpz_gc}, // never throws - {"__tostring", safe_function}, - {"__eq", safe_function}, - {"__lt", safe_function}, - {"__add", safe_function}, - {"__sub", safe_function}, - {"__mul", safe_function}, - {"__div", safe_function}, - {"__pow", safe_function}, - {"__unm", safe_function}, - {0, 0} -}; - -void open_mpz(lua_State * L) { - luaL_newmetatable(L, mpz_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, mpz_m, 0); - - SET_GLOBAL_FUN(mk_mpz, "mpz"); - SET_GLOBAL_FUN(mpz_pred, "is_mpz"); -} } void print(lean::mpz const & n) { std::cout << n << std::endl; } diff --git a/src/util/numerics/mpz.h b/src/util/numerics/mpz.h index 84ccb7915..79dd9a7f4 100644 --- a/src/util/numerics/mpz.h +++ b/src/util/numerics/mpz.h @@ -9,7 +9,6 @@ Author: Leonardo de Moura #include #include #include "util/debug.h" -#include "util/lua.h" #include "util/serializer.h" #include "util/numerics/numeric_traits.h" @@ -246,10 +245,6 @@ serializer & operator<<(serializer & s, mpz const & n); mpz read_mpz(deserializer & d); inline deserializer & operator>>(deserializer & d, mpz & n) { n = read_mpz(d); return d; } -UDATA_DEFS(mpz) -mpz to_mpz_ext(lua_State * L, int idx); -void open_mpz(lua_State * L); - void initialize_mpz(); void finalize_mpz(); } diff --git a/src/util/rb_map.cpp b/src/util/rb_map.cpp deleted file mode 100644 index db35fa00a..000000000 --- a/src/util/rb_map.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* -Copyright (c) 2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include "util/lua.h" -#include "util/luaref.h" -#include "util/rb_map.h" - -namespace lean { -typedef rb_map lua_rb_map; -DECL_UDATA(lua_rb_map) - -static int mk_lua_rb_map(lua_State * L) { - lua_rb_map r; - return push_lua_rb_map(L, r); -} - -static int lua_rb_map_size(lua_State * L) { - return push_integer(L, to_lua_rb_map(L, 1).size()); -} - -static int lua_rb_map_contains(lua_State * L) { - return push_boolean(L, to_lua_rb_map(L, 1).contains(luaref(L, 2))); -} - -static int lua_rb_map_empty(lua_State * L) { - return push_boolean(L, to_lua_rb_map(L, 1).empty()); -} - -static int lua_rb_map_insert(lua_State * L) { - to_lua_rb_map(L, 1).insert(luaref(L, 2), luaref(L, 3)); - return 0; -} - -static int lua_rb_map_erase(lua_State * L) { - to_lua_rb_map(L, 1).erase(luaref(L, 2)); - return 0; -} - -static int lua_rb_map_find(lua_State * L) { - lua_rb_map & m = to_lua_rb_map(L, 1); - luaref const * val = m.find(luaref(L, 2)); - if (val) { - lean_assert(val->get_state() == L); - val->push(); - } else { - lua_pushnil(L); - } - return 1; -} - -static int lua_rb_map_copy(lua_State * L) { - return push_lua_rb_map(L, to_lua_rb_map(L, 1)); -} - -static int lua_rb_map_for_each(lua_State * L) { - // Remark: we take a copy of the map to make sure - // for_each will not crash if the map is updated while being - // traversed. - // The copy operation is very cheap O(1). - lua_rb_map m(to_lua_rb_map(L, 1)); // map - luaL_checktype(L, 2, LUA_TFUNCTION); // user-fun - m.for_each([&](luaref const & k, luaref const & v) { - lua_pushvalue(L, 2); // push user-fun - k.push(); - v.push(); - pcall(L, 2, 0, 0); - }); - return 0; -} - -static const struct luaL_Reg lua_rb_map_m[] = { - {"__gc", lua_rb_map_gc}, // never throws - {"__len", safe_function }, - {"contains", safe_function}, - {"size", safe_function}, - {"empty", safe_function}, - {"insert", safe_function}, - {"erase", safe_function}, - {"find", safe_function}, - {"copy", safe_function}, - {"for_each", safe_function}, - {0, 0} -}; - -void open_rb_map(lua_State * L) { - luaL_newmetatable(L, lua_rb_map_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, lua_rb_map_m, 0); - - SET_GLOBAL_FUN(mk_lua_rb_map, "rb_map"); - SET_GLOBAL_FUN(lua_rb_map_pred, "is_rb_map"); -} -} diff --git a/src/util/rb_map.h b/src/util/rb_map.h index 19446bcd2..af68bfd57 100644 --- a/src/util/rb_map.h +++ b/src/util/rb_map.h @@ -6,7 +6,6 @@ Author: Leonardo de Moura */ #pragma once #include -#include "util/lua.h" #include "util/pair.h" #include "util/rb_tree.h" @@ -100,5 +99,4 @@ template void for_each(rb_map const & m, F && f) { return m.for_each(f); } -void open_rb_map(lua_State * L); } diff --git a/src/util/script_exception.cpp b/src/util/script_exception.cpp deleted file mode 100644 index 9ece688a1..000000000 --- a/src/util/script_exception.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* -Copyright (c) 2013 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include -#include -#include -#include "util/thread.h" -#include "util/debug.h" -#include "util/script_exception.h" - -namespace lean { -script_exception::script_exception(char const * lua_error) { - lean_assert(lua_error); - std::string fname; - std::string line; - std::string msg; - int state = 0; - char const * it = lua_error; - while (*it) { - if (state == 0) { - if (*it == ':') { - state = 1; - } else { - fname += *it; - } - } else if (state == 1) { - if (*it == ':') { - state = 2; - } else { - line += *it; - } - } else { - msg += *it; - } - it++; - } - if (state != 2) { - // failed to decode Lua error message - m_source = source::Unknown; - m_msg = lua_error; - } else { - if (fname == "[string \"...\"]") { - m_source = source::String; - } else { - m_source = source::File; - m_file = fname; - } - m_line = atoi(line.c_str()); - m_msg = msg; - } -} - -script_exception::~script_exception() { -} - -char const * script_exception::get_file_name() const { - lean_assert(get_source() == source::File); - return m_file.c_str(); -} - -unsigned script_exception::get_line() const { - lean_assert(get_source() != source::Unknown); - return m_line; -} - -char const * script_exception::get_msg() const noexcept { - return exception::what(); -} - -MK_THREAD_LOCAL_GET_DEF(std::string, get_g_buffer) - -char const * script_exception::what() const noexcept { - std::string & buffer = get_g_buffer(); - std::ostringstream strm; - char const * msg = get_msg(); - char const * space = msg && *msg == ' ' ? "" : " "; - switch (get_source()) { - case source::String: strm << "[string]:" << get_line() << ":" << space << get_msg(); break; - case source::File: strm << get_file_name() << ":" << get_line() << ":" << space << get_msg(); break; - case source::Unknown: return get_msg(); - } - buffer = strm.str(); - return buffer.c_str(); -} - -script_nested_exception::script_nested_exception(source s, std::string f, unsigned l, std::shared_ptr const & ex): - script_exception(s, f, l, "Lean exception"), - m_exception(ex) { - lean_assert(ex); -} - -script_nested_exception::~script_nested_exception() {} - -char const * script_nested_exception::what() const noexcept { - std::string super_what = script_exception::what(); - std::string nested_what = get_exception().what(); - { - std::string buffer; - std::ostringstream strm; - strm << super_what << "\n" << nested_what; - buffer = strm.str(); - std::string & r_buffer = get_g_buffer(); - r_buffer = buffer; - return r_buffer.c_str(); - } -} -} diff --git a/src/util/script_exception.h b/src/util/script_exception.h deleted file mode 100644 index 002ee1c0c..000000000 --- a/src/util/script_exception.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -Copyright (c) 2013 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#pragma once -#include -#include -#include "util/exception.h" - -namespace lean { -/** - \brief Exception for wrapping errors produced by the Lua engine. -*/ -class script_exception : public exception { -public: - enum class source { String, File, Unknown }; -protected: - source m_source; - std::string m_file; // if source == File, then this field contains the filename that triggered the error. - unsigned m_line; // line number - script_exception(source s, std::string f, unsigned l, std::string const & msg):exception(msg), m_source(s), m_file(f), m_line(l) {} -public: - script_exception(char const * lua_error); - virtual ~script_exception(); - virtual char const * what() const noexcept; - virtual source get_source() const { return m_source; } - virtual char const * get_file_name() const; - virtual unsigned get_line() const; - /** \brief Return error message without position information */ - virtual char const * get_msg() const noexcept; - virtual throwable * clone() const { return new script_exception(m_source, m_file, m_line, m_msg); } - virtual void rethrow() const { throw *this; } -}; - -/** - \brief Lean exception occurred inside of a script -*/ -class script_nested_exception : public script_exception { - std::shared_ptr m_exception; - script_nested_exception(source s, std::string f, unsigned l, std::shared_ptr const & ex); -public: - script_nested_exception(bool file, std::string f, unsigned l, std::shared_ptr const & ex):script_nested_exception(file ? source::File : source::String, f, l, ex) {} - virtual ~script_nested_exception(); - virtual char const * what() const noexcept; - virtual throwable * clone() const { return new script_nested_exception(m_source, m_file, m_line, m_exception); } - virtual void rethrow() const { throw *this; } - throwable const & get_exception() const { return *(m_exception.get()); } -}; -} diff --git a/src/util/script_state.cpp b/src/util/script_state.cpp deleted file mode 100644 index 60cc95366..000000000 --- a/src/util/script_state.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* -Copyright (c) 2013 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include -#include -#include -#include -#include "util/lua.h" -#include "util/debug.h" -#include "util/exception.h" -#include "util/memory.h" -#include "util/buffer.h" -#include "util/interrupt.h" -#include "util/script_state.h" -#include "util/script_exception.h" -#include "util/name.h" -#include "util/name_generator.h" -#include "util/name_set.h" -#include "util/rb_map.h" -#include "util/lean_path.h" - -extern "C" void * lua_realloc(void *, void * q, size_t, size_t new_size) { return lean::realloc(q, new_size); } - -namespace lean { -static std::vector * g_modules = nullptr; - -void script_state::register_module(reg_fn f) { - g_modules->push_back(f); -} - -void initialize_script_state() { - g_modules = new std::vector(); -} - -void finalize_script_state() { - delete g_modules; -} - -static unsigned g_check_interrupt_freq = 1048576; - -void script_state::set_check_interrupt_freq(unsigned count) { - g_check_interrupt_freq = count; -} - -void open_extra(lua_State * L); - -static char g_weak_ptr_key; // key for Lua registry (used at get_weak_ptr and save_weak_ptr) - -struct script_state::imp { - lua_State * m_state; - std::unordered_set m_imported_modules; - - static std::weak_ptr * get_weak_ptr(lua_State * L) { - lua_pushlightuserdata(L, static_cast(&g_weak_ptr_key)); - lua_gettable(L, LUA_REGISTRYINDEX); - std::weak_ptr * ptr = static_cast*>(lua_touserdata(L, -1)); - lua_pop(L, 1); - return ptr; - } - - void save_weak_ptr(std::shared_ptr & ptr) { - lua_pushlightuserdata(m_state, static_cast(&g_weak_ptr_key)); - void * mem = lua_newuserdata(m_state, sizeof(std::weak_ptr)); - new (mem) std::weak_ptr(ptr); - lua_settable(m_state, LUA_REGISTRYINDEX); - } - - static void check_interrupted_hook(lua_State * L, lua_Debug *) { - try { - check_interrupted(); - } catch (interrupted & ex) { - push_exception(L, ex); - lua_error(L); - } - } - - imp() { - // TODO(Leo) investigate why TCMALLOC + lua_realloc do not work together - // #ifdef LEAN_USE_LUA_NEWSTATE - #if 0 - m_state = lua_newstate(lua_realloc, nullptr); - #else - m_state = luaL_newstate(); - #endif - if (m_state == nullptr) - throw exception("fail to create Lua interpreter"); - if (g_check_interrupt_freq > 0) { - lua_sethook(m_state, check_interrupted_hook, LUA_MASKCOUNT, g_check_interrupt_freq); - } - if (!lua_checkstack(m_state, 1024)) - throw exception("lua_checkstack failed"); - luaL_openlibs(m_state); - open_exception(m_state); - open_name(m_state); - open_name_generator(m_state); - open_name_set(m_state); - open_rb_map(m_state); - open_extra(m_state); - - for (auto f : *g_modules) { - f(m_state); - } - } - - ~imp() { - typedef std::weak_ptr wptr; - wptr * ptr = get_weak_ptr(m_state); - ptr->~wptr(); // destruct weak pointer - lua_close(m_state); - } - - void dofile(char const * fname) { - ::lean::dofile(m_state, fname); - } - - void dostring(char const * str) { - ::lean::dostring(m_state, str); - } - - bool import_explicit(std::string const & fname) { - if (m_imported_modules.find(fname) == m_imported_modules.end()) { - dofile(fname.c_str()); - m_imported_modules.insert(fname); - return true; - } else { - return false; - } - } - - bool import_explicit(char const * fname) { - return import_explicit(std::string(fname)); - } - - bool import(char const * fname) { - return import_explicit(find_file(std::string(fname))); - } -}; - -script_state to_script_state(lua_State * L) { - return script_state(*script_state::imp::get_weak_ptr(L)); -} - -script_state::script_state(): - m_ptr(std::make_shared()) { - m_ptr->save_weak_ptr(m_ptr); -} - -script_state::script_state(weak_ref const & r) { - if (r.expired()) - throw exception("weak reference to script_state object has expired (i.e., it has been deleted)"); - m_ptr = r.lock(); -} - -script_state::~script_state() { -} - -void script_state::dofile(char const * fname) { - m_ptr->dofile(fname); -} - -void script_state::dostring(char const * str) { - m_ptr->dostring(str); -} - -bool script_state::import(char const * str) { - return m_ptr->import(str); -} - -bool script_state::import_explicit(char const * str) { - return m_ptr->import_explicit(str); -} - -lua_State * script_state::get_state() { - return m_ptr->m_state; -} - -static int check_interrupted(lua_State *) { // NOLINT - check_interrupted(); - return 0; -} - -static int sleep(lua_State * L) { - sleep_for(luaL_checkinteger(L, 1)); - return 0; -} - -static int yield(lua_State * L) { - check_interrupted(); - int status = lua_pushthread(L); - lua_pop(L, 1); - if (status != 1) { - return lua_yield(L, 0); - } else { - // main thread cannot yield - return 0; - } -} - -static int import(lua_State * L) { - std::string fname = luaL_checkstring(L, 1); - script_state s = to_script_state(L); - s.import(fname.c_str()); - return 0; -} - -void open_extra(lua_State * L) { - SET_GLOBAL_FUN(check_interrupted, "check_interrupted"); - SET_GLOBAL_FUN(sleep, "sleep"); - SET_GLOBAL_FUN(yield, "yield"); - SET_GLOBAL_FUN(import, "import"); -} -} diff --git a/src/util/script_state.h b/src/util/script_state.h deleted file mode 100644 index 3db31ac82..000000000 --- a/src/util/script_state.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright (c) 2013 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#pragma once -#include -#include - -namespace lean { -/** - \brief Wrapper for lua_State objects which contains all Lean bindings. -*/ -class script_state { -public: - struct imp; -private: - std::shared_ptr m_ptr; - friend script_state to_script_state(lua_State * L); - friend class data_channel; -public: - static void set_check_interrupt_freq(unsigned count); - - typedef std::weak_ptr weak_ref; - - script_state(); - script_state(weak_ref const & r); - ~script_state(); - - weak_ref to_weak_ref() const { return weak_ref(m_ptr); } - - /** - \brief Execute the file with the given name. - This method throws an exception if an error occurs. - */ - void dofile(char const * fname); - /** - \brief Execute the given string. - This method throws an exception if an error occurs. - */ - void dostring(char const * str); - /** - \brief Import file \c fname from the LEAN_PATH. - If the file was already included, then nothing happens, and method returns false. - */ - bool import(char const * fname); - /** - \brief Import file \c fname. \c fname is the explicit path to the file. - If the file was already included, then nothing happens, and method returns false. - */ - bool import_explicit(char const * fname); - - lua_State * get_state(); - - typedef void (*reg_fn)(lua_State *); // NOLINT - static void register_module(reg_fn f); -}; -/** - \brief Return a reference to the script_state object that is wrapping \c L. -*/ -script_state to_script_state(lua_State * L); -void initialize_script_state(); -void finalize_script_state(); -} diff --git a/src/util/sexpr/format.cpp b/src/util/sexpr/format.cpp index 53a884b43..9b8f39fff 100644 --- a/src/util/sexpr/format.cpp +++ b/src/util/sexpr/format.cpp @@ -508,103 +508,6 @@ format pp(sexpr const & s) { return sexpr_pp_fn()(s); } -DECL_UDATA(format) - -format to_format_elem(lua_State * L, int idx) { - if (is_format(L, idx)) - return to_format(L, idx); - else if (lua_isnumber(L, idx)) - return format(static_cast(lua_tonumber(L, idx))); - else if (is_name(L, idx)) - return format(to_name(L, idx)); - else if (is_mpz(L, idx)) - return format(to_mpz(L, idx)); - else if (is_mpq(L, idx)) - return format(to_mpq(L, idx)); - else - return format(lua_tostring(L, idx)); -} - -static int format_tostring(lua_State * L) { - std::ostringstream out; - out << mk_pair(to_format(L, 1), get_global_options(L)); - return push_string(L, out.str().c_str()); -} - -static int format_concat(lua_State * L) { - return push_format(L, compose(to_format_elem(L, 1), to_format_elem(L, 2))); -} - -static int mk_format(lua_State * L) { - format r; - int nargs = lua_gettop(L); - if (nargs == 0) { - r = format(); - } else { - int i = nargs; - r = to_format_elem(L, i); - i--; - for (; i >= 1; i--) { - r = compose(to_format_elem(L, i), r); - } - } - return push_format(L, r); -} - -static int format_nest(lua_State * L) { - return push_format(L, nest(luaL_checkinteger(L, 2), to_format(L, 1))); -} - -static int format_group(lua_State * L) { - return push_format(L, group(to_format(L, 1))); -} - -static int format_highlight(lua_State * L) { - char const * color_str = luaL_checkstring(L, 2); - format::format_color color; - if (strcmp(color_str, "red") == 0) { - color = format::RED; - } else if (strcmp(color_str, "green") == 0) { - color = format::GREEN; - } else if (strcmp(color_str, "orange") == 0) { - color = format::ORANGE; - } else if (strcmp(color_str, "blue") == 0) { - color = format::BLUE; - } else if (strcmp(color_str, "cyan") == 0) { - color = format::CYAN; - } else if (strcmp(color_str, "grey") == 0) { - color = format::GREY; - } else { - throw exception(sstream() << "unknown color '" << color_str << "'"); - } - return push_format(L, highlight(to_format(L, 1), color)); -} - -static int format_line(lua_State * L) { return push_format(L, line()); } -static int format_space(lua_State * L) { return push_format(L, space()); } - -static const struct luaL_Reg format_m[] = { - {"__gc", format_gc}, // never throws - {"__tostring", safe_function}, - {"__concat", safe_function}, - {"nest", safe_function}, - {"group", safe_function}, - {"highlight", safe_function}, - {0, 0} -}; - -void open_format(lua_State * L) { - luaL_newmetatable(L, format_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, format_m, 0); - - SET_GLOBAL_FUN(mk_format, "format"); - SET_GLOBAL_FUN(format_line, "line"); - SET_GLOBAL_FUN(format_space, "space"); - SET_GLOBAL_FUN(format_pred, "is_format"); -} - void initialize_format() { g_pp_indent = new name{"pp", "indent"}; g_pp_unicode = new name{"pp", "unicode"}; diff --git a/src/util/sexpr/format.h b/src/util/sexpr/format.h index cc01f4ddc..cee216dcf 100644 --- a/src/util/sexpr/format.h +++ b/src/util/sexpr/format.h @@ -14,7 +14,6 @@ Author: Soonho Kong #include #include "util/pair.h" #include "util/debug.h" -#include "util/lua.h" #include "util/numerics/mpz.h" #include "util/sexpr/sexpr.h" @@ -308,9 +307,6 @@ format pp(sexpr const & s); /** \brief Return true iff \c f1 and \c f2 are equal when formatted with options \c o */ bool format_pp_eq(format const & f1, format const & f2, options const & o); -UDATA_DEFS(format) -void open_format(lua_State * L); - void initialize_format(); void finalize_format(); } diff --git a/src/util/sexpr/options.cpp b/src/util/sexpr/options.cpp index 0caa053d3..1ef04bac6 100644 --- a/src/util/sexpr/options.cpp +++ b/src/util/sexpr/options.cpp @@ -217,218 +217,4 @@ std::ostream & operator<<(std::ostream & out, options const & o) { out << (unicode ? g_right_angle_bracket : ")"); return out; } - -DECL_UDATA(options) - -int mk_options(name const & prefix, lua_State * L) { - options r; - int nargs = lua_gettop(L); - if (nargs % 2 != 0) - throw exception("options expects an even number of arguments"); - for (int i = 1; i < nargs; i+=2) { - name k = prefix + to_name_ext(L, i); - auto it = get_option_declarations().find(k); - if (it == get_option_declarations().end()) { - throw exception(sstream() << "unknown option '" << k.to_string().c_str() << "'"); - } else { - option_declaration const & d = it->second; - switch (d.kind()) { - case BoolOption: r = r.update(k, static_cast(lua_toboolean(L, i+1))); break; - case IntOption: r = r.update(k, static_cast(lua_tointeger(L, i+1))); break; - case UnsignedOption: r = r.update(k, static_cast(lua_tointeger(L, i+1))); break; - case DoubleOption: r = r.update(k, static_cast(lua_tonumber(L, i+1))); break; - case StringOption: r = r.update(k, lua_tostring(L, i+1)); break; - default: throw exception(sstream() << "unsupported option kind for '" << k.to_string().c_str() << "'"); - } - } - } - return push_options(L, r); -} - -static int mk_options(lua_State * L) { - return mk_options(name(), L); -} - -static int options_tostring(lua_State * L) { - std::ostringstream out; - out << to_options(L, 1); - return push_string(L, out.str().c_str()); -} - -static int options_size(lua_State * L) { - return push_integer(L, to_options(L, 1).size()); -} - -static int options_contains(lua_State * L) { - return push_boolean(L, to_options(L, 1).contains(to_name_ext(L, 2))); -} - -static int options_empty(lua_State * L) { - return push_boolean(L, to_options(L, 1).empty()); -} - -static int options_get_bool(lua_State * L) { - int nargs = lua_gettop(L); - bool defval = nargs < 3 ? false : lua_toboolean(L, 3); - return push_boolean(L, to_options(L, 1).get_bool(to_name_ext(L, 2), defval)); -} - -static int options_get_int(lua_State * L) { - int nargs = lua_gettop(L); - int defval = nargs < 3 ? 0 : lua_tointeger(L, 3); - return push_integer(L, to_options(L, 1).get_int(to_name_ext(L, 2), defval)); -} - -static int options_get_unsigned(lua_State * L) { - int nargs = lua_gettop(L); - unsigned defval = nargs < 3 ? 0 : lua_tointeger(L, 3); - return push_number(L, to_options(L, 1).get_unsigned(to_name_ext(L, 2), defval)); -} - -static int options_get_double(lua_State * L) { - int nargs = lua_gettop(L); - double defval = nargs < 3 ? 0.0 : lua_tonumber(L, 3); - return push_number(L, to_options(L, 1).get_double(to_name_ext(L, 2), defval)); -} - -static int options_get_string(lua_State * L) { - int nargs = lua_gettop(L); - char const * defval = nargs < 3 ? "" : lua_tostring(L, 3); - return push_string(L, to_options(L, 1).get_string(to_name_ext(L, 2), defval)); -} - -static int options_update_bool(lua_State * L) { - return push_options(L, to_options(L, 1).update(to_name_ext(L, 2), static_cast(lua_toboolean(L, 3)))); -} - -static int options_update_int(lua_State * L) { - return push_options(L, to_options(L, 1).update(to_name_ext(L, 2), static_cast(lua_tointeger(L, 3)))); -} - -static int options_update_unsigned(lua_State * L) { - return push_options(L, to_options(L, 1).update(to_name_ext(L, 2), static_cast(lua_tointeger(L, 3)))); -} - -static int options_update_double(lua_State * L) { - return push_options(L, to_options(L, 1).update(to_name_ext(L, 2), lua_tonumber(L, 3))); -} - -static int options_update_string(lua_State * L) { - return push_options(L, to_options(L, 1).update(to_name_ext(L, 2), lua_tostring(L, 3))); -} - -static int options_join(lua_State * L) { - return push_options(L, join(to_options(L, 1), to_options(L, 2))); -} - -static int options_get(lua_State * L) { - name k = to_name_ext(L, 2); - auto it = get_option_declarations().find(k); - if (it == get_option_declarations().end()) { - throw exception(sstream() << "unknown option '" << k.to_string().c_str() << "'"); - } else { - option_declaration const & d = it->second; - switch (d.kind()) { - case BoolOption: return options_get_bool(L); - case IntOption: return options_get_int(L); - case UnsignedOption: return options_get_unsigned(L); - case DoubleOption: return options_get_double(L); - case StringOption: return options_get_string(L); - default: throw exception(sstream() << "unsupported option kind for '" << k.to_string().c_str() << "'"); - } - } -} - -int options_update(lua_State * L) { - name k = to_name_ext(L, 2); - auto it = get_option_declarations().find(k); - if (it == get_option_declarations().end()) { - throw exception(sstream() << "unknown option '" << k.to_string().c_str() << "'"); - } else { - option_declaration const & d = it->second; - switch (d.kind()) { - case BoolOption: return options_update_bool(L); - case IntOption: return options_update_int(L); - case UnsignedOption: return options_update_unsigned(L); - case DoubleOption: return options_update_double(L); - case StringOption: return options_update_string(L); - default: throw exception(sstream() << "unsupported option kind for '" << k.to_string().c_str() << "'"); - } - } -} - -static const struct luaL_Reg options_m[] = { - {"__gc", options_gc}, // never throws - {"__tostring", safe_function}, - {"__len", safe_function }, - {"contains", safe_function}, - {"size", safe_function}, - {"empty", safe_function}, - {"get", safe_function}, - {"update", safe_function}, - {"join", safe_function}, - // low-level API - {"get_bool", safe_function}, - {"get_int", safe_function}, - {"get_unsigned", safe_function}, - {"get_double", safe_function}, - {"get_string", safe_function}, - {"update_bool", safe_function}, - {"update_int", safe_function}, - {"update_unsigned", safe_function}, - {"update_double", safe_function}, - {"update_string", safe_function}, - {0, 0} -}; - -static char g_options_key; - -options get_global_options(lua_State * L) { - lua_pushlightuserdata(L, static_cast(&g_options_key)); - lua_gettable(L, LUA_REGISTRYINDEX); - options r; - if (is_options(L, -1)) - r = to_options(L, -1); - lua_pop(L, 1); - return r; -} - -void set_global_options(lua_State * L, options const & o) { - lua_pushlightuserdata(L, static_cast(&g_options_key)); - push_options(L, o); - lua_settable(L, LUA_REGISTRYINDEX); -} - -static int _get_global_options(lua_State * L) { - return push_options(L, get_global_options(L)); -} - -static int _set_global_options(lua_State * L) { - options o = to_options(L, 1); - set_global_options(L, o); - return 0; -} - -static int _set_global_option(lua_State * L) { - options o = get_global_options(L); - push_options(L, o); - lua_insert(L, 1); - options_update(L); - o = to_options(L, -1); - set_global_options(L, o); - return 0; -} - -void open_options(lua_State * L) { - luaL_newmetatable(L, options_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, options_m, 0); - - SET_GLOBAL_FUN(mk_options, "options"); - SET_GLOBAL_FUN(options_pred, "is_options"); - SET_GLOBAL_FUN(_get_global_options, "get_options"); - SET_GLOBAL_FUN(_set_global_options, "set_options"); - SET_GLOBAL_FUN(_set_global_option, "set_option"); -} } diff --git a/src/util/sexpr/options.h b/src/util/sexpr/options.h index 984c7d54f..4d82d1bb1 100644 --- a/src/util/sexpr/options.h +++ b/src/util/sexpr/options.h @@ -9,7 +9,6 @@ Author: Leonardo de Moura #include "util/name.h" #include "util/sexpr/sexpr.h" #include "util/sexpr/format.h" -#include "util/lua.h" #include "util/serializer.h" namespace lean { @@ -105,25 +104,6 @@ struct mk_option_declaration { mk_option_declaration(name const & n, option_kind k, char const * default_value, char const * description); }; -int mk_options(name const & prefix, lua_State * L); - -UDATA_DEFS(options) -int options_update(lua_State * L); -/** - \brief Return the set of options associated with the given Lua State. - This procedure checks for options at: - 1- Lean state object associated with \c L - 2- Lua Registry associated with \c L -*/ -options get_global_options(lua_State * L); -/** - \brief Update the set of options associated with the given Lua State. - If \c L is associated with a Lean state object \c S, then we update the options of \c S. - Otherwise, we update the registry of \c L. -*/ -void set_global_options(lua_State * L, options const & o); -void open_options(lua_State * L); - void initialize_options(); void finalize_options(); } diff --git a/src/util/sexpr/sexpr.cpp b/src/util/sexpr/sexpr.cpp index a21662cce..9c4a0bf49 100644 --- a/src/util/sexpr/sexpr.cpp +++ b/src/util/sexpr/sexpr.cpp @@ -14,7 +14,6 @@ Author: Leonardo de Moura #include "util/buffer.h" #include "util/sstream.h" #include "util/object_serializer.h" -#include "util/luaref.h" #include "util/numerics/mpz.h" #include "util/numerics/mpq.h" #include "util/sexpr/sexpr.h" @@ -388,292 +387,6 @@ serializer & operator<<(serializer & s, sexpr const & n) { sexpr read_sexpr(deserializer & d) { return d.get_extension(g_sexpr_sd->m_d_extid).read(); } - -DECL_UDATA(sexpr) - -class lua_sexpr_atom : public sexpr_ext_atom { - luaref m_ref; -public: - lua_sexpr_atom(luaref && r):m_ref(r) {} - virtual ~lua_sexpr_atom() {} - virtual int cmp(sexpr_ext_atom const & e) const { - if (dynamic_cast(&e) == nullptr) { - return strcmp(typeid(*this).name(), typeid(e).name()); - } else { - luaref other = static_cast(e).m_ref; - lua_State * L = m_ref.get_state(); - if (other.get_state() != L) - throw exception("missing Lua objects from different Lua states"); - m_ref.push(); - other.push(); - int r; - if (equal(L, -2, -1)) - r = 0; - else if (lessthan(L, -2, -1)) - r = -1; - else - r = 0; - lua_pop(L, 2); - return r; - } - } - - virtual unsigned hash() const { - lua_State * L = m_ref.get_state(); - m_ref.push(); - lua_getfield(L, -1, "hash"); - if (lua_isnil(L, -1)) { - lua_pop(L, 2); - return 0; - } else { - m_ref.push(); - pcall(L, 1, 1, 0); - if (lua_isnumber(L, -1)) { - unsigned r = lua_tointeger(L, -1); - lua_pop(L, 1); - return r; - } else { - lua_pop(L, 1); - return 0; - } - } - } - - virtual int push_lua(lua_State * L) const { - if (m_ref.get_state() != L) - throw exception("using Lua object in a different Lua state"); - m_ref.push(); - return 1; - } - - virtual void display(std::ostream & out) const { - lua_State * L = m_ref.get_state(); - m_ref.push(); - out << tostring(L, -1); - lua_pop(L, 1); - } -}; - - -static int sexpr_tostring(lua_State * L) { - std::ostringstream out; - out << to_sexpr(L, 1); - return push_string(L, out.str().c_str()); -} - -static sexpr to_sexpr_elem(lua_State * L, int idx) { - if (lua_isnil(L, idx)) { - return sexpr(); - } else if (lua_isboolean(L, idx)) { - return sexpr(static_cast(lua_toboolean(L, idx))); - } else if (lua_isnumber(L, idx)) { - // Remark: we convert to integer by default - return sexpr(static_cast(lua_tointeger(L, idx))); - } else if (is_name(L, idx)) { - return sexpr(to_name(L, idx)); - } else if (is_sexpr(L, idx)) { - return *static_cast(lua_touserdata(L, idx)); - } else if (is_mpz(L, idx)) { - return sexpr(to_mpz(L, idx)); - } else if (is_mpq(L, idx)) { - return sexpr(to_mpq(L, idx)); - } else if (lua_isstring(L, idx)) { - std::string str = lua_tostring(L, idx); - return sexpr(str); - } else { - return sexpr(std::unique_ptr(new lua_sexpr_atom(luaref(L, idx)))); - } -} - -static int mk_sexpr(lua_State * L) { - sexpr r; - int nargs = lua_gettop(L); - if (nargs == 0) { - r = sexpr(); - } else { - int i = nargs; - r = to_sexpr_elem(L, i); - i--; - for (; i >= 1; i--) { - r = sexpr(to_sexpr_elem(L, i), r); - } - } - return push_sexpr(L, r); -} - -static int sexpr_eq(lua_State * L) { return push_boolean(L, to_sexpr(L, 1) == to_sexpr(L, 2)); } -static int sexpr_lt(lua_State * L) { return push_boolean(L, to_sexpr(L, 1) < to_sexpr(L, 2)); } - -#define SEXPR_PRED(P) static int sexpr_ ## P(lua_State * L) { check_num_args(L, 1); return push_boolean(L, P(to_sexpr(L, 1))); } - -SEXPR_PRED(is_nil) -SEXPR_PRED(is_cons) -SEXPR_PRED(is_list) -SEXPR_PRED(is_atom) -SEXPR_PRED(is_string) -SEXPR_PRED(is_bool) -SEXPR_PRED(is_int) -SEXPR_PRED(is_double) -SEXPR_PRED(is_name) -SEXPR_PRED(is_mpz) -SEXPR_PRED(is_mpq) -SEXPR_PRED(is_external) - -static int sexpr_length(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_list(e)) - throw exception("s-expression is not a list"); - return push_integer(L, length(e)); -} - -static int sexpr_head(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_cons(e)) - throw exception("s-expression is not a cons cell"); - return push_sexpr(L, head(e)); -} - -static int sexpr_tail(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_cons(e)) - throw exception("s-expression is not a cons cell"); - return push_sexpr(L, tail(e)); -} - -static int sexpr_to_bool(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_bool(e)) - throw exception("s-expression is not a Boolean"); - return push_boolean(L, to_bool(e)); -} - -static int sexpr_to_string(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_string(e)) - throw exception("s-expression is not a string"); - return push_string(L, to_string(e).c_str()); -} - -static int sexpr_to_int(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_int(e)) - throw exception("s-expression is not an integer"); - return push_integer(L, to_int(e)); -} - -static int sexpr_to_double(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_double(e)) - throw exception("s-expression is not a double"); - return push_number(L, to_double(e)); -} - -static int sexpr_to_name(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_name(e)) - throw exception("s-expression is not a name"); - return push_name(L, to_name(e)); -} - -static int sexpr_to_mpz(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_mpz(e)) - throw exception("s-expression is not a multi-precision integer"); - return push_mpz(L, to_mpz(e)); -} - -static int sexpr_to_mpq(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_mpq(e)) - throw exception("s-expression is not a multi-precision rational"); - return push_mpq(L, to_mpq(e)); -} - -static int sexpr_to_external(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - if (!is_external(e)) - throw exception("s-expression is not an external atom"); - return to_ext(e).push_lua(L); -} - -static int sexpr_get_kind(lua_State * L) { - return push_integer(L, static_cast(to_sexpr(L, 1).kind())); -} - -static int sexpr_fields(lua_State * L) { - sexpr const & e = to_sexpr(L, 1); - switch (e.kind()) { - case sexpr_kind::Nil: return 0; - case sexpr_kind::String: return sexpr_to_string(L); - case sexpr_kind::Bool: return sexpr_to_bool(L); - case sexpr_kind::Int: return sexpr_to_int(L); - case sexpr_kind::Double: return sexpr_to_double(L); - case sexpr_kind::Name: return sexpr_to_name(L); - case sexpr_kind::MPZ: return sexpr_to_mpz(L); - case sexpr_kind::MPQ: return sexpr_to_mpq(L); - case sexpr_kind::Ext: return sexpr_to_external(L); - case sexpr_kind::Cons: sexpr_head(L); sexpr_tail(L); return 2; - } - lean_unreachable(); // LCOV_EXCL_LINE - return 0; // LCOV_EXCL_LINE -} - -static const struct luaL_Reg sexpr_m[] = { - {"__gc", sexpr_gc}, // never throws - {"__tostring", safe_function}, - {"__eq", safe_function}, - {"__lt", safe_function}, - {"kind", safe_function}, - {"is_nil", safe_function}, - {"is_cons", safe_function}, - {"is_pair", safe_function}, - {"is_list", safe_function}, - {"is_atom", safe_function}, - {"is_string", safe_function}, - {"is_bool", safe_function}, - {"is_int", safe_function}, - {"is_double", safe_function}, - {"is_name", safe_function}, - {"is_mpz", safe_function}, - {"is_mpq", safe_function}, - {"is_external", safe_function}, - {"head", safe_function}, - {"tail", safe_function}, - {"length", safe_function}, - {"to_bool", safe_function}, - {"to_string", safe_function}, - {"to_int", safe_function}, - {"to_double", safe_function}, - {"to_name", safe_function}, - {"to_mpz", safe_function}, - {"to_mpq", safe_function}, - {"to_external", safe_function}, - {"fields", safe_function}, - {0, 0} -}; - -void open_sexpr(lua_State * L) { - luaL_newmetatable(L, sexpr_mt); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - setfuncs(L, sexpr_m, 0); - - SET_GLOBAL_FUN(mk_sexpr, "sexpr"); - SET_GLOBAL_FUN(sexpr_pred, "is_sexpr"); - - lua_newtable(L); - SET_ENUM("Nil", sexpr_kind::Nil); - SET_ENUM("String", sexpr_kind::String); - SET_ENUM("Bool", sexpr_kind::Bool); - SET_ENUM("Int", sexpr_kind::Int); - SET_ENUM("Double", sexpr_kind::Double); - SET_ENUM("Name", sexpr_kind::Name); - SET_ENUM("MPZ", sexpr_kind::MPZ); - SET_ENUM("MPQ", sexpr_kind::MPQ); - SET_ENUM("Cons", sexpr_kind::Cons); - SET_ENUM("Ext", sexpr_kind::Ext); - lua_setglobal(L, "sexpr_kind"); -} } void print(lean::sexpr const & n) { std::cout << n << "\n"; } diff --git a/src/util/sexpr/sexpr.h b/src/util/sexpr/sexpr.h index 88d925da9..c874b1515 100644 --- a/src/util/sexpr/sexpr.h +++ b/src/util/sexpr/sexpr.h @@ -10,7 +10,6 @@ Author: Leonardo de Moura #include #include #include -#include "util/lua.h" #include "util/serializer.h" namespace lean { @@ -106,7 +105,6 @@ public: virtual ~sexpr_ext_atom() {} virtual int cmp(sexpr_ext_atom const & e) const = 0; virtual unsigned hash() const = 0; - virtual int push_lua(lua_State * L) const = 0; virtual void display(std::ostream & out) const = 0; }; @@ -185,8 +183,6 @@ serializer & operator<<(serializer & s, sexpr const & a); sexpr read_sexpr(deserializer & d); inline deserializer & operator>>(deserializer & d, sexpr & a) { a = read_sexpr(d); return d; } -UDATA_DEFS(sexpr) -void open_sexpr(lua_State * L); void initialize_sexpr(); void finalize_sexpr(); } diff --git a/src/util/splay_map.h b/src/util/splay_map.h index e3465b9e6..9c59be676 100644 --- a/src/util/splay_map.h +++ b/src/util/splay_map.h @@ -6,7 +6,6 @@ Author: Leonardo de Moura */ #pragma once #include -#include "util/lua.h" #include "util/pair.h" #include "util/splay_tree.h" @@ -101,6 +100,4 @@ void for_each(splay_map const & m, F f) { "for_each: return type of f is not void"); return m.for_each(f); } - -void open_splay_map(lua_State * L); } diff --git a/src/util/thread_script_state.cpp b/src/util/thread_script_state.cpp deleted file mode 100644 index e58e3d7c5..000000000 --- a/src/util/thread_script_state.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* -Copyright (c) 2014 Microsoft Corporation. All rights reserved. -Released under Apache 2.0 license as described in the file LICENSE. - -Author: Leonardo de Moura -*/ -#include -#include -#include -#include -#include -#include "util/thread.h" -#include "util/pair.h" -#include "util/script_state.h" - -namespace lean { -struct script_state_manager { - mutex m_code_mutex; - std::vector> m_code; - mutex m_state_mutex; - std::vector m_states; - std::vector m_available_states; - script_state_manager() {} - ~script_state_manager() {} -}; - -static script_state_manager * g_manager = nullptr; - -void initialize_thread_script_state() { - g_manager = new script_state_manager(); -} - -void finalize_thread_script_state() { - delete g_manager; - g_manager = nullptr; -} - -static script_state_manager & get_script_state_manager() { - return *g_manager; -} - -static bool is_manager_alive() { return g_manager; } - -/** \brief Execute \c code in all states in the pool */ -void system_dostring(char const * code) { - script_state_manager & m = get_script_state_manager(); - { - // Execute code in all existing states - lock_guard lk(m.m_state_mutex); - for (auto & s : m.m_states) { - s.dostring(code); - } - } - { - // Save code for future states - lock_guard lk(m.m_code_mutex); - m.m_code.push_back(mk_pair(true, code)); - } -} - -/** \brief Import \c fname in all states in the pool */ -void system_import(char const * fname) { - script_state_manager & m = get_script_state_manager(); - { - // Import file in all existing states - lock_guard lk(m.m_state_mutex); - for (auto & s : m.m_states) { - s.import_explicit(fname); - } - } - { - // Save module for future states - lock_guard lk(m.m_code_mutex); - m.m_code.push_back(mk_pair(false, fname)); - } -} - -static script_state get_state() { - script_state_manager & m = get_script_state_manager(); - { - // Try to reuse existing state - lock_guard lk(m.m_state_mutex); - if (!m.m_available_states.empty()) { - script_state r(m.m_available_states.back()); - m.m_available_states.pop_back(); - return r; - } - } - - { - // Execute existing code in new state - lock_guard lk(m.m_code_mutex); - script_state r; - for (auto const & p : m.m_code) { - if (p.first) - r.dostring(p.second.c_str()); - else - r.import_explicit(p.second.c_str()); - } - { - // save new state in vector of all states - lock_guard lk(m.m_state_mutex); - m.m_states.push_back(r); - } - return r; - } -} - -static void recycle_state(script_state s) { - if (is_manager_alive()) { - script_state_manager & m = get_script_state_manager(); - lock_guard lk(m.m_state_mutex); - m.m_available_states.push_back(s); - } -} - -struct script_state_ref { - script_state m_state; - script_state_ref():m_state(get_state()) {} - ~script_state_ref() { recycle_state(m_state); } -}; - -LEAN_THREAD_PTR(bool, g_registered); -LEAN_THREAD_PTR(script_state_ref, g_thread_state_ref); - -static void finalize_registered(void * p) { - delete reinterpret_cast(p); - g_registered = nullptr; -} - -static void finalize_thread_state_ref(void * p) { - delete reinterpret_cast(p); - g_thread_state_ref = nullptr; -} - -script_state get_thread_script_state() { - if (!g_thread_state_ref) { - g_thread_state_ref = new script_state_ref(); - register_thread_finalizer(finalize_thread_state_ref, g_thread_state_ref); - } - if (!g_registered) { - g_registered = new bool(true); - register_thread_finalizer(finalize_registered, g_registered); - } - return g_thread_state_ref->m_state; -} -} diff --git a/src/util/thread_script_state.h b/src/util/thread_script_state.h deleted file mode 100644 index ea0fed35a..000000000 --- a/src/util/thread_script_state.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright (c) 2014 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/script_state.h" -namespace lean { -/** - \brief Execute the given piece of code in all global/system script_state objects. - - \remark The code fragments are saved. If a thread needs to create a new - script_state object, all code blocks are executed. - - \remark System code should be installed when Lean is started. -*/ -void system_dostring(char const * code); -/** - \brief Import the given module in all global/system script_state objects. - - \remark The module name is saved. If a thread needs to create a new - script_state object, all modules are imported. -*/ -void system_import(char const * fname); -/** - \brief Retrieve a script_state object for the current thread. - The thread has exclusive access until the thread is destroyed. - - \remark For performance reasons global script_state objects - are recycled. So, users should not delete/redefine functions - defined using #system_dostring. So, side-effects are discouraged. -*/ -script_state get_thread_script_state(); - -void enable_script_state_recycling(bool flag); -void initialize_thread_script_state(); -void finalize_thread_script_state(); -} diff --git a/tests/lean/natsucc.lean b/tests/lean/natsucc.lean deleted file mode 100644 index 26808c5ab..000000000 --- a/tests/lean/natsucc.lean +++ /dev/null @@ -1,14 +0,0 @@ -import data.nat -open nat - -theorem add_assoc (m n k : nat) : m + n + k = m + (n + k) := -nat.induction_on k -(show m + n + 0 = m + (n + 0), from rfl), -(take k, - assume IH : m + n + k = m + (n + k), - show m + n + mysucc k = m + (n + mysucc k), from - calc - m + n + mysucc k = mysucc (m + n + k) : rfl - ... = mysucc (m + (n + k)) : IH - ... = m + mysucc (n + k) : rfl - ... = m + (n + mysucc k) : rfl) diff --git a/tests/lean/natsucc.lean.expected.out b/tests/lean/natsucc.lean.expected.out deleted file mode 100644 index e37060733..000000000 --- a/tests/lean/natsucc.lean.expected.out +++ /dev/null @@ -1 +0,0 @@ -natsucc.lean:6:40: error: unexpected token, '.', command, Lua script, or end-of-file expected diff --git a/tests/lean/run/362.lean b/tests/lean/run/362.lean index c84fa8bfc..c91736dd6 100644 --- a/tests/lean/run/362.lean +++ b/tests/lean/run/362.lean @@ -5,10 +5,5 @@ begin intro a, assumption end -(* -local d = get_env():find("foo") -assert(#d:univ_params() == 1) -*) - set_option pp.universes true check foo diff --git a/tests/lean/run/class1.lean b/tests/lean/run/class1.lean index 16b5a3ebe..4874ec2ba 100644 --- a/tests/lean/run/class1.lean +++ b/tests/lean/run/class1.lean @@ -3,6 +3,4 @@ open prod inhabited definition H : inhabited (Prop × num × (num → num)) := _ -(* -print(get_env():find("H"):value()) -*) +print H diff --git a/tests/lean/run/class2.lean b/tests/lean/run/class2.lean index 9768fea99..f01ea53f2 100644 --- a/tests/lean/run/class2.lean +++ b/tests/lean/run/class2.lean @@ -4,6 +4,4 @@ open prod nonempty inhabited theorem H {A B : Type} (H1 : inhabited A) : inhabited (Prop × A × (B → num)) := _ reveal H -(* -print(get_env():find("H"):value()) -*) +print H diff --git a/tests/lean/run/class3.lean b/tests/lean/run/class3.lean index 2b3b0f807..1daa55a1e 100644 --- a/tests/lean/run/class3.lean +++ b/tests/lean/run/class3.lean @@ -12,6 +12,4 @@ section end reveal tst -(* -print(get_env():find("tst"):value()) -*) +print tst diff --git a/tests/lean/run/class8.lean b/tests/lean/run/class8.lean index 70efc9c92..31d445358 100644 --- a/tests/lean/run/class8.lean +++ b/tests/lean/run/class8.lean @@ -33,6 +33,4 @@ have h2 [visible] : inh C, from inh_exists H2, by exact _ reveal T1 -(* -print(get_env():find("T1"):value()) -*) +print T1 diff --git a/tests/lean/run/dfun_tst.lean b/tests/lean/run/dfun_tst.lean deleted file mode 100644 index b9e87cc80..000000000 --- a/tests/lean/run/dfun_tst.lean +++ /dev/null @@ -1,11 +0,0 @@ -import logic data.prod data.examples.vector -open prod nat inhabited vector - -theorem tst1 : inhabited (vector nat 2) - -theorem tst2 : inhabited (Prop × (Π n : nat, vector nat n)) - -reveal tst2 -(* -print(get_env():find("tst2"):value()) -*) diff --git a/tests/lean/run/hash.lean b/tests/lean/run/hash.lean deleted file mode 100644 index 0fb3fb789..000000000 --- a/tests/lean/run/hash.lean +++ /dev/null @@ -1,9 +0,0 @@ -definition id1 {A : Type} (a : A) : A := a -definition id2 (A : Type) (a : A) : A := a - -(* - local t1 = get_env():find("id1"):type() - local t2 = get_env():find("id2"):type() - assert(t1:hash() == t2:hash()) - assert(t1:hash_bi() ~= t2:hash_bi()) -*) diff --git a/tests/lean/run/match1.lean b/tests/lean/run/match1.lean deleted file mode 100644 index e1b8298ed..000000000 --- a/tests/lean/run/match1.lean +++ /dev/null @@ -1,30 +0,0 @@ -import data.nat.basic -open nat - -definition two1 : nat := 2 -definition two2 : nat := succ (succ (zero)) -constant f : nat → nat → nat - -(* -local tc = type_checker_with_hints(get_env()) -local plugin = whnf_match_plugin(tc) -function tst_match(p, t) - local r1, r2 = match(p, t, plugin) - assert(r1) - print("--------------") - for i = 1, #r1 do - print(" expr:#" .. i .. " := " .. tostring(r1[i])) - end - for i = 1, #r2 do - print(" lvl:#" .. i .. " := " .. tostring(r2[i])) - end -end - -local nat = Const("nat") -local f = Const("f") -local two1 = Const("two1") -local two2 = Const("two2") -local succ = Const({"nat", "succ"}) -local V0 = mk_idx_metavar(0, nat) -tst_match(f(succ(V0), two1), f(two2, two2)) -*) diff --git a/tests/lean/run/match2.lean b/tests/lean/run/match2.lean deleted file mode 100644 index 6569da0d9..000000000 --- a/tests/lean/run/match2.lean +++ /dev/null @@ -1,35 +0,0 @@ -import data.nat.basic -open nat - -definition two1 : nat := 2 -definition two2 : nat := succ (succ (zero)) -definition f (x : nat) (y : nat) := y -constant g : nat → nat → nat -constants a b : nat - -(* -local tc = type_checker_with_hints(get_env()) -local plugin = whnf_match_plugin(tc) -function tst_match(p, t) - local r1, r2 = match(p, t, plugin) - assert(r1) - print("--------------") - for i = 1, #r1 do - print(" expr:#" .. i .. " := " .. tostring(r1[i])) - end - for i = 1, #r2 do - print(" lvl:#" .. i .. " := " .. tostring(r2[i])) - end -end - -local nat = Const("nat") -local f = Const("f") -local g = Const("g") -local a = Const("a") -local b = Const("b") -local x = mk_idx_metavar(0, nat) -local p = g(x, f(x, a)) -local t = g(a, f(b, a)) -tst_match(p, t) -tst_match(f(x, x), f(a, b)) -*) diff --git a/tests/lean/run/n1.lean b/tests/lean/run/n1.lean deleted file mode 100644 index 7ec581b0e..000000000 --- a/tests/lean/run/n1.lean +++ /dev/null @@ -1,33 +0,0 @@ -constant A : Type.{1} -constant a : A -constant g : A → A -constant f : A → A → A - -(* -local f = Const("f") -local g = Const("g") -local comma = name(",") -function parse_pair() - local p1 = parser.parse_expr() - parser.check_token_next(comma, "invalid pair, ',' expected") - print("line: " .. tostring(parser.pos())) - local p2 = parser.parse_expr() - return f(p1, p2) -end - -local lbracket = name("[") -local rbracket = name("]") -function parse_bracket() - local l, c = parser.pos() - parser.check_token_next(lbracket, "'[' expected") - local r = parser.parse_expr() - parser.check_token_next(rbracket, "']' expected") - return parser.save_pos(g(r), l, c) -end -*) - - -notation `tst` A:(call parse_pair) := A -notation `simple` A:(call parse_bracket) `,` B:(call parse_bracket) := f A B -constant b : A -check g (tst (simple [b], [a]), a) diff --git a/tests/lean/run/n2.lean b/tests/lean/run/n2.lean deleted file mode 100644 index ef963e6e6..000000000 --- a/tests/lean/run/n2.lean +++ /dev/null @@ -1,26 +0,0 @@ -constant A : Type.{1} -constant a : A -constant g : A → A -constant f : A → A → A -precedence `|` : 0 - -(* -local f = Const("f") -local g = Const("g") -local bar = name("|") -local rcurly = name("}") -local lcurly = name("{") -function parse_set() - parser.check_token_next(lcurly, "'{' expected") - local s = parser.parse_binder() - parser.check_token_next(bar, "'|' expected") - local e = parser.parse_scoped_expr(s) - parser.check_token_next(rcurly, "'}' expected") - print(e) - return parser.abstract(s, g(e)) -end -*) - - -notation `set` A:(call parse_set) := A -check set { x : A | f x x } diff --git a/tests/lean/run/n4.lean b/tests/lean/run/n4.lean deleted file mode 100644 index 6e2e9fb04..000000000 --- a/tests/lean/run/n4.lean +++ /dev/null @@ -1,21 +0,0 @@ -prelude -definition Prop : Type.{1} := Type.{0} -section - variable N : Type.{1} - variables a b c : N - variable and : Prop → Prop → Prop - local infixr `∧`:35 := and - variable le : N → N → Prop - variable lt : N → N → Prop - precedence `≤`:50 - precedence `<`:50 - local infixl ≤ := le - local infixl < := lt - check a ≤ b - definition T : Prop := a ≤ b - check T -end -check T -(* -print(get_env():find("T"):value()) -*) diff --git a/tests/lean/run/reducible.lean b/tests/lean/run/reducible.lean deleted file mode 100644 index d87258157..000000000 --- a/tests/lean/run/reducible.lean +++ /dev/null @@ -1,35 +0,0 @@ -open nat -definition x [reducible] := (10:nat) -definition y := (20:nat) -definition z [irreducible] := (30:nat) -definition w := (40:nat) - - -(* - local env = get_env() - local x = Const("x") - local y = Const("y") - local z = Const("z") - local w = Const("w") - local val_x = env:find("x"):value() - local val_y = env:find("y"):value() - local val_z = env:find("z"):value() - local val_w = env:find("w"):value() - -- All definitions are not unfolded - local tc = opaque_type_checker(env) - assert(tc:whnf(x) == x) - assert(tc:whnf(y) == y) - assert(tc:whnf(z) == z) - assert(tc:whnf(w) == w) - -- Opaque and definitions marked as irreducibled are not unfolded - local tc = non_irreducible_type_checker(env) - assert(tc:whnf(z) == z) - -- Only definitions marked as reducible are unfolded - local tc = reducible_type_checker(env) - assert(tc:whnf(x) == val_x) - assert(tc:whnf(y) == y) - assert(tc:whnf(z) == z) - assert(tc:whnf(w) == w) -*) - -eval [whnf] x diff --git a/tests/lean/run/tactic21.lean b/tests/lean/run/tactic21.lean index c4f94cd49..a92696a14 100644 --- a/tests/lean/run/tactic21.lean +++ b/tests/lean/run/tactic21.lean @@ -8,6 +8,4 @@ theorem tst2 {A : Type} {a b c d : A} {p : A → A → Prop} (Ha : p a c) (H1 : := by apply exists.intro; apply and.intro; eassumption; eassumption reveal tst2 -(* -print(get_env():find("tst2"):value()) -*) +print tst2 diff --git a/tests/lean/run/trick.lean b/tests/lean/run/trick.lean deleted file mode 100644 index a04787bd7..000000000 --- a/tests/lean/run/trick.lean +++ /dev/null @@ -1,32 +0,0 @@ -import logic - -definition proj1 (x : num) (y : num) := x -definition One : num := 1 - -(* -local num = Const("num") -local m = mk_metavar("m", num) -local proj1 = Const("proj1") -local zero = Const({"num", "zero"}) -local one = Const("One") -local t1 = proj1(m, one) -local t2 = proj1(m, zero) - -function test_unify(env, m, cs, num_s) - local ss = unify(env, cs, name_generator()) - local n = 0 - for s in ss do - print("solution: " .. tostring(s:instantiate(m))) - n = n + 1 - end - if num_s ~= n then print("n: " .. n) end - assert(num_s == n) -end - -local env = get_env() - -print("===============") -test_unify(env, m, { mk_eq_cnstr(proj1(m, one), proj1(zero, zero)) }, 1) -print("===============") -test_unify(env, m, { mk_eq_cnstr(proj1(m, one), proj1(zero, m)) }, 1) -*) diff --git a/tests/lean/t1.lean b/tests/lean/t1.lean deleted file mode 100644 index a8290155d..000000000 --- a/tests/lean/t1.lean +++ /dev/null @@ -1,12 +0,0 @@ -(* -print("testing...") -local env = get_env() -env = add_decl(env, mk_constant_assumption("x", Prop)) -assert(env:find("x")) -set_env(env) -*) - -(* -local env = get_env() -print(env:find("x"):type()) -*) diff --git a/tests/lean/t1.lean.expected.out b/tests/lean/t1.lean.expected.out deleted file mode 100644 index 717d8562e..000000000 --- a/tests/lean/t1.lean.expected.out +++ /dev/null @@ -1,2 +0,0 @@ -testing... -Prop diff --git a/tests/lean/t4.lean b/tests/lean/t4.lean deleted file mode 100644 index 5f22069d1..000000000 --- a/tests/lean/t4.lean +++ /dev/null @@ -1,59 +0,0 @@ -prelude definition Prop : Type.{1} := Type.{0} -constant N : Type.{1} -check N -constant a : N -check a -check Prop → Prop -constant F.{l} : Type.{l} → Type.{l} -check F.{2} -universe u -check F.{u} -constant vec.{l} (A : Type.{l}) (n : N) : Type.{l} -constant f (a b : N) : N -constant len.{l} (A : Type.{l}) (n : N) (v : vec.{l} A n) : N -check f -check len.{1} -section - parameter A : Type - parameter B : Prop - hypothesis H : B - parameter {C : Type} - check B -> B - check A → A - check C -end -check A -- Error: A is part of the section - -constant R : Type → Type -check R.{1 0} - -check fun x y : N, x - -namespace tst - constant N : Type.{2} - constant M : Type.{2} - print raw N -- Two possible interpretations N and tst.N - print raw tst.N -- Only one interpretation -end tst -print raw N -- Only one interpretation -namespace foo - constant M : Type.{3} - print raw M -- Only one interpretation -end foo -check tst.M -check foo.M -namespace foo - check M -end foo -check M -- Error - -print "ok" -(* -local env = get_env() -print("Declarations:") -env:for_each_decl(function(d) print(d:name()) end) -print("-------------") -*) - -universe l_1 -constant T1 : Type -- T1 parameter is going to be called l_2 diff --git a/tests/lean/t4.lean.expected.out b/tests/lean/t4.lean.expected.out deleted file mode 100644 index 2641a5127..000000000 --- a/tests/lean/t4.lean.expected.out +++ /dev/null @@ -1,35 +0,0 @@ -N : Type -a : N -Prop → Prop : Type -F : Type → Type -F : Type → Type -f : N → N → N -len : Π (A : Type) (n : N), vec A n → N -B → B : Prop -A → A : Type -C : Type -t4.lean:25:6: error: unknown identifier 'A' -R : Type → Prop -λ (x y : N), x : N → N → N -N -N -N -M -tst.M : Type -foo.M : Type -M : Type -t4.lean:48:6: error: unknown identifier 'M' -ok -Declarations: -tst.M -tst.N -N -a -F -R -len -vec -f -Prop -foo.M -------------- diff --git a/tests/lean/t7.lean b/tests/lean/t7.lean deleted file mode 100644 index 3704d002b..000000000 --- a/tests/lean/t7.lean +++ /dev/null @@ -1,20 +0,0 @@ -prelude definition Prop : Type.{1} := Type.{0} -constant and : Prop → Prop → Prop -section - parameter {A : Type} -- Mark A as implicit parameter - parameter R : A → A → Prop - parameter B : Type - definition id (a : A) : A := a - private definition refl : Prop := ∀ (a : A), R a a - definition symm : Prop := ∀ (a b : A), R a b → R b a - definition trans : Prop := ∀ (a b c : A), R a b → R b c → R a c - definition equivalence : Prop := and (and refl symm) trans -end -check id.{2} -check trans.{1} -check symm.{1} -check equivalence.{1} -(* -local env = get_env() -print(env:find("equivalence"):value()) -*) diff --git a/tests/lean/t7.lean.expected.out b/tests/lean/t7.lean.expected.out deleted file mode 100644 index 0b4e495bc..000000000 --- a/tests/lean/t7.lean.expected.out +++ /dev/null @@ -1,6 +0,0 @@ -id : ?A → ?A -trans : (?A → ?A → Prop) → Prop -symm : (?A → ?A → Prop) → Prop -equivalence : (?A → ?A → Prop) → Prop -λ (A : Type) (R : A → A → Prop), - and (and (refl R) (symm R)) (trans R) diff --git a/tests/lean/varcomma.lean b/tests/lean/varcomma.lean deleted file mode 100644 index 9a333e49a..000000000 --- a/tests/lean/varcomma.lean +++ /dev/null @@ -1,15 +0,0 @@ -variable {A : Type}, -variables {A : Type}, -variables {A : Type} {B : Type} in - -variables {C : Type} {D : Type} - -(* - -*) - -theorem a : true := trivial - -(* - -*) diff --git a/tests/lean/varcomma.lean.expected.out b/tests/lean/varcomma.lean.expected.out deleted file mode 100644 index cc99870fd..000000000 --- a/tests/lean/varcomma.lean.expected.out +++ /dev/null @@ -1,3 +0,0 @@ -varcomma.lean:1:19: error: unexpected token, '.', command, Lua script, or end-of-file expected -varcomma.lean:2:20: error: unexpected token, '(', '{', '[', '⦃', '.', command, Lua script, or end-of-file expected -varcomma.lean:3:32: error: unexpected token, '(', '{', '[', '⦃', '.', command, Lua script, or end-of-file expected diff --git a/tests/lua/ac.lua b/tests/lua/ac.lua deleted file mode 100644 index adba24d30..000000000 --- a/tests/lua/ac.lua +++ /dev/null @@ -1,17 +0,0 @@ -local env = environment() -local l = param_univ("l") -local U_l = mk_sort(l) -local A = Local("A", U_l) -local R = Local("R", mk_arrow(A, A, Prop)) -local Acc = Const("Acc", {l}) -local x = Local("x", A) -local y = Local("y", A) -env = add_inductive(env, - "Acc", {l}, 2, Pi(A, R, x, Prop), - "Acc_intro", Pi(A, R, x, mk_arrow(Pi(y, mk_arrow(R(y, x), Acc(A, R, y))), Acc(A, R, x)))) - -function display_type(env, t) - print(tostring(t) .. " : " .. tostring(type_checker(env):infer(t))) -end - -display_type(env, Const({"Acc", "rec"}, {0, 1})) diff --git a/tests/lua/acc.lua b/tests/lua/acc.lua deleted file mode 100644 index 8af444ba4..000000000 --- a/tests/lua/acc.lua +++ /dev/null @@ -1,63 +0,0 @@ -function display_type(env, t) - print(tostring(t) .. " : " .. tostring(env:normalize(env:type_check(t)))) -end - -local env = environment() - -local l = param_univ("l") -local U_l = mk_sort(l) -local A = Local("A", U_l) -local R = Local("R", mk_arrow(A, A, Prop)) -local x = Local("x", A) -local y = Local("y", A) -local Acc = Const("Acc", {l}) - -env = add_inductive(env, - "Acc", {l}, 2, Pi(A, R, x, mk_sort(l+1)), - "Acc_intro", Pi(A, R, x, mk_arrow(Pi(y, mk_arrow(R(y, x), Acc(A, R, y))), Acc(A, R, x)))) - -env = env:add_universe("u") -env = env:add_universe("v") -local u = global_univ("u") -local v = global_univ("v") -display_type(env, Const({"Acc", "rec"}, {v, u})) - --- well_founded_induction_type : --- Pi (A : Type) --- (R : A -> A -> Prop) --- (R_is_wf : Pi (a : A), (Acc A R a)) --- (P : A -> Type) --- (H : Pi (x : A) (Hr : Pi (y : A) (a : R y x), (P y)), (P x)) --- (a : A), --- (P a) -local l1 = param_univ("l1") -local l2 = param_univ("l2") -local Acc = Const("Acc", {l1}) -local Acc_intro = Const("Acc_intro", {l1}) -local Acc_rec = Const({"Acc", "rec"}, {l2, l1}) -local A = Local("A", mk_sort(l1)) -local R = Local("R", mk_arrow(A, A, Prop)) -local x = Local("x", A) -local y = Local("y", A) -local a = Local("a", A) -local P = Local("P", mk_arrow(A, mk_sort(l2))) -local Hr = Local("Hr", Pi(y, mk_arrow(R(y, x), P(y)))) -local H = Local("H", Pi(x, Hr, P(x))) -local HR = Local("HR", R(y, x)) -local HRa = Local("HRa", R(y, a)) -local arg = Local("arg", Pi(y, HR, Acc(A, R, y))) -local H_arg = Local("H_arg", Pi(y, HR, P(y))) -local d = Local("d", Acc(A, R, x)) -local Hwf = Local("R_is_wf", Pi(a, Acc(A, R, a))) -local wfi_th_type = Pi(A, R, Hwf, P, H, a, P(a)) -print(wfi_th_type) -type_checker(env):check(wfi_th_type, {l1, l2}) -local wfi_th_val = Fun(A, R, Hwf, P, H, a, Acc_rec(A, R, - Fun(x, d, P(x)), -- C - Fun(x, arg, H_arg, H(x, H_arg)), -- e_1 - a, - Acc_intro(A, R, a, Fun(y, HRa, Hwf(y))) -)) -print(env:normalize(type_checker(env):check(wfi_th_val, {l1, l2}))) -env = add_decl(env, mk_definition("well_founded_induction_type", {l1, l2}, wfi_th_type, wfi_th_val)) -display_type(env, Const("well_founded_induction_type", {1,1})) diff --git a/tests/lua/alias1.lua b/tests/lua/alias1.lua deleted file mode 100644 index 466479745..000000000 --- a/tests/lua/alias1.lua +++ /dev/null @@ -1,50 +0,0 @@ -local env = environment() - -local env = environment() -local l = mk_param_univ("l") -local U_l = mk_sort(l) -local U_l1 = mk_sort(max_univ(l, 1)) -- Make sure U_l1 is not Prop -local nat = Const({"nat", "nat"}) -local vec_l = Const({"vec", "vec"}, {l}) -- vec.{l} -local zero = Const({"nat", "zero"}) -local succ = Const({"nat", "succ"}) -local one = succ(zero) -local list_l = Const({"list", "list"}, {l}) -- list.{l} - -env = add_inductive(env, - name("nat", "nat"), Type, - name("nat", "zero"), nat, - name("nat", "succ"), mk_arrow(nat, nat)) - -env:for_each_decl(function(d) print(d:name()) end) -env = add_aliases(env, "nat", "natural") -assert(get_expr_aliases(env, {"natural", "zero"}):head() == name("nat", "zero")) -assert(get_expr_aliases(env, {"natural", "nat"}):head() == name("nat", "nat")) -assert(is_expr_aliased(env, {"nat", "nat"}) == name("natural", "nat")) - -local A = Local("A", U_l) - -env = add_inductive(env, - name("list", "list"), {l}, 1, Pi(A, U_l1), - name("list", "nil"), Pi(A, list_l(A)), - name("list", "cons"), Pi(A, mk_arrow(A, list_l(A), list_l(A)))) - -env = add_aliases(env, "list", "lst") -print(not get_expr_aliases(env, {"lst", "list", "rec"}):is_nil()) -env = add_aliases(env, "list") -print(get_expr_aliases(env, {"list", "rec"}):head()) -assert(not get_expr_aliases(env, {"list", "rec"}):is_nil()) -assert(not get_expr_aliases(env, {"lst", "list", "rec"}):is_nil()) - -env = add_aliases(env, "list", "l") -print(get_expr_aliases(env, {"l", "list"}):head()) -print(get_expr_aliases(env, {"l", "cons"}):head()) - -local A = Local("A", mk_sort(1)) -local R = Local("R", mk_arrow(A, A, Prop)) -local a = Local("a", A) -local b = Local("b", A) - -env = add_expr_alias(env, "z", name("nat", "zero")) -assert(get_expr_aliases(env, "z"):head() == name("nat", "zero")) -assert(get_expr_aliases(env, "zz"):is_nil()) diff --git a/tests/lua/alias2.lua b/tests/lua/alias2.lua deleted file mode 100644 index 497b5a1a0..000000000 --- a/tests/lua/alias2.lua +++ /dev/null @@ -1,8 +0,0 @@ -local env = environment() - -local env = environment() -local l = mk_param_univ("l") -local u = mk_global_univ("u") -env = add_level_alias(env, "m", "l") -env = add_level_alias(env, "l1", "l") -assert(is_level_aliased(env, "l") == name("l1")) diff --git a/tests/lua/big.lua b/tests/lua/big.lua deleted file mode 100644 index 375607333..000000000 --- a/tests/lua/big.lua +++ /dev/null @@ -1,23 +0,0 @@ -f = Const("f") -a = Const("a") -b = Const("b") -nodes = {} - -function mk_big(num) - local r - if num == 0 then - r = f(a, b) - else - r = f(mk_big(num-1), mk_big(num-1)) - end - return r -end - -function size(e) - local r = 0 - e:for_each(function(e, o) assert(e:is_app() or e:is_constant()); r = r + 1 end) - return r -end - -local F = mk_big(14) -print(size(F)) diff --git a/tests/lua/choice.lua b/tests/lua/choice.lua deleted file mode 100644 index 803fe31ae..000000000 --- a/tests/lua/choice.lua +++ /dev/null @@ -1,14 +0,0 @@ -local f = Const("f") -local a = Const("a") -local c = mk_choice(f(a), a, f(f(a))) -print(c) -assert(is_choice(c)) -assert(get_num_choices(c) == 3) -assert(get_choice(c, 0) == f(a)) -assert(get_choice(c, 1) == a) -assert(get_choice(c, 2) == f(f(a))) -assert(mk_choice(f(a)) == f(a)) -check_error(function() mk_choice() end) -check_error(function() get_num_choices(f(a)) end) -check_error(function() get_choice(f(a)) end) -check_error(function() get_choice(c, 3) end) diff --git a/tests/lua/choice2.lua b/tests/lua/choice2.lua deleted file mode 100644 index 138483e5f..000000000 --- a/tests/lua/choice2.lua +++ /dev/null @@ -1,6 +0,0 @@ -local a = Local("a", Prop) -local b = Local("b", Prop) -local c = mk_choice(a, b) -print(c) -local env = environment() -check_error(function() env:infer_type(c) end) diff --git a/tests/lua/cnstr1.lua b/tests/lua/cnstr1.lua deleted file mode 100644 index 5591d33a5..000000000 --- a/tests/lua/cnstr1.lua +++ /dev/null @@ -1,16 +0,0 @@ -local a = Const("a") -local f = Const("f") -local m = mk_metavar("m", Prop) -local j = justification("type match") -local c = mk_eq_cnstr(f(a), m, j) -assert(c:is_eq()) -assert(not c:is_level_eq()) -assert(c:lhs() == f(a)) -assert(c:rhs() == m) -assert(c:justification():is_eqp(j)) -print(c) -local c3 = mk_level_eq_cnstr(mk_level_zero(), mk_level_one(), j) -assert(c3:is_level_eq()) -print(c3) -assert(c:is_eqp(c)) -assert(not c:is_eqp(mk_eq_cnstr(f(a), m, j))) diff --git a/tests/lua/def1.lua b/tests/lua/def1.lua deleted file mode 100644 index ec50c074c..000000000 --- a/tests/lua/def1.lua +++ /dev/null @@ -1,67 +0,0 @@ -local b = mk_constant_assumption("bit", Type) -local l1 = mk_param_univ("l1") -local l2 = mk_param_univ("l2") -local p = mk_constant_assumption("tst", {"l1", "l2"}, mk_arrow(mk_sort(l1), mk_sort(l2))) -assert(p:is_constant_assumption()) -assert(not p:is_axiom()) -assert(p:name() == name("tst")) -print(mk_arrow(mk_sort(l1), mk_sort(l2))) -assert(p:type() == mk_arrow(mk_sort(l1), mk_sort(l2))) -assert(#(p:univ_params()) == 2) -assert(p:univ_params():head() == name("l1")) -assert(p:univ_params():tail():head() == name("l2")) -local ax = mk_axiom("ax", {"l1", "l2"}, mk_arrow(mk_sort(l1), mk_sort(l2))) -assert(ax:is_constant_assumption()) -assert(ax:is_axiom()) -assert(ax:name() == name("ax")) -assert(not pcall(function() print(ax:value()) end)) -local th = mk_theorem("t1", {"l1", "l2"}, mk_arrow(mk_sort(l1), mk_sort(l2)), mk_lambda("x", mk_sort(l1), Var(0))) -assert(th:is_theorem()) -assert(th:is_definition()) -assert(th:value() == mk_lambda("x", mk_sort(l1), Var(0))) -print(th:value()) -local A = Const("A") -local B = Const("B") -local th2 = mk_theorem("t2", A, B) -assert(th2:type() == A) -assert(th2:value() == B) -assert(th2:name() == name("t2")) -local d = mk_definition("d1", A, B) -assert(d:is_definition()) -assert(not d:is_theorem()) -assert(d:height() == 0) -assert(d:use_conv_opt()) -assert(d:name() == name("d1")) -assert(d:value() == B) -local d2 = mk_definition("d2", A, B, nil) -local d3 = mk_definition("d3", A, B, {height=100, use_conv_opt=false}) -assert(d3:height() == 100) -assert(not d3:use_conv_opt()) -local env = bare_environment() -local d4 = mk_definition(env, "bool", Type, Prop) -assert(d4:height() == 1) -local d5 = mk_definition(env, "bool", Type, Prop, {height=100, use_conv_opt=true}) -assert(d5:height() == 1) -assert(d5:use_conv_opt()) -local d6 = mk_definition("d6", {"l1", "l2"}, A, B, {height=5}) -assert(d6:type() == A) -assert(d6:value() == B) -assert(#(d6:univ_params()) == 2) -assert(d6:univ_params():head() == name("l1")) -assert(d6:univ_params():tail():head() == name("l2")) -assert(d6:height() == 5) -local d7 = mk_definition(env, "d7", {"l1", "l2"}, A, B, {height=5}) -assert(d7:type() == A) -assert(d7:value() == B) -assert(d7:height() == 1) -assert(#(d7:univ_params()) == 2) -assert(d7:univ_params():head() == name("l1")) -assert(d7:univ_params():tail():head() == name("l2")) -print("done") -assert(not pcall(function() mk_theorem("t1", {max_univ("l1", "l2")}, mk_arrow(mk_sort(l1), mk_sort(l2)), mk_lambda("x", mk_sort(l1), Var(0))) end)) -local l1 = global_univ("l1") -mk_theorem("t1", {l1, "l2"}, mk_arrow(mk_sort(l1), mk_sort(l2)), mk_lambda("x", mk_sort(l1), Var(0))) - -assert(not pcall(function() mk_definition("bit", Type) end)) -local env = environment(10) -assert(not pcall(function() mk_definition(env, "bit", Type) end)) diff --git a/tests/lua/env1.lua b/tests/lua/env1.lua deleted file mode 100644 index 18add0399..000000000 --- a/tests/lua/env1.lua +++ /dev/null @@ -1,9 +0,0 @@ -local env = bare_environment() -assert(is_environment(env)) -assert(not env:is_universe("U")) -local env2 = env:add_universe("U") -assert(not env:is_universe("U")) -assert(env2:is_universe("U")) -assert(env:eta()) -assert(env:prop_proof_irrel()) -assert(env:impredicative()) diff --git a/tests/lua/env11.lua b/tests/lua/env11.lua deleted file mode 100644 index 1d737043d..000000000 --- a/tests/lua/env11.lua +++ /dev/null @@ -1,36 +0,0 @@ -local A = Const("A") -local B = Const("B") -local env = environment() -local env1 = add_decl(env, mk_constant_assumption("A", Prop)) -env1 = add_decl(env1, mk_constant_assumption("B", Prop)) -env1 = add_decl(env1, mk_axiom("H", B)) -local c1 = check(env1, mk_axiom("H1", A)) -local c2 = check(env1, mk_axiom("H2", A)) -local env1b = env1:add(c1) -local env2 = env1b:add(c2) -local c3 = check(env2, mk_theorem("H3", A, Const("H1"))) -function expected_error(f) - ok, ex = pcall(f) - assert(not ok) - print("expected error: " .. ex:what()) -end - -expected_error(function() env1:add(c3) end) -expected_error(function() env2:add(c1) end) -env3 = env2:add_universe("u") -expected_error(function() env3:add_universe("u") end) -expected_error(function() check(env2, mk_theorem("H1", A, Const("H1"))) end) -local c4 = check(env1b, mk_theorem("H2", A, Const("H1"))) -expected_error(function() env3:add(c4) end) -env3 = env3:replace(c4) -assert(env2:find("H2"):is_axiom()) -assert(not env3:find("H2"):is_axiom()) -assert(env3:find("H2"):is_theorem()) -local c5 = check(env1b, mk_theorem("H5", A, Const("H1"))) -expected_error(function() env3:replace(c5) end) -local c6 = check(env, mk_definition("A", Type, Prop)) -expected_error(function() env3:replace(c6) end) -local c7 = check(env1b, mk_definition("H2", A, Const("H1"))) -expected_error(function() env2:replace(c7) end) -local c8 = check(env1b, mk_theorem("H2", B, Const("H"))) -expected_error(function() env2:replace(c8) end) diff --git a/tests/lua/env2.lua b/tests/lua/env2.lua deleted file mode 100644 index e5a323bfd..000000000 --- a/tests/lua/env2.lua +++ /dev/null @@ -1,9 +0,0 @@ -assert(not bare_environment({eta=false}):eta()) -assert(bare_environment({eta=true}):eta()) -assert(not bare_environment({prop_proof_irrel=false}):prop_proof_irrel()) -assert(bare_environment({prop_proof_irrel=true}):prop_proof_irrel()) -assert(bare_environment({impredicative=true}):impredicative()) -assert(not bare_environment({impredicative=false}):impredicative()) -assert(bare_environment({trust_lvl=10}):trust_lvl() == 10) -assert(bare_environment({trust_lvl=0}):trust_lvl() == 0) -assert(bare_environment():trust_lvl() == 0) diff --git a/tests/lua/env3.lua b/tests/lua/env3.lua deleted file mode 100644 index 60a1257db..000000000 --- a/tests/lua/env3.lua +++ /dev/null @@ -1,20 +0,0 @@ -function init(env) - env = add_decl(env, mk_constant_assumption("A", Prop)) - env = add_decl(env, mk_constant_assumption("And", mk_arrow(Prop, mk_arrow(Prop, Prop)))) - env = add_decl(env, mk_axiom("p", Const("A"))) - env = add_decl(env, mk_axiom("q", Const("A"))) - return env -end -local And = Const("And") -local p = Const("p") -local q = Const("q") - -local env = init(bare_environment()) -local t = type_checker(env) -assert(t:is_def_eq(p, q)) -assert(t:is_def_eq(And(p, q), And(q, p))) - -env = init(bare_environment({prop_proof_irrel=false})) -t = type_checker(env) -assert(not t:is_def_eq(p, q)) -assert(not t:is_def_eq(And(p, q), And(q, p))) diff --git a/tests/lua/env4.lua b/tests/lua/env4.lua deleted file mode 100644 index 09c3d4ec5..000000000 --- a/tests/lua/env4.lua +++ /dev/null @@ -1,6 +0,0 @@ -local env = bare_environment() -env = add_decl(env, mk_constant_assumption("A", Prop)) -local c1 = type_check(env, mk_axiom("p", Const("A"))) -local c2 = type_check(env, mk_axiom("q", Const("A"))) -env = env:add(c1) -env = env:add(c2) diff --git a/tests/lua/env5.lua b/tests/lua/env5.lua deleted file mode 100644 index ed97a873e..000000000 --- a/tests/lua/env5.lua +++ /dev/null @@ -1,57 +0,0 @@ -local env = bare_environment() -local l_name = name("l") -local l = mk_param_univ(l_name) -local U_l = mk_sort(l) -local x = Const("x") -local A = Local("A", U_l) -local x = Local("x", A) -local A2A = mk_arrow(A, A) -local id_ty = Pi(A, mk_arrow(A, A)) -local id_def = Fun(A, Fun(x, x)) -env = add_decl(env, mk_definition(env, "id", {l_name}, id_ty, id_def, {opaque=false})) -local ok, ex = pcall(function() - env = add_decl(env, mk_definition(env, "id2", {"l2"}, id_ty, id_def, {opaque=false})) - end -) -assert(not ok) -print(ex:what()) -local tc = type_checker(env) -local ok, ex = pcall(function() - local id = Const("id") - tc:check(id) - end -) -assert(not ok) -print(ex:what()) -local id_1 = Const("id", {mk_level_one()}) -print(tc:check(id_1)) -assert(not pcall(function() - id_u = Const("id", {mk_global_univ("u")}) - print(tc:check(id_u)) - end -)) -assert(not pcall(function() - id_1_1 = Const("id", {mk_level_one(), mk_level_one()}) - print(tc:check(id_1_1)) - end -)) -local env2 = env:add_universe("u") -assert(env2:is_descendant(env)) -assert(not env:is_descendant(env2)) -local tc2 = type_checker(env2) -id_u = Const("id", {mk_global_univ("u")}) -print(tc2:check(id_u)) -local tmp = tc2:check(id_u) -print(tc2:check(tmp)) -local tmp1 = tc2:check(id_u) -local tmp2 = tc2:check(tmp1) -print(tc2:check(tmp2)) -env2 = add_decl(env2, mk_constant_assumption("a", Type)) -local tc2 = type_checker(env2) -local a = Const("a") -local id_2 = Const("id", {mk_level_succ(mk_level_one())}) -print(tc2:check(id_2(Type, a))) -assert(tc2:check(id_2(Type, a)) == Type) -assert(not pcall(function() print(tc2:check(id_1(Type, a))) end)) -assert(tc2:whnf(id_2(Type, a)) == a) -assert(tc2:whnf(id_2(Type, id_2(Type, a))) == a) diff --git a/tests/lua/env6.lua b/tests/lua/env6.lua deleted file mode 100644 index d03a551e5..000000000 --- a/tests/lua/env6.lua +++ /dev/null @@ -1,21 +0,0 @@ -local env = bare_environment() -env = add_decl(env, mk_constant_assumption("A", Prop)) -local A = Const("A") -local x = Local("x", Prop) -env = add_decl(env, mk_axiom("magic", Pi(x, x))) -local saved_env = env -env = add_decl(env, mk_axiom("Ax", A)) -env = add_decl(env, mk_definition("T1", A, Const("Ax"))) --- The check mk_theorem("Ax", A, Const("T1")) failes because env --- contains the axiom named Ax. --- So, we cannot transform Ax into a theorem that depends on itself. --- (This is good) -assert(not pcall(function() env:replace(check(env, mk_theorem("Ax", A, Const("T1")))) end)) -assert(env:find("Ax"):is_axiom()) -local magic = Const("magic") --- Replace axiom Ax with the theorem Ax that is checked in the old --- environment saved_env. Everything works because env is a descendant --- of saved_env -env = env:replace(check(saved_env, mk_theorem("Ax", A, magic(A)))) -assert(not env:find("Ax"):is_axiom()) -assert(env:find("Ax"):is_theorem()) diff --git a/tests/lua/env7.lua b/tests/lua/env7.lua deleted file mode 100644 index dd62a9a91..000000000 --- a/tests/lua/env7.lua +++ /dev/null @@ -1,9 +0,0 @@ -local env1 = bare_environment() -local env2 = add_decl(env1, mk_constant_assumption("A", Type)) -assert(env2:is_descendant(env1)) -assert(env2:is_descendant(env2)) -assert(not env1:is_descendant(env2)) -local env3 = env2:forget() -assert(not env3:is_descendant(env1)) -assert(not env3:is_descendant(env2)) -assert(env3:is_descendant(env3)) diff --git a/tests/lua/env8.lua b/tests/lua/env8.lua deleted file mode 100644 index 36be8220c..000000000 --- a/tests/lua/env8.lua +++ /dev/null @@ -1,13 +0,0 @@ -local env = environment() -local nat = Const("nat") - -env = add_inductive(env, - "nat", Type, - "zero", nat, - "succ", mk_arrow(nat, nat)) - --- Display all declarations in the environment -env:for_each_decl(function(d) - print(tostring(d:name()) .. " : " .. tostring(d:type())) - end -) diff --git a/tests/lua/env9.lua b/tests/lua/env9.lua deleted file mode 100644 index 7bcababb0..000000000 --- a/tests/lua/env9.lua +++ /dev/null @@ -1,6 +0,0 @@ -local env = bare_environment() --- Trust level is set to 0 by default. Then, we must type check a --- definition, before adding it to the environment -assert(not pcall(function() env:add(mk_constant_assumption("A", Prop)) end)) --- The function check produces a "certified declaration". -env:add(check(env, mk_constant_assumption("A", Prop))) diff --git a/tests/lua/eta.lua b/tests/lua/eta.lua deleted file mode 100644 index d5d04fd3d..000000000 --- a/tests/lua/eta.lua +++ /dev/null @@ -1,16 +0,0 @@ -local env = bare_environment() -env = add_decl(env, mk_constant_assumption("f", mk_arrow(Prop, mk_arrow(Prop, Prop)))) -local f = Const("f") -local x = Local("x", Prop) -local y = Local("y", Prop) -local z = Local("z", Prop) -local tc = type_checker(env) -print(tc:whnf(Fun(x, f(x)))) -print(tc:whnf(Fun(x, y, f(x, y)))) -print(tc:whnf(Fun(x, y, f(Const("a"), y)))) -print(tc:whnf(Fun(z, x, y, f(z, y)))) -assert(tc:is_def_eq(f, Fun(x, f(x)))) -assert(tc:is_def_eq(f, Fun(x, y, f(x, y)))) -local A = Const("A") -local a = Local("a", A) -assert(tc:is_def_eq(Fun(a, a)(f), Fun(x, y, f(x, y)))) diff --git a/tests/lua/explicit.lua b/tests/lua/explicit.lua deleted file mode 100644 index 671458b01..000000000 --- a/tests/lua/explicit.lua +++ /dev/null @@ -1,7 +0,0 @@ -local f = Const("f") -local a = Const("a") -print(mk_explicit(f)(a)) -assert(is_explicit(mk_explicit(f))) -assert(not is_explicit(f)) -assert(get_explicit_arg(mk_explicit(f)) == f) -check_error(function() get_explicit_arg(f) end) diff --git a/tests/lua/expr1.lua b/tests/lua/expr1.lua deleted file mode 100644 index d4d550ff6..000000000 --- a/tests/lua/expr1.lua +++ /dev/null @@ -1,7 +0,0 @@ -assert(not binder_info():is_implicit()) -assert(not binder_info(false, false):is_implicit()) -assert(binder_info(true):is_implicit()) -assert(binder_info(true, true):is_implicit()) -assert(binder_info():is_contextual()) -assert(not binder_info(true, false):is_contextual()) -assert(binder_info(false, true):is_contextual()) diff --git a/tests/lua/expr10.lua b/tests/lua/expr10.lua deleted file mode 100644 index 4e6879bf8..000000000 --- a/tests/lua/expr10.lua +++ /dev/null @@ -1,8 +0,0 @@ -local env = environment() -local f = Local("f", mk_arrow(Prop, Prop, Prop)) -local a = Local("a", Prop) -local b = Local("b", Prop) -local x = Local("x", Prop) -local t = Fun(f, a, b, f(Fun(x, x)(b), a)) -print(env:normalize(t)) -assert(env:normalize(t) == Fun(f, a, b, f(b, a))) diff --git a/tests/lua/expr11.lua b/tests/lua/expr11.lua deleted file mode 100644 index 6872dff76..000000000 --- a/tests/lua/expr11.lua +++ /dev/null @@ -1,6 +0,0 @@ -local a = Const("a") -local f = Const("f") -local x = Var(0) -assert(not f(a):has_free_var(0)) -assert(f(a, x):has_free_var(0)) -assert(f(a, Var(2)):lower_free_vars(2) == f(a, Var(0))) diff --git a/tests/lua/expr2.lua b/tests/lua/expr2.lua deleted file mode 100644 index 2ca54ebfc..000000000 --- a/tests/lua/expr2.lua +++ /dev/null @@ -1,27 +0,0 @@ -local f = Const("f") -local a = Const("a") -local b = Const("b") -local x = Var(0) -assert(f(a, a):is_lt(f(a, b))) -assert(Const("a"):is_lt(Const("b"))) -assert(Var(0):is_lt(Const("b"))) -assert(name("a") < name("b")) -assert(not (Prop:is_lt(Prop))) -assert(not (Prop < Prop)) -assert(mk_metavar("a", Prop):is_lt(mk_metavar("b", Prop))) -assert(not mk_metavar("a", Prop):is_lt(mk_metavar("a", Prop))) -assert(mk_metavar("a", Prop):is_lt(mk_metavar("a", Type))) -assert(mk_local("a", Prop):is_lt(mk_local("b", Prop))) -assert(not mk_local("a", Prop):is_lt(mk_local("a", Prop))) -assert(Prop:is_lt(Const("a"))) -local a = Local("a", Prop) -local a1 = Local("a1", Type) -assert(Fun(a, a):is_lt(Fun(a1, a1))) -assert(Fun(a, a):is_lt(Fun(a, Var(2)))) -assert(Pi(a, a):is_lt(Pi(a1, a1))) -assert(Pi(a, a):is_lt(Pi(a, Var(2)))) -assert(Var(0) < Var(1)) -print(Const("a", {mk_level_one(), mk_level_zero()})) -assert(Const("a", {mk_level_one()}):is_lt(Const("a", {mk_level_one(), mk_level_zero()}))) -assert(Const("a", {mk_level_zero(), mk_level_one()}):is_lt(Const("a", {mk_level_one()}))) -assert(not Const("a", {mk_level_zero(), mk_level_one()}):is_lt(Const("a", {mk_level_zero(), mk_level_one()}))) diff --git a/tests/lua/expr3.lua b/tests/lua/expr3.lua deleted file mode 100644 index 3b6dbd4ed..000000000 --- a/tests/lua/expr3.lua +++ /dev/null @@ -1,97 +0,0 @@ -local b1 = binder_info() -assert(not b1:is_implicit()) - -local f = Const("f") -local a = Const("a") -local t = f(a) -assert(t:fn() == f) -assert(t:arg() == a) -assert(not pcall(function() f:fn() end)) - -local a1 = Local("a", Prop) -local pi1 = Pi(a1, Type) -assert(pi1:is_pi()) -assert(not pcall(function() f:binding_name() end)) -local pi2 = mk_pi("a", Prop, Type, binder_info(true, true)) -local pi3 = mk_pi("a", Prop, Type) -assert(pi2:binding_info():is_implicit()) -assert(not pi3:binding_info():is_implicit()) - -local l1 = mk_lambda("a", Prop, Var(0)) -local l2 = mk_lambda("a", Prop, Var(0), binder_info(true, false)) -assert(not l1:binding_info():is_implicit()) -assert(l2:binding_info():is_implicit()) - - -local a = Local("a", Prop) -local b = Local("b", Prop) -local pi3 = Pi(a, b, a) -print(pi3) -assert(not pcall(function() Pi(a) end)) -local pi4 = Pi(a, b, a) -print(pi4) -assert(pi4:binding_name() == name("a")) -assert(pi4:binding_domain() == Prop) -assert(pi4:binding_body():is_pi()) - - -assert(f:kind() == expr_kind.Constant) -assert(pi3:kind() == expr_kind.Pi) - -assert(f:is_constant()) -assert(Var(0):is_var()) -assert(f(a):is_app()) -assert(l1:is_lambda()) -assert(pi3:is_pi()) -assert(l1:is_binding()) -assert(pi3:is_binding()) -assert(mk_metavar("m", Prop):is_metavar()) -assert(mk_local("m", Prop):is_local()) -assert(mk_metavar("m", Prop):is_mlocal()) -assert(mk_local("m", Prop):is_mlocal()) -assert(mk_metavar("m", Prop):is_meta()) -assert(mk_metavar("m", Prop)(a):is_meta()) -assert(f(mk_metavar("m", Prop)):has_metavar()) -assert(f(mk_local("l", Prop)):has_local()) -assert(not f(mk_metavar("m", Prop)):has_local()) -assert(not f(mk_local("l", Prop)):has_metavar()) -assert(f(mk_sort(mk_param_univ("l"))):has_param_univ()) -assert(f(Var(0)):has_free_vars()) -assert(not f(Var(0)):closed()) -assert(f(a):closed()) - -assert(Var(0):data() == 0) -assert(Const("a"):data() == name("a")) -assert(mk_sort(mk_param_univ("l")):data() == mk_param_univ("l")) -local f1, a1 = f(a):data() -assert(f1 == f) -assert(a1 == a) -local m1, t1 = mk_metavar("a", Prop):data() -assert(m1 == name("a")) -assert(t1 == Prop) -local m1, t1 = mk_local("a", Prop):data() -assert(m1 == name("a")) -assert(t1 == Prop) -local a1, t, b1, bi = mk_pi("a", Prop, Var(0), binder_info(true)):data() -assert(a1 == name("a")) -assert(t == Prop) -assert(b1 == Var(0)) -assert(bi:is_implicit()) -assert(f:is_constant()) -f(f(a)):for_each(function (e, o) print(tostring(e)); return true; end) -assert(f(Var(0)):lift_free_vars(1) == f(Var(1))) -assert(f(Var(1)):lift_free_vars(1, 1) == f(Var(2))) -assert(f(Var(1)):lift_free_vars(2, 1) == f(Var(1))) -assert(f(Var(1)):lower_free_vars(1, 1) == f(Var(0))) -assert(f(Var(1)):lower_free_vars(4, 1) == f(Var(1))) -assert(f(Var(0), Var(1)):instantiate(a) == f(a, Var(0))) -assert(f(Var(0), Var(1)):instantiate({a, b}) == f(a, b)) -assert(f(a, b):abstract(a) == f(Var(0), b)) -assert(f(a, b):abstract({a, b}) == f(Var(1), Var(0))) - -assert(a:occurs(f(a))) -enable_expr_caching(false) -assert(not f(a):is_eqp(f(a))) -assert(f(a):arg():is_eqp(a)) -assert(f(a):weight() == 3) -print(f(a):hash()) diff --git a/tests/lua/expr4.lua b/tests/lua/expr4.lua deleted file mode 100644 index 712ebce3b..000000000 --- a/tests/lua/expr4.lua +++ /dev/null @@ -1,8 +0,0 @@ -local vec = Const("vec") -local a = Local("a", Type) -local b = Local("b", vec(a), binder_info(true)) -local f = Const("f") -print(Pi(a, b, vec(b))) -local a = Local("a", Type, binder_info(true, true)) -local b = Local("b", vec(a), binder_info(true)) -print(Pi(a, b, vec(b))) diff --git a/tests/lua/expr7.lua b/tests/lua/expr7.lua deleted file mode 100644 index 9f40cc973..000000000 --- a/tests/lua/expr7.lua +++ /dev/null @@ -1,10 +0,0 @@ -local A = Local("A", Type) -local a = Local("a", A) -local vec = Const("vec") -local A1 = Local("A", vec(A)) -local a1 = Local("a", a) -local T = Const("T") -print(Pi(A, a, A1, a1, a1)) -local t = mk_pi("A", Type, mk_pi("a", Var(0), mk_pi("A", vec(Var(1)), mk_pi("a", Var(0), T(Var(0), Var(2)))))) -print(t) - diff --git a/tests/lua/expr8.lua b/tests/lua/expr8.lua deleted file mode 100644 index f2e290c58..000000000 --- a/tests/lua/expr8.lua +++ /dev/null @@ -1,7 +0,0 @@ -local Or = Const("or") -local A = Local("A", Type) -local a = Local("a", A, binder_info(true)) -local b = Local("b", A) -local H = Local("H", Or(a, b), binder_info(false, true)) -print(Pi(A, a, b, H, Or(b, a))) -print(Fun(A, a, b, H, Or(b, a))) diff --git a/tests/lua/expr9.lua b/tests/lua/expr9.lua deleted file mode 100644 index d30b66491..000000000 --- a/tests/lua/expr9.lua +++ /dev/null @@ -1,19 +0,0 @@ -local env = environment() -local m = mk_metavar("m", mk_arrow(Prop, Prop)) -local a = Local("a", Prop) -print(env:normalize(Fun(a, m))) -print(env:normalize(Fun(a, m(a)))) -local m2 = mk_metavar("m2", mk_arrow(Prop, Prop, Prop)) -print(env:normalize(Fun(a, (m2(a))(a)))) -print("step1") -env:type_check(m) -print("step2") -env:type_check(Fun(a, m(a))) -print("step3") -env:type_check(Fun(a, (m2(a))(a))) -local m3 = mk_metavar("m3", mk_metavar("m4", mk_sort(mk_meta_univ("l")))) -print("step4") -env:type_check(m3) -print("step5") -print(env:type_check(m3(a))) -print("before end") diff --git a/tests/lua/extra.lua b/tests/lua/extra.lua deleted file mode 100644 index 57c498be8..000000000 --- a/tests/lua/extra.lua +++ /dev/null @@ -1,11 +0,0 @@ --- Execute f, and make sure is throws an error -function check_error(f) - ok, msg = pcall(function () - f() - end) - if ok then - error("unexpected success...") - else - print("caught expected error: ", msg:what()) - end -end diff --git a/tests/lua/format1.lua b/tests/lua/format1.lua deleted file mode 100644 index 4e6a3b2cf..000000000 --- a/tests/lua/format1.lua +++ /dev/null @@ -1,4 +0,0 @@ - - -f = format(format("hello"):highlight('red'), line(), 1):group() .. space() .. (line() .. format("world")):nest(4) -print(f) diff --git a/tests/lua/format2.lua b/tests/lua/format2.lua deleted file mode 100644 index 3870e14a0..000000000 --- a/tests/lua/format2.lua +++ /dev/null @@ -1,4 +0,0 @@ -f = format(format("hello"):highlight('red'), line(), 1):group() .. space() .. (line() .. format("world")):nest(4) -assert(is_format(f)) -assert(not is_format("hello")) -assert(not is_format(sexpr(10, 20))) diff --git a/tests/lua/format3.lua b/tests/lua/format3.lua deleted file mode 100644 index 4dfd12898..000000000 --- a/tests/lua/format3.lua +++ /dev/null @@ -1,10 +0,0 @@ -print(format("hello"):highlight("green")) -print(format("hello"):highlight("orange")) -print(format("hello"):highlight("blue")) -print(format("hello"):highlight("cyan")) -print(format("hello"):highlight("grey")) -print(format("hello"):highlight("red")) -check_error(function() print(format("hello"):highlight("xyz")) end) -print(format()) -print(format(mpz(10))) -print(format(mpq(10)/3)) diff --git a/tests/lua/free.lua b/tests/lua/free.lua deleted file mode 100644 index 31d89b5b4..000000000 --- a/tests/lua/free.lua +++ /dev/null @@ -1,7 +0,0 @@ -local f = Const("f") -local x = Var(1) -local y = Var(2) -local t = f(x, y) -check_error(function() t:lower_free_vars(2, 10) end) -check_error(function() t:lower_free_vars(1, 1, 2) end) -assert(t:lower_free_vars(1) == f(Var(0), Var(1))) diff --git a/tests/lua/glvl1.lua b/tests/lua/glvl1.lua deleted file mode 100644 index 6a012b869..000000000 --- a/tests/lua/glvl1.lua +++ /dev/null @@ -1,9 +0,0 @@ -local env = environment() -env = env:add_universe("u") -env = env:add_universe("v") -assert(env:is_universe("u")) - -env:export("glvl1_mod.olean") -local env2 = import_modules("glvl1_mod") -assert(env2:is_universe("u")) -assert(env2:is_universe("v")) diff --git a/tests/lua/goal1.lua b/tests/lua/goal1.lua deleted file mode 100644 index fe562e1f5..000000000 --- a/tests/lua/goal1.lua +++ /dev/null @@ -1,16 +0,0 @@ -local env = environment() -local A = Local("A", Type) -env = add_decl(env, mk_constant_assumption("eq", Pi(A, mk_arrow(A, A, Prop)))) -local eq = Const("eq") -local a = Local("a", A) -local b = Local("b", A) -local H = Local("H", eq(A, a, b)) -local t = eq(A, b, a) -local m = mk_metavar("m", Pi(A, a, b, H, t))(A, a, b, H) -print(m) -print(env:type_check(m)) -local g = goal(m, t) -assert(g:validate(env)) -local m1 = g:mk_meta("m1", Prop) -print(tostring(m1)) -print(env:type_check(m1)) diff --git a/tests/lua/hop1.lua b/tests/lua/hop1.lua deleted file mode 100644 index 427e59102..000000000 --- a/tests/lua/hop1.lua +++ /dev/null @@ -1,28 +0,0 @@ -function tst_match(p, t) - local r = match(p, t) - assert(r) - print("--------------") - for i = 1, #r do - print(" #" .. i .. " := " .. tostring(r[i])) - end -end - -local env = environment() -local N = Const("N") -local f = Const("f") -local a = Const("a") -local b = Const("b") -local x = Local("x", N) -local y = Local("y", N) -local V0 = mk_idx_metavar(0, N) -local V1 = mk_idx_metavar(1, N) -tst_match(f(V0, V0), f(a, a)) -tst_match(f(V0, V1), f(a, b)) -local F0 = mk_idx_metavar(0, Pi(x, y, N)) -tst_match(F0(x, y), f(x, f(x, y))) -assert(not match(F0(x, x), f(x, f(x, y)))) -assert(not match(F0(x), f(x, y))) -local F0 = mk_idx_metavar(0, Pi(x, N)) -tst_match(Pi(x, y, F0(x)), Pi(x, y, f(f(x)))) -tst_match(Fun(x, y, F0(x)), Fun(x, y, f(f(x)))) -assert(match(Pi(x, F0(x)), Pi(x, y, f(f(x))))) diff --git a/tests/lua/hop2.lua b/tests/lua/hop2.lua deleted file mode 100644 index e55eb9b6d..000000000 --- a/tests/lua/hop2.lua +++ /dev/null @@ -1,32 +0,0 @@ -function tst_match(p, t) - local r1, r2 = match(p, t) - assert(r1) - print("--------------") - for i = 1, #r1 do - print(" expr:#" .. i .. " := " .. tostring(r1[i])) - end - for i = 1, #r2 do - print(" lvl:#" .. i .. " := " .. tostring(r2[i])) - end -end - -local env = environment() -local N = Const("N") -local a = Const("a") -local b = Const("b") -local x = Local("x", N) -local y = Local("y", N) -local u1 = mk_global_univ("u1") -local u2 = mk_global_univ("u2") -local z = level() -local f = Const("f", {u1, z}) -local f2 = Const("f", {u1, u1+1}) -local fp = Const("f", {mk_idx_metauniv(0), mk_idx_metauniv(1)}) -local V0 = mk_idx_metavar(0, N) -local V1 = mk_idx_metavar(1, N) -tst_match(fp(V0, V0), f(a, a)) -tst_match(fp(V0, V1), f2(a, b)) -local F0 = mk_idx_metavar(0, Pi(x, y, N)) -tst_match(F0(x, y), f(x, f(x, y))) -assert(not match(F0(x, x), f(x, f(x, y)))) -assert(not match(F0(x), f(x, y))) diff --git a/tests/lua/implua.lua b/tests/lua/implua.lua deleted file mode 100644 index 856578336..000000000 --- a/tests/lua/implua.lua +++ /dev/null @@ -1 +0,0 @@ -import("simple.lua") diff --git a/tests/lua/ind1.lua b/tests/lua/ind1.lua deleted file mode 100644 index 76b5bbdde..000000000 --- a/tests/lua/ind1.lua +++ /dev/null @@ -1,145 +0,0 @@ -local env = environment() -local l = mk_param_univ("l") -local U_l = mk_sort(l) -local A = Local("A", U_l) -local U_l1 = mk_sort(max_univ(l, 1)) -- Make sure U_l1 is not Prop -local list_l = Const("list", {l}) -- list.{l} -local Nat = Const("nat") -local vec_l = Const("vec", {l}) -- vec.{l} -local zero = Const("zero") -local succ = Const("succ") -local forest_l = Const("forest", {l}) -local tree_l = Const("tree", {l}) -local n = Local("n", Nat) - -env = env:add_universe("u") -env = env:add_universe("v") -local u = global_univ("u") -local v = global_univ("v") - -function display_type(env, t) - print(tostring(t) .. " : " .. tostring(type_checker(env):check(t))) -end - -env = add_inductive(env, - "nat", Type, - "zero", Nat, - "succ", mk_arrow(Nat, Nat)) --- In the following inductive datatype, {l} is the list of universe level parameters. --- 1 is the number of parameters. --- The Propean true in {A, U_l, true} is marking that this argument is implicit. -env = add_inductive(env, - "list", {l}, 1, Pi(A, U_l1), - "nil", Pi(A, list_l(A)), - "cons", Pi(A, mk_arrow(A, list_l(A), list_l(A)))) -env = add_inductive(env, - "vec", {l}, 1, Pi(A, n, U_l1), - "vnil", Pi(A, vec_l(A, zero)), - "vcons", Pi(A, n, mk_arrow(A, vec_l(A, n), vec_l(A, succ(n))))) - -local And = Const("and") -local Or = Const("or") --- Datatype without introduction rules (aka constructors). It is a uninhabited type. -env = add_inductive(env, "false", Prop) --- Datatype with a single constructor. -env = add_inductive(env, "true", Prop, "trivial", Const("true")) -local A = Local("A", Prop) -local B = Local("B", Prop) -env = add_inductive(env, - "and", 2, Pi(A, B, Prop), - "and_intro", Pi(A, B, mk_arrow(A, B, And(A, B)))) -env = add_inductive(env, - "or", 2, Pi(A, B, Prop), - "or_intro_left", Pi(A, B, mk_arrow(A, Or(A, B))), - "or_intro_right", Pi(A, B, mk_arrow(B, Or(A, B)))) -local A = Local("A", U_l) -local P = Local("P", mk_arrow(A, Prop)) -local a = Local("a", A) -local exists_l = Const("exists", {l}) -env = add_inductive(env, - "exists", {l}, 2, Pi(A, P, Prop), - "exists_intro", Pi(A, P, a, mk_arrow(P(a), exists_l(A, P)))) - -env = add_inductive(env, {l}, 1, - {"tree", Pi(A, U_l1), - "node", Pi(A, mk_arrow(A, forest_l(A), tree_l(A))) - }, - {"forest", Pi(A, U_l1), - "emptyf", Pi(A, forest_l(A)), - "consf", Pi(A, mk_arrow(tree_l(A), forest_l(A), forest_l(A)))}) -local tc = type_checker(env) - -display_type(env, Const("forest", {0})) -display_type(env, Const("vcons", {0})) -display_type(env, Const("consf", {0})) -display_type(env, Const({"forest", "rec"}, {v, u})) -display_type(env, Const({"nat", "rec"}, {v})) -display_type(env, Const({"or", "rec"})) - -local Even = Const("Even") -local Odd = Const("Odd") -local b = Local("b", Nat) -env = add_inductive(env, {}, - {"Even", mk_arrow(Nat, Prop), - "zero_is_even", Even(zero), - "succ_odd", Pi(b, mk_arrow(Odd(b), Even(succ(b))))}, - {"Odd", mk_arrow(Nat, Prop), - "succ_even", Pi(b, mk_arrow(Even(b), Odd(succ(b))))}) - -local flist_l = Const("flist", {l}) -env = add_inductive(env, - "flist", {l}, 1, Pi(A, U_l1), - "fnil", Pi(A, flist_l(A)), - "fcons", Pi(A, mk_arrow(mk_arrow(Nat, A), mk_arrow(Nat, Prop, flist_l(A)), flist_l(A)))) - -local eq_l = Const("eq", {l}) - -local A = Local("A", U_l) -local a = Local("a", A) -local b = Local("b", A) -env = add_inductive(env, - "eq", {l}, 2, Pi(A, a, b, Prop), - "refl", Pi(A, a, eq_l(A, a, a))) -display_type(env, Const({"eq", "rec"}, {v, u})) -display_type(env, Const({"exists", "rec"}, {u})) -display_type(env, Const({"list", "rec"}, {v, u})) -display_type(env, Const({"Even", "rec"})) -display_type(env, Const({"Odd", "rec"})) -display_type(env, Const({"and", "rec"}, {v})) -display_type(env, Const({"vec", "rec"}, {v, u})) -display_type(env, Const({"flist", "rec"}, {v, u})) - -local nat_rec1 = Const({"nat", "rec"}, {1}) -local a = Local("a", Nat) -local b = Local("b", Nat) -local n = Local("n", Nat) -local c = Local("c", Nat) -local add = Fun(a, b, nat_rec1(mk_lambda("_", Nat, Nat), b, Fun(n, c, succ(c)), a)) -display_type(env, add) -local tc = type_checker(env) -assert(tc:is_def_eq(add(succ(succ(zero)), succ(zero)), - succ(succ(succ(zero))))) -assert(tc:is_def_eq(add(succ(succ(succ(zero))), succ(succ(zero))), - succ(succ(succ(succ(succ(zero))))))) - -local list_nat = Const("list", {1})(Nat) -local list_nat_rec1 = Const({"list", "rec"}, {1, 1})(Nat) -display_type(env, list_nat_rec1) -local h = Local("h", Nat) -local t = Local("t", list_nat) -local c = Local("c", Nat) -local lst = Local("lst", list_nat) -local length = Fun(lst, list_nat_rec1(mk_lambda("_", list_nat, Nat), zero, Fun(h, t, c, succ(c)), lst)) -local nil_nat = Const("nil", {1})(Nat) -local cons_nat = Const("cons", {1})(Nat) -print(tc:whnf(length(nil_nat))) -assert(tc:is_def_eq(length(nil_nat), zero)) -assert(tc:is_def_eq(length(cons_nat(zero, nil_nat)), succ(zero))) -assert(tc:is_def_eq(length(cons_nat(zero, cons_nat(zero, nil_nat))), succ(succ(zero)))) - -env:export("ind1_mod.olean") -local env2 = import_modules("ind1_mod") -local tc = type_checker(env2) -assert(tc:is_def_eq(length(nil_nat), zero)) -assert(tc:is_def_eq(length(cons_nat(zero, nil_nat)), succ(zero))) -assert(tc:is_def_eq(length(cons_nat(zero, cons_nat(zero, nil_nat))), succ(succ(zero)))) diff --git a/tests/lua/ind2.lua b/tests/lua/ind2.lua deleted file mode 100644 index bdeb7be15..000000000 --- a/tests/lua/ind2.lua +++ /dev/null @@ -1,111 +0,0 @@ -local env = environment() - -function bad_add_inductive(...) - arg = {...} - ok, msg = pcall(function() add_inductive(unpack(arg)) end) - assert(not ok) - print("\nExpected error: " .. msg:what()) -end - -local l = mk_param_univ("l") -local U_l = mk_sort(l) -local U_l1 = mk_sort(max_univ(l, 1)) -- Make sure U_l1 is not Prop -local list_l = Const("list", {l}) -- list.{l} -local Nat = Const("nat") -local vec_l = Const("vec", {l}) -- vec.{l} -local zero = Const("zero") -local succ = Const("succ") -local forest_l = Const("forest", {l}) -local tree_l = Const("tree", {l}) -local n = Const("n") - -bad_add_inductive(env, - "nat", Type, - "zero", Prop, -- Incorrect result type - "succ", mk_arrow(Nat, Nat)) - -local A = Local("A", U_l) - -bad_add_inductive(env, {l}, 1, - {"tree", mk_arrow(U_l, U_l1), - "node", Pi(A, mk_arrow(A, forest_l(A), tree_l(A))) - }, - {"forest", mk_arrow(U_l1, U_l1), -- Parameters of all inductive types must match - "emptyf", Pi(A, forest_l(A)), - "consf", Pi(A, mk_arrow(tree_l(A), forest_l(A), forest_l(A)))}) - -bad_add_inductive(env, {l}, 1, - {"tree", mk_arrow(U_l, U_l), -- Result may be in universe zero (e.g., l is instantiated with zero) - "node", Pi(A, mk_arrow(A, forest_l(A), tree_l(A))) - }, - {"forest", mk_arrow(U_l, U_l1), - "emptyf", Pi(A, forest_l(A)), - "consf", Pi(A, mk_arrow(tree_l(A), forest_l(A), forest_l(A)))}) - -bad_add_inductive(env, - "nat", 1, Type, -- mismatch in the number of arguments claimed - "zero", Nat, - "succ", mk_arrow(Nat, Nat)) - -env = add_inductive(env, - "nat", Type, - "zero", Nat, - "succ", mk_arrow(Nat, Nat)) - -local Even = Const("Even") -local Odd = Const("Odd") -local b = Local("b", Nat) -bad_add_inductive(env, {}, - {"Even", mk_arrow(Nat, Type), - "zero_is_even", Even(zero), - "succ_odd", Pi(b, mk_arrow(Odd(b), Even(succ(b))))}, - {"Odd", mk_arrow(Nat, Prop), -- if one datatype lives in Prop, then all must live in Prop - "succ_even", Pi(b, mk_arrow(Even(b), Odd(succ(b))))}) - -bad_add_inductive(env, - "list", {l}, 1, mk_arrow(U_l, U_l1), - "nil", Pi(A, mk_arrow(mk_arrow(list_l(A), Prop), list_l(A))), -- nonpositive occurrence of inductive datatype - "cons", Pi(A, mk_arrow(A, list_l(A), list_l(A)))) - -bad_add_inductive(env, - "list", {l}, 1, mk_arrow(U_l, U_l1), - "nil", Pi(A, list_l(mk_arrow(A, A))), - "cons", Pi(A, mk_arrow(A, list_l(A), list_l(A)))) - -local list_1 = Const("list", {mk_level_one()}) - -bad_add_inductive(env, - "list", {l}, 1, mk_arrow(U_l, U_l1), - "nil", Pi(A, list_l(A)), - "cons", Pi(A, mk_arrow(A, list_1(Nat), list_l(A)))) -- all list occurrences must be of the form list_l(A) - -bad_add_inductive(env, - "list", {l}, 1, mk_arrow(U_l, U_l1), - "nil", Pi(A, list_l(A)), - "cons", Pi(A, mk_arrow(A, list_1(A), list_1(A)))) - -bad_add_inductive(env, - "list", {l}, 1, mk_arrow(U_l, U_l1), - "nil", Pi(A, mk_arrow(U_l, list_l(A))), - "cons", Pi(A, mk_arrow(A, list_l(A), list_l(A)))) - -bad_add_inductive(env, - "list", {l}, 1, mk_arrow(U_l, U_l1), - "nil", Pi(A, list_l(A)), - "cons", Pi(A, mk_arrow(list_l(A), A, list_l(A)))) - -local A = Local("A", Type) -env = add_decl(env, mk_constant_assumption("eq", Pi(A, mk_arrow(A, A, Prop)))) -local eq = Const("eq") -local Nat2 = Const("nat2") -local a = Local("a", Nat2) -bad_add_inductive(env, - "nat2", Type, - "zero2", Nat2, - "succ2", Pi(a, mk_arrow(eq(Nat2, a, a), Nat2))) - -local env = bare_environment() -bad_add_inductive(env, -- Environment does not support inductive datatypes - "nat", Type, - "zero", Nat, - "succ", mk_arrow(Nat, Nat)) diff --git a/tests/lua/ind3.lua b/tests/lua/ind3.lua deleted file mode 100644 index 73770367d..000000000 --- a/tests/lua/ind3.lua +++ /dev/null @@ -1,80 +0,0 @@ -function display_type(env, t) - print(tostring(t) .. " : " .. tostring(env:normalize(env:type_check(t)))) -end - -local env = environment() -local nat = Const("nat") -local zero = Const("zero") -local succ = Const("succ") - -env = add_inductive(env, - "nat", Type, - "zero", nat, - "succ", mk_arrow(nat, nat)) - -local a = Local("a", nat) -local b = Local("b", nat) -local n = Local("n", nat) -local r = Local("r", nat) -local nat_rec_nat = Const({"nat", "rec"}, {1})(Fun(a, nat)) -local add = Fun(a, b, nat_rec_nat(b, Fun(n, r, succ(r)), a)) -local tc = type_checker(env) -assert(tc:is_def_eq(add(succ(succ(zero)), succ(zero)), - succ(succ(succ(zero))))) - -print(env:normalize(add(succ(succ(zero)), succ(succ(succ(zero)))))) - -local l = param_univ("l") -local U_l = mk_sort(l) -local U_l1 = mk_sort(max_univ(l, 1)) -local tree_l = Const("tree", {l}) -local tree_list_l = Const("tree_list", {l}) -local A = Local("A", U_l) -local v = Local("v", A) -local children = Local("children", tree_list_l(A)) -local head = Local("head", tree_l(A)) -local tail = Local("tail", tree_list_l(A)) - -env = add_inductive(env, {l}, 1, - {"tree", Pi(A, U_l1), - "leaf", Pi(A, tree_l(A)), - "node", Pi(A, v, children, tree_l(A)) - }, - {"tree_list", Pi(A, U_l1), - "nil", Pi(A, tree_list_l(A)), - "cons", Pi(A, head, tail, tree_list_l(A))}) - -local tree_nat = Const("tree", {1})(nat) -local tree_list_nat = Const("tree_list", {1})(nat) -local t = Local("t", tree_nat) -local tl = Local("tl", tree_list_nat) -local tree_rec_nat = Const({"tree", "rec"}, {1, 1})(nat, Fun(t, nat), Fun(tl, nat)) -local r1 = Local("r1", nat) -local r2 = Local("r2", nat) -local length_tree_nat = Fun(t, tree_rec_nat(zero, - Fun(a, tl, r, succ(r)), - zero, - Fun(t, tl, r1, r2, add(r1, r2)), - t)) - -display_type(env, length_tree_nat) - -local leaf_nat = Const("leaf", {1})(nat) -local node_nat = Const("node", {1})(nat) -local nil_nat = Const("nil", {1})(nat) -local cons_nat = Const("cons", {1})(nat) -local one = succ(zero) -local two = succ(one) -local tree1 = node_nat(one, nil_nat) -local tree2 = node_nat(two, cons_nat(leaf_nat, cons_nat(leaf_nat, nil_nat))) -local tree3 = node_nat(one, cons_nat(tree1, cons_nat(tree2, nil_nat))) -local tree4 = node_nat(one, cons_nat(tree3, cons_nat(tree3, nil_nat))) -display_type(env, tree4) -print("norm(tree1): " .. tostring(env:normalize(length_tree_nat(tree1)))) -print("norm(tree2): " .. tostring(env:normalize(length_tree_nat(tree2)))) -print("norm(tree3): " .. tostring(env:normalize(length_tree_nat(tree3)))) -print("norm(tree4): " .. tostring(env:normalize(length_tree_nat(tree4)))) -assert(env:normalize(length_tree_nat(tree1)) == succ(zero)) -assert(env:normalize(length_tree_nat(tree2)) == succ(zero)) -assert(env:normalize(length_tree_nat(tree3)) == succ(succ(succ(zero)))) -assert(env:normalize(length_tree_nat(tree4)) == succ(succ(succ(succ(succ(succ(succ(zero)))))))) diff --git a/tests/lua/ind4.lua b/tests/lua/ind4.lua deleted file mode 100644 index 8cdecb4c3..000000000 --- a/tests/lua/ind4.lua +++ /dev/null @@ -1,26 +0,0 @@ -function display_type(env, t) - print(tostring(t) .. " : " .. tostring(env:normalize(env:type_check(t)))) -end - -local env = environment() -local l = param_univ("l") -local U_l = mk_sort(l) -local U_l1 = mk_sort(max_univ(l, 1)) -- Make sure U_l1 is not Prop -local A = Local("A", U_l) -local list_l = Const("list", {l}) - -local env1 = add_inductive(env, - "list", {l}, 1, Pi(A, U_l1), - "nil", Pi(A, list_l(A)), - "cons", Pi(A, mk_arrow(A, list_l(A), list_l(A)))) - -display_type(env1, Const({"list", "rec"}, {1, 1})) - --- Slightly different definition where A : Type.{l} is an index --- instead of a global parameter -local U_sl = mk_sort(succ_univ(l)) -local env2 = add_inductive(env, - "list", {l}, 0, Pi(A, U_sl), -- The resultant type must live in the universe succ(l) - "nil", Pi(A, list_l(A)), - "cons", Pi(A, mk_arrow(A, list_l(A), list_l(A)))) -display_type(env2, Const({"list", "rec"}, {1, 1})) diff --git a/tests/lua/ind5.lua b/tests/lua/ind5.lua deleted file mode 100644 index bda6bb2f2..000000000 --- a/tests/lua/ind5.lua +++ /dev/null @@ -1,23 +0,0 @@ -function display_type(env, t) - print(tostring(t) .. " : " .. tostring(env:normalize(env:type_check(t)))) -end - -local A = Local("A", Prop) -local env = environment() -local retraction = Const("retraction") - -env = add_inductive(env, - "retraction", Prop, - "inj", Pi(A, retraction)) - -local u = global_univ("u") -env = env:add_universe("u") -local a = Local("a", Prop) -local r = Local("r", retraction) - -local rec = Const({"retraction", "rec"}) -display_type(env, rec) -local proj = Fun(r, rec(Prop, Fun(a, a), r)) -local inj = Const("inj") - -assert(not pcall(function() display_type(env, Fun(a, proj(inj(a)))) end)) diff --git a/tests/lua/ind6.lua b/tests/lua/ind6.lua deleted file mode 100644 index ba84b5bab..000000000 --- a/tests/lua/ind6.lua +++ /dev/null @@ -1,18 +0,0 @@ - -local env = environment() -local u = param_univ("u") -local Set = Const("Set", {u}) -local A = Local("A", mk_sort(u)) - -env = add_inductive(env, - "Set", {u}, 0, mk_sort(u+1), - "sup", Pi(A, mk_arrow(mk_arrow(A, Set), Set))) - -local env = environment() -local u = param_univ("u") -local Set = Const("Set", {u}) -local A = Local("A", mk_sort(u)) - -env = add_inductive(env, - "Set", {u}, 1, Pi(A, mk_sort(u+1)), - "sup", Pi(A, mk_arrow(mk_arrow(A, Set(A)), Set(A)))) diff --git a/tests/lua/ind_ex.lua b/tests/lua/ind_ex.lua deleted file mode 100644 index c2a2e8f72..000000000 --- a/tests/lua/ind_ex.lua +++ /dev/null @@ -1,16 +0,0 @@ -local env = environment() -local l = param_univ("l") -local U_l = mk_sort(l) -local inhabited = Const("inhabited", {l}) -local A = Local("A", U_l) -local a = Local("a", A) - -env = add_inductive(env, - "inhabited", {l}, 1, mk_arrow(U_l, Prop), - "inhabited_intro", Pi(A, a, inhabited(A))) - -function display_type(env, t) - print(tostring(t) .. " : " .. tostring(type_checker(env):check(t))) -end - -display_type(env, Const({"inhabited", "rec"}, {1})) diff --git a/tests/lua/ind_tricky.lua b/tests/lua/ind_tricky.lua deleted file mode 100644 index ddcdd1416..000000000 --- a/tests/lua/ind_tricky.lua +++ /dev/null @@ -1,17 +0,0 @@ -local env = environment() - -local tricky = Const("tricky") -local P = Local("P", Prop) - -env = add_inductive(env, - "tricky", Prop, - "C", mk_arrow(Pi(P, mk_arrow(P, P)), tricky)) - -function display_type(env, t) - print(tostring(t) .. " : " .. tostring(type_checker(env):check(t))) -end - -env = env:add_universe("u") -local tricky_rec = Const({"tricky", "rec"}, {0}) - -display_type(env, tricky_rec) diff --git a/tests/lua/int1.lua b/tests/lua/int1.lua deleted file mode 100644 index c43e84826..000000000 --- a/tests/lua/int1.lua +++ /dev/null @@ -1,19 +0,0 @@ -local env = environment() -local nat = Const("nat") -local int = Const("int") - -env = add_inductive(env, - "nat", Type, - "zero", nat, - "succ", mk_arrow(nat, nat)) - -env = add_inductive(env, - "int", Type, - "pos", mk_arrow(nat, int), - "neg", mk_arrow(nat, int)) -function display_type(env, t) - print(tostring(t) .. " : " .. tostring(type_checker(env):check(t))) -end - -display_type(env, Const({"nat", "rec"}, {0})) -display_type(env, Const({"int", "rec"}, {0})) diff --git a/tests/lua/jst1.lua b/tests/lua/jst1.lua deleted file mode 100644 index 271ee22e3..000000000 --- a/tests/lua/jst1.lua +++ /dev/null @@ -1,33 +0,0 @@ -assert(is_justification(justification())) -assert(justification():is_none()) -assert(justification("simple"):is_asserted()) -local env = bare_environment() -local f = Const("f") -local g = Const("g") -local a = Const("a") -local j1 = justification("expression must be a type", env, f(f(a))) -assert(j1:is_asserted()) -print(j1:pp()) -local m = mk_metavar("m", Prop) -local j2 = justification("expresion must be a Proposition", env, g(m)) -print(j2:pp()) -local s = substitution() -s:assign(m, f(a)) -print(j2:pp(s)) -local j3 = assumption_justification(1) -assert(not j2:depends_on(1)) -assert(j3:depends_on(1)) -assert(not j3:depends_on(2)) -local j4 = assumption_justification(2) -assert(j4:depends_on(2)) -assert(not j4:depends_on(1)) -assert(j4:is_assumption()) -assert(not j4:main_expr()) -assert(j4:assumption_idx() == 2) -local j5 = mk_composite_justification(mk_composite_justification(j1, j4), j3) -assert(j5:depends_on(1)) -assert(j5:depends_on(2)) -assert(not j5:depends_on(3)) -assert(j5:is_composite()) -assert(j5:child2():is_eqp(j3)) -assert(j5:child1():child2():is_eqp(j4)) diff --git a/tests/lua/level1.lua b/tests/lua/level1.lua deleted file mode 100644 index e38bf1f02..000000000 --- a/tests/lua/level1.lua +++ /dev/null @@ -1,33 +0,0 @@ -assert(level():is_zero()) -assert(mk_level_zero():is_zero()) -assert(mk_level_one():is_succ()) -assert(not mk_level_one():is_zero()) -assert(mk_level_max(mk_level_zero(), mk_level_one()):is_succ()) -assert(mk_level_max(mk_param_univ("a"), mk_param_univ("b")):is_max()) -assert(mk_level_max(mk_level_one(), mk_level_zero()):is_succ()) -assert(level():succ():is_succ()) -assert(mk_level_imax(mk_level_one(), mk_level_zero()):is_zero()) -assert(is_level(mk_level_one())) -assert(not is_level(1)) -assert(mk_level_one():succ_of() == mk_level_zero()) -assert(mk_level_one():succ_of():is_zero()) -assert(mk_level_succ(mk_level_succ(level())):is_not_zero()) -assert(not mk_param_univ("a"):is_not_zero()) -assert(mk_level_max(mk_param_univ("a"), mk_param_univ("b")):lhs() == mk_param_univ("a")) -assert(mk_level_max(mk_param_univ("a"), mk_param_univ("b")):rhs() == mk_param_univ("b")) -assert(mk_level_imax(mk_param_univ("a"), mk_param_univ("b")):lhs() == mk_param_univ("a")) -assert(mk_level_imax(mk_param_univ("a"), mk_param_univ("b")):rhs() == mk_param_univ("b")) -assert(mk_param_univ("a"):id() == name("a")) -assert(mk_meta_univ("b"):id() == name("b")) -assert(mk_level_succ(mk_level_zero()):is_equivalent(mk_level_one())) -assert(not mk_param_univ("b"):is_equivalent(mk_param_univ("a"))) -assert(mk_level_one():kind() == level_kind.Succ) -assert(not mk_level_one():has_meta()) -assert(not mk_level_succ(mk_param_univ("a")):has_meta()) -assert(mk_level_succ(mk_meta_univ("a")):has_meta()) -local l = mk_level_max(mk_param_univ("a"), mk_param_univ("b")) -assert(l:instantiate({"a"}, {mk_level_one()}) == mk_level_max(mk_level_one(), mk_param_univ("b"))) -assert(l:instantiate({"a", "b"}, {mk_level_one(), mk_param_univ("c")}) == mk_level_max(mk_level_one(), mk_param_univ("c"))) -assert(not pcall(function() l:instantiate({"a", "b", "C"}, {mk_level_one(), mk_param_univ("c")}) end)) -assert(l:is_eqp(l)) -assert(not l:is_eqp(level())) diff --git a/tests/lua/level2.lua b/tests/lua/level2.lua deleted file mode 100644 index f43553e6d..000000000 --- a/tests/lua/level2.lua +++ /dev/null @@ -1,4 +0,0 @@ -local u = mk_global_univ("u") -assert(is_level(u)) -assert(u:is_global()) -assert(u:id() == name("u")) diff --git a/tests/lua/level3.lua b/tests/lua/level3.lua deleted file mode 100644 index 6f8325196..000000000 --- a/tests/lua/level3.lua +++ /dev/null @@ -1,17 +0,0 @@ -local g = mk_global_univ("g") -local g1 = mk_level_succ(g) -local g2 = mk_level_succ(g1) -local g3 = mk_level_succ(g2) -local g1b = mk_level_succ(mk_global_univ("g")) -assert(mk_level_max(g, g1) == g1) -assert(mk_level_max(g2, g1) == g2) -assert(mk_level_max(g3, g2) == g3) -assert(mk_level_max(g2, g3) == g3) -assert(mk_level_max(g1b, g2) == g2) -assert(mk_level_max(g1b, g) == g1b) -assert(mk_level_max(g, g1b) == g1b) -assert(not (mk_level_max(mk_global_univ("g2"), g1b) == g1b)) - -assert(mk_level_imax(g2, g3) == g3) -assert(not (mk_level_imax(g3, g) == g3)) -assert(mk_level_imax(g3, g1) == g3) diff --git a/tests/lua/level4.lua b/tests/lua/level4.lua deleted file mode 100644 index ab4b77cda..000000000 --- a/tests/lua/level4.lua +++ /dev/null @@ -1,10 +0,0 @@ -assert(not (mk_level_zero() < mk_level_zero())) -local u = mk_global_univ("u") -local v = mk_global_univ("v") -local z = mk_level_zero() -local max = mk_level_max -local imax = mk_level_imax -local succ = mk_level_succ -assert(max(succ(max(succ(v), u)), max(v, succ(succ(u)))):norm() == max(succ(succ(u)), succ(succ(v)))) -assert(imax(succ(succ(max(u, u))), v):norm() == imax(succ(succ(u)), v)) -assert(max(u, max(succ(succ(z)), max(u, succ(z)))):norm() == max(succ(succ(z)), u)) diff --git a/tests/lua/level5.lua b/tests/lua/level5.lua deleted file mode 100644 index 52f06a698..000000000 --- a/tests/lua/level5.lua +++ /dev/null @@ -1,14 +0,0 @@ -local l1 = mk_param_univ("l1") -assert(l1:is_param()) -local m = mk_meta_univ("m") -assert(m:is_meta()) -assert(mk_level_zero():is_explicit()) -assert(mk_level_one():is_explicit()) -local t1 = mk_level_max(l1, mk_level_one()) -assert(t1:has_param()) -local t2 = mk_level_imax(mk_level_one(), l1) -assert(t2:is_imax()) -assert(not pcall(function() t2:id() end)) -assert(not pcall(function() l1:lhs() end)) -assert(not pcall(function() l1:rhs() end)) -assert(not pcall(function() l1:succ_of() end)) diff --git a/tests/lua/level6.lua b/tests/lua/level6.lua deleted file mode 100644 index e8a5f6a39..000000000 --- a/tests/lua/level6.lua +++ /dev/null @@ -1,23 +0,0 @@ -local l = mk_param_univ("l") -print(mk_sort(0)) -print(mk_sort(1)) -print(mk_sort(2)) -print(mk_sort(l+2)) -print(mk_sort(mk_level_max(l, 2))) -print(mk_sort(mk_level_imax(l, 2))) -assert(not pcall(function() - print(mk_sort(1000000000)) - end -)) -assert(not pcall(function() - print(mk_sort(-10)) - end -)) -print(mk_sort(l+0)) -assert(not pcall(function() - print(mk_sort(0+l)) - end -)) -local z = mk_level_zero() -assert(is_level(z)) -assert(z:is_equivalent(0)) diff --git a/tests/lua/level7.lua b/tests/lua/level7.lua deleted file mode 100644 index 9f9f77be6..000000000 --- a/tests/lua/level7.lua +++ /dev/null @@ -1,24 +0,0 @@ -assert(max_univ("l1", "l2"):is_geq("l1")) -assert(max_univ("l1", "l2"):is_geq(max_univ("l2", "l1"))) -print(max_univ("l2", "l1", "l3")) -assert(not max_univ("l1", "l2"):is_geq(max_univ("l2", "l1", "l3"))) -assert(not imax_univ("l1", "l2"):is_geq("l1")) -assert(imax_univ("l1", "l2"):is_geq("l2")) -print(imax_univ("l1", succ_univ("l2"))) -assert(imax_univ("l1", succ_univ("l2")):is_geq(max_univ("l2", "l1"))) -assert(max_univ("l1", succ_univ("l2")):is_geq(max_univ("l2", "l1"))) -assert(succ_univ("l1"):is_geq("l1")) -assert(succ_univ(succ_univ("l1")):is_geq("l1")) -assert(max_univ(1, 3):is_geq(3)) -assert(max_univ(1, 3):is_geq(2)) -assert(not max_univ(1, 3):is_geq(5)) -local l1 = param_univ("l1") -local l2 = param_univ("l2") -local g = global_univ("g") -assert((g+1):is_geq(g)) -assert((g+2):is_geq(g+1)) -assert(not g:is_geq(l1)) -assert(not max_univ(l1, l2):is_geq(max_univ(l2, l1+1))) -assert((max_univ(l1, l2) + 1):is_geq(max_univ(l2, l1+1))) -assert(max_univ(l1+2, l2, g+1):is_geq(max_univ(g+1, l1+1, l2))) -assert(not max_univ(l1+2, l2, g+1):is_geq(max_univ(g+2, l1+1, l2))) diff --git a/tests/lua/level8.lua b/tests/lua/level8.lua deleted file mode 100644 index f1a7a86ea..000000000 --- a/tests/lua/level8.lua +++ /dev/null @@ -1,10 +0,0 @@ -local l = max_univ() -assert(l == mk_level_zero()) -assert(l == max_univ(l)) -local l1 = param_univ("l1") -local l2 = param_univ("l2") -assert(max_univ(l1, l2):is_geq(max_univ(l2, l1))) -assert(max_univ(l1+1, l2+1):is_geq(max_univ(l2, l1)+1)) --- is_geq_core assumes the levels are normalized -assert(not max_univ(l1+1, l2+1):is_geq_core(max_univ(l2, l1)+1)) - diff --git a/tests/lua/level9.lua b/tests/lua/level9.lua deleted file mode 100644 index ee145f441..000000000 --- a/tests/lua/level9.lua +++ /dev/null @@ -1,4 +0,0 @@ -local l = param_univ("l") -assert(l+0 == l) -local l = mk_level_zero() -assert(l+0 == mk_level_zero()) diff --git a/tests/lua/map2.lua b/tests/lua/map2.lua deleted file mode 100644 index 2349cf51d..000000000 --- a/tests/lua/map2.lua +++ /dev/null @@ -1,33 +0,0 @@ -local m = rb_map() -for i = 1, 100 do - m:insert(i, i * 3) -end - -local prev_k = nil --- It is safe to add/erase elements from m while we are traversing. --- The for_each method will traverse the elements that are in m --- when the for_each is invoked -m:for_each( - function(k, v) - if prev_k then - assert(prev_k < k) - end - print(k .. " -> " .. v) - prev_k = k - m:insert(-k, v) - end -) - -assert(m:size() == 200) -m2 = m:copy() -m:for_each( - function(k, v) - assert(m2:contains(-k)) - assert(m2:find(-k) == v) - if k > 0 then - m:erase(k) - end - end -) -assert(m:size() == 100) -m:for_each(function(k, v) assert(k < 0) end) diff --git a/tests/lua/mod1.lua b/tests/lua/mod1.lua deleted file mode 100644 index 9f6478c2a..000000000 --- a/tests/lua/mod1.lua +++ /dev/null @@ -1,32 +0,0 @@ -local env = environment() -env = add_decl(env, mk_constant_assumption("A", Prop)) -local A = Const("A") -env = add_decl(env, mk_axiom("H1", A)) -local H1 = Const("H1") -env = add_decl(env, mk_theorem("H2", A, H1)) -assert(env:get("H2"):is_theorem()) -env = add_decl(env, mk_definition("B", Prop, A)) -env:export("mod1_mod.olean") - -local env2 = import_modules("mod1_mod.olean", {keep_proofs=true}) -assert(env2:get("A"):type() == Prop) -assert(env2:get("A"):is_constant_assumption()) -assert(env2:get("H1"):type() == A) -assert(env2:get("H1"):is_axiom()) -assert(env2:get("H2"):type() == A) -assert(env2:get("H2"):is_theorem()) -assert(env2:get("H2"):value() == H1) -assert(env2:get("B"):type() == Prop) -assert(env2:get("B"):value() == A) -assert(env2:get("B"):is_definition()) - -local env3 = import_modules("mod1_mod.olean") -assert(env3:get("A"):type() == Prop) -assert(env3:get("A"):is_constant_assumption()) -assert(env3:get("H1"):type() == A) -assert(env3:get("H1"):is_axiom()) -assert(env3:get("H2"):type() == A) -assert(env3:get("H2"):is_axiom()) -assert(env3:get("B"):type() == Prop) -assert(env3:get("B"):value() == A) -assert(env3:get("B"):is_definition()) diff --git a/tests/lua/mod3.lua b/tests/lua/mod3.lua deleted file mode 100644 index 4ec40505a..000000000 --- a/tests/lua/mod3.lua +++ /dev/null @@ -1,3 +0,0 @@ -local env = environment() -env = add_decl(env, mk_constant_assumption("A", Type)) -env:export("mod3_mod.olean") diff --git a/tests/lua/mod3_corrupted1.olean b/tests/lua/mod3_corrupted1.olean deleted file mode 100644 index 52441c407b743904b7644eec2656f46343ab0881..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 55 ucmd1LNlnbl%t>W{0w$ddS8ga|WMpJ;%}a3usRjTBCJ4a* diff --git a/tests/lua/mod3_corrupted2.olean b/tests/lua/mod3_corrupted2.olean deleted file mode 100644 index e8a133d8611b1db8e65f493b55de4352a61ef9b1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 56 vcmd1LNlna4%gjk-fC46+3|DR_TPh_rIfsFP$qCG7Vq|1waLr3`1E~f89GeL! diff --git a/tests/lua/mod3_corrupted3.olean b/tests/lua/mod3_corrupted3.olean deleted file mode 100644 index 7853e41ed538822960631a42e53d1f2762102c90..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 55 vcmd1LNlna4%gjk-fC47v4av8mY^jvg name("foo", 0)) -assert(name(nil) == name()) - diff --git a/tests/lua/n2.lua b/tests/lua/n2.lua deleted file mode 100644 index ae328dedb..000000000 --- a/tests/lua/n2.lua +++ /dev/null @@ -1,6 +0,0 @@ -assert(is_name(name("foo"))) -assert(not is_name("foo")) -assert(not is_name(3)) -a = name("foo", 1, 2) -print(a) -assert(is_name(a)) diff --git a/tests/lua/n3.lua b/tests/lua/n3.lua deleted file mode 100644 index 7000cb7ac..000000000 --- a/tests/lua/n3.lua +++ /dev/null @@ -1 +0,0 @@ -print(2^32) diff --git a/tests/lua/n5.lua b/tests/lua/n5.lua deleted file mode 100644 index bfd113c5d..000000000 --- a/tests/lua/n5.lua +++ /dev/null @@ -1,3 +0,0 @@ -assert(not pcall(function() name(mpz(10)) end)) -assert(not pcall(function() name(function() return 1 end) end)) -assert(name("x", 1):hash() == name("x", 1):hash()) diff --git a/tests/lua/n6.lua b/tests/lua/n6.lua deleted file mode 100644 index 5aabdb08d..000000000 --- a/tests/lua/n6.lua +++ /dev/null @@ -1,8 +0,0 @@ -assert(name("a", "b"):append_after(1) == name("a", "b_1")) -assert(name("a", 1):append_after(2) == name("a", 1, "_2")) -assert(name("a", "b"):append_after("k") == name("a", "bk")) -assert(name("a", "b"):append_before("k") == name("a", "kb")) -assert(name("a", 1):append_before("k") == name("a", "k", 1)) -assert(name():append_after("a") == name("a")) -assert(name():append_after(1) == name("_1")) -assert(name():append_before("b") == name("b")) diff --git a/tests/lua/n7.lua b/tests/lua/n7.lua deleted file mode 100644 index 54a9cb4f0..000000000 --- a/tests/lua/n7.lua +++ /dev/null @@ -1,7 +0,0 @@ -local n1 = name("foo", "bar", 1) -assert(n1:replace_prefix("foo", {"hello", "world"}) == name("hello", "world", "bar", 1)) -assert(n1:replace_prefix("foo2", {"hello", "world"}) == name("foo", "bar", 1)) -assert(n1:replace_prefix("foo", nil) == name("bar", 1)) -assert(n1:replace_prefix("foo", name()) == name("bar", 1)) -assert(n1:replace_prefix({"foo", "bar"}, {"hello", "world"}) == name("hello", "world", 1)) -assert(n1:replace_prefix({"foo", "bar"}, "tst") == name("tst", 1)) diff --git a/tests/lua/name1.lua b/tests/lua/name1.lua deleted file mode 100644 index c5c0913b5..000000000 --- a/tests/lua/name1.lua +++ /dev/null @@ -1,30 +0,0 @@ -n = name("a") -assert(n:is_atomic()) -assert(not n:is_anonymous()) -assert(n:is_string()) -assert(not n:is_numeral()) -assert(not pcall(function() n:get_prefix() end)) -n = name() -assert(n:is_atomic()) -assert(n:is_anonymous()) -assert(not n:is_string()) -assert(not n:is_numeral()) -assert(not pcall(function() n:get_prefix() end)) -n = name("a", "b") -assert(not n:is_atomic()) -assert(not n:is_anonymous()) -assert(n:is_string()) -assert(not n:is_numeral()) -assert(n:get_prefix() == name("a")) -assert(n:get_string() == "b") -assert(not pcall(function() n:get_numeral() end)) -n = name(name("A"), 1) -assert(not n:is_atomic()) -assert(not n:is_anonymous()) -assert(not n:is_string()) -assert(n:is_numeral()) -assert(n:get_prefix() == name("A")) -assert(n:get_numeral() == 1) -assert(not pcall(function() n:get_string() end)) - - diff --git a/tests/lua/name_gen1.lua b/tests/lua/name_gen1.lua deleted file mode 100644 index 8f93da940..000000000 --- a/tests/lua/name_gen1.lua +++ /dev/null @@ -1,11 +0,0 @@ -local g = name_generator("tst") -assert(g:next() == name("tst", 0)) -assert(g:next() == name("tst", 1)) -assert(g:prefix() == name("tst")) -local cg = g:mk_child() -assert(cg:prefix() == name("tst", 2)) -assert(cg:next() == name("tst", 2, 0)) -assert(cg:next() == name("tst", 2, 1)) -assert(cg:next() == name("tst", 2, 2)) -assert(g:next() == name("tst", 3)) -assert(is_name_generator(g)) diff --git a/tests/lua/ns1.lua b/tests/lua/ns1.lua deleted file mode 100644 index 692cd5e74..000000000 --- a/tests/lua/ns1.lua +++ /dev/null @@ -1,12 +0,0 @@ -local s = name_set() -assert(not s:contains("a")) -s = s:insert("a") -assert(s:contains("a")) -s = s:insert("b") -assert(s:contains("a")) -assert(s:contains("b")) -local s2 = s:erase("a") -assert(s:contains("a")) -assert(s:contains("b")) -assert(not s2:contains("a")) -assert(s2:contains("b")) diff --git a/tests/lua/ns2.lua b/tests/lua/ns2.lua deleted file mode 100644 index 7261e944e..000000000 --- a/tests/lua/ns2.lua +++ /dev/null @@ -1,5 +0,0 @@ -local s = name_set("a", "b", "c", {"a", 1}) -assert(s:contains("a")) -assert(s:contains({"a", 1})) -assert(s:contains("b")) -assert(s:contains("c")) diff --git a/tests/lua/num1.lua b/tests/lua/num1.lua deleted file mode 100644 index 83119a0c6..000000000 --- a/tests/lua/num1.lua +++ /dev/null @@ -1,47 +0,0 @@ -assert(mpz(10) == mpz("10")) -assert(mpz(mpz(3)) == mpz("3")) -print(mpz(10) + mpz(3)) -assert(mpz(10) + mpz(3) == mpz(13)) -assert(mpz(10) + 2 == mpz(12)) -assert(3 + mpz(15) == mpz(18)) -assert(mpz(10) - mpz(3) == mpz(7)) -assert(mpz(10) - 2 == mpz(8)) -assert(3 - mpz(15) == -mpz(12)) -assert(- mpz(15) == mpz("-15")) -assert(- mpz(15) == -mpz("15")) -assert(mpz(10) * mpz(3) == mpz(30)) -assert(mpz(10) * 2 == mpz(20)) -assert(3 * mpz(15) == mpz(45)) -assert(mpz(3)^2 == mpz(9)) -local a = -2 -assert(not pcall(function() print(mpz(3)^a) end)) -assert(mpz(3) < mpz(5)) -assert(mpz(3) > mpz(1)) -assert(mpq(3) == mpq("3")) -assert(mpq(3) == mpq(mpq(3))) -assert(mpq(3) == mpq(mpz(3))) -assert(mpq(0.5) == mpq(1)/2) -assert(mpq(0.4) ~= mpq(1)/2) -assert(mpq(10) + mpq(3) == mpq(13)) -assert(mpq(10) + 2 == mpq(12)) -assert(3 + mpq(15) == mpq(18)) -assert(mpq(3) + mpz(15) == mpq(18)) -assert(mpq(10) - mpq(3) == mpq(7)) -assert(mpq(10) - 2 == mpq(8)) -assert(3 - mpq(15) == -mpq(12)) -assert(mpq(3) - mpz(15) == -mpq(12)) -assert(mpq(10) * mpq(3) == mpq(30)) -assert(mpq(10) * 2 == mpq(20)) -assert(3 * mpq(15) == mpq(45)) -assert(mpq(3) * mpz(15) == mpq(45)) -assert(mpq(3)^2 == mpq(9)) -print(mpq(0.5)^2) -assert(mpq(0.5)^2 == mpq(1)/4) -local a = -2 -assert(not pcall(function() print(mpq(3)^a) end)) -assert(mpq(10) / mpq(3) == mpq("10/3")) -assert(mpq(10) / 2 == mpq(5)) -assert(3 / mpq(15) == mpq(1)/5) -assert(mpq(3) / mpz(15) == mpq("1/5")) -assert(mpq(3) < mpq(5)) -assert(mpq(3) > mpq(1)) diff --git a/tests/lua/old/ceq1.lua b/tests/lua/old/ceq1.lua deleted file mode 100644 index 16fd6756d..000000000 --- a/tests/lua/old/ceq1.lua +++ /dev/null @@ -1,92 +0,0 @@ -local env = get_environment() -assert(env:find_object("neq_elim")) - -function show_ceqs(ceqs) - for i = 1, #ceqs do - print(ceqs[i][1], ceqs[i][2], is_permutation_ceq(ceqs[i][1])) - env:type_check(ceqs[i][2]) - assert(is_ceq(env, nil, ceqs[i][1])) - end -end - -function test_ceq(name, expected, is_perm) - local obj = env:find_object(name) - local r = to_ceqs(env, nil, obj:get_type(), Const(name)) - show_ceqs(r) - assert(#r == expected) - if is_perm ~= nil then - for i = 1, #r do - assert(is_permutation_ceq(r[i][1]) == is_perm) - end - end -end - -parse_lean_cmds([[ - variable f : Nat -> Nat - axiom Ax1 : forall x : Nat, x > 0 -> f x < 0 /\ not (f x = 1) - axiom Ax2 : forall x : Nat, x < 0 -> f (f x) = x - variable g : Nat -> Nat -> Nat - axiom Ax3 : forall x : Nat, not (x = 1) -> if (x < 0) then (g x x = 0) else (g x x < 0 /\ g x 0 = 1 /\ g 0 x = 2) - axiom Ax4 : forall x y : Nat, f x = x - axiom Ax5 : forall x y : Nat, f x = y /\ g x y = x - axiom Ax6 : forall x : Nat, f x ≠ 0 -]]) - -test_ceq("Ax1", 2) -test_ceq("Ax2", 1) -test_ceq("Ax3", 4) -test_ceq("Ax4", 0) -test_ceq("Ax5", 1) -test_ceq("Ax6", 1) -test_ceq("eta", 1) -test_ceq("not_not_eq", 1, false) -test_ceq("or_comm", 1, true) -test_ceq("or_assoc", 1, false) -test_ceq("or_id", 1, false) -test_ceq("or_falsel", 1, false) -test_ceq("or_falser", 1, false) -test_ceq("or_truel", 1, false) -test_ceq("or_truer", 1, false) -test_ceq("or_tauto", 1, false) -test_ceq("and_comm", 1, true) -test_ceq("and_assoc", 1, false) -test_ceq("and_id", 1, false) -test_ceq("and_falsel", 1, false) -test_ceq("and_falser", 1, false) -test_ceq("and_truel", 1, false) -test_ceq("and_truer", 1, false) -test_ceq("and_absurd", 1, false) -test_ceq("imp_truer", 1, false) -test_ceq("imp_truel", 1, false) -test_ceq("imp_falser", 1, false) -test_ceq("imp_falsel", 1, false) -test_ceq("not_and", 1, false) -test_ceq("not_or", 1, false) -test_ceq("not_iff", 1, false) -test_ceq("not_implies", 1, false) -test_ceq("or_left_comm", 1, true) -test_ceq("and_left_comm", 1, true) -test_ceq("forall_or_distributer", 1, false) -test_ceq("forall_or_distributel", 1, false) -test_ceq("forall_and_distribute", 1, false) -test_ceq("exists_and_distributer", 1, false) -test_ceq("exists_and_distributel", 1, false) -test_ceq("exists_or_distribute", 1, false) -test_ceq({"Nat", "add_zeror"}, 1, false) -test_ceq({"Nat", "add_zerol"}, 1, false) -test_ceq({"Nat", "add_comm"}, 1 , true) -test_ceq({"Nat", "add_assoc"}, 1, false) -test_ceq({"Nat", "mul_zerol"}, 1, false) -test_ceq({"Nat", "mul_zeror"}, 1, false) -test_ceq({"Nat", "mul_onel"}, 1, false) -test_ceq({"Nat", "mul_oner"}, 1, false) -test_ceq({"Nat", "mul_comm"}, 1, true) -test_ceq({"Nat", "mul_assoc"}, 1, false) -test_ceq({"Nat", "add_comm"}, 1, true) -test_ceq({"Nat", "add_assoc"}, 1, false) -test_ceq({"Nat", "distributer"}, 1, false) -test_ceq({"Nat", "distributel"}, 1, false) -test_ceq({"Nat", "le_refl"}, 1, false) -test_ceq({"Nat", "le_zero"}, 1, false) -test_ceq({"Nat", "not_lt_0"}, 1, false) -test_ceq({"Nat", "lt_nrefl"}, 1, false) diff --git a/tests/lua/old/cex_builder1.lua b/tests/lua/old/cex_builder1.lua deleted file mode 100644 index 03f29a09f..000000000 --- a/tests/lua/old/cex_builder1.lua +++ /dev/null @@ -1,14 +0,0 @@ -local cex = cex_builder(function(n, cex, a) - if cex then - return cex - else - error("no counterexample") - end -end) -assert(is_cex_builder(cex)) -local env = environment() -env:add_var("T", Type()) -local a = assignment() -local env2 = cex("main", env, a) -assert(env2:find_object("T")) -assert(not pcall(function() cex("main", nil, a) end)) diff --git a/tests/lua/old/coercion_bug1.lua b/tests/lua/old/coercion_bug1.lua deleted file mode 100644 index ef89a4b49..000000000 --- a/tests/lua/old/coercion_bug1.lua +++ /dev/null @@ -1,23 +0,0 @@ -local env = environment() -env:import("Int") -parse_lean_cmds([[ - variable f : Int -> Int -> Int - notation 20 _ +++ _ : f - print f 10 20 - notation 20 _ -+- _ : f - print f 10 20 -]], env) - -local F = parse_lean('f 10 20', env) -print(lean_formatter(env)(F)) -assert(tostring(lean_formatter(env)(F)) == "10 -+- 20") - -local child = env:mk_child() - -parse_lean_cmds([[ - print f 10 20 -]], child) - -assert(tostring(lean_formatter(env)(F)) == "10 -+- 20") -print(lean_formatter(child)(F)) -assert(tostring(lean_formatter(child)(F)) == "10 -+- 20") diff --git a/tests/lua/old/context1.lua b/tests/lua/old/context1.lua deleted file mode 100644 index d05083d17..000000000 --- a/tests/lua/old/context1.lua +++ /dev/null @@ -1,25 +0,0 @@ -c = context() -assert(c:is_empty()) -print(c) -e = context_entry("x", Const("N")) -assert(e:get_name() == name("x")) -assert(e:get_domain() == Const("N")) -assert(not e:get_body()) -print(e:get_body()) -c = context(c, e) -print(c) -assert(not c:is_empty()) -c = context(c, "y", Const("M")) -assert(#c == 2) -assert(c:size() == 2) -e, c1 = lookup(c, 0) -assert(c1:size() == 1) -assert(e:get_name() == name("y")) -c = context(c, "z", Const("N"), Const("a")) -print(c) -check_error(function() lookup(c, 10) end) -assert(lookup(c, 0):get_body() == Const("a")) -assert(not is_context_entry(c)) -assert(is_context(c)) -assert(is_context_entry(e)) -assert(not is_context_entry(c)) diff --git a/tests/lua/old/env1.lua b/tests/lua/old/env1.lua deleted file mode 100644 index d0d2087b3..000000000 --- a/tests/lua/old/env1.lua +++ /dev/null @@ -1,11 +0,0 @@ -import("util.lua") -e = environment() -assert(is_environment(e)) -e:add_uvar_cnstr("M1") -print(e:get_uvar("M1")) -e:add_var("N", Type()) -N, M = Consts("N M") -e:add_var("a", N) -x, a = Consts("x, a") -check_error(function() e:type_check(fun(x, M, a)) end) -print(e:type_check(fun(x, N, a))) diff --git a/tests/lua/old/env2.lua b/tests/lua/old/env2.lua deleted file mode 100644 index 46ef6bd6a..000000000 --- a/tests/lua/old/env2.lua +++ /dev/null @@ -1,18 +0,0 @@ -env = environment() -env:add_var("N", Type()) -env:add_var("x", Const("N")) -for v in env:objects() do - if v:has_name() then - print(v:get_name()) - end -end -assert(env:find_object("N")) -assert(not env:find_object("Z")) -assert(env:find_object("N"):is_var_decl()) -assert(env:find_object("N"):has_type()) -assert(env:find_object("N"):has_name()) -assert(env:find_object("N"):get_type() == Type()) -assert(env:find_object("N"):get_name() == name("N")) -assert(env:find_object("x"):get_type() == Const("N")) -assert(not env:has_parent()) -assert(not env:has_children()) diff --git a/tests/lua/old/env3.lua b/tests/lua/old/env3.lua deleted file mode 100644 index 9d66fd8af..000000000 --- a/tests/lua/old/env3.lua +++ /dev/null @@ -1,4 +0,0 @@ -env = environment() -env:add_var("N", Type()) -env:add_var("x", Const("N")) -print(env) diff --git a/tests/lua/old/env4.lua b/tests/lua/old/env4.lua deleted file mode 100644 index 62cfdc34c..000000000 --- a/tests/lua/old/env4.lua +++ /dev/null @@ -1,34 +0,0 @@ -local env = environment() -env:import("Int") -env:add_uvar_cnstr("M", level(level(), 1)) -env:add_uvar_cnstr("Z", level(level("M"), 1)) -assert(env:is_ge(level("Z"), level("M"))) -local child = env:mk_child() -assert(env:has_children()) -assert(child:has_parent()) -child:add_var("x", Const("Int")) -for o in child:local_objects() do - assert(o:get_name() == name("x")) - print(o) -end -local eenv = empty_environment() -print(not eenv:find_object("Int")) -assert(not pcall(function() env:parent() end)) -local p = child:parent() -assert(p:has_children()) -assert(not pcall(function() env:add_uvar_cnstr("Z") end)) -child:add_uvar_cnstr("Z") -assert(not pcall(function() child:add_uvar_cnstr("M", level("Z")) end)) -child:add_definition("val1", Const("true"), true) -child:add_definition("val2", Const("Bool"), Const("true"), true) -local ok, msg = pcall(function() child:add_definition("val3", Const("Int"), Const("true"), true) end) -assert(not ok) -print(msg) -assert(child:normalize(Const("val2")) == Const("val2")) -local Int = Const("Int") -child:add_theorem("Th1", mk_eq(Int, iVal(0), iVal(0)), Const("refl")(Int, iVal(0))) -child:add_axiom("H1", mk_eq(Int, Const("x"), iVal(0))) -assert(child:has_object("H1")) -local ctx = context(context(), "x", Const("Int"), iVal(10)) -assert(child:normalize(Var(0), ctx) == iVal(10)) -assert(child:type_check(Var(0), ctx) == Const("Int")) diff --git a/tests/lua/old/expr1.lua b/tests/lua/old/expr1.lua deleted file mode 100644 index 146cabd0e..000000000 --- a/tests/lua/old/expr1.lua +++ /dev/null @@ -1,13 +0,0 @@ -f = Const("f") -a = Const("a") -print(f(f(a))) -print(mk_lambda("x", Const("N"), Var(0))) -assert(tostring(f(a)) == "f a") -x = Const("x") -y = Const("y") -N = Const("N") -print(fun(x, N, y, N, f(x, y))) -a = {x, N, x, Y} -print(a[1]) -print(fun({{x, N}, {y, N}}, f(x, y))) -print(Pi({{x, N}, {y, N}}, f(x, y))) diff --git a/tests/lua/old/expr2.lua b/tests/lua/old/expr2.lua deleted file mode 100644 index e3ada5a88..000000000 --- a/tests/lua/old/expr2.lua +++ /dev/null @@ -1,12 +0,0 @@ -import("util.lua") -f = Const("f") -x = Const("x") -y = Const("y") -a = Const("a") -b = Const("b") -print(Let(x, f(a), f(x, x))) -print(Let({{x, f(a)}, {y, f(b)}}, f(x, y))) -x1, x2, x3 = Consts("x1, x2, x3") -assert(tostring(f(x1, x2, x3)) == "f x1 x2 x3") -y1, y2 = Consts("y1 y2") -assert(tostring(f(y1, y2)) == "f y1 y2") diff --git a/tests/lua/old/expr3.lua b/tests/lua/old/expr3.lua deleted file mode 100644 index f1c1a7d9b..000000000 --- a/tests/lua/old/expr3.lua +++ /dev/null @@ -1,4 +0,0 @@ -t = Type() -print(t) -t = Type(level("U")) -print(t) diff --git a/tests/lua/old/expr4.lua b/tests/lua/old/expr4.lua deleted file mode 100644 index 04ce2507e..000000000 --- a/tests/lua/old/expr4.lua +++ /dev/null @@ -1,4 +0,0 @@ -m1 = mk_metavar("a") -print(m1) -m2 = mk_metavar("b", local_context(mk_inst(1, Const("a")), local_context())) -print(m2) diff --git a/tests/lua/old/expr5.lua b/tests/lua/old/expr5.lua deleted file mode 100644 index c4eb92b92..000000000 --- a/tests/lua/old/expr5.lua +++ /dev/null @@ -1,16 +0,0 @@ -e = context_entry("a", Const("a")) -n = e:get_body() -check_error(function() mk_heq(n, Const("a")) end) -print(Const("a") < Const("b")) -check_error(function() mk_app(Const("a")) end) -print(mk_pi("x", Const("N"), Var(0))) -print(Pi("x", Const("N"), Const("x"))) -assert(mk_pi("x", Const("N"), Var(0)) == Pi("x", Const("N"), Const("x"))) -assert(mk_let("x", Const("a"), Var(0)) == Let("x", Const("a"), Const("x"))) -print(mk_let("x", Const("N"), Const("a"), Var(0))) -check_error(function() Pi({"x"}, Const("x")) end) -check_error(function() Pi({"x", Const("N")}, Const("x")) end) -check_error(function() Pi({{"x"}}, Const("x")) end) -check_error(function() Pi(Const("x")) end) -check_error(function() Pi(Const("x"), Const("N"), Const("x"), Const("a")) end) -check_error(function() Pi({}, Const("x")) end) diff --git a/tests/lua/old/expr6.lua b/tests/lua/old/expr6.lua deleted file mode 100644 index 5dffe0b8b..000000000 --- a/tests/lua/old/expr6.lua +++ /dev/null @@ -1,44 +0,0 @@ -import("util.lua") -function print_leaves(e, ctx) - if (not e) then - return - end - local k = e:kind() - if k == expr_kind.Var then - local i = e:fields() - local e = ctx:lookup(i) - print("var idx: " .. i .. ", name: " .. tostring(e:get_name())) - elseif k == expr_kind.Const then - local n = e:fields() - print("constant name: " .. n) - elseif k == expr_kind.App then - local num, args = e:fields() - print("application num args: " .. num) - for a in args do - print_leaves(a, ctx) - end - elseif k == expr_kind.Lambda or k == expr_kind.Pi then - local name, domain, body = e:fields() - print("abstraction var name: " .. tostring(name)) - print_leaves(domain, ctx) - print_leaves(body, ctx:extend(name, domain)) - elseif k == expr_kind.Let then - local name, ty, val, body = e:fields() - print("let var name: " .. tostring(name)) - print_leaves(ty, ctx) - print_leaves(val, ctx) - print_leaves(body, ctx:extend(name, ty, val)) - else - print(e) - end -end - -local f, g, h, a, b, c = Consts("f, g, h, a, b, c") -local N, M = Consts("N, M") -local x, y, z = Consts("x, y, z") -assert(is_expr(f)) - -local F = fun(h, mk_arrow(N, N), - Let(x, h(a), mk_eq(N, f(x), h(x)))) -print(F) -print_leaves(F, context()) diff --git a/tests/lua/old/expr7.lua b/tests/lua/old/expr7.lua deleted file mode 100644 index 6ac159ff6..000000000 --- a/tests/lua/old/expr7.lua +++ /dev/null @@ -1,19 +0,0 @@ -import("util.lua") -local f, g, a, b, c, d = Consts("f, g, a, b, c, d") -local x = Var(0) -local y = Var(1) -assert(f(a):closed()) -local F = f(g(x, a), f(b, f(x, c))) -assert(F:has_free_vars()) -assert(F:lift_free_vars(1) == f(g(y, a), f(b, f(y, c)))) -print(F) -print(F:instantiate{c, g(b)}) -assert(F:instantiate{c, g(b)} == f(g(g(b), a), f(b, f(g(b), c)))) -assert(F:instantiate(g(b)) == f(g(g(b), a), f(b, f(g(b), c)))) -assert(F:lift_free_vars(1):instantiate{c, g(b)} == f(g(c, a), f(b, f(c, c)))) -print(F:lift_free_vars(1):abstract(a)) -assert(F:lift_free_vars(1):abstract(a) == f(g(y, x), f(b, f(y, c)))) -assert(F:lift_free_vars(1):abstract(a):instantiate{c, d} == f(g(c, d), f(b, f(c, c)))) -assert(F:lift_free_vars(1):abstract(a):instantiate{c, d}:abstract{c, b} == f(g(y, d), f(x, f(y, y)))) -assert(F:lift_free_vars(1):lower_free_vars(1) == F) -assert(F:lift_free_vars(0, 1):lower_free_vars(1, 1) == F) diff --git a/tests/lua/old/expr8.lua b/tests/lua/old/expr8.lua deleted file mode 100644 index 9be9c8907..000000000 --- a/tests/lua/old/expr8.lua +++ /dev/null @@ -1,44 +0,0 @@ -import("util.lua") -local f, g, a, b, c, d = Consts("f, g, a, b, c, d") -local N, M = Consts("N, M") -local x = Var(0) -local y = Var(1) -assert(f(a):closed()) -local F = f(g(x, a), f(b, f(x, c))) -assert(F:has_free_vars()) -assert(F:has_free_var(0)) -assert(not F:has_free_var(1)) -assert(F:has_free_var(0, 2)) -assert(not F:has_free_var(1, 3)) -local c = 0 -F:for_each(function() c = c + 1; return false end) -assert(c == 1) -assert(x:is_var()) -assert(not x:is_app()) -assert(F:is_app()) -assert(Let(a, b, f(a)):is_let()) -assert(fun(a, N, f(a)):is_lambda()) -assert(Pi(a, N, f(a)):is_pi()) -assert(Pi(a, N, f(a)):is_abstraction()) -assert(fun(a, N, f(a)):is_abstraction()) -assert(mk_metavar("M"):is_metavar()) -assert(mk_real_value(mpq(10)):is_value()) -assert(not F:has_metavar()) -assert(f(mk_metavar("M")):has_metavar()) -assert(F:num_args() == 3) -assert(F:arg(0) == f) -assert(F:arg(1) == g(x, a)) -assert(not pcall(function() F:arg(3) end)) -assert(not pcall(function() F:arg(-3) end)) -local l1 = level(level("N"), 10) -print(l1) -assert(Type(l1):fields() == l1) -assert(a:fields() == name("a")) -assert(y:fields() == 1) -assert(mk_metavar("M"):fields() == name("M")) -assert(a:occurs(F)) -assert(F:hash() == F:hash()) -assert(a:hash() ~= F:hash()) -assert(mk_nat_value(mpz(10)):is_value()) -assert(not pcall(function() Var(0):num_args() end)) -assert(not pcall(function() print(fun(N, a)) end)) diff --git a/tests/lua/old/fields.lua b/tests/lua/old/fields.lua deleted file mode 100644 index bde312725..000000000 --- a/tests/lua/old/fields.lua +++ /dev/null @@ -1,8 +0,0 @@ -assert(nVal(0):fields() == mpz(0)) -assert(iVal(-1):fields() == mpz(-1)) -assert(rVal("1/2"):fields() == mpq("1/2")) -local env = get_environment() -local add = env:find_object({"Nat", "add"}) -assert(add) -assert(add:get_value():fields() == nil) -assert(add:get_value():is_value()) diff --git a/tests/lua/old/fmt1.lua b/tests/lua/old/fmt1.lua deleted file mode 100644 index b61d6e9b1..000000000 --- a/tests/lua/old/fmt1.lua +++ /dev/null @@ -1,2 +0,0 @@ -fmt = get_formatter() -print(fmt(Const("a"), options())) diff --git a/tests/lua/old/front.lua b/tests/lua/old/front.lua deleted file mode 100644 index 26b595a4f..000000000 --- a/tests/lua/old/front.lua +++ /dev/null @@ -1,55 +0,0 @@ -import("util.lua") -local env = environment() -env:import("Int") -print(get_options()) -parse_lean_cmds([[ -variable f : Int -> Int -> Int -variable g : Bool -> Bool -> Bool -variables a b : Int -variables i j : Int -variables p q : Bool -notation 100 _ ++ _ : f -notation 100 _ ++ _ : g -set_option pp::colors true -set_option pp::width 300 -]], env) -print(get_options()) -assert(get_options():get{"pp", "colors"}) -assert(get_options():get{"pp", "width"} == 300) -parse_lean_cmds([[ - print i ++ j - print f i j -]], env) - -local env2 = environment() -env2:import("Int") -parse_lean_cmds([[ -variable f : Int -> Int -> Int -variables a b : Int -print f a b -notation 100 _ -+ _ : f -]], env2) - -local f, a, b = Consts("f, a, b") -assert(tostring(f(a, b)) == "f a b") -set_formatter(lean_formatter(env)) -assert(tostring(f(a, b)) == "a ++ b") -set_formatter(lean_formatter(env2)) -assert(tostring(f(a, b)) == "a -+ b") - -local fmt = lean_formatter(env) --- We can parse commands with respect to environment env2, --- but using a formatter based on env. -parse_lean_cmds([[ -print f a b -]], env2, options(), fmt) - -set_formatter(fmt) -env = nil -env2 = nil -fmt = nil -collectgarbage() --- The references to env, env2 and fmt were removed, but The global --- formatter (set with set_formatter) still has a reference to its --- environment. -assert(tostring(f(a, b)) == "a ++ b") diff --git a/tests/lua/old/goal1.lua b/tests/lua/old/goal1.lua deleted file mode 100644 index 72dfd364e..000000000 --- a/tests/lua/old/goal1.lua +++ /dev/null @@ -1,30 +0,0 @@ -local hs = hypotheses() -assert(is_hypotheses(hs)) -assert(hs:empty()) -assert(hs:is_nil()) -local hs = hypotheses("H1", Const("q"), hs) -local hs = hypotheses("H2", Const("p"), hs) -local n, p = hs:head() -assert(n == name("H2")) -assert(p == Const("p")) -assert(not hs:empty()) -assert(hs:tail():tail():empty()) -for n, p in hs:pairs() do - print(n, p) -end -assert(not pcall(function() hypotheses("H1", Const("q"), "H2", Const("p"), hs) end)) -assert(#hs == 2) -assert(hs:size() == 2) - -local g = goal(hs, Const("p1")) -assert(is_goal(g)) -print(g) -assert(#(g:hypotheses()) == 2) -assert(g:conclusion() == Const("p1")) -assert(g:unique_name("H") == name("H")) -assert(g:unique_name("H1") == name("H1", 1)) -print(g:pp()) -local opts = options() -opts = opts:update(name("pp", "unicode"), false) -print(opts) -print(g:pp(opts)) diff --git a/tests/lua/old/hidden1.lua b/tests/lua/old/hidden1.lua deleted file mode 100644 index 3db1650de..000000000 --- a/tests/lua/old/hidden1.lua +++ /dev/null @@ -1,14 +0,0 @@ -local env = environment() -env:import("Int") -assert(env:is_opaque("and")) -assert(env:is_opaque("or")) -assert(env:is_opaque({"Int", "lt"})) -parse_lean_cmds([[ - definition a : Bool := true -]], env) -assert(not env:is_opaque("a")) -env:set_opaque("a", true) -assert(env:is_opaque("a")) -env:set_opaque("a", false) -assert(not env:is_opaque("a")) -assert(not env:is_opaque("b")) diff --git a/tests/lua/old/hop1.lua b/tests/lua/old/hop1.lua deleted file mode 100644 index c3799e6f9..000000000 --- a/tests/lua/old/hop1.lua +++ /dev/null @@ -1,29 +0,0 @@ -import("util.lua") -local env = get_environment() -parse_lean_cmds([[ - axiom Ax1 {A : TypeU} (P Q : A -> Bool) : (forall x : A, P x /\ Q x) = ((forall x : A, P x) /\ (forall x : A, Q x)) - variable f : Nat -> Nat -> Nat - variable p : Nat -> Bool -]], env) -local Ax1 = env:find_object("Ax1"):get_type() -function body(e) - while (e:is_pi()) do - local _, _, r = e:fields() - e = r - end - return e -end -local p = body(Ax1):arg(2) -local t = parse_lean([[ - forall x : Nat, p (f x 0) /\ f (f x x) 1 >= 0 -]], env) -r = hop_match(p, t) -assert(r) -assert(#r == 3) -local p, f, x, Nat = Consts("p, f, x, Nat") -assert(r[1] == Nat) -assert(r[2] == fun(x, Nat, p(f(x, nVal(0))))) -assert(r[3] == fun(x, Nat, Const({"Nat", "ge"})(f(f(x, x), nVal(1)), nVal(0)))) -for i = 1, #r do - print("#" .. tostring(i) .. " <--- " .. tostring(r[i])) -end diff --git a/tests/lua/old/hop2.lua b/tests/lua/old/hop2.lua deleted file mode 100644 index 4f9685604..000000000 --- a/tests/lua/old/hop2.lua +++ /dev/null @@ -1,133 +0,0 @@ -import("util.lua") - -function pibody(e) - while (e:is_pi()) do - local _, _, r = e:fields() - e = r - end - return e -end - -function funbody(e) - while (e:is_lambda()) do - local _, _, r = e:fields() - e = r - end - return e -end - -function hoptst(rule, target, expected, perfect_match, no_env) - if expected == nil then - expected = true - end - local th = parse_lean(rule) - local p = pibody(th):arg(2) - local t = funbody(parse_lean(target)) - local r - if no_env then - r = hop_match(p, t, nil) - else - r = hop_match(p, t) - end - -- print(p, t) - if (r and not expected) or (not r and expected) then - error("test failed: " .. tostring(rule) .. " === " .. tostring(target)) - end - if r then - local s = p:instantiate(r):beta_reduce() - print "Solution:" - for i = 1, #r do - print("#" .. tostring(i) .. " <--- " .. tostring(r[i])) - end - print "" - if perfect_match then - t = t:beta_reduce() - if s ~= t then - print("Mismatch") - print(s) - print(t) - end - assert(s == t) - end - end -end - -parse_lean_cmds([[ - variable f : Nat -> Nat -> Nat - variable g : Nat -> Nat - variable p : Nat -> Bool - variable n : Nat -]]) - -hoptst([[forall (h : Nat -> Nat), (forall x : Nat, h 0 = h x) = true]], - [[fun (ff : Nat -> Nat), forall x : Nat, ff 0 = ff x]]) - -hoptst([[forall (h : Nat -> Nat -> Nat) (a : Nat), (forall x : Nat, (h x a) = a) = true]], - [[fun (a b c : Nat), (forall x : Nat, (f x b) = b)]]) - -hoptst([[forall (A : TypeU) (P Q : A -> Bool), (forall x : A, P x /\ Q x) = ((forall x : A, P x) /\ (forall x : A, Q x))]], - [[forall x : Nat, p (f x 0) /\ f (f x x) 1 >= 0]]) - -hoptst([[forall (F G : Nat -> Nat), (forall x y : Nat, F x = x /\ G y = y) = (F = G)]], - [[(forall x y : Nat, f x (g x) = x /\ g (g (g y)) = y)]]) - -hoptst([[forall (F G : Nat -> Nat), (forall x y : Nat, F x = x /\ G y = y) = (F = G)]], - [[fun (a b c : Nat), (forall x y : Nat, f x (f (g b) c) = x /\ (f (g (g (f y c))) a) = y)]]) - -hoptst([[forall (a b c : Bool), ((a /\ b) /\ c) = (a /\ (b /\ c))]], - [[fun (p1 p2 p3 p4 p5 : Bool), (((p1 ∧ p2) ∧ p3) ∧ (p4 ∧ p2))]]) - -hoptst([[forall (F G : Nat -> Bool), (forall x : Nat, F x = (F x ∧ G x)) = (F = G)]], - [[forall x : Nat, p (f x x) = (p (f x x) ∧ p (f x 0))]]) - -hoptst([[forall (F G : Nat -> Bool), (forall x : Nat, F x = (F x ∧ G x)) = (F = G)]], - [[forall x : Nat, p (f x x) = (p (f (g x) x) ∧ p (f x 0))]], false) - -hoptst([[forall (F G : Nat -> Nat), (forall x y : Nat, F x = x /\ G y = y) = (F = G)]], - [[fun (a b c : Nat), (forall x y : Nat, f x (f (g y) c) = x /\ (f (g (g (f y c))) a) = y)]], false) - -hoptst([[forall (a : Bool), (a /\ true) = a]], - [[fun (p1 p2 p3 : Bool), (p1 /\ p2) /\ true]]) - -hoptst([[forall (a : Bool), (a /\ true) = a]], - [[fun (p1 p2 p3 : Bool), (p1 /\ p2) /\ false]], false) - -hoptst([[forall (h : Nat -> Nat) (a : Nat), (h a) = a]], - [[fun (a b c : Nat), f a b]]) - -hoptst([[forall (a : Nat), (g a) = a]], - [[fun (a b c : Nat), f a b]], false) - -hoptst([[forall (A : Type) (a : A), (a = a) = true]], - [[fun (a b : Nat), b = b]]) - -hoptst([[forall (h : Nat -> Nat), (forall x : Nat, h x = h 0) = true]], - [[fun (ff : Nat -> Nat), forall x : Nat, ff x = ff 0]]) - -hoptst([[forall (h : Nat -> Nat), (forall x : Nat, h x = h 0) = true]], - [[fun (ff : Nat -> Nat) (a b c : Nat), forall x : Nat, ff x = ff 0]]) - -hoptst([[forall (h : Nat -> Nat -> Bool), (forall x : Nat, h x x) = true]], - [[fun (a b : Nat), forall x : Nat, f x x]]) - -hoptst([[forall (h : Nat -> Nat -> Bool), (forall x : Nat, h x x) = true]], -- this is not a higher-order pattern - [[fun (a b : Nat), forall x : Nat, f (f x) (f x)]], false) - -hoptst([[forall (h : Nat -> Nat -> Bool), (forall x : Nat, h n x) = true]], - [[fun (ff : Nat -> Nat -> Bool) (a b : Nat), forall x : Nat, ff n x]]) - -hoptst([[forall (h : Nat -> Nat -> Bool), (forall x : Nat, h n x) = true]], -- this is not a higher-order pattern - [[fun (ff : Nat -> Nat -> Bool) (a b : Nat), forall x : Nat, ff n (g x)]], false) - -hoptst([[forall (h : Nat -> Bool), (forall x y : Nat, h x) = true]], - [[fun (a b : Nat), forall x y : Nat, (fun z : Nat, z + x) (fun w1 w2 : Nat, w1 + w2 + x)]]) - -hoptst([[forall (h : Nat -> Bool), (forall x y : Nat, h y) = true]], - [[fun (a b : Nat), forall x y : Nat, (fun z : Nat, z + y) (fun w1 w2 : Nat, w1 + w2 + y)]]) - -parse_lean_cmds([[ - definition ww := 0 -]]) - -hoptst('ww = 0', '0', true, false) -hoptst('ww = 0', '0', false, false, true) diff --git a/tests/lua/old/import.lua b/tests/lua/old/import.lua deleted file mode 100644 index f945b337b..000000000 --- a/tests/lua/old/import.lua +++ /dev/null @@ -1,12 +0,0 @@ -local env = get_environment() -assert(env:imported("kernel")) -assert(env:imported("Nat")) -assert(not env:imported("Real")) -print("before import Real") -env:import("Real") -print("after import Real") -assert(env:imported("Real")) -parse_lean_cmds([[ - variables a b c : Real - check a + b + 0 -]]) diff --git a/tests/lua/old/io_state1.lua b/tests/lua/old/io_state1.lua deleted file mode 100644 index f667fe20e..000000000 --- a/tests/lua/old/io_state1.lua +++ /dev/null @@ -1,9 +0,0 @@ -local ios = io_state() -assert(is_io_state(ios)) -ios:print(Const("a"), Const("b")) -print(ios:get_options()) -assert(is_formatter(ios:get_formatter())) -ios:set_options(options({"pp", "unicode"}, false)) -print(ios:get_options()) -ios:print_diagnostic("warning") -ios:print_diagnostic(ios:get_options()) diff --git a/tests/lua/old/is_prop1.lua b/tests/lua/old/is_prop1.lua deleted file mode 100644 index 472b0cdf6..000000000 --- a/tests/lua/old/is_prop1.lua +++ /dev/null @@ -1,27 +0,0 @@ -local env = get_environment() -assert(env:is_proposition(Const("true"))) -assert(env:is_proposition(Const("false"))) -assert(not env:is_proposition(nVal(0))) -assert(env:is_proposition(parse_lean([[forall x : Nat, x > 0]]))) -parse_lean_cmds([[ - variable f : Nat -> Nat -> Nat - variable p : Nat -> Bool - variables a b c : Nat - definition B := Bool - variable q : B -]]) -assert(env:is_proposition(parse_lean([[p (f a 0)]]))) -assert(env:is_proposition(parse_lean([[p (f a 0) /\ a > 0]]))) -assert(not env:is_proposition(parse_lean([[fun x, p (f x 0) /\ a > 0]]))) -assert(env:is_proposition(parse_lean([[forall x : Bool, x]]))) -assert(not env:is_proposition(parse_lean([[forall x : Nat, Nat]]))) -assert(not env:is_proposition(parse_lean([[forall T : Type, T]]))) -assert(env:is_proposition(parse_lean([[forall x y z, x /\ z /\ y]]))) -assert(env:is_proposition(parse_lean([[true -> false]]))) -assert(env:is_proposition(parse_lean([[Nat -> false]]))) -assert(not env:is_proposition(parse_lean([[true -> Nat]]))) -assert(not env:is_proposition(parse_lean([[Type]]))) -assert(env:is_proposition(parse_lean([[0 = 1]]))) -assert(env:is_proposition(parse_lean([[q]]))) - - diff --git a/tests/lua/old/jst1.lua b/tests/lua/old/jst1.lua deleted file mode 100644 index 073a867e8..000000000 --- a/tests/lua/old/jst1.lua +++ /dev/null @@ -1,11 +0,0 @@ -local j1 = mk_assumption_justification(1) -local j2 = mk_assumption_justification(2) -assert(is_justification(j1)) -assert(j1:depends_on(j1)) -assert(not j1:depends_on(j2)) -for c in j1:children() do - assert(false) -end -assert(not j2:has_children()) -print(j1) -assert(not j1:get_main_expr()) diff --git a/tests/lua/old/localctx1.lua b/tests/lua/old/localctx1.lua deleted file mode 100644 index 6a52c5366..000000000 --- a/tests/lua/old/localctx1.lua +++ /dev/null @@ -1,24 +0,0 @@ -l = local_context() -assert(l:is_nil()) -assert(is_local_context(l)) -e = mk_inst(1, Const("a")) -assert(is_local_entry(e)) -assert(e:is_inst()) -assert(not e:is_lift()) -assert(e:s() == 1) -assert(e:v() == Const("a")) -assert(e:v() ~= Const("b")) -assert(not e:is_lift()) -e2 = mk_lift(0, 2); -assert(is_local_entry(e2)) -assert(not e2:is_inst()) -assert(e2:is_lift()) -assert(e2:s() == 0) -assert(e2:n() == 2) -l = local_context(e, l) -l2 = local_context(e2, l) -assert(l2:head() == e2) -assert(l2:tail():head() == e) -assert(not l2:is_nil()) -assert(is_local_context(l2)) -assert(not is_local_entry(l2)) diff --git a/tests/lua/old/m1.lua b/tests/lua/old/m1.lua deleted file mode 100644 index 9ced95f80..000000000 --- a/tests/lua/old/m1.lua +++ /dev/null @@ -1,36 +0,0 @@ -function body(e) - while (e:is_pi()) do - e = e:abst_body() - end - return e -end -function show_subst(r) - for i = 1, #r do - if r[i] then - print("#" .. tostring(i) .. " <--- " .. tostring(r[i])) - end - end -end -local env = get_environment() -parse_lean_cmds([[ - variable f : Nat -> Nat -> Nat - variable g : Nat -> Nat - variable p : Nat -> Bool - variables a b c : Nat -]]) -local t = parse_lean([[fun x, (f (g a)) x]]) -print(t) -local eta = env:find_object("eta"):get_type() -local eta_lhs = body(eta):arg(2) -print(eta_lhs) -r = hop_match(eta_lhs, t) -print("r: " .. #r) -show_subst(r) -assert(r[3]) -print(eta) -local r3_type = env:infer_type(r[3]) -print(r3_type) -local eta3_type = eta:abst_body():abst_body():abst_domain() -print(eta3_type) -r2 = hop_match(eta3_type, r3_type) -show_subst(r2) diff --git a/tests/lua/old/map.lua b/tests/lua/old/map.lua deleted file mode 100644 index 30177574a..000000000 --- a/tests/lua/old/map.lua +++ /dev/null @@ -1,89 +0,0 @@ -import("util.lua") --- This examples demonstrates that Lean objects are not very useful as Lua table keys. -local f = Const("f") -local m = {} -local env = environment() -env:add_var("T", Type()) -env:add_var("f", mk_arrow(Const("T"), Const("T"))) -for i = 1, 100 do - env:add_var("a" .. i, Const("T")) - local t = f(Const("a" .. i)) - -- Any object can be a key of a Lua table. - -- But, Lua does not use the method __eq for comparing keys. - -- The problem is that Lua uses its own hashcode that may not - -- be compatible with the __eq implemantion. - -- By non-compatible, we mean two objects my be equal by __eq, but - -- the hashcodes may be different. - m[t] = i -end - -for t1, i in pairs(m) do - local t2 = f(Const("a" .. i)) - -- print(t1, i, t2) - assert(m[t1] == i) - -- t1 and t2 are structurally equal - assert(t1 == t2) - -- t1 and t2 are different objects - assert(not t1:is_eqp(t2)) - -- t2 is not a key of map - assert(m[t2] == nil) - assert(env:normalize(t1) == t1) - assert(t1:instantiate(Const("a")) == t1) - local t1_prime = t1:instantiate(Const("a")) - -- t1 and t1_prime are structurally equal - assert(t1 == t1_prime) - -- Moreover, they are references to the same Lean object - assert(t1:is_eqp(t1_prime)) - -- But, they are wrapped by different Lua userdata - assert(m[t1_prime] == nil) -end - --- We can store elements that implement __lt and __eq metamethods in splay_maps. --- The implementation assumes that the elements stored in the splay map can be totally ordered by __lt -m = splay_map() -m:insert(Const("a"), 10) -assert(m:contains(Const("a"))) -assert(not m:contains(Const("b"))) -assert(m:find(Const("a")) == 10) -local a, b = Consts("a, b") -m:insert(f(a, b), 20) -assert(m:find(f(a, b)) == 20) -assert(m:find(f(a, a)) == nil) -assert(m:size() == 2) -assert(#m == 2) -m:erase(f(a, a)) -assert(m:size() == 2) -m:erase(f(a, b)) -assert(m:size() == 1) -for i = 1, 100 do - local t = f(Const("a" .. i)) - m:insert(t, i) - assert(m:contains(t)) - assert(m:find(t) == i) -end - -assert(m:size() == 101) - -for i = 1, 100 do - local t = f(Const("a" .. i)) - assert(m:find(t) == i) -end - --- The following call fails because integers cannot be compared with Lean expressions -assert(not pcall(function() m:insert(10, 20) end)) - --- Splay maps copy operation is O(1) -local m2 = m:copy() -m2:insert(b, 20) -assert(m:size() == 101) -assert(m2:size() == 102) - --- We can also traverse all elements in the map -local num = 0 -m:for_each( - function(k, v) - print(tostring(k) .. " -> " .. v) - num = num + 1 - end -) -assert(num == 101) diff --git a/tests/lua/old/menv1.lua b/tests/lua/old/menv1.lua deleted file mode 100644 index 0ca7b442f..000000000 --- a/tests/lua/old/menv1.lua +++ /dev/null @@ -1,55 +0,0 @@ -import("util.lua") -local menv = metavar_env() -assert(is_metavar_env(menv)) -local m1 = menv:mk_metavar() -local m2 = menv:mk_metavar() -print(m1, m2) -assert(m1 ~= m2) -assert(m1:is_metavar()) -assert(m2:is_metavar()) -assert(not menv:is_assigned(m1)) -assert(not menv:is_assigned(m2)) -local ctx = context():extend("x", Const("Int")) -local m3 = menv:mk_metavar(ctx) -local m4 = menv:mk_metavar(ctx, Const("Int")) -assert(not menv:is_assigned(m3)) -assert(not menv:is_assigned(m4)) -local ts1 = menv:get_timestamp() -local m5 = menv:mk_metavar() -local ts2 = menv:get_timestamp() -assert(ts2 > ts1) -print(menv:get_context(m3)) -assert(menv:get_context(m3):size() == 1) -assert(menv:get_context(m1):size() == 0) -assert(menv:get_context{"M", 3}:size() == 1) -assert(not menv:has_type(m3)) -assert(menv:has_type(m4)) -assert(menv:has_type(m4:fields())) -assert(menv:get_type(m4) == Const("Int")) -assert(menv:get_type(m4:fields()) == Const("Int")) -local f, a, b = Consts("f, a, b") -menv:assign(m1, f(a, b)) -assert(menv:is_assigned(m1)) -assert(menv:is_assigned(m1:fields())) -local menv2 = menv:copy() -local as = mk_assumption_justification(1) -menv:assign(m2, f(a, a), as) -assert(menv:is_assigned(m2)) -assert(menv:is_assigned(m2:fields())) -assert(not menv2:is_assigned(m2)) -assert(not menv2:is_assigned(m2:fields())) -assert(menv:get_justification(m1):is_null()) -assert(menv:get_justification(m1:fields()):is_null()) -assert(not menv:get_justification(m2):is_null()) -local s1, jst1 = menv:get_subst_jst(m1) -assert(s1 == f(a, b)) -assert(jst1:is_null()) -local s2, jst2 = menv:get_subst_jst(m2) -assert(s2 == f(a, a)) -assert(jst2:depends_on(as)) -assert(menv:get_subst(m1) == f(a, b)) -assert(menv:get_subst(m2:fields()) == f(a, a)) -local counter = 0 -menv:for_each_subst(function (m, s) print(m, s); counter = counter + 1 end) -assert(counter == 2) -assert(instantiate_metavars(f(m1, m2), menv) == f(f(a, b), f(a, a))) diff --git a/tests/lua/old/num2.lua b/tests/lua/old/num2.lua deleted file mode 100644 index 0a54705c7..000000000 --- a/tests/lua/old/num2.lua +++ /dev/null @@ -1,10 +0,0 @@ -assert(nVal(10):data() == mpz(10)) -assert(not pcall(function() nVal(-10) end)) -assert(iVal(10):data() == mpz(10)) -assert(iVal(-10):data() == mpz(-10)) -assert(rVal(10):data() == mpq(10)) -assert(rVal(10):data() ~= mpz(10)) -assert(rVal("10/3"):data() == mpq(10)/3) -assert(rVal("-10/3"):data() == mpq(-10)/3) -assert(Const("a"):data() == name("a")) - diff --git a/tests/lua/old/parser1.lua b/tests/lua/old/parser1.lua deleted file mode 100644 index 74ebfa026..000000000 --- a/tests/lua/old/parser1.lua +++ /dev/null @@ -1,12 +0,0 @@ -local env = environment() -local opts = options() -env:add_var("T", Type()) -local T = Const("T") -env:add_var("x", T) -env:add_var("y", T) -env:add_var("f", mk_arrow(T, mk_arrow(T, T))) -print(parse_lean("f x (f x y)", env, opts)) --- parse_lean will use the elaborator to fill missing information -local F = parse_lean("fun x, f x x", env, opts) -print(F) -print(env:type_check(F)) diff --git a/tests/lua/old/parser2.lua b/tests/lua/old/parser2.lua deleted file mode 100644 index 707c69821..000000000 --- a/tests/lua/old/parser2.lua +++ /dev/null @@ -1,27 +0,0 @@ -import("util.lua") -local env = environment() -parse_lean_cmds([[ - variable N : Type - variables x y : N - variable f : N -> N -> N - set_option pp::colors false -]], env) -local f, x, y = Consts("f, x, y") -print(env:type_check(f(x, y))) -assert(env:type_check(f(x, y)) == Const("N")) -assert(not get_options():get{"pp", "colors"}) -parse_lean_cmds([[ - set_option pp::colors true -]], env) -assert(get_options():get{"pp", "colors"}) -local o = get_options() -o:update({"lean", "pp", "notation"}, false) -assert(not o:get{"lean", "pp", "notation"}) -o = parse_lean_cmds([[ - check fun x : N, y - set_option pp::notation true - check fun x : N, y -]], env, o) -print(o) -assert(o:get{"lean", "pp", "notation"}) -assert(parse_lean("f x y", env) == f(x, y)) diff --git a/tests/lua/old/proof_builder1.lua b/tests/lua/old/proof_builder1.lua deleted file mode 100644 index 29b49dc60..000000000 --- a/tests/lua/old/proof_builder1.lua +++ /dev/null @@ -1,19 +0,0 @@ -local pb = proof_builder(function(m, a) - print("builder...") - local e = m:find("main") - print(e) - return e - end) -assert(is_proof_builder(pb)) -local a = assignment() -assert(is_assignment(a)) -local m = proof_map() -assert(#m == 0) -assert(is_proof_map(m)) -m:insert("main", Const("H")) -m:insert("subgoal", Const("H1")) -m:erase("subgoal") -assert(not pcall(function() m:find("subgoal") end)) -print(m:find("main")) -print(pb(m, a)) -assert(pb(m, a) == Const("H")) diff --git a/tests/lua/old/proof_state1.lua b/tests/lua/old/proof_state1.lua deleted file mode 100644 index 903c1e3cc..000000000 --- a/tests/lua/old/proof_state1.lua +++ /dev/null @@ -1,26 +0,0 @@ -import("util.lua") -local ps = proof_state() -local env = environment() -local Bool = Const("Bool") -env:add_var("p", Bool) -env:add_var("q", Bool) -local p, q = Consts("p, q") -local ctx = context() -ctx = ctx:extend("H1", p) -ctx = ctx:extend("H2", q) -ps = to_proof_state(env, ctx, p) -print(ps) -for n, g in ps:goals():pairs() do - assert(is_goal(g)) - print(n, g) -end -assert(#(ps:goals()) == 1) -assert(ps:goals():tail():is_nil()) -assert(ps:goals():head() == name("main")) -assert(not ps:goals():empty()) -assert(ps:precision() == precision.Precise) -local menv = ps:menv() -local pb = ps:proof_builder() -local cb = ps:cex_builder() -assert(not ps:is_proof_final_state()) -assert(not ps:is_cex_final_state()) diff --git a/tests/lua/old/proof_stats.lua b/tests/lua/old/proof_stats.lua deleted file mode 100644 index a66602d6f..000000000 --- a/tests/lua/old/proof_stats.lua +++ /dev/null @@ -1,23 +0,0 @@ -parse_lean_cmds([[ -variables a b c d e f : Nat -rewrite_set simple -add_rewrite Nat::mul_assoc Nat::mul_comm Nat::mul_left_comm Nat::add_assoc Nat::add_comm Nat::add_left_comm - Nat::distributer Nat::distributel : simple -]]) -local t = parse_lean("(a + b) * (c + d) * (e + f) * (a + b) * (c + d) * (e + f)") -local t2, pr = simplify(t, "simple") -print(t) --- Now, we traverse the proof and collect statistics on how often each theorem is used -m = splay_map() -pr:for_each( - function(e, ctx) - if e:is_app() and e:arg(0):is_constant() then - local n = e:arg(0):fields() - local c = m:find(n) - if not c then - c = 0 - end - m:insert(n, c+1) - end - end) -m:for_each(function(k, v) print(tostring(k) .. " ==> " .. tostring(v)) end) diff --git a/tests/lua/old/simp1.lua b/tests/lua/old/simp1.lua deleted file mode 100644 index fff92f267..000000000 --- a/tests/lua/old/simp1.lua +++ /dev/null @@ -1,44 +0,0 @@ -add_rewrite_rules({"Nat", "add_zerol"}) -add_rewrite_rules({"Nat", "add_zeror"}) -parse_lean_cmds([[ - variable f : Nat -> Nat -> Nat - variable g : Nat -> Nat - variable b : Nat - definition a := 1 - theorem a_eq_1 : a = 1 - := refl a - definition c := 1 - set_opaque a true - - axiom f_id (x : Nat) : f x 1 = 2*x - - axiom g_g_x (x : Nat) : (not (x = 0)) -> g (g x) = 0 -]]) -add_rewrite_rules("a_eq_1") -add_rewrite_rules("f_id") -add_rewrite_rules("eq_id") - --- set_option({"lean", "pp", "implicit"}, true) -e, pr = simplify(parse_lean('fun x, f (f x (0 + a)) (g (b + 0))')) -print(e) -print(pr) -local env = get_environment() -print(env:type_check(pr)) - -e, pr = simplify(parse_lean('forall x, let d := a + 1 in f x a >= d')) -print(e) -print(pr) -local env = get_environment() -print(env:type_check(pr)) - -e, pr = simplify(parse_lean('(fun x, f (f x (0 + a)) (g (b + 0))) b')) -print(e) -print(pr) -local env = get_environment() -print(env:type_check(pr)) - -e, pr = simplify(parse_lean('(fun x y, f x y) = f')) -print(e) -print(pr) -local env = get_environment() -print(env:type_check(pr)) diff --git a/tests/lua/old/single.lua b/tests/lua/old/single.lua deleted file mode 100644 index 204245722..000000000 --- a/tests/lua/old/single.lua +++ /dev/null @@ -1,5 +0,0 @@ -print("hello world") -local env = environment() -env:import("Int") -parse_lean_cmds([[ variables a b : Int ]], env) -print(parse_lean([[a + b + 10]], env)) diff --git a/tests/lua/old/splay1.lua b/tests/lua/old/splay1.lua deleted file mode 100644 index dec224203..000000000 --- a/tests/lua/old/splay1.lua +++ /dev/null @@ -1,7 +0,0 @@ -local s = splay_map() -assert(s:empty()) -assert(#s == 0) -s:insert(10, 1) -assert(not s:empty()) -assert(#s == 1) -assert(s:find(10) == 1) diff --git a/tests/lua/old/st1.lua b/tests/lua/old/st1.lua deleted file mode 100644 index 987ae0e11..000000000 --- a/tests/lua/old/st1.lua +++ /dev/null @@ -1,21 +0,0 @@ -f = Const("f") -a = Const("a") -t = f(a) -s = State() -s:dostring("x = 10") - -t1, t2, t3 = -s:dostring([[ -a, b = ... -print("x = " .. tostring(x)) -print("a = " .. tostring(a)) -print("b = " .. tostring(b)) -g = Const("g") -return g(b), g(g(b)), g(b, b) -]], 10, t) -print("t1: " .. tostring(t1)) -print("t2: " .. tostring(t2)) -print("t3: " .. tostring(t3)) -print(x) -print(a) -s:dostring([[ print(b) ]]) diff --git a/tests/lua/old/st2.lua b/tests/lua/old/st2.lua deleted file mode 100644 index fcbbe38dd..000000000 --- a/tests/lua/old/st2.lua +++ /dev/null @@ -1,7 +0,0 @@ --- Create a nested lua_State object -S = State() - -S:dostring([[ - flag = ... - print(flag) -]], true) diff --git a/tests/lua/old/st3.lua b/tests/lua/old/st3.lua deleted file mode 100644 index d4108511a..000000000 --- a/tests/lua/old/st3.lua +++ /dev/null @@ -1,46 +0,0 @@ -S = State() -function mk(x) - return function (y) - return x * y - end -end -f = mk(20) -S:eval([[ -g, x = ... -print("x", x) -print(g(10)) -]], f, 10) - -function mkcounter() - local x = 0 - function inc() - x = x + 1 - return x - end - function dec() - x = x - 1 - return x - end - return inc, dec -end - -inc1, dec1 = mkcounter() -print(inc1()) -print(inc1()) -print(dec1()) -print(inc1()) -print(inc1()) --- inc1 and dec1 are closures, they share the same upvalue x. --- However, when we copy inc1 and dec1 to S, we get two copies of x. -S:eval([[ - inc2, dec2, x = ... - print("in the nested state") - print("x", x) - print("incrementing", inc2()) - print("incrementing", inc2()) - print("decrementing", dec2()) -]], inc1, dec1, 10) -print(inc1()) - -S:set("h", f) -print(S:eval([[ return h(2) ]])) diff --git a/tests/lua/old/tactic1.lua b/tests/lua/old/tactic1.lua deleted file mode 100644 index b7de41b3a..000000000 --- a/tests/lua/old/tactic1.lua +++ /dev/null @@ -1,17 +0,0 @@ -import("util.lua") -local ps = proof_state() -local env = environment() -local Bool = Const("Bool") -env:add_var("p", Bool) -env:add_var("q", Bool) -local p, q = Consts("p, q") -local ctx = context() -ctx = ctx:extend("H1", p) -ctx = ctx:extend("H2", q) -ps = to_proof_state(env, ctx, p) -local ios = io_state() -print(ps) -local ltac = tactic(function(env, ios, s) - print("FIRST tactic in Lua, current state: " .. tostring(s)); - return s -end) diff --git a/tests/lua/old/template1.lua b/tests/lua/old/template1.lua deleted file mode 100644 index f3e79dfa7..000000000 --- a/tests/lua/old/template1.lua +++ /dev/null @@ -1,18 +0,0 @@ -import("util.lua") -import("template.lua") -local env = environment() -env:import("Int") -parse_lean_cmds([[ - variables a b c : Int - variables f : Int -> Int -]], env) -local a, b, c = Consts("a, b, c") -print(parse_template("%1 + f %2 + %1 + %1", {a, b}, env)) -assert(tostring(parse_template("%1 + f %2 + %1 + %1", {a, b}, env)) == "Int::add (Int::add (Int::add a (f b)) a) a") -assert(not pcall(function() print(parse_template("%1 + f %2 + %1 + %1", {a}, env)) end)) -print(parse_template("%1 + f %2 + %3 + f (f %1)", {a, b, c}, env)) -print(parse_template("%1 + f %2 + 10 + f (f %1)", {a, b, c}, env)) -assert(tostring(parse_template("%1 + f %2 + 10 + f (f %1)", {a, b, c}, env)) == "Int::add (Int::add (Int::add a (f b)) (nat_to_int 10)) (f (f a))") -set_formatter(lean_formatter(env)) -print(parse_template("%1 + f %2 + %3 + f (f %1)", {a, b, c}, env)) -assert(tostring(parse_template("%1 + f %2 + %3 + f (f %1)", {a, b, c}, env)) == "a + f b + c + f (f a)") diff --git a/tests/lua/old/ty1.lua b/tests/lua/old/ty1.lua deleted file mode 100644 index d6bf72791..000000000 --- a/tests/lua/old/ty1.lua +++ /dev/null @@ -1,12 +0,0 @@ -local env1 = environment() -local env2 = environment() -env1:add_var("N", Type()) -env1:add_var("x", Const("N")) -env2:add_var("N", Type()) -local x = Const("x") -local N = Const("N") -print(env1:infer_type(x)) -local infer1 = type_inferer(env1) -local infer2 = type_inferer(env2) -assert(env1:infer_type(x) == infer1(x)) -assert(env2:infer_type(N) == infer2(N)) diff --git a/tests/lua/old/ty2.lua b/tests/lua/old/ty2.lua deleted file mode 100644 index 4fc5361be..000000000 --- a/tests/lua/old/ty2.lua +++ /dev/null @@ -1,12 +0,0 @@ -local env = environment() -local inferer = type_inferer(env) -env:add_var("N", Type()) -local N = Const("N") -env:add_var("a", N) -local ctx = context() -ctx = extend(ctx, "x", N) -assert(inferer(Var(0), ctx) == N) -assert(not pcall(function() inferer(Var(1), ctx) end)) -inferer:clear() -assert(inferer(Var(0), ctx) == N) -assert(is_type_inferer(inferer)) diff --git a/tests/lua/old/unify1.lua b/tests/lua/old/unify1.lua deleted file mode 100644 index 82e7a50a3..000000000 --- a/tests/lua/old/unify1.lua +++ /dev/null @@ -1,30 +0,0 @@ -import("util.lua") -local f, g, a, b, c, x = Consts("f, g, a, b, c, x") -local m1 = mk_metavar("m1") -local m2 = mk_metavar("m2") -local m3 = mk_metavar("m3") -local s = fo_unify(f(m1, g(m2, c)), f(g(m2, a), g(m3, m3))) -assert(s) -assert(#s == 3) -assert(s:find(m2) == c) -assert(s:apply(f(m1, g(m2, c))) == s:apply(f(g(m2, a), g(m3, m3)))) -assert(not fo_unify(f(a), g(m2))) -function must_unify(t1, t2) - local s = fo_unify(t1, t2) - assert(s) - print(t1, t2, s:apply(t1)) - assert(s:apply(t1) == s:apply(t2)) -end -Bool = Const("Bool") -must_unify(Type(), m1) -must_unify(fun(x, Bool, x), fun(x, Bool, m1)) -must_unify(Pi(x, Bool, x), Pi(x, Bool, m1)) -must_unify(Var(0), m1) -must_unify(f(m1, m2, m3), f(m1, m1, m2)) -must_unify(mk_let("x", f(b), Var(0)), mk_let("y", f(m1), Var(0))) -assert(not fo_unify(mk_let("x", Bool, f(b), Var(0)), mk_let("y", f(m1), Var(0)))) -assert(not fo_unify(mk_let("x", f(b), Var(0)), mk_let("y", Bool, f(m1), Var(0)))) -must_unify(mk_let("x", Bool, f(b), Var(0)), mk_let("y", Bool, f(m1), Var(0))) -assert(not fo_unify(mk_let("x", Bool, f(b), Var(0)), fun(x, Bool, x))) -must_unify(iVal(10), m1) -must_unify(iVal(10), iVal(10)) diff --git a/tests/lua/opt1.lua b/tests/lua/opt1.lua deleted file mode 100644 index 5e2dd199c..000000000 --- a/tests/lua/opt1.lua +++ /dev/null @@ -1,25 +0,0 @@ --- Return true if x is an integer -function is_integer(x) - return math.floor(x) == x -end - --- Convert a table into a Lean options object -function to_options(t, prefix, opts) - if opts == nil then opts = options() end - for k, v in pairs(t) do - if type(v) == "table" then - opts = to_options(v, name(prefix, k), opts) - else - opts = opts:update(name(prefix, k), v) - end - end - return opts -end - -opts = options() -opts = opts:update(name('pp', 'colors'), false) -opts = opts:update(name('pp', 'colors'), true) -print(opts) - -opts = to_options{pp={colors=true, width=10}} -print(opts) diff --git a/tests/lua/opt2.lua b/tests/lua/opt2.lua deleted file mode 100644 index c21a50aad..000000000 --- a/tests/lua/opt2.lua +++ /dev/null @@ -1,9 +0,0 @@ -opts = options() -assert(is_options(opts)) -opts = opts:update(name('pp', 'colors'), false) -opts = opts:update(name('pp', 'colors'), true) -print(opts) -assert(is_options(opts)) -assert(not is_options(name("foo"))) -assert(not is_options("foo")) -assert(not is_options({})) diff --git a/tests/lua/opt3.lua b/tests/lua/opt3.lua deleted file mode 100644 index 472e4c19f..000000000 --- a/tests/lua/opt3.lua +++ /dev/null @@ -1,36 +0,0 @@ - - -o = options() -assert(#o == 0) -assert(o:empty()) -o = o:update_bool("tst", true) -assert(#o == 1) -assert(not o:empty()) -assert(o:contains("tst")) -assert(o:get_bool("tst") == true) -assert(o:get_bool("tst2", true) == true) -assert(o:get_bool("tst2") == false) -o = o:update_int("val", 10) -assert(#o == 2) -assert(o:contains("val")) -assert(o:get_int("val") == 10) -assert(o:get_int("val2", 20) == 20) -assert(o:get_int("val", 20) == 10) -assert(o:get_int("val2") == 0) -assert(o:get_int("val2", -10) == -10) -o = o:update_unsigned("x", 10) -assert(#o == 3) -assert(o:size() == 3) -print(o) -assert(o:get_unsigned("x") == 10) -assert(o:get_unsigned("y", -1) == 4294967295) -o = o:update_double("ratio", 10.2) -assert(o:contains("ratio")) -print(o:get_double("ratio")) -o = o:update_string("file", "foo") -assert(o:get_string("file") == "foo") -assert(not o:get(name("pp", "colors"))) -o = o:update(name("pp", "colors"), true) -assert(o:get(name("pp", "colors"))) -print(o) - diff --git a/tests/lua/opt4.lua b/tests/lua/opt4.lua deleted file mode 100644 index ca30eae60..000000000 --- a/tests/lua/opt4.lua +++ /dev/null @@ -1,4 +0,0 @@ -local o = options({"pp", "colors"}, true, {"pp", "unicode"}, false) -print(o) -assert(not pcall(function() options({"pp", "colors"}, true, {"pp", "unicode"}) end)) -assert(not pcall(function() options({"pp", "colors"}, true, {"pp", "unicodee"}, false) end)) diff --git a/tests/lua/order.lua b/tests/lua/order.lua deleted file mode 100644 index ec2be1b2a..000000000 --- a/tests/lua/order.lua +++ /dev/null @@ -1,8 +0,0 @@ -local mul = Const("mul") -local div = Const("div") -local z = Const("z") -local x = Const("x") -local y = Const("y") -local t1 = mul(z, mul(div(x, y), y)) -local t2 = mul(div(x, y), mul(z, y)) -assert(t1 < t2) diff --git a/tests/lua/place1.lua b/tests/lua/place1.lua deleted file mode 100644 index 5d03726f4..000000000 --- a/tests/lua/place1.lua +++ /dev/null @@ -1,14 +0,0 @@ -print(mk_expr_placeholder()) -print(mk_level_placeholder()) -assert(is_placeholder(mk_expr_placeholder())) -assert(not is_placeholder(Var(0))) -assert(not is_placeholder(Const("A"))) -assert(is_placeholder(mk_level_placeholder())) -assert(not is_placeholder(param_univ("l"))) -local f = Const("f") -local a = Const("a") -assert(has_placeholder(f(mk_expr_placeholder()))) -assert(not has_placeholder(f(a))) -assert(has_placeholder(f(Const("a", { mk_level_placeholder() })))) -assert(has_placeholder(mk_sort(mk_level_placeholder()))) -assert(has_placeholder(mk_sort(max_univ(1, mk_level_placeholder())))) diff --git a/tests/lua/place2.lua b/tests/lua/place2.lua deleted file mode 100644 index 7bd0f3234..000000000 --- a/tests/lua/place2.lua +++ /dev/null @@ -1,4 +0,0 @@ -print(mk_expr_placeholder()) -assert(not placeholder_type(mk_expr_placeholder())) -assert(placeholder_type(mk_expr_placeholder(Prop)) == Prop) -assert(is_placeholder(mk_expr_placeholder(Prop))) diff --git a/tests/lua/proof_state1.lua b/tests/lua/proof_state1.lua deleted file mode 100644 index aaf945d12..000000000 --- a/tests/lua/proof_state1.lua +++ /dev/null @@ -1,12 +0,0 @@ -local env = environment() -local A = Local("A", Type) -env = add_decl(env, mk_constant_assumption("eq", Pi(A, mk_arrow(A, A, Prop)))) -local eq = Const("eq") -local a = mk_local("a", "a", A) -local b = mk_local("b", "a", A) -local H = Local("H", eq(A, a, b)) -local m = mk_metavar("m", Pi(A, a, b, H, eq(A, a, b)))(A, a, b, H) -print(to_proof_state(m, eq(A, a, b))) -local s = to_proof_state(m, eq(A, a, b)) -local g = s:goals():head() -print(g) diff --git a/tests/lua/prv.lua b/tests/lua/prv.lua deleted file mode 100644 index a68a7e792..000000000 --- a/tests/lua/prv.lua +++ /dev/null @@ -1,25 +0,0 @@ -local env = environment() -env, n1 = add_private_name(env, "foo") -print(n1) -env, n2 = add_private_name(env, "foo") -print(n2) -env, n3 = add_private_name(env, {"foo", "bla"}) -print(n3) -assert(n1 ~= n2) -assert(n1 ~= n3) -assert(n2 ~= n3) -assert(hidden_to_user_name(env, n1)) -assert(hidden_to_user_name(env, n1) == name("foo")) -assert(hidden_to_user_name(env, n2) == name("foo")) -assert(hidden_to_user_name(env, n3) == name("foo", "bla")) - - -env:export("prv_mod.olean") -local env2 = import_modules("prv_mod") -assert(hidden_to_user_name(env2, n1) == name("foo")) -assert(hidden_to_user_name(env2, n2) == name("foo")) -assert(hidden_to_user_name(env2, n3) == name("foo", "bla")) -env2, n4 = add_private_name(env2, "foo") -print(n4) -assert(n1 ~= n4) -assert(not hidden_to_user_name(env, n4)) diff --git a/tests/lua/replace1.lua b/tests/lua/replace1.lua deleted file mode 100644 index 1d01377bf..000000000 --- a/tests/lua/replace1.lua +++ /dev/null @@ -1,10 +0,0 @@ -local f = Const("f") -local a = Const("a") -local b = Const("b") -local t = f(a, f(a)) -local new_t = t:replace(function(e) - if e == a then - return b - end - end) -print(new_t) diff --git a/tests/lua/res1.lua b/tests/lua/res1.lua deleted file mode 100644 index 836cc217b..000000000 --- a/tests/lua/res1.lua +++ /dev/null @@ -1,133 +0,0 @@ --- Create names for commonly used constants -local Or = Const("or") -local Not = Const("not") -local False = Const("false") - -function init_env(env) - -- Populate environment when declarations used by resolve_macro. - -- This is a 'fake' environment used only for testing. - local a = Local("a", Prop) - local b = Local("b", Prop) - local c = Local("c", Prop) - local Ha = Local("Ha", a) - local Hb = Local("Hb", b) - env = add_decl(env, mk_constant_assumption("or", mk_arrow(Prop, Prop, Prop))) - env = add_decl(env, mk_constant_assumption("not", mk_arrow(Prop, Prop))) - env = add_decl(env, mk_constant_assumption("false", Prop)) - env = add_decl(env, mk_axiom({"or", "elim"}, Pi(a, b, c, mk_arrow(Or(a, b), mk_arrow(a, c), mk_arrow(b, c), c)))) - env = add_decl(env, mk_axiom({"or", "intro_left"}, Pi(a, Ha, b, Or(a, b)))) - env = add_decl(env, mk_axiom({"or", "intro_right"}, Pi(b, a, Hb, Or(a, b)))) - env = add_decl(env, mk_axiom("absurd_elim", Pi(a, b, mk_arrow(a, Not(a), b)))) - return env -end - -function decl_bools(env, ls) - for i = 1, #ls do - env = add_decl(env, mk_constant_assumption(ls[i]:data(), Prop)) - end - return env -end - -function Consts(s) - -- Auxiliary function for creating multiple constants - local r = {} - local i = 1 - for c in string.gmatch(s, '[^ ,;\t\n]+') do - r[i] = Const(c) - i = i + 1 - end - return unpack(r) -end - -function OR(...) - -- Nary Or - local arg = {...} - if #arg == 0 then - return False - elseif #arg == 1 then - return arg[1] - else - local r = arg[#arg] - for i = #arg-1, 1, -1 do - r = Or(arg[i], r) - end - return r - end -end - -function print_types(env, ...) - local arg = {...} - local tc = type_checker(env) - for i = 1, #arg do - print(tostring(arg[i]) .. " : " .. tostring(tc:check(arg[i]))) - end -end - -function assert_some_axioms(env) - -- Assert some clauses - local l1, l2, l3, l4, l5, l6 = Consts("l1 l2 l3 l4 l5 l6") - env = decl_bools(env, {l1, l2, l3, l4, l5}) - env = add_decl(env, mk_definition("l6", Prop, l3, {opaque=false})) -- l6 is alias for l3 - env = add_decl(env, mk_axiom("H1", OR(l1, l2, Not(l3)))) - env = add_decl(env, mk_axiom("H2", OR(l2, l3, l4))) - env = add_decl(env, mk_axiom("H3", OR(Not(l1), l2, l4, l5))) - env = add_decl(env, mk_axiom("H4", OR(l4, l6, Not(l5)))) - env = add_decl(env, mk_axiom("H5", OR(Not(l4), l3))) - env = add_decl(env, mk_axiom("H6", Not(l3))) - env = add_decl(env, mk_axiom("H7", Not(l2))) - return env -end - -local env = bare_environment({trust_lvl=1}) -env = init_env(env) -env = assert_some_axioms(env) - -local l1, l2, l3, l4, l5, l6 = Consts("l1 l2 l3 l4 l5 l6") -local H1, H2, H3, H4, H5, H6, H7 = Consts("H1 H2 H3 H4 H5 H6 H7") - -local tc = type_checker(env) -print(tc:check(Or)) -print(tc:check(Const("absurd_elim"))) -print(tc:check(H4)) -local Pr1 = resolve_macro(l6, H2, H1) -local Pr2 = resolve_macro(l1, Pr1, H3) -assert(Pr1:is_macro()) -assert(Pr1:macro_num_args() == 3) -assert(Pr1:macro_arg(0) == l6) -assert(Pr1:macro_def() == Pr2:macro_def()) -assert(Pr1:data() == Pr1:macro_def()) -assert(Pr1 == mk_macro(Pr1:macro_def(), {Pr1:macro_arg(0), Pr1:macro_arg(1), Pr1:macro_arg(2)})) -assert(Pr1:macro_def():name() == name("resolve")) -assert(Pr1:macro_def():trust_level() >= 0) -print(Pr1:macro_def():hash()) -print(Pr1:macro_def()) -print("-----------") -print(tc:check(H2)) -print(tc:check(H1)) -print(tc:check(Pr1)) -print(tc:check(H3)) -print(tc:check(Pr2)) -local Pr3 = resolve_macro(l4, resolve_macro(l5, Pr2, H4), H5) -print(tc:check(Pr3)) -local Pr4 = resolve_macro(l2, resolve_macro(l3, Pr3, H6), H7) -print("-----------") -print("proof for false: ") -print_types(env, H1, H2, H3, H4, H5, H6, H7) -print(tostring(Pr4) .. " : " .. tostring(tc:check(Pr4))) - -print("----------------") -local env = bare_environment({trust_lvl=1}) -env = init_env(env) -env = assert_some_axioms(env) -local tc = type_checker(env) --- Since the trust_lvl is 0, the macro will be expanded during type checking -print(tc:whnf(Pr1)) -print(tc:check(Pr1)) -print(tc:check(Pr4)) - -print(env:normalize(Pr4)) - -local a = Const("a") -assert(not pcall(function() a:macro_num_args() end)) -assert(not pcall(function() a:let_name() end)) -assert(not pcall(function() mk_arrow(a) end)) diff --git a/tests/lua/sexpr1.lua b/tests/lua/sexpr1.lua deleted file mode 100644 index ce86da994..000000000 --- a/tests/lua/sexpr1.lua +++ /dev/null @@ -1,8 +0,0 @@ -s = sexpr(1, 2, 3) -print(s) -s = sexpr(1, 2, 3, nil) -print(s) -s = sexpr(sexpr(1, 2), sexpr(3, 4), nil) -print(s) -s = sexpr(mpz("100000000000000"), mpq(3)/2, sexpr(1, 2, 3, nil), nil) -print(s) \ No newline at end of file diff --git a/tests/lua/sexpr2.lua b/tests/lua/sexpr2.lua deleted file mode 100644 index 92865a100..000000000 --- a/tests/lua/sexpr2.lua +++ /dev/null @@ -1,32 +0,0 @@ -s = sexpr(1, 2, 3) -print(s) -s = sexpr(1, 2, 3, nil) -print(s) -s = sexpr(sexpr(1, 2), sexpr(3, 4), nil) -print(s) -s = sexpr(mpz("100000000000000"), mpq(3)/2, sexpr(1, 2, 3, nil), nil) -print(s) -print(sexpr():is_nil()) -print(sexpr(1):is_nil()) -print(sexpr(true):is_bool()) -print(sexpr(true):to_bool()) -print(sexpr(false):to_bool()) -check_error(function() sexpr(10):to_bool() end) -print(sexpr(name("foo",1)):to_name()) -check_error(function () print(sexpr(10):to_name()) end) -print(sexpr(mpq(10)/3):to_mpq()) -print(sexpr(mpz("10000000000000000000000000000000000")):to_mpz()) -print(sexpr(10, 20, 30, 40, nil):length()) -print(sexpr(10, 20, nil):head()) -print(sexpr(10, 20, nil):tail()) -print(sexpr(10, 20):head()) -print(sexpr(10, 20):tail()) -check_error(function () sexpr(10):head() end) -check_error(function () sexpr(10):tail() end) -check_error(function () sexpr(10):to_mpz() end) -check_error(function () sexpr(10):to_mpq() end) -check_error(function () sexpr(10):to_string() end) -check_error(function () sexpr(10):to_bool() end) -check_error(function () sexpr(10):to_double() end) -print(sexpr("hello"):to_string()) - diff --git a/tests/lua/sexpr3.lua b/tests/lua/sexpr3.lua deleted file mode 100644 index cca3b902f..000000000 --- a/tests/lua/sexpr3.lua +++ /dev/null @@ -1,6 +0,0 @@ -l = sexpr(1, 2, 3) -print(l) -assert(is_sexpr(l)) -assert(is_sexpr(sexpr(10))) -assert(not is_sexpr(10)) -assert(not is_sexpr({})) diff --git a/tests/lua/sexpr4.lua b/tests/lua/sexpr4.lua deleted file mode 100644 index 9f00988fc..000000000 --- a/tests/lua/sexpr4.lua +++ /dev/null @@ -1,28 +0,0 @@ -assert(sexpr("a") < sexpr("b")) -assert(sexpr("a") == sexpr("a")) -assert(sexpr("a") ~= sexpr("b")) -assert(not sexpr("a"):is_cons()) -assert(sexpr(10, 20):is_cons()) -assert(not sexpr(10, 20):is_list()) -assert(sexpr(10, 20, nil):is_list()) -assert(not sexpr(10, 20):is_atom()) -assert(not sexpr(10, 20):is_atom()) -assert(sexpr("a"):is_atom()) -assert(sexpr(mpz(10)):is_atom()) -assert(sexpr("a"):is_string()) -assert(not sexpr(mpz(10)):is_string()) -assert(sexpr(10):is_int()) -assert(not sexpr(10, 20, 30):is_int()) -assert(not sexpr(10):is_name()) -assert(not sexpr("a"):is_name()) -assert(sexpr(name("a")):is_name()) -assert(not sexpr(10):is_mpz()) -assert(not sexpr(mpq(10)):is_mpz()) -assert(sexpr(mpz(10)):is_mpz()) -assert(not sexpr(10):is_mpq()) -assert(not sexpr(mpz(10)):is_mpq()) -assert(sexpr(mpq(10)):is_mpq()) -check_error(function() sexpr(10):length() end) -assert(sexpr(10):to_int() == 10) - - diff --git a/tests/lua/sexpr5.lua b/tests/lua/sexpr5.lua deleted file mode 100644 index 132ddfe4c..000000000 --- a/tests/lua/sexpr5.lua +++ /dev/null @@ -1,15 +0,0 @@ -function display_leaves(s) - if s:kind() == sexpr_kind.Cons then - local h, t = s:fields() - display_leaves(h) - display_leaves(t) - else - print(s) - assert(s:kind() == sexpr_kind.Nil or s:kind() == sexpr_kind.String or tostring(s:fields()) == tostring(s)) - assert(s:kind() ~= sexpr_kind.String or '"' .. tostring(s:fields()) .. '"' == tostring(s)) - end -end - -local l = sexpr(sexpr(1), sexpr(name("a")), sexpr(mpz(10)), sexpr(mpq(3)/2), sexpr(1, 2, 3), sexpr(sexpr("a"), sexpr(10, 2)), sexpr(), sexpr("foo")) -print(l) -display_leaves(l) diff --git a/tests/lua/sexpr_bug1.lua b/tests/lua/sexpr_bug1.lua deleted file mode 100644 index 021effc70..000000000 --- a/tests/lua/sexpr_bug1.lua +++ /dev/null @@ -1,20 +0,0 @@ -local s = sexpr(Local("a", Prop), Local("b", Prop)) -print(s) -local a, b = s:fields() -print(a) -print(b) -assert(a ~= Local("a", Prop)) -assert(a:to_external() == Local("a", Prop)) -assert(a:fields() == Local("a", Prop)) -assert(is_expr(a:to_external())) - -local s = sexpr(Local("a", Prop), Local("b", Prop)) -local s = sexpr({}) - -local s1 = sexpr(Local("a", Prop), Local("b", Prop)) -local s2 = sexpr(Local("a", Prop), Local("c", Prop)) -assert(Local("b", Prop) > Local("c", Prop)) -assert(s1 > s2) -assert(s2 < s1) -assert(s2 == sexpr(Local("a", Prop), Local("c", Prop))) - diff --git a/tests/lua/simple.lua b/tests/lua/simple.lua deleted file mode 100644 index 09678cd03..000000000 --- a/tests/lua/simple.lua +++ /dev/null @@ -1,2 +0,0 @@ -print("hello") -x = 10 diff --git a/tests/lua/slow/extra.lua b/tests/lua/slow/extra.lua deleted file mode 100644 index ccd3ccac8..000000000 --- a/tests/lua/slow/extra.lua +++ /dev/null @@ -1,11 +0,0 @@ --- Execute f, and make sure is throws an error -function check_error(f) - ok, msg = pcall(function () - f() - end) - if ok then - error("unexpected success...") - else - print("caught expected error: ", msg) - end -end diff --git a/tests/lua/slow/mod2.lua b/tests/lua/slow/mod2.lua deleted file mode 100644 index d307f4da9..000000000 --- a/tests/lua/slow/mod2.lua +++ /dev/null @@ -1,46 +0,0 @@ -function mk_env(prefix, sz) - prefix = name(prefix) - local env = environment() - local A = Local("A", mk_sort(0)) - local x = Local("x", A) - env = add_decl(env, mk_definition(name(prefix, "id"), Pi(A, mk_arrow(A, A)), Fun(A, x, x), {opaque=false})) - env = add_decl(env, mk_constant_assumption(name(prefix, "P"), Prop)) - local P = Const(name(prefix, "P")) - local id = Const(name(prefix, "id")) - env = add_decl(env, mk_axiom(name(prefix, "Ax"), P)) - local Ax = Const(name(prefix, "Ax")) - for i = 1, sz do - local pr = id(P, Ax) - for j = 1, i do - pr = id(P, pr) - end - local pr2 = id(P, pr) - env = add_decl(env, mk_theorem(name(prefix, "T", i), P, pr)) - end - return env -end - -local mod_names = {} - -function export_env(i, sz) - local prefix = "mod" .. tostring(i) - local mname = "mod2_" .. prefix - mod_names[#mod_names + 1] = mname - mk_env(prefix, sz):export(mname .. ".olean") -end - -local NumMods=40 -local NumThs=150 -for i = 1, NumMods do - export_env(i, NumThs) -end - -print("importing...") -local initt = os.clock() -local env2 = import_modules(mod_names, {num_threads=4, keep_proofs=true}) -print(string.format("elapsed time: %.2f\n", os.clock() - initt)) -for i = 1, NumMods do - for j = 1, NumThs do - assert(env2:get({"mod" .. tostring(i), "T", j}):is_theorem()) - end -end diff --git a/tests/lua/slow/t1.lua b/tests/lua/slow/t1.lua deleted file mode 100644 index 3a5f40d6a..000000000 --- a/tests/lua/slow/t1.lua +++ /dev/null @@ -1,12 +0,0 @@ -function mk_big(f, depth, val) - if depth == 1 then - return Const{"foo", val} - else - return f(mk_big(f, depth - 1, 2 * val), mk_big(f, depth - 1, 2 * val + 1)) - end -end - -local f = Const("f") -local r1 = mk_big(f, 18, 0) -local r2 = mk_big(f, 18, 0) -assert(r1 == r2) diff --git a/tests/lua/sorted.lua b/tests/lua/sorted.lua deleted file mode 100644 index 38ac74b68..000000000 --- a/tests/lua/sorted.lua +++ /dev/null @@ -1,30 +0,0 @@ -local env = environment() -local l = mk_param_univ("l") -local A = Local("A", mk_sort(l)) -local U_l = mk_sort(l) -local U_l1 = mk_sort(max_univ(l, 1)) -- Make sure U_l1 is not Prop -local list_l = Const("list", {l}) -- list.{l} - -env = add_inductive(env, - "list", {l}, 1, Pi(A, U_l1), - "nil", Pi(A, list_l(A)), - "cons", Pi(A, mk_arrow(A, list_l(A), list_l(A)))) - -local cons_l = Const("cons", {l}) -local nil_l = Const("nil", {l}) -local is_sorted_l = Const("is_sorted", {l}) -local a = Local("a", A) -local lt = Local("lt", mk_arrow(A, A, Prop)) -local a1 = Local("a1", A) -local a2 = Local("a2", A) -local t = Local("t", list_l(A)) -local Hlt = Local("H", lt(a1, a2)) -local Hs = Local("Hs", is_sorted_l(A, lt, cons_l(A, a2, t))) - -env = add_inductive(env, - "is_sorted", {l}, 2, Pi(A, lt, mk_arrow(list_l(A), Prop)), - "is_sorted_nil", Pi(A, lt, is_sorted_l(A, lt, nil_l(A))), - "is_sorted_cons_nil", Pi(A, lt, a, is_sorted_l(A, lt, cons_l(A, a, nil_l(A)))), - "is_sorted_cons_cons", Pi(A, lt, a1, a2, t, Hlt, Hs, is_sorted_l(A, lt, cons_l(A, a1, cons_l(A, a2, t))))) - -print(env:find({"is_sorted", "rec"}):type()) diff --git a/tests/lua/subst1.lua b/tests/lua/subst1.lua deleted file mode 100644 index 3724e5cd1..000000000 --- a/tests/lua/subst1.lua +++ /dev/null @@ -1,34 +0,0 @@ -local m = mk_metavar("m", Prop) -local s = substitution() -assert(not s:is_assigned(m)) -assert(not s:is_expr_assigned("m")) -assert(not s:is_level_assigned("m")) -local f = Const("f") -local g = Const("g") -local a = Const("a") -local t = f(f(a)) -s:assign(m, t) -assert(s:is_assigned(m)) -assert(s:is_expr_assigned("m")) -assert(not s:is_level_assigned("m")) -assert(s:instantiate(g(m)) == g(t)) -s:assign("m", a) -assert(s:instantiate(g(m)) == g(a)) -local l = mk_level_one() -local u = mk_meta_univ("u") -s:assign(u, l) -assert(s:is_assigned(u)) -assert(s:is_level_assigned("u")) -assert(not s:is_expr_assigned("u")) -local m2 = mk_metavar("m2", Prop) -s:assign(m2, f(m)) -assert(s:is_expr_assigned("m")) --- m is assigned, so it is does not occur in f(m2) --- assert(s:occurs_expr("m", f(m2))) -print(s:instantiate(mk_sort(u))) -assert(s:instantiate(mk_sort(u)) == mk_sort(l)) -local s = substitution() -local m2 = mk_metavar("m2", Prop) -s:assign(m2, f(m)) -assert(not s:is_expr_assigned("m")) -assert(s:occurs_expr("m", f(m2))) diff --git a/tests/lua/tactic1.lua b/tests/lua/tactic1.lua deleted file mode 100644 index ab5fc4086..000000000 --- a/tests/lua/tactic1.lua +++ /dev/null @@ -1,9 +0,0 @@ -local env = environment() -local A = Local("A", Type) -env = add_decl(env, mk_constant_assumption("eq", Pi(A, mk_arrow(A, A, Prop)))) -local eq = Const("eq") -local a = Local("a", A) -local b = Local("b", A) -local H = Local("H", eq(A, a, b)) -local m = mk_metavar("m", Pi(A, a, b, H, eq(A, a, b)))(A, a, b, H) -local s = to_proof_state(m, eq(A, a, b)) diff --git a/tests/lua/tag1.lua b/tests/lua/tag1.lua deleted file mode 100644 index fc025d70f..000000000 --- a/tests/lua/tag1.lua +++ /dev/null @@ -1,17 +0,0 @@ -local f = Const("f") -local x = Local("x", Prop) -local a = Const("a") -local t1 = f(x, a, Var(1)) -local t2 = Fun(x, t1) -assert(not t2:tag()) -assert(not t2:binding_body():tag()) -t2:set_tag(2) -t2:binding_body():set_tag(1) -assert(t2:tag() == 2) -assert(t2:binding_body():tag() == 1) -print(t2) -local new_t2 = t2:instantiate(Const("b")) -assert(new_t2:tag() == 2) -assert(new_t2:binding_body():tag() == 1) -assert(not (t2 == new_t2)) - diff --git a/tests/lua/tc1.lua b/tests/lua/tc1.lua deleted file mode 100644 index f152bd1bb..000000000 --- a/tests/lua/tc1.lua +++ /dev/null @@ -1,23 +0,0 @@ -local env = bare_environment() -local g = name_generator("tst") -local tc = type_checker(env, g) -assert(is_type_checker(tc)) -local a = Local("a", Prop) -local t = Fun(a, a) -local b = Const("b") -print(t(b)) -assert(tc:whnf(t(b)) == b) -assert(tc:check(Prop) == mk_sort(mk_level_one())) -print(tc:infer(t)) -local m = mk_metavar("m1", mk_metavar("m2", mk_sort(mk_meta_univ("u")))) -print(tc:infer(m)) - -local tc2 = type_checker(env, g) -local t2 = Fun(a, m(a)) -print("---------") -print("t2: ") -print(t2) -print("check(t): ") -print(tc2:check(t)) -print("check(t2): ") -print(tc2:check(t2)) diff --git a/tests/lua/tc2.lua b/tests/lua/tc2.lua deleted file mode 100644 index 46333764c..000000000 --- a/tests/lua/tc2.lua +++ /dev/null @@ -1,68 +0,0 @@ -local env = environment() -local l = mk_param_univ("l") -local A = Local("A", mk_sort(l)) -local a = Local("a", A) -local b = Local("b", A) -local P = Local("P", mk_arrow(A, Prop)) -env = add_decl(env, mk_definition("id", {l}, - Pi(A, mk_arrow(A, mk_arrow(A, Prop))), - Fun(A, a, b, Pi(P, mk_arrow(P(a), P(b)))))) -local id_l = Const("id", {l}) -local H = Local("H", P(a)) -env = add_decl(env, mk_theorem("refl", {l}, - Pi(A, a, id_l(A, a, a)), - Fun(A, a, P, H, H))) -local H1 = Local("H1", id_l(A, a, b)) -local H2 = Local("H2", P(a)) -env = add_decl(env, mk_theorem("subst", {l}, - Pi(A, P, a, b, H1, H2, P(b)), - Fun(A, P, a, b, H1, H2, H1(P, H2)))) -local refl_l = Const("refl", {l}) -local subst_l = Const("subst", {l}) -local x = Local("x", A) -local H = Local("H", id_l(A, a, b)) -env = add_decl(env, mk_theorem("symm", {l}, - Pi(A, a, b, H, id_l(A, b, a)), - Fun(A, a, b, H, - subst_l(A, Fun(x, id_l(A, x, a)), a, b, H, refl_l(A, a))))) -local c = Local("c", A) -local H1 = Local("H1", id_l(A, a, b)) -local H2 = Local("H2", id_l(A, b, c)) -env = add_decl(env, mk_theorem("trans", {l}, - Pi(A, a, b, c, H1, H2, id_l(A, a, c)), - Fun(A, a, b, c, H1, H2, - subst_l(A, Fun(x, id_l(A, a, x)), b, c, H2, H1)))) -local symm_l = Const("symm", {l}) -local trans_l = Const("trans", {l}) -print(env:get("trans"):value()) -env = env:add_universe("u") -local u = mk_global_univ("u") -local tc = type_checker(env) -print(tc:check(Const("trans", {u}))) - -local id_u = Const("id", {u}) -local refl_u = Const("refl", {u}) -local subst_u = Const("subst", {u}) -local symm_u = Const("symm", {u}) -local trans_u = Const("trans", {u}) -local A = Local("A", mk_sort(u)) -local d = Local("d", A) -local H1 = Local("H1", id_u(A, b, a)) -local H2 = Local("H2", id_u(A, b, c)) -local H3 = Local("H3", id_u(A, c, d)) -print(tc:check(Fun(A, a, b, c, d, H1, H2, H3, - trans_u(A, a, b, d, - symm_u(A, b, a, H1), - trans_u(A, b, c, d, H2, H3))))) -local g = name_generator("tst") -local tc2 = type_checker(env, g) -print("=================") -local A = Local("A", mk_sort(u)) -local mf_ty = mk_metavar("f_ty", Pi(A, mk_sort(mk_meta_univ("l_f")))) -local f = Local("f", mf_ty(A)) -local a = Local("a", A) -local mA1 = mk_metavar("A1", Pi(A, f, a, mk_sort(mk_meta_univ("l_A1")))) -print(tc2:check(Fun(A, f, a, - id_u(mA1(A, f, a), f(a), a)))) - - diff --git a/tests/lua/tc3.lua b/tests/lua/tc3.lua deleted file mode 100644 index 22656b0c8..000000000 --- a/tests/lua/tc3.lua +++ /dev/null @@ -1,18 +0,0 @@ -local env = bare_environment() -local t1 = mk_lambda("A", Type, mk_lambda("a", Var(0), Var(0)), binder_info(true)) -local t2 = mk_lambda("A", Type, mk_lambda("a", Var(0), Var(0))) -print(t1) -print(t2) -local tc = type_checker(env) -local T1 = mk_pi("A", Type, mk_arrow(Var(0), Var(1)), binder_info(true)) -local T2 = mk_pi("A", Type, mk_arrow(Var(0), Var(1))) -print(T1) -print(T2) -assert(T1 == T2) -- The default equality ignores binder information -assert(not (T1:is_bi_equal(T2))) -print(tc:check(t1)) -print(tc:check(t2)) -assert(tc:check(t1):binding_info():is_implicit()) -assert(not tc:check(t2):binding_info():is_implicit()) -assert(tc:check(t1):is_bi_equal(T1)) -assert(tc:check(t2):is_bi_equal(T2)) diff --git a/tests/lua/tc4.lua b/tests/lua/tc4.lua deleted file mode 100644 index d87215299..000000000 --- a/tests/lua/tc4.lua +++ /dev/null @@ -1,17 +0,0 @@ -local env = bare_environment() -env = add_decl(env, mk_constant_assumption("or", mk_arrow(Prop, Prop, Prop))) -env = add_decl(env, mk_constant_assumption("A", Prop)) -local Or = Const("or") -local A = Const("A") -local B = Const("B") -local tc = type_checker(env) -local F = Or(A, B) -assert(tc:infer(F) == Prop) -assert(not pcall(function() - -- The following test must fail since B is not - -- declared in env. - -- This test make sure that infer and check are - -- not sharing the same cache. - print(tc:check(F)) - end -)) diff --git a/tests/lua/tc5.lua b/tests/lua/tc5.lua deleted file mode 100644 index 15a2ec2fa..000000000 --- a/tests/lua/tc5.lua +++ /dev/null @@ -1,44 +0,0 @@ -local env = bare_environment() -env = add_decl(env, mk_constant_assumption("A", Prop)) -env = add_decl(env, mk_constant_assumption("T", Type)) -env = add_decl(env, mk_definition("B2", Type, Prop, {opaque=false})) -env = add_decl(env, mk_constant_assumption("C", Const("B2"))) -env = add_decl(env, mk_definition("BB", Type, mk_arrow(Prop, Prop), {opaque=false})) -local tc = type_checker(env) -assert(tc:is_prop(Const("A"))) -assert(tc:is_prop(Const("C"))) -assert(not tc:is_prop(Const("T"))) -assert(not tc:is_prop(Const("B2"))) -print(tc:check(mk_lambda("x", mk_metavar("m", mk_metavar("t", mk_sort(mk_meta_univ("l")))), Var(0)))) -print(tc:ensure_sort(Const("B2"))) -assert(not pcall(function() - print(tc:ensure_sort(Const("A"))) - end -)) -print(tc:ensure_pi(Const("BB"))) -assert(not pcall(function() - print(tc:ensure_pi(Const("A"))) - end -)) -assert(not pcall(function() - env = add_decl(env, mk_constant_assumption("A", mk_local("l1", Prop))) - end -)) -assert(not pcall(function() - print(tc:check(Let("x", Type, Const("A"), Var(0)))) - end -)) -assert(not pcall(function() - print(tc:check(mk_lambda("x", Prop, Var(0))(Type))) - end -)) -assert(not pcall(function() - print(tc:check(Var(0))) - end -)) - -assert(tc:check(mk_pi("x", Prop, Var(0))) == Prop) - -local env = bare_environment({impredicative=false}) -local tc = type_checker(env) -assert(tc:check(mk_pi("x", Prop, Var(0))) == Type) diff --git a/tests/lua/tc6.lua b/tests/lua/tc6.lua deleted file mode 100644 index 32a19c3c4..000000000 --- a/tests/lua/tc6.lua +++ /dev/null @@ -1,3 +0,0 @@ -local env = environment() -local l = mk_param_univ("l") -check_error(function() env = add_decl(env, mk_constant_assumption("A", {l, l}, mk_sort(l))) end) diff --git a/tests/lua/tc7.lua b/tests/lua/tc7.lua deleted file mode 100644 index cb9c29783..000000000 --- a/tests/lua/tc7.lua +++ /dev/null @@ -1,21 +0,0 @@ -local env = environment() -env = add_decl(env, mk_constant_assumption("N", Type)) -local N = Const("N") -env = add_decl(env, mk_constant_assumption("f", mk_arrow(N, N))) -env = add_decl(env, mk_constant_assumption("g", mk_arrow(N, N))) -env = add_decl(env, mk_constant_assumption("a", N)) -local f = Const("f") -local g = Const("g") -local x = Local("x", N) -env = add_decl(env, mk_definition("h", mk_arrow(N, N), Fun(x, f(x)), {opaque=false})) -local h = Const("h") -local a = Const("a") -local m1 = mk_metavar("m1", N) -local ngen = name_generator("tst") -local tc = type_checker(env, ngen) -assert(not tc:is_def_eq(f(m1), g(a))) -assert(not tc:is_def_eq(f(m1), a)) -assert(not tc:is_def_eq(f(a), a)) -assert(not tc:is_def_eq(mk_lambda("x", N, Var(0)), h(m1))) -assert(tc:is_def_eq(h(a), f(a))) -assert(tc:is_def_eq(h(a), f(m1))) diff --git a/tests/lua/tc8.lua b/tests/lua/tc8.lua deleted file mode 100644 index 3c364e035..000000000 --- a/tests/lua/tc8.lua +++ /dev/null @@ -1,23 +0,0 @@ -local env = environment() -local N = Const("N") -env = add_decl(env, mk_constant_assumption("N", Type)) -env = add_decl(env, mk_constant_assumption("f", mk_arrow(N, N))) -env = add_decl(env, mk_constant_assumption("a", N)) -local f = Const("f") -local a = Const("a") -local m1 = mk_metavar("m1", mk_metavar("m2", mk_sort(mk_meta_univ("l")))) -local ngen = name_generator("tst") -local tc = type_checker(env, ngen) - -function test_check(e) - t, cs = tc:check(e) - print(tostring(e) .. " : " .. tostring(t)) - cs = cs:linearize() - for i = 1, #cs do - print(" >> " .. tostring(cs[i])) - end -end - -test_check(f(m1)) -test_check(f(f(m1))) -test_check(f(m1)) diff --git a/tests/lua/tc_bug1.lua b/tests/lua/tc_bug1.lua deleted file mode 100644 index 5ec467e18..000000000 --- a/tests/lua/tc_bug1.lua +++ /dev/null @@ -1,59 +0,0 @@ -local env = environment() -local N = Const("N") -local p = Const("p") -local q = Const("q") -local a = Const("a") -local b = Const("b") -local f = Const("f") -local H1 = Const("H1") -local H2 = Const("H2") -local And = Const("and") -local and_intro = Const("and_intro") -local A = Local("A", Prop) -local B = Local("B", Prop) -local C = Local("C", Prop) -env = add_decl(env, mk_constant_assumption("N", Type)) -env = add_decl(env, mk_constant_assumption("p", mk_arrow(N, N, Prop))) -env = add_decl(env, mk_constant_assumption("q", mk_arrow(N, Prop))) -env = add_decl(env, mk_constant_assumption("f", mk_arrow(N, N))) -env = add_decl(env, mk_constant_assumption("a", N)) -env = add_decl(env, mk_constant_assumption("b", N)) -env = add_decl(env, mk_constant_assumption("and", mk_arrow(Prop, Prop, Prop))) -env = add_decl(env, mk_constant_assumption("and_intro", Pi(A, B, mk_arrow(A, B, And(A, B))))) -env = add_decl(env, mk_constant_assumption("foo_intro", Pi(A, B, C, mk_arrow(B, B)))) -env = add_decl(env, mk_constant_assumption("foo_intro2", Pi(A, B, C, mk_arrow(B, B)))) -env = add_decl(env, mk_axiom("Ax1", q(a))) -env = add_decl(env, mk_axiom("Ax2", q(a))) -env = add_decl(env, mk_axiom("Ax3", q(b))) -local Ax1 = Const("Ax1") -local Ax2 = Const("Ax2") -local Ax3 = Const("Ax3") -local foo_intro = Const("foo_intro") -local foo_intro2 = Const("foo_intro2") -local ng = name_generator("foo") -local tc = type_checker(env, ng) -local m1 = mk_metavar("m1", Prop) -print("before is_def_eq") -local tc = type_checker(env, ng) -r, cs = tc:is_def_eq(foo_intro(m1, q(a), q(a), Ax1), foo_intro(q(a), q(a), q(a), Ax2)) -assert(r) -cs = cs:linearize() -assert(#cs == 1) -assert(cs[1]:lhs() == m1) -assert(cs[1]:rhs() == q(a)) -local tc = type_checker(env, ng) -print(tostring(foo_intro) .. " : " .. tostring(tc:check(foo_intro))) -print(tostring(foo_intro2) .. " : " .. tostring(tc:check(foo_intro2))) -assert(tc:is_def_eq(foo_intro, foo_intro2)) -print("before is_def_eq2") -local r, cs = tc:is_def_eq(foo_intro(m1, q(a), q(b), Ax1), foo_intro2(q(a), q(a), q(a), Ax2)) -assert(r) -cs = cs:linearize() -assert(#cs == 0) -local tc = type_checker(env, ng) -print("before failure") -assert(not pcall(function() print(tc:check(and_intro(m1, q(a), Ax1, Ax3))) end)) -print("before success") -local t, cs = tc:check(and_intro(m1, q(a), Ax1, Ax2)) -cs = cs:linearize() -assert(#cs == 1) diff --git a/tests/lua/test.sh b/tests/lua/test.sh deleted file mode 100755 index d8df10a6e..000000000 --- a/tests/lua/test.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -cd "$(dirname "$0")" -if [ $# -ne 1 ]; then - echo "Usage: test.sh [lean-executable-path]" - exit 1 -fi -ulimit -s unlimited -LEAN=$1 -NUM_ERRORS=0 -for f in *.lua; do - echo "-- testing $f" - if "$LEAN" "extra.lua" "$f" > "$f.produced.out"; then - echo "-- worked" - else - echo "ERROR executing $f, produced output is at $f.produced.out" - NUM_ERRORS=$(($NUM_ERRORS+1)) - fi -done -if [ $NUM_ERRORS -gt 0 ]; then - echo "-- Number of errors: $NUM_ERRORS" - exit 1 -else - echo "-- Passed" - exit 0 -fi diff --git a/tests/lua/test_single.sh b/tests/lua/test_single.sh deleted file mode 100755 index c604486ba..000000000 --- a/tests/lua/test_single.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -if [ $# -ne 2 ]; then - echo "Usage: test_single.sh [lean-executable-path] [file]" - exit 1 -fi -ulimit -s unlimited -LEAN=$1 -f=$2 -echo "-- testing $f" -if "$LEAN" extra.lua "$f" > "$f.produced.out"; then - echo "-- worked" - exit 0 -else - echo "ERROR executing $f, produced output:" - cat "$f.produced.out" - exit 1 -fi diff --git a/tests/lua/token_table.lua b/tests/lua/token_table.lua deleted file mode 100644 index 6b6b2d251..000000000 --- a/tests/lua/token_table.lua +++ /dev/null @@ -1,45 +0,0 @@ -function display_token_table(s) - s:for_each(function(k, cmd, val, prec) - io.write(k) - if cmd then - io.write(" [command]") - end - print(" => " .. tostring(val) .. " " .. tostring(prec)) - end) -end - -function token_table_size(s) - local r = 0 - s:for_each(function() r = r + 1 end) - return r -end - -local s = token_table() -assert(is_token_table(s)) -assert(token_table_size(s) == 0) -s = s:add_command_token("test", "tst1") -s = s:add_command_token("tast", "tst2") -s = s:add_command_token("tests", "tst3") -s = s:add_command_token("fests", "tst4") -s = s:add_command_token("tes", "tst5") -s = s:add_token("**", "**", 65) -s = s:add_token("**-", "ttimeminus") -assert(token_table_size(s) == 7) -display_token_table(s) - - -print("========") -local s2 = default_token_table() -display_token_table(s2) -assert(token_table_size(s2) > 0) -local sz1 = token_table_size(s) -local sz2 = token_table_size(s2) -s2 = s2:merge(s) -assert(token_table_size(s2) == sz1 + sz2) -s2 = s2:find("t"):find("e") -print("========") -display_token_table(s2) -assert(token_table_size(s2) == 3) -s2 = s2:find("s") -local cmd, val, prec = s2:value_of() -assert(val == name("tst5")) diff --git a/tests/lua/unify1.lua b/tests/lua/unify1.lua deleted file mode 100644 index f202315ee..000000000 --- a/tests/lua/unify1.lua +++ /dev/null @@ -1,57 +0,0 @@ -function test_unify_simple(lhs, rhs, expected) - print(tostring(lhs) .. " =?= " .. tostring(rhs) .. ", expected: " .. tostring(expected)) - s = substitution() - r = unify_simple(s, lhs, rhs, justification()) - if r == unify_status.Solved then - s:for_each_expr(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - s:for_each_level(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - end - if r ~= expected then print("r: " .. r) end - assert(r == expected) -end - -local f = Const("f") -local a = Const("a") -local l1 = mk_local("l1", "x", Prop) -local l2 = mk_local("l2", "y", Prop) -local l3 = mk_local("l3", "z", Prop) -local m = mk_metavar("m", Prop) - -test_unify_simple(m(l1, l2), f(f(a, l1), l1), unify_status.Solved) -test_unify_simple(m(l1, l2), m(l1, l2), unify_status.Solved) -test_unify_simple(m(l1, l2), m(l2, l2), unify_status.Unsupported) -test_unify_simple(m(l1, l2), f(f(l2, l1), l1), unify_status.Solved) -test_unify_simple(m(l1, a), f(f(a), l1), unify_status.Unsupported) -test_unify_simple(f(m, a), f(f(a), l1), unify_status.Unsupported) -test_unify_simple(m(l1, l2), f(f(m), l1), unify_status.Failed) -test_unify_simple(m(l1, l2), f(f(l3), l1), unify_status.Failed) -test_unify_simple(m, f(a), unify_status.Solved) -test_unify_simple(f(a), f(a), unify_status.Solved) -test_unify_simple(f(a), f(f(a)), unify_status.Failed) -test_unify_simple(f(f(a, l1), l1), m(l1, l2), unify_status.Solved) -test_unify_simple(m(l1, l1), f(f(l2, l1), l1), unify_status.Unsupported) -test_unify_simple(m(l1, l2, l1), f(f(l2, l1), l1), unify_status.Unsupported) -test_unify_simple(m(l1, l2), Fun(l3, f(f(a, l1), l3)), unify_status.Solved) - -local zero = level() -local one = zero+1 -local l = mk_param_univ("l") -local u = mk_global_univ("u") -local m = mk_meta_univ("m") -test_unify_simple(m+1, u+1, unify_status.Solved) -test_unify_simple(u+1, u+1, unify_status.Solved) -test_unify_simple(u+1, m+1, unify_status.Solved) -test_unify_simple(m, u+1, unify_status.Solved) -test_unify_simple(m, max_univ(u, l), unify_status.Solved) -test_unify_simple(max_univ(u, l), max_univ(u, l), unify_status.Solved) -test_unify_simple(m+1, m+1, unify_status.Solved) -test_unify_simple(l, l+1, unify_status.Failed) -test_unify_simple(m, m+1, unify_status.Failed) -test_unify_simple(m, max_univ(m, u), unify_status.Unsupported) -test_unify_simple(m, max_univ(m, u)+1, unify_status.Failed) -test_unify_simple(m+2, m+1, unify_status.Failed) -test_unify_simple(u+2, m+1, unify_status.Solved) diff --git a/tests/lua/unify2.lua b/tests/lua/unify2.lua deleted file mode 100644 index 159225617..000000000 --- a/tests/lua/unify2.lua +++ /dev/null @@ -1,32 +0,0 @@ -function test_unify(env, lhs, rhs, num_s) - print(tostring(lhs) .. " =?= " .. tostring(rhs) .. ", expected: " .. tostring(num_s)) - local ss = unify(env, lhs, rhs, name_generator(), true, substitution(), options()) - local n = 0 - for s in ss do - print("solution: ") - s:for_each_expr(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - s:for_each_level(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - n = n + 1 - end - if num_s ~= n then print("n: " .. n) end - assert(num_s == n) -end - -local env = environment() -env = add_decl(env, mk_constant_assumption("N", Type)) -local N = Const("N") -env = add_decl(env, mk_constant_assumption("f", mk_arrow(N, N, N))) -env = add_decl(env, mk_constant_assumption("a", N)) -local f = Const("f") -local a = Const("a") -local l1 = mk_local("l1", "x", N) -local l2 = mk_local("l2", "y", N) -local l3 = mk_local("l3", "z", N) -local m = mk_metavar("m", mk_arrow(N, N, N)) -test_unify(env, m(l1, l2), f(f(a, l1), l1), 1) -test_unify(env, f(m(l1, l2), l1), f(f(a, l1), l1), 1) -test_unify(env, f(m(l1, l2), a), f(f(a, l1), l1), 0) diff --git a/tests/lua/unify3.lua b/tests/lua/unify3.lua deleted file mode 100644 index be7076a8a..000000000 --- a/tests/lua/unify3.lua +++ /dev/null @@ -1,16 +0,0 @@ -local env = environment() -local group = Const("group") -local carrier = Const("carrier") -local real = Const("real") -local nat = Const("nat") -env = add_decl(env, mk_constant_assumption("group", mk_sort(2))) -env = add_decl(env, mk_constant_assumption("carrier", mk_arrow(group, Type))) -env = add_decl(env, mk_constant_assumption("real", Type)) -env = add_decl(env, mk_constant_assumption("nat", Type)) -env = add_decl(env, mk_constant_assumption("real_group", group)) -env = add_decl(env, mk_constant_assumption("nat_group", group)) -local real_group = Const("real_group") -local nat_group = Const("nat_group") -local m = mk_metavar("m", mk_metavar("m_ty", mk_sort(mk_meta_univ("u")))) -local cs = { mk_eq_cnstr(carrier(m), real) } -assert(not unify(env, cs, name_generator())()) diff --git a/tests/lua/unify4.lua b/tests/lua/unify4.lua deleted file mode 100644 index b782172ef..000000000 --- a/tests/lua/unify4.lua +++ /dev/null @@ -1,26 +0,0 @@ -function test_unify(env, m, lhs, rhs, num_s) - print(tostring(lhs) .. " =?= " .. tostring(rhs) .. ", expected: " .. tostring(num_s)) - local ss = unify(env, lhs, rhs, name_generator(), true, substitution(), options()) - local n = 0 - for s in ss do - print("solution: " .. tostring(s:instantiate(m))) - n = n + 1 - end - if num_s ~= n then print("n: " .. n) end - assert(num_s == n) -end - -local env = environment() -env = add_decl(env, mk_constant_assumption("N", Type)) -local N = Const("N") -env = add_decl(env, mk_constant_assumption("f", mk_arrow(N, N, N))) -env = add_decl(env, mk_constant_assumption("a", N)) -local f = Const("f") -local a = Const("a") -local l1 = mk_local("l1", "x", N) -local l2 = mk_local("l2", "y", N) -local l3 = mk_local("l3", "z", N) -local m = mk_metavar("m", mk_arrow(N, N, mk_metavar("m_type", mk_arrow(N, N, mk_sort(mk_meta_univ("u"))))(Var(1), Var(0)))) -test_unify(env, m, m(l1, l1), f(f(a, l1), l1), 4) -print("-----------------") -test_unify(env, m, m(l1, l1), mk_lambda("z", N, f(l1, f(Var(0), a))), 2) diff --git a/tests/lua/unify5.lua b/tests/lua/unify5.lua deleted file mode 100644 index 241589f3e..000000000 --- a/tests/lua/unify5.lua +++ /dev/null @@ -1,35 +0,0 @@ -local env = environment() -env = add_decl(env, mk_constant_assumption("N", Type)) -local N = Const("N") -env = add_decl(env, mk_constant_assumption("f", mk_arrow(N, N, N))) -env = add_decl(env, mk_constant_assumption("a", N)) -env = add_decl(env, mk_constant_assumption("b", N)) -local f = Const("f") -local a = Const("a") -local b = Const("b") -local m1 = mk_metavar("m1", N) -local m2 = mk_metavar("m2", N) -local m3 = mk_metavar("m3", N) -local m4 = mk_metavar("m4", N) - -function display_solutions(m, ss) - local n = 0 - for s in ss do - print("solution: " .. tostring(s:instantiate(m))) - s:for_each_expr(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - s:for_each_level(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - n = n + 1 - end -end - -cs = { mk_eq_cnstr(m1, f(m2, f(m3, m4))), - mk_choice_cnstr(m2, function(m, e, s, ngen) return {{mk_eq_cnstr(m, a)}, {mk_eq_cnstr(m, f(a, a))}} end), - mk_choice_cnstr(m3, function(m, e, s, ngen) return {mk_eq_cnstr(m, b), mk_eq_cnstr(m, f(b, b))} end), - mk_choice_cnstr(m4, function(m, e, s, ngen) return {a, b} end) - } - -display_solutions(m1, unify(env, cs, name_generator())) diff --git a/tests/lua/unify6.lua b/tests/lua/unify6.lua deleted file mode 100644 index cf3163ad7..000000000 --- a/tests/lua/unify6.lua +++ /dev/null @@ -1,26 +0,0 @@ -local env = environment() -local m1 = mk_meta_univ("m1") -local m2 = mk_meta_univ("m2") -local m3 = mk_meta_univ("m3") -local l1 = mk_param_univ("l1") - -function display_solutions(m, ss) - local n = 0 - for s in ss do - print("solution: " .. tostring(s:instantiate(m):normalize())) - s:for_each_expr(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - s:for_each_level(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - n = n + 1 - end -end - -cs = { mk_level_eq_cnstr(m1, max_univ(m2, max_univ(m2, l1, 1))), - mk_level_eq_cnstr(m2, level()+1), - mk_level_eq_cnstr(m3+1, m2+1) - } - -display_solutions(m1, unify(env, cs, name_generator())) diff --git a/tests/lua/unify7.lua b/tests/lua/unify7.lua deleted file mode 100644 index a0cba5107..000000000 --- a/tests/lua/unify7.lua +++ /dev/null @@ -1,25 +0,0 @@ -local env = environment() -local N = Const("N") -local P = Const("P") -env = add_decl(env, mk_constant_assumption("N", Type)) -env = add_decl(env, mk_constant_assumption("P", mk_arrow(N, Prop))) -local a = Local("a", N) -local H = Local("H", P(a)) -local t = Pi(H, Prop) -print(env:infer_type(t)) -local m = mk_metavar("m", mk_arrow(N, N, Type)) -local cs = { mk_eq_cnstr(m(a, a), t) } - -ss = unify(env, cs, name_generator()) -local n = 0 -for s in ss do - print("solution: " .. tostring(s:instantiate(m))) - s:for_each_expr(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - s:for_each_level(function(n, v, j) - print(" " .. tostring(n) .. " := " .. tostring(v)) - end) - n = n + 1 -end -assert(n == 2) diff --git a/tests/lua/yield.lua b/tests/lua/yield.lua deleted file mode 100644 index b7678f6aa..000000000 --- a/tests/lua/yield.lua +++ /dev/null @@ -1,11 +0,0 @@ -function foo() - print("foo", 1) - yield() - print("foo", 2) -end - -co = coroutine.create(foo) -print(coroutine.resume(co)) -print("--------") -print(coroutine.resume(co)) -yield()