Refactor fn arg checking
This commit is contained in:
40
src/types.c
40
src/types.c
@@ -582,3 +582,43 @@ GroundError createGroundError(char* what, char* type, GroundInstruction* where,
|
||||
|
||||
return ge;
|
||||
}
|
||||
|
||||
bool checkFnTypes(GroundValue* left, GroundFunctionArgs* right) {
|
||||
if (left->type != right->type) {
|
||||
return false;
|
||||
}
|
||||
if (left->type == CUSTOM) {
|
||||
if (left->customType->size != right->customType->size) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < left->customType->size; i++) {
|
||||
if (strcmp(left->customType->fields[i].id, right->customType->fields[i].id) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (!checkTypes(&left->customType->fields[i].value, &right->customType->fields[i].value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkTypes(GroundValue* left, GroundValue* right) {
|
||||
if (left->type != right->type) {
|
||||
return false;
|
||||
}
|
||||
if (left->type == CUSTOM) {
|
||||
if (left->customType->size != right->customType->size) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < left->customType->size; i++) {
|
||||
if (strcmp(left->customType->fields[i].id, right->customType->fields[i].id) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (!checkTypes(&left->customType->fields[i].value, &right->customType->fields[i].value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user