summaryrefslogtreecommitdiff
path: root/aisa
diff options
context:
space:
mode:
authorJulian Blake Kongslie2022-06-25 23:20:28 -0700
committerJulian Blake Kongslie2022-06-25 23:20:28 -0700
commitb5608dc9d4739dbb97798d83fd7821a051c6afe2 (patch)
treef17ed20c99e1a4b55ebd27d9c853f815ee537dc3 /aisa
parentRemove unneeded std::move calls. (diff)
downloadissim-b5608dc9d4739dbb97798d83fd7821a051c6afe2.tar.xz
Use a separate EvalContext structure for holding some state.
Diffstat (limited to 'aisa')
-rw-r--r--aisa/eval.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/aisa/eval.h b/aisa/eval.h
index 30dc617..a301e93 100644
--- a/aisa/eval.h
+++ b/aisa/eval.h
@@ -1,6 +1,7 @@
1#pragma once 1#pragma once
2 2
3#include <coroutine> 3#include <coroutine>
4#include <memory>
4#include <optional> 5#include <optional>
5#include <utility> 6#include <utility>
6#include <vector> 7#include <vector>
@@ -11,6 +12,12 @@
11namespace aisa { 12namespace aisa {
12 13
13 template<typename CRTP> struct EvalState { 14 template<typename CRTP> struct EvalState {
15 struct EvalContext {
16 task<void> coroutine;
17
18 bool resume() { return coroutine(); }
19 };
20
14 CRTP & crtp() noexcept { return static_cast<CRTP &>(*this); } 21 CRTP & crtp() noexcept { return static_cast<CRTP &>(*this); }
15 22
16 task<regval_t> async_load_reg(regnum_t rn) 23 task<regval_t> async_load_reg(regnum_t rn)
@@ -31,7 +38,7 @@ namespace aisa {
31 } 38 }
32 } 39 }
33 40
34 task<void> eval(const Step &step) 41 task<void> async_evaluate(EvalContext &contex, const Step &step)
35 { 42 {
36 if (step.predicate.has_value()) { 43 if (step.predicate.has_value()) {
37 regval_t pval = co_await async_load_reg(step.predicate->first); 44 regval_t pval = co_await async_load_reg(step.predicate->first);
@@ -46,6 +53,13 @@ namespace aisa {
46 for (unsigned int i = 0; i < step.destination_regs.size(); ++i) 53 for (unsigned int i = 0; i < step.destination_regs.size(); ++i)
47 co_await async_store_reg(step.destination_regs[i], destination_vals[i]); 54 co_await async_store_reg(step.destination_regs[i], destination_vals[i]);
48 } 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 }
49 }; 63 };
50 64
51} 65}