@@ -22,8 +22,6 @@ open Code_generation
22
22
23
23
type expression = Wasm_ast .expression Code_generation .t
24
24
25
- let include_closure_arity = false
26
-
27
25
module Type = struct
28
26
let value = W. Ref { nullable = false ; typ = Eq }
29
27
@@ -215,13 +213,7 @@ module Type = struct
215
213
let closure_common_fields ~cps =
216
214
let * fun_ty = function_type ~cps 1 in
217
215
return
218
- (let function_pointer =
219
- [ { W. mut = false ; typ = W. Value (Ref { nullable = false ; typ = Type fun_ty }) }
220
- ]
221
- in
222
- if include_closure_arity
223
- then { W. mut = false ; typ = W. Value I32 } :: function_pointer
224
- else function_pointer)
216
+ [ { W. mut = false ; typ = W. Value (Ref { nullable = false ; typ = Type fun_ty }) } ]
225
217
226
218
let closure_type_1 ~cps =
227
219
register_type
@@ -807,9 +799,9 @@ module Memory = struct
807
799
let set_field e idx e' = wasm_array_set e (Arith. const (Int32. of_int (idx + 1 ))) e'
808
800
809
801
let env_start arity =
810
- if arity = 0
811
- then 1
812
- else ( if include_closure_arity then 1 else 0 ) + if arity = 1 then 1 else 2
802
+ match arity with
803
+ | 0 | 1 -> 1
804
+ | _ -> 2
813
805
814
806
let load_function_pointer ~cps ~arity ?(skip_cast = false ) closure =
815
807
let arity = if cps then arity - 1 else arity in
@@ -1082,15 +1074,9 @@ module Closure = struct
1082
1074
{ mut = false ; typ = Type. value }
1083
1075
(W. StructNew
1084
1076
( typ
1085
- , if arity = 0
1086
- then [ W. RefFunc f ]
1087
- else
1088
- let code_pointers =
1089
- if arity = 1 then [ W. RefFunc f ] else [ RefFunc curry_fun; RefFunc f ]
1090
- in
1091
- if include_closure_arity
1092
- then Const (I32 (Int32. of_int arity)) :: code_pointers
1093
- else code_pointers ))
1077
+ , match arity with
1078
+ | 0 | 1 -> [ W. RefFunc f ]
1079
+ | _ -> [ RefFunc curry_fun; RefFunc f ] ))
1094
1080
in
1095
1081
return (W. GlobalGet name)
1096
1082
else
@@ -1111,17 +1097,9 @@ module Closure = struct
1111
1097
return
1112
1098
(W. StructNew
1113
1099
( typ
1114
- , (if arity = 0
1115
- then [ W. RefFunc f ]
1116
- else
1117
- let code_pointers =
1118
- if arity = 1
1119
- then [ W. RefFunc f ]
1120
- else [ RefFunc curry_fun; RefFunc f ]
1121
- in
1122
- if include_closure_arity
1123
- then W. Const (I32 (Int32. of_int arity)) :: code_pointers
1124
- else code_pointers)
1100
+ , (match arity with
1101
+ | 0 | 1 -> [ W. RefFunc f ]
1102
+ | _ -> [ RefFunc curry_fun; RefFunc f ])
1125
1103
@ l ))
1126
1104
| (g , _ ) :: _ as functions ->
1127
1105
let function_count = List. length functions in
@@ -1154,14 +1132,9 @@ module Closure = struct
1154
1132
return
1155
1133
(W. StructNew
1156
1134
( typ
1157
- , (let code_pointers =
1158
- if arity = 1
1159
- then [ W. RefFunc f ]
1160
- else [ RefFunc curry_fun; RefFunc f ]
1161
- in
1162
- if include_closure_arity
1163
- then W. Const (I32 (Int32. of_int arity)) :: code_pointers
1164
- else code_pointers)
1135
+ , (if arity = 1
1136
+ then [ W. RefFunc f ]
1137
+ else [ RefFunc curry_fun; RefFunc f ])
1165
1138
@ [ env ] ))
1166
1139
in
1167
1140
if is_last_fun functions f
@@ -1247,13 +1220,7 @@ module Closure = struct
1247
1220
in
1248
1221
let * closure = Memory. wasm_cast cl_ty (load closure) in
1249
1222
let * arg = load arg in
1250
- let closure_contents = [ W. RefFunc f; closure; arg ] in
1251
- return
1252
- (W. StructNew
1253
- ( ty
1254
- , if include_closure_arity
1255
- then Const (I32 1l ) :: closure_contents
1256
- else closure_contents ))
1223
+ return (W. StructNew (ty, [ W. RefFunc f; closure; arg ]))
1257
1224
1258
1225
let curry_load ~cps ~arity m closure =
1259
1226
let m = m + 1 in
@@ -1283,12 +1250,7 @@ module Closure = struct
1283
1250
then [ W. RefFunc dummy_fun; RefNull (Type cl_typ) ]
1284
1251
else [ RefFunc curry_fun; RefFunc dummy_fun; RefNull (Type cl_typ) ]
1285
1252
in
1286
- return
1287
- (W. StructNew
1288
- ( ty
1289
- , if include_closure_arity
1290
- then Const (I32 1l ) :: closure_contents
1291
- else closure_contents ))
1253
+ return (W. StructNew (ty, closure_contents))
1292
1254
end
1293
1255
1294
1256
module Math = struct
0 commit comments