diff --git a/src/TODO b/src/TODO index 4533407b91e073de3c3974c458aa062e6be3d32b..1cc5670655daa096b511c0e5d679a1a1028b9b8e 100644 --- a/src/TODO +++ b/src/TODO @@ -125,12 +125,6 @@ A faire * Attacher l'horloge des expressions aux expressions elle-meme, plutot que d'utiliser une hashtbl (comme pour le type). -* Maintenant que le type est attaché aux val_exp, il ne devrait plus y -avoir de type attaché a certains variants (eg, STRUCT_ACCESS) ; du coup, -ca permettrait de virer les bouts de types checking qui sont fait dans -GetEff.tralnate_val_exp, alors que pour tous les autres cas, cela est -fait dans EvalType. - * Ne pas générer de "current", "->", "pre" (i.e., les traduire en termes de "merge" et "fby"). diff --git a/src/eff.ml b/src/eff.ml index f7d3f5edc36255388908c80e66a41864a57ed00e..b0e249cebe75361ed53123e135067cd3920c76ac 100644 --- a/src/eff.ml +++ b/src/eff.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 11/03/2009 (at 14:13) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:36) by Erwan Jahier> *) (** @@ -163,13 +163,13 @@ and eq_info = left list * val_exp and val_exp = { core : val_exp_core ; - typ : type_ list + typ : type_ list ; (* An empty list means that its type has not been computed (EvalType.f) yet. a cleaner solution would be to define two versions of val_exp: one with type info, and one without. But it is a big mutually recursive thing, and doing that would be a little bit heavy... *) - (* ; clk : clock *) +(* clk : clock *) } and val_exp_core = | CallByPosEff of (by_pos_op srcflagged * operands) @@ -200,12 +200,12 @@ and by_pos_op = | CONCAT | HAT of int * val_exp | ARRAY of val_exp list - | STRUCT_ACCESS of Ident.t * type_ + | STRUCT_ACCESS of Ident.t (* those are different from [by_pos_op] *) - | ARRAY_ACCES of int * type_ (* index + type_ of the element *) - | ARRAY_SLICE of slice_info * type_ + | ARRAY_ACCES of int + | ARRAY_SLICE of slice_info | MERGE of (Ident.t * (Ident.t list)) @@ -513,7 +513,8 @@ let rec (const_to_val_eff: Lxm.t -> bool -> const -> val_exp) = fun lxm expand_const const -> let mk_by_pos_op by_pos_op_eff = { core = CallByPosEff(flagit by_pos_op_eff lxm, OperEff []) ; - typ = [type_of_const const] } + typ = [type_of_const const] ; + } in let id_of_int i = Ident.of_string (string_of_int i) in match const with diff --git a/src/evalClock.ml b/src/evalClock.ml index c019b09095c78fdcc6e46ba84d6a27793ba0ef87..382addca1fdbfc521622dbd1f874b984ed9c08ad 100644 --- a/src/evalClock.ml +++ b/src/evalClock.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 09/03/2009 (at 16:46) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:44) by Erwan Jahier> *) open Predef @@ -432,8 +432,8 @@ and (eval_by_pos_clock : Eff.id_solver -> Eff.by_pos_op -> Lxm.t -> Eff.val_exp (* One argument. *) | Eff.PRE,args | Eff.STRUCT_ACCESS _,args - | Eff.ARRAY_ACCES (_, _),args - | Eff.ARRAY_SLICE (_,_),args -> + | Eff.ARRAY_ACCES (_),args + | Eff.ARRAY_SLICE (_),args -> assert(List.length args = 1); f_aux id_solver s (List.hd args) diff --git a/src/evalConst.ml b/src/evalConst.ml index e0d90af5557bd1b76b82400f9c09d8deb74f9c36..18746713a50e5ba84293cffb731ae24ecf1e87ac 100644 --- a/src/evalConst.ml +++ b/src/evalConst.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 11/02/2009 (at 18:09) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:39) by Erwan Jahier> *) open Printf @@ -280,7 +280,12 @@ let rec f | [Array_const_eff (elts, typelts)] -> ( try let sz = List.length elts in - let effix = eval_array_index env ix sz lxm in + let effix = eval_array_index env ix lxm in + let _ = if effix > sz then + raise(EvalType_error( + sprintf "array index %d out of bounds 0..%d" + effix (sz-1))) + in [List.nth elts effix] with EvalArray_error msg -> raise(EvalConst_error msg) ) @@ -292,11 +297,9 @@ let rec f | [Array_const_eff (l, t)] -> (l, t) | x -> type_error_const x "some array" in - (* on en déduit la taille du tableau *) - let sz = List.length elts in (* évalue la slice *) try - let sliceff = eval_array_slice env sl sz lxm in + let sliceff = eval_array_slice env sl lxm in make_slice_const elts typelts sliceff with EvalArray_error msg -> raise(EvalConst_error msg) @@ -437,14 +440,13 @@ and (eval_array_size: Eff.id_solver -> val_exp -> int) = and eval_array_index (env : Eff.id_solver) (ixexp : val_exp) - (sz : int) (lxm : Lxm.t) = try ( match (f env ixexp) with | [Int_const_eff i] - | [Abstract_const_eff(_,_, (Int_const_eff i), true)] -> check_int i sz + | [Abstract_const_eff(_,_, (Int_const_eff i), true)] -> i | [Abstract_const_eff(id,_,_,false)] -> raise(EvalArray_error("The const " ^ (Ident.string_of_long id) ^ " is abstract")) @@ -463,10 +465,10 @@ and eval_array_index EvalArray_error msg -> raise (Compile_error(lxm, "\n*** can't eval constant: "^msg)) - and check_int i sz = - if ((i >= 0) && (i < sz)) then i - else raise(EvalArray_error( - sprintf "array index %d out of bounds 0..%d" i (sz-1))) +(* and check_int i sz = *) +(* if ((i >= 0) && (i < sz)) then i *) +(* else raise(EvalArray_error( *) +(* sprintf "array index %d out of bounds 0..%d" i (sz-1))) *) (*--------------------------------------------------------------------- eval_array_slice @@ -485,10 +487,10 @@ and eval_array_index Effets de bord : EvalArray_error msg si pas bon ----------------------------------------------------------------------*) -and eval_array_slice (env : Eff.id_solver) (sl : slice_info) (sz : int) (lxm : Lxm.t) = +and eval_array_slice (env : Eff.id_solver) (sl : slice_info) (lxm : Lxm.t) = try - let first_ix = eval_array_index env sl.si_first sz lxm in - let last_ix = eval_array_index env sl.si_last sz lxm in + let first_ix = eval_array_index env sl.si_first lxm in + let last_ix = eval_array_index env sl.si_last lxm in let step = match sl.si_step with | Some stepexp -> ( diff --git a/src/evalConst.mli b/src/evalConst.mli index 182b1a5310072f4437f50112143636a3d191d985..4ba80e9c93084da15f0e861015d5d6be66246c75 100644 --- a/src/evalConst.mli +++ b/src/evalConst.mli @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 29/08/2008 (at 10:21) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:38) by Erwan Jahier> *) (* @@ -85,13 +85,12 @@ val eval_array_size : Eff.id_solver -> SyntaxTreeCore.val_exp -> int id_solver, val_exp, taille du tableau Sorties : - int (entre 0 et taille du tableau -1 + int (entre 0 et taille du tableau -1) Effets de bord : EvalArray_error msg si pas bon *) -val eval_array_index : Eff.id_solver -> SyntaxTreeCore.val_exp -> - int -> Lxm.t -> int +val eval_array_index : Eff.id_solver -> SyntaxTreeCore.val_exp -> Lxm.t -> int (** Rôle : @@ -109,5 +108,4 @@ val eval_array_index : Eff.id_solver -> SyntaxTreeCore.val_exp -> EvalArray_error msg si pas bon *) val eval_array_slice : - Eff.id_solver -> SyntaxTreeCore.slice_info -> int -> Lxm.t -> - Eff.slice_info + Eff.id_solver -> SyntaxTreeCore.slice_info -> Lxm.t -> Eff.slice_info diff --git a/src/evalType.ml b/src/evalType.ml index b485b45121c41520f0f96d8fa314d9bed9e8a62a..f8f7b5030774c4c71df1893077029d251477af73 100644 --- a/src/evalType.ml +++ b/src/evalType.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 11/03/2009 (at 14:17) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:44) by Erwan Jahier> *) open Predef @@ -110,22 +110,67 @@ and (eval_by_pos_type : Eff.id_solver -> Eff.by_pos_op -> Lxm.t -> in None, args, tve ) - | Eff.STRUCT_ACCESS (fid,teff) -> - let args, targs = List.split (List.map (f id_solver) args) in - (* The type check of teff wrt targs has been done in - GetEff.translate_val_exp (XXX which is not the rigth - place to do that IMHO ; here would be a better place) *) - None, args, [teff] + | Eff.STRUCT_ACCESS (fid) -> + assert (List.length args = 1); + let arg, targ = f id_solver (List.hd args) in + let teff_field = + match targ with + | [Struct_type_eff (name, fl)] -> ( + try fst (List.assoc fid fl) + with Not_found -> + raise ( + PredefEvalType.EvalType_error + (Printf.sprintf "%s is not a field of struct %s" + (Ident.to_string fid) + (LicDump.string_of_type_eff4msg (List.hd targ)))) + ) + | [x] -> PredefEvalType.type_error [x] "struct type" + | x -> PredefEvalType.arity_error x "1" + in + None, [arg], [teff_field] - | Eff.ARRAY_ACCES (_, teff) -> - let args, targs = List.split (List.map (f id_solver) args) in - (* Ditto XXX type check teff wrt targs here *) - None, args, [teff] + | Eff.ARRAY_ACCES(i) -> + assert (List.length args = 1); + let arg, targ = f id_solver (List.hd args) in + let sz, teff = + match targ with + | [Array_type_eff(teff_elt, size)] -> size, teff_elt + | _ -> + let msg = + "\n*** Type error: '"^(LicDump.string_of_type_eff_list4msg targ) ^ + "' was expected to be an array" + in + raise (Compile_error(lxm, msg)) + in + let _ = if ((i >= 0) && (i < sz)) then () else + raise( + EvalType_error(sprintf "array index %d out of bounds 0..%d" i (sz-1))) + in + None, [arg], [teff] - | Eff.ARRAY_SLICE (sieff,teff) -> - let args, targs = List.split (List.map (f id_solver) args) in - (* Ditto XXX type check teff wrt targs here *) - None, args, [Array_type_eff(teff, sieff.se_width)] + | Eff.ARRAY_SLICE(sieff) -> + assert (List.length args = 1); + let arg, targ = f id_solver (List.hd args) in + let sz, teff_elt = + match targ with + | [Array_type_eff(teff_elt, size)] -> size, teff_elt + | _ -> + raise (Compile_error( + lxm, "\n*** Type error: '" ^ + (LicDump.string_of_type_eff_list targ) ^ + "' was expected to be an array")) + in + let _ = if ((sieff.se_first >= 0) && (sieff.se_first < sz)) then () else + raise( + EvalType_error(sprintf "array index %d out of bounds 0..%d" + sieff.se_first (sz-1))) + in + let _ = if ((sieff.se_last >= 0) && (sieff.se_last < sz)) then () else + raise( + EvalType_error(sprintf "array index %d out of bounds 0..%d" + sieff.se_last (sz-1))) + in + None, [arg], [Array_type_eff(teff_elt, sieff.se_width)] | Eff.HAT(size,ceff) -> let ceff, teff_list = f id_solver ceff in @@ -227,7 +272,7 @@ and (eval_by_name_type : Eff.id_solver -> Eff.by_name_op -> Lxm.t -> in (* let's check the type of fv *) let fv, fv_type = f id_solver fv in - let fv_type = (* XXX ignored? *) + let _fv_type = (* XXX ignored? *) match UnifyType.f [ft] fv_type with | UnifyType.Unif t -> t | UnifyType.Equal -> ft diff --git a/src/getEff.ml b/src/getEff.ml index 1b185b1d4259c92e1a82d49ac591a92937835a03..d48da298aa9c9aa9ff1b88710f32c768c3fcbd7b 100644 --- a/src/getEff.ml +++ b/src/getEff.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 11/03/2009 (at 11:26) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:45) by Erwan Jahier> *) open Lxm @@ -331,7 +331,7 @@ and (translate_left_part : id_solver -> SyntaxTreeCore.left_part -> Eff.left) = let lxm = vef.src in match teff with | Array_type_eff(teff_elt, size) -> - let index = EvalConst.eval_array_index id_solver vef.it size lxm in + let index = EvalConst.eval_array_index id_solver vef.it lxm in LeftArrayEff(lp_eff, index, teff_elt) | _ -> raise (Compile_error(vef.src, "an array was expected")) @@ -341,7 +341,7 @@ and (translate_left_part : id_solver -> SyntaxTreeCore.left_part -> Eff.left) = let teff = Eff.type_of_left lp_eff in match teff with | Array_type_eff(teff_elt, size) -> - let sieff = translate_slice_info id_solver sif.it size sif.src in + let sieff = translate_slice_info id_solver sif.it sif.src in let size_slice = sieff.se_width in let teff_slice = Array_type_eff(teff_elt, size_slice) in LeftSliceEff(lp_eff, sieff, teff_slice) @@ -453,23 +453,7 @@ and (translate_val_exp : Eff.id_solver -> SyntaxTreeCore.val_exp -> Eff.val_exp) else mk_by_pos_op (Eff.WITH (translate_val_exp id_solver e2)) | STRUCT_ACCESS_n fid -> - assert (List.length vel_eff = 1); - let _, teff = EvalType.f id_solver (List.hd vel_eff) in - let teff_field = - match teff with - | [Struct_type_eff (name, fl)] -> ( - try fst (List.assoc fid fl) - with Not_found -> - raise ( - PredefEvalType.EvalType_error - (Printf.sprintf "%s is not a field of struct %s" - (Ident.to_string fid) - (LicDump.string_of_type_eff4msg (List.hd teff)))) - ) - | [x] -> PredefEvalType.type_error [x] "struct type" - | x -> PredefEvalType.arity_error x "1" - in - mk_by_pos_op (Eff.STRUCT_ACCESS (fid,teff_field)) + mk_by_pos_op (Eff.STRUCT_ACCESS (fid)) | WHEN_n Base -> mk_by_pos_op (Eff.WHEN Base) | WHEN_n (NamedClock { it = (cc,cv) ; src = lxm }) -> @@ -477,42 +461,14 @@ and (translate_val_exp : Eff.id_solver -> SyntaxTreeCore.val_exp -> Eff.val_exp) mk_by_pos_op (Eff.WHEN (NamedClock { it = (cc,cv) ; src = lxm })) | ARRAY_ACCES_n ve_index -> - let _, teff = - assert (List.length vel = 1); - EvalType.f id_solver (List.hd vel_eff) - in - let size, teff_elt = - match teff with - | [Array_type_eff(teff_elt, size)] -> size, teff_elt - | _ -> - raise (Compile_error( - lxm, "\n*** Type error: '" ^ - (LicDump.string_of_type_eff_list teff) ^ - "' was expected to be an array")) - in mk_by_pos_op ( Eff.ARRAY_ACCES( - EvalConst.eval_array_index id_solver ve_index size lxm, - teff_elt - )) + EvalConst.eval_array_index id_solver ve_index lxm)) | ARRAY_SLICE_n si -> - let _, teff = - assert (List.length vel = 1); - EvalType.f id_solver (List.hd vel_eff) - in - let size, teff_elt = - match teff with - | [Array_type_eff(teff_elt, size)] -> size, teff_elt - | _ -> - raise (Compile_error( - lxm, "\n*** Type error: '" ^ - (LicDump.string_of_type_eff_list teff) ^ - "' was expected to be an array")) - in - mk_by_pos_op - (Eff.ARRAY_SLICE( - EvalConst.eval_array_slice id_solver si size lxm, teff_elt)) + mk_by_pos_op + (Eff.ARRAY_SLICE( + EvalConst.eval_array_slice id_solver si lxm)) | HAT_n -> ( match vel with @@ -723,10 +679,10 @@ and (translate_predef_static_args: Eff.id_solver -> raise (Compile_error(lxm, "bad arguments number for array iterator")) -and (translate_slice_info : Eff.id_solver -> SyntaxTreeCore.slice_info -> int -> +and (translate_slice_info : Eff.id_solver -> SyntaxTreeCore.slice_info -> Lxm.t -> Eff.slice_info) = - fun id_solver si size lxm -> - EvalConst.eval_array_slice id_solver si size lxm + fun id_solver si lxm -> + EvalConst.eval_array_slice id_solver si lxm (**********************************************************************************) diff --git a/src/inline.ml b/src/inline.ml index 9bc53095316047c90f138c9e8c0b3edf4f6cc198..5ec0f5e0d8bb40011977267f94721dd3798de185 100644 --- a/src/inline.ml +++ b/src/inline.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 11/03/2009 (at 11:19) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:35) by Erwan Jahier> *) open Lxm @@ -108,7 +108,7 @@ let rec (inline_eq: Eff.local_env -> (fun arg -> let targ = arg.typ in let t_elt = elt_type_of_array targ in - let op_flg = { src = lxm_ve ; it = ARRAY_ACCES(i,t_elt) } in + let op_flg = { src = lxm_ve ; it = ARRAY_ACCES(i) } in let narg = { core = CallByPosEff(op_flg, OperEff [arg]); typ = [t_elt] @@ -209,7 +209,7 @@ let rec (inline_eq: Eff.local_env -> List.map (fun arg -> let t_elt = elt_type_of_array arg.typ in - let op_flg = {src = lxm_ve ; it = ARRAY_ACCES(i,t_elt)} in + let op_flg = {src = lxm_ve ; it = ARRAY_ACCES(i)} in let new_arg = { core = CallByPosEff(op_flg, OperEff [arg]); typ=[t_elt] } in @@ -377,7 +377,7 @@ let rec (inline_eq: Eff.local_env -> | _ -> assert false in let make_ite i = (* returns '(if A[i] then 1 else 0)' *) - let a_op = { it = ARRAY_ACCES(i,type_elt) ; src = lxm_ve } in + let a_op = { it = ARRAY_ACCES(i) ; src = lxm_ve } in let a_i = { typ = [type_elt]; core = CallByPosEff(a_op, OperEff [array]) } in diff --git a/src/licDump.ml b/src/licDump.ml index 10789eea5a94a9ae75c944030026b2be09306096..c5ffcc00a94b3a5844a2a6a7c4c179b1d663a50d 100644 --- a/src/licDump.ml +++ b/src/licDump.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 10/03/2009 (at 10:02) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:42) by Erwan Jahier> *) open Printf open Lxm @@ -201,6 +201,11 @@ and string_of_type_eff_list = function | [x] -> string_of_type_eff x | l -> String.concat " * " (List.map string_of_type_eff l) +and string_of_type_eff_list4msg = function + | [] -> "" + | [x] -> string_of_type_eff4msg x + | l -> String.concat " * " (List.map string_of_type_eff4msg l) + (* for printing recursive node *) and string_of_node_key_rec (nkey: node_key) = @@ -407,16 +412,16 @@ and (string_of_by_pos_op_eff: Eff.by_pos_op srcflagged -> Eff.val_exp list -> st (string_of_val_exp_eff ve1) ^ " | " ^ (string_of_val_exp_eff ve2) | HAT (i, ve), _ -> (string_of_val_exp_eff ve) ^ "^" ^ (string_of_int i) | ARRAY vel, _ -> tuple_square vel - | STRUCT_ACCESS(id,_), [ve1] -> + | STRUCT_ACCESS(id), [ve1] -> (string_of_val_exp_eff ve1) ^ "." ^ (Ident.to_string id) - | ARRAY_ACCES(i, type_eff), [ve1] -> + | ARRAY_ACCES(i), [ve1] -> (string_of_val_exp_eff ve1) ^ "[" ^ (string_of_int i) ^ "]" - | ARRAY_SLICE(si_eff, type_eff), [ve1] -> + | ARRAY_SLICE(si_eff), [ve1] -> (string_of_val_exp_eff ve1) ^ (string_of_slice_info_eff si_eff) - | ARRAY_SLICE(_,_), _ -> assert false (* todo *) + | ARRAY_SLICE(_), _ -> assert false (* todo *) | MERGE _, _ -> assert false (* todo *) (* | ITERATOR _, _ -> assert false (* todo *) *) @@ -425,7 +430,7 @@ and (string_of_by_pos_op_eff: Eff.by_pos_op srcflagged -> Eff.val_exp list -> st | FBY, _ -> assert false | CONCAT, _ -> assert false | STRUCT_ACCESS(_), _ -> assert false - | ARRAY_ACCES(i, type_eff), _ -> assert false + | ARRAY_ACCES(i), _ -> assert false in let do_not_parenthesize = function | IDENT _,_ diff --git a/src/licDump.mli b/src/licDump.mli index 3523a393d600f0a2c8f0fe76548d12d5d7a69013..4c9f36c57177c6deceadb2eba3b4c78d597010f9 100644 --- a/src/licDump.mli +++ b/src/licDump.mli @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 10/03/2009 (at 10:02) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:32) by Erwan Jahier> *) val string_of_node_key_rec : Eff.node_key -> string @@ -10,6 +10,7 @@ val string_of_leff : Eff.left -> string val string_of_type_eff : Eff.type_ -> string val string_of_type_eff4msg : Eff.type_ -> string val string_of_type_eff_list : Eff.type_ list -> string +val string_of_type_eff_list4msg : Eff.type_ list -> string val type_eff_list_to_string :Eff.type_ list -> string val type_decl: Ident.long -> Eff.type_ -> string diff --git a/src/structArrayExpand.ml b/src/structArrayExpand.ml index f2c3da9750e46947fd1ed993a942f75fe7936690..e04c732fdc9540442f94dbb5ff70a28b3a17d59c 100644 --- a/src/structArrayExpand.ml +++ b/src/structArrayExpand.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 10/03/2009 (at 14:39) by Erwan Jahier> *) +(** Time-stamp: <modified the 11/03/2009 (at 17:45) by Erwan Jahier> *) (* Replace structures and arrays by as many variables as necessary. Since structures can be recursive, it migth be a lot of new variables... @@ -238,19 +238,19 @@ and (var_trees_of_val_exp : Eff.local_env -> Eff.id_solver -> acc -> Eff.val_exp let lxm = by_pos_op.src in let by_pos_op = by_pos_op.it in (match by_pos_op with - | STRUCT_ACCESS (id,teff) -> + | STRUCT_ACCESS (id) -> let ve = try List.hd vel with _ -> assert false in (match loop ve with | acc, S fl -> acc, List.assoc id fl | _, (A _ | L _) -> assert false ) - | ARRAY_ACCES (i,teff) -> + | ARRAY_ACCES (i) -> let ve = try List.hd vel with _ -> assert false in (match loop ve with | acc, A array -> acc, List.nth array i | _, (S _ | L _) -> assert false ) - | ARRAY_SLICE (si,t) -> + | ARRAY_SLICE (si) -> let ve = try List.hd vel with _ -> assert false in (match loop ve with | acc, A array ->