c-repl/src/include/interpreter.h

34 lines
628 B
C
Raw Normal View History

2023-11-10 13:42:53 +01:00
#ifndef INTERPRETER_H
#define INTERPRETER_H
2023-11-10 17:35:33 +01:00
#include <variant>
2023-11-15 13:40:37 +01:00
#include <string>
#include <stdexcept>
2023-11-10 17:35:33 +01:00
using namespace std;
2023-11-10 13:42:53 +01:00
2023-11-15 15:42:30 +01:00
#include "tokenize.h"
using EvalResult = variant<monostate, int, double>;
struct MemoryEntry {
EvalResult value { };
bool assigned { false };
Type type;
};
2023-11-10 17:35:33 +01:00
2023-11-15 13:40:37 +01:00
class RuntimeError : public runtime_error {
public:
2023-11-15 15:42:30 +01:00
explicit RuntimeError(const string& message, CodePosition pos)
: runtime_error(message), pos(pos) {}
const CodePosition pos;
2023-11-15 13:40:37 +01:00
};
2023-11-10 17:35:33 +01:00
/*
Evaluates the AST, returning the latest calulated value
*/
EvalResult eval(Node &ast);
2023-11-10 13:42:53 +01:00
2023-11-15 16:10:36 +01:00
void _debug_flush_memory(void);
2023-11-10 13:42:53 +01:00
#endif