Skip to content

Commit

Permalink
Rename StaticScope to ConstantScope... EVERYWHERE
Browse files Browse the repository at this point in the history
StaticScope is (ehem, was) where constants were scoped to, so IMHO
ConstantScope makes for a much better name :)
  • Loading branch information
Josep M. Bach authored and dbussink committed Jun 8, 2012
1 parent 493ee4c commit a7b957a
Show file tree
Hide file tree
Showing 86 changed files with 287 additions and 288 deletions.
2 changes: 1 addition & 1 deletion kernel/bootstrap/block_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def call(*args)
raise PrimitiveFailure, "BlockEnvironment#call primitive failed"
end

def call_under(recv, static_scope, *args)
def call_under(recv, constant_scope, *args)
Rubinius.primitive :block_call_under
raise PrimitiveFailure, "BlockEnvironment#call_under primitive failed"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# -*- encoding: us-ascii -*-

module Rubinius
class StaticScope
class ConstantScope
def self.of_sender
Rubinius.primitive :static_scope_of_sender
Rubinius.primitive :constant_scope_of_sender
raise PrimitiveFailure, "primitive failed"
end

def class_variable_get(sym)
Rubinius.primitive :static_scope_cvar_get
Rubinius.primitive :constant_scope_cvar_get

raise NameError, "Invalid class variable name '#{sym}'"
end

def class_variable_set(sym, val)
Rubinius.primitive :static_scope_cvar_set
Rubinius.primitive :constant_scope_cvar_set

raise NameError, "Invalid class variable name '#{sym}'"
end

def class_variable_defined?(sym)
Rubinius.primitive :static_scope_cvar_defined
Rubinius.primitive :constant_scope_cvar_defined

raise NameError, "Invalid class variable name '#{sym}'"
end

def class_variable_get_or_set(sym, val)
Rubinius.primitive :static_scope_cvar_get_or_set
Rubinius.primitive :constant_scope_cvar_get_or_set

raise NameError, "Invalid class variable name '#{sym}'"
end
Expand Down
2 changes: 1 addition & 1 deletion kernel/bootstrap/load_order18.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ process.rbc
regexp.rbc
rubinius.rbc
rubinius18.rbc
static_scope.rbc
constant_scope.rbc
string.rbc
symbol.rbc
thread.rbc
Expand Down
2 changes: 1 addition & 1 deletion kernel/bootstrap/load_order19.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ regexp.rbc
regexp19.rbc
rubinius.rbc
rubinius19.rbc
static_scope.rbc
constant_scope.rbc
string.rbc
string19.rbc
symbol.rbc
Expand Down
2 changes: 1 addition & 1 deletion kernel/bootstrap/load_order20.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ regexp.rbc
regexp19.rbc
rubinius.rbc
rubinius19.rbc
static_scope.rbc
constant_scope.rbc
string.rbc
string19.rbc
symbol.rbc
Expand Down
8 changes: 4 additions & 4 deletions kernel/common/binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Binding
attr_accessor :variables
attr_accessor :code
attr_accessor :static_scope
attr_accessor :constant_scope
attr_accessor :proc_environment
attr_accessor :self
attr_accessor :line_number
Expand All @@ -18,18 +18,18 @@ def from_proc?
#
# +variables+ is a Rubinius::VariableScope object
# +code+ is a Rubinius::CompiledMethod object
# +static_scope+ is a Rubinius::StaticScope object
# +constant_scope+ is a Rubinius::ConstantScope object
#
# See Kernel#binding in kernel/common/eval.rb for a simple example of
# creating a Binding object.
#
def self.setup(variables, code, static_scope, recv=nil, location=nil)
def self.setup(variables, code, constant_scope, recv=nil, location=nil)
bind = allocate()

bind.self = recv || variables.self
bind.variables = variables
bind.code = code
bind.static_scope = static_scope
bind.constant_scope = constant_scope
bind.line_number = location ? location.line : 1

return bind
Expand Down
2 changes: 1 addition & 1 deletion kernel/common/block_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def disable_scope!
@code.scope.using_disabled_scope
end

def static_scope
def constant_scope
@code.scope
end

Expand Down
8 changes: 4 additions & 4 deletions kernel/common/compiled_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ def create_script(wrap=false)
script = CompiledMethod::Script.new(self)

# Setup the scoping.
ss = StaticScope.new(Object)
ss.script = script
cs = ConstantScope.new(Object)
cs.script = script

if wrap
@scope = StaticScope.new(Module.new, ss)
@scope = ConstantScope.new(Module.new, cs)
else
@scope = ss
@scope = cs
end

sc = Rubinius::Type.object_singleton_class(MAIN)
Expand Down
22 changes: 11 additions & 11 deletions kernel/common/static_scope.rb → kernel/common/constant_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# TODO: document

module Rubinius
class StaticScope
class ConstantScope

#
# @todo Verify the recursion here does not cause problems. --rue
Expand All @@ -23,7 +23,7 @@ def initialize(mod, par = nil)
# Module or class this lexical scope enclosed into.
attr_reader :module

# Static scope object this scope enclosed into.
# Constant scope object this scope enclosed into.
attr_reader :parent

# Module or class representing the 'current class'. MRI manipulates
Expand All @@ -50,24 +50,24 @@ def top_level?
!@parent
end

# Use the same info as the current StaticScope, but set current_module to
# +mod+. Chains off the current StaticScope.
# Use the same info as the current ConstantScope, but set current_module to
# +mod+. Chains off the current ConstantScope.
def using_current_as(mod)
if top_level?
# Don't chain up if this is a toplevel, create a new one.
ss = dup
cs = dup
else
ss = StaticScope.new @module, self
cs = ConstantScope.new @module, self
end

ss.current_module = mod
return ss
cs.current_module = mod
return cs
end

def using_disabled_scope
ss = using_current_as(@module)
ss.disabled_for_methods = true
return ss
cs = using_current_as(@module)
cs.disabled_for_methods = true
return cs
end

def for_method_definition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-

module Rubinius
class StaticScope
class ConstantScope

def const_defined?(name)
scope = self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-

module Rubinius
class StaticScope
class ConstantScope

def const_defined?(name, search_parents=true)
scope = self
Expand Down
26 changes: 13 additions & 13 deletions kernel/common/eval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def binding
return Binding.setup(
Rubinius::VariableScope.of_sender,
Rubinius::CompiledMethod.of_sender,
Rubinius::StaticScope.of_sender,
Rubinius::ConstantScope.of_sender,
self,
Rubinius::Location.of_closest_ruby_method
)
Expand All @@ -51,26 +51,26 @@ def eval(string, binding=nil, filename=nil, lineno=1)

if binding
binding = Rubinius::Type.coerce_to_binding binding
filename ||= binding.static_scope.active_path
filename ||= binding.constant_scope.active_path
else
binding = Binding.setup(Rubinius::VariableScope.of_sender,
Rubinius::CompiledMethod.of_sender,
Rubinius::StaticScope.of_sender,
Rubinius::ConstantScope.of_sender,
self)

filename ||= "(eval)"
end

existing_scope = binding.static_scope
binding.static_scope = existing_scope.dup
existing_scope = binding.constant_scope
binding.constant_scope = existing_scope.dup

be = Rubinius::Compiler.construct_block string, binding,
filename, lineno

be.set_eval_binding binding

result = be.call_on_instance(binding.self)
binding.static_scope = existing_scope
binding.constant_scope = existing_scope
result
end
module_function :eval
Expand All @@ -87,34 +87,34 @@ class Module

def module_eval(string=undefined, filename="(eval)", line=1, &prc)
# we have a custom version with the prc, rather than using instance_exec
# so that we can setup the StaticScope properly.
# so that we can setup the ConstantScope properly.
if prc
unless string.equal?(undefined)
raise ArgumentError, "cannot pass both string and proc"
end

# Return a copy of the BlockEnvironment with the receiver set to self
env = prc.block
static_scope = env.repoint_scope self
return env.call_under(self, static_scope, self)
constant_scope = env.repoint_scope self
return env.call_under(self, constant_scope, self)
elsif string.equal?(undefined)
raise ArgumentError, 'block not supplied'
end

string = StringValue(string)
filename = StringValue(filename)

# The staticscope of a module_eval CM is the receiver of module_eval
ss = Rubinius::StaticScope.new self, Rubinius::StaticScope.of_sender
# The constantscope of a module_eval CM is the receiver of module_eval
cs = Rubinius::ConstantScope.new self, Rubinius::ConstantScope.of_sender

binding = Binding.setup(Rubinius::VariableScope.of_sender,
Rubinius::CompiledMethod.of_sender,
ss)
cs)

be = Rubinius::Compiler.construct_block string, binding,
filename, line

be.call_under self, ss, self
be.call_under self, cs, self
end

alias_method :class_eval, :module_eval
Expand Down
22 changes: 11 additions & 11 deletions kernel/common/eval18.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ def instance_eval(string=nil, filename="(eval)", line=1, &prc)
env = prc.block

if sc
static_scope = env.repoint_scope sc
constant_scope = env.repoint_scope sc
else
static_scope = env.disable_scope!
constant_scope = env.disable_scope!
end

return env.call_under(self, static_scope, self)
return env.call_under(self, constant_scope, self)
elsif string
string = StringValue(string)

static_scope = Rubinius::StaticScope.of_sender
constant_scope = Rubinius::ConstantScope.of_sender

if sc
static_scope = Rubinius::StaticScope.new(sc, static_scope)
constant_scope = Rubinius::ConstantScope.new(sc, constant_scope)
else
static_scope = static_scope.using_disabled_scope
constant_scope = constant_scope.using_disabled_scope
end

binding = Binding.setup(Rubinius::VariableScope.of_sender,
Rubinius::CompiledMethod.of_sender,
static_scope)
constant_scope)

be = Rubinius::Compiler.construct_block string, binding,
filename, line
Expand Down Expand Up @@ -95,14 +95,14 @@ def instance_exec(*args, &prc)

env = prc.block

static_scope = env.static_scope
constant_scope = env.constant_scope
if ImmediateValue === self
static_scope = static_scope.using_disabled_scope
constant_scope = constant_scope.using_disabled_scope
else
sc = Rubinius::Type.object_singleton_class(self)
static_scope = static_scope.using_current_as(sc)
constant_scope = constant_scope.using_current_as(sc)
end

return env.call_under(self, static_scope, *args)
return env.call_under(self, constant_scope, *args)
end
end
22 changes: 11 additions & 11 deletions kernel/common/eval19.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ def instance_eval(string=nil, filename="(eval)", line=1, &prc)
env = prc.block

if sc
static_scope = env.repoint_scope sc
constant_scope = env.repoint_scope sc
else
static_scope = env.disable_scope!
constant_scope = env.disable_scope!
end

return env.call_under(self, static_scope, self)
return env.call_under(self, constant_scope, self)
elsif string
string = StringValue(string)

static_scope = Rubinius::StaticScope.of_sender
constant_scope = Rubinius::ConstantScope.of_sender

if sc
static_scope = Rubinius::StaticScope.new(sc, static_scope)
constant_scope = Rubinius::ConstantScope.new(sc, constant_scope)
else
static_scope = static_scope.using_disabled_scope
constant_scope = constant_scope.using_disabled_scope
end

binding = Binding.setup(Rubinius::VariableScope.of_sender,
Rubinius::CompiledMethod.of_sender,
static_scope)
constant_scope)

be = Rubinius::Compiler.construct_block string, binding,
filename, line
Expand Down Expand Up @@ -94,14 +94,14 @@ def instance_exec(*args, &prc)
return prc.bound_method.call(*args)
end

static_scope = env.static_scope
constant_scope = env.constant_scope
if ImmediateValue === self
static_scope = static_scope.using_disabled_scope
constant_scope = constant_scope.using_disabled_scope
else
sc = Rubinius::Type.object_singleton_class(self)
static_scope = static_scope.using_current_as(sc)
constant_scope = constant_scope.using_current_as(sc)
end

return env.call_under(self, static_scope, *args)
return env.call_under(self, constant_scope, *args)
end
end
Loading

0 comments on commit a7b957a

Please sign in to comment.