-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathNotImplemented.cpp
More file actions
49 lines (38 loc) · 1.3 KB
/
Copy pathNotImplemented.cpp
File metadata and controls
49 lines (38 loc) · 1.3 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
#include "NotImplemented.hpp"
#include "MemoryError.hpp"
#include "types/api.hpp"
#include "types/builtin.hpp"
namespace py {
NotImplemented::NotImplemented(PyType *type) : PyBaseObject(type) {}
NotImplemented::NotImplemented() : PyBaseObject(types::BuiltinTypes::the().not_implemented()) {}
PyResult<NotImplemented *> NotImplemented::create()
{
auto &heap = VirtualMachine::the().heap();
auto *result = heap.allocate_static<NotImplemented>();
if (!result) { return Err(memory_error(sizeof(NotImplemented))); }
return Ok(result);
}
PyType *NotImplemented::static_type() const { return types::not_implemented(); }
std::string NotImplemented::to_string() const { return "NotImplemented"; }
namespace {
std::once_flag not_implemented_flag;
std::unique_ptr<TypePrototype> register_not_implemented()
{
return std::move(klass<NotImplemented>("NotImplemented").type);
}
}// namespace
std::function<std::unique_ptr<TypePrototype>()> NotImplemented::type_factory()
{
return [] {
static std::unique_ptr<TypePrototype> type = nullptr;
std::call_once(not_implemented_flag, []() { type = register_not_implemented(); });
return std::move(type);
};
}
NotImplemented *not_implemented()
{
static NotImplemented *value = nullptr;
if (!value) { value = NotImplemented::create().unwrap(); }
return value;
}
}// namespace py