Host function to sum values in a slice of std::vector .
| 275 | |
| 276 | // Host function to sum values in a slice of std::vector<uint32_t>. |
| 277 | WasmEdge_Result ExternSTLVectorSum(void *, const WasmEdge_CallingFrameContext *, |
| 278 | const WasmEdge_Value *In, |
| 279 | WasmEdge_Value *Out) { |
| 280 | // Function type: {externref, externref} -> {i32} |
| 281 | void *Ptr0 = WasmEdge_ValueGetExternRef(In[0]); |
| 282 | void *Ptr1 = WasmEdge_ValueGetExternRef(In[1]); |
| 283 | auto &It = *reinterpret_cast<std::vector<uint32_t>::iterator *>(Ptr0); |
| 284 | auto &ItEnd = *reinterpret_cast<std::vector<uint32_t>::iterator *>(Ptr1); |
| 285 | uint32_t Sum = 0; |
| 286 | while (It != ItEnd) { |
| 287 | Sum += *It; |
| 288 | It++; |
| 289 | } |
| 290 | Out[0] = WasmEdge_ValueGenI32(static_cast<int32_t>(Sum)); |
| 291 | return WasmEdge_Result_Success; |
| 292 | } |
| 293 | |
| 294 | // Helper function to create the "extern_module" module instance. |
| 295 | WasmEdge_ModuleInstanceContext *createExternModule() { |
nothing calls this directly
no test coverage detected