Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose ConstantCache to Ruby land like CallSite
This adds a bunch of basic specs for ConstantCache and exposes this object to Ruby land so people can peek at which constants are cached in different places.
- Loading branch information
Showing
18 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
# -*- encoding: us-ascii -*- | |||
|
|||
module Rubinius | |||
class ConstantCache | |||
|
|||
attr_reader :name | |||
attr_reader :value | |||
attr_reader :under | |||
attr_reader :scope | |||
attr_reader :executable | |||
|
|||
def ip | |||
Rubinius.primitive :constant_cache_ip | |||
raise PrimitiveFailure, "CallSite#ip primitive failed" | |||
end | |||
|
|||
def serial | |||
Rubinius.primitive :constant_cache_serial | |||
raise PrimitiveFailure, "CallSite#serial primitive failed" | |||
end | |||
|
|||
def location | |||
"#{@executable.file}:#{@executable.line_from_ip(ip)}" | |||
end | |||
|
|||
def inspect | |||
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} #{location}##{@name} constant=#{@value} under=#{@under}>" | |||
end | |||
|
|||
end | |||
end | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
require File.expand_path('../fixtures/classes.rb', __FILE__) | |||
|
|||
describe "Rubinius::ConstantCache#executable" do | |||
before :each do | |||
@constant_cache = ConstantCacheSpec::ConstantCacheTest.constant_caches[0] | |||
end | |||
|
|||
it "has the correct executable for the constant cache" do | |||
@constant_cache.executable.should == ConstantCacheSpec::ConstantCacheTest | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
class ConstantCacheSpec | |||
|
|||
ConstantCacheTest = def constant_cache_test | |||
Rubinius::VariableScope | |||
end | |||
|
|||
end | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
require File.expand_path('../fixtures/classes.rb', __FILE__) | |||
|
|||
describe "Rubinius::ConstantCache#ip" do | |||
before :each do | |||
@constant_cache = ConstantCacheSpec::ConstantCacheTest.constant_caches[0] | |||
end | |||
|
|||
it "has the correct ip for the constant cache" do | |||
@constant_cache.ip.should == 0 | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
require File.expand_path('../fixtures/classes.rb', __FILE__) | |||
|
|||
describe "Rubinius::ConstantCache#location" do | |||
before :each do | |||
@constant_cache = ConstantCacheSpec::ConstantCacheTest.constant_caches[0] | |||
end | |||
|
|||
it "has the correct location for the constant cache" do | |||
@constant_cache.location.should =~ %r{spec/core/constantcache/fixtures/classes\.rb:4$} | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
require File.expand_path('../fixtures/classes.rb', __FILE__) | |||
|
|||
describe "Rubinius::ConstantCache#name" do | |||
before :each do | |||
@constant_cache_base = ConstantCacheSpec::ConstantCacheTest.constant_caches[0] | |||
@constant_cache_under = ConstantCacheSpec::ConstantCacheTest.constant_caches[1] | |||
|
|||
end | |||
|
|||
it "has the correct name for the constant cache" do | |||
@constant_cache_base.name.should == :Rubinius | |||
@constant_cache_under.name.should == :VariableScope | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
require File.expand_path('../fixtures/classes.rb', __FILE__) | |||
|
|||
describe "Rubinius::ConstantCache#scope" do | |||
before :each do | |||
ConstantCacheSpec.new.constant_cache_test | |||
@constant_cache_base = ConstantCacheSpec::ConstantCacheTest.constant_caches[0] | |||
@constant_cache_under = ConstantCacheSpec::ConstantCacheTest.constant_caches[1] | |||
end | |||
|
|||
it "has a scope after the method is called" do | |||
@constant_cache_base.scope.should be_an_instance_of(Rubinius::ConstantScope) | |||
@constant_cache_under.scope.should be_an_instance_of(Rubinius::ConstantScope) | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
require File.expand_path('../fixtures/classes.rb', __FILE__) | |||
|
|||
describe "Rubinius::ConstantCache#scope" do | |||
before :each do | |||
@constant_cache_base = ConstantCacheSpec::ConstantCacheTest.constant_caches[0] | |||
@constant_cache_under = ConstantCacheSpec::ConstantCacheTest.constant_caches[1] | |||
end | |||
|
|||
it "returns an integer for the serial" do | |||
@constant_cache_base.serial.should be_kind_of(Integer) | |||
@constant_cache_under.serial.should be_kind_of(Integer) | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
require File.expand_path('../fixtures/classes.rb', __FILE__) | |||
|
|||
describe "Rubinius::ConstantCache#under" do | |||
before :each do | |||
ConstantCacheSpec.new.constant_cache_test | |||
@constant_cache_base = ConstantCacheSpec::ConstantCacheTest.constant_caches[0] | |||
@constant_cache_under = ConstantCacheSpec::ConstantCacheTest.constant_caches[1] | |||
end | |||
|
|||
it "has no under value for a top level constant" do | |||
@constant_cache_base.under.should be_nil | |||
end | |||
|
|||
it "has the correct under value for a scoped constant" do | |||
@constant_cache_under.under.should == Rubinius | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
require File.expand_path('../fixtures/classes.rb', __FILE__) | |||
|
|||
describe "Rubinius::ConstantCache#under" do | |||
before :each do | |||
ConstantCacheSpec.new.constant_cache_test | |||
@constant_cache_base = ConstantCacheSpec::ConstantCacheTest.constant_caches[0] | |||
@constant_cache_under = ConstantCacheSpec::ConstantCacheTest.constant_caches[1] | |||
end | |||
|
|||
it "returns the cached constant" do | |||
@constant_cache_base.value.should == Rubinius | |||
@constant_cache_under.value.should == Rubinius::VariableScope | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters