Adjusted how AST Nodes are generated

This commit is contained in:
2022-11-25 12:29:35 +00:00
parent 130ac980fe
commit 30c3a890ee
8 changed files with 491 additions and 230 deletions

View File

@@ -21,6 +21,10 @@ void setRefStringAllocatorFn(RefStringAllocatorFn allocator) {
RefString* createRefString(char* cstring) {
int length = strlen(cstring);
return createRefStringLength(cstring, length);
}
RefString* createRefStringLength(char* cstring, int length) {
//allocate the memory area (including metadata space)
RefString* refString = (RefString*)allocate(NULL, 0, sizeof(int) * 2 + sizeof(char) * length + 1);
@@ -84,3 +88,16 @@ bool equalsRefString(RefString* lhs, RefString* rhs) {
//same string
return strncmp(lhs->data, rhs->data, lhs->length) == 0;
}
bool equalsRefStringCString(RefString* lhs, char* cstring) {
//get the rhs length
int length = strlen(cstring);
//different length
if (lhs->length != length) {
return false;
}
//same string
return strncmp(lhs->data, cstring, lhs->length) == 0;
}