hydroforth/include/hydroforth/interpreter.h
Dominic Grimm 7490439223
All checks were successful
continuous-integration/drone/push Build is passing
Add error call stack if call stack exceeds maximum capacity
2023-08-05 20:19:52 +02:00

53 lines
1.2 KiB
C

#ifndef __HF__INTERPRETER_H__
#define __HF__INTERPRETER_H__
#include <stdbool.h>
#include <stddef.h>
#include "hashmap.h"
#include "parser.h"
#include "result.h"
#define HF__INTERPRETER__WORDS_CAP 23
struct hf__interpreter__word {
struct hf__node *body;
size_t body_len;
};
extern const hf__hashmap__free_value_t hf__interpreter__word_free;
#define HF__INTERPRETER__CALL_STACK_CAP_MAX 1024
struct hf__interpreter {
struct hf__node *call_stack;
size_t call_stack_len;
size_t call_stack_cap;
size_t call_stack_cap_max;
struct hf__hashmap words; // struct hf__interpreter__word *
long *stack;
size_t stack_len;
size_t stack_size;
bool is_running;
int exit_code;
};
extern void hf__interpreter__free(struct hf__interpreter *interpreter);
typedef struct hf__result (*hf__interpreter__word_func_t)(
struct hf__interpreter *const, const struct hf__node *const);
extern const hf__interpreter__word_func_t
HF__INTERPRETER__WORD_FUNCTION[__HF__NODE_TYPE__N];
extern void hf__interpreter__stack_push(long **arr, size_t *const len,
size_t *const cap, long item);
extern struct hf__result
hf__interpreter__run(struct hf__interpreter *const interpreter);
#endif