mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:47:35 +00:00
LibWasm: Load and instantiate tables
This commit is a fairly large refactor, mainly because it unified the two different ways that existed to represent references. Now Reference values are also a kind of value. It also implements a printer for values/references instead of copying the implementation everywhere.
This commit is contained in:
parent
c392a0cf7f
commit
be62e4d1d7
10 changed files with 350 additions and 192 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <LibWasm/AbstractMachine/Configuration.h>
|
||||
#include <LibWasm/AbstractMachine/Interpreter.h>
|
||||
#include <LibWasm/Printer/Printer.h>
|
||||
|
||||
namespace Wasm {
|
||||
|
||||
|
@ -24,6 +25,9 @@ Optional<Label> Configuration::nth_label(size_t i)
|
|||
|
||||
void Configuration::unwind(Badge<CallFrameHandle>, const CallFrameHandle& frame_handle)
|
||||
{
|
||||
if (m_stack.size() == frame_handle.stack_size && frame_handle.frame_index == m_current_frame_index)
|
||||
return;
|
||||
|
||||
VERIFY(m_stack.size() > frame_handle.stack_size);
|
||||
m_stack.entries().remove(frame_handle.stack_size, m_stack.size() - frame_handle.stack_size);
|
||||
m_current_frame_index = frame_handle.frame_index;
|
||||
|
@ -82,29 +86,21 @@ Result Configuration::execute(Interpreter& interpreter)
|
|||
|
||||
void Configuration::dump_stack()
|
||||
{
|
||||
auto print_value = []<typename... Ts>(CheckedFormatString<Ts...> format, Ts... vs)
|
||||
{
|
||||
DuplexMemoryStream memory_stream;
|
||||
Printer { memory_stream }.print(vs...);
|
||||
dbgln(format.view(), StringView(memory_stream.copy_into_contiguous_buffer()).trim_whitespace());
|
||||
};
|
||||
for (const auto& entry : stack().entries()) {
|
||||
entry.visit(
|
||||
[](const Value& v) {
|
||||
v.value().visit([]<typename T>(const T& v) {
|
||||
if constexpr (IsIntegral<T> || IsFloatingPoint<T>)
|
||||
dbgln(" {}", v);
|
||||
else if constexpr (IsSame<Value::Null, T>)
|
||||
dbgln(" *null");
|
||||
else
|
||||
dbgln(" *{}", v.value());
|
||||
});
|
||||
[&](const Value& v) {
|
||||
print_value(" {}", v);
|
||||
},
|
||||
[](const Frame& f) {
|
||||
[&](const Frame& f) {
|
||||
dbgln(" frame({})", f.arity());
|
||||
for (auto& local : f.locals()) {
|
||||
local.value().visit([]<typename T>(const T& v) {
|
||||
if constexpr (IsIntegral<T> || IsFloatingPoint<T>)
|
||||
dbgln(" {}", v);
|
||||
else if constexpr (IsSame<Value::Null, T>)
|
||||
dbgln(" *null");
|
||||
else
|
||||
dbgln(" *{}", v.value());
|
||||
});
|
||||
print_value(" {}", local);
|
||||
}
|
||||
},
|
||||
[](const Label& l) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue