Skip to content

Commit

Permalink
Revert "Revert "lexical scope -> constant scope""
Browse files Browse the repository at this point in the history
This reverts commit 2801876.
  • Loading branch information
vito committed Jul 28, 2016
1 parent 2801876 commit 4fe49f4
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion kernel/define.ay
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ macro(def(~message): ~*body):
structure proc-argument
)

-- helper for adding a module to the constant scope
-- helper for adding a module to the lexical scope
with-module = Class new:
def(bytecode(gen, _)):
gen push-self
Expand Down
6 changes: 3 additions & 3 deletions lib/atomy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def define_branch(binding, name, branch)
if branch.receiver
branch.receiver.target
else
binding.constant_scope.for_method_definition
binding.lexical_scope.for_method_definition
end

method, branch = register_branch(target, name, branch)

if branch.name
Rubinius.add_method(branch.name, branch.as_method, target, binding.constant_scope, 0, :public)
Rubinius.add_method(branch.name, branch.as_method, target, binding.lexical_scope, 0, :public)
end

Rubinius.add_method(name, method.build, target, binding.constant_scope, 0, :public)
Rubinius.add_method(name, method.build, target, binding.lexical_scope, 0, :public)
end
end
2 changes: 1 addition & 1 deletion lib/atomy/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def build_block(scope, mod)
blk.push_scope
blk.send(:module, 0)

# add Atomy::Grammar::AST to the constant scope
# add Atomy::Grammar::AST to the lexical scope
blk.push_cpath_top
blk.find_const(:Atomy)
blk.find_const(:Grammar)
Expand Down
6 changes: 3 additions & 3 deletions lib/atomy/code/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def bytecode(gen, mod)

private

def invoke_function(gen, mod, fun)
fun.get_bytecode(gen)
def invoke_function(gen, mod, flocal)
flocal.get_bytecode(gen)

gen.dup
gen.send(:block_env, 0)
gen.send(:constant_scope, 0)
gen.send(:lexical_scope, 0)
gen.send(:module, 0)

gen.push_literal(@message)
Expand Down
2 changes: 1 addition & 1 deletion lib/atomy/codeloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def run_script(path)
Rubinius.attach_method(
:__script__,
code,
mod.compile_context.constant_scope,
mod.compile_context.lexical_scope,
mod)

res = mod.__script__
Expand Down
2 changes: 1 addition & 1 deletion lib/atomy/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def generate(file, line = 0, state = LocalState.new)

def construct_block(code, binding)
code = code.dup
code.scope = binding.constant_scope
code.scope = binding.lexical_scope
code.name = binding.variables.method.name
code.scope.script =
Rubinius::CompiledCode::Script.new(code, code.file.to_s, true)
Expand Down
4 changes: 2 additions & 2 deletions lib/atomy/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def build

done.set!
end.tap do |cm|
cm.scope = Rubinius::ConstantScope.new(Object)
cm.scope = Rubinius::LexicalScope.new(Object)
end
end

Expand Down Expand Up @@ -293,7 +293,7 @@ def build_branches(gen, done)
gen.push_literal(@name)
gen.move_down(branch_args)

gen.push_literal(b.body.constant_scope.module)
gen.push_literal(b.body.lexical_scope.module)
gen.move_down(branch_args)

gen.push_self
Expand Down
8 changes: 4 additions & 4 deletions lib/atomy/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize

@exported_modules = []

# easy accessor for the current module via ConstantScope lookup
# easy accessor for the current module via LexicalScope lookup
const_set(:Self, self)

super
Expand Down Expand Up @@ -51,7 +51,7 @@ def evaluate(node, binding = nil)
Binding.setup(
Rubinius::VariableScope.of_sender,
Rubinius::CompiledCode.of_sender,
Rubinius::ConstantScope.of_sender,
Rubinius::LexicalScope.of_sender,
self)

code = Atomy::Compiler.compile(
Expand Down Expand Up @@ -108,9 +108,9 @@ def pattern(node)
def compile_context
return @compile_context if @compile_context

scope = Rubinius::ConstantScope.new(
scope = Rubinius::LexicalScope.new(
self,
Rubinius::ConstantScope.new(Object))
Rubinius::LexicalScope.new(Object))

meth = proc {}.block.compiled_code
meth.metadata = nil
Expand Down
2 changes: 1 addition & 1 deletion spec/atomy/bootstrap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
expect(subject.expand(ast("foo"))).to eq(ast("42"))
end

it "adds Atomy::Grammar::AST to its constant scope" do
it "adds Atomy::Grammar::AST to its lexical scope" do
subject.evaluate(subject.macro_definer(ast("Word"), ast("Word")), subject.compile_context)
expect(subject.expand(ast("foo"))).to eq(Atomy::Grammar::AST::Word)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/atomy/code/define_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def define!
end

context "without a receiver" do
it "defines the method on the ConstantScope's for_method_definition" do
it "defines the method on the LexicalScope's for_method_definition" do
mod = Atomy::Module.new
eval_binding.constant_scope.current_module = mod
eval_binding.lexical_scope.current_module = mod
define!
expect(mod.foo).to eq(0)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/atomy/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ def expand(_)
expect(block.scope).to eq(binding.variables)
end

it "sets the code's scope to the binding's constant scope" do
it "sets the code's scope to the binding's lexical scope" do
block = described_class.construct_block(code, binding)
expect(block.compiled_code.scope).to eq(binding.constant_scope)
expect(block.compiled_code.scope).to eq(binding.lexical_scope)
end

it "sets the code's name to the binding's variable scope method name" do
Expand Down
2 changes: 1 addition & 1 deletion spec/atomy/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
expect(subject.build.file).to eq(:__wrapper__)
end

it "has a basic constant scope, so that #under_context works" do
it "has a basic lexical scope, so that #under_context works" do
scope = subject.build.scope
expect(scope).to_not be_nil
expect(scope.module).to eq(Object)
Expand Down
10 changes: 5 additions & 5 deletions spec/atomy/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ def expand(node)
expect(a).to be(b)
end

describe "constant scope" do
subject { mod.compile_context.constant_scope }
describe "lexical scope" do
subject { mod.compile_context.lexical_scope }

it "has the module as the its module" do
expect(subject.module).to be(mod)
Expand All @@ -341,12 +341,12 @@ def expand(node)
context "when the module has a file" do
let(:mod) { Atomy::Module.new.tap { |m| m.file = :foo } }

it "has a script on its ConstantScope" do
it "has a script on it" do
expect(subject.script).to be_a(Rubinius::CompiledCode::Script)
end

describe "script" do
subject { mod.compile_context.constant_scope.script }
subject { mod.compile_context.lexical_scope.script }

its(:file_path) { should == "foo" }
its(:data_path) { should == File.expand_path("foo") }
Expand All @@ -360,7 +360,7 @@ def expand(node)

its(:name) { should == :__script__ }
its(:metadata) { should be_nil }
its(:scope) { should == mod.compile_context.constant_scope }
its(:scope) { should == mod.compile_context.lexical_scope }
end

describe "variable scope" do
Expand Down
2 changes: 1 addition & 1 deletion spec/atomy/node/constructable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def it_can_construct_itself
node.construct(gen)
end

code.scope = binding.constant_scope
code.scope = binding.lexical_scope

block = Atomy::Compiler.construct_block(code, binding)
constructed = block.call
Expand Down

0 comments on commit 4fe49f4

Please sign in to comment.