irc: add ListNode support; fix recursive attrset scoping

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I1657bc6a05c264f0ae0dd2c94d32b1046a6a6964
This commit is contained in:
raf 2026-02-23 02:22:37 +03:00
commit 6612479286
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -1,5 +1,6 @@
#include "ir_gen.h" #include "ir_gen.h"
#include <algorithm> #include <algorithm>
#include <iostream>
#include <stack> #include <stack>
#include <unordered_map> #include <unordered_map>
@ -97,7 +98,8 @@ struct IRGenerator::Impl {
return std::make_shared<Node>(*n); return std::make_shared<Node>(*n);
} }
if (auto* n = node.get_if<VarNode>()) { if (auto* n = node.get_if<VarNode>()) {
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); VarNode converted(idx);
converted.name = n->name; converted.name = n->name;
converted.line = n->line; converted.line = n->line;
@ -121,12 +123,17 @@ struct IRGenerator::Impl {
} }
if (auto* n = node.get_if<AttrsetNode>()) { if (auto* n = node.get_if<AttrsetNode>()) {
AttrsetNode attrs(n->recursive, n->line); AttrsetNode attrs(n->recursive, n->line);
name_resolver.enter_scope();
for (const auto& binding : n->attrs) { // Only enter a new scope for recursive attrsets
if (!binding.is_dynamic()) { if (n->recursive) {
name_resolver.bind(binding.static_name.value()); 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) { for (const auto& binding : n->attrs) {
if (binding.is_dynamic()) { if (binding.is_dynamic()) {
attrs.attrs.push_back(AttrBinding(convert(binding.dynamic_name), convert(binding.value))); 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))); 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<Node>(attrs); return std::make_shared<Node>(attrs);
} }
if (auto* n = node.get_if<SelectNode>()) { if (auto* n = node.get_if<SelectNode>()) {
@ -208,6 +218,14 @@ struct IRGenerator::Impl {
auto operand = convert(n->operand); auto operand = convert(n->operand);
return std::make_shared<Node>(UnaryOpNode(n->op, operand, n->line)); return std::make_shared<Node>(UnaryOpNode(n->op, operand, n->line));
} }
if (auto* n = node.get_if<ListNode>()) {
std::vector<std::shared_ptr<Node>> elements;
elements.reserve(n->elements.size());
for (const auto& elem : n->elements) {
elements.push_back(convert(elem));
}
return std::make_shared<Node>(ListNode(std::move(elements), n->line));
}
return std::make_shared<Node>(ConstNullNode{}); return std::make_shared<Node>(ConstNullNode{});
} }
}; };