From 8edeb273213f084af55b7816fd38abd917a860c0 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Wed, 4 Dec 2019 02:06:41 +0100 Subject: [PATCH] add a function to fetch (param,storage) in a contract's lambda --- src/passes/9-self_michelson/helpers.ml | 12 ++++++++++++ src/passes/9-self_michelson/self_michelson.ml | 1 + 2 files changed, 13 insertions(+) diff --git a/src/passes/9-self_michelson/helpers.ml b/src/passes/9-self_michelson/helpers.ml index 4ce8670c1..feca5a151 100644 --- a/src/passes/9-self_michelson/helpers.ml +++ b/src/passes/9-self_michelson/helpers.ml @@ -17,3 +17,15 @@ let rec map_expression : mapper -> michelson -> michelson result = fun f e -> ok @@ Seq (l , lst') ) | x -> ok x + +open Memory_proto_alpha.Protocol.Script_ir_translator +(* fetches lambda first and second parameter (parameter,storage) *) +let fetch_lambda_parameters : ex_ty -> (ex_ty * ex_ty) result = + let error () = simple_fail "failed to fetch lambda parameters" in + function + | Ex_ty (Lambda_t (in_ty, _, _)) -> ( + match in_ty with + | Pair_t ((param_ty,_,_),(storage_ty,_,_),_,_) -> + ok (Ex_ty param_ty, Ex_ty storage_ty) + |_ -> error () ) + | _ -> error () diff --git a/src/passes/9-self_michelson/self_michelson.ml b/src/passes/9-self_michelson/self_michelson.ml index 711bf64f2..12b8073aa 100644 --- a/src/passes/9-self_michelson/self_michelson.ml +++ b/src/passes/9-self_michelson/self_michelson.ml @@ -8,6 +8,7 @@ open Tezos_micheline.Micheline open Tezos_utils.Michelson +include Helpers (* `arity p` should be `Some n` only if p is (always) an instruction which removes n items from the stack and uses them to push 1 item,