This overall approach is not without its problems:
- It makes Crack code platform-dependent because there are expressions that will work on one platform but will result in a compile-time error on another platform. For example, "int32 i = int(v);" works on platforms with 32 bit integers, but breaks on platforms with 64 bit integers.
- You end up writing a lot of explicit type conversions in places where you really don't care that much (like when using a signed integer value for a function argument of type "uint"). For a scripting language valuing terse syntax, this is kind of lame.
- PDNTs will be promiscuous: any numeric type will implicitly convert to any PDNT type. So "int i = float64(v);" will be perfectly legal on any platform.
- There will be max-size, min-size assumptions about PDNTs. In particular, they will all be at least 32 bits but no more than 64 bits in size. Like everything else in the language, these assumptions are subject to change across major versions of the language.
- UNTs will continue to apply the strict conversion rules. However, because of the min-size/max-size assumptions, certain conversions from PDNTs will always be legal. An example of this is "int64 i = int(v)".
To mitigate this effect, there will be a warning flag that allows you to identify the places where you could potentially lose precision with something like this. We are also considering allowing the generation of a runtime check that would throw an exception if specific values will be truncated.
This change will probably go into the language in Crack 0.5. For anyone interested, the formal proposal is at http://code.google.com/p/crack-language/wiki/PlatformDependentNumericTypes
No comments:
Post a Comment