Start work on error handling

This commit is contained in:
2026-01-18 20:49:50 +11:00
parent 549eaedc04
commit 72162a7410
4 changed files with 106 additions and 1 deletions

View File

@@ -13,7 +13,7 @@ typedef enum GroundInstType {
} GroundInstType;
typedef enum GroundValueType {
INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, STRUCTVAL, CUSTOM, NONE
INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, STRUCTVAL, CUSTOM, ERROR, NONE
} GroundValueType;
typedef enum GroundArgType {
@@ -29,6 +29,7 @@ struct GroundFunction;
struct GroundScope;
struct GroundStruct;
struct GroundObject;
struct GroundInstruction;
struct List;
@@ -42,6 +43,16 @@ typedef struct List {
struct GroundValue* values;
} List;
/*
* Stores data associated with an error thrown during Ground execution.
*/
typedef struct GroundError {
char* what;
char* type;
struct GroundInstruction* where;
size_t line;
} GroundError;
/*
* Stores literal values created in a Ground program.
* Associated functions:
@@ -57,6 +68,7 @@ typedef struct GroundValue {
char charVal;
bool boolVal;
List listVal;
GroundError errorVal;
struct GroundFunction* fnVal;
struct GroundStruct* structVal;
struct GroundObject* customVal;
@@ -187,6 +199,9 @@ GroundValue createListGroundValue(List in);
// Creates a GroundValue conatining (in), with type FUNCTION.
GroundValue createFunctionGroundValue(GroundFunction* in);
// Creates a GroundValue containing (in), with type ERROR.
GroundValue createErrorGroundValue(GroundError in);
// Creates a Groundvalue with type NONE.
GroundValue createNoneGroundValue();
@@ -257,4 +272,9 @@ GroundObjectField* findField(GroundObject head, const char *id);
// Frees a GroundObject
void freeGroundObject(GroundObject* object);
// Creates a GroundError.
GroundError createGroundError(char* what, char* type, GroundInstruction* where, size_t* line);
#endif