8using namespace std::string_literals;
12static_assert(
sizeof(
void*) <=
sizeof(
u64),
"pointer doesn't fit into Lit");
17const Def* do_reify(
const Def* def) {
18 auto& world = def->
world();
19 return world.
lit(world.call<
Code>(def->
type()),
reinterpret_cast<u64>(def));
22void debug_print(
const Def* lvl,
const Def* def) {
23 auto& world = def->
world();
24 auto level = fe::Log::Level::Debug;
26 level = std::to_underlying(fe::Log::Level::Error) <=
int(*l)
27 &&
int(*l) <= std::to_underlying(fe::Log::Level::Debug)
28 ?
static_cast<fe::Log::Level
>(*l)
29 : fe::Log::Level::Debug;
31 world.
log().log(level,
"{}debug_print: {}{}", fe::term::FG::Yellow, def, fe::term::FG::Reset);
32 world.log().log(level, def->
loc(),
"def : {}", def);
34 world.log().log(level, def->
type()->
loc(),
"type: {}", def->
type());
35 world.log().log(level, def->
loc(),
"node: {}", def->
node_name());
36 world.log().log(level, def->
loc(),
"ops : {}", def->
num_ops());
37 world.log().log(level, def->
loc(),
"proj: {}", def->
num_projs());
38 world.log().log(level, def->
loc(),
"eops: {}", def->
num_deps());
45 auto [lvl, x] = arg->
projs<2>();
53 if (
auto l =
Lit::isa(arg))
return reinterpret_cast<const Def*
>(*l);
62 auto [a, b] = arg->
projs<2>();
64 if (res ^ (
id ==
struc::e)) arg->
blame(
"'{}' and '{}' {}structural-equivalent", a, b, !res ?
"not " :
"").bail();
70 auto [a, b] = arg->
projs<2>();
72 if (res ^ (
id ==
alpha::e)) arg->
blame(
"'{}' and '{}' {}alpha-equivalent", a, b, !res ?
"not " :
"").bail();
77 if (!arg->isa<
Bot>()) c->blame(
"'{}' is not bottom", arg).bail();
82 auto& w =
type->world();
83 auto [cond, val, msg] = arg->
projs<3>();
85 if (cond == w.lit_tt())
return val;
86 if (cond == w.lit_ff()) {
88 if (s.empty()) s =
"unknown error"s;
static bool test_alpha(const Def *d1, const Def *d2)
size_t num_deps() const noexcept
World & world() const noexcept
std::string_view node_name() const
auto projs(Projector auto f) const
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (other...
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
fe::Error & blame(fe::cite_string< Args... > s, Args &&... args) const
Reports an error that blames this; chain Error::n for Notes and Error::bail to throw.
nat_t num_projs() const
Yields Def::arity(), if it is a Lit, or 1 otherwise.
constexpr u32 gid() const noexcept
Global id - unique number for this Def.
std::string unique_name() const
name + "_" + Def::gid
constexpr size_t num_ops() const noexcept
static std::optional< T > isa(const Def *def)
const Lit * lit(const Def *type, u64 val)
const fe::Log & log() const
Log via log().e("...", args) etc.; owned by the Driver.
const Lit * lit_nat(nat_t a)
const Def * normalize_reify(const Def *, const Def *, const Def *arg)
const Def * normalize_dbg(const Def *, const Def *, const Def *arg)
const Def * normalize_check(const Def *type, const Def *, const Def *arg)
const Def * normalize_check_bot(const Def *, const Def *c, const Def *arg)
const Def * normalize_gid(const Def *, const Def *, const Def *arg)
const Def * normalize_alpha(const Def *, const Def *, const Def *arg)
const Def * normalize_type(const Def *, const Def *, const Def *arg)
const Def * normalize_struc(const Def *, const Def *, const Def *arg)
const Def * normalize_reflect(const Def *, const Def *, const Def *arg)
std::string tuple2str(const Def *)
#define MIM_refly_NORMALIZER_IMPL