diff --git a/src/Makefile b/src/Makefile index 1cde6f9a45f885ee8782fb46c9241addaee95ed8..a7a4cdb327886e6a7243a699aeb28b5897e83591 100644 --- a/src/Makefile +++ b/src/Makefile @@ -102,8 +102,7 @@ debug: mkdir -p mli mv *.mli mli/ make MLONLY=yes SOURCES="$(MLONLY_SOURCES)" dc || true - mv mli/* . - + mv mli/*.mli . diff --git a/src/eff.ml b/src/eff.ml index e2498fd862ad2ee900ae59cc24df34290aa8a4a4..39df74f848fa3edf898afaff367018fb13185c3f 100644 --- a/src/eff.ml +++ b/src/eff.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 23/10/2008 (at 15:16) by Erwan Jahier> *) +(** Time-stamp: <modified the 23/10/2008 (at 17:50) by Erwan Jahier> *) (** @@ -346,13 +346,12 @@ let (profile_of_node_exp : node_exp -> type_ list * type_ list) = cannot have any package name. and for nodes, the only possibility to have an entry in this table is via the - static parameters. But for the time being, we cannot have parametrised nodes - in argument of parametric node (can we?) + static parameters. i.e. min_4 = min_n<< 4, toto<<2>> >> ; - is not allowed (I think). One has to to something like: + is not allowed (I think). One has to write something like : toto_2 = toto<<2>>; min_4 = min_n<< 4, toto_2 >> ; @@ -471,7 +470,7 @@ let (type_of_left: left -> type_) = | LeftArrayEff(_, _, t) -> t | LeftSliceEff(_, _, t) -> t - + let rec (var_info_of_left: left -> var_info) = function | LeftVarEff (v, _) -> v diff --git a/src/getEff.ml b/src/getEff.ml index a2c3b54b9cd593f307897265994e62947c0edf84..9a76276799b7714af9bc90d12e145adde8c70bd3 100644 --- a/src/getEff.ml +++ b/src/getEff.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 15/09/2008 (at 15:48) by Erwan Jahier> *) +(** Time-stamp: <modified the 24/10/2008 (at 11:00) by Erwan Jahier> *) open Lxm @@ -82,10 +82,16 @@ and (clock_check_equation:Eff.id_solver -> Lxm.t -> Eff.left list -> let (get_static_params_from_idref : SymbolTab.t -> Lxm.t -> Ident.idref -> static_param srcflagged list) = fun symbols lxm idref -> - match SymbolTab.find_node symbols (Ident.name_of_idref idref) lxm with - | SymbolTab.Local ni -> ni.it.static_params - | SymbolTab.Imported(imported_node, params) -> params - + try + match SymbolTab.find_node symbols (Ident.name_of_idref idref) lxm with + | SymbolTab.Local ni -> ni.it.static_params + | SymbolTab.Imported(imported_node, params) -> params + with _ -> + (* can occur for static node parameters, which cannot + themselves have static parameters. A better solution ougth + to be to add node static parameters in the SymbolTab.t + however (in Lazycompiler.node_check_do most probably). *) + [] (* exported *) let rec (node : Eff.id_solver -> SyntaxTreeCore.node_exp srcflagged -> @@ -93,10 +99,18 @@ let rec (node : Eff.id_solver -> SyntaxTreeCore.node_exp srcflagged -> fun id_solver { src = lxm; it=(idref, static_args) } -> let static_params = get_static_params_from_idref id_solver.symbols lxm idref in let static_args_eff = - assert(List.length static_params = List.length static_args); - List.map2 (check_static_arg id_solver) - static_params - static_args + let sp_l = List.length static_params + and sa_l = List.length static_args in + if (sp_l <> sa_l) then + let msg = "Bad number of (static) arguments: " ^ + (string_of_int sp_l) ^ " expected, and " ^ + (string_of_int sa_l) ^ " provided." + in + raise (Compile_error(lxm, msg)) + else + List.map2 (check_static_arg id_solver) + static_params + static_args in id_solver.id2node idref static_args_eff lxm @@ -109,10 +123,65 @@ and (check_static_arg : Eff.id_solver -> SyntaxTreeCore.static_arg srcflagged -> Eff.static_arg) = fun node_id_solver sp sa -> + + let rec (eff_type_and_type_exp_are_equal: + Eff.type_ -> SyntaxTreeCore.type_exp_core -> bool) = + fun teff texp -> + match teff, texp with + | Bool_type_eff, Bool_type_exp + | Real_type_eff, Real_type_exp + | Int_type_eff, Int_type_exp -> true + | External_type_eff l, Named_type_exp idref -> + (* This seems a little bit wrong *) + l = Ident.long_of_idref idref + + | _ , Named_type_exp idref -> true + + | Array_type_eff(teff_ext,i),Array_type_exp(texp,j) -> + i=(EvalConst.eval_array_size node_id_solver j) + & (eff_type_and_type_exp_are_equal teff texp.it) + + | Any,_ -> assert false (* for TTB, polymorphism is not supported *) + | Overload, _ -> assert false (* ditto *) + | Struct_type_eff(_),_ -> assert false (* impossible *) + | Enum_type_eff(_),_ -> assert false (* ditto *) + | _ -> false + in + let check_type_arg type_eff type_exp = + if not (eff_type_and_type_exp_are_equal type_eff type_exp.it) then + let msg = "Bad (static) type argument: '" ^ + (LicDump.string_of_type_eff type_eff) ^ + "' and '" ^ (string_of_type_exp type_exp) ^ "' differs." + in + raise (Compile_error(type_exp.src, msg)) + else () + in + + let type_check_var_info acc vi_eff vi_exp = acc & + eff_type_and_type_exp_are_equal vi_eff.var_type_eff vi_exp.it.var_type.it + in + let type_check_var_info_list vil_eff vil_exp = + List.fold_left2 type_check_var_info true vil_eff vil_exp + in + let check_node_arg neff vii vio = + let str = "Bad (static) node argument: " in + if (List.length neff.inlist_eff) <> (List.length vii) then + raise (Compile_error(sa.src, str ^ "arity error (inputs).")) + else if (List.length neff.outlist_eff) <> (List.length vio) then + raise (Compile_error(sa.src, str ^ "arity error (outputs).")) + else if not (type_check_var_info_list neff.inlist_eff vii) then + raise (Compile_error(sa.src, str ^ "wrong input type profile.")) + else if not (type_check_var_info_list neff.outlist_eff vio) then + raise (Compile_error(sa.src, str ^ "wrong output type profile.")) + else () + in + let sa_eff = match sa.it, sp.it with - | StaticArgIdent idref, StaticParamConst(id, _type_exp) -> + | StaticArgIdent idref, StaticParamConst(id, type_exp) -> let ceff = node_id_solver.id2const idref sa.src in + let t_ceff = type_of_const ceff in + check_type_arg t_ceff type_exp; ConstStaticArgEff (id, ceff) | StaticArgIdent idref, StaticParamType(id) -> @@ -127,8 +196,10 @@ and (check_static_arg : Eff.id_solver -> let neff = node_id_solver.id2node idref sargs sa.src in NodeStaticArgEff (id, neff) - | StaticArgConst ce, StaticParamConst(id, _type_exp) -> ( + | StaticArgConst ce, StaticParamConst(id, type_exp) -> ( let ceff = EvalConst.f node_id_solver ce in + let t_ceff = type_of_const (List.hd ceff) in + check_type_arg t_ceff type_exp; match ceff with | [ceff] -> ConstStaticArgEff (id,ceff) | _ -> assert false (* should not occur *) @@ -137,15 +208,17 @@ and (check_static_arg : Eff.id_solver -> let teff = typ node_id_solver te in TypeStaticArgEff (id, teff) - | StaticArgNode(CALL_n ne), StaticParamNode(id,_,_,_) -> + | StaticArgNode(CALL_n ne), StaticParamNode(id,vii,vio,_) -> let neff = node node_id_solver ne in + check_node_arg neff vii vio; NodeStaticArgEff (id, neff) - | StaticArgNode(Predef_n (op,sargs)), StaticParamNode(id,_,_,_) -> + | StaticArgNode(Predef_n (op,sargs)), StaticParamNode(id,vii,vio,_) -> let sargs_eff = translate_predef_static_args node_id_solver sargs sa.src in let opeff = PredefEvalType.make_node_exp_eff None op sa.src sargs_eff in + check_node_arg opeff vii vio; NodeStaticArgEff (id, opeff) | StaticArgNode( diff --git a/src/syntaxTreeCore.ml b/src/syntaxTreeCore.ml index b504252bd6ff8febc1e16c0407dde484069097a9..03ca9af0651c1e897e5e38d60caa077a34976dbe 100644 --- a/src/syntaxTreeCore.ml +++ b/src/syntaxTreeCore.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 22/10/2008 (at 17:38) by Erwan Jahier> *) +(** Time-stamp: <modified the 23/10/2008 (at 18:12) by Erwan Jahier> *) (** (Raw) Abstract syntax tree of source programs. *) @@ -190,3 +190,13 @@ type item_info = | TypeInfo of type_info | NodeInfo of node_info +(* to be used for error msgs only...*) +let rec string_of_type_exp x = + match x.it with + | Bool_type_exp -> "bool" + | Int_type_exp -> "int" + | Real_type_exp -> "real" + | Named_type_exp id -> (Ident.string_of_idref id) + | Array_type_exp (te, sz) -> (string_of_type_exp te) ^ "^ ..." + + diff --git a/src/test/should_work/NONREG/param_node.lus b/src/test/should_work/NONREG/param_node.lus index 2716196a9977383ef4910db6b898e61abe6ae96f..152fabec5290b92a12e7c882820d309cf485d607 100644 --- a/src/test/should_work/NONREG/param_node.lus +++ b/src/test/should_work/NONREG/param_node.lus @@ -1,7 +1,7 @@ -- A node parametrized by a node -node toto_n<<node f(a, b: int) returns (x: int);const n : int>>(a: int) +node toto_n<<node f(a, b: int) returns (x: int); const n : int>>(a: int) returns (x: int^n); var v : int; let @@ -9,4 +9,5 @@ let x = v ^ n; tel -node toto_3 = toto_n<<Lustre::iplus, 3>>; \ No newline at end of file +node toto_3 = toto_n<<Lustre::iplus, 3>>; + diff --git a/src/test/should_work/Pascal/t2.lus b/src/test/should_work/Pascal/t2.lus index 307043daa85a6d0489ef4f9295bd4b134aec5e0b..914eaaeea369793c239cf6baeb01f0c3d9e7a5c9 100644 --- a/src/test/should_work/Pascal/t2.lus +++ b/src/test/should_work/Pascal/t2.lus @@ -28,11 +28,11 @@ node fold_left << c : t1 ); let - c = with (n = 0) then a + c = with (n = 1) then a else fold_left << t1, t2, n-1, treat >> ( treat(a, X[0]), - X[1..n-1] + X[1 .. n-1] ); tel diff --git a/src/test/should_work/fab_test/onlyroll2.lus b/src/test/should_work/fab_test/onlyroll2.lus index a51ebfe1df2d74c32c201e95f636fefb6b211173..04c5cd2300fc926949cf30ebf873c5878e87f0e4 100644 --- a/src/test/should_work/fab_test/onlyroll2.lus +++ b/src/test/should_work/fab_test/onlyroll2.lus @@ -37,7 +37,7 @@ const HORmaxP = 57.0 ; HORminP = -57.0 ; -- Hard Over Range for pitch - HORmaxY = 57.0 ; + HORmaxY = 57.0 ; HORminY = -57.0 ; -- Hard Over Range for yaw diff --git a/src/test/test.res.exp b/src/test/test.res.exp index 302f1ba7a5208511953587ff16a54863249b6e06..c5bd066a8811f6ead03ac102b5c1797820638517 100644 --- a/src/test/test.res.exp +++ b/src/test/test.res.exp @@ -7218,9 +7218,48 @@ tel ---------------------------------------------------------------------- ====> ../lus2lic -vl 2 --compile-all-items should_work/NONREG/param_node.lus Opening file should_work/NONREG/param_node.lus -*** Error in file "should_work/NONREG/param_node.lus", line 8, col 7 to 7, token 'f': -*** unknown node (f) +node param_node::toto_n_Lustre::iplus_3(a:int) returns (x:A_int_3); +var + v:int; +let + v = Lustre::iplus(a, 1); + x = v^3; +tel +-- end of node param_node::toto_n_Lustre::iplus_3 +node param_node::toto_3(a:int) returns (x:A_int_3); +let + x = param_node::toto_n_Lustre::iplus_3(a); +tel +-- end of node param_node::toto_3 +-- automatically defined aliases: +type A_int_3 = int^3; +---------------------------------------------------------------------- +====> ../lus2lic -vl 2 --compile-all-items should_work/NONREG/param_node2.lus +Opening file should_work/NONREG/param_node2.lus +node param_node2::toto_n_int_3_3(a:int) returns (res:A_int_3); +let + res = a^3; +tel +-- end of node param_node2::toto_n_int_3_3 +node param_node2::toto_int3(a:int) returns (res:A_int_3); +let + res = param_node2::toto_n_int_3_3(a); +tel +-- end of node param_node2::toto_int3 +node param_node2::toto_n_bool_0_4(a:bool) returns (res:A_bool_4); +let + res = a^4; +tel +-- end of node param_node2::toto_n_bool_0_4 +node param_node2::toto_bool4(a:bool) returns (res:A_bool_4); +let + res = param_node2::toto_n_bool_0_4(a); +tel +-- end of node param_node2::toto_bool4 +-- automatically defined aliases: +type A_bool_4 = bool^4; +type A_int_3 = int^3; ---------------------------------------------------------------------- ====> ../lus2lic -vl 2 --compile-all-items should_work/NONREG/patrick.lus @@ -9769,9 +9808,248 @@ type A_bool_2 = bool^2; ---------------------------------------------------------------------- ====> ../lus2lic -vl 2 --compile-all-items should_work/Pascal/t2.lus Opening file should_work/Pascal/t2.lus -*** Error in file "should_work/Pascal/t2.lus", line 34, col 5 to 9, token 'treat': -*** unknown node (treat) +node t2::fold_left_bool_bool_1_Lustre::and( + a:bool; + X:A_bool_1) +returns ( + c:bool); +let + c = a; +tel +-- end of node t2::fold_left_bool_bool_1_Lustre::and + +node t2::fold_left_bool_bool_2_Lustre::and( + a:bool; + X:A_bool_2) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_1; + _v4:bool; +let + c = t2::fold_left_bool_bool_1_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 1]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 1]; + _v4 = t2::fold_left_bool_bool_1_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_2_Lustre::and + +node t2::fold_left_bool_bool_3_Lustre::and( + a:bool; + X:A_bool_3) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_2; + _v4:bool; +let + c = t2::fold_left_bool_bool_2_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 2]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 2]; + _v4 = t2::fold_left_bool_bool_2_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_3_Lustre::and + +node t2::fold_left_bool_bool_4_Lustre::and( + a:bool; + X:A_bool_4) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_3; + _v4:bool; +let + c = t2::fold_left_bool_bool_3_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 3]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 3]; + _v4 = t2::fold_left_bool_bool_3_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_4_Lustre::and + +node t2::fold_left_bool_bool_5_Lustre::and( + a:bool; + X:A_bool_5) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_4; + _v4:bool; +let + c = t2::fold_left_bool_bool_4_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 4]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 4]; + _v4 = t2::fold_left_bool_bool_4_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_5_Lustre::and + +node t2::fold_left_bool_bool_6_Lustre::and( + a:bool; + X:A_bool_6) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_5; + _v4:bool; +let + c = t2::fold_left_bool_bool_5_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 5]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 5]; + _v4 = t2::fold_left_bool_bool_5_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_6_Lustre::and +node t2::consensus_6(X:A_bool_6) returns (c:bool); +let + c = t2::fold_left_bool_bool_6_Lustre::and(true, X); +tel +-- end of node t2::consensus_6 +node t2::t2(X:A_bool_6) returns (c:bool); +let + c = t2::consensus_6(X); +tel +-- end of node t2::t2 + +node t2::fold_left_bool_bool_1_Lustre::and( + a:bool; + X:A_bool_1) +returns ( + c:bool); +let + c = a; +tel +-- end of node t2::fold_left_bool_bool_1_Lustre::and + +node t2::fold_left_bool_bool_2_Lustre::and( + a:bool; + X:A_bool_2) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_1; + _v4:bool; +let + c = t2::fold_left_bool_bool_1_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 1]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 1]; + _v4 = t2::fold_left_bool_bool_1_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_2_Lustre::and + +node t2::fold_left_bool_bool_3_Lustre::and( + a:bool; + X:A_bool_3) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_2; + _v4:bool; +let + c = t2::fold_left_bool_bool_2_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 2]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 2]; + _v4 = t2::fold_left_bool_bool_2_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_3_Lustre::and + +node t2::fold_left_bool_bool_4_Lustre::and( + a:bool; + X:A_bool_4) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_3; + _v4:bool; +let + c = t2::fold_left_bool_bool_3_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 3]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 3]; + _v4 = t2::fold_left_bool_bool_3_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_4_Lustre::and + +node t2::fold_left_bool_bool_5_Lustre::and( + a:bool; + X:A_bool_5) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_4; + _v4:bool; +let + c = t2::fold_left_bool_bool_4_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 4]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 4]; + _v4 = t2::fold_left_bool_bool_4_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_5_Lustre::and + +node t2::fold_left_bool_bool_6_Lustre::and( + a:bool; + X:A_bool_6) +returns ( + c:bool); +var + _v1:bool; + _v2:bool; + _v3:A_bool_5; + _v4:bool; +let + c = t2::fold_left_bool_bool_5_Lustre::and(Lustre::and(a, X[0]), X[1 .. + 5]); + _v1 = X[0]; + _v2 = Lustre::and(a, _v1); + _v3 = X[1 .. 5]; + _v4 = t2::fold_left_bool_bool_5_Lustre::and(_v2, _v3); +tel +-- end of node t2::fold_left_bool_bool_6_Lustre::and +node t2::consensus_6_bis(a:bool; X:A_bool_6) returns (c:bool); +let + c = t2::fold_left_bool_bool_6_Lustre::and(a, X); +tel +-- end of node t2::consensus_6_bis +-- automatically defined aliases: +type A_bool_6 = bool^6; +type A_bool_3 = bool^3; +type A_bool_4 = bool^4; +type A_bool_1 = bool^1; +type A_bool_5 = bool^5; +type A_bool_2 = bool^2; ---------------------------------------------------------------------- ====> ../lus2lic -vl 2 --compile-all-items should_work/Pascal/test.lus @@ -11791,11 +12069,6 @@ tel -- end of node sample_time_change::MainNode ----------------------------------------------------------------------- -====> ../lus2lic -vl 2 --compile-all-items should_work/fab_test/.#onlyroll2.lus -Opening file should_work/fab_test/.#onlyroll2.lus -should_work/fab_test/.#onlyroll2.lus: No such file or directory - ---------------------------------------------------------------------- ====> ../lus2lic -vl 2 --compile-all-items should_work/fab_test/bob.lus Opening file should_work/fab_test/bob.lus @@ -19246,3 +19519,32 @@ type _const2::t8 = A_A_A_A_A_A_int_3_7_8_9_3_8^8; *** *** int and real are not unifiable + +---------------------------------------------------------------------- +====> ../lus2lic -vl 2 --compile-all-items should_fail/type/parametric_node.lus +Opening file should_fail/type/parametric_node.lus +*** Error in file "should_fail/type/parametric_node.lus", line 3, col 60 to 62, token 'int': +*** Bad (static) type argument: 'real' and 'int' differs. + + +---------------------------------------------------------------------- +====> ../lus2lic -vl 2 --compile-all-items should_fail/type/parametric_node2.lus +Opening file should_fail/type/parametric_node2.lus +*** Error in file "should_fail/type/parametric_node2.lus", line 12, col 23 to 35, token 'Lustre::iplus': +*** Bad (static) node argument: wrong output type profile. + + +---------------------------------------------------------------------- +====> ../lus2lic -vl 2 --compile-all-items should_fail/type/parametric_node3.lus +Opening file should_fail/type/parametric_node3.lus +*** Error in file "should_fail/type/parametric_node3.lus", line 10, col 18 to 23, token 'toto_n': +*** Bad number of (static) arguments: 3 expected, and 2 provided. + + +---------------------------------------------------------------------- +====> ../lus2lic -vl 2 --compile-all-items should_fail/type/parametric_node4.lus +Opening file should_fail/type/parametric_node4.lus +const parametric_node4::x = 3.0; +*** Error in file "should_fail/type/parametric_node4.lus", line 3, col 60 to 62, token 'int': +*** Bad (static) type argument: 'real' and 'int' differs. +