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: 43c36117a01b
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e243e50238ac
Choose a head ref
  • 2 commits
  • 53 files changed
  • 1 contributor

Commits on Jul 19, 2016

  1. Renamed ConstantScope to LexicalScope.

    Originally, this was called StaticScope, which was pretty accurate. It was
    renamed ConstantScope to make it more obvious that it was intimately related
    to 'constant' lookup in Ruby.
    
    However, constants are odd things in Ruby: their values are neither constant
    nor is their lookup restricted to one scope.  Instead, their values may be
    reassigned and their lookup starts with the lexical scope but continues with
    the inheritance chain.
    
    With the additional of functions in Rubinius bound to lexical scope, it is
    reasonable to refocus this object on its actual role: to represent a lexical
    scope.
    brixen committed Jul 19, 2016
    Copy the full SHA
    fed71e1 View commit details
  2. Updated compiler version.

    brixen committed Jul 19, 2016
    Copy the full SHA
    e243e50 View commit details
Showing with 221 additions and 217 deletions.
  1. +1 −1 Gemfile.lock
  2. +11 −11 core/basic_object.rb
  3. +4 −4 core/binding.rb
  4. +8 −8 core/block_environment.rb
  5. +3 −3 core/compiled_code.rb
  6. +2 −2 core/constant_cache.rb
  7. +2 −0 core/deprecations.rb
  8. +1 −1 core/enumerable_helper.rb
  9. +8 −8 core/kernel.rb
  10. +9 −9 core/{constant_scope.rb → lexical_scope.rb}
  11. +1 −1 core/load_order.txt
  12. +1 −1 core/location.rb
  13. +8 −8 core/module.rb
  14. +1 −1 core/rubinius.rb
  15. +11 −9 core/zed.rb
  16. +1 −1 gems_list.txt
  17. +1 −1 machine/builtin/access_variable.hpp
  18. +1 −1 machine/builtin/block_as_method.cpp
  19. +8 −8 machine/builtin/block_environment.cpp
  20. +7 −7 machine/builtin/block_environment.hpp
  21. +1 −1 machine/builtin/class.hpp
  22. +2 −2 machine/builtin/compiled_code.cpp
  23. +4 −4 machine/builtin/compiled_code.hpp
  24. +5 −5 machine/builtin/constant_cache.cpp
  25. +10 −10 machine/builtin/constant_cache.hpp
  26. +18 −18 machine/builtin/{constant_scope.cpp → lexical_scope.cpp}
  27. +13 −13 machine/builtin/{constant_scope.hpp → lexical_scope.hpp}
  28. +1 −1 machine/builtin/location.cpp
  29. +4 −4 machine/builtin/location.hpp
  30. +3 −3 machine/builtin/method_table.cpp
  31. +2 −2 machine/builtin/module.cpp
  32. +2 −2 machine/builtin/module.hpp
  33. +1 −1 machine/builtin/native_method.cpp
  34. +6 −6 machine/builtin/system.cpp
  35. +5 −5 machine/builtin/system.hpp
  36. +3 −3 machine/call_frame.cpp
  37. +3 −3 machine/call_frame.hpp
  38. +2 −2 machine/capi/capi.cpp
  39. +1 −1 machine/capi/thread.cpp
  40. +1 −1 machine/codegen/field_extract.rb
  41. +2 −2 machine/compiled_file.cpp
  42. +9 −9 machine/helpers.cpp
  43. +1 −1 machine/instructions.cpp
  44. +11 −11 machine/instructions.def
  45. +2 −2 machine/machine_code.cpp
  46. +1 −1 machine/memory/finalizer.cpp
  47. +7 −7 machine/memory/gc.cpp
  48. +3 −3 machine/ontology.cpp
  49. +3 −3 machine/signal.cpp
  50. +1 −1 machine/test/test_compiled_file.hpp
  51. +2 −2 machine/test/test_constant_scope.hpp
  52. +1 −1 rakelib/vm.rake
  53. +2 −2 spec/core/constantcache/{constant_scope_spec.rb → lexical_scope_spec.rb}
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ GEM
rubinius-melbourne (~> 3)
rubinius-processor (~> 3)
rubinius-toolset (~> 3)
rubinius-compiler (3.4)
rubinius-compiler (3.5)
rubinius-instructions (3.0)
rubinius-melbourne (3.8)
rubinius-processor (3.2)
22 changes: 11 additions & 11 deletions core/basic_object.rb
Original file line number Diff line number Diff line change
@@ -110,26 +110,26 @@ def instance_eval(string=nil, filename="(eval)", line=1, &prc)
env = prc.block

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

return env.call_under(self, constant_scope, true, self)
return env.call_under(self, lexical_scope, true, self)
elsif string
string = ::Kernel.StringValue(string)

constant_scope = ::Rubinius::ConstantScope.of_sender
lexical_scope = ::Rubinius::LexicalScope.of_sender

if sc
constant_scope = ::Rubinius::ConstantScope.new(sc, constant_scope)
lexical_scope = ::Rubinius::LexicalScope.new(sc, lexical_scope)
else
constant_scope = constant_scope.using_disabled_scope
lexical_scope = lexical_scope.using_disabled_scope
end

binding = ::Binding.setup(::Rubinius::VariableScope.of_sender,
::Rubinius::CompiledCode.of_sender,
constant_scope)
lexical_scope)

c = ::Rubinius::ToolSets::Runtime::Compiler
be = c.construct_block string, binding, filename, line
@@ -165,14 +165,14 @@ def instance_exec(*args, &prc)

return prc.ruby_method.call(*args) if prc.ruby_method

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

return env.call_under(self, constant_scope, true, *args)
return env.call_under(self, lexical_scope, true, *args)
end
end
8 changes: 4 additions & 4 deletions core/binding.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Binding
attr_accessor :variables
attr_accessor :compiled_code
attr_accessor :constant_scope
attr_accessor :lexical_scope
attr_accessor :proc_environment
attr_accessor :location
attr_accessor :receiver
@@ -21,18 +21,18 @@ def self.self_context(recv, variables)
#
# +variables+ is a Rubinius::VariableScope object
# +code+ is a Rubinius::CompiledCode object
# +constant_scope+ is a Rubinius::ConstantScope object
# +lexical_scope+ is a Rubinius::LexicalScope object
#
# See Kernel#binding in core/eval.rb for a simple example of creating a
# Binding object.
#
def self.setup(variables, code, constant_scope, recv=nil, location=nil)
def self.setup(variables, code, lexical_scope, recv=nil, location=nil)
bind = allocate()

bind.receiver = self_context(recv, variables)
bind.variables = variables
bind.compiled_code = code
bind.constant_scope = constant_scope
bind.lexical_scope = lexical_scope
bind.location = location

return bind
16 changes: 8 additions & 8 deletions core/block_environment.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ class BlockEnvironment

# The CompiledCode that implements the code for the block
attr_reader :compiled_code
attr_reader :constant_scope
attr_reader :lexical_scope

attr_accessor :proc_environment

@@ -24,7 +24,7 @@ def call(*args)
raise PrimitiveFailure, "BlockEnvironment#call primitive failed"
end

def call_under(recv, constant_scope, visibility_scope, *args)
def call_under(recv, lexical_scope, visibility_scope, *args)
Rubinius.primitive :block_call_under
raise PrimitiveFailure, "BlockEnvironment#call_under primitive failed"
end
@@ -116,7 +116,7 @@ def under_context(scope, code)
@top_scope = scope
@scope = scope
@compiled_code = code
@constant_scope = code.scope
@lexical_scope = code.scope
@module = code.scope.module

return self
@@ -127,15 +127,15 @@ def change_name(name)
end

def repoint_scope(where)
@constant_scope.using_current_as where
@lexical_scope.using_current_as where
end

def disable_scope!
@constant_scope.using_disabled_scope
@lexical_scope.using_disabled_scope
end

def to_binding
Binding.setup @scope, @compiled_code, @constant_scope
Binding.setup @scope, @compiled_code, @lexical_scope
end

def make_independent
@@ -144,7 +144,7 @@ def make_independent
end

def call_on_instance(obj, *args)
call_under obj, @constant_scope, false, *args
call_under obj, @lexical_scope, false, *args
end

def arity
@@ -177,7 +177,7 @@ def ==(other)
end

def inspect
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} scope=#{@scope.inspect} top_scope=#{@top_scope.inspect} module=#{@module.inspect} compiled_code=#{@compiled_code.inspect} constant_scope=#{@constant_scope.inspect}>"
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} scope=#{@scope.inspect} top_scope=#{@top_scope.inspect} module=#{@module.inspect} compiled_code=#{@compiled_code.inspect} lexical_scope=#{@lexical_scope.inspect}>"
end
end
end
6 changes: 3 additions & 3 deletions core/compiled_code.rb
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ def self.current
attr_accessor :lines # [Tuple] tuple of the lines where its found
attr_accessor :file # [Symbol] the file where this comes from
attr_accessor :local_names # [Array<Symbol>] names of the local vars
attr_accessor :scope # [ConstantScope] scope for looking up constants
attr_accessor :scope # [LexicalScope] scope for looking up constants
attr_accessor :keywords # [Tuple] pairs of Symbol name, required flag
attr_accessor :arity # [Integer] number of arguments, negative if variadic.

@@ -249,11 +249,11 @@ def create_script(wrap=false)
script = CompiledCode::Script.new(self)

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

if wrap
@scope = ConstantScope.new(Module.new, cs)
@scope = LexicalScope.new(Module.new, cs)
else
@scope = cs
end
4 changes: 2 additions & 2 deletions core/constant_cache.rb
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ class ConstantCache
attr_reader :name
attr_reader :value
attr_reader :module
attr_reader :constant_scope
attr_reader :lexical_scope
attr_reader :executable

def ip
@@ -21,7 +21,7 @@ def location
end

def inspect
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} #{location}##{@name} constant=#{@value} module=#{@module} constant_scope=#{@constant_scope}>"
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} #{location}##{@name} constant=#{@value} module=#{@module} lexical_scope=#{@lexical_scope}>"
end
end
end
2 changes: 2 additions & 0 deletions core/deprecations.rb
Original file line number Diff line number Diff line change
@@ -3,5 +3,7 @@ module Rubinius
# "Description" => "Alternative"
"Ruby 2.1/2.2 features that are incompatible with Ruby 2.3 are deprecated." =>
"Use Ruby 2.3 features if they are available.",
"Rubinius::ConstantScope is deprecated." =>
"Use Rubinius::LexicalScope instead.",
}
end
2 changes: 1 addition & 1 deletion core/enumerable_helper.rb
Original file line number Diff line number Diff line change
@@ -10,4 +10,4 @@ def self.cycle_size(enum_size, many)
end
end
end
end
end
16 changes: 8 additions & 8 deletions core/kernel.rb
Original file line number Diff line number Diff line change
@@ -261,7 +261,7 @@ def __method__
module_function :__callee__

def __dir__
scope = Rubinius::ConstantScope.of_sender
scope = Rubinius::LexicalScope.of_sender
script = scope.current_script
basepath = script.file_path
fullpath = nil
@@ -858,7 +858,7 @@ def require(name)
module_function :require

def require_relative(name)
scope = Rubinius::ConstantScope.of_sender
scope = Rubinius::LexicalScope.of_sender
Rubinius::CodeLoader.require_relative(name, scope)
end
module_function :require_relative
@@ -1097,7 +1097,7 @@ def binding
return Binding.setup(
Rubinius::VariableScope.of_sender,
Rubinius::CompiledCode.of_sender,
Rubinius::ConstantScope.of_sender,
Rubinius::LexicalScope.of_sender,
Rubinius::VariableScope.of_sender.self,
Rubinius::Location.of_closest_ruby_method
)
@@ -1114,26 +1114,26 @@ def eval(string, binding=nil, filename=nil, lineno=nil)

if binding
binding = Rubinius::Type.coerce_to_binding binding
filename ||= binding.constant_scope.active_path
filename ||= binding.lexical_scope.active_path
else
binding = Binding.setup(Rubinius::VariableScope.of_sender,
Rubinius::CompiledCode.of_sender,
Rubinius::ConstantScope.of_sender,
Rubinius::LexicalScope.of_sender,
self)

filename ||= "(eval)"
end

lineno ||= binding.line_number

existing_scope = binding.constant_scope
binding.constant_scope = existing_scope.dup
existing_scope = binding.lexical_scope
binding.lexical_scope = existing_scope.dup

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

result = be.call_on_instance(binding.receiver)
binding.constant_scope = existing_scope
binding.lexical_scope = existing_scope
result
end
module_function :eval
18 changes: 9 additions & 9 deletions core/constant_scope.rb → core/lexical_scope.rb
Original file line number Diff line number Diff line change
@@ -5,32 +5,32 @@
# TODO: document

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

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

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

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

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

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

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

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

raise NameError, "Invalid class variable name '#{sym}'"
end
@@ -87,14 +87,14 @@ def top_level?
!@parent
end

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

cs.current_module = mod
2 changes: 1 addition & 1 deletion core/load_order.txt
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ complexifier.rb
configuration.rb
console.rb
constant_cache.rb
constant_scope.rb
lexical_scope.rb
constant_table.rb
continuation.rb
ctype.rb
2 changes: 1 addition & 1 deletion core/location.rb
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ class Location

attr_reader :ip
attr_reader :variables
attr_reader :constant_scope
attr_reader :lexical_scope

def self.of_closest_ruby_method
Rubinius.primitive :location_of_closest_ruby_method
Loading