From b5608dc9d4739dbb97798d83fd7821a051c6afe2 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sat, 25 Jun 2022 23:20:28 -0700 Subject: Use a separate EvalContext structure for holding some state. --- aisa/eval.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'aisa') 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 @@ #pragma once #include +#include #include #include #include @@ -11,6 +12,12 @@ namespace aisa { template struct EvalState { + struct EvalContext { + task coroutine; + + bool resume() { return coroutine(); } + }; + CRTP & crtp() noexcept { return static_cast(*this); } task async_load_reg(regnum_t rn) @@ -31,7 +38,7 @@ namespace aisa { } } - task eval(const Step &step) + task async_evaluate(EvalContext &contex, const Step &step) { if (step.predicate.has_value()) { regval_t pval = co_await async_load_reg(step.predicate->first); @@ -46,6 +53,13 @@ namespace aisa { for (unsigned int i = 0; i < step.destination_regs.size(); ++i) co_await async_store_reg(step.destination_regs[i], destination_vals[i]); } + + std::unique_ptr operator()(const Step &step) + { + auto context = std::make_unique(); + context->coroutine = async_evaluate(*context, step); + return context; + } }; } -- cgit v1.2.3