flup/src/interpreter.h

79 lines
1.8 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"
#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;
StringView name;
struct ParameterDefinition_s* next;
2024-10-01 10:53:26 +02:00
} ParameterDefinition;
typedef struct FlupFunction_s {
StringView name;
ParameterDefinition* parameters;
2024-10-01 10:53:26 +02:00
StringView return_type;
2024-10-02 15:42:06 +02:00
FlupFunctionAlternative* alternatives;
struct FlupFunction_s* next;
2024-10-01 10:53:26 +02:00
} FlupFunction;
enum ValueType {
VALUETYPE_INT64,
2024-10-02 15:42:06 +02:00
VALUETYPE_DOUBLE,
VALUETYPE_BOOLEAN,
2024-10-01 10:53:26 +02:00
};
union ValueContent {
int64_t i64;
double f64;
2024-10-02 15:42:06 +02:00
bool boolean;
2024-10-01 10:53:26 +02:00
};
typedef struct Value_s {
enum ValueType type;
union ValueContent get;
} Value;
2024-10-02 15:42:06 +02:00
typedef struct FlupVariable_s {
StringView name;
Value value;
struct FlupVariable_s* next;
} FlupVariable;
2024-10-01 10:53:26 +02:00
typedef struct CallFrame_s {
size_t instruction_pointer;
/* ip = condition start : start
* ip = condition_end + 1 : done
*
*/
2024-10-02 15:42:06 +02:00
FlupFunction* self_function;
FlupFunctionAlternative* alternative;
FlupFunction* functions; // functions defined in this callframe
FlupVariable* variables; // variables defined in this callframe
2024-10-01 10:53:26 +02:00
DynamicArray stack; // Value
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