You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Const i32 expressions do not support integer div/mod operations #2349
running it through lpython breaks with the following error:
$ ~/Workspace/lpython/src/bin/lpython /var/tmp/lp/qux.py
semantic error: Arguments do not match for any generic procedure, _lpython_floordiv
--> /var/tmp/lp/qux.py:4:19
|
4 | bar: Const[i32] = foo // 2
| ^^^^^^^^
Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.
This should be supported, especially since lpython does not complain about multiplication:
$ ~/Workspace/lpython/src/bin/lpython /var/tmp/lp/qux.py
semantic error: Arguments do not match for any generic procedure, _mod
--> /var/tmp/lp/qux.py:4:19
|
4 | bar: Const[i32] = foo % 2
| ^^^^^^^
Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.
--
The information contained in this electronic communication is intended
solely for the individual(s) or entity to which it is addressed. It may
contain proprietary, confidential and/or legally privileged information.
Any review, retransmission, dissemination, printing, copying or other use
of, or taking any action in reliance on the contents of this information by
person(s) or entities other than the intended recipient is strictly
prohibited and may be unlawful. If you have received this communication in
error, please notify us by responding to this email or telephone and
immediately and permanently delete all copies of this message and any
attachments from your system(s). The contents of this message do not
necessarily represent the views or policies of BITS Pilani.
If i am right then this is becasue in C and C++ comments start with "//" so it is unable to recognize it as a floor division operator and thinks of it as a comment.
No, the error comes from LPython not being able to find an implementation for this case. Rather, we should be routing this operation via an explicit ASR node, or via the IntrinsicFunction node.
You can try it, and if the patch is simple, we can merge it as a short-term workaround. Floor belongs into ASR itself as IntrinsicFunction, so it's always better to invest into the long-term solution.
Activity
Thirumalai-Shaktivel commentedon Sep 29, 2023
I think, the
Const[i32]is not handled in_lpython_floordivand_modabhi-glitchhg commentedon Sep 29, 2023
Thirumalai-Shaktivel commentedon Sep 29, 2023
Sure, go ahead and submit a PR!
AnandRaj-7 commentedon Sep 29, 2023
If i am right then this is becasue in C and C++ comments start with "//" so it is unable to recognize it as a floor division operator and thinks of it as a comment.
certik commentedon Sep 29, 2023
No, the error comes from LPython not being able to find an implementation for this case. Rather, we should be routing this operation via an explicit ASR node, or via the IntrinsicFunction node.
ubaidsk commentedon Oct 2, 2023
I think we can implement floordiv operation similar to the mod operation using IntrinsicFunction node as in lfortran/lfortran#2519.
abhi-glitchhg commentedon Oct 2, 2023
I was thinking of overloading the
_lpython_floordivfunction with inputs dtypes const[i32]. is this approach not good/preferred?certik commentedon Oct 2, 2023
You can try it, and if the patch is simple, we can merge it as a short-term workaround. Floor belongs into ASR itself as IntrinsicFunction, so it's always better to invest into the long-term solution.
certik commentedon Oct 8, 2023
The following now works:
Thanks @Shaikh-Ubaid !