mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
LibWasm+LibWeb: Partially resolve memory exports
This allows the JS side to access the wasm memory, assuming it's exported by the module. This can be used to draw stuff on the wasm side and display them from the js side, for example :^)
This commit is contained in:
parent
4a459d2430
commit
cf8b75c2e5
6 changed files with 173 additions and 49 deletions
|
@ -14,10 +14,19 @@
|
|||
|
||||
namespace Wasm {
|
||||
|
||||
#define TRAP_IF_NOT(x) \
|
||||
do { \
|
||||
if (trap_if_not(x)) \
|
||||
return; \
|
||||
#define TRAP_IF_NOT(x) \
|
||||
do { \
|
||||
if (trap_if_not(x)) { \
|
||||
dbgln_if(WASM_TRACE_DEBUG, "Trapped because {} failed, at line {}", #x, __LINE__); \
|
||||
return; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define TRAP_IF_NOT_NORETURN(x) \
|
||||
do { \
|
||||
if (trap_if_not(x)) { \
|
||||
dbgln_if(WASM_TRACE_DEBUG, "Trapped because {} failed, at line {}", #x, __LINE__); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
void Interpreter::interpret(Configuration& configuration)
|
||||
|
@ -56,9 +65,8 @@ void Interpreter::branch_to_label(Configuration& configuration, LabelIndex index
|
|||
configuration.stack().pop();
|
||||
}
|
||||
|
||||
// Push results in reverse
|
||||
for (size_t i = results.size(); i > 0; --i)
|
||||
configuration.stack().push(move(static_cast<Vector<NonnullOwnPtr<Value>>&>(results)[i - 1]));
|
||||
for (auto& result : results)
|
||||
configuration.stack().push(move(result));
|
||||
|
||||
configuration.ip() = label->continuation();
|
||||
}
|
||||
|
@ -269,13 +277,12 @@ struct ConvertToRaw<double> {
|
|||
Vector<NonnullOwnPtr<Value>> Interpreter::pop_values(Configuration& configuration, size_t count)
|
||||
{
|
||||
Vector<NonnullOwnPtr<Value>> results;
|
||||
// Pop results in order
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
auto top_of_stack = configuration.stack().pop();
|
||||
if (auto value = top_of_stack.get_pointer<NonnullOwnPtr<Value>>())
|
||||
results.append(move(*value));
|
||||
results.prepend(move(*value));
|
||||
else
|
||||
trap_if_not(value);
|
||||
TRAP_IF_NOT_NORETURN(value);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
@ -361,9 +368,8 @@ void Interpreter::interpret(Configuration& configuration, InstructionPointer& ip
|
|||
break;
|
||||
}
|
||||
|
||||
// Push results in reverse
|
||||
for (size_t i = 1; i < results.size() + 1; ++i)
|
||||
configuration.stack().push(move(static_cast<Vector<NonnullOwnPtr<Value>>&>(results)[results.size() - i]));
|
||||
for (auto& result : results)
|
||||
configuration.stack().push(move(result));
|
||||
|
||||
if (instruction.opcode() == Instructions::structured_end)
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue