feat(tactic): refine tactic API
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
367108edfa
commit
a03841c18b
6 changed files with 57 additions and 11 deletions
|
@ -1,2 +1,2 @@
|
|||
add_library(tactic goal.cpp)
|
||||
add_library(tactic goal.cpp tactic.cpp)
|
||||
target_link_libraries(tactic ${LEAN_LIBS})
|
||||
|
|
|
@ -18,7 +18,7 @@ class justification_builder_cell {
|
|||
MK_LEAN_RC();
|
||||
public:
|
||||
virtual ~justification_builder_cell() {}
|
||||
virtual justification operator()(name const & n, justification const & j, assignment const & a) const = 0;
|
||||
virtual justification operator()(name const & n, justification const & j, environment const & env, assignment const & a) const = 0;
|
||||
};
|
||||
|
||||
class justification_builder {
|
||||
|
@ -33,6 +33,6 @@ public:
|
|||
justification_builder & operator=(justification_builder const & s) { LEAN_COPY_REF(justification_builder, s); }
|
||||
justification_builder & operator=(justification_builder && s) { LEAN_MOVE_REF(justification_builder, s); }
|
||||
|
||||
justification operator()(name const & n, justification const & j, assignment const & a) const { return m_ptr->operator()(n, j, a); }
|
||||
justification operator()(name const & n, justification const & j, environment const & env, assignment const & a) const { return m_ptr->operator()(n, j, env, a); }
|
||||
};
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class proof_builder_cell {
|
|||
MK_LEAN_RC();
|
||||
public:
|
||||
virtual ~proof_builder_cell() {}
|
||||
virtual expr operator()(proof_map const & p, assignment const & a) const = 0;
|
||||
virtual expr operator()(proof_map const & p, environment const & env, assignment const & a) const = 0;
|
||||
};
|
||||
|
||||
class proof_builder {
|
||||
|
@ -36,6 +36,6 @@ public:
|
|||
proof_builder & operator=(proof_builder const & s) { LEAN_COPY_REF(proof_builder, s); }
|
||||
proof_builder & operator=(proof_builder && s) { LEAN_MOVE_REF(proof_builder, s); }
|
||||
|
||||
expr operator()(proof_map const & p, assignment const & a) const { return m_ptr->operator()(p, a); }
|
||||
expr operator()(proof_map const & p, environment const & env, assignment const & a) const { return m_ptr->operator()(p, env, a); }
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,10 +12,18 @@ Author: Leonardo de Moura
|
|||
|
||||
namespace lean {
|
||||
class proof_state {
|
||||
environment const m_env;
|
||||
list<std::pair<name, goal>> m_goals;
|
||||
metavar_env m_menv;
|
||||
proof_builder m_proof_builder;
|
||||
justification_builder m_justification_builder;
|
||||
public:
|
||||
proof_state(environment const & env, list<std::pair<name, goal>> const & gs, metavar_env const & menv, proof_builder const & p, justification_builder const & j):
|
||||
m_env(env), m_goals(gs), m_menv(menv), m_proof_builder(p), m_justification_builder(j) {}
|
||||
environment const & get_environment() const { return m_env; }
|
||||
list<std::pair<name, goal>> const & get_goals() const { return m_goals; }
|
||||
metavar_env const & get_menv() const { return m_menv; }
|
||||
proof_builder const & get_proof_builder() const { return m_proof_builder; }
|
||||
justification_builder const & get_justification_builder() const { return m_justification_builder; }
|
||||
};
|
||||
}
|
||||
|
|
26
src/library/tactic/tactic.cpp
Normal file
26
src/library/tactic/tactic.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
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 "library/tactic/tactic.h"
|
||||
|
||||
namespace lean {
|
||||
tactic_result::~tactic_result() {
|
||||
}
|
||||
void tactic_result::interrupt() {
|
||||
m_result = true;
|
||||
}
|
||||
|
||||
tactic_cell::~tactic_cell() {
|
||||
}
|
||||
|
||||
tactic & tactic::operator=(tactic const & s) {
|
||||
LEAN_COPY_REF(tactic, s);
|
||||
}
|
||||
|
||||
tactic & tactic::operator=(tactic && s) {
|
||||
LEAN_MOVE_REF(tactic, s);
|
||||
}
|
||||
}
|
|
@ -6,16 +6,28 @@ Author: Leonardo de Moura
|
|||
*/
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include "util/lazy_list.h"
|
||||
#include <memory>
|
||||
#include "library/tactic/proof_state.h"
|
||||
|
||||
namespace lean {
|
||||
class tactic_result {
|
||||
volatile bool m_result;
|
||||
public:
|
||||
tactic_result():m_result(false) {}
|
||||
bool interrupted() const { return m_result; }
|
||||
virtual ~tactic_result();
|
||||
virtual void interrupt();
|
||||
virtual proof_state next() = 0;
|
||||
};
|
||||
|
||||
typedef std::unique_ptr<tactic_result> tactic_result_ref;
|
||||
|
||||
class tactic_cell {
|
||||
void dealloc() { delete this; }
|
||||
MK_LEAN_RC();
|
||||
public:
|
||||
virtual ~tactic_cell() {}
|
||||
virtual lazy_list<proof_state> operator()(proof_state const & p) const = 0;
|
||||
virtual ~tactic_cell();
|
||||
virtual tactic_result_ref operator()(proof_state const & p) const = 0;
|
||||
};
|
||||
|
||||
class tactic {
|
||||
|
@ -27,10 +39,10 @@ public:
|
|||
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); }
|
||||
tactic & operator=(tactic const & s) { LEAN_COPY_REF(tactic, s); }
|
||||
tactic & operator=(tactic && s) { LEAN_MOVE_REF(tactic, s); }
|
||||
tactic & operator=(tactic const & s);
|
||||
tactic & operator=(tactic && s);
|
||||
|
||||
lazy_list<proof_state> operator()(proof_state const & p) const { return m_ptr->operator()(p); }
|
||||
tactic_result_ref operator()(proof_state const & p) const { return m_ptr->operator()(p); }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue