<commit_before>module Atomy
  module AST
    class Block < Rubinius::AST::Iter
      include NodeLike
      extend SentientNode

      children [:contents], [:arguments]
      generate

      def block_arguments
        BlockArguments.new @arguments
      end

      def block_body
        BlockBody.new @line, @contents
      end

      def body
        InlinedBody.new @line, @contents
      end

      alias :caller :body

      def bytecode(g)
        pos(g)

        state = g.state
        state.scope.nest_scope self

        blk = new_block_generator g, block_arguments

        blk.push_state self
        blk.state.push_super state.super
        blk.state.push_eval state.eval

        blk.state.push_name blk.name

        # Push line info down.
        pos(blk)

        block_arguments.bytecode(blk)

        blk.state.push_block
        blk.push_modifiers
        blk.break = nil
        blk.next = nil
        blk.redo = blk.new_label
        blk.redo.set!

        block_body.compile(blk)

        blk.pop_modifiers
        blk.state.pop_block
        blk.ret
        blk.close
        blk.pop_state

        blk.splat_index = block_arguments.splat_index
        blk.local_count = local_count
        blk.local_names = local_names

        g.create_block blk

        g.push_cpath_top
        g.find_const :Proc
        g.swap
        g.send :__from_block__, 1
      end

      def as_message(send)
        case send.receiver
        when Send
          if send.receiver.method_name == "[]"
            dup.tap do |b|
              b.arguments = send.receiver.arguments
            end.as_message(send.receiver)
          else
            send.receiver.dup.tap do |s|
              s.block = self
            end
          end
        when Variable, Unquote,
             Constant, ScopedConstant, ToplevelConstant
          send.receiver = send.receiver.to_send
          as_message(send)
        when List
          dup.tap do |b|
            b.arguments = send.receiver.elements
          end
        else
          unless send.method_name
            raise "unknown receiver for block: #{send.receiver.inspect}"
          end
        end
      end
    end

    class InlinedBody < Node
      children [:expressions]
      generate

      attr_accessor :parent

      def variables
        @variables ||= {}
      end

      def local_count
        @parent.local_names
      end

      def local_names
        @parent.local_names
      end

      def allocate_slot
        @parent.allocate_slot
      end

      def nest_scope(scope)
        scope.parent = self
      end

      def search_local(name)
        if variable = variables[name]
          variable.nested_reference
        else
          @parent.search_local(name)
        end<commit_msg>add #module? to InlinedBody<commit_after>module Atomy
  module AST
    class Block < Rubinius::AST::Iter
      include NodeLike
      extend SentientNode

      children [:contents], [:arguments]
      generate

      def block_arguments
        BlockArguments.new @arguments
      end

      def block_body
        BlockBody.new @line, @contents
      end

      def body
        InlinedBody.new @line, @contents
      end

      alias :caller :body

      def bytecode(g)
        pos(g)

        state = g.state
        state.scope.nest_scope self

        blk = new_block_generator g, block_arguments

        blk.push_state self
        blk.state.push_super state.super
        blk.state.push_eval state.eval

        blk.state.push_name blk.name

        # Push line info down.
        pos(blk)

        block_arguments.bytecode(blk)

        blk.state.push_block
        blk.push_modifiers
        blk.break = nil
        blk.next = nil
        blk.redo = blk.new_label
        blk.redo.set!

        block_body.compile(blk)

        blk.pop_modifiers
        blk.state.pop_block
        blk.ret
        blk.close
        blk.pop_state

        blk.splat_index = block_arguments.splat_index
        blk.local_count = local_count
        blk.local_names = local_names

        g.create_block blk

        g.push_cpath_top
        g.find_const :Proc
        g.swap
        g.send :__from_block__, 1
      end

      def as_message(send)
        case send.receiver
        when Send
          if send.receiver.method_name == "[]"
            dup.tap do |b|
              b.arguments = send.receiver.arguments
            end.as_message(send.receiver)
          else
            send.receiver.dup.tap do |s|
              s.block = self
            end
          end
        when Variable, Unquote,
             Constant, ScopedConstant, ToplevelConstant
          send.receiver = send.receiver.to_send
          as_message(send)
        when List
          dup.tap do |b|
            b.arguments = send.receiver.elements
          end
        else
          unless send.method_name
            raise "unknown receiver for block: #{send.receiver.inspect}"
          end
        end
      end
    end

    class InlinedBody < Node
      children [:expressions]
      generate

      attr_accessor :parent

      def variables
        @variables ||= {}
      end

      def local_count
        @parent.local_names
      end

      def local_names
        @parent.local_names
      end

      def allocate_slot
        @parent.allocate_slot
      end

      def nest_scope(scope)
        scope.parent = self
      end

      def module?
        @parent.module?
      end

      def search_local(name)
        if variable = variables[name]
          variable.nested_reference
        else
          @parent.search_local(name)
        end
{'fraction_non_alphanumeric': 0.06425129394966982, 'fraction_numerical': 0.0003569516330537212, 'mean_word_length': 1.5243243243243243, 'pattern_counts': {'":': 0, '<': 7, '<?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': '458950', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1580, 'n_words': 368}