Merge branch 'dev' of gitlab.com:ligolang/ligo into feature/cameligo-negative-op
This commit is contained in:
commit
dce98c06ec
@ -17,7 +17,7 @@ title: Cheat Sheet
|
|||||||
|Unit| `unit`|
|
|Unit| `unit`|
|
||||||
|Boolean|<pre><code>const hasDriversLicense: bool = False;<br/>const adult: bool = True;</code></pre> |
|
|Boolean|<pre><code>const hasDriversLicense: bool = False;<br/>const adult: bool = True;</code></pre> |
|
||||||
|Boolean Logic|<pre><code>(not True) == False == (False and True) == (False or False)</code></pre>|
|
|Boolean Logic|<pre><code>(not True) == False == (False and True) == (False or False)</code></pre>|
|
||||||
|Mutez (micro tez)| `42mtz`, `7mtz` |
|
|Mutez (micro tez)| `42mutez`, `7mutez` |
|
||||||
|Address | `"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"`, `"KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"`|
|
|Address | `"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"`, `"KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"`|
|
||||||
|Addition |`3 + 4`, `3n + 4n`|
|
|Addition |`3 + 4`, `3n + 4n`|
|
||||||
|Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`|
|
|Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`|
|
||||||
@ -35,11 +35,12 @@ title: Cheat Sheet
|
|||||||
|Variants|<pre><code>type action is<br/>| Increment of int<br/>| Decrement of int</code></pre>|
|
|Variants|<pre><code>type action is<br/>| Increment of int<br/>| Decrement of int</code></pre>|
|
||||||
|Variant *(pattern)* matching|<pre><code>const a: action = Increment(5);<br/>case a of<br/>| Increment(n) -> n + 1<br/>| Decrement(n) -> n - 1<br/>end</code></pre>|
|
|Variant *(pattern)* matching|<pre><code>const a: action = Increment(5);<br/>case a of<br/>| Increment(n) -> n + 1<br/>| Decrement(n) -> n - 1<br/>end</code></pre>|
|
||||||
|Records|<pre><code>type person is record<br/> age: int ;<br/> name: string ;<br/>end<br/><br/>const john : person = record<br/> age = 18;<br/> name = "John Doe";<br/>end<br/><br/>const name: string = john.name;</code></pre>|
|
|Records|<pre><code>type person is record<br/> age: int ;<br/> name: string ;<br/>end<br/><br/>const john : person = record<br/> age = 18;<br/> name = "John Doe";<br/>end<br/><br/>const name: string = john.name;</code></pre>|
|
||||||
|Maps|<pre><code>type prices is map(nat, tez);<br/><br/>const prices : prices = map<br/> 10n -> 60mtz;<br/> 50n -> 30mtz;<br/> 100n -> 10mtz;<br/>end<br/><br/>const price: option(tez) = prices[50n];<br/><br/>prices[200n] := 5mtz;</code></pre>|
|
|Maps|<pre><code>type prices is map(nat, tez);<br/><br/>const prices : prices = map<br/> 10n -> 60mutez;<br/> 50n -> 30mutez;<br/> 100n -> 10mutez;<br/>end<br/><br/>const price: option(tez) = prices[50n];<br/><br/>prices[200n] := 5mutez;</code></pre>|
|
||||||
|Contracts & Accounts|<pre><code>const destinationAddress : address = "tz1...";<br/>const contract : contract(unit) = get_contract(destinationAddress);</code></pre>|
|
|Contracts & Accounts|<pre><code>const destinationAddress : address = "tz1...";<br/>const contract : contract(unit) = get_contract(destinationAddress);</code></pre>|
|
||||||
|Transactions|<pre><code>const payment : operation = transaction(unit, amount, receiver);</code></pre>|
|
|Transactions|<pre><code>const payment : operation = transaction(unit, amount, receiver);</code></pre>|
|
||||||
|Exception/Failure|`fail("Your descriptive error message for the user goes here.")`|
|
|Exception/Failure|`fail("Your descriptive error message for the user goes here.")`|
|
||||||
|
|
||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
</div>
|
</div>
|
@ -31,7 +31,7 @@ const dogBreed: animalBreed = "Saluki";
|
|||||||
type accountBalances is map(address, tez);
|
type accountBalances is map(address, tez);
|
||||||
|
|
||||||
const ledger: accountBalances = map
|
const ledger: accountBalances = map
|
||||||
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) -> 10mtz
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) -> 10mutez
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -60,10 +60,10 @@ end
|
|||||||
type accountBalances is map(account, accountData);
|
type accountBalances is map(account, accountData);
|
||||||
|
|
||||||
// pseudo-JSON representation of our map
|
// pseudo-JSON representation of our map
|
||||||
// { "tz1...": {balance: 10mtz, numberOfTransactions: 5n} }
|
// { "tz1...": {balance: 10mutez, numberOfTransactions: 5n} }
|
||||||
const ledger: accountBalances = map
|
const ledger: accountBalances = map
|
||||||
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) -> record
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) -> record
|
||||||
balance = 10mtz;
|
balance = 10mutez;
|
||||||
numberOfTransactions = 5n;
|
numberOfTransactions = 5n;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -134,11 +134,11 @@ To confirm that our contract is valid, we can dry run it. As a result we see a *
|
|||||||
ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map
|
ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map
|
||||||
1n -> record
|
1n -> record
|
||||||
current_stock = 50n;
|
current_stock = 50n;
|
||||||
max_price = 50000000mtz;
|
max_price = 50000000mutez;
|
||||||
end;
|
end;
|
||||||
2n -> record
|
2n -> record
|
||||||
current_stock = 20n;
|
current_stock = 20n;
|
||||||
max_price = 75000000mtz;
|
max_price = 75000000mutez;
|
||||||
end;
|
end;
|
||||||
end"
|
end"
|
||||||
```
|
```
|
||||||
|
@ -28,8 +28,8 @@ Each taco kind, has its own `max_price` that it sells for, and a finite supply f
|
|||||||
|
|
||||||
|**kind** |id |**available_stock**| **max_price**|
|
|**kind** |id |**available_stock**| **max_price**|
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
|el clásico | `1n` | `50n` | `50000000mtz` |
|
|el clásico | `1n` | `50n` | `50000000mutez` |
|
||||||
|especial del chef | `2n` | `20n` | `75000000mtz` |
|
|especial del chef | `2n` | `20n` | `75000000mutez` |
|
||||||
|
|
||||||
### Calculating the current purchase price
|
### Calculating the current purchase price
|
||||||
|
|
||||||
@ -42,16 +42,16 @@ current_purchase_price = max_price / available_stock
|
|||||||
#### El clásico
|
#### El clásico
|
||||||
|**available_stock**|**max_price**|**current_purchase_price**|
|
|**available_stock**|**max_price**|**current_purchase_price**|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `50n` | `50000000mtz` | `1tz`|
|
| `50n` | `50000000mutez` | `1tz`|
|
||||||
| `20n` | `50000000mtz` | `2.5tz` |
|
| `20n` | `50000000mutez` | `2.5tz` |
|
||||||
| `5n` | `50000000mtz` | `10tz` |
|
| `5n` | `50000000mutez` | `10tz` |
|
||||||
|
|
||||||
#### Especial del chef
|
#### Especial del chef
|
||||||
|**available_stock**|**max_price**|**current_purchase_price**|
|
|**available_stock**|**max_price**|**current_purchase_price**|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `20n` | `75000000mtz` | `3.75tz` |
|
| `20n` | `75000000mutez` | `3.75tz` |
|
||||||
| `10n` | `75000000mtz` | `7.5tz`|
|
| `10n` | `75000000mutez` | `7.5tz`|
|
||||||
| `5n` | `75000000mtz` | `15tz` |
|
| `5n` | `75000000mutez` | `15tz` |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -161,11 +161,11 @@ When dry-running a contract, it's crucial to provide a correct initial storage v
|
|||||||
map
|
map
|
||||||
1n -> record
|
1n -> record
|
||||||
current_stock = 50n;
|
current_stock = 50n;
|
||||||
max_price = 50000000mtz;
|
max_price = 50000000mutez;
|
||||||
end;
|
end;
|
||||||
2n -> record
|
2n -> record
|
||||||
current_stock = 20n;
|
current_stock = 20n;
|
||||||
max_price = 75000000mtz;
|
max_price = 75000000mutez;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
@ -177,11 +177,11 @@ end
|
|||||||
ligo dry-run taco-shop.ligo --syntax pascaligo main unit "map
|
ligo dry-run taco-shop.ligo --syntax pascaligo main unit "map
|
||||||
1n -> record
|
1n -> record
|
||||||
current_stock = 50n;
|
current_stock = 50n;
|
||||||
max_price = 50000000mtz;
|
max_price = 50000000mutez;
|
||||||
end;
|
end;
|
||||||
2n -> record
|
2n -> record
|
||||||
current_stock = 20n;
|
current_stock = 20n;
|
||||||
max_price = 75000000mtz;
|
max_price = 75000000mutez;
|
||||||
end;
|
end;
|
||||||
end"
|
end"
|
||||||
```
|
```
|
||||||
@ -298,11 +298,11 @@ In order to test the `amount` sent, we'll use the `--amount` option of `dry-run`
|
|||||||
ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map
|
ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map
|
||||||
1n -> record
|
1n -> record
|
||||||
current_stock = 50n;
|
current_stock = 50n;
|
||||||
max_price = 50000000mtz;
|
max_price = 50000000mutez;
|
||||||
end;
|
end;
|
||||||
2n -> record
|
2n -> record
|
||||||
current_stock = 20n;
|
current_stock = 20n;
|
||||||
max_price = 75000000mtz;
|
max_price = 75000000mutez;
|
||||||
end;
|
end;
|
||||||
end"
|
end"
|
||||||
```
|
```
|
||||||
|
@ -260,7 +260,7 @@ and arith_expr =
|
|||||||
| Neg of minus un_op reg
|
| Neg of minus un_op reg
|
||||||
| Int of (string * Z.t) reg
|
| Int of (string * Z.t) reg
|
||||||
| Nat of (string * Z.t) reg
|
| Nat of (string * Z.t) reg
|
||||||
| Mtz of (string * Z.t) reg
|
| Mutez of (string * Z.t) reg
|
||||||
|
|
||||||
and logic_expr =
|
and logic_expr =
|
||||||
BoolExpr of bool_expr
|
BoolExpr of bool_expr
|
||||||
@ -391,7 +391,7 @@ let logic_expr_to_region = function
|
|||||||
let arith_expr_to_region = function
|
let arith_expr_to_region = function
|
||||||
Add {region;_} | Sub {region;_} | Mult {region;_}
|
Add {region;_} | Sub {region;_} | Mult {region;_}
|
||||||
| Div {region;_} | Mod {region;_} | Neg {region;_}
|
| Div {region;_} | Mod {region;_} | Neg {region;_}
|
||||||
| Int {region;_} | Mtz {region; _}
|
| Int {region;_} | Mutez {region; _}
|
||||||
| Nat {region; _} -> region
|
| Nat {region; _} -> region
|
||||||
|
|
||||||
let string_expr_to_region = function
|
let string_expr_to_region = function
|
||||||
|
@ -265,7 +265,7 @@ and arith_expr =
|
|||||||
| Neg of minus un_op reg (* -e *)
|
| Neg of minus un_op reg (* -e *)
|
||||||
| Int of (string * Z.t) reg (* 12345 *)
|
| Int of (string * Z.t) reg (* 12345 *)
|
||||||
| Nat of (string * Z.t) reg (* 3p *)
|
| Nat of (string * Z.t) reg (* 3p *)
|
||||||
| Mtz of (string * Z.t) reg (* 1.00tz 3tz *)
|
| Mutez of (string * Z.t) reg (* 1.00tz 3tz *)
|
||||||
|
|
||||||
and logic_expr =
|
and logic_expr =
|
||||||
BoolExpr of bool_expr
|
BoolExpr of bool_expr
|
||||||
|
@ -82,7 +82,7 @@ type t =
|
|||||||
| Constr of string Region.reg
|
| Constr of string Region.reg
|
||||||
| Int of (string * Z.t) Region.reg
|
| Int of (string * Z.t) Region.reg
|
||||||
| Nat of (string * Z.t) Region.reg
|
| Nat of (string * Z.t) Region.reg
|
||||||
| Mtz of (string * Z.t) Region.reg
|
| Mutez of (string * Z.t) Region.reg
|
||||||
| Str of string Region.reg
|
| Str of string Region.reg
|
||||||
| Bytes of (string * Hex.t) Region.reg
|
| Bytes of (string * Hex.t) Region.reg
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ type sym_err = Invalid_symbol
|
|||||||
|
|
||||||
val mk_int : lexeme -> Region.t -> (token, int_err) result
|
val mk_int : lexeme -> Region.t -> (token, int_err) result
|
||||||
val mk_nat : lexeme -> Region.t -> (token, nat_err) result
|
val mk_nat : lexeme -> Region.t -> (token, nat_err) result
|
||||||
val mk_mtz : lexeme -> Region.t -> (token, int_err) result
|
val mk_mutez : lexeme -> Region.t -> (token, int_err) result
|
||||||
val mk_ident : lexeme -> Region.t -> (token, ident_err) result
|
val mk_ident : lexeme -> Region.t -> (token, ident_err) result
|
||||||
val mk_sym : lexeme -> Region.t -> (token, sym_err) result
|
val mk_sym : lexeme -> Region.t -> (token, sym_err) result
|
||||||
val mk_string : lexeme -> Region.t -> token
|
val mk_string : lexeme -> Region.t -> token
|
||||||
|
@ -64,7 +64,7 @@ type t =
|
|||||||
| Constr of string Region.reg
|
| Constr of string Region.reg
|
||||||
| Int of (string * Z.t) Region.reg
|
| Int of (string * Z.t) Region.reg
|
||||||
| Nat of (string * Z.t) Region.reg
|
| Nat of (string * Z.t) Region.reg
|
||||||
| Mtz of (string * Z.t) Region.reg
|
| Mutez of (string * Z.t) Region.reg
|
||||||
| Str of string Region.reg
|
| Str of string Region.reg
|
||||||
| Bytes of (string * Hex.t) Region.reg
|
| Bytes of (string * Hex.t) Region.reg
|
||||||
|
|
||||||
@ -141,8 +141,8 @@ let proj_token = function
|
|||||||
region, sprintf "Int (\"%s\", %s)" s (Z.to_string n)
|
region, sprintf "Int (\"%s\", %s)" s (Z.to_string n)
|
||||||
| Nat Region.{region; value = s,n} ->
|
| Nat Region.{region; value = s,n} ->
|
||||||
region, sprintf "Nat (\"%s\", %s)" s (Z.to_string n)
|
region, sprintf "Nat (\"%s\", %s)" s (Z.to_string n)
|
||||||
| Mtz Region.{region; value = s,n} ->
|
| Mutez Region.{region; value = s,n} ->
|
||||||
region, sprintf "Mtz (\"%s\", %s)" s (Z.to_string n)
|
region, sprintf "Mutez (\"%s\", %s)" s (Z.to_string n)
|
||||||
| Str Region.{region; value} ->
|
| Str Region.{region; value} ->
|
||||||
region, sprintf "Str %s" value
|
region, sprintf "Str %s" value
|
||||||
| Bytes Region.{region; value = s,b} ->
|
| Bytes Region.{region; value = s,b} ->
|
||||||
@ -202,7 +202,7 @@ let to_lexeme = function
|
|||||||
| Constr id -> id.Region.value
|
| Constr id -> id.Region.value
|
||||||
| Int i
|
| Int i
|
||||||
| Nat i
|
| Nat i
|
||||||
| Mtz i -> fst i.Region.value
|
| Mutez i -> fst i.Region.value
|
||||||
| Str s -> s.Region.value
|
| Str s -> s.Region.value
|
||||||
| Bytes b -> fst b.Region.value
|
| Bytes b -> fst b.Region.value
|
||||||
| Begin _ -> "begin"
|
| Begin _ -> "begin"
|
||||||
@ -280,12 +280,9 @@ let reserved =
|
|||||||
|> add "functor"
|
|> add "functor"
|
||||||
|> add "inherit"
|
|> add "inherit"
|
||||||
|> add "initializer"
|
|> add "initializer"
|
||||||
|> add "land"
|
|
||||||
|> add "lazy"
|
|> add "lazy"
|
||||||
|> add "lor"
|
|
||||||
|> add "lsl"
|
|> add "lsl"
|
||||||
|> add "lsr"
|
|> add "lsr"
|
||||||
|> add "lxor"
|
|
||||||
|> add "method"
|
|> add "method"
|
||||||
|> add "module"
|
|> add "module"
|
||||||
|> add "mutable"
|
|> add "mutable"
|
||||||
@ -396,14 +393,14 @@ let mk_nat lexeme region =
|
|||||||
else Ok (Nat Region.{region; value = lexeme, z})
|
else Ok (Nat Region.{region; value = lexeme, z})
|
||||||
)
|
)
|
||||||
|
|
||||||
let mk_mtz lexeme region =
|
let mk_mutez lexeme region =
|
||||||
let z =
|
let z =
|
||||||
Str.(global_replace (regexp "_") "" lexeme) |>
|
Str.(global_replace (regexp "_") "" lexeme) |>
|
||||||
Str.(global_replace (regexp "mtz") "") |>
|
Str.(global_replace (regexp "mutez") "") |>
|
||||||
Z.of_string in
|
Z.of_string in
|
||||||
if Z.equal z Z.zero && lexeme <> "0mtz"
|
if Z.equal z Z.zero && lexeme <> "0mutez"
|
||||||
then Error Non_canonical_zero
|
then Error Non_canonical_zero
|
||||||
else Ok (Mtz Region.{region; value = lexeme, z})
|
else Ok (Mutez Region.{region; value = lexeme, z})
|
||||||
|
|
||||||
let eof region = EOF region
|
let eof region = EOF region
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
%token <(string * Z.t) Region.reg> Int
|
%token <(string * Z.t) Region.reg> Int
|
||||||
%token <(string * Z.t) Region.reg> Nat
|
%token <(string * Z.t) Region.reg> Nat
|
||||||
%token <(string * Z.t) Region.reg> Mtz
|
%token <(string * Z.t) Region.reg> Mutez
|
||||||
|
|
||||||
(*%token And*)
|
(*%token And*)
|
||||||
%token <Region.t> Begin
|
%token <Region.t> Begin
|
||||||
|
@ -761,7 +761,7 @@ call_expr:
|
|||||||
|
|
||||||
core_expr:
|
core_expr:
|
||||||
Int { EArith (Int $1) }
|
Int { EArith (Int $1) }
|
||||||
| Mtz { EArith (Mtz $1) }
|
| Mutez { EArith (Mutez $1) }
|
||||||
| Nat { EArith (Nat $1) }
|
| Nat { EArith (Nat $1) }
|
||||||
| Ident | module_field { EVar $1 }
|
| Ident | module_field { EVar $1 }
|
||||||
| projection { EProj $1 }
|
| projection { EProj $1 }
|
||||||
|
@ -321,8 +321,8 @@ and print_arith_expr buffer = function
|
|||||||
| Int {region; value=lex,z} ->
|
| Int {region; value=lex,z} ->
|
||||||
let line = sprintf "Int %s (%s)" lex (Z.to_string z)
|
let line = sprintf "Int %s (%s)" lex (Z.to_string z)
|
||||||
in print_token buffer region line
|
in print_token buffer region line
|
||||||
| Mtz {region; value=lex,z} ->
|
| Mutez {region; value=lex,z} ->
|
||||||
let line = sprintf "Mtz %s (%s)" lex (Z.to_string z)
|
let line = sprintf "Mutez %s (%s)" lex (Z.to_string z)
|
||||||
in print_token buffer region line
|
in print_token buffer region line
|
||||||
| Nat {region; value=lex,z} ->
|
| Nat {region; value=lex,z} ->
|
||||||
let line = sprintf "Nat %s (%s)" lex (Z.to_string z)
|
let line = sprintf "Nat %s (%s)" lex (Z.to_string z)
|
||||||
|
@ -547,7 +547,7 @@ and arith_expr =
|
|||||||
| Neg of minus un_op reg
|
| Neg of minus un_op reg
|
||||||
| Int of (Lexer.lexeme * Z.t) reg
|
| Int of (Lexer.lexeme * Z.t) reg
|
||||||
| Nat of (Lexer.lexeme * Z.t) reg
|
| Nat of (Lexer.lexeme * Z.t) reg
|
||||||
| Mtz of (Lexer.lexeme * Z.t) reg
|
| Mutez of (Lexer.lexeme * Z.t) reg
|
||||||
|
|
||||||
and string_expr =
|
and string_expr =
|
||||||
Cat of cat bin_op reg
|
Cat of cat bin_op reg
|
||||||
@ -689,7 +689,7 @@ and arith_expr_to_region = function
|
|||||||
| Neg {region; _}
|
| Neg {region; _}
|
||||||
| Int {region; _}
|
| Int {region; _}
|
||||||
| Nat {region; _}
|
| Nat {region; _}
|
||||||
| Mtz {region; _} -> region
|
| Mutez {region; _} -> region
|
||||||
|
|
||||||
and string_expr_to_region = function
|
and string_expr_to_region = function
|
||||||
Cat {region; _}
|
Cat {region; _}
|
||||||
|
@ -538,7 +538,7 @@ and arith_expr =
|
|||||||
| Neg of minus un_op reg
|
| Neg of minus un_op reg
|
||||||
| Int of (Lexer.lexeme * Z.t) reg
|
| Int of (Lexer.lexeme * Z.t) reg
|
||||||
| Nat of (Lexer.lexeme * Z.t) reg
|
| Nat of (Lexer.lexeme * Z.t) reg
|
||||||
| Mtz of (Lexer.lexeme * Z.t) reg
|
| Mutez of (Lexer.lexeme * Z.t) reg
|
||||||
|
|
||||||
and string_expr =
|
and string_expr =
|
||||||
Cat of cat bin_op reg
|
Cat of cat bin_op reg
|
||||||
|
@ -340,10 +340,10 @@ and the canonical form of zero is `0n`.
|
|||||||
|
|
||||||
* The last kind of native numerical type is `tez`, which is a unit of
|
* The last kind of native numerical type is `tez`, which is a unit of
|
||||||
measure of the amounts (fees, accounts). Beware: the literals of the
|
measure of the amounts (fees, accounts). Beware: the literals of the
|
||||||
type `tez` are annotated with the suffix `mtz`, which stands for
|
type `tez` are annotated with the suffix `mutez`, which stands for
|
||||||
millionth of Tez, for instance, `0mtz` or `1200000mtz`. The same handy
|
millionth of Tez, for instance, `0mutez` or `1200000mutez`. The same
|
||||||
use of underscores as in natural literals help in the writing, like
|
handy use of underscores as in natural literals help in the writing,
|
||||||
`1_200_000mtz`.
|
like `1_200_000mutez`.
|
||||||
|
|
||||||
To see how numerical types can be used in expressions see the sections
|
To see how numerical types can be used in expressions see the sections
|
||||||
"Predefined operators" and "Predefined values".
|
"Predefined operators" and "Predefined values".
|
||||||
@ -832,7 +832,7 @@ example, in verbose style:
|
|||||||
A value of that type could be
|
A value of that type could be
|
||||||
|
|
||||||
record
|
record
|
||||||
goal = 10mtz;
|
goal = 10mutez;
|
||||||
deadline = "...";
|
deadline = "...";
|
||||||
backers = map end;
|
backers = map end;
|
||||||
funded = False
|
funded = False
|
||||||
|
@ -331,7 +331,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| var
|
| var
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -337,7 +337,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| var
|
| var
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -317,7 +317,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -295,7 +295,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -289,7 +289,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -292,7 +292,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -279,7 +279,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -284,7 +284,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -288,7 +288,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -283,7 +283,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -281,7 +281,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) brackets(expr) (* lookup *)
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) brackets(expr) (* lookup *)
|
||||||
|
@ -285,7 +285,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
||||||
|
@ -285,7 +285,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
||||||
|
@ -285,7 +285,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
||||||
|
@ -285,7 +285,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
||||||
|
@ -285,7 +285,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
||||||
|
@ -285,7 +285,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
||||||
|
@ -285,7 +285,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
||||||
|
@ -285,7 +285,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
||||||
|
@ -270,7 +270,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident (* var *)
|
| Ident (* var *)
|
||||||
| Ident (* var *) brackets(expr) (* lookup *)
|
| Ident (* var *) brackets(expr) (* lookup *)
|
||||||
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
| Ident (* struct_name *) DOT nsepseq(selection,DOT) option(brackets(expr))
|
||||||
|
@ -291,7 +291,7 @@ unary_expr ::=
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident option(core_suffix)
|
| Ident option(core_suffix)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -349,7 +349,7 @@ XXX
|
|||||||
core_expr ::=
|
core_expr ::=
|
||||||
Int
|
Int
|
||||||
| Nat
|
| Nat
|
||||||
| Mtz
|
| Mutez
|
||||||
| Ident option(core_suffix)
|
| Ident option(core_suffix)
|
||||||
| String
|
| String
|
||||||
| Bytes
|
| Bytes
|
||||||
|
@ -35,7 +35,7 @@ type t =
|
|||||||
| Bytes of (lexeme * Hex.t) Region.reg
|
| Bytes of (lexeme * Hex.t) Region.reg
|
||||||
| Int of (lexeme * Z.t) Region.reg
|
| Int of (lexeme * Z.t) Region.reg
|
||||||
| Nat of (lexeme * Z.t) Region.reg
|
| Nat of (lexeme * Z.t) Region.reg
|
||||||
| Mtz of (lexeme * Z.t) Region.reg
|
| Mutez of (lexeme * Z.t) Region.reg
|
||||||
| Ident of lexeme Region.reg
|
| Ident of lexeme Region.reg
|
||||||
| Constr of lexeme Region.reg
|
| Constr of lexeme Region.reg
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ type sym_err = Invalid_symbol
|
|||||||
|
|
||||||
val mk_int : lexeme -> Region.t -> (token, int_err) result
|
val mk_int : lexeme -> Region.t -> (token, int_err) result
|
||||||
val mk_nat : lexeme -> Region.t -> (token, nat_err) result
|
val mk_nat : lexeme -> Region.t -> (token, nat_err) result
|
||||||
val mk_mtz : lexeme -> Region.t -> (token, int_err) result
|
val mk_mutez : lexeme -> Region.t -> (token, int_err) result
|
||||||
val mk_ident : lexeme -> Region.t -> (token, ident_err) result
|
val mk_ident : lexeme -> Region.t -> (token, ident_err) result
|
||||||
val mk_sym : lexeme -> Region.t -> (token, sym_err) result
|
val mk_sym : lexeme -> Region.t -> (token, sym_err) result
|
||||||
val mk_string : lexeme -> Region.t -> token
|
val mk_string : lexeme -> Region.t -> token
|
||||||
|
@ -33,7 +33,7 @@ type t =
|
|||||||
| Bytes of (lexeme * Hex.t) Region.reg
|
| Bytes of (lexeme * Hex.t) Region.reg
|
||||||
| Int of (lexeme * Z.t) Region.reg
|
| Int of (lexeme * Z.t) Region.reg
|
||||||
| Nat of (lexeme * Z.t) Region.reg
|
| Nat of (lexeme * Z.t) Region.reg
|
||||||
| Mtz of (lexeme * Z.t) Region.reg
|
| Mutez of (lexeme * Z.t) Region.reg
|
||||||
| Ident of lexeme Region.reg
|
| Ident of lexeme Region.reg
|
||||||
| Constr of lexeme Region.reg
|
| Constr of lexeme Region.reg
|
||||||
|
|
||||||
@ -160,8 +160,8 @@ let proj_token = function
|
|||||||
| Nat Region.{region; value = s,n} ->
|
| Nat Region.{region; value = s,n} ->
|
||||||
region, sprintf "Nat (\"%s\", %s)" s (Z.to_string n)
|
region, sprintf "Nat (\"%s\", %s)" s (Z.to_string n)
|
||||||
|
|
||||||
| Mtz Region.{region; value = s,n} ->
|
| Mutez Region.{region; value = s,n} ->
|
||||||
region, sprintf "Mtz (\"%s\", %s)" s (Z.to_string n)
|
region, sprintf "Mutez (\"%s\", %s)" s (Z.to_string n)
|
||||||
|
|
||||||
| Ident Region.{region; value} ->
|
| Ident Region.{region; value} ->
|
||||||
region, sprintf "Ident \"%s\"" value
|
region, sprintf "Ident \"%s\"" value
|
||||||
@ -258,7 +258,7 @@ let to_lexeme = function
|
|||||||
| Bytes b -> fst b.Region.value
|
| Bytes b -> fst b.Region.value
|
||||||
| Int i
|
| Int i
|
||||||
| Nat i
|
| Nat i
|
||||||
| Mtz i -> fst i.Region.value
|
| Mutez i -> fst i.Region.value
|
||||||
| Ident id
|
| Ident id
|
||||||
| Constr id -> id.Region.value
|
| Constr id -> id.Region.value
|
||||||
|
|
||||||
@ -497,14 +497,14 @@ let mk_nat lexeme region =
|
|||||||
else Ok (Nat Region.{region; value = lexeme, z})
|
else Ok (Nat Region.{region; value = lexeme, z})
|
||||||
)
|
)
|
||||||
|
|
||||||
let mk_mtz lexeme region =
|
let mk_mutez lexeme region =
|
||||||
let z =
|
let z =
|
||||||
Str.(global_replace (regexp "_") "" lexeme) |>
|
Str.(global_replace (regexp "_") "" lexeme) |>
|
||||||
Str.(global_replace (regexp "mtz") "") |>
|
Str.(global_replace (regexp "mutez") "") |>
|
||||||
Z.of_string in
|
Z.of_string in
|
||||||
if Z.equal z Z.zero && lexeme <> "0mtz"
|
if Z.equal z Z.zero && lexeme <> "0mutez"
|
||||||
then Error Non_canonical_zero
|
then Error Non_canonical_zero
|
||||||
else Ok (Mtz Region.{region; value = lexeme, z})
|
else Ok (Mutez Region.{region; value = lexeme, z})
|
||||||
|
|
||||||
let eof region = EOF region
|
let eof region = EOF region
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
%token <(LexToken.lexeme * Hex.t) Region.reg> Bytes
|
%token <(LexToken.lexeme * Hex.t) Region.reg> Bytes
|
||||||
%token <(LexToken.lexeme * Z.t) Region.reg> Int
|
%token <(LexToken.lexeme * Z.t) Region.reg> Int
|
||||||
%token <(LexToken.lexeme * Z.t) Region.reg> Nat
|
%token <(LexToken.lexeme * Z.t) Region.reg> Nat
|
||||||
%token <(LexToken.lexeme * Z.t) Region.reg> Mtz
|
%token <(LexToken.lexeme * Z.t) Region.reg> Mutez
|
||||||
%token <LexToken.lexeme Region.reg> Ident
|
%token <LexToken.lexeme Region.reg> Ident
|
||||||
%token <LexToken.lexeme Region.reg> Constr
|
%token <LexToken.lexeme Region.reg> Constr
|
||||||
|
|
||||||
|
@ -856,7 +856,7 @@ unary_expr:
|
|||||||
core_expr:
|
core_expr:
|
||||||
Int { EArith (Int $1) }
|
Int { EArith (Int $1) }
|
||||||
| Nat { EArith (Nat $1) }
|
| Nat { EArith (Nat $1) }
|
||||||
| Mtz { EArith (Mtz $1) }
|
| Mutez { EArith (Mutez $1) }
|
||||||
| var { EVar $1 }
|
| var { EVar $1 }
|
||||||
| String { EString (String $1) }
|
| String { EString (String $1) }
|
||||||
| Bytes { EBytes $1 }
|
| Bytes { EBytes $1 }
|
||||||
|
@ -527,7 +527,7 @@ and print_arith_expr buffer = function
|
|||||||
print_expr buffer arg
|
print_expr buffer arg
|
||||||
| Int i
|
| Int i
|
||||||
| Nat i
|
| Nat i
|
||||||
| Mtz i -> print_int buffer i
|
| Mutez i -> print_int buffer i
|
||||||
|
|
||||||
and print_string_expr buffer = function
|
and print_string_expr buffer = function
|
||||||
Cat {value = {arg1; op; arg2}; _} ->
|
Cat {value = {arg1; op; arg2}; _} ->
|
||||||
@ -1391,8 +1391,8 @@ and pp_arith_expr buffer ~pad:(_,pc as pad) = function
|
|||||||
| Nat {value; _} ->
|
| Nat {value; _} ->
|
||||||
pp_node buffer ~pad "Nat";
|
pp_node buffer ~pad "Nat";
|
||||||
pp_int buffer ~pad value
|
pp_int buffer ~pad value
|
||||||
| Mtz {value; _} ->
|
| Mutez {value; _} ->
|
||||||
pp_node buffer ~pad "Mtz";
|
pp_node buffer ~pad "Mutez";
|
||||||
pp_int buffer ~pad value
|
pp_int buffer ~pad value
|
||||||
|
|
||||||
and pp_set_expr buffer ~pad:(_,pc as pad) = function
|
and pp_set_expr buffer ~pad:(_,pc as pad) = function
|
||||||
|
@ -312,7 +312,7 @@ and unary_expr = parser
|
|||||||
and core_expr = parser
|
and core_expr = parser
|
||||||
[< 'Int _ >] -> ()
|
[< 'Int _ >] -> ()
|
||||||
| [< 'Nat _ >] -> ()
|
| [< 'Nat _ >] -> ()
|
||||||
| [< 'Mtz _ >] -> ()
|
| [< 'Mutez _ >] -> ()
|
||||||
| [< 'Ident _; _ = opt core_suffix >] -> ()
|
| [< 'Ident _; _ = opt core_suffix >] -> ()
|
||||||
| [< 'String _ >] -> ()
|
| [< 'String _ >] -> ()
|
||||||
| [< 'Bytes _ >] -> ()
|
| [< 'Bytes _ >] -> ()
|
||||||
|
@ -70,7 +70,7 @@ module type TOKEN =
|
|||||||
|
|
||||||
val mk_int : lexeme -> Region.t -> (token, int_err) result
|
val mk_int : lexeme -> Region.t -> (token, int_err) result
|
||||||
val mk_nat : lexeme -> Region.t -> (token, nat_err) result
|
val mk_nat : lexeme -> Region.t -> (token, nat_err) result
|
||||||
val mk_mtz : lexeme -> Region.t -> (token, int_err) result
|
val mk_mutez : lexeme -> Region.t -> (token, int_err) result
|
||||||
val mk_ident : lexeme -> Region.t -> (token, ident_err) result
|
val mk_ident : lexeme -> Region.t -> (token, ident_err) result
|
||||||
val mk_sym : lexeme -> Region.t -> (token, sym_err) result
|
val mk_sym : lexeme -> Region.t -> (token, sym_err) result
|
||||||
val mk_string : lexeme -> Region.t -> token
|
val mk_string : lexeme -> Region.t -> token
|
||||||
|
@ -111,7 +111,7 @@ module type TOKEN =
|
|||||||
|
|
||||||
val mk_int : lexeme -> Region.t -> (token, int_err) result
|
val mk_int : lexeme -> Region.t -> (token, int_err) result
|
||||||
val mk_nat : lexeme -> Region.t -> (token, nat_err) result
|
val mk_nat : lexeme -> Region.t -> (token, nat_err) result
|
||||||
val mk_mtz : lexeme -> Region.t -> (token, int_err) result
|
val mk_mutez : lexeme -> Region.t -> (token, int_err) result
|
||||||
val mk_ident : lexeme -> Region.t -> (token, ident_err) result
|
val mk_ident : lexeme -> Region.t -> (token, ident_err) result
|
||||||
val mk_sym : lexeme -> Region.t -> (token, sym_err) result
|
val mk_sym : lexeme -> Region.t -> (token, sym_err) result
|
||||||
val mk_string : lexeme -> Region.t -> token
|
val mk_string : lexeme -> Region.t -> token
|
||||||
@ -436,9 +436,9 @@ module Make (Token: TOKEN) : (S with module Token = Token) =
|
|||||||
| Error Token.Invalid_natural ->
|
| Error Token.Invalid_natural ->
|
||||||
fail region Invalid_natural
|
fail region Invalid_natural
|
||||||
|
|
||||||
let mk_mtz state buffer =
|
let mk_mutez state buffer =
|
||||||
let region, lexeme, state = sync state buffer in
|
let region, lexeme, state = sync state buffer in
|
||||||
match Token.mk_mtz lexeme region with
|
match Token.mk_mutez lexeme region with
|
||||||
Ok token -> token, state
|
Ok token -> token, state
|
||||||
| Error Token.Non_canonical_zero ->
|
| Error Token.Non_canonical_zero ->
|
||||||
fail region Non_canonical_zero
|
fail region Non_canonical_zero
|
||||||
@ -447,7 +447,7 @@ module Make (Token: TOKEN) : (S with module Token = Token) =
|
|||||||
let region, lexeme, state = sync state buffer in
|
let region, lexeme, state = sync state buffer in
|
||||||
let lexeme = Str.string_before lexeme (String.index lexeme 't') in
|
let lexeme = Str.string_before lexeme (String.index lexeme 't') in
|
||||||
let lexeme = Z.mul (Z.of_int 1_000_000) (Z.of_string lexeme) in
|
let lexeme = Z.mul (Z.of_int 1_000_000) (Z.of_string lexeme) in
|
||||||
match Token.mk_mtz (Z.to_string lexeme ^ "mtz") region with
|
match Token.mk_mutez (Z.to_string lexeme ^ "mutez") region with
|
||||||
Ok token -> token, state
|
Ok token -> token, state
|
||||||
| Error Token.Non_canonical_zero ->
|
| Error Token.Non_canonical_zero ->
|
||||||
fail region Non_canonical_zero
|
fail region Non_canonical_zero
|
||||||
@ -461,9 +461,9 @@ module Make (Token: TOKEN) : (S with module Token = Token) =
|
|||||||
let num = Z.of_string (integral ^ fractional)
|
let num = Z.of_string (integral ^ fractional)
|
||||||
and den = Z.of_string ("1" ^ String.make (len-index-1) '0')
|
and den = Z.of_string ("1" ^ String.make (len-index-1) '0')
|
||||||
and million = Q.of_string "1000000" in
|
and million = Q.of_string "1000000" in
|
||||||
let mtz = Q.make num den |> Q.mul million in
|
let mutez = Q.make num den |> Q.mul million in
|
||||||
let should_be_1 = Q.den mtz in
|
let should_be_1 = Q.den mutez in
|
||||||
if Z.equal Z.one should_be_1 then Some (Q.num mtz) else None
|
if Z.equal Z.one should_be_1 then Some (Q.num mutez) else None
|
||||||
| exception Not_found -> assert false
|
| exception Not_found -> assert false
|
||||||
|
|
||||||
let mk_tz_decimal state buffer =
|
let mk_tz_decimal state buffer =
|
||||||
@ -471,7 +471,7 @@ module Make (Token: TOKEN) : (S with module Token = Token) =
|
|||||||
let lexeme = Str.string_before lexeme (String.index lexeme 't') in
|
let lexeme = Str.string_before lexeme (String.index lexeme 't') in
|
||||||
match format_tz lexeme with
|
match format_tz lexeme with
|
||||||
| Some tz -> (
|
| Some tz -> (
|
||||||
match Token.mk_mtz (Z.to_string tz ^ "mtz") region with
|
match Token.mk_mutez (Z.to_string tz ^ "mutez") region with
|
||||||
Ok token ->
|
Ok token ->
|
||||||
token, state
|
token, state
|
||||||
| Error Token.Non_canonical_zero ->
|
| Error Token.Non_canonical_zero ->
|
||||||
@ -559,7 +559,7 @@ and scan state = parse
|
|||||||
| bytes { (mk_bytes seq) state lexbuf |> enqueue }
|
| bytes { (mk_bytes seq) state lexbuf |> enqueue }
|
||||||
| natural 'n' { mk_nat state lexbuf |> enqueue }
|
| natural 'n' { mk_nat state lexbuf |> enqueue }
|
||||||
| natural 'p' { mk_nat state lexbuf |> enqueue }
|
| natural 'p' { mk_nat state lexbuf |> enqueue }
|
||||||
| natural "mtz" { mk_mtz state lexbuf |> enqueue }
|
| natural "mutez" { mk_mutez state lexbuf |> enqueue }
|
||||||
| natural "tz" { mk_tz state lexbuf |> enqueue }
|
| natural "tz" { mk_tz state lexbuf |> enqueue }
|
||||||
| decimal "tz" { mk_tz_decimal state lexbuf |> enqueue }
|
| decimal "tz" { mk_tz_decimal state lexbuf |> enqueue }
|
||||||
| natural { mk_int state lexbuf |> enqueue }
|
| natural { mk_int state lexbuf |> enqueue }
|
||||||
|
@ -409,7 +409,7 @@ let rec simpl_expression :
|
|||||||
let n = Z.to_int @@ snd @@ n in
|
let n = Z.to_int @@ snd @@ n in
|
||||||
return @@ e_literal ~loc (Literal_nat n)
|
return @@ e_literal ~loc (Literal_nat n)
|
||||||
)
|
)
|
||||||
| EArith (Mtz n) -> (
|
| EArith (Mutez n) -> (
|
||||||
let (n , loc) = r_split n in
|
let (n , loc) = r_split n in
|
||||||
let n = Z.to_int @@ snd @@ n in
|
let n = Z.to_int @@ snd @@ n in
|
||||||
return @@ e_literal ~loc (Literal_mutez n)
|
return @@ e_literal ~loc (Literal_mutez n)
|
||||||
|
@ -348,7 +348,7 @@ let rec simpl_expression (t:Raw.expr) : expr result =
|
|||||||
let n = Z.to_int @@ snd @@ n in
|
let n = Z.to_int @@ snd @@ n in
|
||||||
return @@ e_literal ~loc (Literal_nat n)
|
return @@ e_literal ~loc (Literal_nat n)
|
||||||
)
|
)
|
||||||
| EArith (Mtz n) -> (
|
| EArith (Mutez n) -> (
|
||||||
let (n , loc) = r_split n in
|
let (n , loc) = r_split n in
|
||||||
let n = Z.to_int @@ snd @@ n in
|
let n = Z.to_int @@ snd @@ n in
|
||||||
return @@ e_literal ~loc (Literal_mutez n)
|
return @@ e_literal ~loc (Literal_mutez n)
|
||||||
|
@ -177,6 +177,10 @@ module Simplify = struct
|
|||||||
("Big_map.literal" , "BIG_MAP_LITERAL" ) ;
|
("Big_map.literal" , "BIG_MAP_LITERAL" ) ;
|
||||||
("Big_map.empty" , "BIG_MAP_EMPTY" ) ;
|
("Big_map.empty" , "BIG_MAP_EMPTY" ) ;
|
||||||
|
|
||||||
|
("Bitwise.lor" , "OR") ;
|
||||||
|
("Bitwise.land" , "AND") ;
|
||||||
|
("Bitwise.lxor" , "XOR") ;
|
||||||
|
|
||||||
("String.length", "SIZE") ;
|
("String.length", "SIZE") ;
|
||||||
("String.size", "SIZE") ;
|
("String.size", "SIZE") ;
|
||||||
("String.slice", "SLICE") ;
|
("String.slice", "SLICE") ;
|
||||||
@ -407,7 +411,10 @@ module Typer = struct
|
|||||||
let%bind () = assert_eq_1 op_lst (t_list (t_operation ()) ()) in
|
let%bind () = assert_eq_1 op_lst (t_list (t_operation ()) ()) in
|
||||||
ok @@ (t_pair (t_operation ()) (t_address ()) ())
|
ok @@ (t_pair (t_operation ()) (t_address ()) ())
|
||||||
|
|
||||||
let get_contract = typer_1_opt "CONTRACT" @@ fun _ tv_opt ->
|
let get_contract = typer_1_opt "CONTRACT" @@ fun addr_tv tv_opt ->
|
||||||
|
if not (type_value_eq (addr_tv, t_address ()))
|
||||||
|
then fail @@ simple_error (Format.asprintf "get_contract expects an address, got %a" PP.type_value addr_tv)
|
||||||
|
else
|
||||||
let%bind tv =
|
let%bind tv =
|
||||||
trace_option (simple_error "get_contract needs a type annotation") tv_opt in
|
trace_option (simple_error "get_contract needs a type annotation") tv_opt in
|
||||||
let%bind tv' =
|
let%bind tv' =
|
||||||
|
@ -25,7 +25,7 @@ let literal ppf (l:literal) = match l with
|
|||||||
| Literal_int n -> fprintf ppf "%d" n
|
| Literal_int n -> fprintf ppf "%d" n
|
||||||
| Literal_nat n -> fprintf ppf "+%d" n
|
| Literal_nat n -> fprintf ppf "+%d" n
|
||||||
| Literal_timestamp n -> fprintf ppf "+%d" n
|
| Literal_timestamp n -> fprintf ppf "+%d" n
|
||||||
| Literal_mutez n -> fprintf ppf "%dmtz" n
|
| Literal_mutez n -> fprintf ppf "%dmutez" n
|
||||||
| Literal_string s -> fprintf ppf "%S" s
|
| Literal_string s -> fprintf ppf "%S" s
|
||||||
| Literal_bytes b -> fprintf ppf "0x%s" @@ Bytes.to_string @@ Bytes.escaped b
|
| Literal_bytes b -> fprintf ppf "0x%s" @@ Bytes.to_string @@ Bytes.escaped b
|
||||||
| Literal_address s -> fprintf ppf "@%S" s
|
| Literal_address s -> fprintf ppf "@%S" s
|
||||||
|
@ -69,7 +69,7 @@ and literal ppf (l:literal) : unit =
|
|||||||
| Literal_int n -> fprintf ppf "%d" n
|
| Literal_int n -> fprintf ppf "%d" n
|
||||||
| Literal_nat n -> fprintf ppf "+%d" n
|
| Literal_nat n -> fprintf ppf "+%d" n
|
||||||
| Literal_timestamp n -> fprintf ppf "+%d" n
|
| Literal_timestamp n -> fprintf ppf "+%d" n
|
||||||
| Literal_mutez n -> fprintf ppf "%dmtz" n
|
| Literal_mutez n -> fprintf ppf "%dmutez" n
|
||||||
| Literal_string s -> fprintf ppf "%s" s
|
| Literal_string s -> fprintf ppf "%s" s
|
||||||
| Literal_bytes b -> fprintf ppf "0x%s" @@ Bytes.to_string @@ Bytes.escaped b
|
| Literal_bytes b -> fprintf ppf "0x%s" @@ Bytes.to_string @@ Bytes.escaped b
|
||||||
| Literal_address s -> fprintf ppf "@%s" s
|
| Literal_address s -> fprintf ppf "@%s" s
|
||||||
|
@ -53,7 +53,7 @@ let rec value ppf : value -> unit = function
|
|||||||
| D_int n -> fprintf ppf "%d" n
|
| D_int n -> fprintf ppf "%d" n
|
||||||
| D_nat n -> fprintf ppf "+%d" n
|
| D_nat n -> fprintf ppf "+%d" n
|
||||||
| D_timestamp n -> fprintf ppf "+%d" n
|
| D_timestamp n -> fprintf ppf "+%d" n
|
||||||
| D_mutez n -> fprintf ppf "%dmtz" n
|
| D_mutez n -> fprintf ppf "%dmutez" n
|
||||||
| D_unit -> fprintf ppf "unit"
|
| D_unit -> fprintf ppf "unit"
|
||||||
| D_string s -> fprintf ppf "\"%s\"" s
|
| D_string s -> fprintf ppf "\"%s\"" s
|
||||||
| D_bytes x ->
|
| D_bytes x ->
|
||||||
|
10
src/test/contracts/bitwise_arithmetic.mligo
Normal file
10
src/test/contracts/bitwise_arithmetic.mligo
Normal file
@ -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
|
@ -1,16 +1,16 @@
|
|||||||
const add_tez : tez = 21mtz + 0.000021tz;
|
const add_tez : tez = 21mutez + 0.000021tz;
|
||||||
const sub_tez : tez = 21mtz - 20mtz;
|
const sub_tez : tez = 21mutez - 20mutez;
|
||||||
(* This is not enough. *)
|
(* This is not enough. *)
|
||||||
const not_enough_tez : tez = 4611686018427387903mtz;
|
const not_enough_tez : tez = 4611686018427387903mutez;
|
||||||
|
|
||||||
|
|
||||||
const nat_mul_tez : tez = 1n * 100mtz;
|
const nat_mul_tez : tez = 1n * 100mutez;
|
||||||
const tez_mul_nat : tez = 100mtz * 10n;
|
const tez_mul_nat : tez = 100mutez * 10n;
|
||||||
|
|
||||||
const tez_div_tez1 : nat = 100mtz / 1mtz;
|
const tez_div_tez1 : nat = 100mutez / 1mutez;
|
||||||
const tez_div_tez2 : nat = 100mtz / 90mtz;
|
const tez_div_tez2 : nat = 100mutez / 90mutez;
|
||||||
const tez_div_tez3 : nat = 100mtz / 110mtz;
|
const tez_div_tez3 : nat = 100mutez / 110mutez;
|
||||||
|
|
||||||
const tez_mod_tez1 : tez = 100mtz mod 1mtz;
|
const tez_mod_tez1 : tez = 100mutez mod 1mutez;
|
||||||
const tez_mod_tez2 : tez = 100mtz mod 90mtz;
|
const tez_mod_tez2 : tez = 100mutez mod 90mutez;
|
||||||
const tez_mod_tez3 : tez = 100mtz mod 110mtz;
|
const tez_mod_tez3 : tez = 100mutez mod 110mutez;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
let add_tez : tez = 21mtz + 0.000021tz
|
let add_tez : tez = 21mutez + 0.000021tz
|
||||||
let sub_tez : tez = 0.000021tz - 0.000020tz
|
let sub_tez : tez = 0.000021tz - 0.000020tz
|
||||||
let not_enough_tez : tez = 4611686018427.387903tz
|
let not_enough_tez : tez = 4611686018427.387903tz
|
||||||
|
|
||||||
|
@ -203,6 +203,22 @@ let bitwise_arithmetic () : unit result =
|
|||||||
let%bind () = expect_eq program "xor_op" (e_nat 7) (e_nat 0) in
|
let%bind () = expect_eq program "xor_op" (e_nat 7) (e_nat 0) in
|
||||||
ok ()
|
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 string_arithmetic () : unit result =
|
||||||
let%bind program = type_file "./contracts/string_arithmetic.ligo" in
|
let%bind program = type_file "./contracts/string_arithmetic.ligo" in
|
||||||
let%bind () = expect_eq program "concat_op" (e_string "foo") (e_string "foototo") in
|
let%bind () = expect_eq program "concat_op" (e_string "foo") (e_string "foototo") in
|
||||||
@ -970,7 +986,8 @@ let main = test_suite "Integration (End to End)" [
|
|||||||
test "bool" bool_expression ;
|
test "bool" bool_expression ;
|
||||||
test "arithmetic" arithmetic ;
|
test "arithmetic" arithmetic ;
|
||||||
test "arithmetic (mligo)" arithmetic_mligo ;
|
test "arithmetic (mligo)" arithmetic_mligo ;
|
||||||
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" string_arithmetic ;
|
||||||
test "string_arithmetic (mligo)" string_arithmetic_mligo ;
|
test "string_arithmetic (mligo)" string_arithmetic_mligo ;
|
||||||
test "bytes_arithmetic" bytes_arithmetic ;
|
test "bytes_arithmetic" bytes_arithmetic ;
|
||||||
|
Loading…
Reference in New Issue
Block a user