-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoca.hpp
74 lines (59 loc) · 1.5 KB
/
oca.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ollieberzs 2018
** oca.hpp
** oca api
*/
#pragma once
#include <chrono>
#include "common.hpp"
#include "lex.hpp"
#include "scope.hpp"
#include "value.hpp"
#include "parse.hpp"
#include "eval.hpp"
#include "error.hpp"
#define NIL oca::Nil::in(nullptr)
OCA_BEGIN
struct Arg {
ValuePtr caller;
ValuePtr value;
ValuePtr yield;
ValuePtr operator[](uint i);
};
class State {
Scope global;
Scope scope;
Lexer lexer;
Parser parser;
Evaluator evaler;
ErrorHandler eh;
std::chrono::time_point<std::chrono::high_resolution_clock> begin;
std::chrono::milliseconds lextime;
std::chrono::milliseconds parsetime;
std::chrono::milliseconds evaltime;
public:
State();
~State();
State(const State&) = delete;
State& operator=(const State&) = delete;
ValuePtr runFile(const std::string& path);
ValuePtr runString(const std::string& source);
void runREPL();
void load(const std::string& lib);
void bind(const std::string& name, const std::string& params, CPPFunc func);
private:
std::vector<Token> lex(const std::string& source);
std::vector<ExprPtr> parse(const std::vector<Token>& tokens);
ValuePtr evaluate(const std::vector<ExprPtr>& ast);
friend class ErrorHandler;
friend class Evaluator;
friend class Value;
friend class Integer;
friend class Real;
friend class String;
friend class Bool;
friend class Table;
friend class Block;
friend class Func;
friend class Scope;
};
OCA_END