Commit 38651b5d authored by Erwan Jahier's avatar Erwan Jahier
Browse files

Add a loop <int> construct (for looping exactly n times).

i.e., loop 42 is equivalent to loop [42,42]
parent d680e133
......@@ -28,7 +28,7 @@ assert abs(T-T1) < 0.5 in
assert abs(T-T2) < 0.5 in
assert abs(T-T3) < 0.5 in
loop [2, 2] -- R1: j'aimerais bien ecrire Loop 2 en fait...
loop 2
{
(6.0 < T) and (T < 9.0)
}
......
......@@ -126,6 +126,10 @@ printf "check_exp\n";
let tel = rec_list_call [e1] in
match_type_profile tel CkTypeEff.prof_t_t e.src
)
| LOOPE_n (n, e1) -> (
let tel = rec_list_call [n;e1] in
match_type_profile tel CkTypeEff.prof_it_t e.src
)
| LOOPI_n (min, max, e1) -> (
let tel = rec_list_call [min;max;e1] in
match_type_profile tel CkTypeEff.prof_iit_t e.src
......
......@@ -78,6 +78,7 @@ let of_choice lst = TE_choice lst
let of_prio lst = TE_prio lst
let of_para lst = TE_para lst
let of_loope nb e = (TE_loopi (new_loop_cpt (), nb,nb,e))
let of_loopi min max e = (TE_loopi (new_loop_cpt (), min,max,e))
let of_loopa moy ect e = (TE_loopa (new_loop_cpt (), moy,ect,e))
......
......@@ -58,6 +58,8 @@ val of_ref : CoIdent.t -> t
val of_loop : t -> t
val of_loope : CoAlgExp.t -> t -> t
val of_loopi : CoAlgExp.t -> CoAlgExp.t -> t -> t
val of_loopa : CoAlgExp.t -> CoAlgExp.t option -> t -> t
......
......@@ -1084,6 +1084,7 @@ and
| PARA_n _
| LOOP_n _
| LOOPI_n _
| LOOPE_n _
| LOOPA_n _
| RAISE_n _
| TRY_n _
......@@ -1254,14 +1255,23 @@ and
let arg = treat_trace env sstack ee in
CoTraceExp.of_loop arg
)
| LOOPE_n (en,ee) -> (
let nres = treat_exp env sstack en in
let eres = treat_trace env sstack ee in
if (CoAlgExp.is_controlable nres) then (
raise (Compile_error (en.src, "loop params should not be controllable"))
) else (
CoTraceExp.of_loope nres eres
)
)
| LOOPI_n (emin,emax,ee) -> (
let minres = treat_exp env sstack emin in
let maxres = treat_exp env sstack emax in
let eres = treat_trace env sstack ee in
if (CoAlgExp.is_controlable minres) then (
raise ( Compile_error (emin.src, "loop params sould not be controllable"))
raise (Compile_error (emin.src, "loop params should not be controllable"))
) else if (CoAlgExp.is_controlable maxres) then (
raise ( Compile_error (emax.src, "loop params sould not be controllable"))
raise (Compile_error (emax.src, "loop params should not be controllable"))
) else (
CoTraceExp.of_loopi minres maxres eres
)
......@@ -1271,9 +1281,9 @@ and
let ectres = treat_exp env sstack eect in
let eres = treat_trace env sstack ee in
if (CoAlgExp.is_controlable moyres) then (
raise ( Compile_error (emoy.src, "loop params sould not be controllable"))
raise (Compile_error (emoy.src, "loop params should not be controllable"))
) else if (CoAlgExp.is_controlable ectres) then (
raise ( Compile_error (eect.src, "loop params sould not be controllable"))
raise (Compile_error (eect.src, "loop params should not be controllable"))
) else (
CoTraceExp.of_loopa moyres (Some ectres) eres
)
......
......@@ -571,12 +571,19 @@ lutDoPart :
lutLoopExp:
TK_LOOP lutTraceExp
{ make_val_exp (LOOP_n $2) $1 }
| TK_LOOP lutExact lutTraceExp
{ make_val_exp (LOOPE_n ($2, $3)) $1 }
| TK_LOOP lutAverage lutTraceExp
{ make_val_exp (LOOPI_n (fst $2, snd $2, $3)) $1 }
| TK_LOOP lutGaussian lutTraceExp
{ make_val_exp (LOOPA_n (fst $2, snd $2, $3)) $1 }
;
lutExact:
lutExp
{ ($1) }
;
lutAverage:
TK_OPEN_BRACKET lutExp TK_COMA lutExp TK_CLOSE_BRACKET
{ ($2, $4) }
......
......@@ -99,6 +99,7 @@ and val_exp_node =
| CHOICE_n of (val_exp * val_exp srcflaged option) list
| PRIO_n of val_exp list
| LOOP_n of val_exp
| LOOPE_n of val_exp * val_exp
| LOOPI_n of val_exp * val_exp * val_exp
| LOOPA_n of val_exp * val_exp option * val_exp
| ASSERT_n of val_exp * val_exp
......
......@@ -267,6 +267,11 @@ let _ =
Format.fprintf !os "loop ";
dump_brace_exp e
)
| LOOPE_n (nb,e) -> (
Format.fprintf !os "loop ";
dump_exp nb;
dump_brace_exp e
)
| LOOPI_n (min,max,e) -> (
Format.fprintf !os "loop [";
dump_exp min;
......
Supports Markdown
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