@@ -110,10 +110,6 @@ WasmValVector fromWamr(size_t count, const wasm_val_t *values)
110110 assert (false );
111111 }
112112 }
113- // for (size_t i = count; i < target_count; i++)
114- // {
115- // result[i] = (int32_t)(std::get<int32_t>(result[count - 1]) + (i * alignment));
116- // }
117113 return result;
118114}
119115
@@ -163,17 +159,18 @@ int main()
163159
164160 LiftLowerContext liftLowerContext (trap, convert, opts);
165161
166- using and_func_t = std::function <bool_t (bool_t , bool_t )>;
162+ using and_func_t = func_t <bool_t (bool_t , bool_t )>;
167163 auto and_func = wasm_runtime_lookup_function (module_inst, " example:sample/booleans#and" );
168164 and_func_t call_and = [&](bool_t a, bool_t b) -> bool_t
169165 {
170- using inputs_t = ValTrait<and_func_t >::params_t ;
171- using outputs_t = ValTrait<and_func_t >::result_t ;
172- auto inputs = toWamr (lower_flat (liftLowerContext, inputs_t {a, b}));
166+ using params_t = ValTrait<and_func_t >::params_t ;
167+ using results_t = ValTrait<and_func_t >::results_t ;
168+
169+ auto inputs = toWamr (lower_flat_values (liftLowerContext, MAX_FLAT_PARAMS, params_t {a, b}));
173170 auto output_size = 1 ;
174171 wasm_val_t outputs[output_size];
175172 auto call_result = wasm_runtime_call_wasm_a (exec_env, and_func, output_size, outputs, inputs.size (), inputs.data ());
176- auto result = lift_flat< outputs_t >( liftLowerContext, fromWamr<outputs_t >(output_size, outputs));
173+ auto result = std::get< 0 >(lift_flat_values< results_t >( liftLowerContext, MAX_FLAT_RESULTS, fromWamr<results_t >(output_size, outputs) ));
177174 std::cout << " and_func(" << a << " , " << b << " ): " << result << std::endl;
178175 return result;
179176 };
@@ -182,77 +179,78 @@ int main()
182179 call_and (true , false );
183180 call_and (true , true );
184181
185- using add_func_t = std::function <float64_t (float64_t , float64_t )>;
182+ using add_func_t = func_t <float64_t (float64_t , float64_t )>;
186183 auto add_func = wasm_runtime_lookup_function (module_inst, " example:sample/floats#add" );
187184 add_func_t call_add = [&](float64_t input1, float64_t input2) -> float64_t
188185 {
189- using inputs_t = ValTrait<add_func_t >::params_t ;
190- using outputs_t = ValTrait<add_func_t >::result_t ;
186+ using params_t = ValTrait<add_func_t >::params_t ;
187+ using results_t = ValTrait<add_func_t >::results_t ;
191188
192- auto inputs = toWamr (lower_flat (liftLowerContext, inputs_t {input1, input2}));
189+ auto inputs = toWamr (lower_flat_values (liftLowerContext, MAX_FLAT_PARAMS, params_t {input1, input2}));
193190 auto output_size = 1 ;
194191 wasm_val_t outputs[output_size];
195192 auto call_result = wasm_runtime_call_wasm_a (exec_env, add_func, output_size, outputs, inputs.size (), inputs.data ());
196- auto result = lift_flat< outputs_t >( liftLowerContext, fromWamr<outputs_t >(output_size, outputs));
193+ auto result = std::get< 0 >(lift_flat_values< results_t >( liftLowerContext, MAX_FLAT_RESULTS, fromWamr<results_t >(output_size, outputs) ));
197194 std::cout << " add_func(" << input1 << " , " << input2 << " ): " << result << std::endl;
198195 return result;
199196 };
200197 call_add (3.1 , 0.2 );
201198
202- using reverse_func_t = std::function <string_t (string_t )>;
199+ using reverse_func_t = func_t <string_t (string_t )>;
203200 auto reverse_func = wasm_runtime_lookup_function (module_inst, " example:sample/strings#reverse" );
204201 auto reverse_cleanup_func = wasm_runtime_lookup_function (module_inst, " cabi_post_example:sample/strings#reverse" );
205202 reverse_func_t call_reverse = [&](string_t input1) -> string_t
206203 {
207- using inputs_t = ValTrait<reverse_func_t >::params_t ;
208- using outputs_t = ValTrait<reverse_func_t >::result_t ;
204+ auto flat_ft_lower = func::flatten<reverse_func_t >(liftLowerContext, func::ContextType::Lower);
205+ auto flat_ft_lift = func::flatten<reverse_func_t >(liftLowerContext, func::ContextType::Lift);
206+
207+ using params_t = ValTrait<reverse_func_t >::params_t ;
208+ using results_t = ValTrait<reverse_func_t >::results_t ;
209209
210- auto inputs = toWamr (lower_flat (liftLowerContext, inputs_t {input1}));
210+ auto inputs = toWamr (lower_flat_values (liftLowerContext, MAX_FLAT_PARAMS, params_t {input1}));
211211 auto output_size = 1 ;
212212 wasm_val_t outputs[output_size];
213213 auto call_result = wasm_runtime_call_wasm_a (exec_env, reverse_func, output_size, outputs, inputs.size (), inputs.data ());
214- // auto result = load<outputs_t>(liftLowerContext, outputs[0].of.i32);
215- auto result = lift_flat<outputs_t >(liftLowerContext, fromWamr<outputs_t >(output_size, outputs));
214+ auto result = std::get<0 >(lift_flat_values<results_t >(liftLowerContext, MAX_FLAT_RESULTS, fromWamr<results_t >(output_size, outputs)));
216215 std::cout << " reverse_string(" << input1 << " ): " << result << std::endl;
217- call_result = wasm_runtime_call_wasm_a (exec_env, reverse_cleanup_func, 0 , nullptr , 1 , outputs);
218216 return result;
219217 };
220218 auto call_reverse_result = call_reverse (" Hello World!" );
221219 call_reverse (call_reverse_result);
222220
223- using reverse_tuple_func_t = std::function <tuple_t <string_t , bool_t >(tuple_t <bool_t , string_t >)>;
221+ using reverse_tuple_func_t = func_t <tuple_t <string_t , bool_t >(tuple_t <bool_t , string_t >)>;
224222 auto reverse_tuple_func = wasm_runtime_lookup_function (module_inst, " example:sample/tuples#reverse" );
225223 auto reverse_tuple_cleanup_func = wasm_runtime_lookup_function (module_inst, " cabi_post_example:sample/tuples#reverse" );
226224 reverse_tuple_func_t call_reverse_tuple = [&](tuple_t <bool_t , string_t > a) -> tuple_t <string_t , bool_t >
227225 {
228- using inputs_t = ValTrait<reverse_tuple_func_t >::params_t ;
229- using outputs_t = ValTrait<reverse_tuple_func_t >::result_t ;
226+ using params_t = ValTrait<reverse_tuple_func_t >::params_t ;
227+ using results_t = ValTrait<reverse_tuple_func_t >::results_t ;
230228
231- auto inputs = toWamr (lower_flat (liftLowerContext, a ));
229+ auto inputs = toWamr (lower_flat_values (liftLowerContext, MAX_FLAT_PARAMS, params_t {a} ));
232230 auto output_size = 1 ;
233231 wasm_val_t outputs[output_size];
234232 auto call_result = wasm_runtime_call_wasm_a (exec_env, reverse_tuple_func, output_size, outputs, inputs.size (), inputs.data ());
235- auto result = load< outputs_t >( liftLowerContext, outputs-> of . i32 );
233+ auto result = std::get< 0 >(lift_flat_values< results_t >( liftLowerContext, MAX_FLAT_RESULTS, fromWamr< results_t >(output_size, outputs)) );
236234 std::cout << " reverse_tuple(" << std::get<0 >(a) << " , " << std::get<1 >(a) << " ): " << std::get<0 >(result) << " , " << std::get<1 >(result) << std::endl;
237235 call_result = wasm_runtime_call_wasm_a (exec_env, reverse_tuple_cleanup_func, 0 , nullptr , 1 , outputs);
238236 return result;
239237 };
240238 auto call_reverse_tuple_result = call_reverse_tuple ({false , " Hello World!" });
241239 // call_reverse_tuple({std::get<1>(call_reverse_tuple_result), std::get<0>(call_reverse_tuple_result}));
242240
243- using list_filter_bool_func_t = std::function <list_t <string_t >(list_t <variant_t <bool_t , string_t >>)>;
241+ using list_filter_bool_func_t = func_t <list_t <string_t >(list_t <variant_t <bool_t , string_t >>)>;
244242 auto list_filter_bool_func = wasm_runtime_lookup_function (module_inst, " example:sample/lists#filter-bool" );
245243 auto list_filter_bool_cleanup_func = wasm_runtime_lookup_function (module_inst, " cabi_post_example:sample/lists#filter-bool" );
246244 auto call_list_filter_bool = [&](list_t <variant_t <bool_t , string_t >> a) -> list_t <string_t >
247245 {
248- using inputs_t = ValTrait<list_filter_bool_func_t >::params_t ;
249- using outputs_t = ValTrait<list_filter_bool_func_t >::result_t ;
246+ using params_t = ValTrait<list_filter_bool_func_t >::params_t ;
247+ using results_t = ValTrait<list_filter_bool_func_t >::results_t ;
250248
251- auto inputs = toWamr (lower_flat (liftLowerContext, a ));
249+ auto inputs = toWamr (lower_flat_values (liftLowerContext, MAX_FLAT_PARAMS, params_t {a} ));
252250 auto output_size = 1 ;
253251 wasm_val_t outputs[output_size];
254252 auto call_result = wasm_runtime_call_wasm_a (exec_env, list_filter_bool_func, output_size, outputs, inputs.size (), inputs.data ());
255- auto result = lift_flat< outputs_t >( liftLowerContext, fromWamr<outputs_t >(output_size, outputs));
253+ auto result = std::get< 0 >(lift_flat_values< results_t >( liftLowerContext, MAX_FLAT_RESULTS, fromWamr<results_t >(output_size, outputs) ));
256254 std::cout << " list_filter_bool(" << a.size () << " ): " << result.size () << std::endl;
257255 call_result = wasm_runtime_call_wasm_a (exec_env, list_filter_bool_cleanup_func, 0 , nullptr , 1 , outputs);
258256 return result;
0 commit comments