From 3c5cc33562e868904fd14828884e647a042cffa4 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Fri, 20 Sep 2024 15:14:34 +0500 Subject: [PATCH] Add more stdint types --- Cesium.Compiler/stdlib/inttypes.h | 2 +- Cesium.Compiler/stdlib/stddef.h | 2 + Cesium.Compiler/stdlib/stdint.h | 31 +++++++++++++++ .../stdlib/types/integer.c | 39 +++++++++++++++++++ Cesium.Runtime.Tests/StdIoFunctionTests.cs | 1 + Cesium.Runtime/StdIoFunctions.cs | 5 ++- 6 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 Cesium.IntegrationTests/stdlib/types/integer.c diff --git a/Cesium.Compiler/stdlib/inttypes.h b/Cesium.Compiler/stdlib/inttypes.h index b77d5602..1e94a025 100644 --- a/Cesium.Compiler/stdlib/inttypes.h +++ b/Cesium.Compiler/stdlib/inttypes.h @@ -1,6 +1,6 @@ #pragma once -//#include +#include #define PRId8 "hhd" #define PRId16 "hd" #define PRId32 "d" diff --git a/Cesium.Compiler/stdlib/stddef.h b/Cesium.Compiler/stdlib/stddef.h index 6839ea62..39b9d921 100644 --- a/Cesium.Compiler/stdlib/stddef.h +++ b/Cesium.Compiler/stdlib/stddef.h @@ -1,6 +1,8 @@ #pragma once typedef __nint ptrdiff_t; typedef __nuint size_t; +typedef __nuint intptr_t; +typedef __nuint uintptr_t; typedef unsigned int max_align_t; diff --git a/Cesium.Compiler/stdlib/stdint.h b/Cesium.Compiler/stdlib/stdint.h index 2691dff4..85d9ff03 100644 --- a/Cesium.Compiler/stdlib/stdint.h +++ b/Cesium.Compiler/stdlib/stdint.h @@ -1,4 +1,5 @@ #pragma once +#include #define INT8_MIN (-127i8 - 1) #define INT16_MIN (-32767i16 - 1) @@ -38,3 +39,33 @@ #define UINT_FAST16_MAX UINT32_MAX #define UINT_FAST32_MAX UINT32_MAX #define UINT_FAST64_MAX UINT64_MAX + +typedef signed char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef signed char int_least8_t; +typedef short int_least16_t; +typedef int int_least32_t; +typedef long long int_least64_t; +typedef unsigned char uint_least8_t; +typedef unsigned short uint_least16_t; +typedef unsigned int uint_least32_t; +typedef unsigned long long uint_least64_t; + +typedef signed char int_fast8_t; +typedef short int_fast16_t; +typedef int int_fast32_t; +typedef long long int_fast64_t; +typedef unsigned char uint_fast8_t; +typedef unsigned short uint_fast16_t; +typedef unsigned int uint_fast32_t; +typedef unsigned long long uint_fast64_t; + +typedef long long intmax_t; +typedef unsigned long long uintmax_t; diff --git a/Cesium.IntegrationTests/stdlib/types/integer.c b/Cesium.IntegrationTests/stdlib/types/integer.c new file mode 100644 index 00000000..12bb341f --- /dev/null +++ b/Cesium.IntegrationTests/stdlib/types/integer.c @@ -0,0 +1,39 @@ +#include +#include + +int main(int argc, char* argv[]) +{ + printf("%zu\n", sizeof(int8_t)); + printf("%zu\n", sizeof(int16_t)); + printf("%zu\n", sizeof(int32_t)); + printf("%zu\n", sizeof(int64_t)); + + printf("%zu\n", sizeof(int_fast8_t)); + //printf("%zu\n", sizeof(int_fast16_t)); // Different value on Win and non-Win platforms. + printf("%zu\n", sizeof(int_fast32_t)); + printf("%zu\n", sizeof(int_fast64_t)); + + printf("%zu\n", sizeof(int_least8_t)); + printf("%zu\n", sizeof(int_least16_t)); + printf("%zu\n", sizeof(int_least32_t)); + printf("%zu\n", sizeof(int_least64_t)); + + printf("%zu\n", sizeof(uint8_t)); + printf("%zu\n", sizeof(uint16_t)); + printf("%zu\n", sizeof(uint32_t)); + printf("%zu\n", sizeof(uint64_t)); + + printf("%zu\n", sizeof(uint_fast8_t)); + // printf("%zu\n", sizeof(uint_fast16_t)); // Different value on Win and non-Win platforms. + printf("%zu\n", sizeof(uint_fast32_t)); + printf("%zu\n", sizeof(uint_fast64_t)); + + printf("%zu\n", sizeof(uint_least8_t)); + printf("%zu\n", sizeof(uint_least16_t)); + printf("%zu\n", sizeof(uint_least32_t)); + printf("%zu\n", sizeof(uint_least64_t)); + + printf("%zu\n", sizeof(intmax_t)); + printf("%zu\n", sizeof(uintmax_t)); + return 42; +} diff --git a/Cesium.Runtime.Tests/StdIoFunctionTests.cs b/Cesium.Runtime.Tests/StdIoFunctionTests.cs index 82f90c7a..460bec8a 100644 --- a/Cesium.Runtime.Tests/StdIoFunctionTests.cs +++ b/Cesium.Runtime.Tests/StdIoFunctionTests.cs @@ -17,6 +17,7 @@ public void FPrintFHex(long input, string expectedResult) [Theory] [InlineData(-1L, "%li", 2, "-1")] [InlineData(-1L, "%lu", 20, "18446744073709551615")] + [InlineData(-1L, "%zu", 20, "18446744073709551615")] public void FPrintFLong(long input, string format, int expectedExitCode, string expectedResult) { var (exitCode, result) = TestFPrintF(format, input); diff --git a/Cesium.Runtime/StdIoFunctions.cs b/Cesium.Runtime/StdIoFunctions.cs index 9f7ac05d..3267c19b 100644 --- a/Cesium.Runtime/StdIoFunctions.cs +++ b/Cesium.Runtime/StdIoFunctions.cs @@ -231,7 +231,7 @@ public static int FPrintF(void* stream, byte* str, void* varargs) } string formatSpecifier = formatString[formatStartPosition + addition].ToString(); - if (formatString[formatStartPosition + addition] == 'l') + if (formatString[formatStartPosition + addition] == 'l' || formatString[formatStartPosition + addition] == 'z') { addition++; formatSpecifier += formatString[formatStartPosition + addition].ToString(); @@ -349,7 +349,8 @@ public static int FPrintF(void* stream, byte* str, void* varargs) break; } case "lu": - { + case "zu": + { ulong ulongValue = (ulong)((long*)varargs)[consumedArgs]; var ulongValueString = ulongValue.ToString(); streamWriter.Write(ulongValueString);