Add support for iN and uN for all suitable N. (#3868)

`i32` is retained as a special case for now, for bootstrapping purposes,
and maps to `BuiltinIntType`, which is distinct from `Core.Int(32)`.
This will be removed later once we support `Core.BigInt`.

For now this provides both the `iN` types and also the builtins to
support `Core.Int(N)`. The intent is that we'll change the `iN` support
to rewrite to calls here when we do that for the other type literals and
type keywords.

No conversions between integer types are supported yet, and all literals
are of type `i32`, so we can't actually form values of any of these new
types.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
This commit is contained in:
Richard Smith
2024-04-08 10:09:02 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins Carbon Infra Bot
parent 895e90e791
commit bb117aea3a
25 changed files with 1234 additions and 56 deletions
+13 -16
View File
@@ -941,22 +941,19 @@ TEST_F(LexerTest, TypeLiterals) {
{.kind = TokenKind::FileEnd, .line = 6, .column = 3},
}));
auto token_i1 = buffer.tokens().begin() + 2;
EXPECT_EQ(buffer.GetTypeLiteralSize(*token_i1), 1);
auto token_i20 = buffer.tokens().begin() + 3;
EXPECT_EQ(buffer.GetTypeLiteralSize(*token_i20), 20);
auto token_i999999999999 = buffer.tokens().begin() + 4;
EXPECT_EQ(buffer.GetTypeLiteralSize(*token_i999999999999), 999999999999ULL);
auto token_u1 = buffer.tokens().begin() + 7;
EXPECT_EQ(buffer.GetTypeLiteralSize(*token_u1), 1);
auto token_u64 = buffer.tokens().begin() + 8;
EXPECT_EQ(buffer.GetTypeLiteralSize(*token_u64), 64);
auto token_f32 = buffer.tokens().begin() + 10;
EXPECT_EQ(buffer.GetTypeLiteralSize(*token_f32), 32);
auto token_f80 = buffer.tokens().begin() + 11;
EXPECT_EQ(buffer.GetTypeLiteralSize(*token_f80), 80);
auto token_f1 = buffer.tokens().begin() + 12;
EXPECT_EQ(buffer.GetTypeLiteralSize(*token_f1), 1);
auto type_size = [&](int token_index) {
auto token = buffer.tokens().begin()[token_index];
return value_stores_.ints().Get(buffer.GetTypeLiteralSize(token));
};
EXPECT_EQ(type_size(2), 1);
EXPECT_EQ(type_size(3), 20);
EXPECT_EQ(type_size(4), 999999999999ULL);
EXPECT_EQ(type_size(7), 1);
EXPECT_EQ(type_size(8), 64);
EXPECT_EQ(type_size(10), 32);
EXPECT_EQ(type_size(11), 80);
EXPECT_EQ(type_size(12), 1);
}
TEST_F(LexerTest, TypeLiteralTooManyDigits) {