diff --git a/compiler/main/mls2obc.ml b/compiler/main/mls2obc.ml index 9a97916..77e1c79 100644 --- a/compiler/main/mls2obc.ml +++ b/compiler/main/mls2obc.ml @@ -184,14 +184,10 @@ and translate_act map pat let true_act = Aassgn (x, mk_exp p.pat_ty (Epattern p)) in let false_act = Aassgn (x, translate map e2) in let cond = bound_check_expr idx bounds in - [ Acase (cond, [ ptrue, mk_block [true_act]; - pfalse, mk_block [false_act] ]) ] - + [ Acase (cond, [ ptrue, mk_block [true_act]; pfalse, mk_block [false_act] ]) ] + | Minils.Evarpat x, Minils.Eapp ({ Minils.a_op = Minils.Eupdate }, e1::e2::idx, _) -> + let x = Control.var_from_name map x in (** TODO: remplacer par if 0 < e && e < n then for () ; o[e] = v; for () else o = a *) - | Minils.Evarpat x, - Minils.Eapp ({ Minils.a_op = Minils.Eupdate }, - e1::e2::idx, _) -> - let x = var_from_name map x in let bounds = Mls_utils.bounds_list e1.Minils.e_ty in let idx = List.map (translate map) idx in let action = Aassgn (pattern_of_idx_list x idx, diff --git a/test/async/Wanted_Normalized_movie.java b/test/async/Wanted_Normalized_movie.java new file mode 100644 index 0000000..650ea73 --- /dev/null +++ b/test/async/Wanted_Normalized_movie.java @@ -0,0 +1,106 @@ +package pipline_b; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +public class Wanted_Normalized_movie { + protected final int N;; + protected Async_mean_factory mean_factory;; + protected Substr[] substr_inst;; + protected Future v;; + protected boolean v_2;; + protected int[] v_4;; + protected boolean v_5;; + + + + public Wanted_Normalized_movie (int N) { + this.mean_factory = new Async_mean_factory(N); + this.substr_inst = new Substr[N]; + for (int i_3 = 0; i_3 m = null; + if (this.v_2) { v_3 = 0; } + else { v_3 = this.v.get(); }; + if (this.v_5) { v_6 = i; } + else { v_6 = this.v_4; }; + this.v_5 = false; + trash = v_3; + for (int i_2 = 0; i_2 out = substr_inst[i_2].step(v_6[i_2], trash); + im[i_2] = out.c0; + trash = out.c1; + }; + this.v_2 = false; + m = mean_factory.step(i); + this.v_4 = i; + this.v = m; + return im; + } + + + //params, class, step_result_type, step_args + public class Async_mean_factory { + Mean mean_inst; + int N; + Future result; + + public Async_mean_factory(int N) { + this.N = N; + this.mean_inst = new Mean(N); + } + + public void reset () { + this.mean_inst = new Mean(N); + this.result = null; + } + + public Future step(int[] i) { + if (null != result) // Wait for the last result to be completed, null if nothing to wait for. + try { + result.get(); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (ExecutionException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + result = jeptagon.Pervasives.executor_cached.submit(new Async_mean_step(mean_inst, i)); + return result; + } + + class Async_mean_step implements Callable{ + int[] i; + Mean mean_inst; + public Async_mean_step(Mean mean_inst, int[] i) { + this.i = i; + this.mean_inst = mean_inst; + } + public Integer call () { + return mean_inst.step(i); + } + } + + + + } + + + + public static void main() { + + } + + public void reset () { + this.v_5 = true; + this.v_2 = true; + } +} \ No newline at end of file diff --git a/test/async/java_m b/test/async/java_m new file mode 100755 index 0000000..7c7eae0 --- /dev/null +++ b/test/async/java_m @@ -0,0 +1,6 @@ +#!/bin/bash +cp $1 build/ +cd build +../../../heptc $2 $3 $4 $5 $6 -target java $1 +cd .. + diff --git a/test/async/lent.ept b/test/async/lent.ept new file mode 100644 index 0000000..3b87307 --- /dev/null +++ b/test/async/lent.ept @@ -0,0 +1,12 @@ + +node g () returns (y : int) +let + y = 3 +tel + +node f (x : int; c : bool) returns (z : int) +let + z = merge c (true -> (0 fby (g(z when true(c))))) (false -> 0) +tel + + diff --git a/test/async/obc_m b/test/async/obc_m new file mode 100755 index 0000000..4a00eee --- /dev/null +++ b/test/async/obc_m @@ -0,0 +1,6 @@ +#!/bin/bash +cp $@ build/ +cd build +../../../heptc -target obc $@ +cd .. + diff --git a/test/async/pipline.ept b/test/async/pipline.ept new file mode 100644 index 0000000..240bc51 --- /dev/null +++ b/test/async/pipline.ept @@ -0,0 +1,25 @@ + +fun sum (x,m: int) returns (s: int) +let + s = x + m +tel + +fun substr (x,m: int) returns (d: int; m2:int) +let + d = x - m; + m2 = m; +tel + +fun mean<> (i: int^n) returns (m: int) +let + m = (fold (+) <> (i,0)) /n +tel + + +node normalized_movie<> (i: int^n) returns (im: int^n) +var m: int; trash: int; +let + m = mean<>(i); + (im,trash) = mapfold substr <> (i,m) +tel + diff --git a/test/async/pipline_a.ept b/test/async/pipline_a.ept new file mode 100644 index 0000000..501ad72 --- /dev/null +++ b/test/async/pipline_a.ept @@ -0,0 +1,30 @@ + +fun substr (x,m: int) returns (d: int; m2:int) +let + d = x - m; + m2 = m; +tel + +fun mean<> (i: int^n) returns (m: int) +let + m = (fold (+) <> (i,0) )/n +tel + + +node normalized_movie<> (i: int^n) returns (im: int^n) +var m: async int; trash: int; +let + m = async mean<>(i); + (im,trash) = mapfold substr <> (i fby i, 0 -> !(pre m)) +tel + + +node main () returns (r:int) +var f: int^100; nf: int^100; x: int; +let + x = 0 fby x+1; + f = x^100; + nf = normalized_movie<<100>>(f); + r = mean<<100>>(nf) +tel + diff --git a/test/async/pipline_b.ept b/test/async/pipline_b.ept new file mode 100644 index 0000000..544783c --- /dev/null +++ b/test/async/pipline_b.ept @@ -0,0 +1,25 @@ + +fun sum (x,m: int) returns (s: int) +let + s = x + m +tel + +fun substr (x,m: int) returns (d: int; m2:int) +let + d = x - m; + m2 = m; +tel + +fun mean<> (i: int^n) returns (m: int) +let + m = fold sum <> (i,0) +tel + + +node normalized_movie<> (i: int^n) returns (im: int^n) +var m: int; trash: int; +let + m = mean<>(i); + (im,trash) = mapfold substr <> (i fby i, 0 -> (pre m)) +tel + diff --git a/test/async/rapide_lent.ept b/test/async/rapide_lent.ept new file mode 100644 index 0000000..ac0aa53 --- /dev/null +++ b/test/async/rapide_lent.ept @@ -0,0 +1,24 @@ + + +node lent(coeff:int) returns (y:int) +let + y = do_stuff(coeff); +tel + + +node rapide<>() returns (z:int) +var y,cpt : int; big_step : bool; +let + big_step = cpt = 0; + cpt = size fby (if big_step then size else cpt - 1); + y = merge big_step + (true -> 0 -> (pre (lent(size)))) + (false -> 0 fby y when false(big_step)); + z = do_stuff(1) - y; +tel + + +node main() returns(r: int) +let + r = rapide<<1000>>(); +tel diff --git a/test/async/rapide_lent_a.ept b/test/async/rapide_lent_a.ept new file mode 100644 index 0000000..1c53a99 --- /dev/null +++ b/test/async/rapide_lent_a.ept @@ -0,0 +1,24 @@ + + +node lent(coeff:int) returns (y:int) +let + y = do_stuff(coeff); +tel + + +node rapide<>() returns (z:int) +var y : int; cpt : int; big_step : bool; +let + big_step = cpt = 0; + cpt = size fby (if big_step then size else cpt - 1); + y = merge big_step + (true -> 0 -> !(pre (async lent(size)))) + (false -> 0 fby y when false(big_step)); + z = do_stuff(1) - y; +tel + + +node main() returns(r: int) +let + r = rapide<<1000>>(); +tel diff --git a/test/async/scalarize.ept b/test/async/scalarize.ept new file mode 100644 index 0000000..f4ced3a --- /dev/null +++ b/test/async/scalarize.ept @@ -0,0 +1,7 @@ + +node f() returns () +var t1,t2 : int^4; +let + t1 = [3, 5, 6, 7]; + t2 = map (+) <<4>> (4^4,t1); +tel diff --git a/test/async/tt.ept b/test/async/tt.ept new file mode 100644 index 0000000..e77a98c --- /dev/null +++ b/test/async/tt.ept @@ -0,0 +1,12 @@ +node counter(res: bool; tick: bool) returns (o: int) +let + o = if res then 0 else if tick then 1 -> pre o + 1 else 0 -> pre o; +tel + +node counter2() returns (b: bool) +var t : async int; +let + t = async 0 fby async counter(false,true); + b = counter(false,true) -1 = !t; +tel + diff --git a/test/async/ttt.ept b/test/async/ttt.ept new file mode 100644 index 0000000..95c4ae6 --- /dev/null +++ b/test/async/ttt.ept @@ -0,0 +1,18 @@ +node counter(res: bool; tick: bool) returns (o: int) +let + o = if res then 0 else if tick then 1 -> pre o + 1 else 0 -> pre o; +tel + +node counter3() returns (t: async bool) +var last async t: int; cpt: int; +let + cpt = counter(false,true); + automaton + state I do + t = async counter(false,true))); + until true continue III + state III do + until cpt/3 = 0 continue I + end; + b = 0 fby cpt - 1 = 0 -> !t ; +tel \ No newline at end of file