66#include " store.hpp"
77#include " load.hpp"
88#include " util.hpp"
9+ #include " util.hpp"
910
1011#include < tuple>
1112#include < limits>
@@ -15,11 +16,13 @@ namespace cmcpp
1516{
1617 namespace variant
1718 {
19+
1820 // template <Variant T>
19- // std::pair<int, std::optional< typename T::value_type> > match_case(const T &v)
21+ // std::pair<int, typename ValTrait<T>::inner_type > match_case(const T &v)
2022 // {
2123 // auto index = v.index();
22- // auto value = std::get<index>(v);
24+ // auto value = std::visit([](auto &&arg) -> typename ValTrait<T>::inner_type
25+ // { return arg; }, v);
2326 // return {index, value};
2427 // }
2528
@@ -64,62 +67,78 @@ namespace cmcpp
6467 // WasmValVector flatten_variant(const T &v)
6568 // {
6669 // WasmValVector flat;
67- // std::visit([&](auto &&arg) {
70+ // std::visit([&](auto &&arg)
71+ // {
6872 // using V = std::decay_t<decltype(arg)>;
6973 // auto f = lower_flat(arg);
70- // flat.insert(flat.end(), f.begin(), f.end());
71- // }, v);
74+ // flat.insert(flat.end(), f.begin(), f.end()); }, v);
7275 // }
7376
77+ template <Variant T>
78+ WasmValVector lower_flat_variant (CallContext &cx, const T &v)
79+ {
80+ WasmValVector retVal = {};
81+ ValType t = variant_type (v);
82+ // auto index = variant_index(v);
83+ // auto value = std::get<ValTrait<T>::index>(v);
84+ // auto value = variant_value(v, index);
85+ // ValTrait<T>::inner_type v = 42;
86+ // auto value = std::get<typename ValTrait<T>::inner_type>(v);
7487
75- // template <Variant T>
76- // void lower_flat(CallContext &cx, const T &v, uint32_t ptr)
77- // {
78- // auto [case_index, case_value] = match_case(v);
79- // std::vector<std::string> flat_types = flatten_variant(v);
80- // assert(flat_types[0] == "i32");
81- // flat_types.erase(flat_types.begin());
82- // auto c = cases[case_index];
83- // std::vector<WasmVal> payload;
84- // if (c->v.has_value())
85- // {
86- // payload = lower_flat(cx, case_value.value(), c->v.value());
87- // auto vTypes = flatten_type(c->v.value());
88- // for (size_t i = 0; i < payload.size(); ++i)
89- // {
90- // auto fv = payload[i];
91- // auto have = vTypes[i];
92- // auto want = flat_types[0];
93- // flat_types.erase(flat_types.begin());
94- // if (have == "f32" && want == "i32")
95- // {
96- // payload[i] = encode_float_as_i32(std::get<float32_t>(fv));
97- // }
98- // else if (have == "i32" && want == "i64")
99- // {
100- // payload[i] = fv;
101- // }
102- // else if (have == "f32" && want == "i64")
103- // {
104- // payload[i] = encode_float_as_i32(std::get<float32_t>(fv));
105- // }
106- // else if (have == "f64" && want == "i64")
107- // {
108- // payload[i] = static_cast<int64_t>(encode_float_as_i64(std::get<float64_t>(fv)));
109- // }
110- // else
111- // {
112- // assert(have == want);
113- // }
114- // }
115- // }
116- // for (auto _ : flat_types)
117- // {
118- // payload.push_back(0);
119- // }
120- // payload.insert(payload.begin(), case_index);
121- // return payload;
122- // }
88+ // auto [case_index, case_value] = match_case(v);
89+ // auto payload = cmcpp::lower_flat(cx, value);
90+ // auto flat_types = flatten_variant(v);
91+ // assert(flat_types[0] == "i32");
92+ // flat_types.erase(flat_types.begin());
93+ // auto c = cases[case_index];
94+ // std::vector<WasmVal> payload;
95+ // if (c->v.has_value())
96+ // {
97+ // payload = lower_flat(cx, case_value.value(), c->v.value());
98+ // auto vTypes = flatten_type(c->v.value());
99+ // for (size_t i = 0; i < payload.size(); ++i)
100+ // {
101+ // auto fv = payload[i];
102+ // auto have = vTypes[i];
103+ // auto want = flat_types[0];
104+ // flat_types.erase(flat_types.begin());
105+ // if (have == "f32" && want == "i32")
106+ // {
107+ // payload[i] = encode_float_as_i32(std::get<float32_t>(fv));
108+ // }
109+ // else if (have == "i32" && want == "i64")
110+ // {
111+ // payload[i] = fv;
112+ // }
113+ // else if (have == "f32" && want == "i64")
114+ // {
115+ // payload[i] = encode_float_as_i32(std::get<float32_t>(fv));
116+ // }
117+ // else if (have == "f64" && want == "i64")
118+ // {
119+ // payload[i] = static_cast<int64_t>(encode_float_as_i64(std::get<float64_t>(fv)));
120+ // }
121+ // else
122+ // {
123+ // assert(have == want);
124+ // }
125+ // }
126+ // }
127+ // for (auto _ : flat_types)
128+ // {
129+ // payload.push_back(0);
130+ // }
131+ // payload.insert(payload.begin(), case_index);
132+ // return payload;
133+ return retVal;
134+ }
135+
136+ template <Variant T>
137+ inline T lift_flat (const CallContext &cx, const WasmValVectorIterator &vi)
138+ {
139+ T retVal;
140+ return retVal;
141+ }
123142 }
124143}
125144
0 commit comments