package wasmtime

  1. Overview
  2. Docs

Source file bindings.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
open! Ctypes

module C (F : Cstubs.FOREIGN) = struct
  open! F

  module Byte_vec = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_byte_vec_t"
    let size = field struct_ "size" size_t
    let data = field struct_ "data" (ptr char)
    let () = seal struct_
    let t : t typ = ptr struct_
    let new_ = foreign "wasm_byte_vec_new" (t @-> size_t @-> string @-> returning void)

    let new_uninitialized =
      foreign "wasm_byte_vec_new_uninitialized" (t @-> size_t @-> returning void)

    let copy = foreign "wasm_byte_vec_copy" (t @-> t @-> returning void)
    let delete = foreign "wasm_byte_vec_delete" (t @-> returning void)
  end

  module Engine = struct
    type t = unit ptr

    let t : t typ = ptr void
    let new_ = foreign "wasm_engine_new" (void @-> returning t)
    let delete = foreign "wasm_engine_delete" (t @-> returning void)
  end

  module Store = struct
    type t = unit ptr

    let t : t typ = ptr void
    let new_ = foreign "wasm_store_new" (Engine.t @-> returning t)
    let delete = foreign "wasm_store_delete" (t @-> returning void)
  end

  module Trap = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_trap_t"
    let t : t typ = ptr struct_
    let new_ = foreign "wasm_trap_new" (Store.t @-> Byte_vec.t @-> returning t)
    let message = foreign "wasm_trap_message" (t @-> Byte_vec.t @-> returning void)
    let delete = foreign "wasm_trap_delete" (t @-> returning void)
  end

  module Val = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr
    type op

    let op_typ : op union typ = union "op"
    let ( -: ) ty label = field op_typ label ty
    let i32 = int32_t -: "i32"
    let i64 = int64_t -: "i64"
    let f32 = float -: "f32"
    let f64 = double -: "f64"
    let ref = ptr void -: "ref"
    let () = seal op_typ
    let struct_ : struct_ typ = structure "wasm_val_t"
    let kind = field struct_ "kind" uint8_t
    let op = field struct_ "op" op_typ
    let () = seal struct_
    let t : t typ = ptr struct_
    let delete = foreign "wasm_val_delete" (t @-> returning void)
  end

  module Val_vec = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_val_vec_t"
    let size = field struct_ "size" size_t
    let data = field struct_ "data" (ptr Val.t)
    let () = seal struct_
    let t : t typ = ptr struct_
    let delete = foreign "wasm_val_vec_delete" (t @-> returning void)
  end

  module Memory = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_memory_t"
    let t : t typ = ptr struct_
    let data = foreign "wasm_memory_data" (t @-> returning (ptr char))
    let grow = foreign "wasm_memory_grow" (t @-> uint32_t @-> returning bool)
    let size = foreign "wasm_memory_size" (t @-> returning size_t)
    let data_size = foreign "wasm_memory_data_size" (t @-> returning size_t)
    let delete = foreign "wasm_memory_delete" (t @-> returning void)
  end

  module Func_type = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_functype_t"
    let t : t typ = ptr struct_
    let new_ = foreign "wasm_functype_new_0_0" (void @-> returning t)
    let delete = foreign "wasm_functype_delete" (t @-> returning void)
  end

  module Func = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_func_t"
    let t : t typ = ptr struct_

    let new_ =
      foreign
        "wasm_func_new"
        (Store.t
        @-> Func_type.t
        @-> static_funptr Ctypes.(Val_vec.t @-> Val_vec.t @-> returning Trap.t)
        @-> returning t)

    let delete = foreign "wasm_func_delete" (t @-> returning void)
  end

  module Extern = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_extern_t"
    let t : t typ = ptr struct_
    let delete = foreign "wasm_extern_delete" (t @-> returning void)
    let as_func = foreign "wasm_extern_as_func" (t @-> returning Func.t)
    let func_as = foreign "wasm_func_as_extern" (Func.t @-> returning t)
    let as_memory = foreign "wasm_extern_as_memory" (t @-> returning Memory.t)
  end

  module Extern_vec = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_extern_vec_t"
    let size = field struct_ "size" size_t
    let data = field struct_ "data" (ptr Extern.t)
    let () = seal struct_
    let t : t typ = ptr struct_
    let delete = foreign "wasm_extern_vec_delete" (t @-> returning void)
  end

  module Module = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_module_t"
    let t : t typ = ptr struct_
    let delete = foreign "wasm_module_delete" (t @-> returning void)
  end

  module Instance = struct
    type modl
    type struct_ = modl Ctypes.structure
    type t = struct_ ptr

    let struct_ : struct_ typ = structure "wasm_instance_t"
    let t : t typ = ptr struct_
    let delete = foreign "wasm_instance_delete" (t @-> returning void)

    let new_ =
      foreign
        "wasm_instance_new"
        (Store.t @-> Module.t @-> ptr Extern.t @-> ptr Trap.t @-> returning t)

    let exports = foreign "wasm_instance_exports" (t @-> Extern_vec.t @-> returning void)
  end

  (* wasmtime.h specific bits *)
  module Error = struct
    type t = unit ptr

    let t : t typ = ptr void
    let message = foreign "wasmtime_error_message" (t @-> Byte_vec.t @-> returning void)
    let delete = foreign "wasmtime_error_delete" (t @-> returning void)
  end

  module Wasi_config = struct
    type t = unit ptr

    let t : t typ = ptr void
    let new_ = foreign "wasi_config_new" (void @-> returning t)
    let delete = foreign "wasi_config_delete" (t @-> returning void)
    let inherit_argv = foreign "wasi_config_inherit_argv" (t @-> returning void)
    let inherit_env = foreign "wasi_config_inherit_env" (t @-> returning void)
    let inherit_stdin = foreign "wasi_config_inherit_stdin" (t @-> returning void)
    let inherit_stdout = foreign "wasi_config_inherit_stdout" (t @-> returning void)
    let inherit_stderr = foreign "wasi_config_inherit_stderr" (t @-> returning void)

    let preopen_dir =
      foreign "wasi_config_preopen_dir" (t @-> string @-> string @-> returning bool)
  end

  module Wasi_instance = struct
    type t = unit ptr

    let t : t typ = ptr void

    let new_ =
      foreign
        "wasi_instance_new"
        (Store.t @-> string @-> Wasi_config.t @-> ptr Trap.t @-> returning t)

    let delete = foreign "wasi_instance_delete" (t @-> returning void)
  end

  module Wasmtime = struct
    module Linker = struct
      type t = unit ptr

      let t : t typ = ptr void
      let new_ = foreign "wasmtime_linker_new" (Store.t @-> returning t)
      let delete = foreign "wasmtime_linker_delete" (t @-> returning void)

      let define_wasi =
        foreign "wasmtime_linker_define_wasi" (t @-> Wasi_instance.t @-> returning Error.t)

      let module_ =
        foreign
          "wasmtime_linker_module"
          (t @-> Byte_vec.t @-> Module.t @-> returning Error.t)

      let get_default =
        foreign
          "wasmtime_linker_get_default"
          (t @-> Byte_vec.t @-> ptr Func.t @-> returning Error.t)
    end

    let wat2wasm =
      foreign "wasmtime_wat2wasm" (Byte_vec.t @-> Byte_vec.t @-> returning Error.t)

    let new_module =
      foreign
        "wasmtime_module_new"
        (Engine.t @-> Byte_vec.t @-> ptr Module.t @-> returning Error.t)

    let func_call =
      foreign
        "wasmtime_func_call"
        (Func.t
        @-> ptr Val.struct_
        @-> size_t
        @-> ptr Val.struct_
        @-> size_t
        @-> ptr Trap.t
        @-> returning Error.t)

    let new_instance =
      foreign
        "wasmtime_instance_new"
        (Store.t
        @-> Module.t
        @-> ptr Extern.t
        @-> size_t
        @-> ptr Instance.t
        @-> ptr Trap.t
        @-> returning Error.t)
  end
end
OCaml

Innovation. Community. Security.