From 990c22d27d357f4a033a23b40d8a3484e7bcd4e8 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Mon, 10 Mar 2025 03:11:55 -0600 Subject: [PATCH] added life (entity component system) type, and changed chemical param to try to match more to archeus (or at least what I've read from wikipedia) --- CMakeLists.txt | 2 +- include/arc/std/chemical.h | 11 ++++----- src/std/chemical.c | 32 +++++++++++++++------------ tests/res/std/chemical/first.chemical | 2 ++ tests/std/chemical.c | 16 ++++++++++++++ tests/std/hashtable.c | 1 - 6 files changed, 43 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db60061..0b1f06b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,7 +128,7 @@ if(ARCHEUS_TESTS) add_executable(tests tests/test.c - tests/std/chemical.c + #tests/std/chemical.c #tests/std/hashtable.c #tests/std/lexer.c #tests/std/parser.c diff --git a/include/arc/std/chemical.h b/include/arc/std/chemical.h index 7ccab74..aafdcfb 100644 --- a/include/arc/std/chemical.h +++ b/include/arc/std/chemical.h @@ -89,11 +89,11 @@ void ARC_Chemical_SetGroupWithCStr(ARC_Chemical *chemical, const char *groupName * @note name may be prefaced with :: to specify group * * @param[in] chemical ARC_Chemical to get value from - * @param[in] element name of a variable that has been read in + * @param[in] energy name of a variable that has been read in * * @return the stored element on success, or NULL on failure */ -void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element); +void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *energy); /** * @brief get a value from a given keyname @@ -102,11 +102,11 @@ void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element); * @note this function uses ARC_Chemical_Get so it shares error messages with that function * * @param[in] chemical ARC_Chemical to get value from - * @param[in] element name of a variable that has been read in + * @param[in] energy name of a variable that has been read in * * @return the stored element on success, or NULL on failure */ -void *ARC_Chemical_GetWithCStr(ARC_Chemical *chemical, const char *element); +void *ARC_Chemical_GetWithCStr(ARC_Chemical *chemical, const char *energy); /** * @brief TODO: write this @@ -194,8 +194,9 @@ void ARC_Chemical_UnloadFromFile(ARC_Chemical *chemical, ARC_String *data); #define ARC_CHEMICAL_STRING_CHARS 0x36 #define ARC_CHEMICAL_STRING_CHAR 0x37 #define ARC_CHEMICAL_ESCAPE_CHAR 0x38 -#define ARC_CHEMICAL_WHITESPACE 0x39 +#define ARC_CHEMICAL_NUMBER_SIGN 0x39 #define ARC_CHEMICAL_NUMBER_TAG 0x3A +#define ARC_CHEMICAL_WHITESPACE 0x3B #ifdef __cplusplus } diff --git a/src/std/chemical.c b/src/std/chemical.c index 0b3a280..59f60c2 100644 --- a/src/std/chemical.c +++ b/src/std/chemical.c @@ -250,6 +250,9 @@ uint32_t ARC_Chemical_GetStringIdFn(ARC_String *string){ if(ARC_String_EqualsCStringWithStrlen(string, "")){ return ARC_CHEMICAL_ESCAPE_CHAR; } + if(ARC_String_EqualsCStringWithStrlen(string, "")){ + return ARC_CHEMICAL_NUMBER_SIGN; + } if(ARC_String_EqualsCStringWithStrlen(string, "")){ return ARC_CHEMICAL_NUMBER_TAG; } @@ -561,7 +564,7 @@ void ARC_Chemical_Create(ARC_Chemical **chemical){ " -> SPACE | TAB | LAMBDA\n" " -> \n" - " -> | | | \n" + " -> | | | \n" " -> OPEN_CURLY_BRACE CLOSE_CURLY_BRACE\n" " -> COMMA | \n" @@ -574,6 +577,7 @@ void ARC_Chemical_Create(ARC_Chemical **chemical){ " -> TAB | SPACE | BANG | HASH | DOLLAR | PERCENT | AMPERSAND | SINGLE_QUOTE | OPEN_PAREN | CLOSE_PAREN | ASTERISK | PLUS | COMMA | MINUS | PERIOD | SLASH | NUMBER | COLON | SEMICOLON | LESS_THAN | GREATER_THAN | EQUAL | QUESTION_MARK | AT | ALPHA_UPPER_CHAR | OPEN_BRACKET | CLOSE_BRACKET | CARET | UNDERSCORE | GRAVE | ALPHA_LOWER_CHAR | OPEN_CURLY_BRACE | VERTICAL_LINE | CLOSE_CURLY_BRACE | TILDE\n" " -> BACKSLASH BACKSLASH | BACKSLASH QUOTE | BACKSLASH ALPHA_UPPER_CHAR | BACKSLASH ALPHA_LOWER_CHAR\n" + " -> MINUS | \n" " -> NUMBER | NUMBER\n" " -> SPACE | TAB | NEWLINE | LAMBDA\n"; @@ -669,15 +673,15 @@ void ARC_Chemical_SetGroupWithCStr(ARC_Chemical *chemical, const char *groupName chemical->currentGroup = currentGroup; } -void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element){ +void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *energy){ //check if the group separator exists - uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(element, ARC_CHEMICAL_GROUP_SEPARATOR); + uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(energy, ARC_CHEMICAL_GROUP_SEPARATOR); if(startSeparatorIndex == ~(uint64_t)0){ //use empty group chemical->currentGroup = ARC_Hashtable_Get(chemical->groups, (void *)ARC_CHEMICAL_DEFAULT_GROUP); //get the typeData and pass back the data without the cleanup function - ARC_ChemicalTypeData *typeData = (ARC_ChemicalTypeData *)ARC_Hashtable_Get(chemical->currentGroup, (void *)element->data); + ARC_ChemicalTypeData *typeData = (ARC_ChemicalTypeData *)ARC_Hashtable_Get(chemical->currentGroup, (void *)energy->data); if(typeData == NULL){ return NULL; } @@ -688,7 +692,7 @@ void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element){ //get the group startSeparatorIndex--; ARC_String *groupString; - ARC_String_CopySubstring(&groupString, element, 0, startSeparatorIndex); + ARC_String_CopySubstring(&groupString, energy, 0, startSeparatorIndex); //set the group chemical->currentGroup = ARC_Hashtable_Get(chemical->groups, (void *)groupString->data); @@ -697,13 +701,13 @@ void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element){ ARC_String_Destroy(groupString); //get the element - ARC_String *elementString; + ARC_String *energyString; startSeparatorIndex += strlen(ARC_CHEMICAL_GROUP_SEPARATOR); - ARC_String_CopySubstring(&elementString, element, startSeparatorIndex, element->length - startSeparatorIndex); + ARC_String_CopySubstring(&energyString, energy, startSeparatorIndex, energy->length - startSeparatorIndex); //this will either return the value or NULL - ARC_ChemicalTypeData *typeData = (ARC_ChemicalTypeData *)ARC_Hashtable_Get(chemical->currentGroup, (void *)elementString->data); - ARC_String_Destroy(elementString); + ARC_ChemicalTypeData *typeData = (ARC_ChemicalTypeData *)ARC_Hashtable_Get(chemical->currentGroup, (void *)energyString->data); + ARC_String_Destroy(energyString); if(typeData == NULL){ return NULL; } @@ -711,16 +715,16 @@ void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element){ return typeData->data; } -void *ARC_Chemical_GetWithCStr(ARC_Chemical *chemical, const char *element){ +void *ARC_Chemical_GetWithCStr(ARC_Chemical *chemical, const char *energy){ //create and copy into ARC_String - ARC_String *elementString; - ARC_String_CreateWithStrlen(&elementString, (char *)element); + ARC_String *energyString; + ARC_String_CreateWithStrlen(&energyString, (char *)energy); //get the return value - void *returnValue = ARC_Chemical_Get(chemical, elementString); + void *returnValue = ARC_Chemical_Get(chemical, energyString); //cleanup - ARC_String_Destroy(elementString); + ARC_String_Destroy(energyString); return returnValue; } diff --git a/tests/res/std/chemical/first.chemical b/tests/res/std/chemical/first.chemical index 93e9209..392097c 100644 --- a/tests/res/std/chemical/first.chemical +++ b/tests/res/std/chemical/first.chemical @@ -1,3 +1,5 @@ group test { int32 test = 5; + + int32 test1 = -7; } diff --git a/tests/std/chemical.c b/tests/std/chemical.c index 32e5045..bcdc12c 100644 --- a/tests/std/chemical.c +++ b/tests/std/chemical.c @@ -8,8 +8,22 @@ static const char *testType = "int32"; void TEST_ChemicalType_CopyInt32Fn(void **type, ARC_ParserTagToken *parsedData, ARC_Chemical *chemical){ + //go into the tag + ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0); + if(childTagToken->id != ARC_CHEMICAL_NUMBER_SIGN){ + arc_errno = ARC_ERRNO_DATA; + ARC_DEBUG_LOG_ERROR("TEST_ChemicalType_CopyInt32Fn(type, parsedData, chemical), parsed data was not a "); + *type = NULL; + return; + } + + //check if the first tag is a minus sign and create a string starting with that if it is + childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 0); ARC_String *int32String; ARC_String_Create(&int32String, NULL, 0); + if(childTagToken->id == ARC_CHEMICAL_MINUS){ + ARC_String_AppendCStringWithStrlen(&int32String, "-"); + } ARC_ParserData_HelperRecurseStringAdd(&int32String, parsedData); @@ -80,6 +94,8 @@ ARC_TEST(Chemical_BasicTest){ int32_t testVal = *(int32_t *)ARC_Chemical_GetWithCStr(chemical, "test::test"); ARC_CHECK(testVal == 5); + testVal = *(int32_t *)ARC_Chemical_GetWithCStr(chemical, "test::test1"); + ARC_CHECK(testVal == -7); ARC_Chemical_UnloadFromFile(chemical, tempString); diff --git a/tests/std/hashtable.c b/tests/std/hashtable.c index 8a24890..2d1956b 100644 --- a/tests/std/hashtable.c +++ b/tests/std/hashtable.c @@ -83,7 +83,6 @@ ARC_TEST(Hashtable_Add_Get_Remove){ ARC_CHECK(5 == *(int32_t *)ARC_Hashtable_Get(hashtable, (void *)"key7")); ARC_CHECK(6 == *(int32_t *)ARC_Hashtable_Get(hashtable, (void *)"key8")); - TEST_Hashtable_Print(hashtable); ARC_Hashtable_Remove(hashtable, (void *)"key2"); ARC_CHECK(2 == *(int32_t *)ARC_Hashtable_Get(hashtable, (void *)"key0"));