lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.37k stars 157 forks source link

Implemented Lshift #2556

Open Kishan-Ved opened 4 months ago

Kishan-Ved commented 4 months ago

I thought this would be a good one to get started with LPython implementations.

Reference: https://docs.python.org/3/library/operator.html#operator.lshift

Kishan-Ved commented 4 months ago

@certik Sir the error seems weird. Can we rerun this?

Also, I noticed that many intrinsic functions like Trailz don't have integration tests.

Edit: I have fixed the windows CI error in https://github.com/lcompilers/lpython/pull/2562

Thirumalai-Shaktivel commented 4 months ago

Please mark this PR ready for review once it is ready.

Kishan-Ved commented 4 months ago

The test fails for cpython, may I please know the reason. The error is:

Traceback (most recent call last):
  File "/home/kishan/Desktop/lpython/integration_tests/intrinsics_03.py", line 8, in <module>
    print(lshift(a,b))
NameError: name 'lshift' is not defined

The file runs when I do ./src/bin/lpython integration_tests/intrinsics_03.py and gives the correct output.

Do I need to make more additions to some files?

Thirumalai-Shaktivel commented 4 months ago

It fails because, python doesn't have builtin lshift support. I think it needs to be imported from the operator module, see: https://docs.python.org/3/library/operator.html#operator.lshift. Something like:

from operator import lshift
print(lshift(x, y))

Does x << y work in lpython?

Kishan-Ved commented 4 months ago

It fails because, python doesn't have builtin lshift support. I think it needs to be imported from the operator module, see: https://docs.python.org/3/library/operator.html#operator.lshift. Something like:

from operator import lshift
print(lshift(x, y))

Does x << y work in lpython?

Yes, x<<y works in lpython. Also, you are right, lshift() needs to be imported from the operator module and is not built in python.

Kishan-Ved commented 4 months ago

It fails because, python doesn't have builtin lshift support. I think it needs to be imported from the operator module, see: https://docs.python.org/3/library/operator.html#operator.lshift. Something like:

from operator import lshift
print(lshift(x, y))

Does x << y work in lpython?

I want lshift to be imported only for the python test. For LPython's implementation, I want the control to be redirected to my intrinsic function. How can I achieve this? Or should we include the cpython test later, when we implement the operator module for LPython, and there we redirect control to this intrinsic?

Kishan-Ved commented 4 months ago

cc @Thirumalai-Shaktivel @Shaikh-Ubaid