Michelson: add AND of int and nat
This commit is contained in:
parent
60136c13b2
commit
303c43b742
@ -730,11 +730,12 @@ Bitwise logical operators are also available on unsigned integers.
|
|||||||
|
|
||||||
> OR / x : y : S => (x | y) : S
|
> OR / x : y : S => (x | y) : S
|
||||||
|
|
||||||
- ``AND``
|
- ``AND`` (also available when the top operand is signed)
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
:: nat : nat : 'S -> nat : 'S
|
:: nat : nat : 'S -> nat : 'S
|
||||||
|
:: int : nat : 'S -> nat : 'S
|
||||||
|
|
||||||
> AND / x : y : S => (x & y) : S
|
> AND / x : y : S => (x & y) : S
|
||||||
|
|
||||||
@ -749,7 +750,8 @@ Bitwise logical operators are also available on unsigned integers.
|
|||||||
- ``NOT`` The return type of ``NOT`` is an ``int`` and not a ``nat``.
|
- ``NOT`` The return type of ``NOT`` is an ``int`` and not a ``nat``.
|
||||||
This is because the sign is also negated. The resulting integer is
|
This is because the sign is also negated. The resulting integer is
|
||||||
computed using two’s complement. For instance, the boolean negation
|
computed using two’s complement. For instance, the boolean negation
|
||||||
of ``0`` is ``-1``.
|
of ``0`` is ``-1``. To get a natural back, a possibility is to use
|
||||||
|
``AND`` with an unsigned mask afterwards.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
@ -101,7 +101,6 @@ val int : n num -> z num
|
|||||||
Also applies to the sign. *)
|
Also applies to the sign. *)
|
||||||
val lognot : _ num -> z num
|
val lognot : _ num -> z num
|
||||||
|
|
||||||
|
|
||||||
(** Shifts the natural to the left of a number of bits between 0 and 256.
|
(** Shifts the natural to the left of a number of bits between 0 and 256.
|
||||||
Returns [None] if the amount is too high. *)
|
Returns [None] if the amount is too high. *)
|
||||||
val shift_left_n : n num -> n num -> n num option
|
val shift_left_n : n num -> n num -> n num option
|
||||||
@ -119,10 +118,10 @@ val shift_left : 'a num -> n num -> 'a num option
|
|||||||
val shift_right : 'a num -> n num -> 'a num option
|
val shift_right : 'a num -> n num -> 'a num option
|
||||||
|
|
||||||
(** Applies a boolean or operation to each bit. *)
|
(** Applies a boolean or operation to each bit. *)
|
||||||
val logor : n num -> n num -> n num
|
val logor : 'a num -> 'a num -> 'a num
|
||||||
|
|
||||||
(** Applies a boolean and operation to each bit. *)
|
(** Applies a boolean and operation to each bit. *)
|
||||||
val logand : n num -> n num -> n num
|
val logand : _ num -> n num -> n num
|
||||||
|
|
||||||
(** Applies a boolean xor operation to each bit. *)
|
(** Applies a boolean xor operation to each bit. *)
|
||||||
val logxor : n num -> n num -> n num
|
val logxor : n num -> n num -> n num
|
||||||
|
@ -547,6 +547,8 @@ let rec interp
|
|||||||
consume_gas_binop descr (Script_int.logor, x, y) Interp_costs.logor rest ctxt
|
consume_gas_binop descr (Script_int.logor, x, y) Interp_costs.logor rest ctxt
|
||||||
| And_nat, Item (x, Item (y, rest)) ->
|
| And_nat, Item (x, Item (y, rest)) ->
|
||||||
consume_gas_binop descr (Script_int.logand, x, y) Interp_costs.logand rest ctxt
|
consume_gas_binop descr (Script_int.logand, x, y) Interp_costs.logand rest ctxt
|
||||||
|
| And_int_nat, Item (x, Item (y, rest)) ->
|
||||||
|
consume_gas_binop descr (Script_int.logand, x, y) Interp_costs.logand rest ctxt
|
||||||
| Xor_nat, Item (x, Item (y, rest)) ->
|
| Xor_nat, Item (x, Item (y, rest)) ->
|
||||||
consume_gas_binop descr (Script_int.logxor, x, y) Interp_costs.logxor rest ctxt
|
consume_gas_binop descr (Script_int.logxor, x, y) Interp_costs.logxor rest ctxt
|
||||||
| Not_int, Item (x, rest) ->
|
| Not_int, Item (x, rest) ->
|
||||||
|
@ -173,6 +173,7 @@ let number_of_generated_growing_types : type b a. (b, a) instr -> int = function
|
|||||||
| Lsr_nat -> 0
|
| Lsr_nat -> 0
|
||||||
| Or_nat -> 0
|
| Or_nat -> 0
|
||||||
| And_nat -> 0
|
| And_nat -> 0
|
||||||
|
| And_int_nat -> 0
|
||||||
| Xor_nat -> 0
|
| Xor_nat -> 0
|
||||||
| Not_nat -> 0
|
| Not_nat -> 0
|
||||||
| Not_int -> 0
|
| Not_int -> 0
|
||||||
@ -1955,6 +1956,10 @@ and parse_instr
|
|||||||
Item_t (Nat_t, Item_t (Nat_t, rest, _), _) ->
|
Item_t (Nat_t, Item_t (Nat_t, rest, _), _) ->
|
||||||
typed ctxt loc And_nat
|
typed ctxt loc And_nat
|
||||||
(Item_t (Nat_t, rest, instr_annot))
|
(Item_t (Nat_t, rest, instr_annot))
|
||||||
|
| Prim (loc, I_AND, [], instr_annot),
|
||||||
|
Item_t (Int_t, Item_t (Nat_t, rest, _), _) ->
|
||||||
|
typed ctxt loc And_int_nat
|
||||||
|
(Item_t (Nat_t, rest, instr_annot))
|
||||||
| Prim (loc, I_XOR, [], instr_annot),
|
| Prim (loc, I_XOR, [], instr_annot),
|
||||||
Item_t (Nat_t, Item_t (Nat_t, rest, _), _) ->
|
Item_t (Nat_t, Item_t (Nat_t, rest, _), _) ->
|
||||||
typed ctxt loc Xor_nat
|
typed ctxt loc Xor_nat
|
||||||
|
@ -276,6 +276,8 @@ and ('bef, 'aft) instr =
|
|||||||
(n num * (n num * 'rest), n num * 'rest) instr
|
(n num * (n num * 'rest), n num * 'rest) instr
|
||||||
| And_nat :
|
| And_nat :
|
||||||
(n num * (n num * 'rest), n num * 'rest) instr
|
(n num * (n num * 'rest), n num * 'rest) instr
|
||||||
|
| And_int_nat :
|
||||||
|
(z num * (n num * 'rest), n num * 'rest) instr
|
||||||
| Xor_nat :
|
| Xor_nat :
|
||||||
(n num * (n num * 'rest), n num * 'rest) instr
|
(n num * (n num * 'rest), n num * 'rest) instr
|
||||||
| Not_nat :
|
| Not_nat :
|
||||||
|
Loading…
Reference in New Issue
Block a user