-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlox_function.hpp
More file actions
71 lines (61 loc) · 1.59 KB
/
lox_function.hpp
File metadata and controls
71 lines (61 loc) · 1.59 KB
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
#ifndef LOX_FUNCTION_HPP
#define LOX_FUNCTION_HPP
#include "environment.hpp"
#include "stmt.hpp"
#include "deferred_ptr.hpp"
#include <functional>
#include <vector>
#include <iostream>
template <typename T>
class interpreter;
template<typename T>
class lox_function {
public:
std::function<T(lox_function &, interpreter<T> &, std::vector<T> &)> call_f;
std::function<int(lox_function &)> arity_f;
deferred_ptr<environment> closure;
Function<T> function_decl{};
int arity()
{
return arity_f(*this);
}
T call(interpreter<T> &Interpreter, std::vector<T> &arguments)
{
return call_f(*this, Interpreter, arguments);
}
lox_function<T>(std::function<T(lox_function &, interpreter<T> &, std::vector<T> &)> call_f,
std::function<int(lox_function &)> arity_f,
deferred_ptr<environment> &closure,
Function<T> &function_decl) :
call_f(call_f),
arity_f(arity_f),
closure(closure),
function_decl(function_decl) {}
lox_function<T>(std::function<T(lox_function &, interpreter<T> &, std::vector<T> &)> call_f,
std::function<int(lox_function &)> arity_f,
deferred_ptr<environment> &closure,
Function<T> &&function_decl) :
call_f(call_f),
arity_f(arity_f),
closure(closure),
function_decl(function_decl) {}
lox_function() {}
lox_function &operator=(const lox_function &other)
{
if (this == &other)
return *this;
this->call_f = other.call_f;
this->arity_f = other.arity_f;
this->closure = other.closure;
this->function_decl = other.function_decl;
return *this;
}
lox_function(const lox_function &other)
{
operator=(other);
}
~lox_function()
{
}
};
#endif