@@ -122,6 +122,7 @@ void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAdd
122
122
const FunctionType* type { nullptr };
123
123
instance->visit ([&](const auto & function) { type = &function.type (); });
124
124
TRAP_IF_NOT (type);
125
+ TRAP_IF_NOT (configuration.stack ().entries ().size () > type->parameters ().size ());
125
126
Vector<Value> args;
126
127
args.ensure_capacity (type->parameters ().size ());
127
128
auto span = configuration.stack ().entries ().span ().slice_from_end (type->parameters ().size ());
@@ -506,8 +507,18 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
506
507
return ;
507
508
return branch_to_label (configuration, instruction.arguments ().get <LabelIndex>());
508
509
}
509
- case Instructions::br_table.value ():
510
- goto unimplemented;
510
+ case Instructions::br_table.value (): {
511
+ auto & arguments = instruction.arguments ().get <Instruction::TableBranchArgs>();
512
+ auto entry = configuration.stack ().pop ();
513
+ TRAP_IF_NOT (entry.has <Value>());
514
+ auto maybe_i = entry.get <Value>().to <i32 >();
515
+ TRAP_IF_NOT (maybe_i.has_value ());
516
+ TRAP_IF_NOT (maybe_i.value () >= 0 );
517
+ size_t i = *maybe_i;
518
+ if (i < arguments.labels .size ())
519
+ return branch_to_label (configuration, arguments.labels [i]);
520
+ return branch_to_label (configuration, arguments.default_ );
521
+ }
511
522
case Instructions::call.value (): {
512
523
auto index = instruction.arguments ().get <FunctionIndex>();
513
524
TRAP_IF_NOT (index.value () < configuration.frame ().module ().functions ().size ());
0 commit comments