Open Smit-create opened 1 year ago
Yes, I think we have an issue for this somewhere. We need to pick either 0 or 1 for these in ASR. For arrays we always include the first index, so there is no problem. For the rest of the nodes I would pick and probably 0, as that makes it easier on the LLVM backend.
Okay, I think we should probably go with 1 based indexing everywhere to keep it uniform and probably fix that in lpython
?
I would pick 0 for the following reasons:
The only downside is that our future Fortran backend has to fix up string indexing.
If we pick 1, then Fortran is fine, but we have to adjust indexing in Python a lot.
Let's take an example of the
StringSection
node. It was introduced inlpython
and now it is also used inlfortran
. The currentStringSection
in the LLVM backend is implemented based on 0-based indexing and so works forlpython
but fails forlfortran
. We need to have these fixes in ASR so that each front end follows the same indexing in every node.See the following snippet in python:
Works fine:
Fortran
Fails:
This should also be kept the same for loops etc.
cc @certik @czgdp1807