<commit_before>require_relative './shared_noautorun.rb'
require_relative '../compiler/compiler_noautorun.rb'

$autorun = true if $autorun.nil?

class InlineCompilerExit < RuntimeError
  attr_reader :code

  def initialize(code)
    super()
    @code = code
  end
end

class InlineCompilerContext
  attr_reader :stdin, :stdout, :stderr

  def initialize
    @stdin = StringIO.new
    @stdout = StringIO.new
    @stderr = StringIO.new
  end

  def exit(code)
    raise InlineCompilerExit.new(code)
  end
end

class AsmSpec
  def read_test_file(fname)
    base_read_test_file(fname)
  end

  def extract_format_source(input, output)
    describe_action(input, output, 'extract source') do
      text = read_test_file(input)[:code]
      File.open(output, 'wb') do |file|
        file << text
      end
    end
  end

  def compile(input, output, options)
    settings = options.split(' ') + [input]
    context = InlineCompilerContext.new
    settings = read_args!(settings)
    run_dab_compiler(settings, context)
    File.open(output, 'wb') { |f| f << context.stdout.string }
  rescue InlineCompilerExit
    raise SystemCommandError.new('Compile error', context.stderr.string)
  end

  def write_new_testspec(filename, data)
    string = ''
    data.each do |key, value|
      string += "## #{key.upcase}\n"
      string += "\n"
      string += value
      string += "\n"
      string += "\n"
    end
    File.open(filename, 'wb') do |file|
      file << string.strip
      file << "\n"
    end
  end

  def run_test(settings)
    input = settings[:input]<commit_msg>spec: add info how to manually run compilation for asm_spec<commit_after>require_relative './shared_noautorun.rb'
require_relative '../compiler/compiler_noautorun.rb'

$autorun = true if $autorun.nil?

class InlineCompilerExit < RuntimeError
  attr_reader :code

  def initialize(code)
    super()
    @code = code
  end
end

class InlineCompilerContext
  attr_reader :stdin, :stdout, :stderr

  def initialize
    @stdin = StringIO.new
    @stdout = StringIO.new
    @stderr = StringIO.new
  end

  def exit(code)
    raise InlineCompilerExit.new(code)
  end
end

class AsmSpec
  def read_test_file(fname)
    base_read_test_file(fname)
  end

  def extract_format_source(input, output)
    describe_action(input, output, 'extract source') do
      text = read_test_file(input)[:code]
      File.open(output, 'wb') do |file|
        file << text
      end
    end
  end

  def compile(input, output, options)
    err ' > inline compile:'.bold.white
    err " > ruby src/compiler/compiler.rb #{input} #{options}".bold.white
    settings = options.split(' ') + [input]
    context = InlineCompilerContext.new
    settings = read_args!(settings)
    run_dab_compiler(settings, context)
    File.open(output, 'wb') { |f| f << context.stdout.string }
  rescue InlineCompilerExit
    raise SystemCommandError.new('Compile error', context.stderr.string)
  end

  def write_new_testspec(filename, data)
    string = ''
    data.each do |key, value|
      string += "## #{key.upcase}\n"
      string += "\n"
      string += value
      string += "\n"
      string += "\n"
    end
    File.open(filename, 'wb') do |file|
      file << string.strip
      file << "\n"
    end
  end

  def run_test(settings)
    input = settings[:input]
{'fraction_non_alphanumeric': 0.11573511543134872, 'fraction_numerical': 0.0, 'mean_word_length': 3.1317440401505645, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 5, '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': '6618694', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1071, 'n_words': 264}