Skip to content

Commit

Permalink
feat(macros): adding resolving 'empty?' as a macro when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFola committed Aug 31, 2024
1 parent ff04fd5 commit 9315ff4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- `$paste` to paste a node inside a maro without evaluating it further ; useful to stop recursive evaluation of nodes inside function macros
- introduced `Ark::internal::Pass` to describe compiler passes: they all output an AST (parser, import solver, macro processor, and optimizer for now)
- add `-f(no-)importsolver`, `-f(no-)macroprocessor` and `-f(no-)optimizer` to toggle on and off those compiler passes
- added resolving `empty?` as a macro when possible

### 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 4 files
+2 −2 README.md
+18 −20 Switch.ark
+49 −69 Testing.ark
+9 −8 tests/switch-tests.ark
15 changes: 15 additions & 0 deletions src/arkreactor/Compiler/Macros/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,21 @@ namespace Ark::internal
}
}
}
else if (name == "empty?")
{
if (node.list().size() > 2)
throwMacroProcessingError(fmt::format("When expanding `empty?' inside a macro, got {} arguments, expected 1", argcount), node);
if (Node& lst = node.list()[1]; lst.nodeType() == NodeType::List) // only apply len at compile time if we can
{
if (isConstEval(lst))
{
if (!lst.list().empty() && lst.list()[0] == getListNode())
setWithFileAttributes(node, node, lst.list().size() - 1 == 0 ? getTrueNode() : getFalseNode());
else
setWithFileAttributes(node, node, lst.list().size() == 0 ? getTrueNode() : getFalseNode());
}
}
}
else if (name == "@")
{
checkMacroArgCount(node, 2, "@");
Expand Down

0 comments on commit 9315ff4

Please sign in to comment.