.
This commit is contained in:
@@ -90,8 +90,8 @@ ByteArray Bytecode::generate(BytecodePrototype const& bp)
|
|||||||
std::vector<std::pair<FunctionDef, uint32_t>> functions;
|
std::vector<std::pair<FunctionDef, uint32_t>> functions;
|
||||||
ByteArray code;
|
ByteArray code;
|
||||||
for (auto const& f: bp.functions) {
|
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);
|
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
|
// functions
|
||||||
size_t functions_start = idx + (constant_table.size() * 4) + ba.size();
|
size_t functions_start = idx + (constant_table.size() * 4);
|
||||||
idx += functions_start;
|
idx = functions_start;
|
||||||
uint32_t code_idx = 0;
|
uint32_t code_idx = 0;
|
||||||
for (auto const& f: functions) {
|
for (auto const& f: functions) {
|
||||||
ba.set_uint32(idx, code_idx);
|
ba.set_uint32(idx, code_idx);
|
||||||
ba.set_uint16(idx + 4, f.first.n_params);
|
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;
|
idx += 8;
|
||||||
code_idx += f.second;
|
code_idx += f.second;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,16 +117,14 @@ TEST(Bytecode, Code)
|
|||||||
|
|
||||||
// function definitions
|
// function definitions
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
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
|
// code
|
||||||
0x68, 0x54, 0x42,
|
0x68, 0x54, 0x42,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
ByteArray ba = Bytecode::generate(bp);
|
ByteArray ba = Bytecode::generate(bp);
|
||||||
ASSERT_EQ(ba.data(), expected);
|
ASSERT_EQ(ba.data(), expected);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Bytecode, Parsing)
|
TEST(Bytecode, Parsing)
|
||||||
|
|||||||
Reference in New Issue
Block a user