Start work on error handling
This commit is contained in:
51
src/types.c
51
src/types.c
@@ -51,6 +51,13 @@ GroundValue createFunctionGroundValue(GroundFunction* in) {
|
||||
return gv;
|
||||
}
|
||||
|
||||
GroundValue createErrorGroundValue(GroundError in) {
|
||||
GroundValue gv;
|
||||
gv.data.errorVal = in;
|
||||
gv.type = ERROR;
|
||||
return gv;
|
||||
}
|
||||
|
||||
GroundValue createNoneGroundValue() {
|
||||
GroundValue gv;
|
||||
gv.type = NONE;
|
||||
@@ -168,6 +175,18 @@ void freeGroundValue(GroundValue* gv) {
|
||||
freeGroundStruct(gstruct);
|
||||
free(gstruct);
|
||||
}
|
||||
if (gv->type == ERROR) {
|
||||
GroundError* error = &gv->data.errorVal;
|
||||
if (error->type != NULL) {
|
||||
free(error->type);
|
||||
}
|
||||
if (error->what != NULL) {
|
||||
free(error->what);
|
||||
}
|
||||
if (error->where != NULL) {
|
||||
freeGroundInstruction(error->where);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GroundArg createValueGroundArg(GroundValue value) {
|
||||
@@ -529,3 +548,35 @@ void freeGroundObject(GroundObject* object) {
|
||||
}
|
||||
object->fields = NULL;
|
||||
}
|
||||
|
||||
GroundError createGroundError(char* what, char* type, GroundInstruction* where, size_t* line) {
|
||||
GroundError ge;
|
||||
if (what != NULL) {
|
||||
ge.what = malloc(strlen(what) + 1);
|
||||
strcpy(ge.what, what);
|
||||
} else {
|
||||
ge.what = NULL;
|
||||
}
|
||||
|
||||
if (type != NULL) {
|
||||
ge.type = malloc(strlen(type) + 1);
|
||||
strcpy(ge.type, type);
|
||||
} else {
|
||||
ge.type = "GenericError";
|
||||
}
|
||||
|
||||
if (where != NULL) {
|
||||
ge.where = malloc(sizeof(GroundInstruction));
|
||||
*ge.where = copyGroundInstruction(where);
|
||||
} else {
|
||||
ge.where = NULL;
|
||||
}
|
||||
|
||||
if (line != NULL) {
|
||||
ge.line = *line;
|
||||
} else {
|
||||
ge.line = -1;
|
||||
}
|
||||
|
||||
return ge;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user