Source file binable.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
(* Binable: signatures defining generated functions for the binary protocol.
   [S, S1, etc] are the signatures satisfied by the generated code and
   [Minimal.S, Minimal.S1, etc] are the signatures that generated code uses. *)

(* the subset of S containing only functions, so that one can recursively define modules
   implementing this interface *)
module type S_only_functions = sig
  type t

  val bin_size_t : t Size.sizer
  val bin_write_t : t Write.writer
  val bin_read_t : t Read.reader

  (**
     This function only needs implementation if [t] exposed to be a polymorphic variant.
     Despite what the type reads, this does *not* produce a function after reading;
     instead it takes the constructor tag (int) before reading and reads the rest of the
     variant [t] afterwards.
  *)
  val __bin_read_t__ : (int -> t) Read.reader
end

module type S_local_only_functions = sig
  include S_only_functions

  val bin_size_t__local : t Size.sizer_local
  val bin_write_t__local : t Write.writer_local
end

module type S = sig
  type t

  include S_only_functions with type t := t

  val bin_shape_t : Shape.t
  val bin_writer_t : t Type_class.writer
  val bin_reader_t : t Type_class.reader
  val bin_t : t Type_class.t
end

module type S_local = sig
  type t

  include S_local_only_functions with type t := t

  val bin_shape_t : Shape.t
  val bin_writer_t : t Type_class.writer
  val bin_reader_t : t Type_class.reader
  val bin_t : t Type_class.t
end

module type S1 = sig
  type 'a t

  val bin_shape_t : Shape.t -> Shape.t
  val bin_size_t : ('a, 'a t) Size.sizer1
  val bin_write_t : ('a, 'a t) Write.writer1
  val bin_read_t : ('a, 'a t) Read.reader1
  val __bin_read_t__ : ('a, int -> 'a t) Read.reader1
  val bin_writer_t : ('a, 'a t) Type_class.S1.writer
  val bin_reader_t : ('a, 'a t) Type_class.S1.reader
  val bin_t : ('a, 'a t) Type_class.S1.t
end

module type S_local1 = sig
  include S1

  val bin_size_t__local : ('a, 'a t) Size.sizer_local1
  val bin_write_t__local : ('a, 'a t) Write.writer_local1
end

module type S2 = sig
  type ('a, 'b) t

  val bin_shape_t : Shape.t -> Shape.t -> Shape.t
  val bin_size_t : ('a, 'b, ('a, 'b) t) Size.sizer2
  val bin_write_t : ('a, 'b, ('a, 'b) t) Write.writer2
  val bin_read_t : ('a, 'b, ('a, 'b) t) Read.reader2
  val __bin_read_t__ : ('a, 'b, int -> ('a, 'b) t) Read.reader2
  val bin_writer_t : ('a, 'b, ('a, 'b) t) Type_class.S2.writer
  val bin_reader_t : ('a, 'b, ('a, 'b) t) Type_class.S2.reader
  val bin_t : ('a, 'b, ('a, 'b) t) Type_class.S2.t
end

module type S_local2 = sig
  include S2

  val bin_size_t__local : ('a, 'b, ('a, 'b) t) Size.sizer_local2
  val bin_write_t__local : ('a, 'b, ('a, 'b) t) Write.writer_local2
end

module type S3 = sig
  type ('a, 'b, 'c) t

  val bin_shape_t : Shape.t -> Shape.t -> Shape.t -> Shape.t
  val bin_size_t : ('a, 'b, 'c, ('a, 'b, 'c) t) Size.sizer3
  val bin_write_t : ('a, 'b, 'c, ('a, 'b, 'c) t) Write.writer3
  val bin_read_t : ('a, 'b, 'c, ('a, 'b, 'c) t) Read.reader3
  val __bin_read_t__ : ('a, 'b, 'c, int -> ('a, 'b, 'c) t) Read.reader3
  val bin_writer_t : ('a, 'b, 'c, ('a, 'b, 'c) t) Type_class.S3.writer
  val bin_reader_t : ('a, 'b, 'c, ('a, 'b, 'c) t) Type_class.S3.reader
  val bin_t : ('a, 'b, 'c, ('a, 'b, 'c) t) Type_class.S3.t
end

module type S_local3 = sig
  include S3

  val bin_size_t__local : ('a, 'b, 'c, ('a, 'b, 'c) t) Size.sizer_local3
  val bin_write_t__local : ('a, 'b, 'c, ('a, 'b, 'c) t) Write.writer_local3
end

module Minimal = struct
  module type S = sig
    type t

    val bin_shape_t : Shape.t
    val bin_size_t : t Size.sizer
    val bin_write_t : t Write.writer
    val bin_read_t : t Read.reader
    val __bin_read_t__ : (int -> t) Read.reader
  end

  module type S_local = sig
    include S

    val bin_size_t__local : t Size.sizer_local
    val bin_write_t__local : t Write.writer_local
  end

  module type S1 = sig
    type 'a t

    val bin_shape_t : Shape.t -> Shape.t
    val bin_size_t : ('a, 'a t) Size.sizer1
    val bin_write_t : ('a, 'a t) Write.writer1
    val bin_read_t : ('a, 'a t) Read.reader1
    val __bin_read_t__ : ('a, int -> 'a t) Read.reader1
  end

  module type S_local1 = sig
    include S1

    val bin_size_t__local : ('a, 'a t) Size.sizer_local1
    val bin_write_t__local : ('a, 'a t) Write.writer_local1
  end

  module type S2 = sig
    type ('a, 'b) t

    val bin_shape_t : Shape.t -> Shape.t -> Shape.t
    val bin_size_t : ('a, 'b, ('a, 'b) t) Size.sizer2
    val bin_write_t : ('a, 'b, ('a, 'b) t) Write.writer2
    val bin_read_t : ('a, 'b, ('a, 'b) t) Read.reader2
    val __bin_read_t__ : ('a, 'b, int -> ('a, 'b) t) Read.reader2
  end

  module type S_local2 = sig
    include S2

    val bin_size_t__local : ('a, 'b, ('a, 'b) t) Size.sizer_local2
    val bin_write_t__local : ('a, 'b, ('a, 'b) t) Write.writer_local2
  end

  module type S3 = sig
    type ('a, 'b, 'c) t

    val bin_shape_t : Shape.t -> Shape.t -> Shape.t -> Shape.t
    val bin_size_t : ('a, 'b, 'c, ('a, 'b, 'c) t) Size.sizer3
    val bin_write_t : ('a, 'b, 'c, ('a, 'b, 'c) t) Write.writer3
    val bin_read_t : ('a, 'b, 'c, ('a, 'b, 'c) t) Read.reader3
    val __bin_read_t__ : ('a, 'b, 'c, int -> ('a, 'b, 'c) t) Read.reader3
  end

  module type S_local3 = sig
    include S3

    val bin_size_t__local : ('a, 'b, 'c, ('a, 'b, 'c) t) Size.sizer_local3
    val bin_write_t__local : ('a, 'b, 'c, ('a, 'b, 'c) t) Write.writer_local3
  end
end