diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f0c2c1a7..77a9f9475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - check on number of arguments passed to `type` - warning when the formatter deletes comment(s) by mistake - check on arguments passed to `list`, `concat`, `append` and friends to only push valid nodes (that produces a value) +- `$paste` to paste a node inside a maro without evaluating it further ; useful to stop recursive evaluation of nodes inside function macros ### Changed - instructions are on 4 bytes: 1 byte for the instruction, 1 byte of padding, 2 bytes for an immediate argument diff --git a/lib/std b/lib/std index aae15fe5c..c579744df 160000 --- a/lib/std +++ b/lib/std @@ -1 +1 @@ -Subproject commit aae15fe5ca56e6b268068715aab79293a259a407 +Subproject commit c579744dfac36b2149d3c2ebeea917e3da6df738 diff --git a/src/arkreactor/Compiler/Macros/Processor.cpp b/src/arkreactor/Compiler/Macros/Processor.cpp index f1fd7082d..8d9d17d8b 100644 --- a/src/arkreactor/Compiler/Macros/Processor.cpp +++ b/src/arkreactor/Compiler/Macros/Processor.cpp @@ -27,7 +27,8 @@ namespace Ark::internal m_predefined_macros = { "symcat", "argcount", - "$repr" // TODO: unify predefined macro names (update documentation and examples and tests) + "$repr", // TODO: unify predefined macro names (update documentation and examples and tests) + "$paste" }; } @@ -483,6 +484,12 @@ namespace Ark::internal const Node ast = node.constList()[1]; setWithFileAttributes(node, node, Node(NodeType::String, ast.repr())); } + else if (name == "$paste") + { + if (node.list().size() != 2) + throwMacroProcessingError(fmt::format("When expanding `$paste', expected one argument, got {} arguments", argcount), node); + return node.constList()[1]; + } } if (node.nodeType() == NodeType::List && !node.constList().empty()) diff --git a/tests/arkscript/builtins-tests.ark b/tests/arkscript/builtins-tests.ark index f4737e7c6..f3632dc2d 100644 --- a/tests/arkscript/builtins-tests.ark +++ b/tests/arkscript/builtins-tests.ark @@ -20,17 +20,16 @@ (test:eq (list:sort [5]) [5]) (test:eq (list:sort []) []) - # fixme - #(let short_list (list:fill 12 nil)) - #(test:eq (len short_list) 12) - #(mut i 0) - #(while (< i 12) { - # (test:eq (@ short_list i) nil) - # (set i (+ 1 i))}) - #(del i) -# - #(test:eq (@ (list:setAt short_list 5 "a") 5) "a") - #(del short_list) + (let short_list (list:fill 12 nil)) + (test:eq (len short_list) 12) + (mut i 0) + (while (< i 12) { + (test:eq (@ short_list i) nil) + (set i (+ 1 i))}) + (del i) + + (test:eq (@ (list:setAt short_list 5 "a") 5) "a") + (del short_list) (test:expect (not (io:fileExists? "test.txt"))) (io:writeFile "test.txt" "hello, world!")