-
Notifications
You must be signed in to change notification settings - Fork 164
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
Unsigned integers no wrap II #2189
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3305591
ASR: Allow only compile-time 0 in UnsignedUnaryMinus
Shaikh-Ubaid 87c8ca1
TEST: Update unsigned unary minus test and enable it
Shaikh-Ubaid 962ca71
TEST: Update unsigned bit shift test and enable it
Shaikh-Ubaid b7b526a
ASR: Error for casting negative int as unsigned int
Shaikh-Ubaid 528ab8c
TEST: Remove commented code
Shaikh-Ubaid d9e14fa
ASRUtils: Support compile-time values for unsigned in make_Cast_t_val…
Shaikh-Ubaid cbb79b6
TEST: Add test for different unsigned int cases
Shaikh-Ubaid 4629fc7
TEST: Update reference tests
Shaikh-Ubaid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,27 +1,30 @@ | ||
from lpython import u16, u32, u64 | ||
from lpython import u8, u16, u32, u64 | ||
|
||
def f(): | ||
|
||
h: u8 | ||
h = u8(67) | ||
print(+h) | ||
assert +h == u8(67) | ||
|
||
i: u16 | ||
i = u16(67) | ||
print(-i, +i, -(-i)) | ||
assert -i == u16(65469) | ||
print(+i) | ||
assert +i == u16(67) | ||
assert -(-i) == u16(67) | ||
|
||
j: u32 | ||
j = u32(25) | ||
print(-j, +j, -(-j)) | ||
assert -j == u32(4294967271) | ||
print(+j) | ||
assert +j == u32(25) | ||
assert -(-j) == u32(25) | ||
|
||
k: u64 | ||
k = u64(100000000000123) | ||
print(-k, +k, -(-k)) | ||
# TODO: We are unable to store the following u64 in AST/R | ||
# assert -k == u64(18446644073709551493) | ||
print(+k) | ||
assert +k == u64(100000000000123) | ||
assert -(-k) == u64(100000000000123) | ||
|
||
assert -u8(0) == u8(0) | ||
assert -u16(0) == u16(0) | ||
assert -u32(0) == u32(0) | ||
assert -u64(0) == u64(0) | ||
|
||
f() |
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
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,3 @@ | ||
from lpython import u16 | ||
|
||
i: u16 = u16(-5) |
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,3 @@ | ||
from lpython import u16 | ||
|
||
i: u16 = -u16(5) |
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,3 @@ | ||
from lpython import u32, u64 | ||
|
||
print(-u64(u32(10))) |
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 @@ | ||
from lpython import u16 | ||
|
||
i: u16 = u16(5) | ||
i = ~i |
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,13 @@ | ||
{ | ||
"basename": "asr-unsigned_01-892b178", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/unsigned_01.py", | ||
"infile_hash": "c176f4ec65c0b5ca7c2c95b2e35d65f22b4cef342baad15c2dd5ef24", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-unsigned_01-892b178.stderr", | ||
"stderr_hash": "54c7cfbd16c73cbe802a3492cd9c9e8d2fb25035192d229232c377b2", | ||
"returncode": 2 | ||
} |
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,5 @@ | ||
semantic error: Cannot cast negative value to unsigned integer | ||
--> tests/errors/unsigned_01.py:3:10 | ||
| | ||
3 | i: u16 = u16(-5) | ||
| ^^^^^^^ |
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,13 @@ | ||
{ | ||
"basename": "asr-unsigned_02-6563e58", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/unsigned_02.py", | ||
"infile_hash": "7892abcbe7cecdbddc7362fd0940986bf64458880ccd198c16dd2a6e", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-unsigned_02-6563e58.stderr", | ||
"stderr_hash": "93f2cf309dfa7f13d56df9184615fde6a832b79510d8541f95ad5a70", | ||
"returncode": 2 | ||
} |
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,5 @@ | ||
semantic error: The result of the unary minus `-` operation is negative, thus out of range for u16 | ||
--> tests/errors/unsigned_02.py:3:10 | ||
| | ||
3 | i: u16 = -u16(5) | ||
| ^^^^^^^ use -i32(u) for signed result | ||
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,13 @@ | ||
{ | ||
"basename": "asr-unsigned_03-f785652", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/unsigned_03.py", | ||
"infile_hash": "72dd2c6e17b137b6b9f66deeaab0af4ebe3044cb16009e0fab25f05a", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-unsigned_03-f785652.stderr", | ||
"stderr_hash": "d90013a25d9aaa91fbbf2b1193cd06be94a4e716f0fe99771cde5601", | ||
"returncode": 2 | ||
} |
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,5 @@ | ||
semantic error: The result of the unary minus `-` operation is negative, thus out of range for u64 | ||
--> tests/errors/unsigned_03.py:3:7 | ||
| | ||
3 | print(-u64(u32(10))) | ||
| ^^^^^^^^^^^^^ use -i64(u) for signed result |
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,13 @@ | ||
{ | ||
"basename": "asr-unsigned_04-c856d3a", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/unsigned_04.py", | ||
"infile_hash": "d1c2f82e9578ce3f2364f4bbd3177bc0ae72357c644953418eaffe4c", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-unsigned_04-c856d3a.stderr", | ||
"stderr_hash": "3dcdf2e97f8c5f2816bed266587c7c3743f666cf2a4602f65e8ec9b8", | ||
"returncode": 2 | ||
} |
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,5 @@ | ||
semantic error: The result of the bitnot ~ operation is negative, thus out of range for u16 | ||
--> tests/errors/unsigned_04.py:4:5 | ||
| | ||
4 | i = ~i | ||
| ^^ use ~i32(u) for signed result or bitnot_u16(u) for unsigned result |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be great if it could copy the actual expression inside:
But I guess for that we would have to have an ASR -> Python printer, which we plan to, but not right now. So we can do that later.