Skip to content

Commit b0a639b

Browse files
authored
Merge pull request #472 from ArkScript-lang/feat/stop-macro-evaluation
feat(macro processor): adding $paste to stop node evalution inside macros
2 parents e53c837 + 166330c commit b0a639b

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- check on number of arguments passed to `type`
2020
- warning when the formatter deletes comment(s) by mistake
2121
- check on arguments passed to `list`, `concat`, `append` and friends to only push valid nodes (that produces a value)
22+
- `$paste` to paste a node inside a maro without evaluating it further ; useful to stop recursive evaluation of nodes inside function macros
2223

2324
### Changed
2425
- instructions are on 4 bytes: 1 byte for the instruction, 1 byte of padding, 2 bytes for an immediate argument

lib/std

Submodule std updated 1 file

src/arkreactor/Compiler/Macros/Processor.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ namespace Ark::internal
2727
m_predefined_macros = {
2828
"symcat",
2929
"argcount",
30-
"$repr" // TODO: unify predefined macro names (update documentation and examples and tests)
30+
"$repr", // TODO: unify predefined macro names (update documentation and examples and tests)
31+
"$paste"
3132
};
3233
}
3334

@@ -483,6 +484,12 @@ namespace Ark::internal
483484
const Node ast = node.constList()[1];
484485
setWithFileAttributes(node, node, Node(NodeType::String, ast.repr()));
485486
}
487+
else if (name == "$paste")
488+
{
489+
if (node.list().size() != 2)
490+
throwMacroProcessingError(fmt::format("When expanding `$paste', expected one argument, got {} arguments", argcount), node);
491+
return node.constList()[1];
492+
}
486493
}
487494

488495
if (node.nodeType() == NodeType::List && !node.constList().empty())

tests/arkscript/builtins-tests.ark

+10-11
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020
(test:eq (list:sort [5]) [5])
2121
(test:eq (list:sort []) [])
2222

23-
# fixme
24-
#(let short_list (list:fill 12 nil))
25-
#(test:eq (len short_list) 12)
26-
#(mut i 0)
27-
#(while (< i 12) {
28-
# (test:eq (@ short_list i) nil)
29-
# (set i (+ 1 i))})
30-
#(del i)
31-
#
32-
#(test:eq (@ (list:setAt short_list 5 "a") 5) "a")
33-
#(del short_list)
23+
(let short_list (list:fill 12 nil))
24+
(test:eq (len short_list) 12)
25+
(mut i 0)
26+
(while (< i 12) {
27+
(test:eq (@ short_list i) nil)
28+
(set i (+ 1 i))})
29+
(del i)
30+
31+
(test:eq (@ (list:setAt short_list 5 "a") 5) "a")
32+
(del short_list)
3433

3534
(test:expect (not (io:fileExists? "test.txt")))
3635
(io:writeFile "test.txt" "hello, world!")

0 commit comments

Comments
 (0)