diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-01-19 19:37:08 -0600 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-01-19 19:37:08 -0600 |
commit | a84e462b596c24d2562d766ceb019761085390c5 (patch) | |
tree | 51a87e24426a5ad9d94bab104e21d3d3ecbbb9f1 /discocaml/draw_tree.ml | |
parent | 401bc1c5485e26329598d59a140e51f70f58857c (diff) |
Use GADTs for prims, actual redex finding.
Diffstat (limited to 'discocaml/draw_tree.ml')
-rw-r--r-- | discocaml/draw_tree.ml | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/discocaml/draw_tree.ml b/discocaml/draw_tree.ml index 6ea4ff2..e04a59c 100644 --- a/discocaml/draw_tree.ml +++ b/discocaml/draw_tree.ml @@ -9,9 +9,9 @@ let add_node (fmt : Format.formatter) (i : expr index) (expr : expr) : unit = i.index | Int n -> Format.fprintf fmt " expr%d [label=\"%d\"];\n" i.index n | Lam (_, _) -> Format.fprintf fmt " expr%d [label=\"λ\"];\n" i.index - | Prim (`Add, _) -> Format.fprintf fmt " expr%d [label=\"+\"];\n" i.index - | Prim (`Sub, _) -> Format.fprintf fmt " expr%d [label=\"-\"];\n" i.index - | Prim (`Mul, _) -> Format.fprintf fmt " expr%d [label=\"*\"];\n" i.index + | Prim (Add, _) -> Format.fprintf fmt " expr%d [label=\"+\"];\n" i.index + | Prim (Sub, _) -> Format.fprintf fmt " expr%d [label=\"-\"];\n" i.index + | Prim (Mul, _) -> Format.fprintf fmt " expr%d [label=\"*\"];\n" i.index | Var n -> Format.fprintf fmt " expr%d [label=%S];\n" i.index n let add_expr_edges (ast : 'a ast) (fmt : Format.formatter) @@ -31,7 +31,15 @@ let add_expr_edges (ast : 'a ast) (fmt : Format.formatter) 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 + | Prim (Add, (l, r)) -> + edge_to l; + edge_to r + | Prim (Sub, (l, r)) -> + edge_to l; + edge_to r + | Prim (Mul, (l, r)) -> + edge_to l; + edge_to r | Var _ -> () in loop |