From d80e0dbd20bb8597afe92f770e39d20440557d1f Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sat, 25 Jun 2022 10:16:12 -0700 Subject: Demo for a coroutine-based step evaluator. --- main.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 6b7b0f4..0240bb5 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "aisa/aisa.h" #include "git-tag.h" @@ -6,6 +8,54 @@ int main(int argc, const char *argv[]) { std::cout << "Version " << GIT_TAG << "\n"; - aisa::do_something(); + + aisa::Step step; + const_cast> &>(step.predicate) = std::optional(std::make_pair(123, 456)); + const_cast &>(step.source_regs).emplace_back(12); + const_cast &>(step.source_regs).emplace_back(34); + const_cast &>(step.source_regs).emplace_back(56); + + struct State : public aisa::EvalState { + std::map regs; + + std::optional load_reg(aisa::regnum_t rn) + { + std::cout << "state.load_reg(" << rn << ") = "; + if (auto x = regs.find(rn); x != regs.end()) { + std::cout << x->second << "\n"; + return x->second; + } + std::cout << "(not available)\n"; + return {}; + } + } state; + + auto t = state.async_load_reg(999); + t(); + t(); + t(); + std::cout << "set regs[999] = 54321\n"; state.regs[999] = 54321; + std::optional result; + while (!result.has_value()) + result = t(); + std::cout << "result = " << *result << "\n"; + + std::cout << "\n\n\n"; + + auto w = step.evaluate(state); + w(); + w(); + w(); + std::cout << "set predicate (valid)\n"; state.regs[step.predicate->first] = step.predicate->second; + w(); + w(); + w(); + std::cout << "set regs (all)\n"; + for (int i = 10; i < 100; ++i) + state.regs[i] = 1000 + i; + for (bool done = false; !done; done = w()) + ; + std::cout << "huzzah!\n"; + return 0; } -- cgit v1.2.3