Skip to content

Commit

Permalink
Empty implementation for events
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Oct 17, 2024
1 parent 0fd8ca7 commit 7cd071b
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/ukm-with-contract/events.1.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
call :: bytes_hooks :: empty;
return_value_to_arg;
push "logEvent(Uint64,Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 123_u64;
call :: bytes_hooks :: append_u64;
return_value_to_arg;
push 555_u64;
call :: bytes_hooks :: append_u64;
return_value;
mock CallData;

call_contract 12345;
return_value;
check_eq ();

push_status;
check_eq 2

18 changes: 18 additions & 0 deletions tests/ukm-with-contract/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![no_std]

#[allow(unused_imports)]
use ukm::*;

#[ukm::contract]
pub trait Events {
#[event("MyEvent")]
fn my_event(&self, #[indexed] from: u64, value: u64);

#[init]
fn init(&self) {}

#[endpoint(logEvent)]
fn log_event(&self, from:u64, value: u64) {
self.my_event(from, value)
}
}
2 changes: 2 additions & 0 deletions ukm-semantics/main/preprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
requires "preprocessing/crates.md"
requires "preprocessing/endpoints.md"
requires "preprocessing/events.md"
requires "preprocessing/methods.md"
requires "preprocessing/storage.md"
requires "preprocessing/syntax.md"
Expand All @@ -13,6 +14,7 @@ module UKM-PREPROCESSING
imports private UKM-COMMON-TOOLS
imports private UKM-PREPROCESSING-CRATES
imports private UKM-PREPROCESSING-ENDPOINTS
imports private UKM-PREPROCESSING-EVENTS
imports private UKM-PREPROCESSING-METHODS
imports private UKM-PREPROCESSING-STORAGE
imports private UKM-PREPROCESSING-TRAITS
Expand Down
25 changes: 25 additions & 0 deletions ukm-semantics/main/preprocessing/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
```k
module UKM-PREPROCESSING-EVENTS
imports private COMMON-K-CELL
imports private RUST-PREPROCESSING-CONFIGURATION
imports private UKM-PREPROCESSING-SYNTAX-PRIVATE
rule
<k>
ukmPreprocessEvent
(... fullMethodPath: Method:PathInExpression
, eventName: _EventName:String
)
=> .K
...
</k>
<method-name> Method </method-name>
<method-implementation>
empty => block({.InnerAttributes .NonEmptyStatements})
</method-implementation>
<method-return-type> () </method-return-type>
endmodule
```
28 changes: 28 additions & 0 deletions ukm-semantics/main/preprocessing/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module UKM-PREPROCESSING-METHODS
<method-outer-attributes> Atts:OuterAttributes </method-outer-attributes>
requires getEndpointName(Atts, MethodIdentifier) =/=K ""
andBool getStorageName(Atts) ==K ""
andBool getEventName(Atts) ==K ""
rule
<k>
ukmPreprocessMethod(_Trait:TypePath, MethodIdentifier:Identifier, Method:PathInExpression)
Expand All @@ -40,6 +41,21 @@ module UKM-PREPROCESSING-METHODS
<method-outer-attributes> Atts:OuterAttributes </method-outer-attributes>
requires getStorageName(Atts) =/=K ""
andBool getEndpointName(Atts, MethodIdentifier) ==K ""
andBool getEventName(Atts) ==K ""
rule
<k>
ukmPreprocessMethod(_Trait:TypePath, MethodIdentifier:Identifier, Method:PathInExpression)
=> ukmPreprocessEvent
(... fullMethodPath: Method
, eventName: getEventName(Atts)
)
...
</k>
<method-name> Method </method-name>
<method-outer-attributes> Atts:OuterAttributes </method-outer-attributes>
requires getEventName(Atts) =/=K ""
andBool getEndpointName(Atts, MethodIdentifier) ==K ""
andBool getStorageName(Atts) ==K ""
rule ukmPreprocessMethod(_:TypePath, _:Identifier, _:PathInExpression) => .K
[owise]
Expand Down Expand Up @@ -91,6 +107,18 @@ module UKM-PREPROCESSING-METHODS
=> getStorageName(Atts)
[owise]
syntax String ::= getEventName(atts:OuterAttributes) [function, total]
rule getEventName() => ""
rule getEventName(.NonEmptyOuterAttributes) => ""
rule getEventName
( (#[ #token("event", "Identifier") :: .SimplePathList
( Name:String, .CallParamsList )
])
_:NonEmptyOuterAttributes
) => Name
rule getEventName(_:OuterAttribute Atts:NonEmptyOuterAttributes)
=> getEventName(Atts)
[owise]
endmodule
```
4 changes: 4 additions & 0 deletions ukm-semantics/main/preprocessing/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ module UKM-PREPROCESSING-SYNTAX-PRIVATE
, mapperValueType: Type
, appendParamsInstructions: NonEmptyStatementsOrError
)
| ukmPreprocessEvent
( fullMethodPath: PathInExpression
, eventName: String
)
endmodule
Expand Down

0 comments on commit 7cd071b

Please sign in to comment.