From c413a2d189bd09857ae2a2eb472a573e253fa9b2 Mon Sep 17 00:00:00 2001 From: Gordon Smith Date: Sun, 26 May 2024 11:25:23 +0100 Subject: [PATCH] WIP --- src/lift.cpp | 41 +++++++++++++++++++++++------------------ src/lift.hpp | 10 +++++----- test/main.cpp | 2 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/lift.cpp b/src/lift.cpp index 78f1435..656f48c 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -74,31 +74,36 @@ namespace cmcpp return i; } - CoreValueIter::CoreValueIter(const std::vector> &values) : values(values) + CoreValueIter::CoreValueIter(const std::vector> &values) { + for (auto v : values) + { + WasmVal wv(std::holds_alternative(v) ? WasmValType::I32 : WasmValType::F32); + wv.v = WasmValVariant(v); + this->values.push_back(wv); + } } - std::variant CoreValueIter::next(const std::string &t) + std::variant CoreValueIter::next(WasmValType t) { std::variant v = values[i]; i++; - if (t == "i32") - { - assert(std::holds_alternative(v) && std::get(v) >= 0 && std::get(v) < (1UL << 32)); - } - else if (t == "i64") - { - assert(std::holds_alternative(v) && std::get(v) >= 0 && std::get(v) < (1ULL << 64)); - } - else if (t == "f32" || t == "f64") - { - assert(std::holds_alternative(v) || std::holds_alternative(v)); - } - else - { - assert(false); - } + // switch (t) + // { + // case WasmValType::I32: + // assert(std::holds_alternative(v) && std::get(v) >= 0 && std::get(v) < (1UL << 32)); + // break; + // case WasmValType::I64: + // assert(std::holds_alternative(v) && std::get(v) >= 0 && std::get(v) < (1ULL << 64)); + // break; + // case WasmValType::F32: + // case WasmValType::F64: + // assert(std::holds_alternative(v) || std::holds_alternative(v)); + // break; + // default: + // assert(false); + // } return v; } diff --git a/src/lift.hpp b/src/lift.hpp index 9558834..d45c606 100644 --- a/src/lift.hpp +++ b/src/lift.hpp @@ -12,14 +12,14 @@ namespace cmcpp class CoreValueIter { - protected: - std::vector> values; - size_t i = 0; public: - CoreValueIter(const std::vector> &values); + std::vector values; + size_t i = 0; + + CoreValueIter(const std::vector> &values); - std::variant next(const std::string &t); + std::variant next(WasmValType t); }; } diff --git a/test/main.cpp b/test/main.cpp index a0e1639..f407e42 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -154,7 +154,7 @@ void test(const cmcpp::ValBase &t, const std::vector> & // } // auto got = cmcpp::lift_flat(*cx, vi, t.t); - // assert(vi.i == vi.values.size()); + assert(vi.i == vi.values.size()); // if (got != v) // { // fail(test_name() + " initial lift_flat() expected " + v + " but got " + got);