diff options
author | Tim Schumacher <timschumi@gmx.de> | 2023-01-21 10:29:21 +0100 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2023-01-25 17:10:05 +0330 |
commit | 409fb0fe79071686590cfd1fdbc815193a15d795 (patch) | |
tree | 3e65aeb2fdd9261b777192ab1bc3930a4ebd535f /Userland/Utilities/wasm.cpp | |
parent | 4bad4dc8d5cbca8d5ce44413105d110609a6b17a (diff) | |
download | serenity-409fb0fe79071686590cfd1fdbc815193a15d795.zip |
LibWasm: Port `Wasm::Printer` to `Core::Stream`
Diffstat (limited to 'Userland/Utilities/wasm.cpp')
-rw-r--r-- | Userland/Utilities/wasm.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp index 94337c98d9..0d21b98bfc 100644 --- a/Userland/Utilities/wasm.cpp +++ b/Userland/Utilities/wasm.cpp @@ -19,7 +19,7 @@ #include <unistd.h> RefPtr<Line::Editor> g_line_editor; -static OwnPtr<AK::OutputStream> g_stdout {}; +static OwnPtr<Core::Stream::Stream> g_stdout {}; static OwnPtr<Wasm::Printer> g_printer {}; static bool g_continue { false }; static void (*old_signal)(int); @@ -53,12 +53,12 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi if (always_print_stack) config.dump_stack(); if (always_print_instruction) { - g_stdout->write(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()); + g_stdout->write(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors(); g_printer->print(instr); } if (g_continue) return true; - g_stdout->write(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()); + g_stdout->write(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors(); g_printer->print(instr); DeprecatedString last_command = ""; for (;;) { @@ -213,7 +213,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi if (!result.values().is_empty()) warnln("Returned:"); for (auto& value : result.values()) { - g_stdout->write(" -> "sv.bytes()); + g_stdout->write(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors(); g_printer->print(value); } continue; @@ -339,8 +339,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) if (!parse_result.has_value()) return 1; - auto standard_output = TRY(Core::Stream::File::standard_output()); - g_stdout = TRY(try_make<Core::Stream::WrapInAKOutputStream>(*standard_output)); + g_stdout = TRY(Core::Stream::File::standard_output()); g_printer = TRY(try_make<Wasm::Printer>(*g_stdout)); if (print && !attempt_instantiate) { @@ -400,8 +399,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) bool first = true; for (auto& argument : arguments) { Core::Stream::AllocatingMemoryStream stream; - Core::Stream::WrapInAKOutputStream wrapped_stream { stream }; - Wasm::Printer { wrapped_stream }.print(argument); + Wasm::Printer { stream }.print(argument); if (first) first = false; else @@ -454,15 +452,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto print_func = [&](auto const& address) { Wasm::FunctionInstance* fn = machine.store().get(address); - g_stdout->write(DeprecatedString::formatted("- Function with address {}, ptr = {}\n", address.value(), fn).bytes()); + g_stdout->write(DeprecatedString::formatted("- Function with address {}, ptr = {}\n", address.value(), fn).bytes()).release_value_but_fixme_should_propagate_errors(); if (fn) { - g_stdout->write(DeprecatedString::formatted(" wasm function? {}\n", fn->has<Wasm::WasmFunction>()).bytes()); + g_stdout->write(DeprecatedString::formatted(" wasm function? {}\n", fn->has<Wasm::WasmFunction>()).bytes()).release_value_but_fixme_should_propagate_errors(); fn->visit( [&](Wasm::WasmFunction const& func) { Wasm::Printer printer { *g_stdout, 3 }; - g_stdout->write(" type:\n"sv.bytes()); + g_stdout->write(" type:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors(); printer.print(func.type()); - g_stdout->write(" code:\n"sv.bytes()); + g_stdout->write(" code:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors(); printer.print(func.code()); }, [](Wasm::HostFunction const&) {}); @@ -526,7 +524,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) if (!result.values().is_empty()) warnln("Returned:"); for (auto& value : result.values()) { - g_stdout->write(" -> "sv.bytes()); + g_stdout->write(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors(); g_printer->print(value); } } |