|
6 | 6 | #include<iostream>
|
7 | 7 | #include<sstream>
|
8 | 8 |
|
9 |
| -namespace ast { |
10 |
| - enum class VarType { NUMBER, STRING, POINTER, TYPE_NULL }; |
11 |
| -} |
12 | 9 | namespace interp {
|
13 |
| - struct Var { |
14 |
| - Var() = default; |
15 |
| - Var(const std::string &n, ast::VarType v) : name{n}, numeric_value{0}, ptr_value{nullptr}, type{v} {} |
16 |
| - Var(const std::string &n, const std::string &value) : name{n}, string_value{value}, type{ast::VarType::STRING} {} |
17 |
| - Var(const std::string &n, long value) : name{n}, numeric_value{value}, type{ast::VarType::NUMBER} {} |
18 |
| - Var(const std::string &n, void *ptr) : name{n}, ptr_value{ptr}, type {ast::VarType::POINTER} {} |
19 |
| - Var(const Var &v) : name{v.name}, numeric_value{v.numeric_value}, string_value{v.string_value}, ptr_value{v.ptr_value}, type{v.type} {} |
20 |
| - Var(Var &&v) : name{std::move(v.name)}, numeric_value{v.numeric_value}, string_value{std::move(v.string_value)}, ptr_value{v.ptr_value}, type{v.type} {} |
21 |
| - |
22 |
| - Var &operator=(const Var &v) { |
23 |
| - name = v.name; |
24 |
| - numeric_value = v.numeric_value; |
25 |
| - string_value = v.string_value; |
26 |
| - ptr_value = v.ptr_value; |
27 |
| - type = v.type; |
28 |
| - return *this; |
29 |
| - } |
30 |
| - |
31 |
| - Var &operator=(Var &&v) { |
32 |
| - name = std::move(v.name); |
33 |
| - numeric_value = v.numeric_value; |
34 |
| - string_value = std::move(v.string_value); |
35 |
| - ptr_value = v.ptr_value; |
36 |
| - type = v.type; |
37 |
| - return *this; |
38 |
| - } |
39 |
| - |
40 |
| - std::string name; |
41 |
| - long numeric_value = 0; |
42 |
| - std::string string_value; |
43 |
| - void *ptr_value = nullptr; |
44 |
| - ast::VarType type; |
45 |
| - }; |
46 | 10 |
|
47 |
| - void check_args(const std::string &n, const std::vector<interp::Var> &v, std::initializer_list<ast::VarType> args) { |
| 11 | + inline void check_args(const std::string &n, const std::vector<interp::Var> &v, std::initializer_list<ast::VarType> args) { |
48 | 12 | if(v.size() != args.size()) {
|
49 | 13 | std::ostringstream stream;
|
50 | 14 | stream << "In function: " << n << " argument count mismatch.\n";
|
|
0 commit comments