2015-11-11 01:00:26 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "kernel/expr.h"
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
namespace blast {
|
2015-11-11 01:49:41 +00:00
|
|
|
/**
|
|
|
|
\brief Result produced by actions, proof-steps and choice-point next method.
|
|
|
|
There are 3 possible results
|
|
|
|
1- Failed: action/step/next failed.
|
|
|
|
2- NewBranch: a new branch has been created (or updated) in the current state.
|
|
|
|
3- Solved(pr): the current branch has been closed with proof pr. */
|
2015-11-11 01:00:26 +00:00
|
|
|
class action_result {
|
|
|
|
public:
|
2015-11-11 01:49:41 +00:00
|
|
|
enum kind { Failed, NewBranch, Solved };
|
2015-11-11 01:00:26 +00:00
|
|
|
private:
|
|
|
|
kind m_kind;
|
|
|
|
expr m_proof;
|
2015-11-18 20:27:24 +00:00
|
|
|
public:
|
2015-11-11 01:00:26 +00:00
|
|
|
action_result(bool b = true):m_kind(b ? NewBranch : Failed) {}
|
|
|
|
action_result(expr const & pr):m_kind(Solved), m_proof(pr) {}
|
|
|
|
kind get_kind() const { return m_kind; }
|
|
|
|
expr get_proof() const { lean_assert(m_kind == Solved); return m_proof; }
|
|
|
|
static action_result failed() { return action_result(false); }
|
|
|
|
static action_result new_branch() { return action_result(true); }
|
|
|
|
static action_result solved(expr const & pr) { return action_result(pr); }
|
2015-11-14 23:58:11 +00:00
|
|
|
optional<expr> to_opt_expr() const { return m_kind == Solved ? some_expr(m_proof) : none_expr(); }
|
2015-11-11 01:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool failed(action_result const & r) { return r.get_kind() == action_result::Failed; }
|
2015-11-14 23:58:11 +00:00
|
|
|
inline bool solved(action_result const & r) { return r.get_kind() == action_result::Solved; }
|
2015-11-18 20:27:24 +00:00
|
|
|
|
|
|
|
#define Try(Code) { action_result r = Code; if (!failed(r)) return r; }
|
|
|
|
#define TrySolve(Code) { action_result r = Code; if (solved(r)) return r.to_opt_expr(); }
|
2015-11-11 01:00:26 +00:00
|
|
|
}}
|