Skip to content

Commit

Permalink
Move Module#constants/constants_table => constant_table. Fixes rubini…
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed May 2, 2011
1 parent 02330f0 commit 3973f6d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
6 changes: 3 additions & 3 deletions kernel/alpha.rb
Expand Up @@ -425,8 +425,8 @@ def self.exit!(code=1)

class Module
def method_table ; @method_table ; end
def constants_table; @constants ; end
def name ; @module_name.to_s ; end
def constant_table; @constant_table ; end
def name ; @module_name.to_s ; end

# Specialised allocator.
#
Expand Down Expand Up @@ -678,7 +678,7 @@ def self.allocate
#
def initialize(mod)
@method_table = mod.method_table
@constants = mod.constants_table
@constant_table = mod.constant_table
@module = mod
end

Expand Down
2 changes: 1 addition & 1 deletion kernel/common/autoload.rb
Expand Up @@ -23,7 +23,7 @@ def initialize(name, scope, path)
def call(honor_require=false)
# Remove the autoload object from the constant table it was in, so
# we don't recurse back into ourself.
scope.constants_table.delete @name
scope.constant_table.delete @name
Rubinius.inc_global_serial

worked = Rubinius::CodeLoader.require @path
Expand Down
34 changes: 17 additions & 17 deletions kernel/common/module.rb
Expand Up @@ -12,7 +12,7 @@

class Module

attr_reader_specific :constants, :constants_table
attr_reader :constant_table
attr_writer :method_table

private :included
Expand Down Expand Up @@ -456,14 +456,14 @@ def module_exec(*args, &prc)
def constants
tbl = Rubinius::LookupTable.new

@constants.each do |name, val|
@constant_table.each do |name, val|
tbl[name] = true
end

current = self.direct_superclass

while current and current != Object
current.constants_table.each do |name, val|
current.constant_table.each do |name, val|
tbl[name] = true unless tbl.has_key? name
end

Expand All @@ -472,7 +472,7 @@ def constants

# special case: Module.constants returns Object's constants
if self.equal? Module
Object.constants_table.each do |name, val|
Object.constant_table.each do |name, val|
tbl[name] = true unless tbl.has_key? name
end
end
Expand All @@ -481,7 +481,7 @@ def constants
end

def const_defined?(name)
@constants.has_key? normalize_const_name(name)
@constant_table.has_key? normalize_const_name(name)
end

def const_get(name, missing=true)
Expand All @@ -490,7 +490,7 @@ def const_get(name, missing=true)
current, constant = self, undefined

while current
constant = current.constants_table.fetch name, undefined
constant = current.constant_table.fetch name, undefined
unless constant.equal?(undefined)
constant = constant.call if constant.kind_of?(Autoload)
return constant
Expand All @@ -500,7 +500,7 @@ def const_get(name, missing=true)
end

if instance_of?(Module)
constant = Object.constants_table.fetch name, undefined
constant = Object.constant_table.fetch name, undefined
unless constant.equal?(undefined)
constant = constant.call if constant.kind_of?(Autoload)
return constant
Expand All @@ -518,7 +518,7 @@ def const_set(name, value)
end

name = normalize_const_name(name)
@constants[name] = value
@constant_table[name] = value
Rubinius.inc_global_serial

return value
Expand Down Expand Up @@ -614,7 +614,7 @@ def autoload(name, path)

name = normalize_const_name(name)

if existing = @constants[name]
if existing = @constant_table[name]
if existing.kind_of? Autoload
# If there is already an Autoload here, just change the path to
# autoload!
Expand All @@ -627,16 +627,16 @@ def autoload(name, path)
return
end

constants_table[name] = Autoload.new(name, self, path)
constant_table[name] = Autoload.new(name, self, path)
Rubinius.inc_global_serial
return nil
end

# Is an autoload trigger defined for the given path?
def autoload?(name)
name = name.to_sym
return unless constants_table.key?(name)
trigger = constants_table[name]
return unless constant_table.key?(name)
trigger = constant_table[name]
return unless trigger.kind_of?(Autoload)
trigger.path
end
Expand All @@ -651,11 +651,11 @@ def remove_const(name)
end

sym = name.to_sym
unless constants_table.has_key?(sym)
unless constant_table.has_key?(sym)
raise NameError, "Missing or uninitialized constant: #{self.__name__}::#{name}"
end

val = constants_table.delete(sym)
val = constant_table.delete(sym)
Rubinius.inc_global_serial

# Silly API compact. Shield Autoload instances
Expand Down Expand Up @@ -696,14 +696,14 @@ def initialize_copy(other)
sc_s.method_table = sc_o.method_table.dup
sc_s.superclass = sc_o.superclass

@constants = Rubinius::LookupTable.new
@constant_table = Rubinius::LookupTable.new

other.constants_table.each do |name, val|
other.constant_table.each do |name, val|
if val.kind_of? Autoload
val = Autoload.new(val.name, self, val.path)
end

@constants[name] = val
@constant_table[name] = val
end

self
Expand Down
4 changes: 2 additions & 2 deletions kernel/delta/rubinius.rb
Expand Up @@ -13,7 +13,7 @@ def self.open_class_under(name, sup, mod)
raise TypeError, "'#{mod.inspect}' is not a class/module"
end

tbl = mod.constants_table
tbl = mod.constant_table
if !tbl.key?(name)
# Create the class
sup = Object unless sup
Expand Down Expand Up @@ -59,7 +59,7 @@ def self.open_module_under(name, mod)
raise TypeError, "'#{mod.inspect}' is not a class/module"
end

tbl = mod.constants_table
tbl = mod.constant_table
if !tbl.key?(name)
# Create the module
obj = Module.new
Expand Down
8 changes: 4 additions & 4 deletions vm/builtin/module.cpp
Expand Up @@ -44,7 +44,7 @@ namespace rubinius {
}

void Module::setup(STATE) {
constants(state, LookupTable::create(state));
constant_table(state, LookupTable::create(state));
method_table(state, MethodTable::create(state));
}

Expand All @@ -61,7 +61,7 @@ namespace rubinius {
void Module::setup(STATE, Symbol* name, Module* under) {
if(!under) under = G(object);

this->constants(state, LookupTable::create(state));
constant_table(state, LookupTable::create(state));
this->method_table(state, MethodTable::create(state));
this->name(state, name);
under->set_const(state, name, this);
Expand Down Expand Up @@ -89,12 +89,12 @@ namespace rubinius {
}

void Module::set_const(STATE, Object* sym, Object* val) {
constants_->store(state, sym, val);
constants()->store(state, sym, val);
state->shared.inc_global_serial();
}

void Module::del_const(STATE, Symbol* sym) {
constants_->remove(state, sym);
constants()->remove(state, sym);
state->shared.inc_global_serial();
}

Expand Down
8 changes: 6 additions & 2 deletions vm/builtin/module.hpp
Expand Up @@ -16,7 +16,7 @@ namespace rubinius {
private:
MethodTable* method_table_; // slot
Symbol* module_name_; // slot
LookupTable* constants_; // slot
LookupTable* constant_table_; // slot
Module* superclass_; // slot
Array* seen_ivars_; // slot

Expand All @@ -25,10 +25,14 @@ namespace rubinius {

attr_accessor(method_table, MethodTable);
attr_accessor(module_name, Symbol);
attr_accessor(constants, LookupTable);
attr_accessor(constant_table, LookupTable);
attr_accessor(superclass, Module);
attr_accessor(seen_ivars, Array);

LookupTable* constants() {
return constant_table();
}

Symbol* name() { return module_name_; }
void name(STATE, Symbol* sym) {
module_name(state, sym);
Expand Down
4 changes: 2 additions & 2 deletions vm/builtin/object.cpp
Expand Up @@ -58,10 +58,10 @@ namespace rubinius {
Object* Object::copy_singleton_class(STATE, Object* other) {
if(SingletonClass* sc = try_as<SingletonClass>(other->klass())) {
MethodTable* source_methods = sc->method_table()->duplicate(state);
LookupTable* source_constants = sc->constants()->duplicate(state);
LookupTable* source_constants = sc->constant_table()->duplicate(state);

singleton_class(state)->method_table(state, source_methods);
singleton_class(state)->constants(state, source_constants);
singleton_class(state)->constant_table(state, source_constants);
// TODO inc the global serial here?

// This allows us to preserve included modules
Expand Down

0 comments on commit 3973f6d

Please sign in to comment.