From 6612479286cbaae87e8cafd2c7b6cbc177c39d27 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 23 Feb 2026 02:22:37 +0300 Subject: [PATCH] irc: add ListNode support; fix recursive attrset scoping Signed-off-by: NotAShelf Change-Id: I1657bc6a05c264f0ae0dd2c94d32b1046a6a6964 --- src/irc/ir_gen.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/irc/ir_gen.cpp b/src/irc/ir_gen.cpp index ff9f18c..90175f9 100644 --- a/src/irc/ir_gen.cpp +++ b/src/irc/ir_gen.cpp @@ -1,5 +1,6 @@ #include "ir_gen.h" #include +#include #include #include @@ -97,7 +98,8 @@ struct IRGenerator::Impl { return std::make_shared(*n); } if (auto* n = node.get_if()) { - uint32_t idx = name_resolver.resolve(n->name.value_or("")); + std::string var_name = n->name.value_or(""); + uint32_t idx = name_resolver.resolve(var_name); VarNode converted(idx); converted.name = n->name; converted.line = n->line; @@ -121,12 +123,17 @@ struct IRGenerator::Impl { } if (auto* n = node.get_if()) { AttrsetNode attrs(n->recursive, n->line); - name_resolver.enter_scope(); - for (const auto& binding : n->attrs) { - if (!binding.is_dynamic()) { - name_resolver.bind(binding.static_name.value()); + + // Only enter a new scope for recursive attrsets + if (n->recursive) { + name_resolver.enter_scope(); + for (const auto& binding : n->attrs) { + if (!binding.is_dynamic()) { + name_resolver.bind(binding.static_name.value()); + } } } + for (const auto& binding : n->attrs) { if (binding.is_dynamic()) { attrs.attrs.push_back(AttrBinding(convert(binding.dynamic_name), convert(binding.value))); @@ -134,7 +141,10 @@ struct IRGenerator::Impl { attrs.attrs.push_back(AttrBinding(binding.static_name.value(), convert(binding.value))); } } - name_resolver.exit_scope(); + + if (n->recursive) { + name_resolver.exit_scope(); + } return std::make_shared(attrs); } if (auto* n = node.get_if()) { @@ -208,6 +218,14 @@ struct IRGenerator::Impl { auto operand = convert(n->operand); return std::make_shared(UnaryOpNode(n->op, operand, n->line)); } + if (auto* n = node.get_if()) { + std::vector> elements; + elements.reserve(n->elements.size()); + for (const auto& elem : n->elements) { + elements.push_back(convert(elem)); + } + return std::make_shared(ListNode(std::move(elements), n->line)); + } return std::make_shared(ConstNullNode{}); } };