From 550e6b084b8c5da36628884e835954185d963bd5 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Tue, 25 Feb 2020 15:23:28 +0100 Subject: [PATCH] new constant : add self (michelson SELF) --- src/passes/operators/operators.ml | 12 ++++++++++-- src/stages/common/PP.ml | 1 + src/stages/common/types.ml | 1 + src/stages/mini_c/PP.ml | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 9fd521087..bcb0ce691 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -66,7 +66,6 @@ module Simplify = struct module Pascaligo = struct let constants = function (* Tezos module (ex-Michelson) *) - | "Tezos.chain_id" -> ok C_CHAIN_ID | "chain_id" -> ok C_CHAIN_ID (* Deprecated *) | "get_chain_id" -> ok C_CHAIN_ID (* Deprecated *) @@ -79,7 +78,8 @@ module Simplify = struct | "Tezos.sender" -> ok C_SENDER | "sender" -> ok C_SENDER (* Deprecated *) | "Tezos.address" -> ok C_ADDRESS - | "address" -> ok C_ADDRESS (* Deprecated *) + | "address" -> ok C_ADDRESS (* Deprecated *) + | "Tezos.self" -> ok C_SELF | "Tezos.self_address" -> ok C_SELF_ADDRESS | "self_address" -> ok C_SELF_ADDRESS (* Deprecated *) | "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT @@ -267,6 +267,7 @@ module Simplify = struct | "sender" -> ok C_SENDER (* Deprecated *) | "Tezos.address" -> ok C_ADDRESS | "Current.address" -> ok C_ADDRESS (* Deprecated *) + | "Tezos.self" -> ok C_SELF | "Tezos.self_address" -> ok C_SELF_ADDRESS | "Current.self_address" -> ok C_SELF_ADDRESS (* Deprecated *) | "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT @@ -791,6 +792,11 @@ module Typer = struct let self_address = typer_0 "SELF_ADDRESS" @@ fun _ -> ok @@ t_address () + let self = typer_0 "SELF" @@ fun tv_opt -> + match tv_opt with + | None -> simple_fail "untyped SELF" + | Some t -> ok @@ t + let implicit_account = typer_1 "IMPLICIT_ACCOUNT" @@ fun key_hash -> let%bind () = assert_t_key_hash key_hash in ok @@ t_contract (t_unit () ) () @@ -1228,6 +1234,7 @@ module Typer = struct | C_SENDER -> ok @@ sender ; | C_SOURCE -> ok @@ source ; | C_ADDRESS -> ok @@ address ; + | C_SELF -> ok @@ self; | C_SELF_ADDRESS -> ok @@ self_address; | C_IMPLICIT_ACCOUNT -> ok @@ implicit_account; | C_SET_DELEGATE -> ok @@ set_delegate ; @@ -1303,6 +1310,7 @@ module Compiler = struct | C_AMOUNT -> ok @@ simple_constant @@ prim I_AMOUNT | C_ADDRESS -> ok @@ simple_unary @@ prim I_ADDRESS | C_SELF_ADDRESS -> ok @@ simple_constant @@ seq [prim I_SELF; prim I_ADDRESS] + | C_SELF -> ok @@ simple_constant @@ seq [prim I_SELF] | C_IMPLICIT_ACCOUNT -> ok @@ simple_unary @@ prim I_IMPLICIT_ACCOUNT | C_SET_DELEGATE -> ok @@ simple_unary @@ prim I_SET_DELEGATE | C_NOW -> ok @@ simple_constant @@ prim I_NOW diff --git a/src/stages/common/PP.ml b/src/stages/common/PP.ml index 14cde83d5..ee232f044 100644 --- a/src/stages/common/PP.ml +++ b/src/stages/common/PP.ml @@ -143,6 +143,7 @@ let constant ppf : constant' -> unit = function | C_SOURCE -> fprintf ppf "SOURCE" | C_SENDER -> fprintf ppf "SENDER" | C_ADDRESS -> fprintf ppf "ADDRESS" + | C_SELF -> fprintf ppf "SELF" | C_SELF_ADDRESS -> fprintf ppf "SELF_ADDRESS" | C_IMPLICIT_ACCOUNT -> fprintf ppf "IMPLICIT_ACCOUNT" | C_SET_DELEGATE -> fprintf ppf "SET_DELEGATE" diff --git a/src/stages/common/types.ml b/src/stages/common/types.ml index d6b0839fd..1eacb7f7c 100644 --- a/src/stages/common/types.ml +++ b/src/stages/common/types.ml @@ -285,6 +285,7 @@ and constant' = | C_SOURCE | C_SENDER | C_ADDRESS + | C_SELF | C_SELF_ADDRESS | C_IMPLICIT_ACCOUNT | C_SET_DELEGATE diff --git a/src/stages/mini_c/PP.ml b/src/stages/mini_c/PP.ml index bb0ff6476..7626081cc 100644 --- a/src/stages/mini_c/PP.ml +++ b/src/stages/mini_c/PP.ml @@ -237,6 +237,7 @@ and constant ppf : constant' -> unit = function | C_SOURCE -> fprintf ppf "SOURCE" | C_SENDER -> fprintf ppf "SENDER" | C_ADDRESS -> fprintf ppf "ADDRESS" + | C_SELF -> fprintf ppf "SELF" | C_SELF_ADDRESS -> fprintf ppf "SELF_ADDRESS" | C_IMPLICIT_ACCOUNT -> fprintf ppf "IMPLICIT_ACCOUNT" | C_SET_DELEGATE -> fprintf ppf "SET_DELEGATE"