From ebbaccd0646d278c37742bd463244c203829f693 Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Wed, 18 Mar 2020 16:53:59 +0100 Subject: [PATCH 1/8] wip --- gitlab-pages/docs/api/cheat-sheet.md | 153 +++++++++++++++++++++++++-- 1 file changed, 142 insertions(+), 11 deletions(-) diff --git a/gitlab-pages/docs/api/cheat-sheet.md b/gitlab-pages/docs/api/cheat-sheet.md index 412ba5bd5..637d511b5 100644 --- a/gitlab-pages/docs/api/cheat-sheet.md +++ b/gitlab-pages/docs/api/cheat-sheet.md @@ -11,22 +11,153 @@ import Syntax from '@theme/Syntax'; Note that this table is not compiled before production and currently needs to be managed manually. --> +
+
Primitive
+
Example
+
Strings
+
+ +```pascaligo +const name: string = "Tezos"; +``` + +
+
+Characters +
+
+ +```pascaligo +const t: string = "t"; +``` + +
+
+Integers +
+
+ +```pascaligo +const i: int = 42; +``` + +
+
+Natural numbers +
+
+ +```pascaligo +const n: int = 7n; +``` + +
+
+Unit +
+
+ +```pascaligo +const u: unit = unit; +``` + +
+
+Boolean +
+
+ +```pascaligo +const hasDriversLicense: bool = False; +const adult: bool = True; +``` + +
+
+Boolean Logic +
+
+ +```pascaligo +const booleanLogic: bool = (not True) == False == (False and True) == (False or False); +``` + +
+
+Mutez (micro tez) +
+
+ +```pascaligo +const tez: mutez = 42mutez; +``` + +
+
+Address +
+
+ +```pascaligo +const tz1address: address = ""tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"; +const kt1address: address = ""KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"; +``` + +
+
+Addition +
+
+ +```pascaligo +const add_int: int = 3 + 4; +const add_nat: nat = 3n + 4n; +``` + +
+
+Multiplication & Division +
+
+ +```pascaligo +const mul_int: int = 3 + 4; +const mul_nat: nat = 3n + 4n; + +const div_int: int = 10 / 5; +const div_nat: nat = 10n / 5n; +``` + +
+
+Modulo +
+
+ +```pascaligo +const mod: int = 10 mod 3; +``` + +
+
+Tuples +
+
+ +```pascaligo +const mod: int = 10 mod 3; +``` + +
+
+ + + |Primitive |Example| |--- |---| -|Strings | `"Tezos"`| -|Characters | `"t"`| -|Integers | `42`, `7`| -|Natural numbers | `42n`, `7n`| -|Unit| `unit`| -|Boolean|
const hasDriversLicense: bool = False;
const adult: bool = True;
| -|Boolean Logic|
(not True) == False == (False and True) == (False or False)
| -|Mutez (micro tez)| `42mutez`, `7mutez` | -|Address | `"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"`, `"KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"`| -|Addition |`3 + 4`, `3n + 4n`| -|Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`| |Modulo| `10 mod 3`| |Tuples|
type name is (string * string);
const winner: name = ("John", "Doe");
const firstName: string = winner.0;
const lastName: string = winner.1;
| |Types|`type age is int`, `type name is string` | From 7896de89f375d1544dd78319ed976ce3c565b789 Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Thu, 19 Mar 2020 21:27:58 +0100 Subject: [PATCH 2/8] Make cheatsheet testable. --- gitlab-pages/docs/api/cheat-sheet.md | 1075 +++++++++++++++-- .../website/src/theme/CodeBlock/index.js | 2 +- gitlab-pages/website/static/css/custom.css | 52 +- 3 files changed, 989 insertions(+), 140 deletions(-) diff --git a/gitlab-pages/docs/api/cheat-sheet.md b/gitlab-pages/docs/api/cheat-sheet.md index 637d511b5..2d7303138 100644 --- a/gitlab-pages/docs/api/cheat-sheet.md +++ b/gitlab-pages/docs/api/cheat-sheet.md @@ -7,65 +7,61 @@ import Syntax from '@theme/Syntax';
- + -
-
Primitive
-
Example
-
Strings
-
+
+
Strings
+
```pascaligo const name: string = "Tezos"; ```
-
+
Characters
-
+
```pascaligo const t: string = "t"; ```
-
+
Integers
-
+
```pascaligo const i: int = 42; ```
-
+
Natural numbers
-
+
```pascaligo -const n: int = 7n; +const n: nat = 7n; ```
-
+
Unit
-
+
```pascaligo const u: unit = unit; ```
-
+
Boolean
-
+
```pascaligo const hasDriversLicense: bool = False; @@ -73,41 +69,47 @@ const adult: bool = True; ```
-
+
Boolean Logic
-
+
```pascaligo -const booleanLogic: bool = (not True) == False == (False and True) == (False or False); +const booleanLogic: bool = + (not True) = + False = + (False and True) = + (False or False); ```
-
+
Mutez (micro tez)
-
+
```pascaligo -const tez: mutez = 42mutez; +const tez: tez = 42tez; ```
-
+
Address
-
+
```pascaligo -const tz1address: address = ""tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"; -const kt1address: address = ""KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"; +const tz1address: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); +const kt1address: address = + ("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address); ```
-
+
Addition
-
+
```pascaligo const add_int: int = 3 + 4; @@ -115,10 +117,10 @@ const add_nat: nat = 3n + 4n; ```
-
+
Multiplication & Division
-
+
```pascaligo const mul_int: int = 3 + 4; @@ -129,122 +131,947 @@ const div_nat: nat = 10n / 5n; ```
-
+
Modulo
-
+
```pascaligo -const mod: int = 10 mod 3; +const mod_nat: nat = 10 mod 3; ```
-
+
Tuples
-
+
```pascaligo -const mod: int = 10 mod 3; +type name is (string * string); + +const winner: name = ("John", "Doe"); + +const firstName: string = winner.0; +const lastName: string = winner.1; +``` + +
+
+Types +
+
+ +```pascaligo +type age is int; +type name is string +``` + +
+
+Includes +
+
+ +```#include "library.ligo"``` + +
+
+Functions (short form) +
+
+ +```pascaligo +function add (const a : int ; const b : int) : int is + a + b +``` + +
+
+Functions (long form) +
+
+ +```pascaligo +function add (const a : int ; const b : int) : int is + block { + const result: int = a + b; + } with result +``` + +
+
+If Statement +
+
+ +```pascaligo +function if_statement (const age : int) : int is + block { + var id: int := -1; + if age < 16 then { + failwith ("Too young to drive"); + } else { + id := 1; + } + } with id +``` + +
+
+Options +
+
+ +```pascaligo +type middleName is option(string); +const middleName : middleName = Some("Foo"); +const middleName : middleName = None; +``` + +
+
+Assignment +
+
+ +```pascaligo +const age: int = 5; +``` + +
+
+Assignment on an existing variable +
+
+ +:::caution +This feature is not supported at the top-level scope, you can use it e.g. within functions. Works for Records and Maps as well. +::: + +```pascaligo +function assignment_existing (const age : int) : int is + block { + var x : int := 2; + x := 3; + } with x +``` + +
+
+Type Annotations +
+
+ +```pascaligo +const someAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); +``` + +
+
+Variants +
+
+ +```pascaligo group=variants +type action is +| Increment of int +| Decrement of int; +``` + +
+
+Variant *(pattern)* matching +
+
+ +```pascaligo group=variants +function main + (const action : action; const input : int) : int is + (case action of + Increment (n) -> input + 1 + | Decrement (n) -> input - 1 + end) +``` + +
+
+Records +
+
+ +```pascaligo +type person is record + age: int; + name: string; +end + +const john : person = record + age = 18; + name = "john doe"; +end + +const name: string = john.name; +``` + +
+
+Maps +
+
+ +```pascaligo +type prices is map(nat, tez); + +const prices: prices = map + 10n -> 60mutez; + 50n -> 30mutez; + 100n -> 10mutez; +end + +const price: option(tez) = prices[50n]; + +function mutate (const u: unit) : unit is block { + prices[200n] := 10mutez; +} with unit; +``` + +
+
+Contracts & Accounts +
+
+ +```pascaligo group=tezos_specific +const destinationAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); + +const contract : contract (unit) = ( + case (Tezos.get_contract_opt (Tezos.sender) : option(contract(unit))) of + Some (contract) -> contract + | None -> + (failwith ("No contract.") + : contract (unit)) + end); + +``` + +
+
+Transactions +
+
+ +```pascaligo group=tezos_specific + +const payment: operation = + Tezos.transaction(unit, 100mutez, contract); + +``` + +
+
+Exception/Failure +
+
+ +```pascaligo +function fail (const u: unit) : unit is + failwith("a failure message") ```
- - - - - -|Primitive |Example| -|--- |---| -|Modulo| `10 mod 3`| -|Tuples|
type name is (string * string);
const winner: name = ("John", "Doe");
const firstName: string = winner.0;
const lastName: string = winner.1;
| -|Types|`type age is int`, `type name is string` | -|Includes|```#include "library.ligo"```| -|Functions (short form)|
function add (const a : int ; const b : int) : int is
  block { skip } with a + b
| -|Functions (long form)|
function add (const a : int ; const b : int) : int is
  block {
    const result: int = a + b;
  } with result
| -| If Statement |
if age < 16 
then failwith ("Too young to drive.");
else const new_id: int = prev_id + 1;
| -|Options|
type middleName is option(string);
const middleName : middleName = Some("Foo");
const middleName : middleName = None;
| -|Assignment| ```const age: int = 5;```| -|Assignment on an existing variable
*⚠️ This feature is not supported at the top-level scope, you can use it e.g. within functions. Works for Records and Maps as well.*| ```age := 18;```, ```p.age := 21``` | -|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```| -|Variants|
type action is
| Increment of int
| Decrement of int
| -|Variant *(pattern)* matching|
const a: action = Increment(5);
case a of
| Increment(n) -> n + 1
| Decrement(n) -> n - 1
end
| -|Records|
type person is record
  age: int ;
  name: string ;
end

const john : person = record
  age = 18;
  name = "John Doe";
end

const name: string = john.name;
| -|Maps|
type prices is map(nat, tez);

const prices : prices = map
  10n -> 60mutez;
  50n -> 30mutez;
  100n -> 10mutez;
end

const price: option(tez) = prices[50n];

prices[200n] := 5mutez;
| -|Contracts & Accounts|
const destinationAddress : address = "tz1...";
const contract : contract(unit) = get_contract(destinationAddress);
| -|Transactions|
const payment : operation = transaction(unit, amount, receiver);
| -|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`| -
-|Primitive |Example| -|--- |---| -|Strings | `"Tezos"`| -|Characters | `"t"`| -|Integers | `42`, `7`| -|Natural numbers | `42n`, `7n`| -|Unit| `unit`| -|Boolean|
let has_drivers_license: bool = false
let adult: bool = true
| -|Boolean Logic|
(not true) = false = (false && true) = (false || false)
| -|Mutez (micro tez)| `42mutez`, `7mutez` | -|Address | `("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)`, `("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)`| -|Addition |`3 + 4`, `3n + 4n`| -|Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`| -|Modulo| `10 mod 3`| -|Tuples|
type name = (string * string)
let winner: name = "John", "Doe"
let first_name: string = winner.0
let last_name: string = winner.1
| -|Types|`type age = int`, `type name = string` | -|Includes|```#include "library.mligo"```| -|Functions |
let add (a : int) (b : int) : int = a + b 
| -| If Statement |
let new_id: int = if age < 16 
then failwith ("Too young to drive.")
else prev_id + 1
| -|Options|
type middle_name = string option
let middle_name : middle_name = Some "Foo"
let middle_name : middle_name = None
| -|Variable Binding | ```let age: int = 5```| -|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```| -|Variants|
type action =
| Increment of int
| Decrement of int
| -|Variant *(pattern)* matching|
let a: action = Increment 5
match a with
| Increment n -> n + 1
| Decrement n -> n - 1
| -|Records|
type person = {
  age: int ;
  name: string ;
}

let john : person = {
  age = 18;
  name = "John Doe";
}

let name: string = john.name
| -|Maps|
type prices = (nat, tez) map

let prices : prices = Map.literal [
  (10n, 60mutez);
  (50n, 30mutez);
  (100n, 10mutez)
]

let price: tez option = Map.find_opt 50n prices

let prices: prices = Map.update 200n (Some 5mutez) prices
| -|Contracts & Accounts|
let destination_address : address = "tz1..."
let contract : unit contract =
Tezos.get_contract destination_address
| -|Transactions|
let payment : operation = 
Tezos.transaction unit amount receiver
| -|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`| +
+
Strings
+
+ +```cameligo +let name: string = "Tezos" +``` + +
+
+Characters +
+
+ +```cameligo +let t: string = "t" +``` + +
+
+Integers +
+
+ +```cameligo +let i: int = 42 +``` + +
+
+Natural numbers +
+
+ +```cameligo +let n: nat = 7n +``` + +
+
+Unit +
+
+ +```cameligo +let u: unit = unit +``` + +
+
+Boolean +
+
+ +```cameligo +let has_drivers_license: bool = false +let adult: bool = true +``` + +
+
+Boolean Logic +
+
+ +```cameligo +let booleanLogic: bool = + (not true) = + false = + (false && true) = + (false || false) +``` + +
+
+Mutez (micro tez) +
+
+ +```cameligo +let tez: tez = 42tez +let tez: tez = 7mutez +``` + +
+
+Address +
+
+ +```cameligo +let tz1address: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) +let kt1address: address = + ("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address) +``` + +
+
+Addition +
+
+ +```cameligo +let add_int: int = 3 + 4 +let add_nat: nat = 3n + 4n +``` + +
+
+Multiplication & Division +
+
+ +```cameligo +let mul_int: int = 3 + 4 +let mul_nat: nat = 3n + 4n + +let div_int: int = 10 / 5 +let div_nat: nat = 10n / 5n +``` + +
+
+Modulo +
+
+ +```cameligo +let mod_nat: nat = 10 mod 3 +``` + +
+
+Tuples +
+
+ +```cameligo +type name = (string * string) + +let winner: name = "John", "Doe" + +let firstName: string = winner.0 +let lastName: string = winner.1 +``` + +
+
+Types +
+
+ +```cameligo +type age = int +type name = string +``` + +
+
+Includes +
+
+ +```#include "library.mligo"``` + +
+
+Functions +
+
+ +```cameligo +let add (a : int) (b : int) : int = + a + b +``` + +
+ +
+If Statement +
+
+ +```cameligo +let if_statement (age : int) : int = + if age < 16 then + (failwith ("Too young to drive"): int) + else + 1 +``` + +
+
+Options +
+
+ +```cameligo +type middle_name = string option +let middle_name : middle_name = Some "Foo" +let middle_name : middle_name = None +``` + +
+
+Variable Binding +
+
+ +```cameligo +let age: int = 5 +``` + +
+
+Type Annotations +
+
+ +```cameligo +let someAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) +``` + +
+
+Variants +
+
+ +```cameligo group=variants +type action = +| Increment of int +| Decrement of int +``` + +
+
+Variant *(pattern)* matching +
+
+ +```cameligo group=variants +let a: action = Increment 5 +let result: int = match a with +| Increment n -> n + 1 +| Decrement n -> n - 1 +``` + +
+
+Records +
+
+ +```cameligo +type person = { + age: int; + name: string; +} + +let john : person = { + age = 18; + name = "john doe"; +} + +let name: string = john.name +``` + +
+
+Maps +
+
+ +```cameligo +type prices = (nat, tez) map + +let prices: prices = Map.literal [ + (10n, 60mutez); + (50n, 30mutez); + (100n, 10mutez); +] + +let price: tez option = Map.find_opt 50n prices + +let prices : prices = Map.update 200n (Some 5mutez) prices +``` + +
+
+Contracts & Accounts +
+
+ +```cameligo group=tezos_specific +let destinationAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) + +let contract : unit contract = + match (Tezos.get_contract_opt Tezos.sender : unit contract option) with + Some contract -> contract + | None -> (failwith "no contract" : unit contract) +``` + +
+
+Transactions +
+
+ +```cameligo group=tezos_specific + +let payment: operation = + Tezos.transaction unit 100mutez contract + +``` + +
+
+Exception/Failure +
+
+ +```cameligo +let fail (u: unit) : unit = + failwith "a failure message" +``` + +
+
-|Primitive |Example| -|--- |---| -|Strings | `"Tezos"`| -|Characters | `"t"`| -|Integers | `42`, `7`| -|Natural numbers | `42n`, `7n`| -|Unit| `unit`| -|Boolean|
let has_drivers_license: bool = false;
let adult: bool = true;
| -|Boolean Logic|
(not true) = false = (false && true) = (false || false)
| -|Mutez (micro tez)| `42mutez`, `7mutez` | -|Address | `("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)`, `("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)`| -|Addition |`3 + 4`, `3n + 4n`| -|Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`| -|Modulo| `10 mod 3`| -|Tuples|
type name = (string, string);
let winner: name = ("John", "Doe");
let first_name: string = winner[0];
let last_name: string = winner[1];
| -|Types|`type age = int;`, `type name = string;` | -|Includes|```#include "library.mligo"```| -|Functions |
let add = (a: int, b: int) : int => a + b; 
| -| If Statement |
let new_id: int = if (age < 16) {
failwith ("Too young to drive.");
} else { prev_id + 1; }
| -|Options|
type middle_name = option(string);
let middle_name : middle_name = Some("Foo");
let middle_name : middle_name = None;
| -|Variable Binding | ```let age: int = 5;```| -|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```| -|Variants|
type action =
| Increment(int)
| Decrement(int);
| -|Variant *(pattern)* matching|
let a: action = Increment(5);
switch(a) {
| Increment(n) => n + 1
| Decrement(n) => n - 1;
}
| -|Records|
type person = {
  age: int,
  name: string
}

let john : person = {
  age: 18,
  name: "John Doe"
};

let name: string = john.name;
| -|Maps|
type prices = map(nat, tez);

let prices : prices = Map.literal([
  (10n, 60mutez),
  (50n, 30mutez),
  (100n, 10mutez)
]);

let price: option(tez) = Map.find_opt(50n, prices);

let prices: prices = Map.update(200n, Some (5mutez), prices);
| -|Contracts & Accounts|
let destination_address : address = "tz1...";
let contract : contract(unit) =
Tezos.get_contract(destination_address);
| -|Transactions|
let payment : operation = 
Tezos.transaction (unit, amount, receiver);
| -|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.");`| +
+
Strings
+
+ +```reasonligo +let name: string = "Tezos" +``` + +
+
+Characters +
+
+ +```reasonligo +let t: string = "t" +``` + +
+
+Integers +
+
+ +```reasonligo +let i: int = 42 +``` + +
+
+Natural numbers +
+
+ +```reasonligo +let n: nat = 7n +``` + +
+
+Unit +
+
+ +```reasonligo +let u: unit = unit +``` + +
+
+Boolean +
+
+ +```reasonligo +let has_drivers_license: bool = false +let adult: bool = true +``` + +
+
+Boolean Logic +
+
+ +```reasonligo +let booleanLogic: bool = + (!true) == + false == + (false && true) == + (false || false) +``` + +
+
+Mutez (micro tez) +
+
+ +```reasonligo +let tez: tez = 42tez +let tez: tez = 7mutez +``` + +
+
+Address +
+
+ +```reasonligo +let tz1address: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) +let kt1address: address = + ("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address) +``` + +
+
+Addition +
+
+ +```reasonligo +let add_int: int = 3 + 4 +let add_nat: nat = 3n + 4n +``` + +
+
+Multiplication & Division +
+
+ +```reasonligo +let mul_int: int = 3 + 4 +let mul_nat: nat = 3n + 4n + +let div_int: int = 10 / 5 +let div_nat: nat = 10n / 5n +``` + +
+
+Modulo +
+
+ +```reasonligo +let mod_nat: nat = 10 mod 3 +``` + +
+
+Tuples +
+
+ +```reasonligo +type name = (string, string) + +let winner: name = ("John", "Doe") + +let firstName: string = winner[0] +let lastName: string = winner[1] +``` + +
+
+Types +
+
+ +```reasonligo +type age = int +type name = string +``` + +
+
+Includes +
+
+ +```#include "library.religo"``` + +
+
+Functions (short form) +
+
+ +```reasonligo +let add = (a: int, b: int): int => + a + b +``` + +
+
+Functions (long form) +
+
+ +```reasonligo +let add = (a: int, b: int): int => { + let c = a; + let d = b; + c + d +}; +``` + +
+
+If Statement +
+
+ +```reasonligo +let if_statement = (age : int) : int => + if (age < 16) { + (failwith ("Too young to drive"): int) + } else { + 1 + } +``` + +
+
+Options +
+
+ +```reasonligo +type middle_name = option(string); +let middle_name : middle_name = Some ("Foo"); +let middle_name : middle_name = None; +``` + +
+
+Variable Binding +
+
+ +```reasonligo +let age: int = 5 +``` + +
+
+Type Annotations +
+
+ +```reasonligo +let someAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) +``` + +
+
+Variants +
+
+ +```reasonligo group=variants +type action = +| Increment (int) +| Decrement (int) +``` + +
+
+Variant *(pattern)* matching +
+
+ +```reasonligo group=variants +let a: action = Increment(5) +let result: int = switch (a) { +| Increment(n) => n + 1 +| Decrement(n) => n - 1 +} +``` + +
+
+Records +
+
+ +```reasonligo +type person = { + age: int, + name: string +} + +let john : person = { + age: 18, + name: "john doe" +} + +let name: string = john.name +``` + +
+
+Maps +
+
+ +```reasonligo +type prices = map (nat, tez) + +let prices: prices = Map.literal ([ + (10n, 60mutez), + (50n, 30mutez), + (100n, 10mutez), +]) + +let price: option(tez) = Map.find_opt(50n, prices) + +let prices : prices = Map.update(200n, (Some 5mutez), prices) +``` + +
+
+Contracts & Accounts +
+
+ +```reasonligo group=tezos_specific +let destinationAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) + +let contract : contract(unit) = + switch (Tezos.get_contract_opt(Tezos.sender) : option(contract(unit))) { + | Some(contract) => contract + | None => (failwith("no contract") : contract(unit)) + } +``` + +
+
+Transactions +
+
+ +```reasonligo group=tezos_specific + +let payment: operation = + Tezos.transaction(unit, 100mutez, contract); + +``` + +
+
+Exception/Failure +
+
+ +```reasonligo +let fail = (u: unit) : unit => + failwith("a failure message") +``` + +
+
-
diff --git a/gitlab-pages/website/src/theme/CodeBlock/index.js b/gitlab-pages/website/src/theme/CodeBlock/index.js index ca90f0cb0..4c705b717 100644 --- a/gitlab-pages/website/src/theme/CodeBlock/index.js +++ b/gitlab-pages/website/src/theme/CodeBlock/index.js @@ -166,7 +166,7 @@ export default ({children, className: languageClassName, metastring}) => { {showCopied ? 'Copied' : 'Copy'} - + {tokens.map((line, i) => { if (line.length === 1 && line[0].content === '') { line[0].content = '\n'; // eslint-disable-line no-param-reassign diff --git a/gitlab-pages/website/static/css/custom.css b/gitlab-pages/website/static/css/custom.css index b779c2e69..476f1da98 100644 --- a/gitlab-pages/website/static/css/custom.css +++ b/gitlab-pages/website/static/css/custom.css @@ -989,21 +989,43 @@ a:hover { } } - -/* ReasonLIGO specific syntax highlighting */ -.language-reasonligo .hljs-operator { - color: #a626a4; -} -.language-reasonligo .hljs-character { - color: #50a14f; -} -.language-reasonligo .hljs-module-identifier { - color: #00f; -} -.language-reasonligo .hljs-constructor { - color: #a31515; -} - .badge { display: none; } + +.codeTable { + display: grid; + grid-template-columns: 30% 70%; + align-items: center; +} + +.codeTable > .primitive { + width: 100%; + height: 100%; + display: flex; + justify-content: right; + text-align: right; + align-items: center; + font-weight: bold; + padding-right: 1rem; +} + + +.codeTable > div:nth-child(4n+1) { + background-color: var(--ifm-table-stripe-background); +} + +.codeTable > div:nth-child(4n+2) { + background-color: var(--ifm-table-stripe-background); +} + + +.codeTable > .example { + padding-top: var(--ifm-leading); +} + +.codeTable > .example pre, +.codeTable > .example .codeBlockLines_src-theme-CodeBlock- { + background-color: transparent; +} + From d059cf991b6b5d052683c49c6977e53ffe04641f Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Tue, 24 Mar 2020 13:58:18 +0100 Subject: [PATCH 3/8] Give an error when nesting a big_map inside another big_map --- gitlab-pages/docs/reference/big_map.md | 38 +++++++------ src/bin/expect_tests/contract_tests.ml | 54 ++++++++++++++++++- ...t_limit.ml => entrypoints_length_limit.ml} | 0 .../self_ast_imperative.ml | 2 +- .../9-self_ast_typed/no_nested_big_map.ml | 53 ++++++++++++++++++ src/passes/9-self_ast_typed/self_ast_typed.ml | 1 + .../contracts/negative/nested_bigmap_1.religo | 10 ++++ .../contracts/negative/nested_bigmap_2.religo | 9 ++++ .../contracts/negative/nested_bigmap_3.religo | 15 ++++++ .../contracts/negative/nested_bigmap_4.religo | 9 ++++ 10 files changed, 172 insertions(+), 19 deletions(-) rename src/passes/3-self_ast_imperative/{entrypoints_lenght_limit.ml => entrypoints_length_limit.ml} (100%) create mode 100644 src/passes/9-self_ast_typed/no_nested_big_map.ml create mode 100644 src/test/contracts/negative/nested_bigmap_1.religo create mode 100644 src/test/contracts/negative/nested_bigmap_2.religo create mode 100644 src/test/contracts/negative/nested_bigmap_3.religo create mode 100644 src/test/contracts/negative/nested_bigmap_4.religo diff --git a/gitlab-pages/docs/reference/big_map.md b/gitlab-pages/docs/reference/big_map.md index e20bdc48c..dc5893df1 100644 --- a/gitlab-pages/docs/reference/big_map.md +++ b/gitlab-pages/docs/reference/big_map.md @@ -8,9 +8,13 @@ hide_table_of_contents: true import Syntax from '@theme/Syntax'; import SyntaxTitle from '@theme/SyntaxTitle'; -A lazily deserialized map that's intended to store large amounts of data. +A lazily deserialized map that's intended to store large amounts of data. +Lazily means that storage is read or written per key on demand. Therefore +there are no `map`, `fold`, and `iter` operations as in +[Map](./map-reference). -The gast costs of deserialized maps are higher than standard maps as data is lazily deserialized. +The gast costs of big maps are higher than standard maps as data is lazily +deserialized. type big_map ('key, 'value) @@ -47,11 +51,11 @@ type register = (address, move) big_map The type of a big map from values of type `key` to -values of type `value` is `big_map (key, value)`. +values of type `value` is `big_map(key, value)`. ```reasonligo group=big_map type move = (int, int); -type register = big_map (address, move); +type register = big_map(address, move); ``` @@ -63,7 +67,7 @@ function empty : big_map ('key, 'value) val empty : ('key, 'value) big_map -let empty: big_map ('key, 'value) +let empty: big_map('key, 'value) Create an empty big_map. @@ -91,7 +95,7 @@ let empty : register = Big_map.empty ```reasonligo group=big_map -let empty : register = Big_map.empty +let empty: register = Big_map.empty ``` @@ -141,7 +145,7 @@ let moves : register = ```reasonligo group=big_map -let moves : register = +let moves: register = Big_map.literal ([ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]); @@ -156,7 +160,7 @@ function find_opt : 'key -> big_map ('key, 'value) -> option 'value val find_opt : 'key -> ('key, 'value) big_map -> 'value option -let find_opt : ('key, big_map ('key, 'value)) => option ('value) +let find_opt: ('key, big_map ('key, 'value)) => option ('value) Retrieve a value from a big map with the given key. @@ -191,8 +195,8 @@ let my_balance : move option = ```reasonligo group=big_map -let my_balance : option (move) = - Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves); +let my_balance: option (move) = + Big_map.find_opt("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, moves); ``` @@ -204,7 +208,7 @@ function update : 'key -> option 'value -> big_map ('key, 'value) -> big_map ('k val update: 'key -> 'value option -> ('key, 'value) big_map -> ('key, 'value) big_map -let update: ('key, option('value), big_map ('key, 'value)) => big_map ('key, 'value) +let update: ('key, option('value), big_map('key, 'value)) => big_map('key, 'value) Note: when `None` is used as a value, the value is removed from the big_map. @@ -255,9 +259,9 @@ let updated_map : register = ```reasonligo group=big_map -let updated_map : register = +let updated_map: register = Big_map.update - (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves); + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some((4,9)), moves); ``` @@ -292,7 +296,7 @@ let add (m : register) : register = ```reasonligo group=big_map let add = (m: register): register => Big_map.add - (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m); + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), (4,9), m); ``` @@ -305,7 +309,7 @@ function remove: 'key -> big_map ('key, 'value) -> big_map ('key, 'value) val remove: 'key -> ('key, 'value) big_map -> ('key, 'value) big_map -let remove: ('key, big_map ('key, 'value)) => big_map ('key, 'value) +let remove: ('key, big_map('key, 'value)) => big_map('key, 'value) @@ -340,8 +344,8 @@ let updated_map : register = ```reasonligo group=big_map -let updated_map : register = - Big_map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves) +let updated_map: register = + Big_map.remove(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves) ``` diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 3785881be..984a0163b 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -1344,4 +1344,56 @@ let%expect_test _ = * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ * Ask a question on our Discord: https://discord.gg/9rhYaEt * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new - * Check the changelog by running 'ligo changelog' |}] + * Check the changelog by running 'ligo changelog' |}]; + + run_ligo_bad ["compile-contract"; bad_contract "nested_bigmap_1.religo"; "main"]; + [%expect {| + ligo: It looks like you have nested a big map inside another big map. This is not supported. : {} + + + If you're not sure how to fix this error, you can + do one of the following: + + * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ + * Ask a question on our Discord: https://discord.gg/9rhYaEt + * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new + * Check the changelog by running 'ligo changelog' |}]; + + run_ligo_bad ["compile-contract"; bad_contract "nested_bigmap_2.religo"; "main"]; + [%expect {| + ligo: It looks like you have nested a big map inside another big map. This is not supported. : {} + + + If you're not sure how to fix this error, you can + do one of the following: + + * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ + * Ask a question on our Discord: https://discord.gg/9rhYaEt + * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new + * Check the changelog by running 'ligo changelog' |}]; + + run_ligo_bad ["compile-contract"; bad_contract "nested_bigmap_3.religo"; "main"]; + [%expect {| + ligo: It looks like you have nested a big map inside another big map. This is not supported. : {} + + + If you're not sure how to fix this error, you can + do one of the following: + + * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ + * Ask a question on our Discord: https://discord.gg/9rhYaEt + * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new + * Check the changelog by running 'ligo changelog' |}]; + + run_ligo_bad ["compile-contract"; bad_contract "nested_bigmap_4.religo"; "main"]; + [%expect {| + ligo: It looks like you have nested a big map inside another big map. This is not supported. : {} + + + If you're not sure how to fix this error, you can + do one of the following: + + * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ + * Ask a question on our Discord: https://discord.gg/9rhYaEt + * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new + * Check the changelog by running 'ligo changelog' |}] \ No newline at end of file diff --git a/src/passes/3-self_ast_imperative/entrypoints_lenght_limit.ml b/src/passes/3-self_ast_imperative/entrypoints_length_limit.ml similarity index 100% rename from src/passes/3-self_ast_imperative/entrypoints_lenght_limit.ml rename to src/passes/3-self_ast_imperative/entrypoints_length_limit.ml diff --git a/src/passes/3-self_ast_imperative/self_ast_imperative.ml b/src/passes/3-self_ast_imperative/self_ast_imperative.ml index a10968c0c..b0270ebd0 100644 --- a/src/passes/3-self_ast_imperative/self_ast_imperative.ml +++ b/src/passes/3-self_ast_imperative/self_ast_imperative.ml @@ -6,7 +6,7 @@ let all_expression_mapper = [ Literals.peephole_expression ; ] let all_type_expression_mapper = [ - Entrypoints_lenght_limit.peephole_type_expression ; + Entrypoints_length_limit.peephole_type_expression ; ] let all_exp = List.map (fun el -> Helpers.Expression el) all_expression_mapper diff --git a/src/passes/9-self_ast_typed/no_nested_big_map.ml b/src/passes/9-self_ast_typed/no_nested_big_map.ml new file mode 100644 index 000000000..6e5ca3cd6 --- /dev/null +++ b/src/passes/9-self_ast_typed/no_nested_big_map.ml @@ -0,0 +1,53 @@ +open Ast_typed +open Trace + +type contract_pass_data = Contract_passes.contract_pass_data + +module Errors = struct + let no_nested_bigmap () = + let title = (thunk ("It looks like you have nested a big map inside another big map. This is not supported. ")) in + let message () = "" in + let data = [ + (* ("location" , fun () -> Format.asprintf "%a" Location.pp loc) TODO once types have an actual location *) + ] in + error ~data title message () +end + +let rec check_no_nested_bigmap is_in_bigmap e = + match e.type_content with + | T_operator (TC_big_map (_, _)) when is_in_bigmap -> + fail @@ Errors.no_nested_bigmap + | T_operator (TC_big_map (key, value)) -> + let%bind _ = check_no_nested_bigmap true key in + let%bind _ = check_no_nested_bigmap true value in + ok () + | T_operator (TC_contract t) + | T_operator (TC_option t) + | T_operator (TC_list t) + | T_operator (TC_set t) -> + let%bind _ = check_no_nested_bigmap is_in_bigmap t in + ok () + | T_operator (TC_map (a, b)) + | T_operator (TC_arrow (a, b)) -> + let%bind _ = check_no_nested_bigmap is_in_bigmap a in + let%bind _ = check_no_nested_bigmap is_in_bigmap b in + ok () + | T_sum s -> + let es = CMap.to_list s in + let%bind _ = bind_map_list (fun l -> check_no_nested_bigmap is_in_bigmap l) es in + ok () + | T_record elm -> + let es = LMap.to_list elm in + let%bind _ = bind_map_list (fun l -> check_no_nested_bigmap is_in_bigmap l) es in + ok () + | T_arrow { type1; type2 } -> + let%bind _ = check_no_nested_bigmap is_in_bigmap type1 in + let%bind _ = check_no_nested_bigmap is_in_bigmap type2 in + ok () + | T_variable _ + | T_constant _ -> + ok () + +let self_typing : contract_pass_data -> expression -> (bool * contract_pass_data * expression) result = fun dat el -> + let%bind _ = check_no_nested_bigmap false el.type_expression in + ok (true, dat, el) diff --git a/src/passes/9-self_ast_typed/self_ast_typed.ml b/src/passes/9-self_ast_typed/self_ast_typed.ml index 76bfbdf90..e8dfefdce 100644 --- a/src/passes/9-self_ast_typed/self_ast_typed.ml +++ b/src/passes/9-self_ast_typed/self_ast_typed.ml @@ -6,6 +6,7 @@ let all_passes = [ let contract_passes = [ Contract_passes.self_typing ; + No_nested_big_map.self_typing ; ] let all_program = diff --git a/src/test/contracts/negative/nested_bigmap_1.religo b/src/test/contracts/negative/nested_bigmap_1.religo new file mode 100644 index 000000000..b86e549b1 --- /dev/null +++ b/src/test/contracts/negative/nested_bigmap_1.religo @@ -0,0 +1,10 @@ +type bar = big_map (nat, int); + +/* this should result in an error as nested big_maps are not supported: */ +type storage = big_map (int, bar); + +type return = (list (operation), storage); + +let main = ((ignore, store): (unit, storage)): return => { + ([]: list(operation), store) +}; diff --git a/src/test/contracts/negative/nested_bigmap_2.religo b/src/test/contracts/negative/nested_bigmap_2.religo new file mode 100644 index 000000000..d8061f912 --- /dev/null +++ b/src/test/contracts/negative/nested_bigmap_2.religo @@ -0,0 +1,9 @@ +/* this should result in an error as nested big_maps are not supported: */ +type storage = big_map (nat, big_map (int, string)); + +type return = (list (operation), storage); + +let main = ((ignore, store): (unit, storage)): return => { + ([]: list(operation), store) +}; + \ No newline at end of file diff --git a/src/test/contracts/negative/nested_bigmap_3.religo b/src/test/contracts/negative/nested_bigmap_3.religo new file mode 100644 index 000000000..e8941f445 --- /dev/null +++ b/src/test/contracts/negative/nested_bigmap_3.religo @@ -0,0 +1,15 @@ +type bar = big_map (nat, int); + +type foo = { + a: int, + b: bar +}; + +/* this should result in an error as nested big_maps are not supported: */ +type storage = big_map(nat, foo); + +type return = (list (operation), storage); + +let main = ((ignore, store): (unit, storage)): return => { + ([]: list(operation), store) +}; diff --git a/src/test/contracts/negative/nested_bigmap_4.religo b/src/test/contracts/negative/nested_bigmap_4.religo new file mode 100644 index 000000000..653908636 --- /dev/null +++ b/src/test/contracts/negative/nested_bigmap_4.religo @@ -0,0 +1,9 @@ +/* this should result in an error as nested big_maps are not supported: */ +type storage = map (int, big_map (nat, big_map (int, string))); + +type return = (list (operation), storage); + +let main = ((ignore, store): (unit, storage)): return => { + ([]: list(operation), store) +}; + \ No newline at end of file From 715c3a8eac0990842f9fac175d85d30fa18217f3 Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Tue, 24 Mar 2020 14:01:04 +0100 Subject: [PATCH 4/8] Inform that it's not possible to nest a big map inside another big map --- gitlab-pages/docs/reference/big_map.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gitlab-pages/docs/reference/big_map.md b/gitlab-pages/docs/reference/big_map.md index dc5893df1..104751667 100644 --- a/gitlab-pages/docs/reference/big_map.md +++ b/gitlab-pages/docs/reference/big_map.md @@ -60,6 +60,8 @@ type register = big_map(address, move); +Be aware that a `big_map` cannot appear inside another `big_map`. + function empty : big_map ('key, 'value) From 75735cd6ed4aa1ac6768334cbeea7a8927ff960a Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Tue, 24 Mar 2020 14:41:37 +0100 Subject: [PATCH 5/8] Fix tutorial error. --- .../docs/tutorials/get-started/tezos-taco-shop-payout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.md b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.md index 3d9330894..9207f7817 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.md +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.md @@ -169,7 +169,7 @@ function buy_taco (const taco_kind_index : nat ; var taco_shop_storage : taco_sh const receiver : contract(unit) = get_contract (ownerAddress); const payoutOperation : operation = transaction (unit, amount, receiver); const operations : list(operation) = list [payoutOperation] - } with ((nil : list (operation)), taco_shop_storage) + } with ((operations : list (operation)), taco_shop_storage) ``` ### Dry-run the Contract From 9b192d8ba2f38c42d4a01e81fd9d1c92ab0de656 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Mon, 23 Mar 2020 16:07:40 +0100 Subject: [PATCH 6/8] done --- src/bin/cli.ml | 36 +++++++++++++++++++++++++----- src/bin/expect_tests/help_tests.ml | 32 +++++++++++++++++++------- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/bin/cli.ml b/src/bin/cli.ml index 1c9a60fe1..246524f1c 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -167,8 +167,8 @@ let print_cst = let print_ast = let f source_file syntax display_format = ( toplevel ~display_format @@ - let%bind core = Compile.Utils.to_core source_file syntax in - ok @@ Format.asprintf "%a\n" Compile.Of_core.pretty_print core + let%bind imperative = Compile.Utils.to_imperatve source_file syntax in + ok @@ Format.asprintf "%a\n" Compile.Of_imperative.pretty_print imperative ) in let term = Term.(const f $ source_file 0 $ syntax $ display_format) in @@ -176,7 +176,31 @@ let print_ast = let doc = "Subcommand: Print the AST.\n Warning: Intended for development of LIGO and can break at any time." in (Term.ret term, Term.info ~doc cmdname) -let print_typed_ast = +let print_ast_sugar = + let f source_file syntax display_format = ( + toplevel ~display_format @@ + let%bind sugar = Compile.Utils.to_sugar source_file syntax in + ok @@ Format.asprintf "%a\n" Compile.Of_sugar.pretty_print sugar + ) + in + let term = Term.(const f $ source_file 0 $ syntax $ display_format) in + let cmdname = "print-ast-sugar" in + let doc = "Subcommand: Print the AST.\n Warning: Intended for development of LIGO and can break at any time." in + (Term.ret term, Term.info ~doc cmdname) + +let print_ast_core = + let f source_file syntax display_format = ( + toplevel ~display_format @@ + let%bind core = Compile.Utils.to_core source_file syntax in + ok @@ Format.asprintf "%a\n" Compile.Of_core.pretty_print core + ) + in + let term = Term.(const f $ source_file 0 $ syntax $ display_format) in + let cmdname = "print-ast-core" in + let doc = "Subcommand: Print the AST.\n Warning: Intended for development of LIGO and can break at any time." in + (Term.ret term, Term.info ~doc cmdname) + +let print_ast_typed = let f source_file syntax display_format = ( toplevel ~display_format @@ let%bind typed,_ = Compile.Utils.type_file source_file syntax Env in @@ -184,7 +208,7 @@ let print_typed_ast = ) in let term = Term.(const f $ source_file 0 $ syntax $ display_format) in - let cmdname = "print-typed-ast" in + let cmdname = "print-ast-typed" in let doc = "Subcommand: Print the typed AST.\n Warning: Intended for development of LIGO and can break at any time." in (Term.ret term, Term.info ~doc cmdname) @@ -441,7 +465,9 @@ let run ?argv () = dump_changelog ; print_cst ; print_ast ; - print_typed_ast ; + print_ast_sugar ; + print_ast_core ; + print_ast_typed ; print_mini_c ; list_declarations ; ] diff --git a/src/bin/expect_tests/help_tests.ml b/src/bin/expect_tests/help_tests.ml index d1028bfab..f960cc6b9 100644 --- a/src/bin/expect_tests/help_tests.ml +++ b/src/bin/expect_tests/help_tests.ml @@ -57,6 +57,18 @@ let%expect_test _ = Subcommand: Print the AST. Warning: Intended for development of LIGO and can break at any time. + print-ast-core + Subcommand: Print the AST. Warning: Intended for development of + LIGO and can break at any time. + + print-ast-sugar + Subcommand: Print the AST. Warning: Intended for development of + LIGO and can break at any time. + + print-ast-typed + Subcommand: Print the typed AST. Warning: Intended for development + of LIGO and can break at any time. + print-cst Subcommand: Print the CST. Warning: Intended for development of LIGO and can break at any time. @@ -65,10 +77,6 @@ let%expect_test _ = Subcommand: Print Mini-C. Warning: Intended for development of LIGO and can break at any time. - print-typed-ast - Subcommand: Print the typed AST. Warning: Intended for development - of LIGO and can break at any time. - run-function Subcommand: Run a function with the given parameter. @@ -136,6 +144,18 @@ let%expect_test _ = Subcommand: Print the AST. Warning: Intended for development of LIGO and can break at any time. + print-ast-core + Subcommand: Print the AST. Warning: Intended for development of + LIGO and can break at any time. + + print-ast-sugar + Subcommand: Print the AST. Warning: Intended for development of + LIGO and can break at any time. + + print-ast-typed + Subcommand: Print the typed AST. Warning: Intended for development + of LIGO and can break at any time. + print-cst Subcommand: Print the CST. Warning: Intended for development of LIGO and can break at any time. @@ -144,10 +164,6 @@ let%expect_test _ = Subcommand: Print Mini-C. Warning: Intended for development of LIGO and can break at any time. - print-typed-ast - Subcommand: Print the typed AST. Warning: Intended for development - of LIGO and can break at any time. - run-function Subcommand: Run a function with the given parameter. From cb54cd1210f5f8c8695834210a037186aa31eccc Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Thu, 26 Mar 2020 09:23:43 +0100 Subject: [PATCH 7/8] Lambda's and keys shouldn't give errors for nesting big maps. --- src/passes/9-self_ast_typed/no_nested_big_map.ml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/passes/9-self_ast_typed/no_nested_big_map.ml b/src/passes/9-self_ast_typed/no_nested_big_map.ml index 6e5ca3cd6..e1a130ce9 100644 --- a/src/passes/9-self_ast_typed/no_nested_big_map.ml +++ b/src/passes/9-self_ast_typed/no_nested_big_map.ml @@ -18,7 +18,7 @@ let rec check_no_nested_bigmap is_in_bigmap e = | T_operator (TC_big_map (_, _)) when is_in_bigmap -> fail @@ Errors.no_nested_bigmap | T_operator (TC_big_map (key, value)) -> - let%bind _ = check_no_nested_bigmap true key in + let%bind _ = check_no_nested_bigmap false key in let%bind _ = check_no_nested_bigmap true value in ok () | T_operator (TC_contract t) @@ -27,11 +27,14 @@ let rec check_no_nested_bigmap is_in_bigmap e = | T_operator (TC_set t) -> let%bind _ = check_no_nested_bigmap is_in_bigmap t in ok () - | T_operator (TC_map (a, b)) - | T_operator (TC_arrow (a, b)) -> + | T_operator (TC_map (a, b)) -> let%bind _ = check_no_nested_bigmap is_in_bigmap a in let%bind _ = check_no_nested_bigmap is_in_bigmap b in ok () + | T_operator (TC_arrow (a, b)) -> + let%bind _ = check_no_nested_bigmap false a in + let%bind _ = check_no_nested_bigmap false b in + ok () | T_sum s -> let es = CMap.to_list s in let%bind _ = bind_map_list (fun l -> check_no_nested_bigmap is_in_bigmap l) es in @@ -41,8 +44,8 @@ let rec check_no_nested_bigmap is_in_bigmap e = let%bind _ = bind_map_list (fun l -> check_no_nested_bigmap is_in_bigmap l) es in ok () | T_arrow { type1; type2 } -> - let%bind _ = check_no_nested_bigmap is_in_bigmap type1 in - let%bind _ = check_no_nested_bigmap is_in_bigmap type2 in + let%bind _ = check_no_nested_bigmap false type1 in + let%bind _ = check_no_nested_bigmap false type2 in ok () | T_variable _ | T_constant _ -> From 38a61f5cb34cb28528afc1698d3aab12af819d0c Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Thu, 26 Mar 2020 11:06:52 +0100 Subject: [PATCH 8/8] Improve String.sub api documentation. --- gitlab-pages/docs/reference/string.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitlab-pages/docs/reference/string.md b/gitlab-pages/docs/reference/string.md index b61453ec7..afe9ebaa3 100644 --- a/gitlab-pages/docs/reference/string.md +++ b/gitlab-pages/docs/reference/string.md @@ -73,8 +73,8 @@ val sub : nat -> nat -> string -> string let sub: (nat, nat, string) => string -Get the substring of `s` between `pos1` inclusive and `pos2` inclusive. For example -the string "tata" given to the function below would return "at". +Extract a substring from a string based on the given offset and length. For +example the string "abcd" given to the function below would return "bc".