Skip to content

add i64 / u64 types#558

Open
seibert wants to merge 9 commits into
spylang:mainfrom
seibert:i64_u64
Open

add i64 / u64 types#558
seibert wants to merge 9 commits into
spylang:mainfrom
seibert:i64_u64

Conversation

@seibert

@seibert seibert commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

(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.)

seibert and others added 5 commits June 10, 2026 16:30
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>

@antocuni antocuni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do a full review, but let me comment on the "int 64 literal" problem

Comment thread spy/vm/astframe.py
return None
w_val = pyclass(const.value)
return W_MetaArg(self.vm, "blue", w_T, w_val, const.loc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 + 1

currently 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) \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not necessarily opposed to this but:

  1. if we do this, we should do for ALL div/mod/floordiv functions, not just the i64 ones
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants