fusionlanguage / fut

Fusion programming language. Transpiling to C, C++, C#, D, Java, JavaScript, Python, Swift, TypeScript and OpenCL C.
https://fusion-lang.org
GNU General Public License v3.0
1.75k stars 55 forks source link

[Feature Request] Introduce size_t type to language #166

Open al1-ce opened 2 months ago

al1-ce commented 2 months ago

Since 4 languages use it for array length it'd be beneficial to have it.

What it'd transpile to:

Partially related to #97

pfusik commented 2 months ago

In .NET there's Array.LongLength and arrays can be subscripted by longs. Unlike Lists.

In JavaScript and Python arrays of numeric types are typed. So the size type needs to be defined somehow.

pfusik commented 1 month ago

C# has nint and nuint.

pfusik commented 4 weeks ago

I added an initial implementation. Needs testing and documentation. The type is named nint.

I opted for a signed type, hence it's ptrdiff_t in C, C++, D and OpenCL. This way loops like

for (nint i = foo.Length; --i >= 0; )

are not endless loops. I know no machine where 64-bit vs 63-bit size would make a difference.

Browsers cannot create typed arrays above 32-bit counts. But Python happily creates large bytearrays and arrays. Therefore nint is 32-bit in JavaScript and 64-bit in Python.