From a5c254910eb77be8eeb88a78173b4834415e58eb Mon Sep 17 00:00:00 2001 From: Virgil Date: Wed, 28 Aug 2024 18:54:02 +0300 Subject: [PATCH] MX getCaller hook --- mx-semantics/main/biguint/hooks.md | 10 +++++----- mx-semantics/main/calls/configuration.md | 12 ++++++++++++ mx-semantics/main/calls/hooks.md | 14 ++++++++++++++ mx-semantics/main/configuration.md | 3 +++ mx-semantics/main/mx-common.md | 2 ++ mx-semantics/main/syntax.md | 4 +++- mx-semantics/test/execution.md | 13 +++++++++++++ tests/mx/blockchain/get-caller.mx | 3 +++ 8 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 mx-semantics/main/calls/configuration.md create mode 100644 mx-semantics/main/calls/hooks.md create mode 100644 tests/mx/blockchain/get-caller.mx diff --git a/mx-semantics/main/biguint/hooks.md b/mx-semantics/main/biguint/hooks.md index 53697e6d..c7ba438 100644 --- a/mx-semantics/main/biguint/hooks.md +++ b/mx-semantics/main/biguint/hooks.md @@ -1,11 +1,11 @@ ```k module MX-BIGUINT-HOOKS - imports BOOL - imports COMMON-K-CELL - imports K-EQUAL-SYNTAX - imports MX-BIGUINT-CONFIGURATION - imports MX-COMMON-SYNTAX + imports private BOOL + imports private COMMON-K-CELL + imports private K-EQUAL-SYNTAX + imports private MX-BIGUINT-CONFIGURATION + imports private MX-COMMON-SYNTAX rule MX#bigIntNew(mxIntValue(Value:Int)) => mxIntValue(NextId) ... diff --git a/mx-semantics/main/calls/configuration.md b/mx-semantics/main/calls/configuration.md new file mode 100644 index 0000000..c509fd8 --- /dev/null +++ b/mx-semantics/main/calls/configuration.md @@ -0,0 +1,12 @@ +```k + +module MX-CALL-CONFIGURATION + imports STRING + + configuration + + "" + +endmodule + +``` \ No newline at end of file diff --git a/mx-semantics/main/calls/hooks.md b/mx-semantics/main/calls/hooks.md new file mode 100644 index 0000000..c4076e0 --- /dev/null +++ b/mx-semantics/main/calls/hooks.md @@ -0,0 +1,14 @@ +```k + +module MX-CALLS-HOOKS + imports private COMMON-K-CELL + imports private MX-CALL-CONFIGURATION + imports private MX-COMMON-SYNTAX + + rule + MX#getCaller ( .MxHookArgs ) => mxStringValue(Caller) ... + Caller:String + +endmodule + +``` \ No newline at end of file diff --git a/mx-semantics/main/configuration.md b/mx-semantics/main/configuration.md index 3301e9f..6d0125a 100644 --- a/mx-semantics/main/configuration.md +++ b/mx-semantics/main/configuration.md @@ -1,12 +1,15 @@ ```k requires "biguint/configuration.md" +requires "calls/configuration.md" module MX-COMMON-CONFIGURATION imports MX-BIGUINT-CONFIGURATION + imports MX-CALL-CONFIGURATION configuration + endmodule diff --git a/mx-semantics/main/mx-common.md b/mx-semantics/main/mx-common.md index 65f5201..354111c 100644 --- a/mx-semantics/main/mx-common.md +++ b/mx-semantics/main/mx-common.md @@ -1,9 +1,11 @@ ```k requires "biguint/hooks.md" +requires "calls/hooks.md" module MX-COMMON imports private MX-BIGUINT-HOOKS + imports private MX-CALLS-HOOKS endmodule ``` \ No newline at end of file diff --git a/mx-semantics/main/syntax.md b/mx-semantics/main/syntax.md index fdff7ae..66b1315 100644 --- a/mx-semantics/main/syntax.md +++ b/mx-semantics/main/syntax.md @@ -2,8 +2,10 @@ module MX-COMMON-SYNTAX imports INT-SYNTAX + imports STRING-SYNTAX - syntax MxValue ::= mxIntValue(Int) + syntax MxValue ::= mxIntValue(Int) + | mxStringValue(String) syntax MxHookName ::= r"MX#[a-zA-Z][a-zA-Z0-9]*" [token] syntax MxHookArgs ::= List{MxValue, ","} syntax HookCall ::= MxHookName "(" MxHookArgs ")" diff --git a/mx-semantics/test/execution.md b/mx-semantics/test/execution.md index 0b714aa..21eb6aa 100644 --- a/mx-semantics/test/execution.md +++ b/mx-semantics/test/execution.md @@ -3,12 +3,14 @@ module MX-TEST-EXECUTION-PARSING-SYNTAX imports INT-SYNTAX imports MX-COMMON-SYNTAX + imports STRING-SYNTAX syntax TestInstruction ::= "push" MxValue | "call" argcount:Int MxHookName | "get_big_int" | getBigint(Int) | "check_eq" MxValue + | setCaller(String) syntax MxTest ::= NeList{TestInstruction, ";"} @@ -19,6 +21,7 @@ module MX-TEST-EXECUTION imports private COMMON-K-CELL imports private INT imports private MX-BIGUINT-TEST + imports private MX-CALL-TEST imports private MX-TEST-CONFIGURATION imports private MX-TEST-EXECUTION-PARSING-SYNTAX @@ -79,4 +82,14 @@ module MX-BIGUINT-TEST endmodule +module MX-CALL-TEST + imports private COMMON-K-CELL + imports private MX-CALL-CONFIGURATION + imports private MX-TEST-EXECUTION-PARSING-SYNTAX + + rule + setCaller(S:String) => .K ... + _ => S +endmodule + ``` diff --git a/tests/mx/blockchain/get-caller.mx b/tests/mx/blockchain/get-caller.mx new file mode 100644 index 0000000..99fa7ae --- /dev/null +++ b/tests/mx/blockchain/get-caller.mx @@ -0,0 +1,3 @@ +setCaller("Owner"); +call 0 MX#getCaller; +check_eq mxStringValue("Owner")