Skip to content

Commit

Permalink
fix: dump bytecode only after compiling all expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrunix00 committed Apr 17, 2024
1 parent 9820946 commit 12c50d0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "bytecode/instructions/Return.h"
#include "bytecode/vm/Interpreter.h"
#include "exceptions/SyntaxError.h"
#include "lexer/Lexer.h"
Expand Down Expand Up @@ -31,16 +32,16 @@ void exec_program(const std::string &program, struct options opts) {
ast->compile(compiled_bytecode);
delete ast;

if (opts.dumpBytecode) {
for (size_t i = 0; i < compiled_bytecode.segments.size(); i++) {
std::cout << ':' << i << '\n';
for (size_t j = 0; j < compiled_bytecode.segments[i]->instructions.size(); j++)
std::cout << j << '\t' << compiled_bytecode.segments[i]->instructions[j]->toString() << '\n';
std::cout << '\n';
}
}
}

if (opts.dumpBytecode) {
for (size_t i = 0; i < compiled_bytecode.segments.size(); i++) {
std::cout << ':' << i << '\n';
for (size_t j = 0; j < compiled_bytecode.segments[i]->instructions.size(); j++)
std::cout << j << '\t' << compiled_bytecode.segments[i]->instructions[j]->toString() << '\n';
std::cout << '\n';
}
}
interpreter.execute(compiled_bytecode);

const auto stackTop = interpreter.vm.program_stack.top();
Expand Down

0 comments on commit 12c50d0

Please sign in to comment.