-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Arrange the cells for easier debugging * Create a list of traits to help with mx preprocessing * Static method calls * Integer - value conversions * Ignore generic args when casting structs * Framework for executing Mx+Rust * Framework for testing Mx+Rust * Implement storage functions * Implement storage accessors * Implement BigUint::from * Default storage values * Storage set_if_empty * Storage tests --------- Co-authored-by: Virgil <[email protected]>
- Loading branch information
1 parent
ba6decd
commit b62f09a
Showing
39 changed files
with
929 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
```k | ||
requires "mx-semantics/main/configuration.md" | ||
requires "rust-semantics/config.md" | ||
module MX-RUST-COMMON-CONFIGURATION | ||
imports MX-COMMON-CONFIGURATION | ||
imports RUST-CONFIGURATION | ||
configuration | ||
<mx-rust> | ||
<mx-common/> | ||
<rust/> | ||
</mx-rust> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
```k | ||
requires "expression/strings.md" | ||
module MX-RUST-EXPRESSION | ||
imports private MX-RUST-EXPRESSION-STRINGS | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
```k | ||
module MX-RUST-EXPRESSION-STRINGS | ||
imports private BOOL | ||
imports private INT | ||
imports private MX-RUST-REPRESENTATION | ||
imports private RUST-VALUE-SYNTAX | ||
imports private STRING | ||
rule concatString(ptrValue(_, S1:String), ptrValue(_, S2:String)) | ||
=> ptrValue(null, S1 +String S2) | ||
rule toString(ptrValue(_, i32(Value:MInt{32}))) | ||
=> ptrValue(null, padLeftString(Base2String(MInt2Unsigned(Value), 16), "0", 32 divInt 4)) | ||
rule toString(ptrValue(_, u32(Value:MInt{32}))) | ||
=> ptrValue(null, padLeftString(Base2String(MInt2Unsigned(Value), 16), "0", 32 divInt 4)) | ||
rule toString(ptrValue(_, i64(Value:MInt{64}))) | ||
=> ptrValue(null, padLeftString(Base2String(MInt2Unsigned(Value), 16), "0", 64 divInt 4)) | ||
rule toString(ptrValue(_, u64(Value:MInt{64}))) | ||
=> ptrValue(null, padLeftString(Base2String(MInt2Unsigned(Value), 16), "0", 64 divInt 4)) | ||
rule toString(ptrValue(_, u128(Value:MInt{128}))) | ||
=> ptrValue(null, padLeftString(Base2String(MInt2Unsigned(Value), 16), "0", 128 divInt 4)) | ||
rule toString(ptrValue(null, Value:String)) => ptrValue(null, Value) | ||
// TODO: convert all Value entries to string | ||
syntax String ::= padLeftString(value:String, padding:String, count:Int) [function, total] | ||
rule padLeftString(...value:S, padding:P, count:C) => S | ||
requires C <=Int lengthString(S) orBool lengthString(P) =/=Int 1 | ||
rule padLeftString(S:String => P +String S, P:String, _Count:Int) | ||
[owise] | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
```k | ||
module MX-RUST-GLUE | ||
imports private COMMON-K-CELL | ||
imports private MX-COMMON-SYNTAX | ||
imports private RUST-EXECUTION-CONFIGURATION | ||
imports private RUST-VALUE-SYNTAX | ||
imports private MX-RUST-REPRESENTATION | ||
rule | ||
<k> | ||
storeHostValue | ||
(... destination: rustDestination(ValueId, _:MxRustType) | ||
, value: wrappedRust(V:Value) | ||
) | ||
=> .K | ||
... | ||
</k> | ||
<values> Values:Map => Values[ValueId <- V] </values> | ||
requires ValueId >=Int 0 | ||
rule | ||
(.K => mxRustEmptyValue(T)) | ||
~> storeHostValue | ||
(... destination: rustDestination(_, T:MxRustType) | ||
, value: mxWrappedEmpty | ||
) | ||
rule | ||
(ptrValue(_, V:Value) => .K) | ||
~> storeHostValue | ||
(... value: mxWrappedEmpty => wrappedRust(V) | ||
) | ||
rule | ||
<k> | ||
mxRustLoadPtr(P:Int) => ptrValue(ptr(P), V) | ||
... | ||
</k> | ||
<values> P |-> V:Value ... </values> | ||
rule | ||
<k> mxRustNewValue(V:Value) => ptrValue(ptr(NextId), V) ... </k> | ||
<next-value-id> NextId:Int => NextId +Int 1 </next-value-id> | ||
<values> Values:Map => Values[NextId <- V] </values> | ||
rule mxIntValue(I:Int) ~> mxValueToRust(T:Type) | ||
=> mxRustNewValue(integerToValue(I, T)) | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```k | ||
requires "modules/biguint.md" | ||
requires "modules/storage.md" | ||
module MX-RUST-MODULES | ||
imports private MX-RUST-MODULES-BIGUINT | ||
imports private MX-RUST-MODULES-STORAGE | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
```k | ||
module MX-RUST-MODULES-BIGUINT | ||
imports private COMMON-K-CELL | ||
imports private MX-COMMON-SYNTAX | ||
imports private MX-RUST-REPRESENTATION | ||
imports private RUST-EXECUTION-CONFIGURATION | ||
imports private RUST-REPRESENTATION | ||
imports private RUST-SHARED-SYNTAX | ||
rule | ||
<k> | ||
normalizedMethodCall | ||
( #token("BigUint", "Identifier"):Identifier | ||
, #token("from", "Identifier"):Identifier | ||
, ( ptr(ValueId:Int) | ||
, .NormalizedCallParams | ||
) | ||
) | ||
// TODO: Should check that V >= 0 | ||
=> mxRustBigIntNew(valueToInteger(V)) | ||
... | ||
</k> | ||
<values> ValueId |-> V:Value ... </values> | ||
// -------------------------------------- | ||
syntax MxRustInstruction ::= mxRustBigIntNew(IntOrError) | ||
| "mxRustCreateBigUint" | ||
rule mxRustBigIntNew(V:Int) | ||
=> MX#bigIntNew(mxIntValue(V)) | ||
~> mxValueToRust(i32) | ||
~> mxRustCreateBigUint | ||
rule ptrValue(ptr(BigUintId:Int), _) ~> mxRustCreateBigUint | ||
=> mxRustNewValue | ||
( struct | ||
( #token("BigUint", "Identifier"):Identifier | ||
, #token("mx_biguint_id", "Identifier"):Identifier |-> BigUintId | ||
) | ||
) | ||
rule mxRustEmptyValue(BigUint) => mxRustBigIntNew(0) | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
```k | ||
module MX-RUST-MODULES-STORAGE | ||
imports private COMMON-K-CELL | ||
imports private MX-COMMON-SYNTAX | ||
imports private MX-RUST-REPRESENTATION | ||
imports private RUST-EXECUTION-CONFIGURATION | ||
imports private RUST-REPRESENTATION | ||
imports private RUST-SHARED-SYNTAX | ||
rule | ||
normalizedMethodCall | ||
( #token("SingleValueMapper", "Identifier"):Identifier #as Type:Identifier | ||
, #token("new", "Identifier"):Identifier | ||
, ( ptr(KeyId:Int) | ||
, ptr(ResultTypeId:Int) | ||
, .NormalizedCallParams | ||
) | ||
) | ||
=> mxRustNewValue | ||
( struct | ||
( Type | ||
, #token("storage_key", "Identifier"):Identifier |-> KeyId | ||
#token("result_type", "Identifier"):Identifier |-> ResultTypeId | ||
) | ||
) | ||
rule | ||
<k> | ||
normalizedMethodCall | ||
( #token("SingleValueMapper", "Identifier"):Identifier #as Type:Identifier | ||
, #token("set", "Identifier"):Identifier | ||
, ( ptr(SelfId:Int) | ||
, ptr(ValueId:Int) | ||
, .NormalizedCallParams | ||
) | ||
) | ||
=> MX#storageStore(mxStringValue(StorageKey), wrappedRust(V)) | ||
... | ||
</k> | ||
<values> | ||
SelfId |-> struct | ||
( Type | ||
, #token("storage_key", "Identifier"):Identifier |-> StorageKeyId:Int | ||
_:Map | ||
) | ||
StorageKeyId |-> StorageKey:String | ||
ValueId |-> V:Value | ||
... | ||
</values> | ||
rule | ||
<k> | ||
normalizedMethodCall | ||
( #token("SingleValueMapper", "Identifier"):Identifier #as Type:Identifier | ||
, #token("set_if_empty", "Identifier"):Identifier | ||
, ( ptr(SelfId:Int) | ||
, ptr(ValueId:Int) | ||
, .NormalizedCallParams | ||
) | ||
) | ||
=> MX#storageLoad(mxStringValue(StorageKey), rustDestination(-1, noType)) | ||
~> setIfEmpty | ||
~> MX#storageStore(mxStringValue(StorageKey), wrappedRust(V)) | ||
... | ||
</k> | ||
<values> | ||
SelfId |-> struct | ||
( Type | ||
, #token("storage_key", "Identifier"):Identifier |-> StorageKeyId:Int | ||
_:Map | ||
) | ||
StorageKeyId |-> StorageKey:String | ||
ValueId |-> V:Value | ||
... | ||
</values> | ||
rule mxRustEmptyValue(noType) ~> storeHostValue(...) ~> setIfEmpty | ||
=> .K | ||
rule storeHostValue(... value: wrappedRust(_)) | ||
~> setIfEmpty ~> MX#storageStore(_) | ||
=> .K | ||
rule | ||
<k> | ||
normalizedMethodCall | ||
( #token("SingleValueMapper", "Identifier"):Identifier #as Type:Identifier | ||
, #token("get", "Identifier"):Identifier | ||
, ( ptr(SelfId:Int) | ||
, .NormalizedCallParams | ||
) | ||
) | ||
=> MX#storageLoad(mxStringValue(StorageKey), rustDestination(NextId, ResultType)) | ||
~> mxRustLoadPtr(NextId) | ||
... | ||
</k> | ||
<values> | ||
SelfId |-> struct | ||
( Type | ||
, #token("storage_key", "Identifier"):Identifier |-> StorageKeyId:Int | ||
#token("result_type", "Identifier"):Identifier |-> ResultTypeId:Int | ||
_:Map | ||
) | ||
StorageKeyId |-> StorageKey:String | ||
ResultTypeId |-> ResultType:MxRustType | ||
... | ||
</values> | ||
<next-value-id> NextId:Int => NextId +Int 1 </next-value-id> | ||
syntax MxRustInstruction ::= "setIfEmpty" | ||
endmodule | ||
``` |
Oops, something went wrong.