2013-09-13 03:04:10 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2013-07-17 05:10:18 +00:00
|
|
|
#include <iostream>
|
2013-08-18 23:23:29 +00:00
|
|
|
#include <fstream>
|
2013-08-24 23:11:35 +00:00
|
|
|
#include <signal.h>
|
2013-12-04 17:57:33 +00:00
|
|
|
#include <cstdlib>
|
2013-11-20 01:04:52 +00:00
|
|
|
#include <getopt.h>
|
2013-12-04 19:21:26 +00:00
|
|
|
#include <string>
|
2013-12-01 20:42:32 +00:00
|
|
|
#include "util/stackinfo.h"
|
2014-09-27 17:12:59 +00:00
|
|
|
#include "util/macros.h"
|
2013-11-20 03:30:39 +00:00
|
|
|
#include "util/debug.h"
|
2014-09-04 20:33:00 +00:00
|
|
|
#include "util/sstream.h"
|
2013-11-13 05:42:22 +00:00
|
|
|
#include "util/interrupt.h"
|
2013-11-27 22:57:33 +00:00
|
|
|
#include "util/script_state.h"
|
2013-12-10 01:33:47 +00:00
|
|
|
#include "util/thread.h"
|
2014-06-18 04:38:10 +00:00
|
|
|
#include "util/thread_script_state.h"
|
2013-12-23 01:56:53 +00:00
|
|
|
#include "util/lean_path.h"
|
2014-09-04 20:33:00 +00:00
|
|
|
#include "util/sexpr/options.h"
|
|
|
|
#include "util/sexpr/option_declarations.h"
|
2013-12-18 22:37:55 +00:00
|
|
|
#include "kernel/environment.h"
|
2013-12-29 10:44:49 +00:00
|
|
|
#include "kernel/kernel_exception.h"
|
|
|
|
#include "kernel/formatter.h"
|
2014-07-05 17:31:27 +00:00
|
|
|
#include "library/standard_kernel.h"
|
2014-12-05 22:34:02 +00:00
|
|
|
#include "library/hott_kernel.h"
|
2014-06-14 15:01:52 +00:00
|
|
|
#include "library/module.h"
|
2014-06-11 18:26:17 +00:00
|
|
|
#include "library/io_state_stream.h"
|
2014-08-15 01:12:12 +00:00
|
|
|
#include "library/definition_cache.h"
|
2014-08-15 00:44:07 +00:00
|
|
|
#include "library/declaration_index.h"
|
2014-04-29 18:52:09 +00:00
|
|
|
#include "library/error_handling/error_handling.h"
|
2014-06-11 18:26:17 +00:00
|
|
|
#include "frontends/lean/parser.h"
|
2014-07-09 08:12:36 +00:00
|
|
|
#include "frontends/lean/pp.h"
|
2014-08-07 01:07:04 +00:00
|
|
|
#include "frontends/lean/server.h"
|
2014-06-29 00:43:30 +00:00
|
|
|
#include "frontends/lean/dependencies.h"
|
2014-09-22 17:27:48 +00:00
|
|
|
#include "init/init.h"
|
2013-07-17 05:10:18 +00:00
|
|
|
#include "version.h"
|
2013-12-04 19:21:26 +00:00
|
|
|
#include "githash.h" // NOLINT
|
2013-09-13 23:14:24 +00:00
|
|
|
|
2013-11-27 22:57:33 +00:00
|
|
|
using lean::script_state;
|
2013-11-20 03:30:39 +00:00
|
|
|
using lean::unreachable_reached;
|
2014-04-30 17:28:07 +00:00
|
|
|
using lean::environment;
|
2014-04-29 18:52:09 +00:00
|
|
|
using lean::io_state;
|
2014-04-30 17:28:07 +00:00
|
|
|
using lean::io_state_stream;
|
|
|
|
using lean::regular;
|
2014-06-11 18:26:17 +00:00
|
|
|
using lean::mk_environment;
|
2014-12-05 22:34:02 +00:00
|
|
|
using lean::mk_hott_environment;
|
2014-06-18 05:36:47 +00:00
|
|
|
using lean::set_environment;
|
|
|
|
using lean::set_io_state;
|
2014-08-15 01:12:12 +00:00
|
|
|
using lean::definition_cache;
|
2014-08-14 22:47:46 +00:00
|
|
|
using lean::pos_info;
|
|
|
|
using lean::pos_info_provider;
|
|
|
|
using lean::optional;
|
|
|
|
using lean::expr;
|
2014-09-04 20:33:00 +00:00
|
|
|
using lean::options;
|
2014-08-15 00:44:07 +00:00
|
|
|
using lean::declaration_index;
|
2014-10-13 17:05:38 +00:00
|
|
|
using lean::keep_theorem_mode;
|
2014-10-14 15:13:41 +00:00
|
|
|
using lean::module_name;
|
2014-04-29 00:49:23 +00:00
|
|
|
|
2014-12-05 22:34:02 +00:00
|
|
|
enum class input_kind { Unspecified, Lean, HLean, Lua, Trace };
|
2013-11-20 00:47:47 +00:00
|
|
|
|
2013-09-20 04:26:01 +00:00
|
|
|
static void on_ctrl_c(int ) {
|
2013-11-13 05:42:22 +00:00
|
|
|
lean::request_interrupt();
|
2013-08-24 23:11:35 +00:00
|
|
|
}
|
|
|
|
|
2013-11-20 03:30:39 +00:00
|
|
|
static void display_header(std::ostream & out) {
|
2014-10-07 19:00:49 +00:00
|
|
|
out << "Lean (version " << LEAN_VERSION_MAJOR << "."
|
|
|
|
<< LEAN_VERSION_MINOR << "." << LEAN_VERSION_PATCH;
|
2014-10-07 23:51:43 +00:00
|
|
|
if (std::strcmp(g_githash, "GITDIR-NOTFOUND") == 0) {
|
|
|
|
if (std::strcmp(LEAN_PACKAGE_VERSION, "NOT-FOUND") != 0) {
|
|
|
|
out << ", package " << LEAN_PACKAGE_VERSION;
|
|
|
|
}
|
|
|
|
} else {
|
2014-10-07 18:53:29 +00:00
|
|
|
out << ", commit " << std::string(g_githash).substr(0, 12);
|
|
|
|
}
|
|
|
|
out << ", " << LEAN_STR(LEAN_BUILD_TYPE) << ")\n";
|
2013-11-20 03:30:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void display_help(std::ostream & out) {
|
|
|
|
display_header(out);
|
|
|
|
std::cout << "Input format:\n";
|
2013-12-10 01:33:47 +00:00
|
|
|
std::cout << " --lean use parser for Lean default input format for files,\n";
|
|
|
|
std::cout << " with unknown extension (default)\n";
|
2014-12-05 22:34:02 +00:00
|
|
|
std::cout << " --hlean use parser for Lean default input format \n";
|
|
|
|
std::cout << " and use HoTT compatible kernel for files, with unknown extension\n";
|
2013-12-10 01:33:47 +00:00
|
|
|
std::cout << " --lua use Lua parser for files with unknown extension\n";
|
2014-10-27 17:26:29 +00:00
|
|
|
std::cout << " --server-trace use lean server trace parser for files with unknown extension\n";
|
2013-11-20 03:30:39 +00:00
|
|
|
std::cout << "Miscellaneous:\n";
|
2013-12-10 01:33:47 +00:00
|
|
|
std::cout << " --help -h display this message\n";
|
|
|
|
std::cout << " --version -v display version number\n";
|
|
|
|
std::cout << " --githash display the git commit hash number used to build this binary\n";
|
2013-12-23 01:56:53 +00:00
|
|
|
std::cout << " --path display the path used for finding Lean libraries and extensions\n";
|
2013-12-29 01:31:35 +00:00
|
|
|
std::cout << " --output=file -o save the final environment in binary format in the given file\n";
|
2014-10-09 20:07:21 +00:00
|
|
|
std::cout << " --cpp=file -C save the final environment as a C++ array\n";
|
2014-08-10 17:00:04 +00:00
|
|
|
std::cout << " --luahook=num -k how often the Lua interpreter checks the interrupted flag,\n";
|
2013-12-10 01:33:47 +00:00
|
|
|
std::cout << " it is useful for interrupting non-terminating user scripts,\n";
|
|
|
|
std::cout << " 0 means 'do not check'.\n";
|
2014-06-11 18:26:17 +00:00
|
|
|
std::cout << " --trust=num -t trust level (default: 0) \n";
|
2014-10-09 20:07:21 +00:00
|
|
|
std::cout << " --discard -T discard the proof of imported theorems after checking\n";
|
2014-10-13 17:05:38 +00:00
|
|
|
std::cout << " --to_axiom -X discard proofs of all theorems after checking them, i.e.,\n";
|
|
|
|
std::cout << " theorems become axioms after checking\n";
|
2014-01-09 23:31:58 +00:00
|
|
|
std::cout << " --quiet -q do not print verbose messages\n";
|
2014-09-04 19:42:19 +00:00
|
|
|
#if defined(LEAN_MULTI_THREAD)
|
2014-08-07 01:07:04 +00:00
|
|
|
std::cout << " --server start Lean in 'server' mode\n";
|
2014-07-23 21:35:02 +00:00
|
|
|
std::cout << " --threads=num -j number of threads used to process lean files\n";
|
2014-09-04 19:42:19 +00:00
|
|
|
#endif
|
2014-06-29 00:43:30 +00:00
|
|
|
std::cout << " --deps just print dependencies of a Lean input\n";
|
2014-07-31 18:18:51 +00:00
|
|
|
std::cout << " --flycheck print structured error message for flycheck\n";
|
2014-08-10 18:04:16 +00:00
|
|
|
std::cout << " --cache=file -c load/save cached definitions from/to the given file\n";
|
2014-08-15 00:44:07 +00:00
|
|
|
std::cout << " --index=file -i store index for declared symbols in the given file\n";
|
2013-12-10 01:33:47 +00:00
|
|
|
#if defined(LEAN_USE_BOOST)
|
|
|
|
std::cout << " --tstack=num -s thread stack size in Kb\n";
|
|
|
|
#endif
|
2014-09-04 20:33:00 +00:00
|
|
|
std::cout << " -D name=value set a configuration option (see set_option command)\n";
|
2013-11-20 03:30:39 +00:00
|
|
|
}
|
|
|
|
|
2013-11-20 00:47:47 +00:00
|
|
|
static char const * get_file_extension(char const * fname) {
|
|
|
|
if (fname == 0)
|
|
|
|
return 0;
|
|
|
|
char const * last_dot = 0;
|
|
|
|
while (true) {
|
|
|
|
char const * tmp = strchr(fname, '.');
|
|
|
|
if (tmp == 0) {
|
|
|
|
return last_dot;
|
|
|
|
}
|
|
|
|
last_dot = tmp + 1;
|
|
|
|
fname = last_dot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 03:30:39 +00:00
|
|
|
static struct option g_long_options[] = {
|
2014-10-27 17:26:29 +00:00
|
|
|
{"version", no_argument, 0, 'v'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"lean", no_argument, 0, 'l'},
|
2014-12-05 22:34:02 +00:00
|
|
|
{"hlean", no_argument, 0, 'H'},
|
2014-10-27 17:26:29 +00:00
|
|
|
{"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'},
|
|
|
|
{"cpp", required_argument, 0, 'C'},
|
|
|
|
{"trust", required_argument, 0, 't'},
|
|
|
|
{"discard", no_argument, 0, 'T'},
|
|
|
|
{"to_axiom", no_argument, 0, 'X'},
|
2014-09-04 19:42:19 +00:00
|
|
|
#if defined(LEAN_MULTI_THREAD)
|
2014-10-27 17:26:29 +00:00
|
|
|
{"server", no_argument, 0, 'S'},
|
|
|
|
{"threads", required_argument, 0, 'j'},
|
2014-09-04 19:42:19 +00:00
|
|
|
#endif
|
2014-10-27 17:26:29 +00:00
|
|
|
{"quiet", no_argument, 0, 'q'},
|
|
|
|
{"cache", required_argument, 0, 'c'},
|
|
|
|
{"deps", no_argument, 0, 'd'},
|
|
|
|
{"flycheck", no_argument, 0, 'F'},
|
|
|
|
{"index", no_argument, 0, 'i'},
|
2013-12-10 01:33:47 +00:00
|
|
|
#if defined(LEAN_USE_BOOST)
|
2014-10-27 17:26:29 +00:00
|
|
|
{"tstack", required_argument, 0, 's'},
|
2013-12-10 01:33:47 +00:00
|
|
|
#endif
|
2013-11-20 03:30:39 +00:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
2013-08-24 23:11:35 +00:00
|
|
|
|
2014-12-05 22:34:02 +00:00
|
|
|
#define BASIC_OPT_STR "HRXTFC:dD:qlupgvhk:012t:012o:c:i:"
|
2014-09-04 19:42:19 +00:00
|
|
|
|
|
|
|
#if defined(LEAN_USE_BOOST) && defined(LEAN_MULTI_THREAD)
|
|
|
|
static char const * g_opt_str = BASIC_OPT_STR "Sj:012s:012";
|
|
|
|
#elif !defined(LEAN_USE_BOOST) && defined(LEAN_MULTI_THREAD)
|
|
|
|
static char const * g_opt_str = BASIC_OPT_STR "Sj:012";
|
2014-06-11 18:26:17 +00:00
|
|
|
#else
|
2014-09-04 19:42:19 +00:00
|
|
|
static char const * g_opt_str = BASIC_OPT_STR;
|
2014-06-11 18:26:17 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-14 22:47:46 +00:00
|
|
|
class simple_pos_info_provider : public pos_info_provider {
|
|
|
|
char const * m_fname;
|
|
|
|
public:
|
|
|
|
simple_pos_info_provider(char const * fname):m_fname(fname) {}
|
|
|
|
virtual optional<pos_info> get_pos_info(expr const &) const { return optional<pos_info>(); }
|
|
|
|
virtual char const * get_file_name() const { return m_fname; }
|
|
|
|
virtual pos_info get_some_pos() const { return pos_info(-1, -1); }
|
|
|
|
};
|
|
|
|
|
2014-09-04 20:33:00 +00:00
|
|
|
options set_config_option(options const & opts, char const * in) {
|
2014-09-06 01:07:54 +00:00
|
|
|
if (!in) return opts;
|
|
|
|
while (*in && std::isspace(*in))
|
|
|
|
++in;
|
2014-09-04 20:33:00 +00:00
|
|
|
std::string in_str(in);
|
|
|
|
auto pos = in_str.find('=');
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
throw lean::exception("invalid -D parameter, argument must contain '='");
|
|
|
|
lean::name opt = lean::string_to_name(in_str.substr(0, pos));
|
|
|
|
std::string val = in_str.substr(pos+1);
|
|
|
|
auto decls = lean::get_option_declarations();
|
|
|
|
auto it = decls.find(opt);
|
|
|
|
if (it != decls.end()) {
|
|
|
|
switch (it->second.kind()) {
|
|
|
|
case lean::BoolOption:
|
|
|
|
if (val == "true")
|
|
|
|
return opts.update(opt, true);
|
|
|
|
else if (val == "false")
|
|
|
|
return opts.update(opt, false);
|
|
|
|
else
|
|
|
|
throw lean::exception(lean::sstream() << "invalid -D parameter, invalid configuration option '" << opt
|
|
|
|
<< "' value, it must be true/false");
|
|
|
|
case lean::IntOption:
|
|
|
|
case lean::UnsignedOption:
|
|
|
|
return opts.update(opt, atoi(val.c_str()));
|
|
|
|
default:
|
|
|
|
throw lean::exception(lean::sstream() << "invalid -D parameter, configuration option '" << opt
|
|
|
|
<< "' cannot be set in the command line, use set_option command");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw lean::exception(lean::sstream() << "invalid -D parameter, unknown configuration option '" << opt << "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-09 20:07:21 +00:00
|
|
|
static void export_as_cpp_file(std::string const & fname, char const * varname, environment const & env) {
|
|
|
|
std::ostringstream buffer(std::ofstream::binary);
|
|
|
|
export_module(buffer, env);
|
|
|
|
std::string r = buffer.str();
|
|
|
|
std::ofstream out(fname);
|
|
|
|
out << "// automatically generated file do not edit\n";
|
|
|
|
out << "namespace lean {\n";
|
|
|
|
out << " char " << varname << "[" << r.size() + 1 << "] = {";
|
|
|
|
for (unsigned i = 0; i < r.size(); i++) {
|
|
|
|
if (i > 0)
|
|
|
|
out << ", ";
|
|
|
|
out << static_cast<unsigned>(static_cast<unsigned char>(r[i]));
|
|
|
|
}
|
|
|
|
out << " }\n";
|
|
|
|
out << "}\n";
|
|
|
|
}
|
|
|
|
|
2014-10-14 15:13:41 +00:00
|
|
|
environment import_module(environment const & env, io_state const & ios, module_name const & mod, bool keep_proofs = true) {
|
|
|
|
std::string base = ".";
|
|
|
|
bool num_threads = 1;
|
|
|
|
return import_modules(env, base, 1, &mod, num_threads, keep_proofs, ios);
|
|
|
|
}
|
|
|
|
|
|
|
|
environment import_standard(environment const & env, io_state const & ios, bool keep_proofs = true) {
|
|
|
|
module_name std(lean::name("standard"));
|
|
|
|
return import_module(env, ios, std, keep_proofs);
|
|
|
|
}
|
|
|
|
|
2014-10-15 01:57:25 +00:00
|
|
|
#if defined(LEAN_EMSCRIPTEN)
|
|
|
|
#include <emscripten/bind.h>
|
|
|
|
|
|
|
|
class emscripten_shell {
|
|
|
|
private:
|
|
|
|
unsigned trust_lvl;
|
|
|
|
unsigned num_threads;
|
|
|
|
options opts;
|
|
|
|
environment env;
|
|
|
|
io_state ios;
|
|
|
|
script_state S;
|
|
|
|
set_environment set1;
|
|
|
|
set_io_state set2;
|
|
|
|
|
|
|
|
public:
|
2014-10-16 20:24:14 +00:00
|
|
|
emscripten_shell() : trust_lvl(10000), num_threads(1), opts("flycheck", true),
|
2014-10-15 01:57:25 +00:00
|
|
|
env(mk_environment(trust_lvl)), ios(opts, lean::mk_pretty_formatter_factory()),
|
|
|
|
S(lean::get_thread_script_state()), set1(S, env), set2(S, ios) {
|
|
|
|
}
|
|
|
|
|
|
|
|
int import_module(std::string mname) {
|
|
|
|
try {
|
|
|
|
env = ::import_module(env, ios, lean::module_name(mname), false);
|
|
|
|
} catch (lean::exception & ex) {
|
|
|
|
simple_pos_info_provider pp("import_module");
|
|
|
|
lean::display_error(diagnostic(env, ios), &pp, ex);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int process_file(std::string input_filename) {
|
|
|
|
bool ok = true;
|
|
|
|
try {
|
|
|
|
environment temp_env(env);
|
2014-10-22 00:21:48 +00:00
|
|
|
io_state temp_ios(ios);
|
|
|
|
if (!parse_commands(temp_env, temp_ios, input_filename.c_str(), false, num_threads)) {
|
2014-10-15 01:57:25 +00:00
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
} catch (lean::exception & ex) {
|
|
|
|
simple_pos_info_provider pp(input_filename.c_str());
|
|
|
|
ok = false;
|
|
|
|
lean::display_error(diagnostic(env, ios), &pp, ex);
|
|
|
|
}
|
|
|
|
return ok ? 0 : 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
lean::initializer* g_init;
|
|
|
|
emscripten_shell* g_shell;
|
|
|
|
|
|
|
|
void emscripten_init() {
|
|
|
|
g_init = new lean::initializer();
|
|
|
|
g_shell = new emscripten_shell();
|
|
|
|
}
|
|
|
|
|
|
|
|
int emscripten_import_module(std::string mname) {
|
|
|
|
return g_shell->import_module(mname);
|
|
|
|
}
|
|
|
|
|
|
|
|
int emscripten_process_file(std::string input_filename) {
|
|
|
|
return g_shell->process_file(input_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
EMSCRIPTEN_BINDINGS(LEAN_JS) {
|
2014-10-15 04:09:33 +00:00
|
|
|
emscripten::function("lean_init", &emscripten_init);
|
|
|
|
emscripten::function("lean_import_module", &emscripten_import_module);
|
|
|
|
emscripten::function("lean_process_file", &emscripten_process_file);
|
2014-10-15 01:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2013-08-24 23:11:35 +00:00
|
|
|
int main(int argc, char ** argv) {
|
2014-09-22 17:27:48 +00:00
|
|
|
lean::initializer init;
|
2014-10-13 17:05:38 +00:00
|
|
|
bool export_objects = false;
|
|
|
|
unsigned trust_lvl = 0;
|
|
|
|
bool server = false;
|
|
|
|
bool only_deps = false;
|
|
|
|
unsigned num_threads = 1;
|
|
|
|
bool use_cache = false;
|
|
|
|
bool gen_index = false;
|
|
|
|
bool export_cpp = false;
|
|
|
|
keep_theorem_mode tmode = keep_theorem_mode::All;
|
2014-09-04 20:33:00 +00:00
|
|
|
options opts;
|
2014-01-14 00:54:21 +00:00
|
|
|
std::string output;
|
2014-10-09 20:07:21 +00:00
|
|
|
std::string cpp_output;
|
2014-08-10 18:04:16 +00:00
|
|
|
std::string cache_name;
|
2014-08-15 00:44:07 +00:00
|
|
|
std::string index_name;
|
2014-12-05 22:34:02 +00:00
|
|
|
input_kind default_k = input_kind::Unspecified;
|
2014-01-14 00:54:21 +00:00
|
|
|
while (true) {
|
2014-06-11 18:26:17 +00:00
|
|
|
int c = getopt_long(argc, argv, g_opt_str, g_long_options, NULL);
|
2014-01-14 00:54:21 +00:00
|
|
|
if (c == -1)
|
|
|
|
break; // end of command line
|
|
|
|
switch (c) {
|
2014-07-23 21:35:02 +00:00
|
|
|
case 'j':
|
2014-06-16 23:37:46 +00:00
|
|
|
num_threads = atoi(optarg);
|
|
|
|
break;
|
2014-08-07 01:07:04 +00:00
|
|
|
case 'S':
|
|
|
|
server = true;
|
2014-06-14 17:38:42 +00:00
|
|
|
break;
|
2014-01-14 00:54:21 +00:00
|
|
|
case 'v':
|
|
|
|
display_header(std::cout);
|
|
|
|
return 0;
|
|
|
|
case 'g':
|
|
|
|
std::cout << g_githash << "\n";
|
|
|
|
return 0;
|
|
|
|
case 'h':
|
|
|
|
display_help(std::cout);
|
|
|
|
return 0;
|
|
|
|
case 'l':
|
|
|
|
default_k = input_kind::Lean;
|
|
|
|
break;
|
2014-12-05 22:34:02 +00:00
|
|
|
case 'H':
|
|
|
|
default_k = input_kind::HLean;
|
|
|
|
break;
|
2014-01-14 00:54:21 +00:00
|
|
|
case 'u':
|
|
|
|
default_k = input_kind::Lua;
|
|
|
|
break;
|
2014-10-27 17:26:29 +00:00
|
|
|
case 'R':
|
|
|
|
default_k = input_kind::Trace;
|
|
|
|
break;
|
2014-08-10 17:00:04 +00:00
|
|
|
case 'k':
|
2014-01-14 00:54:21 +00:00
|
|
|
script_state::set_check_interrupt_freq(atoi(optarg));
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
std::cout << lean::get_lean_path() << "\n";
|
|
|
|
return 0;
|
|
|
|
case 's':
|
|
|
|
lean::set_thread_stack_size(atoi(optarg)*1024);
|
|
|
|
break;
|
|
|
|
case 'o':
|
2014-08-10 18:04:16 +00:00
|
|
|
output = optarg;
|
2014-06-14 15:01:52 +00:00
|
|
|
export_objects = true;
|
2014-01-14 00:54:21 +00:00
|
|
|
break;
|
2014-10-09 20:07:21 +00:00
|
|
|
case 'C':
|
|
|
|
cpp_output = optarg;
|
|
|
|
export_cpp = true;
|
|
|
|
break;
|
2014-08-10 18:04:16 +00:00
|
|
|
case 'c':
|
|
|
|
cache_name = optarg;
|
|
|
|
use_cache = true;
|
|
|
|
break;
|
2014-08-15 00:44:07 +00:00
|
|
|
case 'i':
|
|
|
|
index_name = optarg;
|
|
|
|
gen_index = true;
|
2014-01-14 00:54:21 +00:00
|
|
|
case 't':
|
2014-06-11 18:26:17 +00:00
|
|
|
trust_lvl = atoi(optarg);
|
2014-01-14 00:54:21 +00:00
|
|
|
break;
|
2014-10-09 20:07:21 +00:00
|
|
|
case 'T':
|
2014-10-13 17:05:38 +00:00
|
|
|
tmode = keep_theorem_mode::DiscardImported;
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
tmode = keep_theorem_mode::DiscardAll;
|
2014-10-09 20:07:21 +00:00
|
|
|
break;
|
2014-01-14 00:54:21 +00:00
|
|
|
case 'q':
|
2014-09-04 20:33:00 +00:00
|
|
|
opts = opts.update("verbose", false);
|
2014-01-14 00:54:21 +00:00
|
|
|
break;
|
2014-09-04 20:33:00 +00:00
|
|
|
case 'd':
|
2014-06-29 00:43:30 +00:00
|
|
|
only_deps = true;
|
|
|
|
break;
|
2014-09-04 20:33:00 +00:00
|
|
|
case 'D':
|
|
|
|
try {
|
|
|
|
opts = set_config_option(opts, optarg);
|
|
|
|
} catch (lean::exception & ex) {
|
|
|
|
std::cerr << ex.what() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
2014-07-31 18:18:51 +00:00
|
|
|
case 'F':
|
2014-09-04 20:33:00 +00:00
|
|
|
opts = opts.update("flycheck", true);
|
2014-08-01 02:54:21 +00:00
|
|
|
break;
|
2014-01-14 00:54:21 +00:00
|
|
|
default:
|
|
|
|
std::cerr << "Unknown command line option\n";
|
|
|
|
display_help(std::cerr);
|
|
|
|
return 1;
|
2013-11-20 03:30:39 +00:00
|
|
|
}
|
2014-01-14 00:54:21 +00:00
|
|
|
}
|
2014-04-29 00:49:23 +00:00
|
|
|
|
2014-09-04 19:42:19 +00:00
|
|
|
#if !defined(LEAN_MULTI_THREAD)
|
|
|
|
lean_assert(!server);
|
|
|
|
lean_assert(num_threads == 1);
|
|
|
|
#endif
|
|
|
|
|
2014-12-05 22:34:02 +00:00
|
|
|
bool has_lean = (default_k == input_kind::Lean);
|
|
|
|
bool has_hlean = (default_k == input_kind::HLean);
|
|
|
|
for (int i = optind; i < argc; i++) {
|
|
|
|
char const * ext = get_file_extension(argv[i]);
|
|
|
|
if (strcmp(ext, "lean") == 0) {
|
|
|
|
has_lean = true;
|
|
|
|
if (has_hlean) {
|
|
|
|
std::cerr << ".hlean file cannot be mixed with .lean files\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (default_k == input_kind::Unspecified)
|
|
|
|
default_k = input_kind::Lean;
|
|
|
|
} else if (strcmp(ext, "hlean") == 0) {
|
|
|
|
has_hlean = true;
|
|
|
|
if (has_lean) {
|
|
|
|
std::cerr << ".lean file cannot be mixed with .hlean files\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (default_k == input_kind::Unspecified)
|
|
|
|
default_k = input_kind::HLean;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (default_k == input_kind::Unspecified)
|
|
|
|
default_k = input_kind::Lean;
|
|
|
|
|
|
|
|
if (has_hlean)
|
|
|
|
lean::initialize_lean_path(true);
|
|
|
|
|
|
|
|
environment env = has_hlean ? mk_hott_environment(trust_lvl) : mk_environment(trust_lvl);
|
2014-09-04 20:33:00 +00:00
|
|
|
io_state ios(opts, lean::mk_pretty_formatter_factory());
|
2014-06-18 05:36:47 +00:00
|
|
|
script_state S = lean::get_thread_script_state();
|
|
|
|
set_environment set1(S, env);
|
|
|
|
set_io_state set2(S, ios);
|
2014-08-15 01:12:12 +00:00
|
|
|
definition_cache cache;
|
|
|
|
definition_cache * cache_ptr = nullptr;
|
2014-08-10 18:04:16 +00:00
|
|
|
if (use_cache) {
|
|
|
|
cache_ptr = &cache;
|
2014-09-19 16:35:32 +00:00
|
|
|
std::ifstream in(cache_name, std::ifstream::binary);
|
2014-08-10 18:04:16 +00:00
|
|
|
if (!in.bad() && !in.fail())
|
|
|
|
cache.load(in);
|
|
|
|
}
|
2014-08-15 00:44:07 +00:00
|
|
|
declaration_index index;
|
|
|
|
declaration_index * index_ptr = nullptr;
|
|
|
|
if (gen_index)
|
|
|
|
index_ptr = &index;
|
2014-04-29 00:49:23 +00:00
|
|
|
|
2014-01-14 00:54:21 +00:00
|
|
|
try {
|
2014-06-14 17:38:42 +00:00
|
|
|
bool ok = true;
|
|
|
|
for (int i = optind; i < argc; i++) {
|
2014-08-14 22:47:46 +00:00
|
|
|
try {
|
|
|
|
char const * ext = get_file_extension(argv[i]);
|
|
|
|
input_kind k = default_k;
|
|
|
|
if (ext) {
|
|
|
|
if (strcmp(ext, "lean") == 0) {
|
|
|
|
k = input_kind::Lean;
|
2014-12-05 22:34:02 +00:00
|
|
|
} else if (strcmp(ext, "hlean") == 0) {
|
|
|
|
k = input_kind::HLean;
|
2014-08-14 22:47:46 +00:00
|
|
|
} else if (strcmp(ext, "lua") == 0) {
|
|
|
|
k = input_kind::Lua;
|
|
|
|
}
|
2013-11-20 00:47:47 +00:00
|
|
|
}
|
2014-10-27 17:26:29 +00:00
|
|
|
switch (k) {
|
|
|
|
case input_kind::Lean:
|
2014-12-05 22:34:02 +00:00
|
|
|
case input_kind::HLean:
|
2014-08-14 22:47:46 +00:00
|
|
|
if (only_deps) {
|
2014-08-29 20:20:25 +00:00
|
|
|
if (!display_deps(env, std::cout, std::cerr, argv[i]))
|
|
|
|
ok = false;
|
2014-10-09 20:07:21 +00:00
|
|
|
} else if (!parse_commands(env, ios, argv[i], false, num_threads,
|
2014-10-13 17:05:38 +00:00
|
|
|
cache_ptr, index_ptr, tmode)) {
|
2014-08-14 22:47:46 +00:00
|
|
|
ok = false;
|
|
|
|
}
|
2014-10-27 17:26:29 +00:00
|
|
|
break;
|
|
|
|
case input_kind::Lua:
|
2014-06-18 05:04:09 +00:00
|
|
|
lean::system_import(argv[i]);
|
2014-10-27 17:26:29 +00:00
|
|
|
break;
|
|
|
|
case input_kind::Trace:
|
|
|
|
ok = lean::parse_server_trace(env, ios, argv[i]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lean_unreachable();
|
|
|
|
break;
|
2014-06-14 17:38:42 +00:00
|
|
|
}
|
2014-08-14 22:47:46 +00:00
|
|
|
} catch (lean::exception & ex) {
|
|
|
|
simple_pos_info_provider pp(argv[i]);
|
|
|
|
ok = false;
|
|
|
|
lean::display_error(diagnostic(env, ios), &pp, ex);
|
2014-06-14 15:01:52 +00:00
|
|
|
}
|
2013-08-18 23:23:29 +00:00
|
|
|
}
|
2014-08-07 01:07:04 +00:00
|
|
|
if (ok && server && default_k == input_kind::Lean) {
|
2014-06-14 17:38:42 +00:00
|
|
|
signal(SIGINT, on_ctrl_c);
|
2014-09-09 21:13:35 +00:00
|
|
|
ios.set_option(lean::name("pp", "beta"), true);
|
2014-08-07 01:07:04 +00:00
|
|
|
lean::server Sv(env, ios, num_threads);
|
|
|
|
if (!Sv(std::cin))
|
|
|
|
ok = false;
|
2014-06-14 17:38:42 +00:00
|
|
|
}
|
2014-08-10 18:04:16 +00:00
|
|
|
if (use_cache) {
|
|
|
|
std::ofstream out(cache_name, std::ofstream::binary);
|
|
|
|
cache.save(out);
|
|
|
|
}
|
2014-08-15 00:44:07 +00:00
|
|
|
if (gen_index) {
|
2014-08-23 19:39:59 +00:00
|
|
|
std::shared_ptr<lean::file_output_channel> out(new lean::file_output_channel(index_name.c_str()));
|
|
|
|
ios.set_regular_channel(out);
|
|
|
|
index.save(regular(env, ios));
|
2014-08-15 00:44:07 +00:00
|
|
|
}
|
2014-08-29 20:26:07 +00:00
|
|
|
if (export_objects && ok) {
|
2014-06-14 17:38:42 +00:00
|
|
|
std::ofstream out(output, std::ofstream::binary);
|
|
|
|
export_module(out, env);
|
|
|
|
}
|
2014-10-09 20:07:21 +00:00
|
|
|
if (export_cpp && ok) {
|
|
|
|
export_as_cpp_file(cpp_output, "olean_lib", env);
|
|
|
|
}
|
2014-06-14 17:38:42 +00:00
|
|
|
return ok ? 0 : 1;
|
2013-12-29 10:44:49 +00:00
|
|
|
} catch (lean::exception & ex) {
|
2014-08-14 22:47:46 +00:00
|
|
|
lean::display_error(diagnostic(env, ios), nullptr, ex);
|
2013-08-18 23:23:29 +00:00
|
|
|
}
|
2014-01-09 19:01:27 +00:00
|
|
|
return 1;
|
2013-07-17 05:10:18 +00:00
|
|
|
}
|
2014-10-15 01:57:25 +00:00
|
|
|
#endif
|