diff --git a/src/passes/7-self_mini_c/self_mini_c.ml b/src/passes/7-self_mini_c/self_mini_c.ml index 7a12a9216..4230effeb 100644 --- a/src/passes/7-self_mini_c/self_mini_c.ml +++ b/src/passes/7-self_mini_c/self_mini_c.ml @@ -31,7 +31,7 @@ let is_pure_constant : constant -> bool = | C_HASH_KEY | C_BYTES_PACK | C_CONCAT -> true (* unfortunately impure: *) - | C_ADD | C_SUB |C_MUL|C_DIV|C_MOD + | C_ADD | C_SUB |C_MUL|C_DIV|C_MOD | C_LSL | C_LSR (* impure: *) | C_ASSERTION | C_ASSERT_INFERRED | C_MAP_FIND diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 57154d0cc..9025b3295 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -87,6 +87,8 @@ module Simplify = struct | "bitwise_or" -> ok C_OR | "bitwise_and" -> ok C_AND | "bitwise_xor" -> ok C_XOR + | "bitwise_lsl" -> ok C_LSL + | "bitwise_lsr" -> ok C_LSR | "string_concat" -> ok C_CONCAT | "string_slice" -> ok C_SLICE | "crypto_check" -> ok C_CHECK_SIGNATURE @@ -209,6 +211,8 @@ module Simplify = struct | "Bitwise.lor" -> ok C_OR | "Bitwise.land" -> ok C_AND | "Bitwise.lxor" -> ok C_XOR + | "Bitwise.shift_left" -> ok C_LSL + | "Bitwise.shift_right" -> ok C_LSR | "String.length" -> ok C_SIZE | "String.size" -> ok C_SIZE @@ -396,6 +400,8 @@ module Typer = struct | C_AND -> ok @@ failwith "t_and" ; | C_OR -> ok @@ failwith "t_or" ; | C_XOR -> ok @@ failwith "t_xor" ; + | C_LSL -> ok @@ failwith "t_lsl" ; + | C_LSR -> ok @@ failwith "t_lsr" ; (* COMPARATOR *) | C_EQ -> ok @@ failwith "t_comparator EQ" ; | C_NEQ -> ok @@ failwith "t_comparator NEQ" ; @@ -994,6 +1000,8 @@ module Typer = struct | C_AND -> ok @@ and_ ; | C_OR -> ok @@ or_ ; | C_XOR -> ok @@ xor ; + | C_LSL -> ok @@ lsl_; + | C_LSR -> ok @@ lsr_; (* COMPARATOR *) | C_EQ -> ok @@ comparator "EQ" ; | C_NEQ -> ok @@ comparator "NEQ" ; @@ -1089,6 +1097,8 @@ module Compiler = struct | C_OR -> ok @@ simple_binary @@ prim I_OR | C_AND -> ok @@ simple_binary @@ prim I_AND | C_XOR -> ok @@ simple_binary @@ prim I_XOR + | C_LSL -> ok @@ simple_binary @@ prim I_LSL + | C_LSR -> ok @@ simple_binary @@ prim I_LSR | C_NOT -> ok @@ simple_unary @@ prim I_NOT | C_PAIR -> ok @@ simple_binary @@ prim I_PAIR | C_CAR -> ok @@ simple_unary @@ prim I_CAR diff --git a/src/stages/common/PP.ml b/src/stages/common/PP.ml index a47965e57..1b9e7b4eb 100644 --- a/src/stages/common/PP.ml +++ b/src/stages/common/PP.ml @@ -45,6 +45,8 @@ let constant ppf : constant -> unit = function | C_AND -> fprintf ppf "AND" | C_OR -> fprintf ppf "OR" | C_XOR -> fprintf ppf "XOR" + | C_LSL -> fprintf ppf "LSL" + | C_LSR -> fprintf ppf "LSR" (* COMPARATOR *) | C_EQ -> fprintf ppf "EQ" | C_NEQ -> fprintf ppf "NEQ" diff --git a/src/stages/common/types.ml b/src/stages/common/types.ml index 1d65e14d5..e87b0682a 100644 --- a/src/stages/common/types.ml +++ b/src/stages/common/types.ml @@ -162,6 +162,8 @@ type constant = | C_AND | C_OR | C_XOR + | C_LSL + | C_LSR (* COMPARATOR *) | C_EQ | C_NEQ diff --git a/src/test/contracts/bitwise_arithmetic.ligo b/src/test/contracts/bitwise_arithmetic.ligo index 282b82be9..ce40fab44 100644 --- a/src/test/contracts/bitwise_arithmetic.ligo +++ b/src/test/contracts/bitwise_arithmetic.ligo @@ -1,10 +1,16 @@ // Test PascaLIGO bitwise operators function or_op (const n : nat) : nat is - begin skip end with bitwise_or(n , 4n) + bitwise_or(n , 4n) function and_op (const n : nat) : nat is - begin skip end with bitwise_and(n , 7n) + bitwise_and(n , 7n) function xor_op (const n : nat) : nat is - begin skip end with bitwise_xor(n , 7n) + bitwise_xor(n , 7n) + +function lsl_op (const n : nat) : nat is + bitwise_lsl(n , 7n) + +function lsr_op (const n : nat) : nat is + bitwise_lsr(n , 7n) \ No newline at end of file diff --git a/src/test/contracts/bitwise_arithmetic.mligo b/src/test/contracts/bitwise_arithmetic.mligo index a62c702c3..a56375f81 100644 --- a/src/test/contracts/bitwise_arithmetic.mligo +++ b/src/test/contracts/bitwise_arithmetic.mligo @@ -3,3 +3,5 @@ let or_op (n: nat) : nat = Bitwise.lor n 4n let and_op (n: nat) : nat = Bitwise.land n 7n let xor_op (n: nat) : nat = Bitwise.lxor n 7n +let lsl_op (n: nat) : nat = Bitwise.shift_left n 7n +let lsr_op (n: nat) : nat = Bitwise.shift_right n 7n diff --git a/src/test/contracts/bitwise_arithmetic.religo b/src/test/contracts/bitwise_arithmetic.religo index c5e2c7837..2cc390b8a 100644 --- a/src/test/contracts/bitwise_arithmetic.religo +++ b/src/test/contracts/bitwise_arithmetic.religo @@ -3,3 +3,5 @@ let or_op = (n: nat): nat => Bitwise.lor(n, 4n); let and_op = (n: nat): nat => Bitwise.land(n, 7n); let xor_op = (n: nat): nat => Bitwise.lxor(n, 7n); +let lsl_op = (n: nat) : nat => Bitwise.shift_left(n, 7n); +let lsr_op = (n: nat) : nat => Bitwise.shift_right(n, 7n); \ No newline at end of file diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 247832641..13d03872e 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -348,6 +348,8 @@ let bitwise_arithmetic () : unit result = 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 + let%bind () = expect_eq program "lsl_op" (e_nat 1000) (e_nat 128000) in + let%bind () = expect_eq program "lsr_op" (e_nat 128000) (e_nat 1000) in ok () let bitwise_arithmetic_mligo () : unit result = @@ -364,6 +366,8 @@ let bitwise_arithmetic_mligo () : unit result = 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 + let%bind () = expect_eq program "lsl_op" (e_nat 1000) (e_nat 128000) in + let%bind () = expect_eq program "lsr_op" (e_nat 128000) (e_nat 1000) in ok () let bitwise_arithmetic_religo () : unit result = @@ -380,6 +384,8 @@ let bitwise_arithmetic_religo () : unit result = 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 + let%bind () = expect_eq program "lsl_op" (e_nat 1000) (e_nat 128000) in + let%bind () = expect_eq program "lsr_op" (e_nat 128000) (e_nat 1000) in ok () let string_arithmetic () : unit result =