-
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.
* Adding initial tests * Removing usage of mut var * Mx-rust framework and storage implementation (#80) (#81) * 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]> * Implementing rules for evaluating conditionals and adding tests * handling cases where the conditional is not the return * Removing dead code * Addressing PR comments and adding tests * Adding test for function without return --------- Co-authored-by: Virgil <[email protected]>
- Loading branch information
1 parent
4eac1c1
commit ff36b94
Showing
10 changed files
with
118 additions
and
3 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,11 @@ | ||
```k | ||
module RUST-BLOCK-EXPRESSIONS | ||
imports private RUST-SHARED-SYNTAX | ||
imports private RUST-VALUE-SYNTAX | ||
rule S:ExpressionWithBlock ; => S | ||
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,15 @@ | ||
```k | ||
module RUST-CONDITIONAL-EXPRESSIONS | ||
imports RUST-SHARED-SYNTAX | ||
imports RUST-VALUE-SYNTAX | ||
rule (if ptrValue(_, true) S:BlockExpression):ExpressionWithBlock => S [owise] | ||
rule (if ptrValue(_, false) _:BlockExpression):ExpressionWithBlock => .K [owise] | ||
rule (if ptrValue(_, true) A:BlockExpression else _:IfElseExpression):ExpressionWithBlock => A | ||
rule (if ptrValue(_, false) _:BlockExpression else B:IfElseExpression):ExpressionWithBlock => B | ||
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
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,4 @@ | ||
new IfExpressions; | ||
call IfExpressions.if_expression; | ||
return_value; | ||
check_eq 1_u64 |
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,4 @@ | ||
new IfExpressions; | ||
call IfExpressions.if_else_expression; | ||
return_value; | ||
check_eq 2_u64 |
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,4 @@ | ||
new IfExpressions; | ||
call IfExpressions.if_else_if_expression; | ||
return_value; | ||
check_eq 3_u64 |
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,4 @@ | ||
new IfExpressions; | ||
call IfExpressions.test_if_instruction; | ||
return_value; | ||
check_eq 11_u64 |
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,2 @@ | ||
new IfExpressions; | ||
call IfExpressions.test_if_no_return |
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,64 @@ | ||
#![no_std] | ||
|
||
#[allow(unused_imports)] | ||
use multiversx_sc::imports::*; | ||
|
||
#[multiversx_sc::contract] | ||
pub trait IfExpressions { | ||
#[init] | ||
fn init(&self) { | ||
} | ||
|
||
#[upgrade] | ||
fn upgrade(&self) {} | ||
|
||
fn if_expression(&self) -> u64 { | ||
|
||
if 80_u64 == 80_u64 { | ||
1_u64 | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
fn if_else_expression(&self) -> u64 { | ||
|
||
if 80_u64 != 80_u64 { | ||
1_u64 | ||
} else { | ||
2_u64 | ||
} | ||
|
||
} | ||
|
||
fn if_else_if_expression(&self) -> u64 { | ||
|
||
if 80_u64 != 80_u64 { | ||
1_u64 | ||
} else if false { | ||
2_u64 | ||
} else { | ||
3_u64 | ||
} | ||
|
||
} | ||
|
||
fn test_if_instruction(&self) -> u64 { | ||
if true { | ||
let x = 10_u64; | ||
} else { | ||
let y = 11_u64; | ||
}; | ||
11_u64 | ||
} | ||
|
||
fn test_if_no_return(&self) { | ||
if true { | ||
let x = 10_u64; | ||
} else { | ||
let y = 11_u64; | ||
}; | ||
} | ||
|
||
} |