Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonSmith committed May 26, 2024
1 parent 4a19a69 commit c413a2d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
41 changes: 23 additions & 18 deletions src/lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,36 @@ namespace cmcpp
return i;
}

CoreValueIter::CoreValueIter(const std::vector<std::variant<int, float>> &values) : values(values)
CoreValueIter::CoreValueIter(const std::vector<std::variant<int32_t, float32_t>> &values)
{
for (auto v : values)
{
WasmVal wv(std::holds_alternative<int32_t>(v) ? WasmValType::I32 : WasmValType::F32);
wv.v = WasmValVariant(v);
this->values.push_back(wv);
}
}

std::variant<int, float> CoreValueIter::next(const std::string &t)
std::variant<int, float> CoreValueIter::next(WasmValType t)
{
std::variant<int, float> v = values[i];
i++;

if (t == "i32")
{
assert(std::holds_alternative<int>(v) && std::get<int>(v) >= 0 && std::get<int>(v) < (1UL << 32));
}
else if (t == "i64")
{
assert(std::holds_alternative<int>(v) && std::get<int>(v) >= 0 && std::get<int>(v) < (1ULL << 64));
}
else if (t == "f32" || t == "f64")
{
assert(std::holds_alternative<int>(v) || std::holds_alternative<float>(v));
}
else
{
assert(false);
}
// switch (t)
// {
// case WasmValType::I32:
// assert(std::holds_alternative<int>(v) && std::get<int>(v) >= 0 && std::get<int>(v) < (1UL << 32));
// break;
// case WasmValType::I64:
// assert(std::holds_alternative<int>(v) && std::get<int>(v) >= 0 && std::get<int>(v) < (1ULL << 64));
// break;
// case WasmValType::F32:
// case WasmValType::F64:
// assert(std::holds_alternative<int>(v) || std::holds_alternative<float>(v));
// break;
// default:
// assert(false);
// }

return v;
}
Expand Down
10 changes: 5 additions & 5 deletions src/lift.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace cmcpp

class CoreValueIter
{
protected:
std::vector<std::variant<int, float>> values;
size_t i = 0;

public:
CoreValueIter(const std::vector<std::variant<int, float>> &values);
std::vector<WasmVal> values;
size_t i = 0;

CoreValueIter(const std::vector<std::variant<int32_t, float32_t>> &values);

std::variant<int, float> next(const std::string &t);
std::variant<int32_t, float32_t> next(WasmValType t);
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void test(const cmcpp::ValBase &t, const std::vector<std::variant<int, float>> &
// }

// 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);
Expand Down

0 comments on commit c413a2d

Please sign in to comment.