Skip to content

Commit

Permalink
Remove remaining tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
chambart committed Oct 17, 2024
1 parent d682661 commit d2f6bcf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
1 change: 0 additions & 1 deletion wasm/emit_wat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,6 @@ module ToWasm = struct
body
in
let _, typs = List.split body in
let exprs = [ C.tuple_make exprs ] in
(exprs, List.map C.result typs)
end
| No_value body -> (conv_no_value body, [])
Expand Down
19 changes: 3 additions & 16 deletions wasm/wat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,22 +243,14 @@ module C = struct
let declare_func f =
node "elem" [ atom "declare"; atom "func"; !$(Func_id.name f) ]

let rec type_atom (t : Type.atom) =
let type_atom (t : Type.atom) =
match t with
| I8 -> atom "i8"
| I16 -> atom "i16"
| I32 -> atom "i32"
| I64 -> atom "i64"
| F64 -> atom "f64"
| Rvar v -> reft v
| Tuple l -> node "tuple" (List.map type_atom l)

let tuple_make fields =
match fields with
| [] -> assert false
| [ field ] -> field
| fields ->
node "tuple.make" (Atom (List.length fields |> string_of_int) :: fields )

let local l t = node "local" [ !$(Expr.Local.var_name l); type_atom t ]

Expand Down Expand Up @@ -317,15 +309,12 @@ module C = struct
nodehv "loop" [ !$(Block_id.name id); results result ] body

let br id args =
match args with
| [] -> node "br" [ !$(Block_id.name id)]
| [arg] -> node "br" [ !$(Block_id.name id); arg ]
| _ -> node "br" [ !$(Block_id.name id); tuple_make args ]
node "br" ((!$(Block_id.name id)) :: args)

let br' id = node "br" [ !$(Block_id.name id) ]

let return args =
node "return" [ tuple_make args ]
node "return" args

let br_on_cast id typ arg =
node "br_on_cast" [ !$(Block_id.name id); type_name typ; arg ]
Expand Down Expand Up @@ -357,8 +346,6 @@ module C = struct
| None -> node "sub" [ descr ]
| Some name -> node "sub" [ type_name name; descr ]

let opt_tuple fields =
[ tuple_make fields ]

let rec_ l = node "rec" l

Expand Down
16 changes: 8 additions & 8 deletions wasm/wexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,20 @@ let required_locals body =
acc
| exception Not_found -> Local.Map.add var typ acc
in
let let_cont_reqs acc ~cont ~params =
let let_cont_reqs acc ~cont:_ ~params =
let acc =
List.fold_left
(fun acc (var, typ) ->
match var with None -> acc | Some var -> add var typ acc )
acc params
in
let acc =
match ( params) with
| _ :: _ :: _ ->
let var = Local.Block_result cont in
add var (Type.Tuple (List.map snd params)) acc
| _ -> acc
in
(* let acc = *)
(* match ( params) with *)
(* | _ :: _ :: _ -> *)
(* let var = Local.Block_result cont in *)
(* add var (Type.Tuple (List.map snd params)) acc *)
(* | _ -> acc *)
(* in *)
acc
in
let rec loop acc = function
Expand Down
4 changes: 1 addition & 3 deletions wasm/wtype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ type atom =
| I64
| F64
| Rvar of Var.t
| Tuple of atom list

type descr =
| Struct of
Expand All @@ -108,11 +107,10 @@ type descr =
; results : atom list
}

let rec print_atom ppf = function
let print_atom ppf = function
| I8 -> Format.fprintf ppf "i8"
| I16 -> Format.fprintf ppf "i16"
| I32 -> Format.fprintf ppf "i32"
| I64 -> Format.fprintf ppf "i64"
| F64 -> Format.fprintf ppf "f64"
| Rvar v -> Format.fprintf ppf "ref_%a" Var.print v
| Tuple l -> Format.fprintf ppf "Tuple (%a)" (print_list print_atom " ") l

0 comments on commit d2f6bcf

Please sign in to comment.