Fixed code generation of n-dim static arrays

Also added some tests.
This commit is contained in:
Cédric Pasteur 2011-07-21 11:19:07 +02:00
parent d20932e13c
commit 69a5ad8df8
4 changed files with 45 additions and 4 deletions

View file

@ -94,18 +94,31 @@ let rec ext_value_of_trunc_idx_list p l =
in
aux p l
let rec ty_of_idx_list ty idx_list = match ty, idx_list with
| _, [] -> ty
| Tarray(ty, _), idx::idx_list -> ty_of_idx_list ty idx_list
| _, _ -> internal_error "mls2obc ty_of_idx_list"
let mk_static_array_power ty c params = match params with
| [] -> mk_ext_value_exp ty (Wconst c)
| _ ->
let se = mk_static_exp ty (Sarray_power (c, params)) in
mk_ext_value_exp ty (Wconst se)
let array_elt_of_exp idx e =
match e.e_desc, Modules.unalias_type e.e_ty with
| Eextvalue { w_desc = Wconst { se_desc = Sarray_power (c, _) }; }, Tarray (ty,_) ->
mk_ext_value_exp ty (Wconst c) (* TODO BUG : (4^2^2^2)[0][1] is not 4, but 4^2 *)
| Eextvalue { w_desc = Wconst { se_desc = Sarray_power (c, _::new_params) }; }, Tarray (ty,_) ->
mk_static_array_power ty c new_params
| _, Tarray (ty,_) ->
mk_ext_value_exp ty (Warray(ext_value_of_exp e, idx))
| _ -> internal_error "mls2obc array_elt_of_exp"
let rec array_elt_of_exp_list idx_list e =
match e.e_desc, Modules.unalias_type e.e_ty with
| Eextvalue { w_desc = Wconst { se_desc = Sarray_power (c, _) } }, Tarray (ty,_) ->
mk_ext_value_exp ty (Wconst c) (* TODO BUG : (4^2^2^2)[0][1] is not 4, but 4^2 *)
| Eextvalue { w_desc = Wconst { se_desc = Sarray_power (c, params) } }, Tarray (ty,n) ->
let new_params, _ = Misc.split_at (List.length params - List.length idx_list) params in
let ty = ty_of_idx_list (Tarray(ty,n)) idx_list in
mk_static_array_power ty c new_params
| _ , t ->
let rec ty id_l t = match id_l, Modules.unalias_type t with
| [] , t -> t

View file

@ -0,0 +1,4 @@
node f() returns (o:int^2^3^4)
let
o = (2^2^3^4)[0][1]
tel

14
test/good/array_power.ept Normal file
View file

@ -0,0 +1,14 @@
node f() returns (o:int^2)
let
o = (2^2^3^4)[0][1]
tel
node plus_tab(a: int^2^10) returns (o:int^2^10)
let
o = a
tel
node g() returns (o:int^2^10^3^4)
let
o = map<<3,4>> plus_tab (2^2^10^3^4);
tel

10
test/good/tuple_args.ept Executable file
View file

@ -0,0 +1,10 @@
fun f(a,b:int) returns (u,v:int)
let
u = a + b;
v = a * b;
tel
fun h(a,b:int) returns (u,v:int)
let
(u,v) = f(f(a,b));
tel