mirror of
https://git.telodendria.io/Telodendria/Cytoplasm.git
synced 2025-04-25 10:26:03 +00:00
Make all timestamps use UInt64.
This commit is contained in:
parent
e9af54e4c7
commit
2c715c6e72
14 changed files with 265 additions and 181 deletions
|
@ -3,7 +3,8 @@
|
|||
#include <Log.h>
|
||||
|
||||
/* AssertEquals(actual, expected) */
|
||||
int AssertEquals(char *msg, Int64 x, Int64 y)
|
||||
int
|
||||
AssertEquals(char *msg, Int64 x, Int64 y)
|
||||
{
|
||||
if (!Int64Eq(x, y))
|
||||
{
|
||||
|
@ -17,9 +18,10 @@ int AssertEquals(char *msg, Int64 x, Int64 y)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int Main(void)
|
||||
int
|
||||
Main(void)
|
||||
{
|
||||
Int64 x, y;
|
||||
Int64 x, y;
|
||||
|
||||
Log(LOG_INFO, "sizeof(Int64) = %lu", sizeof(Int64));
|
||||
|
||||
|
@ -31,9 +33,9 @@ int Main(void)
|
|||
|
||||
/* BSR Tests */
|
||||
|
||||
x = Int64Create(0x000000FF, 0x00000000);
|
||||
x = Int64Create(0x000000FF, 0x00000000);
|
||||
|
||||
y = Int64Sra(x, 4);
|
||||
y = Int64Sra(x, 4);
|
||||
AssertEquals("x >> 4", y, Int64Create(0x0000000F, 0xF0000000));
|
||||
|
||||
y = Int64Sra(x, 8);
|
||||
|
@ -42,15 +44,15 @@ int Main(void)
|
|||
y = Int64Sra(x, 36);
|
||||
AssertEquals("x >> 36", y, Int64Create(0x00000000, 0x0000000F));
|
||||
|
||||
x = Int64Create(0xFF000000, 0x00000000);
|
||||
x = Int64Create(0xFF000000, 0x00000000);
|
||||
|
||||
y = Int64Sra(x, 4);
|
||||
y = Int64Sra(x, 4);
|
||||
AssertEquals("x >> 4", y, Int64Create(0xFFF00000, 0x00000000));
|
||||
|
||||
y = Int64Sra(x, 8);
|
||||
y = Int64Sra(x, 8);
|
||||
AssertEquals("x >> 8", y, Int64Create(0xFFFF0000, 0x00000000));
|
||||
|
||||
y = Int64Sra(x, 63);
|
||||
y = Int64Sra(x, 63);
|
||||
AssertEquals("x >> 63", y, Int64Create(0xFFFFFFFF, 0xFFFFFFFF));
|
||||
|
||||
/* BSL Tests */
|
||||
|
@ -76,9 +78,9 @@ int Main(void)
|
|||
y = Int64Create(0x00000000, 0x10000000);
|
||||
AssertEquals("0xF0000000 + 0x10000000", Int64Add(x, y), Int64Create(0x00000001, 0x00000000));
|
||||
|
||||
x = Int64Create(0, 5);
|
||||
y = Int64Neg(Int64Create(0, 10));
|
||||
AssertEquals("5 + (-10)", Int64Add(x, y), Int64Neg(Int64Create(0, 5)));
|
||||
x = Int64Create(0, 5);
|
||||
y = Int64Neg(Int64Create(0, 10));
|
||||
AssertEquals("5 + (-10)", Int64Add(x, y), Int64Neg(Int64Create(0, 5)));
|
||||
|
||||
/* SUB Tests */
|
||||
x = Int64Create(0x00000000, 0x00000005);
|
||||
|
@ -89,13 +91,13 @@ int Main(void)
|
|||
y = Int64Create(0x00000000, 0x00000001);
|
||||
AssertEquals("0x00000001 0x00000000 - 0x00000001", Int64Sub(x, y), Int64Create(0x00000000, 0xFFFFFFFF));
|
||||
|
||||
x = Int64Create(0, 5);
|
||||
y = Int64Create(0, 10);
|
||||
AssertEquals("5 - 10", Int64Sub(x, y), Int64Neg(Int64Create(0, 5)));
|
||||
x = Int64Create(0, 5);
|
||||
y = Int64Create(0, 10);
|
||||
AssertEquals("5 - 10", Int64Sub(x, y), Int64Neg(Int64Create(0, 5)));
|
||||
|
||||
x = Int64Create(0, 5);
|
||||
y = Int64Neg(Int64Create(0, 10));
|
||||
AssertEquals("5 - (-10)", Int64Sub(x, y), Int64Create(0, 15));
|
||||
x = Int64Create(0, 5);
|
||||
y = Int64Neg(Int64Create(0, 10));
|
||||
AssertEquals("5 - (-10)", Int64Sub(x, y), Int64Create(0, 15));
|
||||
|
||||
/* MUL Tests */
|
||||
x = Int64Create(0, 18);
|
||||
|
@ -136,7 +138,8 @@ int Main(void)
|
|||
y = Int64Create(0x00000000, 0x00000010);
|
||||
AssertEquals("0x00000000 0x000000F0 mod 0x00000010", Int64Rem(x, y), Int64Create(0, 0));
|
||||
|
||||
/* TODO: Add more tests for negative multiplication, division, and mod */
|
||||
/* TODO: Add more tests for negative multiplication, division, and
|
||||
* mod */
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
31
tools/j2s.c
31
tools/j2s.c
|
@ -40,7 +40,8 @@
|
|||
static char *
|
||||
Trim(char c, char *str)
|
||||
{
|
||||
while (*str == c) str++;
|
||||
while (*str == c)
|
||||
str++;
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -89,7 +90,7 @@ JsonTypeToStr(JsonType type)
|
|||
{
|
||||
switch (type)
|
||||
{
|
||||
case JSON_OBJECT:
|
||||
case JSON_OBJECT:
|
||||
return "JSON_OBJECT";
|
||||
case JSON_ARRAY:
|
||||
return "JSON_ARRAY";
|
||||
|
@ -355,6 +356,7 @@ Main(Array * args)
|
|||
!StrEquals(fieldType, "boolean"))
|
||||
{
|
||||
Node *node = HashMapGet(typeToNode, fieldType);
|
||||
|
||||
if (!node)
|
||||
{
|
||||
node = Malloc(sizeof(Node));
|
||||
|
@ -603,11 +605,11 @@ Main(Array * args)
|
|||
StreamPrintf(implFile, " (void) enumParseRes;\n");
|
||||
StreamPrintf(implFile, "\n");
|
||||
StreamPrintf(implFile, " if (!json | !out)\n"
|
||||
" {\n"
|
||||
" *errp = \"Invalid pointers passed to %sFromJson()\";\n"
|
||||
" return 0;\n"
|
||||
" }\n\n"
|
||||
, type);
|
||||
" {\n"
|
||||
" *errp = \"Invalid pointers passed to %sFromJson()\";\n"
|
||||
" return 0;\n"
|
||||
" }\n\n"
|
||||
,type);
|
||||
for (i = 0; i < ArraySize(keys); i++)
|
||||
{
|
||||
char *key = ArrayGet(keys, i);
|
||||
|
@ -777,7 +779,7 @@ Main(Array * args)
|
|||
case JSON_INTEGER:
|
||||
func = "Integer";
|
||||
break;
|
||||
case JSON_FLOAT:
|
||||
case JSON_FLOAT:
|
||||
func = "Float";
|
||||
break;
|
||||
case JSON_BOOLEAN:
|
||||
|
@ -875,8 +877,8 @@ Main(Array * args)
|
|||
fieldType[strlen(fieldType) - 1] = '\0';
|
||||
isEnum = StrEquals(JsonValueAsString(JsonGet(types, 2, fieldType, "type")), "enum");
|
||||
isPrimitive = StrEquals(fieldType, "integer") ||
|
||||
StrEquals(fieldType, "boolean") ||
|
||||
StrEquals(fieldType, "float");
|
||||
StrEquals(fieldType, "boolean") ||
|
||||
StrEquals(fieldType, "float");
|
||||
|
||||
|
||||
StreamPrintf(implFile, " if (val->%s)\n", key);
|
||||
|
@ -996,9 +998,9 @@ Main(Array * args)
|
|||
fieldType[strlen(fieldType) - 1] = '\0';
|
||||
isEnum = StrEquals(JsonValueAsString(JsonGet(types, 2, fieldType, "type")), "enum");
|
||||
isPrimitive = StrEquals(fieldType, "boolean") ||
|
||||
StrEquals(fieldType, "float") ||
|
||||
StrEquals(fieldType, "integer") ||
|
||||
StrEquals(fieldType, "string");
|
||||
StrEquals(fieldType, "float") ||
|
||||
StrEquals(fieldType, "integer") ||
|
||||
StrEquals(fieldType, "string");
|
||||
|
||||
StreamPrintf(implFile, " if (val->%s)\n", key);
|
||||
StreamPrintf(implFile, " {\n");
|
||||
|
@ -1014,7 +1016,8 @@ Main(Array * args)
|
|||
}
|
||||
else
|
||||
{
|
||||
/* Ignore primitives but call the appropriate free method on declared types */
|
||||
/* Ignore primitives but call the appropriate free
|
||||
* method on declared types */
|
||||
if (!isEnum && HashMapGet(types, fieldType))
|
||||
{
|
||||
StreamPrintf(implFile, " %sFree(&val->%s);\n", fieldType, key);
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
#include <Log.h>
|
||||
|
||||
/* AssertEquals(actual, expected) */
|
||||
int AssertEquals(char *msg, UInt64 x, UInt64 y)
|
||||
int
|
||||
AssertEquals(char *msg, UInt64 x, UInt64 y)
|
||||
{
|
||||
if (!UInt64Eq(x, y))
|
||||
{
|
||||
|
@ -17,9 +18,10 @@ int AssertEquals(char *msg, UInt64 x, UInt64 y)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int Main(void)
|
||||
int
|
||||
Main(void)
|
||||
{
|
||||
UInt64 x, y;
|
||||
UInt64 x, y;
|
||||
|
||||
Log(LOG_INFO, "sizeof(UInt64) = %lu", sizeof(UInt64));
|
||||
|
||||
|
@ -31,9 +33,9 @@ int Main(void)
|
|||
|
||||
/* BSR Tests */
|
||||
|
||||
x = UInt64Create(0x000000FF, 0x00000000);
|
||||
x = UInt64Create(0x000000FF, 0x00000000);
|
||||
|
||||
y = UInt64Srl(x, 4);
|
||||
y = UInt64Srl(x, 4);
|
||||
AssertEquals("x >> 4", y, UInt64Create(0x0000000F, 0xF0000000));
|
||||
|
||||
y = UInt64Srl(x, 8);
|
||||
|
@ -113,5 +115,5 @@ int Main(void)
|
|||
y = UInt64Create(0x00000000, 0x00000010);
|
||||
AssertEquals("0x00000000 0x000000F0 mod 0x00000010", UInt64Rem(x, y), UInt64Create(0, 0));
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue