#pragma once #include "aisa/aisa.h" namespace aisa { template struct EvalState { CRTP & crtp() noexcept { return static_cast(*this); } task async_load_reg(regnum_t rn) { while (true) { if (auto rv = crtp().load_reg(rn); rv.has_value()) co_return *rv; co_await suspend(); } } task async_store_reg(regnum_t rn, regval_t rv) { while (true) { if (crtp().store_reg(rn, rv)) co_return; co_await suspend(); } } task eval(const Step &step) { if (step.predicate.has_value()) { regval_t pval = co_await async_load_reg(step.predicate->first); if (pval != step.predicate->second) co_return; } std::vector source_vals; source_vals.reserve(step.source_regs.size()); for (unsigned int i = 0; i < step.source_regs.size(); ++i) source_vals.emplace_back(co_await async_load_reg(step.source_regs[i])); auto destination_vals = step.compute_destinations(source_vals); for (unsigned int i = 0; i < step.destination_regs.size(); ++i) co_await async_store_reg(step.destination_regs[i], destination_vals[i]); } }; }