Skip to content

Commit 230d681

Browse files
committed
fix: remove additional tuple wrapper on lift
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent b49b11d commit 230d681

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

include/cmcpp/lift.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@ namespace cmcpp
4343
template <Option T>
4444
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi);
4545

46-
template <Tuple T>
46+
template <Field T>
4747
inline T lift_heap_values(const LiftLowerContext &cx, const CoreValueIter &vi)
4848
{
4949
uint32_t ptr = vi.next<int32_t>();
50-
using tuple_type = typename std::tuple_element<0, typename ValTrait<T>::inner_type>::type;
51-
trap_if(cx, ptr != align_to(ptr, ValTrait<tuple_type>::alignment));
52-
trap_if(cx, ptr + ValTrait<tuple_type>::size > cx.opts.memory.size());
53-
auto retVal = load<tuple_type>(cx, ptr);
54-
return retVal;
50+
trap_if(cx, ptr != align_to(ptr, ValTrait<T>::alignment));
51+
trap_if(cx, ptr + ValTrait<T>::size > cx.opts.memory.size());
52+
return load<T>(cx, ptr);
5553
}
5654

57-
template <Tuple T>
55+
template <Field T>
5856
inline T lift_flat_values(const LiftLowerContext &cx, uint max_flat, const CoreValueIter &vi)
5957
{
6058
auto flat_types = ValTrait<T>::flat_types;

include/cmcpp/traits.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,9 @@ namespace cmcpp
722722
static constexpr ValType type = ValType::Func;
723723
using inner_type = std::function<R(Args...)>;
724724
using params_t = tuple_t<Args...>;
725-
using results_t = tuple_t<R>;
725+
using result_t = R;
726726
static constexpr auto flat_params_types = ValTrait<params_t>::flat_types;
727-
static constexpr auto flat_result_types = ValTrait<results_t>::flat_types;
727+
static constexpr auto flat_result_types = ValTrait<result_t>::flat_types;
728728
};
729729

730730
template <typename T>

samples/wamr/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ template <typename F>
117117
func_t<F> attach(const wasm_module_inst_t &module_inst, const wasm_exec_env_t &exec_env, LiftLowerContext &liftLowerContext, const char *name)
118118
{
119119
using params_t = typename ValTrait<func_t<F>>::params_t;
120-
using results_t = typename ValTrait<func_t<F>>::results_t;
120+
using result_t = typename ValTrait<func_t<F>>::result_t;
121121

122122
wasm_function_inst_t guest_func = wasm_runtime_lookup_function(module_inst, name);
123123
wasm_function_inst_t guest_cleanup_func = wasm_runtime_lookup_function(module_inst, (std::string("cabi_post_") + name).c_str());
@@ -130,7 +130,7 @@ func_t<F> attach(const wasm_module_inst_t &module_inst, const wasm_exec_env_t &e
130130
{std::forward<decltype(args)>(args)...});
131131
std::vector<wasm_val_t> inputs = toWamr(lowered_args);
132132

133-
constexpr size_t output_size = std::tuple_size<results_t>::value;
133+
constexpr size_t output_size = std::is_same<result_t, void>::value ? 0 : 1;
134134
wasm_val_t outputs[output_size];
135135

136136
bool success = wasm_runtime_call_wasm_a(exec_env, guest_func,
@@ -144,15 +144,15 @@ func_t<F> attach(const wasm_module_inst_t &module_inst, const wasm_exec_env_t &e
144144
liftLowerContext.trap(exception ? exception : "Unknown WAMR execution error");
145145
}
146146

147-
WasmValVector flat_results = fromWamr<results_t>(output_size, outputs);
148-
auto output = lift_flat_values<results_t>(liftLowerContext, MAX_FLAT_RESULTS, flat_results);
147+
WasmValVector flat_results = fromWamr<result_t>(output_size, outputs);
148+
auto output = lift_flat_values<result_t>(liftLowerContext, MAX_FLAT_RESULTS, flat_results);
149149

150150
if (guest_cleanup_func)
151151
{
152152
wasm_runtime_call_wasm_a(exec_env, guest_cleanup_func, 0, nullptr, output_size, outputs);
153153
}
154154

155-
return std::get<0>(output);
155+
return output;
156156
};
157157
}
158158

0 commit comments

Comments
 (0)