From 0ce2a603a347ac37b064b8ba2e0ab141add1367c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Sun, 9 Feb 2020 00:19:43 +0100 Subject: [PATCH 01/19] Fix "hanging sudo" bug. --- scripts/installer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 scripts/installer.sh diff --git a/scripts/installer.sh b/scripts/installer.sh old mode 100755 new mode 100644 index c8623c6a7..ca7c17b83 --- a/scripts/installer.sh +++ b/scripts/installer.sh @@ -62,7 +62,7 @@ else # && redirect the output of the wget download to the temporary file # ) || clean up temporary file if any command in the previous block failed - wget "$url" -O - \ + (wget "$url" -O - 2>/dev/null || echo "ERROR: wget $url failed.") \ | sed -e "s/next/$version/g" \ | sudo sh -c ' \ ( \ From 541728fc6c9263d0a92606cc8f456214062ff2cc Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Mon, 10 Feb 2020 19:27:58 +0100 Subject: [PATCH 02/19] First batch of rewritten contracts (PascaLIGO). --- src/passes/operators/operators.ml | 4 +- src/test/contracts/address.ligo | 6 +- src/test/contracts/annotation.ligo | 2 +- src/test/contracts/application.ligo | 22 +- src/test/contracts/arithmetic.ligo | 21 +- src/test/contracts/assign.ligo | 6 +- src/test/contracts/attributes.ligo | 12 +- src/test/contracts/bad_timestamp.ligo | 10 +- src/test/contracts/bad_type_operator.ligo | 11 +- src/test/contracts/balance_constant.ligo | 11 +- src/test/contracts/big_map.ligo | 39 ++- src/test/contracts/bitwise_arithmetic.ligo | 9 +- src/test/contracts/blockless.ligo | 3 +- src/test/contracts/boolean_operators.ligo | 15 +- src/test/contracts/bytes_arithmetic.ligo | 9 +- src/test/contracts/bytes_unpack.ligo | 18 +- src/test/contracts/chain_id.ligo | 6 +- src/test/contracts/check_signature.ligo | 6 +- src/test/contracts/closure-1.ligo | 5 +- src/test/contracts/closure-2.ligo | 9 +- src/test/contracts/closure-3.ligo | 16 +- src/test/contracts/closure.ligo | 8 +- src/test/contracts/coase.ligo | 161 +++++----- src/test/contracts/condition-simple.ligo | 11 +- src/test/contracts/condition.ligo | 20 +- src/test/contracts/counter.ligo | 9 +- src/test/contracts/crypto.ligo | 4 +- src/test/contracts/declaration-local.ligo | 2 +- src/test/contracts/declarations.ligo | 7 +- src/test/contracts/deep_access.ligo | 52 ++-- src/test/contracts/dispatch-counter.ligo | 27 +- src/test/contracts/double_main.ligo | 17 +- src/test/contracts/empty_case.ligo | 16 +- src/test/contracts/entrypoints.ligo | 23 +- src/test/contracts/evaluation_tests.ligo | 12 +- src/test/contracts/failwith.ligo | 58 ++-- src/test/contracts/for_fail.ligo | 11 +- src/test/contracts/function-complex.ligo | 12 +- src/test/contracts/function-shared.ligo | 9 +- src/test/contracts/function.ligo | 5 +- src/test/contracts/get_contract.ligo | 21 +- src/test/contracts/heap-instance.ligo | 6 +- src/test/contracts/heap.ligo | 156 +++++----- src/test/contracts/high-order.ligo | 36 +-- src/test/contracts/implicit_account.ligo | 2 +- src/test/contracts/isnat.ligo | 3 +- src/test/contracts/key_hash.ligo | 12 +- src/test/contracts/lambda.ligo | 8 +- src/test/contracts/list.ligo | 60 ++-- src/test/contracts/loop.ligo | 329 ++++++++++---------- src/test/contracts/map.ligo | 72 ++--- src/test/contracts/match.ligo | 28 +- src/test/contracts/multiple-parameters.ligo | 16 +- src/test/contracts/multisig-v2.ligo | 218 +++++++------ src/test/contracts/multisig.ligo | 82 ++--- 55 files changed, 862 insertions(+), 891 deletions(-) diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 49f693030..df11d2400 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -32,7 +32,7 @@ module Simplify = struct - The left-hand-side is the reserved name in the given front-end. - The right-hand-side is the name that will be used in the AST. *) - let unit_expr = make_t @@ T_constant TC_unit + let unit_expr = make_t @@ T_constant TC_unit let type_constants s = match s with @@ -1157,7 +1157,7 @@ module Compiler = struct | C_CONCAT -> ok @@ simple_binary @@ prim I_CONCAT | C_CHAIN_ID -> ok @@ simple_constant @@ prim I_CHAIN_ID | _ -> simple_fail @@ Format.asprintf "operator not implemented for %a" Stage_common.PP.constant c - + (* Some complex operators will need to be added in compiler/compiler_program. diff --git a/src/test/contracts/address.ligo b/src/test/contracts/address.ligo index 2113bc7ac..59d5bff4c 100644 --- a/src/test/contracts/address.ligo +++ b/src/test/contracts/address.ligo @@ -1,5 +1,5 @@ -// function main (const c: contract(unit)) : address is address(c) +// 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) = implicit_account (p); +} with address (c) \ No newline at end of file diff --git a/src/test/contracts/annotation.ligo b/src/test/contracts/annotation.ligo index 58fd3e8bc..aaff23336 100644 --- a/src/test/contracts/annotation.ligo +++ b/src/test/contracts/annotation.ligo @@ -1,6 +1,6 @@ (* Test that a string is cast to an address given a type annotation *) -const lst : list(int) = list [] +const lst : list (int) = list [] const my_address : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) diff --git a/src/test/contracts/application.ligo b/src/test/contracts/application.ligo index 32a92701d..a36e86391 100644 --- a/src/test/contracts/application.ligo +++ b/src/test/contracts/application.ligo @@ -1,21 +1,13 @@ // Test different ways of calling functions in PascaLIGO -type foo is record - bar : int -> int ; -end +type foo is record [bar : int -> int] -function f (const i : int) : int is - begin - skip - end with i +function f (const i : int) : int is i -function g (const i : unit) : int -> int is - begin skip end with f +function g (const i : unit) : int -> int is f -const r : foo = record - bar = f ; -end +const r : foo = record [bar = f] -const x : int = f(42) -const y : int = r.bar(42) -const z : int = (g(unit))(42) +const x : int = f (42) +const y : int = r.bar (42) +const z : int = (g (unit))(42) diff --git a/src/test/contracts/arithmetic.ligo b/src/test/contracts/arithmetic.ligo index 1040aeebf..de3dc14ae 100644 --- a/src/test/contracts/arithmetic.ligo +++ b/src/test/contracts/arithmetic.ligo @@ -1,22 +1,15 @@ // Test PascaLIGO arithmetic operators -function mod_op (const n : int) : nat is - begin skip end with n mod 42 +function mod_op (const n : int) : nat is n mod 42 -function plus_op (const n : int) : int is - begin skip end with n + 42 +function plus_op (const n : int) : int is n + 42 -function minus_op (const n : int) : int is - begin skip end with n - 42 +function minus_op (const n : int) : int is n - 42 -function times_op (const n : int) : int is - begin skip end with n * 42 +function times_op (const n : int) : int is n * 42 -function div_op (const n : int) : int is - begin skip end with n / 2 +function div_op (const n : int) : int is n / 2 -function int_op (const n : nat) : int is - block { skip } with int(n) +function int_op (const n : nat) : int is int (n) -function neg_op (const n : int) : int is - begin skip end with -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 d882d0e40..6c6de5351 100644 --- a/src/test/contracts/assign.ligo +++ b/src/test/contracts/assign.ligo @@ -1,4 +1,4 @@ function main (const i : int) : int is - begin - i := i + 1 ; - end with i + block { + i := i + 1 + } with i diff --git a/src/test/contracts/attributes.ligo b/src/test/contracts/attributes.ligo index 561e8f5ff..2248d31be 100644 --- a/src/test/contracts/attributes.ligo +++ b/src/test/contracts/attributes.ligo @@ -1,19 +1,19 @@ const x : int = 1; attributes ["inline"] function foo (const a : int) : int is - begin + block { const test : int = 2 + a; attributes ["inline"]; - end with test; + } with test; attributes ["inline"]; const y : int = 1; attributes ["inline"; "other"] function bar (const b : int) : int is - begin + block { function test (const z : int) : int is - begin + block { const r : int = 2 + b + z - end with r; + } with r; attributes ["inline"; "foo"; "bar"] - end with test(b) + } with test (b) diff --git a/src/test/contracts/bad_timestamp.ligo b/src/test/contracts/bad_timestamp.ligo index 42850560d..8be6968e2 100644 --- a/src/test/contracts/bad_timestamp.ligo +++ b/src/test/contracts/bad_timestamp.ligo @@ -1,7 +1,9 @@ -type storage_ is timestamp +type parameter is unit +type storage is timestamp +type return is list (operation) * storage -function main(const p : unit; const s : storage_) : list(operation) * storage_ is +function main (const p : parameter; const s : storage) : return is block { - var toto : timestamp := ("badtimestamp" : timestamp); + var stamp : timestamp := ("badtimestamp" : timestamp) } - with ((nil: list(operation)), toto) \ No newline at end of file + with ((nil: list(operation)), stamp) diff --git a/src/test/contracts/bad_type_operator.ligo b/src/test/contracts/bad_type_operator.ligo index eff64ad66..328cf2f1e 100644 --- a/src/test/contracts/bad_type_operator.ligo +++ b/src/test/contracts/bad_type_operator.ligo @@ -1,4 +1,9 @@ -type t is (nat * nat) -type s is map(t) +type parameter is unit -function main (const u : unit; const s : s) : (list(operation) * s) is ((nil : list(operation)), s) +type binding is nat * nat +type storage is map (binding) + +type return is list (operation) * storage + +function main (const param : parameter; const store : storage) : return is + ((nil : list (operation)), store) diff --git a/src/test/contracts/balance_constant.ligo b/src/test/contracts/balance_constant.ligo index cbe69d3c1..6a5af3fe4 100644 --- a/src/test/contracts/balance_constant.ligo +++ b/src/test/contracts/balance_constant.ligo @@ -1,11 +1,12 @@ -(** - +(* This test makes sure that the balance is accessible in PascaLIGO. -It's there to detect a regression of: https://gitlab.com/ligolang/ligo/issues/68 +It is meant to detect the regression detailled in the following issue: https://gitlab.com/ligolang/ligo/issues/68 *) +type parameter is unit type storage is tez +type return is list (operation) * storage -function main (const p : unit; const s: tez) : list(operation) * storage is - ((nil : list(operation)), balance) +function main (const param : parameter; const store: storage) : return is + ((nil : list (operation)), balance) diff --git a/src/test/contracts/big_map.ligo b/src/test/contracts/big_map.ligo index e6ab78c58..1a6dcfab0 100644 --- a/src/test/contracts/big_map.ligo +++ b/src/test/contracts/big_map.ligo @@ -1,36 +1,35 @@ -type storage_ is big_map(int, int) * unit -type foo is big_map(int, int) +type parameter is unit +type storage is big_map (int, int) * unit +type return is list (operation) * storage -function main(const p : unit; const s : storage_) : list(operation) * storage_ is +function main (const p : parameter; const s : storage) : return is block { - var toto : option (int) := Some(0); + var toto : option (int) := Some (0); toto := s.0[23]; - s.0[2] := 444; + s.0[2] := 444 } with ((nil: list(operation)), s) -function set_ (var n : int ; var m : foo) : foo is block { - m[23] := n ; +type foo is big_map (int, int) + +function set_ (var n : int; var m : foo) : foo is block { + m[23] := n } with m function rm (var m : foo) : foo is block { - remove 42 from map m; + remove 42 from map m } with m -function gf (const m : foo) : int is begin skip end with get_force(23, m) +function gf (const m : foo) : int is get_force (23, m) -function get (const m : foo) : option(int) is begin skip end with m[42] +function get (const m : foo) : option (int) is m[42] -const empty_big_map : big_map(int,int) = big_map end +const empty_big_map : big_map (int,int) = big_map [] -const big_map1 : big_map(int,int) = big_map - 23 -> 0 ; - 42 -> 0 ; -end +const big_map1 : big_map (int,int) = big_map [23 -> 0; 42 -> 0] -function mutimaps (const m : foo ; const n : foo) : foo is block -{ - var bar : foo := m ; - bar[42] := 0 ; - n[42] := get_force(42, bar) ; +function mutimaps (const m : foo; const n : foo) : foo is block { + var bar : foo := m; + bar[42] := 0; + n[42] := get_force (42, bar) } with n diff --git a/src/test/contracts/bitwise_arithmetic.ligo b/src/test/contracts/bitwise_arithmetic.ligo index 282b82be9..5e814c2c0 100644 --- a/src/test/contracts/bitwise_arithmetic.ligo +++ b/src/test/contracts/bitwise_arithmetic.ligo @@ -1,10 +1,7 @@ // Test PascaLIGO bitwise operators -function or_op (const n : nat) : nat is - begin skip end with bitwise_or(n , 4n) +function or_op (const n : nat) : nat is bitwise_or (n, 4n) -function and_op (const n : nat) : nat is - begin skip end with bitwise_and(n , 7n) +function and_op (const n : nat) : nat is bitwise_and (n, 7n) -function xor_op (const n : nat) : nat is - begin skip end with bitwise_xor(n , 7n) +function xor_op (const n : nat) : nat is bitwise_xor (n, 7n) diff --git a/src/test/contracts/blockless.ligo b/src/test/contracts/blockless.ligo index 103b926f0..94dddc8dd 100644 --- a/src/test/contracts/blockless.ligo +++ b/src/test/contracts/blockless.ligo @@ -1,2 +1 @@ -function blockless (const n: int) : int is - n + 10; +function blockless (const n : int) : int is n + 10 diff --git a/src/test/contracts/boolean_operators.ligo b/src/test/contracts/boolean_operators.ligo index 0d88c0f03..122894d25 100644 --- a/src/test/contracts/boolean_operators.ligo +++ b/src/test/contracts/boolean_operators.ligo @@ -1,16 +1,11 @@ // Test PascaLIGO boolean operators -function or_true (const b : bool) : bool is - begin skip end with b or True +function or_true (const b : bool) : bool is b or True -function or_false (const b : bool) : bool is - begin skip end with b or False +function or_false (const b : bool) : bool is b or False -function and_true (const b : bool) : bool is - begin skip end with b and True +function and_true (const b : bool) : bool is b and True -function and_false (const b : bool) : bool is - begin skip end with b and False +function and_false (const b : bool) : bool is b and False -function not_bool (const b: bool) : bool is - begin skip end with 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 8b9251f93..6d39dd4c9 100644 --- a/src/test/contracts/bytes_arithmetic.ligo +++ b/src/test/contracts/bytes_arithmetic.ligo @@ -1,8 +1,5 @@ -function concat_op (const s : bytes) : bytes is - begin skip end with bytes_concat(s , 0x7070) +function concat_op (const s : bytes) : bytes is bytes_concat (s, 0x7070) -function slice_op (const s : bytes) : bytes is - begin skip end with bytes_slice(1n , 2n , s) +function slice_op (const s : bytes) : bytes is bytes_slice (1n, 2n, s) -function hasherman (const s : bytes) : bytes is - begin skip end with sha_256(s) +function hasherman (const s : bytes) : bytes is sha_256 (s) diff --git a/src/test/contracts/bytes_unpack.ligo b/src/test/contracts/bytes_unpack.ligo index c6b087635..e57ace2ab 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)) +function id_string (const p : string) : option (string) is block { + 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)) +function id_int (const p : int) : option (int) is block { + 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)) \ No newline at end of file +function id_address (const p : address) : option (address) is block { + 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 7372d8ecc..353ba4a45 100644 --- a/src/test/contracts/chain_id.ligo +++ b/src/test/contracts/chain_id.ligo @@ -1,5 +1 @@ - -function chain_id (const tt : chain_id) : chain_id is - block { - var toto : chain_id := get_chain_id ; - } with ( toto ) \ No newline at end of file +function chain_id (const tt : chain_id) : chain_id is get_chain_id diff --git a/src/test/contracts/check_signature.ligo b/src/test/contracts/check_signature.ligo index 231b726ea..97de04bd2 100644 --- a/src/test/contracts/check_signature.ligo +++ b/src/test/contracts/check_signature.ligo @@ -1,2 +1,4 @@ -function check_signature (const pk: key; const signed: signature; const msg: bytes) : bool is - crypto_check(pk, signed, msg) +function check_signature (const pk : key; + const signed : signature; + const msg: bytes) : bool +is crypto_check (pk, signed, msg) diff --git a/src/test/contracts/closure-1.ligo b/src/test/contracts/closure-1.ligo index 420c888c9..4403b8d2e 100644 --- a/src/test/contracts/closure-1.ligo +++ b/src/test/contracts/closure-1.ligo @@ -1,5 +1,4 @@ function foo (const i : int) : int is block { - function bar (const j : int) : int is - i + j ; - } with bar (i) + function add (const j : int) : int is i+j + } with add (i) diff --git a/src/test/contracts/closure-2.ligo b/src/test/contracts/closure-2.ligo index 5e84645e6..aa741ecd2 100644 --- a/src/test/contracts/closure-2.ligo +++ b/src/test/contracts/closure-2.ligo @@ -1,6 +1,5 @@ -function foobar(const i : int) : int is +function foobar (const i : int) : int is block { - const j : int = 3 ; - function toto(const k : int) : int is - i + j + k ; - } with toto(42) + const j : int = 3; + function add (const k : int) : int is i+j+k + } with add (42) diff --git a/src/test/contracts/closure-3.ligo b/src/test/contracts/closure-3.ligo index a23cdbb22..ae4e68956 100644 --- a/src/test/contracts/closure-3.ligo +++ b/src/test/contracts/closure-3.ligo @@ -1,12 +1,10 @@ -// This might seem like it's covered by induction with closure-2.ligo -// But it exists to prevent a regression on the bug patched by: +// This might seem like it is covered by induction with closure-2.ligo, +// but it exists to prevent a regression on the bug patched by: // https://gitlab.com/ligolang/ligo/commit/faf3bbc06106de98189f1c1673bd57e78351dc7e -function foobar(const i : int) : int is +function foobar (const i : int) : int is block { - const j : int = 3 ; - const k : int = 4 ; - function toto(const l : int) : int is - i + j + k + l; - - } with toto(42) + const j : int = 3; + const k : int = 4; + function add (const l : int) : int is i+j+k+l + } with add (42) diff --git a/src/test/contracts/closure.ligo b/src/test/contracts/closure.ligo index ccb8a5e8c..6cc7f19cd 100644 --- a/src/test/contracts/closure.ligo +++ b/src/test/contracts/closure.ligo @@ -1,7 +1,5 @@ function toto (const i : int) : int is block { - function tata (const j : int) : int is - i + j ; - function titi (const j : int) : int is - i + j ; - } with tata(i) + titi(i) + function tata (const j : int) : int is i+j; + function titi (const j : int) : int is i+j + } with tata (i) + titi (i) diff --git a/src/test/contracts/coase.ligo b/src/test/contracts/coase.ligo index 04b891c7d..fd870b7a8 100644 --- a/src/test/contracts/coase.ligo +++ b/src/test/contracts/coase.ligo @@ -1,98 +1,113 @@ // Copyright Coase, Inc 2019 type card_pattern_id is nat + type card_pattern is record [ - coefficient : tez ; - quantity : nat ; + coefficient : tez; + quantity : nat ] -type card_patterns is map(card_pattern_id , card_pattern) +type card_patterns is map (card_pattern_id, card_pattern) type card_id is nat -type card is record [ - card_owner : address ; - card_pattern : card_pattern_id ; -] -type cards is map(card_id , card) -type storage_type is record [ - cards : cards ; - card_patterns : card_patterns ; - next_id : nat ; +type card is record [ + card_owner : address; + card_pattern : card_pattern_id ] +type cards is map (card_id, card) + +type storage is record [ + cards : cards; + card_patterns : card_patterns; + next_id : nat +] + +type return is list (operation) * storage + type action_buy_single is record [ - card_to_buy : card_pattern_id ; -] -type action_sell_single is record [ - card_to_sell : card_id ; -] -type action_transfer_single is record [ - card_to_transfer : card_id ; - destination : address ; + card_to_buy : card_pattern_id ] -type action is -| Buy_single of action_buy_single -| Sell_single of action_sell_single +type action_sell_single is record [ + card_to_sell : card_id +] + +type action_transfer_single is record [ + card_to_transfer : card_id; + destination : address +] + +type parameter is + Buy_single of action_buy_single +| Sell_single of action_sell_single | Transfer_single of action_transfer_single -function transfer_single(const action : action_transfer_single ; const s : storage_type) : (list(operation) * storage_type) is - begin - const cards : cards = s.cards ; - const card : card = get_force(action.card_to_transfer , cards) ; - if (card.card_owner =/= source) 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 ; - end with (operations , s) ; +function transfer_single (const action : action_transfer_single; + const s : storage) : return is block { + const cards : cards = s.cards; + const card : card = get_force (action.card_to_transfer, cards); + if card.card_owner =/= source 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) -function sell_single(const action : action_sell_single ; const s : storage_type) : (list(operation) * storage_type) is - begin - const card : card = get_force(action.card_to_sell , s.cards) ; - if (card.card_owner =/= source) then failwith ("This card doesn't belong to you") else skip ; - const card_pattern : card_pattern = get_force(card.card_pattern , s.card_patterns) ; - card_pattern.quantity := abs(card_pattern.quantity - 1n); - const card_patterns : card_patterns = s.card_patterns ; - card_patterns[card.card_pattern] := card_pattern ; - s.card_patterns := card_patterns ; - const cards : cards = s.cards ; - 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(source) ; - const op : operation = transaction(unit , price , receiver) ; - const operations : list(operation) = list op end ; - end with (operations , 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); + if card.card_owner =/= source + then failwith ("This card doesn't belong to you") + else skip; + const card_pattern : card_pattern = + get_force (card.card_pattern, s.card_patterns); + card_pattern.quantity := abs (card_pattern.quantity - 1n); + const card_patterns : card_patterns = s.card_patterns; + card_patterns[card.card_pattern] := card_pattern; + s.card_patterns := card_patterns; + const cards : cards = s.cards; + 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 (source); + const op : operation = transaction (unit, price, receiver); + const operations : list (operation) = list [op] + } with (operations, s) -function buy_single(const action : action_buy_single ; const s : storage_type) : (list(operation) * storage_type) is - begin +function buy_single (const action : action_buy_single; + const s : storage) : return is + block { // Check funds - const card_pattern : card_pattern = get_force(action.card_to_buy , s.card_patterns) ; - const price : tez = card_pattern.coefficient * (card_pattern.quantity + 1n) ; - if (price > amount) then failwith ("Not enough money") else skip ; + const card_pattern : card_pattern = + get_force (action.card_to_buy, s.card_patterns); + 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 ; + const operations : list(operation) = nil; // Increase quantity - card_pattern.quantity := card_pattern.quantity + 1n ; - const card_patterns : card_patterns = s.card_patterns ; - card_patterns[action.card_to_buy] := card_pattern ; - s.card_patterns := card_patterns ; + card_pattern.quantity := card_pattern.quantity + 1n; + const card_patterns : card_patterns = s.card_patterns; + card_patterns[action.card_to_buy] := card_pattern; + s.card_patterns := card_patterns; // Add card - const cards : cards = s.cards ; - cards[s.next_id] := record - card_owner = source ; - card_pattern = action.card_to_buy ; - end ; - s.cards := cards ; - s.next_id := s.next_id + 1n ; - end with (operations , s) + const cards : cards = s.cards; + cards[s.next_id] := record [ + card_owner = source; + card_pattern = action.card_to_buy + ]; + s.cards := cards; + s.next_id := s.next_id + 1n + } with (operations, s) -function main(const action : action ; const s : storage_type) : (list(operation) * storage_type) is - block {skip} with +function main (const action : parameter; const s : storage) : return is case action of - | Buy_single (bs) -> buy_single (bs , s) - | Sell_single (as) -> sell_single (as , s) - | Transfer_single (at) -> transfer_single (at , s) + Buy_single (bs) -> buy_single (bs, s) + | Sell_single (as) -> sell_single (as, s) + | Transfer_single (at) -> transfer_single (at, s) end diff --git a/src/test/contracts/condition-simple.ligo b/src/test/contracts/condition-simple.ligo index 9df22cbe3..1d8dc7c0b 100644 --- a/src/test/contracts/condition-simple.ligo +++ b/src/test/contracts/condition-simple.ligo @@ -1,10 +1 @@ -// Test if conditional with trivial conditions in PascaLIGO - -function main (const i : int) : int is - begin - if 1 = 1 then - i := 42 - else - i := 0 - end with i - +function main (const i : int) : int is if 1 = 1 then 42 else 0 diff --git a/src/test/contracts/condition.ligo b/src/test/contracts/condition.ligo index baf320f1d..fbf474980 100644 --- a/src/test/contracts/condition.ligo +++ b/src/test/contracts/condition.ligo @@ -1,16 +1,10 @@ -// Test if conditional in PascaLIGO - function main (const i : int) : int is - begin - var result : int := 23 ; - if i = 2 then - result := 42 - else - result := 0 - end with result + block { + var result : int := 23; + if i = 2 then result := 42 else result := 0 + } with result function foo (const b : bool) : int is - begin - var x : int := 41 ; - x := 1 + (if b then x else main(x)) ; - end with x + block { + const x : int = 41 + } with 1 + (if b then x else main (x)) diff --git a/src/test/contracts/counter.ligo b/src/test/contracts/counter.ligo index 469681a4c..295c540ee 100644 --- a/src/test/contracts/counter.ligo +++ b/src/test/contracts/counter.ligo @@ -1,6 +1,7 @@ -type some_type is int +type t is int -function main (const p : int ; const s : some_type) : (list(operation) * int) is - block { skip } // skip is a do nothing instruction, needed for empty blocks +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) - diff --git a/src/test/contracts/crypto.ligo b/src/test/contracts/crypto.ligo index 4e08f7b16..08d417241 100644 --- a/src/test/contracts/crypto.ligo +++ b/src/test/contracts/crypto.ligo @@ -1,3 +1,3 @@ -function hasherman512 (const s: bytes) : bytes is sha_512(s) +function hasherman512 (const s: bytes) : bytes is sha_512 (s) -function hasherman_blake (const s: bytes) : bytes is blake2b(s) +function hasherman_blake (const s: bytes) : bytes is blake2b (s) diff --git a/src/test/contracts/declaration-local.ligo b/src/test/contracts/declaration-local.ligo index 97f380112..3149a01f8 100644 --- a/src/test/contracts/declaration-local.ligo +++ b/src/test/contracts/declaration-local.ligo @@ -1,5 +1,5 @@ // Test PasaLIGO variable declarations inside of a block function main (const i : int) : int is block { - const j : int = 42 ; + const j : int = 42 } with j diff --git a/src/test/contracts/declarations.ligo b/src/test/contracts/declarations.ligo index 4001fbdbf..d6cc5dfb5 100644 --- a/src/test/contracts/declarations.ligo +++ b/src/test/contracts/declarations.ligo @@ -1,8 +1,5 @@ -// Test PascaLIGO top level declarations +// Test PascaLIGO top-level declarations const foo : int = 42 -function main (const i : int) : int is - begin - skip - end with i + foo +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 7912aefc3..2d9ad32d4 100644 --- a/src/test/contracts/deep_access.ligo +++ b/src/test/contracts/deep_access.ligo @@ -1,31 +1,29 @@ -//Test deep_access in PascalLigo -type pii is (int*int) -type ppi is record x:pii; y:pii end -type ppp is (ppi*ppi) +// Test deep access -function main (const toto : unit) : int is block { - var a : ppp := ( - record - x = (0,1); - y = (10,11); - end , - record - x = (100,101); - y = (110,111); - end - ) ; - a.0.x.0 := 2; - const b:int = a.0.x.0; -} with b +type pii is int * int + +type ppi is record [x : pii; y : pii] + +type ppp is ppi * ppi + +function main (const toto : unit) : int is + block { + var a : ppp := + (record [x = (0,1); y = (10,11)], + record [x = (100,101); y = (110,111)]); + a.0.x.0 := 2; + } with a.0.x.0 -function asymetric_tuple_access(const foo : unit) : int is block { - var mytuple : int * (int * (int * int)) := (0,(1,(2,3))) ; -} with mytuple.0 + mytuple.1.0 + mytuple.1.1.0 + mytuple.1.1.1 +function asymetric_tuple_access (const foo : unit) : int is + block { + var tuple : int * (int * (int * int)) := (0,(1,(2,3))) + } 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) ; end) ; -end -function nested_record (var nee : nested_record_t) : string is block { - nee.nesty.mymap[1] := "one" ; -} with ( get_force(1, nee.nesty.mymap) ) \ No newline at end of file +type nested_record_t is + 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) diff --git a/src/test/contracts/dispatch-counter.ligo b/src/test/contracts/dispatch-counter.ligo index 79a71b837..c513381ae 100644 --- a/src/test/contracts/dispatch-counter.ligo +++ b/src/test/contracts/dispatch-counter.ligo @@ -1,16 +1,19 @@ -type action is -| Increment of int +type parameter is + Increment of int | Decrement of int -function increment(const i : int ; const n : int) : int is - block { skip } with (i + n) +type storage is int -function decrement(const i : int ; const n : int) : int is - block { skip } with (i - n) +type return is list (operation) * storage -function main (const p : action ; const s : int) : (list(operation) * int) is - block {skip} with ((nil : list(operation)), - case p of - | Increment (n) -> increment (s, n) - | Decrement (n) -> decrement (s, n) - end) +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 + +function main (const action : parameter; const store : storage) : return is + case action of + Increment (n) -> (nop, increment (store, n)) + | Decrement (n) -> (nop, decrement (store, n)) + end diff --git a/src/test/contracts/double_main.ligo b/src/test/contracts/double_main.ligo index 6ad75dd80..a46df45ab 100644 --- a/src/test/contracts/double_main.ligo +++ b/src/test/contracts/double_main.ligo @@ -1,8 +1,11 @@ -function main(const p : unit; const s : int) : list(operation) * int is - ((list end : list(operation)), s + 1) +type parameter is unit +type storage is int +type return is list (operation) * storage -function main(const p : unit; const s : int) : list(operation) * int is - begin - const ret : list(operation) * int = main(p, s) - end - with (ret.0, ret.1 + 1) \ No newline at end of file +function main(const p : parameter; const s : storage) : return is + ((nil : list(operation)), s+1) + +function main (const p : parameter; const s : storage) : return is + block { + const ret : return = main (p, s) + } with (ret.0, ret.1 + 1) diff --git a/src/test/contracts/empty_case.ligo b/src/test/contracts/empty_case.ligo index 30771c774..c2236099f 100644 --- a/src/test/contracts/empty_case.ligo +++ b/src/test/contracts/empty_case.ligo @@ -1,9 +1,9 @@ -type foo is - | Bar of int - | Baz +type t is + Bar of int +| Baz -function main (const f: foo) : int is - (case f of - | Bar (n) -> n - | Baz -> -1 - end) +function main (const x : t) : int is + case x of + Bar (n) -> n + | Baz -> -1 + end diff --git a/src/test/contracts/entrypoints.ligo b/src/test/contracts/entrypoints.ligo index d884a1ec9..d1945ac8d 100644 --- a/src/test/contracts/entrypoints.ligo +++ b/src/test/contracts/entrypoints.ligo @@ -1,16 +1,19 @@ -function cb(const a : address; const s : unit) : list(operation) * unit is +type storage is unit + +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) + const c : contract (unit) = get_entrypoint ("%cb", a) } - with (list transaction(unit, 0mutez, c) end, s) + with (list [transaction (unit, 0mutez, c)], s) -function cbo(const a : address; const s : unit) : list(operation) * unit is +function cbo (const a : address; const s : storage) : return is block { - const c : contract(unit) = - case (get_entrypoint_opt("%cbo", a) : option(contract (unit))) of - | Some (c) -> c - | None -> (failwith ("entrypoint not found") : contract (unit)) + const c : contract (unit) = + case (get_entrypoint_opt ("%cbo", a) : option (contract (unit))) of + Some (c) -> c + | None -> (failwith ("entrypoint not found") : contract (unit)) end - } - with (list transaction(unit, 0mutez, c) end, s) + } with (list [transaction(unit, 0mutez, c)], s) diff --git a/src/test/contracts/evaluation_tests.ligo b/src/test/contracts/evaluation_tests.ligo index b531d4a7b..7eef1067f 100644 --- a/src/test/contracts/evaluation_tests.ligo +++ b/src/test/contracts/evaluation_tests.ligo @@ -1,11 +1,5 @@ -type myrec is record - foo : nat; - bar : string; -end; +type t is record [foo : nat; bar : string] -const a : myrec = record - foo = 0n; - bar = "bar"; -end; +const a : t = record [foo = 0n; bar = "bar"] -const b : int = 2 ; \ No newline at end of file +const b : int = 2 diff --git a/src/test/contracts/failwith.ligo b/src/test/contracts/failwith.ligo index 29b757c3e..73e9a4f06 100644 --- a/src/test/contracts/failwith.ligo +++ b/src/test/contracts/failwith.ligo @@ -1,37 +1,43 @@ -type param is -| Zero of nat -| Pos of nat +type parameter is + Zero of nat +| Pos of nat -function main (const p : param; const s : unit) : list(operation) * unit is +type storage is unit + +type return is list (operation) * storage + +function main (const p : parameter; const s : storage) : return is block { case p of - | Zero (n) -> if n > 0n then failwith("fail") else skip - | Pos (n) -> if n > 0n then skip else failwith("fail") + Zero (n) -> if n > 0n then failwith ("fail") else skip + | Pos (n) -> if n > 0n then skip else failwith ("fail") end } - with ((nil : list(operation)), s) + with ((nil : list (operation)), s) function foobar (const i : int) : int is block { - var p : param := Zero (42n) ; - if i > 0 then block { - i := i + 1 ; - if i > 10 then block { - i := 20 ; - failwith ("who knows") ; - i := 30 ; - } else skip - } else block { - case p of - | Zero (n) -> failwith ("wooo") - | Pos (n) -> skip - end + var p : parameter := Zero (42n); + if i > 0 then { + i := i + 1; + if i > 10 then { + i := 20; + failwith ("who knows"); + i := 30 // Should be no-op + } + else skip } - } with case p of - | Zero (n) -> i - | Pos (n) -> (failwith ("waaaa") : int) - end + else + case p of + Zero (n) -> failwith ("wooo") + | Pos (n) -> skip + end + } with + case p of + Zero (n) -> i + | Pos (n) -> (failwith ("waaaa") : int) + end -function failer(const p : int) : int is block { - if p = 1 then failwith("some_string") else skip ; +function failer (const p : int) : int is block { + if p = 1 then failwith ("some_string") else skip } with p diff --git a/src/test/contracts/for_fail.ligo b/src/test/contracts/for_fail.ligo index 0a177bca1..a8c870843 100644 --- a/src/test/contracts/for_fail.ligo +++ b/src/test/contracts/for_fail.ligo @@ -1,11 +1,2 @@ -// This was meant to test the for loop in PascaLIGO -// But for whatever reason, the LIGO compiler currently thinks this is a 'complex loop' -// even though it isn't. -// See this error: -// $ ligo dry-run for.ligo main 0 0 -// bounded iterators: only simple for loops are supported yet -// {"loop_loc":"in file \"for.ligo\", line 4, characters 10-42"} - - function main (const a: int) : int is - block { for i := 0 to 100 block { skip } } with i; + block { for i := 0 to 100 block { skip } } with i diff --git a/src/test/contracts/function-complex.ligo b/src/test/contracts/function-complex.ligo index 4c361cbfd..854a9ed65 100644 --- a/src/test/contracts/function-complex.ligo +++ b/src/test/contracts/function-complex.ligo @@ -1,9 +1,9 @@ // Test a PascaLIGO function with more complex logic than function.ligo function main (const i : int) : int is - begin - var j : int := 0 ; - var k : int := 1 ; - j := k + i ; - k := i + j ; - end with (k + j) + block { + var j : int := 0; + var k : int := 1; + j := k + i; + k := i + j + } with k + j diff --git a/src/test/contracts/function-shared.ligo b/src/test/contracts/function-shared.ligo index 0155b5cb1..cd7d64386 100644 --- a/src/test/contracts/function-shared.ligo +++ b/src/test/contracts/function-shared.ligo @@ -1,10 +1,7 @@ // Test a PascaLIGO function which uses other functions as subroutines -function inc ( const i : int ) : int is - block { skip } with i + 1 +function inc (const i : int) : int is i+1 -function double_inc ( const i : int ) : int is - block { skip } with inc(i + 1) +function double_inc (const i : int) : int is inc (i+1) -function foo ( const i : int ) : int is - block { skip } with inc(i) + double_inc(i) +function foo (const i : int) : int is inc (i) + double_inc (i) diff --git a/src/test/contracts/function.ligo b/src/test/contracts/function.ligo index 27f4437ef..81daec7ce 100644 --- a/src/test/contracts/function.ligo +++ b/src/test/contracts/function.ligo @@ -1,6 +1,3 @@ // Test a trivial PascaLIGO function -function main (const i : int) : int is - begin - skip - end with i +function main (const i : int) : int is i diff --git a/src/test/contracts/get_contract.ligo b/src/test/contracts/get_contract.ligo index 12d58aba6..cb203c840 100644 --- a/src/test/contracts/get_contract.ligo +++ b/src/test/contracts/get_contract.ligo @@ -1,16 +1,19 @@ -function cb(const s : unit) : list(operation) * unit is +type storage is unit +type return is list (operation) * storage + +function cb (const s : storage) : return is block { - const c : contract(unit) = get_contract(source) + const c : contract (unit) = get_contract (source) } - with (list transaction(unit, 0mutez, c) end, s) + with (list [transaction(unit, 0mutez, c)], s) -function cbo(const s : unit) : list(operation) * unit is +function cbo (const s : unit) : return is block { - const c : contract(unit) = - case (get_contract_opt(source) : option(contract (unit))) of - | Some (c) -> c - | None -> (failwith ("contract not found") : contract (unit)) + const c : contract (unit) = + case (get_contract_opt (source) : option (contract (unit))) of + Some (c) -> c + | None -> (failwith ("contract not found") : contract (unit)) end } - with (list transaction(unit, 0mutez, c) end, s) + with (list [transaction(unit, 0mutez, c)], s) diff --git a/src/test/contracts/heap-instance.ligo b/src/test/contracts/heap-instance.ligo index b214f0fab..11b1c58de 100644 --- a/src/test/contracts/heap-instance.ligo +++ b/src/test/contracts/heap-instance.ligo @@ -1,6 +1,6 @@ -type heap_element is int * string +type heap_elt is int * string -function heap_element_lt(const x : heap_element ; const y : heap_element) : bool is - block { skip } with x.0 < y.0 +function heap_elt_lt (const x : heap_elt; + const y : heap_elt) : bool is x.0 < y.0 #include "heap.ligo" diff --git a/src/test/contracts/heap.ligo b/src/test/contracts/heap.ligo index 48130f96b..66c7747b6 100644 --- a/src/test/contracts/heap.ligo +++ b/src/test/contracts/heap.ligo @@ -1,93 +1,95 @@ // Implementation of the heap data structure in PascaLIGO // See: https://en.wikipedia.org/wiki/Heap_%28data_structure%29 -type heap is map(nat, heap_element) ; +type heap is map (nat, heap_elt) -function is_empty (const h : heap) : bool is - block {skip} with size(h) = 0n +function is_empty (const h : heap) : bool is size (h) = 0n -function get_top (const h : heap) : heap_element is - block {skip} with get_force(1n, h) +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_element = get_top (h) ; - const s : nat = size(h) ; - const last : heap_element = get_force(s, h) ; - remove 1n from map h ; - h[1n] := last ; + const result : heap_elt = get_top (h); + const s : nat = size (h); + const last : heap_elt = get_force (s, h); + remove 1n from map h; + h[1n] := last } with h function pop_ (const h : heap) : nat is - begin - const result : heap_element = get_top (h) ; - const s : nat = size(h) ; - var current : heap_element := get_force(s, h) ; - const i : nat = 1n ; - const left : nat = 2n * i ; - const right : nat = left + 1n ; - remove 1n from map h ; - h[1n] := current ; - var largest : nat := i ; - if (left <= s and heap_element_lt(get_force(s , h) , get_force(left , h))) then - largest := left - else if (right <= s and heap_element_lt(get_force(s , h) , get_force(right , h))) then - largest := right - else skip - end with largest + block { + const result : heap_elt = get_top (h); + const s : nat = size (h); + var current : heap_elt := get_force (s, h); + const i : nat = 1n; + const left : nat = 2n * i; + const right : nat = left + 1n; + remove 1n from map h; + h[1n] := current; + var largest : nat := i; + const tmp : heap_elt = get_force (s, h); + if left <= s and heap_elt_lt (tmp, get_force (left,h)) + then largest := left + else + if right <= s and heap_elt_lt (tmp, get_force (right,h)) + then largest := right + else skip + } with largest -function insert (const h : heap ; const e : heap_element) : heap is - begin - var i : nat := size(h) + 1n ; - h[i] := e ; - var largest : nat := i ; - var parent : nat := 0n ; - while (largest =/= i) block { - parent := i / 2n ; - largest := i ; - if (parent >= 1n) then block { - if (heap_element_lt(get_force(parent , h) , get_force(i , h))) then block { - largest := parent ; - const tmp : heap_element = get_force(i , h) ; - h[i] := get_force(parent , h) ; - h[parent] := tmp ; +function insert (const h : heap ; const e : heap_elt) : heap is + block { + var i : nat := size (h) + 1n; + h[i] := e; + var largest : nat := i; + var parent : nat := 0n; + while largest =/= i block { + parent := i/2n; + largest := i; + if parent >= 1n then { + if heap_elt_lt (get_force (parent,h), get_force(i,h))) then { + largest := parent; + const tmp : heap_elt = get_force (i,h); + h[i] := get_force(parent, h); + h[parent] := tmp } else skip } else skip } - end with h + } with h -function pop (const h : heap) : (heap * heap_element * nat) is - begin - const result : heap_element = get_top (h) ; - var s : nat := size(h) ; - const last : heap_element = get_force(s, h) ; - remove s from map h ; - h[1n] := last ; - s := size(h) ; - var i : nat := 0n ; - var largest : nat := 1n ; - var left : nat := 0n ; - var right : nat := 0n ; - var c : nat := 0n ; - while (largest =/= i) block { - c := c + 1n ; - i := largest ; - left := 2n * i ; - right := left + 1n ; - if (left <= s) then begin - if (heap_element_lt(get_force(left , h) , get_force(i , h))) then begin - largest := left ; - const tmp : heap_element = get_force(i , h) ; - h[i] := get_force(left , h) ; - h[left] := tmp ; - end else skip ; - end else if (right <= s) then begin - if (heap_element_lt(get_force(right , h) , get_force(i , h))) then begin - largest := right ; - const tmp : heap_element = get_force(i , h) ; - h[i] := get_force(right , h) ; - h[left] := tmp ; - end else skip ; - end else skip ; - } - end with (h , result , c) +function pop (const h : heap) : heap * heap_elt * nat is + block { + const result : heap_elt = get_top (h); + var s : nat := size (h); + const last : heap_elt = get_force (s,h); + remove s from map h; + h[1n] := last; + s := size (h); + var i : nat := 0n; + var largest : nat := 1n; + var left : nat := 0n; + var right : nat := 0n; + var c : nat := 0n; + while largest =/= i block { + c := c + 1n; + i := largest; + left := 2n * i; + right := left + 1n; + if left <= s then { + if heap_elt_lt (get_force (left,h), get_force(i,h)) then { + largest := left; + const tmp : heap_elt = get_force(i,h); + h[i] := get_force (left, h); + h[left] := tmp + } else skip + } + else + if right <= s then { + if heap_elt_lt (get_force (right, h), get_force (i,h)) then { + largest := right; + const tmp : heap_elt = get_force (i,h); + h[i] := get_force (right, h); + h[left] := tmp + } else skip + } else skip + } + } with (h, result, c) diff --git a/src/test/contracts/high-order.ligo b/src/test/contracts/high-order.ligo index 20162400d..e1d3b9a18 100644 --- a/src/test/contracts/high-order.ligo +++ b/src/test/contracts/high-order.ligo @@ -1,27 +1,27 @@ -// Test a PascaLIGO function which takes another PascaLIGO function as an argument +(* Test a PascaLIGO function which takes another function as an + argument *) + function foobar (const i : int) : int is - begin + block { function foo (const i : int) : int is i; function bar (const f : int -> int) : int is f (i); - end with bar (foo); + } with bar (foo) // higher order function with more than one argument -function higher2(const i : int; const f : int -> int): int is - begin - const ii: int = f (i) - end with ii + +function higher2 (const i : int; const f : int -> int): int is f (i) function foobar2 (const i : int) : int is - begin + block { function foo2 (const i : int) : int is i - end with higher2 (i,foo2) + } with higher2 (i, foo2) -const a : int = 0; +const a : int = 0 function foobar3 (const i : int) : int is - begin + block { function foo2 (const i : int) : int is a+i - end with higher2 (i,foo2) + } with higher2 (i, foo2) function f (const i : int) : int is i @@ -29,17 +29,15 @@ function g (const i : int) : int is f (i) function foobar4 (const i : int) : int is g (g (i)) -function higher3(const i : int; const f : int -> int; const g : int -> int) -: int is - begin - const ii : int = f(g(i)) - end with ii +function higher3 (const i : int; + const f : int -> int; + const g : int -> int) : int is f (g (i)) function foobar5 (const i : int) : int is - begin + block { const a : int = 0; function foo (const i : int) : int is a+i; function goo (const i : int) : int is foo (i) - end with higher3(i,foo,goo) + } with higher3 (i, foo, goo) function foobar6 (const i : int) : int -> int is f diff --git a/src/test/contracts/implicit_account.ligo b/src/test/contracts/implicit_account.ligo index 8883a778d..ad0a6c54b 100644 --- a/src/test/contracts/implicit_account.ligo +++ b/src/test/contracts/implicit_account.ligo @@ -1 +1 @@ -function main (const kh: key_hash) : contract(unit) is implicit_account(kh) +function main (const kh: key_hash) : contract (unit) is implicit_account (kh) diff --git a/src/test/contracts/isnat.ligo b/src/test/contracts/isnat.ligo index 75215f28a..1d2a4dfda 100644 --- a/src/test/contracts/isnat.ligo +++ b/src/test/contracts/isnat.ligo @@ -1,2 +1 @@ -function main (const i: int) : option(nat) is - block {skip} with is_nat(i) +function main (const i : int) : option (nat) is is_nat (i) diff --git a/src/test/contracts/key_hash.ligo b/src/test/contracts/key_hash.ligo index 38b72366a..865abfbb8 100644 --- a/src/test/contracts/key_hash.ligo +++ b/src/test/contracts/key_hash.ligo @@ -1,5 +1,7 @@ -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) \ No newline at end of file +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) diff --git a/src/test/contracts/lambda.ligo b/src/test/contracts/lambda.ligo index 036327729..8c3160ed9 100644 --- a/src/test/contracts/lambda.ligo +++ b/src/test/contracts/lambda.ligo @@ -1,7 +1,3 @@ -function f (const x : unit) : unit is - begin skip end with unit +function f (const x : unit) : unit is Unit -function main (const p : unit ; const s : unit) : unit is - begin - var y : unit := f(unit) ; - end with y +function main (const p : unit ; const s : unit) : unit is f (Unit) diff --git a/src/test/contracts/list.ligo b/src/test/contracts/list.ligo index 77f8beec3..155b80ac5 100644 --- a/src/test/contracts/list.ligo +++ b/src/test/contracts/list.ligo @@ -1,49 +1,33 @@ // Test list type and related built-in functions in PascaLIGO -type foobar is list(int) +type foobar is list (int) -const fb : foobar = list - 23 ; - 42 ; -end +const fb : foobar = list [23; 42] const fb2 : foobar = 144 # fb -const fb3 : foobar = cons(688 , fb2) +const fb3 : foobar = cons (688, fb2) -function size_ (const m : foobar) : nat is - block {skip} with (size(m)) +function size_ (const m : foobar) : nat is size (m) -// function hdf (const m : foobar) : int is begin skip end with hd(m) +// function hdf (const m : foobar) : int is hd (m) -const bl : foobar = list - 144 ; - 51 ; - 42 ; - 120 ; - 421 ; -end +const bl : foobar = list [144; 51; 42; 120; 421] -function fold_op (const s: list(int)) : int is - begin - function aggregate (const prec: int; const cur: int) : int is - begin - skip - end with prec + cur - end with list_fold(aggregate, s, 10) - - -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 - -function map_op (const s : list(int)) : list(int) is +function fold_op (const s : list (int)) : int is block { - function increment (const i : int) : int is block { skip } with i + 1 - } with list_map(increment, s) + function aggregate (const prec: int; const cur: int) : int is prec+cur + } 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) + } 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) diff --git a/src/test/contracts/loop.ligo b/src/test/contracts/loop.ligo index 50e87da04..7866a5cdb 100644 --- a/src/test/contracts/loop.ligo +++ b/src/test/contracts/loop.ligo @@ -1,193 +1,188 @@ // Test while loops in PascaLIGO -function counter (var n : nat) : nat is block { - var i : nat := 0n ; - while i < n block { - i := i + 1n; - } -} with i +function counter (var n : nat) : nat is + block { + var i : nat := 0n; + while i < n block { + i := i + 1n + } + } with i -function while_sum (var n : nat) : nat is block { - var i : nat := 0n ; - var r : nat := 0n ; - while i < n block { - i := i + 1n; - r := r + i; - } -} with r +function while_sum (var n : nat) : nat is + block { + var i : nat := 0n; + var r : nat := 0n; + while i < n block { + i := i + 1n; + r := r + i + } + } with r -function for_sum (var n : nat) : int is block { - var acc : int := 0 ; - for i := 1 to int(n) - begin - acc := acc + i; - end -} with acc +function for_sum (var n : nat) : int is + block { + var acc : int := 0; + for i := 1 to int (n) + block { + acc := acc + i + } + } with acc -function for_collection_list (var nee : unit) : (int * string) is block { - var acc : int := 0; - var st : string := "to"; - var mylist : list(int) := list 1; 1; 1 end; - for x in list mylist - begin +function for_collection_list (var nee : unit) : (int * string) is + block { + var acc : int := 0; + var st : string := "to"; + var mylist : list (int) := list [1; 1; 1]; + for x in list mylist + block { + acc := acc + x; + st := st ^ "to" + } + } with (acc, st) + +function for_collection_set (var nee : unit) : int * string is + block { + var acc : int := 0; + var st : string := "to"; + var myset : set (int) := set [1; 2; 3]; + for x in set myset block { acc := acc + x; - st := st ^ "to"; - end -} with (acc, st) + st := st ^ "to" + } + } with (acc, st) -function for_collection_set (var nee : unit) : (int * string) is block { - var acc : int := 0; - var st : string := "to"; - var myset : set(int) := set 1; 2; 3 end; - for x in set myset - begin - acc := acc + x ; - st := st^"to" ; - end -} with (acc, st) +function for_collection_if_and_local_var (var nee : unit) : int is + block { + var acc : int := 0; + const theone : int = 1; + var myset : set (int) := set [1; 2; 3]; + for x in set myset block { + const thetwo : int = 2; + if x = theone then acc := acc + x + else if x = thetwo then acc := acc + thetwo + else acc := acc + 10 + } + } with acc -function for_collection_if_and_local_var (var nee : unit) : int is block { - var acc : int := 0 ; - const theone : int = 1 ; - var myset : set(int) := set 1 ; 2 ; 3 end ; - for x in set myset - begin - const thetwo : int = 2 ; - if x=theone then - acc := acc + x - else if x=thetwo then - acc := acc + thetwo; - else - acc := acc + 10; - end -} with acc +function for_collection_rhs_capture (var nee : unit) : int is + block { + var acc : int := 0; + const mybigint : int = 1000; + var myset : set (int) := set [1; 2; 3]; + for x in set myset block { + if x = 1 then acc := acc + mybigint + else acc := acc + 10 + } + } with acc -function for_collection_rhs_capture (var nee : unit) : int is block { - var acc : int := 0 ; - const mybigint : int = 1000 ; - var myset : set(int) := set 1 ; 2 ; 3 end ; - for x in set myset - begin - if x=1 then acc := acc + mybigint; - else acc := acc + 10; - end -} with acc +function for_collection_proc_call (var nee : unit) : int is + block { + var acc : int := 0; + var myset : set (int) := set [1; 2; 3]; + for x in set myset block { + if x = 1 then + acc := acc + for_collection_rhs_capture (unit) + else acc := acc + 10 + } + } with acc -function for_collection_proc_call (var nee : unit) : int is block { - var acc : int := 0 ; - var myset : set(int) := set 1 ; 2 ; 3 end ; - for x in set myset - begin - if x=1 then - acc := acc + for_collection_rhs_capture(unit); - else - acc := acc + 10; - end -} with acc - -function for_collection_comp_with_acc (var nee : unit) : int is block { - var myint : int := 0 ; - var mylist : list(int) := list 1 ; 10 ; 15 end; - for x in list mylist - begin +function for_collection_comp_with_acc (var nee : unit) : int is + block { + var myint : int := 0; + var mylist : list (int) := list [1; 10; 15]; + for x in list mylist block { if x < myint then skip; else myint := myint + 10 - end -} with myint + } + } with myint -function for_collection_with_patches (var nee : unit) : map(string,int) is block { - var myint : int := 12 ; - var mylist : list(string) := list "I"; "am"; "foo" end; - var mymap : map(string,int) := map end; - for x in list mylist - begin - patch mymap with map [x -> myint]; - end -} with mymap +function for_collection_with_patches (var nee : unit) : map (string,int) is + block { + var myint : int := 12; + var mylist : list (string) := list ["I"; "am"; "foo"]; + var mymap : map (string,int) := map []; + for x in list mylist block { + patch mymap with map [x -> myint] + } + } with mymap -function for_collection_empty (var nee : unit) : int is block { - var acc : int := 0 ; - var myset : set(int) := set 1; 2; 3 end; - for x in set myset - begin +function for_collection_empty (var nee : unit) : int is + block { + var acc : int := 0; + var myset : set(int) := set [1; 2; 3]; + for x in set myset block { skip - end -} with acc + } + } with acc -function for_collection_map_kv (var nee : unit) : (int * string) is block { - var acc : int := 0; - var st : string := ""; - var mymap : map(string,int) := map "1" -> 1; "2" -> 2; "3" -> 3 end; - for k -> v in map mymap - begin +function for_collection_map_kv (var nee : unit) : int * string is + block { + var acc : int := 0; + var st : string := ""; + var mymap : map (string, int) := map ["1" -> 1; "2" -> 2; "3" -> 3]; + for k -> v in map mymap block { acc := acc + v; st := st ^ k; - end -} with (acc, st) + } + } with (acc, st) -function for_collection_map_k (var nee : unit) : string is block { - var st : string := "" ; - var mymap : map(string,int) := map "1" -> 1 ; "2" -> 2 ; "3" -> 3 end ; - for k in map mymap - begin - st := st ^ k; - end -} with st +function for_collection_map_k (var nee : unit) : string is + block { + var st : string := ""; + var mymap : map (string, int) := map ["1" -> 1; "2" -> 2; "3" -> 3]; + for k in map mymap block { + st := st ^ k + } + } with st -function nested_for_collection (var nee : unit) : (int*string) is block { - var myint : int := 0; - var mystoo : string := ""; - var mylist : list(int) := list 1 ; 2 ; 3 end ; - var mymap : map(string,string) := map " one" -> "," ; "two" -> " " end ; +function nested_for_collection (var nee : unit) : int * string is + block { + var myint : int := 0; + var mystoo : string := ""; + var mylist : list(int) := list [1; 2; 3]; + var mymap : map (string, string) := map [" one" -> ","; "two" -> " "]; + for i in list mylist block { + myint := myint + i; + var myset : set (string) := set ["1"; "2"; "3"]; + for st in set myset block { + myint := myint + i; + mystoo := mystoo ^ st; + for k -> v in map mymap block { + mystoo := mystoo ^ k ^ v + } + } + } + } with (myint, mystoo) - for i in list mylist - begin - myint := myint + i ; - var myset : set(string) := set "1" ; "2" ; "3" end ; - for st in set myset - begin - myint := myint + i ; - mystoo := mystoo ^ st ; - for k -> v in map mymap - begin - mystoo := mystoo ^ k ^ v ; - end - end - end -} with (myint,mystoo) - -function nested_for_collection_local_var (var nee : unit) : (int*string) is block { - var myint : int := 0; - var myst : string := ""; - var mylist : list(int) := list 1 ; 2 ; 3 end ; - - for i in list mylist - begin - var myst_loc : string := "" ; - myint := myint + i ; - var myset : set(string) := set "1" ; "2" ; "3" end ; - for st in set myset - begin - myint := myint + i ; - myst_loc := myst_loc ^ st ; - end; - myst := myst_loc ^ myst ; - end -} with (myint,myst) +function nested_for_collection_local_var (var nee : unit) : int*string is + block { + var myint : int := 0; + var myst : string := ""; + var mylist : list (int) := list [1; 2; 3]; + for i in list mylist block { + var myst_loc : string := ""; + myint := myint + i; + var myset : set (string) := set ["1"; "2"; "3"]; + for st in set myset block { + myint := myint + i; + myst_loc := myst_loc ^ st; + }; + myst := myst_loc ^ myst + } + } with (myint, myst) function dummy (const n : nat) : nat is block { while False block { skip } } with n -function inner_capture_in_conditional_block (var nee : unit) : bool*int is block { - var count : int := 1 ; - var ret : bool := False ; - var mylist : list(int) := list 1 ; 2 ; 3 end ; - for it1 in list mylist block { - for it2 in list mylist block { - if count = it2 then ret := not (ret) - else skip; - }; - count := count + 1; - } -} with (ret,count) \ No newline at end of file +function inner_capture_in_conditional_block (var nee : unit) : bool * int is + block { + var count : int := 1; + var ret : bool := False; + var mylist : list (int) := list [1; 2; 3]; + for it1 in list mylist block { + for it2 in list mylist block { + if count = it2 then ret := not (ret) else skip + }; + count := count + 1 + } + } with (ret, count) diff --git a/src/test/contracts/map.ligo b/src/test/contracts/map.ligo index 797bb1a8b..cd394e0d2 100644 --- a/src/test/contracts/map.ligo +++ b/src/test/contracts/map.ligo @@ -1,23 +1,20 @@ // Test map type and related built-in functions in PascaLIGO -type foobar is map(int, int) +type foobar is map (int, int) -const empty_map : foobar = map end +const empty_map : foobar = map [] -const map1 : foobar = map - 144 -> 23 ; - 51 -> 23 ; - 42 -> 23 ; - 120 -> 23 ; - 421 -> 23 ; -end -const map2 : foobar = map - 23 -> 0 ; - 42 -> 0 ; -end +const map1 : foobar = map [ + 144 -> 23; + 51 -> 23; + 42 -> 23; + 120 -> 23; + 421 -> 23] -function set_ (var n : int ; var m : foobar) : foobar is block { - m[23] := n ; +const map2 : foobar = map [23 -> 0; 42 -> 0] + +function set_ (var n : int; var m : foobar) : foobar is block { + m[23] := n } with m @@ -25,50 +22,43 @@ function rm (var m : foobar) : foobar is block { remove 42 from map m } with m -function patch_ (var m: foobar) : foobar is block { +function patch_ (var m : foobar) : foobar is block { patch m with map [0 -> 5; 1 -> 6; 2 -> 7] } with m -function patch_deep (var m: foobar * nat) : foobar * nat is - begin patch m.0 with map [1 -> 9]; end with m +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 - block {skip} with (size(m)) +function size_ (const m : foobar) : nat is size (m) -function gf (const m : foobar) : int is begin skip end with get_force(23, m) +function gf (const m : foobar) : int is get_force (23, m) -function get (const m : foobar) : option(int) is - begin - skip - end with m[42] +function get (const m : foobar) : option (int) is m[42] -function get_ (const m : foobar) : option(int) is - begin - skip - end with map_get(42 , m) +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 ; - // map_iter(m , aggregate) ; - } with map_iter(aggregate, m) ; + 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) function map_op (const m : foobar) : foobar is block { - function increment (const i : int ; const j : int) : int is block { skip } with j + 1 ; - } with map_map(increment, m) ; + function increment (const i : int; const j : int) : int is j+1 + } 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 block { skip } with i + j.0 + j.1 ; - } with map_fold(aggregate, m , 10) + function aggregate (const i : int; const j : int * int) : int is + i + j.0 + j.1 + } with map_fold(aggregate, m, 10) function deep_op (var m : foobar) : foobar is block { - var coco : (int*foobar) := (0, m); - remove 42 from map coco.1 ; - coco.1[32] := 16 ; + var coco : int * foobar := (0, m); + remove 42 from map coco.1; + coco.1[32] := 16 } with coco.1 diff --git a/src/test/contracts/match.ligo b/src/test/contracts/match.ligo index 167f3d976..d4fbae47c 100644 --- a/src/test/contracts/match.ligo +++ b/src/test/contracts/match.ligo @@ -1,37 +1,37 @@ // Test the pattern matching functionality of PascaLIGO function match_bool (const i : int) : int is - begin - var result : int := 23 ; + block { + var result : int := 23; case i = 2 of - | True -> result := 42 + True -> result := 42 | False -> result := 0 end - end with result + } with result -function match_option (const o : option(int)) : int is - begin - var result : int := 23 ; +function match_option (const o : option (int)) : int is + block { + var result : int := 23; case o of - | None -> skip + None -> skip | Some (s) -> result := s end - end with result + } with result function match_expr_bool (const i : int) : int is case i = 2 of - | True -> 42 + True -> 42 | False -> 0 end -function match_expr_option (const o : option(int)) : int is +function match_expr_option (const o : option (int)) : int is case o of - | None -> 42 + None -> 42 | Some (s) -> s end -function match_expr_list (const l : list(int)) : int is +function match_expr_list (const l : list (int)) : int is case l of - | nil -> -1 + nil -> -1 | hd # tl -> hd end diff --git a/src/test/contracts/multiple-parameters.ligo b/src/test/contracts/multiple-parameters.ligo index 26f5daa0d..f955c2301 100644 --- a/src/test/contracts/multiple-parameters.ligo +++ b/src/test/contracts/multiple-parameters.ligo @@ -1,10 +1,14 @@ // Test functions with several parameters in PascaLIGO -function ab(const a : int; const b : int) : int is - begin skip end with (a + b) +function ab (const a : int; const b : int) : int is a+b -function abcd(const a : int; const b : int; const c : int; const d : int) : int is - begin skip end with (a + b + c + d + 2) +function abcd (const a : int; + const b : int; + const c : int; + const d : int) : int is a+b+c+d+2 -function abcde(const a : int; const b : int; const c : int; const d : int; const e : int) : int is - begin skip end with (c + e + 3) +function abcde (const a : int; + const b : int; + const c : int; + const d : int; + const e : int) : int is c+e+3 diff --git a/src/test/contracts/multisig-v2.ligo b/src/test/contracts/multisig-v2.ligo index 81b3536d4..cb3292d18 100644 --- a/src/test/contracts/multisig-v2.ligo +++ b/src/test/contracts/multisig-v2.ligo @@ -1,118 +1,150 @@ // storage type -type threshold_t is nat -type max_proposal_t is nat -type max_message_size_t is nat -type state_hash_t is bytes -type addr_set_t is set(address) -type message_store_t is map(bytes,addr_set_t) -type proposal_counters_t is map(address,nat) -type storage_t is record - state_hash : state_hash_t ; - threshold : threshold_t ; - max_proposal : max_proposal_t ; - max_message_size : max_message_size_t ; - authorized_addresses : addr_set_t ; - message_store : message_store_t ; - proposal_counters : proposal_counters_t ; -end +type threshold is nat +type max_proposal is nat +type max_message_size is nat +type state_hash is bytes +type addr_set is set (address) +type message_store is map (bytes, addr_set) +type proposal_counters is map (address, nat) + +type storage is + record [ + state_hash : state_hash; + threshold : threshold; + max_proposal : max_proposal; + max_message_size : max_message_size; + authorized_addresses : addr_set; + message_store : message_store; + proposal_counters : proposal_counters + ] // I/O types -type message_t is (bytes -> list(operation)) -type send_pt is message_t -type withdraw_pt is message_t + +type message is bytes -> list (operation) +type send_pt is message +type withdraw_pt is message type default_pt is unit -type contract_return_t is (list(operation) * storage_t) +type return is list (operation) * storage -type entry_point_t is -| Send of send_pt +type parameter is + Send of send_pt | Withdraw of withdraw_pt -| Default of default_pt +| Default of default_pt +function send (const param : send_pt; const s : storage) : return is + block { + // check sender against the authorized addresses -function send (const param : send_pt; const s : storage_t) : contract_return_t is block { + if not set_mem (sender, s.authorized_addresses) + then failwith("Unauthorized address") + else skip; - // check sender against the authorized addresses - if not set_mem(sender,s.authorized_addresses) then failwith("Unauthorized address") else skip ; + // check message size against the stored limit - // check message size against the stored limit - var message : message_t := param ; - const packed_msg : bytes = bytes_pack(message) ; - if size(packed_msg) > s.max_message_size then failwith("Message size exceed maximum limit") - else skip ; + var message : message := param; + const packed_msg : bytes = bytes_pack (message); + if size (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_t := set_empty ; - case map_get(packed_msg, s.message_store) of - | Some(voters) -> block { // the message is already stored - // increment the counter only if the sender isn't already associated with the message - if set_mem(sender,voters) then skip - else s.proposal_counters[sender] := get_force(sender,s.proposal_counters) + 1n ; + (* compute the new set of addresses associated with the message and + update counters *) - new_store := set_add(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]; - } - end ; + var new_store : addr_set := set_empty; - // check sender counters against the maximum number of proposal - var sender_proposal_counter : nat := get_force(sender,s.proposal_counters) ; - if sender_proposal_counter > s.max_proposal then failwith("Maximum number of proposal reached") - else skip ; + case map_get (packed_msg, s.message_store) of + Some (voters) -> + block { + (* The message is already stored. + Increment the counter only if the sender is not already + associated with the message. *) + if set_mem (sender, voters) + then skip + else s.proposal_counters[sender] := + get_force (sender, s.proposal_counters) + 1n; - // check the threshold - var ret_ops : list(operation) := (nil : list(operation)) ; - if size(new_store) >= s.threshold then block { - 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) ) ; - // decrement the counters - for addr -> ctr in map s.proposal_counters block { - if set_mem(addr,new_store) then - s.proposal_counters[addr] := abs (ctr - 1n) - else skip ; - } - } else - s.message_store[packed_msg] := new_store - -} with ( ret_ops , s) + new_store := set_add(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] + } + end; -function withdraw (const param : withdraw_pt; const s : storage_t) : contract_return_t is block { + // check sender counters against the maximum number of proposal - var message : message_t := param ; - const packed_msg : bytes = bytes_pack(message) ; + var sender_proposal_counter : nat := + get_force (sender, s.proposal_counters); - case map_get(packed_msg, s.message_store) of - | Some(voters) -> block { // the message is stored - const new_set : addr_set_t = set_remove(sender,voters) ; + if sender_proposal_counter > s.max_proposal + then failwith ("Maximum number of proposal reached") + else skip; - // 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 ; + // check the threshold - // if the message is left without any associated addresses, remove the corresponding message_store field - if size(new_set) = 0n then remove packed_msg from map s.message_store - else s.message_store[packed_msg] := new_set - } - | None -> skip end // the message isn't stored, ignore + var ret_ops : list (operation) := nil; -} with ( (nil: list(operation)) , s) + if size (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)); + // decrement the counters + for addr -> ctr in map s.proposal_counters block { + if set_mem(addr,new_store) then + s.proposal_counters[addr] := abs (ctr - 1n) + else skip + } + } else s.message_store[packed_msg] := new_store + } with (ret_ops, s) -function default (const p : default_pt; const s : storage_t) : contract_return_t is - ((nil: list(operation)) , s) +function withdraw (const param : withdraw_pt; const s : storage) : return is + block { + var message : message := param; + const packed_msg : bytes = bytes_pack (message); -function main(const param : entry_point_t; const s : storage_t) : contract_return_t is + case map_get(packed_msg, s.message_store) of + Some (voters) -> + block { + // The message is stored + const new_set : addr_set = set_remove (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 the message is left without any associated addresses, + remove the corresponding message_store field *) + + if size (new_set) = 0n + then remove packed_msg from map s.message_store + else s.message_store[packed_msg] := new_set + } + | None -> skip + end // The message is not stored, ignore. + } with ((nil : list (operation)), s) + +function default (const p : default_pt; const s : storage) : return is + ((nil : list (operation)), s) + +function main (const param : parameter; const s : storage) : return is case param of - // propagate message p if the number authorized addresses having - // voted for the same message p equals the threshold - | Send (p) -> send(p,s) - // withraw vote for message p - | Withdraw (p) -> withdraw(p,s) - // use this entry-point to transfer tez to the contract - | Default (p) -> default(p,s) -end \ No newline at end of file + (* Propagate message p if the number of authorized addresses having + voted for the same message p equals the threshold. *) + | Send (p) -> send (p, s) + + (* Withraw vote for message p *) + | Withdraw (p) -> withdraw (p, s) + + (* Use this action to transfer tez to the contract *) + | Default (p) -> default (p, s) + end diff --git a/src/test/contracts/multisig.ligo b/src/test/contracts/multisig.ligo index 90e7e30d7..f0cdb636c 100644 --- a/src/test/contracts/multisig.ligo +++ b/src/test/contracts/multisig.ligo @@ -1,62 +1,66 @@ // storage type -type counter_t is nat -type threshold_t is nat -type authorized_keys_t is list(key) -type id_t is string -type storage_t is record - id : id_t ; - counter : counter_t ; - threshold : threshold_t ; - auth : authorized_keys_t ; -end +type counter is nat +type threshold is nat +type authorized_keys is list (key) +type id is string + +type storage is + record [ + id : id; + counter : counter; + threshold : threshold; + auth : authorized_keys + ] // I/O types -type message_t is (unit -> list(operation)) -type signatures_t is list(key_hash * signature) -type check_message_pt is record - counter : counter_t ; - message : message_t ; - signatures : signatures_t ; -end -type contract_return_t is (list(operation) * storage_t) +type message is unit -> list (operation) -type entry_point_t is -| CheckMessage of check_message_pt +type signatures is list (key_hash * signature) + +type check_message_pt is + record [ + counter : counter; + message : message; + signatures : signatures + ] + +type return is list (operation) * storage + +type parameter is CheckMessage of check_message_pt function check_message (const param : check_message_pt; - const s : storage_t) : contract_return_t is block { - var message : message_t := param.message ; + const s : storage) : return is block { + var message : message := param.message; if param.counter =/= s.counter then failwith ("Counters does not match") - else block { + else { const packed_payload : bytes = - bytes_pack((message , param.counter , s.id , get_chain_id)); - var valid : nat := 0n ; + bytes_pack ((message, param.counter, s.id, get_chain_id)); + var valid : nat := 0n; - var keys : authorized_keys_t := s.auth ; + var keys : authorized_keys := s.auth; for pkh_sig in list param.signatures block { case keys of - | nil -> skip + 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) then valid := valid + 1n ; - else failwith ("Invalid signature") - else skip; - } + keys := tl; + 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 }; if valid < s.threshold then failwith ("Not enough signatures passed the check") - else s.counter := s.counter + 1n ; + else s.counter := s.counter + 1n } -} with (message(unit), s) +} with (message (unit), s) -function main(const param : entry_point_t; const s : storage_t) : contract_return_t is - case param of - | CheckMessage (p) -> check_message(p,s) -end \ No newline at end of file +function main (const param : parameter; const s : storage) : return is + case param of CheckMessage (p) -> check_message (p,s) end From 1bd9ca9d1e745f925b41809caaff876e262b2d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Sun, 9 Feb 2020 22:12:41 +0100 Subject: [PATCH 03/19] Remove message "tput: No value for $TERM and no -T specified" in gitlab builds --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc95f2f4b..d7beb8dc1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,6 +40,7 @@ dont-merge-to-master: - build-and-package-ubuntu-18-04 - build-and-package-ubuntu-19-04 before_script: + - export TERM=dumb - scripts/install_native_dependencies.sh - scripts/install_opam.sh # TODO: or scripts/install_build_environment.sh ? - export PATH="/usr/local/bin${PATH:+:}${PATH:-}" @@ -86,6 +87,7 @@ dont-merge-to-master: before_script: # Install dependencies # rsync is needed by opam to sync a package installed from a local directory with the copy in ~/.opam + - export TERM=dumb - scripts/install_native_dependencies.sh - scripts/install_opam.sh # TODO: or scripts/install_build_environment.sh ? - export PATH="/usr/local/bin${PATH:+:}${PATH:-}" From 140a0fe0b2d76425ee664c4cada1ff00f85822f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 11:33:05 +0100 Subject: [PATCH 04/19] Temporary debug prints for build-and-package failure --- .gitlab-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc95f2f4b..08275dfc8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,8 +25,8 @@ dont-merge-to-master: # 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" - - $package_binary_script "$target_os_family" "$target_os" "$target_os_version" + - $build_binary_script "$target_os_family" "$target_os" "$target_os_version" || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) + - $package_binary_script "$target_os_family" "$target_os" "$target_os_version" || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) artifacts: paths: - dist/package/**/* @@ -46,12 +46,12 @@ dont-merge-to-master: - eval $(opam config env) - scripts/setup_switch.sh - eval $(opam config env) - - scripts/setup_repos.sh + - scripts/setup_repos.sh || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) # install deps for internal documentation - - scripts/install_vendors_deps.sh + - scripts/install_vendors_deps.sh || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) - opam install -y odoc - - scripts/build_ligo_local.sh + - scripts/build_ligo_local.sh || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) # build with odoc - dune build @doc From 3969df5a5d17538c03faf9d95ca62a35ee4e4282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 11:35:05 +0100 Subject: [PATCH 05/19] Fixes in SH scripts --- scripts/build_docker_image.sh | 2 +- scripts/distribution/generic/build.sh | 1 + scripts/distribution/generic/package.sh | 1 + scripts/distribution/generic/parameters.sh | 11 +++++++---- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/build_docker_image.sh b/scripts/build_docker_image.sh index 260a530c7..0aaefe8c8 100755 --- a/scripts/build_docker_image.sh +++ b/scripts/build_docker_image.sh @@ -1,3 +1,3 @@ #!/bin/sh set -e -docker build -t "${LIGO_REGISTRY_IMAGE_BUILD:-ligolang/ligo}:next" -f ./docker/distribution/debian/distribute.Dockerfile . \ No newline at end of file +docker build -t "${LIGO_REGISTRY_IMAGE_BUILD:-ligolang/ligo}:next" -f ./docker/distribution/debian/distribute.Dockerfile . diff --git a/scripts/distribution/generic/build.sh b/scripts/distribution/generic/build.sh index 49aba15e1..48971962a 100755 --- a/scripts/distribution/generic/build.sh +++ b/scripts/distribution/generic/build.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -e dockerfile_name="build" # Generic dockerfile diff --git a/scripts/distribution/generic/package.sh b/scripts/distribution/generic/package.sh index 79be37d41..266678ec4 100755 --- a/scripts/distribution/generic/package.sh +++ b/scripts/distribution/generic/package.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -e dockerfile_name="package" dockerfile="" diff --git a/scripts/distribution/generic/parameters.sh b/scripts/distribution/generic/parameters.sh index 3899711d8..98e35e20c 100644 --- a/scripts/distribution/generic/parameters.sh +++ b/scripts/distribution/generic/parameters.sh @@ -1,11 +1,14 @@ +#!/bin/sh +set -e + # This script accepts three arguments, os family, os and its version, # which are subsequently used to fetch the respective docker # image from the ocaml/infrastructure project. # # https://github.com/ocaml/infrastructure/wiki/Containers#selecting-linux-distributions -target_os_family=$1 -target_os=$2 -target_os_version=$3 +target_os_family="$1" +target_os="$2" +target_os_version="$3" # Variables configured at the CI level dist="$LIGO_DIST_DIR" @@ -29,4 +32,4 @@ fi target_os_specific_dockerfile="./docker/distribution/$target_os_family/$target_os/$dockerfile_name.Dockerfile" if test -f "$target_os_specific_dockerfile"; then dockerfile="$target_os_specific_dockerfile" -fi \ No newline at end of file +fi From 8f03d45ec3abfead4c990e6a09c653c667a26ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 11:35:31 +0100 Subject: [PATCH 06/19] Make more scripts print their commands, to help debug issues in GitLab --- scripts/build_docker_image.sh | 1 + scripts/build_ligo_local.sh | 1 + scripts/distribution/generic/build.sh | 1 + scripts/distribution/generic/package.sh | 1 + scripts/distribution/generic/parameters.sh | 1 + scripts/install_native_dependencies.sh | 1 + scripts/install_vendors_deps.sh | 1 + 7 files changed, 7 insertions(+) diff --git a/scripts/build_docker_image.sh b/scripts/build_docker_image.sh index 0aaefe8c8..f342b424f 100755 --- a/scripts/build_docker_image.sh +++ b/scripts/build_docker_image.sh @@ -1,3 +1,4 @@ #!/bin/sh set -e +set -x docker build -t "${LIGO_REGISTRY_IMAGE_BUILD:-ligolang/ligo}:next" -f ./docker/distribution/debian/distribute.Dockerfile . diff --git a/scripts/build_ligo_local.sh b/scripts/build_ligo_local.sh index b78e4ffd6..fb556805a 100755 --- a/scripts/build_ligo_local.sh +++ b/scripts/build_ligo_local.sh @@ -1,5 +1,6 @@ #!/bin/sh set -e +set -x eval $(opam config env) dune build -p ligo diff --git a/scripts/distribution/generic/build.sh b/scripts/distribution/generic/build.sh index 48971962a..968f55a21 100755 --- a/scripts/distribution/generic/build.sh +++ b/scripts/distribution/generic/build.sh @@ -1,5 +1,6 @@ #!/bin/sh set -e +set -x dockerfile_name="build" # Generic dockerfile diff --git a/scripts/distribution/generic/package.sh b/scripts/distribution/generic/package.sh index 266678ec4..d9d047e6d 100755 --- a/scripts/distribution/generic/package.sh +++ b/scripts/distribution/generic/package.sh @@ -1,5 +1,6 @@ #!/bin/sh set -e +set -x dockerfile_name="package" dockerfile="" diff --git a/scripts/distribution/generic/parameters.sh b/scripts/distribution/generic/parameters.sh index 98e35e20c..2241b9fb0 100644 --- a/scripts/distribution/generic/parameters.sh +++ b/scripts/distribution/generic/parameters.sh @@ -1,5 +1,6 @@ #!/bin/sh set -e +set -x # This script accepts three arguments, os family, os and its version, # which are subsequently used to fetch the respective docker diff --git a/scripts/install_native_dependencies.sh b/scripts/install_native_dependencies.sh index 2a0e56903..191ae5502 100755 --- a/scripts/install_native_dependencies.sh +++ b/scripts/install_native_dependencies.sh @@ -1,5 +1,6 @@ #!/bin/sh set -e +set -x . /etc/os-release if [ $ID = arch ] diff --git a/scripts/install_vendors_deps.sh b/scripts/install_vendors_deps.sh index 15f9b47d4..5c870ffdc 100755 --- a/scripts/install_vendors_deps.sh +++ b/scripts/install_vendors_deps.sh @@ -1,5 +1,6 @@ #!/bin/sh set -e +set -x # Install local dependencies opam install -y --deps-only --with-test ./ligo.opam $(find vendors -name \*.opam) From 35815ce5b41c371227fcf5fe23c69bcc8a217b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 11:39:31 +0100 Subject: [PATCH 07/19] Removed vendors/UnionFind/UnionFind.install which is a generated file that was .gitignored but had been added by accident --- vendors/UnionFind/UnionFind.install | 36 ----------------------------- 1 file changed, 36 deletions(-) delete mode 100644 vendors/UnionFind/UnionFind.install diff --git a/vendors/UnionFind/UnionFind.install b/vendors/UnionFind/UnionFind.install deleted file mode 100644 index 692984e20..000000000 --- a/vendors/UnionFind/UnionFind.install +++ /dev/null @@ -1,36 +0,0 @@ -lib: [ - "_build/install/default/lib/UnionFind/META" - "_build/install/default/lib/UnionFind/Partition.cmi" - "_build/install/default/lib/UnionFind/Partition.cmti" - "_build/install/default/lib/UnionFind/Partition.mli" - "_build/install/default/lib/UnionFind/Partition0.cmi" - "_build/install/default/lib/UnionFind/Partition0.cmt" - "_build/install/default/lib/UnionFind/Partition0.cmx" - "_build/install/default/lib/UnionFind/Partition0.ml" - "_build/install/default/lib/UnionFind/Partition1.cmi" - "_build/install/default/lib/UnionFind/Partition1.cmt" - "_build/install/default/lib/UnionFind/Partition1.cmx" - "_build/install/default/lib/UnionFind/Partition1.ml" - "_build/install/default/lib/UnionFind/Partition2.cmi" - "_build/install/default/lib/UnionFind/Partition2.cmt" - "_build/install/default/lib/UnionFind/Partition2.cmx" - "_build/install/default/lib/UnionFind/Partition2.ml" - "_build/install/default/lib/UnionFind/Partition3.cmi" - "_build/install/default/lib/UnionFind/Partition3.cmt" - "_build/install/default/lib/UnionFind/Partition3.cmx" - "_build/install/default/lib/UnionFind/Partition3.ml" - "_build/install/default/lib/UnionFind/UnionFind.a" - "_build/install/default/lib/UnionFind/UnionFind.cma" - "_build/install/default/lib/UnionFind/UnionFind.cmxa" - "_build/install/default/lib/UnionFind/UnionFind.cmxs" - "_build/install/default/lib/UnionFind/dune-package" - "_build/install/default/lib/UnionFind/opam" - "_build/install/default/lib/UnionFind/unionFind.cmi" - "_build/install/default/lib/UnionFind/unionFind.cmt" - "_build/install/default/lib/UnionFind/unionFind.cmx" - "_build/install/default/lib/UnionFind/unionFind.ml" -] -doc: [ - "_build/install/default/doc/UnionFind/LICENSE" - "_build/install/default/doc/UnionFind/README.md" -] From 42699256e5bdb936b2653c9d8b491daff5931b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 11:50:28 +0100 Subject: [PATCH 08/19] Run adt_generator.exe as part of dune runtest --- src/stages/adt_generator/dune | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/stages/adt_generator/dune b/src/stages/adt_generator/dune index 4a52c6088..b47ce3191 100644 --- a/src/stages/adt_generator/dune +++ b/src/stages/adt_generator/dune @@ -16,3 +16,8 @@ (libraries ) ) + +(alias + (name runtest) + (action (run ./adt_generator.exe)) +) From 76ad9c47ec724e03d218ab688a1f366db9de6c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 11:42:32 +0100 Subject: [PATCH 09/19] cleanup --- src/passes/4-typer-old/typer.ml | 1 - src/stages/adt_generator/README | 4 ++-- src/stages/ast_typed/types.ml | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/passes/4-typer-old/typer.ml b/src/passes/4-typer-old/typer.ml index 87f4b2477..7c1cd41a4 100644 --- a/src/passes/4-typer-old/typer.ml +++ b/src/passes/4-typer-old/typer.ml @@ -649,7 +649,6 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let wtype = Format.asprintf "Loops over collections expect lists, sets or maps, got type %a" O.PP.type_expression tv_col in fail @@ simple_error wtype in - let lname = lname in let e' = Environment.add_ez_binder lname input_type e in let%bind body = type_expression' ?tv_opt:(Some tv_out) e' result in let output_type = body.type_expression in diff --git a/src/stages/adt_generator/README b/src/stages/adt_generator/README index 20ecdfd43..2d1b53c3d 100644 --- a/src/stages/adt_generator/README +++ b/src/stages/adt_generator/README @@ -1,6 +1,6 @@ -Build with: +Build & test with: - dune build adt_generator.a + dune build adt_generator.exe && ../../../_build/default/src/stages/adt_generator/adt_generator.exe Run with diff --git a/src/stages/ast_typed/types.ml b/src/stages/ast_typed/types.ml index 5aa323c9b..8804e49e7 100644 --- a/src/stages/ast_typed/types.ml +++ b/src/stages/ast_typed/types.ml @@ -95,7 +95,6 @@ and matching = and ascription = {anno_expr: expression; type_annotation: type_expression} - and environment_element_definition = | ED_binder | ED_declaration of (expression * free_variables) From c3b1c1ac0f2182392ef3947a8c092f10791e6fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 11:49:13 +0100 Subject: [PATCH 10/19] Removed promote-until-clean because it moves the file out of _build instead of copying it, which causes issues for the gitlab build --- src/stages/adt_generator/dune | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stages/adt_generator/dune b/src/stages/adt_generator/dune index b47ce3191..1729a9aba 100644 --- a/src/stages/adt_generator/dune +++ b/src/stages/adt_generator/dune @@ -2,7 +2,8 @@ (target fold.ml) (deps generator.py) (action (with-stdout-to fold.ml (run python3 ./generator.py))) - (mode (promote (until-clean)))) +; (mode (promote (until-clean))) ; If this is uncommented, then "dune build -p ligo" can't find the file (but "dune build" can) +) ; (library ; (name adt_generator) ; (public_name ligo.adt_generator) From 2588de23951ee90102c3b453451ba56ec71acbd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 11:49:54 +0100 Subject: [PATCH 11/19] Remove generated file fold.ml --- src/stages/adt_generator/.gitignore | 2 + src/stages/adt_generator/dune | 4 +- src/stages/adt_generator/fold.ml | 185 +--------------------------- 3 files changed, 5 insertions(+), 186 deletions(-) create mode 100644 src/stages/adt_generator/.gitignore diff --git a/src/stages/adt_generator/.gitignore b/src/stages/adt_generator/.gitignore new file mode 100644 index 000000000..9ec2ad34e --- /dev/null +++ b/src/stages/adt_generator/.gitignore @@ -0,0 +1,2 @@ +# This is an auto-generated test file +/generated_fold.ml diff --git a/src/stages/adt_generator/dune b/src/stages/adt_generator/dune index 1729a9aba..d70d8647e 100644 --- a/src/stages/adt_generator/dune +++ b/src/stages/adt_generator/dune @@ -1,7 +1,7 @@ (rule - (target fold.ml) + (target generated_fold.ml) (deps generator.py) - (action (with-stdout-to fold.ml (run python3 ./generator.py))) + (action (with-stdout-to generated_fold.ml (run python3 ./generator.py))) ; (mode (promote (until-clean))) ; If this is uncommented, then "dune build -p ligo" can't find the file (but "dune build" can) ) ; (library diff --git a/src/stages/adt_generator/fold.ml b/src/stages/adt_generator/fold.ml index 4e4c41357..271974820 100644 --- a/src/stages/adt_generator/fold.ml +++ b/src/stages/adt_generator/fold.ml @@ -1,184 +1 @@ -open A - -type root' = - | A' of a' - | B' of int - | C' of string -and a' = - { - a1' : ta1' ; - a2' : ta2' ; - } -and ta1' = - | X' of root' - | Y' of ta2' -and ta2' = - | Z' of ta2' - | W' of unit - -type 'state continue_fold = - { - root : root -> 'state -> (root' * 'state) ; - root_A : a -> 'state -> (a' * 'state) ; - root_B : int -> 'state -> (int * 'state) ; - root_C : string -> 'state -> (string * 'state) ; - a : a -> 'state -> (a' * 'state) ; - a_a1 : ta1 -> 'state -> (ta1' * 'state) ; - a_a2 : ta2 -> 'state -> (ta2' * 'state) ; - ta1 : ta1 -> 'state -> (ta1' * 'state) ; - ta1_X : root -> 'state -> (root' * 'state) ; - ta1_Y : ta2 -> 'state -> (ta2' * 'state) ; - ta2 : ta2 -> 'state -> (ta2' * 'state) ; - ta2_Z : ta2 -> 'state -> (ta2' * 'state) ; - ta2_W : unit -> 'state -> (unit * 'state) ; - } - -type 'state fold_config = - { - root : root -> 'state -> ('state continue_fold) -> (root' * 'state) ; - root_pre_state : root -> 'state -> 'state ; - root_post_state : root -> root' -> 'state -> 'state ; - root_A : a -> 'state -> ('state continue_fold) -> (a' * 'state) ; - root_B : int -> 'state -> ('state continue_fold) -> (int * 'state) ; - root_C : string -> 'state -> ('state continue_fold) -> (string * 'state) ; - a : a -> 'state -> ('state continue_fold) -> (a' * 'state) ; - a_pre_state : a -> 'state -> 'state ; - a_post_state : a -> a' -> 'state -> 'state ; - a_a1 : ta1 -> 'state -> ('state continue_fold) -> (ta1' * 'state) ; - a_a2 : ta2 -> 'state -> ('state continue_fold) -> (ta2' * 'state) ; - ta1 : ta1 -> 'state -> ('state continue_fold) -> (ta1' * 'state) ; - ta1_pre_state : ta1 -> 'state -> 'state ; - ta1_post_state : ta1 -> ta1' -> 'state -> 'state ; - ta1_X : root -> 'state -> ('state continue_fold) -> (root' * 'state) ; - ta1_Y : ta2 -> 'state -> ('state continue_fold) -> (ta2' * 'state) ; - ta2 : ta2 -> 'state -> ('state continue_fold) -> (ta2' * 'state) ; - ta2_pre_state : ta2 -> 'state -> 'state ; - ta2_post_state : ta2 -> ta2' -> 'state -> 'state ; - ta2_Z : ta2 -> 'state -> ('state continue_fold) -> (ta2' * 'state) ; - ta2_W : unit -> 'state -> ('state continue_fold) -> (unit * 'state) ; - } - -(* Curries the "visitor" argument to the folds (non-customizable traversal functions). *) -let rec mk_continue_fold : type state . state fold_config -> state continue_fold = fun visitor -> - { - root = fold_root visitor ; - root_A = fold_root_A visitor ; - root_B = fold_root_B visitor ; - root_C = fold_root_C visitor ; - a = fold_a visitor ; - a_a1 = fold_a_a1 visitor ; - a_a2 = fold_a_a2 visitor ; - ta1 = fold_ta1 visitor ; - ta1_X = fold_ta1_X visitor ; - ta1_Y = fold_ta1_Y visitor ; - ta2 = fold_ta2 visitor ; - ta2_Z = fold_ta2_Z visitor ; - ta2_W = fold_ta2_W visitor ; -} - -and fold_root : type state . state fold_config -> root -> state -> (root' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - let state = visitor.root_pre_state x state in - let (new_x, state) = visitor.root x state continue_fold in - let state = visitor.root_post_state x new_x state in - (new_x, state) - -and fold_root_A : type state . state fold_config -> a -> state -> (a' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - visitor.root_A x state continue_fold - -and fold_root_B : type state . state fold_config -> int -> state -> (int * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - visitor.root_B x state continue_fold - -and fold_root_C : type state . state fold_config -> string -> state -> (string * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - visitor.root_C x state continue_fold - -and fold_a : type state . state fold_config -> a -> state -> (a' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - let state = visitor.a_pre_state x state in - let (new_x, state) = visitor.a x state continue_fold in - let state = visitor.a_post_state x new_x state in - (new_x, state) - -and fold_a_a1 : type state . state fold_config -> ta1 -> state -> (ta1' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - visitor.a_a1 x state continue_fold - -and fold_a_a2 : type state . state fold_config -> ta2 -> state -> (ta2' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - visitor.a_a2 x state continue_fold - -and fold_ta1 : type state . state fold_config -> ta1 -> state -> (ta1' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - let state = visitor.ta1_pre_state x state in - let (new_x, state) = visitor.ta1 x state continue_fold in - let state = visitor.ta1_post_state x new_x state in - (new_x, state) - -and fold_ta1_X : type state . state fold_config -> root -> state -> (root' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - visitor.ta1_X x state continue_fold - -and fold_ta1_Y : type state . state fold_config -> ta2 -> state -> (ta2' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - visitor.ta1_Y x state continue_fold - -and fold_ta2 : type state . state fold_config -> ta2 -> state -> (ta2' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - let state = visitor.ta2_pre_state x state in - let (new_x, state) = visitor.ta2 x state continue_fold in - let state = visitor.ta2_post_state x new_x state in - (new_x, state) - -and fold_ta2_Z : type state . state fold_config -> ta2 -> state -> (ta2' * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - visitor.ta2_Z x state continue_fold - -and fold_ta2_W : type state . state fold_config -> unit -> state -> (unit * state) = fun visitor x state -> - let continue_fold : state continue_fold = mk_continue_fold visitor in - visitor.ta2_W x state continue_fold - -let no_op : 'a fold_config = { - root = (fun v state continue -> - match v with - | A v -> let (v, state) = continue.root_A v state in (A' v, state) - | B v -> let (v, state) = continue.root_B v state in (B' v, state) - | C v -> let (v, state) = continue.root_C v state in (C' v, state) - ); - root_pre_state = (fun v state -> ignore v; state) ; - root_post_state = (fun v new_v state -> ignore (v, new_v); state) ; - root_A = (fun v state continue -> continue.a v state ) ; - root_B = (fun v state continue -> ignore continue; (v, state) ) ; - root_C = (fun v state continue -> ignore continue; (v, state) ) ; - a = (fun v state continue -> - match v with - { a1; a2; } -> - let (a1', state) = continue.a_a1 a1 state in - let (a2', state) = continue.a_a2 a2 state in - ({ a1'; a2'; }, state) - ); - a_pre_state = (fun v state -> ignore v; state) ; - a_post_state = (fun v new_v state -> ignore (v, new_v); state) ; - a_a1 = (fun v state continue -> continue.ta1 v state ) ; - a_a2 = (fun v state continue -> continue.ta2 v state ) ; - ta1 = (fun v state continue -> - match v with - | X v -> let (v, state) = continue.ta1_X v state in (X' v, state) - | Y v -> let (v, state) = continue.ta1_Y v state in (Y' v, state) - ); - ta1_pre_state = (fun v state -> ignore v; state) ; - ta1_post_state = (fun v new_v state -> ignore (v, new_v); state) ; - ta1_X = (fun v state continue -> continue.root v state ) ; - ta1_Y = (fun v state continue -> continue.ta2 v state ) ; - ta2 = (fun v state continue -> - match v with - | Z v -> let (v, state) = continue.ta2_Z v state in (Z' v, state) - | W v -> let (v, state) = continue.ta2_W v state in (W' v, state) - ); - ta2_pre_state = (fun v state -> ignore v; state) ; - ta2_post_state = (fun v new_v state -> ignore (v, new_v); state) ; - ta2_Z = (fun v state continue -> continue.ta2 v state ) ; - ta2_W = (fun v state continue -> ignore continue; (v, state) ) ; -} +include Generated_fold From 5151a0fd92586af5d899b4ce1d889380aa5b3fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 11:45:44 +0100 Subject: [PATCH 12/19] =?UTF-8?q?ADT=20generator:=20polymorphic=20types=20?= =?UTF-8?q?(list,=20option=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stages/adt_generator/a.ml | 21 +++++++++- src/stages/adt_generator/generator.py | 58 +++++++++++++++++++------- src/stages/adt_generator/use_a_fold.ml | 6 +-- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/src/stages/adt_generator/a.ml b/src/stages/adt_generator/a.ml index f1d8b2fb1..34b611dc1 100644 --- a/src/stages/adt_generator/a.ml +++ b/src/stages/adt_generator/a.ml @@ -1,6 +1,6 @@ type root = -| A of a -| B of int +| A of rootA +| B of rootB | C of string and a = { @@ -15,3 +15,20 @@ and ta1 = and ta2 = | Z of ta2 | W of unit + +and rootA = + a list + +and rootB = + int list + +let fold_list v state continue = + let aux = fun (lst', state) elt -> + let (elt', state) = continue elt state in + (elt' :: lst' , state) in + List.fold_left aux ([], state) v + +let fold_option v state continue = + match v with + Some x -> continue x state + | None -> None diff --git a/src/stages/adt_generator/generator.py b/src/stages/adt_generator/generator.py index 65fe21878..48b8c5fd4 100644 --- a/src/stages/adt_generator/generator.py +++ b/src/stages/adt_generator/generator.py @@ -1,34 +1,49 @@ moduleName = "A" +variant="_ _variant" +record="_ _record" +def poly(x): return x adts = [ - # typename, variant?, fields_or_ctors - ("root", True, [ - # ctor, builtin, type - ("A", False, "a"), - ("B", True, "int"), + # typename, kind, fields_or_ctors + ("root", variant, [ + # ctor, builtin?, type + ("A", False, "rootA"), + ("B", False, "rootB"), ("C", True, "string"), ]), - ("a", False, [ + ("a", record, [ + # field, builtin?, type ("a1", False, "ta1"), ("a2", False, "ta2"), ]), - ("ta1", True, [ + ("ta1", variant, [ ("X", False, "root"), ("Y", False, "ta2"), ]), - ("ta2", True, [ + ("ta2", variant, [ ("Z", False, "ta2"), ("W", True, "unit"), ]), + # polymorphic type + ("rootA", poly("list"), + [ + # Position (0..n-1), builtin?, type argument + (0, False, "a") + ]), + ("rootB", poly("list"), + [ + # Position (0..n-1), builtin?, type argument + (0, True, "int") + ]), ] from collections import namedtuple -adt = namedtuple('adt', ['name', 'newName', 'isVariant', 'ctorsOrFields']) +adt = namedtuple('adt', ['name', 'newName', 'kind', 'ctorsOrFields']) ctorOrField = namedtuple('ctorOrField', ['name', 'newName', 'isBuiltin', 'type_', 'newType']) adts = [ adt( name = name, newName = f"{name}'", - isVariant = isVariant, + kind = kind, ctorsOrFields = [ ctorOrField( name = cf, @@ -40,23 +55,32 @@ adts = [ for (cf, isBuiltin, type_) in ctors ], ) - for (name, isVariant, ctors) in adts + for (name, kind, ctors) in adts ] +print("(* This is an auto-generated file. Do not edit. *)") + +print("") print("open %s" % moduleName) print("") for (index, t) in enumerate(adts): typeOrAnd = "type" if index == 0 else "and" print(f"{typeOrAnd} {t.newName} =") - if t.isVariant: + if t.kind == variant: for c in t.ctorsOrFields: print(f" | {c.newName} of {c.newType}") - else: + elif t.kind == record: print(" {") for f in t.ctorsOrFields: print(f" {f.newName} : {f.newType} ;") print(" }") + else: + print(" ", end='') + for a in t.ctorsOrFields: + print(f"{a.newType}", end=' ') + print(t.kind, end='') + print("") print("") print(f"type 'state continue_fold =") @@ -107,10 +131,10 @@ print("let no_op : 'a fold_config = {") for t in adts: print(f" {t.name} = (fun v state continue ->") print(" match v with") - if t.isVariant: + if t.kind == variant: for c in t.ctorsOrFields: print(f" | {c.name} v -> let (v, state) = continue.{t.name}_{c.name} v state in ({c.newName} v, state)") - else: + elif t.kind == record: print(" {", end=' ') for f in t.ctorsOrFields: print(f"{f.name};", end=' ') @@ -121,6 +145,10 @@ for t in adts: for f in t.ctorsOrFields: print(f"{f.newName};", end=' ') print("}, state)") + else: + print(f" v -> fold_{t.kind} v state (", end=' ') + print(", ".join([f"continue.{t.name}_{f.name}" for f in t.ctorsOrFields]), end='') + print(" )") print(" );") print(f" {t.name}_pre_state = (fun v state -> ignore v; state) ;") print(f" {t.name}_post_state = (fun v new_v state -> ignore (v, new_v); state) ;") diff --git a/src/stages/adt_generator/use_a_fold.ml b/src/stages/adt_generator/use_a_fold.ml index 6a73f4782..0fe476d42 100644 --- a/src/stages/adt_generator/use_a_fold.ml +++ b/src/stages/adt_generator/use_a_fold.ml @@ -4,7 +4,7 @@ open Fold (* TODO: how should we plug these into our test framework? *) let () = - let some_root : root = A { a1 = X (A { a1 = X (B 1) ; a2 = W () ; }) ; a2 = Z (W ()) ; } in + let some_root : root = A [{ a1 = X (A [{ a1 = X (B [1;2;3]) ; a2 = W () ; }]) ; a2 = Z (W ()) ; }] in let op = { no_op with a = fun the_a state continue_fold -> @@ -23,7 +23,7 @@ let () = () let () = - let some_root : root = A { a1 = X (A { a1 = X (B 1) ; a2 = W () ; }) ; a2 = Z (W ()) ; } in + let some_root : root = A [{ a1 = X (A [{ a1 = X (B [1;2;3]) ; a2 = W () ; }]) ; a2 = Z (W ()) ; }] in let op = { no_op with a_pre_state = fun _the_a state -> state + 1 } in let state = 0 in let (_, state) = fold_root op some_root state in @@ -33,7 +33,7 @@ let () = () let () = - let some_root : root = A { a1 = X (A { a1 = X (B 1) ; a2 = W () ; }) ; a2 = Z (W ()) ; } in + let some_root : root = A [{ a1 = X (A [{ a1 = X (B [1;2;3]) ; a2 = W () ; }]) ; a2 = Z (W ()) ; }] in let op = { no_op with a_post_state = fun _the_a _new_a state -> state + 1 } in let state = 0 in let (_, state) = fold_root op some_root state in From c71e47f252d9238007a7584b8050e1159fabde5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 19:01:26 +0100 Subject: [PATCH 13/19] Make menhir less verbose, to see error messages in gitlab. --- src/passes/1-parser/cameligo/dune | 2 +- src/passes/1-parser/pascaligo/dune | 2 +- src/passes/1-parser/reasonligo/dune | 2 +- vendors/Preproc/build.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/passes/1-parser/cameligo/dune b/src/passes/1-parser/cameligo/dune index 8824fdcd4..4e6829f1e 100644 --- a/src/passes/1-parser/cameligo/dune +++ b/src/passes/1-parser/cameligo/dune @@ -7,7 +7,7 @@ (menhir (merge_into Parser) (modules ParToken Parser) - (flags -la 1 --table --strict --explain --external-tokens LexToken)) + (flags --table --strict --external-tokens LexToken)) ;; Build of the parser as a library diff --git a/src/passes/1-parser/pascaligo/dune b/src/passes/1-parser/pascaligo/dune index d0d43f02f..e7b9a9a73 100644 --- a/src/passes/1-parser/pascaligo/dune +++ b/src/passes/1-parser/pascaligo/dune @@ -7,7 +7,7 @@ (menhir (merge_into Parser) (modules ParToken Parser) - (flags -la 1 --table --strict --explain --external-tokens LexToken)) + (flags --table --strict --external-tokens LexToken)) ;; Build of the parser as a library diff --git a/src/passes/1-parser/reasonligo/dune b/src/passes/1-parser/reasonligo/dune index 6eb7304b8..a1408af91 100644 --- a/src/passes/1-parser/reasonligo/dune +++ b/src/passes/1-parser/reasonligo/dune @@ -7,7 +7,7 @@ (menhir (merge_into Parser) (modules ParToken Parser) - (flags -la 1 --table --strict --explain --external-tokens LexToken)) + (flags --table --strict --external-tokens LexToken)) ;; Build of the parser as a library diff --git a/vendors/Preproc/build.sh b/vendors/Preproc/build.sh index e9d6546be..30e3ba705 100755 --- a/vendors/Preproc/build.sh +++ b/vendors/Preproc/build.sh @@ -2,7 +2,7 @@ set -x ocamllex.opt Escan.mll ocamllex.opt Preproc.mll -menhir -la 1 Eparser.mly +menhir Eparser.mly ocamlfind ocamlopt -strict-sequence -w +A-48-4 -c Etree.ml ocamlfind ocamlopt -strict-sequence -w +A-48-4 -c Error.ml ocamlfind ocamlopt -strict-sequence -w +A-48-4 -c Etree.ml From e84b739fbc21e87ba1f30588ccb85c537aa18c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 19:07:39 +0100 Subject: [PATCH 14/19] try to debug inside docker --- docker/distribution/generic/build.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/distribution/generic/build.Dockerfile b/docker/distribution/generic/build.Dockerfile index f6c9358e9..bd1ee920a 100644 --- a/docker/distribution/generic/build.Dockerfile +++ b/docker/distribution/generic/build.Dockerfile @@ -29,7 +29,7 @@ RUN opam update # Install ligo RUN sh scripts/install_vendors_deps.sh -RUN opam install -y . +RUN opam install -y . || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) # Use the ligo binary as a default command ENTRYPOINT [ "/home/opam/.opam/4.07/bin/ligo" ] From 7bad718135d1bac1cec162904d6f4430dde22088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 19:42:35 +0100 Subject: [PATCH 15/19] Add missing dependency on Python 3 --- scripts/install_build_environment.sh | 3 +++ scripts/install_native_dependencies.sh | 2 ++ tools/webide/Dockerfile | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/install_build_environment.sh b/scripts/install_build_environment.sh index 0dd33f068..628235e70 100755 --- a/scripts/install_build_environment.sh +++ b/scripts/install_build_environment.sh @@ -22,6 +22,7 @@ echo "Installing dependencies.." if [ -n "`uname -a | grep -i arch`" ] then sudo pacman -Sy --noconfirm \ + python \ make \ m4 \ gcc \ @@ -34,6 +35,8 @@ fi if [ -n "`uname -a | grep -i ubuntu`" ] then sudo apt-get install -y make \ + python3 \ + make \ m4 \ gcc \ patch \ diff --git a/scripts/install_native_dependencies.sh b/scripts/install_native_dependencies.sh index 191ae5502..f12e76cb2 100755 --- a/scripts/install_native_dependencies.sh +++ b/scripts/install_native_dependencies.sh @@ -7,6 +7,7 @@ if [ $ID = arch ] then pacman -Sy sudo pacman -S --noconfirm \ + python \ libevdev \ perl \ pkg-config \ @@ -21,6 +22,7 @@ then else apt-get update -qq apt-get -y -qq install \ + python3 \ libev-dev \ perl \ pkg-config \ diff --git a/tools/webide/Dockerfile b/tools/webide/Dockerfile index 4dfa9963a..212b12130 100644 --- a/tools/webide/Dockerfile +++ b/tools/webide/Dockerfile @@ -17,7 +17,7 @@ FROM node:12-buster WORKDIR /app -RUN apt-get update && apt-get -y install libev-dev perl pkg-config libgmp-dev libhidapi-dev m4 libcap-dev bubblewrap rsync +RUN apt-get update && apt-get -y install python3 libev-dev perl pkg-config libgmp-dev libhidapi-dev m4 libcap-dev bubblewrap rsync COPY ligo_deb10.deb /tmp/ligo_deb10.deb RUN dpkg -i /tmp/ligo_deb10.deb && rm /tmp/ligo_deb10.deb From e6dbe60c2cb6e41906eb1884cc51ee59a79771e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 19:54:26 +0100 Subject: [PATCH 16/19] Revert "try to debug inside docker" This reverts commit 37daa934d5e7ba60614a92cf0dfa9d4ebfac59d2. --- docker/distribution/generic/build.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/distribution/generic/build.Dockerfile b/docker/distribution/generic/build.Dockerfile index bd1ee920a..f6c9358e9 100644 --- a/docker/distribution/generic/build.Dockerfile +++ b/docker/distribution/generic/build.Dockerfile @@ -29,7 +29,7 @@ RUN opam update # Install ligo RUN sh scripts/install_vendors_deps.sh -RUN opam install -y . || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) +RUN opam install -y . # Use the ligo binary as a default command ENTRYPOINT [ "/home/opam/.opam/4.07/bin/ligo" ] From 76fa4b0549906960b134ca0ac0524120fd850c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 19:54:35 +0100 Subject: [PATCH 17/19] Revert "Make menhir less verbose, to see error messages in gitlab." This reverts commit b5f3ae76b049d4e712bd539b39d771191bc8978b. --- src/passes/1-parser/cameligo/dune | 2 +- src/passes/1-parser/pascaligo/dune | 2 +- src/passes/1-parser/reasonligo/dune | 2 +- vendors/Preproc/build.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/passes/1-parser/cameligo/dune b/src/passes/1-parser/cameligo/dune index 4e6829f1e..8824fdcd4 100644 --- a/src/passes/1-parser/cameligo/dune +++ b/src/passes/1-parser/cameligo/dune @@ -7,7 +7,7 @@ (menhir (merge_into Parser) (modules ParToken Parser) - (flags --table --strict --external-tokens LexToken)) + (flags -la 1 --table --strict --explain --external-tokens LexToken)) ;; Build of the parser as a library diff --git a/src/passes/1-parser/pascaligo/dune b/src/passes/1-parser/pascaligo/dune index e7b9a9a73..d0d43f02f 100644 --- a/src/passes/1-parser/pascaligo/dune +++ b/src/passes/1-parser/pascaligo/dune @@ -7,7 +7,7 @@ (menhir (merge_into Parser) (modules ParToken Parser) - (flags --table --strict --external-tokens LexToken)) + (flags -la 1 --table --strict --explain --external-tokens LexToken)) ;; Build of the parser as a library diff --git a/src/passes/1-parser/reasonligo/dune b/src/passes/1-parser/reasonligo/dune index a1408af91..6eb7304b8 100644 --- a/src/passes/1-parser/reasonligo/dune +++ b/src/passes/1-parser/reasonligo/dune @@ -7,7 +7,7 @@ (menhir (merge_into Parser) (modules ParToken Parser) - (flags --table --strict --external-tokens LexToken)) + (flags -la 1 --table --strict --explain --external-tokens LexToken)) ;; Build of the parser as a library diff --git a/vendors/Preproc/build.sh b/vendors/Preproc/build.sh index 30e3ba705..e9d6546be 100755 --- a/vendors/Preproc/build.sh +++ b/vendors/Preproc/build.sh @@ -2,7 +2,7 @@ set -x ocamllex.opt Escan.mll ocamllex.opt Preproc.mll -menhir Eparser.mly +menhir -la 1 Eparser.mly ocamlfind ocamlopt -strict-sequence -w +A-48-4 -c Etree.ml ocamlfind ocamlopt -strict-sequence -w +A-48-4 -c Error.ml ocamlfind ocamlopt -strict-sequence -w +A-48-4 -c Etree.ml From 0e5002fbeba508e947df119c3ce41732fdb00ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 20:03:47 +0100 Subject: [PATCH 18/19] Revert "Temporary debug prints for build-and-package failure" This reverts commit 81690394b0a6d5194b3f8603a1b066ce856ebfae. --- .gitlab-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 08275dfc8..fc95f2f4b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,8 +25,8 @@ dont-merge-to-master: # 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" || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) - - $package_binary_script "$target_os_family" "$target_os" "$target_os_version" || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) + - $build_binary_script "$target_os_family" "$target_os" "$target_os_version" + - $package_binary_script "$target_os_family" "$target_os" "$target_os_version" artifacts: paths: - dist/package/**/* @@ -46,12 +46,12 @@ dont-merge-to-master: - eval $(opam config env) - scripts/setup_switch.sh - eval $(opam config env) - - scripts/setup_repos.sh || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) + - scripts/setup_repos.sh # install deps for internal documentation - - scripts/install_vendors_deps.sh || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) + - scripts/install_vendors_deps.sh - opam install -y odoc - - scripts/build_ligo_local.sh || (cat _build/log || true; find || true; tail -n +1 ~/.opam/log/* || true; false) + - scripts/build_ligo_local.sh # build with odoc - dune build @doc From e86f15e5daa4e8a862a36cacad1eeae6cd2f88e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Mon, 10 Feb 2020 20:10:34 +0100 Subject: [PATCH 19/19] Show OPAM logs in case of failure inside of Docker --- docker/distribution/generic/build.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/distribution/generic/build.Dockerfile b/docker/distribution/generic/build.Dockerfile index f6c9358e9..ba01c043c 100644 --- a/docker/distribution/generic/build.Dockerfile +++ b/docker/distribution/generic/build.Dockerfile @@ -29,7 +29,7 @@ RUN opam update # Install ligo RUN sh scripts/install_vendors_deps.sh -RUN opam install -y . +RUN opam install -y . || (tail -n +1 ~/.opam/log/* ; false) # Use the ligo binary as a default command ENTRYPOINT [ "/home/opam/.opam/4.07/bin/ligo" ]