aboutsummaryrefslogtreecommitdiff
path: root/discocaml/draw_tree.ml
diff options
context:
space:
mode:
Diffstat (limited to 'discocaml/draw_tree.ml')
-rw-r--r--discocaml/draw_tree.ml19
1 files changed, 12 insertions, 7 deletions
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