Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions lib/ligo_lltz_codgen/ligo_lltz_codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ let rec compile_type_expression (type_ : I.type_expression) : O.Type.t =
| T_sapling_transaction memo -> return @@ Sapling_transaction { memo = Z.to_int memo }
| T_function (arg_type, ret_type) ->
return @@ Function (compile_type_expression arg_type, compile_type_expression ret_type)
| T_tuple annot_types -> return @@ Tuple (compile_row annot_types)
| T_tuple annot_types ->
(match annot_types with
| [] -> assert false
| [ (_annot, el) ] ->
(* TODO: should this handled by LLTZ? *)
compile_type_expression el
| annot_types -> return @@ Tuple (compile_row annot_types))
| T_or (left, right) -> return @@ Or (compile_row [ left; right ])
| T_base TB_unit -> return Unit
| T_base TB_bool -> return Bool
Expand Down Expand Up @@ -557,16 +563,30 @@ let rec compile_expression (expr : I.expression) : O.Expr.t =
let var, body = compile_binders binders ~in_:(compile_expression body) in
return @@ For_each { collection; body = { lam_var = var; body } }
| E_tuple elts ->
let elts = List.map elts ~f:compile_expression in
let row = O.Row.(Node (List.map elts ~f:(fun elt -> Leaf (None, elt)))) in
return @@ Tuple row
| E_proj (tuple, index, _tuple_size) ->
let tuple = compile_expression tuple in
return @@ Proj (tuple, O.Row.Path.Here [ index ])
| E_update (tuple, index, update, _tuple_size) ->
let tuple = compile_expression tuple in
let update = compile_expression update in
return @@ Update { tuple; component = O.Row.Path.Here [ index ]; update }
(match elts with
| [] -> assert false
| [ elt ] -> compile_expression elt
| elts ->
let elts = List.map elts ~f:compile_expression in
let row = O.Row.(Node (List.map elts ~f:(fun elt -> Leaf (None, elt)))) in
return @@ Tuple row)
| E_proj (tuple, index, tuple_size) ->
(match tuple_size with
| 0 -> assert false
| 1 ->
assert (index = 0);
compile_expression tuple
| _ ->
let tuple = compile_expression tuple in
return @@ Proj (tuple, O.Row.Path.Here [ index ]))
| E_update (tuple, index, update, tuple_size) ->
(match tuple_size with
| 0 -> assert false
| 1 -> compile_expression update
| _ ->
let tuple = compile_expression tuple in
let update = compile_expression update in
return @@ Update { tuple; component = O.Row.Path.Here [ index ]; update })
| E_let_tuple (rhs, (binders, in_)) ->
let components = List.map (List.map binders ~f:compile_binder) ~f:fst in
let rhs = compile_expression rhs in
Expand Down
9 changes: 4 additions & 5 deletions src/bin/expect_tests/aggregation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ let%expect_test _ =
storage unit ;
code { DROP ;
PUSH nat 1 ;
PUSH nat 1 ;
DUP ;
ADD ;
PUSH nat 2 ;
COMPARE ;
EQ ;
IF { UNIT } { PUSH string "failed assertion" ; FAILWITH } ;
IF {} { PUSH string "failed assertion" ; FAILWITH } ;
UNIT ;
NIL operation ;
PAIR } } |}]

let%expect_test _ =
run_ligo_good [ "compile"; "contract"; contract "effects.mligo" ];
[%expect
{|
{ parameter int ;
storage int ;
code { CDR ; PUSH string "foo" ; FAILWITH } } |}]
{ parameter int ; storage int ; code { PUSH string "foo" ; FAILWITH } } |}]

let%expect_test _ =
run_ligo_good
Expand Down
7 changes: 4 additions & 3 deletions src/bin/expect_tests/annotated_michelson_record.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let%expect_test _ =
[%expect
{|
{ parameter unit ;
storage (pair (int %ana) (string %anb) (nat %anc)) ;
storage (pair (int %ana) (pair (string %anb) (nat %anc))) ;
code { DROP ;
PUSH nat 1 ;
PUSH string "" ;
Expand All @@ -45,7 +45,8 @@ let%expect_test _ =
{|
{ parameter unit ;
storage
(pair (int %an_One) (string %an_Two) (bool %an_Three) (nat %an_Four) (int %an_Five)) ;
(pair (int %an_One)
(pair (string %an_Two) (pair (bool %an_Three) (pair (nat %an_Four) (int %an_Five))))) ;
code { CDR ; NIL operation ; PAIR } } |}]

let%expect_test _ =
Expand Down Expand Up @@ -127,7 +128,7 @@ let%expect_test _ =
{|
{ parameter unit ;
storage
(pair (pair (pair (int %an_Five) (nat %an_Four)) (int %an_One) (bool %an_Three))
(pair (pair (pair (int %an_Five) (nat %an_Four)) (pair (int %an_One) (bool %an_Three)))
(string %an_Two)) ;
code { CDR ; NIL operation ; PAIR } } |}]

Expand Down
20 changes: 2 additions & 18 deletions src/bin/expect_tests/build_module_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,7 @@ let%expect_test _ =
{|
{ parameter int ;
storage int ;
code { PUSH int 1 ;
PUSH int 10 ;
ADD ;
SWAP ;
UNPAIR ;
ADD ;
ADD ;
NIL operation ;
PAIR } } |}]
code { PUSH int 11 ; SWAP ; UNPAIR ; ADD ; ADD ; NIL operation ; PAIR } } |}]

let%expect_test _ =
run_ligo_good [ "compile"; "contract"; contract "instance/main.mligo" ];
Expand All @@ -122,15 +114,7 @@ let%expect_test _ =
{|
{ parameter int ;
storage int ;
code { PUSH int 1 ;
PUSH int 10 ;
ADD ;
SWAP ;
UNPAIR ;
ADD ;
ADD ;
NIL operation ;
PAIR } } |}]
code { PUSH int 11 ; SWAP ; UNPAIR ; ADD ; ADD ; NIL operation ; PAIR } } |}]

let%expect_test _ =
run_ligo_bad [ "print"; "ast-typed"; contract "cycle_A.mligo" ];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/expect_tests/contract_metadata.ml
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ let%expect_test _ =
Warning: Empty key in metadata big-map is mandatory.
(Pair (Pair 42 { Elt "titi" 0x24 ; Elt "toto" 0x42 })
{ Elt 0
0x050200000047032009310000003b07650765035b076103680369076103620369096500000014055f036d0765035b076103680369076103620369000000000200000006053d036d034200000000 }) |}]
0x050200000041032009310000003507650765035b0761036803690761036203690765055f036d07650765035b0761036803690761036203690200000006053d036d034200000000 }) |}]

(* -------------------------------------------------------------------------- *)
(* Contracts with invalid 'metadata' should pass when the waiver flag is enabled *)
Expand Down
Loading