Commit d3160a97 authored by POTTIER Francois's avatar POTTIER Francois

One more test.

parent ae2761db
...@@ -5,6 +5,7 @@ expr00fold ...@@ -5,6 +5,7 @@ expr00fold
expr00fold2 expr00fold2
expr01 expr01
expr01use expr01use
expr01use_variant
expr02 expr02
expr03 expr03
expr04 expr04
......
...@@ -22,3 +22,4 @@ let () = ...@@ -22,3 +22,4 @@ let () =
assert (optimize (z (EConst 1)) = EConst 1); assert (optimize (z (EConst 1)) = EConst 1);
assert (optimize (z (z (EConst 1))) = EConst 1); assert (optimize (z (z (EConst 1))) = EConst 1);
assert (optimize (EAdd (EConst 1, EConst 1)) = EAdd (EConst 1, EConst 1)); assert (optimize (EAdd (EConst 1, EConst 1)) = EAdd (EConst 1, EConst 1));
assert (optimize (EAdd (z (EConst 1), EConst 1)) = EAdd (EConst 1, EConst 1));
open Expr01
let optimize : expr -> expr =
let o = object(self)
inherit [_] map
method! visit_EAdd env e1 e2 =
match self#visit_expr env e1, self#visit_expr env e2 with
| EConst 0, e
| e, EConst 0 -> e
| e1, e2 -> EAdd (e1, e2)
end in
o # visit_expr ()
let z e = EAdd (e, EConst 0)
let () =
assert (optimize (z (EConst 1)) = EConst 1);
assert (optimize (z (z (EConst 1))) = EConst 1);
assert (optimize (EAdd (EConst 1, EConst 1)) = EAdd (EConst 1, EConst 1));
assert (optimize (EAdd (z (EConst 1), EConst 1)) = EAdd (EConst 1, EConst 1));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment