From 3e25cf54dc02db343399f3fa15e62918e7c6f562 Mon Sep 17 00:00:00 2001 From: Erwan Jahier <jahier@imag.fr> Date: Wed, 20 Mar 2013 18:02:46 +0100 Subject: [PATCH] The -exec mode now supports explicit arrays expression (e.g., [4,3,r]) --- src/socExecEvalPredef.ml | 43 +++++++++++++++++++++++++++------------ src/socPredef.ml | 44 ++++++++++++++++++++++++++++++++++------ 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/src/socExecEvalPredef.ml b/src/socExecEvalPredef.ml index 6d67de26..c372d2da 100644 --- a/src/socExecEvalPredef.ml +++ b/src/socExecEvalPredef.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 20/03/2013 (at 17:25) by Erwan Jahier> *) +(* Time-stamp: <modified the 20/03/2013 (at 17:57) by Erwan Jahier> *) open SocExecValue open Soc @@ -205,21 +205,37 @@ let lustre_if ctx = in { ctx with s = sadd ctx.s vn vv } -let lustre_hat tl ctx = - let i = match tl with - | [_;Soc.Array(_,i)] -> i +let lustre_array tl ctx = + let t,size = match List.hd (List.rev tl) with + | Soc.Array(t,i) -> t,i | _ -> assert false in - let (vn,vv) = - match ([get_val "x" ctx]) with - | [B x] -> "z"::ctx.cpath,A(Array.make i (B x)) - | [I x] -> "z"::ctx.cpath,A(Array.make i (I x)) - | [F x] -> "z"::ctx.cpath,A(Array.make i (F x)) - | [A x] -> "z"::ctx.cpath,A(Array.make i (A x)) - | [U] -> "z"::ctx.cpath,U - | _ -> assert false + let inames = + let res = ref [] in + for k=size downto 1 do + res:= ("x"^(string_of_int k)) :: !res; + done; + !res in - { ctx with s = sadd ctx.s vn vv } + let l = List.map (fun name -> get_val name ctx) inames in + let a = Array.of_list l in + { ctx with s = sadd ctx.s ("z"::ctx.cpath) (A a) } + + let lustre_hat tl ctx = + let i = match tl with + | [_;Soc.Array(_,i)] -> i + | _ -> assert false + in + let (vn,vv) = + match ([get_val "x" ctx]) with + | [B x] -> "z"::ctx.cpath,A(Array.make i (B x)) + | [I x] -> "z"::ctx.cpath,A(Array.make i (I x)) + | [F x] -> "z"::ctx.cpath,A(Array.make i (F x)) + | [A x] -> "z"::ctx.cpath,A(Array.make i (A x)) + | [U] -> "z"::ctx.cpath,U + | _ -> assert false + in + { ctx with s = sadd ctx.s vn vv } (* That one is different *) let lustre_xor ctx = assert false @@ -260,6 +276,7 @@ let (get: Soc.key -> (ctx -> ctx)) = | "Lustre::if" -> lustre_if | "Lustre::hat" -> lustre_hat tl + | "Lustre::array" -> lustre_array tl | "Lustre::xor" -> lustre_xor | "Lustre::diese" -> lustre_diese diff --git a/src/socPredef.ml b/src/socPredef.ml index a5ee877f..b15b1261 100644 --- a/src/socPredef.ml +++ b/src/socPredef.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 19/03/2013 (at 14:39) by Erwan Jahier> *) +(* Time-stamp: <modified the 20/03/2013 (at 18:01) by Erwan Jahier> *) (** Synchronous Object Code for Predefined operators. *) @@ -353,9 +353,42 @@ let make_slice_soc: Lic.slice_info -> Soc.var_type -> Soc.t = (* init = None; *) } +let gen_index_list n = + let rec aux acc i n = + if i<0 then acc else aux (i::acc) (i-1) n + in + aux [] (n-1) n + +let _ = assert (gen_index_list 5 = [0;1;2;3;4]) + let make_array_soc: int -> Soc.var_type -> Soc.t = fun i t -> - assert false + let iprof = + let res = ref [] in + for k=i downto 1 do + res:= ("x"^(string_of_int k),t) :: !res; + done; + !res + in + let array_type = Array(t,i) in + let key_prof = (List.map snd iprof) @ [array_type] in + { + key = ("Lustre::array", key_prof, None); + profile = (iprof, ["z", array_type]); + instances = []; + step = [ + { + name = "step"; + lxm = Lxm.dummy "predef array soc"; + idx_ins = gen_index_list i; + idx_outs = [0]; + impl = None; + }; + ]; + precedences = []; + have_mem = None; + } + let make_hat_soc: int -> Soc.var_type -> Soc.t = fun i t -> @@ -506,10 +539,9 @@ let (soc_interface_of_pos_op: (make_hat_soc i elt_type) | Lic.ARRAY, _ -> - let concrete_type = List.nth types 0 in - let soc = of_soc_key (("Lustre::array"), types@[concrete_type], None) in - let soc = instanciate_soc soc concrete_type in - soc + let elt_type = List.nth types 0 in + let i = (List.length types) in + (make_array_soc i elt_type) | Lic.CONCAT ,_-> finish_me lxm ; assert false -- GitLab