File: gen.mlt

package info (click to toggle)
js-of-ocaml 6.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,932 kB
  • sloc: ml: 135,957; javascript: 58,364; ansic: 437; makefile: 422; sh: 12; perl: 4
file content (380 lines) | stat: -rw-r--r-- 10,440 bytes parent folder | download
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
module Js_of_ocaml = struct
  module Js = struct
    class type js_string = object end

    type +'a t

    type (-'a, +'b) meth_callback

    type +'a opt

    type +'a optdef

    type +'a meth

    type +'a gen_prop

    type 'a readonly_prop = < get : 'a > gen_prop

    type 'a writeonly_prop = < set : 'a -> unit > gen_prop

    type 'a prop = < get : 'a ; set : 'a -> unit > gen_prop

    type 'a optdef_prop = < get : 'a optdef ; set : 'a -> unit > gen_prop

    type +'a constr

    (****)

    type 'a callback = (unit, 'a) meth_callback

    module Unsafe = struct
      type any

      type any_js_array = any

      let inject : 'a -> any = fun _ -> assert false

      let get : 'a -> 'b -> 'c = fun _ _ -> assert false

      let set : 'a -> 'b -> 'c -> unit = fun _ _ _ -> assert false

      let meth_call : 'a -> string -> any array -> 'b = fun _ _ _ -> assert false

      let obj : (string * any) array -> 'a = fun _ -> assert false
    end

    let wrap_meth_callback : ('a -> 'b) -> ('a, 'b) meth_callback = fun _ -> assert false

    let string : string -> js_string t = fun _ -> assert false

    let undefined : unit -> 'a optdef = fun () -> assert false

    let def : 'a -> 'a optdef = fun _ -> assert false
  end
end
;;

#directory "+compiler-libs"

let () = Clflags.dump_source := true

[%%expect
{|
module Js_of_ocaml :
  sig
    module Js :
      sig
        class type js_string = object  end
        type +'a t
        type (-'a, +'b) meth_callback
        type +'a opt
        type +'a optdef
        type +'a meth
        type +'a gen_prop
        type 'a readonly_prop = < get : 'a > gen_prop
        type 'a writeonly_prop = < set : 'a -> unit > gen_prop
        type 'a prop = < get : 'a; set : 'a -> unit > gen_prop
        type 'a optdef_prop = < get : 'a optdef; set : 'a -> unit > gen_prop
        type +'a constr
        type 'a callback = (unit, 'a) meth_callback
        module Unsafe :
          sig
            type any
            type any_js_array = any
            val inject : 'a -> any
            val get : 'a -> 'b -> 'c
            val set : 'a -> 'b -> 'c -> unit
            val meth_call : 'a -> string -> any array -> 'b
            val obj : (string * any) array -> 'a
          end
        val wrap_meth_callback : ('a -> 'b) -> ('a, 'b) meth_callback
        val string : string -> js_string t
        val undefined : unit -> 'a optdef
        val def : 'a -> 'a optdef
      end
  end
|}]

let o () =
  object%js
    method m1 a b = a + b
  end

[%%expect
{|
let o () =
  (fun (type res) (type t0) (type t1) (type t2)
     (t2 : res Js_of_ocaml.Js.t -> t0 -> t1 -> t2)
     (_ :
       res Js_of_ocaml.Js.t ->
         (res Js_of_ocaml.Js.t -> t0 -> t1 -> t2 Js_of_ocaml.Js.meth) -> res)
     : res Js_of_ocaml.Js.t->
     Js_of_ocaml.Js.Unsafe.obj
       [|("m1",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t2)))|])
    (fun _ a b -> a + b) ((fun self m1 -> object method m1 = m1 self end)
    [@merlin.hide ]);;
val o :
  unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
  <fun>
|}]

let o () =
  object%js
    method m1 a = fun b -> a + b
  end

[%%expect
{|
let o () =
  (fun (type res) (type t3) (type t4) (type t5)
     (t5 : res Js_of_ocaml.Js.t -> t3 -> t4 -> t5)
     (_ :
       res Js_of_ocaml.Js.t ->
         (res Js_of_ocaml.Js.t -> t3 -> t4 -> t5 Js_of_ocaml.Js.meth) -> res)
     : res Js_of_ocaml.Js.t->
     Js_of_ocaml.Js.Unsafe.obj
       [|("m1",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t5)))|])
    (fun _ a -> fun b -> a + b)
    ((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
val o :
  unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
  <fun>
|}]

let o () =
  object%js
    method m1 = fun a b -> a + b
  end

[%%expect
{|
let o () =
  (fun (type res) (type t6) (type t7) (type t8)
     (t8 : res Js_of_ocaml.Js.t -> t6 -> t7 -> t8)
     (_ :
       res Js_of_ocaml.Js.t ->
         (res Js_of_ocaml.Js.t -> t6 -> t7 -> t8 Js_of_ocaml.Js.meth) -> res)
     : res Js_of_ocaml.Js.t->
     Js_of_ocaml.Js.Unsafe.obj
       [|("m1",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t8)))|])
    (fun _ a b -> a + b) ((fun self m1 -> object method m1 = m1 self end)
    [@merlin.hide ]);;
val o :
  unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
  <fun>
|}]

let o () =
  object%js
    method m1 = fun a -> fun b -> a + b
  end

[%%expect
{|
let o () =
  (fun (type res) (type t9) (type t10) (type t11)
     (t11 : res Js_of_ocaml.Js.t -> t9 -> t10 -> t11)
     (_ :
       res Js_of_ocaml.Js.t ->
         (res Js_of_ocaml.Js.t -> t9 -> t10 -> t11 Js_of_ocaml.Js.meth) ->
           res)
     : res Js_of_ocaml.Js.t->
     Js_of_ocaml.Js.Unsafe.obj
       [|("m1",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t11)))|])
    (fun _ a -> fun b -> a + b)
    ((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
val o :
  unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
  <fun>
|}]

let o () =
  object%js
    method m1 a =
      function
      | b -> a + b
  end

[%%expect
{|
let o () =
  (fun (type res) (type t12) (type t13) (type t14)
     (t14 : res Js_of_ocaml.Js.t -> t12 -> t13 -> t14)
     (_ :
       res Js_of_ocaml.Js.t ->
         (res Js_of_ocaml.Js.t -> t12 -> t13 -> t14 Js_of_ocaml.Js.meth) ->
           res)
     : res Js_of_ocaml.Js.t->
     Js_of_ocaml.Js.Unsafe.obj
       [|("m1",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t14)))|])
    (fun _ a -> function | b -> a + b)
    ((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
val o :
  unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
  <fun>
|}]

let o () =
  object%js
    method m1 a =
      function
      | 0 -> a
      | b -> a + b
  end

[%%expect
{|
let o () =
  (fun (type res) (type t15) (type t16) (type t17)
     (t17 : res Js_of_ocaml.Js.t -> t15 -> t16 -> t17)
     (_ :
       res Js_of_ocaml.Js.t ->
         (res Js_of_ocaml.Js.t -> t15 -> t16 -> t17 Js_of_ocaml.Js.meth) ->
           res)
     : res Js_of_ocaml.Js.t->
     Js_of_ocaml.Js.Unsafe.obj
       [|("m1",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t17)))|])
    (fun _ a -> function | 0 -> a | b -> a + b)
    ((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
val o :
  unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
  <fun>
|}]

let o () =
  object%js
    method m1 (type b) a =
      function
      | 0 -> a
      | b -> a + b
  end

[%%expect
{|
let o () =
  (fun (type res) (type t18) (type t19) (type t20)
     (t20 : res Js_of_ocaml.Js.t -> t18 -> t19 -> t20)
     (_ :
       res Js_of_ocaml.Js.t ->
         (res Js_of_ocaml.Js.t -> t18 -> t19 -> t20 Js_of_ocaml.Js.meth) ->
           res)
     : res Js_of_ocaml.Js.t->
     Js_of_ocaml.Js.Unsafe.obj
       [|("m1",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t20)))|])
    (fun _ (type b) a -> function | 0 -> a | b -> a + b)
    ((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
val o :
  unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
  <fun>
|}]

let o () =
  object%js
    method m1 a (type b) =
      function
      | 0 -> a
      | b -> a + b
  end

[%%expect
{|
let o () =
  (fun (type res) (type t21) (type t22) (type t23)
     (t23 : res Js_of_ocaml.Js.t -> t21 -> t22 -> t23)
     (_ :
       res Js_of_ocaml.Js.t ->
         (res Js_of_ocaml.Js.t -> t21 -> t22 -> t23 Js_of_ocaml.Js.meth) ->
           res)
     : res Js_of_ocaml.Js.t->
     Js_of_ocaml.Js.Unsafe.obj
       [|("m1",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t23)))|])
    (fun _ a (type b) -> function | 0 -> a | b -> a + b)
    ((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
val o :
  unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
  <fun>
|}]


let o () =
  object%js
    method m1 : 'a. 'a -> unit = fun a -> ignore a
  end

[%%expect {|
let o () = [%ocaml.error "Polymorphic method not supported."];;
Line _, characters 4-50:
Error: Polymorphic method not supported.
|}]

let o () =
  object%js
    method m1 : 'a. 'a -> unit = fun (type a) (a : a) -> ignore a
  end

[%%expect {|
let o () = [%ocaml.error "Polymorphic method not supported."];;
Line _, characters 4-65:
Error: Polymorphic method not supported.
|}]


let o () =
  object%js
    method m1 : 'a  -> unit = fun (type a) (a : a) -> ignore a
    method m2 : int -> unit = fun (type a) (a : a) -> ignore a
    method m3 : 'b -> unit = fun (a : 'b) -> ignore a
  end

[%%expect {|
let o () =
  (fun (type res) (type t26) (type t27) (type t28) (type t29) (type t30)
     (type t31) (t29 : res Js_of_ocaml.Js.t -> t26 -> t29)
     (t30 : res Js_of_ocaml.Js.t -> t27 -> t30)
     (t31 : res Js_of_ocaml.Js.t -> t28 -> t31)
     (_ :
       res Js_of_ocaml.Js.t ->
         (res Js_of_ocaml.Js.t -> t26 -> t29 Js_of_ocaml.Js.meth) ->
           (res Js_of_ocaml.Js.t -> t27 -> t30 Js_of_ocaml.Js.meth) ->
             (res Js_of_ocaml.Js.t -> t28 -> t31 Js_of_ocaml.Js.meth) -> res)
     : res Js_of_ocaml.Js.t->
     Js_of_ocaml.Js.Unsafe.obj
       [|("m1",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t29)));("m2",
                                                          (Js_of_ocaml.Js.Unsafe.inject
                                                             (Js_of_ocaml.Js.wrap_meth_callback
                                                                t30)));
         ("m3",
           (Js_of_ocaml.Js.Unsafe.inject
              (Js_of_ocaml.Js.wrap_meth_callback t31)))|])
    (fun _ : 'a -> unit-> fun (type a) (a : a) -> ignore a)
    (fun _ : int -> unit-> fun (type a) (a : a) -> ignore a)
    (fun _ : 'b -> unit-> fun (a : 'b) -> ignore a)
    ((fun self m1 m2 m3 ->
        object method m1 = m1 self method m2 = m2 self method m3 = m3 self
        end)[@merlin.hide ]);;
val o :
  unit ->
  < m1 : 't26 -> unit Js_of_ocaml.Js.meth;
    m2 : int -> unit Js_of_ocaml.Js.meth;
    m3 : 't28 -> unit Js_of_ocaml.Js.meth >
  Js_of_ocaml.Js.t = <fun>
|}]