<commit_before>require File.dirname(__FILE__) + '/../../spec_helper'

describe "A Call node NOT using FastNew plugin" do
  relates "new" do
    compile do |g|
      g.push :self
      g.send :new, 0, true
    end
  end

  relates "new(a)" do
    compile do |g|
      g.push :self
      g.push :self
      g.send :a, 0, true
      g.send :new, 1, true
    end
  end

  relates "A.new" do
    compile do |g|
      g.push_const :A
      g.send :new, 0, false
    end
  end

  relates "A.new(a)" do
    compile do |g|
      g.push_const :A
      g.push :self
      g.send :a, 0, true
      g.send :new, 1, false
    end
  end
end

describe "A Call node using FastNew plugin" do
  relates "new" do
    compile :fastnew do |g|
      slow = g.new_label
      done = g.new_label

      g.push :self
      g.dup
      idx = g.check_serial idx, CompiledMethod::KernelMethodSerial
      gif slow

      g.send :allocate, 0
      g.dup
      g.send :initialize, 0, true
      g.pop
      g.goto done

      slow.set!
      g.set_call_flags 1
      g.send_method idx

      done.set!
    end
  end

  relates "new(a)" do
    compile :fastnew do |g|
      slow = g.new_label
      done = g.new_label

      g.push :self
      g.dup
      idx = g.check_serial idx, CompiledMethod::KernelMethodSerial
      gif slow

      g.send :allocate, 0
      g.dup
      g.push :self
      g.send :a, 0, true
      g.send :initialize, 1, true
      g.pop
      g.goto done

      slow.set!
      g.push :self
      g.send :a, 0, true
      g.set_call_flags 1
      g.send_stack idx, 1

      done.set!
    end
  end

  relates "A.new" do
    compile :fastnew do |g|
      slow = g.new_label
      done = g.new_label

      g.push_const :A
      g.dup
      idx = g.check_serial idx, CompiledMethod::KernelMethodSerial
      gif slow

      g.send :allocate, 0
      g.dup
      g.send :initialize, 0, true
      g.pop
      g.goto done

      slow.set!
      g.set_call_flags 1
      g.send_method idx

      done.set!
    end
  end

  relates "A.new(a)" do
    compile :fastnew do |g|
      slow = g.new_label
      done = g.new_label

      g.push_const :A
      g.dup
      idx = g.check_serial idx, CompiledMethod::KernelMethodSerial
      gif slow

      g.send :allocate, 0
      g.dup
      g.push :self
      g.send :a, 0, true
      g.send :initialize, 1, true
      g.pop<commit_msg>Fixed up FastNew plugin specs.<commit_after>require File.dirname(__FILE__) + '/../../spec_helper'

describe "A Call node using FastNew plugin" do
  relates "new" do
    parse do
      [:call, nil, :new, [:arglist]]
    end

    compile do |g|
      g.push :self
      g.send :new, 0, true
    end

    compile :fastnew do |g|
      slow = g.new_label
      done = g.new_label

      g.push :self
      g.dup
      idx = g.check_serial idx, CompiledMethod::KernelMethodSerial
      gif slow

      g.send :allocate, 0
      g.dup
      g.send :initialize, 0, true
      g.pop
      g.goto done

      slow.set!
      g.set_call_flags 1
      g.send_method idx

      done.set!
    end
  end

  relates "new(a)" do
    parse do
      [:call, nil, :new, [:arglist, [:call, nil, :a, [:arglist]]]]
    end

    compile do |g|
      g.push :self
      g.push :self
      g.send :a, 0, true
      g.send :new, 1, true
    end

    compile :fastnew do |g|
      slow = g.new_label
      done = g.new_label

      g.push :self
      g.dup
      idx = g.check_serial idx, CompiledMethod::KernelMethodSerial
      gif slow

      g.send :allocate, 0
      g.dup
      g.push :self
      g.send :a, 0, true
      g.send :initialize, 1, true
      g.pop
      g.goto done

      slow.set!
      g.push :self
      g.send :a, 0, true
      g.set_call_flags 1
      g.send_stack idx, 1

      done.set!
    end
  end

  relates "A.new" do
    parse do
      [:call, [:const, :A], :new, [:arglist]]
    end

    compile do |g|
      g.push_const :A
      g.send :new, 0, false
    end

    compile :fastnew do |g|
      slow = g.new_label
      done = g.new_label

      g.push_const :A
      g.dup
      idx = g.check_serial idx, CompiledMethod::KernelMethodSerial
      gif slow

      g.send :allocate, 0
      g.dup
      g.send :initialize, 0, true
      g.pop
      g.goto done

      slow.set!
      g.set_call_flags 1
      g.send_method idx

      done.set!
    end
  end

  relates "A.new(a)" do
    parse do
      [:call, [:const, :A], :new, [:arglist, [:call, nil, :a, [:arglist]]]]
    end

    compile do |g|
      g.push_const :A
      g.push :self
      g.send :a, 0, true
      g.send :new, 1, false
    end

    compile :fastnew do |g|
      slow = g.new_label
      done = g.new_label

      g.push_const :A
      g.dup
      idx = g.check_serial idx, CompiledMethod::KernelMethodSerial
      gif slow

      g.send :allocate, 0
      g.dup
      g.push :self
      g.send :a, 0, true
      g.send :initialize, 1, true
      g.pop
{'fraction_non_alphanumeric': 0.10469387755102041, 'fraction_numerical': 0.008571428571428572, 'mean_word_length': 1.6434735706580368, 'pattern_counts': {'":': 0, '<': 3, '<?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': '114199', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1763, 'n_words': 523}