Treat env element expression as deep_closure only if they are lambda

This commit is contained in:
Lesenechal Remi 2019-09-27 17:31:38 +02:00
parent 6d767e686d
commit 2840eb7414
3 changed files with 30 additions and 8 deletions

View File

@ -225,11 +225,16 @@ let rec transpile_literal : AST.literal -> value = fun l -> match l with
and transpile_environment_element_type : AST.environment_element -> type_value result = fun ele -> and transpile_environment_element_type : AST.environment_element -> type_value result = fun ele ->
match (AST.get_type' ele.type_value , ele.definition) with match (AST.get_type' ele.type_value , ele.definition) with
| (AST.T_function (f , arg) , ED_declaration (ae , ((_ :: _) as captured_variables)) ) -> | (AST.T_function (f , arg) , ED_declaration (ae , ((_ :: _) as captured_variables)) ) ->
let%bind f' = transpile_type f in begin
let%bind arg' = transpile_type arg in match ae.expression with
let%bind env' = transpile_environment ae.environment in | E_lambda _ ->
let sub_env = Mini_c.Environment.select captured_variables env' in let%bind f' = transpile_type f in
ok @@ Combinators.t_deep_closure sub_env f' arg' let%bind arg' = transpile_type arg in
let%bind env' = transpile_environment ae.environment in
let sub_env = Mini_c.Environment.select captured_variables env' in
ok @@ Combinators.t_deep_closure sub_env f' arg'
| _ -> transpile_type ele.type_value
end
| _ -> transpile_type ele.type_value | _ -> transpile_type ele.type_value
and transpile_small_environment : AST.small_environment -> Environment.t result = fun x -> and transpile_small_environment : AST.small_environment -> Environment.t result = fun x ->

View File

@ -1,8 +1,18 @@
// Test a PascaLIGO function which takes another PascaLIGO function as an argument // Test a PascaLIGO function which takes another PascaLIGO function as an argument
function foobar (const i : int) : int is function foobar (const i : int) : int is
function foo (const i : int) : int is function foo (const i : int) : int is
block { skip } with i ; block { skip } with i ;
function bar (const f : int -> int) : int is function bar (const f : int -> int) : int is
block { skip } with f ( i ) ; block { skip } with f ( i ) ;
block { skip } with bar (foo) ; block { skip } with bar (foo) ;
// higher order function with more than one argument
function higher2(const i: int; const f: int -> int): int is
block {
const ii: int = f(i)
} with ii
function foobar2 (const i : int) : int is
function foo2 (const i : int) : int is
block { skip } with i;
block { skip } with higher2(i,foo2)

View File

@ -110,8 +110,15 @@ let shadow () : unit result =
let higher_order () : unit result = let higher_order () : unit result =
let%bind program = type_file "./contracts/high-order.ligo" in let%bind program = type_file "./contracts/high-order.ligo" in
let make_expect = fun n -> n in let%bind _ =
expect_eq_n_int program "foobar" make_expect let make_expect = fun n -> n in
expect_eq_n_int program "foobar" make_expect
in
let%bind _ =
let make_expect = fun n -> n in
expect_eq_n_int program "foobar2" make_expect
in
ok ()
let shared_function () : unit result = let shared_function () : unit result =
let%bind program = type_file "./contracts/function-shared.ligo" in let%bind program = type_file "./contracts/function-shared.ligo" in