From ef06f921f3fb7eac60828d54cbd3a9f0d59e92d2 Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Fri, 19 Jan 2024 14:58:20 -0600 Subject: Working diagramming. --- discocaml/draw_tree.ml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'discocaml/draw_tree.ml') diff --git a/discocaml/draw_tree.ml b/discocaml/draw_tree.ml index 30c466f..fe3f037 100644 --- a/discocaml/draw_tree.ml +++ b/discocaml/draw_tree.ml @@ -4,13 +4,15 @@ module IntSet = Set.Make (Int) let add_node (fmt : Format.formatter) (i : expr index) (expr : expr) : unit = let label = match expr with - | App _ -> "$" - | Int n -> string_of_int n - | Lam (x, _) -> "λ " ^ x ^ " →" - | Prim (`Add, _) -> "+" - | Var n -> n + | App _ -> "\"$\"" + | Int n -> Format.sprintf "\"%d\"" n + | Lam (_, _) -> "\"λ\"" + | Prim (`Add, _) -> "\"+\"" + | Prim (`Sub, _) -> "\"-\"" + | Prim (`Mul, _) -> "\"*\"" + | Var n -> Format.sprintf "%S" n in - Format.fprintf fmt " expr%d [label=%S];\n" i.index label + Format.fprintf fmt " expr%d [label=%s];\n" i.index label let add_expr_edges (ast : 'a ast) (fmt : Format.formatter) (nodes : IntSet.t ref) : expr index -> unit = @@ -25,7 +27,10 @@ let add_expr_edges (ast : 'a ast) (fmt : Format.formatter) edge_to f; edge_to x | Int _ -> () - | Lam (_, b) -> edge_to b + | Lam (x, b) -> + Format.fprintf fmt " expr%d -> expr%d_var;\n" i.index i.index; + Format.fprintf fmt " expr%d_var [label=%S];\n" i.index x; + edge_to b | Prim (_, xs) -> Array.iter edge_to xs | Var _ -> () in -- cgit v1.2.3