.
This commit is contained in:
@@ -31,6 +31,8 @@ ByteArray Assembler::assemble()
|
|||||||
} else if (std::get<std::string>(t.token) == ".func") {
|
} else if (std::get<std::string>(t.token) == ".func") {
|
||||||
section = Section::Function;
|
section = Section::Function;
|
||||||
function_id = std::get<int>(expect_token(TokenType::Integer));
|
function_id = std::get<int>(expect_token(TokenType::Integer));
|
||||||
|
if (function_id >= bp.functions.size())
|
||||||
|
bp.functions.resize(function_id + 1, { 0, 0 });
|
||||||
expect_token(TokenType::Enter);
|
expect_token(TokenType::Enter);
|
||||||
} else {
|
} else {
|
||||||
throw AssemblyError("Invalid directive " + std::get<std::string>(t.token), t.line, t.column);
|
throw AssemblyError("Invalid directive " + std::get<std::string>(t.token), t.line, t.column);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ struct BytecodePrototype {
|
|||||||
struct Function {
|
struct Function {
|
||||||
uint16_t n_pars;
|
uint16_t n_pars;
|
||||||
uint16_t n_locals;
|
uint16_t n_locals;
|
||||||
ByteArray code;
|
ByteArray code {};
|
||||||
|
|
||||||
Function(uint16_t n_pars_, uint16_t n_locals_) : n_pars(n_pars_), n_locals(n_locals_), code(ByteArray {}) {}
|
Function(uint16_t n_pars_, uint16_t n_locals_) : n_pars(n_pars_), n_locals(n_locals_), code(ByteArray {}) {}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user