From 8e5e5f819f5397299d2a1cd56e4e13e7af5843d2 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 12 Apr 2023 00:18:58 +0300 Subject: [PATCH] Kernel: Shell TTY_PRINT is now function instead of macro This makes functions uses way less stack --- kernel/kernel/Shell.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/kernel/kernel/Shell.cpp b/kernel/kernel/Shell.cpp index b25713ed..44faaaf4 100644 --- a/kernel/kernel/Shell.cpp +++ b/kernel/kernel/Shell.cpp @@ -15,23 +15,23 @@ #include #include -#define TTY_PRINT(...) \ - do { \ - BAN::String message_ = BAN::String::formatted(__VA_ARGS__); \ - MUST(Process::current()->write(STDOUT_FILENO, message_.data(), message_.size())); \ - } while (false) - -#define TTY_PRINTLN(...) \ - do { \ - TTY_PRINT(__VA_ARGS__); \ - MUST(Process::current()->write(STDOUT_FILENO, "\n", 1)); \ - } while (false) - - - namespace Kernel { + template + static void TTY_PRINT(Args&&... args) + { + BAN::String message = BAN::String::formatted(BAN::forward(args)...); + MUST(Process::current()->write(STDOUT_FILENO, message.data(), message.size())); + } + + template + static void TTY_PRINTLN(Args&&... args) + { + TTY_PRINT(BAN::forward(args)...); + MUST(Process::current()->write(STDOUT_FILENO, "\n", 1)); + } + static auto s_default_prompt = "\\[\e[32m\\]user\\[\e[m\\]:\\[\e[34m\\]\\w\\[\e[m\\]# "sv; static const char* mode_string(Inode::Mode mode)