Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b0134e8097b9
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 557507659cc4
Choose a head ref
  • 6 commits
  • 16 files changed
  • 1 contributor

Commits on Dec 23, 2014

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1736dbd View commit details
  2. Added more keyword specs.

    brixen committed Dec 23, 2014

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    02d4e83 View commit details

Commits on Dec 24, 2014

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    22cb693 View commit details
  2. 2

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d93ea1e View commit details
  3. Hack in some JIT specs support.

    This is a hack, this is only a hack, had this been real code, the hack
    you are seeing wouldn't be here.
    brixen committed Dec 24, 2014

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5d355c7 View commit details
  4. Added some JIT specs.

    brixen committed Dec 24, 2014
    Copy the full SHA
    5575076 View commit details
16 changes: 16 additions & 0 deletions kernel/bootstrap/jit.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,22 @@ class << self

alias_method :available?, :available
alias_method :enabled?, :enabled

# TODO: Fix configuration
def compile_threshold
Rubinius.primitive :jit_compile_threshold
raise PrimitiveFailure, "Rubinius::JIT.compile_threshold primitive failed"
end

def sync=(flag)
Rubinius.primitive :jit_sync_set
raise PrimitiveFailure, "Rubinius::JIT.sync primitive failed"
end

def sync
Rubinius.primitive :jit_sync_get
raise PrimitiveFailure, "Rubinius::JIT.sync primitive failed"
end
end
end
end
42 changes: 40 additions & 2 deletions kernel/delta/runtime.rb
Original file line number Diff line number Diff line change
@@ -78,6 +78,46 @@ def self.splat_hash_entry(hash, key, value)
hash
end

def self.keyword_object?(obj, optional)
hash = Rubinius::Type.try_convert obj, Hash, :to_hash
return unless hash

hs = hash.size
return [nil, hash] if hs == 0

kw = {}
t = Tuple.new hs
i = 0

hash.each do |key, value|
if key.instance_of? Symbol
kw[key] = value
else
return unless optional

t[i] = key
i += 1
end
end

if i == 0
[nil, kw]
elsif i == hs
[obj, kw]
else
nk = {}
j = 0

while j < i
k = t[j]
nk[k] = hash[k]
j += 1
end

[nk, kw]
end
end

def self.keywords_missing(hash)
keywords = CompiledCode.of_sender.keywords

@@ -101,8 +141,6 @@ def self.keywords_missing(hash)
def self.keywords_extra(hash, kwrest)
keywords = CompiledCode.of_sender.keywords

hash = hash.dup

total = keywords.size
i = 0

2 changes: 2 additions & 0 deletions spec/jit/a_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RubiniusJITSync = Rubinius::JIT.sync
Rubinius::JIT.sync = true
65 changes: 65 additions & 0 deletions spec/jit/method_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require File.expand_path("../spec_helper", __FILE__)

describe "JIT compiling a method call" do
context "to m(a)" do
before :each do
klass = Class.new do
def m(a) a end
end

@o = klass.new

warmup { @o.m 5 }
end

it "returns the passed argument" do
@o.m(:a).should == :a
end

it "raises an ArgumentError when not passed an argument" do
lambda { @o.m }.should raise_error(ArgumentError)
end
end

context "to m(*a)" do
before :each do
klass = Class.new do
def m(*a) a end
end

@o = klass.new

warmup { @o.m }
end

it "returns an empty Array when passed no argument" do
@o.m.should == []
end

it "returns a one-element Array when passed one argument" do
@o.m(1).should == [1]
end
end

context "to m(a=1, **kw)" do
before :each do
klass = Class.new do
def m(a=1 **kw) [a, kw] end
end

@o = klass.new

warmup { @o.m }
end

context "when passed one argument" do
it "assigns Symbol keys to the keyword rest argument" do
@o.m(a: 1, b: 2).should == [1, {a: 1, b: 2}]
end

it "assigns non-Symbol keys to the default argument" do
@o.m("a" => 1, b: 2).should == [{"a" => 1}, {b: 2}]
end
end
end
end
9 changes: 9 additions & 0 deletions spec/jit/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require File.expand_path('../../spec_helper', __FILE__)

WARMUP_ITERATIONS = Rubinius::JIT.compile_threshold

class Object
def warmup
WARMUP_ITERATIONS.times { yield }
end
end
1 change: 1 addition & 0 deletions spec/jit/z_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rubinius::JIT.sync = RubiniusJITSync
30 changes: 28 additions & 2 deletions spec/ruby/language/block_spec.rb
Original file line number Diff line number Diff line change
@@ -49,6 +49,32 @@ def m(a) yield a end
result.should == [1, 2, [], 3, 2, {x: 9}]
end

it "assigns symbol keys from a Hash to keyword arguments" do
result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] }
result.should == [{"a" => 1}, a: 10]
end

it "assigns symbol keys from a Hash returned by #to_hash to keyword arguments" do
obj = mock("coerce block keyword arguments")
obj.should_receive(:to_hash).and_return({"a" => 1, b: 2})

result = m([obj]) { |a=nil, **b| [a, b] }
result.should == [{"a" => 1}, b: 2]
end

it "calls #to_hash on the argument but does not use the result when no keywords are present" do
obj = mock("coerce block keyword arguments")
obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2})

result = m([obj]) { |a=nil, **b| [a, b] }
result.should == [obj, {}]
end

it "assigns non-symbol keys to non-keyword arguments" do
result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] }
result.should == [{"a" => 10}, {b: 2}]
end

it "calls #to_hash on the last element if keyword arguments are present" do
obj = mock("destructure block keyword arguments")
obj.should_receive(:to_hash).and_return({x: 9})
@@ -67,9 +93,9 @@ def m(a) yield a end

it "calls #to_hash on the element that maps to the keyword arguments" do
x = mock("destructure matching block keyword argument")
x.should_receive(:to_hash).and_return({x: 9})
x.should_not_receive(:to_hash)
y = mock("destructure non-matching block keyword argument")
y.should_not_receive(:to_hash)
y.should_receive(:to_hash).and_return({x: 9})

result = m([1, 2, 3, x, 4, 5, y]) { |a, b=5, c, **k| [a, b, c, k] }
result.should == [1, 2, 3, {x: 9}]
Loading