test program stack viz
This commit is contained in:
parent
2fbccd0bc8
commit
3d89031748
@ -171,5 +171,7 @@ int main()
|
||||
.code_coverage = true,
|
||||
});
|
||||
vm.run_until_done();
|
||||
std::cout << std::format("done\n{}\n", vm.stack_repr_string());
|
||||
std::cout << std::format("done\n{}\n", vm.stack_repr_string(4));
|
||||
auto flame_graph = vm.flame_graph_json();
|
||||
std::cout << std::format("flame graph: {}\n", flame_graph);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ void VM::run_n_instructions(size_t amount)
|
||||
void VM::run_instruction()
|
||||
{
|
||||
std::cout << std::format(" {:>4}: {:<12}{}\n", this->pc,
|
||||
maybe_op_to_string(this->program[this->pc]), stack_repr_string());
|
||||
maybe_op_to_string(this->program[this->pc]), stack_repr_string(4));
|
||||
auto op = eat_op();
|
||||
switch (op) {
|
||||
case Op::Nop:
|
||||
|
@ -156,16 +156,20 @@ public:
|
||||
return this->stack;
|
||||
}
|
||||
|
||||
inline auto stack_repr_string() const -> std::string
|
||||
inline auto stack_repr_string(size_t max_items) const -> std::string
|
||||
{
|
||||
auto result = std::string();
|
||||
result += "→";
|
||||
const auto& stack = view_stack();
|
||||
for (size_t i = 0; i < stack.size(); ++i) {
|
||||
for (size_t i = 0; i < stack.size() and i < max_items; ++i) {
|
||||
if (i != 0) {
|
||||
result += " ";
|
||||
}
|
||||
result += stack[stack.size() - i - 1].to_repr_string();
|
||||
result += std::format(
|
||||
"{:<11}", stack[stack.size() - i - 1].to_repr_string());
|
||||
}
|
||||
if (stack.size() >= max_items) {
|
||||
result += std::format(" ... + {}", stack.size() - max_items + 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user