From 1e9c3955bf2c17206c6dd536ebaf96a7e6f4f22d Mon Sep 17 00:00:00 2001 From: William Carroll Date: Mon, 24 Oct 2022 17:51:48 -0400 Subject: refactor(wpcarro/compiler): Modularize debug fns Define `debug.ml` and `prettify.ml` to clean-up some code. Change-Id: Iee2e1ed666f2ccb5e56cc50054ca85b8ba513f3b Reviewed-on: https://cl.tvl.fyi/c/depot/+/7078 Tested-by: BuildkiteCI Reviewed-by: wpcarro --- users/wpcarro/scratch/compiler/type_parser.ml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'users/wpcarro/scratch/compiler/type_parser.ml') diff --git a/users/wpcarro/scratch/compiler/type_parser.ml b/users/wpcarro/scratch/compiler/type_parser.ml index 9b6c0a3093..a11dcdba2b 100644 --- a/users/wpcarro/scratch/compiler/type_parser.ml +++ b/users/wpcarro/scratch/compiler/type_parser.ml @@ -12,6 +12,7 @@ ******************************************************************************) open Types +open Prettify open Parser open Inference @@ -20,10 +21,7 @@ type side = LHS | RHS let ( let* ) = Option.bind let printsub (s : substitution) = - FromString.fold (fun k v acc -> Printf.sprintf "%s\"%s\" |-> %s;" acc k (pretty v)) s "" - |> Printf.sprintf "Sub { %s }" - |> print_string - |> print_newline + s |> Debug.substitution |> print_string |> print_newline let to_array (q : 'a Queue.t) : 'a array = let result = Array.make (Queue.length q) "" in @@ -80,7 +78,7 @@ let print_tokens (xs : string array) = |> print_string |> print_newline let print_type (t : _type) = - t |> pretty |> Printf.sprintf "type: %s" |> print_string |> print_newline + t |> Debug.type' |> Printf.sprintf "type: %s" |> print_string |> print_newline let parse_input (x : string) : _type option = let tokens = tokenize x in @@ -109,7 +107,7 @@ let main = let rhs = read_type RHS in match unify lhs rhs with | None -> - Printf.printf "Cannot unify \"%s\" with \"%s\"\n" (pretty lhs) (pretty rhs) + Printf.printf "Cannot unify \"%s\" with \"%s\"\n" (Debug.type' lhs) (Debug.type' rhs) | Some x -> printsub x end done -- cgit 1.4.1