ReasonLIGO improvements.
This commit is contained in:
parent
cee9cc841e
commit
a688a1afe4
@ -120,8 +120,8 @@ and pp_ptuple {value; _} =
|
|||||||
| p::items ->
|
| p::items ->
|
||||||
group (break 1 ^^ pp_pattern p ^^ string ",") ^^ app items
|
group (break 1 ^^ pp_pattern p ^^ string ",") ^^ app items
|
||||||
in if tail = []
|
in if tail = []
|
||||||
then string "(" ^^ pp_pattern head ^^ string ")"
|
then string "(" ^^ nest 1 (pp_pattern head) ^^ string ")"
|
||||||
else string "(" ^^ pp_pattern head ^^ string "," ^^ app (List.map snd tail) ^^ string ")"
|
else string "(" ^^ nest 1 (pp_pattern head ^^ string "," ^^ app (List.map snd tail)) ^^ string ")"
|
||||||
|
|
||||||
and pp_precord fields = pp_ne_injection pp_field_pattern fields
|
and pp_precord fields = pp_ne_injection pp_field_pattern fields
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ and pp_expr = function
|
|||||||
|
|
||||||
and pp_case_expr {value; _} =
|
and pp_case_expr {value; _} =
|
||||||
let {expr; cases; _} = value in
|
let {expr; cases; _} = value in
|
||||||
group (string "switch" ^^ string "(" ^^ pp_expr expr ^^ (string ") " ^^ string "{")
|
group (string "switch" ^^ string "(" ^^ nest 1 (pp_expr expr) ^^ (string ") " ^^ string "{")
|
||||||
^^ (pp_cases cases) ^^ hardline ^^ string "}" )
|
^^ (pp_cases cases) ^^ hardline ^^ string "}" )
|
||||||
|
|
||||||
and pp_cases {value; _} =
|
and pp_cases {value; _} =
|
||||||
@ -178,7 +178,7 @@ and pp_clause {value; _} =
|
|||||||
and pp_cond_expr {value; _} =
|
and pp_cond_expr {value; _} =
|
||||||
let {test; ifso; kwd_else; ifnot; _} = value in
|
let {test; ifso; kwd_else; ifnot; _} = value in
|
||||||
let if_then =
|
let if_then =
|
||||||
string "if" ^^ string "(" ^^ pp_expr test ^^ string ")" ^^ string " {" ^^ break 0
|
string "if" ^^ string " (" ^^ pp_expr test ^^ string ")" ^^ string " {" ^^ break 0
|
||||||
^^ group (nest 2 (break 2 ^^ pp_expr ifso)) ^^ hardline ^^ string "}" in
|
^^ group (nest 2 (break 2 ^^ pp_expr ifso)) ^^ hardline ^^ string "}" in
|
||||||
if kwd_else#is_ghost then
|
if kwd_else#is_ghost then
|
||||||
if_then
|
if_then
|
||||||
@ -350,8 +350,8 @@ and pp_tuple_expr {value; _} =
|
|||||||
| e::items ->
|
| e::items ->
|
||||||
group (break 1 ^^ pp_expr e ^^ string ",") ^^ app items
|
group (break 1 ^^ pp_expr e ^^ string ",") ^^ app items
|
||||||
in if tail = []
|
in if tail = []
|
||||||
then string "(" ^^ pp_expr head ^^ string ")"
|
then string "(" ^^ nest 1 (pp_expr head) ^^ string ")"
|
||||||
else string "(" ^^ pp_expr head ^^ string "," ^^ app (List.map snd tail) ^^ string ")"
|
else string "(" ^^ nest 1 (pp_expr head ^^ string "," ^^ app (List.map snd tail)) ^^ string ")"
|
||||||
|
|
||||||
and pp_par_expr {value; _} =
|
and pp_par_expr {value; _} =
|
||||||
string "(" ^^ nest 1 (pp_expr value.inside ^^ string ")")
|
string "(" ^^ nest 1 (pp_expr value.inside ^^ string ")")
|
||||||
@ -378,8 +378,8 @@ and pp_fun {value; _} =
|
|||||||
group (break 0 ^^ string ": " ^^ nest 2 (pp_type_expr e))
|
group (break 0 ^^ string ": " ^^ nest 2 (pp_type_expr e))
|
||||||
in
|
in
|
||||||
match body with
|
match body with
|
||||||
| ESeq _ -> string "(" ^^ binders ^^ string ")" ^^ annot ^^ string " => " ^^ pp_expr body
|
| ESeq _ -> string "(" ^^ nest 1 binders ^^ string ")" ^^ annot ^^ string " => " ^^ pp_expr body
|
||||||
| _ -> (prefix 2 0 (string "(" ^^ binders ^^ string ")" ^^ annot
|
| _ -> (prefix 2 0 (string "(" ^^ nest 1 binders ^^ string ")" ^^ annot
|
||||||
^^ string " => ") (pp_expr body))
|
^^ string " => ") (pp_expr body))
|
||||||
|
|
||||||
and pp_seq {value; _} =
|
and pp_seq {value; _} =
|
||||||
@ -412,7 +412,7 @@ and pp_cartesian {value; _} =
|
|||||||
| e::items ->
|
| e::items ->
|
||||||
group (break 1 ^^ pp_type_expr e ^^ string ",") ^^ app items
|
group (break 1 ^^ pp_type_expr e ^^ string ",") ^^ app items
|
||||||
in
|
in
|
||||||
string "(" ^^ pp_type_expr head ^^ (if tail <> [] then string "," else empty) ^^ app (List.map snd tail) ^^ string ")"
|
string "(" ^^ nest 1 (pp_type_expr head ^^ (if tail <> [] then string "," else empty) ^^ app (List.map snd tail)) ^^ string ")"
|
||||||
|
|
||||||
and pp_variants {value; _} =
|
and pp_variants {value; _} =
|
||||||
let head, tail = value in
|
let head, tail = value in
|
||||||
@ -445,7 +445,7 @@ and pp_field_decl {value; _} =
|
|||||||
|
|
||||||
and pp_type_app {value; _} =
|
and pp_type_app {value; _} =
|
||||||
let ctor, tuple = value in
|
let ctor, tuple = value in
|
||||||
prefix 2 0 (pp_type_constr ctor) (string "(" ^^ pp_type_tuple tuple ^^ string ")")
|
prefix 2 0 (pp_type_constr ctor) (string "(" ^^ nest 1 (pp_type_tuple tuple) ^^ string ")")
|
||||||
|
|
||||||
and pp_type_tuple {value; _} =
|
and pp_type_tuple {value; _} =
|
||||||
let head, tail = value.inside in
|
let head, tail = value.inside in
|
||||||
@ -474,7 +474,7 @@ and pp_fun_type {value; _} =
|
|||||||
match lhs, rhs with
|
match lhs, rhs with
|
||||||
| _, TFun tf -> string "(" ^^ pp_type_expr lhs ^^ string ", " ^^ pp_fun_args tf
|
| _, TFun tf -> string "(" ^^ pp_type_expr lhs ^^ string ", " ^^ pp_fun_args tf
|
||||||
| TVar _ , _ -> group (pp_type_expr lhs ^^ string " =>" ^/^ pp_type_expr rhs)
|
| TVar _ , _ -> group (pp_type_expr lhs ^^ string " =>" ^/^ pp_type_expr rhs)
|
||||||
| _ -> group (string "(" ^^ pp_type_expr lhs ^^ string ")" ^^ string " =>" ^/^ pp_type_expr rhs)
|
| _ -> group (string "(" ^^ nest 1 (pp_type_expr lhs) ^^ string ")" ^^ string " =>" ^/^ pp_type_expr rhs)
|
||||||
|
|
||||||
and pp_type_par {value; _} =
|
and pp_type_par {value; _} =
|
||||||
string "(" ^^ nest 1 (pp_type_expr value.inside ^^ string ")")
|
string "(" ^^ nest 1 (pp_type_expr value.inside ^^ string ")")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
let check_ = (p: unit): int =>
|
let check_ = (p: unit): int =>
|
||||||
if(Tezos.amount == 100000000mutez) {
|
if (Tezos.amount == 100000000mutez) {
|
||||||
42
|
42
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
let main = (i: int) => {
|
let main = (i: int) => {
|
||||||
let result = 0;
|
let result = 0;
|
||||||
if(i == 2) {
|
if (i == 2) {
|
||||||
|
|
||||||
let result = 42;
|
let result = 42;
|
||||||
result
|
result
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
let main = (i: int) =>
|
let main = (i: int) =>
|
||||||
if(i == 2) {
|
if (i == 2) {
|
||||||
42
|
42
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
let main = ((a, b): (bool, bool)) =>
|
let main = ((a, b): (bool, bool)) =>
|
||||||
if(a == b) {
|
if (a == b) {
|
||||||
999
|
999
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
type storage = unit;
|
type storage = unit;
|
||||||
|
|
||||||
let main = (p: unit, storage) =>
|
let main = (p: unit, storage) =>
|
||||||
if(true) {
|
if (true) {
|
||||||
failwith("This contract always fails")
|
failwith("This contract always fails")
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
let rec aux_simple = (i: int): int =>
|
let rec aux_simple = (i: int): int =>
|
||||||
if(i < 100) {
|
if (i < 100) {
|
||||||
aux_simple(i + 1)
|
aux_simple(i + 1)
|
||||||
} else {
|
} else {
|
||||||
i
|
i
|
||||||
@ -15,7 +15,7 @@ let counter = (n: int): int => {
|
|||||||
sum: 0
|
sum: 0
|
||||||
};
|
};
|
||||||
let rec aggregate = (prev: sum_aggregator): int =>
|
let rec aggregate = (prev: sum_aggregator): int =>
|
||||||
if(prev.counter <= n) {
|
if (prev.counter <= n) {
|
||||||
|
|
||||||
|
|
||||||
aggregate({
|
aggregate({
|
||||||
@ -29,7 +29,7 @@ let counter = (n: int): int => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let rec aux_nest = (prev: sum_aggregator): sum_aggregator =>
|
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);
|
let sum: int = prev.sum + aux_simple(prev.counter);
|
||||||
aux_nest({counter: prev.counter + 1, sum: sum })
|
aux_nest({counter: prev.counter + 1, sum: sum })
|
||||||
|
@ -33,7 +33,7 @@ let check_message = ((param, s): (check_message_pt, storage))
|
|||||||
: return => {
|
: return => {
|
||||||
let message: message = param.message;
|
let message: message = param.message;
|
||||||
let s =
|
let s =
|
||||||
if(param.counter != s.counter) {
|
if (param.counter != s.counter) {
|
||||||
(failwith("Counters does not match") : storage)
|
(failwith("Counters does not match") : storage)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -47,10 +47,10 @@ let check_message = ((param, s): (check_message_pt, storage))
|
|||||||
switch(keys) {
|
switch(keys) {
|
||||||
| [] => vk
|
| [] => vk
|
||||||
| [key, ...keys] =>
|
| [key, ...keys] =>
|
||||||
if(pkh_sig[0] == Crypto.hash_key(key)) {
|
if (pkh_sig[0] == Crypto.hash_key(key)) {
|
||||||
|
|
||||||
let valid =
|
let valid =
|
||||||
if(
|
if (
|
||||||
Crypto.check(key, pkh_sig[1], packed_payload)) {
|
Crypto.check(key, pkh_sig[1], packed_payload)) {
|
||||||
valid + 1n
|
valid + 1n
|
||||||
} else {
|
} else {
|
||||||
@ -64,7 +64,7 @@ let check_message = ((param, s): (check_message_pt, storage))
|
|||||||
};
|
};
|
||||||
let (valid, keys) =
|
let (valid, keys) =
|
||||||
List.fold(aux, param.signatures, (valid, keys));
|
List.fold(aux, param.signatures, (valid, keys));
|
||||||
if(valid < s.threshold) {
|
if (valid < s.threshold) {
|
||||||
|
|
||||||
(failwith("Not enough signatures passed the check")
|
(failwith("Not enough signatures passed the check")
|
||||||
: storage)
|
: storage)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
type f = int;
|
type f = int;
|
||||||
|
|
||||||
let a = (b: f) => {
|
let a = (b: f) => {
|
||||||
if(b == 2) {
|
if (b == 2) {
|
||||||
3
|
3
|
||||||
} else {
|
} else {
|
||||||
4
|
4
|
||||||
|
@ -11,7 +11,7 @@ let donate = ((p, s): (unit, storage))
|
|||||||
|
|
||||||
let distribute = ((p, s): ((unit => list(operation)),
|
let distribute = ((p, s): ((unit => list(operation)),
|
||||||
storage)): (list(operation), storage) => {
|
storage)): (list(operation), storage) => {
|
||||||
if(Tezos.sender == s) {
|
if (Tezos.sender == s) {
|
||||||
(p(()), s)
|
(p(()), s)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
let rec sum = ((n, acc): (int, int)): int =>
|
let rec sum = ((n, acc): (int, int)): int =>
|
||||||
if(n < 1) {
|
if (n < 1) {
|
||||||
acc
|
acc
|
||||||
} else {
|
} else {
|
||||||
sum((n - 1, acc + n))
|
sum((n - 1, acc + n))
|
||||||
};
|
};
|
||||||
|
|
||||||
let rec fibo = ((n, n_1, n_0): (int, int, int)): int =>
|
let rec fibo = ((n, n_1, n_0): (int, int, int)): int =>
|
||||||
if(n < 2) {
|
if (n < 2) {
|
||||||
n_1
|
n_1
|
||||||
} else {
|
} else {
|
||||||
fibo((n - 1, n_1 + n_0, n_1))
|
fibo((n - 1, n_1 + n_0, n_1))
|
||||||
|
@ -54,7 +54,7 @@ let s = {
|
|||||||
let t = (((((((2)))))));
|
let t = (((((((2)))))));
|
||||||
|
|
||||||
let u =
|
let u =
|
||||||
if(true) {
|
if (true) {
|
||||||
1
|
1
|
||||||
} else {
|
} else {
|
||||||
2
|
2
|
||||||
|
Loading…
Reference in New Issue
Block a user