<commit_before>module Atomy::Macro
  module Helpers
    def variable(name, line = 0)
      Atomy::AST::Variable.new(line, name.to_s)
    end

    # generate symbols
    def names(num = 0, &block)
      num = block.arity if block

      as = []
      num.times do
        as << variable(
          "s:" + Atomy::Macro::Environment.salt!.to_s
        )
      end

      if block
        block.call(*as)
      else
        as
      end
    end
  end

  class Environment
    @@salt = 0
    @@macros = {}
    @@let = {}
    @@line = 0

    class << self
      def let
        @@let
      end

      def line
        @@line
      end

      def line=(x)
        @@line = x
      end

      def salt
        @@salt
      end

      def salt!(n = 1)
        @@salt += n
      end
    end
  end

  def self.intern(name, let_num = nil)
    "atomy-macro#{let_num ? "-let-#{let_num}" : ""}:" + name
  end

  def self.register(target, pattern, body, file = :macro, let = false)
    #ns = Atomy::Namespace.get(Thread.current[:atomy_define_in])
    #meth = !let && ns ? Atomy.namespaced(ns.name, name) : name

    name = let ? :"_let#{Environment.salt!}" : :_expand

    Atomy.define_method(
      target,
      name,
      pattern,
      Atomy::AST::Send.new(
        body.line,
        Atomy::AST::Send.new(
          body.line,
          body.prepare_all,
          [],
          "to_node"
        ),
        [],
        "expand"
      ),
      [],
      Rubinius::StaticScope.new(Atomy::AST),
      :public,
      file,
      pattern.expression.line
    )

    if let<commit_msg>lib/macro cleanups<commit_after>module Atomy::Macro
  module Helpers
    def variable(name, line = 0)
      Atomy::AST::Variable.new(line, name.to_s)
    end

    # generate symbols
    def names(num = 0, &block)
      num = block.arity if block

      as = []
      num.times do
        as << variable(
          "s:" + Atomy::Macro::Environment.salt!.to_s
        )
      end

      if block
        block.call(*as)
      else
        as
      end
    end
  end

  class Environment
    @@salt = 0
    @@let = {}

    class << self
      def let
        @@let
      end

      def salt
        @@salt
      end

      def salt!(n = 1)
        @@salt += n
      end
    end
  end

  def self.register(target, pattern, body, file = :macro, let = false)
    #ns = Atomy::Namespace.get(Thread.current[:atomy_define_in])
    #meth = !let && ns ? Atomy.namespaced(ns.name, name) : name

    name = let ? :"_let#{Environment.salt!}" : :_expand

    Atomy.define_method(
      target,
      name,
      pattern,
      Atomy::AST::Send.new(
        body.line,
        Atomy::AST::Send.new(
          body.line,
          body.prepare_all,
          [],
          "to_node"
        ),
        [],
        "expand"
      ),
      [],
      Rubinius::StaticScope.new(Atomy::AST),
      :public,
      file,
      pattern.expression.line
    )

    if let
{'fraction_non_alphanumeric': 0.13079299691040164, 'fraction_numerical': 0.003089598352214212, 'mean_word_length': 1.5674008810572688, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4065747', 'n_tokens_mistral': 1021, 'n_tokens_neox': 957, 'n_words': 214}