-
Notifications
You must be signed in to change notification settings - Fork 3
/
api.h
48 lines (32 loc) · 1.02 KB
/
api.h
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
#ifndef __TAB_API_H
#define __TAB_API_H
namespace tab {
template <bool SORTED>
struct API {
static void init(size_t seed) {
register_functions<SORTED>(seed);
}
struct compiled_t {
std::vector<Command> commands;
Type result;
Runtime rt;
};
template <typename I>
static void compile(I beg, I end, const Type& input, compiled_t& out, unsigned int debuglevel = 0) {
TypeRuntime typer(debuglevel >= 2 ? true : false);
out.result = parse(beg, end, input, typer, out.commands, debuglevel);
out.rt.init(typer.num_vars());
execute_init<SORTED>(out.commands);
}
static obj::Object* run(compiled_t& code, obj::Object* input) {
return execute<SORTED>(code.commands, code.rt, input);
}
static obj::Object* make(const Type& t) {
obj::Object* ret = obj::make<SORTED>(t);
if (!ret)
throw std::runtime_error("Cannot make() a " + Type::print(t));
return ret;
}
};
} // namespace tab
#endif