add i64 / u64 types#558
Conversation
Also added unit test for sizeof of all primitive numeric types. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Also added unit test for sizeof of all primitive numeric types. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
In order to ensure literals are not truncated, check the type of the local variable they are being assigned to, and wrap them accordingly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
antocuni
left a comment
There was a problem hiding this comment.
I didn't do a full review, but let me comment on the "int 64 literal" problem
| return None | ||
| w_val = pyclass(const.value) | ||
| return W_MetaArg(self.vm, "blue", w_T, w_val, const.loc) | ||
|
|
There was a problem hiding this comment.
this seems overly complicated. I think we should declare that int literals which don't fit into an i32 are automatically wrapped into an W_I64.
This is temporary anyway: the long term plan is to have a notion of "comptime int" which is "sizeless", and gets assigned a concrete type only when you need to create a variable out of it.
This solves ANOTHER problem which is that if you have this:
x: i8 = 10
x + 1currently 1 is typed as i32, and thus x + 1 as well. With a "comptime int", we would be able to keep x + 1 to be an i8.
That's what zig does.
| // floordiv/mod return the integer type. SIGNED guards the (x^y)<0 floor | ||
| // correction, which is meaningless for unsigned. | ||
| // NAME is the SPy type name used in the symbol (i64/u64); CT is the C type. | ||
| #define SPY_DEF_INT64_DIVMOD(NAME, CT, SIGNED) \ |
There was a problem hiding this comment.
I'm not necessarily opposed to this but:
- if we do this, we should do for ALL div/mod/floordiv functions, not just the i64 ones
- the full name of the function should be spelled explicitly in the macro: this makes it much more easy to grep. Something like:
DEFINE_DIV(spy_operator$i64_div, i64, int64_t)
DEFINE_DIV(spy_operator$i32_div, i32, int32_t)
...
DEFINE_UNCHECKED_DIV(spy_operator$i64_unchecked_div, i64, int64_t)
...there is more code duplication than with this approach, but also much less magic IMHO.
(Based on #557. Merge that one first)
This adds the 64-bit integer types, which are frequently needed to interface with external C APIs.
The PR also includes a change to how integer literals are handled to ensure they are not cast down to int32 before being assigned to a 64-bit integer type.
(AI assistance was used to implement this PR.)