1b2c64de1SMangoPeachGrape /// \file wasmtime/component/func.h
2b2c64de1SMangoPeachGrape 
3ce3c1a72SMangoPeachGrape #ifndef WASMTIME_COMPONENT_FUNC_H
4ce3c1a72SMangoPeachGrape #define WASMTIME_COMPONENT_FUNC_H
5ce3c1a72SMangoPeachGrape 
639ec36caSAlex Crichton #include <wasmtime/component/types/func.h>
7b2c64de1SMangoPeachGrape #include <wasmtime/component/val.h>
8ce3c1a72SMangoPeachGrape #include <wasmtime/conf.h>
9b2c64de1SMangoPeachGrape #include <wasmtime/error.h>
10b2c64de1SMangoPeachGrape #include <wasmtime/store.h>
11ce3c1a72SMangoPeachGrape 
12ce3c1a72SMangoPeachGrape #ifdef WASMTIME_FEATURE_COMPONENT_MODEL
13ce3c1a72SMangoPeachGrape 
14ce3c1a72SMangoPeachGrape #ifdef __cplusplus
15ce3c1a72SMangoPeachGrape extern "C" {
16ce3c1a72SMangoPeachGrape #endif
17ce3c1a72SMangoPeachGrape 
18ce3c1a72SMangoPeachGrape /// \brief Representation of a function in Wasmtime.
19ce3c1a72SMangoPeachGrape ///
20ce3c1a72SMangoPeachGrape /// Functions in Wasmtime are represented as an index into a store and don't
21ce3c1a72SMangoPeachGrape /// have any data or destructor associated with the value. Functions cannot
22ce3c1a72SMangoPeachGrape /// interoperate between #wasmtime_store_t instances and if the wrong function
23ce3c1a72SMangoPeachGrape /// is passed to the wrong store then it may trigger an assertion to abort the
24ce3c1a72SMangoPeachGrape /// process.
25ce3c1a72SMangoPeachGrape typedef struct wasmtime_component_func {
26e33836c0SAlex Crichton   struct {
27ce3c1a72SMangoPeachGrape     /// Internal identifier of what store this belongs to, never zero.
28ce3c1a72SMangoPeachGrape     uint64_t store_id;
29e33836c0SAlex Crichton     /// Private internal wasmtime information.
30e33836c0SAlex Crichton     uint32_t __private1;
31e33836c0SAlex Crichton   };
32e33836c0SAlex Crichton 
33e33836c0SAlex Crichton   /// Private internal wasmtime information.
34e33836c0SAlex Crichton   uint32_t __private2;
35ce3c1a72SMangoPeachGrape } wasmtime_component_func_t;
36ce3c1a72SMangoPeachGrape 
3739ec36caSAlex Crichton /// \brief Returns the type of this function.
3839ec36caSAlex Crichton ///
3939ec36caSAlex Crichton /// The caller must deallocate the returned pointer with
4039ec36caSAlex Crichton /// `wasmtime_component_func_type_delete`.
4139ec36caSAlex Crichton WASM_API_EXTERN wasmtime_component_func_type_t *
4239ec36caSAlex Crichton wasmtime_component_func_type(const wasmtime_component_func_t *func,
4339ec36caSAlex Crichton                              wasmtime_context_t *context);
4439ec36caSAlex Crichton 
4553701b21SMangoPeachGrape /**
4653701b21SMangoPeachGrape  * \brief Invokes \p func with the \p args given and returns the result.
4753701b21SMangoPeachGrape  *
4853701b21SMangoPeachGrape  * The \p args provided must match the parameters that this function takes in
4953701b21SMangoPeachGrape  * terms of their types and the number of parameters. Results will be written to
5053701b21SMangoPeachGrape  * the \p results provided if the call completes successfully. The initial types
5153701b21SMangoPeachGrape  * of the values in \p results are ignored and values are overwritten to write
5253701b21SMangoPeachGrape  * the result. It's required that the \p results_size exactly matches the number
5353701b21SMangoPeachGrape  * of results that this function produces.
5453701b21SMangoPeachGrape  */
55b2c64de1SMangoPeachGrape WASM_API_EXTERN wasmtime_error_t *wasmtime_component_func_call(
56b2c64de1SMangoPeachGrape     const wasmtime_component_func_t *func, wasmtime_context_t *context,
57b2c64de1SMangoPeachGrape     const wasmtime_component_val_t *args, size_t args_size,
58b2c64de1SMangoPeachGrape     wasmtime_component_val_t *results, size_t results_size);
59b2c64de1SMangoPeachGrape 
6053701b21SMangoPeachGrape /**
61*c09aa380SJoel Dice  * \brief No longer needs to be called; this function has no effect.
6253701b21SMangoPeachGrape  *
63*c09aa380SJoel Dice  * \deprecated Previously, this invoked the `post-return` canonical ABI option,
64*c09aa380SJoel Dice  * if specified, after a #wasmtime_component_func_call had finished.  Now that's
65*c09aa380SJoel Dice  * taken care of automatically as part of #wasmtime_component_func_call, so this
66*c09aa380SJoel Dice  * function is no longer needed, and any calls to it may be removed.
6753701b21SMangoPeachGrape  */
6853701b21SMangoPeachGrape WASM_API_EXTERN wasmtime_error_t *
6953701b21SMangoPeachGrape wasmtime_component_func_post_return(const wasmtime_component_func_t *func,
7053701b21SMangoPeachGrape                                     wasmtime_context_t *context);
7153701b21SMangoPeachGrape 
72ce3c1a72SMangoPeachGrape #ifdef __cplusplus
73ce3c1a72SMangoPeachGrape } // extern "C"
74ce3c1a72SMangoPeachGrape #endif
75ce3c1a72SMangoPeachGrape 
76ce3c1a72SMangoPeachGrape #endif // WASMTIME_FEATURE_COMPONENT_MODEL
77ce3c1a72SMangoPeachGrape 
78ce3c1a72SMangoPeachGrape #endif // WASMTIME_COMPONENT_FUNC_H
79