-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_int_repr.ml
68 lines (53 loc) · 1.73 KB
/
script_int_repr.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
open Environment.Env
type n = Natural_tag
type z = Integer_tag
type 't num = Z.t
let compare x y = Z.compare x y
let zero = Z.zero
let zero_n = Z.zero
let to_string x = Z.to_string x
let of_string s = try Some (Z.of_string s) with _ -> None
let to_int64 x = try Some (Z.to_int64 x) with _ -> None
let of_int64 n = Z.of_int64 n
let to_int x = try Some (Z.to_int x) with _ -> None
let of_int n = Z.of_int n
let add x y = Z.add x y
let sub x y = Z.sub x y
let mul x y = Z.mul x y
let ediv x y =
try
let (q, r) = Z.ediv_rem x y in
Some (q, r)
with _ -> None
let add_n = add
let mul_n = mul
let ediv_n = ediv
let abs x = Z.abs x
let neg x = Z.neg x
let int x = x
let shift_left x y =
if Compare.Int.(Z.compare y (Z.of_int 256) > 0) then
None
else
let y = Z.to_int y in
Some (Z.shift_left x y)
let shift_right x y =
if Compare.Int.(Z.compare y (Z.of_int 256) > 0) then
None
else
let y = Z.to_int y in
Some (Z.shift_right x y)
let shift_left_n = shift_left
let shift_right_n = shift_right
let logor x y = Z.logor x y
let logxor x y = Z.logxor x y
let logand x y = Z.logand x y
let lognot x = Z.lognot x