flup/src/interpreter.h

60 lines
1.3 KiB
C
Raw Normal View History

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 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 name;
StringView type;
} ParameterDefinition;
typedef struct FlupFunction_s {
StringView name;
DynamicArray argument_defs; // ParameterDefinition
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;
FlupFunctionAlternative* function;
DynamicArray stack; // Value
} 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