2013-11-21 01:02:41 +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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <algorithm>
|
2013-11-22 02:39:33 +00:00
|
|
|
#include <utility>
|
2013-11-21 18:44:53 +00:00
|
|
|
#include <memory>
|
2013-11-21 20:34:37 +00:00
|
|
|
#include <mutex>
|
2013-11-22 02:39:33 +00:00
|
|
|
#include "util/interrupt.h"
|
|
|
|
#include "util/lazy_list.h"
|
2013-11-21 23:51:29 +00:00
|
|
|
#include "library/io_state.h"
|
2013-11-21 01:02:41 +00:00
|
|
|
#include "library/tactic/proof_state.h"
|
|
|
|
|
|
|
|
namespace lean {
|
2013-11-22 02:39:33 +00:00
|
|
|
typedef lazy_list<proof_state> proof_state_seq;
|
2013-11-21 18:44:53 +00:00
|
|
|
|
2013-11-21 01:02:41 +00:00
|
|
|
class tactic_cell {
|
|
|
|
void dealloc() { delete this; }
|
|
|
|
MK_LEAN_RC();
|
|
|
|
public:
|
2013-11-22 02:39:33 +00:00
|
|
|
tactic_cell():m_rc(0) {}
|
|
|
|
virtual ~tactic_cell() {}
|
|
|
|
virtual proof_state_seq operator()(environment const & env, io_state const & io, proof_state const & s) = 0;
|
2013-11-21 01:02:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class tactic {
|
|
|
|
protected:
|
|
|
|
tactic_cell * m_ptr;
|
|
|
|
public:
|
|
|
|
explicit tactic(tactic_cell * ptr):m_ptr(ptr) { if (m_ptr) m_ptr->inc_ref(); }
|
|
|
|
tactic(tactic const & s):m_ptr(s.m_ptr) { if (m_ptr) m_ptr->inc_ref(); }
|
|
|
|
tactic(tactic && s):m_ptr(s.m_ptr) { s.m_ptr = nullptr; }
|
|
|
|
~tactic() { if (m_ptr) m_ptr->dec_ref(); }
|
|
|
|
friend void swap(tactic & a, tactic & b) { std::swap(a.m_ptr, b.m_ptr); }
|
2013-11-21 18:44:53 +00:00
|
|
|
tactic & operator=(tactic const & s);
|
|
|
|
tactic & operator=(tactic && s);
|
2013-11-21 01:02:41 +00:00
|
|
|
|
2013-11-22 02:39:33 +00:00
|
|
|
proof_state_seq operator()(environment const & env, io_state const & io, proof_state const & s) { return m_ptr->operator()(env, io, s); }
|
2013-11-22 00:44:31 +00:00
|
|
|
|
|
|
|
expr solve(environment const & env, io_state const & io, proof_state const & s);
|
2013-11-22 01:25:19 +00:00
|
|
|
expr solve(environment const & env, io_state const & io, context const & ctx, expr const & t);
|
2013-11-21 01:02:41 +00:00
|
|
|
};
|
|
|
|
|
2013-11-21 23:31:55 +00:00
|
|
|
template<typename F>
|
|
|
|
class simple_tactic_cell : public tactic_cell {
|
|
|
|
F m_f;
|
|
|
|
public:
|
|
|
|
simple_tactic_cell(F && f):m_f(f) {}
|
2013-11-22 02:39:33 +00:00
|
|
|
virtual proof_state_seq operator()(environment const & env, io_state const & io, proof_state const & s) {
|
|
|
|
return m_f(env, io, s);
|
2013-11-21 23:31:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename F>
|
|
|
|
tactic mk_tactic(F && f) { return tactic(new simple_tactic_cell<F>(std::forward<F>(f))); }
|
|
|
|
|
|
|
|
tactic id_tactic();
|
|
|
|
tactic fail_tactic();
|
|
|
|
tactic now_tactic();
|
|
|
|
tactic assumption_tactic();
|
2013-11-22 02:39:33 +00:00
|
|
|
tactic then(tactic t1, tactic t2);
|
|
|
|
tactic orelse(tactic t1, tactic t2);
|
|
|
|
tactic try_for(tactic t, unsigned ms, unsigned check_ms = g_small_sleep);
|
|
|
|
tactic repeat(tactic t1);
|
2013-11-21 20:34:37 +00:00
|
|
|
}
|