Merge branch 'fix-entry-point-aggregation' into 'dev'

Fix entry point aggregation

See merge request ligolang/ligo!305
This commit is contained in:
Rémi Lesenechal 2020-01-06 19:32:50 +00:00
commit 012ee0740b
6 changed files with 34 additions and 6 deletions

View File

@ -943,4 +943,12 @@ let%expect_test _ =
let%expect_test _ =
run_ligo_bad [ "compile-contract" ; contract "bad_timestamp.ligo" ; "main" ] ;
[%expect {| ligo: in file "bad_timestamp.ligo", line 5, characters 29-43. Badly formatted timestamp "badtimestamp": {"location":"in file \"bad_timestamp.ligo\", line 5, characters 29-43"} |}]
[%expect {| ligo: in file "bad_timestamp.ligo", line 5, characters 29-43. Badly formatted timestamp "badtimestamp": {"location":"in file \"bad_timestamp.ligo\", line 5, characters 29-43"} |}]
let%expect_test _ =
run_ligo_good [ "dry-run" ; contract "redeclaration.ligo" ; "main" ; "unit" ; "0" ] ;
[%expect {|( [] , 0 ) |}]
let%expect_test _ =
run_ligo_good [ "dry-run" ; contract "double_main.ligo" ; "main" ; "unit" ; "0" ] ;
[%expect {|( [] , 2 ) |}]

View File

@ -25,9 +25,10 @@ let aggregate_and_compile = fun program form ->
| ContractForm _ -> compile_contract aggregated'
| ExpressionForm _ -> compile_expression aggregated'
let aggregate_and_compile_contract = fun program name ->
let%bind (exp, _) = get_entry program name in
aggregate_and_compile program (ContractForm exp)
let aggregate_and_compile_contract = fun (program : Types.program) name ->
let%bind (exp, idx) = get_entry program name in
let program' = List.take idx program in
aggregate_and_compile program' (ContractForm exp)
let aggregate_and_compile_expression = fun program exp ->
aggregate_and_compile program (ExpressionForm exp)

View File

@ -129,14 +129,14 @@ let get_entry (lst : program) (name : string) : (expression * int) result =
then Some decl_expr
else None
in
List.find_map aux lst
List.find_map aux (List.rev lst)
in
let entry_index =
let aux x =
let (((decl_name , _) , _)) = x in
Var.equal decl_name (Var.of_name name)
in
List.find_index aux lst
(List.length lst) - (List.find_index aux (List.rev lst)) - 1
in
ok (entry_expression , entry_index)

View File

@ -0,0 +1,8 @@
function main(const p : unit; const s : int) : list(operation) * int is
((list end : list(operation)), s + 1)
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)

View File

@ -0,0 +1,6 @@
function foo(const p : unit) : int is 0
function main(const p : unit; const s : int) : list(operation) * int is
((list end : list(operation)), foo(unit))
function foo(const p : unit) : int is 1

View File

@ -5,6 +5,11 @@ let rec remove n = function
| _ :: tl when n = 0 -> tl
| hd :: tl -> hd :: remove (n - 1) tl
let rec take n = function
| [] -> []
| _ when n = 0 -> []
| hd :: tl -> hd :: take (n - 1) tl
let map ?(acc = []) f lst =
let rec aux acc f = function
| [] -> acc