Skip to content

Commit 392b4c3

Browse files
committed
feat(repl): print the value of the last expression that ran
1 parent 35f1a87 commit 392b4c3

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log
22

3+
## [Unreleased changes] - 20XX-XX-XX
4+
### Added
5+
- the repl prints the output of the last expression it ran
6+
7+
### Changed
8+
9+
### Removed
10+
311
## [4.1.1] - 2025-12-13
412
### Fixed
513
- the formatter was breaking functions' arguments list containing argument attributes on multiple lines for no reason

src/arkreactor/Compiler/Package/ImportSolver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ namespace Ark::internal
1616

1717
ImportSolver& ImportSolver::setup(const std::filesystem::path& root, const std::vector<Import>& origin_imports)
1818
{
19-
m_root = root.parent_path();
19+
// keep the given root if it's a directory, it means it comes from a code string evaluation in the state, where we don't have a filename
20+
m_root = is_directory(root) ? root : root.parent_path();
2021

2122
for (const auto& origin_import : std::ranges::reverse_view(origin_imports))
2223
m_imports.push({ root, origin_import });

src/arkscript/REPL/Repl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Ark
3535
if (maybe_block.has_value() && !maybe_block.value().empty())
3636
{
3737
std::string new_code = m_code + maybe_block.value();
38-
if (m_state.doString(new_code))
38+
if (m_state.doString(new_code, Ark::DefaultFeatures))
3939
{
4040
// for only one vm init
4141
if (!m_has_init_vm)
@@ -52,6 +52,10 @@ namespace Ark
5252
m_code = new_code;
5353
// place ip to end of bytecode instruction (HALT)
5454
m_vm.m_execution_contexts[0]->ip -= 4;
55+
56+
const Value* maybe_value = m_vm.peekAndResolveAsPtr(*m_vm.getDefaultContext());
57+
if (maybe_value != nullptr && maybe_value->valueType() != ValueType::Undefined && maybe_value->valueType() != ValueType::InstPtr)
58+
fmt::println("{}", fmt::styled(maybe_value->toString(m_vm), fmt::fg(fmt::color::chocolate)));
5559
}
5660
else
5761
{

0 commit comments

Comments
 (0)