diff --git a/src/passes/2-simplify/ligodity.ml b/src/passes/2-simplify/ligodity.ml index 9450f117c..68e5b136f 100644 --- a/src/passes/2-simplify/ligodity.ml +++ b/src/passes/2-simplify/ligodity.ml @@ -49,17 +49,6 @@ module Errors = struct ] in error ~data title message - let unsupported_arith_op expr = - let title () = "arithmetic expressions" in - let message () = - Format.asprintf "this arithmetic operator is not supported yet" in - let expr_loc = Raw.expr_to_region expr in - let data = [ - ("expr_loc", - fun () -> Format.asprintf "%a" Location.pp_lift @@ expr_loc) - ] in - error ~data title message - let untyped_fun_param var = let title () = "function parameter" in let message () = @@ -425,8 +414,7 @@ let rec simpl_expression : let n = Z.to_int @@ snd @@ n in return @@ e_literal ~loc (Literal_mutez n) ) - | EArith _ as e -> - fail @@ unsupported_arith_op e + | EArith (Neg e) -> simpl_unop "NEG" e | EString (String s) -> ( let (s , loc) = r_split s in let s' = diff --git a/src/test/contracts/arithmetic.mligo b/src/test/contracts/arithmetic.mligo new file mode 100644 index 000000000..3dd91648a --- /dev/null +++ b/src/test/contracts/arithmetic.mligo @@ -0,0 +1,11 @@ +// Test CameLIGO arithmetic operators + +let neg_op (n : int) : int = + -n + +let foo (n : int) : int = n + 10 + +let neg_op_2 (b: int) : int = -(foo b) + + + diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 10f4d4d06..cbd750f1b 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -178,6 +178,16 @@ let arithmetic () : unit result = let%bind () = expect_eq_n_pos program "div_op" e_int (fun n -> e_int (n / 2)) in ok () +let arithmetic_mligo () : unit result = + let%bind program = mtype_file "./contracts/arithmetic.mligo" in + let%bind _ = + let aux (name , f) = expect_eq_n_int program name f in + bind_map_list aux [ + ("neg_op", fun n -> (-n)) ; + ("neg_op_2", fun n -> -(n + 10)) ; + ] in + ok () + let bitwise_arithmetic () : unit result = let%bind program = type_file "./contracts/bitwise_arithmetic.ligo" in let%bind () = expect_eq program "or_op" (e_nat 7) (e_nat 7) in @@ -1010,6 +1020,7 @@ let main = test_suite "Integration (End to End)" [ test "multiple parameters" multiple_parameters ; test "bool" bool_expression ; test "arithmetic" arithmetic ; + test "arithmetic (mligo)" arithmetic_mligo ; test "bitwise_arithmetic" bitwise_arithmetic ; test "bitwise_arithmetic (mligo)" bitwise_arithmetic_mligo; test "string_arithmetic" string_arithmetic ;