Merge branch 'add_lsl_lsr' into 'dev'

Add lsl and lsr support.

Closes #146

See merge request ligolang/ligo!387
This commit is contained in:
Sander 2020-02-07 11:08:13 +00:00
commit bd4a75016d
8 changed files with 34 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -162,6 +162,8 @@ type constant =
| C_AND
| C_OR
| C_XOR
| C_LSL
| C_LSR
(* COMPARATOR *)
| C_EQ
| C_NEQ

View File

@ -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)

View File

@ -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

View File

@ -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);

View File

@ -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 =