diff options
Diffstat (limited to '')
| -rw-r--r-- | aisa/eval.h | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/aisa/eval.h b/aisa/eval.h deleted file mode 100644 index a301e93..0000000 --- a/aisa/eval.h +++ /dev/null | |||
| @@ -1,65 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <coroutine> | ||
| 4 | #include <memory> | ||
| 5 | #include <optional> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "aisa/aisa.h" | ||
| 10 | #include "aisa/coroutine.h" // IWYU pragma: export | ||
| 11 | |||
| 12 | namespace aisa { | ||
| 13 | |||
| 14 | template<typename CRTP> struct EvalState { | ||
| 15 | struct EvalContext { | ||
| 16 | task<void> coroutine; | ||
| 17 | |||
| 18 | bool resume() { return coroutine(); } | ||
| 19 | }; | ||
| 20 | |||
| 21 | CRTP & crtp() noexcept { return static_cast<CRTP &>(*this); } | ||
| 22 | |||
| 23 | task<regval_t> async_load_reg(regnum_t rn) | ||
| 24 | { | ||
| 25 | while (true) { | ||
| 26 | if (auto rv = crtp().load_reg(rn); rv.has_value()) | ||
| 27 | co_return *rv; | ||
| 28 | co_await std::suspend_always{}; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | task<void> async_store_reg(regnum_t rn, regval_t rv) | ||
| 33 | { | ||
| 34 | while (true) { | ||
| 35 | if (crtp().store_reg(rn, rv)) | ||
| 36 | co_return; | ||
| 37 | co_await std::suspend_always{}; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | task<void> async_evaluate(EvalContext &contex, const Step &step) | ||
| 42 | { | ||
| 43 | if (step.predicate.has_value()) { | ||
| 44 | regval_t pval = co_await async_load_reg(step.predicate->first); | ||
| 45 | if (pval != step.predicate->second) | ||
| 46 | co_return; | ||
| 47 | } | ||
| 48 | std::vector<regval_t> source_vals; | ||
| 49 | source_vals.reserve(step.source_regs.size()); | ||
| 50 | for (unsigned int i = 0; i < step.source_regs.size(); ++i) | ||
| 51 | source_vals.emplace_back(co_await async_load_reg(step.source_regs[i])); | ||
| 52 | auto destination_vals = step.compute_destinations(source_vals); | ||
| 53 | for (unsigned int i = 0; i < step.destination_regs.size(); ++i) | ||
| 54 | co_await async_store_reg(step.destination_regs[i], destination_vals[i]); | ||
| 55 | } | ||
| 56 | |||
| 57 | std::unique_ptr<EvalContext> operator()(const Step &step) | ||
| 58 | { | ||
| 59 | auto context = std::make_unique<EvalContext>(); | ||
| 60 | context->coroutine = async_evaluate(*context, step); | ||
| 61 | return context; | ||
| 62 | } | ||
| 63 | }; | ||
| 64 | |||
| 65 | } | ||
