Skip to content

Commit

Permalink
Finish phasing out using #metaclass in the kernel. Fixes #189.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed Mar 27, 2010
1 parent 028b856 commit c7ac644
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion kernel/bootstrap/kernel.rb
Expand Up @@ -11,7 +11,7 @@ def eql?(other) # HACK dup of equal?
end

def extend(*mods)
metaclass.include(*mods)
Rubinius.object_metaclass(self).include(*mods)
self
end

Expand Down
2 changes: 1 addition & 1 deletion kernel/common/compiled_method.rb
Expand Up @@ -232,7 +232,7 @@ def as_script(script=nil)
ss.script = script
@scope = ss

mc = MAIN.metaclass
mc = Rubinius.object_metaclass(MAIN)
mc.method_table.store :__script__, self, :public
compile
VM.reset_method_cache :__script__
Expand Down
9 changes: 6 additions & 3 deletions kernel/common/eval.rb
Expand Up @@ -136,13 +136,15 @@ def eval(string, binding=nil, filename=nil, lineno=1)
# k.instance_eval { @secret } #=> 99

def instance_eval(string=nil, filename="(eval)", line=1, &prc)
mc = Rubinius.object_metaclass(self)

if prc
if string
raise ArgumentError, 'cannot pass both a block and a string to evaluate'
end
# Return a copy of the BlockEnvironment with the receiver set to self
env = prc.block
static_scope = env.method.scope.using_current_as(__metaclass__)
static_scope = env.method.scope.using_current_as(mc)
return env.call_under(self, static_scope, self)
elsif string
string = StringValue(string)
Expand All @@ -153,7 +155,7 @@ def instance_eval(string=nil, filename="(eval)", line=1, &prc)
Rubinius::StaticScope.of_sender)

cm = Rubinius::Compiler.compile_eval string, binding.variables, filename, line
cm.scope = binding.static_scope.using_current_as(metaclass)
cm.scope = binding.static_scope.using_current_as(mc)
cm.name = :__instance_eval__
cm.compile

Expand Down Expand Up @@ -192,7 +194,8 @@ def instance_eval(string=nil, filename="(eval)", line=1, &prc)
def instance_exec(*args, &prc)
raise ArgumentError, "Missing block" unless block_given?
env = prc.block
static_scope = env.method.scope.using_current_as(__metaclass__)
mc = Rubinius.object_metaclass(self)
static_scope = env.method.scope.using_current_as(mc)
return env.call_under(self, static_scope, *args)
end
end
Expand Down
10 changes: 5 additions & 5 deletions kernel/common/kernel.rb
Expand Up @@ -552,12 +552,12 @@ def nil?

def methods(all=true)
methods = singleton_methods(all)
methods |= self.metaclass.instance_methods(true) if all
methods |= Rubinius.object_metaclass(self).instance_methods(true) if all

return methods if kind_of?(ImmediateValue)

undefs = []
metaclass.method_table.filter_entries do |entry|
Rubinius.object_metaclass(self).method_table.filter_entries do |entry|
undefs << entry.name.to_s if entry.visibility == :undef
end

Expand All @@ -569,23 +569,23 @@ def private_methods(all=true)
end

def private_singleton_methods
Rubinius.convert_to_names metaclass.method_table.private_names
Rubinius.convert_to_names Rubinius.object_metaclass(self).method_table.private_names
end

def protected_methods(all=true)
protected_singleton_methods() | self.class.protected_instance_methods(all)
end

def protected_singleton_methods
Rubinius.convert_to_names metaclass.method_table.protected_names
Rubinius.convert_to_names Rubinius.object_metaclass(self).method_table.protected_names
end

def public_methods(all=true)
singleton_methods(all) | self.class.public_instance_methods(all)
end

def singleton_methods(all=true)
mt = metaclass.method_table
mt = Rubinius.object_metaclass(self).method_table
methods = (all ? mt.names : mt.public_names + mt.protected_names)

Rubinius.convert_to_names methods
Expand Down
6 changes: 3 additions & 3 deletions kernel/common/module.rb
Expand Up @@ -161,7 +161,7 @@ def superclass_chain
end

def find_class_method_in_hierarchy(sym)
self.metaclass.find_method_in_hierarchy(sym)
Rubinius.object_metaclass(self).find_method_in_hierarchy(sym)
end

def remote_alias(new_name, mod, current_name)
Expand Down Expand Up @@ -392,7 +392,7 @@ def set_visibility(meth, vis, where = nil)
end

def set_class_visibility(meth, vis)
metaclass.set_visibility meth, vis, "class "
Rubinius.object_metaclass(self).set_visibility meth, vis, "class "
end

def protected(*args)
Expand Down Expand Up @@ -694,7 +694,7 @@ def normalize_const_name(name)

def initialize_copy(other)
@method_table = other.method_table.dup
metaclass.method_table = other.metaclass.method_table.dup
Rubinius.object_metaclass(self).method_table = Rubinius.object_metaclass(other).method_table.dup

@constants = Rubinius::LookupTable.new

Expand Down
11 changes: 7 additions & 4 deletions kernel/common/native_method.rb
Expand Up @@ -18,12 +18,15 @@ class NativeMethod < Executable
#
def self.load_extension(library_path, extension_name)
library = library_path.sub /#{Rubinius::LIBSUFFIX}$/, ''
symbol = "Init_#{extension_name}"
name = "Init_#{extension_name}"

entry_point = load_entry_point library, symbol
entry_point = load_entry_point library, name

Rubinius.metaclass.method_table.store symbol.to_sym, entry_point, :public
Rubinius.send symbol.to_sym
symbol = name.to_sym

Rubinius.object_metaclass(self).method_table.store symbol, entry_point, :public
Rubinius::VM.reset_method_cache(symbol)
__send__ symbol

true
end
Expand Down
2 changes: 1 addition & 1 deletion kernel/delta/module.rb
Expand Up @@ -51,7 +51,7 @@ def module_function(*args)

Rubinius::VariableScope.of_sender.method_visibility = :module
else
mc = self.metaclass
mc = Rubinius.object_metaclass(self)
args.each do |meth|
method_name = Type.coerce_to_symbol meth
method = find_method_in_hierarchy(method_name)
Expand Down
2 changes: 1 addition & 1 deletion kernel/platform/library.rb
Expand Up @@ -95,7 +95,7 @@ def attach_function(name, a3, a4, a5=nil)
if func = create_backend(lib, cname, args, ret)

# Make it available as a method callable directly..
metaclass.method_table.store mname, func, :public
Rubinius.object_metaclass(self).method_table.store mname, func, :public

# and expose it as a private method for people who
# want to include this module.
Expand Down

0 comments on commit c7ac644

Please sign in to comment.