bytecode2 #2
@@ -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;
|
||||
}
|
||||
|
||||
@@ -117,16 +117,14 @@ TEST(Bytecode, Code)
|
||||
|
||||
// function definitions
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,
|
||||
|
||||
// code
|
||||
0x68, 0x54, 0x42,
|
||||
};
|
||||
|
||||
/*
|
||||
ByteArray ba = Bytecode::generate(bp);
|
||||
ASSERT_EQ(ba.data(), expected);
|
||||
*/
|
||||
}
|
||||
|
||||
TEST(Bytecode, Parsing)
|
||||
|
||||
Reference in New Issue
Block a user