From d8001c5a33f65743cf1c95ebc910bb77b24ebe5d Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 27 Mar 2025 11:51:14 +0100 Subject: [PATCH 1/2] bare-bones print --- src/rt/core/builtin.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/rt/core/builtin.cc b/src/rt/core/builtin.cc index fb28da2..97db93a 100644 --- a/src/rt/core/builtin.cc +++ b/src/rt/core/builtin.cc @@ -352,6 +352,19 @@ namespace rt::core return result_obj; }); + + add_builtin("print", [](auto frame, auto args) { + if (args != 1) + { + ui::error("print() expected 1 argument"); + } + + auto value = frame->stack_pop("value to print"); + std::cout << "print: " << value->get_name() << std::endl; + rt::remove_reference(frame->object(), value); + + return std::nullopt; + }); } void pragma_builtins() From c1337b61c8eb943f49a6619e782cdfef6e074faa Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 27 Mar 2025 12:13:41 +0100 Subject: [PATCH 2/2] no longer prints quotation marks --- src/rt/core/builtin.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rt/core/builtin.cc b/src/rt/core/builtin.cc index 97db93a..c5c1de5 100644 --- a/src/rt/core/builtin.cc +++ b/src/rt/core/builtin.cc @@ -359,8 +359,15 @@ namespace rt::core ui::error("print() expected 1 argument"); } - auto value = frame->stack_pop("value to print"); - std::cout << "print: " << value->get_name() << std::endl; + auto value = frame->stack_pop("value to print"); + auto name = value->get_name(); + // Lazy way of dealing with stringPrototypeObject + if (name[0] == '\"') + { + name.erase(0, 1); + name.erase(name.size() - 1); + } + std::cout << name << std::endl; rt::remove_reference(frame->object(), value); return std::nullopt;