From a48c45ad54bf049b4a9f2bd913760ee4a470e52e Mon Sep 17 00:00:00 2001 From: Pollux <paul.fournier37@hotmail.fr> Date: Wed, 2 Dec 2020 15:16:04 +0100 Subject: [PATCH] fix : missing function --- ast.ml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ast.ml b/ast.ml index bd6f590..43364a6 100644 --- a/ast.ml +++ b/ast.ml @@ -58,16 +58,22 @@ and program = decl list let rec simplify = function | Ecst(Ccar c) -> Ecst(Cstring (String.make 1 c)) -| Eunop(Unot(Ecst(Cbool(b)))) -> Ecst(Cbool(not b)) -| Eunop(Uneg(Ecst(Cint(n)))) -> Ecst(Cint(-n)) +| Eunop(Unot,Ecst(Cbool(b))) -> Ecst(Cbool(not b)) +| Eunop(Uneg,Ecst(Cint(n))) -> Ecst(Cint(-n)) | Eseq([]) -> Ecst(Cnothing) | Eseq([x]) -> simplify x -| Eseq(h::t) as e -> - let x = -| Ebinop(Beq,Ecst(c1,c2)) -> Ecst(Cbool(c1=c2)) -| Ebinop(Bneq, Ecst(c1,c2)) -> Ecst(Cbool(c1<>c2)) -| Ebinop(Blt, Ecst(Cint(n1),Cint(n2))) -> Ecst(Cbool(n1<n2)) -| Ebinop(Ble, Ecst(Cint(n1),Cint(n2))) -> Ecst(Cbool(n1<=n2)) +| Eseq(h::t) -> +begin + let x = simplify (Eseq(t)) in + let h' = simplify h in + match x with + | Eseq(t') -> Eseq(h'::t') + | _ -> simplify (Eseq(h'::[x])) +end +| Ebinop(Beq,Ecst(c1),Ecst(c2)) -> Ecst(Cbool(c1=c2)) +| Ebinop(Bneq, Ecst(c1),Ecst(c2)) -> Ecst(Cbool(c1<>c2)) +| Ebinop(Blt, Ecst(Cint(n1)),Ecst(Cint(n2))) -> Ecst(Cbool(n1<n2)) +| Ebinop(Ble, Ecst(Cint(n1)),Ecst(Cint(n2))) -> Ecst(Cbool(n1<=n2)) | Ebinop(Bgt, x,y) -> simplify (Ebinop(Blt, y,x)) | Ebinop(Bge, x,y) -> simplify (Ebinop(Ble, y,x)) | Ebinop(Band, Ecst(Cbool(b1)),Ecst(Cbool(b2))) -> Ecst(Cbool(b1 && b2)) @@ -82,7 +88,7 @@ let rec simplify = function if x <> e' then simplify x else x -| Ecall(id, e) -> Ecall(id, simplify e) +| Ecall(id, e) -> Ecall(id, List.map simplify e) | Estruct(e,id) -> Estruct(simplify e, id) | Eif(e1,e2,e3) -> Eif(simplify e1, simplify e2, simplify e3) | Ewhile(e1, e2) -> Ewhile(simplify e1, simplify e2) -- GitLab