diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ccef768..f733fd316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## [Unreleased changes] - 2026-MM-DD ### Breaking changes +### Deprecations +- `list:permutations` is deprecated in favor of `list:combinations` +- `list:permutationsWithReplacement` is deprecated in favor of `list:combinationsWithReplacement` + ### Added - new debugger commands: `stack ` and `locals ` to print the values on the stack and in the current locals scope - custom format specifiers for lists: @@ -15,6 +19,10 @@ - display a warning to `stderr` when using a deprecated function/value (checks for `@deprecated` inside the attached comment of functions / values) ### Changed +- `pop!` can return the removed value +- `@=` and `@@=` return the inserted value +- `append!` and `concat!` return the modified list +- `let`, `mut` and `set` can return the assigned value ### Removed diff --git a/docs/arkdoc/List.txt b/docs/arkdoc/List.txt index ef846fab8..32c031ec7 100644 --- a/docs/arkdoc/List.txt +++ b/docs/arkdoc/List.txt @@ -35,7 +35,7 @@ --# * @name append! -* @brief Add an element to a list, modifying it in place. It doesn't return anything +* @brief Add an element to a list, modifying it in place. Return the modified list * @param lst a list. Must be mutable * @param element * =begin @@ -60,7 +60,7 @@ --# * @name concat! -* @brief Concatenate two lists in place, modifying the first one it in place. It doesn't return anything +* @brief Concatenate two lists in place, modifying the first one it in place. Return the modified list * @param lst a list. Must be mutable * @param more another list * =begin @@ -87,7 +87,7 @@ --# * @name pop! -* @brief Remove an element from a list in place, given its index. It doesn't return anything +* @brief Remove an element from a list in place, given its index. Return the removed element * @details Supports negative indices, -1 being the end. * @param lst a list. Must be mutable * @param index number @@ -157,3 +157,25 @@ * (print (@@ ["abc" "def" "ghi"] 0 -1)) # c * =end #-- + +--# +* @name @= +* @brief Set an element in a list, in place +* @details Return the newly added element +* @param lst list +* @param index number (can be negative to start from the end) +* @param x value +* =begin +* (mut lst [1 2 3 4 5]) +* (print (@= lst 0 "x")) # "x" +* (print lst) # ["x" 2 3 4 5] +* (print (@= lst 1 "y")) # "y" +* (print lst) # ["x" "y" 3 4 5] +* (print (@= lst 2 "z")) # "z" +* (print lst) # ["x" "y" "z" 4 5] +* (@= lst -1 "f") +* (print lst) # ["x" "y" "z" 4 "f"] +* (@= lst -2 "g") +* (print lst) # ["x" "y" "z" "g" "f"] +* =end +#-- diff --git a/docs/arkdoc/String.txt b/docs/arkdoc/String.txt index f0eea36a6..18e567179 100644 --- a/docs/arkdoc/String.txt +++ b/docs/arkdoc/String.txt @@ -77,3 +77,25 @@ * (print (@ "abc" -2)) # "b" * =end #-- + +--# +* @name @= +* @brief Set a character in a string, in place +* @details Return the newly added character +* @param str string +* @param index number (can be negative to start from the end) +* @param char character +* =begin +* (mut str "abcde") +* (print (@= str 0 "x")) # "x" +* (print str) # "xbcde" +* (print (@= str 1 "y")) # "y" +* (print str) # "xycde" +* (print (@= str 2 "z")) # "z" +* (print str) # "xyzde" +* (@= str -1 "f") +* (print str) # "xyzdf" +* (@= str -2 "g") +* (print str) # "xyzgf" +* =end +#-- diff --git a/include/Ark/Compiler/Lowerer/ASTLowerer.hpp b/include/Ark/Compiler/Lowerer/ASTLowerer.hpp index a4b5c5f88..820ed47e3 100644 --- a/include/Ark/Compiler/Lowerer/ASTLowerer.hpp +++ b/include/Ark/Compiler/Lowerer/ASTLowerer.hpp @@ -257,7 +257,7 @@ namespace Ark::internal void compileApplyInstruction(Node& x, Page p, bool is_result_unused); void compileIf(Node& x, Page p, bool is_result_unused, bool is_terminal); void compileFunction(Node& x, Page p, bool is_result_unused); - void compileLetMutSet(Keyword n, Node& x, Page p); + void compileLetMutSet(Keyword n, Node& x, Page p, bool is_result_unused); void compileWhile(Node& x, Page p); void compilePluginImport(const Node& x, Page p); void pushFunctionCallArguments(Node& call, Page p, bool is_tail_call); diff --git a/src/arkreactor/Compiler/BytecodeReader.cpp b/src/arkreactor/Compiler/BytecodeReader.cpp index b51f5be0a..ce1c294e0 100644 --- a/src/arkreactor/Compiler/BytecodeReader.cpp +++ b/src/arkreactor/Compiler/BytecodeReader.cpp @@ -513,6 +513,10 @@ namespace Ark { CONCAT, ArgKind::Raw }, { APPEND_IN_PLACE, ArgKind::Raw }, { CONCAT_IN_PLACE, ArgKind::Raw }, + { POP_LIST, ArgKind::Raw }, + { POP_LIST_IN_PLACE, ArgKind::Raw }, + { SET_AT_INDEX, ArgKind::Raw }, + { SET_AT_2_INDEX, ArgKind::Raw }, { RESET_SCOPE_JUMP, ArgKind::Raw }, { GET_CURRENT_PAGE_ADDR, ArgKind::Symbol }, { LOAD_CONST_LOAD_CONST, ArgKind::ConstConst }, diff --git a/src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp b/src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp index d595ed83a..c37036190 100644 --- a/src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp +++ b/src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp @@ -38,8 +38,8 @@ namespace Ark::internal compileExpression( ast, /* current_page */ global, - /* is_result_unused */ false, - /* is_terminal */ false); + /* is_result_unused= */ true, + /* is_terminal= */ false); m_logger.traceEnd(); } @@ -95,18 +95,24 @@ namespace Ark::internal bool ASTLowerer::nodeProducesOutput(const Node& node) { if (node.nodeType() == NodeType::List && !node.constList().empty() && node.constList()[0].nodeType() == NodeType::Keyword) - // a begin node produces a value if the last node in it produces a value + // a 'begin' node produces a value if the last node in it produces a value return (node.constList()[0].keyword() == Keyword::Begin && node.constList().size() > 1 && nodeProducesOutput(node.constList().back())) || // a function always produces a value ; even if it ends with a node not producing one, the VM returns nil node.constList()[0].keyword() == Keyword::Fun || + // a let/mut/set pushes the value that was assigned + node.constList()[0].keyword() == Keyword::Let || + node.constList()[0].keyword() == Keyword::Mut || + node.constList()[0].keyword() == Keyword::Set || // a condition produces a value if all its branches produce a value (node.constList()[0].keyword() == Keyword::If && nodeProducesOutput(node.constList()[2]) && (node.constList().size() == 3 || nodeProducesOutput(node.constList()[3]))); - // in place list instruction, as well as breakpoint, do not produce values + // breakpoint do not produce values if (node.nodeType() == NodeType::List && !node.constList().empty() && node.constList()[0].nodeType() == NodeType::Symbol) - return std::ranges::find(Language::UpdateRef, node.constList().front().string()) == Language::UpdateRef.end() && - node.constList().front().string() != "breakpoint"; + { + const std::string& name = node.constList().front().string(); + return name != "breakpoint"; + } return true; // any other node, function call, symbol, number... } @@ -248,7 +254,7 @@ namespace Ark::internal case Keyword::Let: [[fallthrough]]; case Keyword::Mut: - compileLetMutSet(keyword, x, p); + compileLetMutSet(keyword, x, p, is_result_unused); break; case Keyword::Fun: @@ -332,15 +338,15 @@ namespace Ark::internal void ASTLowerer::compileListInstruction(Node& x, const Page p, const bool is_result_unused) { const Node head = x.constList()[0]; - std::string name = x.constList()[0].string(); - Instruction inst = getListInstruction(name).value(); + const std::string& name = head.string(); + const Instruction inst = getListInstruction(name).value(); // length of at least 1 since we got a symbol name const auto argc = x.constList().size() - 1u; // error, can not use append/concat/pop (and their in place versions) with a <2 length argument list - if (argc < 2 && APPEND <= inst && inst <= POP) + if (argc < 2 && APPEND <= inst && inst <= SET_AT_2_INDEX) buildAndThrowError(fmt::format("Can not use {} with less than 2 arguments", name), head); - if (inst <= POP && std::cmp_greater(argc, MaxValue16Bits)) + if (std::cmp_greater(argc, MaxValue16Bits)) buildAndThrowError(fmt::format("Too many arguments ({}), exceeds {}", argc, MaxValue16Bits), x); if (argc != 3 && inst == SET_AT_INDEX) buildAndThrowError(fmt::format("Expected 3 arguments (list, index, value) for {}, got {}", name, argc), head); @@ -366,24 +372,42 @@ namespace Ark::internal break; case APPEND: + [[fallthrough]]; case APPEND_IN_PLACE: + [[fallthrough]]; case CONCAT: + [[fallthrough]]; case CONCAT_IN_PLACE: inst_argc = argc - 1; break; case POP_LIST: - case POP_LIST_IN_PLACE: inst_argc = 0; break; + case SET_AT_INDEX: + [[fallthrough]]; + case SET_AT_2_INDEX: + [[fallthrough]]; + case POP_LIST_IN_PLACE: + inst_argc = is_result_unused ? 0 : 1; + break; + default: break; } page(p).emplace_back(inst, static_cast(inst_argc)); page(p).back().setSourceLocation(head.filename(), head.position().start.line); - if (is_result_unused && name.back() != '!' && inst <= POP_LIST_IN_PLACE) // in-place functions never push a value + if (!is_result_unused && (inst == APPEND_IN_PLACE || inst == CONCAT_IN_PLACE)) + { + // Load the first argument which should be a symbol (or field), + // that append!/concat! write to, so that we have its new value available. + compileExpression(x.list()[1], p, false, false); + } + + // append!, concat!, pop!, @= and @@= can push to the stack, but not using its returned value isn't an error + if (is_result_unused && (inst == LIST || inst == APPEND || inst == CONCAT || inst == POP_LIST)) { warning("Ignoring return value of function", x); page(p).emplace_back(POP); @@ -535,7 +559,7 @@ namespace Ark::internal } } - void ASTLowerer::compileLetMutSet(const Keyword n, Node& x, const Page p) + void ASTLowerer::compileLetMutSet(const Keyword n, Node& x, const Page p, const bool is_result_unused) { if (const auto sym = x.constList()[1]; sym.nodeType() != NodeType::Symbol) buildAndThrowError(fmt::format("Expected a symbol, got a {}", typeToString(sym)), sym); @@ -557,17 +581,24 @@ namespace Ark::internal // put value before symbol id // starting at index = 2 because x is a (let|mut|set variable ...) node - for (std::size_t idx = 2, end = x.constList().size(); idx < end; ++idx) - compileExpression(x.list()[idx], p, false, false); + compileExpression(x.list()[2], p, false, false); if (n == Keyword::Let || n == Keyword::Mut) { page(p).emplace_back(STORE, i); m_locals_locator.addLocal(name); + + if (!is_result_unused) + page(p).emplace_back(LOAD_FAST_BY_INDEX, 0); } else + { page(p).emplace_back(SET_VAL, i); + if (!is_result_unused) + page(p).emplace_back(LOAD_FAST, i); + } + if (is_function) m_opened_vars.pop(); page(p).back().setSourceLocation(x.filename(), x.position().start.line); diff --git a/src/arkreactor/VM/Debugger.cpp b/src/arkreactor/VM/Debugger.cpp index b3f561406..08ae3d9dc 100644 --- a/src/arkreactor/VM/Debugger.cpp +++ b/src/arkreactor/VM/Debugger.cpp @@ -179,7 +179,7 @@ namespace Ark::internal if (limit > 0 && count > 0) { fmt::println(m_os, "scope size: {}", limit); - fmt::println(m_os, "index | id | type | value"); + fmt::println(m_os, "index | id | name | type | value"); std::size_t i = 0; do @@ -192,9 +192,10 @@ namespace Ark::internal fmt::println( m_os, - "{:>5} | {:3} | {:>9} | {}", + "{:>5} | {:3} | {:14} | {:>9} | {}", fmt::styled(limit - i - 1, color), fmt::styled(id, color), + fmt::styled(vm.m_state.m_symbols[id], color), fmt::styled(std::to_string(value.valueType()), color), fmt::styled(value.toString(vm, /* show_as_code= */ true), color)); ++i; @@ -257,7 +258,7 @@ namespace Ark::internal m_os, "dbg[{},{}]:{:0>3}{} ", fmt::format("pp:{}", fmt::styled(pp, m_colorize ? fmt::fg(fmt::color::green) : fmt::text_style())), - fmt::format("ip:{}", fmt::styled(ip, m_colorize ? fmt::fg(fmt::color::cyan) : fmt::text_style())), + fmt::format("ip:{}", fmt::styled(ip / 4, m_colorize ? fmt::fg(fmt::color::cyan) : fmt::text_style())), m_line_count, unfinished_block ? ":" : ">"); diff --git a/src/arkreactor/VM/VM.cpp b/src/arkreactor/VM/VM.cpp index 6f6733811..71dee2df2 100644 --- a/src/arkreactor/VM/VM.cpp +++ b/src/arkreactor/VM/VM.cpp @@ -920,7 +920,14 @@ namespace Ark ErrorKind::Index, fmt::format("pop! index ({}) out of range (list size: {})", idx, list->list().size())); + // Save the value we're removing to push it later. + // We need to save the value and push later because we're using a pointer to 'list', and pushing before erasing + // would overwrite values from the stack. + if (arg) + number = list->list()[static_cast(idx)]; list->list().erase(list->list().begin() + idx); + if (arg) + push(number, context); } DISPATCH(); } @@ -954,9 +961,17 @@ namespace Ark fmt::format("@= index ({}) out of range (indexable size: {})", idx, size)); if (list->valueType() == ValueType::List) + { list->list()[static_cast(idx)] = new_value; + if (arg) + push(new_value, context); + } else + { list->stringRef()[static_cast(idx)] = new_value.string()[0]; + if (arg) + push(Value(new_value.string()[0]), context); + } } DISPATCH(); } @@ -1016,9 +1031,17 @@ namespace Ark fmt::format("@@= index (x: {}) out of range (inner indexable size: {})", idx_x, size)); if (is_list) + { list->list()[static_cast(idx_y)].list()[static_cast(idx_x)] = new_value; + if (arg) + push(new_value, context); + } else + { list->list()[static_cast(idx_y)].stringRef()[static_cast(idx_x)] = new_value.string()[0]; + if (arg) + push(Value(new_value.string()[0]), context); + } } DISPATCH(); } diff --git a/tests/benchmarks/compare.py b/tests/benchmarks/compare.py index cda25992d..6ce013b37 100644 --- a/tests/benchmarks/compare.py +++ b/tests/benchmarks/compare.py @@ -127,24 +127,26 @@ def main(files: List[str]): runs_by_name[run.name].append(run) data = [] - times = colorize_time_type("real_time", 0) + "\n" + colorize_time_type("cpu_time", 1) - for (name, runs) in runs_by_name.items(): + for i, (name, runs) in enumerate(runs_by_name.items()): baseline: Run = runs[0] baseline_index = headers.index(baseline.benchmark) - 2 diffs = [r.diff_from_baseline(baseline) for r in runs[1:]] padding = ["" for _ in range(baseline_index)] if baseline_index > 0 else [] data.append( - [name, times] + + [ + colorize_time_type(name, i % 2), + colorize_time_type("real_time", i % 2) + "\n" + colorize_time_type("cpu_time", i % 2) + ] + padding + [ - colorize_time_type(f"{baseline.real_time:.3f}{baseline.time_unit}", 0) + "\n" + - colorize_time_type(f"{baseline.cpu_time:.3f}{baseline.time_unit}", 1) + colorize_time_type(f"{baseline.real_time:.3f}{baseline.time_unit}", i % 2) + "\n" + + colorize_time_type(f"{baseline.cpu_time:.3f}{baseline.time_unit}", i % 2) ] + [ - f"{colorize_time_type(diff.dt_real_time, 0)} ({colorize_diff(diff.dt_rt_percent)}%)\n" + - f"{colorize_time_type(diff.dt_cpu_time, 1)} ({colorize_diff(diff.dt_ct_percent)}%)" + f"{colorize_time_type(diff.dt_real_time, i % 2)} ({colorize_diff(diff.dt_rt_percent)}%)\n" + + f"{colorize_time_type(diff.dt_cpu_time, i % 2)} ({colorize_diff(diff.dt_ct_percent)}%)" for diff in diffs ] diff --git a/tests/benchmarks/results/013-74e64c67.csv b/tests/benchmarks/results/013-74e64c67.csv new file mode 100644 index 000000000..2f178694c --- /dev/null +++ b/tests/benchmarks/results/013-74e64c67.csv @@ -0,0 +1,11 @@ +name,iterations,real_time,cpu_time,time_unit,bytes_per_second,items_per_second,label,error_occurred,error_message +"quicksort",7431,0.0933847,0.0930486,ms,,,,, +"ackermann/iterations:50",50,32.3309,32.1861,ms,,,,, +"fibonacci/iterations:100",100,3.16125,3.14818,ms,,,,, +"builtins",1205,0.581715,0.580722,ms,,,,, +"binary_trees",1,855.337,853.891,ms,,,,, +"for_sum",8,88.2647,88.0911,ms,,,,, +"create_closure/iterations:500",500,0.771819,0.770728,ms,,,,, +"create_list/iterations:500",500,1.7033,1.70064,ms,,,,, +"create_list_with_ref/iterations:500",500,1.46902,1.46652,ms,,,,, +"n_queens/iterations:50",50,13.0718,13.0555,ms,,,,, diff --git a/tests/unittests/Suites/BytecodeReaderSuite.cpp b/tests/unittests/Suites/BytecodeReaderSuite.cpp index 1d4552f9f..158cab7f0 100644 --- a/tests/unittests/Suites/BytecodeReaderSuite.cpp +++ b/tests/unittests/Suites/BytecodeReaderSuite.cpp @@ -121,7 +121,7 @@ ut::suite<"BytecodeReader"> bcr_suite = [] { should("list all code page") = [inst_locations_block, pages, start_code] { expect(that % start_code == inst_locations_block.end); expect(that % pages.size() == 2ull); - expect(that % pages[0].size() == 9 * 4ull); + expect(that % pages[0].size() == 10 * 4ull); expect(that % pages[1].size() == 20 * 4ull); }; }; diff --git a/tests/unittests/Suites/DebuggerSuite.cpp b/tests/unittests/Suites/DebuggerSuite.cpp index 57a9369bf..4c72bfbf3 100644 --- a/tests/unittests/Suites/DebuggerSuite.cpp +++ b/tests/unittests/Suites/DebuggerSuite.cpp @@ -33,19 +33,18 @@ ut::suite<"Debugger"> debugger_suite = [] { std::filesystem::path prompt_path(data.path); prompt_path.replace_extension("prompt"); - try - { - Ark::VM vm(state); - vm.usePromptFileForDebugger(prompt_path.generic_string(), os); - vm.run(/* fail_with_exception= */ false); - - const std::string output = sanitizeOutput(os.str()); - expectOrDiff(data.expected, output); - } - catch (const std::exception&) - { - expect(false); - } + expect( + nothrow( + [&] { + Ark::VM vm(state); + vm.usePromptFileForDebugger(prompt_path.generic_string(), os); + vm.run(/* fail_with_exception= */ false); + + const std::string output = sanitizeOutput(os.str()); + expectOrDiff(data.expected, output); + if (shouldWriteNewDiffsTofile() && data.expected != output) + updateExpectedFile(data, output); + })); }; }); }; diff --git a/tests/unittests/Suites/DiagnosticsSuite.cpp b/tests/unittests/Suites/DiagnosticsSuite.cpp index 59b198753..4410d23b6 100644 --- a/tests/unittests/Suites/DiagnosticsSuite.cpp +++ b/tests/unittests/Suites/DiagnosticsSuite.cpp @@ -38,9 +38,11 @@ ut::suite<"Diagnostics"> diagnostics_suite = [] { "DiagnosticsSuite/runtime", [](TestData&& data) { Ark::State state({ lib_path }); + // custom output stream for warnings to hide them, we don't want to test them here + std::stringstream stream; should("compile without error runtime/" + data.stem) = [&] { - expect(mut(state).doFile(data.path, features)); + expect(mut(state).doFile(data.path, features, &stream)); }; should("generate an error at runtime in " + data.stem) = [&] { @@ -64,9 +66,11 @@ ut::suite<"Diagnostics"> diagnostics_suite = [] { "DiagnosticsSuite/typeChecking", [](TestData&& data) { Ark::State state({ lib_path }); + // custom output stream for warnings to hide them, we don't want to test them here + std::stringstream stream; should("compile without error typeChecking/" + data.stem) = [&] { - expect(mut(state).doFile(data.path, features)); + expect(mut(state).doFile(data.path, features, &stream)); }; should("generate an error at runtime (typeChecking) in " + data.stem) = [&] { diff --git a/tests/unittests/resources/CompilerSuite/ir/ackermann.expected b/tests/unittests/resources/CompilerSuite/ir/ackermann.expected index 819370742..3f276fd99 100644 --- a/tests/unittests/resources/CompilerSuite/ir/ackermann.expected +++ b/tests/unittests/resources/CompilerSuite/ir/ackermann.expected @@ -12,6 +12,7 @@ page_0 BUILTIN 9 CALL 2 .L5: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/CompilerSuite/ir/args_attr.expected b/tests/unittests/resources/CompilerSuite/ir/args_attr.expected index c06f3200e..9480a291e 100644 --- a/tests/unittests/resources/CompilerSuite/ir/args_attr.expected +++ b/tests/unittests/resources/CompilerSuite/ir/args_attr.expected @@ -16,6 +16,7 @@ page_0 BUILTIN 9 CALL 1 .L0: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/CompilerSuite/ir/breakpoints.expected b/tests/unittests/resources/CompilerSuite/ir/breakpoints.expected index 135bdc001..1dfa6ed32 100644 --- a/tests/unittests/resources/CompilerSuite/ir/breakpoints.expected +++ b/tests/unittests/resources/CompilerSuite/ir/breakpoints.expected @@ -50,6 +50,7 @@ page_0 LOAD_FAST_BY_INDEX 0 CALL 0 .L9: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/CompilerSuite/ir/closures.expected b/tests/unittests/resources/CompilerSuite/ir/closures.expected index 0bf9b580f..956b92e51 100644 --- a/tests/unittests/resources/CompilerSuite/ir/closures.expected +++ b/tests/unittests/resources/CompilerSuite/ir/closures.expected @@ -91,6 +91,7 @@ page_0 BUILTIN 9 CALL 2 .L12: + POP 0 HALT 0 page_1 @@ -111,6 +112,7 @@ page_2 STORE 5 LOAD_FAST_BY_INDEX 0 SET_VAL 2 + LOAD_FAST 2 RET 0 HALT 0 diff --git a/tests/unittests/resources/CompilerSuite/ir/factorial.expected b/tests/unittests/resources/CompilerSuite/ir/factorial.expected index 948b695ea..6beab98b9 100644 --- a/tests/unittests/resources/CompilerSuite/ir/factorial.expected +++ b/tests/unittests/resources/CompilerSuite/ir/factorial.expected @@ -11,6 +11,7 @@ page_0 BUILTIN 9 CALL 2 .L2: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/CompilerSuite/ir/operators.expected b/tests/unittests/resources/CompilerSuite/ir/operators.expected index 50a286510..9d3505c00 100644 --- a/tests/unittests/resources/CompilerSuite/ir/operators.expected +++ b/tests/unittests/resources/CompilerSuite/ir/operators.expected @@ -69,4 +69,5 @@ page_0 BUILTIN 9 CALL 22 .L0: - HALT 0 \ No newline at end of file + POP 0 + HALT 0 diff --git a/tests/unittests/resources/CompilerSuite/ir/operators_as_builtins.expected b/tests/unittests/resources/CompilerSuite/ir/operators_as_builtins.expected index a82a0c73d..0662b4151 100644 --- a/tests/unittests/resources/CompilerSuite/ir/operators_as_builtins.expected +++ b/tests/unittests/resources/CompilerSuite/ir/operators_as_builtins.expected @@ -25,4 +25,5 @@ page_0 BUILTIN 9 CALL 22 .L0: + POP 0 HALT 0 diff --git a/tests/unittests/resources/CompilerSuite/ir/plugin.expected b/tests/unittests/resources/CompilerSuite/ir/plugin.expected index 4932688a2..a1b7d256b 100644 --- a/tests/unittests/resources/CompilerSuite/ir/plugin.expected +++ b/tests/unittests/resources/CompilerSuite/ir/plugin.expected @@ -12,4 +12,5 @@ page_0 BUILTIN 26 CALL 2 .L0: + POP 0 HALT 0 diff --git a/tests/unittests/resources/CompilerSuite/ir/renamed_capture.expected b/tests/unittests/resources/CompilerSuite/ir/renamed_capture.expected index 174937145..9768b32f3 100644 --- a/tests/unittests/resources/CompilerSuite/ir/renamed_capture.expected +++ b/tests/unittests/resources/CompilerSuite/ir/renamed_capture.expected @@ -10,6 +10,7 @@ page_0 BUILTIN 9 CALL 1 .L0: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/CompilerSuite/ir/tail_call.expected b/tests/unittests/resources/CompilerSuite/ir/tail_call.expected index c75fc5380..ee62ce3ff 100644 --- a/tests/unittests/resources/CompilerSuite/ir/tail_call.expected +++ b/tests/unittests/resources/CompilerSuite/ir/tail_call.expected @@ -7,6 +7,7 @@ page_0 LOAD_FAST_BY_INDEX 0 CALL 2 .L3: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/CompilerSuite/optimized_ir/ackermann.expected b/tests/unittests/resources/CompilerSuite/optimized_ir/ackermann.expected index 1e3879805..3b2828080 100644 --- a/tests/unittests/resources/CompilerSuite/optimized_ir/ackermann.expected +++ b/tests/unittests/resources/CompilerSuite/optimized_ir/ackermann.expected @@ -9,6 +9,7 @@ page_0 LOAD_CONST 5 CALL_BUILTIN 9, 2 .L5: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/CompilerSuite/optimized_ir/call_builtin_not_optimized.expected b/tests/unittests/resources/CompilerSuite/optimized_ir/call_builtin_not_optimized.expected index 5b095f44a..61340c32e 100644 --- a/tests/unittests/resources/CompilerSuite/optimized_ir/call_builtin_not_optimized.expected +++ b/tests/unittests/resources/CompilerSuite/optimized_ir/call_builtin_not_optimized.expected @@ -12,6 +12,7 @@ page_0 LOAD_FAST_BY_INDEX 0 CALL 1 .L3: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/CompilerSuite/optimized_ir/closures.expected b/tests/unittests/resources/CompilerSuite/optimized_ir/closures.expected index 176d1d18d..338714ebc 100644 --- a/tests/unittests/resources/CompilerSuite/optimized_ir/closures.expected +++ b/tests/unittests/resources/CompilerSuite/optimized_ir/closures.expected @@ -69,6 +69,7 @@ page_1 page_2 STORE 5 SET_VAL_FROM_INDEX 0, 2 + LOAD_FAST 2 RET 0 HALT 0 diff --git a/tests/unittests/resources/CompilerSuite/optimized_ir/factorial.expected b/tests/unittests/resources/CompilerSuite/optimized_ir/factorial.expected index ad4c4c66c..5961d1ee6 100644 --- a/tests/unittests/resources/CompilerSuite/optimized_ir/factorial.expected +++ b/tests/unittests/resources/CompilerSuite/optimized_ir/factorial.expected @@ -9,6 +9,7 @@ page_0 LOAD_CONST 4 CALL_BUILTIN 9, 2 .L2: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/CompilerSuite/optimized_ir/fused_math_ops.expected b/tests/unittests/resources/CompilerSuite/optimized_ir/fused_math_ops.expected index 5b21085d7..26bcca486 100644 --- a/tests/unittests/resources/CompilerSuite/optimized_ir/fused_math_ops.expected +++ b/tests/unittests/resources/CompilerSuite/optimized_ir/fused_math_ops.expected @@ -391,4 +391,5 @@ page_0 LIST 80 CALL_BUILTIN 9, 1 .L0: + POP 0 HALT 0 diff --git a/tests/unittests/resources/CompilerSuite/optimized_ir/lists.ark b/tests/unittests/resources/CompilerSuite/optimized_ir/lists.ark index 6a5a0b4d4..ee8fb4e64 100644 --- a/tests/unittests/resources/CompilerSuite/optimized_ir/lists.ark +++ b/tests/unittests/resources/CompilerSuite/optimized_ir/lists.ark @@ -20,6 +20,15 @@ # APPEND_IN_PLACE_SYM (append! source 6) + # APPEND_IN_PLACE_SYM + # + LOAD_FAST + (print (append! source 6)) + + # CONCAT_IN_PLACE + (concat! source [7]) + # CONCAT_IN_PLACE + # + LOAD_FAST + (print (concat! source [7])) # AT_SYM_SYM (@ source n) })) diff --git a/tests/unittests/resources/CompilerSuite/optimized_ir/lists.expected b/tests/unittests/resources/CompilerSuite/optimized_ir/lists.expected index 7521508a7..53dcdc194 100644 --- a/tests/unittests/resources/CompilerSuite/optimized_ir/lists.expected +++ b/tests/unittests/resources/CompilerSuite/optimized_ir/lists.expected @@ -5,16 +5,16 @@ page_0 STORE_LEN 0, 1 LOAD_CONST_STORE 3, 2 LOAD_CONST_STORE 4, 3 - PUSH_RETURN_ADDRESS L0 + PUSH_RETURN_ADDRESS L2 LOAD_FAST_BY_INDEX 0 CALL 0 -.L0: +.L2: POP 0 STORE_HEAD_BY_INDEX 3, 7 - PUSH_RETURN_ADDRESS L1 + PUSH_RETURN_ADDRESS L3 LOAD_FAST_BY_INDEX 0 CALL_BUILTIN 9, 1 -.L1: +.L3: POP 0 STORE_TAIL_BY_INDEX 4, 8 STORE_FROM_INDEX 5, 9 @@ -24,7 +24,7 @@ page_0 POP 0 AT_SYM_INDEX_CONST 6, 2 POP 0 - LOAD_CONST 6 + LOAD_CONST 7 APPEND_IN_PLACE_SYM_INDEX 1, 1 HALT 0 @@ -36,6 +36,26 @@ page_1 SET_VAL_TAIL 0, 6 LOAD_CONST 5 APPEND_IN_PLACE_SYM 0, 1 + PUSH_RETURN_ADDRESS L0 + LOAD_CONST 5 + APPEND_IN_PLACE_SYM 0, 1 + LOAD_FAST 0 + CALL_BUILTIN 9, 1 +.L0: + POP 0 + LOAD_CONST 6 + LIST 1 + LOAD_FAST 0 + CONCAT_IN_PLACE 1 + PUSH_RETURN_ADDRESS L1 + LOAD_CONST 6 + LIST 1 + LOAD_FAST 0 + CONCAT_IN_PLACE 1 + LOAD_FAST 0 + CALL_BUILTIN 9, 1 +.L1: + POP 0 AT_SYM_SYM 0, 2 RET 0 HALT 0 diff --git a/tests/unittests/resources/CompilerSuite/optimized_ir/mul.expected b/tests/unittests/resources/CompilerSuite/optimized_ir/mul.expected index 4f7bcedc9..c29fe0055 100644 --- a/tests/unittests/resources/CompilerSuite/optimized_ir/mul.expected +++ b/tests/unittests/resources/CompilerSuite/optimized_ir/mul.expected @@ -9,6 +9,7 @@ page_0 LOAD_FAST_BY_INDEX 0 CALL 0 .L0: + POP 0 HALT 0 page_1 @@ -18,5 +19,6 @@ page_1 STORE 2 MUL_SET_VAL 0, 2056 MUL_SET_VAL 0, 2056 + LOAD_FAST 0 RET 0 HALT 0 diff --git a/tests/unittests/resources/CompilerSuite/optimized_ir/type.expected b/tests/unittests/resources/CompilerSuite/optimized_ir/type.expected index ad5810875..90aafdf62 100644 --- a/tests/unittests/resources/CompilerSuite/optimized_ir/type.expected +++ b/tests/unittests/resources/CompilerSuite/optimized_ir/type.expected @@ -25,6 +25,7 @@ page_0 LOAD_FAST_BY_INDEX 0 CALL 0 .L12: + POP 0 HALT 0 page_1 diff --git a/tests/unittests/resources/DebuggerSuite/basic.expected b/tests/unittests/resources/DebuggerSuite/basic.expected index 90fe228bc..cc189307c 100644 --- a/tests/unittests/resources/DebuggerSuite/basic.expected +++ b/tests/unittests/resources/DebuggerSuite/basic.expected @@ -6,11 +6,10 @@ In file tests/unittests/resources/DebuggerSuite/basic.ark:3 4 | (prn (format "ark: after first breakpoint, a={}, b={}" a b)) 5 | -dbg[pp:0,ip:12]:000> (let c (+ a b)) -dbg[pp:0,ip:12]:001> (prn c) +dbg[pp:0,ip:3]:000> (let c (+ a b)) +dbg[pp:0,ip:3]:001> (prn c) 11 -nil -dbg[pp:0,ip:12]:002> c +dbg[pp:0,ip:3]:002> c dbg: continue ark: after first breakpoint, a=5, b=6 @@ -23,17 +22,16 @@ In file tests/unittests/resources/DebuggerSuite/basic.ark:7 8 | (prn "ark: in (foo x y z), after second breakpoint") 9 | (+ x y z) })) -dbg[pp:1,ip:20]:000> (prn x y z) +dbg[pp:1,ip:5]:000> (prn x y z) 567 -nil -dbg[pp:1,ip:20]:001> help +dbg[pp:1,ip:5]:001> help Available commands: help -- display this message c, continue -- resume execution q, quit -- quit the debugger, stopping the script execution stack -- show the last n values on the stack locals -- show the last n values on the locals' stack -dbg[pp:1,ip:20]:001> continue +dbg[pp:1,ip:5]:001> continue dbg: continue ark: in (foo x y z), after second breakpoint 18 diff --git a/tests/unittests/resources/DebuggerSuite/debugger_quit.expected b/tests/unittests/resources/DebuggerSuite/debugger_quit.expected index 0adb73182..2b35cc5e3 100644 --- a/tests/unittests/resources/DebuggerSuite/debugger_quit.expected +++ b/tests/unittests/resources/DebuggerSuite/debugger_quit.expected @@ -6,9 +6,8 @@ In file tests/unittests/resources/DebuggerSuite/debugger_quit.ark:3 4 | (prn (format "ark: after first breakpoint, a={}, b={}" a b)) 5 | -dbg[pp:0,ip:12]:000> (let c (+ a b)) -dbg[pp:0,ip:12]:001> (prn c) +dbg[pp:0,ip:3]:000> (let c (+ a b)) +dbg[pp:0,ip:3]:001> (prn c) 11 -nil -dbg[pp:0,ip:12]:002> q +dbg[pp:0,ip:3]:002> q dbg: stop diff --git a/tests/unittests/resources/DebuggerSuite/loop.expected b/tests/unittests/resources/DebuggerSuite/loop.expected index 424086953..b6bfc2f26 100644 --- a/tests/unittests/resources/DebuggerSuite/loop.expected +++ b/tests/unittests/resources/DebuggerSuite/loop.expected @@ -13,10 +13,9 @@ In file tests/unittests/resources/DebuggerSuite/loop.ark:3 4 | (prn (format "ark: i={}" i)) 5 | (set i (+ 1 i)) }) -dbg[pp:0,ip:32]:000> (prn i) +dbg[pp:0,ip:8]:000> (prn i) 6 -nil -dbg[pp:0,ip:32]:001> c +dbg[pp:0,ip:8]:001> c dbg: continue ark: i=6 @@ -28,10 +27,9 @@ In file tests/unittests/resources/DebuggerSuite/loop.ark:3 4 | (prn (format "ark: i={}" i)) 5 | (set i (+ 1 i)) }) -dbg[pp:0,ip:32]:000> (prn i) +dbg[pp:0,ip:8]:000> (prn i) 7 -nil -dbg[pp:0,ip:32]:001> c +dbg[pp:0,ip:8]:001> c dbg: continue ark: i=7 @@ -43,10 +41,9 @@ In file tests/unittests/resources/DebuggerSuite/loop.ark:3 4 | (prn (format "ark: i={}" i)) 5 | (set i (+ 1 i)) }) -dbg[pp:0,ip:32]:000> (prn i) +dbg[pp:0,ip:8]:000> (prn i) 8 -nil -dbg[pp:0,ip:32]:001> c +dbg[pp:0,ip:8]:001> c dbg: continue ark: i=8 @@ -58,10 +55,9 @@ In file tests/unittests/resources/DebuggerSuite/loop.ark:3 4 | (prn (format "ark: i={}" i)) 5 | (set i (+ 1 i)) }) -dbg[pp:0,ip:32]:000> (prn i) +dbg[pp:0,ip:8]:000> (prn i) 9 -nil -dbg[pp:0,ip:32]:001> c +dbg[pp:0,ip:8]:001> c dbg: continue ark: i=9 ark: end diff --git a/tests/unittests/resources/DebuggerSuite/modify_program_state.expected b/tests/unittests/resources/DebuggerSuite/modify_program_state.expected index 75dc4b45d..2c83d8ce8 100644 --- a/tests/unittests/resources/DebuggerSuite/modify_program_state.expected +++ b/tests/unittests/resources/DebuggerSuite/modify_program_state.expected @@ -13,10 +13,9 @@ In file tests/unittests/resources/DebuggerSuite/modify_program_state.ark:3 4 | (prn (format "ark: i={}" i)) 5 | (set i (+ 1 i)) }) -dbg[pp:0,ip:32]:000> (prn i) +dbg[pp:0,ip:8]:000> (prn i) 6 -nil -dbg[pp:0,ip:32]:001> c +dbg[pp:0,ip:8]:001> c dbg: continue ark: i=6 @@ -28,8 +27,8 @@ In file tests/unittests/resources/DebuggerSuite/modify_program_state.ark:3 4 | (prn (format "ark: i={}" i)) 5 | (set i (+ 1 i)) }) -dbg[pp:0,ip:32]:000> (set i 20) -dbg[pp:0,ip:32]:001> c +dbg[pp:0,ip:8]:000> (set i 20) +dbg[pp:0,ip:8]:001> c dbg: continue ark: i=20 ark: end diff --git a/tests/unittests/resources/DebuggerSuite/on_error.expected b/tests/unittests/resources/DebuggerSuite/on_error.expected index e70e1a9c0..db0686aff 100644 --- a/tests/unittests/resources/DebuggerSuite/on_error.expected +++ b/tests/unittests/resources/DebuggerSuite/on_error.expected @@ -1,8 +1,6 @@ -dbg[pp:0,ip:12]:000> (prn a) +dbg[pp:0,ip:3]:000> (prn a) 5 -nil -dbg[pp:0,ip:12]:001> (prn (type a)) +dbg[pp:0,ip:3]:001> (prn (type a)) Number -nil -dbg[pp:0,ip:12]:002> c +dbg[pp:0,ip:3]:002> c dbg: continue diff --git a/tests/unittests/resources/DebuggerSuite/stack_and_locals.expected b/tests/unittests/resources/DebuggerSuite/stack_and_locals.expected index f960fb2e3..4dc361ae9 100644 --- a/tests/unittests/resources/DebuggerSuite/stack_and_locals.expected +++ b/tests/unittests/resources/DebuggerSuite/stack_and_locals.expected @@ -7,16 +7,16 @@ In file tests/unittests/resources/DebuggerSuite/stack_and_locals.ark:8 9 | (prn (f 1 2)) 10 | -dbg[pp:0,ip:8]:000> stack +dbg[pp:0,ip:2]:000> stack Stack is empty -dbg[pp:0,ip:8]:000> locals +dbg[pp:0,ip:2]:000> locals scope size: 2 -index | id | type | value - 1 | 0 | Function | Function@1 - 0 | 4 | CProc | CProcedure +index | id | name | type | value + 1 | 0 | f | Function | Function@1 + 0 | 4 | prn | CProc | CProcedure -dbg[pp:0,ip:8]:000> c +dbg[pp:0,ip:2]:000> c dbg: continue In file tests/unittests/resources/DebuggerSuite/stack_and_locals.ark:3 @@ -27,38 +27,38 @@ In file tests/unittests/resources/DebuggerSuite/stack_and_locals.ark:3 4 | (if (= 1 a) 5 | (f "correct" "wrong") -dbg[pp:1,ip:16]:000> stack +dbg[pp:1,ip:4]:000> stack 3 -> Instruction@28 2 -> Function@0 1 -> Instruction@32 0 -> Function@0 -dbg[pp:1,ip:16]:000> locals 1 +dbg[pp:1,ip:4]:000> locals 1 scope size: 3 -index | id | type | value - 2 | 3 | Number | 1 +index | id | name | type | value + 2 | 3 | x | Number | 1 -dbg[pp:1,ip:16]:000> locals 2 +dbg[pp:1,ip:4]:000> locals 2 scope size: 3 -index | id | type | value - 2 | 3 | Number | 1 - 1 | 2 | Number | 2 +index | id | name | type | value + 2 | 3 | x | Number | 1 + 1 | 2 | b | Number | 2 -dbg[pp:1,ip:16]:000> locals 3 +dbg[pp:1,ip:4]:000> locals 3 scope size: 3 -index | id | type | value - 2 | 3 | Number | 1 - 1 | 2 | Number | 2 - 0 | 1 | Number | 1 +index | id | name | type | value + 2 | 3 | x | Number | 1 + 1 | 2 | b | Number | 2 + 0 | 1 | a | Number | 1 -dbg[pp:1,ip:16]:000> locals +dbg[pp:1,ip:4]:000> locals scope size: 3 -index | id | type | value - 2 | 3 | Number | 1 - 1 | 2 | Number | 2 - 0 | 1 | Number | 1 +index | id | name | type | value + 2 | 3 | x | Number | 1 + 1 | 2 | b | Number | 2 + 0 | 1 | a | Number | 1 -dbg[pp:1,ip:16]:000> c +dbg[pp:1,ip:4]:000> c dbg: continue In file tests/unittests/resources/DebuggerSuite/stack_and_locals.ark:3 @@ -69,19 +69,19 @@ In file tests/unittests/resources/DebuggerSuite/stack_and_locals.ark:3 4 | (if (= 1 a) 5 | (f "correct" "wrong") -dbg[pp:1,ip:16]:000> stack +dbg[pp:1,ip:4]:000> stack 3 -> Instruction@28 2 -> Function@0 1 -> Instruction@32 0 -> Function@0 -dbg[pp:1,ip:16]:000> locals +dbg[pp:1,ip:4]:000> locals scope size: 3 -index | id | type | value - 2 | 3 | String | "correct" - 1 | 2 | String | "wrong" - 0 | 1 | String | "correct" +index | id | name | type | value + 2 | 3 | x | String | "correct" + 1 | 2 | b | String | "wrong" + 0 | 1 | a | String | "correct" -dbg[pp:1,ip:16]:000> c +dbg[pp:1,ip:4]:000> c dbg: continue correct diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/apply_invalid_node.ark b/tests/unittests/resources/DiagnosticsSuite/compileTime/apply_invalid_node.ark index 182d88530..bed97acf5 100644 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/apply_invalid_node.ark +++ b/tests/unittests/resources/DiagnosticsSuite/compileTime/apply_invalid_node.ark @@ -1,2 +1,2 @@ (mut b []) -(apply print (append! b 5)) +(apply print (breakpoint)) diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/apply_invalid_node.expected b/tests/unittests/resources/DiagnosticsSuite/compileTime/apply_invalid_node.expected index db280353d..796f8c00d 100644 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/apply_invalid_node.expected +++ b/tests/unittests/resources/DiagnosticsSuite/compileTime/apply_invalid_node.expected @@ -1,6 +1,6 @@ In file tests/unittests/resources/DiagnosticsSuite/compileTime/apply_invalid_node.ark:2 1 | (mut b []) - 2 | (apply print (append! b 5)) - | ^~~~~~~~~~~~~ + 2 | (apply print (breakpoint)) + | ^~~~~~~~~~~~ 3 | Invalid node inside call to `apply'. The given node doesn't return a value, and thus can't be used as an expression. diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_breakpoint.ark b/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_breakpoint.ark new file mode 100644 index 000000000..a03603771 --- /dev/null +++ b/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_breakpoint.ark @@ -0,0 +1 @@ +((breakpoint) builtin__list:slice [] 1 1 2) diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_breakpoint.expected b/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_breakpoint.expected new file mode 100644 index 000000000..228dbfcab --- /dev/null +++ b/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_breakpoint.expected @@ -0,0 +1,5 @@ +In file tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_breakpoint.ark:1 + 1 | ((breakpoint) builtin__list:slice [] 1 1 2) + | ^~~~~~~~~~~~ + 2 | + Can not call `(breakpoint)', as it doesn't return a value diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_let.ark b/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_let.ark deleted file mode 100644 index 077cb83eb..000000000 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_let.ark +++ /dev/null @@ -1 +0,0 @@ -((let in (list 0 0 3 4 5)) builtin__list:slice in 1 1 2) diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_let.expected b/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_let.expected deleted file mode 100644 index ab99a2a1b..000000000 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_let.expected +++ /dev/null @@ -1,5 +0,0 @@ -In file tests/unittests/resources/DiagnosticsSuite/compileTime/can_not_call_let.ark:1 - 1 | ((let in (list 0 0 3 4 5)) builtin__list:slice in 1 1 2) - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ - 2 | - Can not call `(let in (list 0 0 3 4 5))', as it doesn't return a value diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/invalid_node_in_list.ark b/tests/unittests/resources/DiagnosticsSuite/compileTime/invalid_node_in_list.ark index 4384732e5..6ca4b6854 100644 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/invalid_node_in_list.ark +++ b/tests/unittests/resources/DiagnosticsSuite/compileTime/invalid_node_in_list.ark @@ -1 +1 @@ -[(mut c 1)] +[(breakpoint)] diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/invalid_node_in_list.expected b/tests/unittests/resources/DiagnosticsSuite/compileTime/invalid_node_in_list.expected index 6c22d23d3..4d4685075 100644 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/invalid_node_in_list.expected +++ b/tests/unittests/resources/DiagnosticsSuite/compileTime/invalid_node_in_list.expected @@ -1,5 +1,5 @@ In file tests/unittests/resources/DiagnosticsSuite/compileTime/invalid_node_in_list.ark:1 - 1 | [(mut c 1)] - | ^~~~~~~~ + 1 | [(breakpoint)] + | ^~~~~~~~~~~~ 2 | Invalid node inside call to `list'. The given node doesn't return a value, and thus can't be used as an expression. diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_breakpoint.ark b/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_breakpoint.ark new file mode 100644 index 000000000..c2061b0df --- /dev/null +++ b/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_breakpoint.ark @@ -0,0 +1 @@ +(print (or 1 (breakpoint))) diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_breakpoint.expected b/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_breakpoint.expected new file mode 100644 index 000000000..978b6ea4b --- /dev/null +++ b/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_breakpoint.expected @@ -0,0 +1,5 @@ +In file tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_breakpoint.ark:1 + 1 | (print (or 1 (breakpoint))) + | ^~~~~~~~~~~~ + 2 | + Can not use `(breakpoint)' inside a `or' expression, as it doesn't return a value diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_mut.ark b/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_mut.ark deleted file mode 100644 index 71ed4309f..000000000 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_mut.ark +++ /dev/null @@ -1 +0,0 @@ -(print (or 1 (mut x 3))) diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_mut.expected b/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_mut.expected deleted file mode 100644 index 7f7f68785..000000000 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_mut.expected +++ /dev/null @@ -1,5 +0,0 @@ -In file tests/unittests/resources/DiagnosticsSuite/compileTime/or_1_mut.ark:1 - 1 | (print (or 1 (mut x 3))) - | ^~~~~~~~ - 2 | - Can not use `(mut x 3)' inside a `or' expression, as it doesn't return a value diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_let_1.ark b/tests/unittests/resources/DiagnosticsSuite/compileTime/or_let_1.ark deleted file mode 100644 index e34b9f093..000000000 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_let_1.ark +++ /dev/null @@ -1 +0,0 @@ -(print (or (let x 1) 1)) diff --git a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_let_1.expected b/tests/unittests/resources/DiagnosticsSuite/compileTime/or_let_1.expected deleted file mode 100644 index e2b2637e7..000000000 --- a/tests/unittests/resources/DiagnosticsSuite/compileTime/or_let_1.expected +++ /dev/null @@ -1,5 +0,0 @@ -In file tests/unittests/resources/DiagnosticsSuite/compileTime/or_let_1.ark:1 - 1 | (print (or (let x 1) 1)) - | ^~~~~~~~ - 2 | - Can not use `(let x 1)' inside a `or' expression, as it doesn't return a value diff --git a/tests/unittests/resources/LangSuite/list-tests.ark b/tests/unittests/resources/LangSuite/list-tests.ark index a363d9a3c..93f0f0871 100644 --- a/tests/unittests/resources/LangSuite/list-tests.ark +++ b/tests/unittests/resources/LangSuite/list-tests.ark @@ -105,15 +105,15 @@ (test:case "in place mutation with @=" { (mut numbers [0 1 2 3 4]) - (@= numbers 2 5) - (@= numbers -1 9) + (test:eq (@= numbers 2 5) 5) + (test:eq (@= numbers -1 9) 9) (@= numbers -2 8) (test:eq numbers [0 1 5 8 9] "@=") }) (test:case "in place 2D mutation with @@=" { (mut numbers [[0 1 2 3] [4 5 6 7] [8 9 0 1]]) - (@@= numbers 0 0 9) - (@@= numbers 1 1 "a") + (test:eq (@@= numbers 0 0 9) 9) + (test:eq (@@= numbers 1 1 "a") "a") (@@= numbers -1 -1 -1) (@@= numbers -2 -2 -2) (test:eq numbers [[9 1 2 3] [4 "a" -2 7] [8 9 0 -1]]) }) @@ -121,14 +121,16 @@ (test:case "in place list mutation" { (mut c a) (mut d b) - (append! c 4) + (test:eq (append! c 4) [1 2 3 4]) (test:eq c [1 2 3 4]) - (concat! c d) + (test:eq (concat! c d) [1 2 3 4 4 5 6]) (test:eq c [1 2 3 4 4 5 6]) (test:eq d [4 5 6]) - (pop! c -1) + (test:eq (pop! c -1) 6) (test:eq c [1 2 3 4 4 5]) - (pop! c 1) + (test:eq (pop! c 1) 2) (test:eq c [1 3 4 4 5]) + (pop! c 0) + (test:eq c [3 4 4 5]) (test:eq a [1 2 3]) (test:eq b [4 5 6]) })}) diff --git a/tests/unittests/resources/LangSuite/vm-tests.ark b/tests/unittests/resources/LangSuite/vm-tests.ark index 5a8cb2531..7430b578a 100644 --- a/tests/unittests/resources/LangSuite/vm-tests.ark +++ b/tests/unittests/resources/LangSuite/vm-tests.ark @@ -28,7 +28,20 @@ (fun (&set-age &name &age) ()) })) (let bob (create-human "Bob" 38)) +(let egg (fun ((mut n)) + (set n n))) + (test:suite vm { + (test:case "assignments" { + (mut val (let x1 4)) + (test:eq val 4) + (set val (mut x2 5)) + (test:eq val 5) + (set val (set x2 6)) + (test:eq val 6) + (set val (egg 7)) + (test:eq val 7) }) + (test:case "arithmetic operations" { (test:eq (+ 1 2) 3) (test:eq (+ 1.5 2.5) 4.0) diff --git a/tests/unittests/resources/ParserSuite/success/compact.ark b/tests/unittests/resources/ParserSuite/success/compact.ark new file mode 100644 index 000000000..2f0ecbf8e --- /dev/null +++ b/tests/unittests/resources/ParserSuite/success/compact.ark @@ -0,0 +1,5 @@ +(+ 1a) +(- 2b) +(* 0c) +(print 1"hello"d) +(concat[1][2]) diff --git a/tests/unittests/resources/ParserSuite/success/compact.expected b/tests/unittests/resources/ParserSuite/success/compact.expected new file mode 100644 index 000000000..9a5a7d23e --- /dev/null +++ b/tests/unittests/resources/ParserSuite/success/compact.expected @@ -0,0 +1,5 @@ +( Symbol:+ Number:1 Symbol:a ) +( Symbol:- Number:2 Symbol:b ) +( Symbol:* Number:0 Symbol:c ) +( Symbol:print Number:1 String:hello Symbol:d ) +( Symbol:concat ( Symbol:list Number:1 ) ( Symbol:list Number:2 ) ) diff --git a/tools/repl.ark b/tools/repl.ark index 70093b7d7..e69de29bb 100644 --- a/tools/repl.ark +++ b/tools/repl.ark @@ -1,2 +0,0 @@ -(let foo (fun (a b) - (+ a b)))