From e82d95de4c9dee8747c1b3a20baba8a19df7518d Mon Sep 17 00:00:00 2001 From: Erwan Jahier <jahier@imag.fr> Date: Fri, 29 Aug 2008 17:37:26 +0200 Subject: [PATCH] Also split tulpes on equations generated by the splitting of expressions. --- src/split.ml | 41 ++++++++++++++++++++++++----------------- src/test/test.res.exp | 24 ++++++++++++++++-------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/split.ml b/src/split.ml index 4d2d1c21..99677616 100644 --- a/src/split.ml +++ b/src/split.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 29/08/2008 (at 16:59) by Erwan Jahier> *) +(** Time-stamp: <modified the 29/08/2008 (at 17:37) by Erwan Jahier> *) open Lxm @@ -79,6 +79,26 @@ let (break_it : val_exp -> val_exp list) = | _ -> assert false + +let (split_tuples:Eff.eq_info Lxm.srcflagged list -> Eff.eq_info Lxm.srcflagged list) = + fun eql -> + let split_one_eq eq = + let { src = lxm_eq ; it = (lhs, n_rhs) } = eq in + if List.length lhs > 1 && (to_be_broken n_rhs) then + let vel = break_it n_rhs in + let eqs = + try List.map2 (fun lhs ve -> [lhs], ve) lhs vel + with _ -> + assert false + in + let eqs = List.map (fun eq -> Lxm.flagit eq lxm_eq) eqs in + eqs + else + [eq] + + in + List.flatten (List.map split_one_eq eql) + (********************************************************************************) (* The functions below accumulate (1) the new equations @@ -89,26 +109,13 @@ type split_acc = (Eff.eq_info srcflagged) list * Eff.var_info list let rec (split_eq : split_acc -> Eff.eq_info srcflagged -> split_acc) = fun (eqs, locs) eq -> let (neqs, nlocs) = split_eq_do eq in - (eqs@neqs, locs@nlocs) + (split_tuples (eqs@neqs), locs@nlocs) + and (split_eq_do : Eff.eq_info Lxm.srcflagged -> split_acc) = fun { src = lxm_eq ; it = (lhs, rhs) } -> let n_rhs, (neqs, nlocs) = split_val_exp true rhs in - let res1 = { src = lxm_eq ; it = (lhs, n_rhs) }::neqs, nlocs in - - if List.length lhs > 1 && (to_be_broken n_rhs) then - (* We also want to split tuples *) - let vel = break_it n_rhs in - let eqs = - try List.map2 (fun lhs ve -> [lhs], ve) lhs vel - with _ -> - assert false - in - let eqs = List.map (fun eq -> Lxm.flagit eq lxm_eq) eqs in - eqs@neqs, nlocs - - else - res1 + { src = lxm_eq ; it = (lhs, n_rhs) }::neqs, nlocs and (split_val_exp : bool -> Eff.val_exp -> Eff.val_exp * split_acc) = fun top_level ve -> diff --git a/src/test/test.res.exp b/src/test/test.res.exp index 01db80a4..03365949 100644 --- a/src/test/test.res.exp +++ b/src/test/test.res.exp @@ -665,7 +665,8 @@ let _v3 = _v2 = scale; _v4 = pre n; _v5 = _v4 + 1; - (_v6, _v7) = if _v3 then 0, true else _v5, false; + _v6 = if _v3 then 0 else _v5; + _v7 = if _v3 then true else false; tel -- end of node Watch::DIVIDE @@ -748,8 +749,9 @@ let _v5 = Watch::WATCH_TIME_TO_MINI_DISPLAY(watch_time); _v6 = Watch::ALARM_TIME_TO_MAIN_DISPLAY(alarm_time); _v7 = Watch::WATCH_TIME_TO_MINI_DISPLAY(watch_time); - (_v8, _v9, _v10) = if mode_is_stopwatch then _v4, _v5, Watch::stringST - else _v6, _v7, Watch::stringAL; + _v8 = if mode_is_stopwatch then _v4 else _v6; + _v9 = if mode_is_stopwatch then _v5 else _v7; + _v10 = if mode_is_stopwatch then Watch::stringST else Watch::stringAL; tel -- end of node Watch::DISPLAY extern function Watch::SOMME(i1:int; i2:int; i3:int) returns (somme:int); @@ -1333,9 +1335,12 @@ let _v3 = pre deadline; _v4 = _v3 + 1; _v5 = pre deadline; - (_v6, _v7) = if _v1 then _v2, _v4 else false, _v5; - (_v8, _v9) = if evt then true, 0 else _v6, _v7; - (_v10, _v11) = false, delay -> _v8, _v9; + _v6 = if _v1 then _v2 else false; + _v7 = if _v1 then _v4 else _v5; + _v8 = if evt then true else _v6; + _v9 = if evt then 0 else _v7; + _v10 = false -> _v8; + _v11 = delay -> _v9; tel -- end of node Watch::MORE_RECENT @@ -2059,7 +2064,8 @@ let c = if _v1 then _v2 else _v5; d = if _v1 then _v3 else _v7; _v1 = a > 0; - (_v2, _v3) = pre a, b; + _v2 = pre a; + _v3 = pre b; _v4 = pre a; _v5 = _v4 + 1; _v6 = pre b; @@ -14786,7 +14792,9 @@ let c4 = true -> _v1; c5 = false -> _v2; c6 = true -> _v3; - (_v1, _v2, _v3) = if c1 then c1, c2, c3 else c1, c2, c3; + _v1 = if c1 then c1 else c1; + _v2 = if c1 then c2 else c2; + _v3 = if c1 then c3 else c3; tel -- end of node test::three_outputs node test::two_outputs(c1:bool; c2:bool) returns (c4:bool; c5:bool); -- GitLab