diff --git a/rust-semantics/expression.md b/rust-semantics/expression.md index 2993e93..7502c3f 100644 --- a/rust-semantics/expression.md +++ b/rust-semantics/expression.md @@ -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" @@ -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 ``` diff --git a/rust-semantics/expression/bool-operations.md b/rust-semantics/expression/bool-operations.md new file mode 100644 index 0000000..dbcd162 --- /dev/null +++ b/rust-semantics/expression/bool-operations.md @@ -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 + +``` diff --git a/rust-semantics/rust-common-syntax.md b/rust-semantics/rust-common-syntax.md index bad7899..e9de99b 100644 --- a/rust-semantics/rust-common-syntax.md +++ b/rust-semantics/rust-common-syntax.md @@ -350,7 +350,7 @@ https://doc.rust-lang.org/reference/items/extern-crates.html | "&" "mut" Expression | "&&" "mut" Expression | "-" Expression - | "!" Expression + | "!" Expression [seqstrict] | DereferenceExpression // > left: @@ -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 diff --git a/rust-semantics/targets/preprocessing/rust.md b/rust-semantics/targets/preprocessing/rust.md index 58c75c9..730f28d 100644 --- a/rust-semantics/targets/preprocessing/rust.md +++ b/rust-semantics/targets/preprocessing/rust.md @@ -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 @@ -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 diff --git a/tests/execution/bool-operations.1.run b/tests/execution/bool-operations.1.run new file mode 100644 index 0000000..8222a7b --- /dev/null +++ b/tests/execution/bool-operations.1.run @@ -0,0 +1,4 @@ +new BoolOperations; +call BoolOperations.bool_logical_operation_and; +return_value; +check_eq true diff --git a/tests/execution/bool-operations.2.run b/tests/execution/bool-operations.2.run new file mode 100644 index 0000000..44d0140 --- /dev/null +++ b/tests/execution/bool-operations.2.run @@ -0,0 +1,4 @@ +new BoolOperations; +call BoolOperations.bool_logical_operation_or; +return_value; +check_eq true diff --git a/tests/execution/bool-operations.3.run b/tests/execution/bool-operations.3.run new file mode 100644 index 0000000..417c49a --- /dev/null +++ b/tests/execution/bool-operations.3.run @@ -0,0 +1,4 @@ +new BoolOperations; +call BoolOperations.bool_logical_operation_not; +return_value; +check_eq false diff --git a/tests/execution/bool-operations.rs b/tests/execution/bool-operations.rs new file mode 100644 index 0000000..db51e49 --- /dev/null +++ b/tests/execution/bool-operations.rs @@ -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 } + +}