Skip to content

Commit 7d06148

Browse files
committed
WIP
1 parent 9b4cc9e commit 7d06148

File tree

1 file changed

+52
-51
lines changed

1 file changed

+52
-51
lines changed

compiler/lib-wasm/generate.ml

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -792,57 +792,51 @@ module Generate (Target : Target_sig.S) = struct
792792
let rec loop acc l =
793793
match l with
794794
| [] -> (
795-
let* b = is_closure f in
796-
if b
797-
then
798-
let* closure = load f in
799-
return (W.Call (f, List.rev (closure :: acc)))
800-
else
801-
match
802-
if exact
803-
then Global_flow.get_unique_closure ctx.global_flow_info f
804-
else None
805-
with
806-
| Some g ->
807-
let* closure = load f in
808-
let* cl =
809-
(* Functions with constant closures ignore their
795+
match
796+
if exact
797+
then Global_flow.get_unique_closure ctx.global_flow_info f
798+
else None
799+
with
800+
| Some g ->
801+
let* closure = load f in
802+
let* cl =
803+
(* Functions with constant closures ignore their
810804
environment. *)
811-
match closure with
812-
| GlobalGet _ -> Value.unit
813-
| _ -> return closure
814-
in
815-
let params =
816-
match ctx.global_flow_info.info_defs.(Var.idx g) with
817-
| Expr (Closure (params, _, _)) -> params
818-
| _ -> assert false
819-
in
820-
let* args =
821-
expression_list
822-
Fun.id
823-
(List.map2
824-
~f:(fun a p ->
825-
convert
826-
~from:(get_var_type ctx a)
827-
~into:(get_var_type ctx p)
828-
(load a))
829-
args
830-
params)
831-
in
832-
return (W.Call (g, List.rev (cl :: List.rev args)))
833-
| None -> (
834-
let arity = List.length args in
835-
let funct = Var.fresh () in
836-
let* closure = tee funct (load f) in
837-
let* ty, funct =
838-
Memory.load_function_pointer
839-
~cps:(Var.Set.mem x ctx.in_cps)
840-
~arity
841-
(load funct)
842-
in
843-
match funct with
844-
| W.RefFunc g -> return (W.Call (g, List.rev (closure :: acc)))
845-
| _ -> return (W.Call_ref (ty, funct, List.rev (closure :: acc)))))
805+
match closure with
806+
| GlobalGet _ -> Value.unit
807+
| _ -> return closure
808+
in
809+
let params =
810+
match ctx.global_flow_info.info_defs.(Var.idx g) with
811+
| Expr (Closure (params, _, _)) -> params
812+
| _ -> assert false
813+
in
814+
let* args =
815+
expression_list
816+
Fun.id
817+
(List.map2
818+
~f:(fun a p ->
819+
convert
820+
~from:(get_var_type ctx a)
821+
~into:(get_var_type ctx p)
822+
(load a))
823+
args
824+
params)
825+
in
826+
return (W.Call (g, List.rev (cl :: List.rev args)))
827+
| None -> (
828+
let arity = List.length args in
829+
let funct = Var.fresh () in
830+
let* closure = tee funct (load f) in
831+
let* ty, funct =
832+
Memory.load_function_pointer
833+
~cps:(Var.Set.mem x ctx.in_cps)
834+
~arity
835+
(load funct)
836+
in
837+
match funct with
838+
| W.RefFunc g -> return (W.Call (g, List.rev (closure :: acc)))
839+
| _ -> return (W.Call_ref (ty, funct, List.rev (closure :: acc)))))
846840
| x :: r ->
847841
let* x = load_and_box ctx x in
848842
loop (x :: acc) r
@@ -1286,7 +1280,14 @@ module Generate (Target : Target_sig.S) = struct
12861280
List.fold_left
12871281
~f:(fun l x ->
12881282
let* _ = l in
1289-
let* _ = add_var x in
1283+
let* _ =
1284+
add_var
1285+
?typ:
1286+
(match get_var_type ctx x with
1287+
| Typing.Int (Normalized | Unnormalized) -> Some I32
1288+
| _ -> None)
1289+
x
1290+
in
12901291
return ())
12911292
~init:(return ())
12921293
params

0 commit comments

Comments
 (0)