From 0b3e05781927a9a078bf573538f6f8062a4b9a35 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 29 Nov 2019 03:53:25 -0800 Subject: [PATCH] Add self address to CameLIGO and PascaLIGO --- src/passes/operators/operators.ml | 9 ++++++++- src/test/contracts/self_address.ligo | 1 + src/test/contracts/self_address.mligo | 1 + src/test/integration_tests.ml | 10 ++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/test/contracts/self_address.ligo create mode 100644 src/test/contracts/self_address.mligo diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 52b799ac3..f91d7d29f 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -74,6 +74,7 @@ module Simplify = struct ("source" , "SOURCE") ; ("sender" , "SENDER") ; ("address", "ADDRESS") ; + ("self_address", "SELF_ADDRESS") ; ("implicit_account", "IMPLICIT_ACCOUNT") ; ("failwith" , "FAILWITH") ; ("bitwise_or" , "OR") ; @@ -139,6 +140,7 @@ module Simplify = struct ("Current.sender" , "SENDER") ; ("sender", "SENDER") ; ("Current.address", "ADDRESS") ; + ("Current.self_address", "SELF_ADDRESS") ; ("Current.implicit_account", "IMPLICIT_ACCOUNT") ; ("Current.source" , "SOURCE") ; ("source", "SOURCE") ; @@ -470,6 +472,9 @@ module Typer = struct let%bind () = assert_t_contract contract in ok @@ t_address () + let self_address = typer_0 "SELF_ADDRESS" @@ fun _ -> + ok @@ t_address () + let implicit_account = typer_1 "IMPLICIT_ACCOUNT" @@ fun key_hash -> let%bind () = assert_t_key_hash key_hash in ok @@ t_contract (t_unit () ) () @@ -802,7 +807,8 @@ module Typer = struct now ; slice ; address ; - implicit_account ; + self_address ; + implicit_account ; assertion ; list_cons ; ] @@ -874,6 +880,7 @@ module Compiler = struct ("BALANCE" , simple_constant @@ prim I_BALANCE) ; ("AMOUNT" , simple_constant @@ prim I_AMOUNT) ; ("ADDRESS" , simple_unary @@ prim I_ADDRESS) ; + ("SELF_ADDRESS", simple_constant @@ (seq [prim I_SELF ; prim I_ADDRESS])) ; ("IMPLICIT_CONTRACT", simple_unary @@ prim I_IMPLICIT_ACCOUNT) ; ("NOW" , simple_constant @@ prim I_NOW) ; ("CALL" , simple_ternary @@ prim I_TRANSFER_TOKENS) ; diff --git a/src/test/contracts/self_address.ligo b/src/test/contracts/self_address.ligo new file mode 100644 index 000000000..72872ce0f --- /dev/null +++ b/src/test/contracts/self_address.ligo @@ -0,0 +1 @@ +function main (const p: unit) : address is self_address diff --git a/src/test/contracts/self_address.mligo b/src/test/contracts/self_address.mligo new file mode 100644 index 000000000..ade0926ee --- /dev/null +++ b/src/test/contracts/self_address.mligo @@ -0,0 +1 @@ +let main (p: unit) : address = Current.self_address diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index d4127bb60..eb8b36535 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1241,6 +1241,14 @@ let address_mligo () : unit result = let%bind _ = mtype_file "./contracts/address.mligo" in ok () +let self_address () : unit result = + let%bind _ = type_file "./contracts/self_address.ligo" in + ok () + +let self_address_mligo () : unit result = + let%bind _ = mtype_file "./contracts/self_address.mligo" in + ok () + let implicit_account () : unit result = let%bind _ = type_file "./contracts/implicit_account.ligo" in ok () @@ -1416,6 +1424,8 @@ let main = test_suite "Integration (End to End)" [ test "balance constant (mligo)" balance_constant_mligo ; test "address" address ; test "address_mligo" address_mligo ; + test "self address" self_address ; + test "self address (mligo)" self_address_mligo ; test "implicit account" implicit_account ; test "implicit account (mligo)" implicit_account_mligo ; test "is_nat" is_nat ;