123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 TriliTech <contact@trili.tech> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openCtypesmoduleTypes=Api_types(** This functor is used by Ctypes to generate function bindings for the
Wasmer C API. *)moduleFunctions(S:FOREIGN)=structopenS(** This functor corresponds to the [WASM_DECLARE_VEC] macro in [wasm.h]. *)moduleDeclare_vec(Vector:sigincludeTypes.Named_typetypeitemvalitem:itemtypend)=structletnew_empty=foreign("wasm_"^Vector.name^"_new_empty")(ptrVector.t@->returningvoid)letnew_=foreign("wasm_"^Vector.name^"_new")(ptrVector.t@->size_t@->ptrVector.item@->returningvoid)letnew_uninitialized=foreign("wasm_"^Vector.name^"_new_uninitialized")(ptrVector.t@->size_t@->returningvoid)letdelete=foreign("wasm_"^Vector.name^"_delete")(ptrVector.t@->returningvoid)end(** Generate a pointer type from another type. *)modulePtr(Item:sigvalname:stringtypetvalt:ttypend)=structincludeItemtypet=Item.tCtypes.ptrlett=ptrItem.tend(** Functions with the [wasmer_] prefix *)moduleWasmer=structmoduleCompiler=structletis_available=foreign"wasmer_is_compiler_available"(Types.Wasmer.Compiler.t@->returningbool)endmoduleFeatures=structletnew_=foreign"wasmer_features_new"(void@->returning(ptrTypes.Wasmer.Features.t))letbulk_memory=foreign"wasmer_features_bulk_memory"(ptrTypes.Wasmer.Features.t@->bool@->returningbool)letmemory64=foreign"wasmer_features_memory64"(ptrTypes.Wasmer.Features.t@->bool@->returningbool)letmodule_linking=foreign"wasmer_features_module_linking"(ptrTypes.Wasmer.Features.t@->bool@->returningbool)letmulti_memory=foreign"wasmer_features_multi_memory"(ptrTypes.Wasmer.Features.t@->bool@->returningbool)letmulti_value=foreign"wasmer_features_multi_value"(ptrTypes.Wasmer.Features.t@->bool@->returningbool)letreference_types=foreign"wasmer_features_reference_types"(ptrTypes.Wasmer.Features.t@->bool@->returningbool)letsimd=foreign"wasmer_features_simd"(ptrTypes.Wasmer.Features.t@->bool@->returningbool)lettail_call=foreign"wasmer_features_tail_call"(ptrTypes.Wasmer.Features.t@->bool@->returningbool)letthreads=foreign"wasmer_features_threads"(ptrTypes.Wasmer.Features.t@->bool@->returningbool)endletlast_error_length=foreign"wasmer_last_error_length"(void@->returningint)letlast_error=foreign"wasmer_last_error_message"(ptrchar@->int@->returningint)end(** Functions with the [wasm_config_] prefix *)moduleConfig=structletnew_=foreign"wasm_config_new"(void@->returning(ptrTypes.Config.t))letset_compiler=foreign"wasm_config_set_compiler"(ptrTypes.Config.t@->Types.Wasmer.Compiler.t@->returningvoid)letset_features=foreign"wasm_config_set_features"(ptrTypes.Config.t@->ptrTypes.Wasmer.Features.t@->returningvoid)letdelete=foreign"wasm_config_delete"(ptrTypes.Config.t@->returningvoid)end(** Functions with the [wasm_engine_] prefix *)moduleEngine=structletnew_with_config=foreign"wasm_engine_new_with_config"(ptrTypes.Config.t@->returning(ptrTypes.Engine.t))letdelete=foreign"wasm_engine_delete"(ptrTypes.Engine.t@->returningvoid)end(** Functions with the [wasm_store_] prefix *)moduleStore=structletnew_=foreign"wasm_store_new"(ptrTypes.Engine.t@->returning(ptrTypes.Store.t))letdelete=foreign"wasm_store_delete"(ptrTypes.Store.t@->returningvoid)end(** Functions with the [wasm_module_] prefix *)moduleModule=structletnew_=foreign"wasm_module_new"(ptrTypes.Store.t@->ptrTypes.Byte_vec.t@->returning(ptrTypes.Module.t))letdelete=foreign"wasm_module_delete"(ptrTypes.Module.t@->returningvoid)letimports=foreign"wasm_module_imports"(ptrTypes.Module.t@->ptrTypes.Importtype.Vec.t@->returningvoid)letexports=foreign"wasm_module_exports"(ptrTypes.Module.t@->ptrTypes.Exporttype.Vec.t@->returningvoid)end(** Functions with the [wasm_byte_vec_] prefix *)moduleByte_vec=struct(* NOTE: This module does not use [Declare_vec] to allow us to use the
better [Ctypes.string] type which takes care of string marshalling. *)letnew_=foreign"wasm_byte_vec_new"(ptrTypes.Byte_vec.t@->Ctypes.size_t@->Ctypes.string@->returningvoid)letnew_empty=foreign"wasm_byte_vec_new_empty"(ptrTypes.Byte_vec.t@->returningvoid)letdelete=foreign"wasm_byte_vec_delete"(ptrTypes.Byte_vec.t@->returningvoid)end(** Functions with the [wasm_val_vec_] prefix *)moduleVal_vec=Declare_vec(Types.Val_vec)(** Functions with the [wasm_valtype_] prefix *)moduleValtype=structletnew_=foreign"wasm_valtype_new"(Types.Valkind.t@->returning(ptrTypes.Valtype.t))letkind=foreign"wasm_valtype_kind"(ptrTypes.Valtype.t@->returningTypes.Valkind.t)end(** Functions with the [wasm_valtype_vec_] prefix *)moduleValtype_vec=Declare_vec(Types.Valtype.Vec)(** Functions with the [wasm_extern_] prefix *)moduleExtern=structletas_func=foreign"wasm_extern_as_func"(ptrTypes.Extern.t@->returning(ptrTypes.Func.t))letas_memory=foreign"wasm_extern_as_memory"(ptrTypes.Extern.t@->returning(ptrTypes.Memory.t))letdelete=foreign"wasm_extern_delete"(ptrTypes.Extern.t@->returningvoid)end(** Functions with the [wasm_extern_vec_] prefix *)moduleExtern_vec=Declare_vec(Types.Extern.Vec)(** Functions with the [wasm_functype_] prefix *)moduleFunctype=structletnew_=foreign"wasm_functype_new"(ptrTypes.Valtype.Vec.t@->ptrTypes.Valtype.Vec.t@->returning(ptrTypes.Functype.t))letparams=foreign"wasm_functype_params"(ptrTypes.Functype.t@->returning(ptrTypes.Valtype.Vec.t))letresults=foreign"wasm_functype_results"(ptrTypes.Functype.t@->returning(ptrTypes.Valtype.Vec.t))letdelete=foreign"wasm_functype_delete"(ptrTypes.Functype.t@->returningvoid)end(** Functions with the [wasm_func_] prefix *)moduleFunc=structletnew_=foreign"wasm_func_new"(ptrTypes.Store.t@->ptrTypes.Functype.t@->Types.Func_callback.t@->returning(ptrTypes.Func.t))letas_extern=foreign"wasm_func_as_extern"(ptrTypes.Func.t@->returning(ptrTypes.Extern.t))letcall=foreign"wasm_func_call"(ptrTypes.Func.t@->ptrTypes.Val_vec.t@->ptrTypes.Val_vec.t@->returning(ptrTypes.Trap.t))letparam_arity=foreign"wasm_func_param_arity"(ptrTypes.Func.t@->returningsize_t)letresult_arity=foreign"wasm_func_result_arity"(ptrTypes.Func.t@->returningsize_t)lettype_=foreign"wasm_func_type"(ptrTypes.Func.t@->returning(ptrTypes.Functype.t))end(** Functions with the [wasm_memory_] prefix *)moduleMemory=structletdata=foreign"wasm_memory_data"(ptrTypes.Memory.t@->returning(ptruint8_t))letdata_size=foreign"wasm_memory_data_size"(ptrTypes.Memory.t@->returningsize_t)lettype_=foreign"wasm_memory_type"(ptrTypes.Memory.t@->returning(ptrTypes.Memorytype.t))end(** Functions with the [wasm_memory_type_] prefix *)moduleMemory_type=structletlimits=foreign"wasm_memorytype_limits"(ptrTypes.Memorytype.t@->returning(ptrTypes.Limits.t))letdelete=foreign"wasm_memorytype_delete"(ptrTypes.Memorytype.t@->returningvoid)end(** Functions with the [wasm_instance_] prefix *)moduleInstance=structletnew_=foreign"wasm_instance_new"(ptrTypes.Store.t@->ptrTypes.Module.t@->ptrTypes.Extern.Vec.t@->ptr(ptrTypes.Trap.t)@->returning(ptrTypes.Instance.t))letdelete=foreign"wasm_instance_delete"(ptrTypes.Instance.t@->returningvoid)letexports=foreign"wasm_instance_exports"(ptrTypes.Instance.t@->ptrTypes.Extern.Vec.t@->returningvoid)end(** Functions with the [wasm_name_] prefix *)moduleName=Byte_vec(** Functions with the [wasm_message_] prefix *)moduleMessage=Name(** Functions with the [wasm_trap_] prefix *)moduleTrap=structletnew_=foreign"wasm_trap_new"(ptrTypes.Store.t@->ptrTypes.Message.t@->returning(ptrTypes.Trap.t))letmessage=foreign"wasm_trap_message"(ptrTypes.Trap.t@->ptrTypes.Message.t@->returningvoid)letdelete=foreign"wasm_trap_delete"(ptrTypes.Trap.t@->returningvoid)end(** Functions with the [wasm_externtype_] prefix *)moduleExterntype=structletkind=foreign"wasm_externtype_kind"(ptrTypes.Externtype.t@->returningTypes.Externkind.t)end(** Functions with the [wasm_importtype_] prefix *)moduleImporttype=structletmodule_=foreign"wasm_importtype_module"(ptrTypes.Importtype.t@->returning(ptrTypes.Name.t))letname=foreign"wasm_importtype_name"(ptrTypes.Importtype.t@->returning(ptrTypes.Name.t))lettype_=foreign"wasm_importtype_type"(ptrTypes.Importtype.t@->returning(ptrTypes.Externtype.t))end(** Functions with the [wasm_importtype_vec_] prefix *)moduleImporttype_vec=Declare_vec(Types.Importtype.Vec)(** Functions with the [wasm_exporttype_] prefix *)moduleExporttype=structletname=foreign"wasm_exporttype_name"(ptrTypes.Exporttype.t@->returning(ptrTypes.Name.t))lettype_=foreign"wasm_exporttype_type"(ptrTypes.Exporttype.t@->returning(ptrTypes.Externtype.t))letdelete=foreign"wasm_exporttype_delete"(ptrTypes.Exporttype.t@->returningvoid)end(** Functions with the [wasm_exporttype_vec_] prefix *)moduleExporttype_vec=Declare_vec(Types.Exporttype.Vec)letwat2wasm=foreign"wat2wasm"(ptrTypes.Byte_vec.t@->ptrTypes.Byte_vec.t@->returningvoid)end