Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top level functions #147

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions mx-rust-semantics/main/calls/implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,21 @@ module MX-RUST-CALLS-IMPLEMENTATION
...
</k>
<mx-rust-endpoint-to-function>
FunctionName |-> Endpoint:Identifier ...
FunctionName:String:KItem |-> Endpoint:PathInExpression ...
</mx-rust-endpoint-to-function>
<mx-rust-contract-trait> TraitName:TypePath </mx-rust-contract-trait>
<mx-call-args> Args:MxValueList </mx-call-args>
<trait-path> TraitName </trait-path>
<method-name> Endpoint </method-name>
<method-params> _:SelfSort : _ , Nfp:NormalizedFunctionParameterList </method-params>

rule (ptrValue(...) #as SelfValue:Expression) , Params:CallParamsList
~> MxRust#partialMethodCall(Method:Identifier)
=> methodCall(... self: SelfValue, method: Method, params: Params)
~> MxRust#partialMethodCall(Method:PathInExpression)
=> functionCall(... function: Method, params: (SelfValue , Params))

syntax MxRustInstruction ::= "MxRust#newContractObject" "(" TypePath ")"
rule MxRust#newContractObject(P:TypePath) => Rust#newStruct(P, .Map)

syntax MxRustInstruction ::= "MxRust#partialMethodCall" "(" Identifier ")"
syntax MxRustInstruction ::= "MxRust#partialMethodCall" "(" PathInExpression ")"

syntax MxRustInstruction ::= mxArgsToRustArgs
( MxValueList
Expand Down
4 changes: 2 additions & 2 deletions mx-rust-semantics/main/modules/address.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module MX-RUST-MODULES-ADDRESS
| "mx_address_value" [token]

rule
normalizedMethodCall
normalizedFunctionCall
( ManagedAddress
, #token("zero", "Identifier"):Identifier
:: #token("zero", "Identifier"):Identifier
, ( .PtrList)
)
=> mxRustEmptyValue(rustType(ManagedAddress))
Expand Down
8 changes: 4 additions & 4 deletions mx-rust-semantics/main/modules/biguint.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module MX-RUST-MODULES-BIGUINT

rule
<k>
normalizedMethodCall
normalizedFunctionCall
( #token("BigUint", "Identifier"):Identifier
, #token("from", "Identifier"):Identifier
:: #token("from", "Identifier"):Identifier
, ( ptr(ValueId:Int)
, .PtrList
)
Expand All @@ -26,9 +26,9 @@ module MX-RUST-MODULES-BIGUINT
</k>
<values> ValueId |-> V:Value ... </values>

rule normalizedMethodCall
rule normalizedFunctionCall
( #token("BigUint", "Identifier"):Identifier
, #token("zero", "Identifier"):Identifier
:: #token("zero", "Identifier"):Identifier
, .PtrList
)
=> mxRustBigIntNew(0)
Expand Down
4 changes: 2 additions & 2 deletions mx-rust-semantics/main/modules/blockchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module MX-RUST-MODULES-BLOCKCHAIN
)

rule
normalizedMethodCall
normalizedFunctionCall
( MxRust#Blockchain
, #token("new", "Identifier"):Identifier
:: #token("new", "Identifier"):Identifier
, .PtrList
)
=> mxRustNewStruct
Expand Down
4 changes: 2 additions & 2 deletions mx-rust-semantics/main/modules/call-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module MX-RUST-MODULES-CALL-VALUE
)

rule
normalizedMethodCall
normalizedFunctionCall
( MxRust#CallValue
, #token("new", "Identifier"):Identifier
:: #token("new", "Identifier"):Identifier
, .PtrList
)
=> mxRustNewStruct
Expand Down
4 changes: 2 additions & 2 deletions mx-rust-semantics/main/modules/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module MX-RUST-MODULES-HOOKS

rule
<k>
normalizedMethodCall
normalizedFunctionCall
( #token("MxRust#Hooks", "Identifier"):Identifier
, #token("MxRust#loadMxReturnValue", "Identifier"):Identifier
:: #token("MxRust#loadMxReturnValue", "Identifier"):Identifier
, ( ptr(ReturnTypeId:Int)
, .PtrList
)
Expand Down
4 changes: 2 additions & 2 deletions mx-rust-semantics/main/modules/managed-vec.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module MX-RUST-MODULES-MANAGED-VEC
imports private RUST-SHARED-SYNTAX

rule
normalizedMethodCall
normalizedFunctionCall
( #token("ManagedVec", "Identifier"):Identifier
, #token("new", "Identifier"):Identifier
:: #token("new", "Identifier"):Identifier
, .PtrList
)
=> mxRustEmptyValue(rustType(#token("ManagedVec", "Identifier")))
Expand Down
11 changes: 5 additions & 6 deletions mx-rust-semantics/main/modules/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ module MX-RUST-MODULES-PROXY

rule
<k>
normalizedMethodCall
normalizedFunctionCall
( #token("MxRust#Proxy", "Identifier"):Identifier
, #token("new", "Identifier"):Identifier
:: #token("new", "Identifier"):Identifier
, ptr(P1), ptr(P2), .PtrList
)
=> mxRustNewStruct
Expand All @@ -70,7 +70,7 @@ module MX-RUST-MODULES-PROXY
normalizedMethodCall
( #token("MxRust#Proxy", "Identifier"):Identifier
=> ProxyType
, MethodName:Identifier
, _MethodName:Identifier
, (ptr(SelfId:Int) , _Params:PtrList)
)
...
Expand All @@ -85,7 +85,6 @@ module MX-RUST-MODULES-PROXY
...
</values>
<trait-path> ProxyType </trait-path>
<method-name> MethodName </method-name>

syntax RustMxInstruction ::= rustMxManagedExecuteOnDestContext
( destination: RustToMxOrInstruction // RustToMx
Expand Down Expand Up @@ -184,9 +183,9 @@ module MX-RUST-MODULES-PROXY

rule
<k>
normalizedMethodCall
normalizedFunctionCall
( #token("MxRust#Proxy", "Identifier"):Identifier
, #token("MxRust#execute_on_dest_context", "Identifier"):Identifier
:: #token("MxRust#execute_on_dest_context", "Identifier"):Identifier
, (ptr(SelfId:Int) , .PtrList)
)
=> rustMxManagedExecuteOnDestContext
Expand Down
4 changes: 2 additions & 2 deletions mx-rust-semantics/main/modules/send.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module MX-RUST-MODULES-SEND
)

rule
normalizedMethodCall
normalizedFunctionCall
( MxRust#Send
, #token("new", "Identifier"):Identifier
:: #token("new", "Identifier"):Identifier
, .PtrList
)
=> mxRustNewStruct
Expand Down
8 changes: 4 additions & 4 deletions mx-rust-semantics/main/modules/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ module MX-RUST-MODULES-STORAGE
imports private RUST-SHARED-SYNTAX

rule
normalizedMethodCall
( #token("SingleValueMapper", "Identifier"):Identifier #as Type:Identifier
, #token("new", "Identifier"):Identifier
normalizedFunctionCall
( #token("SingleValueMapper", "Identifier"):Identifier
:: #token("new", "Identifier"):Identifier
, ( ptr(KeyId:Int)
, ptr(ResultTypeId:Int)
, .PtrList
)
)
=> mxRustNewValue
( struct
( Type
( #token("SingleValueMapper", "Identifier"):Identifier
, #token("storage_key", "Identifier"):Identifier |-> KeyId
#token("result_type", "Identifier"):Identifier |-> ResultTypeId
)
Expand Down
2 changes: 1 addition & 1 deletion mx-rust-semantics/main/preprocessing/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module MX-RUST-PREPROCESSED-ENDPOINTS-CONFIGURATION
imports MAP

configuration
<mx-rust-endpoint-to-function> .Map </mx-rust-endpoint-to-function> // String to Identifier
<mx-rust-endpoint-to-function> .Map </mx-rust-endpoint-to-function> // String to PathInExpression
endmodule

```
33 changes: 22 additions & 11 deletions mx-rust-semantics/main/preprocessing/contract.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
```k

module MX-RUST-PREPROCESSING-CONTRACT
imports COMMON-K-CELL
imports MX-RUST-REPRESENTATION
imports RUST-PREPROCESSING-CONFIGURATION
imports private COMMON-K-CELL
imports private MX-RUST-REPRESENTATION
imports private RUST-CONVERSIONS-SYNTAX
imports private RUST-PREPROCESSING-CONFIGURATION

syntax MxRustInstruction ::= rustMxAddContractSend(TypePath)
| rustMxAddContractCallValue(TypePath)
Expand All @@ -13,6 +14,10 @@ module MX-RUST-PREPROCESSING-CONTRACT
, method: Identifier
, struct: Identifier
)
| rustMxAddContractGenericMethod
( method: PathInExpression
, struct: Identifier
)

rule rustMxAddContractMethods(Trait:TypePath)
=> rustMxAddContractSend(Trait:TypePath)
Expand Down Expand Up @@ -40,33 +45,39 @@ module MX-RUST-PREPROCESSING-CONTRACT
, struct: #token("MxRust#Blockchain", "Identifier")
)

rule rustMxAddContractGenericMethod
(... trait: Trait:TypePath
, method: Method:Identifier
, struct: Identifier
)
=> rustMxAddContractGenericMethod
(... method: typePathToPathInExpression(append(Trait, Method))
, struct: Identifier
)

rule
<k>
rustMxAddContractGenericMethod
(... trait: Trait:TypePath
, method: Method:Identifier
(... method: Method:PathInExpression
)
=> error
( "send already exists for trait"
, ListItem(Trait)
( "method already exists for trait"
, ListItem(Method)
)
...
</k>
<trait-path> Trait </trait-path>
<method-name> Method </method-name>
[priority(50)]

rule
<k>
rustMxAddContractGenericMethod
(... trait: Trait:TypePath
, method: Method:Identifier
(... method: Method:PathInExpression
, struct: Struct:Identifier
)
=> .K
...
</k>
<trait-path> Trait </trait-path>
( .Bag
=> <method>
<method-name> Method </method-name>
Expand Down
Loading
Loading