lpython icon indicating copy to clipboard operation
lpython copied to clipboard

Implemented Lshift

Open Kishan-Ved opened this issue 1 year ago • 7 comments

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 avatar Feb 27 '24 13:02 Kishan-Ved

@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

Kishan-Ved avatar Feb 27 '24 13:02 Kishan-Ved

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

Thirumalai-Shaktivel avatar Mar 07 '24 05:03 Thirumalai-Shaktivel

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?

Kishan-Ved avatar Mar 07 '24 10:03 Kishan-Ved

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?

Thirumalai-Shaktivel avatar Mar 09 '24 06:03 Thirumalai-Shaktivel

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 avatar Mar 09 '24 10:03 Kishan-Ved

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 avatar Mar 09 '24 10:03 Kishan-Ved

cc @Thirumalai-Shaktivel @Shaikh-Ubaid

Kishan-Ved avatar Mar 10 '24 17:03 Kishan-Ved