cleanup and implementation of builtin functions
This commit is contained in:
parent
78bb3321d8
commit
06f385d6b0
11 changed files with 621 additions and 302 deletions
|
@ -5,74 +5,24 @@
|
|||
#include "../submodules/utilitiec/src/Scratchpad/Scratchpad.h"
|
||||
|
||||
#include "tokenizer.h"
|
||||
#include "callframe.h"
|
||||
#include "value.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 Interpreter_s Interpreter;
|
||||
|
||||
typedef struct ParameterDefinition_s {
|
||||
StringView type;
|
||||
StringView name;
|
||||
struct ParameterDefinition_s* next;
|
||||
} ParameterDefinition;
|
||||
typedef int (*BuiltinFunction)(CallFrame *);
|
||||
|
||||
typedef struct FlupFunction_s {
|
||||
StringView name;
|
||||
ParameterDefinition* parameters;
|
||||
StringView return_type;
|
||||
FlupFunctionAlternative* alternatives;
|
||||
struct FlupFunction_s* next;
|
||||
} FlupFunction;
|
||||
struct Interpreter_s {
|
||||
const char** builtin_names;
|
||||
const BuiltinFunction* builtin_functions;
|
||||
|
||||
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
|
||||
#endif //FLUP_INTERPRETER_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue