Tokenizing and printing
This commit is contained in:
parent
371eca6269
commit
b5912b95f7
5 changed files with 259 additions and 1 deletions
59
src/interpreter.h
Normal file
59
src/interpreter.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
#ifndef FLUP_INTERPRETER_H
|
||||
#define FLUP_INTERPRETER_H
|
||||
|
||||
#include "../include/utilitiec/dynamicarray/dynamicarray.h"
|
||||
|
||||
#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
|
Loading…
Add table
Add a link
Reference in a new issue