<commit_before>require_relative 'node_base_jump.rb'

class DabNodeConditionalJump < DabNodeBaseJump
  attr_reader :target
  attr_reader :if_true, :if_false

  def initialize(condition, if_true, if_false)
    super()
    @if_true = if_true
    @if_false = if_false
    insert(condition)
  end

  def extra_dump
    "-> true: #{if_true.label} | false: #{if_false.label}"
  end

  def condition
    children[0]
  end

  def compile(output)
    condition.compile(output)
    output.print('JMP_IF', if_true.label)
    output.print('JMP', if_false.label)
  end

  def replace_target!(from, to)
    @if_true = to if @if_true == from
    @if_false = to if @if_false == from
  end

  def targets
    [@if_true, @if_false]
  end
end<commit_msg>compiler: optimize constant conditional jumps<commit_after>require_relative 'node_base_jump.rb'

class DabNodeConditionalJump < DabNodeBaseJump
  attr_reader :target
  attr_reader :if_true, :if_false

  def initialize(condition, if_true, if_false)
    super()
    @if_true = if_true
    @if_false = if_false
    insert(condition)
  end

  def extra_dump
    "-> true: #{if_true.label} | false: #{if_false.label}"
  end

  def condition
    children[0]
  end

  def compile(output)
    condition.compile(output)
    output.print('JMP_IF', if_true.label)
    output.print('JMP', if_false.label)
  end

  def replace_target!(from, to)
    @if_true = to if @if_true == from
    @if_false = to if @if_false == from
  end

  def targets
    [@if_true, @if_false]
  end

  def optimize!
    if condition.constant?
      test = condition.constant_value
      replace_with!(DabNodeJump.new(test ? if_true : if_false))
      true
    else
      super
    end
  end
end
{'fraction_non_alphanumeric': 0.10047281323877069, 'fraction_numerical': 0.001182033096926714, 'mean_word_length': 3.3860103626943006, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1680135', 'n_tokens_mistral': 619, 'n_tokens_neox': 597, 'n_words': 137}