<commit_before># We monkeypatch Module to add support for Bloom's syntax additions: "state",
# "bloom", and "bootstrap" blocks, plus the "import" statement.
class Module
  # import another module and assign to a qualifier symbol: <tt>import MyModule => :m</tt>
  def import(spec)
    raise Bud::CompileError unless (spec.class <= Hash and spec.length == 1)
    mod, local_name = spec.first
    raise Bud::CompileError unless (mod.class <= Module and local_name.class <= Symbol)

    # Attempting to import a module that has already included the Bud module
    # results in problems (and is a bad idea anyway), so disallow it.
    if mod.included_modules.include? Bud
      raise Bud::CompileError, "cannot import #{mod} because it has already included Bud"
    end

    # To correctly expand qualified references to an imported module, we keep a
    # table with the local bind names of all the modules imported by this
    # module. To handle nested references (a.b.c.d etc.), the import table for
    # module X points to X's own nested import table.
    @bud_import_tbl ||= {}
    child_tbl = mod.bud_import_table
    raise Bud::CompileError, "import symbol #{local_name} already in use" if @bud_import_tbl.has_key? local_name
    @bud_import_tbl[local_name] = child_tbl.clone # XXX: clone needed?

    rewritten_mod_name = ModuleRewriter.do_import(self, mod, local_name)
    self.module_eval "include #{rewritten_mod_name}"
  end

  # the block of Bloom collection declarations.  one per module.
  def state(&block)
    meth_name = Module.make_state_meth_name(self)
    define_method(meth_name, &block)
  end<commit_msg>Minor code cleanup.<commit_after># We monkeypatch Module to add support for Bloom's syntax additions: "state",
# "bloom", and "bootstrap" blocks, plus the "import" statement.
class Module
  # import another module and assign to a qualifier symbol: <tt>import MyModule => :m</tt>
  def import(spec)
    raise Bud::CompileError unless (spec.class <= Hash and spec.length == 1)
    mod, local_name = spec.first
    raise Bud::CompileError unless (mod.class <= Module and local_name.class <= Symbol)

    # Attempting to import a module that has already included the Bud module
    # results in problems (and is a bad idea anyway), so disallow it.
    if mod.included_modules.include? Bud
      raise Bud::CompileError, "cannot import #{mod} because it has already included Bud"
    end

    # To correctly expand qualified references to an imported module, we keep a
    # table with the local bind names of all the modules imported by this
    # module. To handle nested references (a.b.c.d etc.), the import table for
    # module X points to X's own nested import table.
    @bud_import_tbl ||= {}
    if @bud_import_tbl.has_key? local_name
      raise Bud::CompileError, "import symbol #{local_name} already in use"
    end
    child_tbl = mod.bud_import_table
    @bud_import_tbl[local_name] = child_tbl.clone # XXX: clone needed?

    rewritten_mod_name = ModuleRewriter.do_import(self, mod, local_name)
    self.module_eval "include #{rewritten_mod_name}"
  end

  # the block of Bloom collection declarations.  one per module.
  def state(&block)
    meth_name = Module.make_state_meth_name(self)
    define_method(meth_name, &block)
  end
{'fraction_non_alphanumeric': 0.08537331701346389, 'fraction_numerical': 0.0006119951040391676, 'mean_word_length': 3.901049475262369, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '2321474', 'n_tokens_mistral': 973, 'n_tokens_neox': 928, 'n_words': 368}