Improve ReasonLIGO output.

This commit is contained in:
Sander Spies 2020-06-05 13:56:14 +02:00
parent 49d2c870ae
commit db0fdf4abd
27 changed files with 297 additions and 357 deletions

View File

@ -174,13 +174,13 @@ and pp_clause {value; _} =
and pp_cond_expr {value; _} =
let {test; ifso; kwd_else; ifnot; _} = value in
let if_then =
string "if" ^^ string "(" ^^ pp_expr test ^^ string ")" ^^ string " {" ^^ hardline
string "if" ^^ string "(" ^^ pp_expr test ^^ string ")" ^^ string " {" ^^ break 0
^^ group (nest 2 (break 2 ^^ pp_expr ifso)) ^^ hardline ^^ string "}" in
if kwd_else#is_ghost then
if_then
else
if_then
^^ string " else" ^^ string " {" ^^ hardline ^^ group (nest 2 (break 2 ^^ pp_expr ifnot)) ^^ hardline ^^ string "}"
^^ string " else" ^^ string " {" ^^ break 0 ^^ group (nest 2 (break 2 ^^ pp_expr ifnot)) ^^ hardline ^^ string "}"
and pp_annot_expr {value; _} =
let expr, _, type_expr = value.inside in
@ -201,7 +201,7 @@ and pp_bool_expr = function
and pp_bin_op op {value; _} =
let {arg1; arg2; _} = value
and length = String.length op + 1 in
pp_expr arg1 ^/^ string (op ^ " ") ^^ nest length (pp_expr arg2)
pp_expr arg1 ^^ string " " ^^ string (op ^ " ") ^^ nest length (pp_expr arg2)
and pp_un_op op {value; _} =
string (op ^ " ") ^^ pp_expr value.arg
@ -372,8 +372,11 @@ and pp_fun {value; _} =
None -> empty
| Some (_,e) ->
group (break 0 ^^ string ":" ^^ nest 2 (break 1 ^^ pp_type_expr e))
in prefix 2 0 (string "(" ^^ binders ^^ string ")" ^^ annot
^^ string " => ") (pp_expr body)
in
match body with
| ESeq _ -> string "(" ^^ binders ^^ string ")" ^^ annot ^^ string " => " ^^ pp_expr body
| _ -> (prefix 2 0 (string "(" ^^ binders ^^ string ")" ^^ annot
^^ string " => ") (pp_expr body))
and pp_seq {value; _} =
let {compound; elements; _} = value in

View File

@ -1,6 +1,5 @@
let main =
(p: key_hash): address =>
{
let c: contract(unit) = Tezos.implicit_account(p);
Tezos.address(c)
};
(p: key_hash): address => {
let c: contract(unit) = Tezos.implicit_account(p);
Tezos.address(c)
};

View File

@ -1,7 +1,6 @@
let check_ =
(p: unit): int =>
if(Tezos.amount
== 100000000mutez) {
if(Tezos.amount == 100000000mutez) {
42
} else {
0

View File

@ -1,20 +1,17 @@
let id_string =
(p: string): option(string) =>
{
let packed: bytes = Bytes.pack(p);
((Bytes.unpack(packed)) : option(string))
};
(p: string): option(string) => {
let packed: bytes = Bytes.pack(p);
((Bytes.unpack(packed)) : option(string))
};
let id_int =
(p: int): option(int) =>
{
let packed: bytes = Bytes.pack(p);
((Bytes.unpack(packed)) : option(int))
};
(p: int): option(int) => {
let packed: bytes = Bytes.pack(p);
((Bytes.unpack(packed)) : option(int))
};
let id_address =
(p: address): option(address) =>
{
let packed: bytes = Bytes.pack(p);
((Bytes.unpack(packed)) : option(address))
};
(p: address): option(address) => {
let packed: bytes = Bytes.pack(p);
((Bytes.unpack(packed)) : option(address))
};

View File

@ -1,6 +1,5 @@
let check_signature =
(param: (key, signature, bytes)): bool =>
{
let (pk, signed, msg) = param;
Crypto.check(pk, signed, msg)
};
(param: (key, signature, bytes)): bool => {
let (pk, signed, msg) = param;
Crypto.check(pk, signed, msg)
};

View File

@ -1,8 +1,7 @@
let test =
(k: int): int =>
{
let j: int = k + 5;
let close: (int => int) = (i: int) => i + j;
let j: int = 20;
close(20)
};
(k: int): int => {
let j: int = k + 5;
let close: (int => int) = (i: int) => i + j;
let j: int = 20;
close(20)
};

View File

@ -1,15 +1,13 @@
let main =
(i: int) =>
{
(i: int) => {
let result = 0;
if(i == 2) {
let result = 42;
result
} else {
let result = 0;
if(i
== 2) {
let result = 42;
result
} else {
let result = 0;
result
}
};
result
}
};

View File

@ -1,7 +1,6 @@
let main =
(i: int) =>
if(i
== 2) {
if(i == 2) {
42
} else {
0

View File

@ -1,7 +1,6 @@
let main =
((a, b): (bool, bool)) =>
if(a
== b) {
if(a == b) {
999
} else {
1

View File

@ -1,34 +1,30 @@
let foobar =
(i: int): int =>
{
let foo: int => int = (i: int) => i;
let bar: ((int => int) => int) =
(f: (int => int)) => f(i);
bar(foo)
};
(i: int): int => {
let foo: int => int = (i: int) => i;
let bar: ((int => int) => int) =
(f: (int => int)) => f(i);
bar(foo)
};
let higher2 =
(i: int, f: (int => int)): int =>
{
let ii: int = f(i);
ii
};
(i: int, f: (int => int)): int => {
let ii: int = f(i);
ii
};
let foobar2 =
(i: int): int =>
{
let foo2: int => int = (i: int) => i;
higher2(i, foo2)
};
(i: int): int => {
let foo2: int => int = (i: int) => i;
higher2(i, foo2)
};
let a: int = 0;
let foobar3 =
(i: int): int =>
{
let foo2: int => int = (i: int) => a + i;
higher2(i, foo2)
};
(i: int): int => {
let foo2: int => int = (i: int) => a + i;
higher2(i, foo2)
};
let f = (i: int): int => i;
@ -37,17 +33,15 @@ let g = (i: int): int => f(i);
let foobar4 = (i: int): int => g(g(i));
let higher3 =
(i: int, f: (int => int), g: (int => int)): int =>
{
let ii: int = f(g(i));
ii
};
(i: int, f: (int => int), g: (int => int)): int => {
let ii: int = f(g(i));
ii
};
let foobar5 =
(i: int): int =>
{
let a: int = 0;
let foo: int => int = (i: int) => a + i;
let goo: int => int = (i: int) => foo(i);
higher3(i, foo, goo)
};
(i: int): int => {
let a: int = 0;
let foo: int => int = (i: int) => a + i;
let goo: int => int = (i: int) => foo(i);
higher3(i, foo, goo)
};

View File

@ -1,8 +1,6 @@
let check_hash_key =
(kh1_k2: (key_hash, key)): (bool, key_hash) =>
{
let (kh1, k2) = kh1_k2;
let kh2: key_hash = Crypto.hash_key(k2);
((kh1
== kh2), kh2)
};
(kh1_k2: (key_hash, key)): (bool, key_hash) => {
let (kh1, k2) = kh1_k2;
let kh2: key_hash = Crypto.hash_key(k2);
((kh1 == kh2), kh2)
};

View File

@ -1,15 +1,14 @@
type storage = (int, int);
let main =
(n: (int, storage)): (list(operation), storage) =>
{
let x: (int, int) =
{
let x: int = 7;
(x + n[0], n[1][0] + n[1][1])
};
([] : list(operation), x)
};
(n: (int, storage)): (list(operation), storage) => {
let x: (int, int) =
{
let x: int = 7;
(x + n[0], n[1][0] + n[1][1])
};
([] : list(operation), x)
};
let f0 = (a: string) => true;
@ -18,22 +17,20 @@ let f1 = (a: string) => true;
let f2 = (a: string) => true;
let letin_nesting =
(_: unit) =>
{
let s = "test";
let p0 = f0(s);
assert(p0);
let p1 = f1(s);
assert(p1);
let p2 = f2(s);
assert(p2);
s
};
(_: unit) => {
let s = "test";
let p0 = f0(s);
assert(p0);
let p1 = f1(s);
assert(p1);
let p2 = f2(s);
assert(p2);
s
};
let letin_nesting2 =
(x: int) =>
{
let y = 2;
let z = 3;
x + y + z
};
(x: int) => {
let y = 2;
let z = 3;
x + y + z
};

View File

@ -11,32 +11,29 @@ let y: list(int) = [3, 4, 5];
let z: list(int) = [2, ...y];
let main =
((action, s): (parameter, storage)): return =>
{
let storage =
switch(action) {
| [] => s
| [hd, ...tl] => (s[0] + hd, tl)
};
([] : list(operation), storage)
};
((action, s): (parameter, storage)): return => {
let storage =
switch(action) {
| [] => s
| [hd, ...tl] => (s[0] + hd, tl)
};
([] : list(operation), storage)
};
let size_ = (s: list(int)): nat => List.length(s);
let fold_op =
(s: list(int)): int =>
{
let aggregate = (t: (int, int)) => t[0] + t[1];
List.fold(aggregate, s, 10)
};
(s: list(int)): int => {
let aggregate = (t: (int, int)) => t[0] + t[1];
List.fold(aggregate, s, 10)
};
let map_op =
(s: list(int)): list(int) =>
List.map((cur: int) => cur + 1, s);
let iter_op =
(s: list(int)): unit =>
{
let do_nothing = (useless: int) => unit;
List.iter(do_nothing, s)
};
(s: list(int)): unit => {
let do_nothing = (useless: int) => unit;
List.iter(do_nothing, s)
};

View File

@ -1,7 +1,6 @@
let rec aux_simple =
(i: int): int =>
if(i
< 100) {
if(i < 100) {
aux_simple(i + 1)
} else {
i
@ -12,29 +11,26 @@ let counter_simple = (n: int): int => aux_simple(n);
type sum_aggregator = {counter: int, sum: int };
let counter =
(n: int): int =>
{
let initial: sum_aggregator = {counter: 0, sum: 0 };
let rec aggregate =
(prev: sum_aggregator): int =>
if(prev.counter
<= n) {
(n: int): int => {
let initial: sum_aggregator = {counter: 0, sum: 0 };
let rec aggregate =
(prev: sum_aggregator): int =>
if(prev.counter <= n) {
aggregate({
counter: prev.counter + 1,
sum: prev.counter + prev.sum
})
} else {
prev.sum
};
aggregate(initial)
};
aggregate({
counter: prev.counter + 1,
sum: prev.counter + prev.sum
})
} else {
prev.sum
};
aggregate(initial)
};
let rec aux_nest =
(prev: sum_aggregator): sum_aggregator =>
if(prev.counter
< 100) {
if(prev.counter < 100) {
let sum: int = prev.sum + aux_simple(prev.counter);
aux_nest({counter: prev.counter + 1, sum: sum })
@ -43,9 +39,8 @@ let rec aux_nest =
};
let counter_nest =
(n: int): int =>
{
let initial: sum_aggregator = {counter: 0, sum: 0 };
let out: sum_aggregator = aux_nest(initial);
out.sum
};
(n: int): int => {
let initial: sum_aggregator = {counter: 0, sum: 0 };
let out: sum_aggregator = aux_nest(initial);
out.sum
};

View File

@ -40,32 +40,28 @@ let get_ = (m: foobar): option(int) => Map.find_opt(42, m);
let mem = (km: (int, foobar)): bool => Map.mem(km[0], km[1]);
let iter_op =
(m: foobar): unit =>
{
let assert_eq = (i: int, j: int) => assert(i == j);
Map.iter(assert_eq, m)
};
(m: foobar): unit => {
let assert_eq = (i: int, j: int) => assert(i == j);
Map.iter(assert_eq, m)
};
let map_op =
(m: foobar): foobar =>
{
let increment = (z: int, j: int) => j + 1;
Map.map(increment, m)
};
(m: foobar): foobar => {
let increment = (z: int, j: int) => j + 1;
Map.map(increment, m)
};
let fold_op =
(m: foobar): foobar =>
{
let aggregate =
(i: int, j: (int, int)) => i + j[0] + j[1];
Map.fold(aggregate, m, 10)
};
(m: foobar): foobar => {
let aggregate =
(i: int, j: (int, int)) => i + j[0] + j[1];
Map.fold(aggregate, m, 10)
};
let deep_op =
(m: foobar): foobar =>
{
let coco = (0, m);
let coco = (0, Map.remove(42, coco[1]));
let coco = (0, Map.update(32, Some (16), coco[1]));
coco[1]
};
(m: foobar): foobar => {
let coco = (0, m);
let coco = (0, Map.remove(42, coco[1]));
let coco = (0, Map.update(32, Some (16), coco[1]));
coco[1]
};

View File

@ -5,13 +5,11 @@ type parameter = Add(int) | Sub(int);
type return = (list(operation), storage);
let main =
((action, store): (parameter, storage)) =>
{
let store =
store
+ (switch(action) {
| Add(n) => n
| Sub(n) => -n
});
(([] : list(operation)), store)
};
((action, store): (parameter, storage)) => {
let store =
store + (switch(action) {
| Add(n) => n
| Sub(n) => -n
});
(([] : list(operation)), store)
};

View File

@ -7,12 +7,11 @@ let add = ((a: int), (b: int)) => a + b;
let sub = ((a: int), (b: int)) => a - b;
let main =
((action, store): (parameter, storage)) =>
{
let store =
switch(action) {
| Increment(n) => add(store, n)
| Decrement(n) => sub(store, n)
};
(([] : list(operation)), store)
};
((action, store): (parameter, storage)) => {
let store =
switch(action) {
| Increment(n) => add(store, n)
| Decrement(n) => sub(store, n)
};
(([] : list(operation)), store)
};

View File

@ -6,8 +6,7 @@ type storage = michelson_pair
type return = (list(operation), storage);
let main =
((action, store): (unit, storage)): return =>
{
let foo = (3, (1, 2n));
(([] : list(operation)), (foo : storage))
};
((action, store): (unit, storage)): return => {
let foo = (3, (1, 2n));
(([] : list(operation)), (foo : storage))
};

View File

@ -30,65 +30,57 @@ type return = (list(operation), storage);
type parameter = CheckMessage(check_message_pt);
let check_message =
((param, s): (check_message_pt, storage)): return =>
{
let message: message = param.message;
let s =
if(param.counter
!= s.counter) {
(failwith("Counters does not match") : storage)
} else {
let packed_payload: bytes =
Bytes.pack((message, param.counter, s.id,
chain_id));
let valid: nat = 0n;
let keys: authorized_keys = s.auth;
let aux =
((vk, pkh_sig):
((nat, authorized_keys), (key_hash, signature)))
:
(nat, authorized_keys) =>
{
let (valid, keys) = vk;
switch(keys) {
| [] => vk
| [key, ...keys] =>
if(pkh_sig[0]
== Crypto.hash_key(key)) {
let valid =
if(
Crypto.check(key,
pkh_sig[1],
packed_payload)) {
valid + 1n
} else {
(failwith("Invalid signature")
: nat)
};
(valid, keys)
} else {
(valid, keys)
}
}
};
let (valid, keys) =
List.fold(aux, param.signatures, (valid, keys));
if(valid
< s.threshold) {
((param, s): (check_message_pt, storage)): return => {
let message: message = param.message;
let s =
if(param.counter != s.counter) {
(failwith("Counters does not match") : storage)
} else {
let packed_payload: bytes =
(
failwith("Not enough signatures passed the check")
: storage)
} else {
{...s, counter: s.counter + 1n}
}
};
(message(unit), s)
};
Bytes.pack((message, param.counter, s.id, chain_id));
let valid: nat = 0n;
let keys: authorized_keys = s.auth;
let aux =
((vk, pkh_sig):
((nat, authorized_keys), (key_hash, signature)))
:
(nat, authorized_keys) => {
let (valid, keys) = vk;
switch(keys) {
| [] => vk
| [key, ...keys] =>
if(pkh_sig[0] == Crypto.hash_key(key)) {
let valid =
if(
Crypto.check(key,
pkh_sig[1],
packed_payload)) {
valid + 1n
} else {
(failwith("Invalid signature") : nat)
};
(valid, keys)
} else {
(valid, keys)
}
}
};
let (valid, keys) =
List.fold(aux, param.signatures, (valid, keys));
if(valid < s.threshold) {
(
failwith("Not enough signatures passed the check")
: storage)
} else {
{...s, counter: s.counter + 1n}
}
};
(message(unit), s)
};
let main =
((action, store): (parameter, storage)): return =>

View File

@ -1,18 +1,15 @@
type f = int;
let a =
(b: f) =>
{
if(b
== 2) {
3
} else {
4
}
};
(b: f) => {
if(b == 2) {
3
} else {
4
}
};
let c =
(c: f) =>
{
3
};
(c: f) => {
3
};

View File

@ -5,32 +5,28 @@ type parameter =
| Distribute((unit => list(operation)));
let donate =
((p, s): (unit, storage)): (list(operation), storage) =>
{
(([] : list(operation)), s)
};
((p, s): (unit, storage)): (list(operation), storage) => {
(([] : list(operation)), s)
};
let distribute =
((p, s): ((unit => list(operation)), storage))
:
(list(operation), storage) =>
{
if(Tezos.sender
== s) {
(p(()), s)
} else {
(
failwith("You're not the oracle for this distribution.")
: (list(operation), storage))
}
};
(list(operation), storage) => {
if(Tezos.sender == s) {
(p(()), s)
} else {
(
failwith("You're not the oracle for this distribution.")
: (list(operation), storage))
}
};
let main =
((p, s): (parameter, storage)): (list(operation), storage) =>
{
switch(p) {
| Donate => donate(((), s))
| Distribute msg => distribute((msg, s))
}
};
((p, s): (parameter, storage)): (list(operation), storage) => {
switch(p) {
| Donate => donate(((), s))
| Distribute msg => distribute((msg, s))
}
};

View File

@ -1,7 +1,6 @@
let rec sum =
((n, acc): (int, int)): int =>
if(n
< 1) {
if(n < 1) {
acc
} else {
sum((n - 1, acc + n))
@ -9,8 +8,7 @@ let rec sum =
let rec fibo =
((n, n_1, n_0): (int, int, int)): int =>
if(n
< 2) {
if(n < 2) {
n_1
} else {
fibo((n - 1, n_1 + n_0, n_1))

View File

@ -1,6 +1,5 @@
let main =
(p: key_hash): list(operation) =>
{
let unused: operation = (Tezos.set_delegate(Some (p)));
([] : list(operation))
};
(p: key_hash): list(operation) => {
let unused: operation = (Tezos.set_delegate(Some (p)));
([] : list(operation))
};

View File

@ -5,12 +5,11 @@ type storage = int;
type return = (list(operation), storage);
let main =
((action, store): (parameter, storage)): return =>
{
let store =
switch(action) {
| Increment(n) => store + n
| Decrement(n) => store - n
};
([] : list(operation), store)
};
((action, store): (parameter, storage)): return => {
let store =
switch(action) {
| Increment(n) => store + n
| Decrement(n) => store - n
};
([] : list(operation), store)
};

View File

@ -1,10 +1,9 @@
type fun_type = (int, int) => int;
let arguments =
(b: int, c: int) =>
{
b + c
};
(b: int, c: int) => {
b + c
};
let arguments_type_def = (b: fun_type) => b(5, 3);
@ -14,20 +13,18 @@ let arguments_test =
type tuple_type = ((int, int)) => int;
let tuple =
((a, b): (int, int)) =>
{
a + b
};
((a, b): (int, int)) => {
a + b
};
let tuple_type_def = (b: tuple_type) => b((5, 3));
let tuple_test = (_: int) => tuple_type_def(tuple);
let arguments_inline =
(b: int, c: int) =>
{
b + c
};
(b: int, c: int) => {
b + c
};
let arguments_type_def_inline =
(b: (int, int) => int) => b(5, 3);
@ -36,10 +33,9 @@ let arguments_test_inline =
(_: int) => arguments_type_def_inline(arguments_inline);
let tuple_inline =
((a, b): (int, int)) =>
{
a + b
};
((a, b): (int, int)) => {
a + b
};
let tuple_type_def_inline =
(b: ((int, int)) => int) => b((5, 3));

View File

@ -3,7 +3,6 @@ type storage = (int, string, nat, bool);
type parameter = int;
let main =
((p, storage): (parameter, storage)) =>
{
([] : list(operation), (2, "2", 2n, false))
};
((p, storage): (parameter, storage)) => {
([] : list(operation), (2, "2", 2n, false))
};

View File

@ -7,12 +7,11 @@ let add = ((a, b): (int, int)): int => a + b;
let sub = ((a, b): (int, int)): int => a - b;
let main =
((p, storage): (parameter, storage)) =>
{
let storage =
switch(p) {
| Increment(n) => add((storage, n))
| Decrement(n) => sub((storage, n))
};
([] : list(operation), storage)
};
((p, storage): (parameter, storage)) => {
let storage =
switch(p) {
| Increment(n) => add((storage, n))
| Decrement(n) => sub((storage, n))
};
([] : list(operation), storage)
};