github.com/moontrade/wavm-go@v0.3.2-0.20220316110326-d229dd66ad65/wavm-c.h (about)

     1  // WebAssembly C API
     2  
     3  #ifndef __WASM_H
     4  #define __WASM_H
     5  
     6  #include <assert.h>
     7  #include <stdbool.h>
     8  #include <stddef.h>
     9  #include <stdint.h>
    10  
    11  #ifndef WASM_C_API
    12  #ifdef _WIN32
    13  #define WASM_C_API __declspec(dllimport)
    14  #else
    15  #define WASM_C_API
    16  #endif
    17  #endif
    18  
    19  // Opaque types
    20  
    21  #ifndef WASM_OPAQUE_TYPES_DEFINED
    22  typedef struct wasm_config_t wasm_config_t;
    23  typedef struct wasm_engine_t wasm_engine_t;
    24  typedef struct wasm_compartment_t wasm_compartment_t;
    25  typedef struct wasm_store_t wasm_store_t;
    26  typedef struct wasm_valtype_t wasm_valtype_t;
    27  typedef struct wasm_functype_t wasm_functype_t;
    28  typedef struct wasm_tabletype_t wasm_tabletype_t;
    29  typedef struct wasm_memorytype_t wasm_memorytype_t;
    30  typedef struct wasm_globaltype_t wasm_globaltype_t;
    31  typedef struct wasm_externtype_t wasm_externtype_t;
    32  typedef struct wasm_ref_t wasm_ref_t;
    33  typedef struct wasm_trap_t wasm_trap_t;
    34  typedef struct wasm_foreign_t wasm_foreign_t;
    35  typedef struct wasm_module_t wasm_module_t;
    36  typedef struct wasm_func_t wasm_func_t;
    37  typedef struct wasm_table_t wasm_table_t;
    38  typedef struct wasm_memory_t wasm_memory_t;
    39  typedef struct wasm_global_t wasm_global_t;
    40  typedef struct wasm_extern_t wasm_extern_t;
    41  typedef struct wasm_instance_t wasm_instance_t;
    42  
    43  typedef struct wasm_shared_module_t wasm_shared_module_t;
    44  typedef struct wasm_shared_func_t wasm_shared_func_t;
    45  typedef struct wasm_shared_table_t wasm_shared_table_t;
    46  typedef struct wasm_shared_memory_t wasm_shared_memory_t;
    47  typedef struct wasm_shared_foreign_t wasm_shared_foreign_t;
    48  #endif
    49  
    50  #ifdef __cplusplus
    51  extern "C" {
    52  #endif
    53  
    54  ///////////////////////////////////////////////////////////////////////////////
    55  // Auxiliaries
    56  
    57  typedef float wasm_float32_t;
    58  typedef double wasm_float64_t;
    59  
    60  // Ownership
    61  
    62  #define own
    63  
    64  // The qualifier `own` is used to indicate ownership of data in this API.
    65  // It is intended to be interpreted similar to a `const` qualifier:
    66  //
    67  // - `own wasm_xxx_t*` owns the pointed-to data
    68  // - `own wasm_xxx_t` distributes to all fields of a struct or union `xxx`
    69  // - `own wasm_xxx_vec_t` owns the vector as well as its elements(!)
    70  // - an `own` function parameter passes ownership from caller to callee
    71  // - an `own` function result passes ownership from callee to caller
    72  // - an exception are `own` pointer parameters named `out`, which are copy-back
    73  //   output parameters passing back ownership from callee to caller
    74  //
    75  // Own data is created by `wasm_xxx_new` functions and some others.
    76  // It must be released with the corresponding `wasm_xxx_delete` function.
    77  //
    78  // Deleting a reference does not necessarily delete the underlying object,
    79  // it merely indicates that this owner no longer uses it.
    80  //
    81  // For vectors, `const wasm_xxx_vec_t` is used informally to indicate that
    82  // neither the vector nor its elements should be modified.
    83  // TODO: introduce proper `wasm_xxx_const_vec_t`?
    84  
    85  #define WASM_DECLARE_OWN(name) WASM_C_API void wasm_##name##_delete(own wasm_##name##_t*);
    86  
    87  ///////////////////////////////////////////////////////////////////////////////
    88  // Runtime Environment
    89  
    90  // Configuration
    91  
    92  WASM_DECLARE_OWN(config)
    93  
    94  WASM_C_API own wasm_config_t* wasm_config_new();
    95  
    96  #define WASM_DECLARE_FEATURE(feature)                                                              \
    97  	WASM_C_API void wasm_config_feature_set_##feature(wasm_config_t* config, bool enable);
    98  
    99  // Standardized, or mature proposed standard extensions that are expected to be standardized without
   100  // breaking backward compatibility: enabled by default.
   101  WASM_DECLARE_FEATURE(import_export_mutable_globals)
   102  WASM_DECLARE_FEATURE(nontrapping_float_to_int)
   103  WASM_DECLARE_FEATURE(sign_extension)
   104  WASM_DECLARE_FEATURE(bulk_memory_ops)
   105  
   106  // Proposed standard extensions: disabled by default.
   107  WASM_DECLARE_FEATURE(simd)
   108  WASM_DECLARE_FEATURE(atomics)
   109  WASM_DECLARE_FEATURE(exception_handling)
   110  WASM_DECLARE_FEATURE(multivalue)
   111  WASM_DECLARE_FEATURE(reference_types)
   112  WASM_DECLARE_FEATURE(extended_name_section)
   113  WASM_DECLARE_FEATURE(multimemory)
   114  
   115  // Non-standard extensions.
   116  WASM_DECLARE_FEATURE(shared_tables)
   117  WASM_DECLARE_FEATURE(allow_legacy_inst_names)
   118  WASM_DECLARE_FEATURE(any_extern_kind_elems)
   119  WASM_DECLARE_FEATURE(wat_quoted_names)
   120  WASM_DECLARE_FEATURE(wat_custom_sections)
   121  
   122  #undef WASM_DECLARE_FEATURE
   123  
   124  // Engine
   125  
   126  WASM_DECLARE_OWN(engine)
   127  
   128  WASM_C_API own wasm_engine_t* wasm_engine_new();
   129  WASM_C_API own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*);
   130  
   131  // Compartment
   132  
   133  WASM_DECLARE_OWN(compartment)
   134  
   135  WASM_C_API own wasm_compartment_t* wasm_compartment_new(wasm_engine_t* engine,
   136  														const char* debug_name);
   137  WASM_C_API own wasm_compartment_t* wasm_compartment_clone(const wasm_compartment_t*);
   138  
   139  WASM_C_API bool wasm_compartment_contains(const wasm_compartment_t*, const wasm_ref_t*);
   140  
   141  // Store
   142  
   143  WASM_DECLARE_OWN(store)
   144  
   145  WASM_C_API own wasm_store_t* wasm_store_new(wasm_compartment_t*, const char* debug_name);
   146  
   147  ///////////////////////////////////////////////////////////////////////////////
   148  // Type Representations
   149  
   150  // Type attributes
   151  
   152  typedef uint8_t wasm_mutability_t;
   153  enum wasm_mutability_enum
   154  {
   155  	WASM_CONST,
   156  	WASM_VAR,
   157  };
   158  
   159  typedef uint8_t wasm_shared_t;
   160  enum wasm_shared_enum
   161  {
   162  	WASM_NOTSHARED,
   163  	WASM_SHARED,
   164  };
   165  
   166  typedef uint8_t wasm_index_t;
   167  enum wasm_index_enum
   168  {
   169  	WASM_INDEX_I32,
   170  	WASM_INDEX_I64,
   171  };
   172  
   173  typedef struct wasm_limits_t
   174  {
   175  	uint32_t min;
   176  	uint32_t max;
   177  } wasm_limits_t;
   178  
   179  static const uint32_t wasm_limits_max_default = 0xffffffff;
   180  
   181  // Generic
   182  
   183  #define WASM_DECLARE_TYPE(name)                                                                    \
   184  	WASM_DECLARE_OWN(name)                                                                         \
   185                                                                                                     \
   186  	WASM_C_API own wasm_##name##_t* wasm_##name##_copy(wasm_##name##_t*);
   187  
   188  // Value Types
   189  
   190  WASM_DECLARE_TYPE(valtype)
   191  
   192  typedef uint8_t wasm_valkind_t;
   193  enum wasm_valkind_enum
   194  {
   195  	WASM_I32,
   196  	WASM_I64,
   197  	WASM_F32,
   198  	WASM_F64,
   199  	WASM_V128,
   200  	WASM_ANYREF = 128,
   201  	WASM_FUNCREF,
   202  };
   203  
   204  WASM_C_API own wasm_valtype_t* wasm_valtype_new(wasm_valkind_t);
   205  
   206  WASM_C_API wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t*);
   207  
   208  static inline bool wasm_valkind_is_num(wasm_valkind_t k) { return k < WASM_ANYREF; }
   209  static inline bool wasm_valkind_is_ref(wasm_valkind_t k) { return k >= WASM_ANYREF; }
   210  
   211  static inline bool wasm_valtype_is_num(const wasm_valtype_t* t)
   212  {
   213  	return wasm_valkind_is_num(wasm_valtype_kind(t));
   214  }
   215  static inline bool wasm_valtype_is_ref(const wasm_valtype_t* t)
   216  {
   217  	return wasm_valkind_is_ref(wasm_valtype_kind(t));
   218  }
   219  
   220  // Function Types
   221  
   222  WASM_DECLARE_TYPE(functype)
   223  
   224  WASM_C_API own wasm_functype_t* wasm_functype_new(own wasm_valtype_t** params,
   225  												  size_t num_params,
   226  												  own wasm_valtype_t** results,
   227  												  size_t num_results);
   228  
   229  WASM_C_API size_t wasm_functype_num_params(const wasm_functype_t* type);
   230  WASM_C_API wasm_valtype_t* wasm_functype_param(const wasm_functype_t* type, size_t index);
   231  
   232  WASM_C_API size_t wasm_functype_num_results(const wasm_functype_t* type);
   233  WASM_C_API wasm_valtype_t* wasm_functype_result(const wasm_functype_t* type, size_t index);
   234  
   235  // Global Types
   236  
   237  WASM_DECLARE_TYPE(globaltype)
   238  
   239  WASM_C_API own wasm_globaltype_t* wasm_globaltype_new(own wasm_valtype_t*, wasm_mutability_t);
   240  
   241  WASM_C_API const wasm_valtype_t* wasm_globaltype_content(const wasm_globaltype_t*);
   242  WASM_C_API wasm_mutability_t wasm_globaltype_mutability(const wasm_globaltype_t*);
   243  
   244  // Table Types
   245  
   246  WASM_DECLARE_TYPE(tabletype)
   247  
   248  WASM_C_API own wasm_tabletype_t* wasm_tabletype_new(own wasm_valtype_t*,
   249  													const wasm_limits_t*,
   250  													wasm_shared_t,
   251  													wasm_index_t);
   252  
   253  WASM_C_API const wasm_valtype_t* wasm_tabletype_element(const wasm_tabletype_t*);
   254  WASM_C_API const wasm_limits_t* wasm_tabletype_limits(const wasm_tabletype_t*);
   255  WASM_C_API wasm_shared_t wasm_tabletype_shared(const wasm_tabletype_t*);
   256  WASM_C_API wasm_index_t wasm_tabletype_index(const wasm_tabletype_t*);
   257  
   258  // Memory Types
   259  
   260  WASM_DECLARE_TYPE(memorytype)
   261  
   262  WASM_C_API own wasm_memorytype_t* wasm_memorytype_new(const wasm_limits_t*,
   263  													  wasm_shared_t,
   264  													  wasm_index_t);
   265  
   266  WASM_C_API const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t*);
   267  WASM_C_API wasm_shared_t wasm_memorytype_shared(const wasm_memorytype_t*);
   268  WASM_C_API wasm_index_t wasm_memorytype_index(const wasm_memorytype_t*);
   269  
   270  // Extern Types
   271  
   272  WASM_DECLARE_TYPE(externtype)
   273  
   274  typedef uint8_t wasm_externkind_t;
   275  enum wasm_externkind_enum
   276  {
   277  	WASM_EXTERN_FUNC,
   278  	WASM_EXTERN_GLOBAL,
   279  	WASM_EXTERN_TABLE,
   280  	WASM_EXTERN_MEMORY,
   281  };
   282  
   283  WASM_C_API wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t*);
   284  
   285  WASM_C_API wasm_externtype_t* wasm_functype_as_externtype(wasm_functype_t*);
   286  WASM_C_API wasm_externtype_t* wasm_globaltype_as_externtype(wasm_globaltype_t*);
   287  WASM_C_API wasm_externtype_t* wasm_tabletype_as_externtype(wasm_tabletype_t*);
   288  WASM_C_API wasm_externtype_t* wasm_memorytype_as_externtype(wasm_memorytype_t*);
   289  
   290  WASM_C_API wasm_functype_t* wasm_externtype_as_functype(wasm_externtype_t*);
   291  WASM_C_API wasm_globaltype_t* wasm_externtype_as_globaltype(wasm_externtype_t*);
   292  WASM_C_API wasm_tabletype_t* wasm_externtype_as_tabletype(wasm_externtype_t*);
   293  WASM_C_API wasm_memorytype_t* wasm_externtype_as_memorytype(wasm_externtype_t*);
   294  
   295  WASM_C_API const wasm_externtype_t* wasm_functype_as_externtype_const(const wasm_functype_t*);
   296  WASM_C_API const wasm_externtype_t* wasm_globaltype_as_externtype_const(const wasm_globaltype_t*);
   297  WASM_C_API const wasm_externtype_t* wasm_tabletype_as_externtype_const(const wasm_tabletype_t*);
   298  WASM_C_API const wasm_externtype_t* wasm_memorytype_as_externtype_const(const wasm_memorytype_t*);
   299  
   300  WASM_C_API const wasm_functype_t* wasm_externtype_as_functype_const(const wasm_externtype_t*);
   301  WASM_C_API const wasm_globaltype_t* wasm_externtype_as_globaltype_const(const wasm_externtype_t*);
   302  WASM_C_API const wasm_tabletype_t* wasm_externtype_as_tabletype_const(const wasm_externtype_t*);
   303  WASM_C_API const wasm_memorytype_t* wasm_externtype_as_memorytype_const(const wasm_externtype_t*);
   304  
   305  // Imports
   306  
   307  typedef struct wasm_import_t
   308  {
   309  	const char* module;
   310  	size_t num_module_bytes;
   311  	const char* name;
   312  	size_t num_name_bytes;
   313  	wasm_externtype_t* type;
   314  } wasm_import_t;
   315  
   316  // Exports
   317  
   318  typedef struct wasm_export_t
   319  {
   320  	const char* name;
   321  	size_t num_name_bytes;
   322  	wasm_externtype_t* type;
   323  } wasm_export_t;
   324  
   325  ///////////////////////////////////////////////////////////////////////////////
   326  // Runtime Objects
   327  
   328  // Values
   329  
   330  // NOTE: not 128-bit aligned
   331  typedef struct wasm_v128_t
   332  {
   333  	uint64_t u64x2[2];
   334  } wasm_v128_t;
   335  
   336  typedef union wasm_val_t
   337  {
   338  	int32_t i32;
   339  	int64_t i64;
   340  	wasm_float32_t f32;
   341  	wasm_float64_t f64;
   342  	wasm_v128_t v128;
   343  	wasm_ref_t* ref;
   344  } wasm_val_t;
   345  
   346  WASM_C_API void wasm_val_delete(wasm_valkind_t kind, own wasm_val_t* v);
   347  WASM_C_API void wasm_val_copy(wasm_valkind_t kind, own wasm_val_t* out, const wasm_val_t*);
   348  
   349  // References
   350  
   351  #define WASM_DECLARE_REF_BASE(name)                                                                \
   352  	WASM_DECLARE_OWN(name)                                                                         \
   353                                                                                                     \
   354  	WASM_C_API own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*);                    \
   355  	WASM_C_API bool wasm_##name##_same(const wasm_##name##_t*, const wasm_##name##_t*);            \
   356                                                                                                     \
   357  	WASM_C_API void* wasm_##name##_get_host_info(const wasm_##name##_t*);                          \
   358  	WASM_C_API void wasm_##name##_set_host_info(wasm_##name##_t*, void*);                          \
   359  	WASM_C_API void wasm_##name##_set_host_info_with_finalizer(                                    \
   360  		wasm_##name##_t*, void*, void (*)(void*));                                                 \
   361                                                                                                     \
   362  	WASM_C_API own wasm_##name##_t* wasm_##name##_remap_to_cloned_compartment(                     \
   363  		const wasm_##name##_t*, const wasm_compartment_t*);                                        \
   364                                                                                                     \
   365  	WASM_C_API const char* wasm_##name##_name(const wasm_##name##_t*);
   366  
   367  #define WASM_DECLARE_REF(name)                                                                     \
   368  	WASM_DECLARE_REF_BASE(name)                                                                    \
   369                                                                                                     \
   370  	WASM_C_API wasm_ref_t* wasm_##name##_as_ref(wasm_##name##_t*);                                 \
   371  	WASM_C_API wasm_##name##_t* wasm_ref_as_##name(wasm_ref_t*);                                   \
   372  	WASM_C_API const wasm_ref_t* wasm_##name##_as_ref_const(const wasm_##name##_t*);               \
   373  	WASM_C_API const wasm_##name##_t* wasm_ref_as_##name##_const(const wasm_ref_t*);
   374  
   375  #define WASM_DECLARE_SHAREABLE_REF(name)                                                           \
   376  	WASM_DECLARE_REF(name)                                                                         \
   377  	WASM_DECLARE_OWN(shared_##name)                                                                \
   378                                                                                                     \
   379  	WASM_C_API own wasm_shared_##name##_t* wasm_##name##_share(const wasm_##name##_t*);            \
   380  	WASM_C_API own wasm_##name##_t* wasm_##name##_obtain(wasm_store_t*,                            \
   381  														 const wasm_shared_##name##_t*);
   382  
   383  WASM_DECLARE_REF_BASE(ref)
   384  
   385  // Frames
   386  
   387  typedef struct wasm_frame_t
   388  {
   389  	wasm_func_t* function;
   390  	size_t instr_index;
   391  } wasm_frame_t;
   392  
   393  // Traps
   394  
   395  WASM_DECLARE_REF(trap)
   396  
   397  WASM_C_API own wasm_trap_t* wasm_trap_new(wasm_compartment_t*,
   398  										  const char* message,
   399  										  size_t num_message_bytes);
   400  
   401  WASM_C_API bool wasm_trap_message(const wasm_trap_t*,
   402  								  char* out_message,
   403  								  size_t* inout_num_message_bytes);
   404  WASM_C_API size_t wasm_trap_stack_num_frames(const wasm_trap_t*);
   405  WASM_C_API void wasm_trap_stack_frame(const wasm_trap_t*,
   406  									  size_t index,
   407  									  own wasm_frame_t* out_frame);
   408  
   409  // Foreign Objects
   410  
   411  WASM_DECLARE_SHAREABLE_REF(foreign)
   412  
   413  WASM_C_API own wasm_foreign_t* wasm_foreign_new(wasm_compartment_t*, const char* debug_name);
   414  
   415  // Modules
   416  
   417  WASM_DECLARE_TYPE(module)
   418  
   419  WASM_C_API own wasm_module_t* wasm_module_new(wasm_engine_t*,
   420  											  const char* binary,
   421  											  size_t num_binary_bytes);
   422  
   423  WASM_C_API own wasm_module_t* wasm_module_new_text(wasm_engine_t*,
   424  												   const char* text,
   425  												   size_t num_text_chars);
   426  
   427  WASM_C_API own char* wasm_module_print(const wasm_module_t* module, size_t* out_num_chars);
   428  
   429  WASM_C_API bool wasm_module_validate(const char* binary, size_t num_binary_bytes);
   430  
   431  WASM_C_API size_t wasm_module_num_imports(const wasm_module_t* module);
   432  WASM_C_API void wasm_module_import(const wasm_module_t* module,
   433  								   size_t index,
   434  								   own wasm_import_t* out_import);
   435  WASM_C_API size_t wasm_module_num_exports(const wasm_module_t* module);
   436  WASM_C_API void wasm_module_export(const wasm_module_t* module,
   437  								   size_t index,
   438  								   own wasm_export_t* out_export);
   439  
   440  // Function Instances
   441  
   442  WASM_DECLARE_SHAREABLE_REF(func)
   443  
   444  typedef own wasm_trap_t* (*wasm_func_callback_t)(const wasm_val_t args[], wasm_val_t results[]);
   445  typedef own wasm_trap_t* (*wasm_func_callback_with_env_t)(void* env,
   446  														  const wasm_val_t args[],
   447  														  wasm_val_t results[]);
   448  
   449  WASM_C_API own wasm_func_t* wasm_func_new(wasm_compartment_t*,
   450  										  const wasm_functype_t*,
   451  										  wasm_func_callback_t,
   452  										  const char* debug_name);
   453  WASM_C_API own wasm_func_t* wasm_func_new_with_env(wasm_compartment_t*,
   454  												   const wasm_functype_t* type,
   455  												   wasm_func_callback_with_env_t,
   456  												   void* env,
   457  												   void (*finalizer)(void*),
   458  												   const char* debug_name);
   459  
   460  WASM_C_API own wasm_functype_t* wasm_func_type(const wasm_func_t*);
   461  WASM_C_API size_t wasm_func_param_arity(const wasm_func_t*);
   462  WASM_C_API size_t wasm_func_result_arity(const wasm_func_t*);
   463  
   464  WASM_C_API own wasm_trap_t* wasm_func_call(wasm_store_t*,
   465  										   const wasm_func_t*,
   466  										   const wasm_val_t args[],
   467  										   wasm_val_t results[]);
   468  
   469  // Global Instances
   470  
   471  WASM_DECLARE_REF(global)
   472  
   473  WASM_C_API own wasm_global_t* wasm_global_new(wasm_compartment_t*,
   474  											  const wasm_globaltype_t*,
   475  											  const wasm_val_t*,
   476  											  const char* debug_name);
   477  
   478  WASM_C_API own wasm_globaltype_t* wasm_global_type(const wasm_global_t*);
   479  
   480  WASM_C_API void wasm_global_get(wasm_store_t*, const wasm_global_t*, own wasm_val_t* out);
   481  WASM_C_API void wasm_global_set(wasm_global_t*, const wasm_val_t*);
   482  
   483  // Table Instances
   484  
   485  WASM_DECLARE_SHAREABLE_REF(table)
   486  
   487  typedef uint32_t wasm_table_size_t;
   488  
   489  static const wasm_table_size_t WASM_TABLE_SIZE_MAX = UINT32_MAX;
   490  
   491  WASM_C_API own wasm_table_t* wasm_table_new(wasm_compartment_t*,
   492  											const wasm_tabletype_t*,
   493  											wasm_ref_t* init,
   494  											const char* debug_name);
   495  
   496  WASM_C_API own wasm_tabletype_t* wasm_table_type(const wasm_table_t*);
   497  
   498  WASM_C_API own wasm_ref_t* wasm_table_get(const wasm_table_t* table, wasm_table_size_t index);
   499  WASM_C_API bool wasm_table_set(wasm_table_t* table, wasm_table_size_t index, wasm_ref_t* value);
   500  
   501  WASM_C_API wasm_table_size_t wasm_table_size(const wasm_table_t* table);
   502  WASM_C_API bool wasm_table_grow(wasm_table_t* table,
   503  								wasm_table_size_t delta,
   504  								wasm_ref_t* init,
   505  								wasm_table_size_t* out_previous_size);
   506  
   507  // Memory Instances
   508  
   509  WASM_DECLARE_SHAREABLE_REF(memory)
   510  
   511  typedef uint32_t wasm_memory_pages_t;
   512  
   513  static const wasm_memory_pages_t WASM_MEMORY_PAGES_MAX = UINT32_MAX;
   514  
   515  static const size_t MEMORY_PAGE_SIZE = 0x10000;
   516  
   517  WASM_C_API own wasm_memory_t* wasm_memory_new(wasm_compartment_t*,
   518  											  const wasm_memorytype_t*,
   519  											  const char* debug_name);
   520  
   521  WASM_C_API own wasm_memorytype_t* wasm_memory_type(const wasm_memory_t*);
   522  
   523  WASM_C_API char* wasm_memory_data(wasm_memory_t*);
   524  WASM_C_API size_t wasm_memory_data_size(const wasm_memory_t*);
   525  
   526  WASM_C_API wasm_memory_pages_t wasm_memory_size(const wasm_memory_t*);
   527  WASM_C_API bool wasm_memory_grow(wasm_memory_t*,
   528  								 wasm_memory_pages_t delta,
   529  								 wasm_memory_pages_t* out_previous_size);
   530  
   531  // Externals
   532  
   533  WASM_DECLARE_REF(extern)
   534  
   535  WASM_C_API wasm_externkind_t wasm_extern_kind(const wasm_extern_t*);
   536  WASM_C_API own wasm_externtype_t* wasm_extern_type(const wasm_extern_t*);
   537  
   538  WASM_C_API wasm_extern_t* wasm_func_as_extern(wasm_func_t*);
   539  WASM_C_API wasm_extern_t* wasm_global_as_extern(wasm_global_t*);
   540  WASM_C_API wasm_extern_t* wasm_table_as_extern(wasm_table_t*);
   541  WASM_C_API wasm_extern_t* wasm_memory_as_extern(wasm_memory_t*);
   542  
   543  WASM_C_API wasm_func_t* wasm_extern_as_func(wasm_extern_t*);
   544  WASM_C_API wasm_global_t* wasm_extern_as_global(wasm_extern_t*);
   545  WASM_C_API wasm_table_t* wasm_extern_as_table(wasm_extern_t*);
   546  WASM_C_API wasm_memory_t* wasm_extern_as_memory(wasm_extern_t*);
   547  
   548  WASM_C_API const wasm_extern_t* wasm_func_as_extern_const(const wasm_func_t*);
   549  WASM_C_API const wasm_extern_t* wasm_global_as_extern_const(const wasm_global_t*);
   550  WASM_C_API const wasm_extern_t* wasm_table_as_extern_const(const wasm_table_t*);
   551  WASM_C_API const wasm_extern_t* wasm_memory_as_extern_const(const wasm_memory_t*);
   552  
   553  WASM_C_API const wasm_func_t* wasm_extern_as_func_const(const wasm_extern_t*);
   554  WASM_C_API const wasm_global_t* wasm_extern_as_global_const(const wasm_extern_t*);
   555  WASM_C_API const wasm_table_t* wasm_extern_as_table_const(const wasm_extern_t*);
   556  WASM_C_API const wasm_memory_t* wasm_extern_as_memory_const(const wasm_extern_t*);
   557  
   558  // Module Instances
   559  
   560  WASM_DECLARE_REF(instance)
   561  
   562  WASM_C_API own wasm_instance_t* wasm_instance_new(wasm_store_t*,
   563  												  const wasm_module_t*,
   564  												  const wasm_extern_t* const imports[],
   565  												  own wasm_trap_t**,
   566  												  const char* debug_name);
   567  
   568  WASM_C_API own wasm_instance_t* wasm_instance_new_with_quota(wasm_store_t* store,
   569  													const wasm_module_t* module,
   570  													const wasm_extern_t* const imports[],
   571  													own wasm_trap_t** out_trap,
   572  													int32_t max_table_elems,
   573  													int32_t max_memory_pages,
   574  												 	int32_t call_start_function,
   575  													const char* debug_name);
   576  
   577  WASM_C_API size_t wasm_instance_num_exports(const wasm_instance_t*);
   578  WASM_C_API wasm_extern_t* wasm_instance_export(const wasm_instance_t*, size_t index);
   579  
   580  ///////////////////////////////////////////////////////////////////////////////
   581  // Convenience
   582  
   583  // Value Type construction short-hands
   584  
   585  static inline own wasm_valtype_t* wasm_valtype_new_i32() { return wasm_valtype_new(WASM_I32); }
   586  static inline own wasm_valtype_t* wasm_valtype_new_i64() { return wasm_valtype_new(WASM_I64); }
   587  static inline own wasm_valtype_t* wasm_valtype_new_f32() { return wasm_valtype_new(WASM_F32); }
   588  static inline own wasm_valtype_t* wasm_valtype_new_f64() { return wasm_valtype_new(WASM_F64); }
   589  static inline own wasm_valtype_t* wasm_valtype_new_v128() { return wasm_valtype_new(WASM_V128); }
   590  
   591  static inline own wasm_valtype_t* wasm_valtype_new_externref()
   592  {
   593  	return wasm_valtype_new(WASM_ANYREF);
   594  }
   595  static inline own wasm_valtype_t* wasm_valtype_new_funcref()
   596  {
   597  	return wasm_valtype_new(WASM_FUNCREF);
   598  }
   599  
   600  // Function Types construction short-hands
   601  
   602  static inline own wasm_functype_t* wasm_functype_new_0_0()
   603  {
   604  	return wasm_functype_new((wasm_valtype_t**)0, 0, (wasm_valtype_t**)0, 0);
   605  }
   606  
   607  static inline own wasm_functype_t* wasm_functype_new_1_0(own wasm_valtype_t* p)
   608  {
   609  	wasm_valtype_t* ps[1] = {p};
   610  	return wasm_functype_new(ps, 1, (wasm_valtype_t**)0, 0);
   611  }
   612  
   613  static inline own wasm_functype_t* wasm_functype_new_2_0(own wasm_valtype_t* p1,
   614  														 own wasm_valtype_t* p2)
   615  {
   616  	wasm_valtype_t* ps[2] = {p1, p2};
   617  	return wasm_functype_new(ps, 2, (wasm_valtype_t**)0, 0);
   618  }
   619  
   620  static inline own wasm_functype_t* wasm_functype_new_3_0(own wasm_valtype_t* p1,
   621  														 own wasm_valtype_t* p2,
   622  														 own wasm_valtype_t* p3)
   623  {
   624  	wasm_valtype_t* ps[3] = {p1, p2, p3};
   625  	return wasm_functype_new(ps, 3, (wasm_valtype_t**)0, 0);
   626  }
   627  
   628  static inline own wasm_functype_t* wasm_functype_new_0_1(own wasm_valtype_t* r)
   629  {
   630  	wasm_valtype_t* rs[1] = {r};
   631  	return wasm_functype_new((wasm_valtype_t**)0, 0, rs, 1);
   632  }
   633  
   634  static inline own wasm_functype_t* wasm_functype_new_1_1(own wasm_valtype_t* p,
   635  														 own wasm_valtype_t* r)
   636  {
   637  	wasm_valtype_t* ps[1] = {p};
   638  	wasm_valtype_t* rs[1] = {r};
   639  	return wasm_functype_new(ps, 1, rs, 1);
   640  }
   641  
   642  static inline own wasm_functype_t* wasm_functype_new_2_1(own wasm_valtype_t* p1,
   643  														 own wasm_valtype_t* p2,
   644  														 own wasm_valtype_t* r)
   645  {
   646  	wasm_valtype_t* ps[2] = {p1, p2};
   647  	wasm_valtype_t* rs[1] = {r};
   648  	return wasm_functype_new(ps, 2, rs, 1);
   649  }
   650  
   651  static inline own wasm_functype_t* wasm_functype_new_3_1(own wasm_valtype_t* p1,
   652  														 own wasm_valtype_t* p2,
   653  														 own wasm_valtype_t* p3,
   654  														 own wasm_valtype_t* r)
   655  {
   656  	wasm_valtype_t* ps[3] = {p1, p2, p3};
   657  	wasm_valtype_t* rs[1] = {r};
   658  	return wasm_functype_new(ps, 3, rs, 1);
   659  }
   660  
   661  static inline own wasm_functype_t* wasm_functype_new_0_2(own wasm_valtype_t* r1,
   662  														 own wasm_valtype_t* r2)
   663  {
   664  	wasm_valtype_t* rs[2] = {r1, r2};
   665  	return wasm_functype_new((wasm_valtype_t**)0, 0, rs, 2);
   666  }
   667  
   668  static inline own wasm_functype_t* wasm_functype_new_1_2(own wasm_valtype_t* p,
   669  														 own wasm_valtype_t* r1,
   670  														 own wasm_valtype_t* r2)
   671  {
   672  	wasm_valtype_t* ps[1] = {p};
   673  	wasm_valtype_t* rs[2] = {r1, r2};
   674  	return wasm_functype_new(ps, 1, rs, 2);
   675  }
   676  
   677  static inline own wasm_functype_t* wasm_functype_new_2_2(own wasm_valtype_t* p1,
   678  														 own wasm_valtype_t* p2,
   679  														 own wasm_valtype_t* r1,
   680  														 own wasm_valtype_t* r2)
   681  {
   682  	wasm_valtype_t* ps[2] = {p1, p2};
   683  	wasm_valtype_t* rs[2] = {r1, r2};
   684  	return wasm_functype_new(ps, 2, rs, 2);
   685  }
   686  
   687  static inline own wasm_functype_t* wasm_functype_new_3_2(own wasm_valtype_t* p1,
   688  														 own wasm_valtype_t* p2,
   689  														 own wasm_valtype_t* p3,
   690  														 own wasm_valtype_t* r1,
   691  														 own wasm_valtype_t* r2)
   692  {
   693  	wasm_valtype_t* ps[3] = {p1, p2, p3};
   694  	wasm_valtype_t* rs[2] = {r1, r2};
   695  	return wasm_functype_new(ps, 3, rs, 2);
   696  }
   697  
   698  ///////////////////////////////////////////////////////////////////////////////
   699  
   700  #undef own
   701  
   702  #ifdef __cplusplus
   703  } // extern "C"
   704  #endif
   705  
   706  #endif // #ifdef __WASM_H