diff --git a/Cesium.CodeGen/Ir/Expressions/Constants/IntegerConstant.cs b/Cesium.CodeGen/Ir/Expressions/Constants/IntegerConstant.cs index 0d8df579..b56b941a 100644 --- a/Cesium.CodeGen/Ir/Expressions/Constants/IntegerConstant.cs +++ b/Cesium.CodeGen/Ir/Expressions/Constants/IntegerConstant.cs @@ -83,6 +83,54 @@ private static bool TryParse(string text, out long value) textSpan = textSpan[..^1]; } + if (textSpan.EndsWith("i64", StringComparison.InvariantCultureIgnoreCase)) + { + i64Parse = true; + textSpan = textSpan[..^3]; + } + + if (textSpan.EndsWith("i32", StringComparison.InvariantCultureIgnoreCase)) + { + i64Parse = true; + textSpan = textSpan[..^3]; + } + + if (textSpan.EndsWith("i16", StringComparison.InvariantCultureIgnoreCase)) + { + i64Parse = true; + textSpan = textSpan[..^3]; + } + + if (textSpan.EndsWith("i8", StringComparison.InvariantCultureIgnoreCase)) + { + i64Parse = true; + textSpan = textSpan[..^2]; + } + + if (textSpan.EndsWith("ui64", StringComparison.InvariantCultureIgnoreCase)) + { + i64Parse = true; + textSpan = textSpan[..^4]; + } + + if (textSpan.EndsWith("ui32", StringComparison.InvariantCultureIgnoreCase)) + { + i64Parse = true; + textSpan = textSpan[..^4]; + } + + if (textSpan.EndsWith("ui16", StringComparison.InvariantCultureIgnoreCase)) + { + i64Parse = true; + textSpan = textSpan[..^4]; + } + + if (textSpan.EndsWith("ui8", StringComparison.InvariantCultureIgnoreCase)) + { + i64Parse = true; + textSpan = textSpan[..^3]; + } + if (textSpan.EndsWith("u", StringComparison.InvariantCultureIgnoreCase)) { unsignedParse = true; diff --git a/Cesium.Compiler/stdlib/limits.h b/Cesium.Compiler/stdlib/limits.h index 1d0db77e..3901f0d4 100644 --- a/Cesium.Compiler/stdlib/limits.h +++ b/Cesium.Compiler/stdlib/limits.h @@ -1,9 +1,15 @@ #pragma once #define CHAR_BIT 8 +#define CHAR_MIN (-128) +#define CHAR_MAX 127 #define SCHAR_MIN (-128) #define SCHAR_MAX 127 #define UCHAR_MAX 0xff +#define CHAR_MIN SCHAR_MIN +#define CHAR_MAX SCHAR_MAX + +#define MB_LEN_MAX 5 #define SHRT_MIN (-32768) #define SHRT_MAX 32767 #define USHRT_MAX 0xffff diff --git a/Cesium.Compiler/stdlib/stdint.h b/Cesium.Compiler/stdlib/stdint.h index 85d9ff03..33c11259 100644 --- a/Cesium.Compiler/stdlib/stdint.h +++ b/Cesium.Compiler/stdlib/stdint.h @@ -40,6 +40,24 @@ #define UINT_FAST32_MAX UINT32_MAX #define UINT_FAST64_MAX UINT64_MAX +#define INTPTR_MIN INT64_MIN +#define INTPTR_MAX INT64_MAX +#define UINTPTR_MAX UINT64_MAX + +#define PTRDIFF_MIN INTPTR_MIN +#define PTRDIFF_MAX INTPTR_MAX + +#define SIZE_MAX 0xffffffffffffffffui64 + +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX + +#define WCHAR_MIN 0x0000 +#define WCHAR_MAX 0xffff + +#define WINT_MIN 0x0000 +#define WINT_MAX 0xffff + typedef signed char int8_t; typedef short int16_t; typedef int int32_t; diff --git a/Cesium.IntegrationTests/stdlib/types/limits.c b/Cesium.IntegrationTests/stdlib/types/limits.c new file mode 100644 index 00000000..4bfedbea --- /dev/null +++ b/Cesium.IntegrationTests/stdlib/types/limits.c @@ -0,0 +1,46 @@ +#include +#include +#include + +int main(int argc, char* argv[]) +{ + printf("CHAR_BIT = %d\n", CHAR_BIT); + // GCC use different value then MSVC + //printf("MB_LEN_MAX = %d\n\n", MB_LEN_MAX); + + printf("CHAR_MIN = %+d\n", CHAR_MIN); + printf("CHAR_MAX = %+d\n", CHAR_MAX); + printf("SCHAR_MIN = %+d\n", SCHAR_MIN); + printf("SCHAR_MAX = %+d\n", SCHAR_MAX); + printf("UCHAR_MAX = %u\n\n", UCHAR_MAX); + + printf("SHRT_MIN = %+d\n", SHRT_MIN); + printf("SHRT_MAX = %+d\n", SHRT_MAX); + printf("USHRT_MAX = %u\n\n", USHRT_MAX); + + printf("INT_MIN = %+d\n", INT_MIN); + printf("INT_MAX = %+d\n", INT_MAX); + printf("UINT_MAX = %u\n\n", UINT_MAX); + + // We cannot test this across all platforms. + //printf("LONG_MIN = %+ld\n", LONG_MIN); + //printf("LONG_MAX = %+ld\n", LONG_MAX); + //printf("ULONG_MAX = %lu\n\n", ULONG_MAX); + + //printf("LLONG_MIN = %+lld\n", LLONG_MIN); + //printf("LLONG_MAX = %+lld\n", LLONG_MAX); + //printf("ULLONG_MAX = %llu\n\n", ULLONG_MAX); + + // Format t and j is not supported. + // printf("PTRDIFF_MIN = %td\n", PTRDIFF_MIN); + // printf("PTRDIFF_MAX = %+td\n", PTRDIFF_MAX); + // printf("SIZE_MAX = %zu\n", SIZE_MAX); + // printf("SIG_ATOMIC_MIN = %+jd\n", (intmax_t)SIG_ATOMIC_MIN); + // printf("SIG_ATOMIC_MAX = %+jd\n", (intmax_t)SIG_ATOMIC_MAX); + // printf("WCHAR_MIN = %+jd\n", (intmax_t)WCHAR_MIN); + // printf("WCHAR_MAX = %+jd\n", (intmax_t)WCHAR_MAX); + // printf("WINT_MIN = %jd\n", (intmax_t)WINT_MIN); + // printf("WINT_MAX = %jd\n", (intmax_t)WINT_MAX); + + return 42; +} diff --git a/Cesium.Runtime.Tests/StdIoFunctionTests.cs b/Cesium.Runtime.Tests/StdIoFunctionTests.cs index 2efd0af8..7ae1a8b0 100644 --- a/Cesium.Runtime.Tests/StdIoFunctionTests.cs +++ b/Cesium.Runtime.Tests/StdIoFunctionTests.cs @@ -21,6 +21,8 @@ public void FPrintFHex(long input, string format, string expectedResult) [Theory] [InlineData(-1L, "%li", 2, "-1")] [InlineData(-1L, "%lu", 20, "18446744073709551615")] + [InlineData(-9223372036854775808L, "%li", 20, "-9223372036854775808")] + [InlineData(2147483647L, "%ld", 10, "2147483647")] [InlineData(-1L, "%llu", 20, "18446744073709551615")] [InlineData(-1L, "%ull", 20, "18446744073709551615")] [InlineData(-1L, "%zu", 20, "18446744073709551615")] diff --git a/Directory.Packages.props b/Directory.Packages.props index 1e8bb72a..59e89746 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -17,14 +17,14 @@ - - - - - - + + + + + + - \ No newline at end of file +