-
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 arithmetic operations in the preprocessing stage (#68)
* Adding arithmetic operations in the preprocessing stage * Fix typo * Changing strict for seqstrict and introducing a test for arithmetic expressions on constants * Fixing typo in name and addint tests
- Loading branch information
1 parent
0073e26
commit d4f008f
Showing
10 changed files
with
98 additions
and
5 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
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,42 @@ | ||
```k | ||
module RUST-INTEGER-ARITHMETIC-OPERATIONS | ||
imports RUST-SHARED-SYNTAX | ||
imports private RUST-REPRESENTATION | ||
// Operations are implemented only for the same types, | ||
// as implicit type casting (coercion) is not available | ||
// in Rust. | ||
rule i32(A):Value * i32(B):Value => i32(A *MInt B) | ||
rule i32(A):Value + i32(B):Value => i32(A +MInt B) | ||
rule i32(A):Value - i32(B):Value => i32(A -MInt B) | ||
rule i32(A):Value / i32(B):Value => i32(A /sMInt B) | ||
rule i32(A):Value % i32(B):Value => i32(A %sMInt B) | ||
rule u32(A):Value * u32(B):Value => u32(A *MInt B) | ||
rule u32(A):Value + u32(B):Value => u32(A +MInt B) | ||
rule u32(A):Value - u32(B):Value => u32(A -MInt B) | ||
rule u32(A):Value / u32(B):Value => u32(A /uMInt B) | ||
rule u32(A):Value % u32(B):Value => u32(A %uMInt B) | ||
rule i64(A):Value * i64(B):Value => i64(A *MInt B) | ||
rule i64(A):Value + i64(B):Value => i64(A +MInt B) | ||
rule i64(A):Value - i64(B):Value => i64(A -MInt B) | ||
rule i64(A):Value / i64(B):Value => i64(A /sMInt B) | ||
rule i64(A):Value % i64(B):Value => i64(A %sMInt B) | ||
rule u64(A):Value * u64(B):Value => u64(A *MInt B) | ||
rule u64(A):Value + u64(B):Value => u64(A +MInt B) | ||
rule u64(A):Value - u64(B):Value => u64(A -MInt B) | ||
rule u64(A):Value / u64(B):Value => u64(A /uMInt B) | ||
rule u64(A):Value % u64(B):Value => u64(A %uMInt B) | ||
rule u128(A):Value * u128(B):Value => u128(A *MInt B) | ||
rule u128(A):Value + u128(B):Value => u128(A +MInt B) | ||
rule u128(A):Value - u128(B):Value => u128(A -MInt B) | ||
rule u128(A):Value / u128(B):Value => u128(A /uMInt B) | ||
rule u128(A):Value % u128(B):Value => u128(A %uMInt 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 ArithmeticExpression; | ||
call ArithmeticExpression.arithmetic_expression_mult_constant; | ||
return_value; | ||
check_eq 86400_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 ArithmeticExpression; | ||
call ArithmeticExpression.arithmetic_expression_div_constant; | ||
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 ArithmeticExpression; | ||
call ArithmeticExpression.arithmetic_expression_sum_constant; | ||
return_value; | ||
check_eq 101_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 ArithmeticExpression; | ||
call ArithmeticExpression.arithmetic_expression_sub_constant; | ||
return_value; | ||
check_eq 99_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 ArithmeticExpression; | ||
call ArithmeticExpression.arithmetic_expression_mod_constant; | ||
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,25 @@ | ||
#![no_std] | ||
|
||
#[allow(unused_imports)] | ||
use multiversx_sc::imports::*; | ||
|
||
#[multiversx_sc::contract] | ||
pub trait ArithmeticExpression { | ||
#[init] | ||
fn init(&self) { | ||
} | ||
|
||
#[upgrade] | ||
fn upgrade(&self) {} | ||
|
||
fn arithmetic_expression_mult_constant(&self) -> u64 { 24_u64 * 60_u64 * 60_u64 } | ||
|
||
fn arithmetic_expression_div_constant(&self) -> u64 { 10_u64 / 4_u64 } | ||
|
||
fn arithmetic_expression_sum_constant(&self) -> u64 { 100_u64 + 1_u64 } | ||
|
||
fn arithmetic_expression_sub_constant(&self) -> u64 { 100_u64 - 1_u64 } | ||
|
||
fn arithmetic_expression_mod_constant(&self) -> u64 { 5_u64 % 3_u64 } | ||
|
||
} |