@@ -227,6 +227,36 @@ namespace cage
227
227
template <class T >
228
228
struct WasmFunction ;
229
229
230
+ template <privat::WasmParameterConcept R, privat::WasmParameterConcept... Ts>
231
+ struct WasmFunction <R(Ts...)>;
232
+
233
+ class CAGE_CORE_API WasmInstance : private Immovable
234
+ {
235
+ public:
236
+ String instanceName;
237
+
238
+ Holder<WasmModule> module () const ;
239
+
240
+ void *wasm2native (uint32 address, uint32 size = 0 );
241
+ uint32 native2wasm (void *address, uint32 size = 0 );
242
+ uint32 malloc (uint32 size);
243
+ void free (uint32 wasmAddr);
244
+ uint32 strLen (uint32 wasmAddr);
245
+ WasmBuffer allocate (uint32 size, uint32 capacity = 0 , bool owned = true );
246
+ WasmBuffer adapt (uint32 wasmAddr, uint32 size, bool owned = false );
247
+
248
+ template <class T >
249
+ CAGE_FORCE_INLINE WasmFunction<T> function (const WasmName &name)
250
+ {
251
+ return WasmFunction<T>(function_ (name));
252
+ }
253
+
254
+ WasmBuffer temporary; // use for passing data in function calls
255
+
256
+ private:
257
+ Holder<privat::WasmFunctionInternal> function_ (const WasmName &name);
258
+ };
259
+
230
260
template <privat::WasmParameterConcept R, privat::WasmParameterConcept... Ts>
231
261
struct WasmFunction <R(Ts...)> : private Noncopyable
232
262
{
@@ -254,7 +284,7 @@ namespace cage
254
284
}
255
285
catch (...)
256
286
{
257
- CAGE_LOG_THROW (func->name ());
287
+ CAGE_LOG_THROW (Stringizer () + func-> instance ()-> instanceName + " : " + func->name ());
258
288
throw ;
259
289
}
260
290
}
@@ -264,51 +294,31 @@ namespace cage
264
294
R operator ()(Ts... vs)
265
295
{
266
296
CAGE_ASSERT (func);
267
- PointerRange<uint32> data = func->data ();
268
-
269
- uint32 offset = 0 ;
270
- const auto &fill = [&]<class T >(T v) -> void
297
+ try
271
298
{
272
- *(T *)(void *)(data.data () + offset) = v;
273
- offset += sizeof (T) / 4 ;
274
- };
275
- (fill (std::forward<Ts>(vs)), ...);
276
-
277
- func->call ();
278
-
279
- if constexpr (!std::is_same_v<R, void >)
280
- return *(R *)(void *)data.data ();
299
+ PointerRange<uint32> data = func->data ();
300
+ uint32 offset = 0 ;
301
+ const auto &fill = [&]<class T >(T v) -> void
302
+ {
303
+ *(T *)(void *)(data.data () + offset) = v;
304
+ offset += sizeof (T) / 4 ;
305
+ };
306
+ (fill (std::forward<Ts>(vs)), ...);
307
+ func->call ();
308
+ if constexpr (!std::is_same_v<R, void >)
309
+ return *(R *)(void *)data.data ();
310
+ }
311
+ catch (...)
312
+ {
313
+ CAGE_LOG_THROW (Stringizer () + func->instance ()->instanceName + " :" + func->name ());
314
+ throw ;
315
+ }
281
316
}
282
317
283
318
private:
284
319
Holder<privat::WasmFunctionInternal> func;
285
320
};
286
321
287
- class CAGE_CORE_API WasmInstance : private Immovable
288
- {
289
- public:
290
- Holder<WasmModule> module () const ;
291
-
292
- void *wasm2native (uint32 address, uint32 size = 0 );
293
- uint32 native2wasm (void *address, uint32 size = 0 );
294
- uint32 malloc (uint32 size);
295
- void free (uint32 wasmAddr);
296
- uint32 strLen (uint32 wasmAddr);
297
- WasmBuffer allocate (uint32 size, uint32 capacity = 0 , bool owned = true );
298
- WasmBuffer adapt (uint32 wasmAddr, uint32 size, bool owned = false );
299
-
300
- template <class T >
301
- CAGE_FORCE_INLINE WasmFunction<T> function (const WasmName &name)
302
- {
303
- return WasmFunction<T>(function_ (name));
304
- }
305
-
306
- WasmBuffer temporary; // use for passing data in function calls
307
-
308
- private:
309
- Holder<privat::WasmFunctionInternal> function_ (const WasmName &name);
310
- };
311
-
312
322
CAGE_CORE_API Holder<WasmInstance> wasmInstantiate (Holder<WasmModule> &&module);
313
323
}
314
324
0 commit comments