diff --git a/src/passes/1-parser/ligodity/LexToken.mll b/src/passes/1-parser/ligodity/LexToken.mll index e286ff245..45794559c 100644 --- a/src/passes/1-parser/ligodity/LexToken.mll +++ b/src/passes/1-parser/ligodity/LexToken.mll @@ -280,12 +280,9 @@ let reserved = |> add "functor" |> add "inherit" |> add "initializer" - |> add "land" |> add "lazy" - |> add "lor" |> add "lsl" |> add "lsr" - |> add "lxor" |> add "method" |> add "module" |> add "mutable" diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index b80a8d8f2..6638c352e 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -177,6 +177,10 @@ module Simplify = struct ("Big_map.literal" , "BIG_MAP_LITERAL" ) ; ("Big_map.empty" , "BIG_MAP_EMPTY" ) ; + ("Bitwise.lor" , "OR") ; + ("Bitwise.land" , "AND") ; + ("Bitwise.lxor" , "XOR") ; + ("String.length", "SIZE") ; ("String.size", "SIZE") ; ("String.slice", "SLICE") ; diff --git a/src/test/contracts/bitwise_arithmetic.mligo b/src/test/contracts/bitwise_arithmetic.mligo new file mode 100644 index 000000000..831592c70 --- /dev/null +++ b/src/test/contracts/bitwise_arithmetic.mligo @@ -0,0 +1,10 @@ +(* Test CameLIGO bitwise operators *) + +let or_op (n : nat) : nat = + Bitwise.lor n 4p + +let and_op (n : nat) : nat = + Bitwise.land n 7p + +let xor_op (n : nat) : nat = + Bitwise.lxor n 7p diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 09e511322..ed60a0966 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -194,6 +194,22 @@ let bitwise_arithmetic () : unit result = let%bind () = expect_eq program "xor_op" (e_nat 7) (e_nat 0) in ok () +let bitwise_arithmetic_mligo () : unit result = + let%bind program = mtype_file "./contracts/bitwise_arithmetic.mligo" in + let%bind () = expect_eq program "or_op" (e_nat 7) (e_nat 7) in + let%bind () = expect_eq program "or_op" (e_nat 3) (e_nat 7) in + let%bind () = expect_eq program "or_op" (e_nat 2) (e_nat 6) in + let%bind () = expect_eq program "or_op" (e_nat 14) (e_nat 14) in + let%bind () = expect_eq program "or_op" (e_nat 10) (e_nat 14) in + let%bind () = expect_eq program "and_op" (e_nat 7) (e_nat 7) in + let%bind () = expect_eq program "and_op" (e_nat 3) (e_nat 3) in + let%bind () = expect_eq program "and_op" (e_nat 2) (e_nat 2) in + let%bind () = expect_eq program "and_op" (e_nat 14) (e_nat 6) in + let%bind () = expect_eq program "and_op" (e_nat 10) (e_nat 2) in + let%bind () = expect_eq program "xor_op" (e_nat 0) (e_nat 7) in + let%bind () = expect_eq program "xor_op" (e_nat 7) (e_nat 0) in + ok () + let string_arithmetic () : unit result = let%bind program = type_file "./contracts/string_arithmetic.ligo" in let%bind () = expect_eq program "concat_op" (e_string "foo") (e_string "foototo") in @@ -960,7 +976,8 @@ let main = test_suite "Integration (End to End)" [ test "multiple parameters" multiple_parameters ; test "bool" bool_expression ; test "arithmetic" arithmetic ; - test "bitiwse_arithmetic" bitwise_arithmetic ; + test "bitwise_arithmetic" bitwise_arithmetic ; + test "bitwise_arithmetic (mligo)" bitwise_arithmetic_mligo; test "string_arithmetic" string_arithmetic ; test "string_arithmetic (mligo)" string_arithmetic_mligo ; test "bytes_arithmetic" bytes_arithmetic ;