1 /// \file wasmtime/component/func.h
2 
3 #ifndef WASMTIME_COMPONENT_FUNC_H
4 #define WASMTIME_COMPONENT_FUNC_H
5 
6 #include <wasmtime/component/types/func.h>
7 #include <wasmtime/component/val.h>
8 #include <wasmtime/conf.h>
9 #include <wasmtime/error.h>
10 #include <wasmtime/store.h>
11 
12 #ifdef WASMTIME_FEATURE_COMPONENT_MODEL
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /// \brief Representation of a function in Wasmtime.
19 ///
20 /// Functions in Wasmtime are represented as an index into a store and don't
21 /// have any data or destructor associated with the value. Functions cannot
22 /// interoperate between #wasmtime_store_t instances and if the wrong function
23 /// is passed to the wrong store then it may trigger an assertion to abort the
24 /// process.
25 typedef struct wasmtime_component_func {
26   struct {
27     /// Internal identifier of what store this belongs to, never zero.
28     uint64_t store_id;
29     /// Private internal wasmtime information.
30     uint32_t __private1;
31   };
32 
33   /// Private internal wasmtime information.
34   uint32_t __private2;
35 } wasmtime_component_func_t;
36 
37 /// \brief Returns the type of this function.
38 ///
39 /// The caller must deallocate the returned pointer with
40 /// `wasmtime_component_func_type_delete`.
41 WASM_API_EXTERN wasmtime_component_func_type_t *
42 wasmtime_component_func_type(const wasmtime_component_func_t *func,
43                              wasmtime_context_t *context);
44 
45 /**
46  * \brief Invokes \p func with the \p args given and returns the result.
47  *
48  * The \p args provided must match the parameters that this function takes in
49  * terms of their types and the number of parameters. Results will be written to
50  * the \p results provided if the call completes successfully. The initial types
51  * of the values in \p results are ignored and values are overwritten to write
52  * the result. It's required that the \p results_size exactly matches the number
53  * of results that this function produces.
54  */
55 WASM_API_EXTERN wasmtime_error_t *wasmtime_component_func_call(
56     const wasmtime_component_func_t *func, wasmtime_context_t *context,
57     const wasmtime_component_val_t *args, size_t args_size,
58     wasmtime_component_val_t *results, size_t results_size);
59 
60 /**
61  * \brief No longer needs to be called; this function has no effect.
62  *
63  * \deprecated Previously, this invoked the `post-return` canonical ABI option,
64  * if specified, after a #wasmtime_component_func_call had finished.  Now that's
65  * taken care of automatically as part of #wasmtime_component_func_call, so this
66  * function is no longer needed, and any calls to it may be removed.
67  */
68 WASM_API_EXTERN wasmtime_error_t *
69 wasmtime_component_func_post_return(const wasmtime_component_func_t *func,
70                                     wasmtime_context_t *context);
71 
72 #ifdef __cplusplus
73 } // extern "C"
74 #endif
75 
76 #endif // WASMTIME_FEATURE_COMPONENT_MODEL
77 
78 #endif // WASMTIME_COMPONENT_FUNC_H
79