-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathYieldValue.cpp
More file actions
37 lines (28 loc) · 754 Bytes
/
YieldValue.cpp
File metadata and controls
37 lines (28 loc) · 754 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
#include "YieldValue.hpp"
#include "interpreter/Interpreter.hpp"
#include "runtime/PyFrame.hpp"
#include "vm/VM.hpp"
using namespace py;
PyResult<Value> YieldValue::execute(VirtualMachine &vm, Interpreter &interpreter) const
{
auto result = vm.reg(m_source);
std::visit(
overloaded{ [](const auto &val) {
std::ostringstream os;
os << val;
spdlog::debug("Return value: {}", os.str());
},
[](const PyObject *val) { spdlog::debug("Return value: {}", val->to_string()); } },
result);
ASSERT(interpreter.execution_frame()->generator() != nullptr);
vm.reg(0) = result;
vm.pop_frame(false);
return Ok(result);
}
std::vector<uint8_t> YieldValue::serialize() const
{
return {
YIELD_VALUE,
m_source,
};
}