-
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 7 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,91 @@ | ||
```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 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 | ||
|
||
|
||
module RUST-INTEGER-RELATIONAL-OPERATIONS | ||
imports RUST-SHARED-SYNTAX | ||
imports private RUST-REPRESENTATION | ||
|
||
rule i32(A):Value == i32(B):Value => A ==MInt B | ||
rule i32(A):Value != i32(B):Value => A =/=MInt B | ||
rule i32(A):Value > i32(B):Value => A >sMInt B | ||
rule i32(A):Value < i32(B):Value => A <sMInt B | ||
rule i32(A):Value >= i32(B):Value => A >=sMInt B | ||
rule i32(A):Value <= i32(B):Value => A <=sMInt B | ||
|
||
rule u32(A):Value == u32(B):Value => A ==MInt B | ||
rule u32(A):Value != u32(B):Value => A =/=MInt B | ||
rule u32(A):Value > u32(B):Value => A >uMInt B | ||
rule u32(A):Value < u32(B):Value => A <uMInt B | ||
rule u32(A):Value >= u32(B):Value => A >=uMInt B | ||
rule u32(A):Value <= u32(B):Value => A <=uMInt B | ||
|
||
rule i64(A):Value == i64(B):Value => A ==MInt B | ||
rule i64(A):Value != i64(B):Value => A =/=MInt B | ||
rule i64(A):Value > i64(B):Value => A >sMInt B | ||
rule i64(A):Value < i64(B):Value => A <sMInt B | ||
rule i64(A):Value >= i64(B):Value => A >=sMInt B | ||
rule i64(A):Value <= i64(B):Value => A <=sMInt B | ||
|
||
rule u64(A):Value == u64(B):Value => A ==MInt B | ||
rule u64(A):Value != u64(B):Value => A =/=MInt B | ||
rule u64(A):Value > u64(B):Value => A >uMInt B | ||
rule u64(A):Value < u64(B):Value => A <uMInt B | ||
rule u64(A):Value >= u64(B):Value => A >=uMInt B | ||
rule u64(A):Value <= u64(B):Value => A <=uMInt B | ||
|
||
rule u128(A):Value == u128(B):Value => A ==MInt B | ||
rule u128(A):Value != u128(B):Value => A =/=MInt B | ||
rule u128(A):Value > u128(B):Value => A >uMInt B | ||
rule u128(A):Value < u128(B):Value => A <uMInt B | ||
rule u128(A):Value >= u128(B):Value => A >=uMInt B | ||
rule u128(A):Value <= u128(B):Value => A <=uMInt B | ||
|
||
endmodule | ||
|
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,4 +94,5 @@ module RUST-EXPRESSION-INTEGER-LITERALS | |
rule startsWith(_, _) => false [owise] | ||
|
||
endmodule | ||
|
||
``` |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,11 @@ module RUST-CONSTANTS | |
|
||
rule | ||
(const Name:Identifier : T:Type = V:Value;):ConstantItem:KItem | ||
=> setConstant(Name, implicitCast(V, T)) | ||
=> setConstant(Name, implicitCast(V, T)) | ||
|
||
// rule | ||
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. Maybe remove the comment? |
||
// (const Name:Identifier : _:Type = V:Bool;):ConstantItem:KItem | ||
// => setConstant(Name, V) [priority(50)] | ||
|
||
rule | ||
<k> | ||
|
@@ -23,6 +27,8 @@ module RUST-CONSTANTS | |
<constant-value> V </constant-value> | ||
</constant> | ||
... | ||
</constants> | ||
</constants> | ||
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. Why is there a diff for this line? 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. I had implemented a rule below and added some empty lines before. It seems like leaving a blank line below triggered this. 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. I checked this again, and you may have added spaces at the end of the line. |
||
|
||
|
||
endmodule | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,8 +257,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 |
||
|
||
|
||
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. Why is there a diff for this line? It should be identical with the empty line in the original file. 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. It was meaningless spaces. I've just removed it. |
||
syntax CharLiteral ::= "TODO: not needed yet, not implementing" | ||
// TODO: Not implemented properly | ||
syntax StringLiteral ::= String | ||
|
@@ -372,12 +371,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.
Why is there a diff for this line?
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.
I'm honestly not sure. I think it may be a change of tabs for spaces, perhaps. Will try to figure it out.