Skip to content

Commit

Permalink
Add support for top-level floatarray printing. (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
yallop authored and nojb committed Aug 16, 2024
1 parent 8148bc4 commit 54bf62f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions testsuite/tests/typing-extensions/floatarray.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ val x : float array = [|1.; 2.|]
let x : floatarray = [|1.; 2.|]
;;
[%%expect {|
val x : floatarray = <abstr>
val x : floatarray = [|1.; 2.|]
|}]

let x = ([|1.; 2.|] : floatarray)
;;
[%%expect {|
val x : floatarray = <abstr>
val x : floatarray = [|1.; 2.|]
|}]

let f (a : floatarray) = match a with [|x|] -> x | _ -> assert false
Expand Down Expand Up @@ -51,7 +51,7 @@ let x : t = [||]
[%%expect {|
type s = floatarray
type t = s
val x : t = <abstr>
val x : t = [||]
|}]

let f a =
Expand Down
4 changes: 4 additions & 0 deletions toplevel/genprintval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ module Make(O : OBJ)(EVP : EVALPATH with type valu = O.t) = struct
let s = Bytes.to_string (O.obj obj : bytes) in
Oval_string (s, !printer_steps, Ostr_bytes)

| Tconstr(path, [], _)
when Path.same path Predef.path_floatarray ->
Oval_floatarray (O.obj obj : floatarray)

| Tconstr (path, [ty_arg], _)
when Path.same path Predef.path_lazy_t ->
let obj_tag = O.tag obj in
Expand Down
4 changes: 4 additions & 0 deletions typing/oprint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ let print_out_value ppf tree =
| Oval_printer f -> f ppf
| Oval_tuple tree_list ->
fprintf ppf "@[<1>(%a)@]" (print_tree_list print_tree_1 ",") tree_list
| Oval_floatarray arr ->
fprintf ppf "@[<2>[|%a|]@]"
(pp_print_seq ~pp_sep:semicolon pp_print_float)
(Float.Array.to_seq arr)
| tree -> fprintf ppf "@[<1>(%a)@]" (cautious print_tree_1) tree
and print_fields first ppf =
function
Expand Down
1 change: 1 addition & 0 deletions typing/outcometree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type out_value =
| Oval_tuple of out_value list
| Oval_variant of string * out_value option
| Oval_lazy of out_value
| Oval_floatarray of floatarray

type out_type_param = {
ot_non_gen: bool;
Expand Down
1 change: 1 addition & 0 deletions utils/format_doc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ let pp_print_either ~left ~right ppf e =
ppf := Doc.either ~left:(doc_printer left) ~right:(doc_printer right) e !ppf

let comma ppf () = fprintf ppf ",@ "
let semicolon ppf () = fprintf ppf ";@ "

let pp_two_columns ?(sep = "|") ?max_lines ppf (lines: (string * string) list) =
let left_column_size =
Expand Down
1 change: 1 addition & 0 deletions utils/format_doc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ val pp_print_newline: unit printer
(** {2 Separators }*)

val comma: unit printer
val semicolon: unit printer

(** {2 Compiler output} *)

Expand Down

0 comments on commit 54bf62f

Please sign in to comment.