Skip to content

Commit

Permalink
Add more stdint types
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 committed Sep 20, 2024
1 parent eec3a19 commit 3139999
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cesium.Compiler/stdlib/inttypes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

//#include <stdint.h>
#include <stdint.h>
#define PRId8 "hhd"
#define PRId16 "hd"
#define PRId32 "d"
Expand Down
2 changes: 2 additions & 0 deletions Cesium.Compiler/stdlib/stddef.h
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
31 changes: 31 additions & 0 deletions Cesium.Compiler/stdlib/stdint.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <stddef.h>

#define INT8_MIN (-127i8 - 1)
#define INT16_MIN (-32767i16 - 1)
Expand Down Expand Up @@ -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 int int_fast16_t;
typedef int int_fast32_t;
typedef long long int_fast64_t;
typedef unsigned char uint_fast8_t;
typedef unsigned int 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;
39 changes: 39 additions & 0 deletions Cesium.IntegrationTests/stdlib/types/integer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <stdint.h>
#include <stdio.h>

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));
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;
}
1 change: 1 addition & 0 deletions Cesium.Runtime.Tests/StdIoFunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions Cesium.Runtime/StdIoFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3139999

Please sign in to comment.