2024-10-01 10:53:26 +02:00
|
|
|
#ifndef FLUP_INTERPRETER_H
|
|
|
|
#define FLUP_INTERPRETER_H
|
|
|
|
|
2024-10-01 11:07:46 +02:00
|
|
|
#include "../submodules/utilitiec/src/dynamicarray/dynamicarray.h"
|
2024-10-01 21:37:26 +02:00
|
|
|
#include "../submodules/utilitiec/src/Scratchpad/Scratchpad.h"
|
2024-10-01 10:53:26 +02:00
|
|
|
|
|
|
|
#include "tokenizer.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
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;
|
2024-10-01 21:37:26 +02:00
|
|
|
StringView name;
|
|
|
|
struct ParameterDefinition_s* next;
|
2024-10-01 10:53:26 +02:00
|
|
|
} ParameterDefinition;
|
|
|
|
|
|
|
|
typedef struct FlupFunction_s {
|
|
|
|
StringView name;
|
2024-10-01 21:37:26 +02:00
|
|
|
ParameterDefinition* parameters;
|
2024-10-01 10:53:26 +02:00
|
|
|
StringView return_type;
|
|
|
|
FlupFunctionAlternative* alternative;
|
|
|
|
} FlupFunction;
|
|
|
|
|
|
|
|
enum ValueType {
|
|
|
|
VALUETYPE_INT64,
|
|
|
|
VALUETYPE_DOUBLE
|
|
|
|
};
|
|
|
|
|
|
|
|
union ValueContent {
|
|
|
|
int64_t i64;
|
|
|
|
double f64;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct Value_s {
|
|
|
|
enum ValueType type;
|
|
|
|
union ValueContent get;
|
|
|
|
} Value;
|
|
|
|
|
|
|
|
typedef struct CallFrame_s {
|
|
|
|
size_t instruction_pointer;
|
2024-10-01 21:37:26 +02:00
|
|
|
/* ip = condition start : start
|
|
|
|
* ip = condition_end + 1 : done
|
|
|
|
*
|
|
|
|
*/
|
2024-10-01 10:53:26 +02:00
|
|
|
FlupFunctionAlternative* function;
|
|
|
|
DynamicArray stack; // Value
|
2024-10-01 21:37:26 +02:00
|
|
|
Scratchpad memory_pad;
|
2024-10-01 10:53:26 +02:00
|
|
|
} 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
|