This commit is contained in:
2026-04-28 09:56:08 -05:00
parent 61a071cee6
commit 84f725634e
2 changed files with 5 additions and 7 deletions

View File

@@ -90,8 +90,8 @@ ByteArray Bytecode::generate(BytecodePrototype const& bp)
std::vector<std::pair<FunctionDef, uint32_t>> functions;
ByteArray code;
for (auto const& f: bp.functions) {
functions.emplace_back(std::make_pair(FunctionDef { f.n_pars, f.n_locals }, code.size()));
code.append_bytearray(f.code);
functions.emplace_back(std::make_pair(FunctionDef { f.n_pars, f.n_locals }, code.size()));
}
//
@@ -117,13 +117,13 @@ ByteArray Bytecode::generate(BytecodePrototype const& bp)
}
// functions
size_t functions_start = idx + (constant_table.size() * 4) + ba.size();
idx += functions_start;
size_t functions_start = idx + (constant_table.size() * 4);
idx = functions_start;
uint32_t code_idx = 0;
for (auto const& f: functions) {
ba.set_uint32(idx, code_idx);
ba.set_uint16(idx + 4, f.first.n_params);
ba.set_uint16(idx + 6, f.first.n_params);
ba.set_uint16(idx + 6, f.first.locals);
idx += 8;
code_idx += f.second;
}