1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:48:14 +00:00

LibWasm: Implement reference instructions (ref.{null,func,is_null})

This commit is contained in:
Ali Mohammad Pur 2021-06-01 09:48:36 +04:30 committed by Ali Mohammad Pur
parent 7fb458b7c9
commit 56bf80251c
8 changed files with 73 additions and 9 deletions

View file

@ -590,10 +590,29 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
}
case Instructions::table_get.value():
case Instructions::table_set.value():
case Instructions::ref_null.value():
case Instructions::ref_func.value():
case Instructions::ref_is_null.value():
goto unimplemented;
case Instructions::ref_null.value(): {
auto type = instruction.arguments().get<ValueType>();
TRAP_IF_NOT(type.is_reference());
configuration.stack().push(Value(Value::Null { type }));
return;
};
case Instructions::ref_func.value(): {
auto index = instruction.arguments().get<FunctionIndex>().value();
auto& functions = configuration.frame().module().functions();
TRAP_IF_NOT(functions.size() > index);
auto address = functions[index];
configuration.stack().push(Value(ValueType(ValueType::FunctionReference), address.value()));
return;
}
case Instructions::ref_is_null.value(): {
auto top = configuration.stack().peek().get_pointer<Value>();
TRAP_IF_NOT(top);
TRAP_IF_NOT(top->type().is_reference());
auto is_null = top->to<Value::Null>().has_value();
configuration.stack().peek() = Value(ValueType(ValueType::I32), static_cast<u64>(is_null ? 1 : 0));
return;
}
case Instructions::drop.value():
configuration.stack().pop();
return;