lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.5k stars 158 forks source link

String to int conversion in ASR #2554

Open certik opened 7 months ago

certik commented 7 months ago

Figure out a clean way to represent and implement string to int conversions in ASR.

Then figure out how to hook it up in LPython.

Discussed at https://lfortran.zulipchat.com/#narrow/stream/311866-LPython/topic/String.20to.20Int.20conversion.

Shaikh-Ubaid commented 6 months ago

It looks like we already have some support for string to int conversion.

% cat examples/expr2.py 
def main():
    x: str = "123"
    print(int(x))

main()
% python examples/expr2.py         
123
% lpython_in_main examples/expr2.py
123
Shaikh-Ubaid commented 6 months ago

I think we just need to polish the existing support.

kmr-srbh commented 6 months ago

@Shaikh-Ubaid I think we should support the conversion mechanism which intrinsic_int uses, for all the integer types we have. My main concern is that doing i32(int("12345")) is counterintuitive.

kmr-srbh commented 6 months ago

The conversion mechanism for int needs to be improved too. It currently relies on std::stoi() and fails for anything larger than that. We only have to improve the BigInt library we already have.