Skip to content

Commit

Permalink
improve GC types printing
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Jul 30, 2023
1 parent e4aced1 commit 3d2b22a
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,29 @@ struct
| No_extern_ht -> Format.fprintf fmt "noextern"
| Def_ht i -> Format.fprintf fmt "%a" indice i

let heap_type_short fmt = function
| Any_ht -> Format.fprintf fmt "anyref"
| None_ht -> Format.fprintf fmt "(ref none)"
| Eq_ht -> Format.fprintf fmt "eqref"
| I31_ht -> Format.fprintf fmt "i31ref"
| Struct_ht -> Format.fprintf fmt "(ref struct)"
| Array_ht -> Format.fprintf fmt "(ref array)"
| Func_ht -> Format.fprintf fmt "funcref"
| No_func_ht -> Format.fprintf fmt "nofunc"
| Extern_ht -> Format.fprintf fmt "externref"
| No_extern_ht -> Format.fprintf fmt "(ref noextern)"
| Def_ht i -> Format.fprintf fmt "(ref %a)" indice i

let null fmt = function
| No_null ->
(* TODO: no notation to enforce nonnull ? *)
Format.fprintf fmt ""
| Null -> Format.fprintf fmt "null"

let ref_type fmt (n, ht) =
Format.fprintf fmt "(ref %a %a)" null n heap_type ht
match n with
| No_null -> Format.fprintf fmt "%a" heap_type_short ht
| Null -> Format.fprintf fmt "(ref null %a)" heap_type ht

let val_type fmt = function
| Num_type t -> num_type fmt t
Expand Down Expand Up @@ -781,12 +796,15 @@ struct
Format.fprintf fmt "@\n @[<v>(type %a %a)@]" id_opt id sub_type t

let typ fmt l =
(* TODO: special case for empty and singleton case to avoid a big rec printing *)
Format.fprintf fmt "(rec %a)"
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt " ")
type_def )
l
match l with
| [] -> ()
| [ t ] -> type_def fmt t
| l ->
Format.fprintf fmt "(rec %a)"
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt " ")
type_def )
l

module Pp_const = struct
let ibinop fmt : Const.ibinop -> Unit.t = function
Expand Down

0 comments on commit 3d2b22a

Please sign in to comment.