-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathListToTuple.cpp
More file actions
43 lines (36 loc) · 940 Bytes
/
ListToTuple.cpp
File metadata and controls
43 lines (36 loc) · 940 Bytes
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
#include "ListToTuple.hpp"
#include "runtime/PyList.hpp"
#include "runtime/PyString.hpp"
#include "runtime/PyTuple.hpp"
#include "vm/VM.hpp"
#include <iostream>
using namespace py;
PyResult<Value> ListToTuple::execute(VirtualMachine &vm, Interpreter &) const
{
auto &list = vm.reg(m_list);
ASSERT(std::holds_alternative<PyObject *>(list));
auto *pylist = std::get<PyObject *>(list);
if (!as<PyList>(pylist)) {
std::cout << to_string() << std::endl;
if (!pylist) {
std::cout << "(null)" << std::endl;
} else {
std::cout << pylist->str().unwrap()->to_string() << std::endl;
}
}
ASSERT(as<PyList>(pylist));
auto result = PyTuple::create(as<PyList>(pylist)->elements());
if (result.is_ok()) {
vm.reg(m_tuple) = result.unwrap();
return Ok(Value{ result.unwrap() });
}
return Err(result.unwrap_err());
}
std::vector<uint8_t> ListToTuple::serialize() const
{
return {
LIST_TO_TUPLE,
m_tuple,
m_list,
};
}