Merge branch 'galfour@minor-optim' into 'dev'

Minor optimization

See merge request ligolang/ligo!613
This commit is contained in:
Gabriel Alfour 2020-05-19 23:21:25 +00:00
commit dd970385e4
3 changed files with 14 additions and 5 deletions

View File

@ -504,16 +504,17 @@ and translate_function_body ({body ; binder} : anon_function) lst input : michel
and translate_function anon env input_ty output_ty : michelson result =
let fvs = Mini_c.Free_variables.lambda [] anon in
let small_env = Mini_c.Environment.select fvs env in
let%bind lambda_ty = Compiler_type.lambda_closure (small_env , input_ty , output_ty) in
let%bind (_lambda_ty , input_ty' , output_ty') =
Compiler_type.lambda_closure_with_ty (small_env , input_ty , output_ty) in
let%bind lambda_body_code = translate_function_body anon small_env input_ty in
match fvs with
| [] -> ok @@ seq [ i_push lambda_ty lambda_body_code ]
| [] -> ok @@ seq [ i_lambda input_ty' output_ty' lambda_body_code ]
| _ :: _ ->
let selector = List.map fst small_env in
let%bind closure_pack_code = Compiler_environment.pack_closure env selector in
ok @@ seq [
closure_pack_code ;
i_push lambda_ty lambda_body_code ;
i_lambda input_ty' output_ty' lambda_body_code ;
i_swap ;
i_apply ;
]

View File

@ -265,13 +265,19 @@ and environment = fun env ->
@@ List.map snd env
and lambda_closure = fun (c , arg , ret) ->
let%bind (lambda , _arg' , _ret') =
lambda_closure_with_ty (c , arg , ret) in
ok lambda
and lambda_closure_with_ty = fun (c , arg , ret) ->
let%bind arg = type_ arg in
let%bind ret = type_ ret in
match c with
| [] -> ok @@ O.t_lambda arg ret
| [] -> ok @@ (O.t_lambda arg ret , arg , ret)
| _ :: _ ->
let%bind capture = environment_closure c in
ok @@ O.t_lambda (O.t_pair capture arg) ret
let arg' = O.t_pair capture arg in
ok @@ (O.t_lambda arg' ret , arg' , ret)
and environment_closure =
function

View File

@ -87,6 +87,8 @@ val environment_element : string * type_expression -> (int, O.prim) Tezos_michel
val environment : ( 'a * type_expression ) list -> O.t list result
val lambda_closure : environment * type_expression * type_expression -> (int, O.prim) Tezos_micheline.Micheline.node result
val lambda_closure_with_ty : environment * type_expression * type_expression ->
(O.michelson * O.michelson * O.michelson) result
val environment_closure : environment -> (int , O.prim ) Tezos_micheline.Micheline.node result
(*