From f4d688df7bfd4a344f8f938391243b38987692d5 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Fri, 21 Feb 2020 17:16:53 +0100 Subject: [PATCH 01/53] Fixed the tutorial. Enabled underscores in tez amounts. Fixed docs on Tez and tuples (zero-indexation). --- .../docs/language-basics/math-numbers-tez.md | 29 +- .../docs/language-basics/sets-lists-tuples.md | 14 +- .../get-started/tezos-taco-shop-payout.ligo | 61 +-- .../get-started/tezos-taco-shop-payout.md | 234 ++++++----- .../tezos-taco-shop-smart-contract.ligo | 44 +- .../tezos-taco-shop-smart-contract.md | 394 +++++++++++------- gitlab-pages/owner.pp.ligo | 0 gitlab-pages/timestamp.pp.ligo | 0 .../version-next-sidebars.json | 12 +- src/passes/1-parser/shared/Lexer.mll | 15 +- 10 files changed, 493 insertions(+), 310 deletions(-) delete mode 100644 gitlab-pages/owner.pp.ligo delete mode 100644 gitlab-pages/timestamp.pp.ligo diff --git a/gitlab-pages/docs/language-basics/math-numbers-tez.md b/gitlab-pages/docs/language-basics/math-numbers-tez.md index 41d05ed5d..7d8c2342a 100644 --- a/gitlab-pages/docs/language-basics/math-numbers-tez.md +++ b/gitlab-pages/docs/language-basics/math-numbers-tez.md @@ -3,7 +3,28 @@ id: math-numbers-tez title: Math, Numbers & Tez --- -LIGO offers three built-in numerical types: `int`, `nat` and `tez`. +LIGO offers three built-in numerical types: `int`, `nat` and +`tez`. Values of type `int` are integers; values of type `nat` are +natural numbers (integral numbers greater than or equal to zero); +values of type `tez` are units of measure of Tezos tokens. + + * Integer literals are the same found in mainstream programming + languages, for example, `10`, `-6` and `0`, but there is only one + canonical zero: `0` (so, for instance, `-0` and `00` are invalid). + + * Natural numbers are written as digits follwed by the suffix `n`, + like so: `12n`, `0n`, and the same restriction on zero as integers + applies: `0n` is the only way to specify the natural zero. + + * Tezos tokens can be specified using literals of three kinds: + * units of millionth of `tez`, using the suffix `mutez` after a + natural literal, like `10000mutez` or `0mutez`; + * units of `tez`, using the suffix `tz` or `tez`, like `3tz` or + `3tez`; + * decimal amounts of `tz` or `tez`, like `12.3tz` or `12.4tez`. + +Note that large integral values can be expressed using underscores to +separate groups of digits, like `1_000mutez` or `0.000_004tez`. ## Addition @@ -27,7 +48,7 @@ const a : int = 5 + 10 const b : int = 5n + 10 // tez + tez yields tez -const c : tez = 5mutez + 10mutez +const c : tez = 5mutez + 0.000_010tez //tez + int or tez + nat is invalid // const d : tez = 5mutez + 10n @@ -57,7 +78,7 @@ let a : int = 5 + 10 let b : int = 5n + 10 // tez + tez yields tez -let c : tez = 5mutez + 10mutez +let c : tez = 5mutez + 0.000_010tez // tez + int or tez + nat is invalid // let d : tez = 5mutez + 10n @@ -87,7 +108,7 @@ let a : int = 5 + 10; let b : int = 5n + 10; // tez + tez yields tez -let c : tez = 5mutez + 10mutez; +let c : tez = 5mutez + 0.000_010tez; // tez + int or tez + nat is invalid: // let d : tez = 5mutez + 10n; diff --git a/gitlab-pages/docs/language-basics/sets-lists-tuples.md b/gitlab-pages/docs/language-basics/sets-lists-tuples.md index a3db92b6d..6a38d6104 100644 --- a/gitlab-pages/docs/language-basics/sets-lists-tuples.md +++ b/gitlab-pages/docs/language-basics/sets-lists-tuples.md @@ -62,32 +62,28 @@ Accessing the components of a tuple in OCaml is achieved by [pattern matching](language-basics/unit-option-pattern-matching.md). LIGO currently supports tuple patterns only in the parameters of functions, not in pattern matching. However, we can access components by their -position in their tuple, which cannot be done in OCaml. +position in their tuple, which cannot be done in OCaml. *Tuple +components are zero-indexed*, that is, the first component has index +`0`. -Tuple components are one-indexed and accessed like so: - ```pascaligo group=tuple -const first_name : string = full_name.1 +const first_name : string = full_name.0 ``` -Tuple elements are zero-indexed and accessed like so: - ```cameligo group=tuple let first_name : string = full_name.0 ``` -Tuple components are one-indexed and accessed like so: - ```reasonligo group=tuple -let first_name : string = full_name[1]; +let first_name : string = full_name[0]; ``` diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo index 5623eaf3f..9cf169397 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo @@ -1,37 +1,46 @@ -type taco_supply is record +type taco_supply is + record [ current_stock : nat; - max_price : tez; -end -type taco_shop_storage is map(nat, taco_supply); + max_price : tez + ] -const ownerAddress: address = "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV"; -const donationAddress: address = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"; +type taco_shop_storage is map (nat, taco_supply) -function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : (list(operation) * taco_shop_storage) is - begin - // Retrieve the taco_kind from the contract's storage - const taco_kind : taco_supply = get_force(taco_kind_index, taco_shop_storage); - - const current_purchase_price : tez = taco_kind.max_price / taco_kind.current_stock; +type return is list (operation) * taco_shop_storage + +const ownerAddress : address = "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" +const donationAddress : address = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" + +function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is + block { + // Retrieve the taco_kind from the contract's storage or fail + const taco_kind : taco_supply = + case taco_shop_storage[taco_kind_index] of + Some (kind) -> kind + | None -> (failwith ("Unknown kind of taco.") : taco_supply) + end; + + const current_purchase_price : tez = + taco_kind.max_price / taco_kind.current_stock; if amount =/= current_purchase_price then - // we won't sell tacos if the amount isn't correct - fail("Sorry, the taco you're trying to purchase has a different price"); - else - // Decrease the stock by 1n, because we've just sold one - taco_kind.current_stock := abs(taco_kind.current_stock - 1n); + // We won't sell tacos if the amount is not correct + failwith ("Sorry, the taco you are trying to purchase has a different price"); + else skip; + + // Decrease the stock by 1n, because we have just sold one + taco_kind.current_stock := abs (taco_kind.current_stock - 1n); // Update the storage with the refreshed taco_kind taco_shop_storage[taco_kind_index] := taco_kind; - const receiver: contract(unit) = get_contract(ownerAddress); - const donationReceiver: contract(unit) = get_contract(donationAddress); + const receiver : contract (unit) = get_contract (ownerAddress); + const donationReceiver : contract (unit) = get_contract (donationAddress); - const donationAmount: tez = amount / 10n; + const donationAmount : tez = amount / 10n; - const operations : list(operation) = list - transaction(unit, amount - donationAmount, receiver); - transaction(unit, donationAmount, donationReceiver); - end; - - end with (operations, taco_shop_storage) \ No newline at end of file + const operations : list (operation) = list [ + transaction (unit, amount - donationAmount, receiver); + transaction (unit, donationAmount, donationReceiver); + ] + } with (operations, taco_shop_storage) 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 ae9a1b8e3..2d02544d5 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 @@ -3,8 +3,14 @@ id: tezos-taco-shop-payout title: Paying out profits from the Taco Shop --- -In the [previous tutorial](tutorials/get-started/tezos-taco-shop-smart-contract.md) we've learned how to setup & interact with the LIGO CLI. Followed by implementation of a simple Taco Shop smart contract for our entepreneur Pedro. In this tutorial we'll make sure Pedro has access to tokens that people have spent at his shop when buying tacos. +In the +[previous tutorial](tutorials/get-started/tezos-taco-shop-smart-contract.md) +we have learnt how to setup & interact with the LIGO CLI. Followed an +implementation of a simple Taco Shop smart contract for our +entrepreneur Pedro. +In this tutorial we will make sure Pedro has access to tokens that +people have spent at his shop when buying tacos.
@@ -14,133 +20,173 @@ In the [previous tutorial](tutorials/get-started/tezos-taco-shop-smart-contract. -## Analyzing the current contract +## Analyzing the Current Contract ### **`taco-shop.ligo`** ```pascaligo group=a -type taco_supply is record - current_stock : nat; - max_price : tez; -end -type taco_shop_storage is map(nat, taco_supply); +type taco_supply is record [ + current_stock : nat; + max_price : tez +] -function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : - (list(operation) * taco_shop_storage) is - begin - // Retrieve the taco_kind from the contract's storage - const taco_kind : taco_supply = get_force(taco_kind_index, taco_shop_storage); - - const current_purchase_price : tez = taco_kind.max_price / taco_kind.current_stock; +type taco_shop_storage is map (nat, taco_supply) + +type return is list (operation) * taco_shop_storage + +function buy_taco (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is + block { + // Retrieve the taco_kind from the contract's storage or fail + const taco_kind : taco_supply = + case taco_shop_storage[taco_kind_index] of + Some (kind) -> kind + | None -> (failwith ("Unknown kind of taco.") : taco_supply) + end; + + const current_purchase_price : tez = + taco_kind.max_price / taco_kind.current_stock; if amount =/= current_purchase_price then - // we won't sell tacos if the amount isn't correct - failwith("Sorry, the taco you're trying to purchase has a different price"); - else - // Decrease the stock by 1n, because we've just sold one - taco_kind.current_stock := abs(taco_kind.current_stock - 1n); + // We won't sell tacos if the amount is not correct + failwith ("Sorry, the taco you are trying to purchase has a different price"); + else skip; + + // Decrease the stock by 1n, because we have just sold one + taco_kind.current_stock := abs (taco_kind.current_stock - 1n); // Update the storage with the refreshed taco_kind - taco_shop_storage[taco_kind_index] := taco_kind; - end with ((nil : list(operation)), taco_shop_storage) + taco_shop_storage[taco_kind_index] := taco_kind + } with ((nil : list (operation)), taco_shop_storage) ``` -### Purchase price formula -Pedro's Taco Shop contract currently enables customers to buy tacos, at a computed price based on a simple formula. +### Purchase Price Formula + +Pedro's Taco Shop contract currently enables customers to buy tacos, +at a price based on a simple formula. ```pascaligo skip -const current_purchase_price : tez = taco_kind.max_price / taco_kind.current_stock; +const current_purchase_price : tez = + taco_kind.max_price / taco_kind.current_stock ``` -### Replacing *spendable* smart contracts -However, due to the [recent protocol upgrade](http://tezos.gitlab.io/mainnet/protocols/004_Pt24m4xi.html) of the Tezos mainnet, Pedro can't access the tokens stored in his Shop's contract directly. This was previously possible via `spendable` smart contracts, which are no longer available in the new protocol. We will have to implement a solution to access tokens from the contract programatically. +### Replacing *spendable* Smart Contracts + +However, due to the +[recent protocol upgrade](http://tezos.gitlab.io/mainnet/protocols/004_Pt24m4xi.html) +of the Tezos `mainnet`, Pedro cannot access the tokens stored in his +shop's contract directly. This was previously possible via *spendable +smart contracts*, which are no longer available in the new +protocol. We will have to implement a solution to access tokens from +the contract programatically. --- -## Designing a payout scheme +## Designing a Payout Scheme -Pedro is a standalone bussines owner, and in our case, he doesn't have to split profits / earnings of the taco shop with anyone. So for the sake of simplicity, we'll payout all the earned XTZ directly to Pedro right after a succesful taco purchase. +Pedro is a standalone bussines owner, and in our case, he does not +have to split profits and earnings of the taco shop with anyone. So +for the sake of simplicity, we will payout all the earned XTZ directly +to Pedro right after a succesful purchase. -This means that after all the *purchase conditions* of our contract are met - e.g. correct amount is sent to the contract - we'll not only decrease the supply of the individual purchased *taco kind*, but we'll also transfer this amount in a *subsequent transaction* to Pedro's personal address. +This means that after all the *purchase conditions* of our contract +are met, e.g., the correct amount is sent to the contract, we will not +only decrease the supply of the individual purchased *taco kind*, but +we will also transfer this amount in a *subsequent transaction* to +Pedro's personal address. -## Forging a payout transaction +## Forging a Payout Transaction -### Defining the recipient -In order to send tokens, we will need a receiver address - which in our case will be Pedro's personal account. Additionally we'll wrap the given address as a *`contract(unit)`* - which represents either a contract with no parameters, or an implicit account. +### Defining the Recipient + +In order to send tokens, we will need a receiver address, which, in +our case, will be Pedro's personal account. Additionally we will wrap +the given address as a *`contract (unit)`*, which represents either a +contract with no parameters, or an implicit account. ```pascaligo group=ex1 const ownerAddress : address = ("tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" : address); -const receiver : contract(unit) = get_contract(ownerAddress); +const receiver : contract (unit) = get_contract (ownerAddress); ``` -> Would you like to learn more about addresses, contracts and operations in LIGO? Check out the [LIGO cheat sheet](api/cheat-sheet.md) +> Would you like to learn more about addresses, contracts and +> operations in LIGO? Check out the +> [LIGO cheat sheet](api/cheat-sheet.md) -### Adding the transaction to the list of output operations -Now we can transfer the `amount` received by `buy_taco` to Pedro's `ownerAddress`. We will do so by forging a `transaction(unit, amount, receiver)` within a list of operations returned at the end of our contract. +### Adding the Transaction to the List of Output Operations +Now we can transfer the amount received by `buy_taco` to Pedro's +`ownerAddress`. We will do so by forging a `transaction (unit, amount, +receiver)` within a list of operations returned at the end of our +contract. ```pascaligo group=ex1 -const payoutOperation : operation = transaction(unit, amount, receiver) ; -const operations : list(operation) = list - payoutOperation -end; +const payoutOperation : operation = transaction (unit, amount, receiver) ; +const operations : list (operation) = list [payoutOperation]; ``` --- -## Finalizing the contract +## Finalizing the Contract ### **`taco-shop.ligo`** ```pascaligo group=b -type taco_supply is record - current_stock : nat; - max_price : tez; -end -type taco_shop_storage is map(nat, taco_supply); +type taco_supply is record [ + current_stock : nat; + max_price : tez +] -const ownerAddress: address = ("tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" : address); +type taco_shop_storage is map (nat, taco_supply) -function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : (list(operation) * taco_shop_storage) is - begin - // Retrieve the taco_kind from the contract's storage - const taco_kind : taco_supply = get_force(taco_kind_index, taco_shop_storage); - - const current_purchase_price : tez = taco_kind.max_price / taco_kind.current_stock; +type return is list (operation) * taco_shop_storage + +const ownerAddress : address = + ("tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" : address) + +function buy_taco (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is + block { + // Retrieve the taco_kind from the contract's storage or fail + const taco_kind : taco_supply = + case taco_shop_storage[taco_kind_index] of + Some (kind) -> kind + | None -> (failwith ("Unknown kind of taco.") : taco_supply) + end; + + const current_purchase_price : tez = + taco_kind.max_price / taco_kind.current_stock; if amount =/= current_purchase_price then - // we won't sell tacos if the amount isn't correct - failwith("Sorry, the taco you're trying to purchase has a different price"); - else - // Decrease the stock by 1n, because we've just sold one - taco_kind.current_stock := abs(taco_kind.current_stock - 1n); + // We won't sell tacos if the amount is not correct + failwith ("Sorry, the taco you are trying to purchase has a different price"); + else skip; + + // Decrease the stock by 1n, because we have just sold one + taco_kind.current_stock := abs (taco_kind.current_stock - 1n); // Update the storage with the refreshed taco_kind taco_shop_storage[taco_kind_index] := taco_kind; - const receiver : contract(unit) = get_contract(ownerAddress); - const payoutOperation : operation = transaction(unit, amount, receiver); - const operations : list(operation) = list - payoutOperation - end; - - end with (operations, taco_shop_storage) + 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) ``` +### Dry-run the Contract -### Dry-run the contract - -To confirm that our contract is valid, we can dry run it. As a result we see a *new operation* in the list of returned operations to be executed subsequently. +To confirm that our contract is valid, we can dry-run it. As a result, +we see a *new operation* in the list of returned operations to be +executed subsequently. ```pascaligo skip -ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map - 1n -> record - current_stock = 50n; - max_price = 50000000mutez; - end; - 2n -> record - current_stock = 20n; - max_price = 75000000mutez; - end; -end" +ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map [ + 1n -> record [ + current_stock = 50n; + max_price = 50tez + ]; + 2n -> record [ + current_stock = 20n; + max_price = 75tez + ]; +]" ``` @@ -150,32 +196,34 @@ end"
-**Done! Our tokens are no longer locked in the contract, and instead they are sent to Pedro's personal account/wallet.** +**Done! Our tokens are no longer locked in the contract, and instead + they are sent to Pedro's personal account/wallet.** --- -## đź‘Ľ Bonus: donating part of the profits +## đź‘Ľ Bonus: Donating Part of the Profits -Because Pedro is a member of the (STA) Specialty Taco Association, he has decided to donate **10%** of the earnings to the STA. We'll just add a `donationAddress` to the contract, and compute a 10% donation sum from each taco purchase. +Because Pedro is a member of the Specialty Taco Association (STA), he +has decided to donate **10%** of the earnings to the STA. We will just +add a `donationAddress` to the contract, and compute a 10% donation +sum from each taco purchase. ```pascaligo group=bonus -const ownerAddress: address = ("tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" : address); -const donationAddress: address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); -``` +const ownerAddress : address = ("tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" : address); +const donationAddress : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); -```pascaligo group=bonus -const receiver : contract(unit) = get_contract(ownerAddress); -const donationReceiver : contract(unit) = get_contract(donationAddress); +const receiver : contract (unit) = get_contract (ownerAddress); +const donationReceiver : contract(unit) = get_contract (donationAddress); -const donationAmount: tez = amount / 10n; +const donationAmount : tez = amount / 10n; -const operations : list(operation) = list +const operations : list (operation) = list [ // Pedro will get 90% of the amount - transaction(unit, amount - donationAmount, receiver); - transaction(unit, donationAmount, donationReceiver); -end; + transaction (unit, amount - donationAmount, receiver); + transaction (unit, donationAmount, donationReceiver) +]; ``` This will result into two operations being subsequently executed on the blockchain: - Donation transfer (10%) -- Pedro's profits (90%) \ No newline at end of file +- Pedro's profits (90%) diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo index b51460bde..8871a9c87 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo @@ -1,23 +1,33 @@ -type taco_supply is record +type taco_supply is + record [ current_stock : nat; - max_price : tez; -end -type taco_shop_storage is map(nat, taco_supply); + max_price : tez + ] -function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : (list(operation) * taco_shop_storage) is - begin - // Retrieve the taco_kind from the contract's storage - const taco_kind : taco_supply = get_force(taco_kind_index, taco_shop_storage); - - const current_purchase_price : tez = taco_kind.max_price / taco_kind.current_stock; +type taco_shop_storage is map (nat, taco_supply) + +type return is list (operation) * taco_shop_storage + +function buy_taco (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is + block { + // Retrieve the taco_kind from the contract's storage or fail + const taco_kind : taco_supply = + case taco_shop_storage[taco_kind_index] of + Some (kind) -> kind + | None -> (failwith ("Unknown kind of taco.") : taco_supply) + end; + + const current_purchase_price : tez = + taco_kind.max_price / taco_kind.current_stock; if amount =/= current_purchase_price then - // we won't sell tacos if the amount isn't correct - fail("Sorry, the taco you're trying to purchase has a different price"); - else - // Decrease the stock by 1n, because we've just sold one - taco_kind.current_stock := abs(taco_kind.current_stock - 1n); + // We won't sell tacos if the amount is not correct + failwith ("Sorry, the taco you are trying to purchase has a different price"); + else skip; + + // Decrease the stock by 1n, because we have just sold one + taco_kind.current_stock := abs (taco_kind.current_stock - 1n); // Update the storage with the refreshed taco_kind - taco_shop_storage[taco_kind_index] := taco_kind; - end with ((nil : list(operation)), taco_shop_storage) \ No newline at end of file + taco_shop_storage[taco_kind_index] := taco_kind + } with ((nil : list (operation)), taco_shop_storage) diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md index 9d2bf5ab2..8770974a2 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md @@ -1,13 +1,18 @@ --- id: tezos-taco-shop-smart-contract -title: Taco shop smart contract +title: The Taco Shop Smart Contract ---
-Meet **Pedro**, our *artisan taco chef* who has decided to open a Taco shop on the Tezos blockchain, using a smart contract. He sells two different kinds of tacos, the **el clásico** and the **especial del chef**. +Meet **Pedro**, our *artisan taco chef*, who has decided to open a +Taco shop on the Tezos blockchain, using a smart contract. He sells +two different kinds of tacos: **el Clásico** and the **Especial +del Chef**. -To help Pedro open his dream taco shop, we'll implement a smart contract, that will manage supply, pricing & sales of his tacos to the consumers. +To help Pedro open his dream taco shop, we will implement a smart +contract that will manage supply, pricing & sales of his tacos to the +consumers.
@@ -18,91 +23,120 @@ To help Pedro open his dream taco shop, we'll implement a smart contract, that w ## Pricing -Pedro's tacos are a rare delicacy, so their **price goes up**, as the **stock for the day begins to deplete**. +Pedro's tacos are a rare delicacy, so their **price goes up** as the +**stock for the day begins to deplete**. -Each taco kind, has its own `max_price` that it sells for, and a finite supply for the current sales lifecycle. +Each taco kind, has its own `max_price` that it sells for, and a +finite supply for the current sales lifecycle. -> For the sake of simplicity, we won't implement replenishing of the supply after it runs out. +> For the sake of simplicity, we will not implement the replenishing +> of the supply after it has run out. -### Daily offer +### Daily Offer |**kind** |id |**available_stock**| **max_price**| |---|---|---|---| -|el clásico | `1n` | `50n` | `50000000mutez` | -|especial del chef | `2n` | `20n` | `75000000mutez` | +|Clásico | `1n` | `50n` | `50tez` | +|Especial del Chef | `2n` | `20n` | `75tez` | -### Calculating the current purchase price +### Calculating the Current Purchase Price -Current purchase price is calculated with the following equation: +The current purchase price is calculated with the following formula: ```pascaligo skip current_purchase_price = max_price / available_stock ``` -#### El clásico +#### El Clásico |**available_stock**|**max_price**|**current_purchase_price**| |---|---|---| -| `50n` | `50000000mutez` | `1tz`| -| `20n` | `50000000mutez` | `2.5tz` | -| `5n` | `50000000mutez` | `10tz` | +| `50n` | `50tez` | `1tez`| +| `20n` | `50tez` | `2.5tez` | +| `5n` | `50tez` | `10tez` | #### Especial del chef |**available_stock**|**max_price**|**current_purchase_price**| |---|---|---| -| `20n` | `75000000mutez` | `3.75tz` | -| `10n` | `75000000mutez` | `7.5tz`| -| `5n` | `75000000mutez` | `15tz` | +| `20n` | `75tez` | `3.75tez` | +| `10n` | `75tez` | `7.5tez`| +| `5n` | `75tez` | `15tez` | --- ## Installing LIGO -In this tutorial, we'll use LIGO's dockerized version for the sake of simplicity. You can find the installation instructions [here](intro/installation.md#dockerized-installation-recommended). +In this tutorial, we will use LIGO's dockerized version, for the sake +of simplicity. You can find the installation instructions +[here](intro/installation.md#dockerized-installation-recommended). -The best way to install the dockerized LIGO is as a **global executable** through the installation script, as shown in the screenshot below: +The best way to install the dockerized LIGO is as a **global +executable** through the installation script, as shown in the +screenshot below:
Installing the next version of LIGO's CLI
-## Implementing our first entry point +## Implementing our first access function -> From now on we'll get a bit more technical. If you run into something we have not covered yet - please try checking out the [LIGO cheat sheet](api/cheat-sheet.md) for some extra tips & tricks. +> From now on we will get a bit more technical. If you run into +> something we have not covered yet - please try checking out the +> [LIGO cheat sheet](api/cheat-sheet.md) for some extra tips & tricks. -To begin implementing our smart contract, we need an entry point. We'll call it `main` and it'll specify our contract's storage (`int`) and input parameter (`int`). Of course this is not the final storage/parameter of our contract, but it is something to get us started and test our LIGO installation as well. +To begin implementing our smart contract, we need an *access +function*, that is the first function being executed. We will call it +`main` and it will specify our contract's storage (`int`) and input +parameter (`int`). Of course this is not the final storage/parameter +of our contract, but it is something to get us started and test our +LIGO installation as well. ### `taco-shop.ligo` ```pascaligo group=a -function main (const parameter: int; const contractStorage: int) : (list(operation) * int) is - block {skip} with ((nil : list(operation)), contractStorage + parameter) +function main (const parameter : int; const contractStorage : int) : +list (operation) * int is + ((nil : list (operation)), contractStorage + parameter) ``` -Let's break down the contract above to make sure we understand each bit of the LIGO syntax: +Let us break down the contract above to make sure we understand each +bit of the LIGO syntax: -- **`function main`** - definition of a function that serves as an entry point -- **`(const parameter : int; const contractStorage : int)`** - parameters passed to the function - - **`const parameter : int`** - parameter provided by a transaction that invokes our contract - - **`const contractStorage : int`** - definition of our storage (`int`) -- **`(list(operation) * int)`** - return type of our function, in our case a touple with a list of operations, and an int -- **`block {skip}`** - our function has no body, so we instruct LIGO to `skip` it -- **`with ((nil : list(operation)), contractStorage + parameter)`** - essentially a return statement - - **`(nil : list(operation))`** - a `nil` value annotated as a list of operations, because that's required by our return type specified above - - **`contractStorage + parameter`** - a new storage value for our contract, sum of previous storage and a transaction parameter -### Running LIGO for the first time +- **`function main`** - definition of the access function, which takes + a the parameter of the contract and the storage +- **`(const parameter : int; const contractStorage : int)`** - + parameters passed to the function: the first is called `parameter` + because it denotes the parameter of a specific invocation of the + contract, the second is the storage +- **`(list (operation) * int)`** - return type of our function, in our + case a tuple with a list of operations, and an `int` (new value for + the storage after a succesful run of the contract) +- **`((nil : list (operation)), contractStorage + parameter)`** - + essentially a return statement +- **`(nil : list (operation))`** - a `nil` value annotated as a list + of operations, because that is required by our return type specified + above + - **`contractStorage + parameter`** - a new storage value for our + contract, sum of previous storage and a transaction parameter -To test that we've installed LIGO correctly, and that `taco-shop.ligo` is a valid contract, we'll dry-run it. +### Running LIGO for the First Time -> Dry-running is a simulated execution of the smart contract, based on a mock storage value and a parameter. +To test that we have installed LIGO correctly, and that +`taco-shop.ligo` is a valid contract, we will dry-run it. -Our contract has a storage of `int` and accepts a parameter that is also an `int`. +> Dry-running is a simulated execution of the smart contract, based on +> a mock storage value and a parameter. + +Our contract has a storage of `int` and accepts a parameter that is +also an `int`. The `dry-run` command requires a few parameters: - **contract** *(file path)* -- **entrypoint** *(name of the entrypoint function in the contract)* +- **entrypoint** *(name of the access function in the contract)* - **parameter** *(parameter to execute our contract with)* - **storage** *(starting storage before our contract's code is executed)* - -And outputs what's returned from our entrypoint - in our case a touple containing an empty list (of operations to apply) and the new storage value - which in our case is the sum of the previous storage and the parameter we've used. +It outputs what is returned from our access function: in our case a +tuple containing an empty list (of operations to apply) and the new +storage value, which, in our case, is the sum of the previous storage +and the parameter we have used for the invocation. ```zsh # Contract: taco-shop.ligo @@ -124,66 +158,80 @@ ligo dry-run taco-shop.ligo --syntax pascaligo main 4 3 --- -## Designing Taco shop's contract storage +## Designing the Taco Shop's Contract Storage -We know that Pedro's Taco Shop serves two kinds of tacos, so we'll need to manage stock individually, per kind. Let's define a type, that will keep the `stock` & `max_price` per kind - in a record with two fields. Additionally, we'll want to combine our `taco_supply` type into a map, consisting of the entire offer of Pedro's shop. +We know that Pedro's Taco Shop serves two kinds of tacos, so we will +need to manage stock individually, per kind. Let us define a type, +that will keep the `stock` & `max_price` per kind in a record with two +fields. Additionally, we will want to combine our `taco_supply` type +into a map, consisting of the entire offer of Pedro's shop. **Taco shop's storage** ```pascaligo group=b -type taco_supply is record - current_stock : nat; - max_price : tez; -end +type taco_supply is record [ + current_stock : nat; + max_price : tez +] -type taco_shop_storage is map(nat, taco_supply); +type taco_shop_storage is map (nat, taco_supply) ``` -Next step is to update the `main` entry point to include `taco_shop_storage` in its storage - while doing that let's set the `parameter` to `unit` as well to clear things up. +Next step is to update the `main` access function to include +`taco_shop_storage` in its storage. In the meanwhile, let us set the +`parameter` to `unit` as well to clear things up. **`taco-shop.ligo`** ```pascaligo group=b+ -type taco_supply is record - current_stock : nat; - max_price : tez; -end -type taco_shop_storage is map(nat, taco_supply); +type taco_supply is record [ + current_stock : nat; + max_price : tez +] -function main (const parameter: unit ; const taco_shop_storage : taco_shop_storage) : (list(operation) * taco_shop_storage) is - block {skip} with ((nil : list(operation)), taco_shop_storage) +type taco_shop_storage is map (nat, taco_supply) + +type return is list (operation) * taco_shop_storage + +function main (const parameter : unit; const taco_shop_storage : taco_shop_storage) : return is + ((nil : list (operation)), taco_shop_storage) ``` -### Populating our storage in a dry-run +### Populating our Storage in a dry-run -When dry-running a contract, it is crucial to provide a correct initial storage value - in our case the storage is type-checked as `taco_shop_storage`. Reflecting [Pedro's daily offer](tutorials/get-started/tezos-taco-shop-smart-contract.md#daily-offer), our storage's value will be defined as following: +When dry-running a contract, it is crucial to provide a correct +initial storage value. In our case the storage is type-checked as +`taco_shop_storage`. Reflecting +[Pedro's daily offer](tutorials/get-started/tezos-taco-shop-smart-contract.md#daily-offer), +our storage's value will be defined as follows: **Storage value** ```zsh -map - 1n -> record - current_stock = 50n; - max_price = 50000000mutez; - end; - 2n -> record - current_stock = 20n; - max_price = 75000000mutez; - end; -end +map [ + 1n -> record [ + current_stock = 50n; + max_price = 50tez + ]; + 2n -> record [ + current_stock = 20n; + max_price = 75tez + ] +] ``` -> Storage value is a map, with two items in it, both items are records identified by natural numbers `1n` & `2n`. +> The storage value is a map with two bindings (entries) distinguished +> by their keys `1n` and `2n`. **Dry run command with a multi-line storage value** ```zsh -ligo dry-run taco-shop.ligo --syntax pascaligo main unit "map - 1n -> record - current_stock = 50n; - max_price = 50000000mutez; - end; - 2n -> record - current_stock = 20n; - max_price = 75000000mutez; - end; -end" +ligo dry-run taco-shop.ligo --syntax pascaligo main unit "map [ + 1n -> record [ + current_stock = 50n; + max_price = 50tez + ]; + 2n -> record [ + current_stock = 20n; + max_price = 75tez + ] +]" ``` @@ -191,62 +239,85 @@ end"
-*If everything went as expected, the `dry-run` command will return an empty list of operations and the contract's current storage, which is the map of products we've defined based on the daily offer of Pedro's taco shop.* +*If everything went as expected, the `dry-run` command will return an + empty list of operations and the contract's current storage, which is + the map of the products we have defined based on the daily offer of + Pedro's taco shop.* --- -## Providing an entrypoint for buying tacos +## Providing another Access Function for Buying Tacos -Now that we have our stock well defined in form of storage, we can move on to the actual sales. We'll replace the `main` entrypoint with `buy_taco`, that takes an `id` - effectively a key from our `taco_shop_storage` map. This will allow us to calculate pricing, and if the sale is successful - then we can reduce our stock - because we have sold a taco! +Now that we have our stock well defined in form of storage, we can +move on to the actual sales. We will replace the `main` access +function with another, `buy_taco`, that takes a key `id` from our +`taco_shop_storage` map. This will allow us to calculate pricing, and +if the sale is successful, we will be able to reduce our stock because +we have sold a taco! -### Selling the tacos for free +### Selling the Tacos for Free -Let's start by customizing our contract a bit, we will: +Let is start by customizing our contract a bit, we will: -- rename the entrypoint from `main` to `buy_taco` +- rename the access function from `main` to `buy_taco` - rename `parameter` to `taco_kind_index` -- change `taco_shop_storage` to a `var` instead of a `const`, because we'll want to modify it +- change `taco_shop_storage` to a `var` instead of a `const`, because + we will want to modify it **`taco-shop.ligo`** ```pascaligo group=c -type taco_supply is record +type taco_supply is record [ current_stock : nat; - max_price : tez; -end -type taco_shop_storage is map(nat, taco_supply); + max_price : tez +] +type taco_shop_storage is map (nat, taco_supply) -function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : (list(operation) * taco_shop_storage) is - block { skip } with ((nil : list(operation)), taco_shop_storage) +type return is list (operation) * taco_shop_storage + +function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is + ((nil : list (operation)), taco_shop_storage) ``` -#### Decreasing `current_stock` when a taco is sold +#### Decreasing `current_stock` when a Taco is Sold -In order to decrease the stock in our contract's storage for a specific taco kind, a few things needs to happen: +In order to decrease the stock in our contract's storage for a +specific taco kind, a few things needs to happen: -- retrieve the `taco_kind` from our storage, based on the `taco_kind_index` provided -- subtract the `taco_kind.current_stock` by `1n` - - we can find the absolute (`nat`) value of the subtraction above by using `abs`, otherwise we'd be left with an `int` -- update the storage, and return it +- retrieve the `taco_kind` from our storage, based on the + `taco_kind_index` provided; +- subtract the `taco_kind.current_stock` by `1n`; +- we can find the absolute value of the subtraction above by + calling `abs` (otherwise we would be left with an `int`); +- update the storage, and return it. **`taco-shop.ligo`** ```pascaligo group=d -type taco_supply is record - current_stock : nat; - max_price : tez; -end -type taco_shop_storage is map(nat, taco_supply); +type taco_supply is record [ + current_stock : nat; + max_price : tez +] + +type taco_shop_storage is map (nat, taco_supply) + +type return is list (operation) * taco_shop_storage + +function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is + block { + // Retrieve the taco_kind from the contract's storage or fail + const taco_kind : taco_supply = + case taco_shop_storage[taco_kind_index] of + Some (kind) -> kind + | None -> (failwith ("Unknown kind of taco.") : taco_supply) + end; + + // Decrease the stock by 1n, because we have just sold one + taco_kind.current_stock := abs (taco_kind.current_stock - 1n); -function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : (list(operation) * taco_shop_storage) is - begin - // Retrieve the taco_kind from the contract's storage - const taco_kind : taco_supply = get_force(taco_kind_index, taco_shop_storage); - // Decrease the stock by 1n, because we've just sold one - taco_kind.current_stock := abs(taco_kind.current_stock - 1n); // Update the storage with the refreshed taco_kind - taco_shop_storage[taco_kind_index] := taco_kind; - end with ((nil : list(operation)), taco_shop_storage) + taco_shop_storage[taco_kind_index] := taco_kind + } with ((nil : list (operation)), taco_shop_storage) ``` @@ -254,67 +325,85 @@ function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_sho
-### Making sure we get paid for our tacos +### Making Sure We Get Paid for Our Tacos -In order to make Pedro's taco shop profitable, he needs to stop giving away tacos for free. When a contract is invoked via a transaction, an amount of tezzies to be sent can be specified as well. This amount is accessible within LIGO as `amount`. +In order to make Pedro's taco shop profitable, he needs to stop giving +away tacos for free. When a contract is invoked via a transaction, an +amount of tezzies to be sent can be specified as well. This amount is +accessible within LIGO as `amount`. To make sure we get paid, we will: -- calculate a `current_purchase_price` based on the [equation specified earlier](tutorials/get-started/tezos-taco-shop-smart-contract.md#calculating-the-current-purchase-price) -- check if the sent `amount` matches the `current_purchase_price` - - if not, then our contract will `fail` and stop executing - - if yes, stock for the given `taco_kind` will be decreased and the payment accepted +- calculate a `current_purchase_price` based on the + [equation specified earlier](tutorials/get-started/tezos-taco-shop-smart-contract.md#calculating-the-current-purchase-price) +- check if the sent `amount` matches the `current_purchase_price`: + - if not, then our contract will fail (`failwith`) + - otherwise, stock for the given `taco_kind` will be decreased and + the payment accepted **`taco-shop.ligo`** ```pascaligo group=e -type taco_supply is record - current_stock : nat; - max_price : tez; -end -type taco_shop_storage is map(nat, taco_supply); +type taco_supply is record [ + current_stock : nat; + max_price : tez +] -function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : (list(operation) * taco_shop_storage) is - begin - // Retrieve the taco_kind from the contract's storage - const taco_kind : taco_supply = get_force(taco_kind_index, taco_shop_storage); - - const current_purchase_price : tez = taco_kind.max_price / taco_kind.current_stock; +type taco_shop_storage is map (nat, taco_supply) + +type return is list (operation) * taco_shop_storage + +function buy_taco (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is + block { + // Retrieve the taco_kind from the contract's storage or fail + const taco_kind : taco_supply = + case taco_shop_storage[taco_kind_index] of + Some (kind) -> kind + | None -> (failwith ("Unknown kind of taco.") : taco_supply) + end; + + const current_purchase_price : tez = + taco_kind.max_price / taco_kind.current_stock; if amount =/= current_purchase_price then - // we won't sell tacos if the amount isn't correct - failwith("Sorry, the taco you're trying to purchase has a different price"); - else - // Decrease the stock by 1n, because we've just sold one - taco_kind.current_stock := abs(taco_kind.current_stock - 1n); + // We won't sell tacos if the amount is not correct + failwith ("Sorry, the taco you are trying to purchase has a different price"); + else skip; + + // Decrease the stock by 1n, because we have just sold one + taco_kind.current_stock := abs (taco_kind.current_stock - 1n); // Update the storage with the refreshed taco_kind - taco_shop_storage[taco_kind_index] := taco_kind; - end with ((nil : list(operation)), taco_shop_storage) + taco_shop_storage[taco_kind_index] := taco_kind + } with ((nil : list (operation)), taco_shop_storage) ``` -In order to test the `amount` sent, we'll use the `--amount` option of `dry-run`: +In order to test the `amount` sent, we will use the `--amount` option +of `dry-run`: ```zsh -ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map - 1n -> record - current_stock = 50n; - max_price = 50000000mutez; - end; - 2n -> record - current_stock = 20n; - max_price = 75000000mutez; - end; -end" +ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map [ + 1n -> record [ + current_stock = 50n; + max_price = 50tez + ]; + 2n -> record [ + current_stock = 20n; + max_price = 75tez + ] +]" ``` -**Purchasing a taco with 1.0tz** + +** Purchasing a Taco with 1tez **
Stock decreases after selling a taco, if the right amount of tezzies is provided

-**Attempting to purchase a taco with 0.7tz** +**Attempting to Purchase a Taco with 0.7tez** -
Stock does not decrease after a purchase attempt with a lower than required amount.
+
Stock does not decrease after a purchase attempt +with an insufficient payment.

@@ -322,9 +411,10 @@ end" --- -## đź’° Bonus: *Accepting tips above the taco purchase price* +## đź’° Bonus: *Accepting Tips above the Taco Purchase Price* -If you'd like to accept tips in your contract as well, simply change the following line, depending on your preference. +If you would like to accept tips in your contract, simply change the +following line, depending on your preference. **Without tips** ```pascaligo skip diff --git a/gitlab-pages/owner.pp.ligo b/gitlab-pages/owner.pp.ligo deleted file mode 100644 index e69de29bb..000000000 diff --git a/gitlab-pages/timestamp.pp.ligo b/gitlab-pages/timestamp.pp.ligo deleted file mode 100644 index e69de29bb..000000000 diff --git a/gitlab-pages/website/versioned_sidebars/version-next-sidebars.json b/gitlab-pages/website/versioned_sidebars/version-next-sidebars.json index 07fc287dd..5109f0260 100644 --- a/gitlab-pages/website/versioned_sidebars/version-next-sidebars.json +++ b/gitlab-pages/website/versioned_sidebars/version-next-sidebars.json @@ -24,9 +24,17 @@ "version-next-advanced/include", "version-next-advanced/first-contract" ], - "API": [ + "API & Reference": [ "version-next-api/cli-commands", - "version-next-api/cheat-sheet" + "version-next-api/cheat-sheet", + "version-next-reference/big-map-reference", + "version-next-reference/bytes-reference", + "version-next-reference/crypto-reference", + "version-next-reference/current-reference", + "version-next-reference/list-reference", + "version-next-reference/map-reference", + "version-next-reference/set-reference", + "version-next-reference/string-reference" ] }, "version-next-contributors-docs": { diff --git a/src/passes/1-parser/shared/Lexer.mll b/src/passes/1-parser/shared/Lexer.mll index 8b213f70b..569486ef7 100644 --- a/src/passes/1-parser/shared/Lexer.mll +++ b/src/passes/1-parser/shared/Lexer.mll @@ -499,7 +499,7 @@ module Make (Token: TOKEN) : (S with module Token = Token) = | Error Token.Non_canonical_zero -> fail region Non_canonical_zero - let mk_tz state buffer = + let mk_tez state buffer = let region, lexeme, state = sync state buffer 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 @@ -508,7 +508,7 @@ module Make (Token: TOKEN) : (S with module Token = Token) = | Error Token.Non_canonical_zero -> fail region Non_canonical_zero - let format_tz s = + let format_tez s = match String.index s '.' with index -> let len = String.length s in @@ -522,10 +522,11 @@ module Make (Token: TOKEN) : (S with module Token = Token) = if Z.equal Z.one should_be_1 then Some (Q.num mutez) else None | exception Not_found -> assert false - let mk_tz_decimal state buffer = + let mk_tez_decimal state buffer = let region, lexeme, state = sync state buffer in + let lexeme = Str.(global_replace (regexp "_") "" lexeme) in let lexeme = Str.string_before lexeme (String.index lexeme 't') in - match format_tz lexeme with + match format_tez lexeme with None -> assert false | Some tz -> match Token.mk_mutez (Z.to_string tz ^ "mutez") region with @@ -573,7 +574,7 @@ let nl = ['\n' '\r'] | "\r\n" let blank = ' ' | '\t' let digit = ['0'-'9'] let natural = digit | digit (digit | '_')* digit -let decimal = digit+ '.' digit+ +let decimal = natural '.' natural let small = ['a'-'z'] let capital = ['A'-'Z'] let letter = small | capital @@ -624,9 +625,9 @@ and scan state = parse | natural 'n' { mk_nat state lexbuf |> enqueue } | natural "mutez" { mk_mutez state lexbuf |> enqueue } | natural "tz" -| natural "tez" { mk_tz state lexbuf |> enqueue } +| natural "tez" { mk_tez state lexbuf |> enqueue } | decimal "tz" -| decimal "tez" { mk_tz_decimal state lexbuf |> enqueue } +| decimal "tez" { mk_tez_decimal state lexbuf |> enqueue } | natural { mk_int state lexbuf |> enqueue } | symbol { mk_sym state lexbuf |> enqueue } | eof { mk_eof state lexbuf |> enqueue } From feaf143209a60bca737f0b3ba449d02cdcc18ebf Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Fri, 21 Feb 2020 18:13:09 +0100 Subject: [PATCH 02/53] "access function" -> "main function" --- .../docs/advanced/entrypoints-contracts.md | 44 +++++++++---------- gitlab-pages/docs/advanced/first-contract.md | 17 +++---- .../docs/language-basics/sets-lists-tuples.md | 2 +- .../get-started/tezos-taco-shop-payout.ligo | 2 +- .../tezos-taco-shop-smart-contract.ligo | 2 +- .../tezos-taco-shop-smart-contract.md | 40 ++++++++--------- 6 files changed, 53 insertions(+), 54 deletions(-) diff --git a/gitlab-pages/docs/advanced/entrypoints-contracts.md b/gitlab-pages/docs/advanced/entrypoints-contracts.md index 15fa7cb75..e3c70f73b 100644 --- a/gitlab-pages/docs/advanced/entrypoints-contracts.md +++ b/gitlab-pages/docs/advanced/entrypoints-contracts.md @@ -1,24 +1,24 @@ --- id: entrypoints-contracts -title: Access function and Entrypoints +title: Main function and Entrypoints --- ## Access Functions A LIGO contract is made of a series of constant and function declarations. Only functions having a special type can be called when -the contract is activated: we called them *access functions*. An -access function takes two parameters, the *contract parameter* and the +the contract is activated: we called them *main functions*. A main +function takes two parameters, the *contract parameter* and the *on-chain storage*, and returns a pair made of a *list of operations* and a (new) storage. When the contract is originated, the initial value of the storage is -provided. When an access function is later called, only the parameter -is provided, but the type of an access function contains both. +provided. When a main function is later called, only the parameter is +provided, but the type of a main function contains both. The type of the contract parameter and the storage are up to the contract designer, but the type for list operations is not. The return -type of an access function is as follows, assuming that the type +type of a main function is as follows, assuming that the type `storage` has been defined elsewhere. (Note that you can use any type with any name for the storage.) @@ -42,13 +42,12 @@ type return = (list (operation), storage); ``` -The contract storage can only be modified by activating an access +The contract storage can only be modified by activating a main function. It is important to understand what that means. What it does *not* mean is that some global variable holding the storage is -modified by the access function. Instead, what it *does* mean is that, -given the state of the storage *on-chain*, an access function -specifies how to create another state for it, depending on a -parameter. +modified by the main function. Instead, what it *does* mean is that, +given the state of the storage *on-chain*, a main function specifies +how to create another state for it, depending on a parameter. Here is an example where the storage is a single natural number that is updated by the parameter. @@ -89,17 +88,18 @@ let main = ((action, store): (parameter, storage)) : return => ## Entrypoints -In LIGO, the design pattern is to have *one* access function that -dispatches the control flow according to its parameter. Those -functions called for those actions are called *entrypoints*. +In LIGO, the design pattern is to have *one* main function called +`main`, that dispatches the control flow according to its +parameter. Those functions called for those actions are called +*entrypoints*. As an analogy, in the C programming language, the `main` function is -the unique access function and any function called from it would be an +the unique main function and any function called from it would be an entrypoint. The parameter of the contract is then a variant type, and, depending on the constructors of that type, different functions in the contract -are called. In other terms, the unique access function dispatches the +are called. In other terms, the unique main function dispatches the control flow depending on a *pattern matching* on the contract parameter. @@ -128,7 +128,7 @@ function entry_A (const n : nat; const store : storage) : return is function entry_B (const s : string; const store : storage) : return is ((nil : list (operation)), store with record [name = s]) -function access (const action : parameter; const store : storage): return is +function main (const action : parameter; const store : storage): return is case action of Action_A (n) -> entry_A (n, store) | Action_B (s) -> entry_B (s, store) @@ -154,7 +154,7 @@ let entry_A (n, store : nat * storage) : return = let entry_B (s, store : string * storage) : return = ([] : operation list), {store with name = s} -let access (action, store: parameter * storage) : return = +let main (action, store: parameter * storage) : return = match action with Action_A n -> entry_A (n, store) | Action_B s -> entry_B (s, store) @@ -179,7 +179,7 @@ let entry_A = ((n, store): (nat, storage)) : return => let entry_B = ((s, store): (string, storage)) : return => (([] : list (operation)), {...store, name : s}); -let access = ((action, store): (parameter, storage)) : return => +let main = ((action, store): (parameter, storage)) : return => switch (action) { | Action_A (n) => entry_A ((n, store)) | Action_B (s) => entry_B ((s, store)) @@ -249,7 +249,7 @@ This example shows how `sender` or `source` can be used to deny access to an ent ```pascaligo group=c const owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); -function filter (const action : parameter; const store : storage) : return is +function main (const action : parameter; const store : storage) : return is if source =/= owner then (failwith ("Access denied.") : return) else ((nil : list(operation)), store) ``` @@ -258,7 +258,7 @@ function filter (const action : parameter; const store : storage) : return is ```cameligo group=c let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) -let filter (action, store: parameter * storage) : return = +let main (action, store: parameter * storage) : return = if source <> owner then (failwith "Access denied." : return) else (([] : operation list), store) ``` @@ -267,7 +267,7 @@ let filter (action, store: parameter * storage) : return = ```reasonligo group=c let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); -let access = ((action, store): (parameter, storage)) : storage => { +let main = ((action, store): (parameter, storage)) : storage => { if (source != owner) { (failwith ("Access denied.") : return); } else { (([] : list (operation)), store); }; }; diff --git a/gitlab-pages/docs/advanced/first-contract.md b/gitlab-pages/docs/advanced/first-contract.md index 7da4e8cf7..00bed6f7c 100644 --- a/gitlab-pages/docs/advanced/first-contract.md +++ b/gitlab-pages/docs/advanced/first-contract.md @@ -11,13 +11,14 @@ We will be implementing a counter contract. ## Dry-running a Contract Testing a contract can be quite easy if we utilize LIGO's built-in dry -run feature. Dry-run works by simulating the access function -execution, as if it were deployed on a real chain. You need to provide -the following: +run feature. Dry-run works by simulating the main function execution, +as if it were deployed on a real chain. You need to provide the +following: - `file` - contract to run - `entrypoint` - name of the function to execute -- `parameter` - parameter passed to the access function (in a theoretical invocation operation) +- `parameter` - parameter passed to the main function (in a + theoretical invocation operation) - `storage` - a mock storage value, as if it were stored on a real chain Here is a full example: @@ -33,15 +34,15 @@ ligo dry-run src/basic.ligo main Unit Unit ``` -Output of the `dry-run` is the return value of our access function, we -can see the operations emited - in our case an empty list, and the new -storage value being returned - which in our case is still `Unit`. +Output of the `dry-run` is the return value of our main function, we +can see the operations emitted (in our case an empty list, and the new +storage value being returned) which in our case is still `Unit`. ## A Counter Contract Our counter contract will store a single `int` as it's storage, and will accept an `action` variant in order to re-route our single `main` -access function to two entrypoints for `addition` and `subtraction`. +function to two entrypoints for `addition` and `subtraction`. diff --git a/gitlab-pages/docs/language-basics/sets-lists-tuples.md b/gitlab-pages/docs/language-basics/sets-lists-tuples.md index 6a38d6104..57132e9b6 100644 --- a/gitlab-pages/docs/language-basics/sets-lists-tuples.md +++ b/gitlab-pages/docs/language-basics/sets-lists-tuples.md @@ -99,7 +99,7 @@ called the *head*, and the sub-list after the head is called the think of a list a *stack*, where the top is written on the left. > đź’ˇ Lists are needed when returning operations from a smart -> contract's access function. +> contract's main function. ### Defining Lists diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo index 9cf169397..eaf9dde48 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo @@ -11,7 +11,7 @@ type return is list (operation) * taco_shop_storage const ownerAddress : address = "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" const donationAddress : address = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" -function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is +function main (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is block { // Retrieve the taco_kind from the contract's storage or fail const taco_kind : taco_supply = diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo index 8871a9c87..09710bec3 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo @@ -8,7 +8,7 @@ type taco_shop_storage is map (nat, taco_supply) type return is list (operation) * taco_shop_storage -function buy_taco (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is +function main (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is block { // Retrieve the taco_kind from the contract's storage or fail const taco_kind : taco_supply = diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md index 8770974a2..1af525781 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md @@ -76,18 +76,18 @@ screenshot below:
Installing the next version of LIGO's CLI
-## Implementing our first access function +## Implementing our First `main` Function > From now on we will get a bit more technical. If you run into > something we have not covered yet - please try checking out the > [LIGO cheat sheet](api/cheat-sheet.md) for some extra tips & tricks. -To begin implementing our smart contract, we need an *access -function*, that is the first function being executed. We will call it -`main` and it will specify our contract's storage (`int`) and input -parameter (`int`). Of course this is not the final storage/parameter -of our contract, but it is something to get us started and test our -LIGO installation as well. +To begin implementing our smart contract, we need a *main function*, +that is the first function being executed. We will call it `main` and +it will specify our contract's storage (`int`) and input parameter +(`int`). Of course this is not the final storage/parameter of our +contract, but it is something to get us started and test our LIGO +installation as well. ### `taco-shop.ligo` ```pascaligo group=a @@ -99,7 +99,7 @@ list (operation) * int is Let us break down the contract above to make sure we understand each bit of the LIGO syntax: -- **`function main`** - definition of the access function, which takes +- **`function main`** - definition of the main function, which takes a the parameter of the contract and the storage - **`(const parameter : int; const contractStorage : int)`** - parameters passed to the function: the first is called `parameter` @@ -129,11 +129,11 @@ also an `int`. The `dry-run` command requires a few parameters: - **contract** *(file path)* -- **entrypoint** *(name of the access function in the contract)* +- **entrypoint** *(name of the main function in the contract)* - **parameter** *(parameter to execute our contract with)* - **storage** *(starting storage before our contract's code is executed)* -It outputs what is returned from our access function: in our case a +It outputs what is returned from our main function: in our case a tuple containing an empty list (of operations to apply) and the new storage value, which, in our case, is the sum of the previous storage and the parameter we have used for the invocation. @@ -176,7 +176,7 @@ type taco_supply is record [ type taco_shop_storage is map (nat, taco_supply) ``` -Next step is to update the `main` access function to include +Next step is to update the `main` function to include `taco_shop_storage` in its storage. In the meanwhile, let us set the `parameter` to `unit` as well to clear things up. @@ -249,17 +249,15 @@ ligo dry-run taco-shop.ligo --syntax pascaligo main unit "map [ ## Providing another Access Function for Buying Tacos Now that we have our stock well defined in form of storage, we can -move on to the actual sales. We will replace the `main` access -function with another, `buy_taco`, that takes a key `id` from our -`taco_shop_storage` map. This will allow us to calculate pricing, and -if the sale is successful, we will be able to reduce our stock because -we have sold a taco! +move on to the actual sales. The `main` function will take a key `id` +from our `taco_shop_storage` map. This will allow us to calculate +pricing, and if the sale is successful, we will be able to reduce our +stock because we have sold a taco! ### Selling the Tacos for Free Let is start by customizing our contract a bit, we will: -- rename the access function from `main` to `buy_taco` - rename `parameter` to `taco_kind_index` - change `taco_shop_storage` to a `var` instead of a `const`, because we will want to modify it @@ -275,7 +273,7 @@ type taco_shop_storage is map (nat, taco_supply) type return is list (operation) * taco_shop_storage -function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is +function main (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is ((nil : list (operation)), taco_shop_storage) ``` @@ -303,7 +301,7 @@ type taco_shop_storage is map (nat, taco_supply) type return is list (operation) * taco_shop_storage -function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is +function main (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is block { // Retrieve the taco_kind from the contract's storage or fail const taco_kind : taco_supply = @@ -352,7 +350,7 @@ type taco_shop_storage is map (nat, taco_supply) type return is list (operation) * taco_shop_storage -function buy_taco (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is +function main (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is block { // Retrieve the taco_kind from the contract's storage or fail const taco_kind : taco_supply = @@ -381,7 +379,7 @@ In order to test the `amount` sent, we will use the `--amount` option of `dry-run`: ```zsh -ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map [ +ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 main 1n "map [ 1n -> record [ current_stock = 50n; max_price = 50tez From 9fb311ef13e5421addbb05dd8c3c7d70e6bedea7 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Sat, 22 Feb 2020 16:50:36 +0100 Subject: [PATCH 03/53] Renamed `main` to the original `buy_taco`. --- .../tezos-taco-shop-smart-contract.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md index 1af525781..48dfa29a5 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md @@ -140,7 +140,7 @@ and the parameter we have used for the invocation. ```zsh # Contract: taco-shop.ligo -# Entry point: main +# Main function: main # Parameter: 4 # Storage: 3 ligo dry-run taco-shop.ligo --syntax pascaligo main 4 3 @@ -250,9 +250,10 @@ ligo dry-run taco-shop.ligo --syntax pascaligo main unit "map [ Now that we have our stock well defined in form of storage, we can move on to the actual sales. The `main` function will take a key `id` -from our `taco_shop_storage` map. This will allow us to calculate -pricing, and if the sale is successful, we will be able to reduce our -stock because we have sold a taco! +from our `taco_shop_storage` map and will be renamed `buy_taco` for +more readability. This will allow us to calculate pricing, and if the +sale is successful, we will be able to reduce our stock because we +have sold a taco! ### Selling the Tacos for Free @@ -273,7 +274,7 @@ type taco_shop_storage is map (nat, taco_supply) type return is list (operation) * taco_shop_storage -function main (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is +function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is ((nil : list (operation)), taco_shop_storage) ``` @@ -301,7 +302,7 @@ type taco_shop_storage is map (nat, taco_supply) type return is list (operation) * taco_shop_storage -function main (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is +function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is block { // Retrieve the taco_kind from the contract's storage or fail const taco_kind : taco_supply = @@ -350,7 +351,7 @@ type taco_shop_storage is map (nat, taco_supply) type return is list (operation) * taco_shop_storage -function main (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is +function buy_taco (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is block { // Retrieve the taco_kind from the contract's storage or fail const taco_kind : taco_supply = @@ -379,7 +380,7 @@ In order to test the `amount` sent, we will use the `--amount` option of `dry-run`: ```zsh -ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 main 1n "map [ +ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map [ 1n -> record [ current_stock = 50n; max_price = 50tez From 817e94603b3af1aa58f41817e3e6533cd08666bc Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Sun, 23 Feb 2020 07:30:41 +0100 Subject: [PATCH 04/53] Syncronised the *.ligo files of the tutorial with the contents of the tutorial. --- .../docs/tutorials/get-started/tezos-taco-shop-payout.ligo | 2 +- .../tutorials/get-started/tezos-taco-shop-smart-contract.ligo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo index eaf9dde48..9cf169397 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.ligo @@ -11,7 +11,7 @@ type return is list (operation) * taco_shop_storage const ownerAddress : address = "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" const donationAddress : address = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" -function main (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is +function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_shop_storage) : return is block { // Retrieve the taco_kind from the contract's storage or fail const taco_kind : taco_supply = diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo index 09710bec3..8871a9c87 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.ligo @@ -8,7 +8,7 @@ type taco_shop_storage is map (nat, taco_supply) type return is list (operation) * taco_shop_storage -function main (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is +function buy_taco (const taco_kind_index : nat ; var taco_shop_storage : taco_shop_storage) : return is block { // Retrieve the taco_kind from the contract's storage or fail const taco_kind : taco_supply = From 4699d2c954631489d8ffb431f96ffac124b7974c Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Mon, 24 Feb 2020 11:39:45 +0100 Subject: [PATCH 05/53] Included remarks on the MR. --- gitlab-pages/docs/advanced/entrypoints-contracts.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gitlab-pages/docs/advanced/entrypoints-contracts.md b/gitlab-pages/docs/advanced/entrypoints-contracts.md index e3c70f73b..6e5abbca0 100644 --- a/gitlab-pages/docs/advanced/entrypoints-contracts.md +++ b/gitlab-pages/docs/advanced/entrypoints-contracts.md @@ -7,7 +7,7 @@ title: Main function and Entrypoints A LIGO contract is made of a series of constant and function declarations. Only functions having a special type can be called when -the contract is activated: we called them *main functions*. A main +the contract is activated: we call them *main functions*. A main function takes two parameters, the *contract parameter* and the *on-chain storage*, and returns a pair made of a *list of operations* and a (new) storage. @@ -43,11 +43,9 @@ type return = (list (operation), storage); The contract storage can only be modified by activating a main -function. It is important to understand what that means. What it does -*not* mean is that some global variable holding the storage is -modified by the main function. Instead, what it *does* mean is that, -given the state of the storage *on-chain*, a main function specifies -how to create another state for it, depending on a parameter. +function: given the state of the storage *on-chain*, a main function +specifies how to create another state for it, depending on the +contract's parameter. Here is an example where the storage is a single natural number that is updated by the parameter. From 31a39bffbc875383437344c772cfcf0a15e67818 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Tue, 25 Feb 2020 18:07:53 +0100 Subject: [PATCH 06/53] I upgraded the parsers to accept `Map.map` etc. I rewrote the doc except "reference" to promote and deprecate built-ins. --- .../docs/advanced/entrypoints-contracts.md | 67 ++- gitlab-pages/docs/advanced/first-contract.md | 128 +++-- gitlab-pages/docs/advanced/src/counter.ligo | 17 + gitlab-pages/docs/advanced/src/functions.ligo | 9 + .../advanced/src/multiple-entrypoints.ligo | 17 + gitlab-pages/docs/advanced/src/variables.ligo | 5 + .../docs/advanced/timestamps-addresses.md | 54 +- gitlab-pages/docs/api/cheat-sheet.md | 12 +- .../docs/language-basics/boolean-if-else.md | 18 +- .../docs/language-basics/functions.md | 20 +- gitlab-pages/docs/language-basics/loops.md | 16 +- .../docs/language-basics/maps-records.md | 325 ++++++----- .../docs/language-basics/operators.md | 13 +- .../docs/language-basics/sets-lists-tuples.md | 221 +++----- .../src/boolean-if-else/cond.ligo | 2 +- .../src/functions/incr_map.ligo | 2 +- .../src/sets-lists-tuples/lists.ligo | 5 +- .../src/sets-lists-tuples/sets.ligo | 6 +- .../unit-option-pattern-matching/flip.ligo | 4 +- gitlab-pages/docs/language-basics/strings.md | 15 +- .../docs/language-basics/tezos-specific.md | 24 +- gitlab-pages/docs/language-basics/types.md | 4 +- .../unit-option-pattern-matching.md | 21 +- .../variables-and-constants.md | 5 +- gitlab-pages/docs/reference/big_map.md | 303 +++++----- gitlab-pages/docs/reference/list.md | 191 ++++++- gitlab-pages/docs/reference/map.md | 536 +++++++----------- gitlab-pages/examples/counter.ligo | 10 - gitlab-pages/examples/functions.ligo | 10 - .../examples/multiple-entrypoints.ligo | 16 - gitlab-pages/examples/variables.ligo | 5 - src/passes/1-parser/cameligo/.links | 1 + src/passes/1-parser/cameligo/LexToken.mll | 1 - src/passes/1-parser/cameligo/LexerMain.ml | 2 + src/passes/1-parser/cameligo/Parser.mly | 6 +- src/passes/1-parser/pascaligo/.links | 1 + src/passes/1-parser/pascaligo/Parser.mly | 59 +- src/passes/1-parser/reasonligo/.links | 3 +- src/passes/1-parser/reasonligo/LexToken.mll | 3 - src/passes/1-parser/reasonligo/LexerMain.ml | 2 + src/passes/1-parser/reasonligo/Parser.mly | 61 +- src/passes/operators/operators.ml | 513 +++++++++++------ src/test/contracts/bitwise_arithmetic.ligo | 14 +- src/test/contracts/bitwise_arithmetic.mligo | 6 +- src/test/contracts/bitwise_arithmetic.religo | 10 +- 45 files changed, 1534 insertions(+), 1229 deletions(-) create mode 100644 gitlab-pages/docs/advanced/src/counter.ligo create mode 100644 gitlab-pages/docs/advanced/src/functions.ligo create mode 100644 gitlab-pages/docs/advanced/src/multiple-entrypoints.ligo create mode 100644 gitlab-pages/docs/advanced/src/variables.ligo delete mode 100644 gitlab-pages/examples/counter.ligo delete mode 100644 gitlab-pages/examples/functions.ligo delete mode 100644 gitlab-pages/examples/multiple-entrypoints.ligo delete mode 100644 gitlab-pages/examples/variables.ligo diff --git a/gitlab-pages/docs/advanced/entrypoints-contracts.md b/gitlab-pages/docs/advanced/entrypoints-contracts.md index 6e5abbca0..429962a33 100644 --- a/gitlab-pages/docs/advanced/entrypoints-contracts.md +++ b/gitlab-pages/docs/advanced/entrypoints-contracts.md @@ -194,8 +194,8 @@ how those built-ins can be utilized. ### Accepting or Declining Tokens in a Smart Contract -This example shows how `amount` and `failwith` can be used to decline -any transaction that sends more tez than `0mutez`, that is, no +This example shows how `Tezos.amount` and `failwith` can be used to +decline any transaction that sends more tez than `0tez`, that is, no incoming tokens are accepted. @@ -206,11 +206,13 @@ type storage is unit type return is list (operation) * storage function deny (const action : parameter; const store : storage) : return is - if amount > 0mutez then + if Tezos.amount > 0tez then (failwith ("This contract does not accept tokens.") : return) else ((nil : list (operation)), store) ``` +> Note that `amount` is *deprecated*. + ```cameligo group=c type parameter = unit @@ -218,11 +220,13 @@ type storage = unit type return = operation list * storage let deny (action, store : parameter * storage) : return = - if amount > 0mutez then - (failwith "This contract does not accept tokens.": return) + if Tezos.amount > 0tez then + (failwith "This contract does not accept tokens." : return) else (([] : operation list), store) ``` +> Note that `amount` is *deprecated*. + ```reasonligo group=c type parameter = unit; @@ -230,17 +234,20 @@ type storage = unit; type return = (list (operation), storage); let deny = ((action, store): (parameter, storage)) : return => { - if (amount > 0mutez) { + if (Tezos.amount > 0tez) { (failwith("This contract does not accept tokens."): return); } else { (([] : list (operation)), store); }; }; ``` +> Note that `amount` is *deprecated*. + ### Access Control -This example shows how `sender` or `source` can be used to deny access to an entrypoint. +This example shows how `Tezos.source` can be used to deny access to an +entrypoint. @@ -248,28 +255,35 @@ This example shows how `sender` or `source` can be used to deny access to an ent const owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); function main (const action : parameter; const store : storage) : return is - if source =/= owner then (failwith ("Access denied.") : return) - else ((nil : list(operation)), store) + if Tezos.source =/= owner then (failwith ("Access denied.") : return) + else ((nil : list (operation)), store) ``` +> Note that `source` is *deprecated*. + ```cameligo group=c let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) let main (action, store: parameter * storage) : return = - if source <> owner then (failwith "Access denied." : return) + if Tezos.source <> owner then (failwith "Access denied." : return) else (([] : operation list), store) ``` +> Note that `source` is *deprecated*. + ```reasonligo group=c let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); -let main = ((action, store): (parameter, storage)) : storage => { - if (source != owner) { (failwith ("Access denied.") : return); } +let main = ((action, store) : (parameter, storage)) : storage => { + if (Tezos.source != owner) { (failwith ("Access denied.") : return); } else { (([] : list (operation)), store); }; }; ``` + +> Note that `source` is *deprecated*. + ### Inter-Contract Invocations @@ -327,11 +341,15 @@ const dest : address = ("KT19wgxcuXG9VH4Af5Tpm1vqEKdaMFpznXT3" : address) function proxy (const action : parameter; const store : storage): return is block { - const counter : contract (parameter) = get_contract (dest); + const counter : contract (parameter) = + case (Tezos.get_contract_opt (dest) : option (contract (parameter))) of + Some (contract) -> contract + | None -> (failwith ("Contract not found.") : contract (parameter)) + end; (* Reuse the parameter in the subsequent transaction or use another one, `mock_param`. *) const mock_param : parameter = Increment (5n); - const op : operation = transaction (action, 0mutez, counter); + const op : operation = Tezos.transaction (action, 0tez, counter); const ops : list (operation) = list [op] } with (ops, store) ``` @@ -363,14 +381,20 @@ type return = operation list * storage let dest : address = ("KT19wgxcuXG9VH4Af5Tpm1vqEKdaMFpznXT3" : address) let proxy (action, store : parameter * storage) : return = - let counter : parameter contract = Operation.get_contract dest in + let counter : parameter contract = + match (Tezos.get_contract_opt (dest) : parameter contract option) with + Some contract -> contract + | None -> (failwith "Contract not found." : parameter contract) in (* Reuse the parameter in the subsequent transaction or use another one, `mock_param`. *) let mock_param : parameter = Increment (5n) in - let op : operation = Operation.transaction action 0mutez counter + let op : operation = Tezos.transaction action 0tez counter in [op], store ``` +> Note that `Operation.get_contract` and `Operation.transaction` are +> *deprecated*. + ```reasonligo skip // counter.religo @@ -398,13 +422,20 @@ type return = (list (operation), storage); let dest : address = ("KT19wgxcuXG9VH4Af5Tpm1vqEKdaMFpznXT3" : address); let proxy = ((action, store): (parameter, storage)) : return => { - let counter : contract (parameter) = Operation.get_contract (dest); + let counter : contract (parameter) = + switch (Tezos.get_contract_opt (dest) : option (contract (parameter))) { + | Some (contract) => contract; + | None => (failwith ("Contract not found.") : contract (parameter)); + }; (* Reuse the parameter in the subsequent transaction or use another one, `mock_param`. *) let mock_param : parameter = Increment (5n); - let op : operation = Operation.transaction (action, 0mutez, counter); + let op : operation = Tezos.transaction (action, 0tez, counter); ([op], store) }; ``` +> Note that `Operation.get_contract` and `Operation.transaction` are +> *deprecated*. + diff --git a/gitlab-pages/docs/advanced/first-contract.md b/gitlab-pages/docs/advanced/first-contract.md index 00bed6f7c..eb63a25c4 100644 --- a/gitlab-pages/docs/advanced/first-contract.md +++ b/gitlab-pages/docs/advanced/first-contract.md @@ -42,59 +42,78 @@ storage value being returned) which in our case is still `Unit`. Our counter contract will store a single `int` as it's storage, and will accept an `action` variant in order to re-route our single `main` -function to two entrypoints for `addition` and `subtraction`. +function to two entrypoints for `add` (addition) and `sub` +(subtraction). ``` -type action is +type parameter is Increment of int | Decrement of int -function main (const p : action ; const s : int) : (list(operation) * int) is +type storage is int + +type return is list (operation) * storage + +function add (const n : int; const store : storage) : storage is store + n +function sub (const n : int; const store : storage) : storage is store - n + +function main (const action : parameter; const store : storage) : return is ((nil : list(operation)), - (case p of - | Increment (n) -> s + n - | Decrement (n) -> s - n - end)) + case action of + Increment (n) -> add (n, store) + | Decrement (n) -> sub (n, store) + end) ``` ```cameligo -type action = -| Increment of int +type parameter = + Increment of int | Decrement of int -let main (p, s: action * int) : operation list * int = - let result = - match p with - | Increment n -> s + n - | Decrement n -> s - n - in - (([]: operation list), result) +type storage = int + +type return = (operation) list * storage + +let add (n, store : int * storage) : storage = store + n +let sub (n, store : int * storage) : storage = store - n + +let main (action, store : parameter * storage) : operation list * storage = + (([]: operation list), + (match action with + Increment n -> add (n, store) + | Decrement n -> sub (n, store))) ``` ```reasonligo -type action = -| Increment(int) -| Decrement(int); +type parameter = + Increment (int) +| Decrement (int) +; -let main = (p_s: (action, int)) : (list(operation), int) => { - let p, s = p_s; - let result = - switch (p) { - | Increment(n) => s + n - | Decrement(n) => s - n - }; - (([]: list(operation)), result); -}; +type storage = int; + +type return = (list (operation), storage); + +let add = ((n, store) : (int, storage)) : storage => store + n; +let sub = ((n, store) : (int, storage)) : storage => store - n; + +let main = ((action, store) : (parameter, storage)) : return => + (([]: list (operation)), + (switch (action) { + | Increment (n) => add ((n, store)) + | Decrement (n) => sub ((n, store)) + })); ``` -To dry-run the counter contract, we will use the `main` entrypoint, provide a variant parameter of `Increment(5)` and an initial storage value of `5`. - +To dry-run the counter contract, we will provide the `main` function +with a variant parameter of value `Increment (5)` and an initial +storage value of `5`. @@ -131,39 +150,30 @@ Command above will output the following Michelson code: { parameter (or (int %decrement) (int %increment)) ; storage int ; code { DUP ; - CAR ; - DIP { DUP } ; - SWAP ; CDR ; DIP { DUP } ; SWAP ; + CAR ; IF_LEFT { DUP ; - DIP 2 { DUP } ; - DIG 2 ; - DIP { DUP } ; + DIP { DIP { DUP } ; SWAP } ; + PAIR ; + DUP ; + CDR ; + DIP { DUP ; CAR } ; SUB ; - SWAP ; - DROP ; - SWAP ; - DROP } + DIP { DROP 2 } } { DUP ; - DIP 2 { DUP } ; - DIG 2 ; - DIP { DUP } ; + DIP { DIP { DUP } ; SWAP } ; + PAIR ; + DUP ; + CDR ; + DIP { DUP ; CAR } ; ADD ; - SWAP ; - DROP ; - SWAP ; - DROP } ; + DIP { DROP 2 } } ; NIL operation ; PAIR ; - SWAP ; - DROP ; - SWAP ; - DROP ; - SWAP ; - DROP } } + DIP { DROP 2 } } } ``` @@ -180,12 +190,15 @@ ligo compile-storage src/counter.ligo main 5 ``` - -In our case the LIGO storage value maps 1:1 to its Michelson representation, however this will not be the case once the parameter is of a more complex data type, like a record. +In our case the LIGO storage value maps 1:1 to its Michelson +representation, however this will not be the case once the parameter +is of a more complex data type, like a record. ## Invoking a LIGO contract -Same rules apply for parameters, as apply for translating LIGO storage values to Michelson. We will need to use `compile-parameter` to compile our `action` variant into Michelson, here's how: +Same rules apply for parameters, as apply for translating LIGO storage +values to Michelson. We will need to use `compile-parameter` to +compile our `action` variant into Michelson, here's how: @@ -195,6 +208,5 @@ ligo compile-parameter src/counter.ligo main 'Increment(5)' ``` - Now we can use `(Right 5)` which is a Michelson value, to invoke our -contract - e.g. via `tezos-client` +contract - e.g., via `tezos-client` diff --git a/gitlab-pages/docs/advanced/src/counter.ligo b/gitlab-pages/docs/advanced/src/counter.ligo new file mode 100644 index 000000000..301b662c4 --- /dev/null +++ b/gitlab-pages/docs/advanced/src/counter.ligo @@ -0,0 +1,17 @@ +type parameter is + Increment of int +| Decrement of int + +type storage is int + +type return is list (operation) * storage + +function add (const n : int; const store : storage) : storage is store + n +function sub (const n : int; const store : storage) : storage is store - n + +function main (const action : parameter; const store : storage) : return is + ((nil : list(operation)), + case action of + Increment (n) -> add (n, store) + | Decrement (n) -> sub (n, store) + end) diff --git a/gitlab-pages/docs/advanced/src/functions.ligo b/gitlab-pages/docs/advanced/src/functions.ligo new file mode 100644 index 000000000..6e0f83bf5 --- /dev/null +++ b/gitlab-pages/docs/advanced/src/functions.ligo @@ -0,0 +1,9 @@ +function multiply (const a : int; const b : int) : int is + block { + const result : int = a * b + } with result + +function add (const a : int; const b : int) : int is a + b + +function main (const p : unit; const s : unit) : list (operation) * unit is + ((nil : list (operation)), s) diff --git a/gitlab-pages/docs/advanced/src/multiple-entrypoints.ligo b/gitlab-pages/docs/advanced/src/multiple-entrypoints.ligo new file mode 100644 index 000000000..301b662c4 --- /dev/null +++ b/gitlab-pages/docs/advanced/src/multiple-entrypoints.ligo @@ -0,0 +1,17 @@ +type parameter is + Increment of int +| Decrement of int + +type storage is int + +type return is list (operation) * storage + +function add (const n : int; const store : storage) : storage is store + n +function sub (const n : int; const store : storage) : storage is store - n + +function main (const action : parameter; const store : storage) : return is + ((nil : list(operation)), + case action of + Increment (n) -> add (n, store) + | Decrement (n) -> sub (n, store) + end) diff --git a/gitlab-pages/docs/advanced/src/variables.ligo b/gitlab-pages/docs/advanced/src/variables.ligo new file mode 100644 index 000000000..e8e40f1f7 --- /dev/null +++ b/gitlab-pages/docs/advanced/src/variables.ligo @@ -0,0 +1,5 @@ +const four : int = 4 +const name : string = "John Doe" + +function main (const p : unit; const s : unit) : list (operation) * unit is + ((nil : list (operation)), s) diff --git a/gitlab-pages/docs/advanced/timestamps-addresses.md b/gitlab-pages/docs/advanced/timestamps-addresses.md index fb2154bc8..b3a4d2391 100644 --- a/gitlab-pages/docs/advanced/timestamps-addresses.md +++ b/gitlab-pages/docs/advanced/timestamps-addresses.md @@ -18,23 +18,29 @@ current timestamp value. ```pascaligo group=a -const today : timestamp = now +const today : timestamp = Tezos.now ``` +> Note that `now` is *deprecated*. + ```cameligo group=a -let today : timestamp = Current.time +let today : timestamp = Tezos.now ``` +> Note that `Current.time` is *deprecated*. + ```reasonligo group=a -let today : timestamp = Current.time; +let today : timestamp = Tezos.now; ``` +> Note that `Current.time` is *deprecated*. + -> When running code, the LIGO CLI option -> `--predecessor-timestamp` allows you to control what `now` returns. +> When running code, the LIGO CLI option `--predecessor-timestamp` +> allows you to control what `Tezos.now` returns. ### Timestamp Arithmetics @@ -46,31 +52,37 @@ constraints on your smart contracts. Consider the following scenarios. ```pascaligo group=b -const today : timestamp = now +const today : timestamp = Tezos.now const one_day : int = 86400 const in_24_hrs : timestamp = today + one_day const some_date : timestamp = ("2000-01-01T10:10:10Z" : timestamp) const one_day_later : timestamp = some_date + one_day ``` +> Note that `now` is *deprecated*. + ```cameligo group=b -let today : timestamp = Current.time +let today : timestamp = Tezos.now let one_day : int = 86400 let in_24_hrs : timestamp = today + one_day let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp) let one_day_later : timestamp = some_date + one_day ``` +> Note that `Current.time` is *deprecated*. + ```reasonligo group=b -let today : timestamp = Current.time; +let today : timestamp = Tezos.now; let one_day : int = 86400; let in_24_hrs : timestamp = today + one_day; let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp); let one_day_later : timestamp = some_date + one_day; ``` +> Note that `Current.time` is *deprecated*. + #### 24 hours Ago @@ -78,25 +90,32 @@ let one_day_later : timestamp = some_date + one_day; ```pascaligo group=c -const today : timestamp = now +const today : timestamp = Tezos.now const one_day : int = 86400 const in_24_hrs : timestamp = today - one_day ``` +> Note that `now` is *deprecated*. + ```cameligo group=c -let today : timestamp = Current.time +let today : timestamp = Tezos.now let one_day : int = 86400 let in_24_hrs : timestamp = today - one_day ``` +> Note that `Current.time` is *deprecated*. + ```reasonligo group=c -let today : timestamp = Current.time; +let today : timestamp = Tezos.now; let one_day : int = 86400; let in_24_hrs : timestamp = today - one_day; ``` +> Note that `Current.time` is *deprecated*. + + ### Comparing Timestamps @@ -107,19 +126,26 @@ applying to numbers. ```pascaligo group=c -const not_tommorow : bool = (now = in_24_hrs) +const not_tommorow : bool = (Tezos.now = in_24_hrs) ``` +> Note that `now` is *deprecated*. + ```cameligo group=c -let not_tomorrow : bool = (Current.time = in_24_hrs) +let not_tomorrow : bool = (Tezos.now = in_24_hrs) ``` +> Note that `Current.time` is *deprecated*. + ```reasonligo group=c -let not_tomorrow : bool = (Current.time == in_24_hrs); +let not_tomorrow : bool = (Tezos.now == in_24_hrs); ``` +> Note that `Current.time` is *deprecated*. + + ## Addresses diff --git a/gitlab-pages/docs/api/cheat-sheet.md b/gitlab-pages/docs/api/cheat-sheet.md index 8f8baebdb..15e10bfe4 100644 --- a/gitlab-pages/docs/api/cheat-sheet.md +++ b/gitlab-pages/docs/api/cheat-sheet.md @@ -4,7 +4,7 @@ title: Cheat Sheet ---
- @@ -30,7 +30,7 @@ Note that this table is not compiled before production and currently needs to be |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 fail("Too young to drive.");
else const new_id: int = prev_id + 1;
| +| If Statement |
if age < 16 
then fail("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``` | @@ -71,8 +71,8 @@ Note that this table is not compiled before production and currently needs to be |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 =
Operation.get_contract destination_address
| -|Transactions|
let payment : operation = 
Operation.transaction unit amount receiver
| +|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.")`| @@ -103,8 +103,8 @@ Note that this table is not compiled before production and currently needs to be |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) =
Operation.get_contract(destination_address);
| -|Transactions|
let payment : operation = 
Operation.transaction (unit, amount, receiver);
| +|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.");`| diff --git a/gitlab-pages/docs/language-basics/boolean-if-else.md b/gitlab-pages/docs/language-basics/boolean-if-else.md index 8a872d777..e9b38291a 100644 --- a/gitlab-pages/docs/language-basics/boolean-if-else.md +++ b/gitlab-pages/docs/language-basics/boolean-if-else.md @@ -11,8 +11,8 @@ value: ```pascaligo group=a -const a : bool = True // Notice the capital letter -const b : bool = False // Same. +const a : bool = True // Also: true +const b : bool = False // Also: false ``` ```cameligo group=a @@ -137,7 +137,7 @@ state. type magnitude is Small | Large // See variant types. function compare (const n : nat) : magnitude is - if n < 10n then Small (Unit) else Large (Unit) // Unit is needed for now. + if n < 10n then Small else Large ``` You can run the `compare` function defined above using the LIGO compiler @@ -145,7 +145,7 @@ like this: ```shell ligo run-function gitlab-pages/docs/language-basics/boolean-if-else/cond.ligo compare 21n' -# Outputs: Large (Unit) +# Outputs: Large(Unit) ``` When the branches of the conditional are not a single expression, as @@ -161,7 +161,7 @@ else skip; ``` As an exception to the rule, the blocks in a conditional branch do not -need to be introduced by the keywor `block`, so, we could have written +need to be introduced by the keyword `block`, so we could have written instead: ```pascaligo skip if x < y then { @@ -187,9 +187,15 @@ gitlab-pages/docs/language-basics/boolean-if-else/cond.mligo compare 21n' # Outputs: Large ``` +> Notice that, as in OCaml, in CameLIGO, if a conditional has a branch +> `else ()`, that branch can be omitted. The resulting so-called +> *dangling else* problem is parsed by associating any `else` to the +> closest previous `then`. + + ```reasonligo group=e -type magnitude = | Small | Large; // See variant types. +type magnitude = Small | Large; // See variant types. let compare = (n : nat) : magnitude => if (n < 10n) { Small; } else { Large; }; diff --git a/gitlab-pages/docs/language-basics/functions.md b/gitlab-pages/docs/language-basics/functions.md index d0344a754..b4c81beb1 100644 --- a/gitlab-pages/docs/language-basics/functions.md +++ b/gitlab-pages/docs/language-basics/functions.md @@ -4,7 +4,15 @@ title: Functions --- LIGO functions are the basic building block of contracts. For example, -entrypoints are functions. +entrypoints are functions and each smart contract needs a main +function that dispatches control to the entrypoints (it is not already +the default entrypoint). + +The semantics of function calls in LIGO is that of a *copy of the +arguments but also of the environment*. In the case of PascaLIGO, this +means that any mutation (assignment) on variables outside the scope of +the function will be lost when the function returns, just as the +mutations inside the functions will be. ## Declaring Functions @@ -230,10 +238,14 @@ function to all its elements. ```pascaligo group=c function incr_map (const l : list (int)) : list (int) is - list_map (function (const i : int) : int is i + 1, l) + List.map (function (const i : int) : int is i + 1, l) ``` -You can call the function `incr_map` defined above using the LIGO compiler -like so: + +> Note that `list_map` is *deprecated*. + +You can call the function `incr_map` defined above using the LIGO +compiler like so: + ```shell ligo run-function gitlab-pages/docs/language-basics/src/functions/incr_map.ligo incr_map diff --git a/gitlab-pages/docs/language-basics/loops.md b/gitlab-pages/docs/language-basics/loops.md index bb31e124f..1ded1ef05 100644 --- a/gitlab-pages/docs/language-basics/loops.md +++ b/gitlab-pages/docs/language-basics/loops.md @@ -79,17 +79,21 @@ let gcd (x,y : nat * nat) : nat = ``` To ease the writing and reading of the iterated functions (here, -`iter`), two predefined functions are provided: `continue` and `stop`: +`iter`), two predefined functions are provided: `Loop.continue` and +`Loop.stop`: ```cameligo group=a let iter (x,y : nat * nat) : bool * (nat * nat) = - if y = 0n then stop (x,y) else continue (y, x mod y) + if y = 0n then Loop.stop (x,y) else Loop.continue (y, x mod y) let gcd (x,y : nat * nat) : nat = let x,y = if x < y then y,x else x,y in let x,y = Loop.fold_while iter (x,y) in x ``` + +> Note that `stop` and `continue` are *deprecated*. + You can call the function `gcd` defined above using the LIGO compiler like so: ```shell @@ -131,11 +135,12 @@ let gcd = ((x,y) : (nat, nat)) : nat => { ``` To ease the writing and reading of the iterated functions (here, -`iter`), two predefined functions are provided: `continue` and `stop`: +`iter`), two predefined functions are provided: `Loop.continue` and +`Loop.stop`: ```reasonligo group=b let iter = ((x,y) : (nat, nat)) : (bool, (nat, nat)) => - if (y == 0n) { stop ((x,y)); } else { continue ((y, x mod y)); }; + if (y == 0n) { Loop.stop ((x,y)); } else { Loop.continue ((y, x mod y)); }; let gcd = ((x,y) : (nat, nat)) : nat => { let (x,y) = if (x < y) { (y,x); } else { (x,y); }; @@ -143,6 +148,9 @@ let gcd = ((x,y) : (nat, nat)) : nat => { x }; ``` + +> Note that `stop` and `continue` are *deprecated*. + ## Bounded Loops diff --git a/gitlab-pages/docs/language-basics/maps-records.md b/gitlab-pages/docs/language-basics/maps-records.md index d691d588e..f1b491b60 100644 --- a/gitlab-pages/docs/language-basics/maps-records.md +++ b/gitlab-pages/docs/language-basics/maps-records.md @@ -19,7 +19,7 @@ Let us first consider and example of record type declaration. -```pascaligo group=a +```pascaligo group=records1 type user is record [ id : nat; @@ -29,7 +29,7 @@ type user is ``` -```cameligo group=a +```cameligo group=records1 type user = { id : nat; is_admin : bool; @@ -38,7 +38,7 @@ type user = { ``` -```reasonligo group=a +```reasonligo group=records1 type user = { id : nat, is_admin : bool, @@ -51,7 +51,7 @@ And here is how a record value is defined: -```pascaligo group=a +```pascaligo group=records1 const alice : user = record [ id = 1n; @@ -61,7 +61,7 @@ const alice : user = ``` -```cameligo group=a +```cameligo group=records1 let alice : user = { id = 1n; is_admin = true; @@ -70,7 +70,7 @@ let alice : user = { ``` -```reasonligo group=a +```reasonligo group=records1 let alice : user = { id : 1n, is_admin : true, @@ -86,17 +86,17 @@ operator, like so: -```pascaligo group=a +```pascaligo group=records1 const alice_admin : bool = alice.is_admin ``` -```cameligo group=a +```cameligo group=records1 let alice_admin : bool = alice.is_admin ``` -```reasonligo group=a +```reasonligo group=records1 let alice_admin : bool = alice.is_admin; ``` @@ -123,7 +123,7 @@ In PascaLIGO, the shape of that expression is ` with `. The record variable is the record to update and the record value is the update itself. -```pascaligo group=b +```pascaligo group=records2 type point is record [x : int; y : int; z : int] type vector is record [dx : int; dy : int] @@ -151,7 +151,7 @@ the blockless function. The syntax for the functional updates of record in CameLIGO follows that of OCaml: -```cameligo group=b +```cameligo group=records2 type point = {x : int; y : int; z : int} type vector = {dx : int; dy : int} @@ -179,7 +179,7 @@ xy_translate "({x=2;y=3;z=1}, {dx=3;dy=4})" The syntax for the functional updates of record in ReasonLIGO follows that of ReasonML: -```reasonligo group=b +```reasonligo group=records2 type point = {x : int, y : int, z : int}; type vector = {dx : int, dy : int}; @@ -216,7 +216,7 @@ name "patch"). Let us consider defining a function that translates three-dimensional points on a plane. -```pascaligo group=c +```pascaligo group=records3 type point is record [x : int; y : int; z : int] type vector is record [dx : int; dy : int] @@ -242,7 +242,7 @@ Of course, we can actually translate the point with only one `patch`, as the previous example was meant to show that, after the first patch, the value of `p` indeed changed. So, a shorter version would be -```pascaligo group=d +```pascaligo group=records4 type point is record [x : int; y : int; z : int] type vector is record [dx : int; dy : int] @@ -267,7 +267,7 @@ Record patches can actually be simulated with functional updates. All we have to do is *declare a new record value with the same name as the one we want to update* and use a functional update, like so: -```pascaligo group=e +```pascaligo group=records5 type point is record [x : int; y : int; z : int] type vector is record [dx : int; dy : int] @@ -298,71 +298,98 @@ values of the same type. The former are called *key* and the latter is that the type of the keys must be *comparable*, in the Michelson sense. +### Declaring a Map + Here is how a custom map from addresses to a pair of integers is defined. + -```pascaligo group=f +```pascaligo group=maps type move is int * int type register is map (address, move) ``` -```cameligo group=f +```cameligo group=maps type move = int * int type register = (address, move) map ``` -```reasonligo group=f +```reasonligo group=maps type move = (int, int); type register = map (address, move); ``` -And here is how a map value is defined: +### Creating an Empty Map + +Here is how to create an empty map. + + + + +```pascaligo group=maps +const empty : register = map [] +``` + + +```cameligo group=maps +let empty : register = Map.empty +``` + + +```reasonligo group=maps +let empty : register = Map.empty +``` + + +### Creating a Non-empty Map + +And here is how to create a non-empty map value: -```pascaligo group=f +```pascaligo group=maps const moves : register = map [ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2); ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] ``` -> Notice the `->` between the key and its value and `;` to separate -> individual map entries. The annotated value `("" : -> address)` means that we cast a string into an address. Also, `map` -> is a keyword. +Notice the `->` between the key and its value and `;` to separate +individual map entries. The annotated value `("" : +address)` means that we cast a string into an address. Also, `map` is +a keyword. -```cameligo group=f +```cameligo group=maps let moves : register = Map.literal [ (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2)); (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))] ``` -> The `Map.literal` predefined function builds a map from a list of -> key-value pair tuples, `(, )`. Note also the `;` to -> separate individual map entries. `("": address)` -> means that we type-cast a string into an address. +The `Map.literal` predefined function builds a map from a list of +key-value pair tuples, `(, )`. Note also the `;` to +separate individual map entries. `("": address)` means +that we type-cast a string into an address. --> -```reasonligo group=f +```reasonligo group=maps let moves : register = Map.literal ([ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]); ``` -> The `Map.literal` predefined function builds a map from a list of -> key-value pair tuples, `(, )`. Note also the `;` to -> separate individual map entries. `("": address)` -> means that we type-cast a string into an address. +The `Map.literal` predefined function builds a map from a list of +key-value pair tuples, `(, )`. Note also the `;` to +separate individual map entries. `("": address)` means +that we type-cast a string into an address. --> @@ -375,19 +402,19 @@ In PascaLIGO, we can use the postfix `[]` operator to read the `move` value associated to a given key (`address` here) in the register. Here is an example: -```pascaligo group=f +```pascaligo group=maps const my_balance : option (move) = moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] ``` -```cameligo group=f +```cameligo group=maps let my_balance : move option = Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves ``` -```reasonligo group=f +```reasonligo group=maps let my_balance : option (move) = Map.find_opt (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), moves); ``` @@ -400,7 +427,7 @@ the reader to account for a missing key in the map. This requires -```pascaligo group=f +```pascaligo group=maps function force_access (const key : address; const moves : register) : move is case moves[key] of Some (move) -> move @@ -409,7 +436,7 @@ function force_access (const key : address; const moves : register) : move is ``` -```cameligo group=f +```cameligo group=maps let force_access (key, moves : address * register) : move = match Map.find_opt key moves with Some move -> move @@ -417,7 +444,7 @@ let force_access (key, moves : address * register) : move = ``` -```reasonligo group=f +```reasonligo group=maps let force_access = ((key, moves) : (address, register)) : move => { switch (Map.find_opt (key, moves)) { | Some (move) => move @@ -443,7 +470,7 @@ The values of a PascaLIGO map can be updated using the usual assignment syntax `[] := `. Let us consider an example. -```pascaligo group=f +```pascaligo group=maps function assign (var m : register) : register is block { m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) @@ -453,7 +480,7 @@ function assign (var m : register) : register is If multiple bindings need to be updated, PascaLIGO offers a *patch instruction* for maps, similar to that for records. -```pascaligo group=f +```pascaligo group=maps function assignments (var m : register) : register is block { patch m with map [ @@ -463,35 +490,51 @@ function assignments (var m : register) : register is } with m ``` +See further for the removal of bindings. + We can update a binding in a map in CameLIGO by means of the `Map.update` built-in function: -```cameligo group=f +```cameligo group=maps let assign (m : register) : register = Map.update ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) m ``` -> Notice the optional value `Some (4,9)` instead of `(4,9)`. If we had -> use `None` instead, that would have meant that the binding is -> removed. +Notice the optional value `Some (4,9)` instead of `(4,9)`. If we had +use `None` instead, that would have meant that the binding is removed. + +As a particular case, we can only add a key and its associated value. + +```cameligo group=maps +let add (m : register) : register = + Map.add + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m +``` We can update a binding in a map in ReasonLIGO by means of the `Map.update` built-in function: -```reasonligo group=f +```reasonligo group=maps let assign = (m : register) : register => Map.update (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), Some ((4,9)), m); ``` -> Notice the optional value `Some (4,9)` instead of `(4,9)`. If we had -> use `None` instead, that would have meant that the binding is -> removed. +Notice the optional value `Some (4,9)` instead of `(4,9)`. If we had +use `None` instead, that would have meant that the binding is removed. + +As a particular case, we can only add a key and its associated value. + +```reasonligo group=maps +let add = (m : register) : register => + Map.add + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m); +``` @@ -503,7 +546,7 @@ To remove a binding from a map, we need its key. In PascaLIGO, there is a special instruction to remove a binding from a map. -```pascaligo group=f +```pascaligo group=maps function delete (const key : address; var moves : register) : register is block { remove key from map moves @@ -514,7 +557,7 @@ function delete (const key : address; var moves : register) : register is In CameLIGO, we use the predefined function `Map.remove` as follows: -```cameligo group=f +```cameligo group=maps let delete (key, moves : address * register) : register = Map.remove key moves ``` @@ -523,7 +566,7 @@ let delete (key, moves : address * register) : register = In ReasonLIGO, we use the predefined function `Map.remove` as follows: -```reasonligo group=f +```reasonligo group=maps let delete = ((key, moves) : (address, register)) : register => Map.remove (key, moves); ``` @@ -549,34 +592,28 @@ no return value: its only use is to produce side-effects. This can be useful if for example you would like to check that each value inside of a map is within a certain range, and fail with an error otherwise. +The predefined functional iterator implementing the iterated operation +over maps is called `Map.iter`. In the following example, the register +of moves is iterated to check that the start of each move is above +`3`. + -In PascaLIGO, the predefined functional iterator implementing the -iterated operation over maps is called `map_iter`. In the following -example, the register of moves is iterated to check that the start of -each move is above `3`. - -```pascaligo group=f +```pascaligo group=maps function iter_op (const m : register) : unit is block { function iterated (const i : address; const j : move) : unit is if j.1 > 3 then Unit else (failwith ("Below range.") : unit) - } with map_iter (iterated, m) + } with Map.iter (iterated, m) ``` -> The iterated function must be pure, that is, it cannot mutate -> variables. +> Note that `map_iter` is *deprecated*. -In CameLIGO, the predefinded functional iterator implementing the -iterated operation over maps is called `Map.iter`. In the following -example, the register of moves is iterated to check that the start of -each move is above `3`. - -```cameligo group=f +```cameligo group=maps let iter_op (m : register) : unit = let predicate = fun (i,j : address * move) -> assert (j.0 > 3) in Map.iter predicate m @@ -584,12 +621,7 @@ let iter_op (m : register) : unit = -In ReasonLIGO, the predefined functional iterator implementing the -iterated operation over maps is called `Map.iter`. In the following -example, the register of moves is iterated to check that the start of -each move is above `3`. - -```reasonligo group=f +```reasonligo group=maps let iter_op = (m : register) : unit => { let predicate = ((i,j) : (address, move)) => assert (j[0] > 3); Map.iter (predicate, m); @@ -601,32 +633,28 @@ let iter_op = (m : register) : unit => { We may want to change all the bindings of a map by applying to them a function. This is called a *map operation*, not to be confused with -the map data structure. +the map data structure. The predefined functional iterator +implementing the map operation over maps is called `Map.map`. In the +following example, we add `1` to the ordinate of the moves in the +register. -In PascaLIGO, the predefined functional iterator implementing the map -operation over maps is called `map_map` and is used as follows: - -```pascaligo group=f +```pascaligo group=maps function map_op (const m : register) : register is block { function increment (const i : address; const j : move) : move is - (j.0, j.1 + 1); - } with map_map (increment, m) + (j.0, j.1 + 1) + } with Map.map (increment, m) ``` -> The mapped function must be pure, that is, it cannot mutate -> variables. +> Note that `map_map` is *deprecated*. -In CameLIGO, the predefined functional iterator implementing the map -operation over maps is called `Map.map` and is used as follows: - -```cameligo group=f +```cameligo group=maps let map_op (m : register) : register = let increment = fun (i,j : address * move) -> j.0, j.1 + 1 in Map.map increment m @@ -634,10 +662,7 @@ let map_op (m : register) : register = -In ReasonLIGO, the predefined functional iteratir implementing the map -operation over maps is called `Map.map` and is used as follows: - -```reasonligo group=f +```reasonligo group=maps let map_op = (m : register) : register => { let increment = ((i,j): (address, move)) => (j[0], j[1] + 1); Map.map (increment, m); @@ -653,31 +678,26 @@ function takes two arguments: an *accumulator* and the structure enables having a partial result that becomes complete when the traversal of the data structure is over. +The predefined functional iterator implementing the folded operation +over maps is called `Map.fold` and is used as follows. + -In PascaLIGO, the predefined functional iterator implementing the -folded operation over maps is called `map_fold` and is used as -follows: - -```pascaligo group=f -function fold_op (const m : register) : int is block { - function folded (const j : int; const cur : address * move) : int is - j + cur.1.1 - } with map_fold (folded, m, 5) +```pascaligo group=maps +function fold_op (const m : register) : int is + block { + function folded (const i : int; const j : address * move) : int is + i + j.1.1 + } with Map.fold (folded, m, 5) ``` -> The folded function must be pure, that is, it cannot mutate -> variables. +> Note that `map_fold` is *deprecated*. -In CameLIGO, the predefined functional iterator implementing the -folded operation over maps is called `Map.fold` and is used as -follows: - -```cameligo group=f +```cameligo group=maps let fold_op (m : register) : register = let folded = fun (i,j : int * (address * move)) -> i + j.1.1 in Map.fold folded m 5 @@ -685,11 +705,7 @@ let fold_op (m : register) : register = -In ReasonLIGO, the predefined functional iterator implementing the -folded operation over maps is called `Map.fold` and is used as -follows: - -```reasonligo group=f +```reasonligo group=maps let fold_op = (m : register) : register => { let folded = ((i,j): (int, (address, move))) => i + j[1][1]; Map.fold (folded, m, 5); @@ -709,75 +725,102 @@ were it not for *big maps*. Big maps are a data structure offered by Michelson which handles the scaling concerns for us. In LIGO, the interface for big maps is analogous to the one used for ordinary maps. +### Declaring a Map + Here is how we define a big map: -```pascaligo group=g +```pascaligo group=big_maps type move is int * int type register is big_map (address, move) ``` -```cameligo group=g +```cameligo group=big_maps type move = int * int type register = (address, move) big_map ``` -```reasonligo group=g +```reasonligo group=big_maps type move = (int, int); type register = big_map (address, move); ``` -And here is how a map value is created: +### Creating an Empty Big Map + +Here is how to create an empty big map. + + + + + +```pascaligo group=big_maps +const empty : register = big_map [] +``` + + +```cameligo group=big_maps +let empty : register = Big_map.empty +``` + + +```reasonligo group=big_maps +let empty : register = Big_map.empty +``` + + +### Creating a Non-empty Map + +And here is how to create a non-empty map value: -```pascaligo group=g +```pascaligo group=big_maps const moves : register = big_map [ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2); ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] ``` -> Notice the right arrow `->` between the key and its value and the -> semicolon separating individual map entries. The value annotation -> `("" : address)` means that we cast a string into an -> address. + Notice the right arrow `->` between the key and its value and the --> + semicolon separating individual map entries. The value annotation --> + `("" : address)` means that we cast a string into an --> + address. --> -```cameligo group=g +```cameligo group=big_maps let moves : register = Big_map.literal [ (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2)); (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))] ``` -> The predefind function `Big_map.literal` constructs a big map from a -> list of key-value pairs `(, )`. Note also the semicolon -> separating individual map entries. The annotated value `(" value>" : address)` means that we cast a string into an address. +The predefind function `Big_map.literal` constructs a big map from a +list of key-value pairs `(, )`. Note also the semicolon +separating individual map entries. The annotated value `(" +value>" : address)` means that we cast a string into an address. -```reasonligo group=g +```reasonligo group=big_maps let moves : register = Big_map.literal ([ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]); ``` -> The predefind function `Big_map.literal` constructs a big map from a -> list of key-value pairs `(, )`. Note also the semicolon -> separating individual map entries. The annotated value `(" value>" : address)` means that we cast a string into an address. +The predefind function `Big_map.literal` constructs a big map from a +list of key-value pairs `(, )`. Note also the semicolon +separating individual map entries. The annotated value `(" +value>" : address)` means that we cast a string into an address. @@ -793,21 +836,21 @@ the value we read is an optional value (in our case, of type `option -```pascaligo group=g +```pascaligo group=big_maps const my_balance : option (move) = moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] ``` -```cameligo group=g +```cameligo group=big_maps let my_balance : move option = Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves ``` -```reasonligo group=g +```reasonligo group=big_maps let my_balance : option (move) = Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves); ``` @@ -822,7 +865,7 @@ let my_balance : option (move) = The values of a PascaLIGO big map can be updated using the assignment syntax for ordinary maps -```pascaligo group=g +```pascaligo group=big_maps function add (var m : register) : register is block { m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) @@ -836,7 +879,7 @@ const updated_map : register = add (moves) We can update a big map in CameLIGO using the `Big_map.update` built-in: -```cameligo group=g +```cameligo group=big_maps let updated_map : register = Big_map.update ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves @@ -847,10 +890,10 @@ let updated_map : register = We can update a big map in ReasonLIGO using the `Big_map.update` built-in: -```reasonligo group=g +```reasonligo group=big_maps let updated_map : register = Big_map.update - (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some((4,9)), moves); + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves); ``` @@ -867,7 +910,7 @@ syntax. PascaLIGO features a special syntactic construct to remove bindings from maps, of the form `remove from map `. For example, -```pascaligo group=g +```pascaligo group=big_maps function rem (var m : register) : register is block { remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) from map moves @@ -881,7 +924,7 @@ const updated_map : register = rem (moves) In CameLIGO, the predefined function which removes a binding in a map is called `Map.remove` and is used as follows: -```cameligo group=g +```cameligo group=big_maps let updated_map : register = Map.remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves ``` @@ -891,7 +934,7 @@ let updated_map : register = In ReasonLIGO, the predefined function which removes a binding in a map is called `Map.remove` and is used as follows: -```reasonligo group=g +```reasonligo group=big_maps let updated_map : register = Map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves) ``` diff --git a/gitlab-pages/docs/language-basics/operators.md b/gitlab-pages/docs/language-basics/operators.md index fc988c658..07dddbafc 100644 --- a/gitlab-pages/docs/language-basics/operators.md +++ b/gitlab-pages/docs/language-basics/operators.md @@ -3,13 +3,14 @@ id: operators title: Operators --- -## Available operators +## Available Operators -> This list is non-exhaustive. More operators will be added in upcoming LIGO releases. +> This list is non-exhaustive. More operators will be added in +> upcoming LIGO releases. |Michelson |Pascaligo |Description | |--- |--- |--- | -| `SENDER` | `sender` | Address that initiated the current transaction -| `SOURCE` | `source` | Address that initiated the transaction, which triggered the current transaction. (useful e.g. when there's a transaction sent by another contract) -| `AMOUNT` | `amount` | Amount of tez sent by the transaction that invoked the contract -| `NOW` | `now` | Timestamp of the block whose validation triggered execution of the contract, i.e. current time when the contract is run. \ No newline at end of file +| `SENDER` | `Tezos.sender` | Address that initiated the current transaction +| `SOURCE` | `Tezos.source` | Address that initiated the transaction, which triggered the current transaction. (useful e.g. when there's a transaction sent by another contract) +| `AMOUNT` | `Tezos.amount` | Amount of tez sent by the transaction that invoked the contract +| `NOW` | `Tezos.now` | Timestamp of the block whose validation triggered execution of the contract, i.e. current time when the contract is run. diff --git a/gitlab-pages/docs/language-basics/sets-lists-tuples.md b/gitlab-pages/docs/language-basics/sets-lists-tuples.md index 57132e9b6..abf8b4b20 100644 --- a/gitlab-pages/docs/language-basics/sets-lists-tuples.md +++ b/gitlab-pages/docs/language-basics/sets-lists-tuples.md @@ -176,11 +176,6 @@ There are three kinds of functional iterations over LIGO lists: the *iterated operation*, the *map operation* (not to be confused with the *map data structure*) and the *fold operation*. -> 💡 Lists can be iterated, folded or mapped to different values. You -> can find additional examples -> [here](https://gitlab.com/ligolang/ligo/tree/dev/src/test/contracts) -> and other built-in operators -> [here](https://gitlab.com/ligolang/ligo/blob/dev/src/passes/operators/operators.ml#L59) #### Iterated Operation over Lists @@ -188,37 +183,28 @@ The first, the *iterated operation*, is an iteration over the list with a unit return value. It is useful to enforce certain invariants on the element of a list, or fail. For example you might want to check that each value inside of a list is within a certain range, and fail -otherwise. +otherwise. The predefined functional iterator implementing the +iterated operation over lists is called `List.iter`. + +In the following example, a list is iterated to check that all its +elements (integers) are strictly greater than `3`. -In PascaLIGO, the predefined functional iterator implementing the -iterated operation over lists is called `list_iter`. - -In the following example, a list is iterated to check that all its -elements (integers) are greater than `3`: - ```pascaligo group=lists function iter_op (const l : list (int)) : unit is block { function iterated (const i : int) : unit is - if i > 2 then Unit else (failwith ("Below range.") : unit) - } with list_iter (iterated, l) + if i > 3 then Unit else (failwith ("Below range.") : unit) + } with List.iter (iterated, l) ``` -> The iterated function must be pure, that is, it cannot mutate -> variables. +> Note that `list_iter` is *deprecated*. -In CameLIGO, the predefined functional iterator implementing the -iterated operation over lists is called `List.iter`. - -In the following example, a list is iterated to check that all its -elements (integers) are greater than `3`: - ```cameligo group=lists let iter_op (l : int list) : unit = let predicate = fun (i : int) -> assert (i > 3) @@ -227,12 +213,6 @@ let iter_op (l : int list) : unit = -In ReasonLIGO, the predefined functional iterator implementing the -iterated operation over lists is called `List.iter`. - -In the following example, a list is iterated to check that all its -elements (integers) are greater than `3`: - ```reasonligo group=lists let iter_op = (l : list (int)) : unit => { let predicate = (i : int) => assert (i > 3); @@ -247,32 +227,25 @@ let iter_op = (l : list (int)) : unit => { We may want to change all the elements of a given list by applying to them a function. This is called a *map operation*, not to be confused -with the map data structure. +with the map data structure. The predefined functional iterator +implementing the mapped operation over lists is called `List.map` and +is used as follows. -In PascaLIGO, the predefined functional iterator implementing the -mapped operation over lists is called `list_map` and is used as -follows: - ```pascaligo group=lists function increment (const i : int): int is i + 1 // Creates a new list with all elements incremented by 1 -const plus_one : list (int) = list_map (increment, larger_list) +const plus_one : list (int) = List.map (increment, larger_list) ``` -> The mapped function must be pure, that is, it cannot mutate -> variables. +> Note that `list_map` is *deprecated*. -In CameLIGO, the predefined functional iterator implementing the -mapped operation over lists is called `List.map` and is used as -follows: - ```cameligo group=lists let increment (i : int) : int = i + 1 @@ -282,10 +255,6 @@ let plus_one : int list = List.map increment larger_list -In ReasonLIGO, the predefined functional iterator implementing the -mapped operation over lists is called `List.map` and is used as -follows: - ```reasonligo group=lists let increment = (i : int) : int => i + 1; @@ -301,29 +270,23 @@ A *folded operation* is the most general of iterations. The folded function takes two arguments: an *accumulator* and the structure *element* at hand, with which it then produces a new accumulator. This enables having a partial result that becomes complete when the -traversal of the data structure is over. +traversal of the data structure is over. The predefined functional +iterator implementing the folded operation over lists is called +`List.fold` and is used as follows. -In PascaLIGO, the predefined functional iterator implementing the -folded operation over lists is called `list_fold` and is used as -follows: - ```pascaligo group=lists function sum (const acc : int; const i : int): int is acc + i -const sum_of_elements : int = list_fold (sum, my_list, 0) +const sum_of_elements : int = List.fold (sum, my_list, 0) ``` -> The folded function must be pure, that is, it cannot mutate -> variables. +> Note that `list_fold` is *deprecated*. -In CameLIGO, the predefined functional iterator implementing the folded -operation over lists is called `List.fold` and is used as follows: - ```cameligo group=lists let sum (acc, i: int * int) : int = acc + i let sum_of_elements : int = List.fold sum my_list 0 @@ -331,10 +294,6 @@ let sum_of_elements : int = List.fold sum my_list 0 -In ReasonLIGO, the predefined functional iterator implementing the -folded operation over lists is called `List.fold` and is used as -follows: - ```reasonligo group=lists let sum = ((result, i): (int, int)): int => result + i; let sum_of_elements : int = List.fold (sum, my_list, 0); @@ -472,36 +431,31 @@ in a set as follows: ```reasonligo group=sets let contains_3 : bool = Set.mem (3, my_set); ``` + ### Cardinal of Sets +The predefined function `Set.size` returns the number of +elements in a given set as follows. + -In PascaLIGO, the predefined function `size` returns the number of -elements in a given set as follows: - ```pascaligo group=sets -const set_size : nat = size (my_set) +const cardinal : nat = Set.size (my_set) ``` -In CameLIGO, the predefined function `Set.size` returns the number of -elements in a given set as follows: - ```cameligo group=sets -let set_size : nat = Set.size my_set +let cardinal : nat = Set.size my_set ``` -In ReasonLIGO, the predefined function `Set.size` returns the number -of elements in a given set as follows: - ```reasonligo group=sets -let set_size : nat = Set.size (my_set); +let cardinal : nat = Set.size (my_set); ``` @@ -509,20 +463,23 @@ let set_size : nat = Set.size (my_set); ### Updating Sets +There are two ways to update a set, that is to add or remove from +it. + -In PascaLIGO, there are two ways to update a set, that is to add or -remove from it. Either we create a new set from the given one, or we +In PascaLIGO, either we create a new set from the given one, or we modify it in-place. First, let us consider the former way: ```pascaligo group=sets -const larger_set : set (int) = set_add (4, my_set) - -const smaller_set : set (int) = set_remove (3, my_set) +const larger_set : set (int) = Set.add (4, my_set) +const smaller_set : set (int) = Set.remove (3, my_set) ``` +> Note that `set_add` and `set_remove` are *deprecated*. + If we are in a block, we can use an instruction to modify the set bound to a given variable. This is called a *patch*. It is only possible to add elements by means of a patch, not remove any: it is @@ -544,23 +501,23 @@ const new_set : set (int) = update (my_set) -In CameLIGO, we update a given set by creating another one, with or +In CameLIGO, we can use the predefined functions `Set.add` and +`Set.remove`. We update a given set by creating another one, with or without some elements. ```cameligo group=sets let larger_set : int set = Set.add 4 my_set - let smaller_set : int set = Set.remove 3 my_set ``` -In ReasonLIGO, we update a given set by creating another one, with or +In ReasonLIGO, we can use the predefined functions `Set.add` and +`Set.remove`. We update a given set by creating another one, with or without some elements. ```reasonligo group=sets let larger_set : set (int) = Set.add (4, my_set); - let smaller_set : set (int) = Set.remove (3, my_set); ``` @@ -584,35 +541,27 @@ no return value: its only use is to produce side-effects. This can be useful if for example you would like to check that each value inside of a map is within a certain range, and fail with an error otherwise. +The predefined functional iterator implementing the iterated operation +over sets is called `Set.iter`. In the following example, a set is +iterated to check that all its elements (integers) are greater than +`3`. + -In PascaLIGO, the predefined functional iterator implementing the -iterated operation over sets is called `set_iter`. - -In the following example, a set is iterated to check that all its -elements (integers) are greater than `3`: - ```pascaligo group=sets function iter_op (const s : set (int)) : unit is block { function iterated (const i : int) : unit is if i > 2 then Unit else (failwith ("Below range.") : unit) - } with set_iter (iterated, s) + } with Set.iter (iterated, s) ``` -> The iterated function must be pure, that is, it cannot mutate -> variables. +> Note that `set_iter` is *deprecated*. -In CameLIGO, the predefined functional iterator implementing the -iterated operation over sets is called `Set.iter`. - -In the following example, a set is iterated to check that all its -elements (integers) are greater than `3`: - ```cameligo group=sets let iter_op (s : int set) : unit = let predicate = fun (i : int) -> assert (i > 3) @@ -621,12 +570,6 @@ let iter_op (s : int set) : unit = -In ReasonLIGO, the predefined functional iterator implementing the -iterated operation over sets is called `Set.iter`. - -In the following example, a set is iterated to check that all its -elements (integers) are greater than `3`: - ```reasonligo group=sets let iter_op = (s : set (int)) : unit => { let predicate = (i : int) => assert (i > 3); @@ -637,51 +580,51 @@ let iter_op = (s : set (int)) : unit => { -#### Mapped Operation (NOT IMPLEMENTED YET) + -We may want to change all the elements of a given set by applying to -them a function. This is called a *mapped operation*, not to be -confused with the map data structure. + + + - + - + -In PascaLIGO, the predefined functional iterator implementing the -mapped operation over sets is called `set_map` and is used as follows: + + -```pascaligo skip -function increment (const i : int): int is i + 1 + + -// Creates a new set with all elements incremented by 1 -const plus_one : set (int) = set_map (increment, larger_set) -``` + + + - + -In CameLIGO, the predefined functional iterator implementing the -mapped operation over sets is called `Set.map` and is used as follows: + + -```cameligo skip -let increment (i : int) : int = i + 1 + + -// Creates a new set with all elements incremented by 1 -let plus_one : int set = Set.map increment larger_set -``` + + + - + -In ReasonLIGO, the predefined functional iterator implementing the -mapped operation over sets is called `Set.map` and is used as follows: + + -```reasonligo skip -let increment = (i : int) : int => i + 1; + + -// Creates a new set with all elements incremented by 1 -let plus_one : set (int) = Set.map (increment, larger_set); -``` + + + - + #### Folded Operation @@ -689,24 +632,20 @@ A *folded operation* is the most general of iterations. The folded function takes two arguments: an *accumulator* and the structure *element* at hand, with which it then produces a new accumulator. This enables having a partial result that becomes complete when the -traversal of the data structure is over. +traversal of the data structure is over. The predefined fold over sets +is called `Set.fold`. -In PascaLIGO, the predefined functional iterator implementing the -folded operation over sets is called `set_fold` and is used as -follows: - ```pascaligo group=sets function sum (const acc : int; const i : int): int is acc + i -const sum_of_elements : int = set_fold (sum, my_set, 0) +const sum_of_elements : int = Set.fold (sum, my_set, 0) ``` -> The folded function must be pure, that is, it cannot mutate -> variables. +> Note that `set_fold` is *deprecated*. It is possible to use a *loop* over a set as well. @@ -721,8 +660,6 @@ function loop (const s : set (int)) : int is block { -In CameLIGO, the predefined fold over sets is called `Set.fold`. - ```cameligo group=sets let sum (acc, i : int * int) : int = acc + i @@ -731,8 +668,6 @@ let sum_of_elements : int = Set.fold sum my_set 0 -In ReasonLIGO, the predefined fold over sets is called `Set.fold`. - ```reasonligo group=sets let sum = ((acc, i) : (int, int)) : int => acc + i; diff --git a/gitlab-pages/docs/language-basics/src/boolean-if-else/cond.ligo b/gitlab-pages/docs/language-basics/src/boolean-if-else/cond.ligo index 68f01d71b..9722fbac3 100644 --- a/gitlab-pages/docs/language-basics/src/boolean-if-else/cond.ligo +++ b/gitlab-pages/docs/language-basics/src/boolean-if-else/cond.ligo @@ -1,4 +1,4 @@ type magnitude is Small | Large // See variant types function compare (const n : nat) : magnitude is - if n < 10n then Small (Unit) else Large (Unit) + if n < 10n then Small else Large diff --git a/gitlab-pages/docs/language-basics/src/functions/incr_map.ligo b/gitlab-pages/docs/language-basics/src/functions/incr_map.ligo index e5f915847..75bbb9c3a 100644 --- a/gitlab-pages/docs/language-basics/src/functions/incr_map.ligo +++ b/gitlab-pages/docs/language-basics/src/functions/incr_map.ligo @@ -2,4 +2,4 @@ function increment (const b : int) : int is (function (const a : int) : int is a + 1) (b) function incr_map (const l : list (int)) : list (int) is - list_map (function (const i : int) : int is i + 1, l) +List.map (function (const i : int) : int is i + 1, l) diff --git a/gitlab-pages/docs/language-basics/src/sets-lists-tuples/lists.ligo b/gitlab-pages/docs/language-basics/src/sets-lists-tuples/lists.ligo index 7d2d49fbc..70e2b0655 100644 --- a/gitlab-pages/docs/language-basics/src/sets-lists-tuples/lists.ligo +++ b/gitlab-pages/docs/language-basics/src/sets-lists-tuples/lists.ligo @@ -4,9 +4,8 @@ const larger_list : int_list = 5 # my_list function increment (const i : int): int is i + 1 -// Creates a new list with all elements incremented by 1 -const plus_one : list (int) = list_map (increment, larger_list); +const plus_one : list (int) = List.map (increment, larger_list); function sum (const acc : int; const i : int): int is acc + i -const sum_of_elements : int = list_fold (sum, my_list, 0) +const sum_of_elements : int = List.fold (sum, my_list, 0) diff --git a/gitlab-pages/docs/language-basics/src/sets-lists-tuples/sets.ligo b/gitlab-pages/docs/language-basics/src/sets-lists-tuples/sets.ligo index b6ede8212..885d21e02 100644 --- a/gitlab-pages/docs/language-basics/src/sets-lists-tuples/sets.ligo +++ b/gitlab-pages/docs/language-basics/src/sets-lists-tuples/sets.ligo @@ -6,9 +6,9 @@ const contains_3 : bool = my_set contains 3 const set_size : nat = size (my_set) -const larger_set : int_set = set_add (4, my_set) +const larger_set : int_set = Set.add (4, my_set) -const smaller_set : int_set = set_remove (3, my_set) +const smaller_set : int_set = Set.remove (3, my_set) function update (var s : set (int)) : set (int) is block { patch s with set [4; 7] @@ -18,7 +18,7 @@ const new_set : set (int) = update (my_set) function sum (const acc : int; const i : int): int is acc + i -const sum_of_elements : int = set_fold (sum, my_set, 0) +const sum_of_elements : int = Set.fold (sum, my_set, 0) function loop (const s : set (int)) : int is block { var sum : int := 0; diff --git a/gitlab-pages/docs/language-basics/src/unit-option-pattern-matching/flip.ligo b/gitlab-pages/docs/language-basics/src/unit-option-pattern-matching/flip.ligo index 5f54bc61e..f50bc7757 100644 --- a/gitlab-pages/docs/language-basics/src/unit-option-pattern-matching/flip.ligo +++ b/gitlab-pages/docs/language-basics/src/unit-option-pattern-matching/flip.ligo @@ -2,6 +2,6 @@ type coin is Head | Tail function flip (const c : coin) : coin is case c of - Head -> Tail (Unit) // Unit needed because of a bug - | Tail -> Head (Unit) // Unit needed because of a bug + Head -> Tail + | Tail -> Head end diff --git a/gitlab-pages/docs/language-basics/strings.md b/gitlab-pages/docs/language-basics/strings.md index 461d0e38d..9a4022998 100644 --- a/gitlab-pages/docs/language-basics/strings.md +++ b/gitlab-pages/docs/language-basics/strings.md @@ -59,21 +59,27 @@ Strings can be sliced using a built-in function: ```pascaligo group=b const name : string = "Alice" -const slice : string = string_slice (0n, 1n, name) +const slice : string = String.slice (0n, 1n, name) ``` + +> Note that `string_slide` is *deprecated*. + ```cameligo group=b let name : string = "Alice" let slice : string = String.slice 0n 1n name ``` + ```reasonligo group=b let name : string = "Alice"; let slice : string = String.slice (0n, 1n, name); ``` + -> ⚠️ Notice that the offset and length of the slice are natural numbers. +> ⚠️ Notice that the offset and length of the slice are natural +> numbers. ## Length of Strings @@ -83,8 +89,11 @@ The length of a string can be found using a built-in function: ```pascaligo group=c const name : string = "Alice" -const length : nat = size (name) // length = 5 +const length : nat = String.length (name) // length = 5 ``` + +> Note that `size` is *deprecated*. + ```cameligo group=c let name : string = "Alice" diff --git a/gitlab-pages/docs/language-basics/tezos-specific.md b/gitlab-pages/docs/language-basics/tezos-specific.md index e63764b66..9fed6760a 100644 --- a/gitlab-pages/docs/language-basics/tezos-specific.md +++ b/gitlab-pages/docs/language-basics/tezos-specific.md @@ -26,9 +26,11 @@ functionality can be accessed from within LIGO. ```pascaligo group=a function id_string (const p : string) : option (string) is block { const packed : bytes = bytes_pack (p) -} with (bytes_unpack (packed) : option (string)) +} with (Bytes.unpack (packed) : option (string)) ``` +> Note that `bytes_unpack` is *deprecated*. + ```cameligo group=a let id_string (p : string) : string option = @@ -103,9 +105,11 @@ function check_signature (const pk : key; const signed : signature; const msg : bytes) : bool - is crypto_check (pk, signed, msg) + is Crypto.check (pk, signed, msg) ``` +> Note that `crypto_check` is *deprecated*. + ```cameligo group=c let check_signature (pk, signed, msg : key * signature * bytes) : bool = @@ -124,27 +128,29 @@ let check_signature = ## Contract's Own Address Often you want to get the address of the contract being executed. You -can do it with `self_address`. +can do it with `Tezos.self_address`. -> ⚠️ Due to limitations in Michelson, `self_address` in a contract is -> only allowed at the top-level. Using it in an embedded function will -> cause an error. +> Note that `self_address` is *deprecated*. + +> ⚠️ Due to limitations in Michelson, `Tezos.self_address` in a +> contract is only allowed at the top-level. Using it in an embedded +> function will cause an error. ```pascaligo group=d -const current_addr : address = self_address +const current_addr : address = Tezos.self_address ``` ```cameligo group=d -let current_addr : address = Current.self_address +let current_addr : address = Tezos.self_address ``` ```reasonligo group=d -let current_addr : address = Current.self_address; +let current_addr : address = Tezos.self_address; ``` diff --git a/gitlab-pages/docs/language-basics/types.md b/gitlab-pages/docs/language-basics/types.md index 1ea5eeba0..68b79357e 100644 --- a/gitlab-pages/docs/language-basics/types.md +++ b/gitlab-pages/docs/language-basics/types.md @@ -229,7 +229,7 @@ type return = operation list * storage let back (param, store : unit * storage) : return = let no_op : operation list = [] in - if Current.time > store.deadline then + if Tezos.now > store.deadline then (failwith "Deadline passed." : return) // Annotation else match Map.find_opt sender store.backers with @@ -255,7 +255,7 @@ type return = (list (operation), storage); let back = ((param, store) : (unit, storage)) : return => { let no_op : list (operation) = []; - if (Current.time > store.deadline) { + if (Tezos.now > store.deadline) { (failwith ("Deadline passed.") : return); // Annotation } else { diff --git a/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md b/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md index ff497a6b3..881e29d56 100644 --- a/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md +++ b/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md @@ -56,8 +56,8 @@ else): ```pascaligo group=b type coin is Head | Tail -const head : coin = Head (Unit) // Unit needed for now. -const tail : coin = Tail (Unit) // Unit needed for now. +const head : coin = Head +const tail : coin = Tail ``` @@ -69,14 +69,16 @@ let tail : coin = Tail ```reasonligo group=b -type coin = | Head | Tail; +type coin = Head | Tail; let head : coin = Head; let tail : coin = Tail; ``` The names `Head` and `Tail` in the definition of the type `coin` are -called *data constructors*, or *variants*. +called *data constructors*, or *variants*. In this particular, they +carry no information beyond their names, so they are called *constant +constructors*. In general, it is interesting for variants to carry some information, and thus go beyond enumerated types. In the following, we show how to @@ -94,7 +96,7 @@ type user is | Guest const u : user = Admin (1000n) -const g : user = Guest (Unit) // Unit needed because of a bug +const g : user = Guest ``` @@ -125,6 +127,9 @@ let g : user = Guest; +In LIGO, a constant constructor is equivalent to the same constructor +taking an argument of type `unit`, so, for example, `Guest` is the +same value as `Guest (unit)`. ## Optional values @@ -172,8 +177,8 @@ type coin is Head | Tail function flip (const c : coin) : coin is case c of - Head -> Tail (Unit) // Unit needed because of a bug - | Tail -> Head (Unit) // Unit needed because of a bug + Head -> Tail + | Tail -> Head end ``` @@ -181,7 +186,7 @@ You can call the function `flip` by using the LIGO compiler like so: ```shell ligo run-function gitlab-pages/docs/language-basics/src/unit-option-pattern-matching/flip.ligo -flip "(Head (Unit))" +flip "Head" # Outputs: Tail(Unit) ``` diff --git a/gitlab-pages/docs/language-basics/variables-and-constants.md b/gitlab-pages/docs/language-basics/variables-and-constants.md index 3fe31ff18..8c8f48577 100644 --- a/gitlab-pages/docs/language-basics/variables-and-constants.md +++ b/gitlab-pages/docs/language-basics/variables-and-constants.md @@ -60,7 +60,10 @@ a *global scope*, but they can be declared and used within functions, or as function parameters. > ⚠️ Please be wary that mutation only works within the function scope -> itself, values outside of the function scope will not be affected. +> itself, values outside of the function scope will not be +> affected. In other words, when a function is called, its arguments +> are copied, *as well as the environment*. Any side-effect to that +> environment is therefore lost when the function returns. ```pascaligo group=b diff --git a/gitlab-pages/docs/reference/big_map.md b/gitlab-pages/docs/reference/big_map.md index cb733d61c..fa0fa3ebc 100644 --- a/gitlab-pages/docs/reference/big_map.md +++ b/gitlab-pages/docs/reference/big_map.md @@ -1,128 +1,128 @@ --- id: big-map-reference -title: Big Map — Scalable hashmap primitive +title: Big Map — Scalable Maps --- ## Defining A Big Map Type -```pascaligo -type move is (int * int) -type moveset is big_map (address, move) -type foo is big_map (int, int) +```pascaligo group=big_map +type move is int * int +type register is big_map (address, move) ``` -```cameligo +```cameligo group=big_map type move = int * int -type moveset = (address, move) big_map -type foo = (int, int) big_map +type register = (address, move) big_map ``` -```reasonligo +```reasonligo group=big_map type move = (int, int); -type moveset = big_map(address, move); -type foo = big_map(int, int); +type register = big_map (address, move); ``` -## Creating A Map +## Creating an Empty Big Map + +Create an empty big map. + + + + +```pascaligo group=big_map +const empty : register = big_map [] +``` + + +```cameligo group=big_map +let empty : register = Big_map.empty +``` + + +```reasonligo group=big_map +let empty : register = Big_map.empty +``` + + + +## Populating A Big Map -```pascaligo -const moves: moveset = - big_map - ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) -> (1,2); - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) -> (0,3); - end +```pascaligo group=big_map +const moves: register = + big_map [ + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2); + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] ``` -```cameligo -let moves: moveset = +```cameligo group=big_map +let moves: register = Big_map.literal [ - (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address), (1,2)); - (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), (0,3)); - ] + (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2)); + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))] ``` -```reasonligo -let moves: moveset = +```reasonligo group=big_map +let moves: register = Big_map.literal ([ - ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address, (1,2)), - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, (0,3)), - ]); + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]); ``` -## Big_map.find_opt(k: a', m: (a',b') big_map) : b' option +## Retrieving a Value in a Big Map -Retrieve the value associated with a particular key. This version returns an option -which can either shift logic in response to a missing value or throw an error. +Retrieve the value associated with a particular key. This version +returns an option which can either shift logic in response to a +missing value or throw an error. -```pascaligo -const my_balance : option(move) = - moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] +```pascaligo group=big_map +const my_balance : option (move) = + moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] ``` -```cameligo +The function is `Big_map.find_opt` whose type is `'key -> +('key,'value) big_map) -> 'value option`. Recall that the function +`Big_map.find_opt` must always be fully applied to its arguments. Here +is an example: + +```cameligo group=big_map let my_balance : move option = - Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves + Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves ``` -```reasonligo -let my_balance : option(move) = - Big_map.find_opt("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, moves); +The function is `Big_map.find_opt` whose type is `('key, ('key, +'value) big_map) : 'value option`. Here is an example: + +```reasonligo group=big_map +let my_balance : option (move) = + Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves); ``` -## Big_map.find(k: a', m: (a', b') big_map) : b' +## Updating a Binding in a Big Map -Forcefully retrieve the value associated with a particular key. If that value -doesn't exist, this function throws an error. - - - -```pascaligo -const my_balance : move = - get_force (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves); -``` - - - -```cameligo -let my_balance : move = - Big_map.find ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves -``` - - - -```reasonligo -let my_balance : move = - Big_map.find ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, moves); -``` - - - -## Big_map.update(k: a', v: b', m: (a', b') big_map) : (a', b') big_map - -Change the value associated with a particular key, if that value doesn't already -exist add it. +Given a map, we may want to add a new binding, remove one, or modify +one by changing the value associated to an already existing key. We +may even want to retain the key but not the associated value. All +those operations are called *updates*. @@ -131,138 +131,123 @@ exist add it. The values of a PascaLIGO big map can be updated using the ordinary assignment syntax: -```pascaligo - -function set_ (var m : moveset) : moveset is +```pascaligo group=big_map +function add (var m : register) : register is block { - m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9); + m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) } with m + +const updated_map : register = add (moves) ``` +See further for the removal of bindings. + -```cameligo -let updated_map : moveset = - Big_map.update ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) (Some (4,9)) moves +In CameLIGO, you need the predefined function `Big_map.update` whose +type is `'key -> 'value option -> ('key, 'value) big_map -> ('key, +'value) big_map`. If the value (second argument) is `None`, then the +binding is to be removed. Recall that the function `Big_map.update` +must always be fully applied to its arguments. Here is an example: + +```cameligo group=big_map +let updated_map : register = + Big_map.update + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves ``` -```reasonligo -let updated_map : moveset = - Big_map.update(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some((4,9)), moves); +In ReasonLIGO, you need the predefined function `Big_map.update` whose +type is `('key, 'value option, ('key, 'value) big_map) : ('key, +'value) big_map`. If the value (second componenat) is `None`, then the +binding is to be removed. Here is an example: + +```reasonligo group=big_map +let updated_map : register = + Big_map.update + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves); ``` -## Big_map.add(k: a', v: b', m: (a', b') big_map) : (a', b') big_map +## Adding a Binding to a Big Map Add a key and its associated value to the big map. - -```pascaligo -function set_ (var n : int ; var m : foo) : foo is block { - m[23] := n ; -} with m +```pascaligo group=big_map +function add (var m : register) : register is + block { + m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) + } with m + +const updated_map : register = add (moves) ``` -```cameligo -let add (n,m : int * foo) : foo = Big_map.add 23 n m + +In CameLIGO, we use the predefined function `Big_map.add`, whose type +is `'key -> 'value -> ('key, 'value) big_map -> ('key, 'value) +big_map`. Recall that the function `Big_map.add` must always be fully +applied to its arguments. Here is an example: + +```cameligo group=big_map +let add (m : register) : register = + Map.add + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m ``` -```reasonligo -let add = ((n,m): (int, foo)): foo => Big_map.add(23, n, m); + +In ReasonLIGO, we use the predefined function `Big_map.add`, whose +type is `('key, 'value, ('key, 'value) big_map : ('key, 'value) +big_map`. Here is an example: + +```reasonligo group=big_map +let add = (m : register) : register => + Map.add + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m); ``` -## Big_map.remove(k: a', m: (a', b') big_map) : (a', b') big_map +## Removing a Binding from a Big Map Remove a key and its associated value from the big map. -```pascaligo -function rm (var m : foo) : foo is block { - remove 42 from map m; -} with m -``` - - -```cameligo -let rm (m : foo) : foo = Big_map.remove 42 m -``` - - -```reasonligo -let rm = (m: foo): foo => Big_map.remove(42, m); -``` - - - -## Big_map.literal(key_value_pair_list: (a', b') list) : (a', b') big_map - -Constructs a big map from a list of key-value pair tuples. - - - - -```pascaligo -const moves: moveset = - big_map - ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) -> (1,2); - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) -> (0,3); - end +```pascaligo group=big_map +function delete (const key : address; var moves : register) : register is + block { + remove key from map moves + } with moves ``` -```cameligo -let moves: moveset = - Big_map.literal [ - (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address), (1,2)); - (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), (0,3)); - ] +In CameLIGO, we use the predefined function `Big_map.remove` whose +type is `'key -> ('key, 'value) big_map -> ('key, 'value) +big_map`. Note that, despite being curried, the calls to that function +must be complete. Here is an example: + +```cameligo group=big_map +let delete (key, moves : address * register) : register = + Map.remove key moves ``` -```reasonligo -let moves: moveset = - Big_map.literal ([ - ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address, (1,2)), - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, (0,3)), - ]); +In ReasonLIGO, we use the predefined function `Big_map.remove` whose +type is `('key, ('key, 'value) big_map) : ('key, 'value) +big_map`. Here is an example: + +```reasonligo group=big_map +let delete = ((key, moves) : (address, register)) : register => + Map.remove (key, moves); ``` - - -## Big_map.empty() : (a', b') big_map - -Create an empty big map. - - - - -```pascaligo -const empty_big_map : big_map(int,int) = big_map end -``` - - -```cameligo -let empty_map : foo = Big_map.empty -``` - - -```reasonligo -let empty_map: foo = Big_map.empty; -``` - - - diff --git a/gitlab-pages/docs/reference/list.md b/gitlab-pages/docs/reference/list.md index 63efcf66a..1c34215fe 100644 --- a/gitlab-pages/docs/reference/list.md +++ b/gitlab-pages/docs/reference/list.md @@ -1,9 +1,182 @@ --- id: list-reference -title: List — Ordered collection of a type +title: List — Linear Collections --- -## List.size(lst: a' list) : nat +Lists are linear collections of elements of the same type. Linear +means that, in order to reach an element in a list, we must visit all +the elements before (sequential access). Elements can be repeated, as +only their order in the collection matters. The first element is +called the *head*, and the sub-list after the head is called the +*tail*. For those familiar with algorithmic data structure, you can +think of a list a *stack*, where the top is written on the left. + +## Defining Lists + + + +```pascaligo group=lists +const empty_list : list (int) = nil // Or list [] +const my_list : list (int) = list [1; 2; 2] // The head is 1 +``` + + +```cameligo group=lists +let empty_list : int list = [] +let my_list : int list = [1; 2; 2] // The head is 1 +``` + + +```reasonligo group=lists +let empty_list : list (int) = []; +let my_list : list (int) = [1, 2, 2]; // The head is 1 +``` + + + +### Adding to Lists + +Lists can be augmented by adding an element before the head (or, in +terms of stack, by *pushing an element on top*). + + + + + +```pascaligo group=lists +const larger_list : list (int) = 5 # my_list // [5;1;2;2] +``` + + + +```cameligo group=lists +let larger_list : int list = 5 :: my_list // [5;1;2;2] +``` + + + +```reasonligo group=lists +let larger_list : list (int) = [5, ...my_list]; // [5,1,2,2] +``` + + + +### Functional Iteration over Lists + +A *functional iterator* is a function that traverses a data structure +and calls in turn a given function over the elements of that structure +to compute some value. Another approach is possible in PascaLIGO: +*loops* (see the relevant section). + +There are three kinds of functional iterations over LIGO lists: the +*iterated operation*, the *map operation* (not to be confused with the +*map data structure*) and the *fold operation*. + +#### Iterated Operation over Lists + +The first, the *iterated operation*, is an iteration over the list +with a unit return value. It is useful to enforce certain invariants +on the element of a list, or fail. + + + + + +```pascaligo group=lists +function iter_op (const l : list (int)) : unit is + block { + function iterated (const i : int) : unit is + if i > 2 then Unit else (failwith ("Below range.") : unit) + } with list_iter (iterated, l) +``` + + +```cameligo group=lists +let iter_op (l : int list) : unit = + let predicate = fun (i : int) -> assert (i > 3) + in List.iter predicate l +``` + + + +```reasonligo group=lists +let iter_op = (l : list (int)) : unit => { + let predicate = (i : int) => assert (i > 3); + List.iter (predicate, l); +}; +``` + + + +#### Mapped Operation over Lists + +We may want to change all the elements of a given list by applying to +them a function. This is called a *map operation*, not to be confused +with the map data structure. + + + + + +```pascaligo group=lists +function increment (const i : int): int is i + 1 + +// Creates a new list with all elements incremented by 1 +const plus_one : list (int) = list_map (increment, larger_list) +``` + + + +```cameligo group=lists +let increment (i : int) : int = i + 1 + +// Creates a new list with all elements incremented by 1 +let plus_one : int list = List.map increment larger_list +``` + + + +```reasonligo group=lists +let increment = (i : int) : int => i + 1; + +// Creates a new list with all elements incremented by 1 +let plus_one : list (int) = List.map (increment, larger_list); +``` + + +#### Folded Operation over Lists + +A *folded operation* is the most general of iterations. The folded +function takes two arguments: an *accumulator* and the structure +*element* at hand, with which it then produces a new accumulator. This +enables having a partial result that becomes complete when the +traversal of the data structure is over. + + + + + +```pascaligo group=lists +function sum (const acc : int; const i : int): int is acc + i +const sum_of_elements : int = list_fold (sum, my_list, 0) +``` + + + +```cameligo group=lists +let sum (acc, i: int * int) : int = acc + i +let sum_of_elements : int = List.fold sum my_list 0 +``` + + + +```reasonligo group=lists +let sum = ((result, i): (int, int)): int => result + i; +let sum_of_elements : int = List.fold (sum, my_list, 0); +``` + + +## List Length Get the number of elements in a list. @@ -11,29 +184,25 @@ Get the number of elements in a list. ```pascaligo -function size_ (const m : list(int)) : nat is size(m) +function size_of (const l : list (int)) : nat is List.length (l) ``` ```cameligo -let size_ (s: int list) : nat = List.size s +let size_of (l : int list) : nat = List.length l ``` ```reasonligo -let size_ = (s: list(int)): nat => List.size(s); +let size_of = (l : list (int)) : nat => List.length (l); ``` -## List.length(lst: a' list) : nat - -Alias of `List.size`. - ## List.map(map_function: a' -> b', lst: a' list) : 'b list -Apply an operation defined by `map_function` to each element of a list and return -a list of the modified elements. +Apply an operation defined by `map_function` to each element of a list +and return a list of the modified elements. diff --git a/gitlab-pages/docs/reference/map.md b/gitlab-pages/docs/reference/map.md index 70710e8b7..c7a5590e7 100644 --- a/gitlab-pages/docs/reference/map.md +++ b/gitlab-pages/docs/reference/map.md @@ -1,392 +1,274 @@ --- id: map-reference -title: Map — Hashmaps that it makes sense to iterate over +title: Map --- ## Defining A Map Type -```pascaligo +```pascaligo group=map type move is int * int -type moveset is map(address, move) +type register is map (address, move) ``` -```cameligo +```cameligo group=map type move = int * int -type moveset = (address, move) map +type register = (address, move) map ``` -```reasonligo +```reasonligo group=map type move = (int, int); -type moveset = map(address, move); +type register = map (address, move); ``` -## Creating A Map - - - - -```pascaligo -const moves: moveset = map - ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) -> (1, 2); - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) -> (0, 3); -end -``` - - - -```cameligo -let moves: moveset = Map.literal - [ (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address), (1, 2)) ; - (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), (0, 3)) ; - ] -``` - - - -```reasonligo -let moves : moveset = - Map.literal([ - ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address, (1, 2)), - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, (0, 3)), - ]); -``` - - -## Map.find_opt(k: a', m: (a',b') map) : b' option - -Retrieve the value associated with a particular key. This version returns an option -which can either shift logic in response to a missing value or throw an error. - - - -```pascaligo -const my_balance : option(move) = moves[("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)]; -``` - - - -```cameligo -let my_balance : move option = Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves -``` - - - -```reasonligo -let my_balance : option(move) = - Map.find_opt("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, moves); -``` - - -## Map.find(k: a', m: (a', b') map) : b' - -Forcefully retrieve the value associated with a particular key. If that value -doesn't exist, this function throws an error. - - - -```pascaligo -const my_balance : move = get_force(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves); -``` - - - -```cameligo -let my_balance : move = Map.find ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves -``` - - - -```reasonligo -let my_balance : move = - Map.find("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, moves); -``` - - - -## Map.update(k: a', v: b', m: (a', b') map) : (a', b') map - -Change the value associated with a particular key, if that value doesn't already -exist add it. - - - - - -The values of a PascaLIGO map can be updated using the ordinary assignment syntax: - -```pascaligo - -function set_ (var m: moveset) : moveset is - block { - m[("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9); - } with m -``` - - - -We can update a map in CameLIGO using the `Map.update` built-in: - -```cameligo - -let updated_map: moveset = Map.update ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) (Some (4,9)) moves -``` - - - -We can update a map in ReasonLIGO using the `Map.update` built-in: - -```reasonligo - -let updated_map: moveset = Map.update(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some((4,9)), moves); -``` - - - -## Map.add(k: a', v: b', m: (a', b') map) : (a', b') map - - - - -```pascaligo -function set_ (var n : int ; var m : map(int, int)) : map(int, int) is block { - m[23] := n ; -} with m -``` - - -```cameligo -let add (n,m: int * (int, int) map) : foobar = Map.add 23 n m -``` - - -```reasonligo -let add = (n: int, m: map(int, int)) : foobar => Map.add(23, n, m); -``` - - - -## Map.remove(k: a', m: (a', b') map) : (a', b') map - -Remove a key and its associated value from the map. - - - - -```pascaligo -function rm (var m : map(int, int)) : map(int, int) is block { - remove 42 from map m -} with m -``` - - -```cameligo -let rm (m: (int, int) map) : (int, int) map = Map.remove 42 m -``` - - -```reasonligo -let rm = (m: map(int, int)): map(int, int) => Map.remove(42, m); -``` - - - -## Map.iter(iterator_function: (a', b') -> unit, m: (a', b') map) : unit - -Run a function returning unit over the contents of a map's key-value pairs. -For example an assertion. - - - -```pascaligo -function iter_op (const m : moveset) : unit is - block { - function aggregate (const i : address ; const j : move) : unit is block - { if j.1 > 1 then skip else failwith("fail") } with unit - } with map_iter(aggregate, m); -``` - - -```cameligo -let iter_op (m : moveset) : unit = - let assert_eq = fun (i,j: address * move) -> assert (j.0 > 1) - in Map.iter assert_eq m -``` - - -```reasonligo -let iter_op = (m: moveset): unit => { - let assert_eq = ((i,j): (address, move)) => assert (j[0] > 1); - Map.iter(assert_eq, m); -}; -``` - - - -## Map.map(mapping_function: (a', b') -> b', m: (a', b') map) : (a', b') map - -Update the values associated with every key in the map according to some update -rule `mapping_function`. - - - -```pascaligo -function map_op (const m : moveset) : moveset is - block { - function increment (const i : address ; const j : move) : move is (j.0, j.1 + 1); - } with map_map (increment, m); -``` - - -```cameligo -let map_op (m : moveset) : moveset = - let increment = fun (i,j: address * move) -> (j.0, j.1 + 1) - in Map.map increment m -``` - - -```reasonligo -let map_op = (m: moveset): moveset => { - let increment = ((i,j): (address, move)) => (j[0], j[1] + 1); - Map.map(increment, m); -}; -``` - - -## Map.fold(folding_function: (b', (a', b')) -> b', m: (a', b') map, initial: b') : b' - -Combine every value in the map together according to a fold rule `folding_function`. - - - -```pascaligo -function fold_op (const m : moveset) : int is - block { - function aggregate (const j : int; const cur : address * (int * int)) : int is j + cur.1.1 - } with map_fold(aggregate, m, 5) -``` - - -```cameligo -let fold_op (m : moveset) : moveset = - let aggregate = fun (i,j: int * (address * (int * int))) -> i + j.1.1 - in Map.fold aggregate m 5 -``` - - -```reasonligo -let fold_op = (m: moveset): moveset => { - let aggregate = ((i,j): (int, (address, (int,int)))) => i + j[1][1]; - Map.fold(aggregate, m, 5); -}; - -``` - - - - -## Map.mem(k: a', m: (a', b') map) : bool - -Test whether a particular key `k` exists in a given map `m`. - - - - -```pascaligo -function mem (const k: int; const m: map(int, int)) : bool is map_mem(k, m) -``` - -```cameligo -let mem (k,m: int * (int, int) map) : bool = Map.mem k m -``` - - -```reasonligo -let mem = ((k,m): (int, map(int,int))): bool => Map.mem(k, m); -``` - - - -## Map.empty() : (a', b') map +## Creating an Empty Map Create an empty map. -```pascaligo -const empty_map : map(int, int) = map end +```pascaligo group=map +const empty : register = map [] ``` + -```cameligo -let empty_map : (int, int) map = Map.empty +```cameligo group=map +let empty : register = Map.empty ``` -```reasonligo -let empty_map: map(int, int) = Map.empty; +```reasonligo group=map +let empty : register = Map.empty ``` -## Map.literal(key_value_pair_list: (a', b') list) : (a', b') map +## Populating A Map -Constructs a map from a list of key-value pair tuples. + + + +```pascaligo group=map +const moves: register = + map [ + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2); + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] +``` + + + +```cameligo group=map +let moves: register = + Map.literal [ + (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2)); + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))] +``` + + + +```reasonligo group=map +let moves: register = + Map.literal ([ + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]); +``` + + + +## Retrieving a Value in a Map + +Retrieve the value associated with a particular key. This version +returns an option which can either shift logic in response to a +missing value or throw an error. + + + +```pascaligo group=map +const my_balance : option (move) = + moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] +``` + + + +The function is `Map.find_opt` whose type is `'key -> +('key,'value) map) -> 'value option`. Recall that the function +`Map.find_opt` must always be fully applied to its arguments. Here +is an example: + +```cameligo group=map +let my_balance : move option = + Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves +``` + + + +The function is `Map.find_opt` whose type is `('key, ('key, +'value) map) : 'value option`. Here is an example: + +```reasonligo group=map +let my_balance : option (move) = + Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves); +``` + + +## Updating a Binding in a Map + +Given a map, we may want to add a new binding, remove one, or modify +one by changing the value associated to an already existing key. We +may even want to retain the key but not the associated value. All +those operations are called *updates*. -```pascaligo -const moves: moveset = map - ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) -> (1, 2); - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) -> (0, 3); -end +The values of a PascaLIGO map can be updated using the ordinary +assignment syntax: + +```pascaligo group=map +function add (var m : register) : register is + block { + m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) + } with m + +const updated_map : register = add (moves) +``` + +See further for the removal of bindings. + + + +In CameLIGO, you need the predefined function `Map.update` whose +type is `'key -> 'value option -> ('key, 'value) map -> ('key, +'value) map`. If the value (second argument) is `None`, then the +binding is to be removed. Recall that the function `Map.update` +must always be fully applied to its arguments. Here is an example: + +```cameligo group=map +let updated_map : register = + Map.update + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves +``` + + + +In ReasonLIGO, you need the predefined function `Map.update` whose +type is `('key, 'value option, ('key, 'value) map) : ('key, +'value) map`. If the value (second componenat) is `None`, then the +binding is to be removed. Here is an example: + +```reasonligo group=map +let updated_map : register = + Map.update + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves); +``` + + + +## Adding a Binding to a Map + +Add a key and its associated value to the map. + + + +```pascaligo group=map +function add (var m : register) : register is + block { + m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) + } with m + +const updated_map : register = add (moves) ``` -```cameligo -let moves: moveset = Map.literal - [ (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address), (1, 2)) ; - (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), (0, 3)) ; - ] +In CameLIGO, we use the predefined function `Map.add`, whose type +is `'key -> 'value -> ('key, 'value) map -> ('key, 'value) +map`. Recall that the function `Map.add` must always be fully +applied to its arguments. Here is an example: + +```cameligo group=map +let add (m : register) : register = + Map.add + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m ``` -```reasonligo -let moves : moveset = - Map.literal([ - ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address, (1, 2)), - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, (0, 3)), - ]); +In ReasonLIGO, we use the predefined function `Map.add`, whose +type is `('key, 'value, ('key, 'value) map : ('key, 'value) +map`. Here is an example: + +```reasonligo group=map +let add = (m : register) : register => + Map.add + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m); ``` + -## Map.size(m: (a', b') map) : nat +## Removing a Binding from a Map -Get the size of a given map `m`. +Remove a key and its associated value from the map. -```pascaligo -function size_ (const m : map(int, int)) : nat is - block {skip} with (size(m)) +```pascaligo group=map +function delete (const key : address; var moves : register) : register is + block { + remove key from map moves + } with moves ``` + -```cameligo -let size_ (m: (int, int) map) : nat = Map.size m + +In CameLIGO, we use the predefined function `Map.remove` whose +type is `'key -> ('key, 'value) map -> ('key, 'value) +map`. Note that, despite being curried, the calls to that function +must be complete. Here is an example: + +```cameligo group=map +let delete (key, moves : address * register) : register = + Map.remove key moves ``` + -```reasonligo -let size_ = (m: map(int, int)): nat => Map.size(m); + +In ReasonLIGO, we use the predefined function `Map.remove` whose +type is `('key, ('key, 'value) map) : ('key, 'value) +map`. Here is an example: + +```reasonligo group=map +let delete = ((key, moves) : (address, register)) : register => + Map.remove (key, moves); +``` + + + +## Getting the Size of a Map + +The size of a map is its number of bindings. + + + + +```pascaligo group=map +function size_of (const m : register) : nat is size (m) +``` + +```cameligo group=map +let size_of (m : register) : nat = Map.size m +``` + +```reasonligo group=map +let size_of = (m : register): nat => Map.size (m); ``` diff --git a/gitlab-pages/examples/counter.ligo b/gitlab-pages/examples/counter.ligo deleted file mode 100644 index 45ce7462a..000000000 --- a/gitlab-pages/examples/counter.ligo +++ /dev/null @@ -1,10 +0,0 @@ -type action is -| Increment of int -| Decrement of int - -function main (const p : action ; const s : int) : (list(operation) * int) is - block {skip} with ((nil : list(operation)), - case p of - | Increment n -> s + n - | Decrement n -> s - n - end) diff --git a/gitlab-pages/examples/functions.ligo b/gitlab-pages/examples/functions.ligo deleted file mode 100644 index 4f8e4dae1..000000000 --- a/gitlab-pages/examples/functions.ligo +++ /dev/null @@ -1,10 +0,0 @@ -function multiply (const a : int ; const b : int) : int is - begin - const result : int = a * b ; - end with result - -function add (const a : int ; const b : int) : int is - block { skip } with a + b - -function main (const p : unit ; const s : unit) : (list(operation) * unit) is - block {skip} with ((nil : list(operation)), s) \ No newline at end of file diff --git a/gitlab-pages/examples/multiple-entrypoints.ligo b/gitlab-pages/examples/multiple-entrypoints.ligo deleted file mode 100644 index 3b77ff009..000000000 --- a/gitlab-pages/examples/multiple-entrypoints.ligo +++ /dev/null @@ -1,16 +0,0 @@ -type action is -| Increment of int -| Decrement of int - -function add (const a : int ; const b : int) : int is - block { skip } with a + b - -function subtract (const a : int ; const b : int) : int is - block { skip } with a - b - -function main (const p : action ; const s : int) : (list(operation) * int) is - block {skip} with ((nil : list(operation)), - case p of - | Increment n -> add(s, n) - | Decrement n -> subtract(s, n) - end) diff --git a/gitlab-pages/examples/variables.ligo b/gitlab-pages/examples/variables.ligo deleted file mode 100644 index 09254da96..000000000 --- a/gitlab-pages/examples/variables.ligo +++ /dev/null @@ -1,5 +0,0 @@ -const four : int = 4; -const name : string = "John Doe"; - -function main (const p : unit ; const s : unit) : (list(operation) * unit) is - block {skip} with ((nil : list(operation)), s) \ No newline at end of file diff --git a/src/passes/1-parser/cameligo/.links b/src/passes/1-parser/cameligo/.links index 6f2bb3b81..a3ac060f6 100644 --- a/src/passes/1-parser/cameligo/.links +++ b/src/passes/1-parser/cameligo/.links @@ -20,3 +20,4 @@ $HOME/git/ligo/vendors/ligo-utils/simple-utils/region.ml ../shared/LexerUnit.ml ../shared/ParserUnit.ml Stubs/Simple_utils.ml +$HOME/git/ligo/_build/default/src/passes/1-parser/cameligo/ParErr.ml \ No newline at end of file diff --git a/src/passes/1-parser/cameligo/LexToken.mll b/src/passes/1-parser/cameligo/LexToken.mll index d16388591..f17ea903a 100644 --- a/src/passes/1-parser/cameligo/LexToken.mll +++ b/src/passes/1-parser/cameligo/LexToken.mll @@ -266,7 +266,6 @@ let keywords = [ let reserved = let open SSet in empty - |> add "and" |> add "as" |> add "asr" |> add "class" diff --git a/src/passes/1-parser/cameligo/LexerMain.ml b/src/passes/1-parser/cameligo/LexerMain.ml index 5ef471c37..60874bda0 100644 --- a/src/passes/1-parser/cameligo/LexerMain.ml +++ b/src/passes/1-parser/cameligo/LexerMain.ml @@ -1,5 +1,7 @@ (* Driver for the CameLIGO lexer *) +module Region = Simple_utils.Region + module IO = struct let ext = ".mligo" diff --git a/src/passes/1-parser/cameligo/Parser.mly b/src/passes/1-parser/cameligo/Parser.mly index 0901ab875..c8c0470a8 100644 --- a/src/passes/1-parser/cameligo/Parser.mly +++ b/src/passes/1-parser/cameligo/Parser.mly @@ -593,10 +593,14 @@ core_expr: | par(expr ":" type_expr {$1,$2,$3}) { EAnnot $1 } module_field: - module_name "." field_name { + module_name "." module_fun { let region = cover $1.region $3.region in {region; value = $1.value ^ "." ^ $3.value} } +module_fun: + field_name { $1 } +| "or" { {value="or"; region=$1} } + projection: struct_name "." nsepseq(selection,".") { let start = $1.region in diff --git a/src/passes/1-parser/pascaligo/.links b/src/passes/1-parser/pascaligo/.links index 831099d9e..70b9b360f 100644 --- a/src/passes/1-parser/pascaligo/.links +++ b/src/passes/1-parser/pascaligo/.links @@ -24,3 +24,4 @@ $HOME/git/ligo/vendors/ligo-utils/simple-utils/region.ml ../shared/Memo.mli ../shared/Memo.ml Stubs/Simple_utils.ml +$HOME/git/ligo/_build/default/src/passes/1-parser/pascaligo/ParErr.ml \ No newline at end of file diff --git a/src/passes/1-parser/pascaligo/Parser.mly b/src/passes/1-parser/pascaligo/Parser.mly index e5afdc3b5..f31407fca 100644 --- a/src/passes/1-parser/pascaligo/Parser.mly +++ b/src/passes/1-parser/pascaligo/Parser.mly @@ -98,11 +98,12 @@ sepseq(X,Sep): (* Inlines *) -%inline var : "" { $1 } -%inline type_name : "" { $1 } -%inline fun_name : "" { $1 } -%inline field_name : "" { $1 } -%inline struct_name : "" { $1 } +%inline var : "" { $1 } +%inline type_name : "" { $1 } +%inline fun_name : "" { $1 } +%inline field_name : "" { $1 } +%inline struct_name : "" { $1 } +%inline module_name : "" { $1 } (* Main *) @@ -829,7 +830,7 @@ core_expr: "" { EArith (Int $1) } | "" { EArith (Nat $1) } | "" { EArith (Mutez $1) } -| var { EVar $1 } +| "" | module_field { EVar $1 } | "" { EString (String $1) } | "" { EBytes $1 } | "False" { ELogic (BoolExpr (False $1)) } @@ -902,13 +903,32 @@ path: var { Name $1 } | projection { Path $1 } +module_field: + module_name "." module_fun { + let region = cover $1.region $3.region in + {region; value = $1.value ^ "." ^ $3.value} } + +module_fun: + field_name { $1 } +| "map" { {value="map"; region=$1} } +| "or" { {value="or"; region=$1} } +| "and" { {value="and"; region=$1} } +| "remove" { {value="remove"; region=$1} } + projection: struct_name "." nsepseq(selection,".") { let stop = nsepseq_to_region selection_to_region $3 in let region = cover $1.region stop - and value = {struct_name = $1; - selector = $2; - field_path = $3} + and value = {struct_name=$1; selector=$2; field_path=$3} + in {region; value} + } +| module_name "." field_name "." nsepseq(selection,".") { + let value = $1.value ^ "." ^ $3.value in + let struct_name = {$1 with value} in + let start = $1.region in + let stop = nsepseq_to_region selection_to_region $5 in + let region = cover start stop in + let value = {struct_name; selector=$4; field_path=$5} in {region; value} } selection: @@ -939,31 +959,26 @@ record_expr: update_record: path "with" ne_injection("record",field_path_assignment){ let region = cover (path_to_region $1) $3.region in - let value = { - record = $1; - kwd_with = $2; - updates = $3} + let value = {record=$1; kwd_with=$2; updates=$3} in {region; value} } - field_assignment: field_name "=" expr { let region = cover $1.region (expr_to_region $3) - and value = {field_name = $1; - equal = $2; - field_expr = $3} + and value = {field_name=$1; equal=$2; field_expr=$3} in {region; value} } field_path_assignment: nsepseq(field_name,".") "=" expr { - let region = cover (nsepseq_to_region (fun x -> x.region) $1) (expr_to_region $3) - and value = {field_path = $1; - equal = $2; - field_expr = $3} + let start = nsepseq_to_region (fun x -> x.region) $1 + and stop = expr_to_region $3 in + let region = cover start stop + and value = {field_path=$1; equal=$2; field_expr=$3} in {region; value} } fun_call: - fun_name arguments { + fun_name arguments +| module_field arguments { let region = cover $1.region $2.region in {region; value = (EVar $1),$2} } diff --git a/src/passes/1-parser/reasonligo/.links b/src/passes/1-parser/reasonligo/.links index 543bf9ea3..d93e4b610 100644 --- a/src/passes/1-parser/reasonligo/.links +++ b/src/passes/1-parser/reasonligo/.links @@ -25,4 +25,5 @@ Stubs/Parser_cameligo.ml ../cameligo/ParserLog.mli ../cameligo/ParserLog.ml ../cameligo/Scoping.mli -../cameligo/Scoping.ml \ No newline at end of file +../cameligo/Scoping.ml +$HOME/git/ligo/_build/default/src/passes/1-parser/reasonligo/ParErr.ml \ No newline at end of file diff --git a/src/passes/1-parser/reasonligo/LexToken.mll b/src/passes/1-parser/reasonligo/LexToken.mll index e4689082a..842c0fee1 100644 --- a/src/passes/1-parser/reasonligo/LexToken.mll +++ b/src/passes/1-parser/reasonligo/LexToken.mll @@ -238,12 +238,9 @@ let keywords = [ (fun reg -> True reg); (fun reg -> Type reg)] -(* See: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec86 and - https://github.com/facebook/reason/blob/master/src/reason-parser/reason_parser.mly *) let reserved = let open SSet in empty - |> add "and" |> add "as" |> add "asr" |> add "begin" diff --git a/src/passes/1-parser/reasonligo/LexerMain.ml b/src/passes/1-parser/reasonligo/LexerMain.ml index f0589990c..7e8e063da 100644 --- a/src/passes/1-parser/reasonligo/LexerMain.ml +++ b/src/passes/1-parser/reasonligo/LexerMain.ml @@ -1,5 +1,7 @@ (* Driver for the ReasonLIGO lexer *) +module Region = Simple_utils.Region + module IO = struct let ext = ".religo" diff --git a/src/passes/1-parser/reasonligo/Parser.mly b/src/passes/1-parser/reasonligo/Parser.mly index 48765c19a..defde2e55 100644 --- a/src/passes/1-parser/reasonligo/Parser.mly +++ b/src/passes/1-parser/reasonligo/Parser.mly @@ -24,22 +24,22 @@ type 'a sequence_or_record = let (<@) f g x = f (g x) -(** - Covert nsepseq to a chain of TFun's. - +(** + Covert nsepseq to a chain of TFun's. + Necessary to handle cases like: `type foo = (int, int) => int;` *) -let rec nsepseq_to_curry hd rest = - match hd, rest with - | hd, (sep, item) :: rest -> +let rec nsepseq_to_curry hd rest = + match hd, rest with + | hd, (sep, item) :: rest -> let start = type_expr_to_region hd in let stop = nsepseq_to_region type_expr_to_region (hd, rest) in - let region = cover start stop in + let region = cover start stop in TFun { - value = hd, sep, (nsepseq_to_curry item rest); + value = hd, sep, (nsepseq_to_curry item rest); region - } + } | hd, [] -> hd (* END HEADER *) @@ -178,34 +178,34 @@ type_expr: cartesian | sum_type | record_type { $1 } type_expr_func: - "=>" cartesian { + "=>" cartesian { $1, $2 } cartesian: core_type { $1 } -| type_name type_expr_func { +| type_name type_expr_func { let (arrow, c) = $2 in let value = TVar $1, arrow, c in let region = cover $1.region (type_expr_to_region c) in TFun { region; value } } -| "(" cartesian ")" type_expr_func { +| "(" cartesian ")" type_expr_func { let (arrow, c) = $4 in let value = $2, arrow, c in let region = cover $1 (type_expr_to_region c) in TFun { region; value } } | "(" cartesian "," nsepseq(cartesian,",") ")" type_expr_func? { - match $6 with - | Some (arrow, c) -> + match $6 with + | Some (arrow, c) -> let (hd, rest) = Utils.nsepseq_cons $2 $3 $4 in - let rest = rest @ [(arrow, c)] in + let rest = rest @ [(arrow, c)] in nsepseq_to_curry hd rest | None -> let value = Utils.nsepseq_cons $2 $3 $4 in let region = cover $1 $5 in - TProd {region; value} + TProd {region; value} } core_type: @@ -515,30 +515,30 @@ fun_expr: _ }; _ }; region} -> - let expr_to_type = function + let expr_to_type = function | EVar v -> TVar v | e -> let open! SyntaxError in raise (Error (WrongFunctionArguments e)) in let type_expr = ( match type_expr with - | TProd {value; _} -> + | TProd {value; _} -> let (hd, rest) = value in - let rest = rest @ [(arrow, expr_to_type body)] in - nsepseq_to_curry hd rest - | e -> + let rest = rest @ [(arrow, expr_to_type body)] in + nsepseq_to_curry hd rest + | e -> TFun { value = e, arrow, expr_to_type body; region = fun_region - } + } ) - in + in PTyped { value = { pattern; colon; type_expr - }; + }; region; }, [] | EPar {value = {inside = fun_arg; _ }; _} -> @@ -552,7 +552,7 @@ fun_expr: arg_to_pattern (fst fun_args), bindings | EUnit _ as e -> arg_to_pattern e, [] - | EVar _ as e -> + | EVar _ as e -> arg_to_pattern e, [] | e -> let open! SyntaxError in raise (Error (WrongFunctionArguments e)) @@ -834,10 +834,13 @@ core_expr: | par(expr) { EPar $1 } module_field: - module_name "." field_name { - let region = cover $1.region $3.region - and value = $1.value ^ "." ^ $3.value - in {region; value} } + module_name "." module_fun { + let region = cover $1.region $3.region in + {region; value = $1.value ^ "." ^ $3.value} } + +module_fun: + field_name { $1 } +| "or" { {value="or"; region=$1} } selection: "[" "" "]" selection { diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 456c0172a..07a1484c6 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -35,8 +35,8 @@ module Simplify = struct let unit_expr = make_t @@ T_constant TC_unit let type_constants s = - match s with - | "chain_id" -> ok TC_chain_id + match s with + "chain_id" -> ok TC_chain_id | "unit" -> ok TC_unit | "string" -> ok TC_string | "bytes" -> ok TC_bytes @@ -50,95 +50,196 @@ module Simplify = struct | "key_hash" -> ok TC_key_hash | "signature" -> ok TC_signature | "timestamp" -> ok TC_timestamp - | _ -> simple_fail @@ "Not a type_constant " ^ s + | _ -> simple_fail @@ "Not a built-in type (" ^ s ^ ")." let type_operators s = - match s with - | "list" -> ok @@ TC_list unit_expr + match s with + "list" -> ok @@ TC_list unit_expr | "option" -> ok @@ TC_option unit_expr | "set" -> ok @@ TC_set unit_expr | "map" -> ok @@ TC_map (unit_expr,unit_expr) | "big_map" -> ok @@ TC_big_map (unit_expr,unit_expr) | "contract" -> ok @@ TC_contract unit_expr - | _ -> simple_fail @@ "Not a typ_operator " ^ s + | _ -> simple_fail @@ "Not a built-in type (" ^ s ^ ")." module Pascaligo = struct - let constants = function - | "assert" -> ok C_ASSERTION - | "get_chain_id" -> ok C_CHAIN_ID - | "transaction" -> ok C_CALL - | "get_contract" -> ok C_CONTRACT - | "get_contract_opt"-> ok C_CONTRACT_OPT - | "get_entrypoint" -> ok C_CONTRACT_ENTRYPOINT - | "get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT - | "size" -> ok C_SIZE - | "int" -> ok C_INT - | "abs" -> ok C_ABS - | "is_nat" -> ok C_IS_NAT - | "amount" -> ok C_AMOUNT - | "balance" -> ok C_BALANCE - | "now" -> ok C_NOW - | "unit" -> ok C_UNIT - | "source" -> ok C_SOURCE - | "sender" -> ok C_SENDER - | "failwith" -> ok C_FAILWITH - | "bitwise_or" -> ok C_OR - | "bitwise_and" -> ok C_AND - | "bitwise_xor" -> ok C_XOR - | "bitwise_lsl" -> ok C_LSL - | "bitwise_lsr" -> ok C_LSR - | "string_concat" -> ok C_CONCAT - | "string_slice" -> ok C_SLICE - | "crypto_check" -> ok C_CHECK_SIGNATURE - | "crypto_hash_key" -> ok C_HASH_KEY - | "bytes_concat" -> ok C_CONCAT - | "bytes_slice" -> ok C_SLICE - | "bytes_pack" -> ok C_BYTES_PACK - | "bytes_unpack" -> ok C_BYTES_UNPACK - | "set_empty" -> ok C_SET_EMPTY - | "set_mem" -> ok C_SET_MEM - | "set_add" -> ok C_SET_ADD - | "set_remove" -> ok C_SET_REMOVE - | "set_iter" -> ok C_SET_ITER - | "set_fold" -> ok C_SET_FOLD - | "list_iter" -> ok C_LIST_ITER - | "list_fold" -> ok C_LIST_FOLD - | "list_map" -> ok C_LIST_MAP - | "get_force" -> ok C_MAP_FIND - | "map_iter" -> ok C_MAP_ITER - | "map_map" -> ok C_MAP_MAP - | "map_fold" -> ok C_MAP_FOLD - | "map_remove" -> ok C_MAP_REMOVE - | "map_update" -> ok C_MAP_UPDATE - | "map_get" -> ok C_MAP_FIND_OPT - | "map_mem" -> ok C_MAP_MEM - | "sha_256" -> ok C_SHA256 - | "sha_512" -> ok C_SHA512 - | "blake2b" -> ok C_BLAKE2b - | "cons" -> ok C_CONS - | "EQ" -> ok C_EQ - | "NEQ" -> ok C_NEQ - | "NEG" -> ok C_NEG - | "ADD" -> ok C_ADD - | "SUB" -> ok C_SUB - | "TIMES" -> ok C_MUL - | "DIV" -> ok C_DIV - | "MOD" -> ok C_MOD - | "NOT" -> ok C_NOT - | "AND" -> ok C_AND - | "OR" -> ok C_OR - | "GT" -> ok C_GT - | "GE" -> ok C_GE - | "LT" -> ok C_LT - | "LE" -> ok C_LE - | "CONS" -> ok C_CONS - | "address" -> ok C_ADDRESS - | "self_address" -> ok C_SELF_ADDRESS - | "implicit_account"-> ok C_IMPLICIT_ACCOUNT - | "set_delegate" -> ok C_SET_DELEGATE - | _ -> simple_fail "Not a PascaLIGO constant" + (* Tezos module (ex-Michelson) *) + + | "Tezos.chain_id" -> ok C_CHAIN_ID + | "chain_id" -> ok C_CHAIN_ID (* Deprecated *) + | "get_chain_id" -> ok C_CHAIN_ID (* Deprecated *) + | "Tezos.balance" -> ok C_BALANCE + | "balance" -> ok C_BALANCE (* Deprecated *) + | "Tezos.now" -> ok C_NOW + | "now" -> ok C_NOW (* Deprecated *) + | "Tezos.amount" -> ok C_AMOUNT + | "amount" -> ok C_AMOUNT (* Deprecated *) + | "Tezos.sender" -> ok C_SENDER + | "sender" -> ok C_SENDER (* Deprecated *) + | "Tezos.address" -> ok C_ADDRESS + | "address" -> ok C_ADDRESS (* Deprecated *) + | "Tezos.self_address" -> ok C_SELF_ADDRESS + | "self_address" -> ok C_SELF_ADDRESS (* Deprecated *) + | "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT + | "implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *) + | "Tezos.source" -> ok C_SOURCE + | "source" -> ok C_SOURCE (* Deprecated *) + | "Tezos.failwith" -> ok C_FAILWITH + | "failwith" -> ok C_FAILWITH + + | "Tezos.transaction" -> ok C_CALL + | "transaction" -> ok C_CALL (* Deprecated *) + | "Tezos.set_delegate" -> ok C_SET_DELEGATE + | "set_delegate" -> ok C_SET_DELEGATE (* Deprecated *) + | "get_contract" -> ok C_CONTRACT (* Deprecated *) + | "Tezos.get_contract_opt" -> ok C_CONTRACT_OPT + | "get_contract_opt" -> ok C_CONTRACT_OPT (* Deprecated *) + | "get_entrypoint" -> ok C_CONTRACT_ENTRYPOINT (* Deprecated *) + | "Tezos.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT + | "get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT (* Deprecated *) + + | "Michelson.is_nat" -> ok C_IS_NAT (* Deprecated *) + | "is_nat" -> ok C_IS_NAT + | "int" -> ok C_INT + | "abs" -> ok C_ABS + | "unit" -> ok C_UNIT + + | "NEG" -> ok C_NEG + | "ADD" -> ok C_ADD + | "SUB" -> ok C_SUB + | "TIMES" -> ok C_MUL + | "DIV" -> ok C_DIV + | "MOD" -> ok C_MOD + | "EQ" -> ok C_EQ + | "NOT" -> ok C_NOT + | "AND" -> ok C_AND + | "OR" -> ok C_OR + | "GT" -> ok C_GT + | "GE" -> ok C_GE + | "LT" -> ok C_LT + | "LE" -> ok C_LE + | "CONS" -> ok C_CONS + | "cons" -> ok C_CONS (* Deprecated *) + | "NEQ" -> ok C_NEQ + + (* Crypto module *) + + | "Crypto.check" -> ok C_CHECK_SIGNATURE + | "crypto_check" -> ok C_CHECK_SIGNATURE (* Deprecated *) + | "Crypto.hash_key" -> ok C_HASH_KEY + | "crypto_hash_key" -> ok C_HASH_KEY (* Deprecated *) + | "Crypto.blake2b" -> ok C_BLAKE2b + | "blake2b" -> ok C_BLAKE2b (* Deprecated *) + | "Crypto.sha256" -> ok C_SHA256 + | "sha_256" -> ok C_SHA256 (* Deprecated *) + | "Crypto.sha512" -> ok C_SHA512 + | "sha_512" -> ok C_SHA512 (* Deprecated *) + + (* Bytes module *) + + | "Bytes.pack" -> ok C_BYTES_PACK + | "bytes_pack" -> ok C_BYTES_PACK (* Deprecated *) + | "Bytes.unpack" -> ok C_BYTES_UNPACK + | "bytes_unpack" -> ok C_BYTES_UNPACK (* Deprecated *) + | "Bytes.length" -> ok C_SIZE + | "Bytes.size" -> ok C_SIZE + | "bytes_concat" -> ok C_CONCAT (* Deprecated *) + | "Bytes.concat" -> ok C_CONCAT + | "Bytes.slice" -> ok C_SLICE + | "bytes_slice" -> ok C_SLICE (* Deprecated *) + | "Bytes.sub" -> ok C_SLICE + + (* List module *) + + | "List.length" -> ok C_SIZE + | "List.size" -> ok C_SIZE + | "list_size" -> ok C_SIZE (* Deprecated *) + | "List.iter" -> ok C_LIST_ITER + | "list_iter" -> ok C_LIST_ITER (* Deprecated *) + | "List.map" -> ok C_LIST_MAP + | "list_map" -> ok C_LIST_MAP (* Deprecated *) + | "List.fold" -> ok C_LIST_FOLD + | "list_fold" -> ok C_LIST_FOLD (* Deprecated *) + + (* Set module *) + + | "Set.size" -> ok C_SIZE + | "set_size" -> ok C_SIZE (* Deprecated *) + | "set_empty" -> ok C_SET_EMPTY (* Deprecated *) + | "Set.mem" -> ok C_SET_MEM + | "set_mem" -> ok C_SET_MEM (* Deprecated *) + | "Set.add" -> ok C_SET_ADD + | "set_add" -> ok C_SET_ADD (* Deprecated *) + | "Set.remove" -> ok C_SET_REMOVE + | "set_remove" -> ok C_SET_REMOVE (* Deprecated *) + | "Set.iter" -> ok C_SET_ITER + | "set_iter" -> ok C_SET_ITER (* Deprecated *) + | "Set.fold" -> ok C_SET_FOLD + | "set_fold" -> ok C_SET_FOLD (* Deprecated *) + + (* Map module *) + + | "get_force" -> ok C_MAP_FIND (* Deprecated *) + | "map_get" -> ok C_MAP_FIND_OPT (* Deprecated *) + | "Map.find_opt" -> ok C_MAP_FIND_OPT + | "Map.update" -> ok C_MAP_UPDATE + | "map_update" -> ok C_MAP_UPDATE (* Deprecated *) + | "map_remove" -> ok C_MAP_REMOVE (* Deprecated *) + | "Map.iter" -> ok C_MAP_ITER + | "map_iter" -> ok C_MAP_ITER (* Deprecated *) + | "Map.map" -> ok C_MAP_MAP + | "map_map" -> ok C_MAP_MAP (* Deprecated *) + | "Map.fold" -> ok C_MAP_FOLD + | "map_fold" -> ok C_MAP_FOLD (* Deprecated *) + | "Map.mem" -> ok C_MAP_MEM + | "map_mem" -> ok C_MAP_MEM (* Deprecated *) + | "Map.size" -> ok C_SIZE + | "map_size" -> ok C_SIZE (* Deprecated *) + + (* Big_map module *) + + | "Big_map.find_opt" -> ok C_MAP_FIND_OPT + | "Big_map.update" -> ok C_MAP_UPDATE + | "Big_map.literal" -> ok C_BIG_MAP_LITERAL + | "Big_map.empty" -> ok C_BIG_MAP_EMPTY + | "Big_map.size" -> ok C_SIZE + | "Big_map.mem" -> ok C_MAP_MEM + | "Big_map.iter" -> ok C_MAP_ITER + | "Big_map.map" -> ok C_MAP_MAP + | "Big_map.fold" -> ok C_MAP_FOLD + | "Big_map.remove" -> ok C_MAP_REMOVE + + (* Bitwise module *) + + | "Bitwise.or" -> ok C_OR + | "bitwise_or" -> ok C_OR (* Deprecated *) + | "Bitwise.and" -> ok C_AND + | "bitwise_and" -> ok C_AND (* Deprecated *) + | "Bitwise.xor" -> ok C_XOR + | "bitwise_xor" -> ok C_XOR (* Deprecated *) + | "Bitwise.shift_left" -> ok C_LSL + | "bitwise_lsl" -> ok C_LSL (* Deprecated *) + | "Bitwise.shift_right" -> ok C_LSR + | "bitwise_lsr" -> ok C_LSR (* Deprecated *) + + (* String module *) + + | "String.length" -> ok C_SIZE + | "String.size" -> ok C_SIZE + | "String.slice" -> ok C_SLICE + | "string_slice" -> ok C_SLICE (* Deprecated *) + | "String.sub" -> ok C_SLICE + | "String.concat" -> ok C_CONCAT + | "string_concat" -> ok C_CONCAT (* Deprecated *) + + (* Others *) + + | "assert" -> ok C_ASSERTION + | "size" -> ok C_SIZE (* Deprecated *) + + | _ -> simple_fail "Not a PascaLIGO built-in." let type_constants = type_constants let type_operators = type_operators @@ -147,119 +248,163 @@ module Simplify = struct module Cameligo = struct let constants = function - | "assert" -> ok C_ASSERTION - | "chain_id" -> ok C_CHAIN_ID - | "Current.balance" -> ok C_BALANCE - | "balance" -> ok C_BALANCE - | "Current.time" -> ok C_NOW - | "time" -> ok C_NOW - | "Current.amount" -> ok C_AMOUNT - | "amount" -> ok C_AMOUNT - | "Current.sender" -> ok C_SENDER - | "Current.address" -> ok C_ADDRESS - | "Current.self_address" -> ok C_SELF_ADDRESS - | "Current.implicit_account" -> ok C_IMPLICIT_ACCOUNT - | "sender" -> ok C_SENDER - | "Current.source" -> ok C_SOURCE - | "source" -> ok C_SOURCE - | "Current.failwith" -> ok C_FAILWITH - | "failwith" -> ok C_FAILWITH + (* Tezos (ex-Michelson, ex-Current, ex-Operation) *) - | "Crypto.blake2b" -> ok C_BLAKE2b - | "Crypto.sha256" -> ok C_SHA256 - | "Crypto.sha512" -> ok C_SHA512 - | "Crypto.hash_key" -> ok C_HASH_KEY - | "Crypto.check" -> ok C_CHECK_SIGNATURE + | "Tezos.chain_id" -> ok C_CHAIN_ID + | "chain_id" -> ok C_CHAIN_ID (* Deprecated *) + | "Tezos.balance" -> ok C_BALANCE + | "Current.balance" -> ok C_BALANCE (* Deprecated *) + | "balance" -> ok C_BALANCE (* Deprecated *) + | "Tezos.now" -> ok C_NOW + | "Current.time" -> ok C_NOW (* Deprecated *) + | "time" -> ok C_NOW (* Deprecated *) + | "Tezos.amount" -> ok C_AMOUNT + | "Current.amount" -> ok C_AMOUNT (* Deprecated *) + | "amount" -> ok C_AMOUNT (* Deprecated *) + | "Tezos.sender" -> ok C_SENDER + | "Current.sender" -> ok C_SENDER (* Deprecated *) + | "sender" -> ok C_SENDER (* Deprecated *) + | "Tezos.address" -> ok C_ADDRESS + | "Current.address" -> ok C_ADDRESS (* Deprecated *) + | "Tezos.self_address" -> ok C_SELF_ADDRESS + | "Current.self_address" -> ok C_SELF_ADDRESS (* Deprecated *) + | "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT + | "Current.implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *) + | "Tezos.source" -> ok C_SOURCE + | "Current.source" -> ok C_SOURCE (* Deprecated *) + | "source" -> ok C_SOURCE (* Deprecated *) + | "Tezos.failwith" -> ok C_FAILWITH + | "Current.failwith" -> ok C_FAILWITH (* Deprecated *) + | "failwith" -> ok C_FAILWITH - | "Bytes.pack" -> ok C_BYTES_PACK - | "Bytes.unpack" -> ok C_BYTES_UNPACK - | "Bytes.length" -> ok C_SIZE - | "Bytes.size" -> ok C_SIZE - | "Bytes.concat" -> ok C_CONCAT - | "Bytes.slice" -> ok C_SLICE - | "Bytes.sub" -> ok C_SLICE + | "Tezos.transaction" -> ok C_CALL + | "Operation.transaction" -> ok C_CALL (* Deprecated *) + | "Tezos.set_delegate" -> ok C_SET_DELEGATE (* Deprecated *) + | "Operation.set_delegate" -> ok C_SET_DELEGATE (* Deprecated *) + | "Operation.get_contract" -> ok C_CONTRACT (* Deprecated *) + | "Tezos.get_contract_opt" -> ok C_CONTRACT_OPT + | "Operation.get_contract_opt" -> ok C_CONTRACT_OPT (* Deprecated *) + | "Operation.get_entrypoint" -> ok C_CONTRACT_ENTRYPOINT (* Deprecated *) + | "Tezos.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT + | "Operation.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT (* Deprecated *) - | "Set.mem" -> ok C_SET_MEM - | "Set.iter" -> ok C_SET_ITER - | "Set.empty" -> ok C_SET_EMPTY - | "Set.literal" -> ok C_SET_LITERAL - | "Set.add" -> ok C_SET_ADD - | "Set.remove" -> ok C_SET_REMOVE - | "Set.fold" -> ok C_SET_FOLD - | "Set.size" -> ok C_SIZE + | "Michelson.is_nat" -> ok C_IS_NAT (* Deprecated *) + | "is_nat" -> ok C_IS_NAT + | "int" -> ok C_INT + | "abs" -> ok C_ABS + | "unit" -> ok C_UNIT - | "Map.find_opt" -> ok C_MAP_FIND_OPT - | "Map.find" -> ok C_MAP_FIND - | "Map.update" -> ok C_MAP_UPDATE - | "Map.add" -> ok C_MAP_ADD - | "Map.remove" -> ok C_MAP_REMOVE - | "Map.iter" -> ok C_MAP_ITER - | "Map.map" -> ok C_MAP_MAP - | "Map.fold" -> ok C_MAP_FOLD - | "Map.mem" -> ok C_MAP_MEM - | "Map.empty" -> ok C_MAP_EMPTY - | "Map.literal" -> ok C_MAP_LITERAL - | "Map.size" -> ok C_SIZE + | "NEG" -> ok C_NEG + | "ADD" -> ok C_ADD + | "SUB" -> ok C_SUB + | "TIMES" -> ok C_MUL + | "DIV" -> ok C_DIV + | "MOD" -> ok C_MOD + | "EQ" -> ok C_EQ + | "NOT" -> ok C_NOT + | "AND" -> ok C_AND + | "OR" -> ok C_OR + | "GT" -> ok C_GT + | "GE" -> ok C_GE + | "LT" -> ok C_LT + | "LE" -> ok C_LE + | "CONS" -> ok C_CONS + | "NEQ" -> ok C_NEQ - | "Big_map.find_opt" -> ok C_MAP_FIND_OPT - | "Big_map.find" -> ok C_MAP_FIND - | "Big_map.update" -> ok C_MAP_UPDATE - | "Big_map.add" -> ok C_MAP_ADD - | "Big_map.remove" -> ok C_MAP_REMOVE - | "Big_map.literal" -> ok C_BIG_MAP_LITERAL - | "Big_map.empty" -> ok C_BIG_MAP_EMPTY + (* Crypto module *) - | "Bitwise.lor" -> ok C_OR - | "Bitwise.land" -> ok C_AND - | "Bitwise.lxor" -> ok C_XOR - | "Bitwise.shift_left" -> ok C_LSL - | "Bitwise.shift_right" -> ok C_LSR + | "Crypto.check" -> ok C_CHECK_SIGNATURE + | "Crypto.hash_key" -> ok C_HASH_KEY + | "Crypto.blake2b" -> ok C_BLAKE2b + | "Crypto.sha256" -> ok C_SHA256 + | "Crypto.sha512" -> ok C_SHA512 - | "String.length" -> ok C_SIZE - | "String.size" -> ok C_SIZE - | "String.slice" -> ok C_SLICE - | "String.sub" -> ok C_SLICE - | "String.concat" -> ok C_CONCAT + (* Bytes module *) - | "List.length" -> ok C_SIZE - | "List.size" -> ok C_SIZE - | "List.iter" -> ok C_LIST_ITER - | "List.map" -> ok C_LIST_MAP - | "List.fold" -> ok C_LIST_FOLD + | "Bytes.pack" -> ok C_BYTES_PACK + | "Bytes.unpack" -> ok C_BYTES_UNPACK + | "Bytes.length" -> ok C_SIZE + | "Bytes.size" -> ok C_SIZE + | "Bytes.concat" -> ok C_CONCAT + | "Bytes.slice" -> ok C_SLICE + | "Bytes.sub" -> ok C_SLICE - | "Loop.fold_while" -> ok C_FOLD_WHILE - | "continue" -> ok C_CONTINUE - | "stop" -> ok C_STOP + (* List module *) - | "Operation.transaction" -> ok C_CALL - | "Operation.set_delegate" -> ok C_SET_DELEGATE - | "Operation.get_contract" -> ok C_CONTRACT - | "Operation.get_contract_opt" -> ok C_CONTRACT_OPT - | "Operation.get_entrypoint" -> ok C_CONTRACT_ENTRYPOINT - | "Operation.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT - | "int" -> ok C_INT - | "abs" -> ok C_ABS - | "unit" -> ok C_UNIT + | "List.length" -> ok C_SIZE + | "List.size" -> ok C_SIZE + | "List.iter" -> ok C_LIST_ITER + | "List.map" -> ok C_LIST_MAP + | "List.fold" -> ok C_LIST_FOLD - | "NEG" -> ok C_NEG - | "ADD" -> ok C_ADD - | "SUB" -> ok C_SUB - | "TIMES" -> ok C_MUL - | "DIV" -> ok C_DIV - | "MOD" -> ok C_MOD - | "EQ" -> ok C_EQ - | "NOT" -> ok C_NOT - | "AND" -> ok C_AND - | "OR" -> ok C_OR - | "GT" -> ok C_GT - | "GE" -> ok C_GE - | "LT" -> ok C_LT - | "LE" -> ok C_LE - | "CONS" -> ok C_CONS - | "NEQ" -> ok C_NEQ + (* Set module *) - | "Michelson.is_nat" -> ok C_IS_NAT - | _ -> simple_fail "Not a constant" + | "Set.mem" -> ok C_SET_MEM + | "Set.iter" -> ok C_SET_ITER + | "Set.empty" -> ok C_SET_EMPTY + | "Set.literal" -> ok C_SET_LITERAL + | "Set.add" -> ok C_SET_ADD + | "Set.remove" -> ok C_SET_REMOVE + | "Set.fold" -> ok C_SET_FOLD + | "Set.size" -> ok C_SIZE + + (* Map module *) + + | "Map.find_opt" -> ok C_MAP_FIND_OPT + | "Map.find" -> ok C_MAP_FIND (* Deprecated *) + | "Map.update" -> ok C_MAP_UPDATE + | "Map.add" -> ok C_MAP_ADD + | "Map.remove" -> ok C_MAP_REMOVE + | "Map.iter" -> ok C_MAP_ITER + | "Map.map" -> ok C_MAP_MAP + | "Map.fold" -> ok C_MAP_FOLD + | "Map.mem" -> ok C_MAP_MEM + | "Map.empty" -> ok C_MAP_EMPTY + | "Map.literal" -> ok C_MAP_LITERAL + | "Map.size" -> ok C_SIZE + + (* Big_map module *) + + | "Big_map.find_opt" -> ok C_MAP_FIND_OPT + | "Big_map.find" -> ok C_MAP_FIND + | "Big_map.update" -> ok C_MAP_UPDATE + | "Big_map.add" -> ok C_MAP_ADD + | "Big_map.remove" -> ok C_MAP_REMOVE + | "Big_map.literal" -> ok C_BIG_MAP_LITERAL + | "Big_map.empty" -> ok C_BIG_MAP_EMPTY + + (* Bitwise module *) + + | "Bitwise.or" -> ok C_OR + | "Bitwise.lor" -> ok C_OR (* Deprecated *) + | "Bitwise.and" -> ok C_AND + | "Bitwise.land" -> ok C_AND (* Deprecated *) + | "Bitwise.xor" -> ok C_XOR + | "Bitwise.lxor" -> ok C_XOR (* Deprecated *) + | "Bitwise.shift_left" -> ok C_LSL + | "Bitwise.shift_right" -> ok C_LSR + + (* String module *) + + | "String.length" -> ok C_SIZE + | "String.size" -> ok C_SIZE + | "String.slice" -> ok C_SLICE + | "String.sub" -> ok C_SLICE + | "String.concat" -> ok C_CONCAT + + (* Loop module *) + + | "Loop.fold_while" -> ok C_FOLD_WHILE + | "Loop.continue" -> ok C_CONTINUE + | "continue" -> ok C_CONTINUE (* Deprecated *) + | "Loop.stop" -> ok C_STOP + | "stop" -> ok C_STOP (* Deprecated *) + + (* Others *) + + | "assert" -> ok C_ASSERTION + + | _ -> simple_fail "Not a CameLIGO built-in." let type_constants = type_constants let type_operators = type_operators @@ -821,19 +966,19 @@ module Typer = struct let%bind key = get_t_set set in if eq_1 elt key then ok @@ t_bool () - else fail @@ Operator_errors.type_error "Set_mem: elt and set don't match" elt key () + else fail @@ Operator_errors.type_error "Set.mem: elt and set don't match" elt key () let set_add = typer_2 "SET_ADD" @@ fun elt set -> let%bind key = get_t_set set in if eq_1 elt key then ok set - else fail @@ Operator_errors.type_error "Set_add: elt and set don't match" elt key () + else fail @@ Operator_errors.type_error "Set.add: elt and set don't match" elt key () let set_remove = typer_2 "SET_REMOVE" @@ fun elt set -> let%bind key = get_t_set set in if eq_1 elt key then ok set - else fail @@ Operator_errors.type_error "Set_remove: elt and set don't match" key elt () + else fail @@ Operator_errors.type_error "Set.remove: elt and set don't match" key elt () let set_iter = typer_2 "SET_ITER" @@ fun body set -> let%bind (arg , res) = get_t_function body in diff --git a/src/test/contracts/bitwise_arithmetic.ligo b/src/test/contracts/bitwise_arithmetic.ligo index 0a0d1079a..5818a47b5 100644 --- a/src/test/contracts/bitwise_arithmetic.ligo +++ b/src/test/contracts/bitwise_arithmetic.ligo @@ -1,11 +1,7 @@ // Test PascaLIGO bitwise operators -function or_op (const n : nat) : nat is bitwise_or (n, 4n) - -function and_op (const n : nat) : nat is bitwise_and (n, 7n) - -function xor_op (const n : nat) : nat is bitwise_xor (n, 7n) - -function lsl_op (const n : nat) : nat is bitwise_lsl (n, 7n) - -function lsr_op (const n : nat) : nat is bitwise_lsr (n, 7n) +function or_op (const n : nat) : nat is Bitwise.or (n, 4n) +function and_op (const n : nat) : nat is Bitwise.and (n, 7n) +function xor_op (const n : nat) : nat is Bitwise.xor (n, 7n) +function lsl_op (const n : nat) : nat is Bitwise.shift_left (n, 7n) +function lsr_op (const n : nat) : nat is Bitwise.shift_right (n, 7n) diff --git a/src/test/contracts/bitwise_arithmetic.mligo b/src/test/contracts/bitwise_arithmetic.mligo index a56375f81..d79cbe348 100644 --- a/src/test/contracts/bitwise_arithmetic.mligo +++ b/src/test/contracts/bitwise_arithmetic.mligo @@ -1,7 +1,7 @@ (* Test CameLIGO bitwise operators *) -let or_op (n: nat) : nat = Bitwise.lor n 4n -let and_op (n: nat) : nat = Bitwise.land n 7n -let xor_op (n: nat) : nat = Bitwise.lxor n 7n +let or_op (n: nat) : nat = Bitwise.or n 4n +let and_op (n: nat) : nat = Bitwise.and n 7n +let xor_op (n: nat) : nat = Bitwise.xor n 7n let lsl_op (n: nat) : nat = Bitwise.shift_left n 7n let lsr_op (n: nat) : nat = Bitwise.shift_right n 7n diff --git a/src/test/contracts/bitwise_arithmetic.religo b/src/test/contracts/bitwise_arithmetic.religo index 2cc390b8a..e75821c3a 100644 --- a/src/test/contracts/bitwise_arithmetic.religo +++ b/src/test/contracts/bitwise_arithmetic.religo @@ -1,7 +1,7 @@ /* Test ReasonLigo bitwise operators */ -let or_op = (n: nat): nat => Bitwise.lor(n, 4n); -let and_op = (n: nat): nat => Bitwise.land(n, 7n); -let xor_op = (n: nat): nat => Bitwise.lxor(n, 7n); -let lsl_op = (n: nat) : nat => Bitwise.shift_left(n, 7n); -let lsr_op = (n: nat) : nat => Bitwise.shift_right(n, 7n); \ No newline at end of file +let or_op = (n : nat) : nat => Bitwise.or (n, 4n); +let and_op = (n : nat) : nat => Bitwise.and (n, 7n); +let xor_op = (n : nat) : nat => Bitwise.xor (n, 7n); +let lsl_op = (n : nat) : nat => Bitwise.shift_left (n, 7n); +let lsr_op = (n : nat) : nat => Bitwise.shift_right (n, 7n); \ No newline at end of file From 623e16459fd40ee5ca6da9dcb9587e0b0c2b56fe Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Wed, 26 Feb 2020 13:36:50 +0100 Subject: [PATCH 07/53] Changed Loop.continue to Loop.resume. --- gitlab-pages/docs/language-basics/loops.md | 14 ++++++++------ src/passes/operators/operators.ml | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gitlab-pages/docs/language-basics/loops.md b/gitlab-pages/docs/language-basics/loops.md index 1ded1ef05..ffe27c17e 100644 --- a/gitlab-pages/docs/language-basics/loops.md +++ b/gitlab-pages/docs/language-basics/loops.md @@ -79,12 +79,12 @@ let gcd (x,y : nat * nat) : nat = ``` To ease the writing and reading of the iterated functions (here, -`iter`), two predefined functions are provided: `Loop.continue` and +`iter`), two predefined functions are provided: `Loop.resume` and `Loop.stop`: ```cameligo group=a let iter (x,y : nat * nat) : bool * (nat * nat) = - if y = 0n then Loop.stop (x,y) else Loop.continue (y, x mod y) + if y = 0n then Loop.stop (x,y) else Loop.resume (y, x mod y) let gcd (x,y : nat * nat) : nat = let x,y = if x < y then y,x else x,y in @@ -92,7 +92,8 @@ let gcd (x,y : nat * nat) : nat = in x ``` -> Note that `stop` and `continue` are *deprecated*. +> Note that `stop` and `continue` (now `Loop.resume`) are +> *deprecated*. You can call the function `gcd` defined above using the LIGO compiler like so: @@ -135,12 +136,12 @@ let gcd = ((x,y) : (nat, nat)) : nat => { ``` To ease the writing and reading of the iterated functions (here, -`iter`), two predefined functions are provided: `Loop.continue` and +`iter`), two predefined functions are provided: `Loop.resume` and `Loop.stop`: ```reasonligo group=b let iter = ((x,y) : (nat, nat)) : (bool, (nat, nat)) => - if (y == 0n) { Loop.stop ((x,y)); } else { Loop.continue ((y, x mod y)); }; + if (y == 0n) { Loop.stop ((x,y)); } else { Loop.resume ((y, x mod y)); }; let gcd = ((x,y) : (nat, nat)) : nat => { let (x,y) = if (x < y) { (y,x); } else { (x,y); }; @@ -149,7 +150,8 @@ let gcd = ((x,y) : (nat, nat)) : nat => { }; ``` -> Note that `stop` and `continue` are *deprecated*. +> Note that `stop` and `continue` (now `Loop.resume`) are +> *deprecated*. diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 07a1484c6..7cc7f556d 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -395,7 +395,7 @@ module Simplify = struct (* Loop module *) | "Loop.fold_while" -> ok C_FOLD_WHILE - | "Loop.continue" -> ok C_CONTINUE + | "Loop.resume" -> ok C_CONTINUE | "continue" -> ok C_CONTINUE (* Deprecated *) | "Loop.stop" -> ok C_STOP | "stop" -> ok C_STOP (* Deprecated *) @@ -404,7 +404,7 @@ module Simplify = struct | "assert" -> ok C_ASSERTION - | _ -> simple_fail "Not a CameLIGO built-in." + | _ -> simple_fail "Not a CameLIGO built-in." let type_constants = type_constants let type_operators = type_operators From 1522a7d2e4feaa4322be386e65a634f38fea0718 Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Wed, 26 Feb 2020 15:07:14 +0100 Subject: [PATCH 08/53] Update error.messages for PascaLIGO. --- .../pascaligo/error.messages.checked-in | 1682 +++++++++-------- 1 file changed, 898 insertions(+), 784 deletions(-) diff --git a/src/passes/1-parser/pascaligo/error.messages.checked-in b/src/passes/1-parser/pascaligo/error.messages.checked-in index 660825a6e..51fc4f532 100644 --- a/src/passes/1-parser/pascaligo/error.messages.checked-in +++ b/src/passes/1-parser/pascaligo/error.messages.checked-in @@ -1,6 +1,6 @@ interactive_expr: BigMap LBRACKET Unit ARROW Bytes End ## -## Ends in an error in state: 130. +## Ends in an error in state: 144. ## ## injection(BigMap,binding) -> BigMap LBRACKET sep_or_term_list(binding,SEMI) . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -11,26 +11,26 @@ interactive_expr: BigMap LBRACKET Unit ARROW Bytes End ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 225, spurious reduction of production binding -> expr ARROW expr -## In state 226, spurious reduction of production nsepseq(binding,SEMI) -> binding -## In state 222, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 241, spurious reduction of production binding -> expr ARROW expr +## In state 242, spurious reduction of production nsepseq(binding,SEMI) -> binding +## In state 238, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) ## interactive_expr: BigMap LBRACKET With ## -## Ends in an error in state: 123. +## Ends in an error in state: 137. ## ## injection(BigMap,binding) -> BigMap LBRACKET . sep_or_term_list(binding,SEMI) RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## injection(BigMap,binding) -> BigMap LBRACKET . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -43,7 +43,7 @@ interactive_expr: BigMap LBRACKET With interactive_expr: BigMap Unit ARROW Bytes RBRACKET ## -## Ends in an error in state: 234. +## Ends in an error in state: 250. ## ## injection(BigMap,binding) -> BigMap sep_or_term_list(binding,SEMI) . End [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -54,26 +54,26 @@ interactive_expr: BigMap Unit ARROW Bytes RBRACKET ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 225, spurious reduction of production binding -> expr ARROW expr -## In state 226, spurious reduction of production nsepseq(binding,SEMI) -> binding -## In state 222, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 241, spurious reduction of production binding -> expr ARROW expr +## In state 242, spurious reduction of production nsepseq(binding,SEMI) -> binding +## In state 238, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) ## interactive_expr: BigMap With ## -## Ends in an error in state: 122. +## Ends in an error in state: 136. ## ## injection(BigMap,binding) -> BigMap . sep_or_term_list(binding,SEMI) End [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## injection(BigMap,binding) -> BigMap . End [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -88,7 +88,7 @@ interactive_expr: BigMap With interactive_expr: C_Some With ## -## Ends in an error in state: 118. +## Ends in an error in state: 132. ## ## core_expr -> C_Some . arguments [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -100,7 +100,7 @@ interactive_expr: C_Some With interactive_expr: Case Unit Of C_Some LPAR WILD With ## -## Ends in an error in state: 262. +## Ends in an error in state: 278. ## ## par(core_pattern) -> LPAR core_pattern . RPAR [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## @@ -112,7 +112,7 @@ interactive_expr: Case Unit Of C_Some LPAR WILD With interactive_expr: Case Unit Of C_Some LPAR With ## -## Ends in an error in state: 254. +## Ends in an error in state: 270. ## ## par(core_pattern) -> LPAR . core_pattern RPAR [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## @@ -124,7 +124,7 @@ interactive_expr: Case Unit Of C_Some LPAR With interactive_expr: Case Unit Of C_Some With ## -## Ends in an error in state: 253. +## Ends in an error in state: 269. ## ## constr_pattern -> C_Some . par(core_pattern) [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## @@ -136,7 +136,7 @@ interactive_expr: Case Unit Of C_Some With interactive_expr: Case Unit Of Constr LPAR WILD With ## -## Ends in an error in state: 268. +## Ends in an error in state: 284. ## ## nsepseq(core_pattern,COMMA) -> core_pattern . [ RPAR ] ## nsepseq(core_pattern,COMMA) -> core_pattern . COMMA nsepseq(core_pattern,COMMA) [ RPAR ] @@ -149,7 +149,7 @@ interactive_expr: Case Unit Of Constr LPAR WILD With interactive_expr: Case Unit Of Constr LPAR With ## -## Ends in an error in state: 252. +## Ends in an error in state: 268. ## ## par(nsepseq(core_pattern,COMMA)) -> LPAR . nsepseq(core_pattern,COMMA) RPAR [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## @@ -161,7 +161,7 @@ interactive_expr: Case Unit Of Constr LPAR With interactive_expr: Case Unit Of Constr With ## -## Ends in an error in state: 251. +## Ends in an error in state: 267. ## ## constr_pattern -> Constr . tuple_pattern [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## constr_pattern -> Constr . [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] @@ -174,7 +174,7 @@ interactive_expr: Case Unit Of Constr With interactive_expr: Case Unit Of LBRACKET VBAR Block ## -## Ends in an error in state: 239. +## Ends in an error in state: 255. ## ## case(expr) -> Case expr Of LBRACKET option(VBAR) . cases(expr) RBRACKET [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -186,7 +186,7 @@ interactive_expr: Case Unit Of LBRACKET VBAR Block interactive_expr: Case Unit Of LBRACKET WILD ARROW Bytes End ## -## Ends in an error in state: 303. +## Ends in an error in state: 319. ## ## case(expr) -> Case expr Of LBRACKET option(VBAR) cases(expr) . RBRACKET [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -197,26 +197,26 @@ interactive_expr: Case Unit Of LBRACKET WILD ARROW Bytes End ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 301, spurious reduction of production case_clause(expr) -> pattern ARROW expr -## In state 305, spurious reduction of production nsepseq(case_clause(expr),VBAR) -> case_clause(expr) -## In state 302, spurious reduction of production cases(expr) -> nsepseq(case_clause(expr),VBAR) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 317, spurious reduction of production case_clause(expr) -> pattern ARROW expr +## In state 321, spurious reduction of production nsepseq(case_clause(expr),VBAR) -> case_clause(expr) +## In state 318, spurious reduction of production cases(expr) -> nsepseq(case_clause(expr),VBAR) ## interactive_expr: Case Unit Of LBRACKET With ## -## Ends in an error in state: 238. +## Ends in an error in state: 254. ## ## case(expr) -> Case expr Of LBRACKET . option(VBAR) cases(expr) RBRACKET [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -228,7 +228,7 @@ interactive_expr: Case Unit Of LBRACKET With interactive_expr: Case Unit Of LPAR WILD COMMA With ## -## Ends in an error in state: 269. +## Ends in an error in state: 285. ## ## nsepseq(core_pattern,COMMA) -> core_pattern COMMA . nsepseq(core_pattern,COMMA) [ RPAR ] ## @@ -240,7 +240,7 @@ interactive_expr: Case Unit Of LPAR WILD COMMA With interactive_expr: Case Unit Of LPAR WILD CONS Bytes ARROW ## -## Ends in an error in state: 281. +## Ends in an error in state: 297. ## ## par(cons_pattern) -> LPAR cons_pattern . RPAR [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## @@ -251,15 +251,15 @@ interactive_expr: Case Unit Of LPAR WILD CONS Bytes ARROW ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 275, spurious reduction of production pattern -> core_pattern -## In state 274, spurious reduction of production cons_pattern -> core_pattern CONS pattern +## In state 291, spurious reduction of production pattern -> core_pattern +## In state 290, spurious reduction of production cons_pattern -> core_pattern CONS pattern ## interactive_expr: Case Unit Of LPAR WILD CONS With ## -## Ends in an error in state: 273. +## Ends in an error in state: 289. ## ## cons_pattern -> core_pattern CONS . pattern [ RPAR ] ## @@ -271,7 +271,7 @@ interactive_expr: Case Unit Of LPAR WILD CONS With interactive_expr: Case Unit Of LPAR WILD With ## -## Ends in an error in state: 272. +## Ends in an error in state: 288. ## ## cons_pattern -> core_pattern . CONS pattern [ RPAR ] ## nsepseq(core_pattern,COMMA) -> core_pattern . [ RPAR ] @@ -285,7 +285,7 @@ interactive_expr: Case Unit Of LPAR WILD With interactive_expr: Case Unit Of LPAR With ## -## Ends in an error in state: 247. +## Ends in an error in state: 263. ## ## par(cons_pattern) -> LPAR . cons_pattern RPAR [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## par(nsepseq(core_pattern,COMMA)) -> LPAR . nsepseq(core_pattern,COMMA) RPAR [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] @@ -298,7 +298,7 @@ interactive_expr: Case Unit Of LPAR With interactive_expr: Case Unit Of List LBRACKET WILD End ## -## Ends in an error in state: 285. +## Ends in an error in state: 301. ## ## injection(List,core_pattern) -> List LBRACKET sep_or_term_list(core_pattern,SEMI) . RBRACKET [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## @@ -309,15 +309,15 @@ interactive_expr: Case Unit Of List LBRACKET WILD End ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 289, spurious reduction of production nsepseq(core_pattern,SEMI) -> core_pattern -## In state 288, spurious reduction of production sep_or_term_list(core_pattern,SEMI) -> nsepseq(core_pattern,SEMI) +## In state 305, spurious reduction of production nsepseq(core_pattern,SEMI) -> core_pattern +## In state 304, spurious reduction of production sep_or_term_list(core_pattern,SEMI) -> nsepseq(core_pattern,SEMI) ## interactive_expr: Case Unit Of List LBRACKET With ## -## Ends in an error in state: 283. +## Ends in an error in state: 299. ## ## injection(List,core_pattern) -> List LBRACKET . sep_or_term_list(core_pattern,SEMI) RBRACKET [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## injection(List,core_pattern) -> List LBRACKET . RBRACKET [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] @@ -330,7 +330,7 @@ interactive_expr: Case Unit Of List LBRACKET With interactive_expr: Case Unit Of List WILD RBRACKET ## -## Ends in an error in state: 297. +## Ends in an error in state: 313. ## ## injection(List,core_pattern) -> List sep_or_term_list(core_pattern,SEMI) . End [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## @@ -341,15 +341,15 @@ interactive_expr: Case Unit Of List WILD RBRACKET ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 289, spurious reduction of production nsepseq(core_pattern,SEMI) -> core_pattern -## In state 288, spurious reduction of production sep_or_term_list(core_pattern,SEMI) -> nsepseq(core_pattern,SEMI) +## In state 305, spurious reduction of production nsepseq(core_pattern,SEMI) -> core_pattern +## In state 304, spurious reduction of production sep_or_term_list(core_pattern,SEMI) -> nsepseq(core_pattern,SEMI) ## interactive_expr: Case Unit Of List WILD SEMI WILD SEMI With ## -## Ends in an error in state: 294. +## Ends in an error in state: 310. ## ## nsepseq(core_pattern,SEMI) -> core_pattern SEMI . nsepseq(core_pattern,SEMI) [ RBRACKET End ] ## seq(__anonymous_0(core_pattern,SEMI)) -> core_pattern SEMI . seq(__anonymous_0(core_pattern,SEMI)) [ RBRACKET End ] @@ -362,7 +362,7 @@ interactive_expr: Case Unit Of List WILD SEMI WILD SEMI With interactive_expr: Case Unit Of List WILD SEMI WILD With ## -## Ends in an error in state: 293. +## Ends in an error in state: 309. ## ## nsepseq(core_pattern,SEMI) -> core_pattern . [ RBRACKET End ] ## nsepseq(core_pattern,SEMI) -> core_pattern . SEMI nsepseq(core_pattern,SEMI) [ RBRACKET End ] @@ -376,7 +376,7 @@ interactive_expr: Case Unit Of List WILD SEMI WILD With interactive_expr: Case Unit Of List WILD SEMI With ## -## Ends in an error in state: 290. +## Ends in an error in state: 306. ## ## nsepseq(core_pattern,SEMI) -> core_pattern SEMI . nsepseq(core_pattern,SEMI) [ RBRACKET End ] ## nseq(__anonymous_0(core_pattern,SEMI)) -> core_pattern SEMI . seq(__anonymous_0(core_pattern,SEMI)) [ RBRACKET End ] @@ -389,7 +389,7 @@ interactive_expr: Case Unit Of List WILD SEMI With interactive_expr: Case Unit Of List WILD With ## -## Ends in an error in state: 289. +## Ends in an error in state: 305. ## ## nsepseq(core_pattern,SEMI) -> core_pattern . [ RBRACKET End ] ## nsepseq(core_pattern,SEMI) -> core_pattern . SEMI nsepseq(core_pattern,SEMI) [ RBRACKET End ] @@ -403,7 +403,7 @@ interactive_expr: Case Unit Of List WILD With interactive_expr: Case Unit Of List With ## -## Ends in an error in state: 246. +## Ends in an error in state: 262. ## ## injection(List,core_pattern) -> List . sep_or_term_list(core_pattern,SEMI) End [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] ## injection(List,core_pattern) -> List . End [ SEMI RPAR RBRACKET End CONS COMMA ARROW ] @@ -418,7 +418,7 @@ interactive_expr: Case Unit Of List With interactive_expr: Case Unit Of VBAR Block ## -## Ends in an error in state: 308. +## Ends in an error in state: 324. ## ## case(expr) -> Case expr Of option(VBAR) . cases(expr) End [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -430,7 +430,7 @@ interactive_expr: Case Unit Of VBAR Block interactive_expr: Case Unit Of WILD ARROW Bytes RBRACKET ## -## Ends in an error in state: 309. +## Ends in an error in state: 325. ## ## case(expr) -> Case expr Of option(VBAR) cases(expr) . End [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -441,26 +441,26 @@ interactive_expr: Case Unit Of WILD ARROW Bytes RBRACKET ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 301, spurious reduction of production case_clause(expr) -> pattern ARROW expr -## In state 305, spurious reduction of production nsepseq(case_clause(expr),VBAR) -> case_clause(expr) -## In state 302, spurious reduction of production cases(expr) -> nsepseq(case_clause(expr),VBAR) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 317, spurious reduction of production case_clause(expr) -> pattern ARROW expr +## In state 321, spurious reduction of production nsepseq(case_clause(expr),VBAR) -> case_clause(expr) +## In state 318, spurious reduction of production cases(expr) -> nsepseq(case_clause(expr),VBAR) ## interactive_expr: Case Unit Of WILD ARROW Bytes Type ## -## Ends in an error in state: 305. +## Ends in an error in state: 321. ## ## nsepseq(case_clause(expr),VBAR) -> case_clause(expr) . [ RBRACKET End ] ## nsepseq(case_clause(expr),VBAR) -> case_clause(expr) . VBAR nsepseq(case_clause(expr),VBAR) [ RBRACKET End ] @@ -472,24 +472,24 @@ interactive_expr: Case Unit Of WILD ARROW Bytes Type ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 301, spurious reduction of production case_clause(expr) -> pattern ARROW expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 317, spurious reduction of production case_clause(expr) -> pattern ARROW expr ## interactive_expr: Case Unit Of WILD ARROW Bytes VBAR With ## -## Ends in an error in state: 306. +## Ends in an error in state: 322. ## ## nsepseq(case_clause(expr),VBAR) -> case_clause(expr) VBAR . nsepseq(case_clause(expr),VBAR) [ RBRACKET End ] ## @@ -501,7 +501,7 @@ interactive_expr: Case Unit Of WILD ARROW Bytes VBAR With interactive_expr: Case Unit Of WILD ARROW With ## -## Ends in an error in state: 300. +## Ends in an error in state: 316. ## ## case_clause(expr) -> pattern ARROW . expr [ VBAR RBRACKET End ] ## @@ -513,7 +513,7 @@ interactive_expr: Case Unit Of WILD ARROW With interactive_expr: Case Unit Of WILD CONS WILD CONS With ## -## Ends in an error in state: 279. +## Ends in an error in state: 295. ## ## nsepseq(core_pattern,CONS) -> core_pattern CONS . nsepseq(core_pattern,CONS) [ RPAR ARROW ] ## @@ -525,7 +525,7 @@ interactive_expr: Case Unit Of WILD CONS WILD CONS With interactive_expr: Case Unit Of WILD CONS WILD With ## -## Ends in an error in state: 278. +## Ends in an error in state: 294. ## ## nsepseq(core_pattern,CONS) -> core_pattern . [ RPAR ARROW ] ## nsepseq(core_pattern,CONS) -> core_pattern . CONS nsepseq(core_pattern,CONS) [ RPAR ARROW ] @@ -538,7 +538,7 @@ interactive_expr: Case Unit Of WILD CONS WILD With interactive_expr: Case Unit Of WILD CONS With ## -## Ends in an error in state: 276. +## Ends in an error in state: 292. ## ## pattern -> core_pattern CONS . nsepseq(core_pattern,CONS) [ RPAR ARROW ] ## @@ -550,7 +550,7 @@ interactive_expr: Case Unit Of WILD CONS With interactive_expr: Case Unit Of WILD RPAR ## -## Ends in an error in state: 299. +## Ends in an error in state: 315. ## ## case_clause(expr) -> pattern . ARROW expr [ VBAR RBRACKET End ] ## @@ -561,14 +561,14 @@ interactive_expr: Case Unit Of WILD RPAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 275, spurious reduction of production pattern -> core_pattern +## In state 291, spurious reduction of production pattern -> core_pattern ## interactive_expr: Case Unit Of WILD With ## -## Ends in an error in state: 275. +## Ends in an error in state: 291. ## ## pattern -> core_pattern . [ RPAR ARROW ] ## pattern -> core_pattern . CONS nsepseq(core_pattern,CONS) [ RPAR ARROW ] @@ -581,7 +581,7 @@ interactive_expr: Case Unit Of WILD With interactive_expr: Case Unit Of With ## -## Ends in an error in state: 237. +## Ends in an error in state: 253. ## ## case(expr) -> Case expr Of . option(VBAR) cases(expr) End [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## case(expr) -> Case expr Of . LBRACKET option(VBAR) cases(expr) RBRACKET [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] @@ -594,7 +594,7 @@ interactive_expr: Case Unit Of With interactive_expr: Case Unit VBAR ## -## Ends in an error in state: 236. +## Ends in an error in state: 252. ## ## case(expr) -> Case expr . Of option(VBAR) cases(expr) End [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## case(expr) -> Case expr . Of LBRACKET option(VBAR) cases(expr) RBRACKET [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] @@ -606,23 +606,23 @@ interactive_expr: Case Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## interactive_expr: Case With ## -## Ends in an error in state: 117. +## Ends in an error in state: 131. ## ## case(expr) -> Case . expr Of option(VBAR) cases(expr) End [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## case(expr) -> Case . expr Of LBRACKET option(VBAR) cases(expr) RBRACKET [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] @@ -633,12 +633,65 @@ interactive_expr: Case With +interactive_expr: Constr DOT And With +## +## Ends in an error in state: 169. +## +## core_expr -> module_field . [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] +## fun_call -> module_field . arguments [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] +## +## The known suffix of the stack is as follows: +## module_field +## + + + +interactive_expr: Constr DOT Ident DOT With +## +## Ends in an error in state: 120. +## +## projection -> Constr DOT Ident DOT . nsepseq(selection,DOT) [ With VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE LBRACKET GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ASS ARROW ] +## +## The known suffix of the stack is as follows: +## Constr DOT Ident DOT +## + + + +interactive_expr: Constr DOT Ident With +## +## Ends in an error in state: 119. +## +## module_fun -> Ident . [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] +## projection -> Constr DOT Ident . DOT nsepseq(selection,DOT) [ With VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE LBRACKET GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ASS ARROW ] +## +## The known suffix of the stack is as follows: +## Constr DOT Ident +## + + + +interactive_expr: Constr DOT With +## +## Ends in an error in state: 115. +## +## module_field -> Constr DOT . module_fun [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] +## projection -> Constr DOT . Ident DOT nsepseq(selection,DOT) [ With VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE LBRACKET GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ASS ARROW ] +## +## The known suffix of the stack is as follows: +## Constr DOT +## + + + interactive_expr: Constr With ## ## Ends in an error in state: 114. ## ## core_expr -> Constr . arguments [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## core_expr -> Constr . [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] +## module_field -> Constr . DOT module_fun [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] +## projection -> Constr . DOT Ident DOT nsepseq(selection,DOT) [ With VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE LBRACKET GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## ## The known suffix of the stack is as follows: ## Constr @@ -836,7 +889,7 @@ interactive_expr: Function With interactive_expr: Ident DOT Ident ASS ## -## Ends in an error in state: 133. +## Ends in an error in state: 147. ## ## fun_call_or_par_or_projection -> projection . option(arguments) [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## path -> projection . [ With LBRACKET ] @@ -848,15 +901,15 @@ interactive_expr: Ident DOT Ident ASS ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 321, spurious reduction of production nsepseq(selection,DOT) -> selection -## In state 324, spurious reduction of production projection -> Ident DOT nsepseq(selection,DOT) +## In state 123, spurious reduction of production nsepseq(selection,DOT) -> selection +## In state 335, spurious reduction of production projection -> Ident DOT nsepseq(selection,DOT) ## interactive_expr: Ident DOT Int DOT With ## -## Ends in an error in state: 322. +## Ends in an error in state: 124. ## ## nsepseq(selection,DOT) -> selection DOT . nsepseq(selection,DOT) [ With VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE LBRACKET GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ASS ARROW ] ## @@ -868,7 +921,7 @@ interactive_expr: Ident DOT Int DOT With interactive_expr: Ident DOT Int While ## -## Ends in an error in state: 321. +## Ends in an error in state: 123. ## ## nsepseq(selection,DOT) -> selection . [ With VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE LBRACKET GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ASS ARROW ] ## nsepseq(selection,DOT) -> selection . DOT nsepseq(selection,DOT) [ With VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE LBRACKET GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ASS ARROW ] @@ -881,7 +934,7 @@ interactive_expr: Ident DOT Int While interactive_expr: Ident DOT With ## -## Ends in an error in state: 318. +## Ends in an error in state: 334. ## ## projection -> Ident DOT . nsepseq(selection,DOT) [ With VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE LBRACKET GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ASS ARROW ] ## @@ -893,7 +946,7 @@ interactive_expr: Ident DOT With interactive_expr: Ident LBRACKET Unit VBAR ## -## Ends in an error in state: 218. +## Ends in an error in state: 234. ## ## brackets(expr) -> LBRACKET expr . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ASS ARROW ] ## @@ -904,23 +957,23 @@ interactive_expr: Ident LBRACKET Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## interactive_expr: Ident LBRACKET With ## -## Ends in an error in state: 217. +## Ends in an error in state: 233. ## ## brackets(expr) -> LBRACKET . expr RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ASS ARROW ] ## @@ -932,7 +985,7 @@ interactive_expr: Ident LBRACKET With interactive_expr: Ident LPAR Unit COMMA With ## -## Ends in an error in state: 316. +## Ends in an error in state: 332. ## ## nsepseq(expr,COMMA) -> expr COMMA . nsepseq(expr,COMMA) [ RPAR ] ## @@ -944,7 +997,7 @@ interactive_expr: Ident LPAR Unit COMMA With interactive_expr: Ident LPAR Unit VBAR ## -## Ends in an error in state: 315. +## Ends in an error in state: 331. ## ## nsepseq(expr,COMMA) -> expr . [ RPAR ] ## nsepseq(expr,COMMA) -> expr . COMMA nsepseq(expr,COMMA) [ RPAR ] @@ -956,16 +1009,16 @@ interactive_expr: Ident LPAR Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## @@ -999,7 +1052,7 @@ interactive_expr: Ident While interactive_expr: Ident With Record Ident DOT With ## -## Ends in an error in state: 141. +## Ends in an error in state: 155. ## ## nsepseq(field_name,DOT) -> Ident DOT . nsepseq(field_name,DOT) [ EQ ] ## @@ -1011,7 +1064,7 @@ interactive_expr: Ident With Record Ident DOT With interactive_expr: Ident With Record Ident EQ Bytes RBRACKET ## -## Ends in an error in state: 214. +## Ends in an error in state: 230. ## ## ne_injection(Record,field_path_assignment) -> Record sep_or_term_list(field_path_assignment,SEMI) . End [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1022,26 +1075,26 @@ interactive_expr: Ident With Record Ident EQ Bytes RBRACKET ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 171, spurious reduction of production field_path_assignment -> nsepseq(field_name,DOT) EQ expr -## In state 207, spurious reduction of production nsepseq(field_path_assignment,SEMI) -> field_path_assignment -## In state 146, spurious reduction of production sep_or_term_list(field_path_assignment,SEMI) -> nsepseq(field_path_assignment,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 187, spurious reduction of production field_path_assignment -> nsepseq(field_name,DOT) EQ expr +## In state 223, spurious reduction of production nsepseq(field_path_assignment,SEMI) -> field_path_assignment +## In state 160, spurious reduction of production sep_or_term_list(field_path_assignment,SEMI) -> nsepseq(field_path_assignment,SEMI) ## interactive_expr: Ident With Record Ident EQ Bytes SEMI Ident EQ Bytes SEMI With ## -## Ends in an error in state: 212. +## Ends in an error in state: 228. ## ## nsepseq(field_path_assignment,SEMI) -> field_path_assignment SEMI . nsepseq(field_path_assignment,SEMI) [ RBRACKET End ] ## seq(__anonymous_0(field_path_assignment,SEMI)) -> field_path_assignment SEMI . seq(__anonymous_0(field_path_assignment,SEMI)) [ RBRACKET End ] @@ -1054,7 +1107,7 @@ interactive_expr: Ident With Record Ident EQ Bytes SEMI Ident EQ Bytes SEMI With interactive_expr: Ident With Record Ident EQ Bytes SEMI Ident EQ Bytes VBAR ## -## Ends in an error in state: 211. +## Ends in an error in state: 227. ## ## nsepseq(field_path_assignment,SEMI) -> field_path_assignment . [ RBRACKET End ] ## nsepseq(field_path_assignment,SEMI) -> field_path_assignment . SEMI nsepseq(field_path_assignment,SEMI) [ RBRACKET End ] @@ -1067,24 +1120,24 @@ interactive_expr: Ident With Record Ident EQ Bytes SEMI Ident EQ Bytes VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 171, spurious reduction of production field_path_assignment -> nsepseq(field_name,DOT) EQ expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 187, spurious reduction of production field_path_assignment -> nsepseq(field_name,DOT) EQ expr ## interactive_expr: Ident With Record Ident EQ Bytes SEMI With ## -## Ends in an error in state: 208. +## Ends in an error in state: 224. ## ## nsepseq(field_path_assignment,SEMI) -> field_path_assignment SEMI . nsepseq(field_path_assignment,SEMI) [ RBRACKET End ] ## nseq(__anonymous_0(field_path_assignment,SEMI)) -> field_path_assignment SEMI . seq(__anonymous_0(field_path_assignment,SEMI)) [ RBRACKET End ] @@ -1097,7 +1150,7 @@ interactive_expr: Ident With Record Ident EQ Bytes SEMI With interactive_expr: Ident With Record Ident EQ Bytes VBAR ## -## Ends in an error in state: 207. +## Ends in an error in state: 223. ## ## nsepseq(field_path_assignment,SEMI) -> field_path_assignment . [ RBRACKET End ] ## nsepseq(field_path_assignment,SEMI) -> field_path_assignment . SEMI nsepseq(field_path_assignment,SEMI) [ RBRACKET End ] @@ -1110,24 +1163,24 @@ interactive_expr: Ident With Record Ident EQ Bytes VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 171, spurious reduction of production field_path_assignment -> nsepseq(field_name,DOT) EQ expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 187, spurious reduction of production field_path_assignment -> nsepseq(field_name,DOT) EQ expr ## interactive_expr: Ident With Record Ident EQ With ## -## Ends in an error in state: 148. +## Ends in an error in state: 162. ## ## field_path_assignment -> nsepseq(field_name,DOT) EQ . expr [ SEMI RBRACKET End ] ## @@ -1139,7 +1192,7 @@ interactive_expr: Ident With Record Ident EQ With interactive_expr: Ident With Record Ident With ## -## Ends in an error in state: 140. +## Ends in an error in state: 154. ## ## nsepseq(field_name,DOT) -> Ident . [ EQ ] ## nsepseq(field_name,DOT) -> Ident . DOT nsepseq(field_name,DOT) [ EQ ] @@ -1152,7 +1205,7 @@ interactive_expr: Ident With Record Ident With interactive_expr: Ident With Record LBRACKET Ident EQ Bytes End ## -## Ends in an error in state: 143. +## Ends in an error in state: 157. ## ## ne_injection(Record,field_path_assignment) -> Record LBRACKET sep_or_term_list(field_path_assignment,SEMI) . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1163,26 +1216,26 @@ interactive_expr: Ident With Record LBRACKET Ident EQ Bytes End ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 171, spurious reduction of production field_path_assignment -> nsepseq(field_name,DOT) EQ expr -## In state 207, spurious reduction of production nsepseq(field_path_assignment,SEMI) -> field_path_assignment -## In state 146, spurious reduction of production sep_or_term_list(field_path_assignment,SEMI) -> nsepseq(field_path_assignment,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 187, spurious reduction of production field_path_assignment -> nsepseq(field_name,DOT) EQ expr +## In state 223, spurious reduction of production nsepseq(field_path_assignment,SEMI) -> field_path_assignment +## In state 160, spurious reduction of production sep_or_term_list(field_path_assignment,SEMI) -> nsepseq(field_path_assignment,SEMI) ## interactive_expr: Ident With Record LBRACKET With ## -## Ends in an error in state: 139. +## Ends in an error in state: 153. ## ## ne_injection(Record,field_path_assignment) -> Record LBRACKET . sep_or_term_list(field_path_assignment,SEMI) RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1194,7 +1247,7 @@ interactive_expr: Ident With Record LBRACKET With interactive_expr: Ident With Record With ## -## Ends in an error in state: 138. +## Ends in an error in state: 152. ## ## ne_injection(Record,field_path_assignment) -> Record . sep_or_term_list(field_path_assignment,SEMI) End [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## ne_injection(Record,field_path_assignment) -> Record . LBRACKET sep_or_term_list(field_path_assignment,SEMI) RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -1207,7 +1260,7 @@ interactive_expr: Ident With Record With interactive_expr: Ident With With ## -## Ends in an error in state: 137. +## Ends in an error in state: 151. ## ## update_record -> path With . ne_injection(Record,field_path_assignment) [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1219,7 +1272,7 @@ interactive_expr: Ident With With interactive_expr: If Unit Then Unit Else With ## -## Ends in an error in state: 330. +## Ends in an error in state: 341. ## ## cond_expr -> If expr Then expr option(SEMI) Else . expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -1231,7 +1284,7 @@ interactive_expr: If Unit Then Unit Else With interactive_expr: If Unit Then Unit SEMI EQ ## -## Ends in an error in state: 329. +## Ends in an error in state: 340. ## ## cond_expr -> If expr Then expr option(SEMI) . Else expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -1243,7 +1296,7 @@ interactive_expr: If Unit Then Unit SEMI EQ interactive_expr: If Unit Then Unit VBAR ## -## Ends in an error in state: 328. +## Ends in an error in state: 339. ## ## cond_expr -> If expr Then expr . option(SEMI) Else expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -1254,23 +1307,23 @@ interactive_expr: If Unit Then Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## interactive_expr: If Unit Then With ## -## Ends in an error in state: 327. +## Ends in an error in state: 338. ## ## cond_expr -> If expr Then . expr option(SEMI) Else expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -1282,7 +1335,7 @@ interactive_expr: If Unit Then With interactive_expr: If Unit VBAR ## -## Ends in an error in state: 326. +## Ends in an error in state: 337. ## ## cond_expr -> If expr . Then expr option(SEMI) Else expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## @@ -1293,16 +1346,16 @@ interactive_expr: If Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## @@ -1321,7 +1374,7 @@ interactive_expr: If With interactive_expr: LPAR Bytes RPAR With ## -## Ends in an error in state: 150. +## Ends in an error in state: 164. ## ## fun_call_or_par_or_projection -> par(expr) . option(arguments) [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1333,7 +1386,7 @@ interactive_expr: LPAR Bytes RPAR With interactive_expr: LPAR If Unit Then Bytes Else Bytes VBAR ## -## Ends in an error in state: 334. +## Ends in an error in state: 345. ## ## par(expr) -> LPAR expr . RPAR [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LPAR LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## tuple_comp -> expr . COMMA nsepseq(expr,COMMA) [ RPAR ] @@ -1345,25 +1398,25 @@ interactive_expr: LPAR If Unit Then Bytes Else Bytes VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 331, spurious reduction of production cond_expr -> If expr Then expr option(SEMI) Else expr -## In state 205, spurious reduction of production expr -> cond_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 342, spurious reduction of production cond_expr -> If expr Then expr option(SEMI) Else expr +## In state 221, spurious reduction of production expr -> cond_expr ## interactive_expr: LPAR Unit COLON Ident VBAR ## -## Ends in an error in state: 340. +## Ends in an error in state: 351. ## ## annot_expr -> LPAR disj_expr COLON type_expr . RPAR [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1384,7 +1437,7 @@ interactive_expr: LPAR Unit COLON Ident VBAR interactive_expr: LPAR Unit COLON With ## -## Ends in an error in state: 339. +## Ends in an error in state: 350. ## ## annot_expr -> LPAR disj_expr COLON . type_expr RPAR [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1396,7 +1449,7 @@ interactive_expr: LPAR Unit COLON With interactive_expr: LPAR Unit COMMA With ## -## Ends in an error in state: 336. +## Ends in an error in state: 347. ## ## tuple_comp -> expr COMMA . nsepseq(expr,COMMA) [ RPAR ] ## @@ -1408,7 +1461,7 @@ interactive_expr: LPAR Unit COMMA With interactive_expr: LPAR Unit VBAR ## -## Ends in an error in state: 338. +## Ends in an error in state: 349. ## ## annot_expr -> LPAR disj_expr . COLON type_expr RPAR [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## disj_expr -> disj_expr . Or conj_expr [ RPAR Or COMMA COLON ] @@ -1421,15 +1474,15 @@ interactive_expr: LPAR Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr ## @@ -1450,7 +1503,7 @@ interactive_expr: LPAR With interactive_expr: List LBRACKET Unit End ## -## Ends in an error in state: 344. +## Ends in an error in state: 355. ## ## injection(List,expr) -> List LBRACKET sep_or_term_list(expr,SEMI) . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1461,25 +1514,25 @@ interactive_expr: List LBRACKET Unit End ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 348, spurious reduction of production nsepseq(expr,SEMI) -> expr -## In state 347, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 359, spurious reduction of production nsepseq(expr,SEMI) -> expr +## In state 358, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) ## interactive_expr: List LBRACKET With ## -## Ends in an error in state: 342. +## Ends in an error in state: 353. ## ## injection(List,expr) -> List LBRACKET . sep_or_term_list(expr,SEMI) RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## injection(List,expr) -> List LBRACKET . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -1492,7 +1545,7 @@ interactive_expr: List LBRACKET With interactive_expr: List Unit RBRACKET ## -## Ends in an error in state: 356. +## Ends in an error in state: 367. ## ## injection(List,expr) -> List sep_or_term_list(expr,SEMI) . End [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1503,18 +1556,18 @@ interactive_expr: List Unit RBRACKET ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 348, spurious reduction of production nsepseq(expr,SEMI) -> expr -## In state 347, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 359, spurious reduction of production nsepseq(expr,SEMI) -> expr +## In state 358, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) ## @@ -1548,7 +1601,7 @@ interactive_expr: MINUS With interactive_expr: Map LBRACKET Unit ARROW Bytes End ## -## Ends in an error in state: 361. +## Ends in an error in state: 372. ## ## injection(Map,binding) -> Map LBRACKET sep_or_term_list(binding,SEMI) . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1559,26 +1612,26 @@ interactive_expr: Map LBRACKET Unit ARROW Bytes End ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 225, spurious reduction of production binding -> expr ARROW expr -## In state 226, spurious reduction of production nsepseq(binding,SEMI) -> binding -## In state 222, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 241, spurious reduction of production binding -> expr ARROW expr +## In state 242, spurious reduction of production nsepseq(binding,SEMI) -> binding +## In state 238, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) ## interactive_expr: Map LBRACKET With ## -## Ends in an error in state: 359. +## Ends in an error in state: 370. ## ## injection(Map,binding) -> Map LBRACKET . sep_or_term_list(binding,SEMI) RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## injection(Map,binding) -> Map LBRACKET . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -1591,7 +1644,7 @@ interactive_expr: Map LBRACKET With interactive_expr: Map Unit ARROW Bytes RBRACKET ## -## Ends in an error in state: 364. +## Ends in an error in state: 375. ## ## injection(Map,binding) -> Map sep_or_term_list(binding,SEMI) . End [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1602,26 +1655,26 @@ interactive_expr: Map Unit ARROW Bytes RBRACKET ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 225, spurious reduction of production binding -> expr ARROW expr -## In state 226, spurious reduction of production nsepseq(binding,SEMI) -> binding -## In state 222, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 241, spurious reduction of production binding -> expr ARROW expr +## In state 242, spurious reduction of production nsepseq(binding,SEMI) -> binding +## In state 238, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) ## interactive_expr: Map Unit ARROW Bytes SEMI Unit ARROW Bytes SEMI With ## -## Ends in an error in state: 231. +## Ends in an error in state: 247. ## ## nsepseq(binding,SEMI) -> binding SEMI . nsepseq(binding,SEMI) [ RBRACKET End ] ## seq(__anonymous_0(binding,SEMI)) -> binding SEMI . seq(__anonymous_0(binding,SEMI)) [ RBRACKET End ] @@ -1634,7 +1687,7 @@ interactive_expr: Map Unit ARROW Bytes SEMI Unit ARROW Bytes SEMI With interactive_expr: Map Unit ARROW Bytes SEMI Unit ARROW Bytes VBAR ## -## Ends in an error in state: 230. +## Ends in an error in state: 246. ## ## nsepseq(binding,SEMI) -> binding . [ RBRACKET End ] ## nsepseq(binding,SEMI) -> binding . SEMI nsepseq(binding,SEMI) [ RBRACKET End ] @@ -1647,24 +1700,24 @@ interactive_expr: Map Unit ARROW Bytes SEMI Unit ARROW Bytes VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 225, spurious reduction of production binding -> expr ARROW expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 241, spurious reduction of production binding -> expr ARROW expr ## interactive_expr: Map Unit ARROW Bytes SEMI With ## -## Ends in an error in state: 227. +## Ends in an error in state: 243. ## ## nsepseq(binding,SEMI) -> binding SEMI . nsepseq(binding,SEMI) [ RBRACKET End ] ## nseq(__anonymous_0(binding,SEMI)) -> binding SEMI . seq(__anonymous_0(binding,SEMI)) [ RBRACKET End ] @@ -1677,7 +1730,7 @@ interactive_expr: Map Unit ARROW Bytes SEMI With interactive_expr: Map Unit ARROW Bytes VBAR ## -## Ends in an error in state: 226. +## Ends in an error in state: 242. ## ## nsepseq(binding,SEMI) -> binding . [ RBRACKET End ] ## nsepseq(binding,SEMI) -> binding . SEMI nsepseq(binding,SEMI) [ RBRACKET End ] @@ -1690,24 +1743,24 @@ interactive_expr: Map Unit ARROW Bytes VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 225, spurious reduction of production binding -> expr ARROW expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 241, spurious reduction of production binding -> expr ARROW expr ## interactive_expr: Map Unit ARROW With ## -## Ends in an error in state: 224. +## Ends in an error in state: 240. ## ## binding -> expr ARROW . expr [ SEMI RBRACKET End ] ## @@ -1719,7 +1772,7 @@ interactive_expr: Map Unit ARROW With interactive_expr: Map Unit VBAR ## -## Ends in an error in state: 223. +## Ends in an error in state: 239. ## ## binding -> expr . ARROW expr [ SEMI RBRACKET End ] ## @@ -1730,16 +1783,16 @@ interactive_expr: Map Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## @@ -1761,7 +1814,7 @@ interactive_expr: Map With interactive_expr: Not Bytes With ## -## Ends in an error in state: 152. +## Ends in an error in state: 166. ## ## add_expr -> mult_expr . [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE PLUS Or Of NE MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## mult_expr -> mult_expr . TIMES unary_expr [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -1788,7 +1841,7 @@ interactive_expr: Not With interactive_expr: Record Ident EQ Bytes RBRACKET ## -## Ends in an error in state: 379. +## Ends in an error in state: 390. ## ## record_expr -> Record sep_or_term_list(field_assignment,SEMI) . End [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1799,26 +1852,26 @@ interactive_expr: Record Ident EQ Bytes RBRACKET ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 367, spurious reduction of production field_assignment -> Ident EQ expr -## In state 372, spurious reduction of production nsepseq(field_assignment,SEMI) -> field_assignment -## In state 371, spurious reduction of production sep_or_term_list(field_assignment,SEMI) -> nsepseq(field_assignment,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 378, spurious reduction of production field_assignment -> Ident EQ expr +## In state 383, spurious reduction of production nsepseq(field_assignment,SEMI) -> field_assignment +## In state 382, spurious reduction of production sep_or_term_list(field_assignment,SEMI) -> nsepseq(field_assignment,SEMI) ## interactive_expr: Record Ident EQ Bytes SEMI Ident EQ Bytes SEMI With ## -## Ends in an error in state: 377. +## Ends in an error in state: 388. ## ## nsepseq(field_assignment,SEMI) -> field_assignment SEMI . nsepseq(field_assignment,SEMI) [ RBRACKET End ] ## seq(__anonymous_0(field_assignment,SEMI)) -> field_assignment SEMI . seq(__anonymous_0(field_assignment,SEMI)) [ RBRACKET End ] @@ -1831,7 +1884,7 @@ interactive_expr: Record Ident EQ Bytes SEMI Ident EQ Bytes SEMI With interactive_expr: Record Ident EQ Bytes SEMI Ident EQ Bytes VBAR ## -## Ends in an error in state: 376. +## Ends in an error in state: 387. ## ## nsepseq(field_assignment,SEMI) -> field_assignment . [ RBRACKET End ] ## nsepseq(field_assignment,SEMI) -> field_assignment . SEMI nsepseq(field_assignment,SEMI) [ RBRACKET End ] @@ -1844,24 +1897,24 @@ interactive_expr: Record Ident EQ Bytes SEMI Ident EQ Bytes VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 367, spurious reduction of production field_assignment -> Ident EQ expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 378, spurious reduction of production field_assignment -> Ident EQ expr ## interactive_expr: Record Ident EQ Bytes SEMI With ## -## Ends in an error in state: 373. +## Ends in an error in state: 384. ## ## nsepseq(field_assignment,SEMI) -> field_assignment SEMI . nsepseq(field_assignment,SEMI) [ RBRACKET End ] ## nseq(__anonymous_0(field_assignment,SEMI)) -> field_assignment SEMI . seq(__anonymous_0(field_assignment,SEMI)) [ RBRACKET End ] @@ -1874,7 +1927,7 @@ interactive_expr: Record Ident EQ Bytes SEMI With interactive_expr: Record Ident EQ Bytes VBAR ## -## Ends in an error in state: 372. +## Ends in an error in state: 383. ## ## nsepseq(field_assignment,SEMI) -> field_assignment . [ RBRACKET End ] ## nsepseq(field_assignment,SEMI) -> field_assignment . SEMI nsepseq(field_assignment,SEMI) [ RBRACKET End ] @@ -1887,17 +1940,17 @@ interactive_expr: Record Ident EQ Bytes VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 367, spurious reduction of production field_assignment -> Ident EQ expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 378, spurious reduction of production field_assignment -> Ident EQ expr ## @@ -1928,7 +1981,7 @@ interactive_expr: Record Ident With interactive_expr: Record LBRACKET Ident EQ Bytes End ## -## Ends in an error in state: 368. +## Ends in an error in state: 379. ## ## record_expr -> Record LBRACKET sep_or_term_list(field_assignment,SEMI) . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1939,19 +1992,19 @@ interactive_expr: Record LBRACKET Ident EQ Bytes End ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 367, spurious reduction of production field_assignment -> Ident EQ expr -## In state 372, spurious reduction of production nsepseq(field_assignment,SEMI) -> field_assignment -## In state 371, spurious reduction of production sep_or_term_list(field_assignment,SEMI) -> nsepseq(field_assignment,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 378, spurious reduction of production field_assignment -> Ident EQ expr +## In state 383, spurious reduction of production nsepseq(field_assignment,SEMI) -> field_assignment +## In state 382, spurious reduction of production sep_or_term_list(field_assignment,SEMI) -> nsepseq(field_assignment,SEMI) ## @@ -1983,7 +2036,7 @@ interactive_expr: Record With interactive_expr: Set LBRACKET Unit End ## -## Ends in an error in state: 383. +## Ends in an error in state: 394. ## ## injection(Set,expr) -> Set LBRACKET sep_or_term_list(expr,SEMI) . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -1994,25 +2047,25 @@ interactive_expr: Set LBRACKET Unit End ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 348, spurious reduction of production nsepseq(expr,SEMI) -> expr -## In state 347, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 359, spurious reduction of production nsepseq(expr,SEMI) -> expr +## In state 358, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) ## interactive_expr: Set LBRACKET With ## -## Ends in an error in state: 381. +## Ends in an error in state: 392. ## ## injection(Set,expr) -> Set LBRACKET . sep_or_term_list(expr,SEMI) RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## injection(Set,expr) -> Set LBRACKET . RBRACKET [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -2025,7 +2078,7 @@ interactive_expr: Set LBRACKET With interactive_expr: Set Unit RBRACKET ## -## Ends in an error in state: 386. +## Ends in an error in state: 397. ## ## injection(Set,expr) -> Set sep_or_term_list(expr,SEMI) . End [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Contains Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -2036,25 +2089,25 @@ interactive_expr: Set Unit RBRACKET ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 348, spurious reduction of production nsepseq(expr,SEMI) -> expr -## In state 347, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 359, spurious reduction of production nsepseq(expr,SEMI) -> expr +## In state 358, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) ## interactive_expr: Set Unit SEMI Unit SEMI With ## -## Ends in an error in state: 353. +## Ends in an error in state: 364. ## ## nsepseq(expr,SEMI) -> expr SEMI . nsepseq(expr,SEMI) [ RBRACKET End ] ## seq(__anonymous_0(expr,SEMI)) -> expr SEMI . seq(__anonymous_0(expr,SEMI)) [ RBRACKET End ] @@ -2067,7 +2120,7 @@ interactive_expr: Set Unit SEMI Unit SEMI With interactive_expr: Set Unit SEMI Unit VBAR ## -## Ends in an error in state: 352. +## Ends in an error in state: 363. ## ## nsepseq(expr,SEMI) -> expr . [ RBRACKET End ] ## nsepseq(expr,SEMI) -> expr . SEMI nsepseq(expr,SEMI) [ RBRACKET End ] @@ -2080,23 +2133,23 @@ interactive_expr: Set Unit SEMI Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## interactive_expr: Set Unit SEMI With ## -## Ends in an error in state: 349. +## Ends in an error in state: 360. ## ## nsepseq(expr,SEMI) -> expr SEMI . nsepseq(expr,SEMI) [ RBRACKET End ] ## nseq(__anonymous_0(expr,SEMI)) -> expr SEMI . seq(__anonymous_0(expr,SEMI)) [ RBRACKET End ] @@ -2109,7 +2162,7 @@ interactive_expr: Set Unit SEMI With interactive_expr: Set Unit VBAR ## -## Ends in an error in state: 348. +## Ends in an error in state: 359. ## ## nsepseq(expr,SEMI) -> expr . [ RBRACKET End ] ## nsepseq(expr,SEMI) -> expr . SEMI nsepseq(expr,SEMI) [ RBRACKET End ] @@ -2122,16 +2175,16 @@ interactive_expr: Set Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## @@ -2153,7 +2206,7 @@ interactive_expr: Set With interactive_expr: Unit And With ## -## Ends in an error in state: 202. +## Ends in an error in state: 218. ## ## conj_expr -> conj_expr And . set_membership [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of Function From End Else EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## @@ -2165,7 +2218,7 @@ interactive_expr: Unit And With interactive_expr: Unit CAT With ## -## Ends in an error in state: 178. +## Ends in an error in state: 194. ## ## cat_expr -> cons_expr CAT . cat_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of NE LT LE GT GE Function From End Else EQ EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## @@ -2177,7 +2230,7 @@ interactive_expr: Unit CAT With interactive_expr: Unit COLON ## -## Ends in an error in state: 172. +## Ends in an error in state: 188. ## ## disj_expr -> disj_expr . Or conj_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] ## expr -> disj_expr . [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Of Function From End Else EOF Const COMMA Block Begin Attributes ARROW ] @@ -2189,22 +2242,22 @@ interactive_expr: Unit COLON ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr ## interactive_expr: Unit CONS With ## -## Ends in an error in state: 185. +## Ends in an error in state: 201. ## ## cons_expr -> add_expr CONS . cons_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of NE LT LE GT GE Function From End Else EQ EOF Const COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -2216,7 +2269,7 @@ interactive_expr: Unit CONS With interactive_expr: Unit Contains With ## -## Ends in an error in state: 175. +## Ends in an error in state: 191. ## ## set_membership -> core_expr Contains . set_membership [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of Function From End Else EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## @@ -2228,7 +2281,7 @@ interactive_expr: Unit Contains With interactive_expr: Unit EQ With ## -## Ends in an error in state: 198. +## Ends in an error in state: 214. ## ## comp_expr -> comp_expr EQ . cat_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of NE LT LE GT GE Function From End Else EQ EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## @@ -2240,7 +2293,7 @@ interactive_expr: Unit EQ With interactive_expr: Unit GE With ## -## Ends in an error in state: 196. +## Ends in an error in state: 212. ## ## comp_expr -> comp_expr GE . cat_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of NE LT LE GT GE Function From End Else EQ EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## @@ -2252,7 +2305,7 @@ interactive_expr: Unit GE With interactive_expr: Unit GT With ## -## Ends in an error in state: 194. +## Ends in an error in state: 210. ## ## comp_expr -> comp_expr GT . cat_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of NE LT LE GT GE Function From End Else EQ EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## @@ -2264,7 +2317,7 @@ interactive_expr: Unit GT With interactive_expr: Unit LE With ## -## Ends in an error in state: 192. +## Ends in an error in state: 208. ## ## comp_expr -> comp_expr LE . cat_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of NE LT LE GT GE Function From End Else EQ EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## @@ -2276,7 +2329,7 @@ interactive_expr: Unit LE With interactive_expr: Unit LT With ## -## Ends in an error in state: 190. +## Ends in an error in state: 206. ## ## comp_expr -> comp_expr LT . cat_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of NE LT LE GT GE Function From End Else EQ EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## @@ -2288,7 +2341,7 @@ interactive_expr: Unit LT With interactive_expr: Unit MINUS Unit With ## -## Ends in an error in state: 184. +## Ends in an error in state: 200. ## ## add_expr -> add_expr MINUS mult_expr . [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE PLUS Or Of NE MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## mult_expr -> mult_expr . TIMES unary_expr [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -2303,7 +2356,7 @@ interactive_expr: Unit MINUS Unit With interactive_expr: Unit MINUS With ## -## Ends in an error in state: 183. +## Ends in an error in state: 199. ## ## add_expr -> add_expr MINUS . mult_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE PLUS Or Of NE MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -2315,7 +2368,7 @@ interactive_expr: Unit MINUS With interactive_expr: Unit Mod With ## -## Ends in an error in state: 168. +## Ends in an error in state: 184. ## ## mult_expr -> mult_expr Mod . unary_expr [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -2327,7 +2380,7 @@ interactive_expr: Unit Mod With interactive_expr: Unit NE With ## -## Ends in an error in state: 188. +## Ends in an error in state: 204. ## ## comp_expr -> comp_expr NE . cat_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of NE LT LE GT GE Function From End Else EQ EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## @@ -2339,7 +2392,7 @@ interactive_expr: Unit NE With interactive_expr: Unit Or With ## -## Ends in an error in state: 173. +## Ends in an error in state: 189. ## ## disj_expr -> disj_expr Or . conj_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of Function From End Else EOF Const COMMA COLON Block Begin Attributes ARROW ] ## @@ -2351,7 +2404,7 @@ interactive_expr: Unit Or With interactive_expr: Unit PLUS Unit With ## -## Ends in an error in state: 182. +## Ends in an error in state: 198. ## ## add_expr -> add_expr PLUS mult_expr . [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE PLUS Or Of NE MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## mult_expr -> mult_expr . TIMES unary_expr [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -2366,7 +2419,7 @@ interactive_expr: Unit PLUS Unit With interactive_expr: Unit PLUS With ## -## Ends in an error in state: 181. +## Ends in an error in state: 197. ## ## add_expr -> add_expr PLUS . mult_expr [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE PLUS Or Of NE MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -2378,7 +2431,7 @@ interactive_expr: Unit PLUS With interactive_expr: Unit SLASH With ## -## Ends in an error in state: 166. +## Ends in an error in state: 182. ## ## mult_expr -> mult_expr SLASH . unary_expr [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -2390,7 +2443,7 @@ interactive_expr: Unit SLASH With interactive_expr: Unit TIMES With ## -## Ends in an error in state: 153. +## Ends in an error in state: 167. ## ## mult_expr -> mult_expr TIMES . unary_expr [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] ## @@ -2402,7 +2455,7 @@ interactive_expr: Unit TIMES With interactive_expr: Unit VBAR ## -## Ends in an error in state: 570. +## Ends in an error in state: 586. ## ## interactive_expr -> expr . EOF [ # ] ## @@ -2413,23 +2466,23 @@ interactive_expr: Unit VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## interactive_expr: Unit With ## -## Ends in an error in state: 174. +## Ends in an error in state: 190. ## ## set_membership -> core_expr . Contains set_membership [ VBAR Type To Then SEMI RPAR RBRACKET RBRACE Or Of Function From End Else EOF Const COMMA COLON Block Begin Attributes And ARROW ] ## unary_expr -> core_expr . [ VBAR Type To Then TIMES SLASH SEMI RPAR RBRACKET RBRACE PLUS Or Of NE Mod MINUS LT LE GT GE Function From End Else EQ EOF Const CONS COMMA COLON CAT Block Begin Attributes And ARROW ] @@ -2442,7 +2495,7 @@ interactive_expr: Unit With interactive_expr: With ## -## Ends in an error in state: 568. +## Ends in an error in state: 584. ## ## interactive_expr' -> . interactive_expr [ # ] ## @@ -2454,7 +2507,7 @@ interactive_expr: With contract: Attributes LBRACKET String End ## -## Ends in an error in state: 514. +## Ends in an error in state: 530. ## ## ne_injection(Attributes,String) -> Attributes LBRACKET sep_or_term_list(String,SEMI) . RBRACKET [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -2465,15 +2518,15 @@ contract: Attributes LBRACKET String End ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 506, spurious reduction of production nsepseq(String,SEMI) -> String -## In state 517, spurious reduction of production sep_or_term_list(String,SEMI) -> nsepseq(String,SEMI) +## In state 522, spurious reduction of production nsepseq(String,SEMI) -> String +## In state 533, spurious reduction of production sep_or_term_list(String,SEMI) -> nsepseq(String,SEMI) ## contract: Attributes LBRACKET With ## -## Ends in an error in state: 513. +## Ends in an error in state: 529. ## ## ne_injection(Attributes,String) -> Attributes LBRACKET . sep_or_term_list(String,SEMI) RBRACKET [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -2485,7 +2538,7 @@ contract: Attributes LBRACKET With contract: Attributes String End Attributes String End SEMI With ## -## Ends in an error in state: 563. +## Ends in an error in state: 579. ## ## seq(declaration) -> declaration . seq(declaration) [ EOF ] ## @@ -2497,7 +2550,7 @@ contract: Attributes String End Attributes String End SEMI With contract: Attributes String End SEMI With ## -## Ends in an error in state: 561. +## Ends in an error in state: 577. ## ## nseq(declaration) -> declaration . seq(declaration) [ EOF ] ## @@ -2509,7 +2562,7 @@ contract: Attributes String End SEMI With contract: Attributes String End With ## -## Ends in an error in state: 556. +## Ends in an error in state: 572. ## ## attr_decl -> open_attr_decl . option(SEMI) [ Type Function EOF Const Attributes ] ## @@ -2521,7 +2574,7 @@ contract: Attributes String End With contract: Attributes String RBRACKET ## -## Ends in an error in state: 518. +## Ends in an error in state: 534. ## ## ne_injection(Attributes,String) -> Attributes sep_or_term_list(String,SEMI) . End [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -2532,15 +2585,15 @@ contract: Attributes String RBRACKET ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 506, spurious reduction of production nsepseq(String,SEMI) -> String -## In state 517, spurious reduction of production sep_or_term_list(String,SEMI) -> nsepseq(String,SEMI) +## In state 522, spurious reduction of production nsepseq(String,SEMI) -> String +## In state 533, spurious reduction of production sep_or_term_list(String,SEMI) -> nsepseq(String,SEMI) ## contract: Attributes String SEMI String SEMI With ## -## Ends in an error in state: 509. +## Ends in an error in state: 525. ## ## nsepseq(String,SEMI) -> String SEMI . nsepseq(String,SEMI) [ RBRACKET End ] ## seq(__anonymous_0(String,SEMI)) -> String SEMI . seq(__anonymous_0(String,SEMI)) [ RBRACKET End ] @@ -2553,7 +2606,7 @@ contract: Attributes String SEMI String SEMI With contract: Attributes String SEMI String With ## -## Ends in an error in state: 508. +## Ends in an error in state: 524. ## ## nsepseq(String,SEMI) -> String . [ RBRACKET End ] ## nsepseq(String,SEMI) -> String . SEMI nsepseq(String,SEMI) [ RBRACKET End ] @@ -2567,7 +2620,7 @@ contract: Attributes String SEMI String With contract: Attributes String SEMI With ## -## Ends in an error in state: 507. +## Ends in an error in state: 523. ## ## nsepseq(String,SEMI) -> String SEMI . nsepseq(String,SEMI) [ RBRACKET End ] ## nseq(__anonymous_0(String,SEMI)) -> String SEMI . seq(__anonymous_0(String,SEMI)) [ RBRACKET End ] @@ -2580,7 +2633,7 @@ contract: Attributes String SEMI With contract: Attributes String With ## -## Ends in an error in state: 506. +## Ends in an error in state: 522. ## ## nsepseq(String,SEMI) -> String . [ RBRACKET End ] ## nsepseq(String,SEMI) -> String . SEMI nsepseq(String,SEMI) [ RBRACKET End ] @@ -2594,7 +2647,7 @@ contract: Attributes String With contract: Attributes With ## -## Ends in an error in state: 505. +## Ends in an error in state: 521. ## ## ne_injection(Attributes,String) -> Attributes . sep_or_term_list(String,SEMI) End [ Type SEMI RBRACE Function End EOF Const Attributes ] ## ne_injection(Attributes,String) -> Attributes . LBRACKET sep_or_term_list(String,SEMI) RBRACKET [ Type SEMI RBRACE Function End EOF Const Attributes ] @@ -2607,7 +2660,7 @@ contract: Attributes With contract: Const Ident COLON Ident EQ Bytes VBAR ## -## Ends in an error in state: 554. +## Ends in an error in state: 570. ## ## const_decl -> open_const_decl . option(SEMI) [ Type Function EOF Const Attributes ] ## @@ -2618,25 +2671,25 @@ contract: Const Ident COLON Ident EQ Bytes VBAR ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 463, spurious reduction of production unqualified_decl(EQ) -> Ident COLON type_expr EQ expr -## In state 464, spurious reduction of production open_const_decl -> Const unqualified_decl(EQ) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 478, spurious reduction of production unqualified_decl(EQ) -> Ident COLON type_expr EQ expr +## In state 479, spurious reduction of production open_const_decl -> Const unqualified_decl(EQ) ## contract: Const Ident COLON Ident EQ With ## -## Ends in an error in state: 462. +## Ends in an error in state: 477. ## ## unqualified_decl(EQ) -> Ident COLON type_expr EQ . expr [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -2648,7 +2701,7 @@ contract: Const Ident COLON Ident EQ With contract: Const Ident COLON Ident VBAR ## -## Ends in an error in state: 461. +## Ends in an error in state: 476. ## ## unqualified_decl(EQ) -> Ident COLON type_expr . EQ expr [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -2669,7 +2722,7 @@ contract: Const Ident COLON Ident VBAR contract: Const Ident COLON With ## -## Ends in an error in state: 460. +## Ends in an error in state: 475. ## ## unqualified_decl(EQ) -> Ident COLON . type_expr EQ expr [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -2681,7 +2734,7 @@ contract: Const Ident COLON With contract: Const Ident With ## -## Ends in an error in state: 459. +## Ends in an error in state: 474. ## ## unqualified_decl(EQ) -> Ident . COLON type_expr EQ expr [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -2693,7 +2746,7 @@ contract: Const Ident With contract: Const With ## -## Ends in an error in state: 458. +## Ends in an error in state: 473. ## ## open_const_decl -> Const . unqualified_decl(EQ) [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -2705,7 +2758,7 @@ contract: Const With contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of LBRACKET VBAR Block ## -## Ends in an error in state: 469. +## Ends in an error in state: 484. ## ## case(if_clause) -> Case expr Of LBRACKET option(VBAR) . cases(if_clause) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -2717,7 +2770,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of LBRACKET WILD ARROW Skip End ## -## Ends in an error in state: 497. +## Ends in an error in state: 513. ## ## case(if_clause) -> Case expr Of LBRACKET option(VBAR) cases(if_clause) . RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -2728,15 +2781,15 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 499, spurious reduction of production nsepseq(case_clause(if_clause),VBAR) -> case_clause(if_clause) -## In state 496, spurious reduction of production cases(if_clause) -> nsepseq(case_clause(if_clause),VBAR) +## In state 515, spurious reduction of production nsepseq(case_clause(if_clause),VBAR) -> case_clause(if_clause) +## In state 512, spurious reduction of production cases(if_clause) -> nsepseq(case_clause(if_clause),VBAR) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of LBRACKET With ## -## Ends in an error in state: 468. +## Ends in an error in state: 483. ## ## case(if_clause) -> Case expr Of LBRACKET . option(VBAR) cases(if_clause) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -2748,7 +2801,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of VBAR Block ## -## Ends in an error in state: 502. +## Ends in an error in state: 518. ## ## case(if_clause) -> Case expr Of option(VBAR) . cases(if_clause) End [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -2760,7 +2813,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of WILD ARROW Skip RBRACKET ## -## Ends in an error in state: 503. +## Ends in an error in state: 519. ## ## case(if_clause) -> Case expr Of option(VBAR) cases(if_clause) . End [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -2771,15 +2824,15 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 499, spurious reduction of production nsepseq(case_clause(if_clause),VBAR) -> case_clause(if_clause) -## In state 496, spurious reduction of production cases(if_clause) -> nsepseq(case_clause(if_clause),VBAR) +## In state 515, spurious reduction of production nsepseq(case_clause(if_clause),VBAR) -> case_clause(if_clause) +## In state 512, spurious reduction of production cases(if_clause) -> nsepseq(case_clause(if_clause),VBAR) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of WILD ARROW Skip VBAR With ## -## Ends in an error in state: 500. +## Ends in an error in state: 516. ## ## nsepseq(case_clause(if_clause),VBAR) -> case_clause(if_clause) VBAR . nsepseq(case_clause(if_clause),VBAR) [ RBRACKET End ] ## @@ -2791,7 +2844,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of WILD ARROW Skip With ## -## Ends in an error in state: 499. +## Ends in an error in state: 515. ## ## nsepseq(case_clause(if_clause),VBAR) -> case_clause(if_clause) . [ RBRACKET End ] ## nsepseq(case_clause(if_clause),VBAR) -> case_clause(if_clause) . VBAR nsepseq(case_clause(if_clause),VBAR) [ RBRACKET End ] @@ -2804,7 +2857,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of WILD ARROW With ## -## Ends in an error in state: 471. +## Ends in an error in state: 486. ## ## case_clause(if_clause) -> pattern ARROW . if_clause [ VBAR RBRACKET End ] ## @@ -2816,7 +2869,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of WILD RPAR ## -## Ends in an error in state: 470. +## Ends in an error in state: 485. ## ## case_clause(if_clause) -> pattern . ARROW if_clause [ VBAR RBRACKET End ] ## @@ -2827,14 +2880,14 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 275, spurious reduction of production pattern -> core_pattern +## In state 291, spurious reduction of production pattern -> core_pattern ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit Of With ## -## Ends in an error in state: 467. +## Ends in an error in state: 482. ## ## case(if_clause) -> Case expr Of . option(VBAR) cases(if_clause) End [ VBAR SEMI RBRACKET RBRACE End Else ] ## case(if_clause) -> Case expr Of . LBRACKET option(VBAR) cases(if_clause) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -2847,7 +2900,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case Unit VBAR ## -## Ends in an error in state: 466. +## Ends in an error in state: 481. ## ## case(if_clause) -> Case expr . Of option(VBAR) cases(if_clause) End [ VBAR SEMI RBRACKET RBRACE End Else ] ## case(if_clause) -> Case expr . Of LBRACKET option(VBAR) cases(if_clause) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -2859,23 +2912,23 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Case With ## -## Ends in an error in state: 465. +## Ends in an error in state: 480. ## ## case(if_clause) -> Case . expr Of option(VBAR) cases(if_clause) End [ VBAR SEMI RBRACKET RBRACE End Else ] ## case(if_clause) -> Case . expr Of LBRACKET option(VBAR) cases(if_clause) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -2886,9 +2939,34 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin +contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Constr DOT And With +## +## Ends in an error in state: 493. +## +## fun_call -> module_field . arguments [ VBAR SEMI RBRACKET RBRACE End Else ] +## +## The known suffix of the stack is as follows: +## module_field +## + + + +contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Constr With +## +## Ends in an error in state: 472. +## +## module_field -> Constr . DOT module_fun [ LPAR ] +## projection -> Constr . DOT Ident DOT nsepseq(selection,DOT) [ LBRACKET ASS ] +## +## The known suffix of the stack is as follows: +## Constr +## + + + contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident ARROW Ident With ## -## Ends in an error in state: 445. +## Ends in an error in state: 459. ## ## for_loop -> For Ident option(arrow_clause) . In collection expr block [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -2900,7 +2978,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident ARROW With ## -## Ends in an error in state: 443. +## Ends in an error in state: 457. ## ## arrow_clause -> ARROW . Ident [ In ] ## @@ -2912,7 +2990,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident ASS Bytes To Unit VBAR ## -## Ends in an error in state: 456. +## Ends in an error in state: 470. ## ## for_loop -> For var_assign To expr . block [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -2923,23 +3001,23 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident ASS Bytes To With ## -## Ends in an error in state: 455. +## Ends in an error in state: 469. ## ## for_loop -> For var_assign To . expr block [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -2951,7 +3029,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident ASS Bytes VBAR ## -## Ends in an error in state: 454. +## Ends in an error in state: 468. ## ## for_loop -> For var_assign . To expr block [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -2962,24 +3040,24 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 442, spurious reduction of production var_assign -> Ident ASS expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 456, spurious reduction of production var_assign -> Ident ASS expr ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident ASS With ## -## Ends in an error in state: 441. +## Ends in an error in state: 455. ## ## var_assign -> Ident ASS . expr [ To ] ## @@ -2991,7 +3069,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident In Set Unit VBAR ## -## Ends in an error in state: 451. +## Ends in an error in state: 465. ## ## for_loop -> For Ident option(arrow_clause) In collection expr . block [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3002,23 +3080,23 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident In Set With ## -## Ends in an error in state: 450. +## Ends in an error in state: 464. ## ## for_loop -> For Ident option(arrow_clause) In collection . expr block [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3030,7 +3108,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident In With ## -## Ends in an error in state: 446. +## Ends in an error in state: 460. ## ## for_loop -> For Ident option(arrow_clause) In . collection expr block [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3042,7 +3120,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For Ident With ## -## Ends in an error in state: 440. +## Ends in an error in state: 454. ## ## for_loop -> For Ident . option(arrow_clause) In collection expr block [ VBAR SEMI RBRACKET RBRACE End Else ] ## var_assign -> Ident . ASS expr [ To ] @@ -3055,7 +3133,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin For With ## -## Ends in an error in state: 439. +## Ends in an error in state: 453. ## ## for_loop -> For . var_assign To expr block [ VBAR SEMI RBRACKET RBRACE End Else ] ## for_loop -> For . Ident option(arrow_clause) In collection expr block [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3068,7 +3146,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Ident ASS With ## -## Ends in an error in state: 483. +## Ends in an error in state: 499. ## ## assignment -> lhs ASS . rhs [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3080,7 +3158,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Ident DOT Ident With ## -## Ends in an error in state: 477. +## Ends in an error in state: 492. ## ## lhs -> path . [ ASS ] ## map_lookup -> path . brackets(expr) [ ASS ] @@ -3092,16 +3170,16 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 321, spurious reduction of production nsepseq(selection,DOT) -> selection -## In state 324, spurious reduction of production projection -> Ident DOT nsepseq(selection,DOT) -## In state 406, spurious reduction of production path -> projection +## In state 123, spurious reduction of production nsepseq(selection,DOT) -> selection +## In state 335, spurious reduction of production projection -> Ident DOT nsepseq(selection,DOT) +## In state 420, spurious reduction of production path -> projection ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Ident LBRACKET Bytes RBRACKET With ## -## Ends in an error in state: 482. +## Ends in an error in state: 498. ## ## assignment -> lhs . ASS rhs [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3113,7 +3191,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Ident With ## -## Ends in an error in state: 438. +## Ends in an error in state: 452. ## ## fun_call -> Ident . arguments [ VBAR SEMI RBRACKET RBRACE End Else ] ## path -> Ident . [ LBRACKET ASS ] @@ -3127,7 +3205,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin If Unit Then LBRACE Skip End ## -## Ends in an error in state: 534. +## Ends in an error in state: 550. ## ## clause_block -> LBRACE sep_or_term_list(statement,SEMI) . RBRACE [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3138,15 +3216,15 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 520, spurious reduction of production nsepseq(statement,SEMI) -> statement -## In state 537, spurious reduction of production sep_or_term_list(statement,SEMI) -> nsepseq(statement,SEMI) +## In state 536, spurious reduction of production nsepseq(statement,SEMI) -> statement +## In state 553, spurious reduction of production sep_or_term_list(statement,SEMI) -> nsepseq(statement,SEMI) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin If Unit Then LBRACE With ## -## Ends in an error in state: 437. +## Ends in an error in state: 451. ## ## clause_block -> LBRACE . sep_or_term_list(statement,SEMI) RBRACE [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3158,7 +3236,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin If Unit Then Skip Else With ## -## Ends in an error in state: 540. +## Ends in an error in state: 556. ## ## conditional -> If expr Then if_clause option(SEMI) Else . if_clause [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3170,7 +3248,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin If Unit Then Skip SEMI EQ ## -## Ends in an error in state: 539. +## Ends in an error in state: 555. ## ## conditional -> If expr Then if_clause option(SEMI) . Else if_clause [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3182,7 +3260,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin If Unit Then Skip With ## -## Ends in an error in state: 538. +## Ends in an error in state: 554. ## ## conditional -> If expr Then if_clause . option(SEMI) Else if_clause [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3194,7 +3272,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin If Unit Then With ## -## Ends in an error in state: 436. +## Ends in an error in state: 450. ## ## conditional -> If expr Then . if_clause option(SEMI) Else if_clause [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3206,7 +3284,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin If Unit VBAR ## -## Ends in an error in state: 435. +## Ends in an error in state: 449. ## ## conditional -> If expr . Then if_clause option(SEMI) Else if_clause [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3217,23 +3295,23 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin If With ## -## Ends in an error in state: 434. +## Ends in an error in state: 448. ## ## conditional -> If . expr Then if_clause option(SEMI) Else if_clause [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3243,9 +3321,45 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin +contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Constr DOT Ident With +## +## Ends in an error in state: 419. +## +## projection -> Constr DOT Ident . DOT nsepseq(selection,DOT) [ With VBAR SEMI RBRACKET RBRACE End Else ] +## +## The known suffix of the stack is as follows: +## Constr DOT Ident +## + + + +contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Constr DOT With +## +## Ends in an error in state: 418. +## +## projection -> Constr DOT . Ident DOT nsepseq(selection,DOT) [ With VBAR SEMI RBRACKET RBRACE End Else ] +## +## The known suffix of the stack is as follows: +## Constr DOT +## + + + +contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Constr With +## +## Ends in an error in state: 417. +## +## projection -> Constr . DOT Ident DOT nsepseq(selection,DOT) [ With VBAR SEMI RBRACKET RBRACE End Else ] +## +## The known suffix of the stack is as follows: +## Constr +## + + + contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident VBAR ## -## Ends in an error in state: 411. +## Ends in an error in state: 425. ## ## map_patch -> Patch path . With ne_injection(Map,binding) [ VBAR SEMI RBRACKET RBRACE End Else ] ## record_patch -> Patch path . With ne_injection(Record,field_assignment) [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3258,14 +3372,14 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 405, spurious reduction of production path -> Ident +## In state 416, spurious reduction of production path -> Ident ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident While ## -## Ends in an error in state: 405. +## Ends in an error in state: 416. ## ## path -> Ident . [ With VBAR SEMI RBRACKET RBRACE End Else ] ## projection -> Ident . DOT nsepseq(selection,DOT) [ With VBAR SEMI RBRACKET RBRACE End Else ] @@ -3278,7 +3392,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Map LBRACKET Unit ARROW Bytes End ## -## Ends in an error in state: 427. +## Ends in an error in state: 441. ## ## ne_injection(Map,binding) -> Map LBRACKET sep_or_term_list(binding,SEMI) . RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3289,26 +3403,26 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 225, spurious reduction of production binding -> expr ARROW expr -## In state 226, spurious reduction of production nsepseq(binding,SEMI) -> binding -## In state 222, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 241, spurious reduction of production binding -> expr ARROW expr +## In state 242, spurious reduction of production nsepseq(binding,SEMI) -> binding +## In state 238, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Map LBRACKET With ## -## Ends in an error in state: 426. +## Ends in an error in state: 440. ## ## ne_injection(Map,binding) -> Map LBRACKET . sep_or_term_list(binding,SEMI) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3320,7 +3434,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Map Unit ARROW Bytes RBRACKET ## -## Ends in an error in state: 429. +## Ends in an error in state: 443. ## ## ne_injection(Map,binding) -> Map sep_or_term_list(binding,SEMI) . End [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3331,26 +3445,26 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 225, spurious reduction of production binding -> expr ARROW expr -## In state 226, spurious reduction of production nsepseq(binding,SEMI) -> binding -## In state 222, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 241, spurious reduction of production binding -> expr ARROW expr +## In state 242, spurious reduction of production nsepseq(binding,SEMI) -> binding +## In state 238, spurious reduction of production sep_or_term_list(binding,SEMI) -> nsepseq(binding,SEMI) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Map With ## -## Ends in an error in state: 425. +## Ends in an error in state: 439. ## ## ne_injection(Map,binding) -> Map . sep_or_term_list(binding,SEMI) End [ VBAR SEMI RBRACKET RBRACE End Else ] ## ne_injection(Map,binding) -> Map . LBRACKET sep_or_term_list(binding,SEMI) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3363,7 +3477,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Record Ident EQ Bytes RBRACKET ## -## Ends in an error in state: 423. +## Ends in an error in state: 437. ## ## ne_injection(Record,field_assignment) -> Record sep_or_term_list(field_assignment,SEMI) . End [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3374,26 +3488,26 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 367, spurious reduction of production field_assignment -> Ident EQ expr -## In state 372, spurious reduction of production nsepseq(field_assignment,SEMI) -> field_assignment -## In state 371, spurious reduction of production sep_or_term_list(field_assignment,SEMI) -> nsepseq(field_assignment,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 378, spurious reduction of production field_assignment -> Ident EQ expr +## In state 383, spurious reduction of production nsepseq(field_assignment,SEMI) -> field_assignment +## In state 382, spurious reduction of production sep_or_term_list(field_assignment,SEMI) -> nsepseq(field_assignment,SEMI) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Record LBRACKET Ident EQ Bytes End ## -## Ends in an error in state: 421. +## Ends in an error in state: 435. ## ## ne_injection(Record,field_assignment) -> Record LBRACKET sep_or_term_list(field_assignment,SEMI) . RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3404,26 +3518,26 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 367, spurious reduction of production field_assignment -> Ident EQ expr -## In state 372, spurious reduction of production nsepseq(field_assignment,SEMI) -> field_assignment -## In state 371, spurious reduction of production sep_or_term_list(field_assignment,SEMI) -> nsepseq(field_assignment,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 378, spurious reduction of production field_assignment -> Ident EQ expr +## In state 383, spurious reduction of production nsepseq(field_assignment,SEMI) -> field_assignment +## In state 382, spurious reduction of production sep_or_term_list(field_assignment,SEMI) -> nsepseq(field_assignment,SEMI) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Record LBRACKET With ## -## Ends in an error in state: 420. +## Ends in an error in state: 434. ## ## ne_injection(Record,field_assignment) -> Record LBRACKET . sep_or_term_list(field_assignment,SEMI) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3435,7 +3549,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Record With ## -## Ends in an error in state: 419. +## Ends in an error in state: 433. ## ## ne_injection(Record,field_assignment) -> Record . sep_or_term_list(field_assignment,SEMI) End [ VBAR SEMI RBRACKET RBRACE End Else ] ## ne_injection(Record,field_assignment) -> Record . LBRACKET sep_or_term_list(field_assignment,SEMI) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3448,7 +3562,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Set LBRACKET Unit End ## -## Ends in an error in state: 415. +## Ends in an error in state: 429. ## ## ne_injection(Set,expr) -> Set LBRACKET sep_or_term_list(expr,SEMI) . RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3459,25 +3573,25 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 348, spurious reduction of production nsepseq(expr,SEMI) -> expr -## In state 347, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 359, spurious reduction of production nsepseq(expr,SEMI) -> expr +## In state 358, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Set LBRACKET With ## -## Ends in an error in state: 414. +## Ends in an error in state: 428. ## ## ne_injection(Set,expr) -> Set LBRACKET . sep_or_term_list(expr,SEMI) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3489,7 +3603,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Set Unit RBRACKET ## -## Ends in an error in state: 417. +## Ends in an error in state: 431. ## ## ne_injection(Set,expr) -> Set sep_or_term_list(expr,SEMI) . End [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3500,25 +3614,25 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 348, spurious reduction of production nsepseq(expr,SEMI) -> expr -## In state 347, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 359, spurious reduction of production nsepseq(expr,SEMI) -> expr +## In state 358, spurious reduction of production sep_or_term_list(expr,SEMI) -> nsepseq(expr,SEMI) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With Set With ## -## Ends in an error in state: 413. +## Ends in an error in state: 427. ## ## ne_injection(Set,expr) -> Set . sep_or_term_list(expr,SEMI) End [ VBAR SEMI RBRACKET RBRACE End Else ] ## ne_injection(Set,expr) -> Set . LBRACKET sep_or_term_list(expr,SEMI) RBRACKET [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3531,7 +3645,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch Ident With With ## -## Ends in an error in state: 412. +## Ends in an error in state: 426. ## ## map_patch -> Patch path With . ne_injection(Map,binding) [ VBAR SEMI RBRACKET RBRACE End Else ] ## record_patch -> Patch path With . ne_injection(Record,field_assignment) [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3545,7 +3659,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Patch With ## -## Ends in an error in state: 410. +## Ends in an error in state: 424. ## ## map_patch -> Patch . path With ne_injection(Map,binding) [ VBAR SEMI RBRACKET RBRACE End Else ] ## record_patch -> Patch . path With ne_injection(Record,field_assignment) [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3559,7 +3673,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Remove Unit From Map With ## -## Ends in an error in state: 408. +## Ends in an error in state: 422. ## ## map_remove -> Remove expr From Map . path [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3571,7 +3685,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Remove Unit From Set With ## -## Ends in an error in state: 404. +## Ends in an error in state: 415. ## ## set_remove -> Remove expr From Set . path [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3583,7 +3697,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Remove Unit From With ## -## Ends in an error in state: 403. +## Ends in an error in state: 414. ## ## map_remove -> Remove expr From . Map path [ VBAR SEMI RBRACKET RBRACE End Else ] ## set_remove -> Remove expr From . Set path [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3596,7 +3710,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Remove Unit VBAR ## -## Ends in an error in state: 402. +## Ends in an error in state: 413. ## ## map_remove -> Remove expr . From Map path [ VBAR SEMI RBRACKET RBRACE End Else ] ## set_remove -> Remove expr . From Set path [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3608,23 +3722,23 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Remove With ## -## Ends in an error in state: 401. +## Ends in an error in state: 412. ## ## map_remove -> Remove . expr From Map path [ VBAR SEMI RBRACKET RBRACE End Else ] ## set_remove -> Remove . expr From Set path [ VBAR SEMI RBRACKET RBRACE End Else ] @@ -3637,7 +3751,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Skip End While ## -## Ends in an error in state: 548. +## Ends in an error in state: 564. ## ## open_fun_decl -> Function Ident parameters COLON type_expr Is block . With expr [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -3649,7 +3763,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Skip End With With ## -## Ends in an error in state: 549. +## Ends in an error in state: 565. ## ## open_fun_decl -> Function Ident parameters COLON type_expr Is block With . expr [ Type SEMI RBRACE Function End EOF Const Attributes ] ## @@ -3661,7 +3775,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Skip RBRACE ## -## Ends in an error in state: 542. +## Ends in an error in state: 558. ## ## block -> Begin sep_or_term_list(statement,SEMI) . End [ With VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3672,15 +3786,15 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 520, spurious reduction of production nsepseq(statement,SEMI) -> statement -## In state 537, spurious reduction of production sep_or_term_list(statement,SEMI) -> nsepseq(statement,SEMI) +## In state 536, spurious reduction of production nsepseq(statement,SEMI) -> statement +## In state 553, spurious reduction of production sep_or_term_list(statement,SEMI) -> nsepseq(statement,SEMI) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Skip SEMI Skip SEMI With ## -## Ends in an error in state: 523. +## Ends in an error in state: 539. ## ## nsepseq(statement,SEMI) -> statement SEMI . nsepseq(statement,SEMI) [ RBRACE End ] ## seq(__anonymous_0(statement,SEMI)) -> statement SEMI . seq(__anonymous_0(statement,SEMI)) [ RBRACE End ] @@ -3693,7 +3807,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Skip SEMI Skip With ## -## Ends in an error in state: 522. +## Ends in an error in state: 538. ## ## nsepseq(statement,SEMI) -> statement . [ RBRACE End ] ## nsepseq(statement,SEMI) -> statement . SEMI nsepseq(statement,SEMI) [ RBRACE End ] @@ -3707,7 +3821,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Skip SEMI With ## -## Ends in an error in state: 521. +## Ends in an error in state: 537. ## ## nsepseq(statement,SEMI) -> statement SEMI . nsepseq(statement,SEMI) [ RBRACE End ] ## nseq(__anonymous_0(statement,SEMI)) -> statement SEMI . seq(__anonymous_0(statement,SEMI)) [ RBRACE End ] @@ -3720,7 +3834,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Skip With ## -## Ends in an error in state: 520. +## Ends in an error in state: 536. ## ## nsepseq(statement,SEMI) -> statement . [ RBRACE End ] ## nsepseq(statement,SEMI) -> statement . SEMI nsepseq(statement,SEMI) [ RBRACE End ] @@ -3734,7 +3848,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Var Ident COLON Ident ASS With ## -## Ends in an error in state: 397. +## Ends in an error in state: 408. ## ## unqualified_decl(ASS) -> Ident COLON type_expr ASS . expr [ SEMI RBRACE End ] ## @@ -3746,7 +3860,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Var Ident COLON Ident VBAR ## -## Ends in an error in state: 396. +## Ends in an error in state: 407. ## ## unqualified_decl(ASS) -> Ident COLON type_expr . ASS expr [ SEMI RBRACE End ] ## @@ -3767,7 +3881,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Var Ident COLON With ## -## Ends in an error in state: 395. +## Ends in an error in state: 406. ## ## unqualified_decl(ASS) -> Ident COLON . type_expr ASS expr [ SEMI RBRACE End ] ## @@ -3779,7 +3893,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Var Ident With ## -## Ends in an error in state: 394. +## Ends in an error in state: 405. ## ## unqualified_decl(ASS) -> Ident . COLON type_expr ASS expr [ SEMI RBRACE End ] ## @@ -3791,7 +3905,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin Var With ## -## Ends in an error in state: 393. +## Ends in an error in state: 404. ## ## open_var_decl -> Var . unqualified_decl(ASS) [ SEMI RBRACE End ] ## @@ -3803,7 +3917,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin While Unit VBAR ## -## Ends in an error in state: 391. +## Ends in an error in state: 402. ## ## while_loop -> While expr . block [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3814,23 +3928,23 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin While With ## -## Ends in an error in state: 390. +## Ends in an error in state: 401. ## ## while_loop -> While . expr block [ VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3842,7 +3956,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin With ## -## Ends in an error in state: 392. +## Ends in an error in state: 403. ## ## block -> Begin . sep_or_term_list(statement,SEMI) End [ With VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3854,7 +3968,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Begin contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Block LBRACE Skip End ## -## Ends in an error in state: 545. +## Ends in an error in state: 561. ## ## block -> Block LBRACE sep_or_term_list(statement,SEMI) . RBRACE [ With VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3865,15 +3979,15 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Block ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 520, spurious reduction of production nsepseq(statement,SEMI) -> statement -## In state 537, spurious reduction of production sep_or_term_list(statement,SEMI) -> nsepseq(statement,SEMI) +## In state 536, spurious reduction of production nsepseq(statement,SEMI) -> statement +## In state 553, spurious reduction of production sep_or_term_list(statement,SEMI) -> nsepseq(statement,SEMI) ## contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Block LBRACE With ## -## Ends in an error in state: 389. +## Ends in an error in state: 400. ## ## block -> Block LBRACE . sep_or_term_list(statement,SEMI) RBRACE [ With VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3885,7 +3999,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Block contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Block With ## -## Ends in an error in state: 388. +## Ends in an error in state: 399. ## ## block -> Block . LBRACE sep_or_term_list(statement,SEMI) RBRACE [ With VBAR SEMI RBRACKET RBRACE End Else ] ## @@ -3897,7 +4011,7 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Block contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Bytes VBAR ## -## Ends in an error in state: 552. +## Ends in an error in state: 568. ## ## fun_decl -> open_fun_decl . option(SEMI) [ Type Function EOF Const Attributes ] ## @@ -3908,17 +4022,17 @@ contract: Function Ident LPAR Const Ident COLON Ident RPAR COLON Ident Is Bytes ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 174, spurious reduction of production unary_expr -> core_expr -## In state 126, spurious reduction of production mult_expr -> unary_expr -## In state 152, spurious reduction of production add_expr -> mult_expr -## In state 180, spurious reduction of production cons_expr -> add_expr -## In state 177, spurious reduction of production cat_expr -> cons_expr -## In state 200, spurious reduction of production comp_expr -> cat_expr -## In state 187, spurious reduction of production set_membership -> comp_expr -## In state 128, spurious reduction of production conj_expr -> set_membership -## In state 204, spurious reduction of production disj_expr -> conj_expr -## In state 172, spurious reduction of production expr -> disj_expr -## In state 547, spurious reduction of production open_fun_decl -> Function Ident parameters COLON type_expr Is expr +## In state 190, spurious reduction of production unary_expr -> core_expr +## In state 140, spurious reduction of production mult_expr -> unary_expr +## In state 166, spurious reduction of production add_expr -> mult_expr +## In state 196, spurious reduction of production cons_expr -> add_expr +## In state 193, spurious reduction of production cat_expr -> cons_expr +## In state 216, spurious reduction of production comp_expr -> cat_expr +## In state 203, spurious reduction of production set_membership -> comp_expr +## In state 142, spurious reduction of production conj_expr -> set_membership +## In state 220, spurious reduction of production disj_expr -> conj_expr +## In state 188, spurious reduction of production expr -> disj_expr +## In state 563, spurious reduction of production open_fun_decl -> Function Ident parameters COLON type_expr Is expr ## From 127a85822ff32aa2a2e2aef666b8edb6d3375f9c Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Wed, 26 Feb 2020 18:31:58 +0100 Subject: [PATCH 09/53] More updates to the documentation. Synced the new reference page. --- .../docs/language-basics/maps-records.md | 14 +- .../docs/language-basics/math-numbers-tez.md | 43 +- .../docs/language-basics/sets-lists-tuples.md | 24 +- gitlab-pages/docs/reference/big_map.md | 193 +++------ gitlab-pages/docs/reference/current.md | 256 +++++++----- gitlab-pages/docs/reference/list.md | 144 ++----- gitlab-pages/docs/reference/map.md | 371 +++++++++++------- gitlab-pages/docs/reference/set.md | 329 ++++++++-------- 8 files changed, 694 insertions(+), 680 deletions(-) diff --git a/gitlab-pages/docs/language-basics/maps-records.md b/gitlab-pages/docs/language-basics/maps-records.md index f1b491b60..c9837fb26 100644 --- a/gitlab-pages/docs/language-basics/maps-records.md +++ b/gitlab-pages/docs/language-basics/maps-records.md @@ -458,8 +458,7 @@ let force_access = ((key, moves) : (address, register)) : move => { ### Updating a Map Given a map, we may want to add a new binding, remove one, or modify -one by changing the value associated to an already existing key. We -may even want to retain the key but not the associated value. All +one by changing the value associated to an already existing key. All those operations are called *updates*. @@ -733,21 +732,18 @@ Here is how we define a big map: ```pascaligo group=big_maps type move is int * int - type register is big_map (address, move) ``` ```cameligo group=big_maps type move = int * int - type register = (address, move) big_map ``` ```reasonligo group=big_maps type move = (int, int); - type register = big_map (address, move); ``` @@ -789,10 +785,10 @@ const moves : register = ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] ``` - Notice the right arrow `->` between the key and its value and the --> - semicolon separating individual map entries. The value annotation --> - `("" : address)` means that we cast a string into an --> - address. --> +Notice the right arrow `->` between the key and its value and the +semicolon separating individual map entries. The value annotation +`("" : address)` means that we cast a string into an +address. --> diff --git a/gitlab-pages/docs/language-basics/math-numbers-tez.md b/gitlab-pages/docs/language-basics/math-numbers-tez.md index 7d8c2342a..31bdeb872 100644 --- a/gitlab-pages/docs/language-basics/math-numbers-tez.md +++ b/gitlab-pages/docs/language-basics/math-numbers-tez.md @@ -213,7 +213,7 @@ let c : tez = 5n * 5mutez; -## Division +## Euclidean Division In LIGO you can divide `int`, `nat`, and `tez`. Here is how: @@ -243,6 +243,46 @@ let c : nat = 10mutez / 3mutez; +LIGO also allows you to compute the remainder of the Euclidean +division. In LIGO, it is a natural number. + + + +```pascaligo group=d +const a : int = 120 +const b : int = 9 +const rem1 : nat = a mod b // 3 +const c : nat = 120n +const rem2 : nat = c mod b // 3 +const d : nat = 9n +const rem3 : nat = c mod d // 3 +const rem4 : nat = a mod d // 3 +``` + + +```cameligo group=d +let a : int = 120 +let b : int = 9 +let rem1 : nat = a mod b // 3 +let c : nat = 120n +let rem2 : nat = c mod b // 3 +let d : nat = 9n +let rem3 : nat = c mod d // 3 +let rem4 : nat = a mod d // 3 +``` + + +```reasonligo group=d +let a : int = 120; +let b : int = 9; +let rem1 : nat = a mod b; // 3 +let c : nat = 120n; +let rem2 : nat = c mod b; // 3 +let d : nat = 9n; +let rem3 : nat = c mod d; // 3 +let rem4 : nat = a mod d; // 3 +``` + ## From `int` to `nat` and back You can *cast* an `int` to a `nat` and vice versa. Here is how: @@ -265,7 +305,6 @@ let b : nat = abs (1) let a : int = int (1n); let b : nat = abs (1); ``` - ## Checking a `nat` diff --git a/gitlab-pages/docs/language-basics/sets-lists-tuples.md b/gitlab-pages/docs/language-basics/sets-lists-tuples.md index abf8b4b20..8bcb192f6 100644 --- a/gitlab-pages/docs/language-basics/sets-lists-tuples.md +++ b/gitlab-pages/docs/language-basics/sets-lists-tuples.md @@ -124,7 +124,6 @@ let my_list : list (int) = [1, 2, 2]; // The head is 1 - ### Adding to Lists Lists can be augmented by adding an element before the head (or, in @@ -176,15 +175,16 @@ There are three kinds of functional iterations over LIGO lists: the *iterated operation*, the *map operation* (not to be confused with the *map data structure*) and the *fold operation*. - #### Iterated Operation over Lists The first, the *iterated operation*, is an iteration over the list with a unit return value. It is useful to enforce certain invariants -on the element of a list, or fail. For example you might want to check -that each value inside of a list is within a certain range, and fail -otherwise. The predefined functional iterator implementing the -iterated operation over lists is called `List.iter`. +on the element of a list, or fail. + +For example you might want to check that each value inside of a list +is within a certain range, and fail otherwise. The predefined +functional iterator implementing the iterated operation over lists is +called `List.iter`. In the following example, a list is iterated to check that all its elements (integers) are strictly greater than `3`. @@ -305,7 +305,7 @@ let sum_of_elements : int = List.fold (sum, my_list, 0); Sets are unordered collections of values of the same type, like lists are ordered collections. Like the mathematical sets and lists, sets can be empty and, if not, elements of sets in LIGO are *unique*, -whereas they can be repeated in a list. +whereas they can be repeated in a *list*. ### Empty Sets @@ -447,6 +447,9 @@ elements in a given set as follows. ```pascaligo group=sets const cardinal : nat = Set.size (my_set) ``` + +> Note that `size` is *deprecated*. + ```cameligo group=sets @@ -636,12 +639,9 @@ traversal of the data structure is over. The predefined fold over sets is called `Set.fold`. - - ```pascaligo group=sets function sum (const acc : int; const i : int): int is acc + i - const sum_of_elements : int = Set.fold (sum, my_set, 0) ``` @@ -659,18 +659,14 @@ function loop (const s : set (int)) : int is block { ``` - ```cameligo group=sets let sum (acc, i : int * int) : int = acc + i - let sum_of_elements : int = Set.fold sum my_set 0 ``` - ```reasonligo group=sets let sum = ((acc, i) : (int, int)) : int => acc + i; - let sum_of_elements : int = Set.fold (sum, my_set, 0); ``` diff --git a/gitlab-pages/docs/reference/big_map.md b/gitlab-pages/docs/reference/big_map.md index fa0fa3ebc..57f222dc0 100644 --- a/gitlab-pages/docs/reference/big_map.md +++ b/gitlab-pages/docs/reference/big_map.md @@ -1,137 +1,117 @@ --- id: big-map-reference -title: Big Map — Scalable Maps +title: Big Maps — Scalable Maps --- -## Defining A Big Map Type +Ordinary maps are fine for contracts with a finite lifespan or a +bounded number of users. For many contracts however, the intention is +to have a map holding *many* entries, potentially millions of +them. The cost of loading those entries into the environment each time +a user executes the contract would eventually become too expensive +were it not for *big maps*. Big maps are a data structure offered by +Michelson which handles the scaling concerns for us. In LIGO, the +interface for big maps is analogous to the one used for ordinary maps. + +# Declaring a Map - -```pascaligo group=big_map + +```pascaligo group=big_maps type move is int * int type register is big_map (address, move) ``` -```cameligo group=big_map +```cameligo group=big_maps type move = int * int type register = (address, move) big_map ``` -```reasonligo group=big_map +```reasonligo group=big_maps type move = (int, int); type register = big_map (address, move); ``` - -## Creating an Empty Big Map -Create an empty big map. +# Creating an Empty Big Map -```pascaligo group=big_map +```pascaligo group=big_maps const empty : register = big_map [] ``` -```cameligo group=big_map +```cameligo group=big_maps let empty : register = Big_map.empty ``` -```reasonligo group=big_map +```reasonligo group=big_maps let empty : register = Big_map.empty ``` - -## Populating A Big Map +# Creating a Non-empty Map - -```pascaligo group=big_map -const moves: register = + +```pascaligo group=big_maps +const moves : register = big_map [ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2); ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] ``` - -```cameligo group=big_map -let moves: register = +```cameligo group=big_maps +let moves : register = Big_map.literal [ (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2)); (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))] ``` - -```reasonligo group=big_map -let moves: register = +```reasonligo group=big_maps +let moves : register = Big_map.literal ([ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]); ``` - -## Retrieving a Value in a Big Map - -Retrieve the value associated with a particular key. This version -returns an option which can either shift logic in response to a -missing value or throw an error. +# Accessing Values - -```pascaligo group=big_map + +```pascaligo group=big_maps const my_balance : option (move) = moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] ``` - -The function is `Big_map.find_opt` whose type is `'key -> -('key,'value) big_map) -> 'value option`. Recall that the function -`Big_map.find_opt` must always be fully applied to its arguments. Here -is an example: - -```cameligo group=big_map +```cameligo group=big_maps let my_balance : move option = Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves ``` - -The function is `Big_map.find_opt` whose type is `('key, ('key, -'value) big_map) : 'value option`. Here is an example: - -```reasonligo group=big_map +```reasonligo group=big_maps let my_balance : option (move) = Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves); ``` -## Updating a Binding in a Big Map -Given a map, we may want to add a new binding, remove one, or modify -one by changing the value associated to an already existing key. We -may even want to retain the key but not the associated value. All -those operations are called *updates*. +# Updating Big Maps - - - -The values of a PascaLIGO big map can be updated using the ordinary -assignment syntax: - -```pascaligo group=big_map + +```pascaligo group=big_maps function add (var m : register) : register is block { m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) @@ -140,114 +120,45 @@ function add (var m : register) : register is const updated_map : register = add (moves) ``` -See further for the removal of bindings. - - - -In CameLIGO, you need the predefined function `Big_map.update` whose -type is `'key -> 'value option -> ('key, 'value) big_map -> ('key, -'value) big_map`. If the value (second argument) is `None`, then the -binding is to be removed. Recall that the function `Big_map.update` -must always be fully applied to its arguments. Here is an example: - -```cameligo group=big_map + +```cameligo group=big_maps let updated_map : register = Big_map.update ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves ``` - - -In ReasonLIGO, you need the predefined function `Big_map.update` whose -type is `('key, 'value option, ('key, 'value) big_map) : ('key, -'value) big_map`. If the value (second componenat) is `None`, then the -binding is to be removed. Here is an example: - -```reasonligo group=big_map + +```reasonligo group=big_maps let updated_map : register = Big_map.update (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves); ``` - -## Adding a Binding to a Big Map - -Add a key and its associated value to the big map. - - - -```pascaligo group=big_map -function add (var m : register) : register is - block { - m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) - } with m - -const updated_map : register = add (moves) -``` - - - -In CameLIGO, we use the predefined function `Big_map.add`, whose type -is `'key -> 'value -> ('key, 'value) big_map -> ('key, 'value) -big_map`. Recall that the function `Big_map.add` must always be fully -applied to its arguments. Here is an example: - -```cameligo group=big_map -let add (m : register) : register = - Map.add - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m -``` - - - -In ReasonLIGO, we use the predefined function `Big_map.add`, whose -type is `('key, 'value, ('key, 'value) big_map : ('key, 'value) -big_map`. Here is an example: - -```reasonligo group=big_map -let add = (m : register) : register => - Map.add - (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m); -``` - - - -## Removing a Binding from a Big Map - -Remove a key and its associated value from the big map. +# Removing Bindings -```pascaligo group=big_map -function delete (const key : address; var moves : register) : register is +```pascaligo group=big_maps +function rem (var m : register) : register is block { - remove key from map moves - } with moves + remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) from map moves + } with m + +const updated_map : register = rem (moves) ``` - -In CameLIGO, we use the predefined function `Big_map.remove` whose -type is `'key -> ('key, 'value) big_map -> ('key, 'value) -big_map`. Note that, despite being curried, the calls to that function -must be complete. Here is an example: - -```cameligo group=big_map -let delete (key, moves : address * register) : register = - Map.remove key moves +```cameligo group=big_maps +let updated_map : register = + Map.remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves ``` - -In ReasonLIGO, we use the predefined function `Big_map.remove` whose -type is `('key, ('key, 'value) big_map) : ('key, 'value) -big_map`. Here is an example: - -```reasonligo group=big_map -let delete = ((key, moves) : (address, register)) : register => - Map.remove (key, moves); +```reasonligo group=big_maps +let updated_map : register = + Map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves) ``` diff --git a/gitlab-pages/docs/reference/current.md b/gitlab-pages/docs/reference/current.md index c9f1945d8..53fec4d7d 100644 --- a/gitlab-pages/docs/reference/current.md +++ b/gitlab-pages/docs/reference/current.md @@ -1,9 +1,9 @@ --- id: current-reference -title: Current - Things relating to the current execution context +title: Tezos - Things relating to the current execution context --- -## Current.balance() : tez +# Tezos.balance Get the balance for the contract. @@ -11,26 +11,36 @@ Get the balance for the contract. ```pascaligo -function main (const p : unit; const s: tez) : list(operation) * tez is - ((nil : list(operation)), balance) +function main (const p : unit; const s: tez) : list (operation) * tez is + ((nil : list (operation)), Tezos.balance) ``` + +> Note that `balance` and `Current.balance` are *deprecated*. + ```cameligo -let main (p, s : unit * tez) = - ([] : operation list), balance +let main (p,s : unit * tez) = ([] : operation list), Tezos.balance ``` + +> Note that `balance` and `Current.balance` are *deprecated*. + ```reasonligo -let main = ((p,s): (unit, tez)) => ([]: list(operation), balance); +let main = ((p,s) : (unit, tez)) => + ([]: list (operation), Tezos.balance); ``` +> Note that `balance` and `Current.balance` are *deprecated*. + -## Current.time() : timestamp +## Tezos.now -Returns the current time as a [unix timestamp](https://en.wikipedia.org/wiki/Unix_time). +Returns the current time as a [unix timestamp](https://en.wikipedia.org/wiki/Unix_time). -In LIGO, timestamps are type compatible in operations with `int`(s). This lets you set e.g. time constraints for your smart contracts like this: +In LIGO, timestamps are type compatible in operations with +integers. This lets you set for instance time constraints for your +smart contracts like this: ### Examples @@ -38,118 +48,134 @@ In LIGO, timestamps are type compatible in operations with `int`(s). This lets y ```pascaligo group=b -const today: timestamp = now; -const one_day: int = 86400; +const today: timestamp = Tezos.now; +const one_day: int = 86_400; const in_24_hrs: timestamp = today + one_day; const some_date: timestamp = ("2000-01-01T10:10:10Z" : timestamp); const one_day_later: timestamp = some_date + one_day; ``` +> Note that `now` is *deprecated*. + ```cameligo group=b -let today: timestamp = Current.time -let one_day: int = 86400 +let today: timestamp = Tezos.now +let one_day: int = 86_400 let in_24_hrs: timestamp = today + one_day let some_date: timestamp = ("2000-01-01t10:10:10Z" : timestamp) let one_day_later: timestamp = some_date + one_day ``` +> Note that `Current.time` is *deprecated*. + ```reasonligo group=b -let today: timestamp = Current.time; -let one_day: int = 86400; +let today: timestamp = Tezos.now; +let one_day: int = 86_400; let in_24_hrs: timestamp = today + one_day; let some_date: timestamp = ("2000-01-01t10:10:10Z" : timestamp); let one_day_later: timestamp = some_date + one_day; ``` +> Note that `Current.time` is *deprecated*. + #### 24 hours ago + ```pascaligo group=c -const today: timestamp = now; -const one_day: int = 86400; +const today: timestamp = Tezos.now; +const one_day: int = 86_400; const in_24_hrs: timestamp = today - one_day; ``` +> Note that `now` is *deprecated*. + ```cameligo group=c -let today: timestamp = Current.time -let one_day: int = 86400 +let today: timestamp = Tezos.now +let one_day: int = 86_400 let in_24_hrs: timestamp = today - one_day ``` +> Note that `Current.time` is *deprecated*. + ```reasonligo group=c -let today: timestamp = Current.time; -let one_day: int = 86400; +let today: timestamp = Tezos.now; +let one_day: int = 86_400; let in_24_hrs: timestamp = today - one_day; ``` +> Note that `Current.time` is *deprecated*. + -#### Comparing timestamps +#### Comparing Timestamps -You can also compare timestamps using the same comparison operators as for numbers: +You can also compare timestamps using the same comparison operators as +for numbers ```pascaligo group=c -const not_tommorow: bool = (now = in_24_hrs) +const not_tommorow: bool = (Tezos.now = in_24_hrs) ``` +> Note that `now` is *deprecated*. + ```cameligo group=c -let not_tomorrow: bool = (Current.time = in_24_hrs) +let not_tomorrow: bool = (Tezos.now = in_24_hrs) ``` +> Note that `Current.time` is *deprecated*. + ```reasonligo group=c -let not_tomorrow: bool = (Current.time == in_24_hrs); +let not_tomorrow: bool = (Tezos.now == in_24_hrs); ``` +> Note that `Current.time` is *deprecated*. + -## Current.amount() : tez +## Amount -Get the amount of tez provided by the sender to complete this transaction. +Get the amount of tez provided by the sender to complete this +transaction. ```pascaligo -function check (const p: unit) : int is - begin - var result : int := 0; - if amount = 100tz then - result := 42 - else - result := 0 - end with result +function threshold (const p : unit) : int is + if Tezos.amount = 100tz then 42 else 0 ``` +> Note that `amount` is *deprecated*. + ```cameligo -let check_ (p: unit) : int = if Current.amount = 100tz then 42 else 0 +let threshold (p : unit) : int = if Tezos.amount = 100tz then 42 else 0 ``` +> Note that `Current.amount` is *deprecated*. + ```reasonligo -let check_ = (p: unit) : int => - if (Current.amount == 100tz) { - 42; - } - else { - 0; - }; +let threshold = (p : unit) : int => + if (Tezos.amount == 100tz) { 42; } else { 0; }; ``` +> Note that `Current.amount` is *deprecated*. + -## Current.sender() : address +## Sender Get the address that initiated the current transaction. @@ -157,52 +183,67 @@ Get the address that initiated the current transaction. ```pascaligo -function main (const p: unit) : address is sender +function main (const p : unit) : address is Tezos.sender ``` +> Note that `sender` is *deprecated*. + ```cameligo -let main (p: unit) : address = Current.sender +let main (p: unit) : address = Tezos.sender ``` +> Note that `Current.sender` is *deprecated*. + ```reasonligo -let main = (p: unit) : address => Current.sender; +let main = (p : unit) : address => Tezos.sender; ``` +> Note that `Current.sender` is *deprecated*. + -## Current.address(c: a' contract) : address -Get the address associated with a `contract`. +## Address + +Get the address associated with a value of type `contract`. ```pascaligo function main (const p : key_hash) : address is block { - const c : contract(unit) = implicit_account(p) ; -} with address(c) + const c : contract (unit) = Tezos.implicit_account (p) +} with Tezos.address(c) ``` +> Note that `implicit_account` and `address` are *deprecated*. + ```cameligo let main (p : key_hash) = - let c : unit contract = Current.implicit_account p in - Current.address c + let c : unit contract = Tezos.implicit_account p + in Tezos.address c ``` +> Note that `Current.implicit_account` and `Current.address` are +> *deprecated*. + ```reasonligo let main = (p : key_hash) : address => { - let c : contract(unit) = Current.implicit_account(p) ; - Current.address(c) ; + let c : contract (unit) = Tezos.implicit_account (p); + Tezos.address (c); }; ``` +> Note that `Current.implicit_account` and `Current.address` are +> *deprecated*. + -## Current.self_address() : address +## Self Address Get the address of the currently running contract. @@ -210,110 +251,137 @@ Get the address of the currently running contract. ```pascaligo -function main (const p: unit) : address is self_address +function main (const p : unit) : address is Tezos.self_address ``` +> Note that `self_address` is *deprecated*. + ```cameligo -let main (p: unit) : address = Current.self_address +let main (p : unit) : address = Tezos.self_address ``` +> Note that `Current.self_address` is *deprecated*. + ```reasonligo -let main = (p: unit): address => Current.self_address; +let main = (p : unit) : address => Tezos.self_address; ``` +> Note that `Current.self_address` is *deprecated*. + -## Current.implicit_account(p: key_hash) : a' contract +## Implicit Account -Get the default contract associated with an on-chain keypair. This contract -doesn't execute code, instead it exists to receive money on behalf of a keys -owner. +Get the default contract associated with an on-chain key-pair. This +contract does not execute code, instead it exists to receive tokens on +behalf of a key's owner. ```pascaligo -function main (const kh: key_hash) : contract(unit) is implicit_account(kh) +function main (const kh: key_hash) : contract (unit) is + Tezos.implicit_account (kh) ``` +> Note that `implicit_account` is *deprecated*. + ```cameligo -let main (kh: key_hash) : unit contract = Current.implicit_account kh +let main (kh : key_hash) : unit contract = Tezos.implicit_account kh ``` +> Note that `Current.implicit_account` is *deprecated*. + ```reasonligo -let main = (kh: key_hash): contract(unit) => Current.implicit_account(kh); +let main = (kh : key_hash): contract (unit) => + Tezos.implicit_account (kh); ``` +> Note that `Current.implicit_account` is *deprecated*. + -## Current.source() : address +## Source -Get the _originator_ of the current transaction. That is, if a chain of transactions -led to the current execution get the address that began the chain. Not to be confused -with `Current.sender`, which gives the address of the contract or user which directly -caused the current transaction. +Get the _originator_ (address) of the current transaction. That is, if +a chain of transactions led to the current execution get the address +that began the chain. Not to be confused with `Tezos.sender`, which +gives the address of the contract or user which directly caused the +current transaction. -> ⚠️ -> There are a few caveats you should keep in mind before using `SOURCE` over `SENDER`: +> ⚠️ There are a few caveats you should keep in mind before using +> `Tezos.source` over `Tezos.sender`: > -> 1. SOURCE will never be a contract, so if you want to allow contracts (multisigs etc) to operate your contract, you need to use SENDER -> 2. https://vessenes.com/tx-origin-and-ethereum-oh-my/ -- in general it is somewhat unsafe to assume that SOURCE understands everything that's going to happen in a transaction. If SOURCE transfers to a malicious (or sufficiently attackable) contract, that contract might potentially transfer to yours, without SOURCE's consent. So if you are using SOURCE for authentication, you risk being confused. A good historical example of this is bakers paying out delegation rewards. Naive bakers did (and probably still do) just use tezos-client to transfer to whatever KT1 delegates they had, even if those KT1 were malicious scripts. +> 1. `Tezos.source` will never be a contract, so if you want to allow +> contracts (multisigs etc) to operate your contract, you need to +> use `Tezos.sender` +> 2. https://vessenes.com/tx-origin-and-ethereum-oh-my/ -- in general +> it is somewhat unsafe to assume that `Tezos.source` understands +> everything that is going to happen in a transaction. If +> `Tezos.source` transfers to a malicious (or sufficiently +> attackable) contract, that contract might potentially transfer to +> yours, without `Tezos.source`'s consent. So if you are using +> `Tezos.source` for authentication, you risk being confused. A +> good historical example of this is bakers paying out delegation +> rewards. Naive bakers did (and probably still do) just use +> tezos-client to transfer to whatever KT1 delegates they had, even +> if those KT1 were malicious scripts. ```pascaligo -function main (const p: unit) : address is source +function main (const p: unit) : address is Tezos.source ``` +> Note that `source` is *deprecated*. + ```cameligo -let main (p: unit) : address = Current.source +let main (p : unit) : address = Tezos.source ``` +> Note that `Current.source` is *deprecated*. + ```reasonligo -let main = (p: unit) : address => Current.source; +let main = (p : unit) : address => Tezos.source; ``` +> Note that `Current.source` is *deprecated*. -## Current.failwith(error_message: string) : a' +## Failwith Cause the contract to fail with an error message. -> ⚠ Using this currently requires a type annotation on the failwith to unify it -> with the type of whatever other code branch it's on. +> ⚠ Using this currently requires in general a type annotation on the +> `failwith` call. ```pascaligo -function main (const p : int; const s : unit) : list(operation) * unit is +function main (const p : int; const s : unit) : list (operation) * unit is block { - if p > 10 then failwith("fail") else skip; + if p > 10 then failwith ("Failure.") else skip } - with ((nil : list(operation)), s) + with ((nil : list (operation)), s) ``` ```cameligo -let main (p,s: unit * unit) = - if true then failwith "This contract always fails" else () +let main (p,s : int * unit) = if p > 10 then failwith "Failure." ``` ```reasonligo -let main = ((p,s): (unit, unit)) => - if (true) { - failwith("This contract always fails"); - } else { - (); - }; +let main = ((p,s) : (int, unit)) => + if (p > 10) { failwith ("Failure."); }; ``` diff --git a/gitlab-pages/docs/reference/list.md b/gitlab-pages/docs/reference/list.md index 1c34215fe..96d733d50 100644 --- a/gitlab-pages/docs/reference/list.md +++ b/gitlab-pages/docs/reference/list.md @@ -1,6 +1,6 @@ --- id: list-reference -title: List — Linear Collections +title: Lists — Linear Collections --- Lists are linear collections of elements of the same type. Linear @@ -11,7 +11,7 @@ called the *head*, and the sub-list after the head is called the *tail*. For those familiar with algorithmic data structure, you can think of a list a *stack*, where the top is written on the left. -## Defining Lists +# Defining Lists @@ -34,7 +34,7 @@ let my_list : list (int) = [1, 2, 2]; // The head is 1 -### Adding to Lists +# Adding to Lists Lists can be augmented by adding an element before the head (or, in terms of stack, by *pushing an element on top*). @@ -61,7 +61,7 @@ let larger_list : list (int) = [5, ...my_list]; // [5,1,2,2] -### Functional Iteration over Lists +# Functional Iteration over Lists A *functional iterator* is a function that traverses a data structure and calls in turn a given function over the elements of that structure @@ -72,7 +72,7 @@ There are three kinds of functional iterations over LIGO lists: the *iterated operation*, the *map operation* (not to be confused with the *map data structure*) and the *fold operation*. -#### Iterated Operation over Lists +## Iterated Operation over Lists The first, the *iterated operation*, is an iteration over the list with a unit return value. It is useful to enforce certain invariants @@ -86,9 +86,13 @@ on the element of a list, or fail. function iter_op (const l : list (int)) : unit is block { function iterated (const i : int) : unit is - if i > 2 then Unit else (failwith ("Below range.") : unit) - } with list_iter (iterated, l) + if i > 3 then Unit else (failwith ("Below range.") : unit) + } with List.iter (iterated, l) ``` + +> Note that `list_iter` is *deprecated*. + + ```cameligo group=lists @@ -108,7 +112,7 @@ let iter_op = (l : list (int)) : unit => { -#### Mapped Operation over Lists +## Mapped Operation over Lists We may want to change all the elements of a given list by applying to them a function. This is called a *map operation*, not to be confused @@ -122,9 +126,11 @@ with the map data structure. function increment (const i : int): int is i + 1 // Creates a new list with all elements incremented by 1 -const plus_one : list (int) = list_map (increment, larger_list) +const plus_one : list (int) = List.map (increment, larger_list) ``` +> Note that `list_map` is *deprecated*. + ```cameligo group=lists @@ -144,7 +150,8 @@ let plus_one : list (int) = List.map (increment, larger_list); ``` -#### Folded Operation over Lists + +## Folded Operation over Lists A *folded operation* is the most general of iterations. The folded function takes two arguments: an *accumulator* and the structure @@ -158,9 +165,11 @@ traversal of the data structure is over. ```pascaligo group=lists function sum (const acc : int; const i : int): int is acc + i -const sum_of_elements : int = list_fold (sum, my_list, 0) +const sum_of_elements : int = List.fold (sum, my_list, 0) ``` +> Note that `list_fold` is *deprecated*. + ```cameligo group=lists @@ -176,7 +185,7 @@ let sum_of_elements : int = List.fold (sum, my_list, 0); ``` -## List Length +# List Length Get the number of elements in a list. @@ -187,6 +196,8 @@ Get the number of elements in a list. function size_of (const l : list (int)) : nat is List.length (l) ``` +> Note that `size` is *deprecated*. + ```cameligo let size_of (l : int list) : nat = List.length l @@ -198,112 +209,3 @@ let size_of = (l : list (int)) : nat => List.length (l); ``` - -## List.map(map_function: a' -> b', lst: a' list) : 'b list - -Apply an operation defined by `map_function` to each element of a list -and return a list of the modified elements. - - - -```pascaligo group=b -function increment(const i: int): int is i + 1; -// Creates a new list with elements incremented by 1 -const incremented_list: list(int) = list_map(increment, list 1; 2; 3; end ); -``` - - - -```cameligo group=b -let increment (i: int) : int = i + 1 -(* Creates a new list with elements incremented by 1 *) -let incremented_list: int list = List.map increment [1; 2; 3] -``` - - - - -```reasonligo group=b -let increment = (i: int): int => i + 1; -(* Creates a new list with elements incremented by 1 *) -let incremented_list: list(int) = List.map(increment, [1, 2, 3]); -``` - - - -## List.iter(iter_function: a' -> unit, lst: a' list) : unit - -Apply a side effecting function `iter_function` to each element of a list with no -return value. This is useful for asserting that each element of a list satisfies -a particular property. - - - - -```pascaligo -function iter_op (const s : list(int)) : int is - begin - var r : int := 0 ; - function aggregate (const i : int) : unit is - begin - r := r + i ; - end with unit ; - list_iter(aggregate, s) ; - end with r -``` - - -```cameligo -let iter_op (s : int list) : unit = - let do_nothing = fun (_: int) -> unit - in List.iter do_nothing s -``` - - -```reasonligo -let iter_op = (s: list(int)): unit => { - let do_nothing = (z: int) => unit; - List.iter(do_nothing, s); -}; -``` - - - -## List.fold(fold_function: (a' * a') -> a', lst: a' list, acc: a') : 'a - -Combine the elements of a list into one value using the operation defined by -`fold_function'. For example, you could define summation by folding a list of -integers. Starting with some initial accumulator value `acc`, the fold: - -1. Consumes an element of the list. -2. Passes the accumulator value to `fold_function` along with the element to produce -a new accumulated value. -3. The new accumulated value replaces the previous one. -4. IF there are still elements in the list go back to 1, ELSE return the accumulator - -Summation would be defined then by using a `fold_function` that takes two integers and -adds them together. Each step of the fold would consume an element from the list -and add it to the total until you've summed over the list. - - - -```pascaligo group=b -function sum(const result: int; const i: int): int is result + i; -const sum_of_a_list: int = list_fold(sum, list 1; 2; 3; end, 0); -``` - - - -```cameligo group=b -let sum (result, i: int * int) : int = result + i -let sum_of_a_list: int = List.fold sum [1; 2; 3] 0 -``` - - - -```reasonligo group=b -let sum = ((result, i): (int, int)): int => result + i; -let sum_of_a_list: int = List.fold(sum, [1, 2, 3], 0); -``` - - diff --git a/gitlab-pages/docs/reference/map.md b/gitlab-pages/docs/reference/map.md index c7a5590e7..df3ecbb31 100644 --- a/gitlab-pages/docs/reference/map.md +++ b/gitlab-pages/docs/reference/map.md @@ -1,211 +1,199 @@ --- id: map-reference -title: Map +title: Maps --- -## Defining A Map Type +*Maps* are a data structure which associate values of the same type to +values of the same type. The former are called *key* and the latter +*values*. Together they make up a *binding*. An additional requirement +is that the type of the keys must be *comparable*, in the Michelson +sense. + +# Declaring a Map - -```pascaligo group=map + + +```pascaligo group=maps type move is int * int type register is map (address, move) ``` -```cameligo group=map +```cameligo group=maps type move = int * int type register = (address, move) map ``` -```reasonligo group=map +```reasonligo group=maps type move = (int, int); type register = map (address, move); ``` - -## Creating an Empty Map - -Create an empty map. +# Creating an Empty Map -```pascaligo group=map +```pascaligo group=maps const empty : register = map [] ``` -```cameligo group=map +```cameligo group=maps let empty : register = Map.empty ``` -```reasonligo group=map +```reasonligo group=maps let empty : register = Map.empty ``` - -## Populating A Map +# Creating a Non-empty Map - - -```pascaligo group=map -const moves: register = + +```pascaligo group=maps +const moves : register = map [ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2); ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] ``` - -```cameligo group=map -let moves: register = +```cameligo group=maps +let moves : register = Map.literal [ (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2)); (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))] ``` - -```reasonligo group=map -let moves: register = +```reasonligo group=maps +let moves : register = Map.literal ([ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]); ``` - -## Retrieving a Value in a Map - -Retrieve the value associated with a particular key. This version -returns an option which can either shift logic in response to a -missing value or throw an error. +# Accessing Map Bindings - -```pascaligo group=map + +```pascaligo group=maps const my_balance : option (move) = moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] ``` - -The function is `Map.find_opt` whose type is `'key -> -('key,'value) map) -> 'value option`. Recall that the function -`Map.find_opt` must always be fully applied to its arguments. Here -is an example: - -```cameligo group=map +```cameligo group=maps let my_balance : move option = Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves ``` - -The function is `Map.find_opt` whose type is `('key, ('key, -'value) map) : 'value option`. Here is an example: - -```reasonligo group=map +```reasonligo group=maps let my_balance : option (move) = - Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves); + Map.find_opt (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), moves); ``` -## Updating a Binding in a Map - -Given a map, we may want to add a new binding, remove one, or modify -one by changing the value associated to an already existing key. We -may even want to retain the key but not the associated value. All -those operations are called *updates*. +Notice how the value we read is an optional value: this is to force +the reader to account for a missing key in the map. This requires +*pattern matching*. - - -The values of a PascaLIGO map can be updated using the ordinary -assignment syntax: - -```pascaligo group=map -function add (var m : register) : register is - block { - m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) - } with m - -const updated_map : register = add (moves) -``` - -See further for the removal of bindings. - - - -In CameLIGO, you need the predefined function `Map.update` whose -type is `'key -> 'value option -> ('key, 'value) map -> ('key, -'value) map`. If the value (second argument) is `None`, then the -binding is to be removed. Recall that the function `Map.update` -must always be fully applied to its arguments. Here is an example: - -```cameligo group=map -let updated_map : register = - Map.update - ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves -``` - - - -In ReasonLIGO, you need the predefined function `Map.update` whose -type is `('key, 'value option, ('key, 'value) map) : ('key, -'value) map`. If the value (second componenat) is `None`, then the -binding is to be removed. Here is an example: - -```reasonligo group=map -let updated_map : register = - Map.update - (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves); -``` - - - -## Adding a Binding to a Map - -Add a key and its associated value to the map. - - - -```pascaligo group=map -function add (var m : register) : register is - block { - m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) - } with m - -const updated_map : register = add (moves) + +```pascaligo group=maps +function force_access (const key : address; const moves : register) : move is + case moves[key] of + Some (move) -> move + | None -> (failwith ("No move.") : move) + end ``` +```cameligo group=maps +let force_access (key, moves : address * register) : move = + match Map.find_opt key moves with + Some move -> move + | None -> (failwith "No move." : move) +``` -In CameLIGO, we use the predefined function `Map.add`, whose type -is `'key -> 'value -> ('key, 'value) map -> ('key, 'value) -map`. Recall that the function `Map.add` must always be fully -applied to its arguments. Here is an example: + +```reasonligo group=maps +let force_access = ((key, moves) : (address, register)) : move => { + switch (Map.find_opt (key, moves)) { + | Some (move) => move + | None => failwith ("No move.") : move + } +}; +``` + -```cameligo group=map +# Updating a Map + +Given a map, we may want to add a new binding, remove one, or modify +one by changing the value associated to an already existing key. All +those operations are called *updates*. + + + +```pascaligo group=maps +function assign (var m : register) : register is + block { + m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) + } with m +``` + +If multiple bindings need to be updated, PascaLIGO offers a *patch +instruction* for maps, similar to that for records. + +```pascaligo group=maps +function assignments (var m : register) : register is + block { + patch m with map [ + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (4,9); + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2) + ] + } with m +``` + + +```cameligo group=maps +let assign (m : register) : register = + Map.update + ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) m +``` +Notice the optional value `Some (4,9)` instead of `(4,9)`. If we had +use `None` instead, that would have meant that the binding is removed. + +As a particular case, we can only add a key and its associated value. + +```cameligo group=maps let add (m : register) : register = Map.add ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m ``` +```reasonligo group=maps +let assign = (m : register) : register => + Map.update + (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), Some ((4,9)), m); +``` -In ReasonLIGO, we use the predefined function `Map.add`, whose -type is `('key, 'value, ('key, 'value) map : ('key, 'value) -map`. Here is an example: +Notice the optional value `Some (4,9)` instead of `(4,9)`. If we had +use `None` instead, that would have meant that the binding is removed. -```reasonligo group=map +As a particular case, we can only add a key and its associated value. + +```reasonligo group=maps let add = (m : register) : register => Map.add (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m); @@ -213,14 +201,12 @@ let add = (m : register) : register => -## Removing a Binding from a Map - -Remove a key and its associated value from the map. +To remove a binding from a map, we need its key. -```pascaligo group=map +```pascaligo group=maps function delete (const key : address; var moves : register) : register is block { remove key from map moves @@ -228,47 +214,144 @@ function delete (const key : address; var moves : register) : register is ``` - -In CameLIGO, we use the predefined function `Map.remove` whose -type is `'key -> ('key, 'value) map -> ('key, 'value) -map`. Note that, despite being curried, the calls to that function -must be complete. Here is an example: - -```cameligo group=map +```cameligo group=maps let delete (key, moves : address * register) : register = Map.remove key moves ``` - -In ReasonLIGO, we use the predefined function `Map.remove` whose -type is `('key, ('key, 'value) map) : ('key, 'value) -map`. Here is an example: - -```reasonligo group=map +```reasonligo group=maps let delete = ((key, moves) : (address, register)) : register => Map.remove (key, moves); ``` -## Getting the Size of a Map -The size of a map is its number of bindings. +# Functional Iteration over Maps + +A *functional iterator* is a function that traverses a data structure +and calls in turn a given function over the elements of that structure +to compute some value. Another approach is possible in PascaLIGO: +*loops* (see the relevant section). + +There are three kinds of functional iterations over LIGO maps: the +*iterated operation*, the *map operation* (not to be confused with the +*map data structure*) and the *fold operation*. + +## Iterated Operation over Maps + +The first, the *iterated operation*, is an iteration over the map with +no return value: its only use is to produce side-effects. This can be +useful if for example you would like to check that each value inside +of a map is within a certain range, and fail with an error otherwise. -```pascaligo group=map -function size_of (const m : register) : nat is size (m) + +```pascaligo group=maps +function iter_op (const m : register) : unit is + block { + function iterated (const i : address; const j : move) : unit is + if j.1 > 3 then Unit else (failwith ("Below range.") : unit) + } with Map.iter (iterated, m) ``` + +> Note that `map_iter` is *deprecated*. + -```cameligo group=map -let size_of (m : register) : nat = Map.size m + +```cameligo group=maps +let iter_op (m : register) : unit = + let predicate = fun (i,j : address * move) -> assert (j.0 > 3) + in Map.iter predicate m ``` + -```reasonligo group=map -let size_of = (m : register): nat => Map.size (m); + +```reasonligo group=maps +let iter_op = (m : register) : unit => { + let predicate = ((i,j) : (address, move)) => assert (j[0] > 3); + Map.iter (predicate, m); +}; +``` + + +## Map Operations over Maps + +We may want to change all the bindings of a map by applying to them a +function. This is called a *map operation*, not to be confused with +the map data structure. The predefined functional iterator +implementing the map operation over maps is called `Map.map`. + + + + + +```pascaligo group=maps +function map_op (const m : register) : register is + block { + function increment (const i : address; const j : move) : move is + (j.0, j.1 + 1) + } with Map.map (increment, m) +``` + +> Note that `map_map` is *deprecated*. + + + +```cameligo group=maps +let map_op (m : register) : register = + let increment = fun (i,j : address * move) -> j.0, j.1 + 1 + in Map.map increment m +``` + + + +```reasonligo group=maps +let map_op = (m : register) : register => { + let increment = ((i,j): (address, move)) => (j[0], j[1] + 1); + Map.map (increment, m); +}; +``` + + +## Folded Operations over Maps + +A *folded operation* is the most general of iterations. The folded +function takes two arguments: an *accumulator* and the structure +*element* at hand, with which it then produces a new accumulator. This +enables having a partial result that becomes complete when the +traversal of the data structure is over. + + + + + +```pascaligo group=maps +function fold_op (const m : register) : int is + block { + function folded (const i : int; const j : address * move) : int is + i + j.1.1 + } with Map.fold (folded, m, 5) +``` + +> Note that `map_fold` is *deprecated*. + + +```cameligo group=maps +let fold_op (m : register) : register = + let folded = fun (i,j : int * (address * move)) -> i + j.1.1 + in Map.fold folded m 5 +``` + + +```reasonligo group=maps +let fold_op = (m : register) : register => { + let folded = ((i,j): (int, (address, move))) => i + j[1][1]; + Map.fold (folded, m, 5); +}; ``` diff --git a/gitlab-pages/docs/reference/set.md b/gitlab-pages/docs/reference/set.md index 08c7be4f3..c989df627 100644 --- a/gitlab-pages/docs/reference/set.md +++ b/gitlab-pages/docs/reference/set.md @@ -1,201 +1,220 @@ --- id: set-reference -title: Set — Unordered unique collection of a type +title: Sets — Unordered unique collection of a type --- -## Defining a set +Sets are unordered collections of values of the same type, like lists +are ordered collections. Like the mathematical sets and lists, sets +can be empty and, if not, elements of sets in LIGO are *unique*, +whereas they can be repeated in a *list*. + +# Empty Sets - -```pascaligo group=a -type int_set is set (int); -const my_set : int_set = set 1; 2; 3 end + +```pascaligo group=sets +const my_set : set (int) = set [] ``` -```cameligo group=a -type int_set = int set -let my_set : int_set = - Set.add 3 (Set.add 2 (Set.add 1 (Set.empty: int set))) +```cameligo group=sets +let my_set : int set = Set.empty ``` -```reasonligo group=a -type int_set = set (int); -let my_set : int_set = - Set.add (3, Set.add (2, Set.add (1, Set.empty: set (int)))); +```reasonligo group=sets +let my_set : set (int) = Set.empty; ``` - - -## Set.mem(is_member: a', s: a' set) : bool - -Check if a set `s` contains the element `is_member`. +# Non-empty Sets - -```pascaligo group=a -const contains_three : bool = my_set contains 3 -// or alternatively -const contains_three_fn: bool = set_mem (3, my_set); + +```pascaligo group=sets +const my_set : set (int) = set [3; 2; 2; 1] ``` -```cameligo group=a -let contains_three: bool = Set.mem 3 my_set -``` - -```reasonligo group=a -let contains_three: bool = Set.mem(3, my_set); +```cameligo group=sets +let my_set : int set = + Set.add 3 (Set.add 2 (Set.add 2 (Set.add 1 (Set.empty : int set)))) ``` + +```reasonligo group=sets +let my_set : set (int) = + Set.add (3, Set.add (2, Set.add (2, Set.add (1, Set.empty : set (int))))); +``` - -## Set.empty() : a' set - -Create a new empty set. Needs to be annotated with the set type. +# Set Membership - -```pascaligo group=a -const my_set: int_set = set end -const my_set_2: int_set = set_empty + +```pascaligo group=sets +const contains_3 : bool = my_set contains 3 ``` + -```cameligo group=a -let my_set: int_set = (Set.empty: int set) +```cameligo group=sets +let contains_3 : bool = Set.mem 3 my_set ``` + -```reasonligo group=a -let my_set: int_set = (Set.empty: set (int)); +```reasonligo group=sets +let contains_3 : bool = Set.mem (3, my_set); ``` -## Set.literal(element_list_literal: 'a list) : 'a set +# Cardinal of Sets -Create a set from the elements of a list. Note that **you must pass a list literal** -to this function, a variable will not work. +The predefined function `Set.size` returns the number of +elements in a given set as follows. + + + +```pascaligo group=sets +const cardinal : nat = Set.size (my_set) +``` + +> Note that `size` is *deprecated*. + + +```cameligo group=sets +let cardinal : nat = Set.size my_set +``` + +```reasonligo group=sets +let cardinal : nat = Set.size (my_set); +``` + + +# Updating Sets + +There are two ways to update a set, that is to add or remove from it. + + + +In PascaLIGO, either we create a new set from the given one, or we +modify it in-place. First, let us consider the former way: +```pascaligo group=sets +const larger_set : set (int) = Set.add (4, my_set) +const smaller_set : set (int) = Set.remove (3, my_set) +``` + +> Note that `set_add` and `set_remove` are *deprecated*. + +If we are in a block, we can use an instruction to modify the set +bound to a given variable. This is called a *patch*. It is only +possible to add elements by means of a patch, not remove any: it is +the union of two sets. + +```pascaligo group=sets +function update (var s : set (int)) : set (int) is block { + patch s with set [4; 7] +} with s + +const new_set : set (int) = update (my_set) +``` + + +```cameligo group=sets +let larger_set : int set = Set.add 4 my_set +let smaller_set : int set = Set.remove 3 my_set +``` + + +```reasonligo group=sets +let larger_set : set (int) = Set.add (4, my_set); +let smaller_set : set (int) = Set.remove (3, my_set); +``` + + +# Functional Iteration over Sets + +A *functional iterator* is a function that traverses a data structure +and calls in turn a given function over the elements of that structure +to compute some value. Another approach is possible in PascaLIGO: +*loops* (see the relevant section). + +There are three kinds of functional iterations over LIGO maps: the +*iterated operation*, the *mapped operation* (not to be confused with +the *map data structure*) and the *folded operation*. + +## Iterated Operation + +The first, the *iterated operation*, is an iteration over the map with +no return value: its only use is to produce side-effects. This can be +useful if for example you would like to check that each value inside +of a map is within a certain range, and fail with an error otherwise. + + + +```pascaligo group=sets +function iter_op (const s : set (int)) : unit is + block { + function iterated (const i : int) : unit is + if i > 2 then Unit else (failwith ("Below range.") : unit) + } with Set.iter (iterated, s) +``` + +> Note that `set_iter` is *deprecated*. + + +```cameligo group=sets +let iter_op (s : int set) : unit = + let predicate = fun (i : int) -> assert (i > 3) + in Set.iter predicate s +``` + + +```reasonligo group=sets +let iter_op = (s : set (int)) : unit => { + let predicate = (i : int) => assert (i > 3); + Set.iter (predicate, s); +}; +``` + + +## Folded Operation + +A *folded operation* is the most general of iterations. The folded +function takes two arguments: an *accumulator* and the structure +*element* at hand, with which it then produces a new accumulator. This +enables having a partial result that becomes complete when the +traversal of the data structure is over. -```pascaligo -const s_fb : set(string) = set [ - "foo" ; - "bar" ; -] +```pascaligo group=sets +function sum (const acc : int; const i : int): int is acc + i +const sum_of_elements : int = Set.fold (sum, my_set, 0) +``` + +> Note that `set_fold` is *deprecated*. + +It is possible to use a *loop* over a set as well. + +```pascaligo group=sets +function loop (const s : set (int)) : int is block { + var sum : int := 0; + for element in set s block { + sum := sum + element + } +} with sum ``` -```cameligo -let literal_op (p: unit) : string set = - Set.literal ["foo"; "bar"; "foobar"] +```cameligo group=sets +let sum (acc, i : int * int) : int = acc + i +let sum_of_elements : int = Set.fold sum my_set 0 ``` -```reasonligo -let literal_op = (p: unit) : set(string) => Set.literal(["foo", "bar", "foobar"]); -``` - - - -## Set.add(addition: a', s: a' set) : a' set - -Add the element `addition` to a set `s`. - - - -```pascaligo group=a -function add_op (const s : set(string)) : set(string) is - begin skip end with set_add("foobar" , s) -``` - - -```cameligo group=a -type int_set = int set -let my_set : int_set = - Set.add 3 (Set.add 2 (Set.add 1 (Set.empty: int set))) -``` - - -```reasonligo group=a -type int_set = set (int); -let my_set : int_set = - Set.add (3, Set.add (2, Set.add (1, Set.empty: set (int)))); -``` - - - -## Set.remove(removal: a', s: a' set) : a' set - -Remove the element `removal` from a set `s`. - - - -```pascaligo group=a -const smaller_set: int_set = set_remove(3, my_set); -``` - - - -```cameligo group=a -let smaller_set: int_set = Set.remove 3 my_set -``` - - - -```reasonligo group=a -let smaller_set: int_set = Set.remove(3, my_set); -``` - - - - -## Set.fold(folding_function: a' -> a' -> a', s: a' set, initial: a') : a' - -Combine the elements of a set into a single value using a folding function. - - - -```pascaligo group=a -function sum(const result: int; const i: int): int is result + i; -// Outputs 6 -const sum_of_a_set: int = set_fold(sum, my_set, 0); -``` - - -```cameligo group=a -let sum (result, i: int * int) : int = result + i -let sum_of_a_set: int = Set.fold sum my_set 0 -``` - - -```reasonligo group=a -let sum = (result_i: (int, int)): int => result_i[0] + result_i[1]; -let sum_of_a_set: int = Set.fold(sum, my_set, 0); +```reasonligo group=sets +let sum = ((acc, i) : (int, int)) : int => acc + i; +let sum_of_elements : int = Set.fold (sum, my_set, 0); ``` - -## Set.size(s: a' set) : nat - -Get the number of elements in a set. - - - -```pascaligo group=a -const set_size: nat = size (my_set) -``` - - -```cameligo group=a -let set_size: nat = Set.size my_set -``` - - -```reasonligo group=a -let set_size: nat = Set.size (my_set); -``` - - From a0d0da3a4262498a92a6c8b3efa3a101b9eb5327 Mon Sep 17 00:00:00 2001 From: Maksym Bykovskyy Date: Wed, 26 Feb 2020 17:50:59 +0000 Subject: [PATCH 10/53] Ui changes feedback changes --- .../client/src/components/editable-title.tsx | 61 +++--- .../packages/client/src/components/editor.tsx | 41 ++--- .../client/src/components/examples.tsx | 2 +- .../packages/client/src/components/inputs.tsx | 1 + .../packages/client/src/components/share.tsx | 174 +++++++++--------- tools/webide/packages/client/src/index.css | 2 +- .../server/test/schemas/share-latest.spec.ts | 4 +- 7 files changed, 131 insertions(+), 154 deletions(-) diff --git a/tools/webide/packages/client/src/components/editable-title.tsx b/tools/webide/packages/client/src/components/editable-title.tsx index 3f9472032..4f18b44ab 100644 --- a/tools/webide/packages/client/src/components/editable-title.tsx +++ b/tools/webide/packages/client/src/components/editable-title.tsx @@ -1,10 +1,6 @@ -import { faPencilAlt } from '@fortawesome/free-solid-svg-icons'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import React, { useEffect, useRef, useState } from 'react'; import styled, { css } from 'styled-components'; -import { Tooltip } from './tooltip'; - const Container = styled.div` display: flex; align-items: center; @@ -32,34 +28,27 @@ const Input = styled.input<{ visible?: boolean }>` `; const Label = styled.div<{ visible?: boolean }>` + display: flex; + align-items: center; color: var(--blue); opacity: 0; - - ${props => - props.visible && - css` - opacity: 1; - `} -`; - -const PencilIcon = ({ ...props }) => ( - -); - -const Pencil = styled(PencilIcon)<{ visible: boolean }>` - margin-left: 10px; - cursor: pointer; - color: var(--label_foreground); - opacity: 0; + padding-left: 0.5em; :hover { - opacity: 1; + position: absolute; + background-color: white; + border-radius: var(--border_radius); + height: 2em; + + border: none; + outline: none; + width: 15em; } ${props => props.visible && css` - opacity: 0.5; + opacity: 1; `} `; @@ -102,20 +91,18 @@ export const EditableTitleComponent = (props: { } }} > - -
- { - if (inputEl.current) { - inputEl.current.select(); - inputEl.current.setSelectionRange(0, 99999); - setShowInput(true); - } - }} - > - Rename -
+ ); }; diff --git a/tools/webide/packages/client/src/components/editor.tsx b/tools/webide/packages/client/src/components/editor.tsx index 3d2843126..d3d28b99a 100644 --- a/tools/webide/packages/client/src/components/editor.tsx +++ b/tools/webide/packages/client/src/components/editor.tsx @@ -14,16 +14,6 @@ const Container = styled.div` `; const Header = styled.div` - flex: 1; - display: flex; - justify-content: flex-start; - align-items: center; - - min-height: 2.5em; - border-bottom: 5px solid var(--blue_trans1); -`; - -const Subheader = styled.div` flex: 1; display: flex; justify-content: space-between; @@ -31,10 +21,17 @@ const Subheader = styled.div` background: var(--blue_trans1); border: 5px solid rgba(0, 0, 0, 0); - border-top: none; padding: 0 10px; `; +const LeftActions = styled.div` + display: flex; +`; + +const StyledEditableTitleComponent = styled(EditableTitleComponent)` + margin-left: 20px; +`; + export const EditorComponent = () => { const dispatch = useDispatch(); const title = useSelector(state => state.editor.title); @@ -42,18 +39,18 @@ export const EditorComponent = () => { return (
- -
- - { - dispatch({ ...new ChangeTitleAction(value) }); - }} - > + + + { + dispatch({ ...new ChangeTitleAction(value) }); + }} + > + - +
); diff --git a/tools/webide/packages/client/src/components/examples.tsx b/tools/webide/packages/client/src/components/examples.tsx index fec8c13c6..cecd2a4ee 100644 --- a/tools/webide/packages/client/src/components/examples.tsx +++ b/tools/webide/packages/client/src/components/examples.tsx @@ -19,7 +19,7 @@ const Container = styled.div` const MenuItem = styled.div<{ selected?: boolean }>` padding: ${verticalPadding} 0 ${verticalPadding} 1em; - height: 1.5em; + height: 1em; display: flex; align-items: center; cursor: pointer; diff --git a/tools/webide/packages/client/src/components/inputs.tsx b/tools/webide/packages/client/src/components/inputs.tsx index 22eabca0a..aa9ffa039 100644 --- a/tools/webide/packages/client/src/components/inputs.tsx +++ b/tools/webide/packages/client/src/components/inputs.tsx @@ -13,6 +13,7 @@ export const HGroup = styled.div` export const Label = styled.label` font-size: 1em; color: var(--label_foreground); + user-select: none; `; export const Input = styled.input` diff --git a/tools/webide/packages/client/src/components/share.tsx b/tools/webide/packages/client/src/components/share.tsx index 06974784c..0df1795aa 100644 --- a/tools/webide/packages/client/src/components/share.tsx +++ b/tools/webide/packages/client/src/components/share.tsx @@ -1,6 +1,7 @@ -import { faCopy } from '@fortawesome/free-solid-svg-icons'; +import { faCopy, faLink } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import React, { useEffect, useRef, useState } from 'react'; +import OutsideClickHandler from 'react-outside-click-handler'; import { useDispatch, useSelector } from 'react-redux'; import { Dispatch } from 'redux'; import styled, { css } from 'styled-components'; @@ -16,84 +17,66 @@ const Container = styled.div` align-items: center; `; +const Icon = styled(FontAwesomeIcon)` + pointer-events: none; +`; + const Button = styled.div<{ clicked?: boolean }>` cursor: pointer; user-select: none; + z-index: 3; - z-index: 1; display: flex; justify-content: center; align-items: center; - height: 2em; - width: 6em; - color: var(--blue); - background-color: white; - border-radius: 1em; - transition: width 0.3s ease-in; + width: 1.5em; + height: 1.5em; + border-radius: 50%; + + background-color: #aaa; + color: var(--blue_opaque1); + + &:hover { + background-color: white; + color: var(--blue); + opacity: 1; + } ${props => props.clicked && css` - width: 2em; background-color: white; - `} - - &:hover { - background-color: var(--blue_opaque1); - } -`; - -const Label = styled.span<{ visible?: boolean }>` - pointer-events: none; - opacity: 1; - transition: opacity 0.3s ease-in; - - ${props => - !props.visible && - css` - opacity: 0; - `} -`; - -const CopyIcon = ({ visible, ...props }: { visible: boolean }) => ( - -); - -const Copy = styled(CopyIcon)` - position: absolute; - pointer-events: none; - opacity: 1; - transition: opacity 0.3s ease-in; - - ${props => - !props.visible && - css` - opacity: 0; + color: var(--blue); + opacity: 1; `} `; const Input = styled.input<{ visible?: boolean }>` position: absolute; - background-color: var(--blue); - border-radius: 1em; - - opacity: 0; - height: 2em; - width: 2em; - transform: translateX(0.3em); border: none; - padding-left: 2em; + outline: none; + border-radius: 1em; + z-index: 2; + + padding-left: 1.5em; + transform: translateX(0.3em); + font-size: 1em; color: white; + background-color: var(--blue); + + width: 2em; + height: 1.5em; + opacity: 0; + transition: width 0.1s ease-in-out, opacity 0s 0.1s; - transition: width 0.3s ease-in; - outline: none; ${props => props.visible && css` - opacity: 1; width: 25em; + opacity: 1; + transition: width 0.3s ease-in-out; `} `; @@ -118,59 +101,68 @@ export const ShareComponent = () => { const shareLink = useSelector( state => state.share.link ); - const [clicked, setClicked] = useState(false); const SHARE_TOOLTIP = 'Share code'; const COPY_TOOLTIP = 'Copy link'; const COPIED_TOOLTIP = 'Copied!'; const [tooltipMessage, setTooltipMessage] = useState(SHARE_TOOLTIP); + const [clicked, setClicked] = useState(false); + const [icon, setIcon] = useState(faLink); + + const setInitialState = () => { + setClicked(false); + setIcon(faLink); + setTooltipMessage(SHARE_TOOLTIP); + }; + + const setClickedState = () => { + setClicked(true); + setIcon(faCopy); + setTooltipMessage(COPY_TOOLTIP); + }; useEffect(() => { if (shareLink) { if (inputEl.current && copy(inputEl.current)) { setTooltipMessage(COPIED_TOOLTIP); - } else { - setClicked(true); - setTooltipMessage(COPY_TOOLTIP); } } else { - setClicked(false); - setTooltipMessage(SHARE_TOOLTIP); + setInitialState(); } }, [shareLink]); return ( - - - - + setInitialState()}> + + + + + ); }; diff --git a/tools/webide/packages/client/src/index.css b/tools/webide/packages/client/src/index.css index 6f15a1d73..1f3296c3f 100644 --- a/tools/webide/packages/client/src/index.css +++ b/tools/webide/packages/client/src/index.css @@ -48,7 +48,7 @@ --font_ghost_weight: 700; --font_ghost_color: rgba(153, 153, 153, 0.5); /* or #CFCFCF */ - --content_height: 80vh; + --content_height: 85vh; --tooltip_foreground: white; --tooltip_background: rgba(0, 0, 0, 0.75) /*#404040*/; diff --git a/tools/webide/packages/server/test/schemas/share-latest.spec.ts b/tools/webide/packages/server/test/schemas/share-latest.spec.ts index 537a86c40..79fa25699 100644 --- a/tools/webide/packages/server/test/schemas/share-latest.spec.ts +++ b/tools/webide/packages/server/test/schemas/share-latest.spec.ts @@ -1,7 +1,7 @@ import latestSchema from '../../src/schemas/share-latest'; describe('Latest Share Schema Migration', () => { - it('should be v1', () => { - expect(latestSchema.VERSION).toEqual('v1'); + it('should be v2', () => { + expect(latestSchema.VERSION).toEqual('v2'); }); }); From a08adbd085b2f3d69f657cffb71ca7d206944ecd Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Wed, 26 Feb 2020 18:54:16 +0100 Subject: [PATCH 11/53] typer: checks for constructor redundancy --- src/bin/expect_tests/contract_tests.ml | 16 ++++++++++++++- src/passes/4-typer-old/typer.ml | 12 +++++++++++ .../negative/redundant_constructors.mligo | 20 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/test/contracts/negative/redundant_constructors.mligo diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index bacbfc8e2..facee666d 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -1130,4 +1130,18 @@ let%expect_test _ = let%expect_test _ = run_ligo_good [ "dry-run" ; contract "super-counter.mligo" ; "main" ; "test_param" ; "test_storage" ] ; [%expect {| - ( list[] , 3 ) |}] \ No newline at end of file + ( list[] , 3 ) |}] + +let%expect_test _ = + run_ligo_bad [ "compile-contract" ; bad_contract "redundant_constructors.mligo" ; "main" ] ; + [%expect {| + ligo: redundant constructor: {"constructor":"Add","environment":"- E[]\tT[union_a -> sum[Add -> int , Remove -> int]] ]"} + + + 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/4-typer-old/typer.ml b/src/passes/4-typer-old/typer.ml index 87f4b2477..2d5d70a12 100644 --- a/src/passes/4-typer-old/typer.ml +++ b/src/passes/4-typer-old/typer.ml @@ -80,6 +80,15 @@ module Errors = struct ] in error ~data title message () + let redundant_constructor (e:environment) (c:I.constructor') () = + let title = (thunk "redundant constructor") in + let message () = "" in + let data = [ + ("constructor" , fun () -> Format.asprintf "%a" I.PP.constructor c); + ("environment" , fun () -> Format.asprintf "%a" Environment.PP.full_environment e) ; + ] in + error ~data title message () + let wrong_arity (n:string) (expected:int) (actual:int) (loc : Location.t) () = let title () = "wrong arity" in let message () = "" in @@ -321,6 +330,9 @@ and evaluate_type (e:environment) (t:I.type_expression) : O.type_expression resu let aux k v prev = let%bind prev' = prev in let%bind v' = evaluate_type e v in + let%bind () = match Environment.get_constructor k e with + | Some _ -> fail (redundant_constructor e k) + | None -> ok () in ok @@ I.CMap.add k v' prev' in let%bind m = I.CMap.fold aux m (ok I.CMap.empty) in diff --git a/src/test/contracts/negative/redundant_constructors.mligo b/src/test/contracts/negative/redundant_constructors.mligo new file mode 100644 index 000000000..ffa4ec6c6 --- /dev/null +++ b/src/test/contracts/negative/redundant_constructors.mligo @@ -0,0 +1,20 @@ +type union_a = +| Add of int +| Remove of int + +(* comment this type out to successfully compile the contract *) +type union_b = +| Add of nat +| Remove of nat +| Config of nat + + +let foo (a : union_a) = + match a with + |Add a -> unit + |Remove b -> unit + + +let main(p, s : union_a * unit) : (operation list) * unit = + let ss = foo p in + ([]: operation list), ss \ No newline at end of file From 8d5a0990094694703d918ac5ffa1171798075763 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Wed, 26 Feb 2020 19:37:05 +0100 Subject: [PATCH 12/53] Fixed "fail" -> "failwith" in the cheat-sheet. --- gitlab-pages/docs/api/cheat-sheet.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitlab-pages/docs/api/cheat-sheet.md b/gitlab-pages/docs/api/cheat-sheet.md index 15e10bfe4..9e7020177 100644 --- a/gitlab-pages/docs/api/cheat-sheet.md +++ b/gitlab-pages/docs/api/cheat-sheet.md @@ -30,7 +30,7 @@ Note that this table is not compiled before production and currently needs to be |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 fail("Too young to drive.");
else const new_id: int = prev_id + 1;
| +| 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``` | @@ -41,7 +41,7 @@ Note that this table is not compiled before production and currently needs to be |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.")`| +|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`| @@ -63,7 +63,7 @@ Note that this table is not compiled before production and currently needs to be |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
| +| 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)```| @@ -73,7 +73,7 @@ Note that this table is not compiled before production and currently needs to be |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.")`| +|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`| @@ -95,7 +95,7 @@ Note that this table is not compiled before production and currently needs to be |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; }
| +| 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)```| @@ -105,7 +105,7 @@ Note that this table is not compiled before production and currently needs to be |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.");`| +|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.");`| From 93682629b4b3dc94974e9ca0c95aae184ce043ce Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Thu, 27 Feb 2020 17:51:29 +0100 Subject: [PATCH 13/53] Updating contracts. --- src/test/contracts/address.mligo | 4 +- src/test/contracts/amount.ligo | 8 +-- src/test/contracts/amount.mligo | 2 +- src/test/contracts/arithmetic.mligo | 27 +++----- src/test/contracts/assert.mligo | 2 +- src/test/contracts/attributes.mligo | 6 +- src/test/contracts/balance_constant.mligo | 11 ++-- src/test/contracts/big_map.mligo | 14 ++--- src/test/contracts/bitwise_arithmetic.mligo | 10 +-- src/test/contracts/boolean_operators.mligo | 15 ++--- src/test/contracts/bytes_arithmetic.mligo | 9 +-- src/test/contracts/bytes_unpack.mligo | 18 +++--- src/test/contracts/check_signature.mligo | 2 +- src/test/contracts/closure.mligo | 12 ++-- src/test/contracts/condition-annot.mligo | 6 +- src/test/contracts/condition-shadowing.mligo | 2 +- src/test/contracts/counter.mligo | 4 +- src/test/contracts/crypto.mligo | 4 +- src/test/contracts/curry.mligo | 10 +-- src/test/contracts/empty_case.mligo | 12 ++-- src/test/contracts/eq_bool.mligo | 2 +- src/test/contracts/failwith.mligo | 4 +- src/test/contracts/fibo.mligo | 12 ++-- src/test/contracts/fibo2.mligo | 12 ++-- src/test/contracts/fibo3.mligo | 12 ++-- src/test/contracts/function-shared.mligo | 6 +- src/test/contracts/guess_string.mligo | 22 +++---- src/test/contracts/option.ligo | 6 +- .../contracts/parser-bad-reported-term.ligo | 6 -- src/test/contracts/procedure.ligo | 11 ---- src/test/contracts/quote-declaration.ligo | 9 +-- src/test/contracts/quote-declarations.ligo | 14 +---- src/test/contracts/record.ligo | 62 +++++-------------- src/test/contracts/redeclaration.ligo | 8 +-- src/test/contracts/replaceable_id.ligo | 40 ++++++------ src/test/contracts/self_address.ligo | 2 +- src/test/contracts/set_arithmetic-1.ligo | 26 ++++---- src/test/contracts/set_arithmetic.ligo | 35 +++++------ src/test/contracts/set_delegate.ligo | 11 ++-- src/test/contracts/shadow.ligo | 3 +- src/test/contracts/simple_access.ligo | 32 +++++----- src/test/contracts/string.ligo | 4 +- src/test/contracts/string_arithmetic.ligo | 4 +- src/test/contracts/super-counter.ligo | 18 +++--- src/test/contracts/tez.ligo | 24 +++---- src/test/contracts/time-lock.ligo | 29 +++++---- src/test/contracts/timestamp.ligo | 3 +- src/test/contracts/toto.ligo | 5 +- src/test/contracts/tuple.ligo | 18 +++--- src/test/contracts/variant-matching.ligo | 10 +-- src/test/contracts/variant.ligo | 2 +- src/test/contracts/website1.ligo | 4 +- src/test/contracts/website2.ligo | 20 +++--- 53 files changed, 288 insertions(+), 366 deletions(-) delete mode 100644 src/test/contracts/parser-bad-reported-term.ligo delete mode 100644 src/test/contracts/procedure.ligo diff --git a/src/test/contracts/address.mligo b/src/test/contracts/address.mligo index 3651ea223..2b24b7d08 100644 --- a/src/test/contracts/address.mligo +++ b/src/test/contracts/address.mligo @@ -1,3 +1,3 @@ let main (p : key_hash) = - let c : unit contract = Current.implicit_account p in - Current.address c \ No newline at end of file + let c : unit contract = Current.implicit_account p + in Current.address c diff --git a/src/test/contracts/amount.ligo b/src/test/contracts/amount.ligo index 8d4961be8..9c0263635 100644 --- a/src/test/contracts/amount.ligo +++ b/src/test/contracts/amount.ligo @@ -1,8 +1,8 @@ -function check (const p: unit) : int is - begin +function check (const p : unit) : int is + block { var result : int := 0; - if amount = 100tz then + if Tezos.amount = 100tz then result := 42 else result := 0 - end with result + } with result diff --git a/src/test/contracts/amount.mligo b/src/test/contracts/amount.mligo index 8e31e2d0c..a2db44946 100644 --- a/src/test/contracts/amount.mligo +++ b/src/test/contracts/amount.mligo @@ -1 +1 @@ -let check_ (p: unit) : int = if Current.amount = 100tz then 42 else 0 +let check = if Tezos.amount > 100tez then 42 else 0 diff --git a/src/test/contracts/arithmetic.mligo b/src/test/contracts/arithmetic.mligo index e3bb8ba07..66c241f86 100644 --- a/src/test/contracts/arithmetic.mligo +++ b/src/test/contracts/arithmetic.mligo @@ -1,30 +1,17 @@ // Test CameLIGO arithmetic operators -let mod_op (n : int) : nat = - n mod 42 +let mod_op (n : int) : nat = n mod 42 -let plus_op (n : int) : int = - n + 42 +let plus_op (n : int) : int = n + 42 -let minus_op (n : int) : int = - n - 42 +let minus_op (n : int) : int = n - 42 -let times_op (n : int) : int = - n * 42 +let times_op (n : int) : int = n * 42 -let div_op (n : int) : int = - n / 2 +let div_op (n : int) : int = n / 2 -(* TODO (?): Support conversion from nat to int and back - -let int_op (n : nat) : int = - Int n - -*) - -let neg_op (n : int) : int = - -n +let neg_op (n : int) : int = -n let foo (n : int) : int = n + 10 -let neg_op_2 (b: int) : int = -(foo b) +let neg_op_2 (b : int) : int = -(foo b) diff --git a/src/test/contracts/assert.mligo b/src/test/contracts/assert.mligo index 143f7066f..41785c58d 100644 --- a/src/test/contracts/assert.mligo +++ b/src/test/contracts/assert.mligo @@ -1,3 +1,3 @@ -let main (p, s: bool * unit) = +let main (p, s : bool * unit) = let u : unit = assert p in ([] : operation list), s diff --git a/src/test/contracts/attributes.mligo b/src/test/contracts/attributes.mligo index 8f582a725..a96d63710 100644 --- a/src/test/contracts/attributes.mligo +++ b/src/test/contracts/attributes.mligo @@ -1,10 +1,10 @@ let x = 1 [@@inline] -let foo (a: int): int = +let foo (a : int): int = (let test = 2 + a [@@inline] in test) [@@inline] let y = 1 [@@inline][@@other] -let bar (b: int): int = - let test = fun (z: int) -> 2 + b + z [@@inline][@@foo][@@bar] +let bar (b : int): int = + let test = fun (z : int) -> 2 + b + z [@@inline][@@foo][@@bar] in test b diff --git a/src/test/contracts/balance_constant.mligo b/src/test/contracts/balance_constant.mligo index c364d2bce..b73319f8f 100644 --- a/src/test/contracts/balance_constant.mligo +++ b/src/test/contracts/balance_constant.mligo @@ -1,17 +1,16 @@ -(** - +(* This test makes sure that the balance is accessible in CameLIGO. -It's there to detect a regression of: https://gitlab.com/ligolang/ligo/issues/61 -Which results in this error when you attempt to compile this contract: +It is there to detect a regression of: +https://gitlab.com/ligolang/ligo/issues/61 + +which results in this error when you attempt to compile this contract: generated. unrecognized constant: {"constant":"BALANCE","location":"generated"} - *) type storage = tez let main (p, s : unit * storage) = ([] : operation list), balance - diff --git a/src/test/contracts/big_map.mligo b/src/test/contracts/big_map.mligo index 35a173f82..434878013 100644 --- a/src/test/contracts/big_map.mligo +++ b/src/test/contracts/big_map.mligo @@ -2,22 +2,20 @@ type foo = (int, int) big_map let set_ (n, m: int * foo) : foo = Big_map.update 23 (Some n) m -let add (n,m : int * foo) : foo = Big_map.add 23 n m +let add (n, m : int * foo) : foo = Big_map.add 23 n m let rm (m : foo) : foo = Big_map.remove 42 m let gf (m : foo) : int = Big_map.find 23 m -let get (m: foo): int option = Big_map.find_opt 42 m +let get (m : foo): int option = Big_map.find_opt 42 m let empty_map : foo = Big_map.empty -let map1 : foo = Big_map.literal - [ (23 , 0) ; (42, 0) ] +let map1 : foo = Big_map.literal [(23,0); (42,0)] -let map1 : foo = Big_map.literal - [ (23 , 0) ; (42, 0) ] +let map1 : foo = Big_map.literal [(23,0); (42,0)] let mutimaps (m : foo) (n : foo) : foo = - let bar : foo = Big_map.update 42 (Some 0) m in - Big_map.update 42 (get bar) n + let bar : foo = Big_map.update 42 (Some 0) m + in Big_map.update 42 (get bar) n diff --git a/src/test/contracts/bitwise_arithmetic.mligo b/src/test/contracts/bitwise_arithmetic.mligo index d79cbe348..5675df1b8 100644 --- a/src/test/contracts/bitwise_arithmetic.mligo +++ b/src/test/contracts/bitwise_arithmetic.mligo @@ -1,7 +1,7 @@ (* Test CameLIGO bitwise operators *) -let or_op (n: nat) : nat = Bitwise.or n 4n -let and_op (n: nat) : nat = Bitwise.and n 7n -let xor_op (n: nat) : nat = Bitwise.xor n 7n -let lsl_op (n: nat) : nat = Bitwise.shift_left n 7n -let lsr_op (n: nat) : nat = Bitwise.shift_right n 7n +let or_op (n : nat) : nat = Bitwise.lor n 4n +let and_op (n : nat) : nat = Bitwise.land n 7n +let xor_op (n : nat) : nat = Bitwise.lxor n 7n +let lsl_op (n : nat) : nat = Bitwise.shift_left n 7n +let lsr_op (n : nat) : nat = Bitwise.shift_right n 7n diff --git a/src/test/contracts/boolean_operators.mligo b/src/test/contracts/boolean_operators.mligo index 7eb3cfd69..63091dbf8 100644 --- a/src/test/contracts/boolean_operators.mligo +++ b/src/test/contracts/boolean_operators.mligo @@ -1,16 +1,11 @@ // Test CameLIGO boolean operators -let or_true (b : bool) : bool = - b || true +let or_true (b : bool) : bool = b || true -let or_false (b : bool) : bool = - b || false +let or_false (b : bool) : bool = b || false -let and_true (b : bool) : bool = - b && true +let and_true (b : bool) : bool = b && true -let and_false (b : bool) : bool = - b && false +let and_false (b : bool) : bool = b && false -let not_bool (b: bool) : bool = - not b +let not_bool (b : bool) : bool = not b diff --git a/src/test/contracts/bytes_arithmetic.mligo b/src/test/contracts/bytes_arithmetic.mligo index 4d71994a2..44d89cb36 100644 --- a/src/test/contracts/bytes_arithmetic.mligo +++ b/src/test/contracts/bytes_arithmetic.mligo @@ -1,8 +1,5 @@ -let concat_op (s : bytes) : bytes = - Bytes.concat s 0x7070 +let concat_op (s : bytes) : bytes = Bytes.concat s 0x7070 -let slice_op (s : bytes) : bytes = - Bytes.slice 1n 2n s +let slice_op (s : bytes) : bytes = Bytes.slice 1n 2n s -let hasherman (s : bytes) : bytes = - Crypto.sha256 s +let hasherman (s : bytes) : bytes = Crypto.sha256 s diff --git a/src/test/contracts/bytes_unpack.mligo b/src/test/contracts/bytes_unpack.mligo index e33f09b47..56028af77 100644 --- a/src/test/contracts/bytes_unpack.mligo +++ b/src/test/contracts/bytes_unpack.mligo @@ -1,11 +1,11 @@ -let id_string (p: string) : string option = - let packed: bytes = Bytes.pack p in - ((Bytes.unpack packed): string option) +let id_string (p : string) : string option = + let packed : bytes = Bytes.pack p in + (Bytes.unpack packed : string option) -let id_int (p: int) : int option = - let packed: bytes = Bytes.pack p in - ((Bytes.unpack packed): int option) +let id_int (p : int) : int option = + let packed : bytes = Bytes.pack p in + (Bytes.unpack packed : int option) -let id_address (p: address) : address option = - let packed: bytes = Bytes.pack p in - ((Bytes.unpack packed): address option) +let id_address (p : address) : address option = + let packed : bytes = Bytes.pack p in + (Bytes.unpack packed : address option) diff --git a/src/test/contracts/check_signature.mligo b/src/test/contracts/check_signature.mligo index ecd56eb4b..93218ee0f 100644 --- a/src/test/contracts/check_signature.mligo +++ b/src/test/contracts/check_signature.mligo @@ -1,2 +1,2 @@ -let check_signature (pk, signed, msg: key * signature * bytes) : bool = +let check_signature (pk, signed, msg : key * signature * bytes) : bool = Crypto.check pk signed msg diff --git a/src/test/contracts/closure.mligo b/src/test/contracts/closure.mligo index ee5f616ae..ddd866df7 100644 --- a/src/test/contracts/closure.mligo +++ b/src/test/contracts/closure.mligo @@ -1,9 +1,7 @@ (* Test whether closures retain values in CameLIGO *) -let test (k: int) : int = - let j: int = k + 5 in - let close: (int -> int) = - fun (i: int) -> i + j - in - let j: int = 20 in (* Shadow original variable to see if value close'd *) - close 20 +let test (k : int) : int = + let j : int = k + 5 in + let close : int -> int = fun (i : int) -> i + j in + let j : int = 20 (* Shadow original variable *) + in close 20 diff --git a/src/test/contracts/condition-annot.mligo b/src/test/contracts/condition-annot.mligo index 697329fcb..93aece587 100644 --- a/src/test/contracts/condition-annot.mligo +++ b/src/test/contracts/condition-annot.mligo @@ -1,2 +1,4 @@ -let main (i: int) = - if (i=2 : bool) then (42: int) else (0: int) +type integer is int + +let main (i : int) = + if (i = 2 : bool) then (42 : int) else (0 : integer) diff --git a/src/test/contracts/condition-shadowing.mligo b/src/test/contracts/condition-shadowing.mligo index c4dbbbb7b..97ee6eb51 100644 --- a/src/test/contracts/condition-shadowing.mligo +++ b/src/test/contracts/condition-shadowing.mligo @@ -1,6 +1,6 @@ (* TODO : make a test using mutation, not shadowing *) -let main (i: int) = +let main (i : int) = let result = 0 in if i = 2 then let result = 42 in result diff --git a/src/test/contracts/counter.mligo b/src/test/contracts/counter.mligo index 615dfa62a..548a1e07e 100644 --- a/src/test/contracts/counter.mligo +++ b/src/test/contracts/counter.mligo @@ -1,4 +1,4 @@ type storage = int -let main (ps: int * storage) = - (([] : operation list) , ps.0 + ps.1) +let main (ps : int * storage) = + ([] : operation list), ps.0 + ps.1 diff --git a/src/test/contracts/crypto.mligo b/src/test/contracts/crypto.mligo index 9fa7e99e8..902cd088e 100644 --- a/src/test/contracts/crypto.mligo +++ b/src/test/contracts/crypto.mligo @@ -1,2 +1,2 @@ -let hasherman512 (s: bytes) : bytes = Crypto.sha512 s -let hasherman_blake (s: bytes) : bytes = Crypto.blake2b s +let hasherman512 (s : bytes) : bytes = Crypto.sha512 s +let hasherman_blake (s : bytes) : bytes = Crypto.blake2b s diff --git a/src/test/contracts/curry.mligo b/src/test/contracts/curry.mligo index eee47985a..ffcaafe15 100644 --- a/src/test/contracts/curry.mligo +++ b/src/test/contracts/curry.mligo @@ -1,9 +1,9 @@ -let conv_test (j: int) (k: int) = j + k +let conv_test (j : int) (k : int) = j + k -let main (i: int) : int = conv_test i 10 +let main (i : int) : int = conv_test i 10 -let partial (a: int) (b: int) : int = a + b +let partial (a : int) (b : int) : int = a + b -let mk_partial (j: int) : (int -> int) = partial j +let mk_partial (j : int) : int -> int = partial j -let partial_apply (i: int) : int = (mk_partial 10) i +let partial_apply (i : int) : int = mk_partial 10 i diff --git a/src/test/contracts/empty_case.mligo b/src/test/contracts/empty_case.mligo index 844897f01..4d08d9c3c 100644 --- a/src/test/contracts/empty_case.mligo +++ b/src/test/contracts/empty_case.mligo @@ -1,8 +1,8 @@ type foo = - | Bar of int - | Baz + Bar of int +| Baz -let main (f: foo): int = - match f with - | Bar i -> i - | Baz -> -1 \ No newline at end of file +let main (f : foo) : int = + match f with + Bar i -> i + | Baz -> -1 diff --git a/src/test/contracts/eq_bool.mligo b/src/test/contracts/eq_bool.mligo index 6869d5dfd..ef2aefe55 100644 --- a/src/test/contracts/eq_bool.mligo +++ b/src/test/contracts/eq_bool.mligo @@ -1,3 +1,3 @@ // Test conditional in CameLIGO -let main (a , b : bool * bool) = if a = b then 999 else 1 +let main (a, b : bool * bool) = if a = b then 999 else 1 diff --git a/src/test/contracts/failwith.mligo b/src/test/contracts/failwith.mligo index fbc5976bd..2938a703d 100644 --- a/src/test/contracts/failwith.mligo +++ b/src/test/contracts/failwith.mligo @@ -1,4 +1,4 @@ type storage = unit -let main (p: unit) storage = - if true then failwith "This contract always fails" else () +let main (p : unit; store : storage) : operation list * storage = + if true then failwith "This contract always fails" diff --git a/src/test/contracts/fibo.mligo b/src/test/contracts/fibo.mligo index fa345f653..3d2e3a687 100644 --- a/src/test/contracts/fibo.mligo +++ b/src/test/contracts/fibo.mligo @@ -1,7 +1,9 @@ type storage = unit -let main (p: unit) storage = - (fun (f: (int * int) -> int) (x: int) (y: int) -> f (y,x)) - (fun (x: int) (y: int) -> x + y) - 0 - 1 +let main (p : unit; store : storage) : operation list * storage = + let n = + (fun (f : int * int -> int) (x : int) (y : int) -> f (y,x)) + (fun (x : int) (y : int) -> x + y) + 0 + 1 + in ([] : operation list), store diff --git a/src/test/contracts/fibo2.mligo b/src/test/contracts/fibo2.mligo index 0b12826fc..f41ee0e3d 100644 --- a/src/test/contracts/fibo2.mligo +++ b/src/test/contracts/fibo2.mligo @@ -1,7 +1,9 @@ type storage = unit -let main (p: unit) storage = - (fun (f: int -> int) (_: int) (y: int) -> f y) - (fun (x: int) -> x) - 0 - 1 +let main (p : unit; store : storage) : operation list * storage = + let n = + (fun (f : int -> int) (z : int) (y : int) -> f y) + (fun (x : int) -> x) + 0 + 1 + in ([] : operation list), store diff --git a/src/test/contracts/fibo3.mligo b/src/test/contracts/fibo3.mligo index 1310bfa10..836f24517 100644 --- a/src/test/contracts/fibo3.mligo +++ b/src/test/contracts/fibo3.mligo @@ -1,7 +1,9 @@ type storage = unit -let main (p: unit) storage = - (fun (f: int -> int -> int) (x: int) (y: int) -> f y (x+y)) - (fun (x: int) (y: int) -> x + y) - 0 - 1 +let main (p : unit; store : storage) : operation list * storage = + let n = + (fun (f : int -> int -> int) (x : int) (y : int) -> f y (x+y)) + (fun (x : int) (y : int) -> x + y) + 0 + 1 + in ([] : operation list), store diff --git a/src/test/contracts/function-shared.mligo b/src/test/contracts/function-shared.mligo index 3568f0b3a..e8f70f6bd 100644 --- a/src/test/contracts/function-shared.mligo +++ b/src/test/contracts/function-shared.mligo @@ -1,7 +1,7 @@ (* Test use of multiple subroutines in a CameLIGO function *) -let foo (i: int) : int = i + 20 +let foo (i : int) : int = i + 20 -let bar (i: int) : int = i + 50 +let bar (i : int) : int = i + 50 -let foobar (i: int) : int = (foo i) + (bar i) +let foobar (i : int) : int = foo i + bar i diff --git a/src/test/contracts/guess_string.mligo b/src/test/contracts/guess_string.mligo index 3921d4108..adde5b642 100644 --- a/src/test/contracts/guess_string.mligo +++ b/src/test/contracts/guess_string.mligo @@ -1,20 +1,18 @@ type storage = { - challenge : string; + challenge : string } type param = { new_challenge : string; - attempt : string; + attempt : string } -let attempt (p: param) storage = - (* if p.attempt <> storage.challenge then failwith "Failed challenge" else *) - let contract : unit contract = - Operation.get_contract sender in +type return = operation list * storage + +let attempt (p: param; store : storage) : return = + (* if p.attempt <> store.challenge then failwith "Failed challenge" else *) + let contract : unit contract = Operation.get_contract sender in let transfer : operation = - Operation.transaction (unit , contract , 10.00tz) in - (* TODO: no syntax for functional updates yet *) - (* let storage : storage = { storage with challenge = p.new_challenge } in *) - (* for now, rebuild the record by hand. *) - let storage : storage = { challenge = p.new_challenge } - in ([] : operation list), storage + Operation.transaction (unit, contract, 10.00tez) in + let store : storage = {challenge = p.new_challenge} + in ([] : operation list), store diff --git a/src/test/contracts/option.ligo b/src/test/contracts/option.ligo index 424171c93..39614435d 100644 --- a/src/test/contracts/option.ligo +++ b/src/test/contracts/option.ligo @@ -1,13 +1,13 @@ // Test the option type in PascaLIGO -type foobar is option(int) +type foobar is option (int) -const s : foobar = Some(42) +const s : foobar = Some (42) const n : foobar = None function assign (var m : int) : foobar is block { var coco : foobar := None; - coco := Some(m); + coco := Some (m); coco := (None : foobar); //temporary annotation added until type inference } with coco diff --git a/src/test/contracts/parser-bad-reported-term.ligo b/src/test/contracts/parser-bad-reported-term.ligo deleted file mode 100644 index 05dc69e3e..000000000 --- a/src/test/contracts/parser-bad-reported-term.ligo +++ /dev/null @@ -1,6 +0,0 @@ -function f (const x : unit) : unit is - begin skip end with unit - -function main (const p : unit ; const s : unit) : unit is - behin skip end with f unit -// the srcloc is correct but the reported term is "skip" instead of "behin". diff --git a/src/test/contracts/procedure.ligo b/src/test/contracts/procedure.ligo deleted file mode 100644 index a0f6664c6..000000000 --- a/src/test/contracts/procedure.ligo +++ /dev/null @@ -1,11 +0,0 @@ -// Test a trivial PascaLIGO procedure - -procedure sub (const j: int) is - begin - i := i + 1 - end - -function main (const i: int) : int is - begin - sub(i) - end with i diff --git a/src/test/contracts/quote-declaration.ligo b/src/test/contracts/quote-declaration.ligo index 4c5547d4c..d11fa919b 100644 --- a/src/test/contracts/quote-declaration.ligo +++ b/src/test/contracts/quote-declaration.ligo @@ -1,8 +1,3 @@ -function foo (const input : int) : int is begin - skip -end with (input + 42) +function foo (const input : int) : int is input + 42 -function main (const i : int) : int is - begin - skip - end with i + foo (i) +function main (const i : int) : int is i + foo (i) diff --git a/src/test/contracts/quote-declarations.ligo b/src/test/contracts/quote-declarations.ligo index 1b783066d..d98fbe15a 100644 --- a/src/test/contracts/quote-declarations.ligo +++ b/src/test/contracts/quote-declarations.ligo @@ -1,13 +1,5 @@ -function foo (const input : int) : int is begin - skip -end with (input + 23) +function foo (const input : int) : int is input + 23 -function bar (const input : int) : int is begin - skip -end with (input + 51) +function bar (const input : int) : int is input + 51 - -function main (const i : int) : int is - begin - skip - end with foo (i) + bar (i) +function main (const i : int) : int is foo (i) + bar (i) diff --git a/src/test/contracts/record.ligo b/src/test/contracts/record.ligo index 94b49d9fc..1cc6ad2a2 100644 --- a/src/test/contracts/record.ligo +++ b/src/test/contracts/record.ligo @@ -1,68 +1,38 @@ // Test record type in PascaLIGO -type foobar is record - foo : int ; - bar : int ; -end +type foobar is record [foo : int; bar : int] -const fb : foobar = record - foo = 0 ; - bar = 0 ; -end +const fb : foobar = record [foo = 0; bar = 0] -type abc is record - a : int ; - b : int ; - c : int ; -end +type abc is record [a : int; b : int; c : int] -const abc : abc = record - a = 42 ; - b = 142 ; - c = 242 ; -end +const abc : abc = record [a = 42; b = 142; c = 242] -const a : int = abc.a ; -const b : int = abc.b ; -const c : int = abc.c ; +const a : int = abc.a +const b : int = abc.b +const c : int = abc.c -function projection (const r : foobar) : int is - begin - skip - end with r.foo + r.bar +function projection (const r : foobar) : int is r.foo + r.bar -function modify (const r : foobar) : foobar is +function modify (var r : foobar) : foobar is block { - r.foo := 256 ; + r.foo := 256 } with r function modify_abc (const r : abc) : abc is block { const c : int = 42; - r := r with record b = 2048; c = c; end; + r := r with record [b=2048; c=c] } with r -type big_record is record - a : int ; - b : int ; - c : int ; - d : int ; - e : int ; -end +type big_record is record [a : int; b : int; c : int; d : int; e : int] -const br : big_record = record - a = 23 ; - b = 23 ; - c = 23 ; - d = 23 ; - e = 23 ; -end +const br : big_record = + record [a = 23; b = 23; c = 23; d = 23; e = 23] -type double_record is record - inner : abc; -end +type double_record is record [inner : abc] function modify_inner (const r : double_record) : double_record is block { - r := r with record inner.b = 2048; end; + r := r with record [inner.b = 2048] } with r diff --git a/src/test/contracts/redeclaration.ligo b/src/test/contracts/redeclaration.ligo index c74594ad3..b8bcecbc2 100644 --- a/src/test/contracts/redeclaration.ligo +++ b/src/test/contracts/redeclaration.ligo @@ -1,6 +1,6 @@ -function foo(const p : unit) : int is 0 +function foo (const p : unit) : int is 0 -function main(const p : unit; const s : int) : list(operation) * int is - ((list end : list(operation)), foo(unit)) +function main (const p : unit; const s : int) : list (operation) * int is + ((nil : list (operation)), foo (unit)) -function foo(const p : unit) : int is 1 \ No newline at end of file +function foo (const p : unit) : int is 1 diff --git a/src/test/contracts/replaceable_id.ligo b/src/test/contracts/replaceable_id.ligo index 3b116e69b..8e46cde84 100644 --- a/src/test/contracts/replaceable_id.ligo +++ b/src/test/contracts/replaceable_id.ligo @@ -1,35 +1,35 @@ // storage type -type storage_t is address; +type storage_t is address // entry points parameter types type change_addr_pt is address -type message_t is list (operation) ; -type pass_message_pt is (unit -> message_t) +type message_t is list (operation) +type pass_message_pt is unit -> message_t -type contract_return_t is (list(operation) * storage_t) +type contract_return_t is list (operation) * storage_t type entry_point_t is -| Change_address of change_addr_pt -| Pass_message of pass_message_pt + Change_address of change_addr_pt +| Pass_message of pass_message_pt function change_address (const param : change_addr_pt; const s : storage_t) : contract_return_t is - begin - if sender =/= s then failwith("Unauthorized sender") + block { + if sender =/= s then failwith ("Unauthorized sender") else skip -end with ((nil : list(operation)), param) + } with ((nil : list (operation)), param) -function pass_message ( const param: pass_message_pt; - const s : storage_t ) : contract_return_t is - begin - if sender =/= s then failwith("Unauthorized sender") else skip ; - var message : pass_message_pt := param ; -end with (param(unit),s) +function pass_message (const param: pass_message_pt; + const s : storage_t ) : contract_return_t is + block { + if sender =/= s then failwith("Unauthorized sender") else skip; + var message : pass_message_pt := param + } with (param (unit), s) -function main(const param : entry_point_t; const s : storage_t) : contract_return_t is -block {skip} with +function main (const param : entry_point_t; const s : storage_t) : + contract_return_t is case param of - | Change_address (p) -> change_address(p,s) - | Pass_message (p) -> pass_message(p,s) -end \ No newline at end of file + Change_address (p) -> change_address (p,s) + | Pass_message (p) -> pass_message (p,s) + end diff --git a/src/test/contracts/self_address.ligo b/src/test/contracts/self_address.ligo index 72872ce0f..e6f440a7e 100644 --- a/src/test/contracts/self_address.ligo +++ b/src/test/contracts/self_address.ligo @@ -1 +1 @@ -function main (const p: unit) : address is self_address +function main (const p : unit) : address is self_address diff --git a/src/test/contracts/set_arithmetic-1.ligo b/src/test/contracts/set_arithmetic-1.ligo index 87e2621b2..4ad3b13cf 100644 --- a/src/test/contracts/set_arithmetic-1.ligo +++ b/src/test/contracts/set_arithmetic-1.ligo @@ -1,17 +1,17 @@ // Test set iteration in PascaLIGO -function iter_op (const s : set(int)) : int is - begin - var r : int := 0 ; - function aggregate (const i : int) : unit is - begin - r := r + i ; - end with unit ; - set_iter(aggregate, s) ; - end with r - -function fold_op (const s : set(int)) : int is +function iter_op (const s : set (int)) : int is block { - function aggregate (const i : int ; const j : int) : int is + var r : int := 0; + function aggregate (const i : int) : unit is + block { + r := r + i + } with unit; + set_iter (aggregate, s) + } with r // ALWAYS RETURNS 0 + +function fold_op (const s : set (int)) : int is + block { + function aggregate (const i : int; const j : int) : int is i + j - } with set_fold(aggregate, s , 15) + } with set_fold (aggregate, s, 15) diff --git a/src/test/contracts/set_arithmetic.ligo b/src/test/contracts/set_arithmetic.ligo index eb0f8cf9e..2c801abbe 100644 --- a/src/test/contracts/set_arithmetic.ligo +++ b/src/test/contracts/set_arithmetic.ligo @@ -1,30 +1,27 @@ // Test set type and basic operations in PascaLIGO -const s_e : set(string) = (set_empty : set(string)) +const s_e : set (string) = set_empty -const s_fb : set(string) = set [ - "foo" ; - "bar" ; -] +const s_fb : set (string) = set ["foo"; "bar"] -function add_op (const s : set(string)) : set(string) is - begin skip end with set_add("foobar" , s) +function add_op (const s : set (string)) : set (string) is + set_add ("foobar", s) -function remove_op (const s : set(string)) : set(string) is - begin skip end with set_remove("foobar" , s) +function remove_op (const s : set (string)) : set (string) is + set_remove ("foobar", s) // Test the PascaLIGO syntactic sugar for set removal vs. the function call -function remove_syntax (var s : set(string)) : set(string) is - begin remove "foobar" from set s; end with s +function remove_syntax (var s : set (string)) : set (string) is + block {remove "foobar" from set s} with s -function remove_deep (var s : set(string) * nat) : set(string) * nat is - begin remove "foobar" from set s.0; end with s +function remove_deep (var s : set (string) * nat) : set (string) * nat is + block {remove "foobar" from set s.0} with s -function patch_op (var s: set(string)) : set(string) is - begin patch s with set ["foobar"]; end with s +function patch_op (var s : set (string)) : set (string) is + block {patch s with set ["foobar"]} with s -function patch_op_deep (var s: set(string)*nat) : set(string)*nat is - begin patch s.0 with set ["foobar"]; end with s +function patch_op_deep (var s : set (string) * nat) : set (string) * nat is + block {patch s.0 with set ["foobar"]} with s -function mem_op (const s : set(string)) : bool is - begin skip end with set_mem("foobar" , s) +function mem_op (const s : set (string)) : bool is + set_mem ("foobar", s) diff --git a/src/test/contracts/set_delegate.ligo b/src/test/contracts/set_delegate.ligo index 32f571741..dfdc7a0ef 100644 --- a/src/test/contracts/set_delegate.ligo +++ b/src/test/contracts/set_delegate.ligo @@ -1,6 +1,5 @@ -function main (const p: key_hash) : list(operation) is - begin - const unused: operation = set_delegate(Some(p)) ; - const dummy: list(operation) = nil; - end with dummy - +function main (const p : key_hash) : list (operation) is + block { + const unused : operation = set_delegate (Some (p)); + const dummy : list (operation) = nil + } with dummy diff --git a/src/test/contracts/shadow.ligo b/src/test/contracts/shadow.ligo index a1891c651..a170b6d43 100644 --- a/src/test/contracts/shadow.ligo +++ b/src/test/contracts/shadow.ligo @@ -1,5 +1,4 @@ function foo (const i : int) : int is block { - function bar (const i : int) : int is - i ; + function bar (const i : int) : int is i } with bar (0) diff --git a/src/test/contracts/simple_access.ligo b/src/test/contracts/simple_access.ligo index e26e23bc7..9a5c585a3 100644 --- a/src/test/contracts/simple_access.ligo +++ b/src/test/contracts/simple_access.ligo @@ -1,21 +1,21 @@ -//Test simple_access in PascalLigo -type tpi is (int*int) -type rpi is record -x : int; -y : int; -end -type mpi is map(string,int) +//Test simple_access in PascaLIGO + +type tpi is int * int + +type rpi is record [x : int; y : int] + +type mpi is map (string, int) function main (const toto : tpi) : int is - begin + block { var a : tpi := toto; - var b : rpi := record x = 0; y=1 ; end; - var m : mpi := map "y" -> 1; end; + var b : rpi := record [x=0; y=1]; + var m : mpi := map ["y" -> 1]; a.0 := 2; b.x := a.0; - m["x"] := b.x; - end with - case m["x"] of - | Some (s) -> s - | None -> 42 - end + m["x"] := b.x + } with + case m["x"] of + Some (s) -> s + | None -> 42 + end diff --git a/src/test/contracts/string.ligo b/src/test/contracts/string.ligo index 846daf7e5..c563cd16c 100644 --- a/src/test/contracts/string.ligo +++ b/src/test/contracts/string.ligo @@ -1,3 +1,3 @@ const s : string = "toto" -const x : string = s^"bar" -const y : string = "foo"^x +const x : string = s ^ "bar" +const y : string = "foo" ^ x diff --git a/src/test/contracts/string_arithmetic.ligo b/src/test/contracts/string_arithmetic.ligo index c8ceacb01..d76fd041d 100644 --- a/src/test/contracts/string_arithmetic.ligo +++ b/src/test/contracts/string_arithmetic.ligo @@ -1,5 +1,5 @@ function concat_op (const s : string) : string is - begin skip end with string_concat(s , "toto") + string_concat (s, "toto") function slice_op (const s : string) : string is - begin skip end with string_slice(1n , 2n , s) + string_slice (1n, 2n, s) diff --git a/src/test/contracts/super-counter.ligo b/src/test/contracts/super-counter.ligo index fcfa8422e..5bdde86d0 100644 --- a/src/test/contracts/super-counter.ligo +++ b/src/test/contracts/super-counter.ligo @@ -1,10 +1,14 @@ type action is -| Increment of int + Increment of int | Decrement of int -function main (const p : action ; const s : int) : (list(operation) * int) is - block {skip} with ((nil : list(operation)), - case p of - | Increment (n) -> s + n - | Decrement (n) -> s - n - end) +type storage is int + +type return is list (operation) * storage + +function main (const p : action; const s : int) : return is + ((nil : list (operation)), + case p of + Increment (n) -> s + n + | Decrement (n) -> s - n + end) diff --git a/src/test/contracts/tez.ligo b/src/test/contracts/tez.ligo index 31d5915cf..d39524d2b 100644 --- a/src/test/contracts/tez.ligo +++ b/src/test/contracts/tez.ligo @@ -1,16 +1,18 @@ -const add_tez : tez = 21mutez + 0.000021tz; -const sub_tez : tez = 21mutez - 20mutez; +const add_tez : tez = 21mutez + 0.000_021tez + +const sub_tez : tez = 21mutez - 20mutez + (* This is not enough. *) -const not_enough_tez : tez = 4611686018427387903mutez; +const not_enough_tez : tez = 461_168_601_842_738_7903mutez -const nat_mul_tez : tez = 1n * 100mutez; -const tez_mul_nat : tez = 100mutez * 10n; +const nat_mul_tez : tez = 1n * 100mutez +const tez_mul_nat : tez = 100mutez * 10n -const tez_div_tez1 : nat = 100mutez / 1mutez; -const tez_div_tez2 : nat = 100mutez / 90mutez; -const tez_div_tez3 : nat = 100mutez / 110mutez; +const tez_div_tez1 : nat = 100mutez / 1mutez +const tez_div_tez2 : nat = 100mutez / 90mutez +const tez_div_tez3 : nat = 100mutez / 110mutez -const tez_mod_tez1 : tez = 100mutez mod 1mutez; -const tez_mod_tez2 : tez = 100mutez mod 90mutez; -const tez_mod_tez3 : tez = 100mutez mod 110mutez; +const tez_mod_tez1 : tez = 100mutez mod 1mutez +const tez_mod_tez2 : tez = 100mutez mod 90mutez +const tez_mod_tez3 : tez = 100mutez mod 110mutez diff --git a/src/test/contracts/time-lock.ligo b/src/test/contracts/time-lock.ligo index c45f40a23..24065e25a 100644 --- a/src/test/contracts/time-lock.ligo +++ b/src/test/contracts/time-lock.ligo @@ -1,25 +1,28 @@ type storage_t is timestamp -type message_t is (unit -> list(operation)) +type message_t is unit -> list (operation) type default_pt is unit type call_pt is message_t -type contract_return_t is (list(operation) * storage_t) +type contract_return_t is list (operation) * storage_t type entry_point_t is | Call of call_pt | Default of default_pt -function call (const p : call_pt; const s : storage_t) : contract_return_t is block { - if s >= now then failwith("Contract is still time locked") else skip ; - const message : message_t = p ; - const ret_ops : list(operation) = message(unit) ; -} with (ret_ops,s) +function call (const p : call_pt; const s : storage_t) : contract_return_t is + block { + if s >= now then failwith ("Contract is still time locked") else skip; + const message : message_t = p; + const ret_ops : list (operation) = message (unit) + } with (ret_ops, s) -function default (const p : default_pt; const s : storage_t) : contract_return_t is - ((nil: list(operation)) , s) +function default (const p : default_pt; const s : storage_t) : + contract_return_t is + ((nil : list (operation)), s) -function main(const param : entry_point_t; const s : storage_t) : contract_return_t is +function main(const param : entry_point_t; const s : storage_t) : + contract_return_t is case param of - | Call (p) -> call(p,s) - | Default (p) -> default(p,s) -end \ No newline at end of file + Call (p) -> call (p,s) + | Default (p) -> default (p,s) + end diff --git a/src/test/contracts/timestamp.ligo b/src/test/contracts/timestamp.ligo index 4e105c45f..7d176cda8 100644 --- a/src/test/contracts/timestamp.ligo +++ b/src/test/contracts/timestamp.ligo @@ -1,3 +1,4 @@ type storage_ is timestamp -function main(const p : unit; const s : storage_) : list(operation) * storage_ is ((nil: list(operation)), now) \ No newline at end of file +function main (const p : unit; const s : storage_) : + list (operation) * storage_ is ((nil: list (operation)), now) diff --git a/src/test/contracts/toto.ligo b/src/test/contracts/toto.ligo index 785655b4a..6fd888e1c 100644 --- a/src/test/contracts/toto.ligo +++ b/src/test/contracts/toto.ligo @@ -1,6 +1,3 @@ -type toto is record - a : nat ; - b : nat -end +type toto is record [a : nat; b : nat] const foo : int = 3 diff --git a/src/test/contracts/tuple.ligo b/src/test/contracts/tuple.ligo index 9a39cde03..afe953345 100644 --- a/src/test/contracts/tuple.ligo +++ b/src/test/contracts/tuple.ligo @@ -1,22 +1,18 @@ -type abc is (int * int * int) +type abc is int * int * int -function projection_abc (const tpl : abc) : int is - block { skip } with tpl.1 +function projection_abc (const tpl : abc) : int is tpl.1 function modify_abc (const tpl : abc) : abc is block { - tpl.1 := 2048 ; + tpl.1 := 2048 } with tpl -type foobar is (int * int) +type foobar is int * int -const fb : foobar = (0, 0) +const fb : foobar = (0,0) -function projection (const tpl : foobar) : int is - begin - skip - end with tpl.0 + tpl.1 +function projection (const tpl : foobar) : int is tpl.0 + tpl.1 -type big_tuple is (int * int * int * int * int) +type big_tuple is int * int * int * int * int const br : big_tuple = (23, 23, 23, 23, 23) diff --git a/src/test/contracts/variant-matching.ligo b/src/test/contracts/variant-matching.ligo index 5c13a5053..b19303da3 100644 --- a/src/test/contracts/variant-matching.ligo +++ b/src/test/contracts/variant-matching.ligo @@ -1,11 +1,11 @@ type foobar is -| Foo of int + Foo of int | Bar of bool | Kee of nat -function fb(const p : foobar) : int is - block { skip } with (case p of - | Foo (n) -> n +function fb (const p : foobar) : int is + case p of + Foo (n) -> n | Bar (t) -> 42 | Kee (n) -> 23 - end) + end diff --git a/src/test/contracts/variant.ligo b/src/test/contracts/variant.ligo index b98001a02..af84d1731 100644 --- a/src/test/contracts/variant.ligo +++ b/src/test/contracts/variant.ligo @@ -1,5 +1,5 @@ type foobar is -| Foo of int + Foo of int | Bar of bool | Kee of nat diff --git a/src/test/contracts/website1.ligo b/src/test/contracts/website1.ligo index 4c8272d64..38ea61b8f 100644 --- a/src/test/contracts/website1.ligo +++ b/src/test/contracts/website1.ligo @@ -1,2 +1,2 @@ -function main (const p : int ; const s : int) : (list(operation) * int) is - block {skip} with ((nil : list(operation)), s + 1) +function main (const p : int; const s : int) : list (operation) * int is + ((nil : list (operation)), s + 1) diff --git a/src/test/contracts/website2.ligo b/src/test/contracts/website2.ligo index ac13b7c6f..7d326e407 100644 --- a/src/test/contracts/website2.ligo +++ b/src/test/contracts/website2.ligo @@ -1,16 +1,20 @@ -// variant defining pseudo multi-entrypoint actions +// variant defining entrypoints + type action is -| Increment of int + Increment of int | Decrement of int -function add (const a : int ; const b : int) : int is a + b +type return is list (operation) * int -function subtract (const a : int ; const b : int) : int is a - b +function add (const a : int; const b : int) : int is a + b -// real entrypoint that re-routes the flow based on the action provided -function main (const p : action ; const s : int) : (list(operation) * int) is - ((nil : list(operation)), +function subtract (const a : int; const b : int) : int is a - b + +// main function routing the flow based on the action provided + +function main (const p : action; const s : int) : return is + ((nil : list (operation)), case p of - | Increment (n) -> add (s, n) + Increment (n) -> add (s, n) | Decrement (n) -> subtract (s, n) end) From a9214f864d933bb01f01e6cbf68619f3e9887fbe Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Thu, 27 Feb 2020 19:09:14 +0100 Subject: [PATCH 14/53] Reviewing again the PascaLIGO contracts. --- src/bin/expect_tests/contract_tests.ml | 22 ++++++--- src/passes/operators/operators.ml | 48 +++++++++--------- src/test/contracts/address.ligo | 6 +-- src/test/contracts/amount.ligo | 5 +- src/test/contracts/amount.mligo | 2 +- src/test/contracts/arithmetic.ligo | 16 ++---- src/test/contracts/assign.ligo | 5 +- src/test/contracts/bad_timestamp.ligo | 2 +- src/test/contracts/balance_constant.ligo | 2 +- src/test/contracts/big_map.ligo | 6 +-- src/test/contracts/boolean_operators.ligo | 14 ++---- src/test/contracts/bytes_arithmetic.ligo | 8 ++- src/test/contracts/bytes_unpack.ligo | 12 ++--- src/test/contracts/chain_id.ligo | 2 +- src/test/contracts/check_signature.ligo | 6 +-- src/test/contracts/coase.ligo | 42 +++++++++++----- src/test/contracts/condition-annot.mligo | 2 +- src/test/contracts/condition-shadowing.mligo | 2 - src/test/contracts/condition.mligo | 2 +- src/test/contracts/counter.ligo | 4 +- src/test/contracts/crypto.ligo | 5 +- src/test/contracts/declarations.ligo | 2 - src/test/contracts/deep_access.ligo | 7 ++- src/test/contracts/dispatch-counter.ligo | 1 - src/test/contracts/entrypoints.ligo | 13 +++-- src/test/contracts/failwith.mligo | 4 +- src/test/contracts/for_fail.ligo | 2 +- src/test/contracts/get_contract.ligo | 19 ++++---- src/test/contracts/heap.ligo | 16 ++++-- src/test/contracts/implicit_account.ligo | 3 +- src/test/contracts/key_hash.ligo | 6 +-- src/test/contracts/key_hash_comparable.ligo | 11 +++-- src/test/contracts/list.ligo | 6 +-- src/test/contracts/loop_bugs.ligo | 4 +- src/test/contracts/map.ligo | 14 ++---- src/test/contracts/multisig-v2.ligo | 45 +++++++++-------- src/test/contracts/multisig.ligo | 8 +-- src/test/integration_tests.ml | 51 +++++++------------- 38 files changed, 209 insertions(+), 216 deletions(-) diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index facee666d..317c8a87a 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -7,7 +7,7 @@ let bad_contract basename = let%expect_test _ = run_ligo_good [ "measure-contract" ; contract "coase.ligo" ; "main" ] ; - [%expect {| 1747 bytes |}] ; + [%expect {| 1870 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ; [%expect {| 1324 bytes |}] ; @@ -86,7 +86,9 @@ let%expect_test _ = SWAP ; DIP { DUP ; CAR ; CAR } ; GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_NONE + { PUSH string "buy_single: No card pattern." ; FAILWITH } + { DUP ; DIP { DROP } } ; DUP ; CAR ; DIP { DUP ; CDR ; PUSH nat 1 ; ADD } ; @@ -159,7 +161,9 @@ let%expect_test _ = SWAP ; DIP { DUP ; CAR ; CDR } ; GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_NONE + { PUSH string "sell_single: No card." ; FAILWITH } + { DUP ; DIP { DROP } } ; DUP ; CAR ; SENDER ; @@ -173,7 +177,9 @@ let%expect_test _ = CDR ; DIP { DIP 2 { DUP } ; DIG 2 ; CAR ; CAR } ; GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_NONE + { PUSH string "sell_single: No card pattern." ; FAILWITH } + { DUP ; DIP { DROP } } ; DUP ; DIP { DUP } ; SWAP ; @@ -209,7 +215,9 @@ let%expect_test _ = MUL ; SENDER ; CONTRACT unit ; - IF_NONE { PUSH string "bad address for get_contract" ; FAILWITH } {} ; + IF_NONE + { PUSH string "sell_single: No contract." ; FAILWITH } + { DUP ; DIP { DROP } } ; DIP { DUP } ; SWAP ; DIP { DUP } ; @@ -246,7 +254,9 @@ let%expect_test _ = CAR ; DIP { DUP } ; GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_NONE + { PUSH string "transfer_single: No card." ; FAILWITH } + { DUP ; DIP { DROP } } ; DUP ; CAR ; SENDER ; diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 7cc7f556d..4c72934b2 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -68,30 +68,30 @@ module Simplify = struct (* Tezos module (ex-Michelson) *) | "Tezos.chain_id" -> ok C_CHAIN_ID - | "chain_id" -> ok C_CHAIN_ID (* Deprecated *) - | "get_chain_id" -> ok C_CHAIN_ID (* Deprecated *) + | "chain_id" -> ok C_CHAIN_ID (* Deprecated *) + | "get_chain_id" -> ok C_CHAIN_ID (* Deprecated *) | "Tezos.balance" -> ok C_BALANCE - | "balance" -> ok C_BALANCE (* Deprecated *) + | "balance" -> ok C_BALANCE (* Deprecated *) | "Tezos.now" -> ok C_NOW - | "now" -> ok C_NOW (* Deprecated *) + | "now" -> ok C_NOW (* Deprecated *) | "Tezos.amount" -> ok C_AMOUNT - | "amount" -> ok C_AMOUNT (* Deprecated *) + | "amount" -> ok C_AMOUNT (* Deprecated *) | "Tezos.sender" -> ok C_SENDER - | "sender" -> ok C_SENDER (* Deprecated *) + | "sender" -> ok C_SENDER (* Deprecated *) | "Tezos.address" -> ok C_ADDRESS - | "address" -> ok C_ADDRESS (* Deprecated *) + | "address" -> ok C_ADDRESS (* Deprecated *) | "Tezos.self_address" -> ok C_SELF_ADDRESS - | "self_address" -> ok C_SELF_ADDRESS (* Deprecated *) + | "self_address" -> ok C_SELF_ADDRESS (* Deprecated *) | "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT - | "implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *) + | "implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *) | "Tezos.source" -> ok C_SOURCE - | "source" -> ok C_SOURCE (* Deprecated *) + | "source" -> ok C_SOURCE (* Deprecated *) | "Tezos.failwith" -> ok C_FAILWITH - | "failwith" -> ok C_FAILWITH + | "failwith" -> ok C_FAILWITH - | "Tezos.transaction" -> ok C_CALL + | "Tezos.transaction" -> ok C_CALL | "transaction" -> ok C_CALL (* Deprecated *) - | "Tezos.set_delegate" -> ok C_SET_DELEGATE + | "Tezos.set_delegate" -> ok C_SET_DELEGATE | "set_delegate" -> ok C_SET_DELEGATE (* Deprecated *) | "get_contract" -> ok C_CONTRACT (* Deprecated *) | "Tezos.get_contract_opt" -> ok C_CONTRACT_OPT @@ -144,7 +144,7 @@ module Simplify = struct | "Bytes.unpack" -> ok C_BYTES_UNPACK | "bytes_unpack" -> ok C_BYTES_UNPACK (* Deprecated *) | "Bytes.length" -> ok C_SIZE - | "Bytes.size" -> ok C_SIZE + | "Bytes.size" -> ok C_SIZE (* Deprecated *) | "bytes_concat" -> ok C_CONCAT (* Deprecated *) | "Bytes.concat" -> ok C_CONCAT | "Bytes.slice" -> ok C_SLICE @@ -165,7 +165,8 @@ module Simplify = struct (* Set module *) - | "Set.size" -> ok C_SIZE + | "Set.cardinal" -> ok C_SIZE + | "Set.size" -> ok C_SIZE (* Deprecated *) | "set_size" -> ok C_SIZE (* Deprecated *) | "set_empty" -> ok C_SET_EMPTY (* Deprecated *) | "Set.mem" -> ok C_SET_MEM @@ -339,14 +340,15 @@ module Simplify = struct (* Set module *) - | "Set.mem" -> ok C_SET_MEM - | "Set.iter" -> ok C_SET_ITER - | "Set.empty" -> ok C_SET_EMPTY - | "Set.literal" -> ok C_SET_LITERAL - | "Set.add" -> ok C_SET_ADD - | "Set.remove" -> ok C_SET_REMOVE - | "Set.fold" -> ok C_SET_FOLD - | "Set.size" -> ok C_SIZE + | "Set.mem" -> ok C_SET_MEM + | "Set.iter" -> ok C_SET_ITER + | "Set.empty" -> ok C_SET_EMPTY + | "Set.literal" -> ok C_SET_LITERAL + | "Set.add" -> ok C_SET_ADD + | "Set.remove" -> ok C_SET_REMOVE + | "Set.fold" -> ok C_SET_FOLD + | "Set.size" -> ok C_SIZE (* Deprecated *) + | "Set.cardinal" -> ok C_SIZE (* Map module *) diff --git a/src/test/contracts/address.ligo b/src/test/contracts/address.ligo index 59d5bff4c..ae863ac81 100644 --- a/src/test/contracts/address.ligo +++ b/src/test/contracts/address.ligo @@ -1,5 +1,3 @@ -// function main (const c : contract (unit)) : address is address (c) - function main (const p : key_hash) : address is block { - const c : contract (unit) = implicit_account (p); -} with address (c) \ No newline at end of file + const c : contract (unit) = Tezos.implicit_account (p); +} with Tezos.address (c) diff --git a/src/test/contracts/amount.ligo b/src/test/contracts/amount.ligo index 9c0263635..c7816fae3 100644 --- a/src/test/contracts/amount.ligo +++ b/src/test/contracts/amount.ligo @@ -1,8 +1,5 @@ function check (const p : unit) : int is block { var result : int := 0; - if Tezos.amount = 100tz then - result := 42 - else - result := 0 + if amount = 100tz then result := 42 else result := 0 } with result diff --git a/src/test/contracts/amount.mligo b/src/test/contracts/amount.mligo index a2db44946..c14228fc4 100644 --- a/src/test/contracts/amount.mligo +++ b/src/test/contracts/amount.mligo @@ -1 +1 @@ -let check = if Tezos.amount > 100tez then 42 else 0 +let check_ (p : unit) : int = if Tezos.amount = 100tz then 42 else 0 diff --git a/src/test/contracts/arithmetic.ligo b/src/test/contracts/arithmetic.ligo index de3dc14ae..a4a6c51cb 100644 --- a/src/test/contracts/arithmetic.ligo +++ b/src/test/contracts/arithmetic.ligo @@ -1,15 +1,9 @@ // Test PascaLIGO arithmetic operators -function mod_op (const n : int) : nat is n mod 42 - -function plus_op (const n : int) : int is n + 42 - +function mod_op (const n : int) : nat is n mod 42 +function plus_op (const n : int) : int is n + 42 function minus_op (const n : int) : int is n - 42 - function times_op (const n : int) : int is n * 42 - -function div_op (const n : int) : int is n / 2 - -function int_op (const n : nat) : int is int (n) - -function neg_op (const n : int) : int is -n +function div_op (const n : int) : int is n / 2 +function int_op (const n : nat) : int is int (n) +function neg_op (const n : int) : int is -n diff --git a/src/test/contracts/assign.ligo b/src/test/contracts/assign.ligo index 6c6de5351..b5181e2fd 100644 --- a/src/test/contracts/assign.ligo +++ b/src/test/contracts/assign.ligo @@ -1,4 +1 @@ -function main (const i : int) : int is - block { - i := i + 1 - } with i +function main (const i : int) : int is block {i := i + 1} with i diff --git a/src/test/contracts/bad_timestamp.ligo b/src/test/contracts/bad_timestamp.ligo index 8be6968e2..dff8f6f24 100644 --- a/src/test/contracts/bad_timestamp.ligo +++ b/src/test/contracts/bad_timestamp.ligo @@ -6,4 +6,4 @@ function main (const p : parameter; const s : storage) : return is block { var stamp : timestamp := ("badtimestamp" : timestamp) } - with ((nil: list(operation)), stamp) + with ((nil : list (operation)), stamp) diff --git a/src/test/contracts/balance_constant.ligo b/src/test/contracts/balance_constant.ligo index 6a5af3fe4..b23ae23e6 100644 --- a/src/test/contracts/balance_constant.ligo +++ b/src/test/contracts/balance_constant.ligo @@ -9,4 +9,4 @@ type storage is tez type return is list (operation) * storage function main (const param : parameter; const store: storage) : return is - ((nil : list (operation)), balance) + ((nil : list (operation)), Tezos.balance) diff --git a/src/test/contracts/big_map.ligo b/src/test/contracts/big_map.ligo index 9b8364ac3..b89fb8f05 100644 --- a/src/test/contracts/big_map.ligo +++ b/src/test/contracts/big_map.ligo @@ -8,7 +8,7 @@ function main (const p : parameter; const s : storage) : return is toto := s.0[23]; s.0[2] := 444 } - with ((nil: list(operation)), s) + with ((nil : list (operation)), s) type foo is big_map (int, int) @@ -16,14 +16,12 @@ function set_ (var n : int; var m : foo) : foo is block { m[23] := n } with m -function add (var n : int ; var m : foo) : foo is set_(n,m) +function add (var n : int ; var m : foo) : foo is set_ (n,m) function rm (var m : foo) : foo is block { remove 42 from map m } with m -function gf (const m : foo) : int is get_force (23, m) - function get (const m : foo) : option (int) is m[42] const empty_big_map : big_map (int,int) = big_map [] diff --git a/src/test/contracts/boolean_operators.ligo b/src/test/contracts/boolean_operators.ligo index 122894d25..d19e5ad72 100644 --- a/src/test/contracts/boolean_operators.ligo +++ b/src/test/contracts/boolean_operators.ligo @@ -1,11 +1,5 @@ -// Test PascaLIGO boolean operators - -function or_true (const b : bool) : bool is b or True - -function or_false (const b : bool) : bool is b or False - -function and_true (const b : bool) : bool is b and True - +function or_true (const b : bool) : bool is b or True +function or_false (const b : bool) : bool is b or False +function and_true (const b : bool) : bool is b and True function and_false (const b : bool) : bool is b and False - -function not_bool (const b : bool) : bool is not b +function not_bool (const b : bool) : bool is not b diff --git a/src/test/contracts/bytes_arithmetic.ligo b/src/test/contracts/bytes_arithmetic.ligo index 6d39dd4c9..820cf6fdc 100644 --- a/src/test/contracts/bytes_arithmetic.ligo +++ b/src/test/contracts/bytes_arithmetic.ligo @@ -1,5 +1,3 @@ -function concat_op (const s : bytes) : bytes is bytes_concat (s, 0x7070) - -function slice_op (const s : bytes) : bytes is bytes_slice (1n, 2n, s) - -function hasherman (const s : bytes) : bytes is sha_256 (s) +function concat_op (const s : bytes) : bytes is Bytes.concat (s, 0x7070) +function slice_op (const s : bytes) : bytes is Bytes.sub (1n, 2n, s) +function hasherman (const s : bytes) : bytes is Crypto.sha256 (s) diff --git a/src/test/contracts/bytes_unpack.ligo b/src/test/contracts/bytes_unpack.ligo index e57ace2ab..feb76f806 100644 --- a/src/test/contracts/bytes_unpack.ligo +++ b/src/test/contracts/bytes_unpack.ligo @@ -1,11 +1,11 @@ function id_string (const p : string) : option (string) is block { - const packed : bytes = bytes_pack (p) -} with (bytes_unpack (packed) : option (string)) + const packed : bytes = Bytes.pack (p) +} with (Bytes.unpack (packed) : option (string)) function id_int (const p : int) : option (int) is block { - const packed : bytes = bytes_pack (p) -} with (bytes_unpack (packed) : option (int)) + const packed : bytes = Bytes.pack (p) +} with (Bytes.unpack (packed) : option (int)) function id_address (const p : address) : option (address) is block { - const packed : bytes = bytes_pack (p) -} with (bytes_unpack (packed) : option (address)) + const packed : bytes = Bytes.pack (p) +} with (Bytes.unpack (packed) : option (address)) diff --git a/src/test/contracts/chain_id.ligo b/src/test/contracts/chain_id.ligo index 353ba4a45..ad9f17395 100644 --- a/src/test/contracts/chain_id.ligo +++ b/src/test/contracts/chain_id.ligo @@ -1 +1 @@ -function chain_id (const tt : chain_id) : chain_id is get_chain_id +function chain_id (const tt : chain_id) : chain_id is Tezos.chain_id diff --git a/src/test/contracts/check_signature.ligo b/src/test/contracts/check_signature.ligo index 97de04bd2..83554433e 100644 --- a/src/test/contracts/check_signature.ligo +++ b/src/test/contracts/check_signature.ligo @@ -1,4 +1,4 @@ -function check_signature (const pk : key; +function check_signature (const pk : key; const signed : signature; - const msg: bytes) : bool -is crypto_check (pk, signed, msg) + const msg : bytes) : bool +is Crypto.check (pk, signed, msg) diff --git a/src/test/contracts/coase.ligo b/src/test/contracts/coase.ligo index 5f5b00644..5897b8686 100644 --- a/src/test/contracts/coase.ligo +++ b/src/test/contracts/coase.ligo @@ -45,27 +45,38 @@ type parameter is | Transfer_single of action_transfer_single function transfer_single (const action : action_transfer_single; - const s : storage) : return is block { + const s : storage) : return is + block { const cards : cards = s.cards; - const card : card = get_force (action.card_to_transfer, cards); + const card : card = + case cards[action.card_to_transfer] of + Some (card) -> card + | None -> (failwith ("transfer_single: No card.") : card) + end; if card.card_owner =/= sender then failwith ("This card doesn't belong to you") else skip; card.card_owner := action.destination; cards[action.card_to_transfer] := card; - s.cards := cards; - const operations : list (operation) = nil - } with (operations, s) + s.cards := cards + } with ((nil : list (operation)), s) function sell_single (const action : action_sell_single; const s : storage) : return is block { - const card : card = get_force (action.card_to_sell, s.cards); + const card : card = + case s.cards[action.card_to_sell] of + Some (card) -> card + | None -> (failwith ("sell_single: No card.") : card) + end; if card.card_owner =/= sender then failwith ("This card doesn't belong to you") else skip; const card_pattern : card_pattern = - get_force (card.card_pattern, s.card_patterns); + case s.card_patterns[card.card_pattern] of + Some (pattern) -> pattern + | None -> (failwith ("sell_single: No card pattern.") : card_pattern) + end; card_pattern.quantity := abs (card_pattern.quantity - 1n); const card_patterns : card_patterns = s.card_patterns; card_patterns[card.card_pattern] := card_pattern; @@ -74,8 +85,12 @@ function sell_single (const action : action_sell_single; remove action.card_to_sell from map cards; s.cards := cards; const price : tez = card_pattern.coefficient * card_pattern.quantity; - const receiver : contract (unit) = get_contract (sender); - const op : operation = transaction (unit, price, receiver); + const receiver : contract (unit) = + case (Tezos.get_contract_opt (Tezos.sender) : option (contract (unit))) of + Some (contract) -> contract + | None -> (failwith ("sell_single: No contract.") : contract (unit)) + end; + const op : operation = Tezos.transaction (unit, price, receiver); const operations : list (operation) = list [op] } with (operations, s) @@ -84,12 +99,13 @@ function buy_single (const action : action_buy_single; block { // Check funds const card_pattern : card_pattern = - get_force (action.card_to_buy, s.card_patterns); + case s.card_patterns[action.card_to_buy] of + Some (pattern) -> pattern + | None -> (failwith ("buy_single: No card pattern.") : card_pattern) + end; const price : tez = card_pattern.coefficient * (card_pattern.quantity + 1n); if price > amount then failwith ("Not enough money") else skip; - // Administrative procedure - const operations : list(operation) = nil; // Increase quantity card_pattern.quantity := card_pattern.quantity + 1n; const card_patterns : card_patterns = s.card_patterns; @@ -103,7 +119,7 @@ function buy_single (const action : action_buy_single; ]; s.cards := cards; s.next_id := s.next_id + 1n - } with (operations, s) + } with ((nil : list (operation)), s) function main (const action : parameter; const s : storage) : return is case action of diff --git a/src/test/contracts/condition-annot.mligo b/src/test/contracts/condition-annot.mligo index 93aece587..1eb1bf0f9 100644 --- a/src/test/contracts/condition-annot.mligo +++ b/src/test/contracts/condition-annot.mligo @@ -1,4 +1,4 @@ -type integer is int +type integer = int let main (i : int) = if (i = 2 : bool) then (42 : int) else (0 : integer) diff --git a/src/test/contracts/condition-shadowing.mligo b/src/test/contracts/condition-shadowing.mligo index 97ee6eb51..64f1ff42f 100644 --- a/src/test/contracts/condition-shadowing.mligo +++ b/src/test/contracts/condition-shadowing.mligo @@ -1,5 +1,3 @@ -(* TODO : make a test using mutation, not shadowing *) - let main (i : int) = let result = 0 in if i = 2 then diff --git a/src/test/contracts/condition.mligo b/src/test/contracts/condition.mligo index 31568e353..4807f36c1 100644 --- a/src/test/contracts/condition.mligo +++ b/src/test/contracts/condition.mligo @@ -1,3 +1,3 @@ // Test conditional in CameLIGO -let main (i: int) = if i = 2 then 42 else 0 +let main (i : int) = if i = 2 then 42 else 0 diff --git a/src/test/contracts/counter.ligo b/src/test/contracts/counter.ligo index 295c540ee..70bd7ed30 100644 --- a/src/test/contracts/counter.ligo +++ b/src/test/contracts/counter.ligo @@ -1,7 +1,7 @@ type t is int -function main (const p : int ; const s : t) : list (operation) * int is +function main (const p : int; const s : t) : list (operation) * int is block { skip } // skip is a do nothing instruction, needed for empty blocks - with ((nil : list(operation)), p + s) + with ((nil : list (operation)), p+s) diff --git a/src/test/contracts/crypto.ligo b/src/test/contracts/crypto.ligo index 08d417241..5c963fe6e 100644 --- a/src/test/contracts/crypto.ligo +++ b/src/test/contracts/crypto.ligo @@ -1,3 +1,2 @@ -function hasherman512 (const s: bytes) : bytes is sha_512 (s) - -function hasherman_blake (const s: bytes) : bytes is blake2b (s) +function hasherman512 (const s : bytes) : bytes is Crypto.sha512 (s) +function hasherman_blake (const s : bytes) : bytes is Crypto.blake2b (s) diff --git a/src/test/contracts/declarations.ligo b/src/test/contracts/declarations.ligo index d6cc5dfb5..b41c36819 100644 --- a/src/test/contracts/declarations.ligo +++ b/src/test/contracts/declarations.ligo @@ -1,5 +1,3 @@ -// Test PascaLIGO top-level declarations - const foo : int = 42 function main (const i : int) : int is i + foo diff --git a/src/test/contracts/deep_access.ligo b/src/test/contracts/deep_access.ligo index 2d9ad32d4..4c4159111 100644 --- a/src/test/contracts/deep_access.ligo +++ b/src/test/contracts/deep_access.ligo @@ -21,9 +21,12 @@ function asymetric_tuple_access (const foo : unit) : int is } with tuple.0 + tuple.1.0 + tuple.1.1.0 + tuple.1.1.1 type nested_record_t is - record [nesty : record [mymap : map (int,string)]] + record [nesty : record [mymap : map (int, string)]] function nested_record (var nee : nested_record_t) : string is block { nee.nesty.mymap[1] := "one" - } with get_force (1, nee.nesty.mymap) + } with case nee.nesty.mymap[1] of + Some (s) -> s + | None -> (failwith ("Should not happen.") : string) + end diff --git a/src/test/contracts/dispatch-counter.ligo b/src/test/contracts/dispatch-counter.ligo index c513381ae..0ef19ab75 100644 --- a/src/test/contracts/dispatch-counter.ligo +++ b/src/test/contracts/dispatch-counter.ligo @@ -7,7 +7,6 @@ type storage is int type return is list (operation) * storage function increment (const i : int; const n : int) : int is i+n - function decrement (const i : int; const n : int) : int is i-n const nop : list (operation) = nil diff --git a/src/test/contracts/entrypoints.ligo b/src/test/contracts/entrypoints.ligo index d1945ac8d..d47a8b78a 100644 --- a/src/test/contracts/entrypoints.ligo +++ b/src/test/contracts/entrypoints.ligo @@ -4,9 +4,12 @@ type return is list (operation) * storage function cb (const a : address; const s : storage) : return is block { - const c : contract (unit) = get_entrypoint ("%cb", a) - } - with (list [transaction (unit, 0mutez, c)], s) + const c : contract (unit) = + case (Tezos.get_entrypoint_opt ("%cb", a) : option (contract (unit))) of + Some (contract) -> contract + | None -> (failwith ("cb: Entrypoint not found.") : contract (unit)) + end + } with (list [Tezos.transaction (unit, 0tez, c)], s) function cbo (const a : address; const s : storage) : return is @@ -14,6 +17,6 @@ function cbo (const a : address; const s : storage) : return is const c : contract (unit) = case (get_entrypoint_opt ("%cbo", a) : option (contract (unit))) of Some (c) -> c - | None -> (failwith ("entrypoint not found") : contract (unit)) + | None -> (failwith ("cbo: Entrypoint not found.") : contract (unit)) end - } with (list [transaction(unit, 0mutez, c)], s) + } with (list [Tezos.transaction (unit, 0tez, c)], s) diff --git a/src/test/contracts/failwith.mligo b/src/test/contracts/failwith.mligo index 2938a703d..9d82ed6e3 100644 --- a/src/test/contracts/failwith.mligo +++ b/src/test/contracts/failwith.mligo @@ -1,4 +1,4 @@ type storage = unit -let main (p : unit; store : storage) : operation list * storage = - if true then failwith "This contract always fails" +let main (p, store : unit * storage) : operation list * storage = + failwith "This contract always fails" diff --git a/src/test/contracts/for_fail.ligo b/src/test/contracts/for_fail.ligo index a8c870843..682c5e295 100644 --- a/src/test/contracts/for_fail.ligo +++ b/src/test/contracts/for_fail.ligo @@ -1,2 +1,2 @@ -function main (const a: int) : int is +function main (const a : int) : int is block { for i := 0 to 100 block { skip } } with i diff --git a/src/test/contracts/get_contract.ligo b/src/test/contracts/get_contract.ligo index 8ace2277d..5a7ca3541 100644 --- a/src/test/contracts/get_contract.ligo +++ b/src/test/contracts/get_contract.ligo @@ -1,19 +1,20 @@ type storage is unit type return is list (operation) * storage -function cb (const s : storage) : return is - block { - const c : contract(unit) = get_contract(sender) - } - with (list [transaction(unit, 0mutez, c)], s) +function cb (const s : storage) : return is block { + const c : contract (unit) = + case (Tezos.get_contract_opt (Tezos.sender) : option (contract (unit))) of + Some (contract) -> contract + | None -> (failwith ("cb: No contract.") : contract (unit)) + end +} with (list [Tezos.transaction (unit, 0tez, c)], s) function cbo (const s : unit) : return is block { const c : contract (unit) = - case (get_contract_opt(sender) : option(contract(unit))) of - Some (c) -> c + case (Tezos.get_contract_opt (Tezos.sender) : option (contract (unit))) of + Some (contract) -> contract | None -> (failwith ("contract not found") : contract (unit)) end - } - with (list [transaction(unit, 0mutez, c)], s) + } with (list [Tezos.transaction (unit, 0tez, c)], s) diff --git a/src/test/contracts/heap.ligo b/src/test/contracts/heap.ligo index 66c7747b6..9ff8f8154 100644 --- a/src/test/contracts/heap.ligo +++ b/src/test/contracts/heap.ligo @@ -10,8 +10,12 @@ function get_top (const h : heap) : heap_elt is get_force (1n, h) function pop_switch (const h : heap) : heap is block { const result : heap_elt = get_top (h); - const s : nat = size (h); - const last : heap_elt = get_force (s, h); + const s : nat = Map.size (h); + const last : heap_elt = + case h[s] of + Some (e) -> e + | None -> (failwith ("No element.") : heap_elt) + end; remove 1n from map h; h[1n] := last } with h @@ -19,8 +23,12 @@ function pop_switch (const h : heap) : heap is function pop_ (const h : heap) : nat is block { const result : heap_elt = get_top (h); - const s : nat = size (h); - var current : heap_elt := get_force (s, h); + const s : nat = Map.size (h); + var current : heap_elt := + case h[s] of + Some (e) -> e + | None -> (failwith ("No element.") : heap_elt) + end; const i : nat = 1n; const left : nat = 2n * i; const right : nat = left + 1n; diff --git a/src/test/contracts/implicit_account.ligo b/src/test/contracts/implicit_account.ligo index ad0a6c54b..c1f8b3649 100644 --- a/src/test/contracts/implicit_account.ligo +++ b/src/test/contracts/implicit_account.ligo @@ -1 +1,2 @@ -function main (const kh: key_hash) : contract (unit) is implicit_account (kh) +function main (const kh: key_hash) : contract (unit) is + Tezos.implicit_account (kh) diff --git a/src/test/contracts/key_hash.ligo b/src/test/contracts/key_hash.ligo index 865abfbb8..41c7fe56b 100644 --- a/src/test/contracts/key_hash.ligo +++ b/src/test/contracts/key_hash.ligo @@ -1,7 +1,5 @@ function check_hash_key (const kh1 : key_hash; const k2 : key) : bool * key_hash is block { - var ret : bool := False; - var kh2 : key_hash := crypto_hash_key (k2); - if kh1 = kh2 then ret := True else skip - } with (ret, kh2) + var kh2 : key_hash := Crypto.hash_key (k2); + } with ((kh1 = kh2), kh2) diff --git a/src/test/contracts/key_hash_comparable.ligo b/src/test/contracts/key_hash_comparable.ligo index 02003b927..7c5a60613 100644 --- a/src/test/contracts/key_hash_comparable.ligo +++ b/src/test/contracts/key_hash_comparable.ligo @@ -1,8 +1,9 @@ -type storage is record - one: map(key_hash, nat); - two: big_map(key_hash, bool); -end +type storage is record [ + one : map (key_hash, nat); + two : big_map (key_hash, bool) +] type return is list (operation) * storage -function main (const a : int; const store : storage) : return is ((nil: list(operation)), store) \ No newline at end of file +function main (const a : int; const store : storage) : return is + ((nil : list (operation)), store) diff --git a/src/test/contracts/list.ligo b/src/test/contracts/list.ligo index 155b80ac5..ae01f1559 100644 --- a/src/test/contracts/list.ligo +++ b/src/test/contracts/list.ligo @@ -17,17 +17,17 @@ const bl : foobar = list [144; 51; 42; 120; 421] function fold_op (const s : list (int)) : int is block { function aggregate (const prec: int; const cur: int) : int is prec+cur - } with list_fold (aggregate, s, 10) + } with List.fold (aggregate, s, 10) function iter_op (const s : list (int)) : int is block { var r : int := 0; function aggregate (const i : int) : unit is block { r := r + i } with unit; - list_iter (aggregate, s) + List.iter (aggregate, s) } with r function map_op (const s : list (int)) : list (int) is block { function increment (const i : int) : int is i+1 - } with list_map (increment, s) + } with List.map (increment, s) diff --git a/src/test/contracts/loop_bugs.ligo b/src/test/contracts/loop_bugs.ligo index 1a18a6758..55b443352 100644 --- a/src/test/contracts/loop_bugs.ligo +++ b/src/test/contracts/loop_bugs.ligo @@ -1,6 +1,6 @@ function shadowing_in_body (var nee : unit) : string is block { var st : string := ""; - var list1 : list(string) := list "to"; "to" end; + var list1 : list (string) := list ["to"; "to"]; for x in list list1 block { const x : string = "ta"; st := st ^ x; @@ -10,7 +10,7 @@ function shadowing_in_body (var nee : unit) : string is block { function shadowing_assigned_in_body (var nee : unit) : string is block { var st : string := ""; - var list1 : list(string) := list "to"; "to" end; + var list1 : list (string) := list ["to"; "to"]; for x in list list1 block { st := st ^ x; var st : string := "ta"; diff --git a/src/test/contracts/map.ligo b/src/test/contracts/map.ligo index eabd8edc7..51339ada4 100644 --- a/src/test/contracts/map.ligo +++ b/src/test/contracts/map.ligo @@ -30,32 +30,28 @@ function patch_ (var m : foobar) : foobar is block { function patch_deep (var m : foobar * nat) : foobar * nat is block { patch m.0 with map [1 -> 9] } with m -function size_ (const m : foobar) : nat is size (m) - -function gf (const m : foobar) : int is get_force (23, m) +function size_ (const m : foobar) : nat is Map.size (m) function get (const m : foobar) : option (int) is m[42] -function get_ (const m : foobar) : option (int) is map_get (42, m) - -function mem (const k: int; const m: foobar) : bool is map_mem (k, m) +function mem (const k: int; const m: foobar) : bool is Map.mem (k, m) function iter_op (const m : foobar) : unit is block { function aggregate (const i : int; const j : int) : unit is block { if i=j then skip else failwith ("fail") } with unit - } with map_iter (aggregate, m) + } with Map.iter (aggregate, m) function map_op (const m : foobar) : foobar is block { function increment (const i : int; const j : int) : int is j+1 - } with map_map (increment, m) + } with Map.map (increment, m) function fold_op (const m : foobar) : int is block { function aggregate (const i : int; const j : int * int) : int is i + j.0 + j.1 - } with map_fold(aggregate, m, 10) + } with Map.fold (aggregate, m, 10) function deep_op (var m : foobar) : foobar is block { diff --git a/src/test/contracts/multisig-v2.ligo b/src/test/contracts/multisig-v2.ligo index cb3292d18..002379827 100644 --- a/src/test/contracts/multisig-v2.ligo +++ b/src/test/contracts/multisig-v2.ligo @@ -37,22 +37,22 @@ function send (const param : send_pt; const s : storage) : return is block { // check sender against the authorized addresses - if not set_mem (sender, s.authorized_addresses) + if not Set.mem (Tezos.sender, s.authorized_addresses) then failwith("Unauthorized address") else skip; // check message size against the stored limit var message : message := param; - const packed_msg : bytes = bytes_pack (message); - if size (packed_msg) > s.max_message_size + const packed_msg : bytes = Bytes.pack (message); + if Bytes.length (packed_msg) > s.max_message_size then failwith ("Message size exceed maximum limit") else skip; (* compute the new set of addresses associated with the message and update counters *) - var new_store : addr_set := set_empty; + var new_store : addr_set := set []; case map_get (packed_msg, s.message_store) of Some (voters) -> @@ -60,26 +60,25 @@ function send (const param : send_pt; const s : storage) : return is (* The message is already stored. Increment the counter only if the sender is not already associated with the message. *) - if set_mem (sender, voters) + if Set.mem (Tezos.sender, voters) then skip - else s.proposal_counters[sender] := - get_force (sender, s.proposal_counters) + 1n; - - new_store := set_add(sender,voters) + else s.proposal_counters[Tezos.sender] := + get_force (Tezos.sender, s.proposal_counters) + 1n; + new_store := Set.add (Tezos.sender,voters) } | None -> block { // the message has never been received before s.proposal_counters[sender] := - get_force (sender, s.proposal_counters) + 1n; - new_store := set [sender] + get_force (Tezos.sender, s.proposal_counters) + 1n; + new_store := set [Tezos.sender] } end; // check sender counters against the maximum number of proposal var sender_proposal_counter : nat := - get_force (sender, s.proposal_counters); + get_force (Tezos.sender, s.proposal_counters); if sender_proposal_counter > s.max_proposal then failwith ("Maximum number of proposal reached") @@ -89,14 +88,14 @@ function send (const param : send_pt; const s : storage) : return is var ret_ops : list (operation) := nil; - if size (new_store) >= s.threshold then { + if Set.cardinal (new_store) >= s.threshold then { remove packed_msg from map s.message_store; ret_ops := message (s.state_hash); // update the state hash - s.state_hash := sha_256 (bytes_concat (s.state_hash, packed_msg)); + s.state_hash := Crypto.sha256 (Bytes.concat (s.state_hash, packed_msg)); // decrement the counters for addr -> ctr in map s.proposal_counters block { - if set_mem(addr,new_store) then + if Set.mem (addr, new_store) then s.proposal_counters[addr] := abs (ctr - 1n) else skip } @@ -106,26 +105,26 @@ function send (const param : send_pt; const s : storage) : return is function withdraw (const param : withdraw_pt; const s : storage) : return is block { var message : message := param; - const packed_msg : bytes = bytes_pack (message); + const packed_msg : bytes = Bytes.pack (message); - case map_get(packed_msg, s.message_store) of + case s.message_store[packed_msg] of Some (voters) -> block { // The message is stored - const new_set : addr_set = set_remove (sender, voters); + const new_set : addr_set = Set.remove (Tezos.sender, voters); (* Decrement the counter only if the sender was already associated with the message *) - if size (voters) =/= size (new_set) - then s.proposal_counters[sender] := - abs (get_force (sender, s.proposal_counters) - 1n) - else skip ; + if Set.cardinal (voters) =/= Set.cardinal (new_set) + then s.proposal_counters[Tezos.sender] := + abs (get_force (Tezos.sender, s.proposal_counters) - 1n) + else skip; (* If the message is left without any associated addresses, remove the corresponding message_store field *) - if size (new_set) = 0n + if Set.cardinal (new_set) = 0n then remove packed_msg from map s.message_store else s.message_store[packed_msg] := new_set } diff --git a/src/test/contracts/multisig.ligo b/src/test/contracts/multisig.ligo index f0cdb636c..19c8fc3c4 100644 --- a/src/test/contracts/multisig.ligo +++ b/src/test/contracts/multisig.ligo @@ -38,7 +38,7 @@ function check_message (const param : check_message_pt; failwith ("Counters does not match") else { const packed_payload : bytes = - bytes_pack ((message, param.counter, s.id, get_chain_id)); + Bytes.pack ((message, param.counter, s.id, Tezos.chain_id)); var valid : nat := 0n; var keys : authorized_keys := s.auth; @@ -47,12 +47,12 @@ function check_message (const param : check_message_pt; nil -> skip | key # tl -> block { keys := tl; - if pkh_sig.0 = crypto_hash_key (key) then - if crypto_check (key, pkh_sig.1, packed_payload) + if pkh_sig.0 = Crypto.hash_key (key) then + if Crypto.check (key, pkh_sig.1, packed_payload) then valid := valid + 1n else failwith ("Invalid signature") else skip - } + } end }; diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index b8270e005..2ad0dfc8f 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1019,21 +1019,11 @@ let map_ type_f path : unit result = let make_expected = e_nat in expect_eq_n_strict_pos_small program "size_" make_input make_expected in - let%bind () = - let make_input = fun n -> ez [(23, n) ; (42, 4)] in - let make_expected = e_int in - expect_eq_n program "gf" make_input make_expected - in let%bind () = let make_input = fun n -> ez [(23, n) ; (42, 4)] in let make_expected = fun _ -> e_some @@ e_int 4 in expect_eq_n program "get" make_input make_expected in - let%bind () = - let make_input = fun n -> ez [(23, n) ; (42, 4)] in - let make_expected = fun _ -> e_some @@ e_int 4 in - expect_eq_n program "get_" make_input make_expected - in let%bind () = let input_map = ez [(23, 10) ; (42, 4)] in expect_eq program "mem" (e_tuple [(e_int 23) ; input_map]) (e_bool true) @@ -1081,11 +1071,6 @@ let big_map_ type_f path : unit result = let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in (e_typed_big_map lst' t_int t_int) in - let%bind () = - let make_input = fun n -> ez [(23, n) ; (42, 4)] in - let make_expected = e_int in - expect_eq_n program "gf" make_input make_expected - in let%bind () = let make_input = fun n -> let m = ez [(23 , 0) ; (42 , 0)] in @@ -2241,51 +2226,51 @@ let empty_case_religo () : unit result = in ok () -let tuple_type_mligo () : unit result = +let tuple_type_mligo () : unit result = let%bind program = mtype_file "./contracts/tuple_type.mligo" in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "test1" input expected in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 12 in expect_eq_n program "test2" input expected in ok () -let tuple_type_religo () : unit result = +let tuple_type_religo () : unit result = let%bind program = retype_file "./contracts/tuple_type.religo" in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "arguments_test" input expected in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "tuple_test" input expected in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "arguments_test_inline" input expected in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "tuple_test_inline" input expected in ok () -let no_semicolon_religo () : unit result = +let no_semicolon_religo () : unit result = let%bind program = retype_file "./contracts/no_semicolon.religo" in - let%bind () = - let input _ = e_int 2 in + let%bind () = + let input _ = e_int 2 in let expected _ = e_int 3 in expect_eq_n program "a" input expected - in + in ok () let loop_bugs_ligo () : unit result = From a434b935c66a778c0dcfcaddee7273300a1b9136 Mon Sep 17 00:00:00 2001 From: Maksym Bykovskyy Date: Thu, 27 Feb 2020 22:20:23 +0000 Subject: [PATCH 15/53] Compiling storage with compile-storage command instead of compile-expression --- .../client/src/components/output-tab.tsx | 2 +- .../client/src/redux/actions/deploy.ts | 6 ++- .../packages/client/src/services/api.ts | 17 +++++++++ .../webide/packages/e2e/test/common-utils.js | 13 +++++++ tools/webide/packages/e2e/test/deploy.spec.js | 38 +++++++++++++++++++ .../packages/server/src/ligo-compiler.ts | 28 ++++++++++++++ .../server/test/ligo-compiler.spec.ts | 37 ++++++++++++++++++ 7 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 tools/webide/packages/e2e/test/deploy.spec.js create mode 100644 tools/webide/packages/server/test/ligo-compiler.spec.ts diff --git a/tools/webide/packages/client/src/components/output-tab.tsx b/tools/webide/packages/client/src/components/output-tab.tsx index 0f6cad87e..22e0a397c 100644 --- a/tools/webide/packages/client/src/components/output-tab.tsx +++ b/tools/webide/packages/client/src/components/output-tab.tsx @@ -132,7 +132,7 @@ export const OutputTabComponent = (props: { return ( - {output.length !== 0 && ( + {!(loading.loading || output.length === 0) && ( copyOutput(preRef.current)} onDownload={() => downloadOutput(preRef.current)} diff --git a/tools/webide/packages/client/src/redux/actions/deploy.ts b/tools/webide/packages/client/src/redux/actions/deploy.ts index e8b8c2d9e..ffc62c966 100644 --- a/tools/webide/packages/client/src/redux/actions/deploy.ts +++ b/tools/webide/packages/client/src/redux/actions/deploy.ts @@ -2,7 +2,7 @@ import { Tezos } from '@taquito/taquito'; import { TezBridgeSigner } from '@taquito/tezbridge-signer'; import { Dispatch } from 'redux'; -import { compileContract, compileExpression, deploy, getErrorMessage } from '../../services/api'; +import { compileContract, compileStorage, deploy, getErrorMessage } from '../../services/api'; import { AppState } from '../app'; import { MichelsonFormat } from '../compile'; import { DoneLoadingAction, UpdateLoadingAction } from '../loading'; @@ -32,8 +32,10 @@ export class DeployAction extends CancellableAction { } dispatch({ ...new UpdateLoadingAction('Compiling storage...') }); - const michelsonStorage = await compileExpression( + const michelsonStorage = await compileStorage( editorState.language, + editorState.code, + deployState.entrypoint, deployState.storage, MichelsonFormat.Json ); diff --git a/tools/webide/packages/client/src/services/api.ts b/tools/webide/packages/client/src/services/api.ts index 14d89b391..39defca87 100644 --- a/tools/webide/packages/client/src/services/api.ts +++ b/tools/webide/packages/client/src/services/api.ts @@ -36,6 +36,23 @@ export async function compileExpression( return response.data; } +export async function compileStorage( + syntax: Language, + code: string, + entrypoint: string, + storage: string, + format?: string +) { + const response = await axios.post('/api/compile-storage', { + syntax, + code, + entrypoint, + storage, + format + }); + return response.data; +} + export async function dryRun( syntax: Language, code: string, diff --git a/tools/webide/packages/e2e/test/common-utils.js b/tools/webide/packages/e2e/test/common-utils.js index 4b6c53cc1..68cddbadc 100644 --- a/tools/webide/packages/e2e/test/common-utils.js +++ b/tools/webide/packages/e2e/test/common-utils.js @@ -79,6 +79,19 @@ exports.verifyAllExamples = async (action, done) => { done(); }; +exports.verifyWithParameter = async (command, parameter, value, action, done) => { + await page.click('#command-select'); + await page.click(`#${command}`); + + await page.click(`#${parameter}`); + await exports.clearText(page.keyboard); + await page.keyboard.type(value); + + expect(await action()).toEqual(`Error: "${parameter}" is not allowed to be empty`); + + done(); +} + exports.verifyWithBlankParameter = async (command, parameter, action, done) => { await page.click('#command-select'); await page.click(`#${command}`); diff --git a/tools/webide/packages/e2e/test/deploy.spec.js b/tools/webide/packages/e2e/test/deploy.spec.js new file mode 100644 index 000000000..ba0424565 --- /dev/null +++ b/tools/webide/packages/e2e/test/deploy.spec.js @@ -0,0 +1,38 @@ +const commonUtils = require('./common-utils'); + +const API_HOST = commonUtils.API_HOST; + +const runCommandAndGetOutputFor = commonUtils.runCommandAndGetOutputFor; +const clearText = commonUtils.clearText; + +const COMMAND = 'deploy'; +const COMMAND_ENDPOINT = 'deploy'; + +async function deploy() { + return await runCommandAndGetOutputFor(COMMAND, COMMAND_ENDPOINT); +} + +describe('Deploy contract', () => { + beforeAll(() => jest.setTimeout(60000)); + + beforeEach(async () => await page.goto(API_HOST)); + + it('should deploy', async done => { + expect(await deploy()).toContain('The contract was successfully deployed to the babylonnet test network.'); + + done(); + }); + + it('should fail to deploy contract with invalid storage', async done => { + await page.click('#command-select'); + await page.click(`#deploy`); + + await page.click(`#storage`); + await clearText(page.keyboard); + await page.keyboard.type('asdf'); + + expect(await deploy()).toContain('Error: '); + + done(); + }); +}); diff --git a/tools/webide/packages/server/src/ligo-compiler.ts b/tools/webide/packages/server/src/ligo-compiler.ts index b239cab73..53b575b3c 100644 --- a/tools/webide/packages/server/src/ligo-compiler.ts +++ b/tools/webide/packages/server/src/ligo-compiler.ts @@ -120,6 +120,7 @@ export class LigoCompiler { format: string ) { const { name, remove } = await this.createTemporaryFile(code); + try { const result = await this.execPromise(this.ligoCmd, [ 'compile-contract', @@ -148,6 +149,33 @@ export class LigoCompiler { return result; } + async compileStorage( + syntax: string, + code: string, + entrypoint: string, + format: string, + storage: string + ) { + const { name, remove } = await this.createTemporaryFile(code); + + try { + const result = await this.execPromise(this.ligoCmd, [ + 'compile-storage', + '--michelson-format', + format, + '-s', + syntax, + name, + entrypoint, + storage + ]); + + return result; + } finally { + remove(); + } + } + async dryRun( syntax: string, code: string, diff --git a/tools/webide/packages/server/test/ligo-compiler.spec.ts b/tools/webide/packages/server/test/ligo-compiler.spec.ts new file mode 100644 index 000000000..f5dbd0109 --- /dev/null +++ b/tools/webide/packages/server/test/ligo-compiler.spec.ts @@ -0,0 +1,37 @@ +import { LigoCompiler } from '../src/ligo-compiler'; + +const PASCALIGO_CODE = ` +type action is +| Increment of int +| Decrement of int + +function add (const a : int ; const b : int) : int is + block { skip } with a + b + +function subtract (const a : int ; const b : int) : int is + block { skip } with a - b + +function main (const p : action ; const s : int) : + (list(operation) * int) is + block { skip } with ((nil : list(operation)), + case p of + | Increment(n) -> add(s, n) + | Decrement(n) -> subtract(s, n) + end) +`; + +describe('Ligo compiler', () => { + it('should compile storage', async done => { + const michelsonCode = await new LigoCompiler().compileStorage( + 'pascaligo', + PASCALIGO_CODE, + 'main', + 'json', + '0' + ); + + expect(michelsonCode.trim()).toEqual('{ "int": "0" }'); + + done(); + }); +}); From 62f3304bc41bc9b5046d70ecc48fff3de36859b8 Mon Sep 17 00:00:00 2001 From: Maksym Bykovskyy Date: Thu, 27 Feb 2020 12:22:43 -0800 Subject: [PATCH 16/53] Added view in try-michelson link --- .../client/src/components/output-tab.tsx | 38 ++++---- .../client/src/components/output-toolbar.tsx | 92 ++++++++----------- .../client/src/components/toolbar.tsx | 65 +++++++++++++ tools/webide/packages/client/src/index.css | 2 +- .../client/src/redux/actions/compile.ts | 10 +- .../client/src/redux/actions/deploy.ts | 10 +- .../client/src/redux/actions/dry-run.ts | 8 +- .../src/redux/actions/evaluate-function.ts | 10 +- .../src/redux/actions/evaluate-value.ts | 10 +- .../packages/client/src/redux/result.ts | 20 +++- 10 files changed, 178 insertions(+), 87 deletions(-) create mode 100644 tools/webide/packages/client/src/components/toolbar.tsx diff --git a/tools/webide/packages/client/src/components/output-tab.tsx b/tools/webide/packages/client/src/components/output-tab.tsx index 22e0a397c..147942910 100644 --- a/tools/webide/packages/client/src/components/output-tab.tsx +++ b/tools/webide/packages/client/src/components/output-tab.tsx @@ -7,6 +7,7 @@ import { AppState } from '../redux/app'; import { CommandState } from '../redux/command'; import { DoneLoadingAction, LoadingState } from '../redux/loading'; import { ResultState } from '../redux/result'; +import { Command } from '../redux/types'; import { OutputToolbarComponent } from './output-toolbar'; const Container = styled.div<{ visible?: boolean }>` @@ -43,7 +44,7 @@ const CancelButton = styled.div` const Output = styled.div` flex: 1; - padding: 0 0.5em 0.5em 0.5em; + padding: 0.5em; display: flex; overflow: scroll; /* This font size is used to calcuate spinner size */ @@ -81,20 +82,18 @@ function copyOutput(el: HTMLElement | null) { } } -function downloadOutput(el: HTMLElement | null) { - if (el) { - const anchor = document.createElement('a'); - anchor.setAttribute( - 'href', - 'data:text/plain;charset=utf-8,' + encodeURIComponent(el.innerHTML) - ); - anchor.setAttribute('download', 'output.txt'); +function downloadOutput(output: string) { + const anchor = document.createElement('a'); + anchor.setAttribute( + 'href', + `data:text/plain;charset=utf-8,${encodeURIComponent(output)}` + ); + anchor.setAttribute('download', 'output.txt'); - anchor.style.display = 'none'; - document.body.appendChild(anchor); - anchor.click(); - document.body.removeChild(anchor); - } + anchor.style.display = 'none'; + document.body.appendChild(anchor); + anchor.click(); + document.body.removeChild(anchor); } export const OutputTabComponent = (props: { @@ -107,6 +106,9 @@ export const OutputTabComponent = (props: { const contract = useSelector( state => state.result.contract ); + const command = useSelector( + state => state.result.command + ); const loading = useSelector(state => state.loading); @@ -132,10 +134,14 @@ export const OutputTabComponent = (props: { return ( - {!(loading.loading || output.length === 0) && ( + {!( + loading.loading || + output.length === 0 || + command !== Command.Compile + ) && ( copyOutput(preRef.current)} - onDownload={() => downloadOutput(preRef.current)} + onDownload={() => downloadOutput(output)} > )} diff --git a/tools/webide/packages/client/src/components/output-toolbar.tsx b/tools/webide/packages/client/src/components/output-toolbar.tsx index a258352ce..871dcb873 100644 --- a/tools/webide/packages/client/src/components/output-toolbar.tsx +++ b/tools/webide/packages/client/src/components/output-toolbar.tsx @@ -1,78 +1,58 @@ import { faCopy, faDownload } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import React from 'react'; +import { useSelector } from 'react-redux'; import styled from 'styled-components'; +import { AppState } from '../redux/app'; +import { ResultState } from '../redux/result'; +import { Item, Toolbar } from './toolbar'; import { Tooltip } from './tooltip'; -const Container = styled.div` - display: flex; - justify-content: flex-start; - padding: 0.2em 0.5em; - z-index: 3; +const Divider = styled.div` + display: block; + background-color: rgba(0, 0, 0, 0.12); + height: 20px; + width: 1px; + margin: 0 3px; `; -const Action = styled.div` - z-index: 3; - position: relative; - margin: 4px 6px; - cursor: pointer; - - opacity: 0.5; - color: #444; - - ::before { - content: ''; - display: block; - position: absolute; - z-index: -1; - bottom: -4px; - left: -4px; - right: -4px; - top: -4px; - border-radius: 4px; - background: none; - box-sizing: border-box; - opacity: 0; - transform: scale(0); - transition-property: transform, opacity; - transition-duration: 0.15s; - transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); - } - - :hover::before { - background-color: rgba(32, 33, 36, 0.059); - opacity: 1; - transform: scale(1); - } - - :hover { - opacity: 1; - } - - &:first-child { - margin-left: 0; - } - - &:last-child { - margin-right: 0; - } +const Link = styled.a` + font-size: 0.8em; + color: var(--blue); + opacity: 1; `; export const OutputToolbarComponent = (props: { onCopy?: () => void; onDownload?: () => void; }) => { + const output = useSelector( + state => state.result.output + ); + return ( - - props.onCopy && props.onCopy()}> + + props.onCopy && props.onCopy()}> Copy - - props.onDownload && props.onDownload()}> + + props.onDownload && props.onDownload()}> Download - - + + + + + View in Try-Michelson IDE + + + ); }; diff --git a/tools/webide/packages/client/src/components/toolbar.tsx b/tools/webide/packages/client/src/components/toolbar.tsx new file mode 100644 index 000000000..ef3386fab --- /dev/null +++ b/tools/webide/packages/client/src/components/toolbar.tsx @@ -0,0 +1,65 @@ +import React from 'react'; +import styled from 'styled-components'; + +const Container = styled.div` + display: flex; + align-items: center; + padding: 0.2em 0.5em; + z-index: 3; +`; + +export const Group = styled.div` + display: flex; + align-items: center; +`; + +export const Item = styled.div` + z-index: 3; + position: relative; + margin: 4px 6px; + cursor: pointer; + + opacity: 0.5; + color: #444; + + ::before { + content: ''; + display: block; + position: absolute; + z-index: -1; + bottom: -4px; + left: -4px; + right: -4px; + top: -4px; + border-radius: 4px; + background: none; + box-sizing: border-box; + opacity: 0; + transform: scale(0); + transition-property: transform, opacity; + transition-duration: 0.15s; + transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); + } + + :hover::before { + background-color: rgba(32, 33, 36, 0.059); + opacity: 1; + transform: scale(1); + } + + :hover { + opacity: 1; + } + + &:first-child { + margin-left: 0; + } + + &:last-child { + margin-right: 0; + } +`; + +export const Toolbar = (props: any) => { + return {props.children}; +}; diff --git a/tools/webide/packages/client/src/index.css b/tools/webide/packages/client/src/index.css index 1f3296c3f..adb1df287 100644 --- a/tools/webide/packages/client/src/index.css +++ b/tools/webide/packages/client/src/index.css @@ -48,7 +48,7 @@ --font_ghost_weight: 700; --font_ghost_color: rgba(153, 153, 153, 0.5); /* or #CFCFCF */ - --content_height: 85vh; + --content_height: 84vh; --tooltip_foreground: white; --tooltip_background: rgba(0, 0, 0, 0.75) /*#404040*/; diff --git a/tools/webide/packages/client/src/redux/actions/compile.ts b/tools/webide/packages/client/src/redux/actions/compile.ts index 2c3f21a29..cd2ed98db 100644 --- a/tools/webide/packages/client/src/redux/actions/compile.ts +++ b/tools/webide/packages/client/src/redux/actions/compile.ts @@ -4,6 +4,7 @@ import { compileContract, getErrorMessage } from '../../services/api'; import { AppState } from '../app'; import { DoneLoadingAction, UpdateLoadingAction } from '../loading'; import { ChangeOutputAction } from '../result'; +import { Command } from '../types'; import { CancellableAction } from './cancellable'; export class CompileAction extends CancellableAction { @@ -24,13 +25,18 @@ export class CompileAction extends CancellableAction { return; } - dispatch({ ...new ChangeOutputAction(michelsonCode.result) }); + dispatch({ + ...new ChangeOutputAction(michelsonCode.result, Command.Compile) + }); } catch (ex) { if (this.isCancelled()) { return; } dispatch({ - ...new ChangeOutputAction(`Error: ${getErrorMessage(ex)}`) + ...new ChangeOutputAction( + `Error: ${getErrorMessage(ex)}`, + Command.Compile + ) }); } diff --git a/tools/webide/packages/client/src/redux/actions/deploy.ts b/tools/webide/packages/client/src/redux/actions/deploy.ts index ffc62c966..5fc9dcf1d 100644 --- a/tools/webide/packages/client/src/redux/actions/deploy.ts +++ b/tools/webide/packages/client/src/redux/actions/deploy.ts @@ -7,6 +7,7 @@ import { AppState } from '../app'; import { MichelsonFormat } from '../compile'; import { DoneLoadingAction, UpdateLoadingAction } from '../loading'; import { ChangeContractAction, ChangeOutputAction } from '../result'; +import { Command } from '../types'; import { CancellableAction } from './cancellable'; Tezos.setProvider({ @@ -85,13 +86,18 @@ export class DeployAction extends CancellableAction { return; } - dispatch({ ...new ChangeContractAction(contract.address) }); + dispatch({ + ...new ChangeContractAction(contract.address, Command.Deploy) + }); } catch (ex) { if (this.isCancelled()) { return; } dispatch({ - ...new ChangeOutputAction(`Error: ${getErrorMessage(ex)}`) + ...new ChangeOutputAction( + `Error: ${getErrorMessage(ex)}`, + Command.Deploy + ) }); } diff --git a/tools/webide/packages/client/src/redux/actions/dry-run.ts b/tools/webide/packages/client/src/redux/actions/dry-run.ts index 9b51a58ff..515435647 100644 --- a/tools/webide/packages/client/src/redux/actions/dry-run.ts +++ b/tools/webide/packages/client/src/redux/actions/dry-run.ts @@ -4,6 +4,7 @@ import { dryRun, getErrorMessage } from '../../services/api'; import { AppState } from '../app'; import { DoneLoadingAction, UpdateLoadingAction } from '../loading'; import { ChangeOutputAction } from '../result'; +import { Command } from '../types'; import { CancellableAction } from './cancellable'; export class DryRunAction extends CancellableAction { @@ -25,13 +26,16 @@ export class DryRunAction extends CancellableAction { if (this.isCancelled()) { return; } - dispatch({ ...new ChangeOutputAction(result.output) }); + dispatch({ ...new ChangeOutputAction(result.output, Command.DryRun) }); } catch (ex) { if (this.isCancelled()) { return; } dispatch({ - ...new ChangeOutputAction(`Error: ${getErrorMessage(ex)}`) + ...new ChangeOutputAction( + `Error: ${getErrorMessage(ex)}`, + Command.DryRun + ) }); } diff --git a/tools/webide/packages/client/src/redux/actions/evaluate-function.ts b/tools/webide/packages/client/src/redux/actions/evaluate-function.ts index 85871ebda..ab7b0053f 100644 --- a/tools/webide/packages/client/src/redux/actions/evaluate-function.ts +++ b/tools/webide/packages/client/src/redux/actions/evaluate-function.ts @@ -4,6 +4,7 @@ import { getErrorMessage, runFunction } from '../../services/api'; import { AppState } from '../app'; import { DoneLoadingAction, UpdateLoadingAction } from '../loading'; import { ChangeOutputAction } from '../result'; +import { Command } from '../types'; import { CancellableAction } from './cancellable'; export class EvaluateFunctionAction extends CancellableAction { @@ -27,13 +28,18 @@ export class EvaluateFunctionAction extends CancellableAction { if (this.isCancelled()) { return; } - dispatch({ ...new ChangeOutputAction(result.output) }); + dispatch({ + ...new ChangeOutputAction(result.output, Command.EvaluateFunction) + }); } catch (ex) { if (this.isCancelled()) { return; } dispatch({ - ...new ChangeOutputAction(`Error: ${getErrorMessage(ex)}`) + ...new ChangeOutputAction( + `Error: ${getErrorMessage(ex)}`, + Command.EvaluateFunction + ) }); } diff --git a/tools/webide/packages/client/src/redux/actions/evaluate-value.ts b/tools/webide/packages/client/src/redux/actions/evaluate-value.ts index 16f46696d..765476884 100644 --- a/tools/webide/packages/client/src/redux/actions/evaluate-value.ts +++ b/tools/webide/packages/client/src/redux/actions/evaluate-value.ts @@ -4,6 +4,7 @@ import { evaluateValue, getErrorMessage } from '../../services/api'; import { AppState } from '../app'; import { DoneLoadingAction, UpdateLoadingAction } from '../loading'; import { ChangeOutputAction } from '../result'; +import { Command } from '../types'; import { CancellableAction } from './cancellable'; export class EvaluateValueAction extends CancellableAction { @@ -28,13 +29,18 @@ export class EvaluateValueAction extends CancellableAction { return; } - dispatch({ ...new ChangeOutputAction(result.code) }); + dispatch({ + ...new ChangeOutputAction(result.code, Command.EvaluateValue) + }); } catch (ex) { if (this.isCancelled()) { return; } dispatch({ - ...new ChangeOutputAction(`Error: ${getErrorMessage(ex)}`) + ...new ChangeOutputAction( + `Error: ${getErrorMessage(ex)}`, + Command.EvaluateValue + ) }); } diff --git a/tools/webide/packages/client/src/redux/result.ts b/tools/webide/packages/client/src/redux/result.ts index 54315a948..3fcca74c7 100644 --- a/tools/webide/packages/client/src/redux/result.ts +++ b/tools/webide/packages/client/src/redux/result.ts @@ -1,26 +1,36 @@ +import { Command } from './types'; + export enum ActionType { ChangeOutput = 'result-change-output', ChangeContract = 'result-change-contract' } export interface ResultState { + command: Command; output: string; contract: string; } export class ChangeOutputAction { public readonly type = ActionType.ChangeOutput; - constructor(public payload: ResultState['output']) {} + constructor( + public output: ResultState['output'], + public command: ResultState['command'] + ) {} } export class ChangeContractAction { public readonly type = ActionType.ChangeContract; - constructor(public payload: ResultState['contract']) {} + constructor( + public contract: ResultState['contract'], + public command: ResultState['command'] + ) {} } type Action = ChangeOutputAction | ChangeContractAction; const DEFAULT_STATE: ResultState = { + command: Command.Compile, output: '', contract: '' }; @@ -30,13 +40,15 @@ export default (state = DEFAULT_STATE, action: Action): ResultState => { case ActionType.ChangeOutput: return { ...state, - output: action.payload + output: action.output, + command: action.command }; case ActionType.ChangeContract: return { ...state, output: DEFAULT_STATE.output, - contract: action.payload + contract: action.contract, + command: action.command }; } return state; From 14397157a75a83dbdc1fe905a490c4da8091a22a Mon Sep 17 00:00:00 2001 From: Maksym Bykovskyy Date: Thu, 27 Feb 2020 16:08:31 -0800 Subject: [PATCH 17/53] Compile storage for server side deploy --- tools/webide/packages/server/src/handlers/deploy.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/webide/packages/server/src/handlers/deploy.ts b/tools/webide/packages/server/src/handlers/deploy.ts index 0fabd925f..2d24dfd3e 100644 --- a/tools/webide/packages/server/src/handlers/deploy.ts +++ b/tools/webide/packages/server/src/handlers/deploy.ts @@ -40,10 +40,12 @@ export async function deployHandler(req: Request, res: Response) { 'json' ); - const michelsonStorage = await new LigoCompiler().compileExpression( + const michelsonStorage = await new LigoCompiler().compileStorage( body.syntax, - body.storage, - 'json' + body.code, + body.entrypoint, + 'json', + body.storage ); await Tezos.importKey(await fetchRandomPrivateKey()); From 8229d6a6af2e18419908e587b9590a04b83371d5 Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Tue, 25 Feb 2020 12:25:15 -0600 Subject: [PATCH 18/53] Remove (unused) assignment from mini_c --- src/passes/7-self_mini_c/helpers.ml | 10 +- src/passes/7-self_mini_c/self_mini_c.ml | 96 +------------------ src/passes/7-self_mini_c/subst.ml | 10 -- src/passes/8-compiler/compiler_environment.ml | 23 ----- .../8-compiler/compiler_environment.mli | 1 - src/passes/8-compiler/compiler_program.ml | 36 ------- src/stages/mini_c/PP.ml | 2 - src/stages/mini_c/misc.ml | 2 - src/stages/mini_c/types.ml | 1 - 9 files changed, 5 insertions(+), 176 deletions(-) diff --git a/src/passes/7-self_mini_c/helpers.ml b/src/passes/7-self_mini_c/helpers.ml index 1c1116f4b..6b77cf2ee 100644 --- a/src/passes/7-self_mini_c/helpers.ml +++ b/src/passes/7-self_mini_c/helpers.ml @@ -80,10 +80,6 @@ let rec fold_expression : 'a folder -> 'a -> expression -> 'a result = fun f ini let%bind res = bind_fold_pair self init' ab in ok res ) - | E_assignment (_, _, exp) -> ( - let%bind res = self init' exp in - ok res - ) | E_record_update (r, _, e) -> ( let%bind res = self init' r in let%bind res = self res e in @@ -150,10 +146,6 @@ let rec map_expression : mapper -> expression -> expression result = fun f e -> let%bind ab' = bind_map_pair self ab in return @@ E_sequence ab' ) - | E_assignment (s, lrl, exp) -> ( - let%bind exp' = self exp in - return @@ E_assignment (s, lrl, exp') - ) | E_record_update (r, l, e) -> ( let%bind r = self r in let%bind e = self e in @@ -166,4 +158,4 @@ let map_sub_level_expression : mapper -> expression -> expression result = fun f let%bind body = map_expression f body in let content = E_closure {binder; body} in ok @@ { e with content } - | _ -> ok e \ No newline at end of file + | _ -> ok e diff --git a/src/passes/7-self_mini_c/self_mini_c.ml b/src/passes/7-self_mini_c/self_mini_c.ml index 9a334951a..66a0a06b8 100644 --- a/src/passes/7-self_mini_c/self_mini_c.ml +++ b/src/passes/7-self_mini_c/self_mini_c.ml @@ -79,10 +79,6 @@ let rec is_pure : expression -> bool = fun e -> is near... *) | E_while _ -> false - - (* definitely not pure *) - | E_assignment _ -> false - let occurs_in : expression_variable -> expression -> bool = fun x e -> let fvs = Free_variables.expression [] e in @@ -93,63 +89,6 @@ let occurs_count : expression_variable -> expression -> int = let fvs = Free_variables.expression [] e in Free_variables.mem_count x fvs -(* If `ignore_lambdas` is true, ignore assignments which occur inside - lambdas, which have no effect on the value of the variable outside - of the lambda. *) -let rec is_assigned : ignore_lambdas:bool -> expression_variable -> expression -> bool = - fun ~ignore_lambdas x e -> - let self = is_assigned ~ignore_lambdas x in - let selfs = List.exists self in - let it = Var.equal x in - let self_binder binder body = - if it binder - then false - else self body in - let self_binder2 binder1 binder2 body = - if it binder1 || it binder2 - then false - else self body in - match e.content with - | E_assignment (x, _, e) -> - it x || self e - | E_record_update (r, _, e) -> - self r || self e - | E_closure { binder; body } -> - if ignore_lambdas - then false - else self_binder binder body - | E_constant (c) -> - selfs c.arguments - | E_application (f, arg) -> - selfs [ f ; arg ] - | E_iterator (_, ((x, _), e1), e2) -> - self_binder x e1 || self e2 - | E_fold (((x, _), e1), e2, e3) -> - self_binder x e1 || selfs [ e2 ; e3 ] - | E_if_bool (e1, e2, e3) -> - selfs [ e1 ; e2 ; e3 ] - | E_if_none (e1, e2, ((x, _), e3)) -> - selfs [ e1 ; e2 ] || self_binder x e3 - | E_if_cons (e1, e2, (((hd, _), (tl, _)), e3)) -> - selfs [ e1 ; e2 ] || self_binder2 hd tl e3 - | E_if_left (e1, ((l, _), e2), ((r, _), e3)) -> - self e1 || self_binder l e2 || self_binder r e3 - | E_let_in ((x, _), _, e1, e2) -> - self e1 || self_binder x e2 - | E_sequence (e1, e2) -> - selfs [ e1 ; e2 ] - | E_while (e1, e2) -> - selfs [ e1 ; e2 ] - | E_literal _ - | E_skip - | E_variable _ - | E_make_empty_map _ - | E_make_empty_big_map _ - | E_make_empty_list _ - | E_make_empty_set _ - | E_make_none _ -> - false - (* Let "inlining" mean transforming the code: let x = e1 in e2 @@ -163,25 +102,11 @@ let rec is_assigned : ignore_lambdas:bool -> expression_variable -> expression - Things which can go wrong for inlining: - If `e1` is not pure, inlining may fail to preserve semantics. - - If assignments to `x` occur in e2, inlining does not make sense. - - Free variables of `e1` may be assigned in e2, before usages of `x`. - Free variables of `e1` may be shadowed in e2, at usages of `x`. This is not a problem if the substitution is capture-avoiding. - ? *) -let can_inline : expression_variable -> expression -> expression -> bool = - fun x e1 e2 -> - is_pure e1 && - (* if x does not occur in e2, there can be no other problems: - substitution will be a noop up to alpha-equivalence *) - (not (occurs_in x e2) || - (* else, must worry about assignment *) - (not (is_assigned ~ignore_lambdas:false x e2) && - List.for_all - (fun y -> not (is_assigned ~ignore_lambdas:true y e2)) - (Free_variables.expression [] e2))) - let should_inline : expression_variable -> expression -> bool = fun x e -> occurs_count x e <= 1 @@ -190,10 +115,8 @@ let inline_let : bool ref -> expression -> expression = fun changed e -> match e.content with | E_let_in ((x, _a), should_inline_here, e1, e2) -> - if can_inline x e1 e2 && (should_inline_here || should_inline x e2) + if is_pure e1 && (should_inline_here || should_inline x e2) then - (* can raise Subst.Bad_argument, but should not happen, due to - can_inline *) let e2' = Subst.subst_expression ~body:e2 ~x:x ~expr:e1 in (changed := true ; e2') else @@ -215,26 +138,15 @@ let inline_lets : bool ref -> expression -> expression = Things which can go wrong for beta reduction: - - If e1 contains (meaningful) assignments to free variables, semantics - will not be preserved. - - ? + - Nothing? *) -let can_beta : anon_function -> bool = - fun lam -> - List.for_all - (fun x -> not (is_assigned ~ignore_lambdas:true x lam.body)) - (Free_variables.lambda [] lam) - let beta : bool ref -> expression -> expression = fun changed e -> match e.content with | E_application ({ content = E_closure { binder = x ; body = e1 } ; type_value = T_function (xtv, tv) }, e2) -> - if can_beta { binder = x ; body = e1 } - then - (changed := true ; - Expression.make (E_let_in ((x, xtv), false, e2, e1)) tv) - else e + (changed := true ; + Expression.make (E_let_in ((x, xtv), false, e2, e1)) tv) (* also do CAR (PAIR x y) ↦ x, or CDR (PAIR x y) ↦ y, only if x and y are pure *) | E_constant {cons_name = C_CAR| C_CDR as const; arguments = [ { content = E_constant {cons_name = C_PAIR; arguments = [ e1 ; e2 ]} ; type_value = _ } ]} -> diff --git a/src/passes/7-self_mini_c/subst.ml b/src/passes/7-self_mini_c/subst.ml index 0dd1b4f64..c2103c9f5 100644 --- a/src/passes/7-self_mini_c/subst.ml +++ b/src/passes/7-self_mini_c/subst.ml @@ -90,10 +90,6 @@ let rec replace : expression -> var_name -> var_name -> expression = let e1 = replace e1 in let e2 = replace e2 in return @@ E_sequence (e1, e2) - | E_assignment (v, path, e) -> - let v = replace_var v in - let e = replace e in - return @@ E_assignment (v, path, e) | E_record_update (r, p, e) -> let r = replace r in let e = replace e in @@ -107,7 +103,6 @@ let rec replace : expression -> var_name -> var_name -> expression = Computes `body[x := expr]`. This raises Bad_argument in the case of assignments with a name clash. (`x <- 42[x := 23]` makes no sense.) **) -exception Bad_argument let rec subst_expression : body:expression -> x:var_name -> expr:expression -> expression = fun ~body ~x ~expr -> let self body = subst_expression ~body ~x ~expr in @@ -204,11 +199,6 @@ let rec subst_expression : body:expression -> x:var_name -> expr:expression -> e let ab' = Tuple.map2 self ab in return @@ E_sequence ab' ) - | E_assignment (s, lrl, exp) -> ( - let exp' = self exp in - if Var.equal s x then raise Bad_argument ; - return @@ E_assignment (s, lrl, exp') - ) | E_record_update (r, p, e) -> ( let r' = self r in let e' = self e in diff --git a/src/passes/8-compiler/compiler_environment.ml b/src/passes/8-compiler/compiler_environment.ml index 06cc467de..0736593ee 100644 --- a/src/passes/8-compiler/compiler_environment.ml +++ b/src/passes/8-compiler/compiler_environment.ml @@ -35,29 +35,6 @@ let get : environment -> expression_variable -> michelson result = fun e s -> ok code -let set : environment -> expression_variable -> michelson result = fun e n -> - let%bind (_ , position) = - generic_try (simple_error "Environment.set") @@ - (fun () -> Environment.get_i n e) in - let rec aux_bubble = fun n -> - match n with - | 0 -> dip i_drop - | n -> seq [ - i_swap ; - dip (aux_bubble (n - 1)) ; - ] - in - let aux_dug = fun n -> seq [ - dipn (n + 1) i_drop ; - i_dug n ; - ] in - let code = - if position < 2 - then aux_bubble position - else aux_dug position in - - ok code - let pack_closure : environment -> selector -> michelson result = fun e lst -> let%bind () = Assert.assert_true (e <> []) in diff --git a/src/passes/8-compiler/compiler_environment.mli b/src/passes/8-compiler/compiler_environment.mli index 62bcf7b45..22801279d 100644 --- a/src/passes/8-compiler/compiler_environment.mli +++ b/src/passes/8-compiler/compiler_environment.mli @@ -8,7 +8,6 @@ module Stack = Meta_michelson.Stack *) val empty: environment val get : environment -> expression_variable -> michelson result -val set : environment -> expression_variable -> michelson result val pack_closure : environment -> selector -> michelson result val unpack_closure : environment -> michelson result diff --git a/src/passes/8-compiler/compiler_program.ml b/src/passes/8-compiler/compiler_program.ml index a93b58299..74b3599c2 100644 --- a/src/passes/8-compiler/compiler_program.ml +++ b/src/passes/8-compiler/compiler_program.ml @@ -386,42 +386,6 @@ and translate_expression (expr:expression) (env:environment) : michelson result ] in ok code ) - | E_assignment (name , lrs , expr) -> ( - let%bind expr' = translate_expression expr env in - let%bind get_code = Compiler_environment.get env name in - let modify_code = - let aux acc step = match step with - | `Left -> seq [dip i_unpair ; acc ; i_pair] - | `Right -> seq [dip i_unpiar ; acc ; i_piar] - in - let init = dip i_drop in - List.fold_right' aux init lrs - in - let%bind set_code = Compiler_environment.set env name in - let error = - let title () = "michelson type-checking patch" in - let content () = - let aux ppf = function - | `Left -> Format.fprintf ppf "left" - | `Right -> Format.fprintf ppf "right" in - Format.asprintf "Sub path: %a\n" - PP_helpers.(list_sep aux (const " , ")) lrs - in - error title content in - trace error @@ - return @@ seq [ - i_comment "assign: start # env" ; - expr' ; - i_comment "assign: compute rhs # rhs : env" ; - dip get_code ; - i_comment "assign: get name # rhs : name : env" ; - modify_code ; - i_comment "assign: modify code # name+rhs : env" ; - set_code ; - i_comment "assign: set new # new_env" ; - i_push_unit ; - ] - ) | E_record_update (record, path, expr) -> ( let%bind record' = translate_expression record env in diff --git a/src/stages/mini_c/PP.ml b/src/stages/mini_c/PP.ml index 0fde6061c..9be2e37c3 100644 --- a/src/stages/mini_c/PP.ml +++ b/src/stages/mini_c/PP.ml @@ -104,8 +104,6 @@ and expression' ppf (e:expression') = match e with | E_fold (((name , _) , body) , collection , initial) -> fprintf ppf "fold %a on %a with %a do ( %a )" expression collection expression initial Var.pp name expression body - | E_assignment (r , path , e) -> - fprintf ppf "%a.%a := %a" Var.pp r (list_sep lr (const ".")) path expression e | E_record_update (r, path,update) -> fprintf ppf "%a with { %a = %a }" expression r (list_sep lr (const ".")) path expression update | E_while (e , b) -> diff --git a/src/stages/mini_c/misc.ml b/src/stages/mini_c/misc.ml index 6671af26f..31c816178 100644 --- a/src/stages/mini_c/misc.ml +++ b/src/stages/mini_c/misc.ml @@ -79,8 +79,6 @@ module Free_variables = struct expression (union (singleton v) b) body ; ] | E_sequence (x, y) -> union (self x) (self y) - (* NB different from ast_typed... *) - | E_assignment (v, _, e) -> unions [ var_name b v ; self e ] | E_record_update (r, _,e) -> union (self r) (self e) | E_while (cond , body) -> union (self cond) (self body) diff --git a/src/stages/mini_c/types.ml b/src/stages/mini_c/types.ml index f8d65759d..b1e419b8b 100644 --- a/src/stages/mini_c/types.ml +++ b/src/stages/mini_c/types.ml @@ -72,7 +72,6 @@ and expression' = | E_if_left of expression * ((var_name * type_value) * expression) * ((var_name * type_value) * expression) | E_let_in of ((var_name * type_value) * inline * expression * expression) | E_sequence of (expression * expression) - | E_assignment of (expression_variable * [`Left | `Right] list * expression) | E_record_update of (expression * [`Left | `Right] list * expression) | E_while of (expression * expression) From 00e6959503c2f1069df3a4659aa8db427ddc3665 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Mon, 2 Mar 2020 18:01:56 +0100 Subject: [PATCH 19/53] Refactoring of the test contracts. --- src/bin/expect_tests/contract_tests.ml | 106 ++++----- src/passes/operators/operators.ml | 4 +- src/test/contracts/address.mligo | 4 +- src/test/contracts/address.religo | 4 +- src/test/contracts/amount.ligo | 2 +- src/test/contracts/amount.mligo | 2 +- src/test/contracts/amount.religo | 9 +- src/test/contracts/arithmetic.ligo | 2 - src/test/contracts/arithmetic.mligo | 19 +- src/test/contracts/arithmetic.religo | 30 +-- src/test/contracts/assert.religo | 6 +- src/test/contracts/attributes.mligo | 3 - src/test/contracts/attributes.religo | 8 +- src/test/contracts/bad_address_format.religo | 5 +- src/test/contracts/balance_constant.mligo | 6 +- src/test/contracts/balance_constant.religo | 5 +- src/test/contracts/big_map.mligo | 3 - src/test/contracts/big_map.religo | 22 +- src/test/contracts/bitwise_arithmetic.mligo | 6 +- src/test/contracts/boolean_operators.mligo | 12 +- src/test/contracts/boolean_operators.religo | 14 +- src/test/contracts/bytes_arithmetic.mligo | 4 +- src/test/contracts/bytes_unpack.religo | 18 +- src/test/contracts/check_signature.religo | 4 +- src/test/contracts/closure.mligo | 2 +- src/test/contracts/closure.religo | 10 +- src/test/contracts/condition-annot.religo | 8 +- src/test/contracts/condition-shadowing.mligo | 7 +- src/test/contracts/condition.religo | 7 +- src/test/contracts/counter.mligo | 3 +- src/test/contracts/counter.religo | 7 +- src/test/contracts/crypto.religo | 4 +- src/test/contracts/curry.mligo | 4 - src/test/contracts/empty_case.religo | 10 +- src/test/contracts/eq_bool.religo | 8 +- src/test/contracts/failwith.religo | 6 +- src/test/contracts/fibo.mligo | 2 +- src/test/contracts/fibo3.mligo | 2 +- src/test/contracts/fibo4.mligo | 6 +- src/test/contracts/function-shared.mligo | 2 - src/test/contracts/function-shared.religo | 8 +- src/test/contracts/guess_string.mligo | 10 +- src/test/contracts/hashlock.mligo | 85 ++++--- src/test/contracts/high-order.mligo | 40 ++-- src/test/contracts/high-order.religo | 52 ++--- src/test/contracts/id.mligo | 182 +++++++-------- src/test/contracts/implicit.mligo | 6 +- src/test/contracts/implicit_account.mligo | 2 +- src/test/contracts/implicit_account.religo | 3 +- src/test/contracts/incr_decr.mligo | 18 +- src/test/contracts/interpret_test.mligo | 218 +++++++++--------- src/test/contracts/isnat.mligo | 2 +- src/test/contracts/isnat.religo | 2 +- src/test/contracts/key_hash.mligo | 8 +- src/test/contracts/key_hash.religo | 11 +- src/test/contracts/lambda.mligo | 5 +- src/test/contracts/lambda.religo | 4 +- src/test/contracts/lambda2.mligo | 6 +- src/test/contracts/lambda2.religo | 6 +- src/test/contracts/let_in_multi_bind.mligo | 4 +- src/test/contracts/let_multiple.mligo | 24 +- src/test/contracts/let_multiple.religo | 15 +- src/test/contracts/letin.mligo | 2 +- src/test/contracts/letin.religo | 12 +- src/test/contracts/list.mligo | 18 +- src/test/contracts/list.religo | 38 +-- src/test/contracts/loop.mligo | 38 +-- src/test/contracts/loop.religo | 55 ++--- src/test/contracts/map.mligo | 35 +-- src/test/contracts/map.religo | 51 ++-- src/test/contracts/match.mligo | 26 ++- src/test/contracts/match.religo | 25 +- src/test/contracts/match_bis.mligo | 22 +- src/test/contracts/match_bis.religo | 27 +-- src/test/contracts/multiple-parameters.mligo | 2 +- src/test/contracts/multiple-parameters.religo | 7 +- src/test/contracts/multisig.mligo | 88 ++++--- src/test/contracts/multisig.religo | 89 ++++--- .../contracts/negative/self_in_lambda.mligo | 4 +- src/test/contracts/option.religo | 6 +- src/test/contracts/record.mligo | 51 ++-- src/test/contracts/record.religo | 45 ++-- src/test/contracts/self_address.ligo | 2 +- src/test/contracts/self_address.mligo | 2 +- src/test/contracts/self_address.religo | 2 +- src/test/contracts/set_arithmetic-1.mligo | 3 +- src/test/contracts/set_arithmetic.mligo | 6 +- src/test/contracts/set_arithmetic.religo | 27 +-- src/test/contracts/set_delegate.mligo | 6 +- src/test/contracts/set_delegate.religo | 6 +- src/test/contracts/string_arithmetic.mligo | 8 +- src/test/contracts/string_arithmetic.religo | 6 +- src/test/contracts/subtle_nontail_fail.mligo | 2 +- src/test/contracts/super-counter.mligo | 22 +- src/test/contracts/super-counter.religo | 22 +- src/test/contracts/tez.mligo | 9 +- src/test/contracts/timelock_repeat.mligo | 32 +-- src/test/contracts/tuple.mligo | 2 +- src/test/contracts/tuple_type.mligo | 15 +- src/test/contracts/tuple_type.religo | 46 ++-- .../tuples_sequences_functions.religo | 4 +- src/test/contracts/type_tuple_destruct.mligo | 6 +- src/test/contracts/variant.mligo | 2 - src/test/contracts/variant.religo | 14 +- src/test/contracts/vote.mligo | 89 ++++--- src/test/contracts/website2.mligo | 6 +- src/test/contracts/website2.religo | 16 +- src/test/hash_lock_tests.ml | 10 +- src/test/time_lock_repeat_tests.ml | 4 +- src/test/vote_tests.ml | 39 ++-- 110 files changed, 999 insertions(+), 1147 deletions(-) diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 317c8a87a..1f6ff779a 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -16,7 +16,7 @@ let%expect_test _ = [%expect {| 3231 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ; - [%expect {| 642 bytes |}] ; + [%expect {| 589 bytes |}] ; run_ligo_good [ "compile-parameter" ; contract "coase.ligo" ; "main" ; "Buy_single (record card_to_buy = 1n end)" ] ; [%expect {| (Left (Left 1)) |}] ; @@ -948,40 +948,27 @@ let%expect_test _ = run_ligo_good [ "compile-contract" ; contract "vote.mligo" ; "main" ] ; [%expect {| { parameter - (or (pair %init - (pair (timestamp %beginning_time) (timestamp %finish_time)) - (string %title)) - (string %vote)) ; + (or (pair %reset (pair (timestamp %finish_time) (timestamp %start_time)) (string %title)) + (or %vote (unit %nay) (unit %yea))) ; storage - (pair (pair (pair (timestamp %beginning_time) (map %candidates string int)) - (pair (timestamp %finish_time) (string %title))) - (set %voters address)) ; + (pair (pair (pair (timestamp %finish_time) (nat %nay)) + (pair (timestamp %start_time) (string %title))) + (pair (set %voters address) (nat %yea))) ; code { DUP ; + DUP ; CAR ; IF_LEFT { DUP ; - DIP { DIP { DUP } ; SWAP ; CDR } ; - PAIR ; DUP ; CAR ; CAR ; - CAR ; - DIP { PUSH int 0 ; - SOME ; - DIP { PUSH int 0 ; - SOME ; - EMPTY_MAP string int ; - SWAP ; - PUSH string "Yes" ; - UPDATE } ; - PUSH string "No" ; - UPDATE } ; - PAIR ; - DIP { DUP ; CAR ; CAR ; CDR ; DIP { DUP ; CAR ; CDR } ; PAIR } ; - PAIR ; - EMPTY_SET address ; + PUSH nat 0 ; SWAP ; PAIR ; + DIP { DUP ; CAR ; CDR ; DIP { DUP ; CDR } ; PAIR } ; + PAIR ; + DIP { PUSH nat 0 ; EMPTY_SET address ; PAIR } ; + PAIR ; NIL operation ; PAIR ; DIP { DROP 2 } } @@ -989,41 +976,56 @@ let%expect_test _ = DIP { DIP { DUP } ; SWAP ; CDR } ; PAIR ; DUP ; + CDR ; + DIP { DUP } ; + SWAP ; CAR ; - DIP { DUP ; CDR ; CAR ; CAR ; CDR } ; - GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_LEFT + { DIP { DUP } ; + SWAP ; + DIP 2 { DUP } ; + DIG 2 ; + CAR ; + CAR ; + CDR ; + PUSH nat 1 ; + ADD ; + DIP { DUP ; CDR ; SWAP ; CAR ; DUP ; CDR ; SWAP ; CAR ; CAR } ; + SWAP ; + PAIR ; + PAIR ; + PAIR ; + DIP { DROP } } + { DIP { DUP } ; + SWAP ; + DIP 2 { DUP } ; + DIG 2 ; + CDR ; + CDR ; + PUSH nat 1 ; + ADD ; + DIP { DUP ; CAR ; SWAP ; CDR ; CAR } ; + SWAP ; + PAIR ; + SWAP ; + PAIR ; + DIP { DROP } } ; + DUP ; DIP { DUP } ; SWAP ; CDR ; CAR ; - CAR ; - CAR ; - DIP { DIP { DUP } ; - SWAP ; - CAR ; - DIP { DUP ; - PUSH int 1 ; - ADD ; - SOME ; - DIP { DIP { DUP } ; SWAP ; CDR ; CAR ; CAR ; CDR } } ; - UPDATE } ; + PUSH bool True ; + SENDER ; + UPDATE ; + DIP { DUP ; CAR ; SWAP ; CDR ; CDR } ; PAIR ; - DIP { DIP { DUP } ; - SWAP ; - CDR ; - CAR ; - CDR ; - CAR ; - DIP { DIP { DUP } ; SWAP ; CDR ; CAR ; CDR ; CDR } ; - PAIR } ; - PAIR ; - DIP { DIP { DUP } ; SWAP ; CDR ; CDR ; PUSH bool True ; SENDER ; UPDATE } ; + SWAP ; PAIR ; NIL operation ; PAIR ; - DIP { DROP 3 } } ; - DIP { DROP } } } |}] + DIP { DROP 4 } } ; + DIP { DROP 2 } } } |}] let%expect_test _ = run_ligo_good [ "compile-contract" ; contract "implicit.mligo" ; "main" ] ; @@ -1064,7 +1066,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_bad [ "compile-contract" ; contract "bad_address_format.religo" ; "main" ] ; [%expect {| - ligo: in file "bad_address_format.religo", line 2, characters 25-47. Badly formatted literal: @"KT1badaddr" {"location":"in file \"bad_address_format.religo\", line 2, characters 25-47"} + ligo: in file "bad_address_format.religo", line 2, characters 26-48. Badly formatted literal: @"KT1badaddr" {"location":"in file \"bad_address_format.religo\", line 2, characters 26-48"} If you're not sure how to fix this error, you can diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 4c72934b2..bdab8d765 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -325,9 +325,9 @@ module Simplify = struct | "Bytes.pack" -> ok C_BYTES_PACK | "Bytes.unpack" -> ok C_BYTES_UNPACK | "Bytes.length" -> ok C_SIZE - | "Bytes.size" -> ok C_SIZE + | "Bytes.size" -> ok C_SIZE (* Deprecated *) | "Bytes.concat" -> ok C_CONCAT - | "Bytes.slice" -> ok C_SLICE + | "Bytes.slice" -> ok C_SLICE (* Deprecated *) | "Bytes.sub" -> ok C_SLICE (* List module *) diff --git a/src/test/contracts/address.mligo b/src/test/contracts/address.mligo index 2b24b7d08..e4d873bbe 100644 --- a/src/test/contracts/address.mligo +++ b/src/test/contracts/address.mligo @@ -1,3 +1,3 @@ let main (p : key_hash) = - let c : unit contract = Current.implicit_account p - in Current.address c + let c : unit contract = Tezos.implicit_account p + in Tezos.address c diff --git a/src/test/contracts/address.religo b/src/test/contracts/address.religo index df1742ce1..7a5222e04 100644 --- a/src/test/contracts/address.religo +++ b/src/test/contracts/address.religo @@ -1,4 +1,4 @@ let main = (p : key_hash) : address => { - let c : contract(unit) = Current.implicit_account(p) ; - Current.address(c) ; + let c : contract (unit) = Tezos.implicit_account (p); + Tezos.address(c); }; diff --git a/src/test/contracts/amount.ligo b/src/test/contracts/amount.ligo index c7816fae3..0bad23a72 100644 --- a/src/test/contracts/amount.ligo +++ b/src/test/contracts/amount.ligo @@ -1,5 +1,5 @@ function check (const p : unit) : int is block { var result : int := 0; - if amount = 100tz then result := 42 else result := 0 + if amount = 100tez then result := 42 else result := 0 } with result diff --git a/src/test/contracts/amount.mligo b/src/test/contracts/amount.mligo index c14228fc4..483436507 100644 --- a/src/test/contracts/amount.mligo +++ b/src/test/contracts/amount.mligo @@ -1 +1 @@ -let check_ (p : unit) : int = if Tezos.amount = 100tz then 42 else 0 +let check_ (p : unit) : int = if Tezos.amount = 100tez then 42 else 0 diff --git a/src/test/contracts/amount.religo b/src/test/contracts/amount.religo index 9d19491b8..f33527daa 100644 --- a/src/test/contracts/amount.religo +++ b/src/test/contracts/amount.religo @@ -1,7 +1,2 @@ -let check_ = (p: unit) : int => - if (Current.amount == 100tz) { - 42; - } - else { - 0; - }; +let check_ = (p : unit) : int => + if (Tezos.amount == 100tez) { 42; } else { 0; }; diff --git a/src/test/contracts/arithmetic.ligo b/src/test/contracts/arithmetic.ligo index a4a6c51cb..b9bfca273 100644 --- a/src/test/contracts/arithmetic.ligo +++ b/src/test/contracts/arithmetic.ligo @@ -1,5 +1,3 @@ -// Test PascaLIGO arithmetic operators - function mod_op (const n : int) : nat is n mod 42 function plus_op (const n : int) : int is n + 42 function minus_op (const n : int) : int is n - 42 diff --git a/src/test/contracts/arithmetic.mligo b/src/test/contracts/arithmetic.mligo index 66c241f86..3225027ab 100644 --- a/src/test/contracts/arithmetic.mligo +++ b/src/test/contracts/arithmetic.mligo @@ -1,17 +1,8 @@ -// Test CameLIGO arithmetic operators - -let mod_op (n : int) : nat = n mod 42 - -let plus_op (n : int) : int = n + 42 - +let mod_op (n : int) : nat = n mod 42 +let plus_op (n : int) : int = n + 42 let minus_op (n : int) : int = n - 42 - let times_op (n : int) : int = n * 42 - -let div_op (n : int) : int = n / 2 - -let neg_op (n : int) : int = -n - -let foo (n : int) : int = n + 10 - +let div_op (n : int) : int = n / 2 +let neg_op (n : int) : int = -n +let foo (n : int) : int = n + 10 let neg_op_2 (b : int) : int = -(foo b) diff --git a/src/test/contracts/arithmetic.religo b/src/test/contracts/arithmetic.religo index 6d7fc5d29..c598e125d 100644 --- a/src/test/contracts/arithmetic.religo +++ b/src/test/contracts/arithmetic.religo @@ -1,24 +1,10 @@ /* Test ReasonLIGO arithmetic operators */ -let mod_op = (n: int): nat => n mod 42; - -let plus_op = (n: int): int => n + 42; - -let minus_op = (n: int): int => n - 42; - -let times_op = (n: int): int => n * 42; - -let div_op = (n: int): int => n / 2; - -/* TODO (?): Support conversion from nat to int and back - - let int_op (n : nat) : int = - Int n - - */ - -let neg_op = (n: int): int => - n; - -let foo = (n: int): int => n + 10; - -let neg_op_2 = (b: int): int => - foo(b); +let mod_op = (n : int) : nat => n mod 42; +let plus_op = (n : int) : int => n + 42; +let minus_op = (n : int) : int => n - 42; +let times_op = (n : int) : int => n * 42; +let div_op = (n : int) : int => n / 2; +let neg_op = (n : int): int => - n; +let foo = (n : int): int => n + 10; +let neg_op_2 = (b : int): int => -foo(b); diff --git a/src/test/contracts/assert.religo b/src/test/contracts/assert.religo index 26b9f0775..d35ee11e2 100644 --- a/src/test/contracts/assert.religo +++ b/src/test/contracts/assert.religo @@ -1,4 +1,4 @@ -let main = (p: bool, s: unit) => { - let u: unit = assert(p); - ([]: list(operation), s); +let main = (p, s : bool, unit) => { + let u : unit = assert (p); + ([]: list (operation), s); }; diff --git a/src/test/contracts/attributes.mligo b/src/test/contracts/attributes.mligo index a96d63710..d87f4e8e7 100644 --- a/src/test/contracts/attributes.mligo +++ b/src/test/contracts/attributes.mligo @@ -1,10 +1,7 @@ let x = 1 [@@inline] - let foo (a : int): int = (let test = 2 + a [@@inline] in test) [@@inline] - let y = 1 [@@inline][@@other] - let bar (b : int): int = let test = fun (z : int) -> 2 + b + z [@@inline][@@foo][@@bar] in test b diff --git a/src/test/contracts/attributes.religo b/src/test/contracts/attributes.religo index 33062220f..d79928769 100644 --- a/src/test/contracts/attributes.religo +++ b/src/test/contracts/attributes.religo @@ -2,7 +2,7 @@ let x = 1; [@inline] -let foo = (a: int): int => { +let foo = (a : int) : int => { [@inline] let test = 2 + a; test; @@ -11,8 +11,8 @@ let foo = (a: int): int => { [@inline][@other] let y = 1; -let bar = (b: int): int => { +let bar = (b : int) : int => { [@inline][@foo][@bar] - let test = (z: int) => 2 + b + z; - test(b); + let test = (z : int) => 2 + b + z; + test (b); }; diff --git a/src/test/contracts/bad_address_format.religo b/src/test/contracts/bad_address_format.religo index c8668bc45..81f4739b7 100644 --- a/src/test/contracts/bad_address_format.religo +++ b/src/test/contracts/bad_address_format.religo @@ -1,3 +1,2 @@ -let main = (parameter: int, storage: address) => { - ([]:list(operation), "KT1badaddr" : address); -}; +let main = (parameter : int, storage : address) => + ([] : list (operation), "KT1badaddr" : address); diff --git a/src/test/contracts/balance_constant.mligo b/src/test/contracts/balance_constant.mligo index b73319f8f..53cba0c29 100644 --- a/src/test/contracts/balance_constant.mligo +++ b/src/test/contracts/balance_constant.mligo @@ -10,7 +10,9 @@ generated. unrecognized constant: {"constant":"BALANCE","location":"generated"} *) +type parameter = unit type storage = tez +type return = operation list * storage -let main (p, s : unit * storage) = - ([] : operation list), balance +let main (p, s : parameter * storage) : return = + ([] : operation list), Tezos.balance diff --git a/src/test/contracts/balance_constant.religo b/src/test/contracts/balance_constant.religo index efa80fc48..1d136052b 100644 --- a/src/test/contracts/balance_constant.religo +++ b/src/test/contracts/balance_constant.religo @@ -12,6 +12,7 @@ generated. unrecognized constant: {"constant":"BALANCE","location":"generated"} type storage = tez; -let main2 = (p: unit, storage) => ([]: list(operation), balance); +let main2 = (p : unit, storage) => + ([]: list (operation), Tezos.balance); -let main = (x: (unit, storage)) => main2(x[0],x[1]); +let main = (x : (unit, storage)) => main2 (x[0], x[1]); diff --git a/src/test/contracts/big_map.mligo b/src/test/contracts/big_map.mligo index 434878013..270826e51 100644 --- a/src/test/contracts/big_map.mligo +++ b/src/test/contracts/big_map.mligo @@ -1,11 +1,9 @@ type foo = (int, int) big_map let set_ (n, m: int * foo) : foo = Big_map.update 23 (Some n) m - let add (n, m : int * foo) : foo = Big_map.add 23 n m let rm (m : foo) : foo = Big_map.remove 42 m - let gf (m : foo) : int = Big_map.find 23 m let get (m : foo): int option = Big_map.find_opt 42 m @@ -13,7 +11,6 @@ let get (m : foo): int option = Big_map.find_opt 42 m let empty_map : foo = Big_map.empty let map1 : foo = Big_map.literal [(23,0); (42,0)] - let map1 : foo = Big_map.literal [(23,0); (42,0)] let mutimaps (m : foo) (n : foo) : foo = diff --git a/src/test/contracts/big_map.religo b/src/test/contracts/big_map.religo index 92f5431c8..44d64c92e 100644 --- a/src/test/contracts/big_map.religo +++ b/src/test/contracts/big_map.religo @@ -1,24 +1,22 @@ type foo = big_map(int, int); -let set2 = (n: int, m: foo): foo => Big_map.update(23, Some(n), m); +let set2 = (n : int, m : foo) : foo => Big_map.update (23, Some (n), m); -let set_ = (x: (int, foo)): foo => set2(x[0], x[1]); +let set_ = (x : (int, foo)) : foo => set2 (x[0], x[1]); -let add = ((n,m): (int, foo)): foo => Big_map.add(23, n, m); +let add = ((n,m) : (int, foo)) : foo => Big_map.add (23, n, m); -let rm = (m: foo): foo => Big_map.remove(42, m); +let rm = (m : foo) : foo => Big_map.remove (42, m); -let gf = (m: foo): int => Big_map.find(23, m); +let gf = (m : foo) : int => Big_map.find (23, m); -let get = (m: foo): option(int) => Big_map.find_opt(42, m); +let get = (m : foo) : option (int) => Big_map.find_opt (42, m); -let empty_map: foo = Big_map.empty; +let empty_map : foo = Big_map.empty; -let map1: foo = Big_map.literal([(23, 0), (42, 0)]); - -let map1: foo = Big_map.literal([(23, 0), (42, 0)]); +let map1 : foo = Big_map.literal ([(23,0), (42,0)]); let mutimaps = (m: foo, n: foo): foo => { - let bar: foo = Big_map.update(42, Some(0), m); - Big_map.update(42, get(bar), n); + let bar : foo = Big_map.update (42, Some (0), m); + Big_map.update (42, get (bar), n); }; diff --git a/src/test/contracts/bitwise_arithmetic.mligo b/src/test/contracts/bitwise_arithmetic.mligo index 5675df1b8..7cb38f439 100644 --- a/src/test/contracts/bitwise_arithmetic.mligo +++ b/src/test/contracts/bitwise_arithmetic.mligo @@ -1,7 +1,7 @@ (* Test CameLIGO bitwise operators *) -let or_op (n : nat) : nat = Bitwise.lor n 4n -let and_op (n : nat) : nat = Bitwise.land n 7n -let xor_op (n : nat) : nat = Bitwise.lxor n 7n +let or_op (n : nat) : nat = Bitwise.or n 4n +let and_op (n : nat) : nat = Bitwise.and n 7n +let xor_op (n : nat) : nat = Bitwise.xor n 7n let lsl_op (n : nat) : nat = Bitwise.shift_left n 7n let lsr_op (n : nat) : nat = Bitwise.shift_right n 7n diff --git a/src/test/contracts/boolean_operators.mligo b/src/test/contracts/boolean_operators.mligo index 63091dbf8..1c5b46a00 100644 --- a/src/test/contracts/boolean_operators.mligo +++ b/src/test/contracts/boolean_operators.mligo @@ -1,11 +1,7 @@ // Test CameLIGO boolean operators -let or_true (b : bool) : bool = b || true - -let or_false (b : bool) : bool = b || false - -let and_true (b : bool) : bool = b && true - +let or_true (b : bool) : bool = b || true +let or_false (b : bool) : bool = b || false +let and_true (b : bool) : bool = b && true let and_false (b : bool) : bool = b && false - -let not_bool (b : bool) : bool = not b +let not_bool (b : bool) : bool = not b diff --git a/src/test/contracts/boolean_operators.religo b/src/test/contracts/boolean_operators.religo index 8603380a7..acacfb198 100644 --- a/src/test/contracts/boolean_operators.religo +++ b/src/test/contracts/boolean_operators.religo @@ -1,11 +1,7 @@ // Test ReasonLIGO boolean operators -let or_true = (b: bool): bool => b || true; - -let or_false = (b: bool): bool => b || false; - -let and_true = (b: bool): bool => b && true; - -let and_false = (b: bool): bool => b && false; - -let not_bool = (b: bool): bool => !b; +let or_true = (b : bool) : bool => b || true; +let or_false = (b : bool) : bool => b || false; +let and_true = (b : bool) : bool => b && true; +let and_false = (b : bool) : bool => b && false; +let not_bool = (b : bool) : bool => !b; diff --git a/src/test/contracts/bytes_arithmetic.mligo b/src/test/contracts/bytes_arithmetic.mligo index 44d89cb36..dbdc2a147 100644 --- a/src/test/contracts/bytes_arithmetic.mligo +++ b/src/test/contracts/bytes_arithmetic.mligo @@ -1,5 +1,3 @@ let concat_op (s : bytes) : bytes = Bytes.concat s 0x7070 - -let slice_op (s : bytes) : bytes = Bytes.slice 1n 2n s - +let slice_op (s : bytes) : bytes = Bytes.sub 1n 2n s let hasherman (s : bytes) : bytes = Crypto.sha256 s diff --git a/src/test/contracts/bytes_unpack.religo b/src/test/contracts/bytes_unpack.religo index 86b291ecc..f8119e564 100644 --- a/src/test/contracts/bytes_unpack.religo +++ b/src/test/contracts/bytes_unpack.religo @@ -1,14 +1,14 @@ -let id_string = (p: string) : option(string) => { - let packed : bytes = Bytes.pack(p); - ((Bytes.unpack(packed)): option(string)); +let id_string = (p : string) : option(string) => { + let packed : bytes = Bytes.pack (p); + ((Bytes.unpack (packed)) : option (string)); }; -let id_int = (p: int) : option(int) => { - let packed: bytes = Bytes.pack(p); - ((Bytes.unpack(packed)): option(int)); +let id_int = (p : int) : option (int) => { + let packed : bytes = Bytes.pack (p); + ((Bytes.unpack (packed)) : option (int)); }; -let id_address = (p: address) : option(address) => { - let packed: bytes = Bytes.pack(p); - ((Bytes.unpack(packed)): option(address)); +let id_address = (p : address) : option (address) => { + let packed : bytes = Bytes.pack (p); + ((Bytes.unpack (packed)) : option (address)); }; diff --git a/src/test/contracts/check_signature.religo b/src/test/contracts/check_signature.religo index 9d2f266ce..992e693fd 100644 --- a/src/test/contracts/check_signature.religo +++ b/src/test/contracts/check_signature.religo @@ -1,4 +1,4 @@ -let check_signature = (param: (key, signature, bytes)) : bool => { +let check_signature = (param : (key, signature, bytes)) : bool => { let pk, signed, msg = param; - Crypto.check(pk, signed, msg); + Crypto.check (pk, signed, msg); }; diff --git a/src/test/contracts/closure.mligo b/src/test/contracts/closure.mligo index ddd866df7..d849db1f0 100644 --- a/src/test/contracts/closure.mligo +++ b/src/test/contracts/closure.mligo @@ -1,4 +1,4 @@ -(* Test whether closures retain values in CameLIGO *) +(* Test whether closures capture variables in CameLIGO *) let test (k : int) : int = let j : int = k + 5 in diff --git a/src/test/contracts/closure.religo b/src/test/contracts/closure.religo index a17ddb728..72eaac5da 100644 --- a/src/test/contracts/closure.religo +++ b/src/test/contracts/closure.religo @@ -1,9 +1,9 @@ /* Test whether closures retain values in ReasonLIGO */ -let test = (k: int): int => { - let j: int = k + 5; - let close: (int => int) = (i: int) => i + j; +let test = (k : int) : int => { + let j : int = k + 5; + let close : (int => int) = (i : int) => i + j; - let j: int = 20; /* Shadow original variable to see if value close'd */ - close(20); + let j : int = 20; /* Shadow original variable */ + close (20); }; diff --git a/src/test/contracts/condition-annot.religo b/src/test/contracts/condition-annot.religo index 97e14f489..792090326 100644 --- a/src/test/contracts/condition-annot.religo +++ b/src/test/contracts/condition-annot.religo @@ -1,6 +1,2 @@ -let main = (i: int) => - if (((i == 2): bool)) { - (42: int); - } else { - (0: int); - }; +let main = (i : int) => + if (((i == 2) : bool)) { (42 : int); } else { (0 : int); }; diff --git a/src/test/contracts/condition-shadowing.mligo b/src/test/contracts/condition-shadowing.mligo index 64f1ff42f..577d3f4b5 100644 --- a/src/test/contracts/condition-shadowing.mligo +++ b/src/test/contracts/condition-shadowing.mligo @@ -1,6 +1,5 @@ let main (i : int) = let result = 0 in - if i = 2 then - let result = 42 in result - else - let result = 0 in result + if i = 2 + then let result = 42 in result + else let result = 0 in result diff --git a/src/test/contracts/condition.religo b/src/test/contracts/condition.religo index e44e93d7f..231fbe3fe 100644 --- a/src/test/contracts/condition.religo +++ b/src/test/contracts/condition.religo @@ -1,8 +1,3 @@ /* Test conditional in ReasonLIGO */ -let main = (i: int) => - if (i == 2) { - 42; - } else { - 0; - }; +let main = (i : int) => if (i == 2) { 42; } else { 0; }; diff --git a/src/test/contracts/counter.mligo b/src/test/contracts/counter.mligo index 548a1e07e..c16620367 100644 --- a/src/test/contracts/counter.mligo +++ b/src/test/contracts/counter.mligo @@ -1,4 +1,3 @@ type storage = int -let main (ps : int * storage) = - ([] : operation list), ps.0 + ps.1 +let main (p, s : int * storage) = ([] : operation list), p + s diff --git a/src/test/contracts/counter.religo b/src/test/contracts/counter.religo index 8ed3f201f..a2c27966f 100644 --- a/src/test/contracts/counter.religo +++ b/src/test/contracts/counter.religo @@ -1,7 +1,4 @@ - type storage = int; -let main2 = (p: int, storage): string => ([]: list(operation), p + storage); - -let main = (x: (int, storage)) : string => main2(x[0],x[1]); - +let main = ((p, s) : (int, storage)) : (list (operation), storage) => + ([] : list (operation), p + s); diff --git a/src/test/contracts/crypto.religo b/src/test/contracts/crypto.religo index c5b17ce8e..befe63391 100644 --- a/src/test/contracts/crypto.religo +++ b/src/test/contracts/crypto.religo @@ -1,2 +1,2 @@ -let hasherman512 = (s: bytes) => Crypto.sha512(s); -let hasherman_blake = (s: bytes) => Crypto.blake2b(s); +let hasherman512 = (s : bytes) => Crypto.sha512 (s); +let hasherman_blake = (s : bytes) => Crypto.blake2b (s); diff --git a/src/test/contracts/curry.mligo b/src/test/contracts/curry.mligo index ffcaafe15..9584cf7b1 100644 --- a/src/test/contracts/curry.mligo +++ b/src/test/contracts/curry.mligo @@ -1,9 +1,5 @@ let conv_test (j : int) (k : int) = j + k - let main (i : int) : int = conv_test i 10 - let partial (a : int) (b : int) : int = a + b - let mk_partial (j : int) : int -> int = partial j - let partial_apply (i : int) : int = mk_partial 10 i diff --git a/src/test/contracts/empty_case.religo b/src/test/contracts/empty_case.religo index c5d6bdc5a..68d179140 100644 --- a/src/test/contracts/empty_case.religo +++ b/src/test/contracts/empty_case.religo @@ -1,9 +1,9 @@ type foo = - | Bar(int) - | Baz; +| Bar (int) +| Baz; -let main = (f: foo): int => +let main = (f : foo) : int => switch (f) { - | Bar(i) => i - | Baz => (-1) + | Bar (i) => i + | Baz => (-1) }; diff --git a/src/test/contracts/eq_bool.religo b/src/test/contracts/eq_bool.religo index 5674d49b5..85e52ae7c 100644 --- a/src/test/contracts/eq_bool.religo +++ b/src/test/contracts/eq_bool.religo @@ -1,8 +1,4 @@ /* Test boolean comparison in ReasonLIGO */ -let main = ((a , b) : (bool , bool)) => - if (a == b) { - 999; - } else { - 1; - }; +let main = ((a, b) : (bool, bool)) => + if (a == b) { 999; } else { 1; }; diff --git a/src/test/contracts/failwith.religo b/src/test/contracts/failwith.religo index c7b028c3e..24317a106 100644 --- a/src/test/contracts/failwith.religo +++ b/src/test/contracts/failwith.religo @@ -1,8 +1,4 @@ type storage = unit; let main = (p: unit, storage) => - if (true) { - failwith("This contract always fails"); - } else { - (); - }; + if (true) { failwith("This contract always fails"); }; diff --git a/src/test/contracts/fibo.mligo b/src/test/contracts/fibo.mligo index 3d2e3a687..73886ccce 100644 --- a/src/test/contracts/fibo.mligo +++ b/src/test/contracts/fibo.mligo @@ -1,6 +1,6 @@ type storage = unit -let main (p : unit; store : storage) : operation list * storage = +let main (p, store : unit * storage) : operation list * storage = let n = (fun (f : int * int -> int) (x : int) (y : int) -> f (y,x)) (fun (x : int) (y : int) -> x + y) diff --git a/src/test/contracts/fibo3.mligo b/src/test/contracts/fibo3.mligo index 836f24517..bfa5a5dd3 100644 --- a/src/test/contracts/fibo3.mligo +++ b/src/test/contracts/fibo3.mligo @@ -1,6 +1,6 @@ type storage = unit -let main (p : unit; store : storage) : operation list * storage = +let main (p, s : unit * storage) : operation list * storage = let n = (fun (f : int -> int -> int) (x : int) (y : int) -> f y (x+y)) (fun (x : int) (y : int) -> x + y) diff --git a/src/test/contracts/fibo4.mligo b/src/test/contracts/fibo4.mligo index ccb3e5451..9806eabee 100644 --- a/src/test/contracts/fibo4.mligo +++ b/src/test/contracts/fibo4.mligo @@ -1,6 +1,6 @@ type storage = unit -let main (p: unit) storage = - (fun (f: int -> int) (x: int) -> f x) - (fun (x: int) -> x) +let main (p, s : unit * storage) = + (fun (f : int -> int) (x : int) -> f x) + (fun (x : int) -> x) 1 diff --git a/src/test/contracts/function-shared.mligo b/src/test/contracts/function-shared.mligo index e8f70f6bd..044af0d32 100644 --- a/src/test/contracts/function-shared.mligo +++ b/src/test/contracts/function-shared.mligo @@ -1,7 +1,5 @@ (* Test use of multiple subroutines in a CameLIGO function *) let foo (i : int) : int = i + 20 - let bar (i : int) : int = i + 50 - let foobar (i : int) : int = foo i + bar i diff --git a/src/test/contracts/function-shared.religo b/src/test/contracts/function-shared.religo index 94cc6b337..0e6c9dc47 100644 --- a/src/test/contracts/function-shared.religo +++ b/src/test/contracts/function-shared.religo @@ -1,7 +1,5 @@ /* Test use of multiple subroutines in a ReasonLIGO function */ -let foo = (i: int): int => i + 20; - -let bar = (i: int): int => i + 50; - -let foobar = (i: int): int => foo(i) + bar(i); +let foo = (i : int) : int => i + 20; +let bar = (i : int) : int => i + 50; +let foobar = (i : int) : int => foo (i) + bar (i); diff --git a/src/test/contracts/guess_string.mligo b/src/test/contracts/guess_string.mligo index adde5b642..0b2395180 100644 --- a/src/test/contracts/guess_string.mligo +++ b/src/test/contracts/guess_string.mligo @@ -9,10 +9,14 @@ type param = { type return = operation list * storage -let attempt (p: param; store : storage) : return = +let attempt (p, store : param * storage) : return = (* if p.attempt <> store.challenge then failwith "Failed challenge" else *) - let contract : unit contract = Operation.get_contract sender in + let contract : unit contract = + match (Tezos.get_contract_opt Tezos.sender : unit contract option) with + Some contract -> contract + | None -> (failwith "No contract" : unit contract) + in let transfer : operation = - Operation.transaction (unit, contract, 10.00tez) in + Tezos.transaction (unit, contract, 10.00tez) in let store : storage = {challenge = p.new_challenge} in ([] : operation list), store diff --git a/src/test/contracts/hashlock.mligo b/src/test/contracts/hashlock.mligo index 1f6fa02a1..c354bdfc2 100644 --- a/src/test/contracts/hashlock.mligo +++ b/src/test/contracts/hashlock.mligo @@ -1,56 +1,67 @@ type commit = { - date: timestamp; - salted_hash: bytes; + date : timestamp; + salted_hash : bytes; } type commit_set = (address, commit) big_map type storage = { - hashed: bytes; - unused: bool; - commits: commit_set; + hashed : bytes; + unused : bool; + commits : commit_set } type reveal = { - hashable: bytes; - message: unit -> operation list; + hashable : bytes; + message : unit -> operation list } type parameter = -| Commit of bytes + Commit of bytes | Reveal of reveal -(* We use hash-commit so that a baker can't steal *) -let commit ((p,s): bytes * storage) : operation list * storage = - let commit: commit = {date = Current.time + 86400; salted_hash = p;} in - let updated_map: commit_set = Big_map.update sender (Some commit) s.commits in - let s = {hashed = s.hashed; unused = s.unused; commits = updated_map} in - (([]: operation list), s) +type return = operation list * storage -let reveal ((p,s): reveal * storage) : operation list * storage = +(* We use hash-commit so that a baker can not steal *) + +let commit (p, s : bytes * storage) : return = + let commit : commit = + {date = Tezos.now + 86_400; salted_hash = p} in + let updated_map: commit_set = + Big_map.update Tezos.sender (Some commit) s.commits in + let s = {s with commits = updated_map} + in ([] : operation list), s + +let reveal (p, s : reveal * storage) : return = if not s.unused - then (failwith "This contract has already been used.": operation list * storage) - else - let commit: commit = - match (Big_map.find_opt sender s.commits) with - | Some c -> c - | None -> (failwith "You haven't made a commitment to hash against yet.": commit) - in - if Current.time < commit.date - then (failwith "It hasn't been 24 hours since your commit yet.": operation list * storage) - else - let salted = Crypto.sha256 (Bytes.concat p.hashable (Bytes.pack sender)) in - if (salted <> commit.salted_hash) - then (failwith "This reveal doesn't match your commitment.": operation list * storage) - else - if (s.hashed = Crypto.sha256 p.hashable) then - let s: storage = {hashed = s.hashed; unused = false; commits = s.commits} in - ((p.message ()), s) - else (failwith "Your commitment did not match the storage hash.": - operation list * storage) + (failwith "This contract has already been used." : return) + else + let commit : commit = + match Big_map.find_opt sender s.commits with + | Some c -> c + | None -> + (failwith "You have not made a commitment to hash against yet." + : commit) + in + if Tezos.now < commit.date + then + (failwith "It has not been 24 hours since your commit yet.": return) + else + let salted = + Crypto.sha256 (Bytes.concat p.hashable (Bytes.pack sender)) in + if salted <> commit.salted_hash + then + (failwith "This reveal does not match your commitment.": return) + else + if s.hashed = Crypto.sha256 p.hashable + then + let s : storage = {s with unused = false} + in p.message (), s + else (failwith "Your commitment did not match the storage hash." + : return) -let main ((p,s): parameter * storage) : operation list * storage = +let main (p, s : parameter * storage) : return = match p with - | Commit c -> commit (c, s) - | Reveal r -> reveal (r, s) + | Commit c -> commit (c,s) + | Reveal r -> reveal (r,s) diff --git a/src/test/contracts/high-order.mligo b/src/test/contracts/high-order.mligo index 4bba30eb3..41d50f67a 100644 --- a/src/test/contracts/high-order.mligo +++ b/src/test/contracts/high-order.mligo @@ -1,30 +1,24 @@ (* Test a function which takes another function as an argument *) + let foobar (i : int) : int = - let foo: (int -> int) = - fun (i : int) -> i - in - let bar: ((int -> int) -> int) = - fun (f : int -> int) -> f i - in - bar foo + let foo: (int -> int) = fun (i : int) -> i in + let bar: ((int -> int) -> int) = fun (f : int -> int) -> f i + in bar foo (* higher order function with more than one argument *) -let higher2 (i: int) (f: int -> int): int = + +let higher2 (i : int) (f : int -> int): int = let ii: int = f i in ii let foobar2 (i : int) : int = - let foo2: (int -> int) = - fun (i : int) -> i - in - higher2 i foo2 + let foo2 : (int -> int) = fun (i : int) -> i + in higher2 i foo2 let a : int = 0 let foobar3 (i : int) : int = - let foo2: (int -> int) = - fun (i : int) -> a + i - in - higher2 i foo2 + let foo2 : (int -> int) = fun (i : int) -> a + i + in higher2 i foo2 let f (i : int) : int = i @@ -32,15 +26,11 @@ let g (i : int) : int = f i let foobar4 (i : int) : int = g (g i) -let higher3 (i: int) (f: int -> int) (g: int -> int) : int = - let ii: int = f (g i) in ii +let higher3 (i : int) (f : int -> int) (g : int -> int) : int = + let ii : int = f (g i) in ii let foobar5 (i : int) : int = let a : int = 0 in - let foo: (int -> int) = - fun (i : int) -> a + i - in - let goo: (int -> int) = - fun (i : int) -> foo i - in - higher3 i foo goo + let foo : (int -> int) = fun (i : int) -> a + i in + let goo : (int -> int) = fun (i : int) -> foo i + in higher3 i foo goo diff --git a/src/test/contracts/high-order.religo b/src/test/contracts/high-order.religo index 9e8e5cd17..0ec28a689 100644 --- a/src/test/contracts/high-order.religo +++ b/src/test/contracts/high-order.religo @@ -1,48 +1,44 @@ /* Test a function which takes another function as an argument */ -let foobar = (i: int): int => { + +let foobar = (i : int): int => { let foo: int => int = (i: int) => i; - - let bar: ((int => int) => int) = (f: (int => int)) => f(i); - - bar(foo); + let bar: ((int => int) => int) = (f : (int => int)) => f (i); + bar (foo); }; /* higher order function with more than one argument */ -let higher2 = (i: int, f: (int => int)): int => { - let ii: int = f(i); + +let higher2 = (i : int, f : (int => int)) : int => { + let ii : int = f (i); ii; }; -let foobar2 = (i: int): int => { - let foo2: int => int = (i: int) => i; - - higher2(i, foo2); +let foobar2 = (i : int) : int => { + let foo2 : int => int = (i : int) => i; + higher2 (i, foo2); }; -let a: int = 0; +let a : int = 0; -let foobar3 = (i: int): int => { - let foo2: int => int = (i: int) => a + i; - - higher2(i, foo2); +let foobar3 = (i : int) : int => { + let foo2: int => int = (i : int) => a + i; + higher2 (i, foo2); }; -let f = (i: int): int => i; +let f = (i : int) : int => i; -let g = (i: int): int => f(i); +let g = (i : int) : int => f (i); -let foobar4 = (i: int): int => g(g(i)); +let foobar4 = (i : int) : int => g (g (i)); -let higher3 = (i: int, f: (int => int), g: (int => int)): int => { - let ii: int = f(g(i)); +let higher3 = (i : int, f : (int => int), g : (int => int)) : int => { + let ii : int = f (g (i)); ii; }; -let foobar5 = (i: int): int => { - let a: int = 0; - let foo: int => int = (i: int) => a + i; - - let goo: int => int = (i: int) => foo(i); - - higher3(i, foo, goo); +let foobar5 = (i : int) : int => { + let a : int = 0; + let foo : int => int = (i : int) => a + i; + let goo : int => int = (i : int) => foo (i); + higher3 (i, foo, goo); }; diff --git a/src/test/contracts/id.mligo b/src/test/contracts/id.mligo index fd7b7c424..e23f8d841 100644 --- a/src/test/contracts/id.mligo +++ b/src/test/contracts/id.mligo @@ -3,7 +3,7 @@ type id = int type id_details = { owner: address; controller: address; - profile: bytes; + profile: bytes } type buy = bytes * address option @@ -14,126 +14,118 @@ type action = | Buy of buy | Update_owner of update_owner | Update_details of update_details -| Skip of unit +| Skip + +(* The prices kept in storage can be changed by bakers, though they + should only be adjusted down over time, not up. *) -(* The prices kept in storage can be changed by bakers, though they should only be - adjusted down over time, not up. *) type storage = (id, id_details) big_map * int * (tez * tez) -(** Preliminary thoughts on ids: +type return = operation list * storage -I very much like the simplicity of http://gurno.com/adam/mne/. -5 three letter words means you have a 15 character identity, not actually more -annoying than an IP address and a lot more memorable than the raw digits. This -can be stored as a single integer which is then translated into the corresponding -series of 5 words. +(* Preliminary thoughts on ids: -I in general like the idea of having a 'skip' mechanism, but it does need to cost -something so people don't eat up the address space. 256 ^ 5 means you have a lot -of address space, but if people troll by skipping a lot that could be eaten up. -Should probably do some napkin calculations for how expensive skipping needs to -be to deter people from doing it just to chew up address space. -*) +I very much like the simplicity of http://gurno.com/adam/mne/. 5 three +letter words means you have a 15 character identity, not actually more +annoying than an IP address and a lot more memorable than the raw +digits. This can be stored as a single integer which is then +translated into the corresponding series of 5 words. + +I in general like the idea of having a 'skip' mechanism, but it does +need to cost something so people don't eat up the address space. 256^5 +means you have a lot of address space, but if people troll by skipping +a lot that could be eaten up. Should probably do some napkin +calculations for how expensive skipping needs to be to deter people +from doing it just to chew up address space. *) let buy (parameter, storage: (bytes * address option) * storage) = - let void: unit = - if amount = storage.2.0 - then () - else (failwith "Incorrect amount paid.": unit) - in + let void : unit = + if Tezos.amount <> storage.2.0 + then (failwith "Incorrect amount paid.": unit) in let profile, initial_controller = parameter in let identities, new_id, prices = storage in - let controller: address = + let controller : address = match initial_controller with | Some addr -> addr - | None -> sender - in + | None -> sender in let new_id_details: id_details = { - owner = sender ; - controller = controller ; - profile = profile ; - } - in - let updated_identities: (id, id_details) big_map = + owner = sender; + controller = controller; + profile = profile} in + let updated_identities : (id, id_details) big_map = Big_map.update new_id (Some new_id_details) identities - in - ([]: operation list), (updated_identities, new_id + 1, prices) + in ([]: operation list), (updated_identities, new_id + 1, prices) -let update_owner (parameter, storage: (id * address) * storage) = - if (amount <> 0mutez) - then (failwith "Updating owner doesn't cost anything.": (operation list) * storage) +let update_owner (parameter, storage : (id * address) * storage) = + if amount <> 0tez + then (failwith "Updating owner doesn't cost anything.": return) else - let id, new_owner = parameter in - let identities, last_id, prices = storage in - let current_id_details: id_details = - match Big_map.find_opt id identities with - | Some id_details -> id_details - | None -> (failwith "This ID does not exist.": id_details) - in - let is_allowed: bool = - if sender = current_id_details.owner - then true - else (failwith "You are not the owner of this ID.": bool) - in - let updated_id_details: id_details = { + let id, new_owner = parameter in + let identities, last_id, prices = storage in + let current_id_details : id_details = + match Big_map.find_opt id identities with + | Some id_details -> id_details + | None -> (failwith "This ID does not exist." : id_details) in + let is_allowed : bool = + if Tezos.sender = current_id_details.owner + then true + else (failwith "You are not the owner of this ID." : bool) in + let updated_id_details : id_details = { owner = new_owner; controller = current_id_details.controller; - profile = current_id_details.profile; - } - in - let updated_identities = Big_map.update id (Some updated_id_details) identities in - ([]: operation list), (updated_identities, last_id, prices) + profile = current_id_details.profile} in + let updated_identities = + Big_map.update id (Some updated_id_details) identities + in ([]: operation list), (updated_identities, last_id, prices) let update_details (parameter, storage: (id * bytes option * address option) * storage) = - if (amount <> 0mutez) - then (failwith "Updating details doesn't cost anything.": (operation list) * storage) + if Tezos.amount <> 0tez + then + (failwith "Updating details doesn't cost anything." : return) else - let id, new_profile, new_controller = parameter in - let identities, last_id, prices = storage in - let current_id_details: id_details = - match Big_map.find_opt id identities with - | Some id_details -> id_details - | None -> (failwith "This ID does not exist.": id_details) - in - let is_allowed: bool = - if (sender = current_id_details.controller) || (sender = current_id_details.owner) - then true - else (failwith ("You are not the owner or controller of this ID."): bool) - in - let owner: address = current_id_details.owner in - let profile: bytes = - match new_profile with - | None -> (* Default *) current_id_details.profile - | Some new_profile -> new_profile - in - let controller: address = - match new_controller with - | None -> (* Default *) current_id_details.controller - | Some new_controller -> new_controller - in - let updated_id_details: id_details = { - owner = owner; - controller = controller; - profile = profile; - } - in + let id, new_profile, new_controller = parameter in + let identities, last_id, prices = storage in + let current_id_details: id_details = + match Big_map.find_opt id identities with + | Some id_details -> id_details + | None -> (failwith "This ID does not exist.": id_details) in + let is_allowed : bool = + if Tezos.sender = current_id_details.controller + || Tezos.sender = current_id_details.owner + then true + else + (failwith ("You are not the owner or controller of this ID.") + : bool) in + let owner : address = current_id_details.owner in + let profile : bytes = + match new_profile with + | None -> (* Default *) current_id_details.profile + | Some new_profile -> new_profile in + let controller : address = + match new_controller with + | None -> (* Default *) current_id_details.controller + | Some new_controller -> new_controller in + let updated_id_details: id_details = { + owner = owner; + controller = controller; + profile = profile} in let updated_identities: (id, id_details) big_map = - Big_map.update id (Some updated_id_details) identities in - ([]: operation list), (updated_identities, last_id, prices) + Big_map.update id (Some updated_id_details) identities + in ([]: operation list), (updated_identities, last_id, prices) -(* Let someone skip the next identity so nobody has to take one that's undesirable *) -let skip (p,storage: unit * storage) = - let void: unit = - if amount = storage.2.1 - then () - else (failwith "Incorrect amount paid.": unit) - in +(* Let someone skip the next identity so nobody has to take one that's +undesirable *) + +let skip (p, storage: unit * storage) = + let void : unit = + if Tezos.amount <> storage.2.1 + then (failwith "Incorrect amount paid." : unit) in let identities, last_id, prices = storage in ([]: operation list), (identities, last_id + 1, prices) -let main (action, storage: action * storage) : operation list * storage = +let main (action, storage : action * storage) : return = match action with | Buy b -> buy (b, storage) | Update_owner uo -> update_owner (uo, storage) | Update_details ud -> update_details (ud, storage) - | Skip s -> skip ((), storage) + | Skip -> skip ((), storage) diff --git a/src/test/contracts/implicit.mligo b/src/test/contracts/implicit.mligo index 443ef8710..9b4ba9068 100644 --- a/src/test/contracts/implicit.mligo +++ b/src/test/contracts/implicit.mligo @@ -1,5 +1,5 @@ let main2 (p : key_hash) (s : unit) = - let c : unit contract = Current.implicit_account p in - (([] : operation list), unit) + let c : unit contract = Tezos.implicit_account p + in ([] : operation list), unit -let main (t: key_hash * unit) = main2 t.0 t.1 +let main (p,s : key_hash * unit) = main2 p s diff --git a/src/test/contracts/implicit_account.mligo b/src/test/contracts/implicit_account.mligo index bf3c89dcc..0b52bf0b8 100644 --- a/src/test/contracts/implicit_account.mligo +++ b/src/test/contracts/implicit_account.mligo @@ -1 +1 @@ -let main (kh: key_hash) : unit contract = Current.implicit_account kh +let main (kh : key_hash) : unit contract = Tezos.implicit_account kh diff --git a/src/test/contracts/implicit_account.religo b/src/test/contracts/implicit_account.religo index dba1656ec..1c22b5e0e 100644 --- a/src/test/contracts/implicit_account.religo +++ b/src/test/contracts/implicit_account.religo @@ -1 +1,2 @@ -let main = (kh: key_hash): contract(unit) => Current.implicit_account(kh); +let main = (kh : key_hash) : contract (unit) => + Tezos.implicit_account (kh); diff --git a/src/test/contracts/incr_decr.mligo b/src/test/contracts/incr_decr.mligo index bceb88af3..f7f3e3e83 100644 --- a/src/test/contracts/incr_decr.mligo +++ b/src/test/contracts/incr_decr.mligo @@ -1,19 +1,17 @@ type storage = int -(* variant defining pseudo multi-entrypoint actions *) - -type action = +type parameter = Increment of int | Decrement of int -let add (a: int) (b: int) : int = a + b -let sub (a: int) (b: int) : int = a - b +type return = operation list * storage -(* real entrypoint that re-routes the flow based on the action provided *) +let add (a : int) (b : int) : int = a + b +let sub (a : int) (b : int) : int = a - b -let main (p: action) storage = - let storage = - match p with +let main (action, store : parameter * storage) : return = + let store = + match action with Increment n -> add s n | Decrement n -> sub s n - in ([] : operation list), storage + in ([] : operation list), store diff --git a/src/test/contracts/interpret_test.mligo b/src/test/contracts/interpret_test.mligo index 90fe2bcbf..c06113589 100644 --- a/src/test/contracts/interpret_test.mligo +++ b/src/test/contracts/interpret_test.mligo @@ -1,87 +1,87 @@ let lambda_call = let a = 3 in - let foo = fun (i : int) -> i * i in - foo (a + 1) + let foo = fun (i : int) -> i * i + in foo (a + 1) let higher_order1 = let a = 2 in - let foo = fun (i:int) (j:int) (k:int) -> - a + i + j + 0 in - let bar = (foo 1 2) in - bar 3 + let foo = fun (i : int) (j : int) (k : int) -> a + i + j + 0 in + let bar = (foo 1 2) + in bar 3 let higher_order2 = let a = 2 in - let foo = fun (i:int) -> - let b = 2 in - let bar = fun (i:int) -> i + a + b - in bar i + let foo = fun (i : int) -> + let b = 2 in + let bar = fun (i : int) -> i + a + b + in bar i in foo 1 let higher_order3 = - let foo = fun (i:int) -> i + 1 in - let bar = fun (f:int->int) (i:int) -> (f i) + 1 in - let baz : (int -> int ) = bar foo in - baz 3 + let foo = fun (i : int) -> i + 1 in + let bar = fun (f : int -> int) (i : int) -> f i + 1 in + let baz : int -> int = bar foo + in baz 3 let higher_order4 = let a = 3 in let foo = fun (i : int) -> a + i in - let bar: (int -> int) = fun (i : int) -> foo i in - bar 2 - -let concats = - 0x70 ^ 0x70 + let bar : int -> int = fun (i : int) -> foo i + in bar 2 + +let concats = 0x70 ^ 0x70 type foo_record = { - a : string ; - b : string ; + a : string; + b : string } + let record_concat = - let ab : foo_record = { a = "a" ; b = "b" } in - ab.a ^ ab.b + let ab : foo_record = {a="a"; b="b"} + in ab.a ^ ab.b let record_patch = - let ab : foo_record = { a = "a" ; b = "b" } in - {ab with b = "c"} + let ab : foo_record = {a="a"; b="b"} + in {ab with b = "c"} type bar_record = { - f : int -> int ; - arg : int ; + f : int -> int; + arg : int } + let record_lambda = let a = 1 in - let foo : (int -> int) = fun (i:int) -> a+(i*2) in - let farg : bar_record = { f = foo ; arg = 2 } in - farg.f farg.arg + let foo : int -> int = fun (i : int) -> a + i*2 in + let farg : bar_record = {f = foo; arg = 2} + in farg.f farg.arg type foo_variant = | Foo | Bar of int | Baz of string -let variant_exp = - (Foo, Bar 1, Baz "b") +let variant_exp = Foo, Bar 1, Baz "b" let variant_match = let a = Bar 1 in match a with - | Foo -> 1 - | Bar(i) -> 2 - | Baz(s) -> 3 + | Foo -> 1 + | Bar i -> 2 + | Baz s -> 3 -/* UNSUPPORTED +(* UNSUPPORTED: No deep patterns yet. type bar_variant = | Baz | Buz of int * int | Biz of int * int * string + let long_variant_match = let a = Biz (1,2,"Biz") in match a with | Baz -> "Baz" - | Buz(a,b) -> "Buz" - | Biz(a,b,c) -> c -*/ + | Buz (a,b) -> "Buz" + | Biz (a,b,c) -> c + *) let bool_match = let b = true in @@ -90,149 +90,145 @@ let bool_match = | false -> 2 let list_match = - let a = [ 1 ; 2 ; 3 ; 4 ] in + let a = [1; 2; 3; 4] in match a with - | hd :: tl -> hd::a + | hd::tl -> hd::a | [] -> a let tuple_proj = - let (a,b) = (true,false) in - a or b + let a, b = true, false + in a or b let list_const = - let a = [1 ; 2 ; 3 ; 4] in - 0 :: a + let a = [1; 2; 3; 4] + in 0::a type foobar = int option let options_match_some = let a = Some 0 in match a with - | Some(i) -> i + | Some i -> i | None -> 1 let options_match_none = let a : foobar = None in match a with - | Some(i) -> i + | Some i -> i | None -> 0 let is_nat_nat = let i : int = 1 in - let j : int = -1 in - (Michelson.is_nat i, Michelson.is_nat j) + let j : int = -1 + in is_nat i, is_nat j let abs_int = abs (-5) -let nat_int = int (5n) +let nat_int = int 5n let map_list = - let a = [1 ; 2 ; 3 ; 4] in - let add_one: (int -> int) = fun (i : int) -> i + 1 in - List.map add_one a + let a = [1; 2; 3; 4] in + let add_one : (int -> int) = fun (i : int) -> i + 1 + in List.map add_one a let fail_alone = failwith "you failed" let iter_list_fail = - let a = [1 ; 2 ; 3 ; 4] in - let check_something: (int -> unit) = fun (i : int) -> - if i = 2 then failwith "you failed" - else () - in - List.iter check_something a + let a = [1; 2; 3; 4] in + let check_something : int -> unit = + fun (i : int) -> + if i = 2 then failwith "you failed" + in List.iter check_something a let fold_list = - let a = [1 ; 2 ; 3 ; 4] in - let acc : (int * int -> int) = - fun (prev, el : int * int) -> prev + el in - List.fold acc a 0 + let a = [1; 2; 3; 4] in + let acc : int * int -> int = + fun (prev, el : int * int) -> prev + el + in List.fold acc a 0 -let comparison_int = - (1 > 2, 2 > 1, 1 >=2 , 2 >= 1) +let comparison_int = 1 > 2, 2 > 1, 1 >=2, 2 >= 1 -let comparison_string = - ("foo" = "bar", "baz" = "baz") +let comparison_string = "foo"="bar", "baz"="baz" -let divs : (int * nat * tez * nat) = - (1/2 , 1n/2n , 1tz/2n , 1tz/2tz) +let divs : int * nat * tez * nat = 1/2, 1n/2n, 1tez/2n, 1tez/2tez let var_neg = - let a = 2 in - -a + let a = 2 in -a let sizes = - let a = [ 1 ; 2 ; 3 ; 4 ; 5 ] in + let a = [1; 2; 3; 4; 5] in let b = "12345" in - let c = Set.literal [ 1 ; 2 ; 3 ; 4 ; 5 ] in - let d = Map.literal [ (1,1) ; (2,2) ; (3,3) ] in + let c = Set.literal [1; 2; 3; 4; 5] in + let d = Map.literal [(1,1); (2,2); (3,3)] in let e = 0xFFFF in - (List.size a, String.size b, Set.size c, Map.size d, Bytes.size e) + List.length a, + String.length b, + Set.cardinal c, + Map.size d, + Bytes.length e let modi = 3 mod 2 let fold_while = - let aux : int -> bool * int = fun (i:int) -> - if i < 10 then continue (i + 1) else stop i in - (Loop.fold_while aux 20, Loop.fold_while aux 0) + let aux : int -> bool * int = + fun (i : int) -> + if i < 10 then Loop.resume (i + 1) else Loop.stop i + in (Loop.fold_while aux 20, Loop.fold_while aux 0) -let assertion_pass = - assert (1=1) +let assertion_pass = assert (1=1) -let assertion_fail = - assert (1=2) +let assertion_fail = assert (1=2) let lit_address = ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" : address) let map_finds = - let m = Map.literal [ ("one" , 1) ; ("two" , 2) ; ("three" , 3) ] in - Map.find_opt "two" m + let m = Map.literal [("one", 1); ("two", 2); ("three", 3)] + in Map.find_opt "two" m let map_finds_fail = - let m = Map.literal [ ("one" , 1) ; ("two" , 2) ; ("three" , 3) ] in - Map.find "four" m + let m = Map.literal [("one", 1); ("two", 2); ("three", 3)] + in Map.find "four" m let map_empty = - ((Map.empty : (int,int) map) , (Map.literal [] : (int,int) map)) + ((Map.empty : (int, int) map), (Map.literal [] : (int, int) map)) -let m = Map.literal [ ("one" , 1) ; ("two" , 2) ; ("three" , 3) ] +let m = Map.literal [("one", 1); ("two", 2); ("three", 3)] let map_fold = - let aux = fun (i: int * (string * int)) -> i.0 + i.1.1 in - Map.fold aux m (-2) + let aux = fun (i : int * (string * int)) -> i.0 + i.1.1 + in Map.fold aux m (-2) let map_iter = - let aux = fun (i: string * int) -> if (i.1=12) then failwith "never" else () in - Map.iter aux m + let aux = + fun (i : string * int) -> if i.1 = 12 then failwith "never" + in Map.iter aux m let map_map = - let aux = fun (i: string * int) -> i.1 + (String.size i.0) in - Map.map aux m + let aux = fun (i : string * int) -> i.1 + String.length i.0 + in Map.map aux m -let map_mem = (Map.mem "one" m , Map.mem "four" m) +let map_mem = Map.mem "one" m, Map.mem "four" m -let map_remove = (Map.remove "one" m, Map.remove "four" m) +let map_remove = Map.remove "one" m, Map.remove "four" m -let map_update = ( - Map.update "one" (Some(1)) (Map.literal [ "one", 2 ]), - Map.update "one" (None : int option) (Map.literal [ "one", 1]), - Map.update "one" (None : int option) (Map.literal []:(string,int) map), - Map.update "one" (Some(1)) (Map.literal []:(string,int) map) -) +let map_update = + Map.update "one" (Some 1) (Map.literal ["one", 2]), + Map.update "one" (None : int option) (Map.literal ["one", 1]), + Map.update "one" (None : int option) (Map.empty : (string, int) map), + Map.update "one" (Some 1) (Map.literal [] : (string, int) map) -let s = Set.literal [ 1 ; 2 ; 3 ] +let s = Set.literal [1; 2; 3] -let set_add = ( +let set_add = Set.add 1 s, Set.add 4 s, - Set.add 1 (Set.literal [] : int set) -) + Set.add 1 (Set.empty : int set) let set_iter_fail = - let aux = fun (i:int) -> if i = 1 then failwith "set_iter_fail" else () in - Set.iter aux (Set.literal [1 ; 2 ; 3]) + let aux = fun (i : int) -> if i = 1 then failwith "set_iter_fail" + in Set.iter aux (Set.literal [1; 2; 3]) -let set_mem = ( +let set_mem = Set.mem 1 s, Set.mem 4 s, - Set.mem 1 (Set.literal [] : int set) -) + Set.mem 1 (Set.empty : int set) diff --git a/src/test/contracts/isnat.mligo b/src/test/contracts/isnat.mligo index c5bea0294..7440ea85e 100644 --- a/src/test/contracts/isnat.mligo +++ b/src/test/contracts/isnat.mligo @@ -1 +1 @@ -let main (i: int) : nat option = Michelson.is_nat i +let main (i : int) : nat option = is_nat i diff --git a/src/test/contracts/isnat.religo b/src/test/contracts/isnat.religo index b6b5921b7..be81913c0 100644 --- a/src/test/contracts/isnat.religo +++ b/src/test/contracts/isnat.religo @@ -1 +1 @@ -let main = (i: int): option(nat) => Michelson.is_nat(i); +let main = (i : int): option (nat) => is_nat (i); diff --git a/src/test/contracts/key_hash.mligo b/src/test/contracts/key_hash.mligo index 0eba14d9b..d42dcc8f1 100644 --- a/src/test/contracts/key_hash.mligo +++ b/src/test/contracts/key_hash.mligo @@ -1,5 +1,3 @@ -let check_hash_key (kh1, k2: key_hash * key) : bool * key_hash = - let kh2 : key_hash = Crypto.hash_key k2 in - if kh1 = kh2 - then (true, kh2) - else (false, kh2) +let check_hash_key (kh1, k2 : key_hash * key) : bool * key_hash = + let kh2 : key_hash = Crypto.hash_key k2 + in kh1 = kh2, kh2 diff --git a/src/test/contracts/key_hash.religo b/src/test/contracts/key_hash.religo index f3b8e8976..e434cfb50 100644 --- a/src/test/contracts/key_hash.religo +++ b/src/test/contracts/key_hash.religo @@ -1,10 +1,5 @@ -let check_hash_key = (kh1_k2: (key_hash, key)) : (bool, key_hash) => { +let check_hash_key = (kh1_k2 : (key_hash, key)) : (bool, key_hash) => { let kh1, k2 = kh1_k2; - let kh2 : key_hash = Crypto.hash_key(k2); - if (kh1 == kh2) { - (true, kh2); - } - else { - (false, kh2); - } + let kh2 : key_hash = Crypto.hash_key (k2); + ((kh1 == kh2), kh2) }; diff --git a/src/test/contracts/lambda.mligo b/src/test/contracts/lambda.mligo index fc32e0334..f7d21eeb1 100644 --- a/src/test/contracts/lambda.mligo +++ b/src/test/contracts/lambda.mligo @@ -1,8 +1,7 @@ type storage = unit (* not supported yet -let main (p:unit) storage = - (fun x -> ()) () +let main (p, s : unit * storage) = (fun x -> ()) () *) -let main (ps: unit * storage) = (fun (_: unit) -> ()) () +let main (p, s : unit * storage) = (fun (_ : unit) -> ()) () diff --git a/src/test/contracts/lambda.religo b/src/test/contracts/lambda.religo index 19d885228..8160a5d36 100644 --- a/src/test/contracts/lambda.religo +++ b/src/test/contracts/lambda.religo @@ -5,6 +5,4 @@ type storage = unit; (fun x -> ()) () */ -let main2 = ((p: unit), storage) => (((xxx: unit)) => ())(); - -let main = (x: (unit, storage)) => main2(x[0], x[1]); +let main = ((p,s) : (unit, storage)) => (((useless : unit)) => ()) (); diff --git a/src/test/contracts/lambda2.mligo b/src/test/contracts/lambda2.mligo index 840761bb2..6608f87e8 100644 --- a/src/test/contracts/lambda2.mligo +++ b/src/test/contracts/lambda2.mligo @@ -1,8 +1,8 @@ type storage = unit (* Not supported yet: -let main (p:unit) storage = (fun x -> ()) () +let main (a, s : unit * storage) = (fun x -> ()) () *) -let main (_: unit * storage) = - (fun (f: unit -> unit) -> f ()) (fun (_: unit) -> unit) +let main (a, s : unit * storage) = + (fun (f : unit -> unit) -> f ()) (fun (_ : unit) -> unit) diff --git a/src/test/contracts/lambda2.religo b/src/test/contracts/lambda2.religo index fd6a6bd27..8459101ee 100644 --- a/src/test/contracts/lambda2.religo +++ b/src/test/contracts/lambda2.religo @@ -4,7 +4,5 @@ type storage = unit; let main (p:unit) storage = (fun x -> ()) () */ -let main2 = (z: unit, storage) => - ((f: (unit => unit)) => f())((z: unit) => unit); - -let main = (x: (unit, storage)) => main2(x[0],x[1]); +let main = ((a, s) : (unit, storage)) : (operation (list), storage) => + ((f : (unit => unit)) => f ()) ((useless : unit) => unit); diff --git a/src/test/contracts/let_in_multi_bind.mligo b/src/test/contracts/let_in_multi_bind.mligo index e61dc14a7..e77d52990 100644 --- a/src/test/contracts/let_in_multi_bind.mligo +++ b/src/test/contracts/let_in_multi_bind.mligo @@ -1,5 +1,5 @@ -let sum (p: int * int) : int = +let sum (p : int * int) : int = let i, result = p in i + result -let sum2 (p: string * string * string * string) : int = +let sum2 (p : string * string * string * string) : int = let a, b, c, d = p in a ^ b ^ c ^ d diff --git a/src/test/contracts/let_multiple.mligo b/src/test/contracts/let_multiple.mligo index 08cb6dc3c..1ef5fbfa3 100644 --- a/src/test/contracts/let_multiple.mligo +++ b/src/test/contracts/let_multiple.mligo @@ -1,38 +1,36 @@ (* Simple test of binding multiple values *) -let (x: int), (y: int) = 1,2 +let (x : int), (y : int) = 1,2 -let main (p: unit) : int = x + y +let main (p : unit) : int = x + y -let ((x : int) , (y :int)) = 3,3 +let ((x : int) , (y : int)) = 3,3 -let main_paren (p: unit) : int = x + y +let main_paren (p : unit) : int = x + y let foobar : (int * int) = (23 , 42) let (foo : int) , (bar : int) = foobar (* Here to prevent a regression of https://gitlab.com/ligolang/ligo/issues/63#note_254106580 *) -let correct_values_bound (p: unit) : int * int = - foo, bar +let correct_values_bound (p : unit) : int * int = foo, bar -let non_tuple_rhs (p: unit) : int = - bar - foo +let non_tuple_rhs (p : unit) : int = bar - foo (* Here to prevent a regression of https://gitlab.com/ligolang/ligo/issues/63#note_254106580 *) -let big_tuple : (int * int * int * int * int) = (10, 20, 30, 40, 50) +let big_tuple : int * int * int * int * int = 10, 20, 30, 40, 50 let (a: int), (b: int), (c: int), (d: int), (e: int) = big_tuple -let correct_values_big_tuple (p: unit) : int * int * int * int * int = +let correct_values_big_tuple (p : unit) : int * int * int * int * int = a, b, c, d, e (* Here to prevent a regression of https://gitlab.com/ligolang/ligo/issues/63#note_254106580 *) -let different_types: (int * string) = 10, "hello" +let different_types : int * string = 10, "hello" -let (greet_num: int), (greeting: string) = different_types +let (greet_num : int), (greeting : string) = different_types -let correct_values_different_types (p: unit) : int * string = +let correct_values_different_types (p : unit) : int * string = greet_num, greeting diff --git a/src/test/contracts/let_multiple.religo b/src/test/contracts/let_multiple.religo index 0e5934027..b55df0d1d 100644 --- a/src/test/contracts/let_multiple.religo +++ b/src/test/contracts/let_multiple.religo @@ -1,14 +1,15 @@ /* Simple test of binding multiple values */ -let ((x: int), (y: int)) = (1, 2); +let ((x : int), (y : int)) = (1,2); -let main = (p: unit): int => x + y; +let main = (p : unit): int => x + y; -let ((x: int), (y: int)) = (3, 3); +let ((x : int), (y : int)) = (3,3); -let main_paren = (p: unit): int => x + y; +let main_paren = (p : unit): int => x + y; -let foobar: (int, int) = (23, 42); -let ((foo: int), (bar: int)) = foobar; +let foobar : (int, int) = (23, 42); -let non_tuple_rhs = (p: unit): int => foo + bar; +let ((foo : int), (bar : int)) = foobar; + +let non_tuple_rhs = (p : unit) : int => foo + bar; diff --git a/src/test/contracts/letin.mligo b/src/test/contracts/letin.mligo index 37b89aa3f..8ee8912c7 100644 --- a/src/test/contracts/letin.mligo +++ b/src/test/contracts/letin.mligo @@ -1,6 +1,6 @@ type storage = int * int -let main (n: int * storage) = +let main (n : int * storage) : operation list * storage = let x : int * int = let x : int = 7 in x + n.0, n.1.0 + n.1.1 diff --git a/src/test/contracts/letin.religo b/src/test/contracts/letin.religo index b370c0a59..8956133e3 100644 --- a/src/test/contracts/letin.religo +++ b/src/test/contracts/letin.religo @@ -1,11 +1,9 @@ type storage = (int, int); -let main2 = ((n : int), storage) => { - let x: (int, int) = { - let x: int = 7; - (x + n, storage[0] + storage[1]); +let main = (n : (int, storage)) : (list (operation), storage) => { + let x : (int, int) = { + let x : int = 7; + (x + n[0], n[1][0] + n[1][1]); }; - ([]: list(operation), x); + ([]: list (operation), x); }; - -let main = (x: (int, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/list.mligo b/src/test/contracts/list.mligo index 06a914514..26383f27b 100644 --- a/src/test/contracts/list.mligo +++ b/src/test/contracts/list.mligo @@ -1,27 +1,29 @@ type storage = int * int list -type param = int list +type parameter = int list + +type return = operation list * storage let x : int list = [] let y : int list = [3; 4; 5] let z : int list = 2::y -let main (p, s: param * storage) = +let main (p, s: parameter * storage) : return = let storage = match p with [] -> s | hd::tl -> s.0 + hd, tl in ([] : operation list), storage -let size_ (s: int list) : nat = List.size s +let size_ (s : int list) : nat = List.length s -let fold_op (s: int list) : int = - let aggregate = fun (t: int * int) -> t.0 + t.1 +let fold_op (s : int list) : int = + let aggregate = fun (t : int * int) -> t.0 + t.1 in List.fold aggregate s 10 -let map_op (s: int list) : int list = - List.map (fun (cur: int) -> cur + 1) s +let map_op (s : int list) : int list = + List.map (fun (cur : int) -> cur + 1) s let iter_op (s : int list) : unit = - let do_nothing = fun (_: int) -> unit + let do_nothing = fun (_ : int) -> unit in List.iter do_nothing s diff --git a/src/test/contracts/list.religo b/src/test/contracts/list.religo index 9f9a2ec1c..013188d7b 100644 --- a/src/test/contracts/list.religo +++ b/src/test/contracts/list.religo @@ -1,33 +1,33 @@ -type storage = (int, list(int)); +type storage = (int, list (int)); -type param = list(int); +type parameter = list (int); -let x: list(int) = []; -let y: list(int) = [3, 4, 5]; -let z: list(int) = [2, ...y]; +type return = (list (operation), storage); -let main2 = (p: param, storage) => { +let x : list (int) = []; +let y : list (int) = [3, 4, 5]; +let z : list (int) = [2, ...y]; + +let main = ((p,s) : (parameter, storage)) : return => { let storage = switch (p) { - | [] => storage - | [hd, ...tl] => (storage[0] + hd, tl) + | [] => s + | [hd, ...tl] => (s[0] + hd, tl) }; ([]: list(operation), storage); }; -let main = (x: (param, storage)) => main2(x[0],x[1]); +let size_ = (s : list (int)) : nat => List.length (s); -let size_ = (s: list(int)): nat => List.size(s); - -let fold_op = (s: list(int)): int => { - let aggregate = (prec_cur: (int, int)) => prec_cur[0] + prec_cur[1]; - List.fold(aggregate, s, 10); +let fold_op = (s : list (int)) : int => { + let aggregate = (t: (int, int)) => t[0] + t[1]; + List.fold (aggregate, s, 10); }; -let map_op = (s: list(int)): list(int) => - List.map((cur: int) => cur + 1, s); +let map_op = (s : list (int)) : list (int) => + List.map ((cur : int) => cur + 1, s); -let iter_op = (s: list(int)): unit => { - let do_nothing = (z: int) => unit; - List.iter(do_nothing, s); +let iter_op = (s : list (int)) : unit => { + let do_nothing = (useless : int) => unit; + List.iter (do_nothing, s); }; diff --git a/src/test/contracts/loop.mligo b/src/test/contracts/loop.mligo index 215aa6c41..82da7268e 100644 --- a/src/test/contracts/loop.mligo +++ b/src/test/contracts/loop.mligo @@ -1,33 +1,37 @@ -(* Test loops in CameLIGO *) +(* Test functional iterators in CameLIGO *) -let aux_simple (i: int) : bool * int = - if i < 100 then continue (i + 1) else stop i +let aux_simple (i : int) : bool * int = + if i < 100 then Loop.resume (i + 1) else Loop.stop i -let counter_simple (n: int) : int = +let counter_simple (n : int) : int = Loop.fold_while aux_simple n type sum_aggregator = { - counter : int ; - sum : int ; + counter : int; + sum : int } let counter (n : int) : int = - let initial : sum_aggregator = { counter = 0 ; sum = 0 } in - let out : sum_aggregator = Loop.fold_while (fun (prev: sum_aggregator) -> + let initial : sum_aggregator = {counter=0; sum=0} in + let aggregate = fun (prev : sum_aggregator) -> if prev.counter <= n then - continue ({ counter = prev.counter + 1 ; sum = prev.counter + prev.sum }) + Loop.resume {counter = prev.counter + 1; + sum = prev.counter + prev.sum} else - stop ({ counter = prev.counter ; sum = prev.sum }) ) - initial in out.sum + Loop.stop {counter = prev.counter; sum = prev.sum} in + let out : sum_aggregator = + Loop.fold_while aggregate initial + in out.sum -let aux_nest (prev: sum_aggregator) : bool * sum_aggregator = +let aux_nest (prev : sum_aggregator) : bool * sum_aggregator = if prev.counter < 100 then - continue ({ counter = prev.counter + 1 ; - sum = prev.sum + Loop.fold_while aux_simple prev.counter}) + let sum : int = + prev.sum + Loop.fold_while aux_simple prev.counter + in Loop.resume {counter = prev.counter + 1; sum = sum} else - stop ({ counter = prev.counter ; sum = prev.sum }) + Loop.stop {counter = prev.counter; sum = prev.sum} -let counter_nest (n: int) : int = - let initial : sum_aggregator = { counter = 0 ; sum = 0 } in +let counter_nest (n : int) : int = + let initial : sum_aggregator = {counter=0; sum=0} in let out : sum_aggregator = Loop.fold_while aux_nest initial in out.sum diff --git a/src/test/contracts/loop.religo b/src/test/contracts/loop.religo index 60bba7d17..a1d8b6e44 100644 --- a/src/test/contracts/loop.religo +++ b/src/test/contracts/loop.religo @@ -1,46 +1,41 @@ /* Test loops in ReasonLIGO */ -let aux_simple = (i: int): (bool, int) => - if (i < 100) { - continue(i + 1); - } else { - stop(i); - }; +let aux_simple = (i : int) : (bool, int) => + if (i < 100) { Loop.resume (i + 1); } else { Loop.stop (i); }; -let counter_simple = (n: int): int => Loop.fold_while(aux_simple, n); +let counter_simple = (n : int) : int => Loop.fold_while (aux_simple, n); type sum_aggregator = { - counter: int, - sum: int, + counter : int, + sum : int, }; -let counter = (n: int): int => { - let initial: sum_aggregator = {counter: 0, sum: 0}; - let out: sum_aggregator = - Loop.fold_while( - (prev: sum_aggregator) => - if (prev.counter <= n) { - continue({counter: prev.counter + 1, sum: prev.counter + prev.sum}); - } else { - stop({counter: prev.counter, sum: prev.sum}); - }, - initial - ); +let counter = (n : int) : int => { + let initial : sum_aggregator = {counter: 0, sum: 0}; + let aggregate = (prev : sum_aggregator) => + if (prev.counter <= n) { + Loop.resume ({counter : prev.counter + 1, + sum : prev.counter + prev.sum}); + } else { + Loop.stop ({counter: prev.counter, sum: prev.sum}); + }; + let out : sum_aggregator = + Loop.fold_while (aggregate, initial); out.sum; }; -let aux_nest = (prev: sum_aggregator): (bool, sum_aggregator) => +let aux_nest = (prev : sum_aggregator) : (bool, sum_aggregator) => if (prev.counter < 100) { - continue({ - counter: prev.counter + 1, - sum: prev.sum + Loop.fold_while(aux_simple, prev.counter), - }); + let sum : int = + prev.sum + Loop.fold_while (aux_simple, prev.counter); + Loop.resume ({counter: prev.counter + 1, + sum: sum}); } else { - stop({counter: prev.counter, sum: prev.sum}); + Loop.stop ({counter: prev.counter, sum: prev.sum}); }; -let counter_nest = (n: int): int => { - let initial: sum_aggregator = {counter: 0, sum: 0}; - let out: sum_aggregator = Loop.fold_while(aux_nest, initial); +let counter_nest = (n : int) : int => { + let initial : sum_aggregator = {counter: 0, sum: 0}; + let out : sum_aggregator = Loop.fold_while (aux_nest, initial); out.sum; }; diff --git a/src/test/contracts/map.mligo b/src/test/contracts/map.mligo index 7b13f406c..54772bf5b 100644 --- a/src/test/contracts/map.mligo +++ b/src/test/contracts/map.mligo @@ -7,47 +7,48 @@ let map1 : foobar = let map2 : foobar = Map.literal [(23,0); (42,0)] -let set_2 (n: int) (m: foobar) : foobar = Map.update 23 (Some n) m +let set_2 (n : int) (m : foobar) : foobar = Map.update 23 (Some n) m -let set_ (t: int * foobar) : foobar = set_2 t.0 t.1 +let set_ (t : int * foobar) : foobar = set_2 t.0 t.1 -let add (n,m: int * foobar) : foobar = Map.add 23 n m +let add (n,m : int * foobar) : foobar = Map.add 23 n m -let rm (m: foobar) : foobar = Map.remove 42 m +let rm (m : foobar) : foobar = Map.remove 42 m (* Dummy test so that we can add the same test for PascaLIGO *) -let patch_ (m: foobar) : foobar = Map.literal [(0,5); (1,6); (2,7)] + +let patch_ (m : foobar) : foobar = Map.literal [(0,5); (1,6); (2,7)] (* Second dummy test, see above *) -let patch_empty (m: foobar) : foobar = Map.literal [(0,0); (1,1); (2,2)] + +let patch_empty (m : foobar) : foobar = Map.literal [(0,0); (1,1); (2,2)] (* Third dummy test, see above *) -let patch_deep (m: foobar * nat) : foobar * nat = + +let patch_deep (m : foobar * nat) : foobar * nat = Map.literal [(0,0); (1,9); (2,2)], 10n -let size_ (m: foobar) : nat = Map.size m +let size_ (m : foobar) : nat = Map.size m -let gf (m: foobar) : int = Map.find 23 m +let get (m : foobar) : int option = Map.find_opt 42 m +let get_ (m : foobar) : int option = Map.find_opt 42 m -let get (m: foobar) : int option = Map.find_opt 42 m -let get_ (m: foobar) : int option = Map.find_opt 42 m - -let mem (k,m: int * foobar) : bool = Map.mem k m +let mem (k,m : int * foobar) : bool = Map.mem k m let iter_op (m : foobar) : unit = - let assert_eq = fun (i: int * int) -> assert (i.0 = i.1) + let assert_eq = fun (a, b : int * int) -> assert (a = b) in Map.iter assert_eq m let map_op (m : foobar) : foobar = - let increment = fun (i: int * int) -> i.1 + 1 + let increment = fun (i : int * int) -> i.1 + 1 in Map.map increment m let fold_op (m : foobar) : foobar = - let aggregate = fun (i: int * (int * int)) -> i.0 + i.1.0 + i.1.1 + let aggregate = fun (i : int * (int * int)) -> i.0 + i.1.0 + i.1.1 in Map.fold aggregate m 10 let deep_op (m: foobar) : foobar = - let coco = 0,m in + let coco = 0, m in let coco = 0, Map.remove 42 coco.1 in let coco = 0, Map.update 32 (Some 16) coco.1 in coco.1 diff --git a/src/test/contracts/map.religo b/src/test/contracts/map.religo index 74ec39dcf..a88ea1ad7 100644 --- a/src/test/contracts/map.religo +++ b/src/test/contracts/map.religo @@ -1,59 +1,60 @@ - -type foobar = map(int, int); +type foobar = map (int, int); let empty_map: foobar = Map.empty; -let map1: foobar = - Map.literal([(144, 23), (51, 23), (42, 23), (120, 23), (421, 23)]); +let map1 : foobar = + Map.literal ([(144, 23), (51, 23), (42, 23), (120, 23), (421, 23)]); -let map2: foobar = Map.literal([(23, 0), (42, 0)]); +let map2 : foobar = Map.literal ([(23, 0), (42, 0)]); -let set_ = (n: int, m: foobar): foobar => Map.update(23, Some(n), m); +let set_ = (n: int, m: foobar) : foobar => Map.update (23, Some (n), m); -let add = (n: int, m: foobar) : foobar => Map.add(23, n, m); +let add = (n: int, m: foobar) : foobar => Map.add (23, n, m); -let rm = (m: foobar): foobar => Map.remove(42, m); +let rm = (m: foobar) : foobar => Map.remove (42, m); /* Dummy test so that we can add the same test for PascaLIGO */ -let patch_ = (m: foobar): foobar => Map.literal([(0, 5), (1, 6), (2, 7)]); + +let patch_ = (m : foobar) : foobar => + Map.literal ([(0, 5), (1, 6), (2, 7)]); /* Second dummy test, see above */ -let patch_empty = (m: foobar): foobar => - Map.literal([(0, 0), (1, 1), (2, 2)]); + +let patch_empty = (m : foobar) : foobar => + Map.literal ([(0, 0), (1, 1), (2, 2)]); /* Third dummy test, see above */ -let patch_deep = (m: (foobar, nat)): (foobar, nat) => ( + +let patch_deep = (m : (foobar, nat)) : (foobar, nat) => ( Map.literal([(0, 0), (1, 9), (2, 2)]), 10n ); -let size_ = (m: foobar): nat => Map.size(m); +let size_ = (m : foobar) : nat => Map.size (m); -let gf = (m: foobar): int => Map.find(23, m); - -let get = (m: foobar): option(int) => Map.find_opt(42, m); +let get = (m: foobar): option(int) => Map.find_opt (42, m); let get_ = (m: foobar): option(int) => Map.find_opt(42, m); -let mem = (km: (int, foobar)): bool => Map.mem(km[0], km[1]); +let mem = (km: (int, foobar)): bool => Map.mem (km[0], km[1]); let iter_op = (m: foobar): unit => { - let assert_eq = (i: int, j: int) => assert(i == j); - Map.iter(assert_eq, m); + let assert_eq = (i: int, j: int) => assert (i == j); + Map.iter (assert_eq, m); }; -let map_op = (m: foobar): foobar => { +let map_op = (m: foobar) : foobar => { let increment = (z: int, j: int) => j + 1; - Map.map(increment, m); + Map.map (increment, m); }; let fold_op = (m: foobar): foobar => { let aggregate = (i: int, j: (int, int)) => i + j[0] + j[1]; - Map.fold(aggregate, m, 10); + Map.fold (aggregate, m, 10); }; -let deep_op = (m: foobar): foobar => { +let deep_op = (m: foobar) : foobar => { let coco = (0, m); - let coco = (0, Map.remove(42, coco[1])); - let coco = (0, Map.update(32, Some(16), coco[1])); + let coco = (0, Map.remove (42, coco[1])); + let coco = (0, Map.update (32, Some (16), coco[1])); coco[1]; }; diff --git a/src/test/contracts/match.mligo b/src/test/contracts/match.mligo index 36d3f4b9b..d3e9d8d52 100644 --- a/src/test/contracts/match.mligo +++ b/src/test/contracts/match.mligo @@ -1,28 +1,30 @@ type storage = int -type param = +type parameter = Add of int | Sub of int -let main (p, s: param * storage) = - let storage = - s + - (match p with - Add n -> n - | Sub n -> 0-n) - in ([] : operation list), storage +type return = operation list * storage -let match_bool (b: bool) : int = +let main (action, store : parameter * storage) = + let store = + store + + (match action with + Add n -> n + | Sub n -> -n) + in ([] : operation list), store + +let match_bool (b : bool) : int = match b with true -> 10 | false -> 0 -let match_list (l: int list) : int = +let match_list (l : int list) : int = match l with - hd :: tl -> hd + hd::tl -> hd | [] -> 10 -let match_option (i: int option) : int = +let match_option (i : int option) : int = match i with Some n -> n | None -> 0 diff --git a/src/test/contracts/match.religo b/src/test/contracts/match.religo index 3f77b252d..6aaf3f0a4 100644 --- a/src/test/contracts/match.religo +++ b/src/test/contracts/match.religo @@ -1,19 +1,18 @@ type storage = int; -type param = - | Add(int) - | Sub(int); +type parameter = +| Add (int) +| Sub (int); -let main2 = ((p: param), storage) => { - let storage = - storage - + ( - switch (p) { - | Add(n) => n - | Sub(n) => 0 - n +type return = (list (operation), storage); + +let main = ((action, store): (parameter, storage)) => { + let store = + store + + (switch (action) { + | Add (n) => n + | Sub (n) => -n } ); - (([]: list(operation)), storage); + (([]: list(operation)), store); }; - -let main = (x: (param, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/match_bis.mligo b/src/test/contracts/match_bis.mligo index dcbc155e9..145e1bcf6 100644 --- a/src/test/contracts/match_bis.mligo +++ b/src/test/contracts/match_bis.mligo @@ -1,19 +1,17 @@ type storage = int -(* variant defining pseudo multi-entrypoint actions *) - -type action = +type parameter = Increment of int | Decrement of int -let add (a: int) (b: int) : int = a + b -let sub (a: int) (b: int) : int = a - b +type return = operation list * storage -(* real entrypoint that re-routes the flow based on the action provided *) +let add (a : int) (b : int) : int = a + b +let sub (a : int) (b : int) : int = a - b -let main (p, s: action * storage) = - let storage = - match p with - Increment n -> add s n - | Decrement n -> sub s n - in ([] : operation list), storage +let main (action, store : parameter * storage) : return = + let store = + match action with + Increment n -> add store n + | Decrement n -> sub store n + in ([] : operation list), store diff --git a/src/test/contracts/match_bis.religo b/src/test/contracts/match_bis.religo index d1465d77b..9c7d12dae 100644 --- a/src/test/contracts/match_bis.religo +++ b/src/test/contracts/match_bis.religo @@ -1,24 +1,17 @@ type storage = int; -/* variant defining pseudo multi-entrypoint actions */ - -type action = - Increment(int) - | Decrement(int); +type parameter = + Increment (int) +| Decrement (int); let add = ((a: int), (b: int)) => a + b; +let sub = ((a: int), (b: int)) => a - b; -let subtract = ((a: int), (b: int)) => a - b; - -/* real entrypoint that re-routes the flow based on the action provided */ - -let main2 = ((p: action), storage) => { - let storage = - switch (p) { - | Increment(n) => add(storage, n) - | Decrement(n) => subtract(storage, n) +let main = ((action, store) : (parameter, storage)) => { + let store = + switch (action) { + | Increment (n) => add (store, n) + | Decrement (n) => sub (store, n) }; - (([]: list(operation)), storage); + (([]: list (operation)), store); }; - -let main = (x: (action, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/multiple-parameters.mligo b/src/test/contracts/multiple-parameters.mligo index 8b6d442f7..745b421cf 100644 --- a/src/test/contracts/multiple-parameters.mligo +++ b/src/test/contracts/multiple-parameters.mligo @@ -1,7 +1,7 @@ (* Test function with several parameters *) let abcde_curried (a : int) (b : int) (c : int) (d : int) (e : int) : int = - (c + e + 3) + c + e + 3 let abcde (x : int * int * int * int * int) : int = abcde_curried x.0 x.1 x.2 x.3 x.4 diff --git a/src/test/contracts/multiple-parameters.religo b/src/test/contracts/multiple-parameters.religo index 09af4152b..bececfa8f 100644 --- a/src/test/contracts/multiple-parameters.religo +++ b/src/test/contracts/multiple-parameters.religo @@ -1,6 +1,7 @@ /* Test function with several parameters */ -let abcde_curried = (a: int, b: int, c: int, d: int, e: int): int => c + e + 3; - -let abcde = (x: (int , int , int , int , int)): int => abcde_curried(x[0], x[1], x[2], x[3], x[4]); +let abcde_curried = + (a: int, b: int, c: int, d: int, e: int): int => c + e + 3; +let abcde = (x: (int , int , int , int , int)) : int => + abcde_curried (x[0], x[1], x[2], x[3], x[4]); diff --git a/src/test/contracts/multisig.mligo b/src/test/contracts/multisig.mligo index 2a7753cc6..4d81e158a 100644 --- a/src/test/contracts/multisig.mligo +++ b/src/test/contracts/multisig.mligo @@ -2,65 +2,63 @@ type counter = nat type threshold = nat -type authorized_keys = (key) list +type authorized_keys = key list type id = string type storage = { - id : id; - counter : counter; - threshold : threshold; - auth : authorized_keys + id : id; + counter : counter; + threshold : threshold; + auth : authorized_keys } // I/O types -type message = unit -> (operation) list +type message = unit -> operation list + +type signatures = (key_hash * signature) list -type signatures = (key_hash*signature) list type check_message_pt = { - counter : counter; - message : message; - signatures : signatures + counter : counter; + message : message; + signatures : signatures } -type return = (operation) list * storage +type return = operation list * storage type parameter = CheckMessage of check_message_pt -let check_message (param,s : check_message_pt * storage) : return = +let check_message (param, s : check_message_pt * storage) : return = let message : message = param.message in let s = - if (param.counter <> s.counter) then - let coco = failwith ("Counters does not match") in s - else ( - let packed_payload : bytes = Bytes.pack ((message, param.counter, s.id, chain_id)) in - let valid : nat = 0n in - let keys : authorized_keys = s.auth in - let aux = fun (vk, pkh_sig: (nat* authorized_keys) * (key_hash*signature)) -> - let (valid,keys) = vk in - match (keys) with - | [] -> (valid,keys) - | key::tl -> ( - let keys = tl in - if (pkh_sig.0 = Crypto.hash_key (key)) then - let valid = - if (Crypto.check key pkh_sig.1 packed_payload) then valid + 1n - else let coco = failwith ("Invalid signature") in valid - in - (valid,keys) - else (valid,keys) - ) - in - let (valid,keys) = List.fold aux param.signatures (valid,keys) in - if (valid < s.threshold) then - let coco = failwith ("Not enough signatures passed the check") in - s - else - {s with counter = s.counter + 1n} - ) - in - (message(unit),s) + if param.counter <> s.counter then + (failwith "Counters does not match" : storage) + else + let packed_payload : bytes = + Bytes.pack (message, param.counter, s.id, chain_id) in + let valid : nat = 0n in + let keys : authorized_keys = s.auth in + let aux = + fun (vk, pkh_sig: (nat * authorized_keys)*(key_hash * signature)) -> + let valid, keys = vk in + match keys with + | [] -> vk + | key::keys -> + if pkh_sig.0 = Crypto.hash_key key + then + let valid = + if Crypto.check key pkh_sig.1 packed_payload + then valid + 1n + else (failwith "Invalid signature" : nat) + in valid, keys + else valid, keys in + let valid, keys = + List.fold aux param.signatures (valid, keys) in + if valid < s.threshold then + (failwith ("Not enough signatures passed the check") : storage) + else {s with counter = s.counter + 1n} + in message unit, s -let main (param, s: parameter * storage) : return = - match (param) with - | CheckMessage (p) -> check_message (p,s) +let main (action, store : parameter * storage) : return = + match action with + CheckMessage (p) -> check_message (p, store) diff --git a/src/test/contracts/multisig.religo b/src/test/contracts/multisig.religo index a2d709ab9..82b44d861 100644 --- a/src/test/contracts/multisig.religo +++ b/src/test/contracts/multisig.religo @@ -6,75 +6,72 @@ type authorized_keys = list (key); type id = string; type storage = { - id : id, - counter : counter, - threshold : threshold, - auth : authorized_keys + id : id, + counter : counter, + threshold : threshold, + auth : authorized_keys }; // I/O types type message = unit => list (operation); + type dummy = (key_hash,signature); -type signatures = list (dummy); + +type signatures = list (dummy); /* Waiting to be fixed */ type check_message_pt = { - counter : counter, - message : message, - signatures : signatures + counter : counter, + message : message, + signatures : signatures }; -type return = (list (operation),storage); +type return = (list (operation),storage); type parameter = CheckMessage (check_message_pt); -let check_message = ((param,s) : (check_message_pt, storage)) : return => { +let check_message = ((param, s): (check_message_pt, storage)) : return => +{ let message : message = param.message; let s = - if (param.counter != s.counter) { - let coco = failwith ("Counters does not match"); - s; - } - else { - let packed_payload : bytes = Bytes.pack ((message, param.counter, s.id, chain_id)); - let valid : nat = 0n; - let keys : authorized_keys = s.auth; - let aux = ((vk,pkh_sig) : ((nat, authorized_keys),(key_hash,signature))):(nat,authorized_keys) => { - let (valid,keys) = vk; - switch(keys) { - | [] => (valid,keys); - | [key, ...tl] => { - let keys = tl; - if (pkh_sig[0] == Crypto.hash_key (key)){ - let valid = - if (Crypto.check (key, pkh_sig[1], packed_payload)){ - valid + 1n ; - } - else { - let coco = failwith ("Invalid signature"); - valid; - }; - (valid,keys); - } - else { - (valid,keys); - }; + if (param.counter != s.counter) { + (failwith ("Counters does not match") : storage); + } else { + let packed_payload : bytes = + Bytes.pack ((message, param.counter, s.id, chain_id)); + let valid : nat = 0n; + let keys : authorized_keys = s.auth; + let aux = ((vk, pkh_sig) : + ((nat, authorized_keys), (key_hash, signature))) + : (nat, authorized_keys) => { + let (valid, keys) = vk; + switch (keys) { + | [] => vk; + | [key, ...keys] => + if (pkh_sig[0] == Crypto.hash_key (key)) { + let valid = + if (Crypto.check (key, pkh_sig[1], packed_payload)) { + valid + 1n; + } + else { (failwith ("Invalid signature") : nat) }; + (valid, keys); + } + else { (valid, keys); }; }; }; - }; - let (valid,keys) = List.fold (aux, param.signatures, (valid,keys)); + let (valid, keys) = + List.fold (aux, param.signatures, (valid, keys)); if (valid < s.threshold) { - let coco = failwith ("Not enough signatures passed the check"); - s; + (failwith ("Not enough signatures passed the check") : storage); } else { {...s,counter : s.counter + 1n}; }; }; - (message(unit),s) + (message (unit),s) }; -let main = ((param, s) : (parameter,storage)) : return => - switch(param) { - | CheckMessage (p) => check_message ((p,s)) +let main = ((action, store) : (parameter,storage)) : return => + switch (action) { + | CheckMessage (p) => check_message ((p, store)) } diff --git a/src/test/contracts/negative/self_in_lambda.mligo b/src/test/contracts/negative/self_in_lambda.mligo index 493047199..88d201974 100644 --- a/src/test/contracts/negative/self_in_lambda.mligo +++ b/src/test/contracts/negative/self_in_lambda.mligo @@ -1,5 +1,5 @@ let foo (u: unit) : address = - Current.self_address + Tezos.self_address let main (ps: unit * address): (operation list * address) = - ( ([] : operation list) , foo) \ No newline at end of file + ( ([] : operation list) , foo) diff --git a/src/test/contracts/option.religo b/src/test/contracts/option.religo index 75dacb697..e416a034e 100644 --- a/src/test/contracts/option.religo +++ b/src/test/contracts/option.religo @@ -1,4 +1,4 @@ -type foobar = option(int); +type foobar = option (int); -let s: foobar = Some(42); -let n: foobar = None; +let s : foobar = Some (42); +let n : foobar = None; diff --git a/src/test/contracts/record.mligo b/src/test/contracts/record.mligo index 4863cdf6c..96cb99a33 100644 --- a/src/test/contracts/record.mligo +++ b/src/test/contracts/record.mligo @@ -1,24 +1,10 @@ -type foobar = { - foo : int ; - bar : int ; -} +type foobar = {foo : int; bar : int} -let fb : foobar = { - foo = 0 ; - bar = 0 ; -} +let fb : foobar = {foo=0; bar=0} -type abc = { - a : int ; - b : int ; - c : int -} +type abc = {a : int; b : int; c : int} -let abc : abc = { - a = 42 ; - b = 142 ; - c = 242 -} +let abc : abc = {a=42; b=142; c=242} let a : int = abc.a let b : int = abc.b @@ -28,26 +14,25 @@ let projection (r : foobar) : int = r.foo + r.bar let modify (r : foobar) : foobar = {foo = 256; bar = r.bar} -let modify_abc (r : abc) : abc = let c = 42 in {r with b = 2048; c = c} +let modify_abc (r : abc) : abc = let c = 42 in {r with b=2048; c=c} type big_record = { - a : int ; - b : int ; - c : int ; - d : int ; - e : int ; + a : int; + b : int; + c : int; + d : int; + e : int } let br : big_record = { - a = 23 ; - b = 23 ; - c = 23 ; - d = 23 ; - e = 23 ; + a = 23; + b = 23; + c = 23; + d = 23; + e = 23 } -type double_record = { - inner : abc; -} +type double_record = {inner : abc} -let modify_inner (r : double_record) : double_record = {r with inner.b = 2048 } +let modify_inner (r : double_record) : double_record = + {r with inner.b = 2048} diff --git a/src/test/contracts/record.religo b/src/test/contracts/record.religo index c82801324..793d01640 100644 --- a/src/test/contracts/record.religo +++ b/src/test/contracts/record.religo @@ -1,22 +1,22 @@ type foobar = { - foo : int , - bar : int , + foo : int, + bar : int }; let fb : foobar = { - foo : 0 , - bar : 0 , + foo : 0, + bar : 0 }; type abc = { - a : int , - b : int , + a : int, + b : int, c : int }; let abc : abc = { - a : 42 , - b : 142 , + a : 42, + b : 142, c : 242 }; @@ -24,30 +24,31 @@ let a : int = abc.a; let b : int = abc.b; let c : int = abc.c; -let projection = (r : foobar) : int => r.foo + r.bar; +let projection = (r: foobar) : int => r.foo + r.bar; -let modify = (r : foobar) : foobar => {foo : 256, bar : r.bar}; +let modify = (r: foobar) : foobar => {foo: 256, bar: r.bar}; -let modify_abc = (r : abc) : abc => {...r,b : 2048 , c:42}; +let modify_abc = (r: abc) : abc => {...r, b: 2048, c: 42}; type big_record = { - a : int , - b : int , - c : int , - d : int , - e : int , + a : int, + b : int, + c : int, + d : int, + e : int }; let br : big_record = { - a : 23 , - b : 23 , - c : 23 , - d : 23 , - e : 23 , + a : 23, + b : 23, + c : 23, + d : 23, + e : 23 }; type double_record = { inner : abc, }; -let modify_inner = (r : double_record) : double_record => {...r,inner.b : 2048 }; +let modify_inner = + (r: double_record) : double_record => {...r, inner.b : 2048}; diff --git a/src/test/contracts/self_address.ligo b/src/test/contracts/self_address.ligo index e6f440a7e..5dd4aebe0 100644 --- a/src/test/contracts/self_address.ligo +++ b/src/test/contracts/self_address.ligo @@ -1 +1 @@ -function main (const p : unit) : address is self_address +function main (const p : unit) : address is Tezos.self_address diff --git a/src/test/contracts/self_address.mligo b/src/test/contracts/self_address.mligo index ade0926ee..bd33b92a6 100644 --- a/src/test/contracts/self_address.mligo +++ b/src/test/contracts/self_address.mligo @@ -1 +1 @@ -let main (p: unit) : address = Current.self_address +let main (p : unit) : address = Tezos.self_address diff --git a/src/test/contracts/self_address.religo b/src/test/contracts/self_address.religo index e072bc56f..a2dd5a652 100644 --- a/src/test/contracts/self_address.religo +++ b/src/test/contracts/self_address.religo @@ -1 +1 @@ -let main = (p: unit): address => Current.self_address; +let main = (p: unit) : address => Tezos.self_address; diff --git a/src/test/contracts/set_arithmetic-1.mligo b/src/test/contracts/set_arithmetic-1.mligo index 6c31953b4..634c18cc6 100644 --- a/src/test/contracts/set_arithmetic-1.mligo +++ b/src/test/contracts/set_arithmetic-1.mligo @@ -2,5 +2,4 @@ let aggregate (i : int) (j : int) : int = i + j -let fold_op (s : int set) : int = - Set.fold aggregate s 15 +let fold_op (s : int set) : int = Set.fold aggregate s 15 diff --git a/src/test/contracts/set_arithmetic.mligo b/src/test/contracts/set_arithmetic.mligo index 2713905b3..9d3c6e2a1 100644 --- a/src/test/contracts/set_arithmetic.mligo +++ b/src/test/contracts/set_arithmetic.mligo @@ -20,8 +20,6 @@ let patch_op_deep (s: string set * nat) : string set * nat = begin patch s.0 with set ["foobar"]; end with s *) -let mem_op (s : string set) : bool = - Set.mem "foobar" s +let mem_op (s : string set) : bool = Set.mem "foobar" s -let size_op (s: string set) : nat = - Set.size s +let size_op (s: string set) : nat = Set.cardinal s diff --git a/src/test/contracts/set_arithmetic.religo b/src/test/contracts/set_arithmetic.religo index 5aa634333..a219fba9b 100644 --- a/src/test/contracts/set_arithmetic.religo +++ b/src/test/contracts/set_arithmetic.religo @@ -1,22 +1,19 @@ /* Test set operations in ReasonLIGO */ -let literal_op = (p: unit) : set(string) => Set.literal(["foo", "bar", "foobar"]); +let literal_op = (p: unit) : set (string) => + Set.literal (["foo", "bar", "foobar"]); -let add_op = (s: set(string)): set(string) => Set.add("foobar", s); +let add_op = (s: set (string)) : set (string) => + Set.add ("foobar", s); -let remove_op = (s: set(string)): set(string) => Set.remove("foobar", s); +let remove_op = (s: set (string)) : set(string) => + Set.remove ("foobar", s); -let remove_deep = (s: (set(string), nat)): (set(string), nat) => - Set.remove("foobar", s[0]); +let remove_deep = (s: (set (string), nat)): (set (string), nat) => + Set.remove ("foobar", s[0]); -/* - let patch_op (s: string set) : string set = - begin patch s with set ["foobar"]; end with s +let mem_op = (s: set (string)) : bool => + Set.mem ("foobar", s); - let patch_op_deep (s: string set * nat) : string set * nat = - begin patch s[0] with set ["foobar"]; end with s - */ - -let mem_op = (s: set(string)): bool => Set.mem("foobar", s); - -let size_op = (s: set(string)): nat => Set.size(s); +let size_op = (s: set (string)): nat => + Set.cardinal (s); diff --git a/src/test/contracts/set_delegate.mligo b/src/test/contracts/set_delegate.mligo index 9b3629f5d..66346cef6 100644 --- a/src/test/contracts/set_delegate.mligo +++ b/src/test/contracts/set_delegate.mligo @@ -1,3 +1,3 @@ -let main (p: key_hash) : operation list = - let unused: operation = (Operation.set_delegate (Some p)) in ([]: operation list) - +let main (p : key_hash) : operation list = + let useless : operation = Tezos.set_delegate (Some p) + in ([] : operation list) diff --git a/src/test/contracts/set_delegate.religo b/src/test/contracts/set_delegate.religo index bae3a38fb..90d3d0c12 100644 --- a/src/test/contracts/set_delegate.religo +++ b/src/test/contracts/set_delegate.religo @@ -1,4 +1,4 @@ -let main = (p: key_hash) : list(operation) => { - let unused: operation = (Operation.set_delegate(Some(p))); - ([]: list(operation)); +let main = (p: key_hash) : list (operation) => { + let unused : operation = (Tezos.set_delegate (Some (p))); + ([] : list (operation)); } ; diff --git a/src/test/contracts/string_arithmetic.mligo b/src/test/contracts/string_arithmetic.mligo index a17e8bd47..97d74d5e3 100644 --- a/src/test/contracts/string_arithmetic.mligo +++ b/src/test/contracts/string_arithmetic.mligo @@ -1,7 +1,5 @@ (* Test that the string concatenation syntax in CameLIGO works *) -let size_op (s: string) : nat = String.size s - -let slice_op (s: string) : string = String.slice 1n 2n s - -let concat_syntax (s: string) = s ^ "test_literal" +let size_op (s : string) : nat = String.length s +let slice_op (s : string) : string = String.sub 1n 2n s +let concat_syntax (s : string) = s ^ "test_literal" diff --git a/src/test/contracts/string_arithmetic.religo b/src/test/contracts/string_arithmetic.religo index ba3949f08..cd3a785cb 100644 --- a/src/test/contracts/string_arithmetic.religo +++ b/src/test/contracts/string_arithmetic.religo @@ -1,7 +1,5 @@ /* Test that the string concatenation syntax in ReasonLIGO works */ -let size_op = (s: string): nat => String.size(s); - -let slice_op = (s: string): string => String.slice(1n, 2n, s); - +let size_op = (s: string) : nat => String.length (s); +let slice_op = (s: string) : string => String.sub (1n, 2n, s); let concat_syntax = (s: string) => s ++ "test_literal"; diff --git a/src/test/contracts/subtle_nontail_fail.mligo b/src/test/contracts/subtle_nontail_fail.mligo index 107dbdb1e..6b3c52b9b 100644 --- a/src/test/contracts/subtle_nontail_fail.mligo +++ b/src/test/contracts/subtle_nontail_fail.mligo @@ -1,4 +1,4 @@ -let main (ps : unit * unit) = +let main (_ : unit * unit) = if true then failwith "This contract always fails" else failwith "This contract still always fails" diff --git a/src/test/contracts/super-counter.mligo b/src/test/contracts/super-counter.mligo index dc00c9567..2090a5732 100644 --- a/src/test/contracts/super-counter.mligo +++ b/src/test/contracts/super-counter.mligo @@ -1,13 +1,17 @@ -type action = -| Increment of int +type parameter = + Increment of int | Decrement of int -let test_param = Increment(1) +type storage = int + +type return = operation list * storage + +let test_param = Increment 1 let test_storage = 2 -let main (ps : action * int) : (operation list * int) = - let storage = - match ps.0 with - | Increment n -> ps.1 + n - | Decrement n -> ps.1 - n in - (([] : operation list) , storage) +let main (action, store : parameter * storage) : return = + let store = + match action with + | Increment n -> store + n + | Decrement n -> store - n + in ([] : operation list), store diff --git a/src/test/contracts/super-counter.religo b/src/test/contracts/super-counter.religo index 3e64f3152..53eba61af 100644 --- a/src/test/contracts/super-counter.religo +++ b/src/test/contracts/super-counter.religo @@ -1,12 +1,16 @@ -type action = - | Increment(int) - | Decrement(int); +type parameter = + Increment (int) +| Decrement (int); -let main = (p: action, s: int): (list(operation), int) => { - let storage = - switch (p) { - | Increment(n) => s + n - | Decrement(n) => s - n +type storage = int; + +type return = (list (operation), storage); + +let main = ((action, store): (parameter, storage) : return => { + let store = + switch (action) { + | Increment (n) => store + n + | Decrement (n) => store - n }; - ([]: list(operation), storage); + ([] : list (operation), store); }; diff --git a/src/test/contracts/tez.mligo b/src/test/contracts/tez.mligo index 557de9e2d..f03821ec8 100644 --- a/src/test/contracts/tez.mligo +++ b/src/test/contracts/tez.mligo @@ -1,5 +1,6 @@ -let add_tez : tez = 21mutez + 0.000021tz -let sub_tez : tez = 0.000021tz - 0.000020tz -let not_enough_tez : tez = 4611686018427.387903tz +let add_tez : tez = 21mutez + 0.000_021tez +let sub_tez : tez = 0.000021tez - 0.000_020tez +let not_enough_tez : tez = 461_168_601_842_738_7903mutez -let add_more_tez : tez = 100tz + 10tz + 1tz + 0.1tz + 0.01tz + 0.001tz +let add_more_tez : tez = + 100tez + 10tez + 1tez + 0.1tez + 0.01tez + 0.001tez diff --git a/src/test/contracts/timelock_repeat.mligo b/src/test/contracts/timelock_repeat.mligo index 5efff81a9..e2d4edd05 100644 --- a/src/test/contracts/timelock_repeat.mligo +++ b/src/test/contracts/timelock_repeat.mligo @@ -1,22 +1,22 @@ +type parameter = unit + type storage = { - next_use: timestamp; - interval: int; - execute: unit -> operation list; + next_use : timestamp; + interval : int; + execute : unit -> operation list } -let main (p,s: unit * storage) : operation list * storage = - (* Multiple calls to Current.time give different values *) - let now: timestamp = Current.time in - if now > s.next_use +type return = operation list * storage + +let main (action, store : parameter * storage) : return = + (* Multiple evaluations of Tezos.now give different values *) + let my_now : timestamp = Tezos.now in + if my_now > store.next_use then - let s: storage = { - next_use = now + s.interval; - interval = s.interval; - execute = s.execute; - } - in - (s.execute (), s) + let store : storage = + {store with next_use = my_now + store.interval} + in store.execute (), store else (* TODO: Add the time until next use to this message *) - (failwith "You have to wait before you can execute this contract again.": - operation list * storage) + (failwith "You have to wait before you can execute this contract again." + : return) diff --git a/src/test/contracts/tuple.mligo b/src/test/contracts/tuple.mligo index 11726bf18..5dd1c4c2e 100644 --- a/src/test/contracts/tuple.mligo +++ b/src/test/contracts/tuple.mligo @@ -4,7 +4,7 @@ let projection_abc (tpl : abc) : int = tpl.1 type foobar = int * int -let fb : foobar = (0, 0) +let fb : foobar = (0,0) let projection (tpl : foobar) : int = tpl.0 + tpl.1 diff --git a/src/test/contracts/tuple_type.mligo b/src/test/contracts/tuple_type.mligo index d9cdb62b5..98e85209f 100644 --- a/src/test/contracts/tuple_type.mligo +++ b/src/test/contracts/tuple_type.mligo @@ -1,14 +1,13 @@ -let g (b: int) = b + 3 +let g (b : int) = b + 3 -let f (b: int * int) : int -> int = g +let f (b : int * int) : int -> int = g -let a (b: int * int -> int -> int) : int = (b (5,3)) 5 +let a (b : int * int -> int -> int) : int = (b (5,3)) 5 -let test1 (_: int) = - a f +let test1 (_: int) = a f -let n (a, b: int * int): int = a + b +let n (a, b : int * int) : int = a + b -let o (p: int * int -> int): int = p((3, 9)) +let o (p : int * int -> int) : int = p (3, 9) -let test2 (ignore: int) = o(n) +let test2 (ignore : int) = o (n) diff --git a/src/test/contracts/tuple_type.religo b/src/test/contracts/tuple_type.religo index 6148840c0..e17fbc9fb 100644 --- a/src/test/contracts/tuple_type.religo +++ b/src/test/contracts/tuple_type.religo @@ -1,49 +1,43 @@ -/* - The difference between tuples and arguments is subtle in ReasonLIGO. - - `f(a, b);` +/* + The difference between tuples and arguments is subtle in ReasonLIGO. + + `f(a, b);` f is called with two arguments - `f((a, b));` + `f((a, b));` f is called with a tuple. - + */ type fun_type = (int, int) => int; -let arguments = (b: int, c: int) => { - b + c; -}; +let arguments = (b: int, c: int) => { b + c; }; -let arguments_type_def = (b: fun_type) => b(5, 3); +let arguments_type_def = (b: fun_type) => b (5, 3); -let arguments_test = (ignore: int) => arguments_type_def(arguments); +let arguments_test = (ignore: int) => arguments_type_def (arguments); type tuple_type = ((int, int)) => int; -let tuple = ((a, b): (int, int)) => { - a + b; -}; +let tuple = ((a, b): (int, int)) => { a + b; }; -let tuple_type_def = (b: tuple_type) => b((5, 3)); +let tuple_type_def = (b: tuple_type) => b ((5, 3)); -let tuple_test = (ignore: int) => tuple_type_def(tuple); +let tuple_test = (ignore: int) => tuple_type_def (tuple); /* inline */ -let arguments_inline = (b: int, c: int) => { - b + c; -}; +let arguments_inline = (b: int, c: int) => { b + c; }; -let arguments_type_def_inline = (b: (int, int) => int) => b(5, 3); +let arguments_type_def_inline = (b: (int, int) => int) => b (5, 3); -let arguments_test_inline = (ignore: int) => arguments_type_def_inline(arguments_inline); +let arguments_test_inline = (ignore: int) => + arguments_type_def_inline (arguments_inline); -let tuple_inline = ((a, b): (int, int)) => { - a + b; -}; +let tuple_inline = ((a, b): (int, int)) => { a + b; }; -let tuple_type_def_inline = (b: ((int, int)) => int) => b((5, 3)); +let tuple_type_def_inline = (b: ((int, int)) => int) => b ((5, 3)); -let tuple_test_inline = (ignore: int) => tuple_type_def_inline(tuple_inline); +let tuple_test_inline = (ignore: int) => + tuple_type_def_inline(tuple_inline); diff --git a/src/test/contracts/tuples_sequences_functions.religo b/src/test/contracts/tuples_sequences_functions.religo index bffd78faf..38107dd54 100644 --- a/src/test/contracts/tuples_sequences_functions.religo +++ b/src/test/contracts/tuples_sequences_functions.religo @@ -34,12 +34,12 @@ let q = { }, }; -/* +/* Not supported yet by parser: let r = { a: 1 -}; +}; */ let s = { diff --git a/src/test/contracts/type_tuple_destruct.mligo b/src/test/contracts/type_tuple_destruct.mligo index 05bcaea59..b9b9afcaa 100644 --- a/src/test/contracts/type_tuple_destruct.mligo +++ b/src/test/contracts/type_tuple_destruct.mligo @@ -1,11 +1,11 @@ type foobar = int * int -let test_t: foobar = 10, 25 +let test_t : foobar = 10, 25 let foo, bar = test_t -let type_tuple_d (p: unit) = foo + bar +let type_tuple_d (p : unit) = foo + bar type complex = string * int * string * nat let test_t_2 = "hello", 10, "world", 50n let hello, ten, world, fifty_n = test_t_2 -let type_tuple_d_2 (p: unit) = hello ^ world +let type_tuple_d_2 (p : unit) = hello ^ world diff --git a/src/test/contracts/variant.mligo b/src/test/contracts/variant.mligo index ee56b808d..874ab75be 100644 --- a/src/test/contracts/variant.mligo +++ b/src/test/contracts/variant.mligo @@ -4,7 +4,5 @@ type foobar = | Kee of nat let foo : foobar = Foo 42 - let bar : foobar = Bar true - let kee : foobar = Kee 23n diff --git a/src/test/contracts/variant.religo b/src/test/contracts/variant.religo index 99b69e94f..a408a3900 100644 --- a/src/test/contracts/variant.religo +++ b/src/test/contracts/variant.religo @@ -1,10 +1,8 @@ type foobar = - | Foo(int) - | Bar(bool) - | Kee(nat); + Foo (int) +| Bar (bool) +| Kee (nat); -let foo: foobar = Foo(42); - -let bar: foobar = Bar(true); - -let kee: foobar = Kee(23n); +let foo: foobar = Foo (42); +let bar: foobar = Bar (true); +let kee: foobar = Kee (23n); diff --git a/src/test/contracts/vote.mligo b/src/test/contracts/vote.mligo index a32f54fa4..aefc8e4a0 100644 --- a/src/test/contracts/vote.mligo +++ b/src/test/contracts/vote.mligo @@ -1,56 +1,49 @@ type storage = { - title : string ; - candidates : (string , int) map ; - voters : address set ; - beginning_time : timestamp ; - finish_time : timestamp ; + title : string; + yea : nat; + nay : nat; + voters : address set; + start_time : timestamp; + finish_time : timestamp } -type init_action = { - title : string ; - beginning_time : timestamp ; - finish_time : timestamp ; +type return = operation list * storage + +type vote = Yea | Nay + +type reset = { + title : string; + start_time : timestamp; + finish_time : timestamp } -type action = - | Vote of string - | Init of init_action +type parameter = +| Vote of vote +| Reset of reset -let init (init_params_s : init_action * storage) = - let candidates = Map.literal [ - ("Yes" , 0) ; - ("No" , 0) - ] in - ( - ([] : operation list), - { - title = init_params_s.0.title ; - candidates = candidates ; - voters = (Set.empty : address set) ; - beginning_time = init_params_s.0.beginning_time ; - finish_time = init_params_s.0.finish_time ; - } - ) +let reset (reset, _ : reset * storage) : return = + ([] : operation list), + {title = reset.title; + yea = 0n; + nay = 0n; + voters = (Set.empty : address set); + start_time = reset.start_time; + finish_time = reset.finish_time} -let vote (ps : string * storage) = - let now = Current.time in - (* let _ = assert (now >= ps.1.beginning_time && ps.1.finish_time > now) in *) - let addr = Current.sender in - (* let _ = assert (not Set.mem addr ps.1.voters) in *) - let x = Map.find ps.0 ps.1.candidates in - ( - ([] : operation list), - { - title = ps.1.title ; - candidates = Map.update ps.0 (Some (x + 1)) ps.1.candidates ; - voters = Set.add addr ps.1.voters ; - beginning_time = ps.1.beginning_time ; - finish_time = ps.1.finish_time ; - } - ) - -let main (a_s : action * storage) = - match a_s.0 with - | Vote p -> vote (p, a_s.1) - | Init ps -> init (ps, a_s.1) +let vote (vote, store : vote * storage) : return = + let now = Tezos.now in + (* let _ = + assert (now >= store.start_time && store.finish_time > now) in *) + let addr = Tezos.sender in + (* let _ = assert (not Set.mem addr store.voters) in *) + let store = + match vote with + Yea -> {store with yea = store.yea + 1n} + | Nay -> {store with nay = store.nay + 1n} + in ([] : operation list), + {store with voters = Set.add addr store.voters} +let main (action, store : parameter * storage) : return = + match action with + | Vote v -> vote (v, store) + | Reset r -> reset (r, store) diff --git a/src/test/contracts/website2.mligo b/src/test/contracts/website2.mligo index 73c04cbd5..cc6d85ff5 100644 --- a/src/test/contracts/website2.mligo +++ b/src/test/contracts/website2.mligo @@ -4,16 +4,16 @@ type storage = int (* variant defining pseudo multi-entrypoint actions *) -type action = +type parameter = | Increment of int | Decrement of int let add (a,b: int * int) : int = a + b let sub (a,b: int * int) : int = a - b -(* real entrypoint that re-routes the flow based on the action provided *) +(* real entrypoint that re-routes the flow based on the parameter provided *) -let main (p,s: action * storage) = +let main (p,s: parameter * storage) = let storage = match p with | Increment n -> add (s, n) diff --git a/src/test/contracts/website2.religo b/src/test/contracts/website2.religo index ffed8cd90..f9b936047 100644 --- a/src/test/contracts/website2.religo +++ b/src/test/contracts/website2.religo @@ -4,22 +4,22 @@ type storage = int; /* variant defining pseudo multi-entrypoint actions */ -type action = - | Increment(int) - | Decrement(int); +type parameter = +| Increment (int) +| Decrement (int); let add = ((a,b): (int, int)): int => a + b; let sub = ((a,b): (int, int)): int => a - b; -/* real entrypoint that re-routes the flow based on the action provided */ +/* real entrypoint that re-routes the flow based on the parameter provided */ -let main = ((p,storage): (action, storage)) => { +let main = ((p,storage): (parameter, storage)) => { let storage = switch (p) { - | Increment(n) => add((storage, n)) - | Decrement(n) => sub((storage, n)) + | Increment(n) => add ((storage, n)) + | Decrement(n) => sub ((storage, n)) }; - ([]: list(operation), storage); + ([]: list (operation), storage); }; (* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *) diff --git a/src/test/hash_lock_tests.ml b/src/test/hash_lock_tests.ml index 7bfe77c88..7da1882ab 100644 --- a/src/test/hash_lock_tests.ml +++ b/src/test/hash_lock_tests.ml @@ -61,7 +61,7 @@ let commit () = let salted_hash = e_bytes_raw (sha_256_hash (Bytes.concat Bytes.empty [test_hash_raw; packed_sender])) - + in let pre_commits = e_typed_big_map [] t_address (t_record_ez [("date", t_timestamp); ("salted_hash", t_bytes)]) @@ -99,7 +99,7 @@ let reveal_no_commit () = let init_storage = storage test_hash true pre_commits in expect_string_failwith program "reveal" (e_pair reveal init_storage) - "You haven't made a commitment to hash against yet." + "You have not made a commitment to hash against yet." (* Test that the contract fails if our commit isn't 24 hours old yet *) let reveal_young_commit () = @@ -132,7 +132,7 @@ let reveal_young_commit () = in expect_string_failwith ~options program "reveal" (e_pair reveal init_storage) - "It hasn't been 24 hours since your commit yet." + "It has not been 24 hours since your commit yet." (* Test that the contract fails if our reveal doesn't meet our commitment *) let reveal_breaks_commit () = @@ -164,7 +164,7 @@ let reveal_breaks_commit () = in expect_string_failwith ~options program "reveal" (e_pair reveal init_storage) - "This reveal doesn't match your commitment." + "This reveal does not match your commitment." (* Test that the contract fails if we reveal the wrong bytes for the stored hash *) let reveal_wrong_commit () = @@ -199,7 +199,7 @@ let reveal_wrong_commit () = "Your commitment did not match the storage hash." (* Test that the contract fails if we try to reuse it after unused flag changed *) -let reveal_no_reuse () = +let reveal_no_reuse () = let%bind program,_ = get_program () in let empty_message = empty_message in let reveal = e_record_ez [("hashable", e_bytes_string "hello"); diff --git a/src/test/time_lock_repeat_tests.ml b/src/test/time_lock_repeat_tests.ml index aa7b8b01b..4405948bf 100644 --- a/src/test/time_lock_repeat_tests.ml +++ b/src/test/time_lock_repeat_tests.ml @@ -17,7 +17,7 @@ let get_program = ok program ) -let compile_main () = +let compile_main () = let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/timelock_repeat.mligo" (Syntax_name "cameligo") in let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in @@ -63,7 +63,7 @@ let interval_advance () = let%bind predecessor_timestamp = mk_time "2000-01-01T10:10:10Z" in let%bind lock_time = mk_time "2000-01-01T00:10:10Z" in let init_storage = storage lock_time 86400 empty_message in - (* It takes a second for Current.now to be called, awful hack *) + (* It takes a second for Tezos.now to be called, awful hack *) let%bind new_timestamp = mk_time "2000-01-02T10:10:11Z" in let new_storage_fake = storage new_timestamp 86400 fake_uncompiled_empty_message in let options = diff --git a/src/test/vote_tests.ml b/src/test/vote_tests.ml index 6817b9d6d..3a0a95021 100644 --- a/src/test/vote_tests.ml +++ b/src/test/vote_tests.ml @@ -20,38 +20,33 @@ open Ast_simplified let init_storage name = e_record_ez [ ("title" , e_string name) ; - ("candidates" , e_map [ - (e_string "Yes" , e_int 0) ; - (e_string "No" , e_int 0) ; - ]) ; + ("yea", e_nat 0) ; + ("nay", e_nat 0) ; ("voters" , e_typed_set [] t_address) ; - ("beginning_time" , e_timestamp 0) ; + ("start_time" , e_timestamp 0) ; ("finish_time" , e_timestamp 1000000000) ; ] -let init title beginning_time finish_time = - let init_action = e_record_ez [ +let reset title start_time finish_time = + let reset_action = e_record_ez [ ("title" , e_string title) ; - ("beginning_time" , e_timestamp beginning_time) ; - ("finish_time" , e_timestamp finish_time) ; - ] in - e_constructor "Init" init_action + ("start_time" , e_timestamp start_time) ; + ("finish_time" , e_timestamp finish_time)] + in e_constructor "Reset" reset_action -let vote str = - let vote = e_string str in - e_constructor "Vote" vote +let yea = e_constructor "Vote" (e_constructor "Yea" (e_unit ())) let init_vote () = let%bind (program , _) = get_program () in - let%bind result = Test_helpers.run_typed_program_with_simplified_input program "main" (e_pair (vote "Yes") (init_storage "basic")) in - let%bind (_ , storage) = extract_pair result in + let%bind result = + Test_helpers.run_typed_program_with_simplified_input + program "main" (e_pair yea (init_storage "basic")) in + let%bind (_, storage) = extract_pair result in let%bind storage' = extract_record storage in - let votes = List.assoc (Label "candidates") storage' in - let%bind votes' = extract_map votes in - let%bind (_ , yess) = - trace_option (simple_error "") @@ - List.find_opt (fun (k , _) -> Ast_simplified.Misc.is_value_eq (k , e_string "Yes")) votes' in - let%bind () = Ast_simplified.Misc.assert_value_eq (yess , e_int 1) in +(* let votes = List.assoc (Label "voters") storage' in + let%bind votes' = extract_map votes in *) + let yea = List.assoc (Label "yea") storage' in + let%bind () = Ast_simplified.Misc.assert_value_eq (yea, e_nat 1) in ok () let main = test_suite "Vote" [ From e91661189b63aca41869aa645493e3c39f61e2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jev=20Bj=C3=B6rsell?= Date: Mon, 2 Mar 2020 16:57:29 -0800 Subject: [PATCH 20/53] Prevent IDE jobs running when the ide code has no changes --- .gitlab-ci.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b3deaa2d9..671998b46 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -224,9 +224,10 @@ run-webide-unit-tests: - cd tools/webide/packages/server - npm ci - npm run test - only: - changes: + rules: + - changes: - tools/webide/** + when: always build-publish-ide-image: stage: build_and_deploy @@ -246,7 +247,8 @@ build-publish-ide-image: . - docker push "${WEBIDE_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}" rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + - changes: + - tools/webide/** when: always - if: '$CI_COMMIT_REF_NAME == "dev"' when: always @@ -260,7 +262,8 @@ run-webide-e2e-tests: - export WEBIDE_IMAGE="${WEBIDE_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}" - docker-compose run e2e rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + - changes: + - tools/webide/** when: always - if: '$CI_COMMIT_REF_NAME == "dev"' when: always From 3260e87d67b51eaa15d5c9c2271694413c4111fe Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 27 Feb 2020 12:49:38 +0100 Subject: [PATCH 21/53] new constant : C_CREATE_CONTRACT --- src/stages/common/PP.ml | 1 + src/stages/common/types.ml | 1 + src/stages/mini_c/PP.ml | 1 + 3 files changed, 3 insertions(+) diff --git a/src/stages/common/PP.ml b/src/stages/common/PP.ml index a04d303a7..14cde83d5 100644 --- a/src/stages/common/PP.ml +++ b/src/stages/common/PP.ml @@ -146,6 +146,7 @@ let constant ppf : constant' -> unit = function | C_SELF_ADDRESS -> fprintf ppf "SELF_ADDRESS" | C_IMPLICIT_ACCOUNT -> fprintf ppf "IMPLICIT_ACCOUNT" | C_SET_DELEGATE -> fprintf ppf "SET_DELEGATE" + | C_CREATE_CONTRACT -> fprintf ppf "CREATE_CONTRACT" let literal ppf (l : literal) = match l with diff --git a/src/stages/common/types.ml b/src/stages/common/types.ml index e923bc924..d6b0839fd 100644 --- a/src/stages/common/types.ml +++ b/src/stages/common/types.ml @@ -288,3 +288,4 @@ and constant' = | C_SELF_ADDRESS | C_IMPLICIT_ACCOUNT | C_SET_DELEGATE + | C_CREATE_CONTRACT diff --git a/src/stages/mini_c/PP.ml b/src/stages/mini_c/PP.ml index 0fde6061c..46899c212 100644 --- a/src/stages/mini_c/PP.ml +++ b/src/stages/mini_c/PP.ml @@ -242,6 +242,7 @@ and constant ppf : constant' -> unit = function | C_SELF_ADDRESS -> fprintf ppf "SELF_ADDRESS" | C_IMPLICIT_ACCOUNT -> fprintf ppf "IMPLICIT_ACCOUNT" | C_SET_DELEGATE -> fprintf ppf "SET_DELEGATE" + | C_CREATE_CONTRACT -> fprintf ppf "CREATE_CONTRACT" let%expect_test _ = Format.printf "%a" value (D_bytes (Bytes.of_string "foo")) ; From 4e48026daa0747b09df8e5b4c4bca9247c82c0fb Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 27 Feb 2020 12:49:50 +0100 Subject: [PATCH 22/53] typer: typing C_CREATE_CONTRACT --- src/passes/operators/operators.ml | 26 ++++++++++++++------------ src/passes/operators/operators.mli | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 7cc7f556d..3537e1d89 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -88,6 +88,7 @@ module Simplify = struct | "source" -> ok C_SOURCE (* Deprecated *) | "Tezos.failwith" -> ok C_FAILWITH | "failwith" -> ok C_FAILWITH + | "Tezos.create_contract" -> ok C_CREATE_CONTRACT | "Tezos.transaction" -> ok C_CALL | "transaction" -> ok C_CALL (* Deprecated *) @@ -287,6 +288,7 @@ module Simplify = struct | "Operation.get_entrypoint" -> ok C_CONTRACT_ENTRYPOINT (* Deprecated *) | "Tezos.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT | "Operation.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT (* Deprecated *) + | "Tezos.create_contract" -> ok C_CREATE_CONTRACT | "Michelson.is_nat" -> ok C_IS_NAT (* Deprecated *) | "is_nat" -> ok C_IS_NAT @@ -800,18 +802,17 @@ module Typer = struct let%bind () = assert_type_expression_eq (param , contract_param) in ok @@ t_operation () - let originate = typer_6 "ORIGINATE" @@ fun manager delegate_opt spendable delegatable init_balance code -> - let%bind () = assert_eq_1 manager (t_key_hash ()) in - let%bind () = assert_eq_1 delegate_opt (t_option (t_key_hash ()) ()) in - let%bind () = assert_eq_1 spendable (t_bool ()) in - let%bind () = assert_eq_1 delegatable (t_bool ()) in - let%bind () = assert_t_mutez init_balance in - let%bind (arg , res) = get_t_function code in - let%bind (_param , storage) = get_t_pair arg in - let%bind (storage' , op_lst) = get_t_pair res in - let%bind () = assert_eq_1 storage storage' in - let%bind () = assert_eq_1 op_lst (t_list (t_operation ()) ()) in - ok @@ (t_pair (t_operation ()) (t_address ()) ()) + let create_contract = typer_4 "CREATE_CONTRACT" @@ fun f kh_opt amount init_storage -> + let%bind (args , ret) = get_t_function f in + let%bind (_,s) = get_t_pair args in + let%bind (oplist,s') = get_t_pair ret in + let%bind () = assert_t_mutez amount in + let%bind (delegate) = get_t_option kh_opt in + let%bind () = assert_type_expression_eq (s,s') in + let%bind () = assert_type_expression_eq (s,init_storage) in + let%bind () = assert_t_list_operation oplist in + let%bind () = assert_t_key_hash delegate in + ok @@ t_pair (t_operation ()) (t_address ()) () let get_contract = typer_1_opt "CONTRACT" @@ fun addr_tv tv_opt -> if not (type_expression_eq (addr_tv, t_address ())) @@ -1229,6 +1230,7 @@ module Typer = struct | C_SELF_ADDRESS -> ok @@ self_address; | C_IMPLICIT_ACCOUNT -> ok @@ implicit_account; | C_SET_DELEGATE -> ok @@ set_delegate ; + | C_CREATE_CONTRACT -> ok @@ create_contract ; | _ -> simple_fail @@ Format.asprintf "Typer not implemented for consant %a" PP.constant c diff --git a/src/passes/operators/operators.mli b/src/passes/operators/operators.mli index 2adb00b5b..77ce53196 100644 --- a/src/passes/operators/operators.mli +++ b/src/passes/operators/operators.mli @@ -140,7 +140,7 @@ module Typer : sig val now : typer val transaction : typer *) - val originate : typer + val create_contract : typer (* val get_contract : typer *) From ad7024c62b442f19a88ce6461f971aa7fb4502fe Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Fri, 28 Feb 2020 18:11:02 +0100 Subject: [PATCH 23/53] compiler: compile CREATE_CONTRACT --- src/passes/8-compiler/compiler_program.ml | 21 +++++++++++++++++++-- src/stages/mini_c/combinators.ml | 2 +- src/stages/mini_c/combinators.mli | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/passes/8-compiler/compiler_program.ml b/src/passes/8-compiler/compiler_program.ml index a93b58299..a4ffbd0e0 100644 --- a/src/passes/8-compiler/compiler_program.ml +++ b/src/passes/8-compiler/compiler_program.ml @@ -27,7 +27,7 @@ end open Errors (* This does not makes sense to me *) -let get_operator : constant' -> type_value -> expression list -> predicate result = fun s ty lst -> +let rec get_operator : constant' -> type_value -> expression list -> predicate result = fun s ty lst -> match Operators.Compiler.get_operators s with | Ok (x,_) -> ok x | Error _ -> ( @@ -114,10 +114,23 @@ let get_operator : constant' -> type_value -> expression list -> predicate resul i_drop ; (* drop the entrypoint... *) prim ~annot:[entry] ~children:[r_ty] I_CONTRACT ; ] + | C_CREATE_CONTRACT -> + let%bind ch = match lst with + | { content= E_closure {body;binder} ; type_value = T_function (T_pair ((_,p),(_,s)) as tin,_)} :: _ -> + let%bind closure = translate_function_body {body;binder} [] tin in + let%bind (p',s') = bind_map_pair Compiler_type.type_ (p,s) in + ok @@ contract p' s' closure + | _ -> fail @@ corner_case ~loc:__LOC__ "mini_c . CREATE_CONTRACT" + in + ok @@ simple_tetrary @@ seq [ + i_drop ; + prim ~children:[ch] I_CREATE_CONTRACT ; + i_pair ; + ] | x -> simple_fail (Format.asprintf "predicate \"%a\" doesn't exist" PP.constant x) ) -let rec translate_value (v:value) ty : michelson result = match v with +and translate_value (v:value) ty : michelson result = match v with | D_bool b -> ok @@ prim (if b then D_True else D_False) | D_int n -> ok @@ int (Z.of_int n) | D_nat n -> ok @@ int (Z.of_int n) @@ -249,6 +262,10 @@ and translate_expression (expr:expression) (env:environment) : michelson result pre_code ; f ; ] + | Tetrary f, 4 -> ok @@ seq [ + pre_code ; + f ; + ] | _ -> simple_fail (Format.asprintf "bad arity for %a" PP.constant str) in let error = diff --git a/src/stages/mini_c/combinators.ml b/src/stages/mini_c/combinators.ml index 2912aec93..019a111be 100644 --- a/src/stages/mini_c/combinators.ml +++ b/src/stages/mini_c/combinators.ml @@ -152,7 +152,7 @@ let get_t_contract t = match t with | _ -> fail @@ wrong_type "contract" t let get_t_operation t = match t with - | T_base TC_operation -> ok () + | T_base TC_operation -> ok t | _ -> fail @@ wrong_type "operation" t let get_operation (v:value) = match v with diff --git a/src/stages/mini_c/combinators.mli b/src/stages/mini_c/combinators.mli index 3f9b1552e..d61620589 100644 --- a/src/stages/mini_c/combinators.mli +++ b/src/stages/mini_c/combinators.mli @@ -49,7 +49,7 @@ val wrong_type : string -> type_value -> unit -> error val get_t_left : type_value -> type_value result val get_t_right : type_value -> type_value result val get_t_contract : type_value -> type_value result -val get_t_operation : type_value -> unit result +val get_t_operation : type_value -> type_value result val get_operation : value -> Memory_proto_alpha.Protocol.Alpha_context.packed_internal_operation result val t_int : type_value From ffd792e2f8248841f7a3bd6bdad10e89ab6cdbfe Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Fri, 28 Feb 2020 19:30:09 +0100 Subject: [PATCH 24/53] CREATE_CONTRACT: add a check in the typer to allow only closures --- src/passes/4-typer-old/typer.ml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/passes/4-typer-old/typer.ml b/src/passes/4-typer-old/typer.ml index 2d5d70a12..e966b5a52 100644 --- a/src/passes/4-typer-old/typer.ml +++ b/src/passes/4-typer-old/typer.ml @@ -154,6 +154,15 @@ module Errors = struct ] in error ~data title message () + let fvs_in_create_contract_lambda (e : I.expression) (case : Ast_typed.expression_variable) () = + let title = (thunk "No free variable allowed in this lambda") in + let message () = Format.asprintf "%a " Var.pp case in + let data = [ + ("expression" , fun () -> Format.asprintf "%a" I.PP.expression e) ; + ("location" , fun () -> Format.asprintf "%a" Location.pp e.location) + ] in + error ~data title message () + let type_error_approximate ?(msg="") ~(expected: string) ~(actual: O.type_expression) ~(expression : I.expression) (loc:Location.t) () = let title = (thunk "type error") in let message () = msg in @@ -696,6 +705,20 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let%bind (opname',tv) = type_constant opname tv_lst tv_opt in Format.printf "Typed constant : %a \n%!" O.PP.type_expression tv; return (E_constant {cons_name=opname';arguments=lst'}) tv + | E_constant {cons_name=C_CREATE_CONTRACT as cons_name;arguments} -> + let%bind lst' = bind_list @@ List.map (type_expression' e) arguments in + let%bind () = match lst' with + | { expression_content = O.E_lambda l ; _ } :: _ -> + let open Ast_typed.Misc in + let fvs = Free_variables.lambda [] l in + if List.length fvs = 0 then ok () + else fail @@ fvs_in_create_contract_lambda ae (List.hd fvs) + | _ -> ok () + in + let tv_lst = List.map get_type_expression lst' in + let%bind (name', tv) = + type_constant cons_name tv_lst tv_opt in + return (E_constant {cons_name=name';arguments=lst'}) tv | E_constant {cons_name;arguments} -> let%bind lst' = bind_list @@ List.map (type_expression' e) arguments in let tv_lst = List.map get_type_expression lst' in From 9a30eb67c1016ac6a11846e95e64b52c7ae50366 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Fri, 28 Feb 2020 19:49:51 +0100 Subject: [PATCH 25/53] create_contract: add some tests --- src/bin/expect_tests/contract_tests.ml | 49 ++++++++++++++++++- src/test/contracts/create_contract.mligo | 10 ++++ .../negative/create_contract_toplevel.mligo | 10 ++++ .../negative/create_contract_var.mligo | 12 +++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/test/contracts/create_contract.mligo create mode 100644 src/test/contracts/negative/create_contract_toplevel.mligo create mode 100644 src/test/contracts/negative/create_contract_var.mligo diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index facee666d..795e554ea 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -1144,4 +1144,51 @@ 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' |}] \ No newline at end of file + * Check the changelog by running 'ligo changelog' |}] + +let%expect_test _ = + run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ; + [%expect {| + ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: store {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * string ):Some(( nat * string ))) : None return let rhs#752 = #P in let p = rhs#752.0 in let s = rhs#752.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} + + + 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 "create_contract_var.mligo" ; "main" ] ; + [%expect {| + ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: a {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * int ):Some(( nat * int ))) : None return let rhs#755 = #P in let p = rhs#755.0 in let s = rhs#755.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} + + + 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_good [ "compile-contract" ; contract "create_contract.mligo" ; "main" ] ; + [%expect {| + { parameter string ; + storage string ; + code { PUSH string "un" ; + PUSH mutez 300000000 ; + NONE key_hash ; + CREATE_CONTRACT + { parameter nat ; + storage string ; + code { PUSH string "one" ; NIL operation ; PAIR ; DIP { DROP } } } ; + PAIR ; + DUP ; + CAR ; + NIL operation ; + SWAP ; + CONS ; + DIP { DIP { DUP } ; SWAP ; CDR } ; + PAIR ; + DIP { DROP 2 } } } |}] diff --git a/src/test/contracts/create_contract.mligo b/src/test/contracts/create_contract.mligo new file mode 100644 index 000000000..8c405102c --- /dev/null +++ b/src/test/contracts/create_contract.mligo @@ -0,0 +1,10 @@ +type return = operation list * string + +let main (action, store : string * string) : return = + let toto : operation * address = Tezos.create_contract + (fun (p, s : nat * string) -> (([] : operation list), "one")) + (None: key_hash option) + 300tz + "un" + in + ([toto.0], store) \ No newline at end of file diff --git a/src/test/contracts/negative/create_contract_toplevel.mligo b/src/test/contracts/negative/create_contract_toplevel.mligo new file mode 100644 index 000000000..051464c11 --- /dev/null +++ b/src/test/contracts/negative/create_contract_toplevel.mligo @@ -0,0 +1,10 @@ +type return = operation list * string + +let main (action, store : string * string) : return = + let toto : operation * address = Tezos.create_contract + (fun (p, s : nat * string) -> (([] : operation list), store)) + (None: key_hash option) + 300tz + "un" + in + ([toto.0], store) \ No newline at end of file diff --git a/src/test/contracts/negative/create_contract_var.mligo b/src/test/contracts/negative/create_contract_var.mligo new file mode 100644 index 000000000..9bd0a3ffb --- /dev/null +++ b/src/test/contracts/negative/create_contract_var.mligo @@ -0,0 +1,12 @@ +type return = operation list * string + +let a : int = 2 + +let main (action, store : string * string) : return = + let toto : operation * address = Tezos.create_contract + (fun (p, s : nat * int) -> (([] : operation list), a)) + (None: key_hash option) + 300tz + 1 + in + ([toto.0], store) \ No newline at end of file From 1e5abda3eed2c66f005457293c9924a4600ddd32 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Mon, 2 Mar 2020 12:53:03 +0100 Subject: [PATCH 26/53] create contract : conservative restrictions & errors in typer, before inlining/beta optimizations --- src/passes/4-typer-old/typer.ml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/passes/4-typer-old/typer.ml b/src/passes/4-typer-old/typer.ml index e966b5a52..1b220754f 100644 --- a/src/passes/4-typer-old/typer.ml +++ b/src/passes/4-typer-old/typer.ml @@ -154,9 +154,18 @@ module Errors = struct ] in error ~data title message () - let fvs_in_create_contract_lambda (e : I.expression) (case : Ast_typed.expression_variable) () = + let fvs_in_create_contract_lambda (e : I.expression) (fvar : Ast_typed.expression_variable) () = let title = (thunk "No free variable allowed in this lambda") in - let message () = Format.asprintf "%a " Var.pp case in + let message () = Format.asprintf "variable '%a'" Var.pp fvar in + let data = [ + ("expression" , fun () -> Format.asprintf "%a" I.PP.expression e) ; + ("location" , fun () -> Format.asprintf "%a" Location.pp e.location) + ] in + error ~data title message () + + let create_contract_lambda (cst : I.constant') (e : I.expression) () = + let title () = Format.asprintf "%a first argument must be inlined" I.PP.constant cst in + let message () = Format.asprintf "contract code can be inlined using a lambda" in let data = [ ("expression" , fun () -> Format.asprintf "%a" I.PP.expression e) ; ("location" , fun () -> Format.asprintf "%a" Location.pp e.location) @@ -713,7 +722,7 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let fvs = Free_variables.lambda [] l in if List.length fvs = 0 then ok () else fail @@ fvs_in_create_contract_lambda ae (List.hd fvs) - | _ -> ok () + | _ -> fail @@ create_contract_lambda C_CREATE_CONTRACT ae in let tv_lst = List.map get_type_expression lst' in let%bind (name', tv) = From cf383fe3274cc93b9bd44afb1e74f6449ccd92fa Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Mon, 2 Mar 2020 12:53:10 +0100 Subject: [PATCH 27/53] more tests --- src/bin/expect_tests/contract_tests.ml | 18 ++++++++++++++++-- .../negative/create_contract_no_inline.mligo | 11 +++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/test/contracts/negative/create_contract_no_inline.mligo diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 795e554ea..0706ceda8 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -1149,7 +1149,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: store {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * string ):Some(( nat * string ))) : None return let rhs#752 = #P in let p = rhs#752.0 in let s = rhs#752.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} + ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * string ):Some(( nat * string ))) : None return let rhs#752 = #P in let p = rhs#752.0 in let s = rhs#752.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} If you're not sure how to fix this error, you can @@ -1162,7 +1162,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_var.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: a {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * int ):Some(( nat * int ))) : None return let rhs#755 = #P in let p = rhs#755.0 in let s = rhs#755.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} + ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * int ):Some(( nat * int ))) : None return let rhs#755 = #P in let p = rhs#755.0 in let s = rhs#755.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} If you're not sure how to fix this error, you can @@ -1172,6 +1172,20 @@ let%expect_test _ = * 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 "create_contract_no_inline.mligo" ; "main" ] ; + [%expect {| + ligo: in file "create_contract_no_inline.mligo", line 9, characters 19-89. CREATE_CONTRACT first argument must be inlined: contract code can be inlined using a lambda {"expression":"CREATE_CONTRACT(dummy_contract , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_no_inline.mligo\", line 9, characters 19-89"} + + + 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_good [ "compile-contract" ; contract "create_contract.mligo" ; "main" ] ; [%expect {| { parameter string ; diff --git a/src/test/contracts/negative/create_contract_no_inline.mligo b/src/test/contracts/negative/create_contract_no_inline.mligo new file mode 100644 index 000000000..ba5a30cd0 --- /dev/null +++ b/src/test/contracts/negative/create_contract_no_inline.mligo @@ -0,0 +1,11 @@ +let foo : int = 42 + +let dummy_contract (p, s : nat * int) : return = + (([] : operation list), foo) + +type return = operation list * string + +let main (action, store : int * int) : return = + let (op, addr) = Tezos.create_contract dummy_contract ((None: key_hash option)) 300tz 1 in + let toto : operation list = [ op ] in + (toto, foo) From a4fece03d66e9b957c1049416763e023ad668e7b Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Mon, 2 Mar 2020 13:35:26 +0100 Subject: [PATCH 28/53] doc & changelog --- CHANGELOG.md | 4 ++ .../docs/language-basics/tezos-specific.md | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b40924f28..fe908e334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +## [Add crypto reference page to docs](https://gitlab.com/ligolang/ligo/-/merge_requests/459) +### Added +- support for `Tezos.create_contract` origination + ## [9164206ef1fcf3e577820442b5afbad92d03ffa4] - 2020-02-09 ### Changed - Mutation of variables inside lambdas passed to list_iter do not have effect anymore. Side-effects used to survive iterations of list_iter via a quirk in the Michelson list_iter. Now, either use a list_fold and explicitly pass through the updated variables (e.g. storage) to the next iteration, or use a `for` loop which automatically detects mutations within the loop body and lifts the affected variables to a record that is passed from iteration to iteration. diff --git a/gitlab-pages/docs/language-basics/tezos-specific.md b/gitlab-pages/docs/language-basics/tezos-specific.md index 9fed6760a..99b980f44 100644 --- a/gitlab-pages/docs/language-basics/tezos-specific.md +++ b/gitlab-pages/docs/language-basics/tezos-specific.md @@ -154,3 +154,42 @@ let current_addr : address = Tezos.self_address; ``` + +## Origination of a contract + +`Tezos.create_contract` allows you to originate a contract given its code, delegate (if any), initial balance and initial storage. +The return value is a pair of type `(operation * address)`. + +> ⚠️ Due to limitations in Michelson, `Tezos.create_contract` first argument +> must be inlined and must not contain references to free variables + + + + +```pascaligo group=e +const origination : operation * address = Tezos.create_contract ( + function (const p : nat; const s : string): list(operation) * string is ((nil : list(operation)), s), + (None : option(key_hash)), + 3tz, + "initial_storage") +``` + + +```cameligo group=e +let origination : operation * address = Tezos.create_contract + (fun (p, s : nat * string) -> (([] : operation list), s)) + (None: key_hash option) + 3tz + "initial_storage" +``` + + +```reasonligo group=e +let origination : (operation, address) = Tezos.create_contract ( + ((p, s) : (nat,string)) : (list(operation),string) => (([] : list(operation)), s), + None: option(key_hash), + 3tz, + "initial_storage") +``` + + From e27dfa1bcec670418ec53a679ec24a89d8aad83e Mon Sep 17 00:00:00 2001 From: Maksym Bykovskyy Date: Tue, 3 Mar 2020 22:41:16 +0000 Subject: [PATCH 29/53] Moved examples folder --- .gitlab-ci.yml | 9 +- .../cameligo/arithmetic-contract.ligo | 0 .../pascaligo/arithmetic-contract.ligo | 0 src/test/examples/pascaligo/fa-1.2.ligo | 164 ++++++++++++++++++ .../reasonligo/arithmetic-contract.ligo | 0 tools/webide/Dockerfile | 10 +- .../packages/client/package-examples.js | 19 +- .../client/src/components/examples.tsx | 45 ++--- 8 files changed, 206 insertions(+), 41 deletions(-) rename {tools/webide/packages/client => src/test}/examples/cameligo/arithmetic-contract.ligo (100%) rename {tools/webide/packages/client => src/test}/examples/pascaligo/arithmetic-contract.ligo (100%) create mode 100644 src/test/examples/pascaligo/fa-1.2.ligo rename {tools/webide/packages/client => src/test}/examples/reasonligo/arithmetic-contract.ligo (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b3deaa2d9..c94a01ddf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,8 +23,8 @@ dont-merge-to-master: only: - master -.build_binary: &build_binary - # To run in sequence and save CPU usage, use stage: build_and_package_binaries +.build_binary: + &build_binary # To run in sequence and save CPU usage, use stage: build_and_package_binaries stage: test script: - $build_binary_script "$target_os_family" "$target_os" "$target_os_version" @@ -71,8 +71,6 @@ dont-merge-to-master: # move internal odoc documentation to the website folder - mkdir -p build/ligo/ - mv ../../_build/default/_doc/_html/ build/ligo/odoc - - pwd # for debug - - ls build/ligo/ # for debug after_script: - cp -r gitlab-pages/website/build/ligo public artifacts: @@ -84,7 +82,6 @@ dont-merge-to-master: services: - docker:19.03.5-dind - .before_script: &before_script before_script: # Install dependencies @@ -236,6 +233,7 @@ build-publish-ide-image: - find dist/ - find dist/package/ -name '*ligo_*deb' - mv $(realpath dist/package/debian-10/*.deb) tools/webide/ligo_deb10.deb + - cp -r src/test/examples tools/webide/packages/client/examples - cd tools/webide - echo "${CI_BUILD_TOKEN}" | docker login -u gitlab-ci-token --password-stdin registry.gitlab.com - > @@ -243,6 +241,7 @@ build-publish-ide-image: -t "${WEBIDE_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}" --build-arg GIT_TAG="${CI_COMMIT_SHA}" --build-arg GIT_COMMIT="${CI_COMMIT_SHORT_SHA}" + --build-arg EXAMPLES_DIR_SRC=packages/client/examples . - docker push "${WEBIDE_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}" rules: diff --git a/tools/webide/packages/client/examples/cameligo/arithmetic-contract.ligo b/src/test/examples/cameligo/arithmetic-contract.ligo similarity index 100% rename from tools/webide/packages/client/examples/cameligo/arithmetic-contract.ligo rename to src/test/examples/cameligo/arithmetic-contract.ligo diff --git a/tools/webide/packages/client/examples/pascaligo/arithmetic-contract.ligo b/src/test/examples/pascaligo/arithmetic-contract.ligo similarity index 100% rename from tools/webide/packages/client/examples/pascaligo/arithmetic-contract.ligo rename to src/test/examples/pascaligo/arithmetic-contract.ligo diff --git a/src/test/examples/pascaligo/fa-1.2.ligo b/src/test/examples/pascaligo/fa-1.2.ligo new file mode 100644 index 000000000..62f8d7c98 --- /dev/null +++ b/src/test/examples/pascaligo/fa-1.2.ligo @@ -0,0 +1,164 @@ +(*_* + name: FA1.2 PascaLIGO implementation + language: pascaligo + compile: + entrypoint: main + dryRun: + entrypoint: main + parameters: "" + storage: "" + deploy: + entrypoint: main + storage: "" + evaluateValue: + entrypoint: "" + evaluateFunction: + entrypoint: "" + parameters: "" +*_*) +// This is an implimentation of the FA1.2 specification in PascaLIGO + +type amt is nat; + +type account is record + balance : amt; + allowances: map(address, amt); +end + +type action is +| Transfer of (address * address * amt) +| Approve of (address * amt) +| GetAllowance of (address * address * contract(amt)) +| GetBalance of (address * contract(amt)) +| GetTotalSupply of (unit * contract(amt)) + +type contract_storage is record + totalSupply: amt; + ledger: big_map(address, account); +end + +function isAllowed ( const src : address ; const value : amt ; var s : contract_storage) : bool is + begin + var allowed: bool := False; + if sender =/= source then block { + const src: account = get_force(src, s.ledger); + const allowanceAmount: amt = get_force(sender, src.allowances); + allowed := allowanceAmount >= value; + }; + else allowed := True; + end with allowed + +// Transfer a specific amount of tokens from the accountFrom address to a destination address +// Pre conditions: +// The sender address is the account owner or is allowed to spend x in the name of accountFrom +// The accountFrom account has a balance higher than amount +// Post conditions: +// The balance of accountFrom is decreased by amount +// The balance of destination is increased by amount +function transfer (const accountFrom : address ; const destination : address ; const value : amt ; var s : contract_storage) : contract_storage is + begin + // If accountFrom = destination transfer is not necessary + if accountFrom = destination then skip; + else block { + // Is sender allowed to spend value in the name of source + case isAllowed(accountFrom, value, s) of + | False -> failwith ("Sender not allowed to spend token from source") + | True -> skip + end; + + // Fetch src account + const src: account = get_force(accountFrom, s.ledger); + + // Check that the source can spend that much + if value > src.balance + then failwith ("Source balance is too low"); + else skip; + + // Update the source balance + // Using the abs function to convert int to nat + src.balance := abs(src.balance - value); + + s.ledger[accountFrom] := src; + + // Fetch dst account or add empty dst account to ledger + var dst: account := record + balance = 0n; + allowances = (map end : map(address, amt)); + end; + case s.ledger[destination] of + | None -> skip + | Some(n) -> dst := n + end; + + // Update the destination balance + dst.balance := dst.balance + value; + + // Decrease the allowance amount if necessary + if accountFrom =/= sender then block { + const allowanceAmount: amt = get_force(sender, src.allowances); + if allowanceAmount - value < 0 then failwith ("Allowance amount cannot be negative"); + else src.allowances[sender] := abs(allowanceAmount - value); + } else skip; + + s.ledger[destination] := dst; + } + end with s + +// Approve an amount to be spent by another address in the name of the sender +// Pre conditions: +// The spender account is not the sender account +// Post conditions: +// The allowance of spender in the name of sender is value +function approve (const spender : address ; const value : amt ; var s : contract_storage) : contract_storage is + begin + // If sender is the spender approving is not necessary + if sender = spender then skip; + else block { + const src: account = get_force(sender, s.ledger); + src.allowances[spender] := value; + s.ledger[sender] := src; // Not sure if this last step is necessary + } + end with s + +// View function that forwards the allowance amount of spender in the name of tokenOwner to a contract +// Pre conditions: +// None +// Post conditions: +// The state is unchanged +function getAllowance (const owner : address ; const spender : address ; const contr : contract(amt) ; var s : contract_storage) : list(operation) is + begin + const src: account = get_force(owner, s.ledger); + const destAllowance: amt = get_force(spender, src.allowances); + end with list [transaction(destAllowance, 0tz, contr)] + +// View function that forwards the balance of source to a contract +// Pre conditions: +// None +// Post conditions: +// The state is unchanged +function getBalance (const src : address ; const contr : contract(amt) ; var s : contract_storage) : list(operation) is + begin + const src: account = get_force(src, s.ledger); + end with list [transaction(src.balance, 0tz, contr)] + +// View function that forwards the totalSupply to a contract +// Pre conditions: +// None +// Post conditions: +// The state is unchanged +function getTotalSupply (const contr : contract(amt) ; var s : contract_storage) : list(operation) is + list [transaction(s.totalSupply, 0tz, contr)] + +function main (const p : action ; const s : contract_storage) : + (list(operation) * contract_storage) is + block { + // Reject any transaction that try to transfer token to this contract + if amount =/= 0tz then failwith ("This contract do not accept token"); + else skip; + } with case p of + | Transfer(n) -> ((nil : list(operation)), transfer(n.0, n.1, n.2, s)) + | Approve(n) -> ((nil : list(operation)), approve(n.0, n.1, s)) + | GetAllowance(n) -> (getAllowance(n.0, n.1, n.2, s), s) + | GetBalance(n) -> (getBalance(n.0, n.1, s), s) + | GetTotalSupply(n) -> (getTotalSupply(n.1, s), s) + end diff --git a/tools/webide/packages/client/examples/reasonligo/arithmetic-contract.ligo b/src/test/examples/reasonligo/arithmetic-contract.ligo similarity index 100% rename from tools/webide/packages/client/examples/reasonligo/arithmetic-contract.ligo rename to src/test/examples/reasonligo/arithmetic-contract.ligo diff --git a/tools/webide/Dockerfile b/tools/webide/Dockerfile index 4dfa9963a..cf259c68c 100644 --- a/tools/webide/Dockerfile +++ b/tools/webide/Dockerfile @@ -1,16 +1,20 @@ FROM node:12-alpine as builder +ARG EXAMPLES_DIR_SRC +ARG EXAMPLES_DIR_DEST=packages/client/examples + WORKDIR /app COPY package.json package.json COPY yarn.lock yarn.lock +COPY tsconfig.json tsconfig.json COPY packages/client packages/client COPY packages/server packages/server +COPY $EXAMPLES_DIR_SRC $EXAMPLES_DIR_DEST + +ENV EXAMPLES_DIR=/app/$EXAMPLES_DIR_DEST RUN yarn install - -COPY tsconfig.json tsconfig.json - RUN yarn workspaces run build FROM node:12-buster diff --git a/tools/webide/packages/client/package-examples.js b/tools/webide/packages/client/package-examples.js index 848721660..04146b7f4 100644 --- a/tools/webide/packages/client/package-examples.js +++ b/tools/webide/packages/client/package-examples.js @@ -98,20 +98,27 @@ async function main() { throw error; }); - const EXAMPLES_DEST_DIR = join(process.cwd(), 'build', 'static', 'examples'); - const EXAMPLES_DIR = join(process.cwd(), 'examples'); - const EXAMPLES_GLOB = '**/*.ligo'; - const EXAMPLES_LIST_FILE = 'list'; + const EXAMPLES_DIR = process.env['EXAMPLES_DIR'] || join(process.cwd(), '../../../../src/test/examples'); + // const EXAMPLES_GLOB = '**/*.ligo'; + // const files = await findFiles(EXAMPLES_GLOB, EXAMPLES_DIR); + + const CURATED_EXAMPLES = [ + 'cameligo/arithmetic-contract.ligo', + 'pascaligo/arithmetic-contract.ligo', + 'reasonligo/arithmetic-contract.ligo' + ]; + + const EXAMPLES_DEST_DIR = join(process.cwd(), 'build', 'static', 'examples'); fs.mkdirSync(EXAMPLES_DEST_DIR, { recursive: true }); - const files = await findFiles(EXAMPLES_GLOB, EXAMPLES_DIR); const examples = await processExamples( EXAMPLES_DIR, - files, + CURATED_EXAMPLES, EXAMPLES_DEST_DIR ); + const EXAMPLES_LIST_FILE = 'list'; await writeFile(join(EXAMPLES_DEST_DIR, EXAMPLES_LIST_FILE), examples); } diff --git a/tools/webide/packages/client/src/components/examples.tsx b/tools/webide/packages/client/src/components/examples.tsx index cecd2a4ee..9662b6618 100644 --- a/tools/webide/packages/client/src/components/examples.tsx +++ b/tools/webide/packages/client/src/components/examples.tsx @@ -7,34 +7,18 @@ import { ChangeDirtyAction, EditorState } from '../redux/editor'; import { ChangeSelectedAction, ExamplesState } from '../redux/examples'; import { getExample } from '../services/api'; -const bgColor = 'transparent'; -const borderSize = '5px'; -const verticalPadding = '0.6em'; - const Container = styled.div` flex: 0.5; display: flex; flex-direction: column; + min-width: 0; `; -const MenuItem = styled.div<{ selected?: boolean }>` - padding: ${verticalPadding} 0 ${verticalPadding} 1em; - height: 1em; +const Header = styled.div` + min-height: 2.5em; display: flex; align-items: center; - cursor: pointer; - background-color: ${props => - props.selected ? 'var(--blue_trans1)' : bgColor}; - border-left: ${`${borderSize} solid ${bgColor}`}; - border-left-color: ${props => (props.selected ? 'var(--blue)' : bgColor)}; - - :hover { - background-color: ${props => - props.selected ? 'var(--blue_trans1)' : 'var(--blue_trans2)'}; - border-left: ${`${borderSize} solid ${bgColor}`}; - border-left-color: ${props => - props.selected ? 'var(--blue)' : 'transparent'}; - } + font-weight: 600; `; const MenuContainer = styled.div` @@ -42,15 +26,22 @@ const MenuContainer = styled.div` flex-direction: column; overflow-y: auto; height: var(--content_height); - box-sizing: border-box; + font-size: 0.8em; `; -const Header = styled.div` - min-height: 2.5em; - padding: 0 10px; - display: flex; - align-items: center; - font-weight: 600; +const MenuItem = styled.span` + height: 1em; + padding: 0.6em; + cursor: pointer; + background-color: transparent; + + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + + :hover { + background-color: var(--blue_trans2); + } `; export const Examples = () => { From ac374ed2ba0f5ec5db3be86d7b72dc426c7a788f Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Tue, 3 Mar 2020 23:47:10 -0600 Subject: [PATCH 30/53] Remove debug printfs --- src/passes/4-typer-old/typer.ml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/passes/4-typer-old/typer.ml b/src/passes/4-typer-old/typer.ml index 1b220754f..2e13a76ab 100644 --- a/src/passes/4-typer-old/typer.ml +++ b/src/passes/4-typer-old/typer.ml @@ -698,21 +698,16 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression location = _ }) as _lambda ; init_record ; ]} -> - Format.printf "typing foldwhile \n %!"; let%bind v_initr = type_expression' e init_record in let tv_out = get_type_expression v_initr in let input_type = tv_out in let e' = Environment.add_ez_binder lname input_type e in - Format.printf "typing foldwhile %a\n %a\n %!" Ast_typed.PP.type_expression tv_out I.PP.expression result; let%bind body = type_expression' e' result in - Format.printf "typing foldwhile %a\n %!" O.PP.expression body; let output_type = body.type_expression in let lambda' = make_a_e (E_lambda {binder = lname ; result=body}) (t_function input_type output_type ()) e' in let lst' = [lambda';v_initr] in let tv_lst = List.map get_type_expression lst' in - Format.printf "Typing constant : %a \n%!" (Ast_typed.PP.list_sep_d Ast_typed.PP.type_expression) tv_lst; let%bind (opname',tv) = type_constant opname tv_lst tv_opt in - Format.printf "Typed constant : %a \n%!" O.PP.type_expression tv; return (E_constant {cons_name=opname';arguments=lst'}) tv | E_constant {cons_name=C_CREATE_CONTRACT as cons_name;arguments} -> let%bind lst' = bind_list @@ List.map (type_expression' e) arguments in From 5159f293f81d9189281b2f0cd6038a5523f65053 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Thu, 27 Feb 2020 01:36:56 +0100 Subject: [PATCH 31/53] Repare function annotation in let binding for Camligo and ReasonLigo and fix some contracts --- .../docs/language-basics/functions.md | 2 +- .../docs/language-basics/maps-records.md | 4 +-- gitlab-pages/docs/reference/map.md | 4 +-- src/passes/2-simplify/cameligo.ml | 30 +++++++++++++++---- src/test/contracts/failwith.mligo | 2 +- src/test/contracts/let_in_multi_bind.mligo | 2 +- src/test/contracts/map.mligo | 4 +-- .../contracts/negative/self_in_lambda.mligo | 4 +-- src/test/contracts/set_arithmetic.mligo | 2 +- 9 files changed, 37 insertions(+), 17 deletions(-) diff --git a/gitlab-pages/docs/language-basics/functions.md b/gitlab-pages/docs/language-basics/functions.md index b4c81beb1..9f55eec5c 100644 --- a/gitlab-pages/docs/language-basics/functions.md +++ b/gitlab-pages/docs/language-basics/functions.md @@ -133,7 +133,7 @@ returns an integer as well: ```cameligo group=b let add (a, b : int * int) : int = a + b // Uncurried let add_curry (a : int) (b : int) : int = add (a, b) // Curried -let increment (b : int) : int = add_curry 1 // Partial application +let increment (b : int) : int = add_curry 1 b // Partial application ``` You can run the `increment` function defined above using the LIGO diff --git a/gitlab-pages/docs/language-basics/maps-records.md b/gitlab-pages/docs/language-basics/maps-records.md index c9837fb26..fda74b822 100644 --- a/gitlab-pages/docs/language-basics/maps-records.md +++ b/gitlab-pages/docs/language-basics/maps-records.md @@ -697,7 +697,7 @@ function fold_op (const m : register) : int is ```cameligo group=maps -let fold_op (m : register) : register = +let fold_op (m : register) : int = let folded = fun (i,j : int * (address * move)) -> i + j.1.1 in Map.fold folded m 5 ``` @@ -705,7 +705,7 @@ let fold_op (m : register) : register = ```reasonligo group=maps -let fold_op = (m : register) : register => { +let fold_op = (m : register) : int => { let folded = ((i,j): (int, (address, move))) => i + j[1][1]; Map.fold (folded, m, 5); }; diff --git a/gitlab-pages/docs/reference/map.md b/gitlab-pages/docs/reference/map.md index df3ecbb31..529de3edf 100644 --- a/gitlab-pages/docs/reference/map.md +++ b/gitlab-pages/docs/reference/map.md @@ -341,14 +341,14 @@ function fold_op (const m : register) : int is ```cameligo group=maps -let fold_op (m : register) : register = +let fold_op (m : register) : int = let folded = fun (i,j : int * (address * move)) -> i + j.1.1 in Map.fold folded m 5 ``` ```reasonligo group=maps -let fold_op = (m : register) : register => { +let fold_op = (m : register) : int => { let folded = ((i,j): (int, (address, move))) => i + j[1][1]; Map.fold (folded, m, 5); }; diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index 1680caf96..d9f516ae8 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -156,6 +156,14 @@ let rec pattern_to_var : Raw.pattern -> _ = fun p -> | Raw.PWild r -> ok @@ ({ region = r ; value = "_" } : Raw.variable) | _ -> fail @@ wrong_pattern "single var" p +let rec tuple_pattern_to_vars : Raw.pattern -> _ = fun pattern -> + match pattern with + | Raw.PPar pp -> tuple_pattern_to_vars pp.value.inside + | Raw.PTuple pt -> bind_map_list pattern_to_var (npseq_to_list pt.value) + | Raw.PVar _ | Raw.PWild _-> bind_list [pattern_to_var pattern] + | other -> (fail @@ wrong_pattern "parenthetical, tuple, or variable" other) + + let rec pattern_to_typed_var : Raw.pattern -> _ = fun p -> match p with | Raw.PPar p -> pattern_to_typed_var p.value.inside @@ -180,11 +188,21 @@ let rec tuple_pattern_to_typed_vars : Raw.pattern -> _ = fun pattern -> | Raw.PVar _ -> bind_list [pattern_to_typed_var pattern] | other -> (fail @@ wrong_pattern "parenthetical, tuple, or variable" other) -let rec unpar_pattern : Raw.pattern -> Raw.pattern = function +let rec typed_pattern_to_typed_vars : Raw.pattern -> _ = fun pattern -> + match pattern with + | Raw.PPar pp -> typed_pattern_to_typed_vars pp.value.inside + | Raw.PTyped pt -> + let (p,t) = pt.value.pattern,pt.value.type_expr in + let%bind p = tuple_pattern_to_vars p in + let%bind t = simpl_type_expression t in + ok @@ (p,t) + | other -> (fail @@ wrong_pattern "parenthetical or type annotation" other) + +and unpar_pattern : Raw.pattern -> Raw.pattern = function | PPar p -> unpar_pattern p.value.inside | _ as p -> p -let rec simpl_type_expression : Raw.type_expr -> type_expression result = fun te -> +and simpl_type_expression : Raw.type_expr -> type_expression result = fun te -> trace (simple_info "simplifying this type expression...") @@ match te with TPar x -> simpl_type_expression x.value.inside @@ -793,10 +811,9 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result let%bind var = pattern_to_var hd in ok (var , tl) in + let%bind lhs_type' = bind_map_option (fun x -> simpl_type_expression (snd x)) lhs_type in match args with | [] -> - let%bind lhs_type' = - bind_map_option (fun (_,te) -> simpl_type_expression te) lhs_type in let%bind rhs' = simpl_expression let_rhs in ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , lhs_type' , inline, rhs'))] | param1::others -> @@ -809,7 +826,10 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result } in let rhs = Raw.EFun {region=Region.ghost ; value=fun_} in let%bind rhs' = simpl_expression rhs in - ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , None , inline, rhs'))] + let%bind ty = bind_map_list typed_pattern_to_typed_vars args in + let aux acc ty = Option.map (t_function (snd ty)) acc in + let func_type = List.fold_right' aux lhs_type' ty in + ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , func_type , inline, rhs'))] ) and simpl_cases : type a . (Raw.pattern * a) list -> (a, unit) matching_content result = diff --git a/src/test/contracts/failwith.mligo b/src/test/contracts/failwith.mligo index fbc5976bd..b2f7411da 100644 --- a/src/test/contracts/failwith.mligo +++ b/src/test/contracts/failwith.mligo @@ -1,4 +1,4 @@ type storage = unit -let main (p: unit) storage = +let main (p: unit) (s:storage) = if true then failwith "This contract always fails" else () diff --git a/src/test/contracts/let_in_multi_bind.mligo b/src/test/contracts/let_in_multi_bind.mligo index e61dc14a7..f6e11b035 100644 --- a/src/test/contracts/let_in_multi_bind.mligo +++ b/src/test/contracts/let_in_multi_bind.mligo @@ -1,5 +1,5 @@ let sum (p: int * int) : int = let i, result = p in i + result -let sum2 (p: string * string * string * string) : int = +let sum2 (p: string * string * string * string) : string = let a, b, c, d = p in a ^ b ^ c ^ d diff --git a/src/test/contracts/map.mligo b/src/test/contracts/map.mligo index 7b13f406c..5ad4246f7 100644 --- a/src/test/contracts/map.mligo +++ b/src/test/contracts/map.mligo @@ -42,8 +42,8 @@ let map_op (m : foobar) : foobar = let increment = fun (i: int * int) -> i.1 + 1 in Map.map increment m -let fold_op (m : foobar) : foobar = - let aggregate = fun (i: int * (int * int)) -> i.0 + i.1.0 + i.1.1 +let fold_op (m : foobar) : int = + let aggregate = fun (i,m: int * (int * int)) -> i + m.0 + m.1 in Map.fold aggregate m 10 let deep_op (m: foobar) : foobar = diff --git a/src/test/contracts/negative/self_in_lambda.mligo b/src/test/contracts/negative/self_in_lambda.mligo index 493047199..9595b752d 100644 --- a/src/test/contracts/negative/self_in_lambda.mligo +++ b/src/test/contracts/negative/self_in_lambda.mligo @@ -1,5 +1,5 @@ let foo (u: unit) : address = Current.self_address -let main (ps: unit * address): (operation list * address) = - ( ([] : operation list) , foo) \ No newline at end of file +let main (ps: unit * address): (operation list * (unit -> address)) = + ( ([] : operation list) , foo) diff --git a/src/test/contracts/set_arithmetic.mligo b/src/test/contracts/set_arithmetic.mligo index 2713905b3..0eff261f7 100644 --- a/src/test/contracts/set_arithmetic.mligo +++ b/src/test/contracts/set_arithmetic.mligo @@ -9,7 +9,7 @@ let add_op (s : string set) : string set = let remove_op (s : string set) : string set = Set.remove "foobar" s -let remove_deep (s : string set * nat) : string set * nat = +let remove_deep (s : string set * nat) : string set = Set.remove "foobar" s.0 (* From 6e35dadcc4e854584cf6388531e7b57b96934123 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Thu, 27 Feb 2020 12:04:53 +0100 Subject: [PATCH 32/53] fix self_in_lambda.mligo --- src/test/contracts/negative/self_in_lambda.mligo | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/contracts/negative/self_in_lambda.mligo b/src/test/contracts/negative/self_in_lambda.mligo index 9595b752d..982973973 100644 --- a/src/test/contracts/negative/self_in_lambda.mligo +++ b/src/test/contracts/negative/self_in_lambda.mligo @@ -1,5 +1,6 @@ let foo (u: unit) : address = Current.self_address -let main (ps: unit * address): (operation list * (unit -> address)) = - ( ([] : operation list) , foo) +let main (ps: unit * address): (operation list * address) = + let dummy = foo() in + ( ([] : operation list) , foo()) From 89f2b44e7d2b0971f3585b8866ea5e1515a2520a Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Thu, 27 Feb 2020 12:38:00 +0100 Subject: [PATCH 33/53] Works also when the function parameter are passed in the rhs Fix some religo contract --- src/passes/2-simplify/cameligo.ml | 24 +++++++++++++--------- src/test/contracts/balance_constant.religo | 2 +- src/test/contracts/counter.religo | 3 +-- src/test/contracts/lambda.religo | 2 +- src/test/contracts/lambda2.religo | 2 +- src/test/contracts/letin.religo | 4 ++-- src/test/contracts/list.religo | 2 +- src/test/contracts/match.religo | 4 ++-- src/test/contracts/match_bis.religo | 2 +- 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index d9f516ae8..222dee09f 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -812,10 +812,8 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result ok (var , tl) in let%bind lhs_type' = bind_map_option (fun x -> simpl_type_expression (snd x)) lhs_type in - match args with - | [] -> - let%bind rhs' = simpl_expression let_rhs in - ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , lhs_type' , inline, rhs'))] + let let_rhs = match args with + | [] -> let_rhs | param1::others -> let fun_ = { kwd_fun = Region.ghost; @@ -824,12 +822,18 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result arrow = Region.ghost; body = let_rhs } in - let rhs = Raw.EFun {region=Region.ghost ; value=fun_} in - let%bind rhs' = simpl_expression rhs in - let%bind ty = bind_map_list typed_pattern_to_typed_vars args in - let aux acc ty = Option.map (t_function (snd ty)) acc in - let func_type = List.fold_right' aux lhs_type' ty in - ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , func_type , inline, rhs'))] + Raw.EFun {region=Region.ghost ; value=fun_} + in + let f_args = (match let_rhs with + | Raw.EFun f -> nseq_to_list f.value.binders + | _ -> [] + ) + in + let%bind rhs' = simpl_expression let_rhs in + let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in + let aux acc ty = Option.map (t_function (snd ty)) acc in + let func_type = List.fold_right' aux lhs_type' ty in + ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , func_type , inline, rhs'))] ) and simpl_cases : type a . (Raw.pattern * a) list -> (a, unit) matching_content result = diff --git a/src/test/contracts/balance_constant.religo b/src/test/contracts/balance_constant.religo index efa80fc48..52373431f 100644 --- a/src/test/contracts/balance_constant.religo +++ b/src/test/contracts/balance_constant.religo @@ -12,6 +12,6 @@ generated. unrecognized constant: {"constant":"BALANCE","location":"generated"} type storage = tez; -let main2 = (p: unit, storage) => ([]: list(operation), balance); +let main2 = (p: unit, s: storage) => ([]: list(operation), balance); let main = (x: (unit, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/counter.religo b/src/test/contracts/counter.religo index 8ed3f201f..773c94deb 100644 --- a/src/test/contracts/counter.religo +++ b/src/test/contracts/counter.religo @@ -1,7 +1,6 @@ type storage = int; -let main2 = (p: int, storage): string => ([]: list(operation), p + storage); +let main2 = (p: int, s: storage): string => ([]: list(operation), p + s); let main = (x: (int, storage)) : string => main2(x[0],x[1]); - diff --git a/src/test/contracts/lambda.religo b/src/test/contracts/lambda.religo index 19d885228..6a997e826 100644 --- a/src/test/contracts/lambda.religo +++ b/src/test/contracts/lambda.religo @@ -5,6 +5,6 @@ type storage = unit; (fun x -> ()) () */ -let main2 = ((p: unit), storage) => (((xxx: unit)) => ())(); +let main2 = ((p: unit), s: storage) => (((xxx: unit)) => ())(); let main = (x: (unit, storage)) => main2(x[0], x[1]); diff --git a/src/test/contracts/lambda2.religo b/src/test/contracts/lambda2.religo index fd6a6bd27..4be943b06 100644 --- a/src/test/contracts/lambda2.religo +++ b/src/test/contracts/lambda2.religo @@ -4,7 +4,7 @@ type storage = unit; let main (p:unit) storage = (fun x -> ()) () */ -let main2 = (z: unit, storage) => +let main2 = (z: unit, s: storage) => ((f: (unit => unit)) => f())((z: unit) => unit); let main = (x: (unit, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/letin.religo b/src/test/contracts/letin.religo index b370c0a59..22b08bda9 100644 --- a/src/test/contracts/letin.religo +++ b/src/test/contracts/letin.religo @@ -1,9 +1,9 @@ type storage = (int, int); -let main2 = ((n : int), storage) => { +let main2 = ((n : int), s: storage) => { let x: (int, int) = { let x: int = 7; - (x + n, storage[0] + storage[1]); + (x + n, s[0] + s[1]); }; ([]: list(operation), x); }; diff --git a/src/test/contracts/list.religo b/src/test/contracts/list.religo index 9f9a2ec1c..5dc8f17d2 100644 --- a/src/test/contracts/list.religo +++ b/src/test/contracts/list.religo @@ -6,7 +6,7 @@ let x: list(int) = []; let y: list(int) = [3, 4, 5]; let z: list(int) = [2, ...y]; -let main2 = (p: param, storage) => { +let main2 = (p: param, storage : storage) => { let storage = switch (p) { | [] => storage diff --git a/src/test/contracts/match.religo b/src/test/contracts/match.religo index 3f77b252d..361443089 100644 --- a/src/test/contracts/match.religo +++ b/src/test/contracts/match.religo @@ -4,9 +4,9 @@ type param = | Add(int) | Sub(int); -let main2 = ((p: param), storage) => { +let main2 = ((p: param), s: storage) => { let storage = - storage + s + ( switch (p) { | Add(n) => n diff --git a/src/test/contracts/match_bis.religo b/src/test/contracts/match_bis.religo index d1465d77b..ece959639 100644 --- a/src/test/contracts/match_bis.religo +++ b/src/test/contracts/match_bis.religo @@ -12,7 +12,7 @@ let subtract = ((a: int), (b: int)) => a - b; /* real entrypoint that re-routes the flow based on the action provided */ -let main2 = ((p: action), storage) => { +let main2 = ((p: action), storage : storage) => { let storage = switch (p) { | Increment(n) => add(storage, n) From 32d3bb5a0f6e3a6e8fa79b1201cf92c63ae00919 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Mon, 2 Mar 2020 18:20:15 +0100 Subject: [PATCH 34/53] fixing doc or fonction (partial application) --- gitlab-pages/docs/language-basics/functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-pages/docs/language-basics/functions.md b/gitlab-pages/docs/language-basics/functions.md index 9f55eec5c..bab722159 100644 --- a/gitlab-pages/docs/language-basics/functions.md +++ b/gitlab-pages/docs/language-basics/functions.md @@ -133,7 +133,7 @@ returns an integer as well: ```cameligo group=b let add (a, b : int * int) : int = a + b // Uncurried let add_curry (a : int) (b : int) : int = add (a, b) // Curried -let increment (b : int) : int = add_curry 1 b // Partial application +let increment : int -> int = add_curry 1 // Partial application ``` You can run the `increment` function defined above using the LIGO From a19e2ceb3bd6e8770c2e3df01cf27d23d7b24c42 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Tue, 3 Mar 2020 14:39:00 +0100 Subject: [PATCH 35/53] adding negative test --- src/bin/expect_tests/typer_error_tests.ml | 15 ++++++++++++++- .../negative/error_function_annotation.mligo | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/test/contracts/negative/error_function_annotation.mligo diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index 4aa7b95e8..32eb559d7 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -1,6 +1,19 @@ open Cli_expect let%expect_test _ = + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation.mligo"; "main"]; + [%expect {| + ligo: in file "", line 0, characters 0-0. different type constructors: Expected these two constant type constructors to be the same, but they're different {"a":"unit","b":"int"} + + + 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" ; "../../test/contracts/negative/error_type.ligo" ; "main" ] ; [%expect {| ligo: in file "error_type.ligo", line 3, characters 18-28. Adding modulo with wrong types: Expected arguments with one of the following combinations of types: add(nat , nat) or add(int , int) or add(mutez , mutez) or add(nat , int) or add(int , nat) or add(timestamp , int) or add(int , timestamp) but got this combination instead: add(int , string) @@ -135,4 +148,4 @@ 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' |}]; \ No newline at end of file + * Check the changelog by running 'ligo changelog' |}]; diff --git a/src/test/contracts/negative/error_function_annotation.mligo b/src/test/contracts/negative/error_function_annotation.mligo new file mode 100644 index 000000000..3360a7b1a --- /dev/null +++ b/src/test/contracts/negative/error_function_annotation.mligo @@ -0,0 +1 @@ +let main (a:int) : unit = a From 4f13a33d46b2b18a409debab89e76f72de9a533b Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Tue, 3 Mar 2020 16:17:07 +0100 Subject: [PATCH 36/53] fix bug with wrong annotation at the beginning --- src/passes/2-simplify/cameligo.ml | 19 +++++++------------ test.mligo | 3 +++ 2 files changed, 10 insertions(+), 12 deletions(-) create mode 100644 test.mligo diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index 222dee09f..910da246f 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -812,8 +812,8 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result ok (var , tl) in let%bind lhs_type' = bind_map_option (fun x -> simpl_type_expression (snd x)) lhs_type in - let let_rhs = match args with - | [] -> let_rhs + let%bind let_rhs,lhs_type = match args with + | [] -> ok (let_rhs, lhs_type') | param1::others -> let fun_ = { kwd_fun = Region.ghost; @@ -822,18 +822,13 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result arrow = Region.ghost; body = let_rhs } in - Raw.EFun {region=Region.ghost ; value=fun_} - in - let f_args = (match let_rhs with - | Raw.EFun f -> nseq_to_list f.value.binders - | _ -> [] - ) + let f_args = nseq_to_list (param1,others) in + let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in + let aux acc ty = Option.map (t_function (snd ty)) acc in + ok (Raw.EFun {region=Region.ghost ; value=fun_},List.fold_right' aux lhs_type' ty) in let%bind rhs' = simpl_expression let_rhs in - let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in - let aux acc ty = Option.map (t_function (snd ty)) acc in - let func_type = List.fold_right' aux lhs_type' ty in - ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , func_type , inline, rhs'))] + ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , lhs_type , inline, rhs'))] ) and simpl_cases : type a . (Raw.pattern * a) list -> (a, unit) matching_content result = diff --git a/test.mligo b/test.mligo new file mode 100644 index 000000000..5ad65e3f3 --- /dev/null +++ b/test.mligo @@ -0,0 +1,3 @@ +let f : int = fun (x, y : int*int) -> x + y +let g (x, y : int * int) : int = f (x, y) + From dfb1e1ebef90154ec88acd08d1b1ac1458374e42 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Tue, 3 Mar 2020 16:37:46 +0100 Subject: [PATCH 37/53] add negative test --- src/bin/expect_tests/typer_error_tests.ml | 15 ++++++++++++++- ...on.mligo => error_function_annotation_1.mligo} | 0 .../negative/error_function_annotation_2.mligo | 1 - 3 files changed, 14 insertions(+), 2 deletions(-) rename src/test/contracts/negative/{error_function_annotation.mligo => error_function_annotation_1.mligo} (100%) rename test.mligo => src/test/contracts/negative/error_function_annotation_2.mligo (98%) diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index 32eb559d7..a9b5ce6f2 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -1,11 +1,24 @@ open Cli_expect let%expect_test _ = - run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation.mligo"; "main"]; + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_1.mligo"; "main"]; [%expect {| ligo: in file "", line 0, characters 0-0. different type constructors: Expected these two constant type constructors to be the same, but they're different {"a":"unit","b":"int"} + 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" ; "../../test/contracts/negative/error_function_annotation_2.mligo"; "f"]; + [%expect {| + ligo: in file "error_function_annotation_2.mligo", line 1, characters 14-43. different kinds: {"a":"int","b":"( int * int ) -> int"} + + If you're not sure how to fix this error, you can do one of the following: diff --git a/src/test/contracts/negative/error_function_annotation.mligo b/src/test/contracts/negative/error_function_annotation_1.mligo similarity index 100% rename from src/test/contracts/negative/error_function_annotation.mligo rename to src/test/contracts/negative/error_function_annotation_1.mligo diff --git a/test.mligo b/src/test/contracts/negative/error_function_annotation_2.mligo similarity index 98% rename from test.mligo rename to src/test/contracts/negative/error_function_annotation_2.mligo index 5ad65e3f3..a65a8d47e 100644 --- a/test.mligo +++ b/src/test/contracts/negative/error_function_annotation_2.mligo @@ -1,3 +1,2 @@ let f : int = fun (x, y : int*int) -> x + y let g (x, y : int * int) : int = f (x, y) - From c23827e8de9c3405111c7460e5d38f7119401cc0 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Tue, 3 Mar 2020 17:45:59 +0100 Subject: [PATCH 38/53] new negative test --- src/bin/expect_tests/typer_error_tests.ml | 13 +++++++++++++ .../negative/error_function_annotation_3.mligo | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/contracts/negative/error_function_annotation_3.mligo diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index a9b5ce6f2..48d53bcbd 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -19,6 +19,19 @@ let%expect_test _ = ligo: in file "error_function_annotation_2.mligo", line 1, characters 14-43. different kinds: {"a":"int","b":"( int * int ) -> int"} + 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" ; "../../test/contracts/negative/error_function_annotation_3.mligo"; "f"]; + [%expect {| + ligo: in file "", line 0, characters 0-0. different kinds: {"a":"( (TO_list(operation)) * sum[Add -> int , Sub -> int] )","b":"sum[Add -> int , Sub -> int]"} + + If you're not sure how to fix this error, you can do one of the following: diff --git a/src/test/contracts/negative/error_function_annotation_3.mligo b/src/test/contracts/negative/error_function_annotation_3.mligo new file mode 100644 index 000000000..28d1e0e42 --- /dev/null +++ b/src/test/contracts/negative/error_function_annotation_3.mligo @@ -0,0 +1,9 @@ +type op = + | Add of int + | Sub of int + + +let main (p,s : int * op) : (operation list) * op = + match s with + | Add si -> Add si + | Sub si -> Sub si From b7e65764ddb99289e1ab07ac160f7f4cd6715b13 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Wed, 4 Mar 2020 00:10:52 +0100 Subject: [PATCH 39/53] dune promote --- src/bin/expect_tests/contract_tests.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 0706ceda8..1e7b64778 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -1149,7 +1149,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * string ):Some(( nat * string ))) : None return let rhs#752 = #P in let p = rhs#752.0 in let s = rhs#752.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} + ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * string ):Some(( nat * string ))) : None return let rhs#756 = #P in let p = rhs#756.0 in let s = rhs#756.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} If you're not sure how to fix this error, you can @@ -1162,7 +1162,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_var.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * int ):Some(( nat * int ))) : None return let rhs#755 = #P in let p = rhs#755.0 in let s = rhs#755.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} + ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * int ):Some(( nat * int ))) : None return let rhs#759 = #P in let p = rhs#759.0 in let s = rhs#759.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} If you're not sure how to fix this error, you can @@ -1175,7 +1175,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_no_inline.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_no_inline.mligo", line 9, characters 19-89. CREATE_CONTRACT first argument must be inlined: contract code can be inlined using a lambda {"expression":"CREATE_CONTRACT(dummy_contract , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_no_inline.mligo\", line 9, characters 19-89"} + ligo: unbound type variable: {"variable":"return","in":"- E[foo -> int]\tT[] ]","did_you_mean":"no suggestion"} If you're not sure how to fix this error, you can From 8f60accc24e3cebc45a7ea871d0ed82fa3f2f6b5 Mon Sep 17 00:00:00 2001 From: Sander Date: Wed, 4 Mar 2020 13:19:00 +0000 Subject: [PATCH 40/53] - Improve darkmode support - Reenable code block tabs - Reeneble code blocks highlighting --- gitlab-pages/Dockerfile | 2 +- gitlab-pages/docker-compose.yml | 15 +- .../docs/advanced/entrypoints-contracts.md | 100 ++++-- gitlab-pages/docs/advanced/first-contract.md | 54 ++- gitlab-pages/docs/advanced/include.md | 34 +- .../docs/advanced/timestamps-addresses.md | 118 +++++-- gitlab-pages/docs/api/cheat-sheet.md | 20 +- gitlab-pages/docs/intro/what-and-why.md | 19 +- .../docs/language-basics/boolean-if-else.md | 92 ++++-- .../docs/language-basics/functions.md | 47 ++- gitlab-pages/docs/language-basics/loops.md | 19 +- .../docs/language-basics/maps-records.md | 307 ++++++++++++------ .../docs/language-basics/math-numbers-tez.md | 115 +++++-- .../docs/language-basics/sets-lists-tuples.md | 199 ++++++++---- gitlab-pages/docs/language-basics/strings.md | 73 +++-- .../docs/language-basics/tezos-specific.md | 79 +++-- gitlab-pages/docs/language-basics/types.md | 64 ++-- .../unit-option-pattern-matching.md | 81 +++-- .../variables-and-constants.md | 34 +- gitlab-pages/docs/reference/big_map.md | 103 ++++-- gitlab-pages/docs/reference/bytes.md | 59 ++-- gitlab-pages/docs/reference/crypto.md | 76 +++-- gitlab-pages/docs/reference/current.md | 179 ++++++---- gitlab-pages/docs/reference/list.md | 90 +++-- gitlab-pages/docs/reference/map.md | 162 ++++++--- gitlab-pages/docs/reference/set.md | 122 +++++-- gitlab-pages/docs/reference/string.md | 53 ++- .../get-started/tezos-taco-shop-payout.md | 6 +- .../tezos-taco-shop-smart-contract.md | 25 +- gitlab-pages/website/.gitignore | 20 ++ ...> 2019-06-13-public-launch-of-ligo.md.old} | 0 ...pdate.md => 2019-07-11-ligo-update.md.old} | 0 gitlab-pages/website/core/CodeExamples.js | 131 +++++--- gitlab-pages/website/core/Footer.js | 2 + gitlab-pages/website/docusaurus.config.js | 226 +++++++++++++ gitlab-pages/website/package.json | 29 +- gitlab-pages/website/pages/en/index.js | 100 ------ gitlab-pages/website/pages/en/versions.js | 113 ------- gitlab-pages/website/siteConfig.js | 158 --------- .../en/404.js => src/pages/404.js.fixme} | 0 .../{pages/en => src/pages}/contact.js | 46 ++- gitlab-pages/website/src/pages/index.js | 184 +++++++++++ .../website/src/pages/versions.js.fixme | 113 +++++++ .../website/src/theme/CodeBlock/index.js | 194 +++++++++++ .../src/theme/CodeBlock/styles.module.css | 45 +++ .../website/src/theme/DocPage/index.js | 77 +++++ .../src/theme/DocPage/styles.module.css | 28 ++ .../website/src/theme/DocSidebar/index.js | 229 +++++++++++++ .../src/theme/DocSidebar/styles.module.css | 90 +++++ .../website/src/theme/Navbar/index.js | 201 ++++++++++++ .../src/theme/Navbar/styles.module.css | 26 ++ .../website/src/theme/Syntax/SyntaxContext.js | 6 + .../website/src/theme/Syntax/SyntaxSwitch.js | 15 + .../website/src/theme/Syntax/index.js | 18 + .../src/theme/Syntax/styles.module.css | 37 +++ gitlab-pages/website/static/css/custom.css | 107 ++++-- .../website/static/fonts/Inter-Black.woff | Bin 0 -> 140036 bytes .../website/static/fonts/Inter-Black.woff2 | Bin 0 -> 104524 bytes .../static/fonts/Inter-BlackItalic.woff | Bin 0 -> 145924 bytes .../static/fonts/Inter-BlackItalic.woff2 | Bin 0 -> 109900 bytes .../website/static/fonts/Inter-Bold.woff | Bin 0 -> 143708 bytes .../website/static/fonts/Inter-Bold.woff2 | Bin 0 -> 107400 bytes .../static/fonts/Inter-BoldItalic.woff | Bin 0 -> 149420 bytes .../static/fonts/Inter-BoldItalic.woff2 | Bin 0 -> 112580 bytes .../website/static/fonts/Inter-ExtraBold.woff | Bin 0 -> 143552 bytes .../static/fonts/Inter-ExtraBold.woff2 | Bin 0 -> 107552 bytes .../static/fonts/Inter-ExtraBoldItalic.woff | Bin 0 -> 149196 bytes .../static/fonts/Inter-ExtraBoldItalic.woff2 | Bin 0 -> 112876 bytes .../static/fonts/Inter-ExtraLight.woff | Bin 0 -> 141864 bytes .../static/fonts/Inter-ExtraLight.woff2 | Bin 0 -> 105960 bytes .../static/fonts/Inter-ExtraLightItalic.woff | Bin 0 -> 148688 bytes .../static/fonts/Inter-ExtraLightItalic.woff2 | Bin 0 -> 112056 bytes .../website/static/fonts/Inter-Italic.woff | Bin 0 -> 142744 bytes .../website/static/fonts/Inter-Italic.woff2 | Bin 0 -> 107508 bytes .../website/static/fonts/Inter-Light.woff | Bin 0 -> 141528 bytes .../website/static/fonts/Inter-Light.woff2 | Bin 0 -> 105640 bytes .../static/fonts/Inter-LightItalic.woff | Bin 0 -> 148436 bytes .../static/fonts/Inter-LightItalic.woff2 | Bin 0 -> 111968 bytes .../website/static/fonts/Inter-Medium.woff | Bin 0 -> 142836 bytes .../website/static/fonts/Inter-Medium.woff2 | Bin 0 -> 106720 bytes .../static/fonts/Inter-MediumItalic.woff | Bin 0 -> 149184 bytes .../static/fonts/Inter-MediumItalic.woff2 | Bin 0 -> 112504 bytes .../website/static/fonts/Inter-Regular.woff | Bin 0 -> 134652 bytes .../website/static/fonts/Inter-Regular.woff2 | Bin 0 -> 100124 bytes .../website/static/fonts/Inter-SemiBold.woff | Bin 0 -> 143248 bytes .../website/static/fonts/Inter-SemiBold.woff2 | Bin 0 -> 107232 bytes .../static/fonts/Inter-SemiBoldItalic.woff | Bin 0 -> 149276 bytes .../static/fonts/Inter-SemiBoldItalic.woff2 | Bin 0 -> 112552 bytes .../website/static/fonts/Inter-Thin.woff | Bin 0 -> 136952 bytes .../website/static/fonts/Inter-Thin.woff2 | Bin 0 -> 101408 bytes .../static/fonts/Inter-ThinItalic.woff | Bin 0 -> 144412 bytes .../static/fonts/Inter-ThinItalic.woff2 | Bin 0 -> 107496 bytes .../static/fonts/Inter-italic.var.woff2 | Bin 0 -> 240688 bytes .../static/fonts/Inter-roman.var.woff2 | Bin 0 -> 226368 bytes gitlab-pages/website/static/fonts/inter.css | 16 + gitlab-pages/website/static/img/circle.svg | 27 ++ .../website/static/img/logo-night.svg | 31 ++ gitlab-pages/website/static/img/logo-old.svg | 52 +++ gitlab-pages/website/static/img/logo.svg | 90 +++-- .../version-next/api-cli-commands.md | 48 --- .../contributors/big-picture/back-end.md | 19 -- .../contributors/big-picture/front-end.md | 16 - .../contributors/big-picture/middle-end.md | 17 - .../contributors/big-picture/overview.md | 17 - .../contributors/big-picture/vendors.md | 22 -- .../version-next/contributors/origin.md | 11 - .../version-next/contributors/philosophy.md | 45 --- .../contributors/road-map/long-term.md | 21 -- .../contributors/road-map/short-term.md | 21 -- .../version-next-sidebars.json | 65 ---- .../website/{versions.json => versions._} | 0 111 files changed, 3482 insertions(+), 1578 deletions(-) create mode 100644 gitlab-pages/website/.gitignore rename gitlab-pages/website/blog/{2019-06-13-public-launch-of-ligo.md => 2019-06-13-public-launch-of-ligo.md.old} (100%) rename gitlab-pages/website/blog/{2019-07-11-ligo-update.md => 2019-07-11-ligo-update.md.old} (100%) create mode 100644 gitlab-pages/website/docusaurus.config.js delete mode 100644 gitlab-pages/website/pages/en/index.js delete mode 100644 gitlab-pages/website/pages/en/versions.js delete mode 100644 gitlab-pages/website/siteConfig.js rename gitlab-pages/website/{pages/en/404.js => src/pages/404.js.fixme} (100%) rename gitlab-pages/website/{pages/en => src/pages}/contact.js (73%) create mode 100644 gitlab-pages/website/src/pages/index.js create mode 100644 gitlab-pages/website/src/pages/versions.js.fixme create mode 100644 gitlab-pages/website/src/theme/CodeBlock/index.js create mode 100644 gitlab-pages/website/src/theme/CodeBlock/styles.module.css create mode 100644 gitlab-pages/website/src/theme/DocPage/index.js create mode 100644 gitlab-pages/website/src/theme/DocPage/styles.module.css create mode 100644 gitlab-pages/website/src/theme/DocSidebar/index.js create mode 100644 gitlab-pages/website/src/theme/DocSidebar/styles.module.css create mode 100644 gitlab-pages/website/src/theme/Navbar/index.js create mode 100644 gitlab-pages/website/src/theme/Navbar/styles.module.css create mode 100644 gitlab-pages/website/src/theme/Syntax/SyntaxContext.js create mode 100644 gitlab-pages/website/src/theme/Syntax/SyntaxSwitch.js create mode 100644 gitlab-pages/website/src/theme/Syntax/index.js create mode 100644 gitlab-pages/website/src/theme/Syntax/styles.module.css create mode 100644 gitlab-pages/website/static/fonts/Inter-Black.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-Black.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-BlackItalic.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-BlackItalic.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-Bold.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-Bold.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-BoldItalic.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-BoldItalic.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-ExtraBold.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-ExtraBold.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-ExtraBoldItalic.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-ExtraBoldItalic.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-ExtraLight.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-ExtraLight.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-ExtraLightItalic.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-ExtraLightItalic.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-Italic.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-Italic.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-Light.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-Light.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-LightItalic.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-LightItalic.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-Medium.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-Medium.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-MediumItalic.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-MediumItalic.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-Regular.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-Regular.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-SemiBold.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-SemiBold.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-SemiBoldItalic.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-SemiBoldItalic.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-Thin.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-Thin.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-ThinItalic.woff create mode 100644 gitlab-pages/website/static/fonts/Inter-ThinItalic.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-italic.var.woff2 create mode 100644 gitlab-pages/website/static/fonts/Inter-roman.var.woff2 create mode 100644 gitlab-pages/website/static/fonts/inter.css create mode 100644 gitlab-pages/website/static/img/circle.svg create mode 100644 gitlab-pages/website/static/img/logo-night.svg create mode 100644 gitlab-pages/website/static/img/logo-old.svg delete mode 100644 gitlab-pages/website/versioned_docs/version-next/api-cli-commands.md delete mode 100644 gitlab-pages/website/versioned_docs/version-next/contributors/big-picture/back-end.md delete mode 100644 gitlab-pages/website/versioned_docs/version-next/contributors/big-picture/front-end.md delete mode 100644 gitlab-pages/website/versioned_docs/version-next/contributors/big-picture/middle-end.md delete mode 100644 gitlab-pages/website/versioned_docs/version-next/contributors/big-picture/overview.md delete mode 100644 gitlab-pages/website/versioned_docs/version-next/contributors/big-picture/vendors.md delete mode 100644 gitlab-pages/website/versioned_docs/version-next/contributors/origin.md delete mode 100644 gitlab-pages/website/versioned_docs/version-next/contributors/philosophy.md delete mode 100644 gitlab-pages/website/versioned_docs/version-next/contributors/road-map/long-term.md delete mode 100644 gitlab-pages/website/versioned_docs/version-next/contributors/road-map/short-term.md delete mode 100644 gitlab-pages/website/versioned_sidebars/version-next-sidebars.json rename gitlab-pages/website/{versions.json => versions._} (100%) diff --git a/gitlab-pages/Dockerfile b/gitlab-pages/Dockerfile index d369844d5..93c4179f2 100644 --- a/gitlab-pages/Dockerfile +++ b/gitlab-pages/Dockerfile @@ -1,4 +1,4 @@ -FROM node:8.11.4 +FROM node:12.16 WORKDIR /app/website diff --git a/gitlab-pages/docker-compose.yml b/gitlab-pages/docker-compose.yml index 90c32ea95..af12b7af7 100644 --- a/gitlab-pages/docker-compose.yml +++ b/gitlab-pages/docker-compose.yml @@ -8,15 +8,16 @@ services: - 35729:35729 volumes: - ./docs:/app/docs - - ./website/blog:/app/website/blog + # - ./website/blog:/app/website/blog - ./website/core:/app/website/core - - ./website/i18n:/app/website/i18n - - ./website/pages:/app/website/pages + # - ./website/i18n:/app/website/i18n + - ./website/src:/app/website/src - ./website/static:/app/website/static - - ./website/versioned_sidebars:/app/website/versioned_sidebars - - ./website/versioned_docs:/app/website/versioned_docs + # - ./website/versioned_sidebars:/app/website/versioned_sidebars + # - ./website/versioned_docs:/app/website/versioned_docs - ./website/sidebars.json:/app/website/sidebars.json - - ./website/siteConfig.js:/app/website/siteConfig.js + - ./website/docusaurus.config.js:/app/website/docusaurus.config.js - ./website/versions.json:/app/website/versions.json - - ./website/node_modules/reason-highlightjs:/app/website/node_modules/reason-highlightjs + # - ./website/core/AlgoliaSearch.js:/app/website/core/AlgoliaSearch.js + working_dir: /app/website diff --git a/gitlab-pages/docs/advanced/entrypoints-contracts.md b/gitlab-pages/docs/advanced/entrypoints-contracts.md index 429962a33..499d07c58 100644 --- a/gitlab-pages/docs/advanced/entrypoints-contracts.md +++ b/gitlab-pages/docs/advanced/entrypoints-contracts.md @@ -3,6 +3,8 @@ id: entrypoints-contracts title: Main function and Entrypoints --- +import Syntax from '@theme/Syntax'; + ## Access Functions A LIGO contract is made of a series of constant and function @@ -22,25 +24,33 @@ type of a main function is as follows, assuming that the type `storage` has been defined elsewhere. (Note that you can use any type with any name for the storage.) - - + + + ```pascaligo skip type storage is ... // Any name, any type type return is list (operation) * storage ``` - + + + ```cameligo skip type storage = ... // Any name, any type type return = operation list * storage ``` - + + + ```reasonligo skip type storage = ...; // Any name, any type type return = (list (operation), storage); ``` - + + + + The contract storage can only be modified by activating a main function: given the state of the storage *on-chain*, a main function @@ -50,9 +60,9 @@ contract's parameter. Here is an example where the storage is a single natural number that is updated by the parameter. - - + + ```pascaligo group=a type parameter is nat @@ -62,8 +72,9 @@ type return is list (operation) * storage function save (const action : parameter; const store : storage) : return is ((nil : list (operation)), store) ``` + + - ```cameligo group=a type parameter = nat type storage = nat @@ -73,7 +84,9 @@ let save (action, store: parameter * storage) : return = (([] : operation list), store) ``` - + + + ```reasonligo group=a type parameter = nat; type storage = nat; @@ -82,7 +95,9 @@ type return = (list (operation), storage); let main = ((action, store): (parameter, storage)) : return => (([] : list (operation)), store); ``` - + + + ## Entrypoints @@ -105,9 +120,10 @@ In the following example, the storage contains a counter of type `nat` and a name of type `string`. Depending on the parameter of the contract, either the counter or the name is updated. - - + + + ```pascaligo group=b type parameter is Action_A of nat @@ -133,7 +149,9 @@ function main (const action : parameter; const store : storage): return is end ``` - + + + ```cameligo group=b type parameter = Action_A of nat @@ -158,7 +176,9 @@ let main (action, store: parameter * storage) : return = | Action_B s -> entry_B (s, store) ``` - + + + ```reasonligo group=b type parameter = | Action_A (nat) @@ -183,7 +203,9 @@ let main = ((action, store): (parameter, storage)) : return => | Action_B (s) => entry_B ((s, store)) }; ``` - + + + ## Tezos-specific Built-ins @@ -198,8 +220,9 @@ This example shows how `Tezos.amount` and `failwith` can be used to decline any transaction that sends more tez than `0tez`, that is, no incoming tokens are accepted. - - + + + ```pascaligo group=c type parameter is unit type storage is unit @@ -213,7 +236,10 @@ function deny (const action : parameter; const store : storage) : return is > Note that `amount` is *deprecated*. - + + + + ```cameligo group=c type parameter = unit type storage = unit @@ -227,7 +253,9 @@ let deny (action, store : parameter * storage) : return = > Note that `amount` is *deprecated*. - + + + ```reasonligo group=c type parameter = unit; type storage = unit; @@ -242,15 +270,17 @@ let deny = ((action, store): (parameter, storage)) : return => { > Note that `amount` is *deprecated*. - + + ### Access Control This example shows how `Tezos.source` can be used to deny access to an entrypoint. - - + + + ```pascaligo group=c const owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); @@ -261,7 +291,9 @@ function main (const action : parameter; const store : storage) : return is > Note that `source` is *deprecated*. - + + + ```cameligo group=c let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) @@ -272,7 +304,9 @@ let main (action, store: parameter * storage) : return = > Note that `source` is *deprecated*. - + + + ```reasonligo group=c let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); @@ -284,7 +318,8 @@ let main = ((action, store) : (parameter, storage)) : storage => { > Note that `source` is *deprecated*. - + + ### Inter-Contract Invocations @@ -310,9 +345,10 @@ of type `parameter`, and we have a `proxy.ligo` contract that accepts the same parameter type, and forwards the call to the deployed counter contract. - - + + + ```pascaligo skip // counter.ligo type parameter is @@ -354,7 +390,9 @@ function proxy (const action : parameter; const store : storage): return is } with (ops, store) ``` - + + + ```cameligo skip // counter.mligo @@ -395,7 +433,8 @@ let proxy (action, store : parameter * storage) : return = > Note that `Operation.get_contract` and `Operation.transaction` are > *deprecated*. - + + ```reasonligo skip // counter.religo @@ -438,4 +477,5 @@ let proxy = ((action, store): (parameter, storage)) : return => { > Note that `Operation.get_contract` and `Operation.transaction` are > *deprecated*. - + + diff --git a/gitlab-pages/docs/advanced/first-contract.md b/gitlab-pages/docs/advanced/first-contract.md index eb63a25c4..a22abd5a2 100644 --- a/gitlab-pages/docs/advanced/first-contract.md +++ b/gitlab-pages/docs/advanced/first-contract.md @@ -3,6 +3,8 @@ id: first-contract title: First contract --- +import Syntax from '@theme/Syntax'; + So far so good, we have learned enough of the LIGO language, we are confident enough to write out first smart contract. @@ -23,16 +25,15 @@ following: Here is a full example: - - -``` + +```shell ligo dry-run src/basic.ligo main Unit Unit // Outputs: // tuple[ list[] // Unit // ] ``` - + Output of the `dry-run` is the return value of our main function, we can see the operations emitted (in our case an empty list, and the new @@ -45,9 +46,9 @@ will accept an `action` variant in order to re-route our single `main` function to two entrypoints for `add` (addition) and `sub` (subtraction). - - -``` + + +```pascaligo type parameter is Increment of int | Decrement of int @@ -67,7 +68,9 @@ function main (const action : parameter; const store : storage) : return is end) ``` - + + + ```cameligo type parameter = Increment of int @@ -87,7 +90,10 @@ let main (action, store : parameter * storage) : operation list * storage = | Decrement n -> sub (n, store))) ``` - + + + + ```reasonligo type parameter = Increment (int) @@ -109,21 +115,18 @@ let main = ((action, store) : (parameter, storage)) : return => })); ``` - + To dry-run the counter contract, we will provide the `main` function with a variant parameter of value `Increment (5)` and an initial storage value of `5`. - - -``` +```shell ligo dry-run src/counter.ligo main "Increment(5)" 5 // tuple[ list[] // 10 // ] ``` - Our contract's storage has been successfuly incremented to `10`. @@ -134,19 +137,14 @@ In order to deploy the counter contract to a real Tezos network, we'd have to compile it first, this can be done with the help of the `compile-contract` CLI command: - - -``` +```shell ligo compile-contract src/counter.ligo main ``` - - Command above will output the following Michelson code: - - -``` + +```michelson { parameter (or (int %decrement) (int %increment)) ; storage int ; code { DUP ; @@ -175,20 +173,16 @@ Command above will output the following Michelson code: PAIR ; DIP { DROP 2 } } } ``` - However in order to originate a Michelson contract on Tezos, we also need to provide the initial storage value, we can use `compile-storage` to compile the LIGO representation of the storage to Michelson. - - -``` +```shell ligo compile-storage src/counter.ligo main 5 // Outputs: 5 ``` - In our case the LIGO storage value maps 1:1 to its Michelson representation, however this will not be the case once the parameter @@ -200,13 +194,11 @@ Same rules apply for parameters, as apply for translating LIGO storage values to Michelson. We will need to use `compile-parameter` to compile our `action` variant into Michelson, here's how: - - -``` +```shell ligo compile-parameter src/counter.ligo main 'Increment(5)' // Outputs: (Right 5) ``` - + Now we can use `(Right 5)` which is a Michelson value, to invoke our contract - e.g., via `tezos-client` diff --git a/gitlab-pages/docs/advanced/include.md b/gitlab-pages/docs/advanced/include.md index 21094102e..6b82a89df 100644 --- a/gitlab-pages/docs/advanced/include.md +++ b/gitlab-pages/docs/advanced/include.md @@ -3,6 +3,8 @@ id: include title: Including Other Contracts --- +import Syntax from '@theme/Syntax'; + Let us say that we have a contract that is getting a too large. If it has a modular structure, you might find it useful to use the `#include` statement to split the contract up over multiple files. @@ -10,9 +12,10 @@ has a modular structure, you might find it useful to use the You take the code that you want to include and put it in a separate file, for example `included.ligo`: - - + + + ```pascaligo // Demonstrate PascaLIGO inclusion statements, see includer.ligo @@ -20,46 +23,57 @@ file, for example `included.ligo`: const foo : int = 144 ``` - + + + ```cameligo // Demonstrate CameLIGO inclusion statements, see includer.mligo let foo : int = 144 ``` - + + + ```reasonligo // Demonstrate ReasonLIGO inclusion statements, see includer.religo let foo : int = 144; ``` - + + And then you can include this code using the `#include` statement like so: - - + + + ```pascaligo #include "included.ligo" const bar : int = foo ``` - + + + ```cameligo #include "included.mligo" let bar : int = foo ``` - + + + ```reasonligo #include "included.religo" let bar : int = foo; ``` - + + diff --git a/gitlab-pages/docs/advanced/timestamps-addresses.md b/gitlab-pages/docs/advanced/timestamps-addresses.md index b3a4d2391..30f0b55b0 100644 --- a/gitlab-pages/docs/advanced/timestamps-addresses.md +++ b/gitlab-pages/docs/advanced/timestamps-addresses.md @@ -3,6 +3,8 @@ id: timestamps-addresses title: Timestamps, Addresses --- +import Syntax from '@theme/Syntax'; + ## Timestamps LIGO features timestamps, as Michelson does, while bakers baking the @@ -15,29 +17,35 @@ You can obtain the current time using the built-in syntax specific expression, please be aware that it is up to the baker to set the current timestamp value. - - + + + ```pascaligo group=a const today : timestamp = Tezos.now ``` > Note that `now` is *deprecated*. - + + + ```cameligo group=a let today : timestamp = Tezos.now ``` > Note that `Current.time` is *deprecated*. - + + + ```reasonligo group=a let today : timestamp = Tezos.now; ``` > Note that `Current.time` is *deprecated*. - + + > When running code, the LIGO CLI option `--predecessor-timestamp` > allows you to control what `Tezos.now` returns. @@ -49,8 +57,9 @@ constraints on your smart contracts. Consider the following scenarios. #### In 24 hours - - + + + ```pascaligo group=b const today : timestamp = Tezos.now const one_day : int = 86400 @@ -61,7 +70,9 @@ const one_day_later : timestamp = some_date + one_day > Note that `now` is *deprecated*. - + + + ```cameligo group=b let today : timestamp = Tezos.now let one_day : int = 86400 @@ -72,7 +83,9 @@ let one_day_later : timestamp = some_date + one_day > Note that `Current.time` is *deprecated*. - + + + ```reasonligo group=b let today : timestamp = Tezos.now; let one_day : int = 86400; @@ -83,12 +96,14 @@ let one_day_later : timestamp = some_date + one_day; > Note that `Current.time` is *deprecated*. - + + #### 24 hours Ago - - + + + ```pascaligo group=c const today : timestamp = Tezos.now const one_day : int = 86400 @@ -97,7 +112,9 @@ const in_24_hrs : timestamp = today - one_day > Note that `now` is *deprecated*. - + + + ```cameligo group=c let today : timestamp = Tezos.now let one_day : int = 86400 @@ -106,7 +123,9 @@ let in_24_hrs : timestamp = today - one_day > Note that `Current.time` is *deprecated*. - + + + ```reasonligo group=c let today : timestamp = Tezos.now; let one_day : int = 86400; @@ -115,38 +134,43 @@ let in_24_hrs : timestamp = today - one_day; > Note that `Current.time` is *deprecated*. + - ### Comparing Timestamps You can compare timestamps using the same comparison operators applying to numbers. - - + + + ```pascaligo group=c const not_tommorow : bool = (Tezos.now = in_24_hrs) ``` > Note that `now` is *deprecated*. - + + + ```cameligo group=c let not_tomorrow : bool = (Tezos.now = in_24_hrs) ``` > Note that `Current.time` is *deprecated*. - + + + ```reasonligo group=c let not_tomorrow : bool = (Tezos.now == in_24_hrs); ``` > Note that `Current.time` is *deprecated*. + - ## Addresses @@ -155,26 +179,32 @@ KT1, ...). Currently, addresses are created by casting a string to the `address` type. Beware of failures if the address is invalid. Consider the following examples. - - + + + ```pascaligo group=d const my_account : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) ``` - + + + ```cameligo group=d let my_account : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) ``` - + + + ```reasonligo group=d let my_account : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); ``` - + + ## Signatures @@ -184,26 +214,35 @@ failure if the signature is invalid. Here is how you can define a signature: - - + + + ```pascaligo group=e const my_sig : signature = ("edsigthTzJ8X7MPmNeEwybRAvdxS1pupqcM5Mk4uCuyZAe7uEk68YpuGDeViW8wSXMrCi5CwoNgqs8V2w8ayB5dMJzrYCHhD8C7" : signature) ``` - + + + + ```cameligo group=e let my_sig : signature = ("edsigthTzJ8X7MPmNeEwybRAvdxS1pupqcM5Mk4uCuyZAe7uEk68YpuGDeViW8wSXMrCi5CwoNgqs8V2w8ayB5dMJzrYCHhD8C7" : signature) ``` - + + + + ```reasonligo group=e let my_sig : signature = ("edsigthTzJ8X7MPmNeEwybRAvdxS1pupqcM5Mk4uCuyZAe7uEk68YpuGDeViW8wSXMrCi5CwoNgqs8V2w8ayB5dMJzrYCHhD8C7" : signature); ``` - + + + ## Keys @@ -213,20 +252,29 @@ failure if the key is invalid. Here is how you can define a key. - - + + + ```pascaligo group=f const my_key : key = ("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" : key) ``` - + + + + ```cameligo group=f let my_key : key = ("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" : key) ``` - + + + + ```reasonligo group=f let my_key : key = ("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" : key); ``` - + + + diff --git a/gitlab-pages/docs/api/cheat-sheet.md b/gitlab-pages/docs/api/cheat-sheet.md index 9e7020177..412ba5bd5 100644 --- a/gitlab-pages/docs/api/cheat-sheet.md +++ b/gitlab-pages/docs/api/cheat-sheet.md @@ -2,14 +2,17 @@ id: cheat-sheet title: Cheat Sheet --- -
+ +import Syntax from '@theme/Syntax'; + +
- - + + |Primitive |Example| |--- |---| @@ -33,7 +36,7 @@ Note that this table is not compiled before production and currently needs to be | 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``` | +|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
| @@ -43,7 +46,8 @@ Note that this table is not compiled before production and currently needs to be |Transactions|
const payment : operation = transaction(unit, amount, receiver);
| |Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`| - +
+ |Primitive |Example| |--- |---| @@ -75,7 +79,8 @@ Note that this table is not compiled before production and currently needs to be |Transactions|
let payment : operation = 
Tezos.transaction unit amount receiver
| |Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`| - +
+ |Primitive |Example| |--- |---| @@ -107,7 +112,8 @@ Note that this table is not compiled before production and currently needs to be |Transactions|
let payment : operation = 
Tezos.transaction (unit, amount, receiver);
| |Exception/Failure|`failwith ("Your descriptive error message for the user goes here.");`| +
+ -
diff --git a/gitlab-pages/docs/intro/what-and-why.md b/gitlab-pages/docs/intro/what-and-why.md index f195b97a7..4a68141da 100644 --- a/gitlab-pages/docs/intro/what-and-why.md +++ b/gitlab-pages/docs/intro/what-and-why.md @@ -3,6 +3,8 @@ id: what-and-why title: Michelson and LIGO --- +import Syntax from '@theme/Syntax'; + Before we get into what LIGO is and why LIGO needs to exist, let us take a look at what options the Tezos blockchain offers us out of the box. If you want to implement smart contracts natively on Tezos, you @@ -161,8 +163,9 @@ Let us decline the same LIGO contract in the three flavours above. Do not worry if it is a little confusing at first; we will explain all the syntax in the upcoming sections of the documentation. - - + + + ```pascaligo group=a type storage is int @@ -182,7 +185,9 @@ function main (const action : parameter; const store : storage) : return is end) ``` - + + + ```cameligo group=a type storage = int @@ -201,7 +206,9 @@ let main (action, store : parameter * storage) : return = | Reset -> 0) ``` - + + + ```reasonligo group=a type storage = int; @@ -220,7 +227,9 @@ let main = ((action, store): (parameter, storage)) : return => { | Reset => 0})); }; ``` - + + + - + + + ```pascaligo group=a const a : bool = True // Also: true const b : bool = False // Also: false ``` - + + + + ```cameligo group=a let a : bool = true let b : bool = false ``` - + + + + ```reasonligo group=a let a : bool = true; let b : bool = false; ``` - + + + ## Comparing Values @@ -39,31 +50,41 @@ function. ### Comparing Strings - - + + + ```pascaligo group=b const a : string = "Alice" const b : string = "Alice" const c : bool = (a = b) // True ``` - + + + + ```cameligo group=b let a : string = "Alice" let b : string = "Alice" let c : bool = (a = b) // true ``` - + + + + ```reasonligo group=b let a : string = "Alice"; let b : string = "Alice"; let c : bool = (a == b); // true ``` - + + + ### Comparing numbers - - + + + ```pascaligo group=c const a : int = 5 const b : int = 4 @@ -74,7 +95,10 @@ const f : bool = (a <= b) const g : bool = (a >= b) const h : bool = (a =/= b) ``` - + + + + ```cameligo group=c let a : int = 5 let b : int = 4 @@ -86,7 +110,9 @@ let g : bool = (a >= b) let h : bool = (a <> b) ``` - + + + ```reasonligo group=c let a : int = 5; let b : int = 4; @@ -97,33 +123,43 @@ let f : bool = (a <= b); let g : bool = (a >= b); let h : bool = (a != b); ``` - + + + ### Comparing tez > 💡 Comparing `tez` values is especially useful when dealing with an > amount sent in a transaction. - - + + + ```pascaligo group=d const a : tez = 5mutez const b : tez = 10mutez const c : bool = (a = b) // False ``` - + + + + ```cameligo group=d let a : tez = 5mutez let b : tez = 10mutez let c : bool = (a = b) // false ``` - + + + ```reasonligo group=d let a : tez = 5mutez; let b : tez = 10mutez; let c : bool = (a == b); // false ``` - + + + ## Conditionals @@ -131,8 +167,9 @@ let c : bool = (a == b); // false Conditional logic enables forking the control flow depending on the state. - - + + + ```pascaligo group=e type magnitude is Small | Large // See variant types. @@ -171,7 +208,9 @@ if x < y then { else skip; ``` - + + + ```cameligo group=e type magnitude = Small | Large // See variant types. @@ -192,8 +231,9 @@ gitlab-pages/docs/language-basics/boolean-if-else/cond.mligo compare 21n' > *dangling else* problem is parsed by associating any `else` to the > closest previous `then`. + + - ```reasonligo group=e type magnitude = Small | Large; // See variant types. @@ -208,4 +248,6 @@ ligo run-function gitlab-pages/docs/language-basics/boolean-if-else/cond.religo compare 21n' # Outputs: Large ``` - + + + diff --git a/gitlab-pages/docs/language-basics/functions.md b/gitlab-pages/docs/language-basics/functions.md index b4c81beb1..c0fc83153 100644 --- a/gitlab-pages/docs/language-basics/functions.md +++ b/gitlab-pages/docs/language-basics/functions.md @@ -3,6 +3,8 @@ id: functions title: Functions --- +import Syntax from '@theme/Syntax'; + LIGO functions are the basic building block of contracts. For example, entrypoints are functions and each smart contract needs a main function that dispatches control to the entrypoints (it is not already @@ -16,8 +18,8 @@ mutations inside the functions will be. ## Declaring Functions - - + + There are two ways in PascaLIGO to define functions: with or without a *block*. @@ -91,7 +93,8 @@ ligo run-function gitlab-pages/docs/language-basics/src/functions/blockless.ligo # Outputs: 3 ``` - + + Functions in CameLIGO are defined using the `let` keyword, like other values. The difference is that a succession of parameters is provided @@ -145,7 +148,8 @@ ligo run-function gitlab-pages/docs/language-basics/src/functions/curry.mligo in The function body is a single expression, whose value is returned. - + + Functions in ReasonLIGO are defined using the `let` keyword, like other values. The difference is that a tuple of parameters is provided @@ -176,7 +180,8 @@ let myFun = ((x, y) : (int, int)) : int => { }; ``` - + + ## Anonymous functions (a.k.a. lambdas) @@ -186,8 +191,9 @@ a key in a record or a map. Here is how to define an anonymous function: - - + + + ```pascaligo group=c function increment (const b : int) : int is (function (const a : int) : int is a + 1) (b) @@ -201,7 +207,9 @@ ligo evaluate-value gitlab-pages/docs/language-basics/src/functions/anon.ligo a # Outputs: 2 ``` - + + + ```cameligo group=c let increment (b : int) : int = (fun (a : int) -> a + 1) b let a : int = increment 1 // a = 2 @@ -214,7 +222,9 @@ ligo evaluate-value gitlab-pages/docs/language-basics/src/functions/anon.mligo a # Outputs: 2 ``` - + + + ```reasonligo group=c let increment = (b : int) : int => ((a : int) : int => a + 1) (b); let a : int = increment (1); // a == 2 @@ -227,15 +237,17 @@ ligo evaluate-value gitlab-pages/docs/language-basics/src/functions/anon.religo # Outputs: 2 ``` - + + If the example above seems contrived, here is a more common design pattern for lambdas: to be used as parameters to functions. Consider the use case of having a list of integers and mapping the increment function to all its elements. - - + + + ```pascaligo group=c function incr_map (const l : list (int)) : list (int) is List.map (function (const i : int) : int is i + 1, l) @@ -253,7 +265,9 @@ gitlab-pages/docs/language-basics/src/functions/incr_map.ligo incr_map # Outputs: [ 2 ; 3 ; 4 ] ``` - + + + ```cameligo group=c let incr_map (l : int list) : int list = List.map (fun (i : int) -> i + 1) l @@ -267,7 +281,9 @@ gitlab-pages/docs/language-basics/src/functions/incr_map.mligo incr_map # Outputs: [ 2 ; 3 ; 4 ] ``` - + + + ```reasonligo group=c let incr_map = (l : list (int)) : list (int) => List.map ((i : int) => i + 1, l); @@ -281,4 +297,5 @@ gitlab-pages/docs/language-basics/src/functions/incr_map.religo incr_map # Outputs: [ 2 ; 3 ; 4 ] ``` - + + diff --git a/gitlab-pages/docs/language-basics/loops.md b/gitlab-pages/docs/language-basics/loops.md index ffe27c17e..8f81c93ae 100644 --- a/gitlab-pages/docs/language-basics/loops.md +++ b/gitlab-pages/docs/language-basics/loops.md @@ -3,11 +3,13 @@ id: loops title: Loops --- +import Syntax from '@theme/Syntax'; + ## General Iteration - - + + General iteration in PascaLIGO takes the shape of general loops, which should be familiar to programmers of imperative languages as "while @@ -47,7 +49,8 @@ gitlab-pages/docs/language-basics/src/loops/gcd.ligo gcd '(2n*2n*3n*11n, 2n*2n*2 # Outputs: +12 ``` - + + CameLIGO is a functional language where user-defined values are constant, therefore it makes no sense in CameLIGO to feature loops, @@ -103,7 +106,8 @@ gitlab-pages/docs/language-basics/src/loops/gcd.mligo gcd (2n*2n*3n*11n, 2n*2n*2 # Outputs: +12 ``` - + + ReasonLIGO is a functional language where user-defined values are constant, therefore it makes no sense in ReasonLIGO to feature loops, @@ -153,7 +157,8 @@ let gcd = ((x,y) : (nat, nat)) : nat => { > Note that `stop` and `continue` (now `Loop.resume`) are > *deprecated*. - + + ## Bounded Loops @@ -185,8 +190,8 @@ gitlab-pages/docs/language-basics/src/loops/sum.ligo sum 7n PascaLIGO "for" loops can also iterate through the contents of a collection, that is, a list, a set or a map. This is done with a loop -of the form `for in -`, where `` is any of the following keywords: +of the form `for in `, +where `` is any of the following keywords: `list`, `set` or `map`. Here is an example where the integers in a list are summed up. diff --git a/gitlab-pages/docs/language-basics/maps-records.md b/gitlab-pages/docs/language-basics/maps-records.md index c9837fb26..b4d7db1c1 100644 --- a/gitlab-pages/docs/language-basics/maps-records.md +++ b/gitlab-pages/docs/language-basics/maps-records.md @@ -3,6 +3,8 @@ id: maps-records title: Records and Maps --- +import Syntax from '@theme/Syntax'; + So far we have seen pretty basic data types. LIGO also offers more complex built-in constructs, such as *records* and *maps*. @@ -16,9 +18,10 @@ special operator (`.`). Let us first consider and example of record type declaration. - - + + + ```pascaligo group=records1 type user is record [ @@ -28,7 +31,9 @@ type user is ] ``` - + + + ```cameligo group=records1 type user = { id : nat; @@ -37,7 +42,9 @@ type user = { } ``` - + + + ```reasonligo group=records1 type user = { id : nat, @@ -45,12 +52,15 @@ type user = { name : string }; ``` - + + + And here is how a record value is defined: - - + + + ```pascaligo group=records1 const alice : user = record [ @@ -60,7 +70,9 @@ const alice : user = ] ``` - + + + ```cameligo group=records1 let alice : user = { id = 1n; @@ -69,7 +81,9 @@ let alice : user = { } ``` - + + + ```reasonligo group=records1 let alice : user = { id : 1n, @@ -77,29 +91,38 @@ let alice : user = { name : "Alice" }; ``` - + + + ### Accessing Record Fields If we want the contents of a given field, we use the (`.`) infix operator, like so: - - + + + ```pascaligo group=records1 const alice_admin : bool = alice.is_admin ``` - + + + ```cameligo group=records1 let alice_admin : bool = alice.is_admin ``` - + + + ```reasonligo group=records1 let alice_admin : bool = alice.is_admin; ``` - + + + ### Functional Updates @@ -115,12 +138,13 @@ updated record. Let us consider defining a function that translates three-dimensional points on a plane. - - -In PascaLIGO, the shape of that expression is ` with -`. The record variable is the record to update and the + + +In PascaLIGO, the shape of that expression is +` with `. +The record variable is the record to update and the record value is the update itself. ```pascaligo group=records2 @@ -146,7 +170,8 @@ You have to understand that `p` has not been changed by the functional update: a namless new version of it has been created and returned by the blockless function. - + + The syntax for the functional updates of record in CameLIGO follows that of OCaml: @@ -174,7 +199,8 @@ xy_translate "({x=2;y=3;z=1}, {dx=3;dy=4})" > functional update: a nameless new version of it has been created and > returned. - + + The syntax for the functional updates of record in ReasonLIGO follows that of ReasonML: @@ -188,7 +214,9 @@ let origin : point = {x : 0, y : 0, z : 0}; let xy_translate = ((p, vec) : (point, vector)) : point => {...p, x : p.x + vec.dx, y : p.y + vec.dy}; ``` - + + + You can call the function `xy_translate` defined above by running the following command of the shell: @@ -303,55 +331,69 @@ sense. Here is how a custom map from addresses to a pair of integers is defined. - - + + + ```pascaligo group=maps type move is int * int type register is map (address, move) ``` - + + + ```cameligo group=maps type move = int * int type register = (address, move) map ``` - + + + ```reasonligo group=maps type move = (int, int); type register = map (address, move); ``` - + + + ### Creating an Empty Map Here is how to create an empty map. - - + + + ```pascaligo group=maps const empty : register = map [] ``` - + + + ```cameligo group=maps let empty : register = Map.empty ``` - + + + ```reasonligo group=maps let empty : register = Map.empty ``` - + + + ### Creating a Non-empty Map And here is how to create a non-empty map value: - - + + ```pascaligo group=maps const moves : register = @@ -365,7 +407,9 @@ individual map entries. The annotated value `("" : address)` means that we cast a string into an address. Also, `map` is a keyword. - + + + ```cameligo group=maps let moves : register = Map.literal [ @@ -378,7 +422,9 @@ key-value pair tuples, `(, )`. Note also the `;` to separate individual map entries. `("": address)` means that we type-cast a string into an address. --> - + + + ```reasonligo group=maps let moves : register = Map.literal ([ @@ -391,12 +437,13 @@ key-value pair tuples, `(, )`. Note also the `;` to separate individual map entries. `("": address)` means that we type-cast a string into an address. --> - + + ### Accessing Map Bindings - - + + In PascaLIGO, we can use the postfix `[]` operator to read the `move` value associated to a given key (`address` here) in the register. Here @@ -407,26 +454,33 @@ const my_balance : option (move) = moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] ``` - + + + ```cameligo group=maps let my_balance : move option = Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves ``` - + + + ```reasonligo group=maps let my_balance : option (move) = Map.find_opt (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), moves); ``` - + + + Notice how the value we read is an optional value: this is to force the reader to account for a missing key in the map. This requires *pattern matching*. - - + + + ```pascaligo group=maps function force_access (const key : address; const moves : register) : move is case moves[key] of @@ -435,7 +489,9 @@ function force_access (const key : address; const moves : register) : move is end ``` - + + + ```cameligo group=maps let force_access (key, moves : address * register) : move = match Map.find_opt key moves with @@ -443,7 +499,9 @@ let force_access (key, moves : address * register) : move = | None -> (failwith "No move." : move) ``` - + + + ```reasonligo group=maps let force_access = ((key, moves) : (address, register)) : move => { switch (Map.find_opt (key, moves)) { @@ -452,7 +510,9 @@ let force_access = ((key, moves) : (address, register)) : move => { } }; ``` - + + + ### Updating a Map @@ -461,9 +521,9 @@ Given a map, we may want to add a new binding, remove one, or modify one by changing the value associated to an already existing key. All those operations are called *updates*. - - + + The values of a PascaLIGO map can be updated using the usual assignment syntax `[] := `. Let us @@ -491,7 +551,8 @@ function assignments (var m : register) : register is See further for the removal of bindings. - + + We can update a binding in a map in CameLIGO by means of the `Map.update` built-in function: @@ -513,7 +574,8 @@ let add (m : register) : register = ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m ``` - + + We can update a binding in a map in ReasonLIGO by means of the `Map.update` built-in function: @@ -535,13 +597,14 @@ let add = (m : register) : register => (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m); ``` - + + To remove a binding from a map, we need its key. - - + + In PascaLIGO, there is a special instruction to remove a binding from a map. @@ -552,7 +615,8 @@ function delete (const key : address; var moves : register) : register is } with moves ``` - + + In CameLIGO, we use the predefined function `Map.remove` as follows: @@ -561,7 +625,8 @@ let delete (key, moves : address * register) : register = Map.remove key moves ``` - + + In ReasonLIGO, we use the predefined function `Map.remove` as follows: @@ -570,7 +635,8 @@ let delete = ((key, moves) : (address, register)) : register => Map.remove (key, moves); ``` - + + ### Functional Iteration over Maps @@ -596,9 +662,9 @@ over maps is called `Map.iter`. In the following example, the register of moves is iterated to check that the start of each move is above `3`. - - + + ```pascaligo group=maps function iter_op (const m : register) : unit is @@ -610,7 +676,8 @@ function iter_op (const m : register) : unit is > Note that `map_iter` is *deprecated*. - + + ```cameligo group=maps let iter_op (m : register) : unit = @@ -618,7 +685,8 @@ let iter_op (m : register) : unit = in Map.iter predicate m ``` - + + ```reasonligo group=maps let iter_op = (m : register) : unit => { @@ -626,7 +694,9 @@ let iter_op = (m : register) : unit => { Map.iter (predicate, m); }; ``` - + + + #### Map Operations over Maps @@ -637,9 +707,9 @@ implementing the map operation over maps is called `Map.map`. In the following example, we add `1` to the ordinate of the moves in the register. - - + + ```pascaligo group=maps function map_op (const m : register) : register is @@ -651,7 +721,8 @@ function map_op (const m : register) : register is > Note that `map_map` is *deprecated*. - + + ```cameligo group=maps let map_op (m : register) : register = @@ -659,7 +730,8 @@ let map_op (m : register) : register = in Map.map increment m ``` - + + ```reasonligo group=maps let map_op = (m : register) : register => { @@ -667,7 +739,9 @@ let map_op = (m : register) : register => { Map.map (increment, m); }; ``` - + + + #### Folded Operations over Maps @@ -680,9 +754,9 @@ traversal of the data structure is over. The predefined functional iterator implementing the folded operation over maps is called `Map.fold` and is used as follows. - - + + ```pascaligo group=maps function fold_op (const m : register) : int is @@ -694,7 +768,8 @@ function fold_op (const m : register) : int is > Note that `map_fold` is *deprecated*. - + + ```cameligo group=maps let fold_op (m : register) : register = @@ -702,7 +777,8 @@ let fold_op (m : register) : register = in Map.fold folded m 5 ``` - + + ```reasonligo group=maps let fold_op = (m : register) : register => { @@ -711,7 +787,8 @@ let fold_op = (m : register) : register => { }; ``` - + + ## Big Maps @@ -728,55 +805,69 @@ interface for big maps is analogous to the one used for ordinary maps. Here is how we define a big map: - - + + + ```pascaligo group=big_maps type move is int * int type register is big_map (address, move) ``` - + + + ```cameligo group=big_maps type move = int * int type register = (address, move) big_map ``` - + + + ```reasonligo group=big_maps type move = (int, int); type register = big_map (address, move); ``` - + + + ### Creating an Empty Big Map Here is how to create an empty big map. - - + + + ```pascaligo group=big_maps const empty : register = big_map [] ``` - + + + ```cameligo group=big_maps let empty : register = Big_map.empty ``` - + + + ```reasonligo group=big_maps let empty : register = Big_map.empty ``` - + + + ### Creating a Non-empty Map And here is how to create a non-empty map value: - - + + ```pascaligo group=big_maps const moves : register = @@ -790,7 +881,8 @@ semicolon separating individual map entries. The value annotation `("" : address)` means that we cast a string into an address. --> - + + ```cameligo group=big_maps let moves : register = @@ -804,7 +896,8 @@ list of key-value pairs `(, )`. Note also the semicolon separating individual map entries. The annotated value `(" value>" : address)` means that we cast a string into an address. - + + ```reasonligo group=big_maps let moves : register = @@ -818,8 +911,8 @@ list of key-value pairs `(, )`. Note also the semicolon separating individual map entries. The annotated value `(" value>" : address)` means that we cast a string into an address. + - ### Accessing Values @@ -828,35 +921,39 @@ postfix `[]` operator to read the associated `move` value. However, the value we read is an optional value (in our case, of type `option (move)`), to account for a missing key. Here is an example: - - + + ```pascaligo group=big_maps const my_balance : option (move) = moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] ``` - + + ```cameligo group=big_maps let my_balance : move option = Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves ``` - + + ```reasonligo group=big_maps let my_balance : option (move) = Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves); ``` - + + + ### Updating Big Maps - - + + The values of a PascaLIGO big map can be updated using the assignment syntax for ordinary maps @@ -870,7 +967,8 @@ function add (var m : register) : register is const updated_map : register = add (moves) ``` - + + We can update a big map in CameLIGO using the `Big_map.update` built-in: @@ -881,7 +979,8 @@ let updated_map : register = ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves ``` - + + We can update a big map in ReasonLIGO using the `Big_map.update` built-in: @@ -892,16 +991,17 @@ let updated_map : register = (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves); ``` - + + ### Removing Bindings Removing a binding in a map is done differently according to the LIGO syntax. - - + + PascaLIGO features a special syntactic construct to remove bindings from maps, of the form `remove from map `. For example, @@ -915,7 +1015,8 @@ function rem (var m : register) : register is const updated_map : register = rem (moves) ``` - + + In CameLIGO, the predefined function which removes a binding in a map is called `Map.remove` and is used as follows: @@ -925,7 +1026,8 @@ let updated_map : register = Map.remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves ``` - + + In ReasonLIGO, the predefined function which removes a binding in a map is called `Map.remove` and is used as follows: @@ -935,4 +1037,5 @@ let updated_map : register = Map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves) ``` - + + diff --git a/gitlab-pages/docs/language-basics/math-numbers-tez.md b/gitlab-pages/docs/language-basics/math-numbers-tez.md index 31bdeb872..c56119c64 100644 --- a/gitlab-pages/docs/language-basics/math-numbers-tez.md +++ b/gitlab-pages/docs/language-basics/math-numbers-tez.md @@ -3,6 +3,8 @@ id: math-numbers-tez title: Math, Numbers & Tez --- +import Syntax from '@theme/Syntax'; + LIGO offers three built-in numerical types: `int`, `nat` and `tez`. Values of type `int` are integers; values of type `nat` are natural numbers (integral numbers greater than or equal to zero); @@ -38,8 +40,9 @@ remain in comments as they would otherwise not compile, for example, adding a value of type `int` to a value of type `tez` is invalid. Note that adding an integer to a natural number produces an integer. - - + + + ```pascaligo group=a // int + int yields int const a : int = 5 + 10 @@ -69,7 +72,9 @@ const g : int = 1_000_000 > const sum : tez = 100_000mutez >``` - + + + ```cameligo group=a // int + int yields int let a : int = 5 + 10 @@ -99,7 +104,9 @@ let g : int = 1_000_000 >let sum : tez = 100_000mutez >``` - + + + ```reasonligo group=a // int + int yields int let a : int = 5 + 10; @@ -127,7 +134,9 @@ let g : int = 1_000_000; >```reasonligo >let sum : tex = 100_000mutez; >``` - + + + ## Subtraction @@ -135,8 +144,9 @@ Subtraction looks as follows. > ⚠️ Even when subtracting two `nats`, the result is an `int` - - + + + ```pascaligo group=b const a : int = 5 - 10 @@ -149,7 +159,9 @@ const b : int = 5n - 2n const d : tez = 5mutez - 1mutez ``` - + + + ```cameligo group=b let a : int = 5 - 10 @@ -162,7 +174,9 @@ let b : int = 5n - 2n let d : tez = 5mutez - 1mutez ``` - + + + ```reasonligo group=b let a : int = 5 - 10; @@ -175,15 +189,16 @@ let b : int = 5n - 2n; let d : tez = 5mutez - 1mutez; ``` - + + ## Multiplication You can multiply values of the same type, such as: - - + + ```pascaligo group=c const a : int = 5 * 5 @@ -193,7 +208,9 @@ const b : nat = 5n * 5n const c : tez = 5n * 5mutez ``` - + + + ```cameligo group=c let a : int = 5 * 5 let b : nat = 5n * 5n @@ -202,7 +219,9 @@ let b : nat = 5n * 5n let c : tez = 5n * 5mutez ``` - + + + ```reasonligo group=c let a : int = 5 * 5; let b : nat = 5n * 5n; @@ -211,7 +230,8 @@ let b : nat = 5n * 5n; let c : tez = 5n * 5mutez; ``` - + + ## Euclidean Division @@ -219,35 +239,42 @@ In LIGO you can divide `int`, `nat`, and `tez`. Here is how: > ⚠️ Division of two `tez` values results into a `nat` - - + + + ```pascaligo group=d const a : int = 10 / 3 const b : nat = 10n / 3n const c : nat = 10mutez / 3mutez ``` - + + + ```cameligo group=d let a : int = 10 / 3 let b : nat = 10n / 3n let c : nat = 10mutez / 3mutez ``` - + + + ```reasonligo group=d let a : int = 10 / 3; let b : nat = 10n / 3n; let c : nat = 10mutez / 3mutez; ``` - + + LIGO also allows you to compute the remainder of the Euclidean division. In LIGO, it is a natural number. - - + + + ```pascaligo group=d const a : int = 120 const b : int = 9 @@ -259,7 +286,9 @@ const rem3 : nat = c mod d // 3 const rem4 : nat = a mod d // 3 ``` - + + + ```cameligo group=d let a : int = 120 let b : int = 9 @@ -271,7 +300,9 @@ let rem3 : nat = c mod d // 3 let rem4 : nat = a mod d // 3 ``` - + + + ```reasonligo group=d let a : int = 120; let b : int = 9; @@ -283,29 +314,39 @@ let rem3 : nat = c mod d; // 3 let rem4 : nat = a mod d; // 3 ``` + + + ## From `int` to `nat` and back You can *cast* an `int` to a `nat` and vice versa. Here is how: - - + + + ```pascaligo group=e const a : int = int (1n) const b : nat = abs (1) ``` - + + + ```cameligo group=e let a : int = int (1n) let b : nat = abs (1) ``` - + + + ```reasonligo group=e let a : int = int (1n); let b : nat = abs (1); ``` - + + + ## Checking a `nat` @@ -314,20 +355,26 @@ function which accepts an `int` and returns an optional `nat`: if the result is not `None`, then the provided integer was indeed a natural number, and not otherwise. - - + + + ```pascaligo group=e const is_a_nat : option (nat) = is_nat (1) ``` - + + + ```cameligo group=e let is_a_nat : nat option = Michelson.is_nat (1) ``` - + + + ```reasonligo group=e let is_a_nat : option (nat) = Michelson.is_nat (1); ``` - + + diff --git a/gitlab-pages/docs/language-basics/sets-lists-tuples.md b/gitlab-pages/docs/language-basics/sets-lists-tuples.md index 8bcb192f6..31963eb26 100644 --- a/gitlab-pages/docs/language-basics/sets-lists-tuples.md +++ b/gitlab-pages/docs/language-basics/sets-lists-tuples.md @@ -3,6 +3,8 @@ id: sets-lists-tuples title: Tuples, Lists, Sets --- +import Syntax from '@theme/Syntax'; + Apart from complex data types such as `maps` and `records`, LIGO also features `tuples`, `lists` and `sets`. @@ -27,9 +29,9 @@ Unlike [a record](language-basics/maps-records.md), tuple types do not have to be defined before they can be used. However below we will give them names by *type aliasing*. - - + + ```pascaligo group=tuple type full_name is string * string // Alias @@ -37,7 +39,8 @@ type full_name is string * string // Alias const full_name : full_name = ("Alice", "Johnson") ``` - + + ```cameligo group=tuple type full_name = string * string // Alias @@ -45,7 +48,8 @@ type full_name = string * string // Alias let full_name : full_name = ("Alice", "Johnson") // Optional parentheses ``` - + + ```reasonligo group=tuple type full_name = (string, string); // Alias @@ -53,7 +57,8 @@ type full_name = (string, string); // Alias let full_name : full_name = ("Alice", "Johnson"); ``` - + + ### Accessing Components @@ -66,27 +71,30 @@ position in their tuple, which cannot be done in OCaml. *Tuple components are zero-indexed*, that is, the first component has index `0`. - - + + ```pascaligo group=tuple const first_name : string = full_name.0 ``` - + + ```cameligo group=tuple let first_name : string = full_name.0 ``` - + + ```reasonligo group=tuple let first_name : string = full_name[0]; ``` - + + ## Lists @@ -103,26 +111,32 @@ think of a list a *stack*, where the top is written on the left. ### Defining Lists - - + + + ```pascaligo group=lists const empty_list : list (int) = nil // Or list [] const my_list : list (int) = list [1; 2; 2] // The head is 1 ``` - + + + ```cameligo group=lists let empty_list : int list = [] let my_list : int list = [1; 2; 2] // The head is 1 ``` - + + + ```reasonligo group=lists let empty_list : list (int) = []; let my_list : list (int) = [1, 2, 2]; // The head is 1 ``` - + + ### Adding to Lists @@ -130,9 +144,9 @@ Lists can be augmented by adding an element before the head (or, in terms of stack, by *pushing an element on top*). This operation is usually called *consing* in functional languages. - - + + In PascaLIGO, the *cons operator* is infix and noted `#`. It is not symmetric: on the left lies the element to cons, and, on the right, a @@ -143,7 +157,8 @@ you of that.) const larger_list : list (int) = 5 # my_list // [5;1;2;2] ``` - + + In CameLIGO, the *cons operator* is infix and noted `::`. It is not symmetric: on the left lies the element to cons, and, on the right, a @@ -153,7 +168,8 @@ list on which to cons. let larger_list : int list = 5 :: my_list // [5;1;2;2] ``` - + + In ReasonLIGO, the *cons operator* is infix and noted `, ...`. It is not symmetric: on the left lies the element to cons, and, on the @@ -162,7 +178,9 @@ right, a list on which to cons. ```reasonligo group=lists let larger_list : list (int) = [5, ...my_list]; // [5,1,2,2] ``` - + + + ### Functional Iteration over Lists @@ -189,9 +207,9 @@ called `List.iter`. In the following example, a list is iterated to check that all its elements (integers) are strictly greater than `3`. - - + + ```pascaligo group=lists function iter_op (const l : list (int)) : unit is @@ -203,7 +221,8 @@ function iter_op (const l : list (int)) : unit is > Note that `list_iter` is *deprecated*. - + + ```cameligo group=lists let iter_op (l : int list) : unit = @@ -211,7 +230,8 @@ let iter_op (l : int list) : unit = in List.iter predicate l ``` - + + ```reasonligo group=lists let iter_op = (l : list (int)) : unit => { @@ -220,7 +240,8 @@ let iter_op = (l : list (int)) : unit => { }; ``` - + + #### Mapped Operation over Lists @@ -231,9 +252,9 @@ with the map data structure. The predefined functional iterator implementing the mapped operation over lists is called `List.map` and is used as follows. - - + + ```pascaligo group=lists function increment (const i : int): int is i + 1 @@ -244,7 +265,8 @@ const plus_one : list (int) = List.map (increment, larger_list) > Note that `list_map` is *deprecated*. - + + ```cameligo group=lists let increment (i : int) : int = i + 1 @@ -253,7 +275,8 @@ let increment (i : int) : int = i + 1 let plus_one : int list = List.map increment larger_list ``` - + + ```reasonligo group=lists let increment = (i : int) : int => i + 1; @@ -261,7 +284,9 @@ let increment = (i : int) : int => i + 1; // Creates a new list with all elements incremented by 1 let plus_one : list (int) = List.map (increment, larger_list); ``` - + + + #### Folded Operation over Lists @@ -274,9 +299,9 @@ traversal of the data structure is over. The predefined functional iterator implementing the folded operation over lists is called `List.fold` and is used as follows. - - + + ```pascaligo group=lists function sum (const acc : int; const i : int): int is acc + i @@ -285,20 +310,24 @@ const sum_of_elements : int = List.fold (sum, my_list, 0) > Note that `list_fold` is *deprecated*. - + + ```cameligo group=lists let sum (acc, i: int * int) : int = acc + i let sum_of_elements : int = List.fold sum my_list 0 ``` - + + ```reasonligo group=lists let sum = ((result, i): (int, int)): int => result + i; let sum_of_elements : int = List.fold (sum, my_list, 0); ``` - + + + ## Sets @@ -309,9 +338,9 @@ whereas they can be repeated in a *list*. ### Empty Sets - - + + In PascaLIGO, the notation for sets is similar to that for lists, except the keyword `set` is used before: @@ -319,7 +348,9 @@ except the keyword `set` is used before: ```pascaligo group=sets const my_set : set (int) = set [] ``` - + + + In CameLIGO, the empty set is denoted by the predefined value `Set.empty`. @@ -328,7 +359,8 @@ In CameLIGO, the empty set is denoted by the predefined value let my_set : int set = Set.empty ``` - + + In ReasonLIGO, the empty set is denoted by the predefined value `Set.empty`. @@ -336,13 +368,15 @@ In ReasonLIGO, the empty set is denoted by the predefined value ```reasonligo group=sets let my_set : set (int) = Set.empty; ``` - + + + ### Non-empty Sets - - + + In PascaLIGO, the notation for sets is similar to that for lists, except the keyword `set` is used before: @@ -359,7 +393,8 @@ gitlab-pages/docs/language-basics/src/sets-lists-tuples/sets.ligo my_set # Outputs: { 3 ; 2 ; 1 } ``` - + + In CameLIGO, there is no predefined syntactic construct for sets: you must build your set by adding to the empty set. (This is the way in @@ -379,7 +414,8 @@ gitlab-pages/docs/language-basics/src/sets-lists-tuples/sets.mligo my_set # Outputs: { 3 ; 2 ; 1 } ``` - + + In ReasonLIGO, there is no predefined syntactic construct for sets: you must build your set by adding to the empty set. (This is the way @@ -399,13 +435,15 @@ ligo evaluate-value gitlab-pages/docs/language-basics/src/sets-lists-tuples/sets.religo my_set # Outputs: { 3 ; 2 ; 1 } ``` - + + + ### Set Membership - - + + PascaLIGO features a special keyword `contains` that operates like an infix operator checking membership in a set. @@ -414,7 +452,8 @@ infix operator checking membership in a set. const contains_3 : bool = my_set contains 3 ``` - + + In CameLIGO, the predefined predicate `Set.mem` tests for membership in a set as follows: @@ -423,7 +462,8 @@ in a set as follows: let contains_3 : bool = Set.mem 3 my_set ``` - + + In ReasonLIGO, the predefined predicate `Set.mem` tests for membership in a set as follows: @@ -432,7 +472,8 @@ in a set as follows: let contains_3 : bool = Set.mem (3, my_set); ``` - + + ### Cardinal of Sets @@ -440,9 +481,9 @@ let contains_3 : bool = Set.mem (3, my_set); The predefined function `Set.size` returns the number of elements in a given set as follows. - - + + ```pascaligo group=sets const cardinal : nat = Set.size (my_set) @@ -450,18 +491,22 @@ const cardinal : nat = Set.size (my_set) > Note that `size` is *deprecated*. - + + ```cameligo group=sets let cardinal : nat = Set.size my_set ``` - + + + ```reasonligo group=sets let cardinal : nat = Set.size (my_set); ``` - + + ### Updating Sets @@ -469,9 +514,9 @@ let cardinal : nat = Set.size (my_set); There are two ways to update a set, that is to add or remove from it. - - + + In PascaLIGO, either we create a new set from the given one, or we modify it in-place. First, let us consider the former way: @@ -502,7 +547,8 @@ function update (var s : set (int)) : set (int) is block { const new_set : set (int) = update (my_set) ``` - + + In CameLIGO, we can use the predefined functions `Set.add` and `Set.remove`. We update a given set by creating another one, with or @@ -513,7 +559,8 @@ let larger_set : int set = Set.add 4 my_set let smaller_set : int set = Set.remove 3 my_set ``` - + + In ReasonLIGO, we can use the predefined functions `Set.add` and `Set.remove`. We update a given set by creating another one, with or @@ -523,7 +570,9 @@ without some elements. let larger_set : set (int) = Set.add (4, my_set); let smaller_set : set (int) = Set.remove (3, my_set); ``` - + + + ### Functional Iteration over Sets @@ -549,9 +598,9 @@ over sets is called `Set.iter`. In the following example, a set is iterated to check that all its elements (integers) are greater than `3`. - - + + ```pascaligo group=sets function iter_op (const s : set (int)) : unit is @@ -563,7 +612,8 @@ function iter_op (const s : set (int)) : unit is > Note that `set_iter` is *deprecated*. - + + ```cameligo group=sets let iter_op (s : int set) : unit = @@ -571,7 +621,8 @@ let iter_op (s : int set) : unit = in Set.iter predicate s ``` - + + ```reasonligo group=sets let iter_op = (s : set (int)) : unit => { @@ -580,7 +631,8 @@ let iter_op = (s : set (int)) : unit => { }; ``` - + + @@ -638,8 +690,9 @@ enables having a partial result that becomes complete when the traversal of the data structure is over. The predefined fold over sets is called `Set.fold`. - - + + + ```pascaligo group=sets function sum (const acc : int; const i : int): int is acc + i const sum_of_elements : int = Set.fold (sum, my_set, 0) @@ -658,15 +711,21 @@ function loop (const s : set (int)) : int is block { } with sum ``` - + + + ```cameligo group=sets let sum (acc, i : int * int) : int = acc + i let sum_of_elements : int = Set.fold sum my_set 0 ``` - + + + ```reasonligo group=sets let sum = ((acc, i) : (int, int)) : int => acc + i; let sum_of_elements : int = Set.fold (sum, my_set, 0); ``` - + + + diff --git a/gitlab-pages/docs/language-basics/strings.md b/gitlab-pages/docs/language-basics/strings.md index 9a4022998..be1e201c9 100644 --- a/gitlab-pages/docs/language-basics/strings.md +++ b/gitlab-pages/docs/language-basics/strings.md @@ -3,28 +3,40 @@ id: strings title: Strings --- +import Syntax from '@theme/Syntax'; + Strings are defined using the built-in `string` type like this: - - + + + ``` const a : string = "Hello Alice" ``` - + + + + ``` let a : string = "Hello Alice" ``` - + + + + ```reasonligo let a : string = "Hello Alice"; ``` - + + + ## Concatenating Strings - - + + + Strings can be concatenated using the `^` operator. ```pascaligo group=a @@ -32,7 +44,10 @@ const name : string = "Alice" const greeting : string = "Hello" const full_greeting : string = greeting ^ " " ^ name ``` - + + + + Strings can be concatenated using the `^` operator. ```cameligo group=a @@ -40,7 +55,10 @@ let name : string = "Alice" let greeting : string = "Hello" let full_greeting : string = greeting ^ " " ^ name ``` - + + + + Strings can be concatenated using the `++` operator. ```reasonligo group=a @@ -48,15 +66,18 @@ let name : string = "Alice"; let greeting : string = "Hello"; let full_greeting : string = greeting ++ " " ++ name; ``` - + + + ## Slicing Strings Strings can be sliced using a built-in function: - - + + + ```pascaligo group=b const name : string = "Alice" const slice : string = String.slice (0n, 1n, name) @@ -64,19 +85,24 @@ const slice : string = String.slice (0n, 1n, name) > Note that `string_slide` is *deprecated*. - + + + ```cameligo group=b let name : string = "Alice" let slice : string = String.slice 0n 1n name ``` - + + + ```reasonligo group=b let name : string = "Alice"; let slice : string = String.slice (0n, 1n, name); ``` - + + > ⚠️ Notice that the offset and length of the slice are natural > numbers. @@ -85,8 +111,9 @@ let slice : string = String.slice (0n, 1n, name); The length of a string can be found using a built-in function: - - + + + ```pascaligo group=c const name : string = "Alice" const length : nat = String.length (name) // length = 5 @@ -94,15 +121,21 @@ const length : nat = String.length (name) // length = 5 > Note that `size` is *deprecated*. - + + + ```cameligo group=c let name : string = "Alice" let length : nat = String.size name // length = 5 ``` - + + + ```reasonligo group=c let name : string = "Alice"; let length : nat = String.size (name); // length == 5 ``` - + + + diff --git a/gitlab-pages/docs/language-basics/tezos-specific.md b/gitlab-pages/docs/language-basics/tezos-specific.md index 99b980f44..a73698fd6 100644 --- a/gitlab-pages/docs/language-basics/tezos-specific.md +++ b/gitlab-pages/docs/language-basics/tezos-specific.md @@ -3,6 +3,8 @@ id: tezos-specific title: Tezos Domain-Specific Operations --- +import Syntax from '@theme/Syntax'; + LIGO is a programming language for writing Tezos smart contracts. It would be a little odd if it did not have any Tezos specific functions. This page will tell you about them. @@ -20,9 +22,10 @@ functionality can be accessed from within LIGO. > untrusted source or casting the result to the wrong type. Do not use > the corresponding LIGO functions without doing your homework first. - - + + + ```pascaligo group=a function id_string (const p : string) : option (string) is block { const packed : bytes = bytes_pack (p) @@ -31,14 +34,18 @@ function id_string (const p : string) : option (string) is block { > Note that `bytes_unpack` is *deprecated*. - + + + ```cameligo group=a let id_string (p : string) : string option = let packed: bytes = Bytes.pack p in (Bytes.unpack packed : string option) ``` - + + + ```reasonligo group=a let id_string = (p : string) : option (string) => { let packed : bytes = Bytes.pack (p); @@ -46,7 +53,8 @@ let id_string = (p : string) : option (string) => { }; ``` - + + ## Hashing Keys @@ -56,9 +64,10 @@ if this were not the case, hashes are much smaller than keys, and storage on blockchains comes at a cost premium. You can hash keys with a predefined functions returning a value of type `key_hash`. - - + + + ```pascaligo group=b function check_hash_key (const kh1 : key_hash; const k2 : key) : bool * key_hash is block { @@ -68,14 +77,18 @@ function check_hash_key (const kh1 : key_hash; const k2 : key) : bool * key_hash } with (ret, kh2) ``` - + + + ```cameligo group=b let check_hash_key (kh1, k2 : key_hash * key) : bool * key_hash = let kh2 : key_hash = Crypto.hash_key k2 in if kh1 = kh2 then true, kh2 else false, kh2 ``` - + + + ```reasonligo group=b let check_hash_key = ((kh1, k2) : (key_hash, key)) : (bool, key_hash) => { let kh2 : key_hash = Crypto.hash_key (k2); @@ -83,7 +96,8 @@ let check_hash_key = ((kh1, k2) : (key_hash, key)) : (bool, key_hash) => { }; ``` - + + ## Checking Signatures @@ -97,9 +111,10 @@ asynchronously. You can do this in LIGO using the `key` and > because that would require storing a private key on chain, at which > point it is not... private anymore. - - + + + ```pascaligo group=c function check_signature (const pk : key; @@ -110,20 +125,25 @@ function check_signature > Note that `crypto_check` is *deprecated*. - + + + ```cameligo group=c let check_signature (pk, signed, msg : key * signature * bytes) : bool = Crypto.check pk signed msg ``` - + + + ```reasonligo group=c let check_signature = ((pk, signed, msg) : (key, signature, bytes)) : bool => Crypto.check (pk, signed, msg); ``` - + + ## Contract's Own Address @@ -136,24 +156,29 @@ can do it with `Tezos.self_address`. > contract is only allowed at the top-level. Using it in an embedded > function will cause an error. - - + + + ```pascaligo group=d const current_addr : address = Tezos.self_address ``` - + + + ```cameligo group=d let current_addr : address = Tezos.self_address ``` - + + + ```reasonligo group=d let current_addr : address = Tezos.self_address; ``` - + ## Origination of a contract @@ -163,9 +188,8 @@ The return value is a pair of type `(operation * address)`. > ⚠️ Due to limitations in Michelson, `Tezos.create_contract` first argument > must be inlined and must not contain references to free variables - + - ```pascaligo group=e const origination : operation * address = Tezos.create_contract ( function (const p : nat; const s : string): list(operation) * string is ((nil : list(operation)), s), @@ -174,7 +198,9 @@ const origination : operation * address = Tezos.create_contract ( "initial_storage") ``` - + + + ```cameligo group=e let origination : operation * address = Tezos.create_contract (fun (p, s : nat * string) -> (([] : operation list), s)) @@ -183,7 +209,9 @@ let origination : operation * address = Tezos.create_contract "initial_storage" ``` - + + + ```reasonligo group=e let origination : (operation, address) = Tezos.create_contract ( ((p, s) : (nat,string)) : (list(operation),string) => (([] : list(operation)), s), @@ -192,4 +220,5 @@ let origination : (operation, address) = Tezos.create_contract ( "initial_storage") ``` - + + diff --git a/gitlab-pages/docs/language-basics/types.md b/gitlab-pages/docs/language-basics/types.md index 68b79357e..5a58aa0cb 100644 --- a/gitlab-pages/docs/language-basics/types.md +++ b/gitlab-pages/docs/language-basics/types.md @@ -3,6 +3,8 @@ id: types title: Types --- +import Syntax from '@theme/Syntax'; + *LIGO is strongly and statically typed.* This means that the compiler checks how your contract processes data. If it passes the test, your contract will not fail at run-time due to inconsistent assumptions on @@ -22,36 +24,41 @@ maintainability of your smart contracts. For example we can choose to alias a string type as an animal breed - this will allow us to comunicate our intent with added clarity. - - + + + ```pascaligo group=a type breed is string const dog_breed : breed = "Saluki" ``` - + + ```cameligo group=a type breed = string let dog_breed : breed = "Saluki" ``` - + + ```reasonligo group=a type breed = string; let dog_breed : breed = "Saluki"; ``` - + + > The above type definitions are aliases, which means that `breed` and > `string` are interchangable in all contexts. ## Simple types - - + + + ```pascaligo group=b // The type account_balances denotes maps from addresses to tez @@ -61,7 +68,9 @@ const ledger : account_balances = map [("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> 10mutez] ``` - + + + ```cameligo group=b // The type account_balances denotes maps from addresses to tez @@ -72,7 +81,9 @@ let ledger : account_balances = [(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), 10mutez)] ``` - + + + ```reasonligo group=b // The type account_balances denotes maps from addresses to tez @@ -83,7 +94,8 @@ let ledger: account_balances = ([("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, 10mutez)]); ``` - + + ## Structured types @@ -96,8 +108,9 @@ types as *fields* and index them with a *field name*. In the example below you can see the definition of data types for a ledger that keeps the balance and number of previous transactions for a given account. - - + + + ```pascaligo group=c // Type aliasing @@ -124,7 +137,9 @@ const my_ledger : ledger = map [ ] ``` - + + + ```cameligo group=c // Type aliasing @@ -147,7 +162,9 @@ let my_ledger : ledger = Map.literal {balance = 10mutez; transactions = 5n})] ``` - + + + ```reasonligo group=c // Type aliasing @@ -177,7 +194,8 @@ are dual because records are a product of types (types are bundled into a record), whereas variant types are a sum of types (they are exclusive to each other). - + + ## Annotations @@ -185,9 +203,10 @@ In certain cases, the type of an expression cannot be properly inferred by the compiler. In order to help the type checker, you can annotate an expression with its desired type. Here is an example: - - + + + ```pascaligo group=d type parameter is Back | Claim | Withdraw @@ -213,7 +232,9 @@ function back (var action : unit; var store : storage) : return is end with ((nil : list (operation)), store) // Annotation ``` - + + + ```cameligo group=d type parameter = Back | Claim | Withdraw @@ -239,7 +260,9 @@ let back (param, store : unit * storage) : return = | Some (x) -> no_op, store ``` - + + + ```reasonligo group=d type parameter = | Back | Claim | Withdraw; @@ -269,4 +292,5 @@ let back = ((param, store) : (unit, storage)) : return => { }; ``` - + + diff --git a/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md b/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md index 881e29d56..9ae8b34f3 100644 --- a/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md +++ b/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md @@ -3,6 +3,9 @@ id: unit-option-pattern-matching title: Unit, Option, Pattern matching --- +import Syntax from '@theme/Syntax'; + + Optionals are a pervasive programing pattern in OCaml. Since Michelson and LIGO are both inspired by OCaml, *optional types* are available in LIGO as well. Similarly, OCaml features a *unit* type, and LIGO @@ -16,15 +19,16 @@ The `unit` type in Michelson or LIGO is a predefined type that contains only one value that carries no information. It is used when no relevant information is required or produced. Here is how it used. - - + + In PascaLIGO, the unique value of the `unit` type is `Unit`. ```pascaligo group=a const n : unit = Unit // Note the capital letter ``` - + + In CameLIGO, the unique value of the `unit` type is `()`, following the OCaml convention. @@ -32,7 +36,8 @@ the OCaml convention. let n : unit = () ``` - + + In ReasonLIGO, the unique value of the `unit` type is `()`, following the OCaml convention. @@ -40,7 +45,8 @@ the OCaml convention. let n : unit = (); ``` - + + ## Variant types @@ -52,28 +58,35 @@ the enumerated types found in Java, C++, JavaScript etc. Here is how we define a coin as being either head or tail (and nothing else): - - + + + ```pascaligo group=b type coin is Head | Tail const head : coin = Head const tail : coin = Tail ``` - + + + ```cameligo group=b type coin = Head | Tail let head : coin = Head let tail : coin = Tail ``` - + + + ```reasonligo group=b type coin = Head | Tail; let head : coin = Head; let tail : coin = Tail; ``` - + + + The names `Head` and `Tail` in the definition of the type `coin` are called *data constructors*, or *variants*. In this particular, they @@ -84,9 +97,10 @@ In general, it is interesting for variants to carry some information, and thus go beyond enumerated types. In the following, we show how to define different kinds of users of a system. - - + + + ```pascaligo group=c type id is nat @@ -99,7 +113,9 @@ const u : user = Admin (1000n) const g : user = Guest ``` - + + + ```cameligo group=c type id = nat @@ -112,7 +128,9 @@ let u : user = Admin 1000n let g : user = Guest ``` - + + + ```reasonligo group=c type id = nat; @@ -125,7 +143,8 @@ let u : user = Admin (1000n); let g : user = Guest; ``` - + + In LIGO, a constant constructor is equivalent to the same constructor taking an argument of type `unit`, so, for example, `Guest` is the @@ -141,26 +160,32 @@ type would be `None`, otherwise `Some (v)`, where `v` is some meaningful value *of any type*. An example in arithmetic is the division operation: - - + + + ```pascaligo group=d function div (const a : nat; const b : nat) : option (nat) is if b = 0n then (None: option (nat)) else Some (a/b) ``` - + + + ```cameligo group=d let div (a, b : nat * nat) : nat option = if b = 0n then (None: nat option) else Some (a/b) ``` - + + + ```reasonligo group=d let div = ((a, b) : (nat, nat)) : option (nat) => if (b == 0n) { (None: option (nat)); } else { Some (a/b); }; ``` - + + ## Pattern matching @@ -170,8 +195,9 @@ Javascript, and can be used to route the program's control flow based on the value of a variant. Consider for example the definition of a function `flip` that flips a coin. - - + + + ```pascaligo group=e type coin is Head | Tail @@ -190,7 +216,9 @@ flip "Head" # Outputs: Tail(Unit) ``` - + + + ```cameligo group=e type coin = Head | Tail @@ -208,7 +236,9 @@ flip Head # Outputs: Tail(Unit) ``` - + + + ```reasonligo group=e type coin = | Head | Tail; @@ -227,4 +257,5 @@ flip Head # Outputs: Tail(Unit) ``` - + + diff --git a/gitlab-pages/docs/language-basics/variables-and-constants.md b/gitlab-pages/docs/language-basics/variables-and-constants.md index 8c8f48577..1194d6c23 100644 --- a/gitlab-pages/docs/language-basics/variables-and-constants.md +++ b/gitlab-pages/docs/language-basics/variables-and-constants.md @@ -3,6 +3,9 @@ id: constants-and-variables title: Constants & Variables --- +import Syntax from '@theme/Syntax'; + + The next building block after types are *constants* and *variables*. ## Constants @@ -12,8 +15,9 @@ reassigned. Put in another way, they can be assigned once, at their declaration. When defining a constant you need to provide a `name`, `type` and a `value`: - - + + + ```pascaligo group=a const age : int = 25 ``` @@ -24,7 +28,10 @@ command: ligo evaluate-value gitlab-pages/docs/language-basics/src/variables-and-constants/const.ligo age # Outputs: 25 ``` - + + + + ```cameligo group=a let age : int = 25 ``` @@ -36,7 +43,9 @@ ligo evaluate-value gitlab-pages/docs/language-basics/src/variables-and-constant # Outputs: 25 ``` - + + + ```reasonligo group=a let age : int = 25; ``` @@ -48,12 +57,13 @@ ligo evaluate-value gitlab-pages/docs/language-basics/src/variables-and-constant # Outputs: 25 ``` - + + ## Variables - - + + Variables, unlike constants, are *mutable*. They cannot be declared in a *global scope*, but they can be declared and used within functions, @@ -88,7 +98,8 @@ ligo run-function gitlab-pages/docs/language-basics/src/variables-and-constants/ # Outputs: 2 ``` - + + As expected in the pure subset of a functional language, CameLIGO only features *constant values*: once they are declared, the value cannot @@ -105,7 +116,9 @@ like this: ligo run-function gitlab-pages/docs/language-basics/src/variables-and-constants/add.mligo add '(1,1)' # Outputs: 2 ``` - + + + As expected in the pure subset of a functional language, ReasonLIGO only features *constant values*: once they are declared, the value @@ -125,4 +138,5 @@ ligo run-function gitlab-pages/docs/language-basics/src/variables-and-constants/ # Outputs: 2 ``` - + + diff --git a/gitlab-pages/docs/reference/big_map.md b/gitlab-pages/docs/reference/big_map.md index 57f222dc0..952275c1c 100644 --- a/gitlab-pages/docs/reference/big_map.md +++ b/gitlab-pages/docs/reference/big_map.md @@ -3,6 +3,8 @@ id: big-map-reference title: Big Maps — Scalable Maps --- +import Syntax from '@theme/Syntax'; + Ordinary maps are fine for contracts with a finite lifespan or a bounded number of users. For many contracts however, the intention is to have a map holding *many* entries, potentially millions of @@ -14,52 +16,67 @@ interface for big maps is analogous to the one used for ordinary maps. # Declaring a Map - - + + + ```pascaligo group=big_maps type move is int * int type register is big_map (address, move) ``` - + + + ```cameligo group=big_maps type move = int * int type register = (address, move) big_map ``` - + + + ```reasonligo group=big_maps type move = (int, int); type register = big_map (address, move); ``` - + + + # Creating an Empty Big Map - - + + + ```pascaligo group=big_maps const empty : register = big_map [] ``` - + + + ```cameligo group=big_maps let empty : register = Big_map.empty ``` - + + + ```reasonligo group=big_maps let empty : register = Big_map.empty ``` - + + + # Creating a Non-empty Map - - + + + ```pascaligo group=big_maps const moves : register = big_map [ @@ -67,7 +84,9 @@ const moves : register = ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] ``` - + + + ```cameligo group=big_maps let moves : register = Big_map.literal [ @@ -75,42 +94,54 @@ let moves : register = (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))] ``` - + + + ```reasonligo group=big_maps let moves : register = Big_map.literal ([ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]); ``` - + + + # Accessing Values - - + + + ```pascaligo group=big_maps const my_balance : option (move) = moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] ``` - + + + ```cameligo group=big_maps let my_balance : move option = Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves ``` - + + + ```reasonligo group=big_maps let my_balance : option (move) = Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves); ``` - + + + # Updating Big Maps - - + + + ```pascaligo group=big_maps function add (var m : register) : register is block { @@ -120,26 +151,33 @@ function add (var m : register) : register is const updated_map : register = add (moves) ``` - + + + ```cameligo group=big_maps let updated_map : register = Big_map.update ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves ``` - + + + ```reasonligo group=big_maps let updated_map : register = Big_map.update (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves); ``` - + + + # Removing Bindings - - + + + ```pascaligo group=big_maps function rem (var m : register) : register is block { @@ -149,16 +187,21 @@ function rem (var m : register) : register is const updated_map : register = rem (moves) ``` - + + + ```cameligo group=big_maps let updated_map : register = Map.remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves ``` - + + + ```reasonligo group=big_maps let updated_map : register = Map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves) ``` - + + diff --git a/gitlab-pages/docs/reference/bytes.md b/gitlab-pages/docs/reference/bytes.md index c585ffeed..dc8dc1aec 100644 --- a/gitlab-pages/docs/reference/bytes.md +++ b/gitlab-pages/docs/reference/bytes.md @@ -3,62 +3,67 @@ id: bytes-reference title: Bytes — Manipulate bytes data --- +import Syntax from '@theme/Syntax'; + ## Bytes.concat(b1: bytes, b2: bytes) : bytes Concatenate together two `bytes` arguments and return the result. - - - + ```pascaligo function concat_op (const s : bytes) : bytes is begin skip end with bytes_concat(s , 0x7070) ``` - + + ```cameligo let concat_op (s : bytes) : bytes = Bytes.concat s 0x7070 ``` - + + ```reasonligo let concat_op = (s: bytes): bytes => Bytes.concat(s, 0x7070); ``` - + ## Bytes.slice(pos1: nat, pos2: nat, data: bytes) : bytes Extract the bytes between `pos1` and `pos2`. **Positions are zero indexed and inclusive**. For example if you gave the input "ff7a7aff" to the following: - - + + ```pascaligo function slice_op (const s : bytes) : bytes is begin skip end with bytes_slice(1n , 2n , s) ``` - + + ```cameligo let slice_op (s : bytes) : bytes = Bytes.slice 1n 2n s ``` - + + ``` let slice_op = (s: bytes): bytes => Bytes.slice(1n, 2n, s); ``` - + + It would return "7a7a" rather than "ff7a" or "ff" or "7a". @@ -68,23 +73,28 @@ Converts Michelson data structures to a binary format for serialization. > ⚠️ `PACK` and `UNPACK` are features of Michelson that are intended to be used by people that really know what they're doing. There are several failure cases (such as `UNPACK`ing a lambda from an untrusted source), most of which are beyond the scope of this document. Don't use these functions without doing your homework first. - - + + + ```pascaligo function id_string (const p : string) : option(string) is block { const packed : bytes = bytes_pack(p) ; } with (bytes_unpack(packed): option(string)) ``` - + + + ```cameligo let id_string (p: string) : string option = let packed: bytes = Bytes.pack p in ((Bytes.unpack packed): string option) ``` - + + + ```reasonligo let id_string = (p: string) : option(string) => { let packed : bytes = Bytes.pack(p); @@ -92,7 +102,8 @@ let id_string = (p: string) : option(string) => { }; ``` - + + ## Bytes.unpack(packed: bytes) : a' @@ -101,23 +112,28 @@ serialization format to the `option` type annotated on the call. > ⚠️ `PACK` and `UNPACK` are features of Michelson that are intended to be used by people that really know what they're doing. There are several failure cases (such as `UNPACK`ing a lambda from an untrusted source), most of which are beyond the scope of this document. Don't use these functions without doing your homework first. - - + + + ```pascaligo function id_string (const p : string) : option(string) is block { const packed : bytes = bytes_pack(p) ; } with (bytes_unpack(packed): option(string)) ``` - + + + ```cameligo let id_string (p: string) : string option = let packed: bytes = Bytes.pack p in ((Bytes.unpack packed): string option) ``` - + + + ```reasonligo let id_string = (p: string) : option(string) => { let packed : bytes = Bytes.pack(p); @@ -125,4 +141,5 @@ let id_string = (p: string) : option(string) => { }; ``` - + + diff --git a/gitlab-pages/docs/reference/crypto.md b/gitlab-pages/docs/reference/crypto.md index e2b0511d2..49f5a9f02 100644 --- a/gitlab-pages/docs/reference/crypto.md +++ b/gitlab-pages/docs/reference/crypto.md @@ -3,93 +3,108 @@ id: crypto-reference title: Crypto — Cryptographic functions --- +import Syntax from '@theme/Syntax'; + ## Crypto.blake2b(data: bytes): bytes Runs the [blake2b hash algorithm](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2) over the given `bytes` data and returns a `bytes` representing the hash. - - + + ```pascaligo function hasherman_blake (const s: bytes) : bytes is blake2b(s) ``` - + + ```cameligo let hasherman_blake (s: bytes) : bytes = Crypto.blake2b s ``` - + + ```reasonligo let hasherman_blake = (s: bytes) => Crypto.blake2b(s); ``` - + + ## Crypto.sha256(data: bytes) : bytes Runs the [sha256 hash algorithm](https://en.wikipedia.org/wiki/SHA-2) over the given `bytes` data and returns a `bytes` representing the hash. - - + + + ```pascaligo function hasherman (const s : bytes) : bytes is begin skip end with sha_256(s) ``` - + + + ```cameligo let hasherman (s : bytes) : bytes = Crypto.sha256 s ``` - + + + ```reasonligo let hasherman = (s: bytes): bytes => Crypto.sha256(s); ``` - + + ## Crypto.sha512(data: bytes) : bytes Runs the [sha512 hash algorithm](https://en.wikipedia.org/wiki/SHA-2) over the given `bytes` data and returns a `bytes` representing the hash. - - + + ```pascaligo function hasherman512 (const s: bytes) : bytes is sha_512(s) ``` - + + ```cameligo let hasherman512 (s: bytes) : bytes = Crypto.sha512 s ``` - + + ```reasonligo let hasherman512 = (s: bytes) => Crypto.sha512(s); ``` - + + ## Crypto.hash_key(k: key) : key_hash Hashes a key for easy comparison and storage. - - + + + ```pascaligo function check_hash_key (const kh1 : key_hash; const k2 : key) : bool * key_hash is block { var ret : bool := False ; @@ -98,7 +113,9 @@ function check_hash_key (const kh1 : key_hash; const k2 : key) : bool * key_hash } with (ret, kh2) ``` - + + + ```cameligo let check_hash_key (kh1, k2: key_hash * key) : bool * key_hash = let kh2 : key_hash = Crypto.hash_key k2 in @@ -107,7 +124,9 @@ let check_hash_key (kh1, k2: key_hash * key) : bool * key_hash = else (false, kh2) ``` - + + + ```reasonligo let check_hash_key = ((kh1, k2): (key_hash, key)) : (bool, key_hash) => { let kh2 : key_hash = Crypto.hash_key(k2); @@ -120,7 +139,8 @@ let check_hash_key = ((kh1, k2): (key_hash, key)) : (bool, key_hash) => { }; ``` - + + ## Crypto.check(pk: key, signed: signature, data: bytes) : bool @@ -128,9 +148,10 @@ Check that a message has been signed by a particular key. > ⚠️ There is no way to *generate* a signed message in LIGO. This is because that would require storing a private key on chain, at which point it isn't very private anymore. - - + + + ```pascaligo function check_signature (const pk: key; @@ -139,17 +160,22 @@ function check_signature is crypto_check(pk, signed, msg) ``` - + + + ```cameligo let check_signature (pk, signed, msg: key * signature * bytes) : bool = Crypto.check pk signed msg ``` - + + + ```reasonligo let check_signature = ((pk, signed, msg): (key, signature, bytes)) : bool => { Crypto.check(pk, signed, msg); }; ``` - + + diff --git a/gitlab-pages/docs/reference/current.md b/gitlab-pages/docs/reference/current.md index 53fec4d7d..0b5cd7265 100644 --- a/gitlab-pages/docs/reference/current.md +++ b/gitlab-pages/docs/reference/current.md @@ -3,13 +3,16 @@ id: current-reference title: Tezos - Things relating to the current execution context --- +import Syntax from '@theme/Syntax'; + # Tezos.balance Get the balance for the contract. - - + + + ```pascaligo function main (const p : unit; const s: tez) : list (operation) * tez is ((nil : list (operation)), Tezos.balance) @@ -17,14 +20,18 @@ function main (const p : unit; const s: tez) : list (operation) * tez is > Note that `balance` and `Current.balance` are *deprecated*. - + + + ```cameligo let main (p,s : unit * tez) = ([] : operation list), Tezos.balance ``` > Note that `balance` and `Current.balance` are *deprecated*. - + + + ```reasonligo let main = ((p,s) : (unit, tez)) => ([]: list (operation), Tezos.balance); @@ -32,7 +39,8 @@ let main = ((p,s) : (unit, tez)) => > Note that `balance` and `Current.balance` are *deprecated*. - + + ## Tezos.now @@ -45,8 +53,9 @@ smart contracts like this: ### Examples #### 24 hours from now - - + + + ```pascaligo group=b const today: timestamp = Tezos.now; const one_day: int = 86_400; @@ -57,7 +66,9 @@ const one_day_later: timestamp = some_date + one_day; > Note that `now` is *deprecated*. - + + + ```cameligo group=b let today: timestamp = Tezos.now let one_day: int = 86_400 @@ -68,7 +79,9 @@ let one_day_later: timestamp = some_date + one_day > Note that `Current.time` is *deprecated*. - + + + ```reasonligo group=b let today: timestamp = Tezos.now; let one_day: int = 86_400; @@ -79,12 +92,14 @@ let one_day_later: timestamp = some_date + one_day; > Note that `Current.time` is *deprecated*. - + + #### 24 hours ago - - + + + ```pascaligo group=c const today: timestamp = Tezos.now; const one_day: int = 86_400; @@ -93,7 +108,9 @@ const in_24_hrs: timestamp = today - one_day; > Note that `now` is *deprecated*. - + + + ```cameligo group=c let today: timestamp = Tezos.now let one_day: int = 86_400 @@ -102,7 +119,9 @@ let in_24_hrs: timestamp = today - one_day > Note that `Current.time` is *deprecated*. - + + + ```reasonligo group=c let today: timestamp = Tezos.now; let one_day: int = 86_400; @@ -111,36 +130,43 @@ let in_24_hrs: timestamp = today - one_day; > Note that `Current.time` is *deprecated*. - + + #### Comparing Timestamps You can also compare timestamps using the same comparison operators as for numbers - - + + + ```pascaligo group=c const not_tommorow: bool = (Tezos.now = in_24_hrs) ``` > Note that `now` is *deprecated*. - + + + ```cameligo group=c let not_tomorrow: bool = (Tezos.now = in_24_hrs) ``` > Note that `Current.time` is *deprecated*. - + + + ```reasonligo group=c let not_tomorrow: bool = (Tezos.now == in_24_hrs); ``` > Note that `Current.time` is *deprecated*. - + + ## Amount @@ -148,9 +174,10 @@ let not_tomorrow: bool = (Tezos.now == in_24_hrs); Get the amount of tez provided by the sender to complete this transaction. - - + + + ```pascaligo function threshold (const p : unit) : int is if Tezos.amount = 100tz then 42 else 0 @@ -158,14 +185,18 @@ function threshold (const p : unit) : int is > Note that `amount` is *deprecated*. - + + + ```cameligo let threshold (p : unit) : int = if Tezos.amount = 100tz then 42 else 0 ``` > Note that `Current.amount` is *deprecated*. - + + + ```reasonligo let threshold = (p : unit) : int => if (Tezos.amount == 100tz) { 42; } else { 0; }; @@ -173,45 +204,53 @@ let threshold = (p : unit) : int => > Note that `Current.amount` is *deprecated*. - + + ## Sender Get the address that initiated the current transaction. - - + + + ```pascaligo function main (const p : unit) : address is Tezos.sender ``` > Note that `sender` is *deprecated*. - + + + ```cameligo let main (p: unit) : address = Tezos.sender ``` > Note that `Current.sender` is *deprecated*. - + + + ```reasonligo let main = (p : unit) : address => Tezos.sender; ``` > Note that `Current.sender` is *deprecated*. - + + ## Address Get the address associated with a value of type `contract`. - - + + + ```pascaligo function main (const p : key_hash) : address is block { const c : contract (unit) = Tezos.implicit_account (p) @@ -220,7 +259,9 @@ function main (const p : key_hash) : address is block { > Note that `implicit_account` and `address` are *deprecated*. - + + + ```cameligo let main (p : key_hash) = let c : unit contract = Tezos.implicit_account p @@ -230,7 +271,9 @@ let main (p : key_hash) = > Note that `Current.implicit_account` and `Current.address` are > *deprecated*. - + + + ```reasonligo let main = (p : key_hash) : address => { let c : contract (unit) = Tezos.implicit_account (p); @@ -241,36 +284,43 @@ let main = (p : key_hash) : address => { > Note that `Current.implicit_account` and `Current.address` are > *deprecated*. - + + ## Self Address Get the address of the currently running contract. - - + + + ```pascaligo function main (const p : unit) : address is Tezos.self_address ``` > Note that `self_address` is *deprecated*. - + + + ```cameligo let main (p : unit) : address = Tezos.self_address ``` > Note that `Current.self_address` is *deprecated*. - + + + ```reasonligo let main = (p : unit) : address => Tezos.self_address; ``` > Note that `Current.self_address` is *deprecated*. - + + ## Implicit Account @@ -278,9 +328,10 @@ Get the default contract associated with an on-chain key-pair. This contract does not execute code, instead it exists to receive tokens on behalf of a key's owner. - - + + + ```pascaligo function main (const kh: key_hash) : contract (unit) is Tezos.implicit_account (kh) @@ -288,14 +339,18 @@ function main (const kh: key_hash) : contract (unit) is > Note that `implicit_account` is *deprecated*. - + + + ```cameligo let main (kh : key_hash) : unit contract = Tezos.implicit_account kh ``` > Note that `Current.implicit_account` is *deprecated*. - + + + ```reasonligo let main = (kh : key_hash): contract (unit) => Tezos.implicit_account (kh); @@ -303,7 +358,8 @@ let main = (kh : key_hash): contract (unit) => > Note that `Current.implicit_account` is *deprecated*. - + + ## Source @@ -331,29 +387,36 @@ current transaction. > tezos-client to transfer to whatever KT1 delegates they had, even > if those KT1 were malicious scripts. - - + + + ```pascaligo function main (const p: unit) : address is Tezos.source ``` > Note that `source` is *deprecated*. - + + + ```cameligo let main (p : unit) : address = Tezos.source ``` > Note that `Current.source` is *deprecated*. - + + + ```reasonligo let main = (p : unit) : address => Tezos.source; ``` > Note that `Current.source` is *deprecated*. - + + + ## Failwith @@ -362,9 +425,10 @@ Cause the contract to fail with an error message. > ⚠ Using this currently requires in general a type annotation on the > `failwith` call. - - + + + ```pascaligo function main (const p : int; const s : unit) : list (operation) * unit is block { @@ -373,15 +437,20 @@ function main (const p : int; const s : unit) : list (operation) * unit is with ((nil : list (operation)), s) ``` - + + + ```cameligo let main (p,s : int * unit) = if p > 10 then failwith "Failure." ``` - + + + ```reasonligo let main = ((p,s) : (int, unit)) => if (p > 10) { failwith ("Failure."); }; ``` - + + diff --git a/gitlab-pages/docs/reference/list.md b/gitlab-pages/docs/reference/list.md index 96d733d50..cbded72e6 100644 --- a/gitlab-pages/docs/reference/list.md +++ b/gitlab-pages/docs/reference/list.md @@ -3,6 +3,8 @@ id: list-reference title: Lists — Linear Collections --- +import Syntax from '@theme/Syntax'; + Lists are linear collections of elements of the same type. Linear means that, in order to reach an element in a list, we must visit all the elements before (sequential access). Elements can be repeated, as @@ -13,52 +15,62 @@ think of a list a *stack*, where the top is written on the left. # Defining Lists - - + + + ```pascaligo group=lists const empty_list : list (int) = nil // Or list [] const my_list : list (int) = list [1; 2; 2] // The head is 1 ``` - + + + ```cameligo group=lists let empty_list : int list = [] let my_list : int list = [1; 2; 2] // The head is 1 ``` - + + + ```reasonligo group=lists let empty_list : list (int) = []; let my_list : list (int) = [1, 2, 2]; // The head is 1 ``` - + + # Adding to Lists Lists can be augmented by adding an element before the head (or, in terms of stack, by *pushing an element on top*). - - + + ```pascaligo group=lists const larger_list : list (int) = 5 # my_list // [5;1;2;2] ``` - + + ```cameligo group=lists let larger_list : int list = 5 :: my_list // [5;1;2;2] ``` - + + ```reasonligo group=lists let larger_list : list (int) = [5, ...my_list]; // [5,1,2,2] ``` - + + + # Functional Iteration over Lists @@ -78,9 +90,9 @@ The first, the *iterated operation*, is an iteration over the list with a unit return value. It is useful to enforce certain invariants on the element of a list, or fail. - - + + ```pascaligo group=lists function iter_op (const l : list (int)) : unit is @@ -92,8 +104,8 @@ function iter_op (const l : list (int)) : unit is > Note that `list_iter` is *deprecated*. - - + + ```cameligo group=lists let iter_op (l : int list) : unit = @@ -101,7 +113,8 @@ let iter_op (l : int list) : unit = in List.iter predicate l ``` - + + ```reasonligo group=lists let iter_op = (l : list (int)) : unit => { @@ -110,7 +123,8 @@ let iter_op = (l : list (int)) : unit => { }; ``` - + + ## Mapped Operation over Lists @@ -118,9 +132,9 @@ We may want to change all the elements of a given list by applying to them a function. This is called a *map operation*, not to be confused with the map data structure. - - + + ```pascaligo group=lists function increment (const i : int): int is i + 1 @@ -131,7 +145,8 @@ const plus_one : list (int) = List.map (increment, larger_list) > Note that `list_map` is *deprecated*. - + + ```cameligo group=lists let increment (i : int) : int = i + 1 @@ -140,7 +155,8 @@ let increment (i : int) : int = i + 1 let plus_one : int list = List.map increment larger_list ``` - + + ```reasonligo group=lists let increment = (i : int) : int => i + 1; @@ -148,7 +164,9 @@ let increment = (i : int) : int => i + 1; // Creates a new list with all elements incremented by 1 let plus_one : list (int) = List.map (increment, larger_list); ``` - + + + ## Folded Operation over Lists @@ -159,9 +177,9 @@ function takes two arguments: an *accumulator* and the structure enables having a partial result that becomes complete when the traversal of the data structure is over. - - + + ```pascaligo group=lists function sum (const acc : int; const i : int): int is acc + i @@ -170,42 +188,52 @@ const sum_of_elements : int = List.fold (sum, my_list, 0) > Note that `list_fold` is *deprecated*. - + + ```cameligo group=lists let sum (acc, i: int * int) : int = acc + i let sum_of_elements : int = List.fold sum my_list 0 ``` - + + ```reasonligo group=lists let sum = ((result, i): (int, int)): int => result + i; let sum_of_elements : int = List.fold (sum, my_list, 0); ``` - + + + # List Length Get the number of elements in a list. - - + + + ```pascaligo function size_of (const l : list (int)) : nat is List.length (l) ``` > Note that `size` is *deprecated*. - + + + ```cameligo let size_of (l : int list) : nat = List.length l ``` - + + + ```reasonligo let size_of = (l : list (int)) : nat => List.length (l); ``` - + + diff --git a/gitlab-pages/docs/reference/map.md b/gitlab-pages/docs/reference/map.md index df3ecbb31..d674f54e5 100644 --- a/gitlab-pages/docs/reference/map.md +++ b/gitlab-pages/docs/reference/map.md @@ -3,6 +3,8 @@ id: map-reference title: Maps --- +import Syntax from '@theme/Syntax'; + *Maps* are a data structure which associate values of the same type to values of the same type. The former are called *key* and the latter *values*. Together they make up a *binding*. An additional requirement @@ -11,51 +13,66 @@ sense. # Declaring a Map - - + + + ```pascaligo group=maps type move is int * int type register is map (address, move) ``` - + + + ```cameligo group=maps type move = int * int type register = (address, move) map ``` - + + + ```reasonligo group=maps type move = (int, int); type register = map (address, move); ``` - + + + # Creating an Empty Map - - + + + ```pascaligo group=maps const empty : register = map [] ``` - + + + ```cameligo group=maps let empty : register = Map.empty ``` - + + + ```reasonligo group=maps let empty : register = Map.empty ``` - + + + # Creating a Non-empty Map - - + + + ```pascaligo group=maps const moves : register = map [ @@ -63,7 +80,9 @@ const moves : register = ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] ``` - + + + ```cameligo group=maps let moves : register = Map.literal [ @@ -71,44 +90,56 @@ let moves : register = (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))] ``` - + + + ```reasonligo group=maps let moves : register = Map.literal ([ ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]); ``` - + + + # Accessing Map Bindings - - + + + ```pascaligo group=maps const my_balance : option (move) = moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] ``` - + + + ```cameligo group=maps let my_balance : move option = Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves ``` - + + + ```reasonligo group=maps let my_balance : option (move) = Map.find_opt (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), moves); ``` - + + + Notice how the value we read is an optional value: this is to force the reader to account for a missing key in the map. This requires *pattern matching*. - - + + + ```pascaligo group=maps function force_access (const key : address; const moves : register) : move is case moves[key] of @@ -117,7 +148,9 @@ function force_access (const key : address; const moves : register) : move is end ``` - + + + ```cameligo group=maps let force_access (key, moves : address * register) : move = match Map.find_opt key moves with @@ -125,7 +158,9 @@ let force_access (key, moves : address * register) : move = | None -> (failwith "No move." : move) ``` - + + + ```reasonligo group=maps let force_access = ((key, moves) : (address, register)) : move => { switch (Map.find_opt (key, moves)) { @@ -134,7 +169,9 @@ let force_access = ((key, moves) : (address, register)) : move => { } }; ``` - + + + # Updating a Map @@ -142,8 +179,9 @@ Given a map, we may want to add a new binding, remove one, or modify one by changing the value associated to an already existing key. All those operations are called *updates*. - - + + + ```pascaligo group=maps function assign (var m : register) : register is block { @@ -164,7 +202,9 @@ function assignments (var m : register) : register is } with m ``` - + + + ```cameligo group=maps let assign (m : register) : register = Map.update @@ -181,7 +221,9 @@ let add (m : register) : register = ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m ``` - + + + ```reasonligo group=maps let assign = (m : register) : register => Map.update @@ -199,13 +241,15 @@ let add = (m : register) : register => (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m); ``` - + + To remove a binding from a map, we need its key. - - + + + ```pascaligo group=maps function delete (const key : address; var moves : register) : register is block { @@ -213,19 +257,24 @@ function delete (const key : address; var moves : register) : register is } with moves ``` - + + + ```cameligo group=maps let delete (key, moves : address * register) : register = Map.remove key moves ``` - + + + ```reasonligo group=maps let delete = ((key, moves) : (address, register)) : register => Map.remove (key, moves); ``` - + + # Functional Iteration over Maps @@ -246,9 +295,9 @@ no return value: its only use is to produce side-effects. This can be useful if for example you would like to check that each value inside of a map is within a certain range, and fail with an error otherwise. - - + + ```pascaligo group=maps function iter_op (const m : register) : unit is @@ -260,7 +309,8 @@ function iter_op (const m : register) : unit is > Note that `map_iter` is *deprecated*. - + + ```cameligo group=maps let iter_op (m : register) : unit = @@ -268,7 +318,8 @@ let iter_op (m : register) : unit = in Map.iter predicate m ``` - + + ```reasonligo group=maps let iter_op = (m : register) : unit => { @@ -276,7 +327,9 @@ let iter_op = (m : register) : unit => { Map.iter (predicate, m); }; ``` - + + + ## Map Operations over Maps @@ -285,9 +338,9 @@ function. This is called a *map operation*, not to be confused with the map data structure. The predefined functional iterator implementing the map operation over maps is called `Map.map`. - - + + ```pascaligo group=maps function map_op (const m : register) : register is @@ -299,7 +352,8 @@ function map_op (const m : register) : register is > Note that `map_map` is *deprecated*. - + + ```cameligo group=maps let map_op (m : register) : register = @@ -307,7 +361,8 @@ let map_op (m : register) : register = in Map.map increment m ``` - + + ```reasonligo group=maps let map_op = (m : register) : register => { @@ -315,7 +370,9 @@ let map_op = (m : register) : register => { Map.map (increment, m); }; ``` - + + + ## Folded Operations over Maps @@ -325,9 +382,9 @@ function takes two arguments: an *accumulator* and the structure enables having a partial result that becomes complete when the traversal of the data structure is over. - - + + ```pascaligo group=maps function fold_op (const m : register) : int is @@ -339,14 +396,18 @@ function fold_op (const m : register) : int is > Note that `map_fold` is *deprecated*. - + + + ```cameligo group=maps let fold_op (m : register) : register = let folded = fun (i,j : int * (address * move)) -> i + j.1.1 in Map.fold folded m 5 ``` - + + + ```reasonligo group=maps let fold_op = (m : register) : register => { let folded = ((i,j): (int, (address, move))) => i + j[1][1]; @@ -354,4 +415,5 @@ let fold_op = (m : register) : register => { }; ``` - + + diff --git a/gitlab-pages/docs/reference/set.md b/gitlab-pages/docs/reference/set.md index c989df627..eca62a741 100644 --- a/gitlab-pages/docs/reference/set.md +++ b/gitlab-pages/docs/reference/set.md @@ -3,6 +3,8 @@ id: set-reference title: Sets — Unordered unique collection of a type --- +import Syntax from '@theme/Syntax'; + Sets are unordered collections of values of the same type, like lists are ordered collections. Like the mathematical sets and lists, sets can be empty and, if not, elements of sets in LIGO are *unique*, @@ -10,92 +12,122 @@ whereas they can be repeated in a *list*. # Empty Sets - - + + + ```pascaligo group=sets const my_set : set (int) = set [] ``` - + + + ```cameligo group=sets let my_set : int set = Set.empty ``` - + + + ```reasonligo group=sets let my_set : set (int) = Set.empty; ``` - + + + # Non-empty Sets - - + + + ```pascaligo group=sets const my_set : set (int) = set [3; 2; 2; 1] ``` - + + + ```cameligo group=sets let my_set : int set = Set.add 3 (Set.add 2 (Set.add 2 (Set.add 1 (Set.empty : int set)))) ``` - + + + ```reasonligo group=sets let my_set : set (int) = Set.add (3, Set.add (2, Set.add (2, Set.add (1, Set.empty : set (int))))); ``` - + + + # Set Membership - - + + + ```pascaligo group=sets const contains_3 : bool = my_set contains 3 ``` - + + + ```cameligo group=sets let contains_3 : bool = Set.mem 3 my_set ``` - + + + ```reasonligo group=sets let contains_3 : bool = Set.mem (3, my_set); ``` - + + + # Cardinal of Sets The predefined function `Set.size` returns the number of elements in a given set as follows. - - + + + ```pascaligo group=sets const cardinal : nat = Set.size (my_set) ``` > Note that `size` is *deprecated*. - + + + ```cameligo group=sets let cardinal : nat = Set.size my_set ``` - + + + + ```reasonligo group=sets let cardinal : nat = Set.size (my_set); ``` - + + + # Updating Sets There are two ways to update a set, that is to add or remove from it. - - + + + In PascaLIGO, either we create a new set from the given one, or we modify it in-place. First, let us consider the former way: ```pascaligo group=sets @@ -118,18 +150,24 @@ function update (var s : set (int)) : set (int) is block { const new_set : set (int) = update (my_set) ``` - + + + ```cameligo group=sets let larger_set : int set = Set.add 4 my_set let smaller_set : int set = Set.remove 3 my_set ``` - + + + ```reasonligo group=sets let larger_set : set (int) = Set.add (4, my_set); let smaller_set : set (int) = Set.remove (3, my_set); ``` - + + + # Functional Iteration over Sets @@ -149,8 +187,9 @@ no return value: its only use is to produce side-effects. This can be useful if for example you would like to check that each value inside of a map is within a certain range, and fail with an error otherwise. - - + + + ```pascaligo group=sets function iter_op (const s : set (int)) : unit is block { @@ -161,21 +200,27 @@ function iter_op (const s : set (int)) : unit is > Note that `set_iter` is *deprecated*. - + + + ```cameligo group=sets let iter_op (s : int set) : unit = let predicate = fun (i : int) -> assert (i > 3) in Set.iter predicate s ``` - + + + ```reasonligo group=sets let iter_op = (s : set (int)) : unit => { let predicate = (i : int) => assert (i > 3); Set.iter (predicate, s); }; ``` - + + + ## Folded Operation @@ -185,9 +230,10 @@ function takes two arguments: an *accumulator* and the structure enables having a partial result that becomes complete when the traversal of the data structure is over. - - + + + ```pascaligo group=sets function sum (const acc : int; const i : int): int is acc + i const sum_of_elements : int = Set.fold (sum, my_set, 0) @@ -206,15 +252,21 @@ function loop (const s : set (int)) : int is block { } with sum ``` - + + + ```cameligo group=sets let sum (acc, i : int * int) : int = acc + i let sum_of_elements : int = Set.fold sum my_set 0 ``` - + + + ```reasonligo group=sets let sum = ((acc, i) : (int, int)) : int => acc + i; let sum_of_elements : int = Set.fold (sum, my_set, 0); ``` - + + + diff --git a/gitlab-pages/docs/reference/string.md b/gitlab-pages/docs/reference/string.md index b29cdec54..c75e850a4 100644 --- a/gitlab-pages/docs/reference/string.md +++ b/gitlab-pages/docs/reference/string.md @@ -3,29 +3,37 @@ id: string-reference title: String — Manipulate string data --- +import Syntax from '@theme/Syntax'; + ## String.size(s: string) : nat Get the size of a string. [Michelson only supports ASCII strings](http://tezos.gitlab.io/whitedoc/michelson.html#constants) so for now you can assume that each character takes one byte of storage. - - + + + ```pascaligo function string_size (const s: string) : nat is size(s) ``` - + + + ```cameligo let size_op (s: string) : nat = String.size s ``` - + + + ```reasonligo let size_op = (s: string): nat => String.size(s); ``` - + + ## String.length(s: string) : nat @@ -36,20 +44,29 @@ Alias for `String.size`. Get the substring of `s` between `pos1` inclusive and `pos2` inclusive. For example the string "tata" given to the function below would return "at". - - + + + ```pascaligo function slice_op (const s : string) : string is string_slice(1n , 2n , s) ``` - + + + + ```cameligo let slice_op (s: string) : string = String.slice 1n 2n s ``` - + + + + ```reasonligo let slice_op = (s: string): string => String.slice(1n, 2n, s); ``` - + + + ## String.sub(pos1: nat, pos2: nat, s: string) : string @@ -59,21 +76,27 @@ Alias for `String.slice`. Concatenate two strings and return the result. - - + + + ```pascaligo function concat_op (const s : string) : string is s ^ "toto" ``` - + + + ```cameligo let concat_syntax (s: string) = s ^ "test_literal" ``` - + + + ```reasonligo let concat_syntax = (s: string) => s ++ "test_literal"; ``` - + + 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 2d02544d5..3d9330894 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 @@ -15,7 +15,7 @@ people have spent at his shop when buying tacos.
-
+
Icons made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY
@@ -23,6 +23,7 @@ people have spent at his shop when buying tacos. ## Analyzing the Current Contract ### **`taco-shop.ligo`** + ```pascaligo group=a type taco_supply is record [ current_stock : nat; @@ -128,6 +129,7 @@ const operations : list (operation) = list [payoutOperation]; ## Finalizing the Contract ### **`taco-shop.ligo`** + ```pascaligo group=b type taco_supply is record [ current_stock : nat; @@ -190,7 +192,7 @@ ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map [ ``` -
+
Operation(...bytes) included in the output
diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md index 48dfa29a5..986888889 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md @@ -16,7 +16,7 @@ consumers.
-
Made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY
+
Made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY
--- @@ -74,7 +74,7 @@ executable** through the installation script, as shown in the screenshot below: -
Installing the next version of LIGO's CLI
+
Installing the next version of LIGO's CLI
## Implementing our First `main` Function @@ -90,6 +90,7 @@ contract, but it is something to get us started and test our LIGO installation as well. ### `taco-shop.ligo` + ```pascaligo group=a function main (const parameter : int; const contractStorage : int) : list (operation) * int is @@ -150,7 +151,7 @@ ligo dry-run taco-shop.ligo --syntax pascaligo main 4 3 ``` -
Simulating contract execution with the CLI
+
Simulating contract execution with the CLI

@@ -167,6 +168,7 @@ fields. Additionally, we will want to combine our `taco_supply` type into a map, consisting of the entire offer of Pedro's shop. **Taco shop's storage** + ```pascaligo group=b type taco_supply is record [ current_stock : nat; @@ -181,6 +183,7 @@ Next step is to update the `main` function to include `parameter` to `unit` as well to clear things up. **`taco-shop.ligo`** + ```pascaligo group=b+ type taco_supply is record [ current_stock : nat; @@ -204,6 +207,7 @@ initial storage value. In our case the storage is type-checked as our storage's value will be defined as follows: **Storage value** + ```zsh map [ 1n -> record [ @@ -221,6 +225,7 @@ map [ > by their keys `1n` and `2n`. **Dry run command with a multi-line storage value** + ```zsh ligo dry-run taco-shop.ligo --syntax pascaligo main unit "map [ 1n -> record [ @@ -235,7 +240,7 @@ ligo dry-run taco-shop.ligo --syntax pascaligo main unit "map [ ``` -
Dry-run with a complex storage value
+
Dry-run with a complex storage value

@@ -264,6 +269,7 @@ Let is start by customizing our contract a bit, we will: we will want to modify it **`taco-shop.ligo`** + ```pascaligo group=c type taco_supply is record [ current_stock : nat; @@ -320,7 +326,7 @@ function buy_taco (const taco_kind_index : nat; var taco_shop_storage : taco_sho ``` -
Stock decreases after selling a taco
+
Stock decreases after selling a taco

@@ -341,6 +347,7 @@ To make sure we get paid, we will: the payment accepted **`taco-shop.ligo`** + ```pascaligo group=e type taco_supply is record [ current_stock : nat; @@ -394,14 +401,14 @@ ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map [ ** Purchasing a Taco with 1tez ** -
Stock decreases after selling a taco, if the right amount of tezzies is provided
+
Stock decreases after selling a taco, if the right amount of tezzies is provided

**Attempting to Purchase a Taco with 0.7tez** -
Stock does not decrease after a purchase attempt +
Stock does not decrease after a purchase attempt with an insufficient payment.

@@ -416,11 +423,13 @@ If you would like to accept tips in your contract, simply change the following line, depending on your preference. **Without tips** + ```pascaligo skip if amount =/= current_purchase_price then ``` **With tips** + ```pascaligo skip if amount >= current_purchase_price then ``` diff --git a/gitlab-pages/website/.gitignore b/gitlab-pages/website/.gitignore new file mode 100644 index 000000000..1b34df512 --- /dev/null +++ b/gitlab-pages/website/.gitignore @@ -0,0 +1,20 @@ +# dependencies +/node_modules + +# production +/build + +# generated files +.docusaurus +.cache-loader + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* \ No newline at end of file diff --git a/gitlab-pages/website/blog/2019-06-13-public-launch-of-ligo.md b/gitlab-pages/website/blog/2019-06-13-public-launch-of-ligo.md.old similarity index 100% rename from gitlab-pages/website/blog/2019-06-13-public-launch-of-ligo.md rename to gitlab-pages/website/blog/2019-06-13-public-launch-of-ligo.md.old diff --git a/gitlab-pages/website/blog/2019-07-11-ligo-update.md b/gitlab-pages/website/blog/2019-07-11-ligo-update.md.old similarity index 100% rename from gitlab-pages/website/blog/2019-07-11-ligo-update.md rename to gitlab-pages/website/blog/2019-07-11-ligo-update.md.old diff --git a/gitlab-pages/website/core/CodeExamples.js b/gitlab-pages/website/core/CodeExamples.js index 9cdf27c1c..289d14a73 100644 --- a/gitlab-pages/website/core/CodeExamples.js +++ b/gitlab-pages/website/core/CodeExamples.js @@ -1,8 +1,12 @@ -const React = require('react'); +import React from 'react'; +import Highlight, { defaultProps } from "prism-react-renderer"; +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import useThemeContext from '@theme/hooks/useThemeContext'; +import defaultTheme from 'prism-react-renderer/themes/palenight'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; -const pre = '```'; - -const PASCALIGO_EXAMPLE = `${pre}pascaligo +const PASCALIGO_EXAMPLE = ` type storage is int type parameter is @@ -14,8 +18,11 @@ type return is list (operation) * storage // Two entrypoints -function add (const store : storage; const delta : int) : storage is store + delta -function sub (const store : storage; const delta : int) : storage is store - delta +function add (const store : storage; const delta : int) : storage is + store + delta + +function sub (const store : storage; const delta : int) : storage is + store - delta (* Main access point that dispatches to the entrypoints according to the smart contract parameter. *) @@ -27,9 +34,9 @@ function main (const action : parameter; const store : storage) : return is | Decrement (n) -> sub (store, n) | Reset -> 0 end) -${pre}`; +`; -const CAMELIGO_EXAMPLE = `${pre}ocaml +const CAMELIGO_EXAMPLE = ` type storage = int type parameter = @@ -53,10 +60,10 @@ let main (action, store : parameter * storage) : return = Increment (n) -> add (store, n) | Decrement (n) -> sub (store, n) | Reset -> 0) -${pre}`; +`; -const REASONLIGO_EXAMPLE = `${pre}reasonligo +const REASONLIGO_EXAMPLE = ` type storage = int; type parameter = @@ -81,40 +88,82 @@ let main = ((action, store) : (parameter, storage)) : return => { | Decrement (n) => sub ((store, n)) | Reset => 0})) }; -${pre}`; +`; -module.exports = props => { - const MarkdownBlock = props.MarkdownBlock; +function CodeExamples (props) { + const { + siteConfig: { + themeConfig: {prism = {}}, + }, + } = useDocusaurusContext(); + const {isDarkTheme} = useThemeContext(); + const lightModeTheme = prism.theme || defaultTheme; + const darkModeTheme = prism.darkTheme || lightModeTheme; + const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme; return ( -
-
-
- PascaLIGO -
-
- CameLIGO -
-
- ReasonLIGO -
-
-
-
- {PASCALIGO_EXAMPLE} -
-
- {CAMELIGO_EXAMPLE} -
-
- {REASONLIGO_EXAMPLE} -
-
-
+ + + + + {({ className, style, tokens, getLineProps, getTokenProps }) => ( +
+                {tokens.map((line, i) => (
+                  
+ {line.map((token, key) => ( + + ))} +
+ ))} +
+ )} +
+
+ + + + {({ className, style, tokens, getLineProps, getTokenProps }) => ( +
+                {tokens.map((line, i) => (
+                  
+ {line.map((token, key) => ( + + ))} +
+ ))} +
+ )} +
+
+ + + + {({ className, style, tokens, getLineProps, getTokenProps }) => ( +
+                {tokens.map((line, i) => (
+                  
+ {line.map((token, key) => ( + + ))} +
+ ))} +
+ )} +
+
+ + + +
); }; + +export default CodeExamples \ No newline at end of file diff --git a/gitlab-pages/website/core/Footer.js b/gitlab-pages/website/core/Footer.js index c40de4b0a..3aae1cda0 100644 --- a/gitlab-pages/website/core/Footer.js +++ b/gitlab-pages/website/core/Footer.js @@ -1,3 +1,5 @@ +// deprecated. + const React = require('react'); const docUrl = require(`${process.cwd()}/core/UrlUtils`).docUrl; diff --git a/gitlab-pages/website/docusaurus.config.js b/gitlab-pages/website/docusaurus.config.js new file mode 100644 index 000000000..d94dd362b --- /dev/null +++ b/gitlab-pages/website/docusaurus.config.js @@ -0,0 +1,226 @@ + +const repoUrl = 'https://gitlab.com/ligolang/ligo'; + +// let reasonHighlightJs = require('reason-highlightjs'); + +const siteConfig = { + title: 'LIGO', // Title for your website. + tagline: 'LIGO is a friendly smart contract language for Tezos', + // taglineSub: 'Michelson was never so easy', + url: 'https://ligolang.org', // Your website URL + baseUrl: '/', // Base URL for your project */ + // For github.io type URLs, you would set the url and baseUrl like: + // url: 'https://facebook.github.io', + // baseUrl: '/test-site/', + + // Used for publishing and more + projectName: 'ligo', + organizationName: 'TBN', + // For top-level user or org sites, the organization is still the same. + // e.g., for the https://JoelMarcey.github.io site, it would be set like... + // organizationName: 'JoelMarcey' + + // For no header links in the top nav bar -> headerLinks: [], + + + // footerLinks: { + // docs: [ + // { doc: 'intro/installation', label: 'Install' }, + // { doc: 'api/cli-commands', label: 'CLI Commands' }, + // { doc: 'contributors/origin', label: 'Contribute' }, + // { href: '/odoc', label: 'API Documentation' } + // ], + // community: [ + // { + // href: 'https://forum.tezosagora.org/tag/ligo', + // label: 'Tezos Agora Forum', + // blankTarget: true + // }, + // { + // href: 'https://tezos.stackexchange.com/questions/tagged/ligo', + // label: 'Tezos Stack Exchange', + // blankTarget: true + // }, + // { + // href: 'https://t.me/LigoLang', + // label: 'Telegram', + // blankTarget: true + // }, + // { + // href: 'https://discord.gg/9rhYaEt', + // label: 'Discord', + // blankTarget: true + // } + // ], + // more: [ + // { + // doc: 'tutorials/get-started/tezos-taco-shop-smart-contract', + // label: 'Tutorials' + // }, + // { href: repoUrl, label: 'GitLab' } + // ] + // }, + + favicon: 'img/circle.svg', + + /* highlight: { + // Highlight.js theme to use for syntax highlighting in code blocks. + theme: 'default', + hljs: function (hljs) { + hljs.registerLanguage('reasonligo', reasonHighlightJs); + hljs.registerLanguage('pascaligo', function (hljs) { + return { + // case_insensitive: true, + beginKeywords: '', + keywords: { + keyword: + 'and attributes begin big_map block case const contains else' + + ' end False for from function if in is list map mod nil' + + ' not of or patch record remove set skip then to True type' + + ' var while with', + literal: 'true false unit int string Some None bool nat list' + }, + lexemes: '[a-zA-Z][a-zA-Z0-9_]*', + contains: [ + hljs.C_LINE_COMMENT_MODE, + + { + className: 'type', + begin: /[A-Z][a-z]+/ + }, + { + begin: /[*+-:;\(\)\{\}|\>\<]/ + // className: 'ignore' + } + ] + }; + }); + } + },*/ + + // Add custom scripts here that would be placed in