| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
This is a Work in progress (WIP). The tests might not pass. |
Sorry, something went wrong.
$ cat examples/expr2.py from lpython import u16, bitnot_u16, i32 u: u16 = u16(255) u = bitnot_u16(u) print(u) print(~i32(u)) $ lpython examples/expr2.py 65280 255 $ python examples/expr2.py 65280 -65281 It seems we are unable to use bitnot() and ~ successively. |
Sorry, something went wrong.
|
The bitnot seems correct but ~ doesn't work? We have to debug it. |
Sorry, something went wrong.
|
That issue is fixed. The following is a concern: $ cat examples/expr2.py
from lpython import i16, u64, bitnot_u64
w: u64 = u64(123457889998923)
x: u64 = bitnot_u64(w)
print(w, i16(w), ~i16(w))
print(x, i16(x), ~i16(x))
$ python examples/expr2.py
123457889998923 123457889998923 -123457889998924
18446620615819552692 18446620615819552692 -18446620615819552693
$ lpython examples/expr2.py
123457889998923 -26549 26548
18446620615819552692 26548 -26549It seems u8, u16, u32 and u64 need to be some functions that could convert values appropriately in CPython. |
Sorry, something went wrong.
|
the i16 and u16 in LPython must give a runtime (or compile time) error when the value you are converting is out of range. The contract is that if LPython works, then CPython must work. So in CPython we don't need to do any checking and all these casts become a no-op. |
Sorry, something went wrong.
|
If the casts in CPython become no-op, the output value of CPython is not matching the output of LPython (Example: #2176 (comment)). |
Sorry, something went wrong.
|
For unsigned unary minus, shall we throw error in LPython similar to unsigned bit not? |
Sorry, something went wrong.
|
The contract is that if LPython compiles and runs this without errors, then CPython produces the same value. The design of all i8-i64, u8-u64 is such that they are just no-op in CPython and they always produce exactly the same number as in LPython, since LPython only allows such casts that don't change the value. If the value is out of range, we give an error message. So this design should work. |
Sorry, something went wrong.
Got it. Thank you so much for the clarification! |
Sorry, something went wrong.
Given that -0 = 0, the unary minus should be allowed for unsigned, but obviously it will only work for 0, for all other values it must give a runtime error. |
Sorry, something went wrong.
|
The CI might temporarily pass now. As a next step, we need to support
|
Sorry, something went wrong.
|
Further steps could be to support compile time overflow checking and later runtime error checking for which we have a dedicated issue here #2183. |
Sorry, something went wrong.
|
Otherwise it looks good. After you fix the above, please do not merge it, I have to manually check and update our internal codes if needed before we can merge it. |
Sorry, something went wrong.
There was a problem hiding this comment.
I think this change is good. I'll mark it as draft, so that we don't accidentally merge it. I need to see if anything broke first.
Sorry, something went wrong.
|
I tested the compiled mode (LPython) and it gives a nice error message (it could be improved to give back exactly the expression to use, but it's good enough for now) and after using bitnot_u64 it works. I now need to test the emulation mode (lpython.py), which is the more fragile mode that might have some bugs. |
Sorry, something went wrong.
|
Everything works for us, so I am merging this PR. Thanks @Shaikh-Ubaid ! |
Sorry, something went wrong.
|
I made a new release with this change: https://github.com/lcompilers/lpython/releases/tag/v0.18.4 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
towards #2173