From 68dcae1a114f0d29d383eb8c412e015b61b5b45b Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Fri, 18 May 2018 22:32:23 +0200 Subject: [PATCH] Michelson: RENAME macro --- .../lib_client/michelson_v1_macros.ml | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_client/michelson_v1_macros.ml b/src/proto_alpha/lib_client/michelson_v1_macros.ml index 766bf0bd4..3fc5cc1c4 100644 --- a/src/proto_alpha/lib_client/michelson_v1_macros.ml +++ b/src/proto_alpha/lib_client/michelson_v1_macros.ml @@ -487,6 +487,15 @@ let expand_if_right = function error (Unexpected_macro_annotation "IF_RIGHT") | _ -> ok @@ None +let expand_rename = function + | Prim (loc, "RENAME", [], annot) -> + ok @@ Some (Seq (loc, [ + Prim (loc, "DUP", [], annot) ; + Prim (loc, "SWAP", [], []) ; + Prim (loc, "DROP", [], []) ; + ])) + | _ -> ok @@ None + let expand original = let rec try_expansions = function | [] -> ok @@ original @@ -505,7 +514,9 @@ let expand original = expand_compare ; expand_asserts ; expand_if_some ; - expand_if_right ] + expand_if_right ; + expand_rename ; + ] let expand_rec expr = let rec error_map (expanded, errors) f = function @@ -842,6 +853,15 @@ let unexpand_if_right = function Some (Prim (loc, "IF_RIGHT", [ right ; left ], [])) | _ -> None +let unexpand_rename = function + | Seq (loc, [ + Prim (_, "DUP", [], annot) ; + Prim (_, "SWAP", [], []) ; + Prim (_, "DROP", [], []) ; + ]) -> + Some (Prim (loc, "RENAME", [], annot)) + | _ -> None + let unexpand original = let try_unexpansions unexpanders = match @@ -864,7 +884,8 @@ let unexpand original = unexpand_duuuuup ; unexpand_compare ; unexpand_if_some ; - unexpand_if_right ] + unexpand_if_right ; + unexpand_rename ] let rec unexpand_rec expr = match unexpand expr with