MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / ExternSTLVectorSum

Function ExternSTLVectorSum

test/externref/ExternrefTest.cpp:277–292  ·  view source on GitHub ↗

Host function to sum values in a slice of std::vector .

Source from the content-addressed store, hash-verified

275
276// Host function to sum values in a slice of std::vector<uint32_t>.
277WasmEdge_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.
295WasmEdge_ModuleInstanceContext *createExternModule() {

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected