diff --git a/src/assembler/assembler.cc b/src/assembler/assembler.cc index f5fe59f..d189a26 100644 --- a/src/assembler/assembler.cc +++ b/src/assembler/assembler.cc @@ -31,6 +31,8 @@ ByteArray Assembler::assemble() } else if (std::get(t.token) == ".func") { section = Section::Function; function_id = std::get(expect_token(TokenType::Integer)); + if (function_id >= bp.functions.size()) + bp.functions.resize(function_id + 1, { 0, 0 }); expect_token(TokenType::Enter); } else { throw AssemblyError("Invalid directive " + std::get(t.token), t.line, t.column); diff --git a/src/bytecode/bytecodeprototype.hh b/src/bytecode/bytecodeprototype.hh index df92c81..5a1bb58 100644 --- a/src/bytecode/bytecodeprototype.hh +++ b/src/bytecode/bytecodeprototype.hh @@ -14,7 +14,7 @@ struct BytecodePrototype { struct Function { uint16_t n_pars; 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 {}) {} };