-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathIndexError.hpp
More file actions
48 lines (37 loc) · 1.12 KB
/
Copy pathIndexError.hpp
File metadata and controls
48 lines (37 loc) · 1.12 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
#pragma once
#include "Exception.hpp"
#include "LookupError.hpp"
#include "PyNone.hpp"
#include "PyString.hpp"
#include "PyTuple.hpp"
#include "vm/VM.hpp"
namespace py {
class IndexError : public LookupError
{
friend class ::Heap;
template<typename... Args>
friend BaseException *index_error(const std::string &message, Args &&...args);
private:
IndexError(PyType *type);
IndexError(PyTuple *msg);
static IndexError *create(PyTuple *args)
{
auto &heap = VirtualMachine::the().heap();
return heap.allocate<IndexError>(args);
}
public:
static std::function<std::unique_ptr<TypePrototype>()> type_factory();
static PyResult<PyObject *> __new__(const PyType *type, PyTuple *args, PyDict *kwargs);
PyType *static_type() const override;
static PyType *class_type();
};
template<typename... Args>
inline BaseException *index_error(const std::string &message, Args &&...args)
{
auto msg = PyString::create(fmt::format(message, std::forward<Args>(args)...));
ASSERT(msg.is_ok());
auto args_tuple = PyTuple::create(msg.unwrap());
ASSERT(args_tuple.is_ok());
return IndexError::create(args_tuple.unwrap());
}
}// namespace py