Skip to content

Commit f23345a

Browse files
committed
Add some comments to fizzy.h
1 parent 125ef35 commit f23345a

1 file changed

Lines changed: 45 additions & 9 deletions

File tree

include/fizzy/fizzy.h

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,82 @@
1111
extern "C" {
1212
#endif
1313

14-
bool fizzy_validate(const uint8_t* wasm_binary, size_t wasm_binary_size);
15-
14+
/// The opaque data type representing a module.
1615
struct fizzy_module;
1716

18-
struct fizzy_module* fizzy_parse(const uint8_t* wasm_binary, size_t wasm_binary_size);
19-
20-
void fizzy_free_module(struct fizzy_module*);
17+
/// The opaque data type representing an instance (instantiated module).
18+
struct fizzy_instance;
2119

20+
/// The data type representing numeric values.
21+
///
22+
/// i64 member is used to represent values of both i32 and i64 type.
2223
union fizzy_value
2324
{
2425
uint64_t i64;
2526
float f32;
2627
double f64;
2728
};
2829

30+
/// Result of execution of a function.
2931
typedef struct fizzy_execution_result
3032
{
33+
/// Whether execution ended with a trap.
3134
bool trapped;
35+
/// Whether function returned a value. Valid only if trapped == false
3236
bool has_value;
37+
/// Value returned from a function. Valid only if has_value == true
3338
union fizzy_value value;
3439
} fizzy_execution_result;
3540

36-
struct fizzy_instance;
3741

42+
/// Pointer to external function.
43+
///
44+
/// @param context Opaque pointer to execution context.
45+
/// @param instance Pointer to module instance.
46+
/// @param args Pointer to the argument array.
47+
/// @param args_size Size of the argument array.
48+
/// @param depth Call stack depth.
3849
typedef struct fizzy_execution_result (*fizzy_external_fn)(void* context,
39-
struct fizzy_instance* instance, const union fizzy_value* args, uint32_t cargs_size, int depth);
50+
struct fizzy_instance* instance, const union fizzy_value* args, uint32_t args_size, int depth);
4051

52+
/// External function.
4153
typedef struct fizzy_external_function
4254
{
4355
// TODO function type
56+
57+
/// Pointer to function.
4458
fizzy_external_fn function;
59+
/// Opaque pointer to execution context, that will be passed to function.
4560
void* context;
4661
} fizzy_external_function;
4762

48-
// Takes ownership of module.
63+
/// Validate binary module.
64+
bool fizzy_validate(const uint8_t* wasm_binary, size_t wasm_binary_size);
65+
66+
/// Parse binary module.
67+
struct fizzy_module* fizzy_parse(const uint8_t* wasm_binary, size_t wasm_binary_size);
68+
69+
/// Free resources associated with the module.
70+
void fizzy_free_module(struct fizzy_module* module);
71+
72+
/// Instantiate a module.
73+
/// Takes ownership of module.
74+
///
75+
/// @param module Pointer to module.
76+
/// @param imported_functions Pointer to the imported function array.
77+
/// @param imported_functions_size Size of the imported function array.
4978
struct fizzy_instance* fizzy_instantiate(struct fizzy_module* module,
5079
const struct fizzy_external_function* imported_functions, uint32_t imported_functions_size);
5180

52-
void fizzy_free_instance(struct fizzy_instance*);
81+
/// Free resources associated with the instance.
82+
void fizzy_free_instance(struct fizzy_instance* instance);
5383

84+
/// Execute module function.
85+
///
86+
/// @param instance Pointer to module instance.
87+
/// @param args Pointer to the argument array.
88+
/// @param args_size Size of the argument array.
89+
/// @param depth Call stack depth.
5490
fizzy_execution_result fizzy_execute(struct fizzy_instance* instance, uint32_t func_idx,
5591
const union fizzy_value* args, uint32_t args_size, int depth);
5692

0 commit comments

Comments
 (0)