Skip to content

Commit eae1735

Browse files
committed
fix(macro): $repr should be able to show the representation of a macro, when given one
1 parent ee657b6 commit eae1735

5 files changed

Lines changed: 27 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
### Changed
2727
- `$repr` shows the correct representation for macros
2828
- `$symcat` accepts symbols and strings as its first argument
29+
- `math:pow` uses a more precise way of computing values when inputs are integers
2930

3031
### Removed
3132

src/arkreactor/Compiler/Macros/Processor.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,15 @@ namespace Ark::internal
585585
checkMacroArgCountEq(node, 1, Language::Repr.data(), true);
586586

587587
const Node arg = node.constList()[1];
588-
node.updateValueAndType(Node(NodeType::String, arg.repr()));
588+
if (arg.nodeType() == NodeType::Symbol)
589+
{
590+
if (const Node* arg_as_macro = findNearestMacro(arg.string()); arg_as_macro != nullptr)
591+
node.updateValueAndType(Node(NodeType::String, arg_as_macro->repr()));
592+
else
593+
node.updateValueAndType(Node(NodeType::String, arg.repr()));
594+
}
595+
else
596+
node.updateValueAndType(Node(NodeType::String, arg.repr()));
589597
}
590598
else if (name == Language::AsIs)
591599
{

tests/unittests/resources/DiagnosticsSuite/runtime/backtrace_builtin.expected

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ Signature
66
Arguments
77
→ `list' (expected List), got "live" (String)
88

9-
In file /lib/std/List.ark:62
10-
59 | # (list:sort [4 2 3]) # [1 2 4]
11-
60 | # =end
12-
61 | # @author https://github.com/SuperFola
13-
62 | (let sort (fun (_L) (builtin__list:sort _L)))
9+
In file /lib/std/List.ark:63
10+
60 | # (list:sort [4 2 3]) # [1 2 4]
11+
61 | # =end
12+
62 | # @author https://github.com/SuperFola
13+
63 | (let sort (fun (_L) (builtin__list:sort _L)))
1414
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15-
63 |
16-
64 | # @brief Generate a List of n copies of an element
15+
64 |
16+
65 | # @brief Generate a List of n copies of an element
1717

18-
[ 2] In function `list:sort' (/lib/std/List.ark:62)
18+
[ 2] In function `list:sort' (/lib/std/List.ark:63)
1919
[ 1] In global scope (tests/unittests/resources/DiagnosticsSuite/runtime/backtrace_builtin.ark:3)
2020

2121
Current scope variables values:

tests/unittests/resources/LangSuite/macro-tests.ark

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,14 @@
130130
(test:case "builtin macros" {
131131
(macro nil-type ($type nil))
132132
(macro bool-type ($type true))
133-
(test:eq "Nil" nil-type)
134-
(test:eq "Bool" bool-type) })
133+
(macro show-repr (v) ($repr v))
134+
(test:eq nil-type "Nil")
135+
(test:eq bool-type "Bool")
136+
(test:eq (show-repr (macro a 5)) "(macro a 5)")
137+
# function macros are evaluated on instantiation
138+
(test:eq (show-repr show-repr) "(macro show-repr (v) ($repr v))")
139+
# constant macros are evaluated on declaration
140+
(test:eq (show-repr nil-type) "(macro nil-type \"Nil\")") })
135141

136142
(test:case "generate valid arkscript code with macros" {
137143
(macro make-func (retval) (fun () retval))

0 commit comments

Comments
 (0)