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
notice 15 did not have to be i32(15) -- could it be that i32 is required (unnecessarily) only in the default-value initializers in the dataclass StringIO?
Currently we support int() (CPython builtin method) which converts to i64 and float() ((CPython builtin method)) which converts to f64. I think we do not yet support int and float as types.
CPython doesn't have double, and float is f64, so we can make an alias float -> f64. Regarding int, we have the following options:
i32, as the default int in LPython
i64 the widest int currently available
arbitrary precision integer (not currently implemented, but on our long term todo list, we need it for symbolics and in general it's good to have, since CPython has it, and sometimes it would be useful in Fortran also): the advantage is that int would then behave exactly as in CPython, and then i64, i32, etc. are faster fixed size integers. Also we need some name for the arbitrary precision integer anyway, and CPython already has a name for that, int, so why not just use int for arbitrary precision integer? If we go this route, I would then change the casting int(n) to cast to arbitrary precision as well.
So maybe for now we can give a nice error message for int that it is not supported yet. And later once we can do arbitrary precision int, we can revisit this.
This is also related to currently having to explicitly cast all integers and floats to be the same type for arithmetic operations and for assignments. We switched to this more strict approach which made things clear what type everything is, and it discovered bugs in our test suite, showing that it's easy to make a mistake if not casting things explicitly. But once we have more experience using LPython as a programming language, we can relax things in various ways. And if we do, it might also influence how we decide about what int should be, as well as what an integer number like 123 should be (currently it is i32).
Activity
rebcabin commentedon Jun 16, 2023
notice
15did not have to bei32(15)-- could it be thati32is required (unnecessarily) only in the default-value initializers in the dataclassStringIO?certik commentedon Jun 16, 2023
I am not quite sure. But indeed the default integer should just be i32, no matter where it is used.
ubaidsk commentedon Jun 18, 2023
lpython/src/lpython/semantics/python_intrinsic_eval.h
Lines 48 to 63 in 8838e52
Currently we support
int()(CPython builtin method) which converts toi64andfloat()((CPython builtin method)) which converts tof64. I think we do not yet supportintandfloatas types.ubaidsk commentedon Jun 18, 2023
In this issue, do we wish to support type alias
intandfloat? Shouldintcorrespond toi32ori64? Shouldfloatcorrespond tof64?Thirumalai-Shaktivel commentedon Jun 19, 2023
I think we need to support the following type
int->i32float->f32double->f64Or we can also implement this as #1199
certik commentedon Jun 20, 2023
CPython doesn't have double, and
floatisf64, so we can make an aliasfloat->f64. Regardingint, we have the following options:i32, as the default int in LPythoni64the widest int currently availableintwould then behave exactly as in CPython, and theni64,i32, etc. are faster fixed size integers. Also we need some name for the arbitrary precision integer anyway, and CPython already has a name for that,int, so why not just useintfor arbitrary precision integer? If we go this route, I would then change the castingint(n)to cast to arbitrary precision as well.So maybe for now we can give a nice error message for
intthat it is not supported yet. And later once we can do arbitrary precision int, we can revisit this.This is also related to currently having to explicitly cast all integers and floats to be the same type for arithmetic operations and for assignments. We switched to this more strict approach which made things clear what type everything is, and it discovered bugs in our test suite, showing that it's easy to make a mistake if not casting things explicitly. But once we have more experience using LPython as a programming language, we can relax things in various ways. And if we do, it might also influence how we decide about what
intshould be, as well as what an integer number like123should be (currently it isi32).certik commentedon Sep 27, 2023
Right now let's do:
NishantBansal2003 commentedon Feb 3, 2024
Can I work on this issue??
NishantBansal2003 commentedon Feb 3, 2024
I have explicitly changed the error message for 'int' to :
certik commentedon Feb 3, 2024
Just submit a PR, no need to ask for a permission.
fixes semantic error for int (Issue lcompilers#1926)
Improved int semantic error message with hint (Issue lcompilers#1926)
Added Reference test (Issue lcompilers#1926)
Merge pull request #2476 from NishantBansal2003/semantic_error_update
fixes semantic error for int (Issue lcompilers#1926)
Improved int semantic error message with hint (Issue lcompilers#1926)
Added Reference test (Issue lcompilers#1926)