Skip to content

Commit

Permalink
MX getCaller hook
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Aug 28, 2024
1 parent f0207dd commit a5c2549
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 6 deletions.
10 changes: 5 additions & 5 deletions mx-semantics/main/biguint/hooks.md
Original file line number Diff line number Diff line change
@@ -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
<k> MX#bigIntNew(mxIntValue(Value:Int)) => mxIntValue(NextId) ... </k>
Expand Down
12 changes: 12 additions & 0 deletions mx-semantics/main/calls/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```k
module MX-CALL-CONFIGURATION
imports STRING
configuration
<mx-call-data>
<mx-caller> "" </mx-caller>
</mx-call-data>
endmodule
```
14 changes: 14 additions & 0 deletions mx-semantics/main/calls/hooks.md
Original file line number Diff line number Diff line change
@@ -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
<k> MX#getCaller ( .MxHookArgs ) => mxStringValue(Caller) ... </k>
<mx-caller> Caller:String </mx-caller>
endmodule
```
3 changes: 3 additions & 0 deletions mx-semantics/main/configuration.md
Original file line number Diff line number Diff line change
@@ -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
<mx-common>
<mx-call-data/>
<mx-biguint/>
</mx-common>
endmodule
Expand Down
2 changes: 2 additions & 0 deletions mx-semantics/main/mx-common.md
Original file line number Diff line number Diff line change
@@ -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
```
4 changes: 3 additions & 1 deletion mx-semantics/main/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")"
Expand Down
13 changes: 13 additions & 0 deletions mx-semantics/test/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, ";"}
Expand All @@ -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
Expand Down Expand Up @@ -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
<k> setCaller(S:String) => .K ... </k>
<mx-caller> _ => S </mx-caller>
endmodule
```
3 changes: 3 additions & 0 deletions tests/mx/blockchain/get-caller.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setCaller("Owner");
call 0 MX#getCaller;
check_eq mxStringValue("Owner")

0 comments on commit a5c2549

Please sign in to comment.