some cleaning

This commit is contained in:
Lesenechal Remi 2019-10-15 13:56:21 +02:00
parent 1d3d57c7c5
commit 536b5648c8

View File

@ -969,12 +969,12 @@ and simpl_block : Raw.block -> (_ -> expression result) result = fun t ->
and simpl_for_int : Raw.for_int -> (_ -> expression result) result = fun fi -> and simpl_for_int : Raw.for_int -> (_ -> expression result) result = fun fi ->
(* cond part *) (* cond part *)
let%bind var = ok @@ e_variable fi.assign.value.name.value in let var = e_variable fi.assign.value.name.value in
let%bind value = simpl_expression fi.assign.value.expr in let%bind value = simpl_expression fi.assign.value.expr in
let%bind bound = simpl_expression fi.bound in let%bind bound = simpl_expression fi.bound in
let%bind comp = match fi.down with let comp = match fi.down with
| Some _ -> ok @@ e_annotation (e_constant "GE" [var ; bound]) t_bool | Some _ -> e_annotation (e_constant "GE" [var ; bound]) t_bool
| None -> ok @@ e_annotation (e_constant "LE" [var ; bound]) t_bool | None -> e_annotation (e_constant "LE" [var ; bound]) t_bool
in in
(* body part *) (* body part *)
let%bind body = simpl_block fi.block.value in let%bind body = simpl_block fi.block.value in
@ -982,32 +982,29 @@ and simpl_for_int : Raw.for_int -> (_ -> expression result) result = fun fi ->
let%bind step = match fi.step with let%bind step = match fi.step with
| Some (_,e) -> simpl_expression e | Some (_,e) -> simpl_expression e
| None -> ok (e_int 1) in | None -> ok (e_int 1) in
let%bind ctrl = match fi.down with let ctrl = match fi.down with
| Some _ -> | Some _ ->
let%bind _addi = ok @@ e_constant "SUB" [ var ; step ] in let _addi = e_constant "SUB" [ var ; step ] in
ok @@ e_assign fi.assign.value.name.value [] _addi e_assign fi.assign.value.name.value [] _addi
| None -> | None ->
let%bind _subi = ok @@ e_constant "ADD" [ var ; step ] in let _subi = e_constant "ADD" [ var ; step ] in
ok @@ e_assign fi.assign.value.name.value [] _subi e_assign fi.assign.value.name.value [] _subi
in in
let rec add_to_seq expr = match expr.expression with let rec add_to_seq expr = match expr.expression with
| E_sequence (_,a) -> add_to_seq a | E_sequence (_,a) -> add_to_seq a
| _ -> e_sequence body ctrl in | _ -> e_sequence body ctrl in
let%bind body' = ok @@ add_to_seq body in let body' = add_to_seq body in
let%bind loop = ok @@ e_loop comp body' in let loop = e_loop comp body' in
return_statement @@ e_let_in (fi.assign.value.name.value, Some t_int) value loop return_statement @@ e_let_in (fi.assign.value.name.value, Some t_int) value loop
and simpl_for_collect : Raw.for_collect -> (_ -> expression result) result = fun fc -> and simpl_for_collect : Raw.for_collect -> (_ -> expression result) result = fun fc ->
let%bind col = simpl_expression fc.expr in let%bind col = simpl_expression fc.expr in
let%bind body = simpl_block fc.block.value in let%bind body = simpl_block fc.block.value in
let%bind body = body None in let%bind body = body None in
let invar = e_variable fc.var.value in
let%bind invar = ok @@ e_variable fc.var.value in let letin = e_let_in (fc.var.value, None) invar body in
let%bind letin = ok @@ e_let_in (fc.var.value, None) invar body in let lambda = e_lambda fc.var.value None (Some t_unit) letin in
let%bind lambda = ok @@ e_lambda fc.var.value None (Some t_unit) letin in
(* let%bind lambda = ok @@ e_lambda fc.var.value None (Some t_unit) body in *) (* let%bind lambda = ok @@ e_lambda fc.var.value None (Some t_unit) body in *)
return_statement @@ e_constant "SET_ITER" [col ; lambda] return_statement @@ e_constant "SET_ITER" [col ; lambda]
let simpl_program : Raw.ast -> program result = fun t -> let simpl_program : Raw.ast -> program result = fun t ->