mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Tweaked AST bitness test
This commit is contained in:
@@ -88,7 +88,7 @@ typedef struct Toy_AstBlock {
|
|||||||
bool innerScope;
|
bool innerScope;
|
||||||
Toy_Ast* child; //begin encoding the line
|
Toy_Ast* child; //begin encoding the line
|
||||||
Toy_Ast* next; //'next' is either an AstBlock or null
|
Toy_Ast* next; //'next' is either an AstBlock or null
|
||||||
Toy_Ast* tail; //'tail' - either points to the tail of the current list, or null; only used by the head of a list as an optimisation
|
Toy_Ast* tail; //'tail' - either points to the tail of the current list, or null; only used as an optimisation in toy_ast.c
|
||||||
} Toy_AstBlock;
|
} Toy_AstBlock;
|
||||||
|
|
||||||
typedef struct Toy_AstValue {
|
typedef struct Toy_AstValue {
|
||||||
@@ -203,30 +203,30 @@ typedef struct Toy_AstEnd {
|
|||||||
Toy_AstType type;
|
Toy_AstType type;
|
||||||
} Toy_AstEnd;
|
} Toy_AstEnd;
|
||||||
|
|
||||||
union Toy_Ast { //32 | 64 BITNESS
|
union Toy_Ast { //see 'test_ast.c' for bitness tests
|
||||||
Toy_AstType type; //4 | 4
|
Toy_AstType type;
|
||||||
Toy_AstBlock block; //16 | 32
|
Toy_AstBlock block;
|
||||||
Toy_AstValue value; //12 | 24
|
Toy_AstValue value;
|
||||||
Toy_AstUnary unary; //12 | 16
|
Toy_AstUnary unary;
|
||||||
Toy_AstBinary binary; //16 | 24
|
Toy_AstBinary binary;
|
||||||
Toy_AstBinaryShortCircuit binaryShortCircuit; //16 | 24
|
Toy_AstBinaryShortCircuit binaryShortCircuit;
|
||||||
Toy_AstCompare compare; //16 | 24
|
Toy_AstCompare compare;
|
||||||
Toy_AstGroup group; //8 | 16
|
Toy_AstGroup group;
|
||||||
Toy_AstCompound compound; //12 | 16
|
Toy_AstCompound compound;
|
||||||
Toy_AstAggregate aggregate; //16 | 24
|
Toy_AstAggregate aggregate;
|
||||||
Toy_AstAssert assert; //16 | 24
|
Toy_AstAssert assert;
|
||||||
Toy_AstIfThenElse ifThenElse; //16 | 32
|
Toy_AstIfThenElse ifThenElse;
|
||||||
Toy_AstWhileThen whileThen; //16 | 24
|
Toy_AstWhileThen whileThen;
|
||||||
Toy_AstBreak breakPoint; //4 | 4
|
Toy_AstBreak breakPoint;
|
||||||
Toy_AstContinue continuePoint; //4 | 4
|
Toy_AstContinue continuePoint;
|
||||||
Toy_AstPrint print; //8 | 16
|
Toy_AstPrint print;
|
||||||
Toy_AstVarDeclare varDeclare; //16 | 24
|
Toy_AstVarDeclare varDeclare;
|
||||||
Toy_AstVarAssign varAssign; //16 | 24
|
Toy_AstVarAssign varAssign;
|
||||||
Toy_AstVarAccess varAccess; //8 | 16
|
Toy_AstVarAccess varAccess;
|
||||||
Toy_AstPass pass; //4 | 4
|
Toy_AstPass pass;
|
||||||
Toy_AstError error; //4 | 4
|
Toy_AstError error;
|
||||||
Toy_AstEnd end; //4 | 4
|
Toy_AstEnd end;
|
||||||
}; //16 | 32
|
};
|
||||||
|
|
||||||
void Toy_private_initAstBlock(Toy_Bucket** bucketHandle, Toy_Ast** astHandle);
|
void Toy_private_initAstBlock(Toy_Bucket** bucketHandle, Toy_Ast** astHandle);
|
||||||
void Toy_private_appendAstBlock(Toy_Bucket** bucketHandle, Toy_Ast* block, Toy_Ast* child);
|
void Toy_private_appendAstBlock(Toy_Bucket** bucketHandle, Toy_Ast* block, Toy_Ast* child);
|
||||||
|
|||||||
@@ -4,87 +4,62 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int test_sizeof_ast_64bit(void) {
|
#if TOY_BITNESS == 32
|
||||||
//NOTE: This could've covered both bitness sizes as TEST_SIZEOF(type, bit32, bit32)
|
|
||||||
#define TEST_SIZEOF(type, size) \
|
#define TEST_SIZEOF(type, bit32, bit64) \
|
||||||
if (sizeof(type) != size) { \
|
if (sizeof(type) != bit32) { \
|
||||||
fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d\n" TOY_CC_RESET, (int)sizeof(type), size); \
|
fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d (bitness %d)\n" TOY_CC_RESET, (int)sizeof(type), bit32, TOY_BITNESS); \
|
||||||
++err; \
|
++err; \
|
||||||
}
|
}
|
||||||
|
|
||||||
//count errors
|
#elif TOY_BITNESS == 64
|
||||||
|
|
||||||
|
#define TEST_SIZEOF(type, bit32, bit64) \
|
||||||
|
if (sizeof(type) != bit64) { \
|
||||||
|
fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d (bitness %d)\n" TOY_CC_RESET, (int)sizeof(type), bit64, TOY_BITNESS); \
|
||||||
|
++err; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#pragma message("Unable to test the size of Toy_Ast members, as TOY_BITNESS is not recognized")
|
||||||
|
#define TEST_SIZEOF(type, bit32, bit64)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int test_sizeof_ast(void) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
//run for each type
|
//run for each type
|
||||||
TEST_SIZEOF(Toy_AstType, 4);
|
TEST_SIZEOF(Toy_AstType, 4 , 4);
|
||||||
TEST_SIZEOF(Toy_AstBlock, 32);
|
TEST_SIZEOF(Toy_AstBlock, 20 , 32);
|
||||||
TEST_SIZEOF(Toy_AstValue, 24);
|
TEST_SIZEOF(Toy_AstValue, 12 , 24);
|
||||||
TEST_SIZEOF(Toy_AstUnary, 16);
|
TEST_SIZEOF(Toy_AstUnary, 12 , 16);
|
||||||
TEST_SIZEOF(Toy_AstBinary, 24);
|
TEST_SIZEOF(Toy_AstBinary, 16 , 24);
|
||||||
TEST_SIZEOF(Toy_AstBinaryShortCircuit, 24);
|
TEST_SIZEOF(Toy_AstBinaryShortCircuit, 16 , 24);
|
||||||
TEST_SIZEOF(Toy_AstCompare, 24);
|
TEST_SIZEOF(Toy_AstCompare, 16 , 24);
|
||||||
TEST_SIZEOF(Toy_AstGroup, 16);
|
TEST_SIZEOF(Toy_AstGroup, 8 , 16);
|
||||||
TEST_SIZEOF(Toy_AstCompound, 16);
|
TEST_SIZEOF(Toy_AstCompound, 12 , 16);
|
||||||
TEST_SIZEOF(Toy_AstAggregate, 24);
|
TEST_SIZEOF(Toy_AstAggregate, 16 , 24);
|
||||||
TEST_SIZEOF(Toy_AstAssert, 24);
|
TEST_SIZEOF(Toy_AstAssert, 12 , 24);
|
||||||
TEST_SIZEOF(Toy_AstIfThenElse, 32);
|
TEST_SIZEOF(Toy_AstIfThenElse, 16 , 32);
|
||||||
TEST_SIZEOF(Toy_AstWhileThen, 24);
|
TEST_SIZEOF(Toy_AstWhileThen, 12 , 24);
|
||||||
TEST_SIZEOF(Toy_AstBreak, 4);
|
TEST_SIZEOF(Toy_AstBreak, 4 , 4);
|
||||||
TEST_SIZEOF(Toy_AstContinue, 4);
|
TEST_SIZEOF(Toy_AstContinue, 4 , 4);
|
||||||
TEST_SIZEOF(Toy_AstPrint, 16);
|
TEST_SIZEOF(Toy_AstPrint, 8 , 16);
|
||||||
TEST_SIZEOF(Toy_AstVarDeclare, 24);
|
TEST_SIZEOF(Toy_AstVarDeclare, 12 , 24);
|
||||||
TEST_SIZEOF(Toy_AstVarAssign, 24);
|
TEST_SIZEOF(Toy_AstVarAssign, 16 , 24);
|
||||||
TEST_SIZEOF(Toy_AstVarAccess, 16);
|
TEST_SIZEOF(Toy_AstVarAccess, 8 , 16);
|
||||||
TEST_SIZEOF(Toy_AstPass, 4);
|
TEST_SIZEOF(Toy_AstPass, 4 , 4);
|
||||||
TEST_SIZEOF(Toy_AstError, 4);
|
TEST_SIZEOF(Toy_AstError, 4 , 4);
|
||||||
TEST_SIZEOF(Toy_AstEnd, 4);
|
TEST_SIZEOF(Toy_AstEnd, 4 , 4);
|
||||||
TEST_SIZEOF(Toy_Ast, 32);
|
TEST_SIZEOF(Toy_Ast, 20 , 32);
|
||||||
|
|
||||||
#undef TEST_SIZEOF
|
|
||||||
|
|
||||||
return -err;
|
return -err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_sizeof_ast_32bit(void) {
|
|
||||||
#define TEST_SIZEOF(type, size) \
|
|
||||||
if (sizeof(type) != size) { \
|
|
||||||
fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d\n" TOY_CC_RESET, (int)sizeof(type), size); \
|
|
||||||
++err; \
|
|
||||||
}
|
|
||||||
|
|
||||||
//count errors
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
//run for each type
|
|
||||||
TEST_SIZEOF(Toy_AstType, 4);
|
|
||||||
TEST_SIZEOF(Toy_AstBlock, 20);
|
|
||||||
TEST_SIZEOF(Toy_AstValue, 12);
|
|
||||||
TEST_SIZEOF(Toy_AstUnary, 12);
|
|
||||||
TEST_SIZEOF(Toy_AstBinary, 16);
|
|
||||||
TEST_SIZEOF(Toy_AstBinaryShortCircuit, 16);
|
|
||||||
TEST_SIZEOF(Toy_AstCompare, 16);
|
|
||||||
TEST_SIZEOF(Toy_AstGroup, 8);
|
|
||||||
TEST_SIZEOF(Toy_AstCompound, 12);
|
|
||||||
TEST_SIZEOF(Toy_AstAggregate, 16);
|
|
||||||
TEST_SIZEOF(Toy_AstAssert, 12);
|
|
||||||
TEST_SIZEOF(Toy_AstIfThenElse, 16);
|
|
||||||
TEST_SIZEOF(Toy_AstWhileThen, 12);
|
|
||||||
TEST_SIZEOF(Toy_AstBreak, 4);
|
|
||||||
TEST_SIZEOF(Toy_AstContinue, 4);
|
|
||||||
TEST_SIZEOF(Toy_AstPrint, 8);
|
|
||||||
TEST_SIZEOF(Toy_AstVarDeclare, 12);
|
|
||||||
TEST_SIZEOF(Toy_AstVarAssign, 16);
|
|
||||||
TEST_SIZEOF(Toy_AstVarAccess, 8);
|
|
||||||
TEST_SIZEOF(Toy_AstPass, 4);
|
|
||||||
TEST_SIZEOF(Toy_AstError, 4);
|
|
||||||
TEST_SIZEOF(Toy_AstEnd, 4);
|
|
||||||
TEST_SIZEOF(Toy_Ast, 20);
|
|
||||||
|
|
||||||
#undef TEST_SIZEOF
|
#undef TEST_SIZEOF
|
||||||
|
|
||||||
return -err;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_type_emission(Toy_Bucket** bucketHandle) {
|
int test_type_emission(Toy_Bucket** bucketHandle) {
|
||||||
//emit value
|
//emit value
|
||||||
{
|
{
|
||||||
@@ -498,21 +473,11 @@ int main(void) {
|
|||||||
int total = 0, res = 0;
|
int total = 0, res = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
#if TOY_BITNESS == 64
|
res = test_sizeof_ast();
|
||||||
res = test_sizeof_ast_64bit();
|
|
||||||
#elif TOY_BITNESS == 32
|
|
||||||
res = test_sizeof_ast_32bit();
|
|
||||||
#else
|
|
||||||
res = -1;
|
|
||||||
fprintf(stderr, TOY_CC_WARN "WARNING: Skipping test_sizeof_ast_**bit(); Can't determine the 'bitness' of this platform (seems to be %d)\n" TOY_CC_RESET, TOY_BITNESS);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
|
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
|
||||||
}
|
}
|
||||||
else if (res > 0) {
|
total += res;
|
||||||
total += res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user