brewery
notashelf /
e8fcaccacca58cacc6c7ad1e395da5d6d664fb51

nixir

public

Import-resolving Nix IR plugin

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/nixir.git

Commit e8fcaccacca5

tarball

NotAShelf <raf@notashelf.dev> · 2026-04-24 20:13 UTC

unverified1 files changed+24-6
irc: add ListNode support; fix recursive attrset scoping

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I1657bc6a05c264f0ae0dd2c94d32b1046a6a6964
diff --git a/src/irc/ir_gen.cpp b/src/irc/ir_gen.cppindex ff9f18c..90175f9 100644--- a/src/irc/ir_gen.cpp+++ b/src/irc/ir_gen.cpp@@ -1,5 +1,6 @@ #include "ir_gen.h" #include <algorithm>+#include <iostream> #include <stack> #include <unordered_map> @@ -97,7 +98,8 @@ struct IRGenerator::Impl {       return std::make_shared<Node>(*n);     }     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);       converted.name = n->name;       converted.line = n->line;@@ -121,12 +123,17 @@ struct IRGenerator::Impl {     }     if (auto* n = node.get_if<AttrsetNode>()) {       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<Node>(attrs);     }     if (auto* n = node.get_if<SelectNode>()) {@@ -208,6 +218,14 @@ struct IRGenerator::Impl {       auto operand = convert(n->operand);       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{});   } };