about summary refs log tree commit diff
path: root/users/wpcarro/scratch/compiler/expr_parser.ml
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-10-24T21·51-0400
committerwpcarro <wpcarro@gmail.com>2022-10-25T03·59+0000
commit1e9c3955bf2c17206c6dd536ebaf96a7e6f4f22d (patch)
tree3ad05bbd2f8c6fc7ccfe8e6e507fe386d9957a75 /users/wpcarro/scratch/compiler/expr_parser.ml
parenta8876a4cdaaf0a1f051fefad436e08d983b402e2 (diff)
refactor(wpcarro/compiler): Modularize debug fns r/5195
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 <wpcarro@gmail.com>
Diffstat (limited to 'users/wpcarro/scratch/compiler/expr_parser.ml')
-rw-r--r--users/wpcarro/scratch/compiler/expr_parser.ml27
1 files changed, 4 insertions, 23 deletions
diff --git a/users/wpcarro/scratch/compiler/expr_parser.ml b/users/wpcarro/scratch/compiler/expr_parser.ml
index 7d24efc80de3..04ec1dbe928d 100644
--- a/users/wpcarro/scratch/compiler/expr_parser.ml
+++ b/users/wpcarro/scratch/compiler/expr_parser.ml
@@ -28,6 +28,8 @@
 
 open Parser
 open Inference
+open Debug
+open Prettify
 
 let to_array (q : 'a Queue.t) : 'a array =
   let result = Array.make (Queue.length q) "" in
@@ -149,27 +151,6 @@ let parse_language (x : string) : Types.value option =
   print_tokens tokens;
   parse_expression (new parser tokens)
 
-let rec debug (ast : Types.value) : string =
-  match ast with
-  | ValueLiteral (LiteralBool x) ->
-     Printf.sprintf "ValueLiteral (LiteralBool %s)" (string_of_bool x)
-  | ValueLiteral (LiteralInt x) ->
-     Printf.sprintf "ValueLiteral (LiteralInt %s)" (string_of_int x)
-  | ValueVariable x ->
-     Printf.sprintf "ValueVariable %s" x
-  | ValueFunction (x, body) ->
-     Printf.sprintf "ValueFunction (%s, %s)" x (debug body)
-  | ValueApplication (f, x) ->
-     Printf.sprintf "ValueApplication (%s, %s)" (debug f) (debug x)
-  | ValueVarApplication (f, x) ->
-     Printf.sprintf "ValueVarApplication (%s, %s)" f (debug x)
-  | ValueBinder (k, v, x) ->
-      Printf.sprintf "ValueBinder (%s, %s, %s)" k (debug v) (debug x)
-
-let debug_ast (ast : Types.value) : Types.value =
-  ast |> debug |> Printf.sprintf "ast: %s" |> print_string |> print_newline;
-  ast
-
 let main =
   while true do
     begin
@@ -177,14 +158,14 @@ let main =
       let x = read_line () in
       match parse_language x with
       | Some ast ->
-         (match ast |> debug_ast |> do_infer with
+         (match ast |> Debug.print Debug.ast "ast" |> do_infer with
           | None ->
              "Type-check failed"
              |> print_string
              |> print_newline
           | Some x ->
              x
-             |> Types.pretty
+             |> Prettify.type'
              |> print_string
              |> print_newline)
       | None ->