Skip to content

Commit

Permalink
fix: segfault on empty stack in repl fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mrunix00 committed Feb 17, 2024
1 parent ac6d5c7 commit f33ff63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ void exec_program(const std::string &program, struct options opts) {
if (opts.executeBytecode) {
static auto interpreter = Bytecode::Interpreter();
interpreter.execute(compiler.program);
if (interpreter.vm.stackTop()->literal->type == Bytecode::Literal::Type::Integer)
std::cout << interpreter.vm.stackTop()->literal->int_literal << '\n';
if (interpreter.vm.stackTop()->literal->type == Bytecode::Literal::Type::Boolean) {
if (interpreter.vm.stackTop()->literal->bool_literal == Bytecode::Boolean::True)
std::cout << "true\n";
else
std::cout << "false\n";
if (interpreter.vm.stackTop() != nullptr) {
if (interpreter.vm.stackTop()->literal->type == Bytecode::Literal::Type::Integer)
std::cout << interpreter.vm.stackTop()->literal->int_literal << '\n';
if (interpreter.vm.stackTop()->literal->type == Bytecode::Literal::Type::Boolean) {
if (interpreter.vm.stackTop()->literal->bool_literal == Bytecode::Boolean::True)
std::cout << "true\n";
else
std::cout << "false\n";
}
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/bytecode/vm/cond_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST(vm_conf_test, ShouldJumpToOppositeCondition) {
new Jump(7),
new LoadLiteral(10),
}),
});;
});

const auto expected_result = new StackObject(new Literal(20));

Expand Down

0 comments on commit f33ff63

Please sign in to comment.