diff --git a/mx-rust-semantics/main/calls/configuration.md b/mx-rust-semantics/main/calls/configuration.md index 3cab8a3..491fdcf 100644 --- a/mx-rust-semantics/main/calls/configuration.md +++ b/mx-rust-semantics/main/calls/configuration.md @@ -7,10 +7,6 @@ module MX-RUST-CALLS-CONFIGURATION configuration .List - .Map // String to Identifier - - // Valid only while a contract call is being prepared - (#token("no#path", "Identifier"):Identifier):TypePath endmodule diff --git a/mx-rust-semantics/main/calls/implementation.md b/mx-rust-semantics/main/calls/implementation.md index 6e6445d..6f2ddb5 100644 --- a/mx-rust-semantics/main/calls/implementation.md +++ b/mx-rust-semantics/main/calls/implementation.md @@ -5,6 +5,8 @@ module MX-RUST-CALLS-IMPLEMENTATION imports private MX-CALL-CONFIGURATION imports private MX-COMMON-SYNTAX imports private MX-RUST-CALLS-CONFIGURATION + imports private MX-RUST-PREPROCESSED-ENDPOINTS-CONFIGURATION + imports private MX-RUST-PREPROCESSED-CONFIGURATION imports private MX-RUST-REPRESENTATION imports private RUST-EXECUTION-CONFIGURATION imports private RUST-PREPROCESSING-CONFIGURATION @@ -45,16 +47,14 @@ module MX-RUST-CALLS-IMPLEMENTATION host.newEnvironment ( rustCode - ( EndpointToFunction:Map - , TraitName:TypePath + ( MxRustPreprocessed:MxRustPreprocessedCell , Preprocessed:PreprocessedCell ) ) => .K ... - _ => TraitName - _ => EndpointToFunction + (_:MxRustPreprocessedCell => MxRustPreprocessed) (_:PreprocessedCell => Preprocessed) rule @@ -68,10 +68,7 @@ module MX-RUST-CALLS-IMPLEMENTATION FunctionName |-> Endpoint:Identifier ... - - TraitName:TypePath - => (#token("no#path", "Identifier"):Identifier):TypePath - + TraitName:TypePath Args:MxValueList TraitName Endpoint diff --git a/mx-rust-semantics/main/configuration.md b/mx-rust-semantics/main/configuration.md index d0fab20..0587c2e 100644 --- a/mx-rust-semantics/main/configuration.md +++ b/mx-rust-semantics/main/configuration.md @@ -2,18 +2,21 @@ requires "calls/configuration.md" requires "mx-semantics/main/configuration.md" +requires "preprocessing/configuration.md" requires "rust-semantics/config.md" module MX-RUST-COMMON-CONFIGURATION imports MX-COMMON-CONFIGURATION imports MX-RUST-CALLS-CONFIGURATION + imports MX-RUST-PREPROCESSED-CONFIGURATION imports RUST-CONFIGURATION configuration + + - endmodule diff --git a/mx-rust-semantics/main/preprocessing/configuration.md b/mx-rust-semantics/main/preprocessing/configuration.md new file mode 100644 index 0000000..21d67cb --- /dev/null +++ b/mx-rust-semantics/main/preprocessing/configuration.md @@ -0,0 +1,27 @@ +```k + +module MX-RUST-PREPROCESSED-CONFIGURATION + imports MX-RUST-PREPROCESSED-CONTRACT-TRAIT-CONFIGURATION + imports MX-RUST-PREPROCESSED-ENDPOINTS-CONFIGURATION + + configuration + + + + +endmodule + +module MX-RUST-PREPROCESSED-CONTRACT-TRAIT-CONFIGURATION + imports RUST-SHARED-SYNTAX + + configuration + (#token("no#path", "Identifier"):Identifier):TypePath // String to Identifier +endmodule + +module MX-RUST-PREPROCESSED-ENDPOINTS-CONFIGURATION + imports MAP + + configuration + .Map // String to Identifier +endmodule +``` diff --git a/mx-rust-semantics/main/preprocessing/methods.md b/mx-rust-semantics/main/preprocessing/methods.md index bf0676e..b53ae64 100644 --- a/mx-rust-semantics/main/preprocessing/methods.md +++ b/mx-rust-semantics/main/preprocessing/methods.md @@ -5,6 +5,7 @@ module MX-RUST-PREPROCESSING-METHODS imports private K-EQUAL-SYNTAX imports private LIST imports private MX-RUST-CALLS-CONFIGURATION + imports private MX-RUST-PREPROCESSED-ENDPOINTS-CONFIGURATION imports private MX-RUST-REPRESENTATION imports private RUST-PREPROCESSING-CONFIGURATION imports private RUST-REPRESENTATION diff --git a/mx-rust-semantics/main/preprocessing/traits.md b/mx-rust-semantics/main/preprocessing/traits.md index e37339e..7c561da 100644 --- a/mx-rust-semantics/main/preprocessing/traits.md +++ b/mx-rust-semantics/main/preprocessing/traits.md @@ -3,20 +3,43 @@ module MX-RUST-PREPROCESSING-TRAITS imports private COMMON-K-CELL imports private LIST + imports private MX-RUST-PREPROCESSED-CONTRACT-TRAIT-CONFIGURATION imports private MX-RUST-REPRESENTATION imports private RUST-PREPROCESSING-CONFIGURATION imports private RUST-SHARED-SYNTAX - syntax MxRustInstruction ::= mxRustPreprocessTraits(List) + syntax MxRustInstruction ::= mxRustPreprocessAddTraits(List) + | mxRustPreprocessAddTrait(TypePath) + | mxRustPreprocessTraits(List) | mxRustPreprocessTrait(TypePath) rule - mxRustPreprocessTraits => mxRustPreprocessTraits(Traits) + mxRustPreprocessTraits + => mxRustPreprocessAddTraits(Traits) ~> mxRustPreprocessTraits(Traits) ... Traits:List + rule mxRustPreprocessAddTraits(.List) => .K + rule mxRustPreprocessAddTraits(ListItem(Trait:TypePath) Traits:List) + => mxRustPreprocessAddTrait(Trait) ~> mxRustPreprocessAddTraits(Traits) + + rule + + mxRustPreprocessAddTrait(Trait:TypePath) => .K + ... + + Trait + + #[ #token("multiversx_sc", "Identifier") + :: #token("contract", "Identifier") + :: .SimplePathList + ] + .NonEmptyOuterAttributes + + _ => Trait + rule mxRustPreprocessTraits(.List) => .K rule mxRustPreprocessTraits(ListItem(Trait:TypePath) Traits:List) => mxRustPreprocessTrait(Trait) ~> mxRustPreprocessTraits(Traits) diff --git a/mx-rust-semantics/main/representation.md b/mx-rust-semantics/main/representation.md index 5de8bc8..5cd417f 100644 --- a/mx-rust-semantics/main/representation.md +++ b/mx-rust-semantics/main/representation.md @@ -33,8 +33,9 @@ module MX-RUST-REPRESENTATION syntax MxValue ::= rustDestination(Int, MxRustType) + syntax MxRustPreprocessedCell syntax PreprocessedCell - syntax ContractCode ::= rustCode(endpointToFunction: Map, type: TypePath, preprocessed: PreprocessedCell) + syntax ContractCode ::= rustCode(MxRustPreprocessedCell, PreprocessedCell) endmodule ``` diff --git a/mx-rust-semantics/setup/mx.md b/mx-rust-semantics/setup/mx.md index 75f243b..478e988 100644 --- a/mx-rust-semantics/setup/mx.md +++ b/mx-rust-semantics/setup/mx.md @@ -3,7 +3,7 @@ module MX-RUST-SETUP-MX imports private COMMON-K-CELL imports private MX-COMMON-SYNTAX - imports private MX-RUST-CALLS-CONFIGURATION + imports private MX-RUST-PREPROCESSED-CONFIGURATION imports private MX-RUST-REPRESENTATION imports private MX-SETUP-SYNTAX imports private RUST-PREPROCESSING-CONFIGURATION @@ -16,7 +16,7 @@ module MX-RUST-SETUP-MX "," gasLimit: Int "," args: MxValueList ")" - syntax MXRustInstruction ::= "MxRust#addAccountWithPreprocessedCode" "(" String "," TypePath ")" + syntax MXRustInstruction ::= "MxRust#addAccountWithPreprocessedCode" "(" String ")" | "MxRust#clearMxReturnValue" rule mxRustCreateAccount(Address:String) => MXSetup#add_account(Address) @@ -59,7 +59,7 @@ module MX-RUST-SETUP-MX , gasLimit: GasLimit:Int , args: Args:MxValueList ) - => MxRust#addAccountWithPreprocessedCode(Contract, TraitName) + => MxRust#addAccountWithPreprocessedCode(Contract) ~> callContract ( "#init" , prepareIndirectContractCallInput @@ -75,20 +75,19 @@ module MX-RUST-SETUP-MX ~> MxRust#clearMxReturnValue ... - ... ListItem(TraitName:TypePath) rule - MxRust#addAccountWithPreprocessedCode(Contract, TraitName) + MxRust#addAccountWithPreprocessedCode(Contract) => MxRust#clearPreprocessed ~> MXSetup#add_account_with_code ( Contract - , rustCode(EndpointToFunction, TraitName, Preprocessed) + , rustCode(MxRustPreprocessed, Preprocessed) ) ... Preprocessed:PreprocessedCell - EndpointToFunction:Map + MxRustPreprocessed:MxRustPreprocessedCell syntax MXRustInstruction ::= "MxRust#clearPreprocessed" rule @@ -99,7 +98,12 @@ module MX-RUST-SETUP-MX (_:PreprocessedCell => ... .List ) - _ => .Map + (_:MxRustPreprocessedCell + => + .Map + ... + + ) rule _V:MxValue ~> MxRust#clearMxReturnValue => .K diff --git a/rust-semantics/preprocessing/configuration.md b/rust-semantics/preprocessing/configuration.md index fc3a6fd..314415a 100644 --- a/rust-semantics/preprocessing/configuration.md +++ b/rust-semantics/preprocessing/configuration.md @@ -18,6 +18,7 @@ module RUST-PREPROCESSING-CONFIGURATION my_identifier:TypePath + `emptyOuterAttributes`(.KList):OuterAttributes .List // List of Identifier diff --git a/rust-semantics/preprocessing/crate.md b/rust-semantics/preprocessing/crate.md index 099a3e6..7a7e817 100644 --- a/rust-semantics/preprocessing/crate.md +++ b/rust-semantics/preprocessing/crate.md @@ -13,9 +13,9 @@ module CRATE => (.InnerAttributes Is):Crate ) rule - (.K => traitParser(T)) + (.K => traitParser(T, ItemAtts)) ~> crateParser - ( (_Atts:InnerAttributes (_ItemAtts:OuterAttributes _V:MaybeVisibility T:Trait):Item Is:Items):Crate + ( (_Atts:InnerAttributes (ItemAtts:OuterAttributes _V:MaybeVisibility T:Trait):Item Is:Items):Crate => (.InnerAttributes Is):Crate ) rule (.K => CI:ConstantItem:KItem) diff --git a/rust-semantics/preprocessing/initialization.md b/rust-semantics/preprocessing/initialization.md index 4828b65..e77c750 100644 --- a/rust-semantics/preprocessing/initialization.md +++ b/rust-semantics/preprocessing/initialization.md @@ -7,7 +7,7 @@ module INITIALIZATION imports private RUST-PREPROCESSING-PRIVATE-SYNTAX rule - traitInitializer(Name:TypePath) => .K + traitInitializer(Name:TypePath, Atts:OuterAttributes) => .K ... .List => ListItem(Name) ... @@ -16,6 +16,7 @@ module INITIALIZATION .Bag => Name + Atts ... diff --git a/rust-semantics/preprocessing/syntax.md b/rust-semantics/preprocessing/syntax.md index e848d55..59797b9 100644 --- a/rust-semantics/preprocessing/syntax.md +++ b/rust-semantics/preprocessing/syntax.md @@ -12,10 +12,11 @@ module RUST-PREPROCESSING-PRIVATE-SYNTAX imports RUST-REPRESENTATION imports RUST-SHARED-SYNTAX - syntax Initializer ::= traitParser(Trait) + syntax Initializer ::= traitParser(Trait, OuterAttributes) | traitMethodsParser(AssociatedItems, traitName:Identifier) | traitInitializer ( traitName: TypePath + , atts: OuterAttributes ) syntax Initializer ::= addMethod(traitName : TypePath, function: Function, atts:OuterAttributes) diff --git a/rust-semantics/preprocessing/trait.md b/rust-semantics/preprocessing/trait.md index 0fc23aa..3a1c360 100644 --- a/rust-semantics/preprocessing/trait.md +++ b/rust-semantics/preprocessing/trait.md @@ -3,8 +3,11 @@ module TRAIT imports private RUST-PREPROCESSING-PRIVATE-SYNTAX - rule traitParser(trait Name:Identifier { .InnerAttributes Functions:AssociatedItems }) - => traitInitializer(Name) + rule traitParser + ( trait Name:Identifier { .InnerAttributes Functions:AssociatedItems } + , ItemAtts:OuterAttributes + ) + => traitInitializer(Name, ItemAtts) ~> traitMethodsParser(Functions, Name) endmodule