From 080b25a3bd817269cf09af4ac55cfcfd60e5289e Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Fri, 18 Oct 2019 14:32:58 +0200 Subject: [PATCH] WIP: add test. still have two ECond implementation, none of them pass the test --- src/passes/2-simplify/pascaligo.ml | 28 +++++++++++----------------- src/test/contracts/condition.ligo | 6 ++++++ src/test/integration_tests.ml | 13 ++++++++++--- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/passes/2-simplify/pascaligo.ml b/src/passes/2-simplify/pascaligo.ml index 42a33d930..591e61180 100644 --- a/src/passes/2-simplify/pascaligo.ml +++ b/src/passes/2-simplify/pascaligo.ml @@ -379,28 +379,22 @@ let rec simpl_expression (t:Raw.expr) : expr result = | ELogic l -> simpl_logic_expression l | EList l -> simpl_list_expression l | ESet s -> simpl_set_expression s - | ECond _ -> ( failwith "TODO" -(* - let (c , loc) = r_split c in + | ECond c -> (*fail @@ simple_error "TODO"*) + (* let (c , loc) = r_split c in let%bind expr = simpl_expression c.test in - let%bind match_true = simpl_expression c.ifso in let%bind match_false = simpl_expression c.ifnot in + return @@ e_matching expr ~loc (Match_bool {match_true; match_false}) *) - let%bind match_true = match_true None in - let%bind match_false = match_false None in - return @@ e_matching expr ~loc (Match_bool {match_true; match_false}) -*) - -(* - let%bind lst = - bind_list @@ - [ok (Raw.PTrue Region.ghost, simpl_expression c.ifso); - ok (Raw.PFalse Region.ghost, simpl_expression c.ifnot)] in + let (c , loc) = r_split c in + let%bind expr = simpl_expression c.test in + let%bind match_true = simpl_expression c.ifso in + let%bind match_false = simpl_expression c.ifnot in + let%bind lst = ok @@ + [(Raw.PTrue Region.ghost, match_true); + (Raw.PFalse Region.ghost, match_false)] in let%bind cases = simpl_cases lst in - return @@ e_matching ~loc e cases -*) - ) + return @@ e_matching ~loc expr cases | ECase c -> ( let (c , loc) = r_split c in let%bind e = simpl_expression c.expr in diff --git a/src/test/contracts/condition.ligo b/src/test/contracts/condition.ligo index 98672b1c9..53a75ed07 100644 --- a/src/test/contracts/condition.ligo +++ b/src/test/contracts/condition.ligo @@ -8,3 +8,9 @@ function main (const i : int) : int is else result := 0 end with result + +function foo (const b : bool) : int is + var x : int := 41 ; + begin + x := 1 + (if b then x else main(x)) ; + end with x \ No newline at end of file diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 6726d66b5..8f7cd5415 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -587,9 +587,16 @@ let list () : unit result = let condition () : unit result = let%bind program = type_file "./contracts/condition.ligo" in - let make_input = e_int in - let make_expected = fun n -> e_int (if n = 2 then 42 else 0) in - expect_eq_n program "main" make_input make_expected + let%bind _ = + let make_input = e_int in + let make_expected = fun n -> e_int (if n = 2 then 42 else 0) in + expect_eq_n program "main" make_input make_expected + in + let%bind _ = + let make_expected = fun b -> e_int (if b then 42 else 1) in + expect_eq_b program "main" make_expected + in + ok () let condition_simple () : unit result = let%bind program = type_file "./contracts/condition-simple.ligo" in