This commit is contained in:
Andre Wagner
2026-05-01 10:12:23 -05:00
parent 25c6f6e6dd
commit 9104f0b7e2
2 changed files with 3 additions and 1 deletions

View File

@@ -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);

View File

@@ -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 {}) {}
}; };