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

Introducing boolean logical operators #79

Merged
merged 1 commit into from
Sep 10, 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
2 changes: 2 additions & 0 deletions rust-semantics/expression.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
```k
requires "expression/calls.md"
requires "expression/integer-operations.md"
requires "expression/bool-operations.md"
requires "expression/constants.md"
requires "expression/casts.md"
requires "expression/literals.md"
Expand All @@ -17,5 +18,6 @@ module RUST-EXPRESSION
imports private RUST-EXPRESSION-TOOLS
imports private RUST-EXPRESSION-VARIABLES
imports private RUST-INTEGER-OPERATIONS
imports private RUST-BOOL-OPERATIONS
endmodule
```
17 changes: 17 additions & 0 deletions rust-semantics/expression/bool-operations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```k

module RUST-BOOL-OPERATIONS
imports private RUST-BOOL-LOGICAL-OPERATIONS
endmodule

module RUST-BOOL-LOGICAL-OPERATIONS
imports RUST-SHARED-SYNTAX
imports private RUST-REPRESENTATION

rule ptrValue(_, A:Bool) && ptrValue(_, B:Bool) => ptrValue(null, A andBool B)
rule ptrValue(_, A:Bool) || ptrValue(_, B:Bool) => ptrValue(null, A orBool B)
rule ! ptrValue(_, B:Bool) => ptrValue(null, notBool B)

endmodule

```
6 changes: 3 additions & 3 deletions rust-semantics/rust-common-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ https://doc.rust-lang.org/reference/items/extern-crates.html
| "&" "mut" Expression
| "&&" "mut" Expression
| "-" Expression
| "!" Expression
| "!" Expression [seqstrict]
| DereferenceExpression

// > left:
Expand Down Expand Up @@ -382,8 +382,8 @@ https://doc.rust-lang.org/reference/items/extern-crates.html
| Expression "<=" Expression [seqstrict]

> left:
Expression "&&" Expression
| Expression "||" Expression
Expression "&&" Expression [seqstrict]
| Expression "||" Expression [seqstrict]

> Expression ".." Expression

Expand Down
2 changes: 2 additions & 0 deletions rust-semantics/targets/preprocessing/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ requires "../../expression/constants.md"
requires "../../expression/literals.md"
requires "../../rust-common-syntax.md"
requires "../../expression/integer-operations.md"
requires "../../expression/bool-operations.md"

module RUST-SYNTAX
imports RUST-COMMON-SYNTAX
Expand All @@ -16,6 +17,7 @@ endmodule
module RUST
imports private RUST-EXPRESSION-LITERALS
imports private RUST-INTEGER-OPERATIONS
imports private RUST-BOOL-OPERATIONS
imports private RUST-EXPRESSION-CONSTANTS
imports private RUST-PREPROCESSING
imports private RUST-RUNNING-CONFIGURATION
Expand Down
4 changes: 4 additions & 0 deletions tests/execution/bool-operations.1.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
new BoolOperations;
call BoolOperations.bool_logical_operation_and;
return_value;
check_eq true
4 changes: 4 additions & 0 deletions tests/execution/bool-operations.2.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
new BoolOperations;
call BoolOperations.bool_logical_operation_or;
return_value;
check_eq true
4 changes: 4 additions & 0 deletions tests/execution/bool-operations.3.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
new BoolOperations;
call BoolOperations.bool_logical_operation_not;
return_value;
check_eq false
21 changes: 21 additions & 0 deletions tests/execution/bool-operations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![no_std]

#[allow(unused_imports)]
use multiversx_sc::imports::*;

#[multiversx_sc::contract]
pub trait BoolOperations {
#[init]
fn init(&self) {
}

#[upgrade]
fn upgrade(&self) {}

fn bool_logical_operation_and(&self) -> bool { true && true }

fn bool_logical_operation_or(&self) -> bool { false || true }

fn bool_logical_operation_not(&self) -> bool { ! true }

}
Loading