Skip to content

Commit

Permalink
Merge pull request #472 from ArkScript-lang/feat/stop-macro-evaluation
Browse files Browse the repository at this point in the history
feat(macro processor): adding $paste to stop node evalution inside macros
  • Loading branch information
SuperFola authored Jul 12, 2024
2 parents e53c837 + 166330c commit b0a639b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/std
Submodule std updated 1 files
+7 −7 Testing.ark
9 changes: 8 additions & 1 deletion src/arkreactor/Compiler/Macros/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};
}

Expand Down Expand Up @@ -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())
Expand Down
21 changes: 10 additions & 11 deletions tests/arkscript/builtins-tests.ark
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down

0 comments on commit b0a639b

Please sign in to comment.