#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 } GroundInstType; typedef enum GroundValueType { INT, DOUBLE, STRING, CHAR, BOOL, LIST, CUSTOM } GroundValueType; typedef enum GroundArgType { VALUE, VALREF, DIRREF, LINEREF, LABEL, FNREF } GroundArgType; struct GroundValue; struct 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; struct List* listVal; void* customVal; } data; } GroundValue; /* * Currently unused. Max, implement this sometime soon. */ typedef struct List { size_t size; size_t capacity; GroundValue* values; } List; /* * 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; // 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); // If (gv) contains any data stored on the heap, frees it. void freeGroundValue(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); // 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); // Adds arg (arg) to the GroundInstruction (gi). void addArgToInstruction(GroundInstruction* gi, GroundArg arg); #endif