From 1e6f3fb7d8ac8e72ca38f08d7e4be5c835e3443a Mon Sep 17 00:00:00 2001 From: Son Ho Date: Tue, 8 Feb 2022 17:51:04 +0100 Subject: Make progress on implementing support for types and functions like Option and Vec --- src/PrintPure.ml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/PrintPure.ml') diff --git a/src/PrintPure.ml b/src/PrintPure.ml index 5c25f2bd..f0e5df77 100644 --- a/src/PrintPure.ml +++ b/src/PrintPure.ml @@ -265,7 +265,23 @@ let adt_g_value_to_string (fmt : value_formatter) else if variant_id = result_fail_id then ( assert (field_values = []); "@Result::Fail") - else failwith "Unreachable: improper variant id for result type") + else failwith "Unreachable: improper variant id for result type" + | Option -> + let variant_id = Option.get variant_id in + if variant_id = option_some_id then + match field_values with + | [ v ] -> "@Option::Some " ^ v + | _ -> failwith "Option::Some takes exactly one value" + else if variant_id = option_none_id then ( + assert (field_values = []); + "@Option::None") + else failwith "Unreachable: improper variant id for result type" + | Vec -> + assert (variant_id = None); + let field_values = + List.mapi (fun i v -> string_of_int i ^ " -> " ^ v) field_values + in + "Vec [" ^ String.concat "; " field_values ^ "]") | _ -> failwith "Inconsistent typed value" let rec typed_lvalue_to_string (fmt : value_formatter) (v : typed_lvalue) : -- cgit v1.2.3