-
Notifications
You must be signed in to change notification settings - Fork 2
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
Int relational operators #76
Changes from 11 commits
c4bb571
0c902b5
df723ab
60b83ff
39ccfe6
d3fb1dd
a85e903
6d8c04e
dd66d41
def647f
1e9fc51
a1fedf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
```k | ||
|
||
module RUST-INTEGER-OPERATIONS | ||
imports private RUST-INTEGER-ARITHMETIC-OPERATIONS | ||
imports private RUST-INTEGER-RELATIONAL-OPERATIONS | ||
endmodule | ||
|
||
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 ptrValue(_, i32(A):Value) * ptrValue(_, i32(B):Value) => ptrValue(null, i32(A *MInt B)) | ||
rule ptrValue(_, i32(A):Value) + ptrValue(_, i32(B):Value) => ptrValue(null, i32(A +MInt B)) | ||
rule ptrValue(_, i32(A):Value) - ptrValue(_, i32(B):Value) => ptrValue(null, i32(A -MInt B)) | ||
rule ptrValue(_, i32(A):Value) / ptrValue(_, i32(B):Value) => ptrValue(null, i32(A /sMInt B)) | ||
rule ptrValue(_, i32(A):Value) % ptrValue(_, i32(B):Value) => ptrValue(null, i32(A %sMInt B)) | ||
|
||
rule ptrValue(_, u32(A):Value) * ptrValue(_, u32(B):Value) => ptrValue(null, u32(A *MInt B)) | ||
rule ptrValue(_, u32(A):Value) + ptrValue(_, u32(B):Value) => ptrValue(null, u32(A +MInt B)) | ||
rule ptrValue(_, u32(A):Value) - ptrValue(_, u32(B):Value) => ptrValue(null, u32(A -MInt B)) | ||
rule ptrValue(_, u32(A):Value) / ptrValue(_, u32(B):Value) => ptrValue(null, u32(A /uMInt B)) | ||
rule ptrValue(_, u32(A):Value) % ptrValue(_, u32(B):Value) => ptrValue(null, u32(A %uMInt B)) | ||
|
||
rule ptrValue(_, i64(A):Value) * ptrValue(_, i64(B):Value) => ptrValue(null, i64(A *MInt B)) | ||
rule ptrValue(_, i64(A):Value) + ptrValue(_, i64(B):Value) => ptrValue(null, i64(A +MInt B)) | ||
rule ptrValue(_, i64(A):Value) - ptrValue(_, i64(B):Value) => ptrValue(null, i64(A -MInt B)) | ||
rule ptrValue(_, i64(A):Value) / ptrValue(_, i64(B):Value) => ptrValue(null, i64(A /sMInt B)) | ||
rule ptrValue(_, i64(A):Value) % ptrValue(_, i64(B):Value) => ptrValue(null, i64(A %sMInt B)) | ||
|
||
rule ptrValue(_, u64(A):Value) * ptrValue(_, u64(B):Value) => ptrValue(null, u64(A *MInt B)) | ||
rule ptrValue(_, u64(A):Value) + ptrValue(_, u64(B):Value) => ptrValue(null, u64(A +MInt B)) | ||
rule ptrValue(_, u64(A):Value) - ptrValue(_, u64(B):Value) => ptrValue(null, u64(A -MInt B)) | ||
rule ptrValue(_, u64(A):Value) / ptrValue(_, u64(B):Value) => ptrValue(null, u64(A /uMInt B)) | ||
rule ptrValue(_, u64(A):Value) % ptrValue(_, u64(B):Value) => ptrValue(null, u64(A %uMInt B)) | ||
|
||
rule ptrValue(_, u128(A):Value) * ptrValue(_, u128(B):Value) => ptrValue(null, u128(A *MInt B)) | ||
rule ptrValue(_, u128(A):Value) + ptrValue(_, u128(B):Value) => ptrValue(null, u128(A +MInt B)) | ||
rule ptrValue(_, u128(A):Value) - ptrValue(_, u128(B):Value) => ptrValue(null, u128(A -MInt B)) | ||
rule ptrValue(_, u128(A):Value) / ptrValue(_, u128(B):Value) => ptrValue(null, u128(A /uMInt B)) | ||
rule ptrValue(_, u128(A):Value) % ptrValue(_, u128(B):Value) => ptrValue(null, u128(A %uMInt B)) | ||
|
||
endmodule | ||
|
||
|
||
module RUST-INTEGER-RELATIONAL-OPERATIONS | ||
imports RUST-SHARED-SYNTAX | ||
imports private RUST-REPRESENTATION | ||
|
||
rule ptrValue(null, i32(A):Value) == ptrValue(null, i32(B):Value) => ptrValue(null, A ==MInt B) | ||
rule ptrValue(null, i32(A):Value) != ptrValue(null, i32(B):Value) => ptrValue(null, A =/=MInt B) | ||
rule ptrValue(null, i32(A):Value) > ptrValue(null, i32(B):Value) => ptrValue(null, A >sMInt B) | ||
rule ptrValue(null, i32(A):Value) < ptrValue(null, i32(B):Value) => ptrValue(null, A <sMInt B) | ||
rule ptrValue(null, i32(A):Value) >= ptrValue(null, i32(B):Value) => ptrValue(null, A >=sMInt B) | ||
rule ptrValue(null, i32(A):Value) <= ptrValue(null, i32(B):Value) => ptrValue(null, A <=sMInt B) | ||
|
||
rule ptrValue(null, u32(A):Value) == ptrValue(null, u32(B):Value) => ptrValue(null, A ==MInt B) | ||
rule ptrValue(null, u32(A):Value) != ptrValue(null, u32(B):Value) => ptrValue(null, A =/=MInt B) | ||
rule ptrValue(null, u32(A):Value) > ptrValue(null, u32(B):Value) => ptrValue(null, A >uMInt B) | ||
rule ptrValue(null, u32(A):Value) < ptrValue(null, u32(B):Value) => ptrValue(null, A <uMInt B) | ||
rule ptrValue(null, u32(A):Value) >= ptrValue(null, u32(B):Value) => ptrValue(null, A >=uMInt B) | ||
rule ptrValue(null, u32(A):Value) <= ptrValue(null, u32(B):Value) => ptrValue(null, A <=uMInt B) | ||
|
||
rule ptrValue(null, i64(A):Value) == ptrValue(null, i64(B):Value) => ptrValue(null, A ==MInt B) | ||
rule ptrValue(null, i64(A):Value) != ptrValue(null, i64(B):Value) => ptrValue(null, A =/=MInt B) | ||
rule ptrValue(null, i64(A):Value) > ptrValue(null, i64(B):Value) => ptrValue(null, A >sMInt B) | ||
rule ptrValue(null, i64(A):Value) < ptrValue(null, i64(B):Value) => ptrValue(null, A <sMInt B) | ||
rule ptrValue(null, i64(A):Value) >= ptrValue(null, i64(B):Value) => ptrValue(null, A >=sMInt B) | ||
rule ptrValue(null, i64(A):Value) <= ptrValue(null, i64(B):Value) => ptrValue(null, A <=sMInt B) | ||
|
||
rule ptrValue(null, u64(A):Value) == ptrValue(null, u64(B):Value) => ptrValue(null, A ==MInt B) | ||
rule ptrValue(null, u64(A):Value) != ptrValue(null, u64(B):Value) => ptrValue(null, A =/=MInt B) | ||
rule ptrValue(null, u64(A):Value) > ptrValue(null, u64(B):Value) => ptrValue(null, A >uMInt B) | ||
rule ptrValue(null, u64(A):Value) < ptrValue(null, u64(B):Value) => ptrValue(null, A <uMInt B) | ||
rule ptrValue(null, u64(A):Value) >= ptrValue(null, u64(B):Value) => ptrValue(null, A >=uMInt B) | ||
rule ptrValue(null, u64(A):Value) <= ptrValue(null, u64(B):Value) => ptrValue(null, A <=uMInt B) | ||
|
||
rule ptrValue(null, u128(A):Value) == ptrValue(null, u128(B):Value) => ptrValue(null, A ==MInt B) | ||
rule ptrValue(null, u128(A):Value) != ptrValue(null, u128(B):Value) => ptrValue(null, A =/=MInt B) | ||
rule ptrValue(null, u128(A):Value) > ptrValue(null, u128(B):Value) => ptrValue(null, A >uMInt B) | ||
rule ptrValue(null, u128(A):Value) < ptrValue(null, u128(B):Value) => ptrValue(null, A <uMInt B) | ||
rule ptrValue(null, u128(A):Value) >= ptrValue(null, u128(B):Value) => ptrValue(null, A >=uMInt B) | ||
rule ptrValue(null, u128(A):Value) <= ptrValue(null, u128(B):Value) => ptrValue(null, A <=uMInt B) | ||
|
||
endmodule | ||
|
||
``` |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ endmodule | |
|
||
module RUST-SHARED-SYNTAX | ||
imports STRING-SYNTAX | ||
imports BOOL-SYNTAX | ||
``` | ||
|
||
https://doc.rust-lang.org/reference/crates-and-source-files.html | ||
|
@@ -257,7 +258,7 @@ https://doc.rust-lang.org/reference/items/extern-crates.html | |
| ByteLiteral | ByteStringLiteral | RawByteStringLiteral | ||
| CStringLiteral | RawCStringLiteral | ||
| IntegerLiteral | FloatLiteral | ||
| "true" | "false" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure these aren't needed here? Would this grammar still parse a .rs file containing true/false? Even if the file is still parsable (e.g. it may identify true/false as identifiers), why is it a good idea to remove these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My motivation for removing them was to primarily eliminate parsing ambiguity in the execution module. Having a syntax element named Keeping Finally, please, correct me if I'm wrong, but my understanding is that an |
||
| Bool | ||
|
||
syntax CharLiteral ::= "TODO: not needed yet, not implementing" | ||
// TODO: Not implemented properly | ||
|
@@ -373,12 +374,12 @@ https://doc.rust-lang.org/reference/items/extern-crates.html | |
| Expression "^" Expression | ||
| Expression "|" Expression | ||
|
||
> Expression "==" Expression | ||
| Expression "!=" Expression | ||
| Expression ">" Expression | ||
| Expression "<" Expression | ||
| Expression ">=" Expression | ||
| Expression "<=" Expression | ||
> Expression "==" Expression [seqstrict] | ||
| Expression "!=" Expression [seqstrict] | ||
| Expression ">" Expression [seqstrict] | ||
| Expression "<" Expression [seqstrict] | ||
| Expression ">=" Expression [seqstrict] | ||
| Expression "<=" Expression [seqstrict] | ||
|
||
> left: | ||
Expression "&&" Expression | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.arithmetic_expression_mult_constant; | ||
return_value; | ||
check_eq 86400_u64 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.relational_expression_smaller; | ||
return_value; | ||
check_eq true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.relational_expression_greater; | ||
return_value; | ||
check_eq false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.arithmetic_expression_div_constant; | ||
return_value; | ||
check_eq 2_u64 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.arithmetic_expression_sum_constant; | ||
return_value; | ||
check_eq 101_u64 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.arithmetic_expression_sub_constant; | ||
return_value; | ||
check_eq 99_u64 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.arithmetic_expression_mod_constant; | ||
return_value; | ||
check_eq 2_u64 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.relational_expression_equals; | ||
return_value; | ||
check_eq true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.relational_expression_diff; | ||
return_value; | ||
check_eq false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.relational_expression_smaller_or_equal; | ||
return_value; | ||
check_eq true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new IntegerOperations; | ||
call IntegerOperations.relational_expression_greater_or_equal; | ||
return_value; | ||
check_eq true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but you could also write
ptrValue(null, B:Bool:Value)
directly.