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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
(* SPDX-License-Identifier: AGPL-3.0-or-later *)
(* Copyright © 2021-2024 OCamlPro *)
(* Written by the Owi programmers *)

open Types

module type Iop = sig
  type num

  type const

  type vbool

  type float32

  type float64

  val zero : num

  val clz : num -> num

  val ctz : num -> num

  val popcnt : num -> num

  val add : num -> num -> num

  val sub : num -> num -> num

  val mul : num -> num -> num

  val div : num -> num -> num

  val unsigned_div : num -> num -> num

  val rem : num -> num -> num

  val unsigned_rem : num -> num -> num

  val logand : num -> num -> num

  val logor : num -> num -> num

  val logxor : num -> num -> num

  val shl : num -> num -> num

  val shr_s : num -> num -> num

  val shr_u : num -> num -> num

  val rotl : num -> num -> num

  val rotr : num -> num -> num

  val eq_const : num -> const -> vbool

  val eq : num -> num -> vbool

  val ne : num -> num -> vbool

  val lt : num -> num -> vbool

  val gt : num -> num -> vbool

  val lt_u : num -> num -> vbool

  val gt_u : num -> num -> vbool

  val le : num -> num -> vbool

  val ge : num -> num -> vbool

  val le_u : num -> num -> vbool

  val ge_u : num -> num -> vbool

  val trunc_f32_s : float32 -> num

  val trunc_f32_u : float32 -> num

  val trunc_f64_s : float64 -> num

  val trunc_f64_u : float64 -> num

  val trunc_sat_f32_s : float32 -> num

  val trunc_sat_f32_u : float32 -> num

  val trunc_sat_f64_s : float64 -> num

  val trunc_sat_f64_u : float64 -> num

  val extend_s : int -> num -> num
end

module type Fop = sig
  type num

  type vbool

  type int32

  type int64

  type same_size_int

  val zero : num

  val abs : num -> num

  val neg : num -> num

  val sqrt : num -> num

  val ceil : num -> num

  val floor : num -> num

  val trunc : num -> num

  val nearest : num -> num

  val add : num -> num -> num

  val sub : num -> num -> num

  val mul : num -> num -> num

  val div : num -> num -> num

  val min : num -> num -> num

  val max : num -> num -> num

  val copy_sign : num -> num -> num

  val eq : num -> num -> vbool

  val ne : num -> num -> vbool

  val lt : num -> num -> vbool

  val gt : num -> num -> vbool

  val le : num -> num -> vbool

  val ge : num -> num -> vbool

  val convert_i32_s : int32 -> num

  val convert_i32_u : int32 -> num

  val convert_i64_s : int64 -> num

  val convert_i64_u : int64 -> num

  val of_bits : same_size_int -> num

  val to_bits : num -> same_size_int
end

type 'a get_ref =
  | Null
  | Ref_value of 'a
  | Type_mismatch

module type T = sig
  type vbool

  type int32

  val pp_int32 : Fmt.formatter -> int32 -> unit

  type int64

  val pp_int64 : Fmt.formatter -> int64 -> unit

  type float32

  val pp_float32 : Fmt.formatter -> float32 -> unit

  type float64

  val pp_float64 : Fmt.formatter -> float64 -> unit

  type ref_value

  val pp_ref_value : Fmt.formatter -> ref_value -> unit

  type t =
    | I32 of int32
    | I64 of int64
    | F32 of float32
    | F64 of float64
    | Ref of ref_value

  val pp : Fmt.formatter -> t -> unit

  val const_i32 : Int32.t -> int32

  val const_i64 : Int64.t -> int64

  val const_f32 : Float32.t -> float32

  val const_f64 : Float64.t -> float64
  (* TODO ref *)

  val ref_null : binary heap_type -> t

  val ref_func : Func_intf.t -> t

  val ref_externref : 'a Type.Id.t -> 'a -> t

  val ref_is_null : ref_value -> vbool

  module Ref : sig
    val get_func : ref_value -> Func_intf.t get_ref

    val get_externref : ref_value -> 'a Type.Id.t -> 'a get_ref
  end

  module Bool : sig
    val const : bool -> vbool

    val not : vbool -> vbool

    val or_ : vbool -> vbool -> vbool

    val and_ : vbool -> vbool -> vbool

    val int32 : vbool -> int32

    val pp : Fmt.formatter -> vbool -> unit
  end

  module F32 : sig
    include
      Fop
        with type num := float32
         and type vbool := vbool
         and type int32 := int32
         and type int64 := int64
         and type same_size_int := int32

    val demote_f64 : float64 -> float32

    val reinterpret_i32 : int32 -> float32
  end

  module F64 : sig
    include
      Fop
        with type num := float64
         and type vbool := vbool
         and type int32 := int32
         and type int64 := int64
         and type same_size_int := int64

    val promote_f32 : float32 -> float64

    val reinterpret_i64 : int64 -> float64
  end

  module I32 : sig
    include
      Iop
        with type num := int32
         and type vbool := vbool
         and type const := Int32.t
         and type float32 := float32
         and type float64 := float64

    val to_bool : int32 -> vbool

    val reinterpret_f32 : float32 -> int32

    val wrap_i64 : int64 -> int32
  end

  module I64 : sig
    include
      Iop
        with type num := int64
         and type vbool := vbool
         and type const := Int64.t
         and type float32 := float32
         and type float64 := float64

    val of_int32 : int32 -> int64

    val to_int32 : int64 -> int32

    val reinterpret_f64 : float64 -> int64

    val extend_i32_s : int32 -> int64

    val extend_i32_u : int32 -> int64
  end
end