#pragma once #include "ast.h" #include #include #define VARIABLES_MAX 64 #define FUNCTIONS_MAX 32 // the longest thing a single type can say when emitted #define TEXT_LENGTH_MAX 255 enum TypeKind { KIND_VOID, KIND_INT32, KIND_BYTE, KIND_SIZE, KIND_ARRAY, KIND_CHAR, KIND_CHAR_CONSTANT, KIND_TUPLE, KIND_VALUE }; struct Type { enum TypeKind kind; int64_t number; char text[TEXT_LENGTH_MAX + 1]; }; struct Variable { char name[NAME_LENGTH_MAX + 1]; int64_t value; bool declared; }; struct Function { char name[NAME_LENGTH_MAX + 1]; const struct Node* node; bool defined; }; struct Machine { struct Variable variables[VARIABLES_MAX]; struct Function functions[FUNCTIONS_MAX]; struct Type returned; int depth; }; enum RunStatus { RUN_DONE, RUN_FAILED, RUN_RETURNED }; void machine_init(struct Machine* machine); enum RunStatus execute(struct Machine* machine, const struct Node* statement);