#ifndef FLUP_INTERPRETER_H #define FLUP_INTERPRETER_H #include "../submodules/utilitiec/src/dynamicarray/dynamicarray.h" #include "../submodules/utilitiec/src/Scratchpad/Scratchpad.h" #include "tokenizer.h" #include typedef struct FlupFunctionAlternative_s { size_t condition_token_start; size_t condition_token_end; size_t body_token_start; size_t body_token_end; struct FlupFunctionAlternative_s* next; } FlupFunctionAlternative; typedef struct ParameterDefinition_s { StringView type; StringView name; struct ParameterDefinition_s* next; } ParameterDefinition; typedef struct FlupFunction_s { StringView name; ParameterDefinition* parameters; StringView return_type; FlupFunctionAlternative* alternatives; struct FlupFunction_s* next; } FlupFunction; enum ValueType { VALUETYPE_INT64, VALUETYPE_DOUBLE, VALUETYPE_BOOLEAN, }; union ValueContent { int64_t i64; double f64; bool boolean; }; typedef struct Value_s { enum ValueType type; union ValueContent get; } Value; typedef struct FlupVariable_s { StringView name; Value value; struct FlupVariable_s* next; } FlupVariable; typedef struct CallFrame_s { size_t instruction_pointer; /* ip = condition start : start * ip = condition_end + 1 : done * */ FlupFunction* self_function; FlupFunctionAlternative* alternative; FlupFunction* functions; // functions defined in this callframe FlupVariable* variables; // variables defined in this callframe DynamicArray stack; // Value Scratchpad memory_pad; } CallFrame; typedef struct Interpreter_s { DynamicArray* tokens; DynamicArray call_frames; // stores CallFrame } Interpreter; int Interpreter_Create(Interpreter* self, DynamicArray* tokens); int Interpreter_Interpret(Interpreter* self); void Interpreter_Destroy(Interpreter* self); #endif //header guard