-
Notifications
You must be signed in to change notification settings - Fork 0
/
lox_callable.h
39 lines (28 loc) · 1.04 KB
/
lox_callable.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
#ifndef LOX_LOX_CALLABLE_H
#define LOX_LOX_CALLABLE_H
#include "AST.h"
#include "lox_object.h"
#include "lox_instance.h"
#include "interpreter_exceptions.h"
class interpreter;
class environment;
class lox_callable : public lox_object/*, public enable_shared_from_this<lox_callable> */{
public:
virtual int arity() = 0;
virtual shared_ptr<lox_object> call(interpreter& i, vector<shared_ptr<lox_object>>& arguments) = 0;
virtual string to_string() = 0;
~lox_callable() override = default;
};
class lox_function : public lox_callable {
private:
shared_ptr<Function_Stmt> declaration;
shared_ptr<environment> closure;
bool is_initializer;
public:
lox_function(shared_ptr<Function_Stmt> declaration, shared_ptr<environment> closure, bool is_initializer);
shared_ptr<lox_function> bind(const shared_ptr<lox_instance>& instance);
shared_ptr<lox_object> call(interpreter& i, vector<shared_ptr<lox_object>>& arguments) override;
int arity() override;
string to_string() override;
};
#endif //LOX_LOX_CALLABLE_H