#ifndef TYPES_H #define TYPES_H #include #include #include #include #include typedef enum GroundInstType { IF, JUMP, END, INPUT, PRINT, PRINTLN, SET, GETTYPE, EXISTS, SETLIST, SETLISTAT, GETLISTAT, GETLISTSIZE, LISTAPPEND, GETSTRSIZE, GETSTRCHARAT, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, NOT, GREATER, LESSER, STOI, STOD, TOSTRING, FUN, RETURN, ENDFUN, PUSHARG, CALL, STRUCT, ENDSTRUCT, INIT, USE, EXTERN, CREATELABEL } GroundInstType; typedef enum GroundValueType { INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, CUSTOM, NONE } GroundValueType; typedef enum GroundArgType { VALUE, VALREF, DIRREF, LINEREF, LABEL, FNREF, TYPEREF } GroundArgType; typedef enum ListAccessStatus { LIST_OKAY, LIST_OUT_OF_BOUNDS, LIST_FIXME } ListAccessStatus; struct GroundValue; struct GroundFunction; struct List; /* * Custom data type that stores Ground values. * Associated functions: * createList(), appendToList(), getListAt(), setListAt() */ typedef struct List { size_t size; struct GroundValue* values; } List; /* * Stores literal values created in a Ground program. * Associated functions: * createIntGroundValue(), createDoubleGroundValue(), createStringGroundvalue(), * createCharGroundValue(), createBoolGroundValue(), freeGroundValue() */ typedef struct GroundValue { GroundValueType type; union { int64_t intVal; double doubleVal; char* stringVal; char charVal; bool boolVal; List listVal; struct GroundFunction* fnVal; void* customVal; } data; } GroundValue; /* * Indicates status when accessing a list. * Associated functions: * getListAt() */ typedef struct ListAccess { ListAccessStatus status; GroundValue* value; } ListAccess; /* * Stores arguments for the GroundInstruction struct. * Associated functions: * createValueGroundArg(), createRefGroundArg(), freeGroundArg() */ typedef struct GroundArg { GroundArgType type; union { GroundValue value; char* refName; } value; } GroundArg; /* * Represents a Ground instruction. * Associated functions: * createGroundInstruction(), freeGroundInstruction(), addArgToInstruction() */ typedef struct GroundInstruction { GroundInstType type; struct { GroundArg* args; size_t length; } args; } GroundInstruction; /* * Represents a Ground program or function. */ typedef struct GroundProgram { GroundInstruction* instructions; size_t size; } GroundProgram; /* * Represents the argument typing for a GroundFunction. */ typedef struct GroundFunctionArgs { GroundValueType type; char* name; } GroundFunctionArgs; /* * Represents a Ground function. */ typedef struct GroundFunction { GroundFunctionArgs* args; size_t argSize; GroundValueType returnType; GroundProgram program; } GroundFunction; // Creates a GroundValue containing (in), with type INT. GroundValue createIntGroundValue(int64_t in); // Creates a GroundValue containing (in), with type DOUBLE. GroundValue createDoubleGroundValue(double in); // Creates a GroundValue containing (in), with type STRING. GroundValue createStringGroundValue(const char* in); // Creates a GroundValue containing (in), with type CHAR. GroundValue createCharGroundValue(char in); // Creates a GroundValue containing (in), with type BOOl. GroundValue createBoolGroundValue(bool in); // Creates a GroundValue containing (in), with type LIST. GroundValue createListGroundValue(List in); // Creates a GroundValue conatining (in), with type FUNCTION. GroundValue createFunctionGroundValue(GroundFunction* in); // Creates a deep copy of a GroundValue GroundValue copyGroundValue(const GroundValue* gv); // If (gv) contains any data stored on the heap, frees it. void freeGroundValue(GroundValue* gv); // Prints out a GroundValue. void printGroundValue(GroundValue* gv); // Initializes a GroundArg with type VALUE GroundArg createValueGroundArg(GroundValue value); // Initializes a GroundArg with type (type), and refname (refname). GroundArg createRefGroundArg(GroundArgType type, const char* refname); // Frees all data stored on the heap in a GroundArg. void freeGroundArg(GroundArg* ga); // Prints out a GroundArg. void printGroundArg(GroundArg* ga); // Initializes a GroundInstruction, with inst type (type). GroundInstruction createGroundInstruction(GroundInstType type); // Frees all data stored on the heap in a GroundInstruction. void freeGroundInstruction(GroundInstruction* gi); // Creates a deep copy of a GroundInstruction. GroundInstruction copyGroundInstruction(const GroundInstruction* gi); // Adds arg (arg) to the GroundInstruction (gi). void addArgToInstruction(GroundInstruction* gi, GroundArg arg); // Prints out a GroundInstruction. void printGroundInstruction(GroundInstruction* gi); // Creates a Ground list List createList(); // Add item (value) to List (list) void appendToList(List* list, GroundValue value); // Gets item at index (idx) from list (list). If there is an error, it // will be indicated in the status field. ListAccess getListAt(List* list, int idx); // Sets an item in list (list) at index (idx) to GroundValue (value). ListAccessStatus setListAt(List* list, int idx, GroundValue value); #endif