@@ -24,11 +24,6 @@ open Code_generation
24
24
module Make (Target : Target_sig.S ) = struct
25
25
open Target
26
26
27
- let func_type n =
28
- { W. params = List. init ~len: (n + 1 ) ~f: (fun _ -> Value. value)
29
- ; result = [ Value. value ]
30
- }
31
-
32
27
let bind_parameters l =
33
28
List. fold_left
34
29
~f: (fun l x ->
@@ -102,7 +97,7 @@ module Make (Target : Target_sig.S) = struct
102
97
let param_names = args @ [ f ] in
103
98
let locals, body = function_body ~context ~param_names ~body in
104
99
W. Function
105
- { name; exported_name = None ; typ = func_type 1 ; param_names; locals; body }
100
+ { name; exported_name = None ; typ = Type. func_type 1 ; param_names; locals; body }
106
101
107
102
let curry_name n m = Printf. sprintf " curry_%d_%d" n m
108
103
@@ -130,7 +125,7 @@ module Make (Target : Target_sig.S) = struct
130
125
let param_names = [ x; f ] in
131
126
let locals, body = function_body ~context ~param_names ~body in
132
127
W. Function
133
- { name; exported_name = None ; typ = func_type 1 ; param_names; locals; body }
128
+ { name; exported_name = None ; typ = Type. func_type 1 ; param_names; locals; body }
134
129
:: functions
135
130
136
131
let curry ~arity ~name = curry ~arity arity ~name
@@ -174,7 +169,7 @@ module Make (Target : Target_sig.S) = struct
174
169
let param_names = args @ [ f ] in
175
170
let locals, body = function_body ~context ~param_names ~body in
176
171
W. Function
177
- { name; exported_name = None ; typ = func_type 2 ; param_names; locals; body }
172
+ { name; exported_name = None ; typ = Type. func_type 2 ; param_names; locals; body }
178
173
179
174
let cps_curry_name n m = Printf. sprintf " cps_curry_%d_%d" n m
180
175
@@ -206,7 +201,7 @@ module Make (Target : Target_sig.S) = struct
206
201
let param_names = [ x; cont; f ] in
207
202
let locals, body = function_body ~context ~param_names ~body in
208
203
W. Function
209
- { name; exported_name = None ; typ = func_type 2 ; param_names; locals; body }
204
+ { name; exported_name = None ; typ = Type. func_type 2 ; param_names; locals; body }
210
205
:: functions
211
206
212
207
let cps_curry ~arity ~name = cps_curry ~arity arity ~name
@@ -243,7 +238,13 @@ module Make (Target : Target_sig.S) = struct
243
238
let param_names = l @ [ f ] in
244
239
let locals, body = function_body ~context ~param_names ~body in
245
240
W. Function
246
- { name; exported_name = None ; typ = func_type arity; param_names; locals; body }
241
+ { name
242
+ ; exported_name = None
243
+ ; typ = Type. primitive_type (arity + 1 )
244
+ ; param_names
245
+ ; locals
246
+ ; body
247
+ }
247
248
248
249
let cps_apply ~context ~arity ~name =
249
250
assert (arity > 2 );
@@ -271,7 +272,7 @@ module Make (Target : Target_sig.S) = struct
271
272
(List. map ~f: (fun x -> `Var x) (List. tl l))
272
273
in
273
274
let * make_iterator =
274
- register_import ~name: " caml_apply_continuation" (Fun (func_type 0 ))
275
+ register_import ~name: " caml_apply_continuation" (Fun (Type. primitive_type 1 ))
275
276
in
276
277
let iterate = Var. fresh_n " iterate" in
277
278
let * () = store iterate (return (W. Call (make_iterator, [ args ]))) in
@@ -283,7 +284,13 @@ module Make (Target : Target_sig.S) = struct
283
284
let param_names = l @ [ f ] in
284
285
let locals, body = function_body ~context ~param_names ~body in
285
286
W. Function
286
- { name; exported_name = None ; typ = func_type arity; param_names; locals; body }
287
+ { name
288
+ ; exported_name = None
289
+ ; typ = Type. primitive_type (arity + 1 )
290
+ ; param_names
291
+ ; locals
292
+ ; body
293
+ }
287
294
288
295
let dummy ~context ~cps ~arity ~name =
289
296
let arity = if cps then arity + 1 else arity in
@@ -311,7 +318,13 @@ module Make (Target : Target_sig.S) = struct
311
318
let param_names = l @ [ f ] in
312
319
let locals, body = function_body ~context ~param_names ~body in
313
320
W. Function
314
- { name; exported_name = None ; typ = func_type arity; param_names; locals; body }
321
+ { name
322
+ ; exported_name = None
323
+ ; typ = Type. func_type arity
324
+ ; param_names
325
+ ; locals
326
+ ; body
327
+ }
315
328
316
329
let f ~context =
317
330
IntMap. iter
0 commit comments