-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPyClassMethodDescriptor.hpp
More file actions
56 lines (42 loc) · 1.42 KB
/
Copy pathPyClassMethodDescriptor.hpp
File metadata and controls
56 lines (42 loc) · 1.42 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
#pragma once
#include "MemoryError.hpp"
#include "PyObject.hpp"
#include "vm/VM.hpp"
namespace py {
class PyClassMethodDescriptor : public PyBaseObject
{
friend class ::Heap;
PyString *m_name;
PyType *m_underlying_type;
std::optional<std::reference_wrapper<MethodDefinition>> m_method;
std::vector<PyObject *> m_captures;
PyClassMethodDescriptor(PyType *);
PyClassMethodDescriptor(PyString *name,
PyType *underlying_type,
MethodDefinition &method,
std::vector<PyObject *> &&captures);
public:
template<typename... Args>
static PyResult<PyClassMethodDescriptor *>
create(PyString *name, PyType *underlying_type, MethodDefinition &method, Args &&...args)
{
auto *obj = VirtualMachine::the().heap().allocate<PyClassMethodDescriptor>(
name, underlying_type, method, std::vector<PyObject *>{ args... });
if (!obj) { return Err(memory_error(sizeof(PyClassMethodDescriptor))); }
return Ok(obj);
}
PyString *name() { return m_name; }
const MethodDefinition &method_descriptor() const
{
ASSERT(m_method);
return m_method->get();
}
std::string to_string() const override;
PyResult<PyObject *> __repr__() const;
PyResult<PyObject *> __call__(PyTuple *args, PyDict *kwargs);
PyResult<PyObject *> __get__(PyObject *, PyObject *) const;
void visit_graph(Visitor &visitor) override;
static std::function<std::unique_ptr<TypePrototype>()> type_factory();
PyType *static_type() const override;
};
}// namespace py